@sinclair/typebox 0.34.40 → 0.34.42
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/parser/index.js +35 -2
- package/build/cjs/parser/runtime/index.js +24 -2
- package/build/cjs/parser/runtime/parse.js +35 -2
- package/build/cjs/parser/static/index.js +23 -1
- package/build/cjs/syntax/mapping.js +34 -1
- package/build/cjs/syntax/parser.js +34 -1
- package/build/cjs/syntax/syntax.js +34 -1
- package/build/cjs/type/clone/value.js +34 -1
- package/build/cjs/type/composite/composite.d.ts +1 -1
- package/build/cjs/type/constructor-parameters/constructor-parameters.js +34 -1
- package/build/cjs/type/create/immutable.js +34 -1
- package/build/cjs/type/guard/index.js +36 -3
- package/build/cjs/type/guard/kind.js +34 -1
- package/build/cjs/type/guard/type.js +34 -1
- package/build/cjs/type/instance-type/instance-type.js +34 -1
- package/build/cjs/type/instantiate/instantiate.d.ts +1 -1
- package/build/cjs/type/instantiate/instantiate.js +35 -2
- package/build/cjs/type/module/compute.js +34 -1
- package/build/cjs/type/object/object.d.ts +6 -2
- package/build/cjs/type/object/object.js +6 -10
- package/build/cjs/type/omit/omit.d.ts +3 -3
- package/build/cjs/type/omit/omit.js +8 -8
- package/build/cjs/type/parameters/parameters.js +34 -1
- package/build/cjs/type/partial/partial.d.ts +2 -2
- package/build/cjs/type/partial/partial.js +38 -5
- package/build/cjs/type/pick/pick.d.ts +3 -3
- package/build/cjs/type/pick/pick.js +8 -8
- package/build/cjs/type/registry/index.js +35 -2
- package/build/cjs/type/required/required.d.ts +2 -2
- package/build/cjs/type/required/required.js +38 -5
- package/build/cjs/type/return-type/return-type.js +34 -1
- package/build/cjs/type/tuple/tuple.d.ts +3 -3
- package/build/cjs/type/type/index.js +34 -1
- package/build/cjs/value/pointer/index.js +34 -1
- package/build/cjs/value/value/index.js +34 -1
- package/build/esm/type/composite/composite.d.mts +1 -1
- package/build/esm/type/instantiate/instantiate.d.mts +1 -1
- package/build/esm/type/object/object.d.mts +6 -2
- package/build/esm/type/object/object.mjs +6 -10
- package/build/esm/type/omit/omit.d.mts +3 -3
- package/build/esm/type/omit/omit.mjs +8 -8
- package/build/esm/type/partial/partial.d.mts +2 -2
- package/build/esm/type/partial/partial.mjs +4 -4
- package/build/esm/type/pick/pick.d.mts +3 -3
- package/build/esm/type/pick/pick.mjs +8 -8
- package/build/esm/type/required/required.d.mts +2 -2
- package/build/esm/type/required/required.mjs +4 -4
- package/build/esm/type/tuple/tuple.d.mts +3 -3
- package/license +24 -24
- package/package.json +2 -2
- package/readme.md +1863 -1861
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
3
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
37
|
exports.ValuePointer = void 0;
|
|
5
|
-
exports.ValuePointer = require("./pointer");
|
|
38
|
+
exports.ValuePointer = __importStar(require("./pointer"));
|
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
3
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
37
|
exports.Value = void 0;
|
|
5
|
-
exports.Value = require("./value");
|
|
38
|
+
exports.Value = __importStar(require("./value"));
|
|
@@ -12,7 +12,7 @@ type TCompositeProperty<T extends TSchema[], K extends PropertyKey, Acc extends
|
|
|
12
12
|
type TCompositeProperties<T extends TSchema[], K extends PropertyKey[], Acc = {}> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TCompositeProperties<T, R, Acc & {
|
|
13
13
|
[_ in L]: TIntersectEvaluated<TCompositeProperty<T, L>>;
|
|
14
14
|
}> : Acc);
|
|
15
|
-
type TCompositeEvaluate<T extends TSchema[], K extends PropertyKey[] = TCompositeKeys<T>, P extends TProperties = Evaluate<TCompositeProperties<T, K>>, R extends
|
|
15
|
+
type TCompositeEvaluate<T extends TSchema[], K extends PropertyKey[] = TCompositeKeys<T>, P extends TProperties = Evaluate<TCompositeProperties<T, K>>, R extends TSchema = TObject<P>> = R;
|
|
16
16
|
export type TComposite<T extends TSchema[]> = TCompositeEvaluate<T>;
|
|
17
17
|
export declare function Composite<T extends TSchema[]>(T: [...T], options?: ObjectOptions): TComposite<T>;
|
|
18
18
|
export {};
|
|
@@ -24,7 +24,7 @@ type TFromArray<Args extends TSchema[], Type extends TSchema, Result extends TAr
|
|
|
24
24
|
type TFromAsyncIterator<Args extends TSchema[], Type extends TSchema, Result extends TAsyncIterator = TAsyncIterator<TFromType<Args, Type>>> = Result;
|
|
25
25
|
type TFromIterator<Args extends TSchema[], Type extends TSchema, Result extends TIterator = TIterator<TFromType<Args, Type>>> = Result;
|
|
26
26
|
type TFromPromise<Args extends TSchema[], Type extends TSchema, Result extends TPromise = TPromise<TFromType<Args, Type>>> = Result;
|
|
27
|
-
type TFromObject<Args extends TSchema[], Properties extends TProperties, MappedProperties extends TProperties = TFromProperties<Args, Properties>, Result extends
|
|
27
|
+
type TFromObject<Args extends TSchema[], Properties extends TProperties, MappedProperties extends TProperties = TFromProperties<Args, Properties>, Result extends TSchema = TObject<MappedProperties>> = Result;
|
|
28
28
|
type TFromRecord<Args extends TSchema[], Key extends TSchema, Value extends TSchema, MappedKey extends TSchema = TFromType<Args, Key>, MappedValue extends TSchema = TFromType<Args, Value>, Result extends TSchema = TRecordOrObject<MappedKey, MappedValue>> = Result;
|
|
29
29
|
type TFromArgument<Args extends TSchema[], Index extends number, Result extends TSchema = Index extends keyof Args[Index] ? Args[Index] : TUnknown> = Result;
|
|
30
30
|
type TFromProperty<Args extends TSchema[], Type extends TSchema, IsReadonly extends boolean = Type extends TReadonly<Type> ? true : false, IsOptional extends boolean = Type extends TOptional<Type> ? true : false, Mapped extends TSchema = TFromType<Args, Type>, Result extends TSchema = ([
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
2
|
import type { Static } from '../static/index.mjs';
|
|
3
|
-
import type { Evaluate } from '../helpers/index.mjs';
|
|
3
|
+
import type { Evaluate, UnionToTuple } from '../helpers/index.mjs';
|
|
4
4
|
import type { TReadonly } from '../readonly/index.mjs';
|
|
5
5
|
import type { TOptional } from '../optional/index.mjs';
|
|
6
6
|
import { Kind } from '../symbols/index.mjs';
|
|
@@ -20,6 +20,10 @@ type ObjectStatic<T extends TProperties, P extends unknown[]> = ObjectStaticProp
|
|
|
20
20
|
}>;
|
|
21
21
|
export type TPropertyKey = string | number;
|
|
22
22
|
export type TProperties = Record<TPropertyKey, TSchema>;
|
|
23
|
+
/** Creates a RequiredArray derived from the given TProperties value. */
|
|
24
|
+
type TRequiredArray<Properties extends TProperties, RequiredProperties extends TProperties = {
|
|
25
|
+
[Key in keyof Properties as Properties[Key] extends TOptional<Properties[Key]> ? never : Key]: Properties[Key];
|
|
26
|
+
}, RequiredKeys extends string[] = UnionToTuple<Extract<keyof RequiredProperties, string>>, Result extends string[] | undefined = RequiredKeys extends [] ? undefined : RequiredKeys> = Result;
|
|
23
27
|
export type TAdditionalProperties = undefined | TSchema | boolean;
|
|
24
28
|
export interface ObjectOptions extends SchemaOptions {
|
|
25
29
|
/** Additional property constraints for this object */
|
|
@@ -35,7 +39,7 @@ export interface TObject<T extends TProperties = TProperties> extends TSchema, O
|
|
|
35
39
|
additionalProperties?: TAdditionalProperties;
|
|
36
40
|
type: 'object';
|
|
37
41
|
properties: T;
|
|
38
|
-
required
|
|
42
|
+
required: TRequiredArray<T>;
|
|
39
43
|
}
|
|
40
44
|
/** `[Json]` Creates an Object type */
|
|
41
45
|
declare function _Object<T extends TProperties>(properties: T, options?: ObjectOptions): TObject<T>;
|
|
@@ -4,19 +4,15 @@ import { Kind } from '../symbols/index.mjs';
|
|
|
4
4
|
// TypeGuard
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
6
|
import { IsOptional } from '../guard/kind.mjs';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (!IsOptional(properties[key]))
|
|
11
|
-
keys.push(key);
|
|
12
|
-
}
|
|
13
|
-
return keys;
|
|
7
|
+
/** Creates a RequiredArray derived from the given TProperties value. */
|
|
8
|
+
function RequiredArray(properties) {
|
|
9
|
+
return globalThis.Object.keys(properties).filter((key) => !IsOptional(properties[key]));
|
|
14
10
|
}
|
|
15
11
|
/** `[Json]` Creates an Object type */
|
|
16
12
|
function _Object(properties, options) {
|
|
17
|
-
const required =
|
|
18
|
-
const
|
|
19
|
-
return CreateType(
|
|
13
|
+
const required = RequiredArray(properties);
|
|
14
|
+
const schema = required.length > 0 ? { [Kind]: 'Object', type: 'object', required, properties } : { [Kind]: 'Object', type: 'object', properties };
|
|
15
|
+
return CreateType(schema, options);
|
|
20
16
|
}
|
|
21
17
|
/** `[Json]` Creates an Object type */
|
|
22
18
|
export var Object = _Object;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SchemaOptions, TSchema } from '../schema/index.mjs';
|
|
2
|
-
import type { TupleToUnion, Evaluate
|
|
2
|
+
import type { TupleToUnion, Evaluate } from '../helpers/index.mjs';
|
|
3
3
|
import { type TRecursive } from '../recursive/index.mjs';
|
|
4
4
|
import type { TMappedKey, TMappedResult } from '../mapped/index.mjs';
|
|
5
5
|
import { TComputed } from '../computed/index.mjs';
|
|
@@ -14,9 +14,9 @@ import { type TOmitFromMappedResult } from './omit-from-mapped-result.mjs';
|
|
|
14
14
|
type TFromIntersect<Types extends TSchema[], PropertyKeys extends PropertyKey[], Result extends TSchema[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromIntersect<R, PropertyKeys, [...Result, TOmit<L, PropertyKeys>]> : Result);
|
|
15
15
|
type TFromUnion<T extends TSchema[], K extends PropertyKey[], Result extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, K, [...Result, TOmit<L, K>]> : Result);
|
|
16
16
|
type TFromProperties<Properties extends TProperties, PropertyKeys extends PropertyKey[], UnionKey extends PropertyKey = TupleToUnion<PropertyKeys>> = (Evaluate<Omit<Properties, UnionKey>>);
|
|
17
|
-
type TFromObject<
|
|
17
|
+
type TFromObject<_Type extends TObject, PropertyKeys extends PropertyKey[], Properties extends TProperties, MappedProperties extends TProperties = TFromProperties<Properties, PropertyKeys>, Result extends TSchema = TObject<MappedProperties>> = Result;
|
|
18
18
|
type TUnionFromPropertyKeys<PropertyKeys extends PropertyKey[], Result extends TLiteral[] = []> = (PropertyKeys extends [infer Key extends PropertyKey, ...infer Rest extends PropertyKey[]] ? Key extends TLiteralValue ? TUnionFromPropertyKeys<Rest, [...Result, TLiteral<Key>]> : TUnionFromPropertyKeys<Rest, [...Result]> : TUnion<Result>);
|
|
19
|
-
export type TOmitResolve<Properties extends TProperties, PropertyKeys extends PropertyKey[]> = (Properties extends TRecursive<infer Types extends TSchema> ? TRecursive<TOmitResolve<Types, PropertyKeys>> : Properties extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromIntersect<Types, PropertyKeys>> : Properties extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromUnion<Types, PropertyKeys>> : Properties extends TObject<infer
|
|
19
|
+
export type TOmitResolve<Properties extends TProperties, PropertyKeys extends PropertyKey[]> = (Properties extends TRecursive<infer Types extends TSchema> ? TRecursive<TOmitResolve<Types, PropertyKeys>> : Properties extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromIntersect<Types, PropertyKeys>> : Properties extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromUnion<Types, PropertyKeys>> : Properties extends TObject<infer Properties extends TProperties> ? TFromObject<TObject, PropertyKeys, Properties> : TObject<{}>);
|
|
20
20
|
type TResolvePropertyKeys<Key extends TSchema | PropertyKey[]> = Key extends TSchema ? TIndexPropertyKeys<Key> : Key;
|
|
21
21
|
type TResolveTypeKey<Key extends TSchema | PropertyKey[]> = Key extends PropertyKey[] ? TUnionFromPropertyKeys<Key> : Key;
|
|
22
22
|
export type TOmit<Type extends TSchema, Key extends TSchema | PropertyKey[], IsTypeRef extends boolean = Type extends TRef ? true : false, IsKeyRef extends boolean = Key extends TRef ? true : false> = (Type extends TMappedResult ? TOmitFromMappedResult<Type, TResolvePropertyKeys<Key>> : Key extends TMappedKey ? TOmitFromMappedKey<Type, Key> : [
|
|
@@ -38,10 +38,10 @@ function FromProperties(properties, propertyKeys) {
|
|
|
38
38
|
return propertyKeys.reduce((T, K2) => FromProperty(T, K2), properties);
|
|
39
39
|
}
|
|
40
40
|
// prettier-ignore
|
|
41
|
-
function FromObject(
|
|
42
|
-
const options = Discard(
|
|
43
|
-
const
|
|
44
|
-
return Object(
|
|
41
|
+
function FromObject(type, propertyKeys, properties) {
|
|
42
|
+
const options = Discard(type, [TransformKind, '$id', 'required', 'properties']);
|
|
43
|
+
const mappedProperties = FromProperties(properties, propertyKeys);
|
|
44
|
+
return Object(mappedProperties, options);
|
|
45
45
|
}
|
|
46
46
|
// prettier-ignore
|
|
47
47
|
function UnionFromPropertyKeys(propertyKeys) {
|
|
@@ -49,10 +49,10 @@ function UnionFromPropertyKeys(propertyKeys) {
|
|
|
49
49
|
return Union(result);
|
|
50
50
|
}
|
|
51
51
|
// prettier-ignore
|
|
52
|
-
function OmitResolve(
|
|
53
|
-
return (IsIntersect(
|
|
54
|
-
IsUnion(
|
|
55
|
-
IsObject(
|
|
52
|
+
function OmitResolve(type, propertyKeys) {
|
|
53
|
+
return (IsIntersect(type) ? Intersect(FromIntersect(type.allOf, propertyKeys)) :
|
|
54
|
+
IsUnion(type) ? Union(FromUnion(type.anyOf, propertyKeys)) :
|
|
55
|
+
IsObject(type) ? FromObject(type, propertyKeys, type.properties) :
|
|
56
56
|
Object({}));
|
|
57
57
|
}
|
|
58
58
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
@@ -25,9 +25,9 @@ type TFromRef<Ref extends string> = Ensure<TComputed<'Partial', [TRef<Ref>]>>;
|
|
|
25
25
|
type TFromProperties<Properties extends TProperties> = Evaluate<{
|
|
26
26
|
[K in keyof Properties]: Properties[K] extends (TReadonlyOptional<infer S>) ? TReadonlyOptional<S> : Properties[K] extends (TReadonly<infer S>) ? TReadonlyOptional<S> : Properties[K] extends (TOptional<infer S>) ? TOptional<S> : TOptional<Properties[K]>;
|
|
27
27
|
}>;
|
|
28
|
-
type TFromObject<
|
|
28
|
+
type TFromObject<_Type extends TObject, Properties extends TProperties, MappedProperties extends TProperties = TFromProperties<Properties>, Result extends TSchema = TObject<MappedProperties>> = Result;
|
|
29
29
|
type TFromRest<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Result, TPartial<L>]> : Result);
|
|
30
|
-
export type TPartial<Type extends TSchema> = (Type extends TRecursive<infer Type extends TSchema> ? TRecursive<TPartial<Type>> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<Target, Parameters> : Type extends TRef<infer Ref extends string> ? TFromRef<Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromRest<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromRest<Types>> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<TObject
|
|
30
|
+
export type TPartial<Type extends TSchema> = (Type extends TRecursive<infer Type extends TSchema> ? TRecursive<TPartial<Type>> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<Target, Parameters> : Type extends TRef<infer Ref extends string> ? TFromRef<Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromRest<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromRest<Types>> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<TObject, Properties> : Type extends TBigInt ? Type : Type extends TBoolean ? Type : Type extends TInteger ? Type : Type extends TLiteral ? Type : Type extends TNull ? Type : Type extends TNumber ? Type : Type extends TString ? Type : Type extends TSymbol ? Type : Type extends TUndefined ? Type : TObject<{}>);
|
|
31
31
|
/** `[Json]` Constructs a type where all properties are optional */
|
|
32
32
|
export declare function Partial<MappedResult extends TMappedResult>(type: MappedResult, options?: SchemaOptions): TPartialFromMappedResult<MappedResult>;
|
|
33
33
|
/** `[Json]` Constructs a type where all properties are optional */
|
|
@@ -28,10 +28,10 @@ function FromProperties(properties) {
|
|
|
28
28
|
return partialProperties;
|
|
29
29
|
}
|
|
30
30
|
// prettier-ignore
|
|
31
|
-
function FromObject(type) {
|
|
31
|
+
function FromObject(type, properties) {
|
|
32
32
|
const options = Discard(type, [TransformKind, '$id', 'required', 'properties']);
|
|
33
|
-
const
|
|
34
|
-
return Object(
|
|
33
|
+
const mappedProperties = FromProperties(properties);
|
|
34
|
+
return Object(mappedProperties, options);
|
|
35
35
|
}
|
|
36
36
|
// prettier-ignore
|
|
37
37
|
function FromRest(types) {
|
|
@@ -48,7 +48,7 @@ function PartialResolve(type) {
|
|
|
48
48
|
KindGuard.IsRef(type) ? FromRef(type.$ref) :
|
|
49
49
|
KindGuard.IsIntersect(type) ? Intersect(FromRest(type.allOf)) :
|
|
50
50
|
KindGuard.IsUnion(type) ? Union(FromRest(type.anyOf)) :
|
|
51
|
-
KindGuard.IsObject(type) ? FromObject(type) :
|
|
51
|
+
KindGuard.IsObject(type) ? FromObject(type, type.properties) :
|
|
52
52
|
// Intrinsic
|
|
53
53
|
KindGuard.IsBigInt(type) ? type :
|
|
54
54
|
KindGuard.IsBoolean(type) ? type :
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
|
-
import type { TupleToUnion, Evaluate
|
|
2
|
+
import type { TupleToUnion, Evaluate } from '../helpers/index.mjs';
|
|
3
3
|
import { type TRecursive } from '../recursive/index.mjs';
|
|
4
4
|
import { type TComputed } from '../computed/index.mjs';
|
|
5
5
|
import { type TIntersect } from '../intersect/index.mjs';
|
|
@@ -14,9 +14,9 @@ import { type TPickFromMappedResult } from './pick-from-mapped-result.mjs';
|
|
|
14
14
|
type TFromIntersect<Types extends TSchema[], PropertyKeys extends PropertyKey[], Result extends TSchema[] = []> = Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromIntersect<R, PropertyKeys, [...Result, TPick<L, PropertyKeys>]> : Result;
|
|
15
15
|
type TFromUnion<Types extends TSchema[], PropertyKeys extends PropertyKey[], Result extends TSchema[] = []> = Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, PropertyKeys, [...Result, TPick<L, PropertyKeys>]> : Result;
|
|
16
16
|
type TFromProperties<Properties extends TProperties, PropertyKeys extends PropertyKey[], UnionKeys extends PropertyKey = TupleToUnion<PropertyKeys>> = (Evaluate<Pick<Properties, UnionKeys & keyof Properties>>);
|
|
17
|
-
type TFromObject<
|
|
17
|
+
type TFromObject<_Type extends TObject, Keys extends PropertyKey[], Properties extends TProperties, MappedProperties extends TProperties = TFromProperties<Properties, Keys>, Result extends TSchema = TObject<MappedProperties>> = Result;
|
|
18
18
|
type TUnionFromPropertyKeys<PropertyKeys extends PropertyKey[], Result extends TLiteral[] = []> = (PropertyKeys extends [infer Key extends PropertyKey, ...infer Rest extends PropertyKey[]] ? Key extends TLiteralValue ? TUnionFromPropertyKeys<Rest, [...Result, TLiteral<Key>]> : TUnionFromPropertyKeys<Rest, [...Result]> : TUnion<Result>);
|
|
19
|
-
export type TPickResolve<
|
|
19
|
+
export type TPickResolve<Type extends TProperties, PropertyKeys extends PropertyKey[]> = (Type extends TRecursive<infer Types extends TSchema> ? TRecursive<TPickResolve<Types, PropertyKeys>> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromIntersect<Types, PropertyKeys>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromUnion<Types, PropertyKeys>> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<TObject, PropertyKeys, Properties> : TObject<{}>);
|
|
20
20
|
type TResolvePropertyKeys<Key extends TSchema | PropertyKey[]> = Key extends TSchema ? TIndexPropertyKeys<Key> : Key;
|
|
21
21
|
type TResolveTypeKey<Key extends TSchema | PropertyKey[]> = Key extends PropertyKey[] ? TUnionFromPropertyKeys<Key> : Key;
|
|
22
22
|
export type TPick<Type extends TSchema, Key extends TSchema | PropertyKey[], IsTypeRef extends boolean = Type extends TRef ? true : false, IsKeyRef extends boolean = Key extends TRef ? true : false> = (Type extends TMappedResult ? TPickFromMappedResult<Type, TResolvePropertyKeys<Key>> : Key extends TMappedKey ? TPickFromMappedKey<Type, Key> : [
|
|
@@ -33,10 +33,10 @@ function FromProperties(properties, propertyKeys) {
|
|
|
33
33
|
return result;
|
|
34
34
|
}
|
|
35
35
|
// prettier-ignore
|
|
36
|
-
function FromObject(
|
|
37
|
-
const options = Discard(
|
|
38
|
-
const
|
|
39
|
-
return Object(
|
|
36
|
+
function FromObject(Type, keys, properties) {
|
|
37
|
+
const options = Discard(Type, [TransformKind, '$id', 'required', 'properties']);
|
|
38
|
+
const mappedProperties = FromProperties(properties, keys);
|
|
39
|
+
return Object(mappedProperties, options);
|
|
40
40
|
}
|
|
41
41
|
// prettier-ignore
|
|
42
42
|
function UnionFromPropertyKeys(propertyKeys) {
|
|
@@ -44,10 +44,10 @@ function UnionFromPropertyKeys(propertyKeys) {
|
|
|
44
44
|
return Union(result);
|
|
45
45
|
}
|
|
46
46
|
// prettier-ignore
|
|
47
|
-
function PickResolve(
|
|
48
|
-
return (IsIntersect(
|
|
49
|
-
IsUnion(
|
|
50
|
-
IsObject(
|
|
47
|
+
function PickResolve(type, propertyKeys) {
|
|
48
|
+
return (IsIntersect(type) ? Intersect(FromIntersect(type.allOf, propertyKeys)) :
|
|
49
|
+
IsUnion(type) ? Union(FromUnion(type.anyOf, propertyKeys)) :
|
|
50
|
+
IsObject(type) ? FromObject(type, propertyKeys, type.properties) :
|
|
51
51
|
Object({}));
|
|
52
52
|
}
|
|
53
53
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
@@ -25,9 +25,9 @@ type TFromRef<Ref extends string> = Ensure<TComputed<'Required', [TRef<Ref>]>>;
|
|
|
25
25
|
type TFromProperties<Properties extends TProperties> = Evaluate<{
|
|
26
26
|
[K in keyof Properties]: Properties[K] extends (TReadonlyOptional<infer S>) ? TReadonly<S> : Properties[K] extends (TReadonly<infer S>) ? TReadonly<S> : Properties[K] extends (TOptional<infer S>) ? S : Properties[K];
|
|
27
27
|
}>;
|
|
28
|
-
type TFromObject<
|
|
28
|
+
type TFromObject<_Type extends TObject, Properties extends TProperties, MappedProperties extends TProperties = TFromProperties<Properties>, Result extends TSchema = TObject<MappedProperties>> = Result;
|
|
29
29
|
type TFromRest<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Result, TRequired<L>]> : Result);
|
|
30
|
-
export type TRequired<Type extends TSchema> = (Type extends TRecursive<infer Type extends TSchema> ? TRecursive<TRequired<Type>> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<Target, Parameters> : Type extends TRef<infer Ref extends string> ? TFromRef<Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromRest<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromRest<Types>> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<TObject
|
|
30
|
+
export type TRequired<Type extends TSchema> = (Type extends TRecursive<infer Type extends TSchema> ? TRecursive<TRequired<Type>> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<Target, Parameters> : Type extends TRef<infer Ref extends string> ? TFromRef<Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromRest<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromRest<Types>> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<TObject, Properties> : Type extends TBigInt ? Type : Type extends TBoolean ? Type : Type extends TInteger ? Type : Type extends TLiteral ? Type : Type extends TNull ? Type : Type extends TNumber ? Type : Type extends TString ? Type : Type extends TSymbol ? Type : Type extends TUndefined ? Type : TObject<{}>);
|
|
31
31
|
/** `[Json]` Constructs a type where all properties are required */
|
|
32
32
|
export declare function Required<MappedResult extends TMappedResult>(type: MappedResult, options?: SchemaOptions): TRequiredFromMappedResult<MappedResult>;
|
|
33
33
|
/** `[Json]` Constructs a type where all properties are required */
|
|
@@ -27,10 +27,10 @@ function FromProperties(properties) {
|
|
|
27
27
|
return requiredProperties;
|
|
28
28
|
}
|
|
29
29
|
// prettier-ignore
|
|
30
|
-
function FromObject(type) {
|
|
30
|
+
function FromObject(type, properties) {
|
|
31
31
|
const options = Discard(type, [TransformKind, '$id', 'required', 'properties']);
|
|
32
|
-
const
|
|
33
|
-
return Object(
|
|
32
|
+
const mappedProperties = FromProperties(properties);
|
|
33
|
+
return Object(mappedProperties, options);
|
|
34
34
|
}
|
|
35
35
|
// prettier-ignore
|
|
36
36
|
function FromRest(types) {
|
|
@@ -47,7 +47,7 @@ function RequiredResolve(type) {
|
|
|
47
47
|
KindGuard.IsRef(type) ? FromRef(type.$ref) :
|
|
48
48
|
KindGuard.IsIntersect(type) ? Intersect(FromRest(type.allOf)) :
|
|
49
49
|
KindGuard.IsUnion(type) ? Union(FromRest(type.anyOf)) :
|
|
50
|
-
KindGuard.IsObject(type) ? FromObject(type) :
|
|
50
|
+
KindGuard.IsObject(type) ? FromObject(type, type.properties) :
|
|
51
51
|
// Intrinsic
|
|
52
52
|
KindGuard.IsBigInt(type) ? type :
|
|
53
53
|
KindGuard.IsBoolean(type) ? type :
|
|
@@ -6,10 +6,10 @@ export interface TTuple<T extends TSchema[] = TSchema[]> extends TSchema {
|
|
|
6
6
|
[Kind]: 'Tuple';
|
|
7
7
|
static: TupleStatic<T, this['params']>;
|
|
8
8
|
type: 'array';
|
|
9
|
-
items
|
|
9
|
+
items: T;
|
|
10
10
|
additionalItems?: false;
|
|
11
|
-
minItems:
|
|
12
|
-
maxItems:
|
|
11
|
+
minItems: T['length'];
|
|
12
|
+
maxItems: T['length'];
|
|
13
13
|
}
|
|
14
14
|
/** `[Json]` Creates a Tuple type */
|
|
15
15
|
export declare function Tuple<Types extends TSchema[]>(types: [...Types], options?: SchemaOptions): TTuple<Types>;
|
package/license
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
TypeBox
|
|
2
|
-
|
|
3
|
-
Json Schema Type Builder with Static Type Resolution for TypeScript
|
|
4
|
-
|
|
5
|
-
The MIT License (MIT)
|
|
6
|
-
|
|
7
|
-
Copyright (c) 2017-2025 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
8
|
-
|
|
9
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
-
in the Software without restriction, including without limitation the rights
|
|
12
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
-
furnished to do so, subject to the following conditions:
|
|
15
|
-
|
|
16
|
-
The above copyright notice and this permission notice shall be included in
|
|
17
|
-
all copies or substantial portions of the Software.
|
|
18
|
-
|
|
19
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
1
|
+
TypeBox
|
|
2
|
+
|
|
3
|
+
Json Schema Type Builder with Static Type Resolution for TypeScript
|
|
4
|
+
|
|
5
|
+
The MIT License (MIT)
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2017-2025 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in
|
|
17
|
+
all copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
25
|
THE SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sinclair/typebox",
|
|
3
|
-
"version": "0.34.
|
|
3
|
+
"version": "0.34.42",
|
|
4
4
|
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
|
-
"url": "https://github.com/sinclairzx81/typebox"
|
|
15
|
+
"url": "https://github.com/sinclairzx81/typebox-legacy"
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
18
|
"test": "echo test"
|