@ark/schema
Advanced tools
Comparing version 0.14.0 to 0.15.0
@@ -37,2 +37,3 @@ import { type array, type listable } from "@ark/util"; | ||
lastMorph: BaseRoot<import("./root.ts").InternalRootDeclaration> | Morph<any, unknown> | undefined; | ||
lastMorphIfNode: BaseRoot | undefined; | ||
introspectableIn: BaseRoot | undefined; | ||
@@ -39,0 +40,0 @@ introspectableOut: BaseRoot | undefined; |
@@ -82,6 +82,7 @@ import { arrayEquals, liftArray, throwParseError } from "@ark/util"; | ||
lastMorph = this.inner.morphs.at(-1); | ||
lastMorphIfNode = hasArkKind(this.lastMorph, "root") ? this.lastMorph : undefined; | ||
introspectableIn = this.inner.in; | ||
introspectableOut = hasArkKind(this.lastMorph, "root") ? | ||
Object.assign(this.referencesById, this.lastMorph.out.referencesById) && | ||
this.lastMorph.out | ||
introspectableOut = this.lastMorphIfNode ? | ||
Object.assign(this.referencesById, this.lastMorphIfNode.referencesById) && | ||
this.lastMorphIfNode.out | ||
: undefined; | ||
@@ -88,0 +89,0 @@ get in() { |
@@ -29,2 +29,3 @@ import { inferred, type array } from "@ark/util"; | ||
constructor(attachments: UnknownAttachments, $: BaseScope); | ||
assert: (data: unknown) => unknown; | ||
get internal(): this; | ||
@@ -49,3 +50,2 @@ get optionalMeta(): boolean; | ||
rawOr(r: BaseRoot): BaseRoot; | ||
assert(data: unknown): unknown; | ||
map(flatMapEntry: PropFlatMapper): BaseRoot; | ||
@@ -52,0 +52,0 @@ pick(...keys: KeyOrKeyNode[]): BaseRoot; |
@@ -17,2 +17,6 @@ import { includes, inferred, omit, throwInternalError, throwParseError, unset } from "@ark/util"; | ||
} | ||
assert = (data) => { | ||
const result = this.traverse(data); | ||
return result instanceof ArkErrors ? result.throw() : result; | ||
}; | ||
get internal() { | ||
@@ -80,6 +84,2 @@ return this; | ||
} | ||
assert(data) { | ||
const result = this.traverse(data); | ||
return result instanceof ArkErrors ? result.throw() : result; | ||
} | ||
map(flatMapEntry) { | ||
@@ -86,0 +86,0 @@ return this.$.schema(this.applyStructuralOperation("map", [flatMapEntry])); |
@@ -108,5 +108,5 @@ import { Disjoint } from "./disjoint.js"; | ||
const morphs = [...from.morphs]; | ||
if (from.introspectableOut) { | ||
if (from.lastMorphIfNode) { | ||
// still piped from context, so allows appending additional morphs | ||
const outIntersection = intersectNodes(from.introspectableOut, to, ctx); | ||
const outIntersection = intersectNodes(from.lastMorphIfNode, to, ctx); | ||
if (outIntersection instanceof Disjoint) | ||
@@ -113,0 +113,0 @@ return outIntersection; |
@@ -5,3 +5,3 @@ import type { array } from "@ark/util"; | ||
import { ArkError, ArkErrors, type ArkErrorCode, type ArkErrorInput } from "./errors.ts"; | ||
import type { TraversalPath } from "./utils.ts"; | ||
import { type TraversalPath } from "./utils.ts"; | ||
export type MorphsAtPath = { | ||
@@ -8,0 +8,0 @@ path: TraversalPath; |
import { ArkError, ArkErrors } from "./errors.js"; | ||
import { pathToPropString } from "./utils.js"; | ||
export class TraversalContext { | ||
@@ -28,6 +29,4 @@ path = []; | ||
finalize() { | ||
if (this.hasError()) | ||
return this.errors; | ||
if (!this.queuedMorphs.length) | ||
return this.root; | ||
return this.hasError() ? this.errors : this.root; | ||
if (typeof this.root === "object" && | ||
@@ -42,2 +41,9 @@ this.root !== null && | ||
const { path, morphs } = this.queuedMorphs.shift(); | ||
// even if we already have an error, apply morphs that are not at a path | ||
// with errors to capture potential validation errors | ||
if (this.hasError()) { | ||
const morphPropString = pathToPropString(path); | ||
if (this.errors.some(e => morphPropString.startsWith(e.propString))) | ||
continue; | ||
} | ||
const key = path.at(-1); | ||
@@ -54,21 +60,21 @@ let parent; | ||
const result = morph(parent === undefined ? this.root : parent[key], this); | ||
if (result instanceof ArkErrors) | ||
return result; | ||
if (this.hasError()) | ||
return this.errors; | ||
if (result instanceof ArkError) { | ||
// if an ArkError was returned but wasn't added to these | ||
// errors, add it then return | ||
this.error(result); | ||
return this.errors; | ||
// errors, add it | ||
if (!this.errors.includes(result)) | ||
this.error(result); | ||
} | ||
// apply the morph function and assign the result to the | ||
// corresponding property, or to root if path is empty | ||
if (parent === undefined) | ||
this.root = result; | ||
else | ||
parent[key] = result; | ||
else if (!(result instanceof ArkErrors)) { | ||
// if the morph was successful, assign the result to the | ||
// corresponding property, or to root if path is empty | ||
if (parent === undefined) | ||
this.root = result; | ||
else | ||
parent[key] = result; | ||
} | ||
// if ArkErrors was returned, the morph itself was likely a type | ||
// and the errors will have been added directly via this piped context | ||
} | ||
} | ||
return this.root; | ||
return this.hasError() ? this.errors : this.root; | ||
} | ||
@@ -75,0 +81,0 @@ get currentErrorCount() { |
{ | ||
"name": "@ark/schema", | ||
"version": "0.14.0", | ||
"version": "0.15.0", | ||
"license": "MIT", | ||
@@ -32,3 +32,3 @@ "author": { | ||
"dependencies": { | ||
"@ark/util": "0.14.0" | ||
"@ark/util": "0.15.0" | ||
}, | ||
@@ -35,0 +35,0 @@ "publishConfig": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
348545
8137
+ Added@ark/util@0.15.0(transitive)
- Removed@ark/util@0.14.0(transitive)
Updated@ark/util@0.15.0