@orkestrel/contract 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/core/index.cjs +348 -0
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +245 -0
- package/dist/src/core/index.d.ts +245 -0
- package/dist/src/core/index.js +343 -1
- package/dist/src/core/index.js.map +1 -1
- package/package.json +1 -1
package/dist/src/core/index.js
CHANGED
|
@@ -3654,7 +3654,349 @@ function rawShape(schema) {
|
|
|
3654
3654
|
schema
|
|
3655
3655
|
};
|
|
3656
3656
|
}
|
|
3657
|
+
/**
|
|
3658
|
+
* Derive `min`/`max` shape bounds from a pair of non-negative-integer JSON
|
|
3659
|
+
* Schema length keywords (`minLength`/`maxLength`, `minItems`/`maxItems`).
|
|
3660
|
+
*
|
|
3661
|
+
* @remarks
|
|
3662
|
+
* Total and pure. Either keyword is used only when it is a non-negative
|
|
3663
|
+
* integer (`isInteger` + `>= 0`); a malformed value (a string, a negative
|
|
3664
|
+
* number, `NaN`, `Infinity`, a fraction) is dropped as if absent. When both
|
|
3665
|
+
* bounds are present and `min` exceeds `max`, the PAIR is dropped entirely
|
|
3666
|
+
* (an unbounded shape is always a legal widening of a contradictory schema).
|
|
3667
|
+
*
|
|
3668
|
+
* @param min - The raw `minLength` / `minItems` keyword value
|
|
3669
|
+
* @param max - The raw `maxLength` / `maxItems` keyword value
|
|
3670
|
+
* @returns The derived `min` / `max` pair, either possibly `undefined`
|
|
3671
|
+
*
|
|
3672
|
+
* @example
|
|
3673
|
+
* ```ts
|
|
3674
|
+
* deriveLengthBounds(1, 10) // { min: 1, max: 10 }
|
|
3675
|
+
* deriveLengthBounds(10, 1) // {} — contradictory, dropped
|
|
3676
|
+
* deriveLengthBounds(-1, 10) // { max: 10 } — negative min dropped
|
|
3677
|
+
* ```
|
|
3678
|
+
*/
|
|
3679
|
+
function deriveLengthBounds(min, max) {
|
|
3680
|
+
const lo = isInteger(min) && min >= 0 ? min : void 0;
|
|
3681
|
+
const hi = isInteger(max) && max >= 0 ? max : void 0;
|
|
3682
|
+
if (lo !== void 0 && hi !== void 0 && lo > hi) return {};
|
|
3683
|
+
return {
|
|
3684
|
+
min: lo,
|
|
3685
|
+
max: hi
|
|
3686
|
+
};
|
|
3687
|
+
}
|
|
3688
|
+
/**
|
|
3689
|
+
* Derive `min`/`max` shape bounds from a pair of finite-number JSON Schema
|
|
3690
|
+
* range keywords (`minimum`/`maximum`).
|
|
3691
|
+
*
|
|
3692
|
+
* @remarks
|
|
3693
|
+
* Total and pure. Either keyword is used only when it is a finite number
|
|
3694
|
+
* ({@link isFiniteNumber} — rejects `NaN` / `±Infinity` / non-numbers); when
|
|
3695
|
+
* both bounds are present and `min` exceeds `max`, the PAIR is dropped
|
|
3696
|
+
* entirely, the same contradiction rule {@link deriveLengthBounds} applies.
|
|
3697
|
+
*
|
|
3698
|
+
* @param min - The raw `minimum` keyword value
|
|
3699
|
+
* @param max - The raw `maximum` keyword value
|
|
3700
|
+
* @returns The derived `min` / `max` pair, either possibly `undefined`
|
|
3701
|
+
*
|
|
3702
|
+
* @example
|
|
3703
|
+
* ```ts
|
|
3704
|
+
* deriveRangeBounds(0, 120) // { min: 0, max: 120 }
|
|
3705
|
+
* deriveRangeBounds(5, 1) // {} — contradictory, dropped
|
|
3706
|
+
* ```
|
|
3707
|
+
*/
|
|
3708
|
+
function deriveRangeBounds(min, max) {
|
|
3709
|
+
const lo = isFiniteNumber(min) ? min : void 0;
|
|
3710
|
+
const hi = isFiniteNumber(max) ? max : void 0;
|
|
3711
|
+
if (lo !== void 0 && hi !== void 0 && lo > hi) return {};
|
|
3712
|
+
return {
|
|
3713
|
+
min: lo,
|
|
3714
|
+
max: hi
|
|
3715
|
+
};
|
|
3716
|
+
}
|
|
3717
|
+
/**
|
|
3718
|
+
* Build an {@link ObjectShape} from a JSON Schema object node's `properties` /
|
|
3719
|
+
* `required` / `additionalProperties` keywords — the object-specialized branch
|
|
3720
|
+
* of {@link buildShapeFromNode}.
|
|
3721
|
+
*
|
|
3722
|
+
* @remarks
|
|
3723
|
+
* `properties` (when a record) contributes one child shape per own key, capped
|
|
3724
|
+
* at {@link INFER_BREADTH_LIMIT}; a key is wrapped in {@link optionalShape}
|
|
3725
|
+
* unless it appears as a string entry of `required`. A property whose value is
|
|
3726
|
+
* not itself a record widens to {@link jsonShape}. `additionalProperties`:
|
|
3727
|
+
* `false` closes the object; a record value recurses into it (`objectShape`
|
|
3728
|
+
* validates extras against that shape); anything else — `true`, absent, or
|
|
3729
|
+
* malformed — leaves the object OPEN (`true`), matching JSON Schema's own
|
|
3730
|
+
* absent-means-open default and the fact that {@link valueToSchema} /
|
|
3731
|
+
* {@link samplesToSchema} always emit the keyword explicitly, so an absent
|
|
3732
|
+
* value only arises from a hand-written schema. When `properties` has MORE
|
|
3733
|
+
* keys than {@link INFER_BREADTH_LIMIT}, the schema's own
|
|
3734
|
+
* `additionalProperties` is OVERRIDDEN and forced to `true` (fully open) —
|
|
3735
|
+
* a dropped key's value could otherwise fail a `false` or record-valued rest
|
|
3736
|
+
* shape it was never checked against — mirroring `inferObject`'s
|
|
3737
|
+
* `truncated ? true : !closed` rule (inferers.ts:485). The accumulator uses a
|
|
3738
|
+
* null-prototype record so a property literally named `__proto__` becomes an
|
|
3739
|
+
* own data key rather than mutating the prototype, mirroring
|
|
3740
|
+
* {@link inferObject} (inferers.ts).
|
|
3741
|
+
*
|
|
3742
|
+
* @param schema - The object schema node
|
|
3743
|
+
* @param depth - Remaining descent budget passed to child properties
|
|
3744
|
+
* @param visited - The ancestor set guarding against cycles — recursion
|
|
3745
|
+
* state owned by the {@link schemaToShape} entry point; passing a shared or
|
|
3746
|
+
* pre-populated `WeakSet` changes cycle-detection behavior and is not
|
|
3747
|
+
* supported usage
|
|
3748
|
+
* @param memo - A per-call `(schema node, remaining depth) → shape` cache —
|
|
3749
|
+
* recursion state owned by the {@link schemaToShape} entry point; passing
|
|
3750
|
+
* a shared or pre-populated `WeakMap` changes caching behavior and is not
|
|
3751
|
+
* supported usage
|
|
3752
|
+
* @param description - The node's already-extracted `description`, if any
|
|
3753
|
+
* @returns The built object shape
|
|
3754
|
+
*
|
|
3755
|
+
* @example
|
|
3756
|
+
* ```ts
|
|
3757
|
+
* buildObjectShape(
|
|
3758
|
+
* { type: 'object', properties: { id: { type: 'integer' } }, required: ['id'] },
|
|
3759
|
+
* INFER_DEPTH_LIMIT,
|
|
3760
|
+
* new WeakSet(),
|
|
3761
|
+
* new WeakMap(),
|
|
3762
|
+
* undefined,
|
|
3763
|
+
* )
|
|
3764
|
+
* // objectShape({ id: integerShape() }, { additionalProperties: true })
|
|
3765
|
+
* ```
|
|
3766
|
+
*/
|
|
3767
|
+
function buildObjectShape(schema, depth, visited, memo, description) {
|
|
3768
|
+
const propertiesSource = isRecord(schema.properties) ? schema.properties : void 0;
|
|
3769
|
+
const requiredSource = isArray(schema.required) ? schema.required.filter((entry) => isString(entry)) : [];
|
|
3770
|
+
const properties = Object.create(null);
|
|
3771
|
+
let truncated = false;
|
|
3772
|
+
if (propertiesSource) {
|
|
3773
|
+
const allKeys = Object.keys(propertiesSource);
|
|
3774
|
+
truncated = allKeys.length > 256;
|
|
3775
|
+
const keys = allKeys.slice(0, 256);
|
|
3776
|
+
for (const key of keys) {
|
|
3777
|
+
const child = propertiesSource[key];
|
|
3778
|
+
const childShape = isRecord(child) ? schemaNodeToShape(child, depth - 1, visited, memo) : jsonShape();
|
|
3779
|
+
properties[key] = requiredSource.includes(key) ? childShape : optionalShape(childShape);
|
|
3780
|
+
}
|
|
3781
|
+
}
|
|
3782
|
+
const extra = schema.additionalProperties;
|
|
3783
|
+
return objectShape(properties, {
|
|
3784
|
+
additionalProperties: truncated ? true : extra === false ? false : isRecord(extra) ? schemaNodeToShape(extra, depth - 1, visited, memo) : true,
|
|
3785
|
+
description
|
|
3786
|
+
});
|
|
3787
|
+
}
|
|
3788
|
+
/**
|
|
3789
|
+
* Build a {@link ContractShape} for one JSON Schema node — the recursive
|
|
3790
|
+
* spine of {@link schemaToShape}, shared with per-child recursion via
|
|
3791
|
+
* {@link schemaNodeToShape}.
|
|
3792
|
+
*
|
|
3793
|
+
* @remarks
|
|
3794
|
+
* Every keyword is read defensively (the node's static `JSONSchema` type is
|
|
3795
|
+
* NOT trusted at runtime — a caller-supplied node may be adversarial), so a
|
|
3796
|
+
* malformed keyword falls through to the next rule instead of throwing.
|
|
3797
|
+
* Precedence, top-down:
|
|
3798
|
+
*
|
|
3799
|
+
* 1. `enum` — an array with at least one string/number/boolean entry (finite
|
|
3800
|
+
* numbers only) becomes a {@link literalShape} over the filtered entries.
|
|
3801
|
+
* Non-primitive / non-finite entries are dropped; an empty result falls
|
|
3802
|
+
* through.
|
|
3803
|
+
* 2. `oneOf` — an array with at least one record entry becomes an
|
|
3804
|
+
* {@link oneOfShape} over the recursively-built variants, provided the
|
|
3805
|
+
* record-entry count is at or under {@link INFER_BREADTH_LIMIT}; OVER the
|
|
3806
|
+
* limit, building a subset union would be strictly narrower than the
|
|
3807
|
+
* schema's full union (a value matching only a dropped variant would be
|
|
3808
|
+
* wrongly rejected), so the whole node widens to {@link jsonShape} instead
|
|
3809
|
+
* of sampling a subset.
|
|
3810
|
+
* 3. `anyOf` — identically, via {@link unionShape}.
|
|
3811
|
+
* 4. `type: 'string'` / `'number'` / `'integer'` / `'boolean'` / `'null'` —
|
|
3812
|
+
* the matching primitive shape, with length/range bounds derived via
|
|
3813
|
+
* {@link deriveLengthBounds} / {@link deriveRangeBounds}. An integer node
|
|
3814
|
+
* additionally drops its bounds when they describe an EMPTY integer range
|
|
3815
|
+
* (e.g. `minimum: 1.5, maximum: 1.6`) — the same emptiness `validateShape`
|
|
3816
|
+
* rejects — so the result is always a valid shape.
|
|
3817
|
+
* 5. `type: 'array'` — an {@link arrayShape} whose element shape recurses into
|
|
3818
|
+
* a record-valued `items` (widening to {@link jsonShape} otherwise), with
|
|
3819
|
+
* bounds from `minItems` / `maxItems`.
|
|
3820
|
+
* 6. `type: 'object'`, OR no `type` / `enum` / `oneOf` / `anyOf` but a
|
|
3821
|
+
* record-valued `properties` — delegates to {@link buildObjectShape}.
|
|
3822
|
+
* 7. Everything else — an empty schema, an unrecognized/absent `type`,
|
|
3823
|
+
* exhausted depth/breadth, or an attempt failure — widens to
|
|
3824
|
+
* {@link jsonShape} (the exact inverse of `compileSchema(jsonShape())`,
|
|
3825
|
+
* and where the inferers themselves bottom out at their own limits).
|
|
3826
|
+
*
|
|
3827
|
+
* `format` and `pattern` are NEVER read into the compiled shape — `format` is
|
|
3828
|
+
* annotation-only and `pattern` compiling an attacker-supplied string into a
|
|
3829
|
+
* `RegExp` is a ReDoS vector. `description`, when a string, carries through to
|
|
3830
|
+
* the produced shape's `description` option.
|
|
3831
|
+
*
|
|
3832
|
+
* @param schema - The schema node to convert
|
|
3833
|
+
* @param depth - Remaining descent budget (0 halts recursion with `jsonShape()`)
|
|
3834
|
+
* @param visited - The ancestor set guarding against cycles — recursion
|
|
3835
|
+
* state owned by the {@link schemaToShape} entry point; passing a shared or
|
|
3836
|
+
* pre-populated `WeakSet` changes cycle-detection behavior and is not
|
|
3837
|
+
* supported usage
|
|
3838
|
+
* @param memo - A per-call `(schema node, remaining depth) → shape` cache
|
|
3839
|
+
* guarding against exponential re-conversion of a
|
|
3840
|
+
* shared-reference schema DAG — recursion state owned by the
|
|
3841
|
+
* {@link schemaToShape} entry point; passing a shared or
|
|
3842
|
+
* pre-populated `WeakMap` changes caching behavior and is not
|
|
3843
|
+
* supported usage
|
|
3844
|
+
* @returns The built shape for `schema`
|
|
3845
|
+
*
|
|
3846
|
+
* @example
|
|
3847
|
+
* ```ts
|
|
3848
|
+
* buildShapeFromNode({ type: 'string', minLength: 1 }, INFER_DEPTH_LIMIT, new WeakSet(), new WeakMap())
|
|
3849
|
+
* // stringShape({ min: 1 })
|
|
3850
|
+
* ```
|
|
3851
|
+
*/
|
|
3852
|
+
function buildShapeFromNode(schema, depth, visited, memo) {
|
|
3853
|
+
const description = isString(schema.description) ? schema.description : void 0;
|
|
3854
|
+
if (isArray(schema.enum)) {
|
|
3855
|
+
const literals = schema.enum.filter((entry) => isString(entry) || isFiniteNumber(entry) || isBoolean(entry));
|
|
3856
|
+
if (literals.length > 0) return literalShape(literals, { description });
|
|
3857
|
+
}
|
|
3858
|
+
if (isArray(schema.oneOf)) {
|
|
3859
|
+
const records = schema.oneOf.filter((entry) => isRecord(entry));
|
|
3860
|
+
if (records.length > 256) return jsonShape({ description });
|
|
3861
|
+
const variants = records.map((entry) => schemaNodeToShape(entry, depth - 1, visited, memo));
|
|
3862
|
+
if (variants.length > 0) return oneOfShape(...variants);
|
|
3863
|
+
}
|
|
3864
|
+
if (isArray(schema.anyOf)) {
|
|
3865
|
+
const records = schema.anyOf.filter((entry) => isRecord(entry));
|
|
3866
|
+
if (records.length > 256) return jsonShape({ description });
|
|
3867
|
+
const variants = records.map((entry) => schemaNodeToShape(entry, depth - 1, visited, memo));
|
|
3868
|
+
if (variants.length > 0) return unionShape(...variants);
|
|
3869
|
+
}
|
|
3870
|
+
const type = isString(schema.type) ? schema.type : void 0;
|
|
3871
|
+
if (type === "string") {
|
|
3872
|
+
const bounds = deriveLengthBounds(schema.minLength, schema.maxLength);
|
|
3873
|
+
return stringShape({
|
|
3874
|
+
min: bounds.min,
|
|
3875
|
+
max: bounds.max,
|
|
3876
|
+
description
|
|
3877
|
+
});
|
|
3878
|
+
}
|
|
3879
|
+
if (type === "number") {
|
|
3880
|
+
const bounds = deriveRangeBounds(schema.minimum, schema.maximum);
|
|
3881
|
+
return numberShape({
|
|
3882
|
+
min: bounds.min,
|
|
3883
|
+
max: bounds.max,
|
|
3884
|
+
description
|
|
3885
|
+
});
|
|
3886
|
+
}
|
|
3887
|
+
if (type === "integer") {
|
|
3888
|
+
const bounds = deriveRangeBounds(schema.minimum, schema.maximum);
|
|
3889
|
+
return integerShape(Math.ceil(bounds.min ?? Number.NEGATIVE_INFINITY) > Math.floor(bounds.max ?? Number.POSITIVE_INFINITY) ? { description } : {
|
|
3890
|
+
min: bounds.min,
|
|
3891
|
+
max: bounds.max,
|
|
3892
|
+
description
|
|
3893
|
+
});
|
|
3894
|
+
}
|
|
3895
|
+
if (type === "boolean") return booleanShape({ description });
|
|
3896
|
+
if (type === "null") return nullShape({ description });
|
|
3897
|
+
if (type === "array") {
|
|
3898
|
+
const items = isRecord(schema.items) ? schemaNodeToShape(schema.items, depth - 1, visited, memo) : jsonShape();
|
|
3899
|
+
const bounds = deriveLengthBounds(schema.minItems, schema.maxItems);
|
|
3900
|
+
return arrayShape(items, {
|
|
3901
|
+
min: bounds.min,
|
|
3902
|
+
max: bounds.max,
|
|
3903
|
+
description
|
|
3904
|
+
});
|
|
3905
|
+
}
|
|
3906
|
+
if (type === "object" || type === void 0 && isRecord(schema.properties)) return buildObjectShape(schema, depth, visited, memo, description);
|
|
3907
|
+
return jsonShape({ description });
|
|
3908
|
+
}
|
|
3909
|
+
/**
|
|
3910
|
+
* Convert one JSON Schema node into a {@link ContractShape} — the recursion
|
|
3911
|
+
* entry point {@link schemaToShape} and {@link buildShapeFromNode} share for
|
|
3912
|
+
* every child (`items`, `properties` values, `additionalProperties`,
|
|
3913
|
+
* `oneOf` / `anyOf` variants).
|
|
3914
|
+
*
|
|
3915
|
+
* @remarks
|
|
3916
|
+
* Total: never throws. Guards depth exhaustion, a non-record node (the
|
|
3917
|
+
* node's static `JSONSchema` type is not trusted at runtime), and a cyclic
|
|
3918
|
+
* re-encounter of `schema` — all three widen to {@link jsonShape}. The
|
|
3919
|
+
* ancestor set is added to and removed from around the WHOLE subtree
|
|
3920
|
+
* conversion (not permanently), so a DAG-shaped schema reached twice via two
|
|
3921
|
+
* different, non-cyclic paths does not false-positive as a cycle. The
|
|
3922
|
+
* subtree conversion itself runs inside {@link attempt}, so a hostile
|
|
3923
|
+
* throwing getter/Proxy anywhere in `schema` cannot escape as a thrown error
|
|
3924
|
+
* — it degrades to {@link jsonShape} instead. A same-node re-conversion at
|
|
3925
|
+
* the same remaining `depth` is served from `memo` (guards a
|
|
3926
|
+
* shared-reference schema DAG against exponential blowup), mirroring
|
|
3927
|
+
* {@link inferObject} / {@link inferArray} (inferers.ts).
|
|
3928
|
+
*
|
|
3929
|
+
* @param schema - The schema node to convert
|
|
3930
|
+
* @param depth - Remaining descent budget
|
|
3931
|
+
* @param visited - The ancestor set guarding against cycles — recursion
|
|
3932
|
+
* state owned by the {@link schemaToShape} entry point; passing a shared or
|
|
3933
|
+
* pre-populated `WeakSet` changes cycle-detection behavior and is not
|
|
3934
|
+
* supported usage
|
|
3935
|
+
* @param memo - A per-call `(schema node, remaining depth) → shape` cache —
|
|
3936
|
+
* recursion state owned by the {@link schemaToShape} entry point; passing
|
|
3937
|
+
* a shared or pre-populated `WeakMap` changes caching behavior and is not
|
|
3938
|
+
* supported usage
|
|
3939
|
+
* @returns The built shape for `schema`, or {@link jsonShape} on any failure
|
|
3940
|
+
*
|
|
3941
|
+
* @example
|
|
3942
|
+
* ```ts
|
|
3943
|
+
* schemaNodeToShape({ type: 'boolean' }, INFER_DEPTH_LIMIT, new WeakSet(), new WeakMap())
|
|
3944
|
+
* // booleanShape()
|
|
3945
|
+
* ```
|
|
3946
|
+
*/
|
|
3947
|
+
function schemaNodeToShape(schema, depth, visited, memo) {
|
|
3948
|
+
if (!(depth > 0) || !isRecord(schema) || visited.has(schema)) return jsonShape();
|
|
3949
|
+
const cached = memo.get(schema)?.get(depth);
|
|
3950
|
+
if (cached) return cached;
|
|
3951
|
+
visited.add(schema);
|
|
3952
|
+
const outcome = attempt(() => buildShapeFromNode(schema, depth, visited, memo));
|
|
3953
|
+
visited.delete(schema);
|
|
3954
|
+
const shape = outcome.success ? outcome.value : jsonShape();
|
|
3955
|
+
let depths = memo.get(schema);
|
|
3956
|
+
if (!depths) {
|
|
3957
|
+
depths = /* @__PURE__ */ new Map();
|
|
3958
|
+
memo.set(schema, depths);
|
|
3959
|
+
}
|
|
3960
|
+
depths.set(depth, shape);
|
|
3961
|
+
return shape;
|
|
3962
|
+
}
|
|
3963
|
+
/**
|
|
3964
|
+
* Convert a runtime `JSONSchema` value into a validating {@link ContractShape}
|
|
3965
|
+
* — the inverse of {@link compileSchema}, and the validating sibling of
|
|
3966
|
+
* {@link rawShape} (which embeds a schema fragment WITHOUT validating it).
|
|
3967
|
+
*
|
|
3968
|
+
* @remarks
|
|
3969
|
+
* Total: NEVER throws, for any input — a malformed, cyclic, deeply-nested, or
|
|
3970
|
+
* outright hostile (throwing-getter Proxy) `schema` value all degrade to
|
|
3971
|
+
* {@link jsonShape} rather than escaping as an error, so
|
|
3972
|
+
* `createContract(schemaToShape(x))` is safe to call for any `x`. See
|
|
3973
|
+
* {@link buildShapeFromNode} for the exact per-keyword precedence.
|
|
3974
|
+
*
|
|
3975
|
+
* `format` and `pattern` are NEVER asserted by the compiled shape — `format`
|
|
3976
|
+
* is annotation-only (per the JSON Schema spec, it never narrows validation
|
|
3977
|
+
* on its own) and compiling an attacker-controlled `pattern` string into a
|
|
3978
|
+
* `RegExp` is a ReDoS vector; both keywords are read only far enough to be
|
|
3979
|
+
* ignored. Any node the walk cannot express — an empty `{}`, an
|
|
3980
|
+
* unrecognized `type`, a schema past {@link INFER_DEPTH_LIMIT} deep, or a
|
|
3981
|
+
* cyclic re-encounter — widens to {@link jsonShape} (accept any JSON), never
|
|
3982
|
+
* narrows: the round trip `compileGuard(schemaToShape(valueToSchema(v)))(v)`
|
|
3983
|
+
* holds for every `v`, with widening as the only source of looseness.
|
|
3984
|
+
*
|
|
3985
|
+
* @param schema - The JSON Schema value to convert
|
|
3986
|
+
* @returns The built {@link ContractShape}
|
|
3987
|
+
*
|
|
3988
|
+
* @example
|
|
3989
|
+
* ```ts
|
|
3990
|
+
* const schema = samplesToSchema([{ id: 1, name: 'Ada' }, { id: 2, name: 'Grace' }])
|
|
3991
|
+
* const contract = createContract(schemaToShape(schema))
|
|
3992
|
+
* contract.parse({ id: 3, name: 'Alan' }) // { id: 3, name: 'Alan' }
|
|
3993
|
+
* contract.parse({ id: 'nope' }) // undefined
|
|
3994
|
+
* ```
|
|
3995
|
+
*/
|
|
3996
|
+
function schemaToShape(schema) {
|
|
3997
|
+
return schemaNodeToShape(schema, 32, /* @__PURE__ */ new WeakSet(), /* @__PURE__ */ new WeakMap());
|
|
3998
|
+
}
|
|
3657
3999
|
//#endregion
|
|
3658
|
-
export { FAULT_LIMIT, FORMAT_MAX_LENGTH, FORMAT_PATTERNS, INFER_BREADTH_LIMIT, INFER_DEPTH_LIMIT, INFER_ENUM_LIMIT, JSON_SCHEMA_TYPES, PREVIEW_LIMIT, andOf, arrayOf, arrayShape, attempt, booleanShape, boundsOf, canonicalStringify, compileGenerator, compileGuard, compileParser, compileReporter, compileSchema, complementOf, createContract, enumOf, enumerableSymbolCount, inferArray, inferObject, inferPrimitiveEnum, inferRecordSamples, inferSamples, inferValue, instanceOf, integerShape, intersectionOf, isArray, isArrayBuffer, isArrayBufferView, isAsyncFunction, isAsyncGeneratorFunction, isAsyncIterable, isBigInt, isBigInt64Array, isBigUint64Array, isBoolean, isConstructor, isDataView, isDate, isDefined, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isError, isFalse, isFiniteNumber, isFloat32Array, isFloat64Array, isFunction, isGeneratorFunction, isInstance, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isJSONPrimitive, isJSONValue, isMap, isNonEmptyArray, isNonEmptyMap, isNonEmptyObject, isNonEmptySet, isNonEmptyString, isNull, isNullableBoolean, isNullableNumber, isNullableString, isNumber, isObject, isPromise, isPromiseLike, isRecord, isRegExp, isSet, isSharedArrayBuffer, isString, isSymbol, isTrue, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isValidISOInstant, isWeakMap, isWeakSet, isZeroArg, isZeroArgAsync, isZeroArgAsyncGenerator, isZeroArgGenerator, iterableOf, jsonShape, keyOf, lazyOf, literalOf, literalShape, mapOf, matchOf, notOf, nullShape, nullableOf, nullableShape, numberShape, objectShape, omitOf, oneOfShape, optionalOf, optionalShape, orOf, parseArray, parseArrayField, parseBoolean, parseBooleanField, parseEnum, parseEnumField, parseInteger, parseIntegerField, parseJSON, parseJSONAs, parseJSONValue, parseJSONValueField, parseNull, parseNullField, parseNumber, parseNumberField, parseRecord, parseRecordField, parseString, parseStringField, pickOf, preview, rawShape, recordOf, recordShape, resolveField, samplesToFormat, samplesToSchema, sanitizeBudget, schemaToObject, schemaToParameters, seededRandom, setOf, shapeToKind, stringOf, stringShape, stringToFormat, transformOf, tupleOf, unifySchemas, unionOf, unionShape, validateShape, valueToSchema, whereOf };
|
|
4000
|
+
export { FAULT_LIMIT, FORMAT_MAX_LENGTH, FORMAT_PATTERNS, INFER_BREADTH_LIMIT, INFER_DEPTH_LIMIT, INFER_ENUM_LIMIT, JSON_SCHEMA_TYPES, PREVIEW_LIMIT, andOf, arrayOf, arrayShape, attempt, booleanShape, boundsOf, buildObjectShape, buildShapeFromNode, canonicalStringify, compileGenerator, compileGuard, compileParser, compileReporter, compileSchema, complementOf, createContract, deriveLengthBounds, deriveRangeBounds, enumOf, enumerableSymbolCount, inferArray, inferObject, inferPrimitiveEnum, inferRecordSamples, inferSamples, inferValue, instanceOf, integerShape, intersectionOf, isArray, isArrayBuffer, isArrayBufferView, isAsyncFunction, isAsyncGeneratorFunction, isAsyncIterable, isBigInt, isBigInt64Array, isBigUint64Array, isBoolean, isConstructor, isDataView, isDate, isDefined, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isError, isFalse, isFiniteNumber, isFloat32Array, isFloat64Array, isFunction, isGeneratorFunction, isInstance, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isJSONPrimitive, isJSONValue, isMap, isNonEmptyArray, isNonEmptyMap, isNonEmptyObject, isNonEmptySet, isNonEmptyString, isNull, isNullableBoolean, isNullableNumber, isNullableString, isNumber, isObject, isPromise, isPromiseLike, isRecord, isRegExp, isSet, isSharedArrayBuffer, isString, isSymbol, isTrue, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isValidISOInstant, isWeakMap, isWeakSet, isZeroArg, isZeroArgAsync, isZeroArgAsyncGenerator, isZeroArgGenerator, iterableOf, jsonShape, keyOf, lazyOf, literalOf, literalShape, mapOf, matchOf, notOf, nullShape, nullableOf, nullableShape, numberShape, objectShape, omitOf, oneOfShape, optionalOf, optionalShape, orOf, parseArray, parseArrayField, parseBoolean, parseBooleanField, parseEnum, parseEnumField, parseInteger, parseIntegerField, parseJSON, parseJSONAs, parseJSONValue, parseJSONValueField, parseNull, parseNullField, parseNumber, parseNumberField, parseRecord, parseRecordField, parseString, parseStringField, pickOf, preview, rawShape, recordOf, recordShape, resolveField, samplesToFormat, samplesToSchema, sanitizeBudget, schemaNodeToShape, schemaToObject, schemaToParameters, schemaToShape, seededRandom, setOf, shapeToKind, stringOf, stringShape, stringToFormat, transformOf, tupleOf, unifySchemas, unionOf, unionShape, validateShape, valueToSchema, whereOf };
|
|
3659
4001
|
|
|
3660
4002
|
//# sourceMappingURL=index.js.map
|