@sinclair/typebox 0.34.21 → 0.34.23
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/build/cjs/index.d.ts +0 -1
- package/build/cjs/index.js +0 -1
- package/build/cjs/syntax/runtime.js +10 -3
- package/build/cjs/syntax/static.d.ts +1 -1
- package/build/cjs/type/instantiate/instantiate.d.ts +43 -18
- package/build/cjs/type/instantiate/instantiate.js +104 -17
- package/build/cjs/type/partial/partial.d.ts +10 -1
- package/build/cjs/type/partial/partial.js +25 -12
- package/build/cjs/type/required/required.d.ts +10 -1
- package/build/cjs/type/required/required.js +21 -8
- package/build/cjs/type/type/type.d.ts +0 -1
- package/build/cjs/type/type/type.js +30 -32
- package/build/esm/index.d.mts +0 -1
- package/build/esm/index.mjs +0 -1
- package/build/esm/syntax/runtime.mjs +10 -3
- package/build/esm/syntax/static.d.mts +1 -1
- package/build/esm/type/instantiate/instantiate.d.mts +43 -18
- package/build/esm/type/instantiate/instantiate.mjs +103 -17
- package/build/esm/type/partial/partial.d.mts +10 -1
- package/build/esm/type/partial/partial.mjs +25 -12
- package/build/esm/type/required/required.d.mts +10 -1
- package/build/esm/type/required/required.mjs +21 -8
- package/build/esm/type/type/type.d.mts +0 -1
- package/build/esm/type/type/type.mjs +0 -1
- package/package.json +1 -1
- package/readme.md +79 -64
- package/build/cjs/type/remap/index.d.ts +0 -1
- package/build/cjs/type/remap/index.js +0 -18
- package/build/cjs/type/remap/remap.d.ts +0 -30
- package/build/cjs/type/remap/remap.js +0 -47
- package/build/esm/type/remap/index.d.mts +0 -1
- package/build/esm/type/remap/index.mjs +0 -1
- package/build/esm/type/remap/remap.d.mts +0 -30
- package/build/esm/type/remap/remap.mjs +0 -43
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
-
};
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
__exportStar(require("./remap"), exports);
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { TSchema } from '../schema/index';
|
|
2
|
-
import { TObject, TProperties } from '../object/index';
|
|
3
|
-
import { TConstructor } from '../constructor/index';
|
|
4
|
-
import { TFunction } from '../function/index';
|
|
5
|
-
import { TIntersect } from '../intersect/index';
|
|
6
|
-
import { TUnion } from '../union/index';
|
|
7
|
-
import { TTuple } from '../tuple/index';
|
|
8
|
-
import { TArray } from '../array/index';
|
|
9
|
-
import { TAsyncIterator } from '../async-iterator/index';
|
|
10
|
-
import { TIterator } from '../iterator/index';
|
|
11
|
-
import { TPromise } from '../promise/index';
|
|
12
|
-
import { TRecord, TRecordOrObject } from '../record/index';
|
|
13
|
-
export type TCallback = (schema: TSchema) => TSchema;
|
|
14
|
-
export interface TMapping {
|
|
15
|
-
input: unknown;
|
|
16
|
-
output: unknown;
|
|
17
|
-
}
|
|
18
|
-
type TApply<Type extends TSchema, Mapping extends TMapping, Mapped = (Mapping & {
|
|
19
|
-
input: Type;
|
|
20
|
-
})['output'], Result = Mapped extends TSchema ? Mapped : never> = Result;
|
|
21
|
-
type TFromProperties<Properties extends TProperties, Mapping extends TMapping, Result extends TProperties = {
|
|
22
|
-
[Key in keyof Properties]: TRemap<Properties[Key], Mapping>;
|
|
23
|
-
}> = Result;
|
|
24
|
-
type TFromTypes<Types extends TSchema[], Mapping extends TMapping, Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromTypes<Right, Mapping, [...Result, TRemap<Left, Mapping>]> : Result);
|
|
25
|
-
type TFromType<Type extends TSchema, Mapping extends TMapping, Result extends TSchema = (TApply<Type, Mapping>)> = Result;
|
|
26
|
-
/** `[Internal]` Applies a recursive conditional remapping of a type and its sub type constituents */
|
|
27
|
-
export type TRemap<Type extends TSchema, Mapping extends TMapping, Mapped extends TSchema = TFromType<Type, Mapping>, Result extends TSchema = (Mapped extends TConstructor<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TConstructor<TFromTypes<Parameters, Mapping>, TFromType<ReturnType, Mapping>> : Mapped extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFunction<TFromTypes<Parameters, Mapping>, TFromType<ReturnType, Mapping>> : Mapped extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromTypes<Types, Mapping>> : Mapped extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromTypes<Types, Mapping>> : Mapped extends TTuple<infer Types extends TSchema[]> ? TTuple<TFromTypes<Types, Mapping>> : Mapped extends TArray<infer Type extends TSchema> ? TArray<TFromType<Type, Mapping>> : Mapped extends TAsyncIterator<infer Type extends TSchema> ? TAsyncIterator<TFromType<Type, Mapping>> : Mapped extends TIterator<infer Type extends TSchema> ? TIterator<TFromType<Type, Mapping>> : Mapped extends TPromise<infer Type extends TSchema> ? TPromise<TFromType<Type, Mapping>> : Mapped extends TObject<infer Properties extends TProperties> ? TObject<TFromProperties<Properties, Mapping>> : Mapped extends TRecord<infer Key extends TSchema, infer Value extends TSchema> ? TRecordOrObject<TFromType<Key, Mapping>, TFromType<Value, Mapping>> : Mapped)> = Result;
|
|
28
|
-
/** `[Internal]` Applies a recursive conditional remapping of a type and its sub type constituents */
|
|
29
|
-
export declare function Remap(type: TSchema, callback: TCallback): TSchema;
|
|
30
|
-
export {};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.Remap = Remap;
|
|
5
|
-
const index_1 = require("../object/index");
|
|
6
|
-
const index_2 = require("../constructor/index");
|
|
7
|
-
const index_3 = require("../function/index");
|
|
8
|
-
const index_4 = require("../intersect/index");
|
|
9
|
-
const index_5 = require("../union/index");
|
|
10
|
-
const index_6 = require("../tuple/index");
|
|
11
|
-
const index_7 = require("../array/index");
|
|
12
|
-
const index_8 = require("../async-iterator/index");
|
|
13
|
-
const index_9 = require("../iterator/index");
|
|
14
|
-
const index_10 = require("../promise/index");
|
|
15
|
-
const index_11 = require("../record/index");
|
|
16
|
-
const KindGuard = require("../guard/kind");
|
|
17
|
-
const type_1 = require("../clone/type");
|
|
18
|
-
function FromProperties(properties, func) {
|
|
19
|
-
return globalThis.Object.getOwnPropertyNames(properties).reduce((result, key) => {
|
|
20
|
-
return { ...result, [key]: Remap(properties[key], func) };
|
|
21
|
-
}, {});
|
|
22
|
-
}
|
|
23
|
-
function FromTypes(types, callback) {
|
|
24
|
-
return types.map((type) => Remap(type, callback));
|
|
25
|
-
}
|
|
26
|
-
function FromType(type, callback) {
|
|
27
|
-
return callback(type);
|
|
28
|
-
}
|
|
29
|
-
/** `[Internal]` Applies a recursive conditional remapping of a type and its sub type constituents */
|
|
30
|
-
// prettier-ignore
|
|
31
|
-
function Remap(type, callback) {
|
|
32
|
-
// Map incoming type
|
|
33
|
-
const mapped = (0, type_1.CloneType)(FromType(type, callback));
|
|
34
|
-
// Return remapped interior
|
|
35
|
-
return (KindGuard.IsConstructor(type) ? (0, index_2.Constructor)(FromTypes(type.parameters, callback), FromType(type.returns, callback), mapped) :
|
|
36
|
-
KindGuard.IsFunction(type) ? (0, index_3.Function)(FromTypes(type.parameters, callback), FromType(type.returns, callback), mapped) :
|
|
37
|
-
KindGuard.IsIntersect(type) ? (0, index_4.Intersect)(FromTypes(type.allOf, callback), mapped) :
|
|
38
|
-
KindGuard.IsUnion(type) ? (0, index_5.Union)(FromTypes(type.anyOf, callback), mapped) :
|
|
39
|
-
KindGuard.IsTuple(type) ? (0, index_6.Tuple)(FromTypes(type.items || [], callback), mapped) :
|
|
40
|
-
KindGuard.IsArray(type) ? (0, index_7.Array)(FromType(type.items, callback), mapped) :
|
|
41
|
-
KindGuard.IsAsyncIterator(type) ? (0, index_8.AsyncIterator)(FromType(type.items, callback), mapped) :
|
|
42
|
-
KindGuard.IsIterator(type) ? (0, index_9.Iterator)(FromType(type.items, callback), mapped) :
|
|
43
|
-
KindGuard.IsPromise(type) ? (0, index_10.Promise)(FromType(type.items, callback), mapped) :
|
|
44
|
-
KindGuard.IsObject(type) ? (0, index_1.Object)(FromProperties(type.properties, callback), mapped) :
|
|
45
|
-
KindGuard.IsRecord(type) ? (0, index_11.Record)(FromType((0, index_11.RecordKey)(type), callback), FromType((0, index_11.RecordValue)(type), callback), mapped) :
|
|
46
|
-
(0, type_1.CloneType)(mapped));
|
|
47
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './remap.mjs';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './remap.mjs';
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { TSchema } from '../schema/index.mjs';
|
|
2
|
-
import { TObject, TProperties } from '../object/index.mjs';
|
|
3
|
-
import { TConstructor } from '../constructor/index.mjs';
|
|
4
|
-
import { TFunction } from '../function/index.mjs';
|
|
5
|
-
import { TIntersect } from '../intersect/index.mjs';
|
|
6
|
-
import { TUnion } from '../union/index.mjs';
|
|
7
|
-
import { TTuple } from '../tuple/index.mjs';
|
|
8
|
-
import { TArray } from '../array/index.mjs';
|
|
9
|
-
import { TAsyncIterator } from '../async-iterator/index.mjs';
|
|
10
|
-
import { TIterator } from '../iterator/index.mjs';
|
|
11
|
-
import { TPromise } from '../promise/index.mjs';
|
|
12
|
-
import { TRecord, TRecordOrObject } from '../record/index.mjs';
|
|
13
|
-
export type TCallback = (schema: TSchema) => TSchema;
|
|
14
|
-
export interface TMapping {
|
|
15
|
-
input: unknown;
|
|
16
|
-
output: unknown;
|
|
17
|
-
}
|
|
18
|
-
type TApply<Type extends TSchema, Mapping extends TMapping, Mapped = (Mapping & {
|
|
19
|
-
input: Type;
|
|
20
|
-
})['output'], Result = Mapped extends TSchema ? Mapped : never> = Result;
|
|
21
|
-
type TFromProperties<Properties extends TProperties, Mapping extends TMapping, Result extends TProperties = {
|
|
22
|
-
[Key in keyof Properties]: TRemap<Properties[Key], Mapping>;
|
|
23
|
-
}> = Result;
|
|
24
|
-
type TFromTypes<Types extends TSchema[], Mapping extends TMapping, Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromTypes<Right, Mapping, [...Result, TRemap<Left, Mapping>]> : Result);
|
|
25
|
-
type TFromType<Type extends TSchema, Mapping extends TMapping, Result extends TSchema = (TApply<Type, Mapping>)> = Result;
|
|
26
|
-
/** `[Internal]` Applies a recursive conditional remapping of a type and its sub type constituents */
|
|
27
|
-
export type TRemap<Type extends TSchema, Mapping extends TMapping, Mapped extends TSchema = TFromType<Type, Mapping>, Result extends TSchema = (Mapped extends TConstructor<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TConstructor<TFromTypes<Parameters, Mapping>, TFromType<ReturnType, Mapping>> : Mapped extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFunction<TFromTypes<Parameters, Mapping>, TFromType<ReturnType, Mapping>> : Mapped extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromTypes<Types, Mapping>> : Mapped extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromTypes<Types, Mapping>> : Mapped extends TTuple<infer Types extends TSchema[]> ? TTuple<TFromTypes<Types, Mapping>> : Mapped extends TArray<infer Type extends TSchema> ? TArray<TFromType<Type, Mapping>> : Mapped extends TAsyncIterator<infer Type extends TSchema> ? TAsyncIterator<TFromType<Type, Mapping>> : Mapped extends TIterator<infer Type extends TSchema> ? TIterator<TFromType<Type, Mapping>> : Mapped extends TPromise<infer Type extends TSchema> ? TPromise<TFromType<Type, Mapping>> : Mapped extends TObject<infer Properties extends TProperties> ? TObject<TFromProperties<Properties, Mapping>> : Mapped extends TRecord<infer Key extends TSchema, infer Value extends TSchema> ? TRecordOrObject<TFromType<Key, Mapping>, TFromType<Value, Mapping>> : Mapped)> = Result;
|
|
28
|
-
/** `[Internal]` Applies a recursive conditional remapping of a type and its sub type constituents */
|
|
29
|
-
export declare function Remap(type: TSchema, callback: TCallback): TSchema;
|
|
30
|
-
export {};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { Object } from '../object/index.mjs';
|
|
2
|
-
import { Constructor } from '../constructor/index.mjs';
|
|
3
|
-
import { Function } from '../function/index.mjs';
|
|
4
|
-
import { Intersect } from '../intersect/index.mjs';
|
|
5
|
-
import { Union } from '../union/index.mjs';
|
|
6
|
-
import { Tuple } from '../tuple/index.mjs';
|
|
7
|
-
import { Array } from '../array/index.mjs';
|
|
8
|
-
import { AsyncIterator } from '../async-iterator/index.mjs';
|
|
9
|
-
import { Iterator } from '../iterator/index.mjs';
|
|
10
|
-
import { Promise } from '../promise/index.mjs';
|
|
11
|
-
import { Record, RecordKey, RecordValue } from '../record/index.mjs';
|
|
12
|
-
import * as KindGuard from '../guard/kind.mjs';
|
|
13
|
-
import { CloneType } from '../clone/type.mjs';
|
|
14
|
-
function FromProperties(properties, func) {
|
|
15
|
-
return globalThis.Object.getOwnPropertyNames(properties).reduce((result, key) => {
|
|
16
|
-
return { ...result, [key]: Remap(properties[key], func) };
|
|
17
|
-
}, {});
|
|
18
|
-
}
|
|
19
|
-
function FromTypes(types, callback) {
|
|
20
|
-
return types.map((type) => Remap(type, callback));
|
|
21
|
-
}
|
|
22
|
-
function FromType(type, callback) {
|
|
23
|
-
return callback(type);
|
|
24
|
-
}
|
|
25
|
-
/** `[Internal]` Applies a recursive conditional remapping of a type and its sub type constituents */
|
|
26
|
-
// prettier-ignore
|
|
27
|
-
export function Remap(type, callback) {
|
|
28
|
-
// Map incoming type
|
|
29
|
-
const mapped = CloneType(FromType(type, callback));
|
|
30
|
-
// Return remapped interior
|
|
31
|
-
return (KindGuard.IsConstructor(type) ? Constructor(FromTypes(type.parameters, callback), FromType(type.returns, callback), mapped) :
|
|
32
|
-
KindGuard.IsFunction(type) ? Function(FromTypes(type.parameters, callback), FromType(type.returns, callback), mapped) :
|
|
33
|
-
KindGuard.IsIntersect(type) ? Intersect(FromTypes(type.allOf, callback), mapped) :
|
|
34
|
-
KindGuard.IsUnion(type) ? Union(FromTypes(type.anyOf, callback), mapped) :
|
|
35
|
-
KindGuard.IsTuple(type) ? Tuple(FromTypes(type.items || [], callback), mapped) :
|
|
36
|
-
KindGuard.IsArray(type) ? Array(FromType(type.items, callback), mapped) :
|
|
37
|
-
KindGuard.IsAsyncIterator(type) ? AsyncIterator(FromType(type.items, callback), mapped) :
|
|
38
|
-
KindGuard.IsIterator(type) ? Iterator(FromType(type.items, callback), mapped) :
|
|
39
|
-
KindGuard.IsPromise(type) ? Promise(FromType(type.items, callback), mapped) :
|
|
40
|
-
KindGuard.IsObject(type) ? Object(FromProperties(type.properties, callback), mapped) :
|
|
41
|
-
KindGuard.IsRecord(type) ? Record(FromType(RecordKey(type), callback), FromType(RecordValue(type), callback), mapped) :
|
|
42
|
-
CloneType(mapped));
|
|
43
|
-
}
|