@sinclair/typebox 0.34.17 → 0.34.18

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.
@@ -1,19 +1,30 @@
1
- import * as t from '@sinclair/typebox';
2
- export type TCallback = (schema: t.TSchema) => t.TSchema;
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;
3
14
  export interface TMapping {
4
15
  input: unknown;
5
16
  output: unknown;
6
17
  }
7
- type TApply<Type extends t.TSchema, Mapping extends TMapping, Mapped = (Mapping & {
18
+ type TApply<Type extends TSchema, Mapping extends TMapping, Mapped = (Mapping & {
8
19
  input: Type;
9
- })['output'], Result = Mapped extends t.TSchema ? Mapped : never> = Result;
10
- type TFromProperties<Properties extends t.TProperties, Mapping extends TMapping, Result extends t.TProperties = {
20
+ })['output'], Result = Mapped extends TSchema ? Mapped : never> = Result;
21
+ type TFromProperties<Properties extends TProperties, Mapping extends TMapping, Result extends TProperties = {
11
22
  [Key in keyof Properties]: TRemap<Properties[Key], Mapping>;
12
23
  }> = Result;
13
- type TFromTypes<Types extends t.TSchema[], Mapping extends TMapping, Result extends t.TSchema[] = []> = (Types extends [infer Left extends t.TSchema, ...infer Right extends t.TSchema[]] ? TFromTypes<Right, Mapping, [...Result, TRemap<Left, Mapping>]> : Result);
14
- type TFromType<Type extends t.TSchema, Mapping extends TMapping, Result extends t.TSchema = (TApply<Type, Mapping>)> = 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;
15
26
  /** `[Internal]` Applies a recursive conditional remapping of a type and its sub type constituents */
16
- export type TRemap<Type extends t.TSchema, Mapping extends TMapping, Mapped extends t.TSchema = TFromType<Type, Mapping>, Result extends t.TSchema = (Mapped extends t.TConstructor<infer Parameters extends t.TSchema[], infer ReturnType extends t.TSchema> ? t.TConstructor<TFromTypes<Parameters, Mapping>, TFromType<ReturnType, Mapping>> : Mapped extends t.TFunction<infer Parameters extends t.TSchema[], infer ReturnType extends t.TSchema> ? t.TFunction<TFromTypes<Parameters, Mapping>, TFromType<ReturnType, Mapping>> : Mapped extends t.TIntersect<infer Types extends t.TSchema[]> ? t.TIntersect<TFromTypes<Types, Mapping>> : Mapped extends t.TUnion<infer Types extends t.TSchema[]> ? t.TUnion<TFromTypes<Types, Mapping>> : Mapped extends t.TTuple<infer Types extends t.TSchema[]> ? t.TTuple<TFromTypes<Types, Mapping>> : Mapped extends t.TArray<infer Type extends t.TSchema> ? t.TArray<TFromType<Type, Mapping>> : Mapped extends t.TAsyncIterator<infer Type extends t.TSchema> ? t.TAsyncIterator<TFromType<Type, Mapping>> : Mapped extends t.TIterator<infer Type extends t.TSchema> ? t.TIterator<TFromType<Type, Mapping>> : Mapped extends t.TPromise<infer Type extends t.TSchema> ? t.TPromise<TFromType<Type, Mapping>> : Mapped extends t.TObject<infer Properties extends t.TProperties> ? t.TObject<TFromProperties<Properties, Mapping>> : Mapped extends t.TRecord<infer Key extends t.TSchema, infer Value extends t.TSchema> ? t.TRecordOrObject<TFromType<Key, Mapping>, TFromType<Value, Mapping>> : Mapped)> = Result;
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;
17
28
  /** `[Internal]` Applies a recursive conditional remapping of a type and its sub type constituents */
18
- export declare function Remap(type: t.TSchema, callback: TCallback): t.TSchema;
29
+ export declare function Remap(type: TSchema, callback: TCallback): TSchema;
19
30
  export {};
@@ -2,7 +2,19 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Remap = Remap;
5
- const t = require("@sinclair/typebox");
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");
6
18
  function FromProperties(properties, func) {
7
19
  return globalThis.Object.getOwnPropertyNames(properties).reduce((result, key) => {
8
20
  return { ...result, [key]: Remap(properties[key], func) };
@@ -18,18 +30,18 @@ function FromType(type, callback) {
18
30
  // prettier-ignore
19
31
  function Remap(type, callback) {
20
32
  // Map incoming type
21
- const mapped = t.CloneType(FromType(type, callback));
33
+ const mapped = (0, type_1.CloneType)(FromType(type, callback));
22
34
  // Return remapped interior
23
- return (t.KindGuard.IsConstructor(type) ? t.Constructor(FromTypes(type.parameters, callback), FromType(type.returns, callback), mapped) :
24
- t.KindGuard.IsFunction(type) ? t.Function(FromTypes(type.parameters, callback), FromType(type.returns, callback), mapped) :
25
- t.KindGuard.IsIntersect(type) ? t.Intersect(FromTypes(type.allOf, callback), mapped) :
26
- t.KindGuard.IsUnion(type) ? t.Union(FromTypes(type.anyOf, callback), mapped) :
27
- t.KindGuard.IsTuple(type) ? t.Tuple(FromTypes(type.items || [], callback), mapped) :
28
- t.KindGuard.IsArray(type) ? t.Array(FromType(type.items, callback), mapped) :
29
- t.KindGuard.IsAsyncIterator(type) ? t.AsyncIterator(FromType(type.items, callback), mapped) :
30
- t.KindGuard.IsIterator(type) ? t.Iterator(FromType(type.items, callback), mapped) :
31
- t.KindGuard.IsPromise(type) ? t.Promise(FromType(type.items, callback), mapped) :
32
- t.KindGuard.IsObject(type) ? t.Object(FromProperties(type.properties, callback), mapped) :
33
- t.KindGuard.IsRecord(type) ? t.Record(FromType(t.RecordKey(type), callback), FromType(t.RecordValue(type), callback), mapped) :
34
- t.CloneType(mapped));
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));
35
47
  }
@@ -1,19 +1,30 @@
1
- import * as t from '@sinclair/typebox.mjs';
2
- export type TCallback = (schema: t.TSchema) => t.TSchema;
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;
3
14
  export interface TMapping {
4
15
  input: unknown;
5
16
  output: unknown;
6
17
  }
7
- type TApply<Type extends t.TSchema, Mapping extends TMapping, Mapped = (Mapping & {
18
+ type TApply<Type extends TSchema, Mapping extends TMapping, Mapped = (Mapping & {
8
19
  input: Type;
9
- })['output'], Result = Mapped extends t.TSchema ? Mapped : never> = Result;
10
- type TFromProperties<Properties extends t.TProperties, Mapping extends TMapping, Result extends t.TProperties = {
20
+ })['output'], Result = Mapped extends TSchema ? Mapped : never> = Result;
21
+ type TFromProperties<Properties extends TProperties, Mapping extends TMapping, Result extends TProperties = {
11
22
  [Key in keyof Properties]: TRemap<Properties[Key], Mapping>;
12
23
  }> = Result;
13
- type TFromTypes<Types extends t.TSchema[], Mapping extends TMapping, Result extends t.TSchema[] = []> = (Types extends [infer Left extends t.TSchema, ...infer Right extends t.TSchema[]] ? TFromTypes<Right, Mapping, [...Result, TRemap<Left, Mapping>]> : Result);
14
- type TFromType<Type extends t.TSchema, Mapping extends TMapping, Result extends t.TSchema = (TApply<Type, Mapping>)> = 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;
15
26
  /** `[Internal]` Applies a recursive conditional remapping of a type and its sub type constituents */
16
- export type TRemap<Type extends t.TSchema, Mapping extends TMapping, Mapped extends t.TSchema = TFromType<Type, Mapping>, Result extends t.TSchema = (Mapped extends t.TConstructor<infer Parameters extends t.TSchema[], infer ReturnType extends t.TSchema> ? t.TConstructor<TFromTypes<Parameters, Mapping>, TFromType<ReturnType, Mapping>> : Mapped extends t.TFunction<infer Parameters extends t.TSchema[], infer ReturnType extends t.TSchema> ? t.TFunction<TFromTypes<Parameters, Mapping>, TFromType<ReturnType, Mapping>> : Mapped extends t.TIntersect<infer Types extends t.TSchema[]> ? t.TIntersect<TFromTypes<Types, Mapping>> : Mapped extends t.TUnion<infer Types extends t.TSchema[]> ? t.TUnion<TFromTypes<Types, Mapping>> : Mapped extends t.TTuple<infer Types extends t.TSchema[]> ? t.TTuple<TFromTypes<Types, Mapping>> : Mapped extends t.TArray<infer Type extends t.TSchema> ? t.TArray<TFromType<Type, Mapping>> : Mapped extends t.TAsyncIterator<infer Type extends t.TSchema> ? t.TAsyncIterator<TFromType<Type, Mapping>> : Mapped extends t.TIterator<infer Type extends t.TSchema> ? t.TIterator<TFromType<Type, Mapping>> : Mapped extends t.TPromise<infer Type extends t.TSchema> ? t.TPromise<TFromType<Type, Mapping>> : Mapped extends t.TObject<infer Properties extends t.TProperties> ? t.TObject<TFromProperties<Properties, Mapping>> : Mapped extends t.TRecord<infer Key extends t.TSchema, infer Value extends t.TSchema> ? t.TRecordOrObject<TFromType<Key, Mapping>, TFromType<Value, Mapping>> : Mapped)> = Result;
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;
17
28
  /** `[Internal]` Applies a recursive conditional remapping of a type and its sub type constituents */
18
- export declare function Remap(type: t.TSchema, callback: TCallback): t.TSchema;
29
+ export declare function Remap(type: TSchema, callback: TCallback): TSchema;
19
30
  export {};
@@ -1,4 +1,16 @@
1
- import * as t from '@sinclair/typebox.mjs';
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';
2
14
  function FromProperties(properties, func) {
3
15
  return globalThis.Object.getOwnPropertyNames(properties).reduce((result, key) => {
4
16
  return { ...result, [key]: Remap(properties[key], func) };
@@ -14,18 +26,18 @@ function FromType(type, callback) {
14
26
  // prettier-ignore
15
27
  export function Remap(type, callback) {
16
28
  // Map incoming type
17
- const mapped = t.CloneType(FromType(type, callback));
29
+ const mapped = CloneType(FromType(type, callback));
18
30
  // Return remapped interior
19
- return (t.KindGuard.IsConstructor(type) ? t.Constructor(FromTypes(type.parameters, callback), FromType(type.returns, callback), mapped) :
20
- t.KindGuard.IsFunction(type) ? t.Function(FromTypes(type.parameters, callback), FromType(type.returns, callback), mapped) :
21
- t.KindGuard.IsIntersect(type) ? t.Intersect(FromTypes(type.allOf, callback), mapped) :
22
- t.KindGuard.IsUnion(type) ? t.Union(FromTypes(type.anyOf, callback), mapped) :
23
- t.KindGuard.IsTuple(type) ? t.Tuple(FromTypes(type.items || [], callback), mapped) :
24
- t.KindGuard.IsArray(type) ? t.Array(FromType(type.items, callback), mapped) :
25
- t.KindGuard.IsAsyncIterator(type) ? t.AsyncIterator(FromType(type.items, callback), mapped) :
26
- t.KindGuard.IsIterator(type) ? t.Iterator(FromType(type.items, callback), mapped) :
27
- t.KindGuard.IsPromise(type) ? t.Promise(FromType(type.items, callback), mapped) :
28
- t.KindGuard.IsObject(type) ? t.Object(FromProperties(type.properties, callback), mapped) :
29
- t.KindGuard.IsRecord(type) ? t.Record(FromType(t.RecordKey(type), callback), FromType(t.RecordValue(type), callback), mapped) :
30
- t.CloneType(mapped));
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));
31
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.34.17",
3
+ "version": "0.34.18",
4
4
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",