@ark/schema
Advanced tools
Comparing version 0.16.0 to 0.17.0
@@ -59,4 +59,3 @@ import { type array, type describe, type listable, type satisfy } from "@ark/util"; | ||
export declare const flattenConstraints: (inner: object) => BaseConstraint[]; | ||
interface FlatIntersectionInner extends Intersection.Inner, Structure.Inner { | ||
} | ||
type FlatIntersectionInner = Intersection.Inner & Structure.Inner; | ||
export declare const unflattenConstraints: (constraints: array<BaseConstraint>) => FlatIntersectionInner; | ||
@@ -63,0 +62,0 @@ export type constraintKindLeftOf<kind extends ConstraintKind> = ConstraintKind & kindLeftOf<kind>; |
@@ -15,2 +15,3 @@ import { Callable, type Guardable, type Json, type Key, type array, type conform, type listable, type mutable } from "@ark/util"; | ||
import { type arkKind } from "./shared/utils.ts"; | ||
import type { UndeclaredKeyHandling } from "./structure/structure.ts"; | ||
export declare abstract class BaseNode< | ||
@@ -103,3 +104,4 @@ /** uses -ignore rather than -expect-error because this is not an error in .d.ts | ||
parseOptions: BaseParseOptions; | ||
undeclaredKeyHandling: UndeclaredKeyHandling | undefined; | ||
} | ||
export type DeepNodeTransformation = <kind extends NodeKind>(kind: kind, inner: Inner<kind>, ctx: DeepNodeTransformContext) => NormalizedSchema<kind> | null; |
@@ -198,3 +198,4 @@ import { Callable, appendUnique, flatMorph, includes, isArray, isEmptyObject, throwError } from "@ark/util"; | ||
prereduced: opts?.prereduced ?? false | ||
} | ||
}, | ||
undeclaredKeyHandling: undefined | ||
}); | ||
@@ -212,2 +213,9 @@ } | ||
ctx.seen[this.id] = () => transformedNode; | ||
if (this.hasKind("structure") && | ||
this.undeclared !== ctx.undeclaredKeyHandling) { | ||
ctx = { | ||
...ctx, | ||
undeclaredKeyHandling: this.undeclared | ||
}; | ||
} | ||
const innerWithTransformedChildren = flatMorph(this.inner, (k, v) => { | ||
@@ -244,4 +252,7 @@ if (!this.impl.keys[k].child) | ||
this.kind === "index") && | ||
!("value" in transformedInner)) | ||
return null; | ||
!("value" in transformedInner)) { | ||
return ctx.undeclaredKeyHandling ? | ||
{ ...transformedInner, value: $ark.intrinsic.unknown } | ||
: null; | ||
} | ||
if (this.kind === "morph") { | ||
@@ -248,0 +259,0 @@ ; |
@@ -89,3 +89,3 @@ import { arrayEquals, liftArray, throwParseError } from "@ark/util"; | ||
get in() { | ||
return this.declaredIn ?? this.inner.in ?? $ark.intrinsic.unknown.internal; | ||
return (this.declaredIn ?? this.inner.in?.in ?? $ark.intrinsic.unknown.internal); | ||
} | ||
@@ -92,0 +92,0 @@ get out() { |
@@ -79,15 +79,12 @@ import { append, conflatenate, flatMorph, printable, spliterate, throwParseError } from "@ark/util"; | ||
const rInner = { ...r.inner }; | ||
const disjointResult = new Disjoint(); | ||
if (l.undeclared) { | ||
const lKey = l.keyof(); | ||
const disjointRKeys = r.requiredKeys.filter(k => !lKey.allows(k)); | ||
if (disjointRKeys.length) { | ||
return new Disjoint(...disjointRKeys.map(k => ({ | ||
kind: "presence", | ||
discriminantKind: undefined, | ||
l: $ark.intrinsic.never.internal, | ||
r: r.propsByKey[k].value, | ||
path: [k], | ||
optional: false | ||
}))); | ||
} | ||
r.requiredKeys.forEach(k => { | ||
if (!lKey.allows(k)) { | ||
disjointResult.add("presence", $ark.intrinsic.never.internal, r.propsByKey[k].value, { | ||
path: [k] | ||
}); | ||
} | ||
}); | ||
if (rInner.optional) | ||
@@ -115,13 +112,9 @@ rInner.optional = rInner.optional.filter(n => lKey.allows(n.key)); | ||
const rKey = r.keyof(); | ||
const disjointLKeys = l.requiredKeys.filter(k => !rKey.allows(k)); | ||
if (disjointLKeys.length) { | ||
return new Disjoint(...disjointLKeys.map(k => ({ | ||
kind: "presence", | ||
discriminantKind: undefined, | ||
l: l.propsByKey[k].value, | ||
r: $ark.intrinsic.never.internal, | ||
path: [k], | ||
optional: false | ||
}))); | ||
} | ||
l.requiredKeys.forEach(k => { | ||
if (!rKey.allows(k)) { | ||
disjointResult.add("presence", l.propsByKey[k].value, $ark.intrinsic.never.internal, { | ||
path: [k] | ||
}); | ||
} | ||
}); | ||
if (lInner.optional) | ||
@@ -154,3 +147,3 @@ lInner.optional = lInner.optional.filter(n => rKey.allows(n.key)); | ||
} | ||
return intersectConstraints({ | ||
const childIntersectionResult = intersectConstraints({ | ||
kind: "structure", | ||
@@ -163,2 +156,7 @@ baseInner, | ||
}); | ||
if (childIntersectionResult instanceof Disjoint) | ||
disjointResult.push(...childIntersectionResult); | ||
if (disjointResult.length) | ||
return disjointResult; | ||
return childIntersectionResult; | ||
} | ||
@@ -165,0 +163,0 @@ } |
{ | ||
"name": "@ark/schema", | ||
"version": "0.16.0", | ||
"version": "0.17.0", | ||
"license": "MIT", | ||
@@ -32,3 +32,3 @@ "author": { | ||
"dependencies": { | ||
"@ark/util": "0.16.0" | ||
"@ark/util": "0.17.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
351266
8213
+ Added@ark/util@0.17.0(transitive)
- Removed@ark/util@0.16.0(transitive)
Updated@ark/util@0.17.0