agentsclimarketplace

Br write schema

Skill Lonsdale201/wp-agent-skills/better-route/br-write-schema

Configure Better Route 1.1 Resource writeSchema or payloadSchema validation for create and update payloads. Use when defining writable fields, coercion, sanitization, required and nullable values, lengths, ranges, regexes, enums, or structured fieldErrors.From its SKILL.md

Install
npx -y skills add Lonsdale201/wp-agent-skills --skill br-write-schema

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 21 stars21 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

3.6 KB, 727 tokens by cl100k_base, as published. Nobody here has run it

Better Route Resource write schema

Use writeSchema() to validate and normalize Resource create/update payload fields. payloadSchema() is an exact alias.

Resource::make('articles')
    ->allow(['create', 'update'])
    ->fields(['id', 'title', 'status', 'priority', 'published_at'])
    ->writeSchema([
        'title' => [
            'type' => 'string',
            'required' => true,
            'sanitize' => 'text',
            'minLength' => 1,
            'maxLength' => 180,
        ],
        'status' => [
            'type' => 'enum',
            'values' => ['draft', 'published'],
        ],
        'priority' => ['type' => 'int', 'min' => 0, 'max' => 100],
        'published_at' => ['type' => 'date', 'nullable' => true],
    ]);

The enum allowlist is flat: use ['type' => 'enum', 'values' => [...]]. Do not nest values under an enum key.

Rule contract

  • Type strings may be supplied directly, such as 'title' => 'string'.
  • Supported coercion types are int/integer, float/number, bool/boolean, string, date, email, url, enum, array, object, and mixed.
  • required is enforced only on create; updates may be partial but must contain at least one writable field.
  • nullable: true accepts null; otherwise null fails validation.
  • String constraints are minLength, maxLength, and regex. Numeric constraints are min and max.
  • email and url use PHP validation after coercion/sanitization. date is only string coercion; validate date format with regex or a callable sanitizer/other domain layer.
  • Sanitizers are text, email, key, url, or a callable receiving (value, field). An unknown sanitizer string leaves the value unchanged, so never treat arbitrary names as validation.
  • Callable sanitizers transform values; they are not authorization checks and must return a value compatible with subsequent constraints.

Resource writable fields come from configured fields minus the ID field. Unknown payload keys fail with 400 validation_failed; they are not silently dropped. A field denied by fieldPolicy also fails, rather than disappearing from the write.

Validation errors use the standard error envelope with details.fieldErrors. Boolean fieldPolicy: false produces a 400 non-writable validation error; failed capabilities or policy callbacks produce 403 errors. Follow br-resource-policy for authorization.

Checks

  • Test unknown, empty, null, malformed, boundary, and coerced values.
  • Test required fields separately on create and partial update.
  • Test enum values with strict type expectations; enum values are compared strictly after string coercion.
  • Anchor regexes and set explicit maximum lengths before expensive domain processing.
  • Do not add patch to allow(); the Resource action name is update, even though its route handles update semantics.

Source reference: src/Resource/Resource.php (readPayload, coercePayloadValue, assertValueConstraints, validationError).

References

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 326,835. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.