IPLDSchema class

IPLD schema validator for structured data validation.

Validates IPLD nodes against type schemas including structs, maps, lists, enums, unions, links, and scalar kinds. Supports the commonly-used subset of the IPLD schema DSL (https://ipld.io/specs/schemas/):

  • type declarations addressed by name.
  • Kinds: struct, map, list, enum, union, link, bytes, string, int, float, bool, null, any, unit, copy.
  • Field modifiers optional and nullable on struct fields, and valueNullable on map/list value types.
  • Representation strategies: map, listpairs, stringpairs, tuple, stringjoin (structs and maps); kinded, keyed, envelope/ enveloped, inline, stringprefix, bytesprefix/byteprefix (unions); string, int (enums); advanced (see below).
  • Link types may carry expectedType (e.g. {"kind": "link", "expectedType": "Foo"}). When an IPLDLinkResolver is supplied — per call or via the constructor — the link target is loaded and validated against that type, with failures reported at the link's path. Without a resolver links are kind-checked only.
  • advanced representations name an ADL whose data-model shape is declared in the schema's top-level advanced map ({<adl>: <term>}) or the adlTypes registry. The ADL name is taken from representation: {advanced: <name>}, or defaults to the type's own name per the IPLD spec. A representation clause that explicitly references an undeclared ADL name throws IPLDSchemaError when the schema is constructed; ADLs that are merely unknown (no declared or registered schema) skip validation leniently.
  • Legacy extensions are preserved: valueConstraint (min, max, pattern, minLength, maxLength), required/optional field lists, strict unknown-key rejection, and {"kind": "type", "valueType": ...} reference wrappers.

Two validation styles are available: validate returns a boolean for backward compatibility, while check returns a SchemaValidationResult carrying every error with a precise path. validateOrThrow throws IPLDSchemaError with the first offending path. The synchronous check/validateOrThrow entry points never resolve links; use checkAsync/validateOrThrowAsync (or validate with a resolver) to enforce link expectedType clauses.

Constructors

IPLDSchema(String name, Map<String, dynamic> _schema, {IPLDLinkResolver? linkResolver, Map<String, Object?>? adlTypes})
Creates an IPLD schema with name and schema definition.

Properties

hashCode → int
The hash code for this object.
no setterinherited
name → String
Schema name.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

check(String typeName, IPLDNode node) → SchemaValidationResult
Validates node against typeName, collecting every mismatch with a precise path instead of stopping at the first boolean answer.
checkAsync(String typeName, IPLDNode node, {IPLDLinkResolver? linkResolver}) → Future<SchemaValidationResult>
Validates node against typeName like check, additionally resolving link targets when an IPLDLinkResolver is available.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited
validate(String typeName, IPLDNode node, {IPLDLinkResolver? linkResolver}) → Future<bool>
Validates an IPLD node against the schema type.
validateOrThrow(String typeName, IPLDNode node) → void
Validates node against typeName, throwing IPLDSchemaError with the first precise error path when the node does not match.
validateOrThrowAsync(String typeName, IPLDNode node, {IPLDLinkResolver? linkResolver}) → Future<void>
As validateOrThrow, but resolves link targets through linkResolver (or the constructor-supplied resolver) so expectedType clauses are enforced.

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

linkResolverFromNodeLoader(Future<IPLDNode?> loadNode(CID cid)) → IPLDLinkResolver
Adapts a CID-based node loader — e.g. IPLDHandler.getNode, the same block-fetch path used by selector execution — into an IPLDLinkResolver. Loader exceptions propagate and are reported as resolution failures at the link's path.