@ts-runtypes/core 0.9.3 → 0.11.0
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/README.md +31 -0
- package/dist/cjs/createRTFBinary.d.ts +10 -10
- package/dist/cjs/createRTFBinary.js +13 -13
- package/dist/cjs/createRTFunctions.d.ts +16 -15
- package/dist/cjs/createRTFunctions.js +16 -20
- package/dist/cjs/enrich/createFriendlyText.js +19 -0
- package/dist/cjs/fnHash.d.ts +4 -1
- package/dist/cjs/fnHash.js +27 -1
- package/dist/cjs/formats/datetime/dateTime-pure-fns.js +313 -313
- package/dist/cjs/formats/string/string-formats-pure-fns.js +118 -118
- package/dist/cjs/{fnHashes.generated.d.ts → go-generated/fnHashes.generated.d.ts} +78 -16
- package/dist/cjs/go-generated/fnHashes.generated.js +117 -0
- package/dist/cjs/go-generated/typeFormats.generated.d.ts +80 -0
- package/dist/cjs/go-generated/typeFormats.generated.js +24 -0
- package/dist/cjs/index.d.ts +12 -8
- package/dist/cjs/index.js +29 -21
- package/dist/cjs/markers.d.ts +6 -0
- package/dist/cjs/mocking/binarySize.d.ts +2 -1
- package/dist/cjs/mocking/binarySize.js +2 -2
- package/dist/cjs/mocking/constants.mock.js +1 -0
- package/dist/cjs/mocking/createMockData.d.ts +2 -2
- package/dist/cjs/mocking/createMockData.js +6 -4
- package/dist/cjs/mocking/mockBigIntFormat.js +7 -9
- package/dist/cjs/mocking/mockDateTimeBounds.d.ts +5 -4
- package/dist/cjs/mocking/mockDateTimeBounds.js +23 -23
- package/dist/cjs/mocking/mockInvalid.d.ts +2 -1
- package/dist/cjs/mocking/mockInvalid.js +10 -8
- package/dist/cjs/mocking/mockNumberFormat.js +8 -10
- package/dist/cjs/mocking/mockOversized.js +14 -11
- package/dist/cjs/mocking/mockRandom.d.ts +20 -0
- package/dist/cjs/mocking/mockRandom.js +106 -0
- package/dist/cjs/mocking/mockRegistry.d.ts +3 -2
- package/dist/cjs/mocking/mockStringFormat.d.ts +2 -1
- package/dist/cjs/mocking/mockStringFormat.js +58 -84
- package/dist/cjs/mocking/mockTemporal.d.ts +2 -1
- package/dist/cjs/mocking/mockTemporal.js +62 -63
- package/dist/cjs/mocking/mockType.js +92 -88
- package/dist/cjs/mocking/mockTypes.d.ts +3 -0
- package/dist/cjs/overrideRTFunctions.d.ts +2 -3
- package/dist/cjs/overrideRTFunctions.js +2 -3
- package/dist/cjs/runtypes/circular-pure-fns.d.ts +10 -0
- package/dist/cjs/runtypes/circular-pure-fns.js +115 -0
- package/dist/cjs/runtypes/circular.d.ts +0 -5
- package/dist/cjs/runtypes/circular.js +0 -256
- package/dist/cjs/runtypes/entryTuple.d.ts +7 -2
- package/dist/cjs/runtypes/entryTuple.js +7 -48
- package/dist/cjs/runtypes/pure-fns-utils.d.ts +1 -3
- package/dist/cjs/runtypes/pure-fns-utils.js +53 -77
- package/dist/cjs/runtypes/pureFn.d.ts +6 -3
- package/dist/cjs/runtypes/pureFn.js +64 -12
- package/dist/cjs/runtypes/rtUtils.d.ts +7 -1
- package/dist/cjs/runtypes/rtUtils.js +24 -1
- package/dist/cjs/runtypes/types.d.ts +5 -6
- package/dist/cjs/standard/createStandardSchema.js +2 -6
- package/dist/createRTFBinary.d.ts +10 -10
- package/dist/createRTFBinary.d.ts.map +1 -1
- package/dist/createRTFBinary.js +10 -10
- package/dist/createRTFBinary.js.map +1 -1
- package/dist/createRTFunctions.d.ts +16 -15
- package/dist/createRTFunctions.d.ts.map +1 -1
- package/dist/createRTFunctions.js +13 -17
- package/dist/createRTFunctions.js.map +1 -1
- package/dist/enrich/createFriendlyText.d.ts.map +1 -1
- package/dist/enrich/createFriendlyText.js +19 -0
- package/dist/enrich/createFriendlyText.js.map +1 -1
- package/dist/fnHash.d.ts +4 -1
- package/dist/fnHash.d.ts.map +1 -1
- package/dist/fnHash.js +27 -1
- package/dist/fnHash.js.map +1 -1
- package/dist/formats/datetime/dateTime-pure-fns.js +313 -313
- package/dist/formats/string/string-formats-pure-fns.js +118 -118
- package/dist/{fnHashes.generated.d.ts → go-generated/fnHashes.generated.d.ts} +78 -16
- package/dist/go-generated/fnHashes.generated.d.ts.map +1 -0
- package/dist/go-generated/fnHashes.generated.js +115 -0
- package/dist/go-generated/fnHashes.generated.js.map +1 -0
- package/dist/{runTypeKind.d.ts → go-generated/runTypeKind.generated.d.ts} +1 -1
- package/dist/go-generated/runTypeKind.generated.d.ts.map +1 -0
- package/dist/{runTypeKind.js → go-generated/runTypeKind.generated.js} +1 -1
- package/dist/go-generated/runTypeKind.generated.js.map +1 -0
- package/dist/go-generated/typeFormats.generated.d.ts +81 -0
- package/dist/go-generated/typeFormats.generated.d.ts.map +1 -0
- package/dist/go-generated/typeFormats.generated.js +22 -0
- package/dist/go-generated/typeFormats.generated.js.map +1 -0
- package/dist/index.d.ts +12 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -7
- package/dist/index.js.map +1 -1
- package/dist/markers.d.ts +6 -0
- package/dist/markers.d.ts.map +1 -1
- package/dist/mocking/binarySize.d.ts +2 -1
- package/dist/mocking/binarySize.d.ts.map +1 -1
- package/dist/mocking/binarySize.js +2 -2
- package/dist/mocking/binarySize.js.map +1 -1
- package/dist/mocking/constants.mock.d.ts.map +1 -1
- package/dist/mocking/constants.mock.js +1 -0
- package/dist/mocking/constants.mock.js.map +1 -1
- package/dist/mocking/createMockData.d.ts +2 -2
- package/dist/mocking/createMockData.d.ts.map +1 -1
- package/dist/mocking/createMockData.js +5 -3
- package/dist/mocking/createMockData.js.map +1 -1
- package/dist/mocking/mockBigIntFormat.js +6 -8
- package/dist/mocking/mockBigIntFormat.js.map +1 -1
- package/dist/mocking/mockDateTimeBounds.d.ts +5 -4
- package/dist/mocking/mockDateTimeBounds.d.ts.map +1 -1
- package/dist/mocking/mockDateTimeBounds.js +23 -23
- package/dist/mocking/mockDateTimeBounds.js.map +1 -1
- package/dist/mocking/mockInvalid.d.ts +2 -1
- package/dist/mocking/mockInvalid.d.ts.map +1 -1
- package/dist/mocking/mockInvalid.js +9 -7
- package/dist/mocking/mockInvalid.js.map +1 -1
- package/dist/mocking/mockNumberFormat.js +7 -9
- package/dist/mocking/mockNumberFormat.js.map +1 -1
- package/dist/mocking/mockOversized.d.ts.map +1 -1
- package/dist/mocking/mockOversized.js +13 -10
- package/dist/mocking/mockOversized.js.map +1 -1
- package/dist/mocking/mockRandom.d.ts +21 -0
- package/dist/mocking/mockRandom.d.ts.map +1 -0
- package/dist/mocking/mockRandom.js +102 -0
- package/dist/mocking/mockRandom.js.map +1 -0
- package/dist/mocking/mockRegistry.d.ts +3 -2
- package/dist/mocking/mockRegistry.d.ts.map +1 -1
- package/dist/mocking/mockRegistry.js.map +1 -1
- package/dist/mocking/mockStringFormat.d.ts +2 -1
- package/dist/mocking/mockStringFormat.d.ts.map +1 -1
- package/dist/mocking/mockStringFormat.js +57 -83
- package/dist/mocking/mockStringFormat.js.map +1 -1
- package/dist/mocking/mockTemporal.d.ts +2 -1
- package/dist/mocking/mockTemporal.d.ts.map +1 -1
- package/dist/mocking/mockTemporal.js +47 -48
- package/dist/mocking/mockTemporal.js.map +1 -1
- package/dist/mocking/mockType.d.ts.map +1 -1
- package/dist/mocking/mockType.js +40 -36
- package/dist/mocking/mockType.js.map +1 -1
- package/dist/mocking/mockTypes.d.ts +3 -0
- package/dist/mocking/mockTypes.d.ts.map +1 -1
- package/dist/overrideRTFunctions.d.ts +2 -3
- package/dist/overrideRTFunctions.d.ts.map +1 -1
- package/dist/overrideRTFunctions.js +1 -2
- package/dist/overrideRTFunctions.js.map +1 -1
- package/dist/runtypes/circular-pure-fns.d.ts +11 -0
- package/dist/runtypes/circular-pure-fns.d.ts.map +1 -0
- package/dist/runtypes/circular-pure-fns.js +114 -0
- package/dist/runtypes/circular-pure-fns.js.map +1 -0
- package/dist/runtypes/circular.d.ts +0 -5
- package/dist/runtypes/circular.d.ts.map +1 -1
- package/dist/runtypes/circular.js +0 -252
- package/dist/runtypes/circular.js.map +1 -1
- package/dist/runtypes/entryTuple.d.ts +7 -2
- package/dist/runtypes/entryTuple.d.ts.map +1 -1
- package/dist/runtypes/entryTuple.js +7 -48
- package/dist/runtypes/entryTuple.js.map +1 -1
- package/dist/runtypes/pure-fns-utils.d.ts +1 -3
- package/dist/runtypes/pure-fns-utils.d.ts.map +1 -1
- package/dist/runtypes/pure-fns-utils.js +52 -76
- package/dist/runtypes/pure-fns-utils.js.map +1 -1
- package/dist/runtypes/pureFn.d.ts +6 -3
- package/dist/runtypes/pureFn.d.ts.map +1 -1
- package/dist/runtypes/pureFn.js +61 -12
- package/dist/runtypes/pureFn.js.map +1 -1
- package/dist/runtypes/rtUtils.d.ts +7 -1
- package/dist/runtypes/rtUtils.d.ts.map +1 -1
- package/dist/runtypes/rtUtils.js +23 -1
- package/dist/runtypes/rtUtils.js.map +1 -1
- package/dist/runtypes/types.d.ts +5 -6
- package/dist/runtypes/types.d.ts.map +1 -1
- package/dist/standard/createStandardSchema.d.ts.map +1 -1
- package/dist/standard/createStandardSchema.js +2 -6
- package/dist/standard/createStandardSchema.js.map +1 -1
- package/package.json +3 -3
- package/skills/rt-enrich-types/SKILL.md +59 -43
- package/skills/runtypes-friendly-type/SKILL.md +48 -46
- package/skills/runtypes-mock-data/SKILL.md +25 -25
- package/src/createRTFBinary.ts +50 -43
- package/src/createRTFunctions.ts +121 -94
- package/src/enrich/createFriendlyText.ts +30 -1
- package/src/enrich/friendlyText.ts +1 -1
- package/src/enrich/mockData.ts +1 -1
- package/src/fnHash.ts +46 -2
- package/src/formats/bigintFormats.ts +1 -1
- package/src/formats/datetime/temporalFormats.ts +2 -2
- package/src/formats/numberFormats.ts +1 -1
- package/src/formats/scalars.ts +1 -1
- package/src/formats/string/stringFormats.ts +3 -3
- package/src/getRunType.ts +3 -3
- package/src/go-generated/README.md +37 -0
- package/src/go-generated/fnHashes.generated.ts +153 -0
- package/src/{runTypeKind.ts → go-generated/runTypeKind.generated.ts} +5 -3
- package/src/go-generated/typeFormats.generated.ts +56 -0
- package/src/index.ts +68 -33
- package/src/markers.ts +48 -8
- package/src/mocking/binarySize.ts +4 -3
- package/src/mocking/constants.mock.ts +3 -0
- package/src/mocking/createMockData.ts +13 -7
- package/src/mocking/mockBigIntFormat.ts +7 -10
- package/src/mocking/mockDateTimeBounds.ts +31 -23
- package/src/mocking/mockInvalid.ts +19 -7
- package/src/mocking/mockNumberFormat.ts +8 -11
- package/src/mocking/mockOversized.ts +14 -10
- package/src/mocking/mockRandom.ts +181 -0
- package/src/mocking/mockRegistry.ts +9 -3
- package/src/mocking/mockStringFormat.ts +68 -90
- package/src/mocking/mockTemporal.ts +48 -48
- package/src/mocking/mockType.ts +62 -54
- package/src/mocking/mockTypes.ts +18 -3
- package/src/overrideRTFunctions.ts +4 -10
- package/src/runtypes/circular-pure-fns.ts +184 -0
- package/src/runtypes/circular.ts +12 -294
- package/src/runtypes/dataOnly.ts +4 -4
- package/src/runtypes/dataView.ts +1 -1
- package/src/runtypes/entryTuple.ts +39 -82
- package/src/runtypes/pure-fns-utils.ts +14 -46
- package/src/runtypes/pureFn.ts +186 -36
- package/src/runtypes/rtUtils.ts +55 -5
- package/src/runtypes/types.ts +15 -8
- package/src/schema/atomic.ts +6 -6
- package/src/schema/compose.ts +2 -2
- package/src/schema/index.ts +1 -1
- package/src/schema/utility.ts +2 -2
- package/src/standard/createStandardSchema.ts +10 -16
- package/src/standard/issueMapping.ts +1 -1
- package/dist/cjs/fnHashes.generated.js +0 -31
- package/dist/cjs/mocking/mockUtils.d.ts +0 -10
- package/dist/cjs/mocking/mockUtils.js +0 -58
- package/dist/fnHashes.generated.d.ts.map +0 -1
- package/dist/fnHashes.generated.js +0 -29
- package/dist/fnHashes.generated.js.map +0 -1
- package/dist/mocking/mockUtils.d.ts +0 -11
- package/dist/mocking/mockUtils.d.ts.map +0 -1
- package/dist/mocking/mockUtils.js +0 -47
- package/dist/mocking/mockUtils.js.map +0 -1
- package/dist/runTypeKind.d.ts.map +0 -1
- package/dist/runTypeKind.js.map +0 -1
- package/src/fnHashes.generated.ts +0 -54
- package/src/mocking/mockUtils.ts +0 -64
- /package/dist/cjs/{runTypeKind.d.ts → go-generated/runTypeKind.generated.d.ts} +0 -0
- /package/dist/cjs/{runTypeKind.js → go-generated/runTypeKind.generated.js} +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @ts-runtypes/core
|
|
2
|
+
|
|
3
|
+
**Compile-time runtime types for TypeScript 7 / typescript-go (tsgo).**
|
|
4
|
+
|
|
5
|
+
TypeScript throws your types away before your code ever runs. RunTypes reads them
|
|
6
|
+
first, at build time, and hands the runtime back what it lost: validators, JSON and
|
|
7
|
+
binary (de)serializers, mock data, and reflection.
|
|
8
|
+
|
|
9
|
+
This is the runtime package: the sentinel markers the compiler looks for, plus the
|
|
10
|
+
small helper runtime the generated code calls into. It has **zero dependencies**.
|
|
11
|
+
The build-time half lives in
|
|
12
|
+
[`@ts-runtypes/devtools`](https://www.npmjs.com/package/@ts-runtypes/devtools).
|
|
13
|
+
|
|
14
|
+
## Documentation
|
|
15
|
+
|
|
16
|
+
Install, guides, the factory reference, and benchmarks live at
|
|
17
|
+
**[runtypes.pages.dev](https://runtypes.pages.dev/)**.
|
|
18
|
+
|
|
19
|
+
- [Quick start](https://runtypes.pages.dev/introduction/quick-start)
|
|
20
|
+
- [Configuration](https://runtypes.pages.dev/introduction/configuration)
|
|
21
|
+
- [Source and issues](https://github.com/MionKit/ts-run-types)
|
|
22
|
+
|
|
23
|
+
## Status
|
|
24
|
+
|
|
25
|
+
Experimental.
|
|
26
|
+
|
|
27
|
+
## License
|
|
28
|
+
|
|
29
|
+
Proprietary — all rights reserved. No use, copying, or distribution without prior
|
|
30
|
+
written authorization. See
|
|
31
|
+
[LICENSE](https://github.com/MionKit/ts-run-types/blob/main/LICENSE).
|
|
@@ -22,15 +22,15 @@ export interface BinaryEncoderOptions {
|
|
|
22
22
|
export interface BinaryDecoderOptions {
|
|
23
23
|
cacheKey?: string;
|
|
24
24
|
}
|
|
25
|
-
export declare function
|
|
26
|
-
export declare function
|
|
27
|
-
export declare function
|
|
28
|
-
export declare function
|
|
29
|
-
export declare function
|
|
30
|
-
export declare function
|
|
25
|
+
export declare function createBinaryEncoderFn<T>(schema: RunType<T>, options: InitialSizeOptions, id?: InjectTypeFnArgs<T, 'tb'>): BinaryEncoderSizeFn;
|
|
26
|
+
export declare function createBinaryEncoderFn<T>(val: T | undefined, options: InitialSizeOptions, id?: InjectTypeFnArgs<T, 'tb'>): BinaryEncoderSizeFn;
|
|
27
|
+
export declare function createBinaryEncoderFn<T>(schema: RunType<T>, options: IntoBufferOptions, id?: InjectTypeFnArgs<T, 'tb'>): BinaryEncoderIntoFn;
|
|
28
|
+
export declare function createBinaryEncoderFn<T>(val: T | undefined, options: IntoBufferOptions, id?: InjectTypeFnArgs<T, 'tb'>): BinaryEncoderIntoFn;
|
|
29
|
+
export declare function createBinaryEncoderFn<T>(schema: RunType<T>, options?: BinaryEncoderOptions, id?: InjectTypeFnArgs<T, 'tb'>): BinaryEncoderFn;
|
|
30
|
+
export declare function createBinaryEncoderFn<T>(val?: T, options?: BinaryEncoderOptions, id?: InjectTypeFnArgs<T, 'tb'>): BinaryEncoderFn;
|
|
31
31
|
export type BinarySizerFn = (value: unknown) => number;
|
|
32
|
-
export declare function
|
|
33
|
-
export declare function
|
|
34
|
-
export declare function
|
|
35
|
-
export declare function
|
|
32
|
+
export declare function createBinarySizerFn<T>(schema: RunType<T>, id?: InjectTypeFnArgs<T, 'tb'>): BinarySizerFn;
|
|
33
|
+
export declare function createBinarySizerFn<T>(val?: T, id?: InjectTypeFnArgs<T, 'tb'>): BinarySizerFn;
|
|
34
|
+
export declare function createBinaryDecoderFn<T>(schema: RunType<T>, options?: BinaryDecoderOptions, id?: InjectTypeFnArgs<T, 'fb'>): BinaryDecoderFn<DataOnly<T>>;
|
|
35
|
+
export declare function createBinaryDecoderFn<T>(val?: T, options?: BinaryDecoderOptions, id?: InjectTypeFnArgs<T, 'fb'>): BinaryDecoderFn<DataOnly<T>>;
|
|
36
36
|
export {};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
3
|
+
exports.createBinaryEncoderFn = createBinaryEncoderFn;
|
|
4
|
+
exports.createBinarySizerFn = createBinarySizerFn;
|
|
5
|
+
exports.createBinaryDecoderFn = createBinaryDecoderFn;
|
|
6
6
|
const rtUtils_ts_1 = require("./runtypes/rtUtils.js");
|
|
7
7
|
const entryTuple_ts_1 = require("./runtypes/entryTuple.js");
|
|
8
8
|
const dataView_ts_1 = require("./runtypes/dataView.js");
|
|
9
9
|
const noopToBinaryFn = (_v, Ser) => Ser;
|
|
10
10
|
const noopFromBinaryFn = (ret) => ret;
|
|
11
11
|
function fixedBufferTooSmall(capacity) {
|
|
12
|
-
return new RangeError(`
|
|
13
|
-
`Use
|
|
12
|
+
return new RangeError(`createBinaryEncoderFn: the payload does not fit in the ${capacity}-byte buffer. ` +
|
|
13
|
+
`Use createBinarySizerFn<T>() to compute the exact size, enlarge the buffer, or use sizeStrategy 'dynamic' / 'precalculate'.`);
|
|
14
14
|
}
|
|
15
15
|
function encodeFixed(encodeFn, value, ser, capacity) {
|
|
16
16
|
try {
|
|
@@ -32,10 +32,10 @@ function binarySizingKey(schemaId, injected) {
|
|
|
32
32
|
return (0, entryTuple_ts_1.entryTupleKey)(injected).slice(entryTuple_ts_1.FN_HASH_LEN + 1);
|
|
33
33
|
return 'unknown';
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function createBinaryEncoderFn(valOrSchema, options, id) {
|
|
36
36
|
const schemaId = (0, rtUtils_ts_1.isRunTypeSchema)(valOrSchema) ? valOrSchema.id : undefined;
|
|
37
37
|
const cacheKey = options?.cacheKey ?? binarySizingKey(schemaId, id);
|
|
38
|
-
const encodeFn = (0, entryTuple_ts_1.resolveEntryTupleFn)('
|
|
38
|
+
const encodeFn = (0, entryTuple_ts_1.resolveEntryTupleFn)('createBinaryEncoderFn', noopToBinaryFn, schemaId, id);
|
|
39
39
|
const sizeStrategy = options?.sizeStrategy ?? 'dynamic';
|
|
40
40
|
if (sizeStrategy === 'precalculate') {
|
|
41
41
|
const fn = (value) => {
|
|
@@ -51,7 +51,7 @@ function createBinaryEncoder(valOrSchema, options, id) {
|
|
|
51
51
|
if (sizeStrategy === 'initialSize') {
|
|
52
52
|
const fn = (value, size) => {
|
|
53
53
|
if (typeof size !== 'number')
|
|
54
|
-
throw new Error("
|
|
54
|
+
throw new Error("createBinaryEncoderFn: sizeStrategy 'initialSize' requires a numeric `size` argument.");
|
|
55
55
|
return encodeFixed(encodeFn, value, (0, dataView_ts_1.createDataViewSerializer)(cacheKey, { size, grow: false }), size);
|
|
56
56
|
};
|
|
57
57
|
return fn;
|
|
@@ -59,7 +59,7 @@ function createBinaryEncoder(valOrSchema, options, id) {
|
|
|
59
59
|
if (sizeStrategy === 'intoBuffer') {
|
|
60
60
|
const fn = (value, into) => {
|
|
61
61
|
if (!(into instanceof ArrayBuffer))
|
|
62
|
-
throw new Error("
|
|
62
|
+
throw new Error("createBinaryEncoderFn: sizeStrategy 'intoBuffer' requires an ArrayBuffer `into` argument.");
|
|
63
63
|
return encodeFixed(encodeFn, value, (0, dataView_ts_1.createDataViewSerializer)(cacheKey, { buffer: into }), into.byteLength);
|
|
64
64
|
};
|
|
65
65
|
return fn;
|
|
@@ -73,20 +73,20 @@ function createBinaryEncoder(valOrSchema, options, id) {
|
|
|
73
73
|
};
|
|
74
74
|
return fn;
|
|
75
75
|
}
|
|
76
|
-
function
|
|
76
|
+
function createBinarySizerFn(valOrSchema, id) {
|
|
77
77
|
const schemaId = (0, rtUtils_ts_1.isRunTypeSchema)(valOrSchema) ? valOrSchema.id : undefined;
|
|
78
78
|
const cacheKey = binarySizingKey(schemaId, id);
|
|
79
|
-
const encodeFn = (0, entryTuple_ts_1.resolveEntryTupleFn)('
|
|
79
|
+
const encodeFn = (0, entryTuple_ts_1.resolveEntryTupleFn)('createBinarySizerFn', noopToBinaryFn, schemaId, id);
|
|
80
80
|
return (value) => {
|
|
81
81
|
const sizer = (0, dataView_ts_1.createSizingSerializer)(cacheKey);
|
|
82
82
|
encodeFn(value, sizer);
|
|
83
83
|
return sizer.getLength();
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
|
-
function
|
|
86
|
+
function createBinaryDecoderFn(valOrSchema, options, id) {
|
|
87
87
|
const schemaId = (0, rtUtils_ts_1.isRunTypeSchema)(valOrSchema) ? valOrSchema.id : undefined;
|
|
88
88
|
const cacheKey = options?.cacheKey ?? binarySizingKey(schemaId, id);
|
|
89
|
-
const decodeFn = (0, entryTuple_ts_1.resolveEntryTupleFn)('
|
|
89
|
+
const decodeFn = (0, entryTuple_ts_1.resolveEntryTupleFn)('createBinaryDecoderFn', noopFromBinaryFn, schemaId, id);
|
|
90
90
|
return ((input) => {
|
|
91
91
|
let des;
|
|
92
92
|
if (input && typeof input.desString === 'function') {
|
|
@@ -6,6 +6,7 @@ export interface ValidateOptions {
|
|
|
6
6
|
noLiterals?: boolean;
|
|
7
7
|
noIsArrayCheck?: boolean;
|
|
8
8
|
rejectCircularRefs?: boolean;
|
|
9
|
+
numberMode?: 'isFinite' | 'typeof' | 'notNaN';
|
|
9
10
|
}
|
|
10
11
|
export type ValidateFn<T = unknown> = (value: unknown) => value is DataOnly<T>;
|
|
11
12
|
export interface RTPathSegment {
|
|
@@ -28,10 +29,12 @@ export type GetValidationErrorsFn = (value: unknown, path?: RTValidationErrorPat
|
|
|
28
29
|
export interface HasUnknownKeysOptions {
|
|
29
30
|
checkNonRTProps?: boolean;
|
|
30
31
|
}
|
|
32
|
+
export interface HasUnknownKeysCompileOptions {
|
|
33
|
+
runsAfterValidation?: boolean;
|
|
34
|
+
}
|
|
31
35
|
export type HasUnknownKeysFn = (value: unknown, options?: HasUnknownKeysOptions) => boolean;
|
|
32
|
-
export type
|
|
36
|
+
export type CloneExactShapeFn<T = unknown> = (value: T) => T;
|
|
33
37
|
export type UnknownKeyErrorsFn = (value: unknown, path?: RTValidationErrorPathSegment[], errors?: RTValidationError[]) => RTValidationError[];
|
|
34
|
-
export type UnknownKeysToUndefinedFn = (value: unknown) => unknown;
|
|
35
38
|
export type FormatTransformValue<T> = T extends string ? string : T extends number ? number : T extends boolean ? boolean : T extends readonly (infer E)[] ? FormatTransformValue<E>[] : T extends object ? {
|
|
36
39
|
[K in keyof T]: FormatTransformValue<T[K]>;
|
|
37
40
|
} : T;
|
|
@@ -50,24 +53,22 @@ export type JsonDecoderStrategy = 'strip' | 'preserve' | 'compact';
|
|
|
50
53
|
export type JsonDecoderOptions = {
|
|
51
54
|
strategy?: JsonDecoderStrategy;
|
|
52
55
|
};
|
|
53
|
-
export declare const
|
|
54
|
-
export declare const
|
|
55
|
-
export declare const
|
|
56
|
-
export declare const
|
|
57
|
-
export declare const
|
|
58
|
-
export declare const
|
|
59
|
-
export declare
|
|
60
|
-
export declare function
|
|
61
|
-
export declare function
|
|
62
|
-
export declare function
|
|
63
|
-
export declare function createJsonDecoder<T>(val?: T, options?: CompTimeFnArgs<JsonDecoderOptions>, id?: InjectTypeFnArgs<T, 'jsonDecoder'>): JsonDecoderFn<DataOnly<T>>;
|
|
56
|
+
export declare const createValidateFn: (<T>(schema: RunType<T>, options?: CompTimeFnArgs<ValidateOptions>, id?: InjectTypeFnArgs<T, "val">) => ValidateFn<T>) & (<T>(val?: T, options?: CompTimeFnArgs<ValidateOptions>, id?: InjectTypeFnArgs<T, "val">) => ValidateFn<T>);
|
|
57
|
+
export declare const createGetValidationErrorsFn: (<T>(schema: RunType<T>, options?: CompTimeFnArgs<ValidateOptions>, id?: InjectTypeFnArgs<T, "verr">) => GetValidationErrorsFn) & (<T>(val?: T, options?: CompTimeFnArgs<ValidateOptions>, id?: InjectTypeFnArgs<T, "verr">) => GetValidationErrorsFn);
|
|
58
|
+
export declare const createHasUnknownKeysFn: (<T>(schema: RunType<T>, options?: CompTimeFnArgs<HasUnknownKeysCompileOptions>, id?: InjectTypeFnArgs<T, "huk">) => HasUnknownKeysFn) & (<T>(val?: T, options?: CompTimeFnArgs<HasUnknownKeysCompileOptions>, id?: InjectTypeFnArgs<T, "huk">) => HasUnknownKeysFn);
|
|
59
|
+
export declare const createCloneExactShapeFn: (<T>(schema: RunType<T>, id?: InjectTypeFnArgs<T, "ces">) => CloneExactShapeFn<T>) & (<T>(val?: T, id?: InjectTypeFnArgs<T, "ces">) => CloneExactShapeFn<T>);
|
|
60
|
+
export declare const createUnknownKeyErrorsFn: (<T>(schema: RunType<T>, id?: InjectTypeFnArgs<T, "uke">) => UnknownKeyErrorsFn) & (<T>(val?: T, id?: InjectTypeFnArgs<T, "uke">) => UnknownKeyErrorsFn);
|
|
61
|
+
export declare const createFormatTransformFn: (<T>(schema: RunType<T>, id?: InjectTypeFnArgs<T, "fmt">) => FormatTransformFn<T>) & (<T>(val?: T, id?: InjectTypeFnArgs<T, "fmt">) => FormatTransformFn<T>);
|
|
62
|
+
export declare function createJsonEncoderFn<T>(schema: RunType<T>, options?: CompTimeFnArgs<JsonEncoderOptions>, id?: InjectTypeFnArgs<T, 'jsonEncoder'>): JsonEncoderFn;
|
|
63
|
+
export declare function createJsonEncoderFn<T>(val?: T, options?: CompTimeFnArgs<JsonEncoderOptions>, id?: InjectTypeFnArgs<T, 'jsonEncoder'>): JsonEncoderFn;
|
|
64
|
+
export declare function createJsonDecoderFn<T>(schema: RunType<T>, options?: CompTimeFnArgs<JsonDecoderOptions>, id?: InjectTypeFnArgs<T, 'jsonDecoder'>): JsonDecoderFn<DataOnly<T>>;
|
|
65
|
+
export declare function createJsonDecoderFn<T>(val?: T, options?: CompTimeFnArgs<JsonDecoderOptions>, id?: InjectTypeFnArgs<T, 'jsonDecoder'>): JsonDecoderFn<DataOnly<T>>;
|
|
64
66
|
export interface RTFunctionByKey {
|
|
65
67
|
val: ValidateFn;
|
|
66
68
|
verr: GetValidationErrorsFn;
|
|
67
69
|
huk: HasUnknownKeysFn;
|
|
68
|
-
|
|
70
|
+
ces: CloneExactShapeFn;
|
|
69
71
|
uke: UnknownKeyErrorsFn;
|
|
70
|
-
uku: UnknownKeysToUndefinedFn;
|
|
71
72
|
fmt: FormatTransformFn<unknown>;
|
|
72
73
|
jsonEncoder: JsonEncoderFn;
|
|
73
74
|
jsonDecoder: JsonDecoderFn;
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
3
|
+
exports.createFormatTransformFn = exports.createUnknownKeyErrorsFn = exports.createCloneExactShapeFn = exports.createHasUnknownKeysFn = exports.createGetValidationErrorsFn = exports.createValidateFn = void 0;
|
|
4
|
+
exports.createJsonEncoderFn = createJsonEncoderFn;
|
|
5
|
+
exports.createJsonDecoderFn = createJsonDecoderFn;
|
|
6
6
|
exports.getRTFunction = getRTFunction;
|
|
7
7
|
const rtUtils_ts_1 = require("./runtypes/rtUtils.js");
|
|
8
8
|
const entryTuple_ts_1 = require("./runtypes/entryTuple.js");
|
|
9
|
-
function resolveTupleEntry(fnName, identityFn, val, args
|
|
9
|
+
function resolveTupleEntry(fnName, identityFn, val, args) {
|
|
10
10
|
const schemaId = (0, rtUtils_ts_1.isRunTypeSchema)(val) ? val.id : undefined;
|
|
11
|
-
return (0, entryTuple_ts_1.resolveEntryTupleFn)(fnName, identityFn, schemaId, args
|
|
12
|
-
}
|
|
13
|
-
function readRejectCircularRefs(options) {
|
|
14
|
-
return options?.rejectCircularRefs;
|
|
11
|
+
return (0, entryTuple_ts_1.resolveEntryTupleFn)(fnName, identityFn, schemaId, args);
|
|
15
12
|
}
|
|
16
13
|
function createTypeFnArgsFunction(fnName, identityFn) {
|
|
17
|
-
return (val,
|
|
14
|
+
return (val, _options, args) => resolveTupleEntry(fnName, identityFn, val, args);
|
|
18
15
|
}
|
|
19
16
|
function createRTFunction(fnName, identityFn) {
|
|
20
17
|
return (val, args) => resolveTupleEntry(fnName, identityFn, val, args);
|
|
@@ -22,20 +19,19 @@ function createRTFunction(fnName, identityFn) {
|
|
|
22
19
|
const identityValueFn = (v) => v;
|
|
23
20
|
const getValidationErrorsIdentity = () => [];
|
|
24
21
|
const unknownKeyErrorsIdentity = () => [];
|
|
25
|
-
exports.
|
|
26
|
-
exports.
|
|
27
|
-
exports.
|
|
28
|
-
exports.
|
|
29
|
-
exports.
|
|
30
|
-
exports.
|
|
31
|
-
exports.createFormatTransform = createRTFunction('createFormatTransform', identityValueFn);
|
|
22
|
+
exports.createValidateFn = createTypeFnArgsFunction('createValidateFn', (() => true));
|
|
23
|
+
exports.createGetValidationErrorsFn = createTypeFnArgsFunction('createGetValidationErrorsFn', getValidationErrorsIdentity);
|
|
24
|
+
exports.createHasUnknownKeysFn = createTypeFnArgsFunction('createHasUnknownKeysFn', () => false);
|
|
25
|
+
exports.createCloneExactShapeFn = createRTFunction('createCloneExactShapeFn', identityValueFn);
|
|
26
|
+
exports.createUnknownKeyErrorsFn = createRTFunction('createUnknownKeyErrorsFn', unknownKeyErrorsIdentity);
|
|
27
|
+
exports.createFormatTransformFn = createRTFunction('createFormatTransformFn', identityValueFn);
|
|
32
28
|
const jsonStringifyFallback = (v) => JSON.stringify(v);
|
|
33
29
|
const jsonParseFallback = (s) => JSON.parse(s);
|
|
34
|
-
function
|
|
35
|
-
return resolveTupleEntry('
|
|
30
|
+
function createJsonEncoderFn(valOrSchema, _options, id) {
|
|
31
|
+
return resolveTupleEntry('createJsonEncoderFn', jsonStringifyFallback, valOrSchema, id);
|
|
36
32
|
}
|
|
37
|
-
function
|
|
38
|
-
return resolveTupleEntry('
|
|
33
|
+
function createJsonDecoderFn(valOrSchema, options, id) {
|
|
34
|
+
return resolveTupleEntry('createJsonDecoderFn', jsonParseFallback, valOrSchema, id);
|
|
39
35
|
}
|
|
40
36
|
function getRTFunction(injected, fallback) {
|
|
41
37
|
const identityFn = (fallback ?? ((value) => value));
|
|
@@ -188,6 +188,25 @@ function renderErrors(state, errs) {
|
|
|
188
188
|
const sourceNode = state.source ? nodeAt(state.source, group.path) : undefined;
|
|
189
189
|
const label = node?.rt$label || sourceNode?.rt$label || rawLabel(group.path);
|
|
190
190
|
const index = numericIndex(group.path);
|
|
191
|
+
const first = group.errors[0];
|
|
192
|
+
const firstVal = primitiveVal(first.format?.val);
|
|
193
|
+
const rootProvides = resolveTemplate(node, constraintKey(first.format), firstVal, state.rootLocale) !== undefined;
|
|
194
|
+
const defaultNode = rootProvides ? node : sourceNode;
|
|
195
|
+
const defaultLocale = rootProvides ? state.rootLocale : state.sourceLocale;
|
|
196
|
+
const catchAll = leafTemplate(defaultNode?.rt$errors?.rt$default, firstVal, defaultLocale);
|
|
197
|
+
if (catchAll !== undefined) {
|
|
198
|
+
out.push({
|
|
199
|
+
path: group.pathStr,
|
|
200
|
+
label,
|
|
201
|
+
message: interpolate(catchAll, {
|
|
202
|
+
label,
|
|
203
|
+
valText: renderBoundText(state, first.format, firstVal),
|
|
204
|
+
path: group.pathStr,
|
|
205
|
+
index,
|
|
206
|
+
}),
|
|
207
|
+
});
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
191
210
|
for (const err of group.errors) {
|
|
192
211
|
const key = constraintKey(err.format);
|
|
193
212
|
const val = primitiveVal(err.format?.val);
|
package/dist/cjs/fnHash.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { FN_HASHES } from './fnHashes.generated.ts';
|
|
1
|
+
import { FN_HASHES } from './go-generated/fnHashes.generated.ts';
|
|
2
2
|
export type FnHashKey = keyof typeof FN_HASHES;
|
|
3
3
|
export interface FnHashOptions {
|
|
4
4
|
noLiterals?: boolean;
|
|
5
5
|
noIsArrayCheck?: boolean;
|
|
6
|
+
numberMode?: string;
|
|
6
7
|
strategy?: string;
|
|
8
|
+
runsAfterValidation?: boolean;
|
|
9
|
+
rejectCircularRefs?: boolean;
|
|
7
10
|
}
|
|
8
11
|
export declare function getFnHash(fnKey: FnHashKey | (string & {}), options?: FnHashOptions): string;
|
package/dist/cjs/fnHash.js
CHANGED
|
@@ -1,13 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getFnHash = getFnHash;
|
|
4
|
-
const fnHashes_generated_ts_1 = require("./fnHashes.generated.js");
|
|
4
|
+
const fnHashes_generated_ts_1 = require("./go-generated/fnHashes.generated.js");
|
|
5
|
+
function numberModeOptionName(mode) {
|
|
6
|
+
if (mode === 'typeof')
|
|
7
|
+
return 'numberTypeof';
|
|
8
|
+
if (mode === 'notNaN')
|
|
9
|
+
return 'numberNotNaN';
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
5
12
|
function validateVariantToken(options) {
|
|
6
13
|
if (!options)
|
|
7
14
|
return '';
|
|
15
|
+
const numberModeName = numberModeOptionName(options.numberMode);
|
|
8
16
|
let suffix = 'N';
|
|
9
17
|
let hit = false;
|
|
10
18
|
for (const [name, letter] of fnHashes_generated_ts_1.VALIDATE_OPTION_LETTERS) {
|
|
19
|
+
const present = name === numberModeName || options[name];
|
|
20
|
+
if (present) {
|
|
21
|
+
suffix += letter;
|
|
22
|
+
hit = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return hit ? suffix : '';
|
|
26
|
+
}
|
|
27
|
+
function hasUnknownKeysVariantToken(options) {
|
|
28
|
+
if (!options)
|
|
29
|
+
return '';
|
|
30
|
+
let suffix = 'O';
|
|
31
|
+
let hit = false;
|
|
32
|
+
for (const [name, letter] of fnHashes_generated_ts_1.HAS_UNKNOWN_KEYS_OPTION_LETTERS) {
|
|
11
33
|
if (options[name]) {
|
|
12
34
|
suffix += letter;
|
|
13
35
|
hit = true;
|
|
@@ -24,6 +46,10 @@ function getFnHash(fnKey, options) {
|
|
|
24
46
|
token = validateVariantToken(options);
|
|
25
47
|
else if (entry.axis === 'jsonStrategy')
|
|
26
48
|
token = options?.strategy ?? entry.defaultVariant ?? '';
|
|
49
|
+
else if (entry.axis === 'hasUnknownKeysOptions')
|
|
50
|
+
token = hasUnknownKeysVariantToken(options);
|
|
51
|
+
if (entry.circularGuarded && options?.rejectCircularRefs)
|
|
52
|
+
token += 'C';
|
|
27
53
|
const hash = entry.variants[token];
|
|
28
54
|
if (hash === undefined)
|
|
29
55
|
throw new Error(`getFnHash: fnKey ${JSON.stringify(fnKey)} has no ${JSON.stringify(token)} variant`);
|