@orkestrel/contract 0.0.11 → 0.0.12
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 +101 -28
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +48 -12
- package/dist/src/core/index.d.ts +48 -12
- package/dist/src/core/index.js +100 -29
- package/dist/src/core/index.js.map +1 -1
- package/package.json +9 -8
|
@@ -118,7 +118,7 @@ export declare function arrayOf(elementGuard: (value: unknown) => boolean): Guar
|
|
|
118
118
|
*/
|
|
119
119
|
export declare interface ArrayRead<T = unknown> {
|
|
120
120
|
/** Frozen native entries in index order, retaining sparse positions as holes. */
|
|
121
|
-
readonly entries:
|
|
121
|
+
readonly entries: ReadonlyArray<T | undefined>;
|
|
122
122
|
/** Whether every index from zero through length minus one was reflected. */
|
|
123
123
|
readonly dense: boolean;
|
|
124
124
|
}
|
|
@@ -1890,10 +1890,10 @@ export declare function holds(callback: () => boolean): boolean;
|
|
|
1890
1890
|
export declare type Infer<S extends ContractShape> = [ContractShape] extends [S] ? unknown : S extends StringShape ? string : S extends NumberShape ? number : S extends BooleanShape ? boolean : S extends NullShape ? null : S extends {
|
|
1891
1891
|
readonly type: 'literal';
|
|
1892
1892
|
readonly values: infer V;
|
|
1893
|
-
} ? V extends
|
|
1893
|
+
} ? V extends ReadonlyArray<infer L> ? L : never : S extends {
|
|
1894
1894
|
readonly type: 'array';
|
|
1895
1895
|
readonly items: infer I;
|
|
1896
|
-
} ? I extends ContractShape ?
|
|
1896
|
+
} ? I extends ContractShape ? ReadonlyArray<Infer<I>> : never : S extends ObjectShape<infer P, infer A> ? P extends Readonly<Record<string, ContractShape>> ? [A] extends [boolean | ContractShape] ? InferObject<P, A> : never : never : S extends {
|
|
1897
1897
|
readonly type: 'union';
|
|
1898
1898
|
readonly variants: infer V;
|
|
1899
1899
|
} ? V extends readonly ContractShape[] ? InferUnion<V> : never : S extends {
|
|
@@ -2211,7 +2211,7 @@ export declare function inferPrimitiveEnum(values: readonly unknown[], limit: nu
|
|
|
2211
2211
|
* // required: ['id'], additionalProperties: false }
|
|
2212
2212
|
* ```
|
|
2213
2213
|
*/
|
|
2214
|
-
export declare function inferRecordSamples(samples:
|
|
2214
|
+
export declare function inferRecordSamples(samples: ReadonlyArray<Record<string, unknown>>, depth: number, breadth: number, closed: boolean, format: boolean, enumOn: boolean, memo: SampleMemo): JSONSchema;
|
|
2215
2215
|
|
|
2216
2216
|
/**
|
|
2217
2217
|
* Infer a `JSONSchema` for a collected slot of sample values — the shared
|
|
@@ -2252,7 +2252,7 @@ export declare function inferRecordSamples(samples: readonly Record<string, unkn
|
|
|
2252
2252
|
export declare function inferSamples(samples: readonly unknown[], depth: number, breadth: number, closed: boolean, format: boolean, enumOn: boolean, memo: SampleMemo): JSONSchema;
|
|
2253
2253
|
|
|
2254
2254
|
/** {@link Infer} of a union shape's `variants` — the union of each variant's inferred type. */
|
|
2255
|
-
export declare type InferUnion<V extends readonly ContractShape[]> = V extends
|
|
2255
|
+
export declare type InferUnion<V extends readonly ContractShape[]> = V extends ReadonlyArray<infer U> ? (U extends ContractShape ? Infer<U> : never) : never;
|
|
2256
2256
|
|
|
2257
2257
|
/**
|
|
2258
2258
|
* Infer a `JSONSchema` fragment for one runtime value — the recursive spine
|
|
@@ -3796,9 +3796,9 @@ export declare function limitEntries<T>(entries: readonly T[], limit: number): r
|
|
|
3796
3796
|
* const isSameRole = literalOf(['admin', 'member', 'guest']) // the same guard, from an array
|
|
3797
3797
|
* ```
|
|
3798
3798
|
*/
|
|
3799
|
-
export declare function literalOf<const Literals extends
|
|
3799
|
+
export declare function literalOf<const Literals extends readonly LiteralValue[]>(literals: Literals): Guard<Literals[number]>;
|
|
3800
3800
|
|
|
3801
|
-
export declare function literalOf<const Literals extends
|
|
3801
|
+
export declare function literalOf<const Literals extends readonly LiteralValue[]>(...literals: Literals): Guard<Literals[number]>;
|
|
3802
3802
|
|
|
3803
3803
|
/** A literal shape — accepts exactly one of a fixed set of primitive values. */
|
|
3804
3804
|
export declare interface LiteralShape<T extends readonly LiteralValue[] = readonly LiteralValue[]> {
|
|
@@ -3931,7 +3931,7 @@ export declare function matchesJSONValue(entry: unknown, ancestors: WeakSet<obje
|
|
|
3931
3931
|
* matchesMember(collectMembers([Number.NaN]), Number.NaN) // true — SameValueZero
|
|
3932
3932
|
* ```
|
|
3933
3933
|
*/
|
|
3934
|
-
export declare function matchesMember(members:
|
|
3934
|
+
export declare function matchesMember(members: ReadonlySet<unknown>, value: unknown): boolean;
|
|
3935
3935
|
|
|
3936
3936
|
/**
|
|
3937
3937
|
* Determine whether a string is in the language of a pattern this package owns.
|
|
@@ -4170,6 +4170,14 @@ export declare interface NumberShapeOptions {
|
|
|
4170
4170
|
readonly description?: string;
|
|
4171
4171
|
}
|
|
4172
4172
|
|
|
4173
|
+
export declare function objectOf<S extends GuardsShape>(shape: S): Guard<FromGuards<S>>;
|
|
4174
|
+
|
|
4175
|
+
export declare function objectOf<S extends GuardsShape, K extends ReadonlyArray<keyof S & string>>(shape: S, optional: K): Guard<OptionalFromGuards<S, K>>;
|
|
4176
|
+
|
|
4177
|
+
export declare function objectOf<S extends GuardsShape>(shape: S, optional: true): Guard<Readonly<{
|
|
4178
|
+
[P in keyof S]?: FromGuards<S>[P];
|
|
4179
|
+
}>>;
|
|
4180
|
+
|
|
4173
4181
|
/**
|
|
4174
4182
|
* An object shape — a map of property names to child shapes.
|
|
4175
4183
|
*
|
|
@@ -4740,7 +4748,7 @@ export declare function parseStringField(record: Record<string, unknown>, path:
|
|
|
4740
4748
|
* pathOf(path) // an owned copy
|
|
4741
4749
|
* ```
|
|
4742
4750
|
*/
|
|
4743
|
-
export declare function pathOf(path: readonly string[], ...segments:
|
|
4751
|
+
export declare function pathOf(path: readonly string[], ...segments: ReadonlyArray<string | undefined>): readonly string[];
|
|
4744
4752
|
|
|
4745
4753
|
/**
|
|
4746
4754
|
* Build a new guard shape by keeping only the listed keys — the structural
|
|
@@ -4916,6 +4924,34 @@ export declare function rawShape(schema: JSONSchema): RawShape;
|
|
|
4916
4924
|
*/
|
|
4917
4925
|
export declare function readArrayEntries<T>(value: readonly T[]): Result<ArrayRead<T>>;
|
|
4918
4926
|
|
|
4927
|
+
/**
|
|
4928
|
+
* Snapshot a guard shape and its optional-key mode for a shape combinator.
|
|
4929
|
+
*
|
|
4930
|
+
* @remarks
|
|
4931
|
+
* A null-prototype record plus its own key list is used instead of a `Map`.
|
|
4932
|
+
* The declared-key population decides the guard's answer, and
|
|
4933
|
+
* `Map.prototype.has`, `Map.prototype.get`, and map iteration are three
|
|
4934
|
+
* caller-writable members on that path. An own data key read by index
|
|
4935
|
+
* dispatches through nothing.
|
|
4936
|
+
*
|
|
4937
|
+
* @param shape - The guard shape whose own string declarations to snapshot
|
|
4938
|
+
* @param optional - The optional-key list, `true` for every key, or `undefined`
|
|
4939
|
+
* @param reader - The public combinator name used in read refusals
|
|
4940
|
+
* @returns The owned guards and names plus the collected optional-key membership
|
|
4941
|
+
* @throws {ContractError} When the shape or optional-key list cannot be read
|
|
4942
|
+
*
|
|
4943
|
+
* @example
|
|
4944
|
+
* ```ts
|
|
4945
|
+
* readGuardShape({ id: isString }, undefined, 'recordOf')
|
|
4946
|
+
* ```
|
|
4947
|
+
*/
|
|
4948
|
+
export declare function readGuardShape(shape: GuardsShape, optional: readonly string[] | true | undefined, reader: string): Readonly<{
|
|
4949
|
+
readonly guards: Readonly<Record<string, Guard<unknown> | undefined>>;
|
|
4950
|
+
readonly names: readonly string[];
|
|
4951
|
+
readonly optional: ReadonlySet<unknown>;
|
|
4952
|
+
readonly vocabulary: ReadonlySet<unknown>;
|
|
4953
|
+
}>;
|
|
4954
|
+
|
|
4919
4955
|
/**
|
|
4920
4956
|
* Snapshot the genuine entries of a caller's `Map` without running an iterator.
|
|
4921
4957
|
*
|
|
@@ -4935,7 +4971,7 @@ export declare function readArrayEntries<T>(value: readonly T[]): Result<ArrayRe
|
|
|
4935
4971
|
* readMapEntries(new Map([['a', 1]])) // { success: true, value: [['a', 1]] }
|
|
4936
4972
|
* ```
|
|
4937
4973
|
*/
|
|
4938
|
-
export declare function readMapEntries(value: ReadonlyMap<unknown, unknown>): Result<readonly
|
|
4974
|
+
export declare function readMapEntries(value: ReadonlyMap<unknown, unknown>): Result<ReadonlyArray<readonly unknown[]>>;
|
|
4939
4975
|
|
|
4940
4976
|
/**
|
|
4941
4977
|
* Validate and snapshot a shape-builder options record through every reflective
|
|
@@ -4963,7 +4999,7 @@ export declare function readMapEntries(value: ReadonlyMap<unknown, unknown>): Re
|
|
|
4963
4999
|
* const options = readOptions(source, ['min', 'max'], 'numberShape', 'number')
|
|
4964
5000
|
* ```
|
|
4965
5001
|
*/
|
|
4966
|
-
export declare function readOptions<T extends object>(source: T | undefined, keys:
|
|
5002
|
+
export declare function readOptions<T extends object>(source: T | undefined, keys: ReadonlyArray<keyof T & string>, builder: string, shape: string): T | undefined;
|
|
4967
5003
|
|
|
4968
5004
|
/**
|
|
4969
5005
|
* Rebuild a caller's regular expression as a stateless pattern this package
|
|
@@ -5685,7 +5721,7 @@ export declare type SeederFunction<T> = (random?: RandomFunction) => T;
|
|
|
5685
5721
|
* selectClosestFaults([]) // []
|
|
5686
5722
|
* ```
|
|
5687
5723
|
*/
|
|
5688
|
-
export declare function selectClosestFaults<T extends AuditFault>(reports: readonly
|
|
5724
|
+
export declare function selectClosestFaults<T extends AuditFault>(reports: ReadonlyArray<readonly T[]>): readonly T[];
|
|
5689
5725
|
|
|
5690
5726
|
/**
|
|
5691
5727
|
* Build a guard that accepts `Set` instances whose every element satisfies
|
package/dist/src/core/index.d.ts
CHANGED
|
@@ -118,7 +118,7 @@ export declare function arrayOf(elementGuard: (value: unknown) => boolean): Guar
|
|
|
118
118
|
*/
|
|
119
119
|
export declare interface ArrayRead<T = unknown> {
|
|
120
120
|
/** Frozen native entries in index order, retaining sparse positions as holes. */
|
|
121
|
-
readonly entries:
|
|
121
|
+
readonly entries: ReadonlyArray<T | undefined>;
|
|
122
122
|
/** Whether every index from zero through length minus one was reflected. */
|
|
123
123
|
readonly dense: boolean;
|
|
124
124
|
}
|
|
@@ -1890,10 +1890,10 @@ export declare function holds(callback: () => boolean): boolean;
|
|
|
1890
1890
|
export declare type Infer<S extends ContractShape> = [ContractShape] extends [S] ? unknown : S extends StringShape ? string : S extends NumberShape ? number : S extends BooleanShape ? boolean : S extends NullShape ? null : S extends {
|
|
1891
1891
|
readonly type: 'literal';
|
|
1892
1892
|
readonly values: infer V;
|
|
1893
|
-
} ? V extends
|
|
1893
|
+
} ? V extends ReadonlyArray<infer L> ? L : never : S extends {
|
|
1894
1894
|
readonly type: 'array';
|
|
1895
1895
|
readonly items: infer I;
|
|
1896
|
-
} ? I extends ContractShape ?
|
|
1896
|
+
} ? I extends ContractShape ? ReadonlyArray<Infer<I>> : never : S extends ObjectShape<infer P, infer A> ? P extends Readonly<Record<string, ContractShape>> ? [A] extends [boolean | ContractShape] ? InferObject<P, A> : never : never : S extends {
|
|
1897
1897
|
readonly type: 'union';
|
|
1898
1898
|
readonly variants: infer V;
|
|
1899
1899
|
} ? V extends readonly ContractShape[] ? InferUnion<V> : never : S extends {
|
|
@@ -2211,7 +2211,7 @@ export declare function inferPrimitiveEnum(values: readonly unknown[], limit: nu
|
|
|
2211
2211
|
* // required: ['id'], additionalProperties: false }
|
|
2212
2212
|
* ```
|
|
2213
2213
|
*/
|
|
2214
|
-
export declare function inferRecordSamples(samples:
|
|
2214
|
+
export declare function inferRecordSamples(samples: ReadonlyArray<Record<string, unknown>>, depth: number, breadth: number, closed: boolean, format: boolean, enumOn: boolean, memo: SampleMemo): JSONSchema;
|
|
2215
2215
|
|
|
2216
2216
|
/**
|
|
2217
2217
|
* Infer a `JSONSchema` for a collected slot of sample values — the shared
|
|
@@ -2252,7 +2252,7 @@ export declare function inferRecordSamples(samples: readonly Record<string, unkn
|
|
|
2252
2252
|
export declare function inferSamples(samples: readonly unknown[], depth: number, breadth: number, closed: boolean, format: boolean, enumOn: boolean, memo: SampleMemo): JSONSchema;
|
|
2253
2253
|
|
|
2254
2254
|
/** {@link Infer} of a union shape's `variants` — the union of each variant's inferred type. */
|
|
2255
|
-
export declare type InferUnion<V extends readonly ContractShape[]> = V extends
|
|
2255
|
+
export declare type InferUnion<V extends readonly ContractShape[]> = V extends ReadonlyArray<infer U> ? (U extends ContractShape ? Infer<U> : never) : never;
|
|
2256
2256
|
|
|
2257
2257
|
/**
|
|
2258
2258
|
* Infer a `JSONSchema` fragment for one runtime value — the recursive spine
|
|
@@ -3796,9 +3796,9 @@ export declare function limitEntries<T>(entries: readonly T[], limit: number): r
|
|
|
3796
3796
|
* const isSameRole = literalOf(['admin', 'member', 'guest']) // the same guard, from an array
|
|
3797
3797
|
* ```
|
|
3798
3798
|
*/
|
|
3799
|
-
export declare function literalOf<const Literals extends
|
|
3799
|
+
export declare function literalOf<const Literals extends readonly LiteralValue[]>(literals: Literals): Guard<Literals[number]>;
|
|
3800
3800
|
|
|
3801
|
-
export declare function literalOf<const Literals extends
|
|
3801
|
+
export declare function literalOf<const Literals extends readonly LiteralValue[]>(...literals: Literals): Guard<Literals[number]>;
|
|
3802
3802
|
|
|
3803
3803
|
/** A literal shape — accepts exactly one of a fixed set of primitive values. */
|
|
3804
3804
|
export declare interface LiteralShape<T extends readonly LiteralValue[] = readonly LiteralValue[]> {
|
|
@@ -3931,7 +3931,7 @@ export declare function matchesJSONValue(entry: unknown, ancestors: WeakSet<obje
|
|
|
3931
3931
|
* matchesMember(collectMembers([Number.NaN]), Number.NaN) // true — SameValueZero
|
|
3932
3932
|
* ```
|
|
3933
3933
|
*/
|
|
3934
|
-
export declare function matchesMember(members:
|
|
3934
|
+
export declare function matchesMember(members: ReadonlySet<unknown>, value: unknown): boolean;
|
|
3935
3935
|
|
|
3936
3936
|
/**
|
|
3937
3937
|
* Determine whether a string is in the language of a pattern this package owns.
|
|
@@ -4170,6 +4170,14 @@ export declare interface NumberShapeOptions {
|
|
|
4170
4170
|
readonly description?: string;
|
|
4171
4171
|
}
|
|
4172
4172
|
|
|
4173
|
+
export declare function objectOf<S extends GuardsShape>(shape: S): Guard<FromGuards<S>>;
|
|
4174
|
+
|
|
4175
|
+
export declare function objectOf<S extends GuardsShape, K extends ReadonlyArray<keyof S & string>>(shape: S, optional: K): Guard<OptionalFromGuards<S, K>>;
|
|
4176
|
+
|
|
4177
|
+
export declare function objectOf<S extends GuardsShape>(shape: S, optional: true): Guard<Readonly<{
|
|
4178
|
+
[P in keyof S]?: FromGuards<S>[P];
|
|
4179
|
+
}>>;
|
|
4180
|
+
|
|
4173
4181
|
/**
|
|
4174
4182
|
* An object shape — a map of property names to child shapes.
|
|
4175
4183
|
*
|
|
@@ -4740,7 +4748,7 @@ export declare function parseStringField(record: Record<string, unknown>, path:
|
|
|
4740
4748
|
* pathOf(path) // an owned copy
|
|
4741
4749
|
* ```
|
|
4742
4750
|
*/
|
|
4743
|
-
export declare function pathOf(path: readonly string[], ...segments:
|
|
4751
|
+
export declare function pathOf(path: readonly string[], ...segments: ReadonlyArray<string | undefined>): readonly string[];
|
|
4744
4752
|
|
|
4745
4753
|
/**
|
|
4746
4754
|
* Build a new guard shape by keeping only the listed keys — the structural
|
|
@@ -4916,6 +4924,34 @@ export declare function rawShape(schema: JSONSchema): RawShape;
|
|
|
4916
4924
|
*/
|
|
4917
4925
|
export declare function readArrayEntries<T>(value: readonly T[]): Result<ArrayRead<T>>;
|
|
4918
4926
|
|
|
4927
|
+
/**
|
|
4928
|
+
* Snapshot a guard shape and its optional-key mode for a shape combinator.
|
|
4929
|
+
*
|
|
4930
|
+
* @remarks
|
|
4931
|
+
* A null-prototype record plus its own key list is used instead of a `Map`.
|
|
4932
|
+
* The declared-key population decides the guard's answer, and
|
|
4933
|
+
* `Map.prototype.has`, `Map.prototype.get`, and map iteration are three
|
|
4934
|
+
* caller-writable members on that path. An own data key read by index
|
|
4935
|
+
* dispatches through nothing.
|
|
4936
|
+
*
|
|
4937
|
+
* @param shape - The guard shape whose own string declarations to snapshot
|
|
4938
|
+
* @param optional - The optional-key list, `true` for every key, or `undefined`
|
|
4939
|
+
* @param reader - The public combinator name used in read refusals
|
|
4940
|
+
* @returns The owned guards and names plus the collected optional-key membership
|
|
4941
|
+
* @throws {ContractError} When the shape or optional-key list cannot be read
|
|
4942
|
+
*
|
|
4943
|
+
* @example
|
|
4944
|
+
* ```ts
|
|
4945
|
+
* readGuardShape({ id: isString }, undefined, 'recordOf')
|
|
4946
|
+
* ```
|
|
4947
|
+
*/
|
|
4948
|
+
export declare function readGuardShape(shape: GuardsShape, optional: readonly string[] | true | undefined, reader: string): Readonly<{
|
|
4949
|
+
readonly guards: Readonly<Record<string, Guard<unknown> | undefined>>;
|
|
4950
|
+
readonly names: readonly string[];
|
|
4951
|
+
readonly optional: ReadonlySet<unknown>;
|
|
4952
|
+
readonly vocabulary: ReadonlySet<unknown>;
|
|
4953
|
+
}>;
|
|
4954
|
+
|
|
4919
4955
|
/**
|
|
4920
4956
|
* Snapshot the genuine entries of a caller's `Map` without running an iterator.
|
|
4921
4957
|
*
|
|
@@ -4935,7 +4971,7 @@ export declare function readArrayEntries<T>(value: readonly T[]): Result<ArrayRe
|
|
|
4935
4971
|
* readMapEntries(new Map([['a', 1]])) // { success: true, value: [['a', 1]] }
|
|
4936
4972
|
* ```
|
|
4937
4973
|
*/
|
|
4938
|
-
export declare function readMapEntries(value: ReadonlyMap<unknown, unknown>): Result<readonly
|
|
4974
|
+
export declare function readMapEntries(value: ReadonlyMap<unknown, unknown>): Result<ReadonlyArray<readonly unknown[]>>;
|
|
4939
4975
|
|
|
4940
4976
|
/**
|
|
4941
4977
|
* Validate and snapshot a shape-builder options record through every reflective
|
|
@@ -4963,7 +4999,7 @@ export declare function readMapEntries(value: ReadonlyMap<unknown, unknown>): Re
|
|
|
4963
4999
|
* const options = readOptions(source, ['min', 'max'], 'numberShape', 'number')
|
|
4964
5000
|
* ```
|
|
4965
5001
|
*/
|
|
4966
|
-
export declare function readOptions<T extends object>(source: T | undefined, keys:
|
|
5002
|
+
export declare function readOptions<T extends object>(source: T | undefined, keys: ReadonlyArray<keyof T & string>, builder: string, shape: string): T | undefined;
|
|
4967
5003
|
|
|
4968
5004
|
/**
|
|
4969
5005
|
* Rebuild a caller's regular expression as a stateless pattern this package
|
|
@@ -5685,7 +5721,7 @@ export declare type SeederFunction<T> = (random?: RandomFunction) => T;
|
|
|
5685
5721
|
* selectClosestFaults([]) // []
|
|
5686
5722
|
* ```
|
|
5687
5723
|
*/
|
|
5688
|
-
export declare function selectClosestFaults<T extends AuditFault>(reports: readonly
|
|
5724
|
+
export declare function selectClosestFaults<T extends AuditFault>(reports: ReadonlyArray<readonly T[]>): readonly T[];
|
|
5689
5725
|
|
|
5690
5726
|
/**
|
|
5691
5727
|
* Build a guard that accepts `Set` instances whose every element satisfies
|
package/dist/src/core/index.js
CHANGED
|
@@ -2477,6 +2477,61 @@ function readArrayEntries(value) {
|
|
|
2477
2477
|
});
|
|
2478
2478
|
}
|
|
2479
2479
|
/**
|
|
2480
|
+
* Snapshot a guard shape and its optional-key mode for a shape combinator.
|
|
2481
|
+
*
|
|
2482
|
+
* @remarks
|
|
2483
|
+
* A null-prototype record plus its own key list is used instead of a `Map`.
|
|
2484
|
+
* The declared-key population decides the guard's answer, and
|
|
2485
|
+
* `Map.prototype.has`, `Map.prototype.get`, and map iteration are three
|
|
2486
|
+
* caller-writable members on that path. An own data key read by index
|
|
2487
|
+
* dispatches through nothing.
|
|
2488
|
+
*
|
|
2489
|
+
* @param shape - The guard shape whose own string declarations to snapshot
|
|
2490
|
+
* @param optional - The optional-key list, `true` for every key, or `undefined`
|
|
2491
|
+
* @param reader - The public combinator name used in read refusals
|
|
2492
|
+
* @returns The owned guards and names plus the collected optional-key membership
|
|
2493
|
+
* @throws {ContractError} When the shape or optional-key list cannot be read
|
|
2494
|
+
*
|
|
2495
|
+
* @example
|
|
2496
|
+
* ```ts
|
|
2497
|
+
* readGuardShape({ id: isString }, undefined, 'recordOf')
|
|
2498
|
+
* ```
|
|
2499
|
+
*/
|
|
2500
|
+
function readGuardShape(shape, optional, reader) {
|
|
2501
|
+
const declared = readValue(() => {
|
|
2502
|
+
const members = INTRINSICS.members(shape);
|
|
2503
|
+
const guards = INTRINSICS.create(null);
|
|
2504
|
+
const names = [];
|
|
2505
|
+
for (let index = 0; index < members.length; index += 1) {
|
|
2506
|
+
const key = members[index];
|
|
2507
|
+
if (!isString(key)) continue;
|
|
2508
|
+
if (!INTRINSICS.own(guards, key)) names[names.length] = key;
|
|
2509
|
+
guards[key] = shape[key];
|
|
2510
|
+
}
|
|
2511
|
+
return {
|
|
2512
|
+
guards,
|
|
2513
|
+
names,
|
|
2514
|
+
vocabulary: collectMembers(names)
|
|
2515
|
+
};
|
|
2516
|
+
}, reader, { subject: "shape" });
|
|
2517
|
+
const optionalKeys = readValue(() => {
|
|
2518
|
+
if (optional === true) return collectMembers(declared.names);
|
|
2519
|
+
if (!INTRINSICS.array(optional)) return collectMembers([]);
|
|
2520
|
+
const entries = readArrayEntries(optional);
|
|
2521
|
+
if (!entries.success) throw entries.error;
|
|
2522
|
+
if (!entries.value.dense) throw new INTRINSICS.error("Optional key list must be dense");
|
|
2523
|
+
const keys = collectMembers([]);
|
|
2524
|
+
for (let index = 0; index < entries.value.entries.length; index += 1) admitMember(keys, INTRINSICS.text(entries.value.entries[index]));
|
|
2525
|
+
return keys;
|
|
2526
|
+
}, reader, { subject: "optional" });
|
|
2527
|
+
return {
|
|
2528
|
+
guards: declared.guards,
|
|
2529
|
+
names: declared.names,
|
|
2530
|
+
optional: optionalKeys,
|
|
2531
|
+
vocabulary: declared.vocabulary
|
|
2532
|
+
};
|
|
2533
|
+
}
|
|
2534
|
+
/**
|
|
2480
2535
|
* Snapshot an object's own enumerable string keys through a total boundary.
|
|
2481
2536
|
*
|
|
2482
2537
|
* @remarks
|
|
@@ -5703,32 +5758,7 @@ function mapOf(keyGuard, valueGuard) {
|
|
|
5703
5758
|
*/
|
|
5704
5759
|
function recordOf(shape, optional) {
|
|
5705
5760
|
return contain(() => {
|
|
5706
|
-
const declared =
|
|
5707
|
-
const members = INTRINSICS.members(shape);
|
|
5708
|
-
const collected = INTRINSICS.create(null);
|
|
5709
|
-
const names = [];
|
|
5710
|
-
for (let index = 0; index < members.length; index += 1) {
|
|
5711
|
-
const key = members[index];
|
|
5712
|
-
if (!isString(key)) continue;
|
|
5713
|
-
if (!INTRINSICS.own(collected, key)) names[names.length] = key;
|
|
5714
|
-
collected[key] = shape[key];
|
|
5715
|
-
}
|
|
5716
|
-
return {
|
|
5717
|
-
collected,
|
|
5718
|
-
names,
|
|
5719
|
-
vocabulary: collectMembers(names)
|
|
5720
|
-
};
|
|
5721
|
-
}, "recordOf", { subject: "shape" });
|
|
5722
|
-
const optionalKeys = readValue(() => {
|
|
5723
|
-
if (optional === true) return collectMembers(declared.names);
|
|
5724
|
-
if (!INTRINSICS.array(optional)) return collectMembers([]);
|
|
5725
|
-
const entries = readArrayEntries(optional);
|
|
5726
|
-
if (!entries.success) throw entries.error;
|
|
5727
|
-
if (!entries.value.dense) throw new INTRINSICS.error("Optional key list must be dense");
|
|
5728
|
-
const keys = collectMembers([]);
|
|
5729
|
-
for (let index = 0; index < entries.value.entries.length; index += 1) admitMember(keys, INTRINSICS.text(entries.value.entries[index]));
|
|
5730
|
-
return keys;
|
|
5731
|
-
}, "recordOf", { subject: "optional" });
|
|
5761
|
+
const declared = readGuardShape(shape, optional, "recordOf");
|
|
5732
5762
|
return (value) => holds(() => {
|
|
5733
5763
|
if (!isRecord(value)) return false;
|
|
5734
5764
|
const members = INTRINSICS.members(value);
|
|
@@ -5739,9 +5769,9 @@ function recordOf(shape, optional) {
|
|
|
5739
5769
|
for (let index = 0; index < declared.names.length; index += 1) {
|
|
5740
5770
|
const key = declared.names[index];
|
|
5741
5771
|
if (key === void 0) continue;
|
|
5742
|
-
const guard = declared.
|
|
5772
|
+
const guard = declared.guards[key];
|
|
5743
5773
|
const present = INTRINSICS.own(value, key);
|
|
5744
|
-
if (!matchesMember(
|
|
5774
|
+
if (!matchesMember(declared.optional, key) && !present) return false;
|
|
5745
5775
|
if (present) {
|
|
5746
5776
|
if (guard === void 0 || !guard(value[key])) return false;
|
|
5747
5777
|
}
|
|
@@ -5751,6 +5781,47 @@ function recordOf(shape, optional) {
|
|
|
5751
5781
|
}, "recordOf");
|
|
5752
5782
|
}
|
|
5753
5783
|
/**
|
|
5784
|
+
* Build a guard that accepts non-array objects matching an open guard shape.
|
|
5785
|
+
*
|
|
5786
|
+
* @remarks
|
|
5787
|
+
* Three calling modes mirror {@link recordOf}:
|
|
5788
|
+
* - **No `optional`** — all shape keys required; unknown members admitted.
|
|
5789
|
+
* - **`optional: K[]`** — the listed keys are optional; all others required.
|
|
5790
|
+
* - **`optional: true`** — every shape key is optional.
|
|
5791
|
+
*
|
|
5792
|
+
* Each declared member is read through `Reflect.get`, so inherited data and
|
|
5793
|
+
* prototype accessors can satisfy the shape. An optional member passes when its
|
|
5794
|
+
* read value is `undefined`; otherwise its guard must accept the value. Unknown
|
|
5795
|
+
* members are never enumerated or inspected. Member-carrying functions are
|
|
5796
|
+
* accepted. Arrays, `null`, and primitives are rejected. Hostile reads return
|
|
5797
|
+
* `false` rather than throwing.
|
|
5798
|
+
*
|
|
5799
|
+
* @example
|
|
5800
|
+
* ```ts
|
|
5801
|
+
* const isResult = objectOf({ conclusion: isBoolean })
|
|
5802
|
+
* isResult({ conclusion: true, metadata: 'retained' }) // true
|
|
5803
|
+
* isResult([]) // false
|
|
5804
|
+
* ```
|
|
5805
|
+
*/
|
|
5806
|
+
function objectOf(shape, optional) {
|
|
5807
|
+
return contain(() => {
|
|
5808
|
+
const declared = readGuardShape(shape, optional, "objectOf");
|
|
5809
|
+
return (value) => holds(() => {
|
|
5810
|
+
if (!isObject(value) && !isFunction(value) || INTRINSICS.array(value)) return false;
|
|
5811
|
+
for (let index = 0; index < declared.names.length; index += 1) {
|
|
5812
|
+
const key = declared.names[index];
|
|
5813
|
+
if (key === void 0) continue;
|
|
5814
|
+
const guard = declared.guards[key];
|
|
5815
|
+
const member = INTRINSICS.read(value, key);
|
|
5816
|
+
if (matchesMember(declared.optional, key)) {
|
|
5817
|
+
if (member !== void 0 && (guard === void 0 || !guard(member))) return false;
|
|
5818
|
+
} else if (guard === void 0 || !guard(member)) return false;
|
|
5819
|
+
}
|
|
5820
|
+
return true;
|
|
5821
|
+
});
|
|
5822
|
+
}, "objectOf");
|
|
5823
|
+
}
|
|
5824
|
+
/**
|
|
5754
5825
|
* Build a guard that accepts values that are own keys of the provided object.
|
|
5755
5826
|
*
|
|
5756
5827
|
* @remarks
|
|
@@ -10341,6 +10412,6 @@ function schemaToShape(schema) {
|
|
|
10341
10412
|
}, "schemaToShape");
|
|
10342
10413
|
}
|
|
10343
10414
|
//#endregion
|
|
10344
|
-
export { CLONE_NODE_LIMIT, COMPILE_DEPTH_LIMIT, COMPILE_NODE_LIMIT, ContractCompiler, ContractError, FAULT_LIMIT, FORMAT_MAX_LENGTH, FORMAT_PATTERNS, GENERATION_ATTEMPT_LIMIT, GUARD_DEPTH_LIMIT, INFER_BREADTH_LIMIT, INFER_DEPTH_LIMIT, INFER_ENUM_LIMIT, INTRINSICS, JSONCloner, JSON_SCHEMA_TYPES, PREVIEW_LIMIT, SchemaCloner, ShapeCloner, ShapeValidator, admitMember, admitVisited, andOf, appendEntries, arrayOf, arrayShape, attempt, booleanShape, boundsOf, buildObjectShape, buildSampleMemo, buildShapeFromNode, canonicalStringify, canonicalizeValue, classifyFormat, cloneJSONRecord, cloneJSONValue, cloneSchema, cloneShape, collectEntries, collectMembers, compareValues, compileAuditor, compileGenerator, compileGuard, compileParser, compileReporter, compileSchema, complementOf, contain, createArrayFaults, createContract, createNumberFaults, createStringFaults, deriveLengthBounds, deriveRangeBounds, drawRandom, encodeLeaf, enumOf, enumerableKeys, enumerableSymbolCount, holds, inferArray, inferObject, inferPrimitiveEnum, inferRecordSamples, inferSamples, inferValue, instanceOf, integerShape, intersectionOf, isArray, isArrayBuffer, isArrayBufferView, isAsyncFunction, isAsyncGeneratorFunction, isAsyncIterable, isBigInt, isBigInt64Array, isBigUint64Array, isBoolean, isBoundedJSONRecord, isBoundedJSONValue, isConstructor, isContractError, isDataView, isDate, isDefined, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isError, isFalse, isFiniteNumber, isFloat32Array, isFloat64Array, isFunction, isGeneratorFunction, isInstance, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isJSONPrimitive, isJSONValue, isLiteralValue, isMap, isNonEmptyArray, isNonEmptyMap, isNonEmptyObject, isNonEmptySet, isNonEmptyString, isNonNegativeInteger, isNonNegativeNumber, 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, jsonShape, keyOf, lazyOf, limitEntries, literalOf, literalShape, mapOf, matchOf, matchesJSONDepth, matchesJSONValue, matchesMember, matchesPattern, matchesRecordBrand, matchesVisited, notOf, nullShape, nullableOf, nullableShape, numberShape, objectShape, omitOf, omitVisited, oneOfShape, optionalOf, optionalShape, orOf, ownShape, parseArray, parseArrayField, parseBoolean, parseBooleanField, parseEnum, parseEnumField, parseInteger, parseIntegerField, parseJSON, parseJSONAs, parseJSONValue, parseJSONValueField, parseNull, parseNullField, parseNumber, parseNumberField, parseRecord, parseRecordField, parseString, parseStringField, pathOf, pickOf, pinMembers, preview, rawShape, readArrayEntries, readMapEntries, readOptions, readPattern, readPatternFlags, readPatternSource, readSampleMemo, readSetEntries, readValue, recordOf, recordShape, refuseExpansion, resolveField, retainDepth, samplesToFormat, samplesToSchema, sanitizeBudget, sanitizeDepth, schemaNodeToShape, schemaToObject, schemaToParameters, schemaToShape, seededRandom, selectClosestFaults, setOf, shapeToKind, sortValues, stringOf, stringShape, stringToFormat, transformOf, tupleOf, unifySchemas, unionOf, unionShape, validateShapeDepth, valueToSchema, whereOf };
|
|
10415
|
+
export { CLONE_NODE_LIMIT, COMPILE_DEPTH_LIMIT, COMPILE_NODE_LIMIT, ContractCompiler, ContractError, FAULT_LIMIT, FORMAT_MAX_LENGTH, FORMAT_PATTERNS, GENERATION_ATTEMPT_LIMIT, GUARD_DEPTH_LIMIT, INFER_BREADTH_LIMIT, INFER_DEPTH_LIMIT, INFER_ENUM_LIMIT, INTRINSICS, JSONCloner, JSON_SCHEMA_TYPES, PREVIEW_LIMIT, SchemaCloner, ShapeCloner, ShapeValidator, admitMember, admitVisited, andOf, appendEntries, arrayOf, arrayShape, attempt, booleanShape, boundsOf, buildObjectShape, buildSampleMemo, buildShapeFromNode, canonicalStringify, canonicalizeValue, classifyFormat, cloneJSONRecord, cloneJSONValue, cloneSchema, cloneShape, collectEntries, collectMembers, compareValues, compileAuditor, compileGenerator, compileGuard, compileParser, compileReporter, compileSchema, complementOf, contain, createArrayFaults, createContract, createNumberFaults, createStringFaults, deriveLengthBounds, deriveRangeBounds, drawRandom, encodeLeaf, enumOf, enumerableKeys, enumerableSymbolCount, holds, inferArray, inferObject, inferPrimitiveEnum, inferRecordSamples, inferSamples, inferValue, instanceOf, integerShape, intersectionOf, isArray, isArrayBuffer, isArrayBufferView, isAsyncFunction, isAsyncGeneratorFunction, isAsyncIterable, isBigInt, isBigInt64Array, isBigUint64Array, isBoolean, isBoundedJSONRecord, isBoundedJSONValue, isConstructor, isContractError, isDataView, isDate, isDefined, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isError, isFalse, isFiniteNumber, isFloat32Array, isFloat64Array, isFunction, isGeneratorFunction, isInstance, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isJSONPrimitive, isJSONValue, isLiteralValue, isMap, isNonEmptyArray, isNonEmptyMap, isNonEmptyObject, isNonEmptySet, isNonEmptyString, isNonNegativeInteger, isNonNegativeNumber, 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, jsonShape, keyOf, lazyOf, limitEntries, literalOf, literalShape, mapOf, matchOf, matchesJSONDepth, matchesJSONValue, matchesMember, matchesPattern, matchesRecordBrand, matchesVisited, notOf, nullShape, nullableOf, nullableShape, numberShape, objectOf, objectShape, omitOf, omitVisited, oneOfShape, optionalOf, optionalShape, orOf, ownShape, parseArray, parseArrayField, parseBoolean, parseBooleanField, parseEnum, parseEnumField, parseInteger, parseIntegerField, parseJSON, parseJSONAs, parseJSONValue, parseJSONValueField, parseNull, parseNullField, parseNumber, parseNumberField, parseRecord, parseRecordField, parseString, parseStringField, pathOf, pickOf, pinMembers, preview, rawShape, readArrayEntries, readGuardShape, readMapEntries, readOptions, readPattern, readPatternFlags, readPatternSource, readSampleMemo, readSetEntries, readValue, recordOf, recordShape, refuseExpansion, resolveField, retainDepth, samplesToFormat, samplesToSchema, sanitizeBudget, sanitizeDepth, schemaNodeToShape, schemaToObject, schemaToParameters, schemaToShape, seededRandom, selectClosestFaults, setOf, shapeToKind, sortValues, stringOf, stringShape, stringToFormat, transformOf, tupleOf, unifySchemas, unionOf, unionShape, validateShapeDepth, valueToSchema, whereOf };
|
|
10345
10416
|
|
|
10346
10417
|
//# sourceMappingURL=index.js.map
|