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/):
typedeclarations addressed by name.- Kinds:
struct,map,list,enum,union,link,bytes,string,int,float,bool,null,any,unit,copy. - Field modifiers
optionalandnullableon struct fields, andvalueNullableon 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. advancedrepresentations name an ADL whose data-model shape is declared in the schema's top-leveladvancedmap ({<adl>: <term>}) or theadlTypesregistry. The ADL name is taken fromrepresentation: {advanced: <name>}, or defaults to the type's own name per the IPLD spec. Arepresentationclause 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/optionalfield lists,strictunknown-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
nameand schema definition.
Properties
Methods
-
check(
String typeName, IPLDNode node) → SchemaValidationResult -
Validates
nodeagainsttypeName, 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
nodeagainsttypeNamelike 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
nodeagainsttypeName, 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) soexpectedTypeclauses 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.