checkAsync method
- String typeName,
- IPLDNode node, {
- IPLDLinkResolver? linkResolver,
Validates node against typeName like check, additionally
resolving link targets when an IPLDLinkResolver is available.
linkResolver overrides the constructor-supplied resolver; when both
are absent this behaves exactly like check (links are kind-checked
only). With a resolver, every link type carrying expectedType
loads its target — transitively, so links inside resolved nodes are
checked too — and reports mismatches at the link's path. A target
that cannot be loaded produces an error rather than an exception;
a (target, expectedType) pair is resolved once per call and cyclic
links are validated once to guarantee termination.
Throws IPLDSchemaError for malformed schema definitions.
Implementation
Future<SchemaValidationResult> checkAsync(
String typeName,
IPLDNode node, {
IPLDLinkResolver? linkResolver,
}) async {
final resolver = linkResolver ?? _linkResolver;
if (resolver == null) return check(typeName, node);
final validator = _SchemaValidator(
_schema,
linkResolver: resolver,
adlTypes: _adlTypes,
);
validator._validateType(node, _typeDef(typeName), typeName: typeName);
while (validator._deferred.isNotEmpty) {
final deferred = validator._deferred.removeAt(0);
final relative = await deferred.run();
if (relative.isEmpty) continue;
final base = _describeSegments(deferred.path);
for (final error in relative) {
validator.errors.add(
SchemaValidationError(
path: _joinPaths(base, error.path),
message: error.message,
),
);
}
}
return SchemaValidationResult(validator.errors);
}