@sinclair/typebox 0.33.21 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/build/cjs/compiler/compiler.d.ts +2 -2
  2. package/build/cjs/compiler/compiler.js +13 -2
  3. package/build/cjs/errors/errors.js +7 -0
  4. package/build/cjs/index.d.ts +1 -3
  5. package/build/cjs/index.js +1 -6
  6. package/build/cjs/syntax/parse.d.ts +15 -0
  7. package/build/cjs/{parse → syntax}/parse.js +6 -5
  8. package/build/cjs/{parse → syntax}/runtime.d.ts +17 -4
  9. package/build/cjs/{parse → syntax}/runtime.js +180 -27
  10. package/build/cjs/{parse → syntax}/static.d.ts +104 -20
  11. package/build/cjs/type/guard/kind.d.ts +3 -0
  12. package/build/cjs/type/guard/kind.js +5 -0
  13. package/build/cjs/type/guard/type.d.ts +3 -0
  14. package/build/cjs/type/guard/type.js +13 -0
  15. package/build/cjs/type/index.d.ts +1 -2
  16. package/build/cjs/type/index.js +1 -2
  17. package/build/cjs/type/module/index.d.ts +1 -0
  18. package/build/cjs/type/{deref → module}/index.js +1 -1
  19. package/build/cjs/type/module/module.d.ts +71 -0
  20. package/build/cjs/type/module/module.js +34 -0
  21. package/build/cjs/type/ref/ref.d.ts +4 -7
  22. package/build/cjs/type/ref/ref.js +3 -11
  23. package/build/cjs/type/static/static.d.ts +1 -1
  24. package/build/cjs/type/type/json.d.ts +4 -17
  25. package/build/cjs/type/type/json.js +52 -68
  26. package/build/cjs/type/type/type.d.ts +1 -2
  27. package/build/cjs/type/type/type.js +55 -57
  28. package/build/cjs/value/cast/cast.js +8 -1
  29. package/build/cjs/value/check/check.js +8 -1
  30. package/build/cjs/value/clean/clean.js +8 -1
  31. package/build/cjs/value/convert/convert.js +7 -0
  32. package/build/cjs/value/create/create.js +7 -0
  33. package/build/cjs/value/default/default.js +7 -0
  34. package/build/cjs/value/transform/decode.js +11 -0
  35. package/build/cjs/value/transform/encode.js +11 -0
  36. package/build/esm/compiler/compiler.d.mts +2 -2
  37. package/build/esm/compiler/compiler.mjs +13 -2
  38. package/build/esm/errors/errors.mjs +7 -0
  39. package/build/esm/index.d.mts +1 -3
  40. package/build/esm/index.mjs +1 -6
  41. package/build/esm/syntax/parse.d.mts +15 -0
  42. package/build/esm/syntax/parse.mjs +14 -0
  43. package/build/esm/{parse → syntax}/runtime.d.mts +17 -4
  44. package/build/esm/{parse → syntax}/runtime.mjs +180 -27
  45. package/build/esm/{parse → syntax}/static.d.mts +104 -20
  46. package/build/esm/type/guard/kind.d.mts +3 -0
  47. package/build/esm/type/guard/kind.mjs +4 -0
  48. package/build/esm/type/guard/type.d.mts +3 -0
  49. package/build/esm/type/guard/type.mjs +12 -0
  50. package/build/esm/type/index.d.mts +1 -2
  51. package/build/esm/type/index.mjs +1 -2
  52. package/build/esm/type/module/index.d.mts +1 -0
  53. package/build/esm/type/module/index.mjs +1 -0
  54. package/build/esm/type/module/module.d.mts +71 -0
  55. package/build/esm/type/module/module.mjs +28 -0
  56. package/build/esm/type/ref/ref.d.mts +4 -7
  57. package/build/esm/type/ref/ref.mjs +3 -11
  58. package/build/esm/type/static/static.d.mts +1 -1
  59. package/build/esm/type/type/json.d.mts +4 -17
  60. package/build/esm/type/type/json.mjs +7 -23
  61. package/build/esm/type/type/type.d.mts +1 -2
  62. package/build/esm/type/type/type.mjs +1 -2
  63. package/build/esm/value/cast/cast.mjs +9 -2
  64. package/build/esm/value/check/check.mjs +9 -2
  65. package/build/esm/value/clean/clean.mjs +9 -2
  66. package/build/esm/value/convert/convert.mjs +7 -0
  67. package/build/esm/value/create/create.mjs +7 -0
  68. package/build/esm/value/default/default.mjs +7 -0
  69. package/build/esm/value/transform/decode.mjs +11 -0
  70. package/build/esm/value/transform/encode.mjs +11 -0
  71. package/package.json +6 -6
  72. package/readme.md +219 -97
  73. package/syntax/package.json +4 -0
  74. package/build/cjs/parse/parse.d.ts +0 -11
  75. package/build/cjs/type/deref/deref.d.ts +0 -22
  76. package/build/cjs/type/deref/deref.js +0 -106
  77. package/build/cjs/type/deref/index.d.ts +0 -1
  78. package/build/cjs/type/strict/index.d.ts +0 -1
  79. package/build/cjs/type/strict/index.js +0 -18
  80. package/build/cjs/type/strict/strict.d.ts +0 -12
  81. package/build/cjs/type/strict/strict.js +0 -16
  82. package/build/esm/parse/parse.d.mts +0 -11
  83. package/build/esm/parse/parse.mjs +0 -13
  84. package/build/esm/type/deref/deref.d.mts +0 -22
  85. package/build/esm/type/deref/deref.mjs +0 -102
  86. package/build/esm/type/deref/index.d.mts +0 -1
  87. package/build/esm/type/deref/index.mjs +0 -1
  88. package/build/esm/type/strict/index.d.mts +0 -1
  89. package/build/esm/type/strict/index.mjs +0 -1
  90. package/build/esm/type/strict/strict.d.mts +0 -12
  91. package/build/esm/type/strict/strict.mjs +0 -12
  92. package/parse/package.json +0 -4
  93. /package/build/cjs/{parse → syntax}/index.d.ts +0 -0
  94. /package/build/cjs/{parse → syntax}/index.js +0 -0
  95. /package/build/cjs/{parse → syntax}/parsebox/index.d.ts +0 -0
  96. /package/build/cjs/{parse → syntax}/parsebox/index.js +0 -0
  97. /package/build/cjs/{parse → syntax}/parsebox/runtime/guard.d.ts +0 -0
  98. /package/build/cjs/{parse → syntax}/parsebox/runtime/guard.js +0 -0
  99. /package/build/cjs/{parse → syntax}/parsebox/runtime/index.d.ts +0 -0
  100. /package/build/cjs/{parse → syntax}/parsebox/runtime/index.js +0 -0
  101. /package/build/cjs/{parse → syntax}/parsebox/runtime/module.d.ts +0 -0
  102. /package/build/cjs/{parse → syntax}/parsebox/runtime/module.js +0 -0
  103. /package/build/cjs/{parse → syntax}/parsebox/runtime/parse.d.ts +0 -0
  104. /package/build/cjs/{parse → syntax}/parsebox/runtime/parse.js +0 -0
  105. /package/build/cjs/{parse → syntax}/parsebox/runtime/token.d.ts +0 -0
  106. /package/build/cjs/{parse → syntax}/parsebox/runtime/token.js +0 -0
  107. /package/build/cjs/{parse → syntax}/parsebox/runtime/types.d.ts +0 -0
  108. /package/build/cjs/{parse → syntax}/parsebox/runtime/types.js +0 -0
  109. /package/build/cjs/{parse → syntax}/parsebox/static/index.d.ts +0 -0
  110. /package/build/cjs/{parse → syntax}/parsebox/static/index.js +0 -0
  111. /package/build/cjs/{parse → syntax}/parsebox/static/parse.d.ts +0 -0
  112. /package/build/cjs/{parse → syntax}/parsebox/static/parse.js +0 -0
  113. /package/build/cjs/{parse → syntax}/parsebox/static/token.d.ts +0 -0
  114. /package/build/cjs/{parse → syntax}/parsebox/static/token.js +0 -0
  115. /package/build/cjs/{parse → syntax}/parsebox/static/types.d.ts +0 -0
  116. /package/build/cjs/{parse → syntax}/parsebox/static/types.js +0 -0
  117. /package/build/cjs/{parse → syntax}/static.js +0 -0
  118. /package/build/esm/{parse → syntax}/index.d.mts +0 -0
  119. /package/build/esm/{parse → syntax}/index.mjs +0 -0
  120. /package/build/esm/{parse → syntax}/parsebox/index.d.mts +0 -0
  121. /package/build/esm/{parse → syntax}/parsebox/index.mjs +0 -0
  122. /package/build/esm/{parse → syntax}/parsebox/runtime/guard.d.mts +0 -0
  123. /package/build/esm/{parse → syntax}/parsebox/runtime/guard.mjs +0 -0
  124. /package/build/esm/{parse → syntax}/parsebox/runtime/index.d.mts +0 -0
  125. /package/build/esm/{parse → syntax}/parsebox/runtime/index.mjs +0 -0
  126. /package/build/esm/{parse → syntax}/parsebox/runtime/module.d.mts +0 -0
  127. /package/build/esm/{parse → syntax}/parsebox/runtime/module.mjs +0 -0
  128. /package/build/esm/{parse → syntax}/parsebox/runtime/parse.d.mts +0 -0
  129. /package/build/esm/{parse → syntax}/parsebox/runtime/parse.mjs +0 -0
  130. /package/build/esm/{parse → syntax}/parsebox/runtime/token.d.mts +0 -0
  131. /package/build/esm/{parse → syntax}/parsebox/runtime/token.mjs +0 -0
  132. /package/build/esm/{parse → syntax}/parsebox/runtime/types.d.mts +0 -0
  133. /package/build/esm/{parse → syntax}/parsebox/runtime/types.mjs +0 -0
  134. /package/build/esm/{parse → syntax}/parsebox/static/index.d.mts +0 -0
  135. /package/build/esm/{parse → syntax}/parsebox/static/index.mjs +0 -0
  136. /package/build/esm/{parse → syntax}/parsebox/static/parse.d.mts +0 -0
  137. /package/build/esm/{parse → syntax}/parsebox/static/parse.mjs +0 -0
  138. /package/build/esm/{parse → syntax}/parsebox/static/token.d.mts +0 -0
  139. /package/build/esm/{parse → syntax}/parsebox/static/token.mjs +0 -0
  140. /package/build/esm/{parse → syntax}/parsebox/static/types.d.mts +0 -0
  141. /package/build/esm/{parse → syntax}/parsebox/static/types.mjs +0 -0
  142. /package/build/esm/{parse → syntax}/static.mjs +0 -0
