schema_issues.ts

Validation issues of a @fuzdev/fuz_schema parse (SchemaIssue) as the stack reads them: on the input or on a field, unknown keys, text, and the one shape every error response carries them in, WireIssue.

view source

Declarations
#

8 declarations

assert_validation_schema
#

schema_issues.ts view source

(value: unknown, label: string): asserts value is AnySchema import {assert_validation_schema} from '@fuzdev/fuz_app/schema_issues.js';

Throw unless value is a @fuzdev/fuz_schema schema (is_schema), naming label — what spec registration runs on each schema slot, so a value that is no schema fails at registration rather than at request time.

value

the value a spec declares as a schema

type unknown

label

names the spec and slot in the error, e.g. `` RPC action "foo": input ``

type string

returns

void

throws

  • Error - when `value` is not a fuz_schema schema

format_issues
#

schema_issues.ts view source

(issues: readonly SchemaIssue[]): string import {format_issues} from '@fuzdev/fuz_app/schema_issues.js';

A failed parse's issues as text, a format_issue line each.

issues

a failed parse's issues

type readonly SchemaIssue[]

returns

string

is_schema_validation_error
#

schema_issues.ts view source

(err: unknown): err is SchemaError import {is_schema_validation_error} from '@fuzdev/fuz_app/schema_issues.js';

Whether err is a thrown validation failure, a SchemaError (parse_or_throw), which carries the failed parse's issues.

err

a caught value

type unknown

returns

boolean

issue_is_on_input
#

schema_issues.ts view source

(issue: SchemaIssue): boolean import {issue_is_on_input} from '@fuzdev/fuz_app/schema_issues.js';

Whether issue sits on the input itself rather than on one of its fields: a non-object input, or an unknown key on the input object — what the Rust twin refuses before reading any field.

A non-object is reported at an empty path, and each unknown key as an unknown_key issue whose path ends at the key, so one on the input has a path of the key alone. An unknown key on a nested object is on that field.

On the wire the unknown_key rule changes no answer today: a root unknown_key comes from a root object, which resolve_issues_invalid_reason already answers with none from its check of the input's keys, or from a schema such as a variant whose fields resolve no reason. It is kept as the direct statement of the rule.

issue

one issue of a failed parse

type SchemaIssue

returns

boolean

to_wire_issues
#

schema_issues.ts view source

(issues: readonly SchemaIssue[]): ({ kind: string; path: (string | number)[]; expected: string; received: string; message: string; } & Record<string, unknown>)[] import {to_wire_issues} from '@fuzdev/fuz_app/schema_issues.js';

A failed parse's issues as WireIssues: each keeps its kind, path, expected and received, and its message is format_issue's text, the path included. A symbol key in a path goes as its text.

issues

a failed parse's issues

type readonly SchemaIssue[]

returns

WireIssue[]

one per issue

unknown_key_targets
#

schema_issues.ts view source

(issues: readonly SchemaIssue[]): UnknownKeyTarget[] | null import {unknown_key_targets} from '@fuzdev/fuz_app/schema_issues.js';

The unknown keys among issues, each with the path of its object, or null when any issue is something else. An unknown_key issue is one key, the last element of its path.

issues

a failed parse's issues

type readonly SchemaIssue[]

returns

UnknownKeyTarget[] | null

a target per issue, or null when not every issue is an unknown key

UnknownKeyTarget
#

schema_issues.ts view source

UnknownKeyTarget import type {UnknownKeyTarget} from '@fuzdev/fuz_app/schema_issues.js';

Keys a parse refused as unknown, and the path of the object holding them.

path

The path of the object the keys are on, [] for the input itself.

type readonly PropertyKey[]

keys

The unknown keys.

type readonly PropertyKey[]

WireIssue
#

schema_issues.ts view source

value + type

{ kind: string; path: (string | number)[]; expected: string; received: string; message: string; } & Record<string, unknown>

type { kind: string; path: (string | number)[]; expected: string; received: string; message: string; } & Record<string, unknown>

import {WireIssue} from '@fuzdev/fuz_app/schema_issues.js';

A @fuzdev/fuz_schema loose_object: a validation issue as an error response carries it — SchemaIssue as JSON, with message the text of the issue. to_wire_issues builds it.

Loose: a client reads it, and a newer server may add fields.

kind

The fuz_schema kind of the check that failed, or unknown_key / missing_key.

type string

path

Keys from the root value to the one that failed, outermost first.

type (string | number)[]

expected

Describes what was expected, as fuz_schema writes it.

type string

received

The type of the value that failed: 'null', 'array', 'NaN', 'Infinity', '-Infinity', or its typeof.

type string

message

The issue as text, format_issue's.

type string

[key: string]

type unknown

Imported by
#