ts-fortress 11.2.0 → 12.0.1
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 +4 -4
- package/dist/array/bounded-length-array.d.mts +3 -3
- package/dist/array/bounded-length-array.d.mts.map +1 -1
- package/dist/array/bounded-length-array.mjs.map +1 -1
- package/dist/array/bounded-length-tuple.d.mts +3 -3
- package/dist/array/bounded-length-tuple.d.mts.map +1 -1
- package/dist/array/bounded-length-tuple.mjs.map +1 -1
- package/dist/array/fixed-length-array.d.mts +1 -1
- package/dist/array/fixed-length-array.d.mts.map +1 -1
- package/dist/array/fixed-length-array.mjs.map +1 -1
- package/dist/array/fixed-length-tuple.d.mts +1 -1
- package/dist/array/fixed-length-tuple.d.mts.map +1 -1
- package/dist/array/fixed-length-tuple.mjs +1 -1
- package/dist/array/fixed-length-tuple.mjs.map +1 -1
- package/dist/array/max-length-array.d.mts +1 -1
- package/dist/array/max-length-array.d.mts.map +1 -1
- package/dist/array/max-length-array.mjs.map +1 -1
- package/dist/array/max-length-tuple.d.mts +1 -1
- package/dist/array/max-length-tuple.d.mts.map +1 -1
- package/dist/array/max-length-tuple.mjs.map +1 -1
- package/dist/array/min-length-array.d.mts +1 -1
- package/dist/array/min-length-array.d.mts.map +1 -1
- package/dist/array/min-length-array.mjs.map +1 -1
- package/dist/array/min-length-tuple.d.mts +1 -1
- package/dist/array/min-length-tuple.d.mts.map +1 -1
- package/dist/array/min-length-tuple.mjs.map +1 -1
- package/dist/array/non-empty-array.mjs +1 -1
- package/dist/array/non-empty-array.mjs.map +1 -1
- package/dist/array/tuple.mjs +6 -8
- package/dist/array/tuple.mjs.map +1 -1
- package/dist/compose/intersection.mjs +1 -1
- package/dist/compose/intersection.mjs.map +1 -1
- package/dist/compose/union.mjs +1 -1
- package/dist/compose/union.mjs.map +1 -1
- package/dist/enum/uint-range.d.mts +2 -2
- package/dist/enum/uint-range.d.mts.map +1 -1
- package/dist/enum/uint-range.mjs.map +1 -1
- package/dist/other-types/literal.d.mts +2 -2
- package/dist/other-types/literal.d.mts.map +1 -1
- package/dist/other-types/literal.mjs.map +1 -1
- package/dist/other-types/refine.d.mts +2 -2
- package/dist/other-types/refine.d.mts.map +1 -1
- package/dist/other-types/refine.mjs.map +1 -1
- package/dist/predefined/brand/string/non-empty-string.d.mts +2 -2
- package/dist/predefined/brand/string/non-empty-string.d.mts.map +1 -1
- package/dist/predefined/brand/string/non-empty-string.mjs.map +1 -1
- package/dist/primitives/bigint.d.mts.map +1 -1
- package/dist/primitives/bigint.mjs +1 -1
- package/dist/primitives/bigint.mjs.map +1 -1
- package/dist/primitives/number.d.mts +2 -2
- package/dist/primitives/number.d.mts.map +1 -1
- package/dist/primitives/number.mjs +1 -1
- package/dist/primitives/number.mjs.map +1 -1
- package/dist/primitives/string.d.mts.map +1 -1
- package/dist/primitives/string.mjs +1 -1
- package/dist/primitives/string.mjs.map +1 -1
- package/dist/record/at.mjs +1 -1
- package/dist/record/at.mjs.map +1 -1
- package/dist/record/keyof.d.mts.map +1 -1
- package/dist/record/keyof.mjs.map +1 -1
- package/dist/record/merge-records.mjs +1 -1
- package/dist/record/merge-records.mjs.map +1 -1
- package/dist/record/omit.d.mts +2 -2
- package/dist/record/omit.d.mts.map +1 -1
- package/dist/record/omit.mjs.map +1 -1
- package/dist/record/pick.d.mts +2 -2
- package/dist/record/pick.d.mts.map +1 -1
- package/dist/record/pick.mjs.map +1 -1
- package/dist/record/record.d.mts +3 -3
- package/dist/record/record.d.mts.map +1 -1
- package/dist/record/record.mjs +2 -2
- package/dist/record/record.mjs.map +1 -1
- package/dist/record/valueof.mjs +1 -1
- package/dist/record/valueof.mjs.map +1 -1
- package/package.json +26 -18
- package/src/array/bounded-length-array.mts +3 -3
- package/src/array/bounded-length-tuple.mts +3 -3
- package/src/array/fixed-length-array.mts +1 -1
- package/src/array/fixed-length-tuple.mts +2 -2
- package/src/array/max-length-array.mts +1 -1
- package/src/array/max-length-tuple.mts +1 -1
- package/src/array/min-length-array.mts +1 -1
- package/src/array/min-length-tuple.mts +1 -1
- package/src/array/non-empty-array.mts +1 -1
- package/src/array/tuple.mts +4 -4
- package/src/brand/branded-number.test.mts +1 -1
- package/src/compose/intersection.mts +1 -1
- package/src/compose/union.mts +1 -1
- package/src/enum/uint-range.mts +3 -3
- package/src/other-types/literal.mts +2 -2
- package/src/other-types/literal.test.mts +5 -5
- package/src/other-types/recursion.test.mts +1 -1
- package/src/other-types/refine.mts +2 -2
- package/src/predefined/brand/string/non-empty-string.mts +5 -2
- package/src/primitives/bigint.mts +1 -4
- package/src/primitives/number.mts +3 -5
- package/src/primitives/number.test.mts +2 -2
- package/src/primitives/string.mts +1 -4
- package/src/record/at.mts +1 -1
- package/src/record/keyof.mts +7 -2
- package/src/record/merge-records.mts +1 -1
- package/src/record/omit.mts +5 -5
- package/src/record/pick.mts +6 -2
- package/src/record/record.mts +7 -4
- package/src/record/valueof.mts +1 -1
package/README.md
CHANGED
|
@@ -8,8 +8,8 @@ TypeScript-first schema validation library with static type inference.
|
|
|
8
8
|
|
|
9
9
|
[](https://www.npmjs.com/package/ts-fortress)
|
|
10
10
|
[](https://www.npmjs.com/package/ts-fortress)
|
|
11
|
-
[](
|
|
12
|
-
[](https://github.com/noshiro-pf/mono/blob/main/libs/ts-fortress/LICENSE)
|
|
12
|
+
[](https://codecov.io/gh/noshiro-pf/mono)
|
|
13
13
|
|
|
14
14
|
**ts-fortress** is a runtime validation library similar to [io-ts](https://github.com/gcanti/io-ts) and [Zod](https://zod.dev/), designed to provide type-safe schema validation with excellent TypeScript integration and static type inference.
|
|
15
15
|
|
|
@@ -286,7 +286,7 @@ String constraints:
|
|
|
286
286
|
|
|
287
287
|
- `startsWith`, `endsWith`, `includes` — narrow the result to the corresponding template literal type
|
|
288
288
|
- `lowercase`, `uppercase`
|
|
289
|
-
- `nonempty` — brands the result as `NonEmptyString` (from [ts-type-forge](https://github.com/noshiro-pf/ts-type-forge))
|
|
289
|
+
- `nonempty` — brands the result as `NonEmptyString` (from [ts-type-forge](https://github.com/noshiro-pf/mono/tree/main/libs/ts-type-forge))
|
|
290
290
|
- `minLength`, `maxLength` — brand the result as `MinLengthString<N>` / `MaxLengthString<N>` (from ts-type-forge), which preserve the natural subtyping between length bounds
|
|
291
291
|
- `regex`
|
|
292
292
|
|
|
@@ -341,7 +341,7 @@ Bigint constraints mirror the numeric API but operate on `bigint` literals. When
|
|
|
341
341
|
|
|
342
342
|
While ts-fortress, [Zod](https://github.com/colinhacks/zod), and [io-ts](https://github.com/gcanti/io-ts) are all excellent TypeScript validation libraries, ts-fortress offers more readable and informative error messages than both, a more type-safe way of building validators than Zod, and addresses some critical runtime consistency issues found in io-ts.
|
|
343
343
|
|
|
344
|
-
For more information, please see [this documentation](
|
|
344
|
+
For more information, please see [this documentation](https://github.com/noshiro-pf/mono/blob/main/libs/ts-fortress/documents/why-ts-fortress-over-zod-and-io-ts.md).
|
|
345
345
|
|
|
346
346
|
### Migration from io-ts
|
|
347
347
|
|
|
@@ -10,15 +10,15 @@ export type { BoundedLengthArray } from 'ts-type-forge';
|
|
|
10
10
|
* of the element type is ever constructed, which keeps type-checking cheap
|
|
11
11
|
* even when `A` is a large type.
|
|
12
12
|
*/
|
|
13
|
-
export declare function boundedLengthArray<
|
|
13
|
+
export declare function boundedLengthArray<Min extends SupportedLength, Max extends SupportedLength, A>(min: Min, max: Max, elementType: Type<A>, options?: Partial<Readonly<{
|
|
14
14
|
typeName: string;
|
|
15
15
|
defaultValue: BoundedLengthArray<Min, Max, A>;
|
|
16
16
|
}>>): Type<BoundedLengthArray<Min, Max, A>>;
|
|
17
|
-
export declare function boundedLengthArray<
|
|
17
|
+
export declare function boundedLengthArray<Min extends SupportedLength, A>(min: Min, max: number, elementType: Type<A>, options?: Partial<Readonly<{
|
|
18
18
|
typeName: string;
|
|
19
19
|
defaultValue: MinLengthArray<Min, A>;
|
|
20
20
|
}>>): Type<MinLengthArray<Min, A>>;
|
|
21
|
-
export declare function boundedLengthArray<
|
|
21
|
+
export declare function boundedLengthArray<Max extends SupportedLength, A>(min: number, max: Max, elementType: Type<A>, options?: Partial<Readonly<{
|
|
22
22
|
typeName: string;
|
|
23
23
|
defaultValue: MaxLengthArray<Max, A>;
|
|
24
24
|
}>>): Type<MaxLengthArray<Max, A>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bounded-length-array.d.mts","sourceRoot":"","sources":["../../src/array/bounded-length-array.mts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAOxC,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAExD;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,
|
|
1
|
+
{"version":3,"file":"bounded-length-array.d.mts","sourceRoot":"","sources":["../../src/array/bounded-length-array.mts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAOxC,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAExD;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,SAAS,eAAe,EAC3B,GAAG,SAAS,eAAe,EAC3B,CAAC,EAED,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EAAE,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;CAC/C,CAAC,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import { Arr, asUint32, memoizeFunction, Result } from 'ts-data-forge';\nimport {\n type BoundedLengthArray,\n type MaxLengthArray,\n type MinLengthArray,\n type SupportedLength,\n} from 'ts-type-forge';\nimport { type Type } from '../type.mjs';\nimport {\n createPrimitiveValidationError,\n type ValidationError,\n} from '../utils/index.mjs';\nimport { buildType, validateElements } from './build-type.mjs';\n\nexport type { BoundedLengthArray } from 'ts-type-forge';\n\n/**\n * Creates a `Type` for a readonly array whose length is within the inclusive\n * range `[min, max]`, typed as the branded {@link BoundedLengthArray} instead\n * of the union of tuple types produced by `boundedLengthTuple`.\n *\n * Because the length constraint lives only in the brand, no union of tuples\n * of the element type is ever constructed, which keeps type-checking cheap\n * even when `A` is a large type.\n */\nexport function boundedLengthArray<\n
|
|
1
|
+
{"version":3,"file":"bounded-length-array.mjs","sources":["../../src/array/bounded-length-array.mts"],"sourcesContent":["import { Arr, asUint32, memoizeFunction, Result } from 'ts-data-forge';\nimport {\n type BoundedLengthArray,\n type MaxLengthArray,\n type MinLengthArray,\n type SupportedLength,\n} from 'ts-type-forge';\nimport { type Type } from '../type.mjs';\nimport {\n createPrimitiveValidationError,\n type ValidationError,\n} from '../utils/index.mjs';\nimport { buildType, validateElements } from './build-type.mjs';\n\nexport type { BoundedLengthArray } from 'ts-type-forge';\n\n/**\n * Creates a `Type` for a readonly array whose length is within the inclusive\n * range `[min, max]`, typed as the branded {@link BoundedLengthArray} instead\n * of the union of tuple types produced by `boundedLengthTuple`.\n *\n * Because the length constraint lives only in the brand, no union of tuples\n * of the element type is ever constructed, which keeps type-checking cheap\n * even when `A` is a large type.\n */\nexport function boundedLengthArray<\n Min extends SupportedLength,\n Max extends SupportedLength,\n A,\n>(\n min: Min,\n max: Max,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: BoundedLengthArray<Min, Max, A>;\n }>\n >,\n): Type<BoundedLengthArray<Min, Max, A>>;\n\n// Only the lower bound is in `SupportedLength`, so the upper bound is dropped from\n// the result type and only the \"at least `min`\" guarantee is kept.\nexport function boundedLengthArray<Min extends SupportedLength, A>(\n min: Min,\n max: number,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: MinLengthArray<Min, A>;\n }>\n >,\n): Type<MinLengthArray<Min, A>>;\n\n// Only the upper bound is in `SupportedLength`, so the lower bound is dropped from\n// the result type and only the \"at most `max`\" guarantee is kept.\nexport function boundedLengthArray<Max extends SupportedLength, A>(\n min: number,\n max: Max,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: MaxLengthArray<Max, A>;\n }>\n >,\n): Type<MaxLengthArray<Max, A>>;\n\n// Neither bound is in `SupportedLength`, so the result length is left unconstrained.\nexport function boundedLengthArray<A>(\n min: number,\n max: number,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: readonly A[];\n }>\n >,\n): Type<readonly A[]>;\n\nexport function boundedLengthArray<A>(\n min: number,\n max: number,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: readonly A[];\n }>\n >,\n): Type<readonly A[]> {\n type T = readonly A[];\n\n const typeName =\n options?.typeName ??\n `BoundedLengthArray<${min}, ${max}, ${elementType.typeName}>`;\n\n const getDefaultValue = memoizeFunction(\n (): T =>\n options?.defaultValue ??\n // An array of the minimum length is the shortest value within the range.\n Arr.create(asUint32(min), elementType.defaultValue),\n );\n\n const validate: Type<T>['validate'] = (a) => {\n if (!Arr.isArray(a)) {\n return Result.err([\n createPrimitiveValidationError({\n actualValue: a,\n expectedType: 'array',\n typeName,\n details: undefined,\n }),\n ]);\n }\n\n if (a.length < min || max < a.length) {\n return Result.err([\n {\n path: [],\n actualValue: a,\n expectedType: typeName,\n typeName,\n details: {\n kind: 'array-range-length',\n minLength: min,\n maxLength: max,\n actualLength: a.length,\n },\n } satisfies ValidationError,\n ]);\n }\n\n return validateElements(a, elementType);\n };\n\n const fill: Type<T>['fill'] = (a) => {\n if (!Arr.isArray(a)) {\n return getDefaultValue();\n }\n\n // Trim down to at most `max`, then pad up to at least `min`.\n const capped = Arr.take(a, asUint32(max));\n\n return capped.length >= min\n ? Arr.map(capped, (el) => elementType.fill(el) satisfies A)\n : Arr.map(\n Arr.seq(asUint32(min)),\n (i) => elementType.fill(capped[i]) satisfies A,\n );\n };\n\n return buildType({ typeName, getDefaultValue, validate, fill, elementType });\n}\n"],"names":[],"mappings":";;;;AAkFO,SAAS,kBAAA,CACd,GAAA,EACA,GAAA,EACA,WAAA,EACA,OAAA,EAMoB;AAGpB,EAAA,MAAM,QAAA,GACJ,SAAS,QAAA,IACT,CAAA,mBAAA,EAAsB,GAAG,CAAA,EAAA,EAAK,GAAG,CAAA,EAAA,EAAK,WAAA,CAAY,QAAQ,CAAA,CAAA,CAAA;AAE5D,EAAA,MAAM,eAAA,GAAkB,eAAA;AAAA,IACtB,MACE,OAAA,EAAS,YAAA;AAAA,IAET,IAAI,MAAA,CAAO,QAAA,CAAS,GAAG,CAAA,EAAG,YAAY,YAAY;AAAA,GACtD;AAEA,EAAA,MAAM,QAAA,GAAgC,CAAC,CAAA,KAAM;AAC3C,IAAA,IAAI,CAAC,GAAA,CAAI,OAAA,CAAQ,CAAC,CAAA,EAAG;AACnB,MAAA,OAAO,OAAO,GAAA,CAAI;AAAA,QAChB,8BAAA,CAA+B;AAAA,UAC7B,WAAA,EAAa,CAAA;AAAA,UACb,YAAA,EAAc,OAAA;AAAA,UACd,QAAA;AAAA,UACA,OAAA,EAAS;AAAA,SACV;AAAA,OACF,CAAA;AAAA,IACH;AAEA,IAAA,IAAI,CAAA,CAAE,MAAA,GAAS,GAAA,IAAO,GAAA,GAAM,EAAE,MAAA,EAAQ;AACpC,MAAA,OAAO,OAAO,GAAA,CAAI;AAAA,QAChB;AAAA,UACE,MAAM,EAAC;AAAA,UACP,WAAA,EAAa,CAAA;AAAA,UACb,YAAA,EAAc,QAAA;AAAA,UACd,QAAA;AAAA,UACA,OAAA,EAAS;AAAA,YACP,IAAA,EAAM,oBAAA;AAAA,YACN,SAAA,EAAW,GAAA;AAAA,YACX,SAAA,EAAW,GAAA;AAAA,YACX,cAAc,CAAA,CAAE;AAAA;AAClB;AACF,OACD,CAAA;AAAA,IACH;AAEA,IAAA,OAAO,gBAAA,CAAiB,GAAG,WAAW,CAAA;AAAA,EACxC,CAAA;AAEA,EAAA,MAAM,IAAA,GAAwB,CAAC,CAAA,KAAM;AACnC,IAAA,IAAI,CAAC,GAAA,CAAI,OAAA,CAAQ,CAAC,CAAA,EAAG;AACnB,MAAA,OAAO,eAAA,EAAgB;AAAA,IACzB;AAGA,IAAA,MAAM,SAAS,GAAA,CAAI,IAAA,CAAK,CAAA,EAAG,QAAA,CAAS,GAAG,CAAC,CAAA;AAExC,IAAA,OAAO,MAAA,CAAO,MAAA,IAAU,GAAA,GACpB,GAAA,CAAI,GAAA,CAAI,MAAA,EAAQ,CAAC,EAAA,KAAO,WAAA,CAAY,IAAA,CAAK,EAAE,CAAa,IACxD,GAAA,CAAI,GAAA;AAAA,MACF,GAAA,CAAI,GAAA,CAAI,QAAA,CAAS,GAAG,CAAC,CAAA;AAAA,MACrB,CAAC,CAAA,KAAM,WAAA,CAAY,IAAA,CAAK,MAAA,CAAO,CAAC,CAAC;AAAA,KACnC;AAAA,EACN,CAAA;AAEA,EAAA,OAAO,UAAU,EAAE,QAAA,EAAU,iBAAiB,QAAA,EAAU,IAAA,EAAM,aAAa,CAAA;AAC7E;;;;"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { type BoundedLengthTuple, type MaxLengthTuple, type MinLengthTuple, type StructuralPrefixLength } from 'ts-type-forge';
|
|
2
2
|
import { type Type } from '../type.mjs';
|
|
3
3
|
export type { BoundedLengthTuple } from 'ts-type-forge';
|
|
4
|
-
export declare function boundedLengthTuple<
|
|
4
|
+
export declare function boundedLengthTuple<Min extends StructuralPrefixLength, Max extends StructuralPrefixLength, A>(min: Min, max: Max, elementType: Type<A>, options?: Partial<Readonly<{
|
|
5
5
|
typeName: string;
|
|
6
6
|
defaultValue: BoundedLengthTuple<Min, Max, A>;
|
|
7
7
|
}>>): Type<BoundedLengthTuple<Min, Max, A>>;
|
|
8
|
-
export declare function boundedLengthTuple<
|
|
8
|
+
export declare function boundedLengthTuple<Min extends StructuralPrefixLength, A>(min: Min, max: number, elementType: Type<A>, options?: Partial<Readonly<{
|
|
9
9
|
typeName: string;
|
|
10
10
|
defaultValue: MinLengthTuple<Min, A>;
|
|
11
11
|
}>>): Type<MinLengthTuple<Min, A>>;
|
|
12
|
-
export declare function boundedLengthTuple<
|
|
12
|
+
export declare function boundedLengthTuple<Max extends StructuralPrefixLength, A>(min: number, max: Max, elementType: Type<A>, options?: Partial<Readonly<{
|
|
13
13
|
typeName: string;
|
|
14
14
|
defaultValue: MaxLengthTuple<Max, A>;
|
|
15
15
|
}>>): Type<MaxLengthTuple<Max, A>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bounded-length-tuple.d.mts","sourceRoot":"","sources":["../../src/array/bounded-length-tuple.mts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC5B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAUxC,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAExD,wBAAgB,kBAAkB,CAChC,
|
|
1
|
+
{"version":3,"file":"bounded-length-tuple.d.mts","sourceRoot":"","sources":["../../src/array/bounded-length-tuple.mts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC5B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAUxC,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAA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,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EAAE,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,SAAS,CAAC,EAAE,CAAC;CAC5B,CAAC,CACH,GACA,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bounded-length-tuple.mjs","sources":["../../src/array/bounded-length-tuple.mts"],"sourcesContent":["import { Arr, asUint32, memoizeFunction, Result } from 'ts-data-forge';\nimport {\n type BoundedLengthTuple,\n type MaxLengthTuple,\n type MinLengthTuple,\n type StructuralPrefixLength,\n} from 'ts-type-forge';\nimport { type Type } from '../type.mjs';\nimport {\n createAssertFn,\n createCastFn,\n createIsFn,\n createPrimitiveValidationError,\n prependIndexToValidationErrors,\n type ValidationError,\n} from '../utils/index.mjs';\n\nexport type { BoundedLengthTuple } from 'ts-type-forge';\n\nexport function boundedLengthTuple<\n
|
|
1
|
+
{"version":3,"file":"bounded-length-tuple.mjs","sources":["../../src/array/bounded-length-tuple.mts"],"sourcesContent":["import { Arr, asUint32, memoizeFunction, Result } from 'ts-data-forge';\nimport {\n type BoundedLengthTuple,\n type MaxLengthTuple,\n type MinLengthTuple,\n type StructuralPrefixLength,\n} from 'ts-type-forge';\nimport { type Type } from '../type.mjs';\nimport {\n createAssertFn,\n createCastFn,\n createIsFn,\n createPrimitiveValidationError,\n prependIndexToValidationErrors,\n type ValidationError,\n} from '../utils/index.mjs';\n\nexport type { BoundedLengthTuple } from 'ts-type-forge';\n\nexport function boundedLengthTuple<\n Min extends StructuralPrefixLength,\n Max extends StructuralPrefixLength,\n A,\n>(\n min: Min,\n max: Max,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: BoundedLengthTuple<Min, Max, A>;\n }>\n >,\n): Type<BoundedLengthTuple<Min, Max, A>>;\n\n// Only the lower bound is in `StructuralPrefixLength` (`0..10`), so the upper bound is dropped from the\n// result type and only the \"at least `min`\" guarantee is kept.\nexport function boundedLengthTuple<Min extends StructuralPrefixLength, A>(\n min: Min,\n max: number,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: MinLengthTuple<Min, A>;\n }>\n >,\n): Type<MinLengthTuple<Min, A>>;\n\n// Only the upper bound is in `StructuralPrefixLength` (`0..10`), so the lower bound is dropped from the\n// result type and only the \"at most `max`\" guarantee is kept.\nexport function boundedLengthTuple<Max extends StructuralPrefixLength, A>(\n min: number,\n max: Max,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: MaxLengthTuple<Max, A>;\n }>\n >,\n): Type<MaxLengthTuple<Max, A>>;\n\n// Neither bound is in `StructuralPrefixLength` (`0..10`), so the result length is left unconstrained.\nexport function boundedLengthTuple<A>(\n min: number,\n max: number,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: readonly A[];\n }>\n >,\n): Type<readonly A[]>;\n\nexport function boundedLengthTuple<A>(\n min: number,\n max: number,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: readonly A[];\n }>\n >,\n): Type<readonly A[]> {\n type T = readonly A[];\n\n const typeName =\n options?.typeName ??\n `BoundedLengthTuple<${min}, ${max}, ${elementType.typeName}>`;\n\n const getDefaultValue = memoizeFunction(\n (): T =>\n options?.defaultValue ??\n // An array of the minimum length is the shortest value within the range.\n Arr.create(asUint32(min), elementType.defaultValue),\n );\n\n const validate: Type<T>['validate'] = (a) => {\n if (!Arr.isArray(a)) {\n return Result.err([\n createPrimitiveValidationError({\n actualValue: a,\n expectedType: 'array',\n typeName,\n details: undefined,\n }),\n ]);\n }\n\n if (a.length < min || max < a.length) {\n return Result.err([\n {\n path: [],\n actualValue: a,\n expectedType: typeName,\n typeName,\n details: {\n kind: 'array-range-length',\n minLength: min,\n maxLength: max,\n actualLength: a.length,\n },\n } satisfies ValidationError,\n ]);\n }\n\n const errors: readonly ValidationError[] = Arr.generate(function* () {\n for (const [index, el] of a.entries()) {\n const res = elementType.validate(el);\n\n if (Result.isErr(res)) {\n yield* prependIndexToValidationErrors(res.value, index);\n }\n }\n });\n\n if (Arr.isNonEmpty(errors)) {\n return Result.err(errors);\n }\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return Result.ok(a as unknown as T);\n };\n\n const fill: Type<T>['fill'] = (a) => {\n if (!Arr.isArray(a)) {\n return getDefaultValue();\n }\n\n // Trim down to at most `max`, then pad up to at least `min`.\n const capped = Arr.take(a, asUint32(max));\n\n return capped.length >= min\n ? Arr.map(capped, (el) => elementType.fill(el) satisfies A)\n : Arr.map(\n Arr.seq(asUint32(min)),\n (i) => elementType.fill(capped[i]) satisfies A,\n );\n };\n\n const prune = (a: T): T => a.map((el) => elementType.prune(el));\n\n return {\n typeName,\n get defaultValue() {\n return getDefaultValue();\n },\n fill,\n prune,\n validate,\n is: createIsFn(validate),\n cast: createCastFn(validate),\n assertIs: createAssertFn(validate),\n };\n}\n"],"names":[],"mappings":";;;;;;AA4EO,SAAS,kBAAA,CACd,GAAA,EACA,GAAA,EACA,WAAA,EACA,OAAA,EAMoB;AAGpB,EAAA,MAAM,QAAA,GACJ,SAAS,QAAA,IACT,CAAA,mBAAA,EAAsB,GAAG,CAAA,EAAA,EAAK,GAAG,CAAA,EAAA,EAAK,WAAA,CAAY,QAAQ,CAAA,CAAA,CAAA;AAE5D,EAAA,MAAM,eAAA,GAAkB,eAAA;AAAA,IACtB,MACE,OAAA,EAAS,YAAA;AAAA,IAET,IAAI,MAAA,CAAO,QAAA,CAAS,GAAG,CAAA,EAAG,YAAY,YAAY;AAAA,GACtD;AAEA,EAAA,MAAM,QAAA,GAAgC,CAAC,CAAA,KAAM;AAC3C,IAAA,IAAI,CAAC,GAAA,CAAI,OAAA,CAAQ,CAAC,CAAA,EAAG;AACnB,MAAA,OAAO,O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AI,CAAC,GAAA,CAAI,OAAA,CAAQ,CAAC,CAAA,EAAG;AACnB,MAAA,OAAO,eAAA,EAAgB;AAAA,IACzB;AAGA,IAAA,MAAM,SAAS,GAAA,CAAI,IAAA,CAAK,CAAA,EAAG,QAAA,CAAS,GAAG,CAAC,CAAA;AAExC,IAAA,OAAO,MAAA,CAAO,MAAA,IAAU,GAAA,GACpB,GAAA,CAAI,GAAA,CAAI,MAAA,EAAQ,CAAC,EAAA,KAAO,WAAA,CAAY,IAAA,CAAK,EAAE,CAAa,IACxD,GAAA,CAAI,GAAA;AAAA,MACF,GAAA,CAAI,GAAA,CAAI,QAAA,CAAS,GAAG,CAAC,CAAA;AAAA,MACrB,CAAC,CAAA,KAAM,WAAA,CAAY,IAAA,CAAK,MAAA,CAAO,CAAC,CAAC;AAAA,KACnC;AAAA,EACN,CAAA;AAEA,EAAA,MAAM,KAAA,GAAQ,CAAC,CAAA,KAAY,CAAA,CAAE,GAAA,CAAI,CAAC,EAAA,KAAO,WAAA,CAAY,KAAA,CAAM,EAAE,CAAC,CAAA;AAE9D,EAAA,OAAO;AAAA,IACL,QAAA;AAAA,IACA,IAAI,YAAA,GAAe;AACjB,MAAA,OAAO,eAAA,EAAgB;AAAA,IACzB,CAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA;AAAA,IACA,QAAA;AAAA,IACA,EAAA,EAAI,WAAW,QAAQ,CAAA;AAAA,IACvB,IAAA,EAAM,aAAa,QAAQ,CAAA;AAAA,IAC3B,QAAA,EAAU,eAAe,QAAQ;AAAA,GACnC;AACF;;;;"}
|
|
@@ -12,7 +12,7 @@ export type { FixedLengthArray } from 'ts-type-forge';
|
|
|
12
12
|
* large; prefer `fixedLengthTuple` when positional element types or a literal
|
|
13
13
|
* `length` are needed.
|
|
14
14
|
*/
|
|
15
|
-
export declare function fixedLengthArray<
|
|
15
|
+
export declare function fixedLengthArray<N extends SupportedLength, A>(size: N, elementType: Type<A>, options?: Partial<Readonly<{
|
|
16
16
|
typeName: string;
|
|
17
17
|
defaultValue: FixedLengthArray<N, A>;
|
|
18
18
|
}>>): Type<FixedLengthArray<N, A>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixed-length-array.d.mts","sourceRoot":"","sources":["../../src/array/fixed-length-array.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAOxC,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"fixed-length-array.d.mts","sourceRoot":"","sources":["../../src/array/fixed-length-array.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAOxC,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,eAAe,EAAE,CAAC,EAC3D,IAAI,EAAE,CAAC,EACP,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EAAE,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CACtC,CAAC,CACH,GACA,IAAI,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAIhC,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EAAE,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,SAAS,CAAC,EAAE,CAAC;CAC5B,CAAC,CACH,GACA,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixed-length-array.mjs","sources":["../../src/array/fixed-length-array.mts"],"sourcesContent":["import { Arr, asUint32, memoizeFunction, Result } from 'ts-data-forge';\nimport { type FixedLengthArray, type SupportedLength } from 'ts-type-forge';\nimport { type Type } from '../type.mjs';\nimport {\n createPrimitiveValidationError,\n type ValidationError,\n} from '../utils/index.mjs';\nimport { buildType, validateElements } from './build-type.mjs';\n\nexport type { FixedLengthArray } from 'ts-type-forge';\n\n/**\n * Creates a `Type` for a readonly array with exactly `size` elements, typed as\n * the branded {@link FixedLengthArray} instead of the structural tuple type\n * produced by `fixedLengthTuple`.\n *\n * Because the length constraint lives only in the brand, the element type is\n * never expanded into tuple positions, which keeps type-checking cheap even\n * when `A` is a large type. Prefer this over `fixedLengthTuple` when `A` is\n * large; prefer `fixedLengthTuple` when positional element types or a literal\n * `length` are needed.\n */\nexport function fixedLengthArray<
|
|
1
|
+
{"version":3,"file":"fixed-length-array.mjs","sources":["../../src/array/fixed-length-array.mts"],"sourcesContent":["import { Arr, asUint32, memoizeFunction, Result } from 'ts-data-forge';\nimport { type FixedLengthArray, type SupportedLength } from 'ts-type-forge';\nimport { type Type } from '../type.mjs';\nimport {\n createPrimitiveValidationError,\n type ValidationError,\n} from '../utils/index.mjs';\nimport { buildType, validateElements } from './build-type.mjs';\n\nexport type { FixedLengthArray } from 'ts-type-forge';\n\n/**\n * Creates a `Type` for a readonly array with exactly `size` elements, typed as\n * the branded {@link FixedLengthArray} instead of the structural tuple type\n * produced by `fixedLengthTuple`.\n *\n * Because the length constraint lives only in the brand, the element type is\n * never expanded into tuple positions, which keeps type-checking cheap even\n * when `A` is a large type. Prefer this over `fixedLengthTuple` when `A` is\n * large; prefer `fixedLengthTuple` when positional element types or a literal\n * `length` are needed.\n */\nexport function fixedLengthArray<N extends SupportedLength, A>(\n size: N,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: FixedLengthArray<N, A>;\n }>\n >,\n): Type<FixedLengthArray<N, A>>;\n\n// For sizes outside `SupportedLength` (`0..2048`) the length cannot be encoded in the brand,\n// so the result length is left unconstrained (`readonly A[]`).\nexport function fixedLengthArray<A>(\n size: number,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: readonly A[];\n }>\n >,\n): Type<readonly A[]>;\n\nexport function fixedLengthArray<A>(\n size: number,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: readonly A[];\n }>\n >,\n): Type<readonly A[]> {\n type T = readonly A[];\n\n const typeName =\n options?.typeName ?? `FixedLengthArray<${size}, ${elementType.typeName}>`;\n\n const getDefaultValue = memoizeFunction(\n (): T =>\n options?.defaultValue ??\n Arr.create(asUint32(size), elementType.defaultValue),\n );\n\n const validate: Type<T>['validate'] = (a) => {\n if (!Arr.isArray(a)) {\n return Result.err([\n createPrimitiveValidationError({\n actualValue: a,\n expectedType: 'array',\n typeName,\n details: undefined,\n }),\n ]);\n }\n\n if (a.length !== size) {\n return Result.err([\n {\n path: [],\n actualValue: a,\n expectedType: typeName,\n typeName,\n details: {\n kind: 'array-length',\n expectedLength: size,\n actualLength: a.length,\n },\n } satisfies ValidationError,\n ]);\n }\n\n return validateElements(a, elementType);\n };\n\n const fill: Type<T>['fill'] = (a) =>\n Arr.isArray(a)\n ? Arr.map(\n Arr.seq(asUint32(size)),\n (i) => elementType.fill(a[i]) satisfies A,\n )\n : getDefaultValue();\n\n return buildType({ typeName, getDefaultValue, validate, fill, elementType });\n}\n"],"names":[],"mappings":";;;;AA8CO,SAAS,gBAAA,CACd,IAAA,EACA,WAAA,EACA,OAAA,EAMoB;AAGpB,EAAA,MAAM,WACJ,OAAA,EAAS,QA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AO,UAAU,EAAE,QAAA,EAAU,iBAAiB,QAAA,EAAU,IAAA,EAAM,aAAa,CAAA;AAC7E;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type FixedLengthTuple, type StructuralPrefixLength } from 'ts-type-forge';
|
|
2
2
|
import { type Type } from '../type.mjs';
|
|
3
3
|
export type { FixedLengthTuple } from 'ts-type-forge';
|
|
4
|
-
export declare const fixedLengthTuple: <
|
|
4
|
+
export declare const fixedLengthTuple: <N extends StructuralPrefixLength, A>(size: N, elementType: Type<A>, options?: Partial<Readonly<{
|
|
5
5
|
typeName: string;
|
|
6
6
|
defaultValue: FixedLengthTuple<N, A>;
|
|
7
7
|
}>>) => Type<FixedLengthTuple<N, A>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixed-length-tuple.d.mts","sourceRoot":"","sources":["../../src/array/fixed-length-tuple.mts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC5B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAUxC,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"fixed-length-tuple.d.mts","sourceRoot":"","sources":["../../src/array/fixed-length-tuple.mts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC5B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAUxC,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,sBAAsB,EAAE,CAAC,QAC5D,CAAC,eACM,IAAI,CAAC,CAAC,CAAC,YACV,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CACtC,CAAC,CACH,KACA,IAAI,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAoF7B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixed-length-tuple.mjs","sources":["../../src/array/fixed-length-tuple.mts"],"sourcesContent":["import { Arr, memoizeFunction, Result } from 'ts-data-forge';\nimport {\n type FixedLengthTuple,\n type StructuralPrefixLength,\n} from 'ts-type-forge';\nimport { type Type } from '../type.mjs';\nimport {\n createAssertFn,\n createCastFn,\n createIsFn,\n createPrimitiveValidationError,\n prependIndexToValidationErrors,\n type ValidationError,\n} from '../utils/index.mjs';\n\nexport type { FixedLengthTuple } from 'ts-type-forge';\n\nexport const fixedLengthTuple = <
|
|
1
|
+
{"version":3,"file":"fixed-length-tuple.mjs","sources":["../../src/array/fixed-length-tuple.mts"],"sourcesContent":["import { Arr, memoizeFunction, Result } from 'ts-data-forge';\nimport {\n type FixedLengthTuple,\n type StructuralPrefixLength,\n} from 'ts-type-forge';\nimport { type Type } from '../type.mjs';\nimport {\n createAssertFn,\n createCastFn,\n createIsFn,\n createPrimitiveValidationError,\n prependIndexToValidationErrors,\n type ValidationError,\n} from '../utils/index.mjs';\n\nexport type { FixedLengthTuple } from 'ts-type-forge';\n\nexport const fixedLengthTuple = <N extends StructuralPrefixLength, A>(\n size: N,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: FixedLengthTuple<N, A>;\n }>\n >,\n): Type<FixedLengthTuple<N, A>> => {\n type T = FixedLengthTuple<N, A>;\n\n const typeName =\n options?.typeName ?? `FixedLengthTuple<${size}, ${elementType.typeName}>`;\n\n const getDefaultValue = memoizeFunction(\n (): T =>\n options?.defaultValue ??\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n (Arr.create(size, elementType.defaultValue) as T),\n );\n\n const validate: Type<T>['validate'] = (a) => {\n if (!Arr.isArray(a)) {\n return Result.err([\n createPrimitiveValidationError({\n actualValue: a,\n expectedType: 'array',\n typeName,\n details: undefined,\n }),\n ]);\n }\n\n if (!Arr.isFixedLengthTuple(size, a)) {\n return Result.err([\n {\n path: [],\n actualValue: a,\n expectedType: typeName,\n typeName,\n details: {\n kind: 'array-length',\n expectedLength: size,\n actualLength: a.length,\n },\n } satisfies ValidationError,\n ]);\n }\n\n const errors: readonly ValidationError[] = Arr.generate(function* () {\n for (const [index, el] of a.entries()) {\n const res = elementType.validate(el);\n\n if (Result.isErr(res)) {\n yield* prependIndexToValidationErrors(res.value, index);\n }\n }\n });\n\n if (Arr.isNonEmpty(errors)) {\n return Result.err(errors);\n }\n\n return Result.ok(a);\n };\n\n const fill: Type<T>['fill'] = (a) =>\n !Arr.isArray(a)\n ? getDefaultValue()\n : // TODO: remove as\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n (Arr.map(\n Arr.seq(size),\n (i) => elementType.fill(a[i]) satisfies A,\n ) as T);\n\n const prune = (a: T): T =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Arr.map(a, (el) => elementType.prune(el)) as T;\n\n return {\n typeName,\n get defaultValue() {\n return getDefaultValue();\n },\n fill,\n prune,\n validate,\n is: createIsFn(validate),\n cast: createCastFn(validate),\n assertIs: createAssertFn(validate),\n };\n};\n"],"names":[],"mappings":";;;;;;AAiBO,MAAM,gBAAA,GAAmB,CAC9B,IAAA,EACA,WAAA,EACA,OAAA,KAMiC;AAGjC,EAAA,MAAM,WACJ,OAAA,EAAS,QAAA,IAAY,oBAAoB,IAAI,CAAA,EAAA,EAAK,YAAY,QAAQ,CAAA,CAAA,CAAA;AAExE,EAAA,MAAM,eAAA,GAAkB,eAAA;AAAA,IACtB,MACE,OAAA,EAAS,YAAA;AAAA,IAER,GAAA,CAAI,MAAA,CAAO,IAAA,EAAM,WAAA,CAAY,YAAY;AAAA,GAC9C;AAEA,EAAA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AAC,CAAA;AAAA,EACpB,CAAA;AAEA,EAAA,MAAM,IAAA,GAAwB,CAAC,CAAA,KAC7B,CAAC,IAAI,OAAA,CAAQ,CAAC,IACV,eAAA,EAAgB;AAAA;AAAA;AAAA,IAGf,GAAA,CAAI,GAAA;AAAA,MACH,GAAA,CAAI,IAAI,IAAI,CAAA;AAAA,MACZ,CAAC,CAAA,KAAM,WAAA,CAAY,IAAA,CAAK,CAAA,CAAE,CAAC,CAAC;AAAA;AAC9B,GAAA;AAEN,EAAA,MAAM,QAAQ,CAAC,CAAA;AAAA;AAAA,IAEb,GAAA,CAAI,IAAI,CAAA,EAAG,CAAC,OAAO,WAAA,CAAY,KAAA,CAAM,EAAE,CAAC;AAAA,GAAA;AAE1C,EAAA,OAAO;AAAA,IACL,QAAA;AAAA,IACA,IAAI,YAAA,GAAe;AACjB,MAAA,OAAO,eAAA,EAAgB;AAAA,IACzB,CAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA;AAAA,IACA,QAAA;AAAA,IACA,EAAA,EAAI,WAAW,QAAQ,CAAA;AAAA,IACvB,IAAA,EAAM,aAAa,QAAQ,CAAA;AAAA,IAC3B,QAAA,EAAU,eAAe,QAAQ;AAAA,GACnC;AACF;;;;"}
|
|
@@ -10,7 +10,7 @@ export type { MaxLengthArray } from 'ts-type-forge';
|
|
|
10
10
|
* of the element type is ever constructed, which keeps type-checking cheap
|
|
11
11
|
* even when `A` is a large type.
|
|
12
12
|
*/
|
|
13
|
-
export declare function maxLengthArray<
|
|
13
|
+
export declare function maxLengthArray<N extends SupportedLength, A>(maxLength: N, elementType: Type<A>, options?: Partial<Readonly<{
|
|
14
14
|
typeName: string;
|
|
15
15
|
defaultValue: MaxLengthArray<N, A>;
|
|
16
16
|
}>>): Type<MaxLengthArray<N, A>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"max-length-array.d.mts","sourceRoot":"","sources":["../../src/array/max-length-array.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAOxC,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"max-length-array.d.mts","sourceRoot":"","sources":["../../src/array/max-length-array.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAOxC,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,eAAe,EAAE,CAAC,EACzD,SAAS,EAAE,CAAC,EACZ,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EAAE,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CACpC,CAAC,CACH,GACA,IAAI,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAI9B,wBAAgB,cAAc,CAAC,CAAC,EAC9B,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EAAE,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,SAAS,CAAC,EAAE,CAAC;CAC5B,CAAC,CACH,GACA,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"max-length-array.mjs","sources":["../../src/array/max-length-array.mts"],"sourcesContent":["import { Arr, asUint32, memoizeFunction, Result } from 'ts-data-forge';\nimport { type MaxLengthArray, type SupportedLength } from 'ts-type-forge';\nimport { type Type } from '../type.mjs';\nimport {\n createPrimitiveValidationError,\n type ValidationError,\n} from '../utils/index.mjs';\nimport { buildType, validateElements } from './build-type.mjs';\n\nexport type { MaxLengthArray } from 'ts-type-forge';\n\n/**\n * Creates a `Type` for a readonly array with at most `maxLength` elements,\n * typed as the branded {@link MaxLengthArray} instead of the union of tuple\n * types produced by `maxLengthTuple`.\n *\n * Because the length constraint lives only in the brand, no union of tuples\n * of the element type is ever constructed, which keeps type-checking cheap\n * even when `A` is a large type.\n */\nexport function maxLengthArray<
|
|
1
|
+
{"version":3,"file":"max-length-array.mjs","sources":["../../src/array/max-length-array.mts"],"sourcesContent":["import { Arr, asUint32, memoizeFunction, Result } from 'ts-data-forge';\nimport { type MaxLengthArray, type SupportedLength } from 'ts-type-forge';\nimport { type Type } from '../type.mjs';\nimport {\n createPrimitiveValidationError,\n type ValidationError,\n} from '../utils/index.mjs';\nimport { buildType, validateElements } from './build-type.mjs';\n\nexport type { MaxLengthArray } from 'ts-type-forge';\n\n/**\n * Creates a `Type` for a readonly array with at most `maxLength` elements,\n * typed as the branded {@link MaxLengthArray} instead of the union of tuple\n * types produced by `maxLengthTuple`.\n *\n * Because the length constraint lives only in the brand, no union of tuples\n * of the element type is ever constructed, which keeps type-checking cheap\n * even when `A` is a large type.\n */\nexport function maxLengthArray<N extends SupportedLength, A>(\n maxLength: N,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: MaxLengthArray<N, A>;\n }>\n >,\n): Type<MaxLengthArray<N, A>>;\n\n// For bounds outside `SupportedLength` (`0..2048`) the length cannot be encoded in the brand,\n// so the result length is left unconstrained (`readonly A[]`).\nexport function maxLengthArray<A>(\n maxLength: number,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: readonly A[];\n }>\n >,\n): Type<readonly A[]>;\n\nexport function maxLengthArray<A>(\n maxLength: number,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: readonly A[];\n }>\n >,\n): Type<readonly A[]> {\n type T = readonly A[];\n\n const typeName =\n options?.typeName ??\n `MaxLengthArray<${maxLength}, ${elementType.typeName}>`;\n\n const getDefaultValue = memoizeFunction(\n (): T =>\n options?.defaultValue ??\n // The empty array is the shortest value satisfying `length <= maxLength`.\n Arr.create(0, elementType.defaultValue),\n );\n\n const validate: Type<T>['validate'] = (a) => {\n if (!Arr.isArray(a)) {\n return Result.err([\n createPrimitiveValidationError({\n actualValue: a,\n expectedType: 'array',\n typeName,\n details: undefined,\n }),\n ]);\n }\n\n if (a.length > maxLength) {\n return Result.err([\n {\n path: [],\n actualValue: a,\n expectedType: typeName,\n typeName,\n details: {\n kind: 'array-max-length',\n maxLength,\n actualLength: a.length,\n },\n } satisfies ValidationError,\n ]);\n }\n\n return validateElements(a, elementType);\n };\n\n const fill: Type<T>['fill'] = (a) =>\n Arr.isArray(a)\n ? // Keep the input but trim down to at most `maxLength` elements.\n Arr.map(\n Arr.take(a, asUint32(maxLength)),\n (el) => elementType.fill(el) satisfies A,\n )\n : getDefaultValue();\n\n return buildType({ typeName, getDefaultValue, validate, fill, elementType });\n}\n"],"names":[],"mappings":";;;;AA4CO,SAAS,cAAA,CACd,SAAA,EACA,WAAA,EACA,OAAA,EAMoB;AAGpB,EAAA,MAAM,WACJ,OAAA,EAAS,QAAA,IACT,kBAAkB,SAAS,CAAA,EAAA,EAAK,YAAY,QAAQ,CAAA,CAAA,CAAA;AAEtD,EAAA,MAAM,eAAA,GAAkB,eAAA;AAAA,IACtB,MACE,OAAA,EAAS,YAAA;AAAA,IAET,GAAA,CAAI,MAAA,CAAO,CAAA,EAAG,WAAA,CAAY,YAAY;AAAA,GAC1C;AAEA,EAAA,MAAM,QAAA,GAAgC,CAAC,CAAA,KAAM;AAC3C,IAAA,IAAI,CAAC,GAAA,CAAI,OAAA,CAAQ,CAAC,CAAA,EAAG;AACnB,MAAA,OAAO,OAAO,GAAA,CAAI;AAAA,QAChB,8BAAA,CAA+B;AAAA,UAC7B,WAAA,EAAa,CAAA;AAAA,UACb,YAAA,EAAc,OAAA;AAAA,UACd,QAAA;AAAA,UACA,OAAA,EAAS;AAAA,SACV;AAAA,OACF,CAAA;AAAA,IACH;AAEA,IAAA,IAAI,CAAA,CAAE,SAAS,SAAA,EAAW;AACxB,MAAA,OAAO,OAAO,GAAA,CAAI;AAAA,QAChB;AAAA,UACE,MAAM,EAAC;AAAA,UACP,WAAA,EAAa,CAAA;AAAA,UACb,YAAA,EAAc,QAAA;AAAA,UACd,QAAA;AAAA,UACA,OAAA,EAAS;AAAA,YACP,IAAA,EAAM,kBAAA;AAAA,YACN,SAAA;AAAA,YACA,cAAc,CAAA,CAAE;AAAA;AAClB;AACF,OACD,CAAA;AAAA,IACH;AAEA,IAAA,OAAO,gBAAA,CAAiB,GAAG,WAAW,CAAA;AAAA,EACxC,CAAA;AAEA,EAAA,MAAM,IAAA,GAAwB,CAAC,CAAA,KAC7B,GAAA,CAAI,QAAQ,CAAC,CAAA;AAAA;AAAA,IAET,GAAA,CAAI,GAAA;AAAA,MACF,GAAA,CAAI,IAAA,CAAK,CAAA,EAAG,QAAA,CAAS,SAAS,CAAC,CAAA;AAAA,MAC/B,CAAC,EAAA,KAAO,WAAA,CAAY,IAAA,CAAK,EAAE;AAAA;AAC7B,MACA,eAAA,EAAgB;AAEtB,EAAA,OAAO,UAAU,EAAE,QAAA,EAAU,iBAAiB,QAAA,EAAU,IAAA,EAAM,aAAa,CAAA;AAC7E;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type MaxLengthTuple, type StructuralPrefixLength } from 'ts-type-forge';
|
|
2
2
|
import { type Type } from '../type.mjs';
|
|
3
3
|
export type { MaxLengthTuple } from 'ts-type-forge';
|
|
4
|
-
export declare function maxLengthTuple<
|
|
4
|
+
export declare function maxLengthTuple<N extends StructuralPrefixLength, A>(size: N, elementType: Type<A>, options?: Partial<Readonly<{
|
|
5
5
|
typeName: string;
|
|
6
6
|
defaultValue: MaxLengthTuple<N, A>;
|
|
7
7
|
}>>): Type<MaxLengthTuple<N, A>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"max-length-tuple.d.mts","sourceRoot":"","sources":["../../src/array/max-length-tuple.mts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC5B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAUxC,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"max-length-tuple.d.mts","sourceRoot":"","sources":["../../src/array/max-length-tuple.mts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC5B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAUxC,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,wBAAgB,cAAc,CAAC,CAAC,SAAS,sBAAsB,EAAE,CAAC,EAChE,IAAI,EAAE,CAAC,EACP,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EAAE,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CACpC,CAAC,CACH,GACA,IAAI,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAI9B,wBAAgB,cAAc,CAAC,CAAC,EAC9B,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EAAE,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,SAAS,CAAC,EAAE,CAAC;CAC5B,CAAC,CACH,GACA,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"max-length-tuple.mjs","sources":["../../src/array/max-length-tuple.mts"],"sourcesContent":["import { Arr, asUint32, memoizeFunction, Result } from 'ts-data-forge';\nimport {\n type MaxLengthTuple,\n type StructuralPrefixLength,\n} from 'ts-type-forge';\nimport { type Type } from '../type.mjs';\nimport {\n createAssertFn,\n createCastFn,\n createIsFn,\n createPrimitiveValidationError,\n prependIndexToValidationErrors,\n type ValidationError,\n} from '../utils/index.mjs';\n\nexport type { MaxLengthTuple } from 'ts-type-forge';\n\nexport function maxLengthTuple<
|
|
1
|
+
{"version":3,"file":"max-length-tuple.mjs","sources":["../../src/array/max-length-tuple.mts"],"sourcesContent":["import { Arr, asUint32, memoizeFunction, Result } from 'ts-data-forge';\nimport {\n type MaxLengthTuple,\n type StructuralPrefixLength,\n} from 'ts-type-forge';\nimport { type Type } from '../type.mjs';\nimport {\n createAssertFn,\n createCastFn,\n createIsFn,\n createPrimitiveValidationError,\n prependIndexToValidationErrors,\n type ValidationError,\n} from '../utils/index.mjs';\n\nexport type { MaxLengthTuple } from 'ts-type-forge';\n\nexport function maxLengthTuple<N extends StructuralPrefixLength, A>(\n size: N,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: MaxLengthTuple<N, A>;\n }>\n >,\n): Type<MaxLengthTuple<N, A>>;\n\n// For sizes outside `StructuralPrefixLength` (`0..10`) the exact length cannot be encoded in the type,\n// so the result length is left unconstrained (`readonly A[]`).\nexport function maxLengthTuple<A>(\n size: number,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: readonly A[];\n }>\n >,\n): Type<readonly A[]>;\n\nexport function maxLengthTuple<A>(\n size: number,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: readonly A[];\n }>\n >,\n): Type<readonly A[]> {\n type T = readonly A[];\n\n const typeName =\n options?.typeName ?? `MaxLengthTuple<${size}, ${elementType.typeName}>`;\n\n const getDefaultValue = memoizeFunction(\n (): T =>\n options?.defaultValue ??\n // The empty array is the shortest value satisfying `length <= size`.\n Arr.create(0, elementType.defaultValue),\n );\n\n const validate: Type<T>['validate'] = (a) => {\n if (!Arr.isArray(a)) {\n return Result.err([\n createPrimitiveValidationError({\n actualValue: a,\n expectedType: 'array',\n typeName,\n details: undefined,\n }),\n ]);\n }\n\n if (a.length > size) {\n return Result.err([\n {\n path: [],\n actualValue: a,\n expectedType: typeName,\n typeName,\n details: {\n kind: 'array-max-length',\n maxLength: size,\n actualLength: a.length,\n },\n } satisfies ValidationError,\n ]);\n }\n\n const errors: readonly ValidationError[] = Arr.generate(function* () {\n for (const [index, el] of a.entries()) {\n const res = elementType.validate(el);\n\n if (Result.isErr(res)) {\n yield* prependIndexToValidationErrors(res.value, index);\n }\n }\n });\n\n if (Arr.isNonEmpty(errors)) {\n return Result.err(errors);\n }\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return Result.ok(a as unknown as T);\n };\n\n const fill: Type<T>['fill'] = (a) =>\n Arr.isArray(a)\n ? // Keep the input but trim down to at most `size` elements.\n Arr.map(\n Arr.take(a, asUint32(size)),\n (el) => elementType.fill(el) satisfies A,\n )\n : getDefaultValue();\n\n const prune = (a: T): T => a.map((el) => elementType.prune(el));\n\n return {\n typeName,\n get defaultValue() {\n return getDefaultValue();\n },\n fill,\n prune,\n validate,\n is: createIsFn(validate),\n cast: createCastFn(validate),\n assertIs: createAssertFn(validate),\n };\n}\n"],"names":[],"mappings":";;;;;;AAyCO,SAAS,cAAA,CACd,IAAA,EACA,WAAA,EACA,OAAA,EAMoB;AAGpB,EAAA,MAAM,WACJ,OAAA,EAAS,QAAA,IAAY,kBAAkB,IAAI,CAAA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F,CAAC,CAAA;AAED,IAAA,IAAI,GAAA,CAAI,UAAA,CAAW,MAAM,CAAA,EAAG;AAC1B,MAAA,OAAO,MAAA,CAAO,IAAI,MAAM,CAAA;AAAA,IAC1B;AAGA,IAAA,OAAO,MAAA,CAAO,GAAG,CAAiB,CAAA;AAAA,EACpC,CAAA;AAEA,EAAA,MAAM,IAAA,GAAwB,CAAC,CAAA,KAC7B,GAAA,CAAI,QAAQ,CAAC,CAAA;AAAA;AAAA,IAET,GAAA,CAAI,GAAA;AAAA,MACF,GAAA,CAAI,IAAA,CAAK,CAAA,EAAG,QAAA,CAAS,IAAI,CAAC,CAAA;AAAA,MAC1B,CAAC,EAAA,KAAO,WAAA,CAAY,IAAA,CAAK,EAAE;AAAA;AAC7B,MACA,eAAA,EAAgB;AAEtB,EAAA,MAAM,KAAA,GAAQ,CAAC,CAAA,KAAY,CAAA,CAAE,GAAA,CAAI,CAAC,EAAA,KAAO,WAAA,CAAY,KAAA,CAAM,EAAE,CAAC,CAAA;AAE9D,EAAA,OAAO;AAAA,IACL,QAAA;AAAA,IACA,IAAI,YAAA,GAAe;AACjB,MAAA,OAAO,eAAA,EAAgB;AAAA,IACzB,CAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA;AAAA,IACA,QAAA;AAAA,IACA,EAAA,EAAI,WAAW,QAAQ,CAAA;AAAA,IACvB,IAAA,EAAM,aAAa,QAAQ,CAAA;AAAA,IAC3B,QAAA,EAAU,eAAe,QAAQ;AAAA,GACnC;AACF;;;;"}
|
|
@@ -10,7 +10,7 @@ export type { MinLengthArray } from 'ts-type-forge';
|
|
|
10
10
|
* never expanded into tuple positions, which keeps type-checking cheap even
|
|
11
11
|
* when `A` is a large type.
|
|
12
12
|
*/
|
|
13
|
-
export declare function minLengthArray<
|
|
13
|
+
export declare function minLengthArray<N extends SupportedLength, A>(minLength: N, elementType: Type<A>, options?: Partial<Readonly<{
|
|
14
14
|
typeName: string;
|
|
15
15
|
defaultValue: MinLengthArray<N, A>;
|
|
16
16
|
}>>): Type<MinLengthArray<N, A>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"min-length-array.d.mts","sourceRoot":"","sources":["../../src/array/min-length-array.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAOxC,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"min-length-array.d.mts","sourceRoot":"","sources":["../../src/array/min-length-array.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAOxC,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,eAAe,EAAE,CAAC,EACzD,SAAS,EAAE,CAAC,EACZ,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EAAE,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CACpC,CAAC,CACH,GACA,IAAI,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAI9B,wBAAgB,cAAc,CAAC,CAAC,EAC9B,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EAAE,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,SAAS,CAAC,EAAE,CAAC;CAC5B,CAAC,CACH,GACA,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"min-length-array.mjs","sources":["../../src/array/min-length-array.mts"],"sourcesContent":["import { Arr, asUint32, memoizeFunction, Result } from 'ts-data-forge';\nimport { type MinLengthArray, type SupportedLength } from 'ts-type-forge';\nimport { type Type } from '../type.mjs';\nimport {\n createPrimitiveValidationError,\n type ValidationError,\n} from '../utils/index.mjs';\nimport { buildType, validateElements } from './build-type.mjs';\n\nexport type { MinLengthArray } from 'ts-type-forge';\n\n/**\n * Creates a `Type` for a readonly array with at least `minLength` elements,\n * typed as the branded {@link MinLengthArray} instead of the structural\n * `readonly [A, ..., A, ...A[]]` type produced by `minLengthTuple`.\n *\n * Because the length constraint lives only in the brand, the element type is\n * never expanded into tuple positions, which keeps type-checking cheap even\n * when `A` is a large type.\n */\nexport function minLengthArray<
|
|
1
|
+
{"version":3,"file":"min-length-array.mjs","sources":["../../src/array/min-length-array.mts"],"sourcesContent":["import { Arr, asUint32, memoizeFunction, Result } from 'ts-data-forge';\nimport { type MinLengthArray, type SupportedLength } from 'ts-type-forge';\nimport { type Type } from '../type.mjs';\nimport {\n createPrimitiveValidationError,\n type ValidationError,\n} from '../utils/index.mjs';\nimport { buildType, validateElements } from './build-type.mjs';\n\nexport type { MinLengthArray } from 'ts-type-forge';\n\n/**\n * Creates a `Type` for a readonly array with at least `minLength` elements,\n * typed as the branded {@link MinLengthArray} instead of the structural\n * `readonly [A, ..., A, ...A[]]` type produced by `minLengthTuple`.\n *\n * Because the length constraint lives only in the brand, the element type is\n * never expanded into tuple positions, which keeps type-checking cheap even\n * when `A` is a large type.\n */\nexport function minLengthArray<N extends SupportedLength, A>(\n minLength: N,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: MinLengthArray<N, A>;\n }>\n >,\n): Type<MinLengthArray<N, A>>;\n\n// For bounds outside `SupportedLength` (`0..2048`) the length cannot be encoded in the brand,\n// so the result length is left unconstrained (`readonly A[]`).\nexport function minLengthArray<A>(\n minLength: number,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: readonly A[];\n }>\n >,\n): Type<readonly A[]>;\n\nexport function minLengthArray<A>(\n minLength: number,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: readonly A[];\n }>\n >,\n): Type<readonly A[]> {\n type T = readonly A[];\n\n const typeName =\n options?.typeName ??\n `MinLengthArray<${minLength}, ${elementType.typeName}>`;\n\n const getDefaultValue = memoizeFunction(\n (): T =>\n options?.defaultValue ??\n // An array of `minLength` elements is the shortest value satisfying the bound.\n Arr.create(asUint32(minLength), elementType.defaultValue),\n );\n\n const validate: Type<T>['validate'] = (a) => {\n if (!Arr.isArray(a)) {\n return Result.err([\n createPrimitiveValidationError({\n actualValue: a,\n expectedType: 'array',\n typeName,\n details: undefined,\n }),\n ]);\n }\n\n if (a.length < minLength) {\n return Result.err([\n {\n path: [],\n actualValue: a,\n expectedType: typeName,\n typeName,\n details: {\n kind: 'array-min-length',\n minLength,\n actualLength: a.length,\n },\n } satisfies ValidationError,\n ]);\n }\n\n return validateElements(a, elementType);\n };\n\n const fill: Type<T>['fill'] = (a) => {\n if (!Arr.isArray(a)) {\n return getDefaultValue();\n }\n\n // Keep the input if it is long enough; otherwise pad up to `minLength`.\n return a.length >= minLength\n ? Arr.map(a, (el) => elementType.fill(el) satisfies A)\n : Arr.map(\n Arr.seq(asUint32(minLength)),\n (i) => elementType.fill(a[i]) satisfies A,\n );\n };\n\n return buildType({ typeName, getDefaultValue, validate, fill, elementType });\n}\n"],"names":[],"mappings":";;;;AA4CO,SAAS,cAAA,CACd,SAAA,EACA,WAAA,EACA,OAAA,EAMoB;AAGpB,EAAA,MAAM,WACJ,OAAA,EAAS,QAAA,IACT,kBAAkB,SAAS,CAAA,EAAA,EAAK,YAAY,QAAQ,CAAA,CAAA,CAAA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,CAAI,QAAA,CAAS,SAAS,CAAC,CAAA;AAAA,MAC3B,CAAC,CAAA,KAAM,WAAA,CAAY,IAAA,CAAK,CAAA,CAAE,CAAC,CAAC;AAAA,KAC9B;AAAA,EACN,CAAA;AAEA,EAAA,OAAO,UAAU,EAAE,QAAA,EAAU,iBAAiB,QAAA,EAAU,IAAA,EAAM,aAAa,CAAA;AAC7E;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type MinLengthTuple, type StructuralPrefixLength } from 'ts-type-forge';
|
|
2
2
|
import { type Type } from '../type.mjs';
|
|
3
3
|
export type { MinLengthTuple } from 'ts-type-forge';
|
|
4
|
-
export declare function minLengthTuple<
|
|
4
|
+
export declare function minLengthTuple<N extends StructuralPrefixLength, A>(size: N, elementType: Type<A>, options?: Partial<Readonly<{
|
|
5
5
|
typeName: string;
|
|
6
6
|
defaultValue: MinLengthTuple<N, A>;
|
|
7
7
|
}>>): Type<MinLengthTuple<N, A>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"min-length-tuple.d.mts","sourceRoot":"","sources":["../../src/array/min-length-tuple.mts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC5B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAUxC,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"min-length-tuple.d.mts","sourceRoot":"","sources":["../../src/array/min-length-tuple.mts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC5B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAUxC,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,wBAAgB,cAAc,CAAC,CAAC,SAAS,sBAAsB,EAAE,CAAC,EAChE,IAAI,EAAE,CAAC,EACP,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EAAE,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CACpC,CAAC,CACH,GACA,IAAI,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAI9B,wBAAgB,cAAc,CAAC,CAAC,EAC9B,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EAAE,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,SAAS,CAAC,EAAE,CAAC;CAC5B,CAAC,CACH,GACA,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"min-length-tuple.mjs","sources":["../../src/array/min-length-tuple.mts"],"sourcesContent":["import { Arr, asUint32, memoizeFunction, Result } from 'ts-data-forge';\nimport {\n type MinLengthTuple,\n type StructuralPrefixLength,\n} from 'ts-type-forge';\nimport { type Type } from '../type.mjs';\nimport {\n createAssertFn,\n createCastFn,\n createIsFn,\n createPrimitiveValidationError,\n prependIndexToValidationErrors,\n type ValidationError,\n} from '../utils/index.mjs';\n\nexport type { MinLengthTuple } from 'ts-type-forge';\n\nexport function minLengthTuple<
|
|
1
|
+
{"version":3,"file":"min-length-tuple.mjs","sources":["../../src/array/min-length-tuple.mts"],"sourcesContent":["import { Arr, asUint32, memoizeFunction, Result } from 'ts-data-forge';\nimport {\n type MinLengthTuple,\n type StructuralPrefixLength,\n} from 'ts-type-forge';\nimport { type Type } from '../type.mjs';\nimport {\n createAssertFn,\n createCastFn,\n createIsFn,\n createPrimitiveValidationError,\n prependIndexToValidationErrors,\n type ValidationError,\n} from '../utils/index.mjs';\n\nexport type { MinLengthTuple } from 'ts-type-forge';\n\nexport function minLengthTuple<N extends StructuralPrefixLength, A>(\n size: N,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: MinLengthTuple<N, A>;\n }>\n >,\n): Type<MinLengthTuple<N, A>>;\n\n// For sizes outside `StructuralPrefixLength` (`0..10`) the exact length cannot be encoded in the type,\n// so the result length is left unconstrained (`readonly A[]`).\nexport function minLengthTuple<A>(\n size: number,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: readonly A[];\n }>\n >,\n): Type<readonly A[]>;\n\nexport function minLengthTuple<A>(\n size: number,\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: readonly A[];\n }>\n >,\n): Type<readonly A[]> {\n type T = readonly A[];\n\n const typeName =\n options?.typeName ?? `MinLengthTuple<${size}, ${elementType.typeName}>`;\n\n const getDefaultValue = memoizeFunction(\n (): T =>\n options?.defaultValue ??\n // An array of `size` elements is the shortest value satisfying the bound.\n Arr.create(asUint32(size), elementType.defaultValue),\n );\n\n const validate: Type<T>['validate'] = (a) => {\n if (!Arr.isArray(a)) {\n return Result.err([\n createPrimitiveValidationError({\n actualValue: a,\n expectedType: 'array',\n typeName,\n details: undefined,\n }),\n ]);\n }\n\n if (a.length < size) {\n return Result.err([\n {\n path: [],\n actualValue: a,\n expectedType: typeName,\n typeName,\n details: {\n kind: 'array-min-length',\n minLength: size,\n actualLength: a.length,\n },\n } satisfies ValidationError,\n ]);\n }\n\n const errors: readonly ValidationError[] = Arr.generate(function* () {\n for (const [index, el] of a.entries()) {\n const res = elementType.validate(el);\n\n if (Result.isErr(res)) {\n yield* prependIndexToValidationErrors(res.value, index);\n }\n }\n });\n\n if (Arr.isNonEmpty(errors)) {\n return Result.err(errors);\n }\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return Result.ok(a as unknown as T);\n };\n\n const fill: Type<T>['fill'] = (a) =>\n Arr.isArray(a)\n ? Arr.map(\n Arr.seq(asUint32(size)),\n (i) => elementType.fill(a[i]) satisfies A,\n )\n : getDefaultValue();\n\n const prune = (a: T): T => a.map((el) => elementType.prune(el));\n\n return {\n typeName,\n get defaultValue() {\n return getDefaultValue();\n },\n fill,\n prune,\n validate,\n is: createIsFn(validate),\n cast: createCastFn(validate),\n assertIs: createAssertFn(validate),\n };\n}\n"],"names":[],"mappings":";;;;;;AAyCO,SAAS,cAAA,CACd,IAAA,EACA,WAAA,EACA,OAAA,EAMoB;AAGpB,EAAA,MAAM,WACJ,OAAA,EAAS,QAAA,IAAY,kBAAkB,IAAI,CAAA,EAAA,EAAK,YAAY,QAAQ,CAAA,CAAA,CAAA;AAEtE,EAAA,MAAM,eAAA,GAAkB,eAAA;AAAA,IACtB,MACE,OAAA,EAAS,YAAA;AAAA,IAET,IAAI,MAAA,CAAO,QAAA,CAAS,IAAI,CAAA,EAAG,YAAY,YAAY;AAAA,GACvD;AAEA,EAAA,MAAM,QAAA,GAAgC,CAAC,CAAA,KAAM;AAC3C,IAAA,IAAI,CAAC,GAAA,CAAI,OAAA,CAAQ,CAAC,CAAA,EAAG;AACnB,MAAA,OAAO,OAAO,GAAA,CAAI;AAAA,QAChB,8BAAA,CAA+B;AAAA,UAC7B,WAAA,EAAa,CAAA;AAAA,UACb,YAAA,EAAc,OAAA;AAAA,UACd,QAAA;AAAA,UACA,OAAA,EAAS;AAAA,SACV;AAAA,OACF,CAAA;AAAA,IACH;AAEA,IAAA,IAAI,CAAA,CAAE,SAAS,IAAA,EAAM;AACnB,MAAA,OAAO,OAAO,GAAA,CAAI;AAAA,QAChB;AAAA,UACE,MAAM,EAAC;AAAA,UACP,WAAA,EAAa,CAAA;AAAA,UACb,YAAA,EAAc,QAAA;AAAA,UACd,QAAA;AAAA,UACA,OAAA,EAAS;AAAA,YACP,IAAA,EAAM,kBAAA;AAAA,YACN,SAAA,EAAW,IAAA;AAAA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AAQ,CAAA;AAAA,IACvB,IAAA,EAAM,aAAa,QAAQ,CAAA;AAAA,IAC3B,QAAA,EAAU,eAAe,QAAQ;AAAA,GACnC;AACF;;;;"}
|
|
@@ -44,7 +44,7 @@ const nonEmptyArray = (elementType, options) => {
|
|
|
44
44
|
}
|
|
45
45
|
return Result.ok(a);
|
|
46
46
|
};
|
|
47
|
-
const fill = (a) => Arr.isArray(a) && Arr.
|
|
47
|
+
const fill = (a) => Arr.isArray(a) && Arr.isNonEmpty(a) ? Arr.map(a, (e) => elementType.fill(e)) : getDefaultValue();
|
|
48
48
|
return buildType({
|
|
49
49
|
typeName,
|
|
50
50
|
getDefaultValue,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"non-empty-array.mjs","sources":["../../src/array/non-empty-array.mts"],"sourcesContent":["import { Arr, memoizeFunction, Result } from 'ts-data-forge';\nimport { type NonEmptyArray, type NonEmptyTuple } from 'ts-type-forge';\nimport { type Type } from '../type.mjs';\nimport {\n createPrimitiveValidationError,\n prependIndexToValidationErrors,\n type ValidationError,\n} from '../utils/index.mjs';\nimport { buildType } from './build-type.mjs';\n\nexport type { NonEmptyArray } from 'ts-type-forge';\n\nexport const nonEmptyArray = <A,>(\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: NonEmptyTuple<A>;\n }>\n >,\n): Type<NonEmptyArray<A>> => {\n const typeName =\n options?.typeName ?? `NonEmptyArray<${elementType.typeName}>`;\n\n const getDefaultValue = memoizeFunction(\n (): readonly A[] =>\n options?.defaultValue ?? Arr.newArray(1, elementType.defaultValue),\n );\n\n const validate = (\n a: unknown,\n ): Result<readonly A[], readonly ValidationError[]> => {\n if (!Arr.isArray(a)) {\n return Result.err([\n createPrimitiveValidationError({\n actualValue: a,\n expectedType: 'array',\n typeName,\n details: undefined,\n }),\n ]);\n }\n\n if (Arr.isEmpty(a)) {\n return Result.err([\n {\n path: [],\n actualValue: a,\n expectedType: typeName,\n typeName,\n details: {\n kind: 'non-empty-array',\n },\n } satisfies ValidationError,\n ]);\n }\n\n const errors: readonly ValidationError[] = Arr.generate(function* () {\n for (const [index, el] of a.entries()) {\n const res = elementType.validate(el);\n\n if (Result.isErr(res)) {\n yield* prependIndexToValidationErrors(res.value, index);\n }\n }\n });\n\n if (Arr.isNonEmpty(errors)) {\n return Result.err(errors);\n }\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return Result.ok(a as readonly A[]);\n };\n\n const fill = (a: unknown): readonly A[] =>\n Arr.isArray(a) && Arr.
|
|
1
|
+
{"version":3,"file":"non-empty-array.mjs","sources":["../../src/array/non-empty-array.mts"],"sourcesContent":["import { Arr, memoizeFunction, Result } from 'ts-data-forge';\nimport { type NonEmptyArray, type NonEmptyTuple } from 'ts-type-forge';\nimport { type Type } from '../type.mjs';\nimport {\n createPrimitiveValidationError,\n prependIndexToValidationErrors,\n type ValidationError,\n} from '../utils/index.mjs';\nimport { buildType } from './build-type.mjs';\n\nexport type { NonEmptyArray } from 'ts-type-forge';\n\nexport const nonEmptyArray = <A,>(\n elementType: Type<A>,\n options?: Partial<\n Readonly<{\n typeName: string;\n defaultValue: NonEmptyTuple<A>;\n }>\n >,\n): Type<NonEmptyArray<A>> => {\n const typeName =\n options?.typeName ?? `NonEmptyArray<${elementType.typeName}>`;\n\n const getDefaultValue = memoizeFunction(\n (): readonly A[] =>\n options?.defaultValue ?? Arr.newArray(1, elementType.defaultValue),\n );\n\n const validate = (\n a: unknown,\n ): Result<readonly A[], readonly ValidationError[]> => {\n if (!Arr.isArray(a)) {\n return Result.err([\n createPrimitiveValidationError({\n actualValue: a,\n expectedType: 'array',\n typeName,\n details: undefined,\n }),\n ]);\n }\n\n if (Arr.isEmpty(a)) {\n return Result.err([\n {\n path: [],\n actualValue: a,\n expectedType: typeName,\n typeName,\n details: {\n kind: 'non-empty-array',\n },\n } satisfies ValidationError,\n ]);\n }\n\n const errors: readonly ValidationError[] = Arr.generate(function* () {\n for (const [index, el] of a.entries()) {\n const res = elementType.validate(el);\n\n if (Result.isErr(res)) {\n yield* prependIndexToValidationErrors(res.value, index);\n }\n }\n });\n\n if (Arr.isNonEmpty(errors)) {\n return Result.err(errors);\n }\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return Result.ok(a as readonly A[]);\n };\n\n const fill = (a: unknown): readonly A[] =>\n Arr.isArray(a) && Arr.isNonEmpty(a)\n ? Arr.map(a, (e) => elementType.fill(e) satisfies A)\n : getDefaultValue();\n\n return buildType<A, NonEmptyArray<A>>({\n typeName,\n getDefaultValue,\n validate,\n fill,\n elementType,\n });\n};\n"],"names":[],"mappings":";;;;AAYO,MAAM,aAAA,GAAgB,CAC3B,WAAA,EACA,OAAA,KAM2B;AAC3B,EAAA,MAAM,QAAA,GACJ,OAAA,EAAS,QAAA,IAAY,CAAA,cAAA,EAAiB,YAAY,QAAQ,CAAA,CAAA,CAAA;AAE5D,EAAA,MAAM,eAAA,GAAkB,eAAA;AAAA,IACtB,MACE,OAAA,EAAS,YAAA,IAAgB,IAAI,QAAA,CAAS,CAAA,EAAG,YAAY,YAAY;AAAA,GACrE;AAEA,EAAA,MAAM,QAAA,GAAW,CACf,CAAA,KACqD;AACrD,IAAA,IAAI,CAAC,GAAA,CAAI,OAAA,CAAQ,CAAC,CAAA,EAAG;AACnB,MAAA,OAAO,OAAO,GAAA,CAAI;AAAA,QAChB,8BAAA,CAA+B;AAAA,UAC7B,WAAA,EAAa,CAAA;AAAA,UACb,YAAA,EAAc,OAAA;AAAA,UACd,QAAA;AAAA,UACA,OAAA,EAAS;AAAA,SACV;AAAA,OACF,CAAA;AAAA,IACH;AAEA,IAAA,IAAI,GAAA,CAAI,OAAA,CAAQ,CAAC,CAAA,EAAG;AAClB,MAAA,OAAO,OAAO,GAAA,CAAI;AAAA,QAChB;AAAA,UACE,MAAM,EAAC;AAAA,UACP,WAAA,EAAa,CAAA;AAAA,UACb,YAAA,EAAc,QAAA;AAAA,UACd,QAAA;AAAA,UACA,OAAA,EAAS;AAAA,YACP,IAAA,EAAM;AAAA;AACR;AACF,OACD,CAAA;AAAA,IACH;AAEA,IAAA,MAAM,MAAA,GAAqC,GAAA,CAAI,QAAA,CAAS,aAAa;AACnE,MAAA,KAAA,MAAW,CAAC,KAAA,EAAO,EAAE,CAAA,IAAK,CAAA,CAAE,SAAQ,EAAG;AACrC,QAAA,MAAM,GAAA,GAAM,WAAA,CAAY,QAAA,CAAS,EAAE,CAAA;AAEnC,QAAA,IAAI,MAAA,CAAO,KAAA,CAAM,GAAG,CAAA,EAAG;AACrB,UAAA,OAAO,8BAAA,CAA+B,GAAA,CAAI,KAAA,EAAO,KAAK,CAAA;AAAA,QACxD;AAAA,MACF;AAAA,IACF,CAAC,CAAA;AAED,IAAA,IAAI,GAAA,CAAI,UAAA,CAAW,MAAM,CAAA,EAAG;AAC1B,MAAA,OAAO,MAAA,CAAO,IAAI,MAAM,CAAA;AAAA,IAC1B;AAGA,IAAA,OAAO,MAAA,CAAO,GAAG,CAAiB,CAAA;AAAA,EACpC,CAAA;AAEA,EAAA,MAAM,IAAA,GAAO,CAAC,CAAA,KACZ,GAAA,CAAI,QAAQ,CAAC,CAAA,IAAK,IAAI,UAAA,CAAW,CAAC,IAC9B,GAAA,CAAI,GAAA,CAAI,GAAG,CAAC,CAAA,KAAM,YAAY,IAAA,CAAK,CAAC,CAAa,CAAA,GACjD,eAAA,EAAgB;AAEtB,EAAA,OAAO,SAAA,CAA+B;AAAA,IACpC,QAAA;AAAA,IACA,eAAA;AAAA,IACA,QAAA;AAAA,IACA,IAAA;AAAA,IACA;AAAA,GACD,CAAA;AACH;;;;"}
|
package/dist/array/tuple.mjs
CHANGED
|
@@ -7,12 +7,10 @@ import { createPrimitiveValidationError, prependIndexToValidationErrors } from '
|
|
|
7
7
|
const tuple = (types, options) => {
|
|
8
8
|
const typeName = options?.typeName ?? "tuple";
|
|
9
9
|
const getDefaultValue = memoizeFunction(
|
|
10
|
-
()
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Arr.map(types, (t) => t.defaultValue)
|
|
15
|
-
)
|
|
10
|
+
// `types` is bound by `AnyType` (payload `any`), so element accessors are
|
|
11
|
+
// typed `any` inside this generic body; the outer signature keeps it precise.
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
13
|
+
() => Arr.map(types, (t) => t.defaultValue)
|
|
16
14
|
);
|
|
17
15
|
const validate = (a) => {
|
|
18
16
|
if (!Arr.isArray(a)) {
|
|
@@ -41,8 +39,8 @@ const tuple = (types, options) => {
|
|
|
41
39
|
]);
|
|
42
40
|
}
|
|
43
41
|
const errors = Arr.generate(function* () {
|
|
44
|
-
for (const [index,
|
|
45
|
-
const res = typeDef.validate(
|
|
42
|
+
for (const [index, typeDef] of types.entries()) {
|
|
43
|
+
const res = typeDef.validate(a[index]);
|
|
46
44
|
if (Result.isErr(res)) {
|
|
47
45
|
yield* prependIndexToValidationErrors(res.value, index);
|
|
48
46
|
}
|
package/dist/array/tuple.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tuple.mjs","sources":["../../src/array/tuple.mts"],"sourcesContent":["import { Arr, memoizeFunction, Result } from 'ts-data-forge';\nimport {\n type AnyType,\n type TupleTypeInternals,\n type Type,\n type TypeOf,\n} from '../type.mjs';\nimport {\n createAssertFn,\n createCastFn,\n createIsFn,\n createPrimitiveValidationError,\n prependIndexToValidationErrors,\n type ValidationError,\n} from '../utils/index.mjs';\n\ntype MapTuple<T extends readonly AnyType[]> = Readonly<{\n [K in keyof T]: TypeOf<T[K]>;\n}>;\n\nexport const tuple = <const A extends readonly AnyType[]>(\n types: A,\n options?: Partial<\n Readonly<{\n typeName: string;\n }>\n >,\n): Type<MapTuple<A>> => {\n type T = MapTuple<A>;\n\n const typeName = options?.typeName ?? 'tuple';\n\n const getDefaultValue = memoizeFunction(
|
|
1
|
+
{"version":3,"file":"tuple.mjs","sources":["../../src/array/tuple.mts"],"sourcesContent":["import { Arr, memoizeFunction, Result } from 'ts-data-forge';\nimport {\n type AnyType,\n type TupleTypeInternals,\n type Type,\n type TypeOf,\n} from '../type.mjs';\nimport {\n createAssertFn,\n createCastFn,\n createIsFn,\n createPrimitiveValidationError,\n prependIndexToValidationErrors,\n type ValidationError,\n} from '../utils/index.mjs';\n\ntype MapTuple<T extends readonly AnyType[]> = Readonly<{\n [K in keyof T]: TypeOf<T[K]>;\n}>;\n\nexport const tuple = <const A extends readonly AnyType[]>(\n types: A,\n options?: Partial<\n Readonly<{\n typeName: string;\n }>\n >,\n): Type<MapTuple<A>> => {\n type T = MapTuple<A>;\n\n const typeName = options?.typeName ?? 'tuple';\n\n const getDefaultValue = memoizeFunction(\n // `types` is bound by `AnyType` (payload `any`), so element accessors are\n // typed `any` inside this generic body; the outer signature keeps it precise.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n (): MapTuple<A> => Arr.map(types, (t) => t.defaultValue),\n );\n\n const validate: Type<T>['validate'] = (a) => {\n if (!Arr.isArray(a)) {\n return Result.err([\n createPrimitiveValidationError({\n actualValue: a,\n expectedType: 'array',\n typeName,\n details: undefined,\n }),\n ]);\n }\n\n if (a.length !== types.length) {\n return Result.err([\n {\n path: [],\n actualValue: a,\n expectedType: typeName,\n typeName,\n details: {\n kind: 'tuple-length',\n expectedLength: types.length,\n actualLength: a.length,\n },\n } satisfies ValidationError,\n ]);\n }\n\n const errors: readonly ValidationError[] = Arr.generate(function* () {\n for (const [index, typeDef] of types.entries()) {\n const res = typeDef.validate(a[index]);\n\n if (Result.isErr(res)) {\n yield* prependIndexToValidationErrors(res.value, index);\n }\n }\n });\n\n if (Arr.isNonEmpty(errors)) {\n return Result.err(errors);\n }\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return Result.ok(a as T);\n };\n\n const fill: Type<T>['fill'] = (a) =>\n !Arr.isArray(a)\n ? getDefaultValue()\n : // eslint-disable-next-line total-functions/no-unsafe-type-assertion, @typescript-eslint/no-unsafe-return\n (types.map((t, i) => t.fill(a[i])) as MapTuple<A>);\n\n const prune = (a: T): T =>\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n Arr.map(types, (t, i) => t.prune(a[i]));\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return {\n typeName,\n get defaultValue() {\n return getDefaultValue();\n },\n fill,\n prune,\n validate,\n is: createIsFn(validate),\n assertIs: createAssertFn(validate),\n cast: createCastFn(validate),\n // Retain the element types so that `at(tupleType, index)` can recover the\n // Type at a given position.\n elementTypes: types,\n } satisfies Type<T> & TupleTypeInternals as Type<T>;\n};\n"],"names":[],"mappings":";;;;;;AAoBO,MAAM,KAAA,GAAQ,CACnB,KAAA,EACA,OAAA,KAKsB;AAGtB,EAAA,MAAM,QAAA,GAAW,SAAS,QAAA,IAAY,OAAA;AAEtC,EAAA,MAAM,eAAA,GAAkB,eAAA;AAAA;AAAA;AAAA;AAAA,IAItB,MAAmB,GAAA,CAAI,GAAA,CAAI,OAAO,CAAC,CAAA,KAAM,EAAE,YAAY;AAAA,GACzD;AAEA,EAAA,MAAM,QAAA,GAAgC,CAAC,CAAA,KAAM;AAC3C,IAAA,IAAI,CAAC,GAAA,CAAI,OAAA,CAAQ,CAAC,CAAA,EAAG;AACnB,MAAA,OAAO,OAAO,GAAA,CAAI;AAAA,QAChB,8BAAA,CAA+B;AAAA,UAC7B,WAAA,EAAa,CAAA;AAAA,UACb,YAAA,EAAc,OAAA;AAAA,UACd,QAAA;AAAA,UACA,OAAA,EAAS;AAAA,SACV;AAAA,OACF,CAAA;AAAA,IACH;AAEA,IAAA,IAAI,CAAA,CAAE,MAAA,KAAW,KAAA,CAAM,MAAA,EAAQ;AAC7B,MAAA,OAAO,OAAO,GAAA,CAAI;AAAA,QAChB;AAAA,UACE,MAAM,EAAC;AAAA,UACP,WAAA,EAAa,CAAA;AAAA,UACb,YAAA,EAAc,QAAA;AAAA,UACd,QAAA;AAAA,UACA,OAAA,EAAS;AAAA,YACP,IAAA,EAAM,c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zB,CAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA;AAAA,IACA,QAAA;AAAA,IACA,EAAA,EAAI,WAAW,QAAQ,CAAA;AAAA,IACvB,QAAA,EAAU,eAAe,QAAQ,CAAA;AAAA,IACjC,IAAA,EAAM,aAAa,QAAQ,CAAA;AAAA;AAAA;AAAA,IAG3B,YAAA,EAAc;AAAA,GAChB;AACF;;;;"}
|
|
@@ -62,7 +62,7 @@ const intersection = (types, defaultType, options) => {
|
|
|
62
62
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion, @typescript-eslint/no-unsafe-return
|
|
63
63
|
types.map((t) => t.prune(a)).reduce(mergePruned, {})
|
|
64
64
|
),
|
|
65
|
-
shapeStructure: Arr.isFixedLengthTuple(
|
|
65
|
+
shapeStructure: Arr.isFixedLengthTuple(1, shapeStructures) ? shapeStructures[0] : { kind: "intersection", parts: shapeStructures },
|
|
66
66
|
excessProperty
|
|
67
67
|
};
|
|
68
68
|
}
|