@@ -1,22 +0,0 @@
1
- import type { TSchema } from '../schema/index';
2
- import type { Evaluate } from '../helpers/index';
3
- import type { TTuple } from '../tuple/index';
4
- import type { TIntersect } from '../intersect/index';
5
- import type { TUnion } from '../union/index';
6
- import type { TPromise } from '../promise/index';
7
- import type { TAsyncIterator } from '../async-iterator/index';
8
- import type { TIterator } from '../iterator/index';
9
- import type { TArray } from '../array/index';
10
- import type { TConstructor } from '../constructor/index';
11
- import type { TFunction } from '../function/index';
12
- import type { TRef } from '../ref/index';
13
- import type { TObject, TProperties } from '../object/index';
14
- export type TFromRest<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Acc, TDeref<L>]> : Acc);
15
- type FromProperties<T extends TProperties> = Evaluate<{
16
- [K in keyof T]: TDeref<T[K]>;
17
- }>;
18
- declare function FromProperties(properties: TProperties, references: TSchema[]): never;
19
- export type TDeref<T extends TSchema> = T extends TConstructor<infer S extends TSchema[], infer R extends TSchema> ? TConstructor<TFromRest<S>, TDeref<R>> : T extends TFunction<infer S extends TSchema[], infer R extends TSchema> ? TFunction<TFromRest<S>, TDeref<R>> : T extends TIntersect<infer S extends TSchema[]> ? TIntersect<TFromRest<S>> : T extends TUnion<infer S extends TSchema[]> ? TUnion<TFromRest<S>> : T extends TTuple<infer S extends TSchema[]> ? TTuple<TFromRest<S>> : T extends TObject<infer S extends TProperties> ? TObject<FromProperties<S>> : T extends TArray<infer S extends TSchema> ? TArray<TDeref<S>> : T extends TPromise<infer S extends TSchema> ? TPromise<TDeref<S>> : T extends TAsyncIterator<infer S extends TSchema> ? TAsyncIterator<TDeref<S>> : T extends TIterator<infer S extends TSchema> ? TIterator<TDeref<S>> : T extends TRef<infer S extends TSchema> ? TDeref<S> : T;
20
- /** `[Json]` Creates a dereferenced type */
21
- export declare function Deref<T extends TSchema>(schema: T, references: TSchema[]): TDeref<T>;
22
- export {};
@@ -1,106 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.Deref = Deref;
5
- const type_1 = require("../clone/type");
6
- const index_1 = require("../discard/index");
7
- const value_1 = require("../guard/value");
8
- // ------------------------------------------------------------------
9
- // TypeGuard
10
- // ------------------------------------------------------------------
11
- const kind_1 = require("../guard/kind");
12
- function FromRest(schema, references) {
13
- return schema.map((schema) => Deref(schema, references));
14
- }
15
- // prettier-ignore
16
- function FromProperties(properties, references) {
17
- const Acc = {};
18
- for (const K of globalThis.Object.getOwnPropertyNames(properties)) {
19
- Acc[K] = Deref(properties[K], references);
20
- }
21
- return Acc;
22
- }
23
- // prettier-ignore
24
- function FromConstructor(schema, references) {
25
- schema.parameters = FromRest(schema.parameters, references);
26
- schema.returns = Deref(schema.returns, references);
27
- return schema;
28
- }
29
- // prettier-ignore
30
- function FromFunction(schema, references) {
31
- schema.parameters = FromRest(schema.parameters, references);
32
- schema.returns = Deref(schema.returns, references);
33
- return schema;
34
- }
35
- // prettier-ignore
36
- function FromIntersect(schema, references) {
37
- schema.allOf = FromRest(schema.allOf, references);
38
- return schema;
39
- }
40
- // prettier-ignore
41
- function FromUnion(schema, references) {
42
- schema.anyOf = FromRest(schema.anyOf, references);
43
- return schema;
44
- }
45
- // prettier-ignore
46
- function FromTuple(schema, references) {
47
- if ((0, value_1.IsUndefined)(schema.items))
48
- return schema;
49
- schema.items = FromRest(schema.items, references);
50
- return schema;
51
- }
52
- // prettier-ignore
53
- function FromArray(schema, references) {
54
- schema.items = Deref(schema.items, references);
55
- return schema;
56
- }
57
- // prettier-ignore
58
- function FromObject(schema, references) {
59
- schema.properties = FromProperties(schema.properties, references);
60
- return schema;
61
- }
62
- // prettier-ignore
63
- function FromPromise(schema, references) {
64
- schema.item = Deref(schema.item, references);
65
- return schema;
66
- }
67
- // prettier-ignore
68
- function FromAsyncIterator(schema, references) {
69
- schema.items = Deref(schema.items, references);
70
- return schema;
71
- }
72
- // prettier-ignore
73
- function FromIterator(schema, references) {
74
- schema.items = Deref(schema.items, references);
75
- return schema;
76
- }
77
- // prettier-ignore
78
- function FromRef(schema, references) {
79
- const target = references.find(remote => remote.$id === schema.$ref);
80
- if (target === undefined)
81
- throw Error(`Unable to dereference schema with $id ${schema.$ref}`);
82
- const discard = (0, index_1.Discard)(target, ['$id']);
83
- return Deref(discard, references);
84
- }
85
- // prettier-ignore
86
- function DerefResolve(schema, references) {
87
- return ((0, kind_1.IsConstructor)(schema) ? FromConstructor(schema, references) :
88
- (0, kind_1.IsFunction)(schema) ? FromFunction(schema, references) :
89
- (0, kind_1.IsIntersect)(schema) ? FromIntersect(schema, references) :
90
- (0, kind_1.IsUnion)(schema) ? FromUnion(schema, references) :
91
- (0, kind_1.IsTuple)(schema) ? FromTuple(schema, references) :
92
- (0, kind_1.IsArray)(schema) ? FromArray(schema, references) :
93
- (0, kind_1.IsObject)(schema) ? FromObject(schema, references) :
94
- (0, kind_1.IsPromise)(schema) ? FromPromise(schema, references) :
95
- (0, kind_1.IsAsyncIterator)(schema) ? FromAsyncIterator(schema, references) :
96
- (0, kind_1.IsIterator)(schema) ? FromIterator(schema, references) :
97
- (0, kind_1.IsRef)(schema) ? FromRef(schema, references) :
98
- schema);
99
- }
100
- // ------------------------------------------------------------------
101
- // TDeref
102
- // ------------------------------------------------------------------
103
- /** `[Json]` Creates a dereferenced type */
104
- function Deref(schema, references) {
105
- return DerefResolve((0, type_1.CloneType)(schema), (0, type_1.CloneRest)(references));
106
- }
@@ -1 +0,0 @@
1
- export * from './deref';
@@ -1 +0,0 @@
1
- export * from './strict';
@@ -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("./strict"), exports);
@@ -1,12 +0,0 @@
1
- import type { TSchema } from '../schema/index';
2
- export type TStrict<T extends TSchema> = T;
3
- /**
4
- * @deprecated `[Json]` Omits compositing symbols from this schema. It is recommended
5
- * to use the JSON parse/stringify to remove compositing symbols if needed. This
6
- * is how Strict works internally.
7
- *
8
- * ```typescript
9
- * JSON.parse(JSON.stringify(Type.String()))
10
- * ```
11
- */
12
- export declare function Strict<T extends TSchema>(schema: T): TStrict<T>;
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.Strict = Strict;
5
- /**
6
- * @deprecated `[Json]` Omits compositing symbols from this schema. It is recommended
7
- * to use the JSON parse/stringify to remove compositing symbols if needed. This
8
- * is how Strict works internally.
9
- *
10
- * ```typescript
11
- * JSON.parse(JSON.stringify(Type.String()))
12
- * ```
13
- */
14
- function Strict(schema) {
15
- return JSON.parse(JSON.stringify(schema));
16
- }
@@ -1,11 +0,0 @@
1
- import { Static } from './parsebox/index.mjs';
2
- import { TSchema, SchemaOptions } from '../type/schema/index.mjs';
3
- import { Type } from './static.mjs';
4
- /** `[Experimental]` Parses a TypeScript type annotation as an inferred TypeBox type */
5
- export declare function Parse<Code extends string, Context extends Record<PropertyKey, TSchema> = {}>(context: Context, code: Code, options?: SchemaOptions): Static.Parse<Type, Code, Context>[0];
6
- /** `[Experimental]` Parses a TypeScript type annotation as an inferred TypeBox type */
7
- export declare function Parse<Code extends string>(code: Code, options?: SchemaOptions): Static.Parse<Type, Code, {}>[0];
8
- /** `[Experimental]` Parses a TypeScript type annotation as TSchema */
9
- export declare function ParseOnly<Code extends string, Context extends Record<PropertyKey, TSchema> = {}>(context: Context, code: Code, options?: SchemaOptions): TSchema | undefined;
10
- /** `[Experimental]` Parses a TypeScript type annotation as TSchema */
11
- export declare function ParseOnly<Code extends string>(code: Code, options?: SchemaOptions): TSchema | undefined;
@@ -1,13 +0,0 @@
1
- import { CreateType } from '../type/create/type.mjs';
2
- import { Module } from './runtime.mjs';
3
- /** `[Experimental]` Parses a TypeScript type annotation as an inferred TypeBox type */
4
- export function Parse(...args) {
5
- return ParseOnly.apply(null, args);
6
- }
7
- /** `[Experimental]` Parses a TypeScript type annotation as TSchema */
8
- export function ParseOnly(...args) {
9
- const withContext = typeof args[0] === 'string' ? false : true;
10
- const [context, code, options] = withContext ? [args[0], args[1], args[2] || {}] : [{}, args[0], args[1] || {}];
11
- const type = Module.Parse('Type', code, context)[0];
12
- return (type !== undefined ? CreateType(type, options) : undefined);
13
- }
@@ -1,22 +0,0 @@
1
- import type { TSchema } from '../schema/index.mjs';
2
- import type { Evaluate } from '../helpers/index.mjs';
3
- import type { TTuple } from '../tuple/index.mjs';
4
- import type { TIntersect } from '../intersect/index.mjs';
5
- import type { TUnion } from '../union/index.mjs';
6
- import type { TPromise } from '../promise/index.mjs';
7
- import type { TAsyncIterator } from '../async-iterator/index.mjs';
8
- import type { TIterator } from '../iterator/index.mjs';
9
- import type { TArray } from '../array/index.mjs';
10
- import type { TConstructor } from '../constructor/index.mjs';
11
- import type { TFunction } from '../function/index.mjs';
12
- import type { TRef } from '../ref/index.mjs';
13
- import type { TObject, TProperties } from '../object/index.mjs';
14
- export type TFromRest<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Acc, TDeref<L>]> : Acc);
15
- type FromProperties<T extends TProperties> = Evaluate<{
16
- [K in keyof T]: TDeref<T[K]>;
17
- }>;
18
- declare function FromProperties(properties: TProperties, references: TSchema[]): never;
19
- export type TDeref<T extends TSchema> = T extends TConstructor<infer S extends TSchema[], infer R extends TSchema> ? TConstructor<TFromRest<S>, TDeref<R>> : T extends TFunction<infer S extends TSchema[], infer R extends TSchema> ? TFunction<TFromRest<S>, TDeref<R>> : T extends TIntersect<infer S extends TSchema[]> ? TIntersect<TFromRest<S>> : T extends TUnion<infer S extends TSchema[]> ? TUnion<TFromRest<S>> : T extends TTuple<infer S extends TSchema[]> ? TTuple<TFromRest<S>> : T extends TObject<infer S extends TProperties> ? TObject<FromProperties<S>> : T extends TArray<infer S extends TSchema> ? TArray<TDeref<S>> : T extends TPromise<infer S extends TSchema> ? TPromise<TDeref<S>> : T extends TAsyncIterator<infer S extends TSchema> ? TAsyncIterator<TDeref<S>> : T extends TIterator<infer S extends TSchema> ? TIterator<TDeref<S>> : T extends TRef<infer S extends TSchema> ? TDeref<S> : T;
20
- /** `[Json]` Creates a dereferenced type */
21
- export declare function Deref<T extends TSchema>(schema: T, references: TSchema[]): TDeref<T>;
22
- export {};
@@ -1,102 +0,0 @@
1
- import { CloneType, CloneRest } from '../clone/type.mjs';
2
- import { Discard } from '../discard/index.mjs';
3
- import { IsUndefined } from '../guard/value.mjs';
4
- // ------------------------------------------------------------------
5
- // TypeGuard
6
- // ------------------------------------------------------------------
7
- import { IsConstructor, IsFunction, IsIntersect, IsUnion, IsTuple, IsArray, IsObject, IsPromise, IsAsyncIterator, IsIterator, IsRef } from '../guard/kind.mjs';
8
- function FromRest(schema, references) {
9
- return schema.map((schema) => Deref(schema, references));
10
- }
11
- // prettier-ignore
12
- function FromProperties(properties, references) {
13
- const Acc = {};
14
- for (const K of globalThis.Object.getOwnPropertyNames(properties)) {
15
- Acc[K] = Deref(properties[K], references);
16
- }
17
- return Acc;
18
- }
19
- // prettier-ignore
20
- function FromConstructor(schema, references) {
21
- schema.parameters = FromRest(schema.parameters, references);
22
- schema.returns = Deref(schema.returns, references);
23
- return schema;
24
- }
25
- // prettier-ignore
26
- function FromFunction(schema, references) {
27
- schema.parameters = FromRest(schema.parameters, references);
28
- schema.returns = Deref(schema.returns, references);
29
- return schema;
30
- }
31
- // prettier-ignore
32
- function FromIntersect(schema, references) {
33
- schema.allOf = FromRest(schema.allOf, references);
34
- return schema;
35
- }
36
- // prettier-ignore
37
- function FromUnion(schema, references) {
38
- schema.anyOf = FromRest(schema.anyOf, references);
39
- return schema;
40
- }
41
- // prettier-ignore
42
- function FromTuple(schema, references) {
43
- if (IsUndefined(schema.items))
44
- return schema;
45
- schema.items = FromRest(schema.items, references);
46
- return schema;
47
- }
48
- // prettier-ignore
49
- function FromArray(schema, references) {
50
- schema.items = Deref(schema.items, references);
51
- return schema;
52
- }
53
- // prettier-ignore
54
- function FromObject(schema, references) {
55
- schema.properties = FromProperties(schema.properties, references);
56
- return schema;
57
- }
58
- // prettier-ignore
59
- function FromPromise(schema, references) {
60
- schema.item = Deref(schema.item, references);
61
- return schema;
62
- }
63
- // prettier-ignore
64
- function FromAsyncIterator(schema, references) {
65
- schema.items = Deref(schema.items, references);
66
- return schema;
67
- }
68
- // prettier-ignore
69
- function FromIterator(schema, references) {
70
- schema.items = Deref(schema.items, references);
71
- return schema;
72
- }
73
- // prettier-ignore
74
- function FromRef(schema, references) {
75
- const target = references.find(remote => remote.$id === schema.$ref);
76
- if (target === undefined)
77
- throw Error(`Unable to dereference schema with $id ${schema.$ref}`);
78
- const discard = Discard(target, ['$id']);
79
- return Deref(discard, references);
80
- }
81
- // prettier-ignore
82
- function DerefResolve(schema, references) {
83
- return (IsConstructor(schema) ? FromConstructor(schema, references) :
84
- IsFunction(schema) ? FromFunction(schema, references) :
85
- IsIntersect(schema) ? FromIntersect(schema, references) :
86
- IsUnion(schema) ? FromUnion(schema, references) :
87
- IsTuple(schema) ? FromTuple(schema, references) :
88
- IsArray(schema) ? FromArray(schema, references) :
89
- IsObject(schema) ? FromObject(schema, references) :
90
- IsPromise(schema) ? FromPromise(schema, references) :
91
- IsAsyncIterator(schema) ? FromAsyncIterator(schema, references) :
92
- IsIterator(schema) ? FromIterator(schema, references) :
93
- IsRef(schema) ? FromRef(schema, references) :
94
- schema);
95
- }
96
- // ------------------------------------------------------------------
97
- // TDeref
98
- // ------------------------------------------------------------------
99
- /** `[Json]` Creates a dereferenced type */
100
- export function Deref(schema, references) {
101
- return DerefResolve(CloneType(schema), CloneRest(references));
102
- }
@@ -1 +0,0 @@
1
- export * from './deref.mjs';
@@ -1 +0,0 @@
1
- export * from './deref.mjs';
@@ -1 +0,0 @@
1
- export * from './strict.mjs';
@@ -1 +0,0 @@
1
- export * from './strict.mjs';
@@ -1,12 +0,0 @@
1
- import type { TSchema } from '../schema/index.mjs';
2
- export type TStrict<T extends TSchema> = T;
3
- /**
4
- * @deprecated `[Json]` Omits compositing symbols from this schema. It is recommended
5
- * to use the JSON parse/stringify to remove compositing symbols if needed. This
6
- * is how Strict works internally.
7
- *
8
- * ```typescript
9
- * JSON.parse(JSON.stringify(Type.String()))
10
- * ```
11
- */
12
- export declare function Strict<T extends TSchema>(schema: T): TStrict<T>;
@@ -1,12 +0,0 @@
1
- /**
2
- * @deprecated `[Json]` Omits compositing symbols from this schema. It is recommended
3
- * to use the JSON parse/stringify to remove compositing symbols if needed. This
4
- * is how Strict works internally.
5
- *
6
- * ```typescript
7
- * JSON.parse(JSON.stringify(Type.String()))
8
- * ```
9
- */
10
- export function Strict(schema) {
11
- return JSON.parse(JSON.stringify(schema));
12
- }
@@ -1,4 +0,0 @@
1
- {
2
- "main": "../build/cjs/parse/index.js",
3
- "types": "../build/cjs/parse/index.d.ts"
4
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes