typia 6.7.2 → 6.8.0-dev.20240811

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 (63) hide show
  1. package/lib/programmers/internal/application_bigint.d.ts +1 -0
  2. package/lib/programmers/internal/application_bigint.js +14 -0
  3. package/lib/programmers/internal/application_bigint.js.map +1 -0
  4. package/lib/programmers/internal/application_v30_schema.js +10 -12
  5. package/lib/programmers/internal/application_v30_schema.js.map +1 -1
  6. package/lib/programmers/internal/application_v31_constant.js +3 -1
  7. package/lib/programmers/internal/application_v31_constant.js.map +1 -1
  8. package/lib/programmers/internal/application_v31_schema.js +10 -12
  9. package/lib/programmers/internal/application_v31_schema.js.map +1 -1
  10. package/lib/tags/Constant.d.ts +2 -2
  11. package/lib/tags/Default.d.ts +5 -1
  12. package/lib/tags/ExclusiveMaximum.d.ts +9 -5
  13. package/lib/tags/ExclusiveMinimum.d.ts +9 -5
  14. package/lib/tags/JsonSchemaPlugin.d.ts +1 -1
  15. package/lib/tags/Maximum.d.ts +8 -5
  16. package/lib/tags/Minimum.d.ts +8 -5
  17. package/lib/tags/MultipleOf.d.ts +7 -4
  18. package/package.json +2 -2
  19. package/src/factories/CommentFactory.ts +79 -79
  20. package/src/factories/MetadataCollection.ts +274 -274
  21. package/src/factories/MetadataFactory.ts +272 -272
  22. package/src/factories/StatementFactory.ts +74 -74
  23. package/src/factories/TypeFactory.ts +118 -118
  24. package/src/factories/internal/metadata/emplace_metadata_array_type.ts +42 -42
  25. package/src/factories/internal/metadata/emplace_metadata_object.ts +176 -176
  26. package/src/factories/internal/metadata/iterate_metadata.ts +94 -94
  27. package/src/factories/internal/metadata/iterate_metadata_array.ts +63 -63
  28. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +62 -62
  29. package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
  30. package/src/factories/internal/metadata/iterate_metadata_constant.ts +76 -76
  31. package/src/factories/internal/metadata/iterate_metadata_intersection.ts +213 -213
  32. package/src/factories/internal/metadata/iterate_metadata_map.ts +50 -50
  33. package/src/factories/internal/metadata/iterate_metadata_native.ts +220 -220
  34. package/src/factories/internal/metadata/iterate_metadata_object.ts +33 -33
  35. package/src/factories/internal/metadata/iterate_metadata_set.ts +41 -41
  36. package/src/factories/internal/metadata/iterate_metadata_template.ts +44 -44
  37. package/src/factories/internal/metadata/iterate_metadata_union.ts +27 -27
  38. package/src/programmers/internal/application_bigint.ts +25 -0
  39. package/src/programmers/internal/application_v30_alias.ts +52 -52
  40. package/src/programmers/internal/application_v30_object.ts +149 -149
  41. package/src/programmers/internal/application_v30_schema.ts +162 -159
  42. package/src/programmers/internal/application_v30_tuple.ts +33 -33
  43. package/src/programmers/internal/application_v31_constant.ts +4 -1
  44. package/src/programmers/internal/application_v31_schema.ts +159 -157
  45. package/src/programmers/json/JsonApplicationProgrammer.ts +82 -82
  46. package/src/schemas/metadata/IMetadataConstantValue.ts +11 -11
  47. package/src/schemas/metadata/IMetadataTemplate.ts +7 -7
  48. package/src/tags/Constant.ts +2 -2
  49. package/src/tags/Default.ts +7 -3
  50. package/src/tags/ExclusiveMaximum.ts +12 -6
  51. package/src/tags/ExclusiveMinimum.ts +12 -6
  52. package/src/tags/JsonSchemaPlugin.ts +1 -1
  53. package/src/tags/Maximum.ts +9 -8
  54. package/src/tags/Minimum.ts +9 -8
  55. package/src/tags/MultipleOf.ts +9 -8
  56. package/src/tags/Type.ts +32 -32
  57. package/src/transformers/FileTransformer.ts +91 -91
  58. package/src/transformers/features/CreateRandomTransformer.ts +40 -40
  59. package/src/transformers/features/RandomTransformer.ts +44 -44
  60. package/src/transformers/features/json/JsonApplicationTransformer.ts +124 -124
  61. package/src/transformers/features/misc/MiscLiteralsTransformer.ts +32 -32
  62. package/src/transformers/features/protobuf/ProtobufMessageTransformer.ts +33 -33
  63. package/src/transformers/features/reflect/ReflectMetadataTransformer.ts +62 -62
@@ -1,157 +1,159 @@
1
- import { OpenApi } from "@samchon/openapi";
2
-
3
- import { Metadata } from "../../schemas/metadata/Metadata";
4
- import { MetadataAtomic } from "../../schemas/metadata/MetadataAtomic";
5
-
6
- import { AtomicPredicator } from "../helpers/AtomicPredicator";
7
- import { application_array } from "./application_array";
8
- import { application_boolean } from "./application_boolean";
9
- import { application_escaped } from "./application_escaped";
10
- import { application_number } from "./application_number";
11
- import { application_string } from "./application_string";
12
- import { application_templates } from "./application_templates";
13
- import { application_union_discriminator } from "./application_union_discriminator";
14
- import { application_v31_alias } from "./application_v31_alias";
15
- import { application_v31_constant } from "./application_v31_constant";
16
- import { application_v31_native } from "./application_v31_native";
17
- import { application_v31_object } from "./application_v31_object";
18
- import { application_v31_tuple } from "./application_v31_tuple";
19
-
20
- /**
21
- * @internal
22
- */
23
- export const application_v31_schema =
24
- <BlockNever extends boolean>(blockNever: BlockNever) =>
25
- (components: OpenApi.IComponents) =>
26
- (attribute: OpenApi.IJsonSchema.__IAttribute) =>
27
- (
28
- meta: Metadata,
29
- ): BlockNever extends true
30
- ? OpenApi.IJsonSchema | null
31
- : OpenApi.IJsonSchema => {
32
- if (meta.any === true)
33
- return {
34
- ...attribute,
35
- type: undefined,
36
- };
37
-
38
- //----
39
- // GATHER UNION SCHEMAS
40
- //----
41
- const union: OpenApi.IJsonSchema[] = [];
42
- const insert = (schema: OpenApi.IJsonSchema) => union.push(schema);
43
-
44
- // NULLABLE
45
- if (meta.nullable === true)
46
- insert({
47
- type: "null",
48
- });
49
-
50
- // toJSON() METHOD
51
- if (meta.escaped !== null)
52
- application_escaped(application_v31_schema(false)(components)({}))(
53
- meta.escaped,
54
- ).forEach(insert as any);
55
-
56
- // ATOMIC TYPES
57
- if (meta.templates.length && AtomicPredicator.template(meta))
58
- application_templates(meta).map(insert as any);
59
- for (const constant of meta.constants)
60
- if (constant.type === "bigint") throw new TypeError(NO_BIGINT);
61
- else if (AtomicPredicator.constant(meta)(constant.type) === false)
62
- continue;
63
- else application_v31_constant(constant).map(insert);
64
- for (const a of meta.atomics)
65
- if (a.type === "bigint") throw new TypeError(NO_BIGINT);
66
- else if (a.type === "boolean")
67
- application_boolean(a).forEach(insert as any);
68
- else if (a.type === "number")
69
- application_number(a).forEach(insert as any);
70
- else if (a.type === "string")
71
- application_string(a).forEach(insert as any);
72
-
73
- // ARRAY
74
- for (const array of meta.arrays)
75
- application_array(application_v31_schema(false)(components)({}))(
76
- components,
77
- )(array).forEach(insert as any);
78
-
79
- // TUPLE
80
- for (const tuple of meta.tuples)
81
- insert(
82
- application_v31_tuple(application_v31_schema(false)(components)({}))(
83
- tuple,
84
- ),
85
- );
86
-
87
- // NATIVES
88
- for (const native of meta.natives)
89
- if (AtomicPredicator.native(native)) {
90
- const type: string = native.toLowerCase();
91
- if (meta.atomics.some((a) => a.type === type)) continue;
92
- else if (type === "bigint") throw new TypeError(NO_BIGINT);
93
- else if (type === "boolean")
94
- insert(
95
- application_boolean(
96
- MetadataAtomic.create({
97
- type: "boolean",
98
- tags: [],
99
- }),
100
- )[0]! as any,
101
- );
102
- else if (type === "number")
103
- insert(
104
- application_number(
105
- MetadataAtomic.create({
106
- type: "number",
107
- tags: [],
108
- }),
109
- )[0]! as any,
110
- );
111
- else if (type === "string")
112
- insert(
113
- application_string(
114
- MetadataAtomic.create({
115
- type: "string",
116
- tags: [],
117
- }),
118
- )[0]! as any,
119
- );
120
- } else insert(application_v31_native(components)(native));
121
- if (meta.sets.length) insert(application_v31_native(components)(`Set`));
122
- if (meta.maps.length) insert(application_v31_native(components)(`Map`));
123
-
124
- // OBJECT
125
- for (const obj of meta.objects)
126
- insert(application_v31_object(components)(obj));
127
-
128
- // ALIASES
129
- for (const alias of meta.aliases)
130
- insert(application_v31_alias(blockNever)(components)(alias));
131
-
132
- //----
133
- // RETURNS
134
- //----
135
- if (union.length === 0 && blockNever === true) return null!;
136
- const schema: OpenApi.IJsonSchema =
137
- union.length === 0
138
- ? { type: undefined }
139
- : union.length === 1
140
- ? union[0]!
141
- : {
142
- oneOf: union,
143
- discriminator: application_union_discriminator(meta),
144
- };
145
- return {
146
- ...schema,
147
- ...attribute,
148
- title: attribute.title ?? schema.title,
149
- description: attribute.description ?? schema.description,
150
- deprecated: attribute.deprecated ?? schema.deprecated,
151
- };
152
- };
153
-
154
- /**
155
- * @internal
156
- */
157
- const NO_BIGINT = "Error on typia.application(): does not allow bigint type.";
1
+ import { OpenApi } from "@samchon/openapi";
2
+
3
+ import { Metadata } from "../../schemas/metadata/Metadata";
4
+ import { MetadataAtomic } from "../../schemas/metadata/MetadataAtomic";
5
+
6
+ import { AtomicPredicator } from "../helpers/AtomicPredicator";
7
+ import { application_array } from "./application_array";
8
+ import { application_bigint } from "./application_bigint";
9
+ import { application_boolean } from "./application_boolean";
10
+ import { application_escaped } from "./application_escaped";
11
+ import { application_number } from "./application_number";
12
+ import { application_string } from "./application_string";
13
+ import { application_templates } from "./application_templates";
14
+ import { application_union_discriminator } from "./application_union_discriminator";
15
+ import { application_v31_alias } from "./application_v31_alias";
16
+ import { application_v31_constant } from "./application_v31_constant";
17
+ import { application_v31_native } from "./application_v31_native";
18
+ import { application_v31_object } from "./application_v31_object";
19
+ import { application_v31_tuple } from "./application_v31_tuple";
20
+
21
+ /**
22
+ * @internal
23
+ */
24
+ export const application_v31_schema =
25
+ <BlockNever extends boolean>(blockNever: BlockNever) =>
26
+ (components: OpenApi.IComponents) =>
27
+ (attribute: OpenApi.IJsonSchema.__IAttribute) =>
28
+ (
29
+ meta: Metadata,
30
+ ): BlockNever extends true
31
+ ? OpenApi.IJsonSchema | null
32
+ : OpenApi.IJsonSchema => {
33
+ if (meta.any === true)
34
+ return {
35
+ ...attribute,
36
+ type: undefined,
37
+ };
38
+
39
+ //----
40
+ // GATHER UNION SCHEMAS
41
+ //----
42
+ const union: OpenApi.IJsonSchema[] = [];
43
+ const insert = (schema: OpenApi.IJsonSchema) => union.push(schema);
44
+
45
+ // NULLABLE
46
+ if (meta.nullable === true)
47
+ insert({
48
+ type: "null",
49
+ });
50
+
51
+ // toJSON() METHOD
52
+ if (meta.escaped !== null)
53
+ application_escaped(application_v31_schema(false)(components)({}))(
54
+ meta.escaped,
55
+ ).forEach(insert as any);
56
+
57
+ // ATOMIC TYPES
58
+ if (meta.templates.length && AtomicPredicator.template(meta))
59
+ application_templates(meta).map(insert as any);
60
+ for (const constant of meta.constants)
61
+ if (AtomicPredicator.constant(meta)(constant.type) === false) continue;
62
+ else application_v31_constant(constant).map(insert);
63
+ for (const a of meta.atomics)
64
+ if (a.type === "boolean") application_boolean(a).forEach(insert as any);
65
+ else if (a.type === "bigint")
66
+ application_bigint(a).forEach(insert as any);
67
+ else if (a.type === "number")
68
+ application_number(a).forEach(insert as any);
69
+ else if (a.type === "string")
70
+ application_string(a).forEach(insert as any);
71
+
72
+ // ARRAY
73
+ for (const array of meta.arrays)
74
+ application_array(application_v31_schema(false)(components)({}))(
75
+ components,
76
+ )(array).forEach(insert as any);
77
+
78
+ // TUPLE
79
+ for (const tuple of meta.tuples)
80
+ insert(
81
+ application_v31_tuple(application_v31_schema(false)(components)({}))(
82
+ tuple,
83
+ ),
84
+ );
85
+
86
+ // NATIVES
87
+ for (const native of meta.natives)
88
+ if (AtomicPredicator.native(native)) {
89
+ const type: string = native.toLowerCase();
90
+ if (meta.atomics.some((a) => a.type === type)) continue;
91
+ else if (type === "boolean")
92
+ insert(
93
+ application_boolean(
94
+ MetadataAtomic.create({
95
+ type: "boolean",
96
+ tags: [],
97
+ }),
98
+ )[0]! as any,
99
+ );
100
+ else if (type === "bigint")
101
+ insert(
102
+ application_bigint(
103
+ MetadataAtomic.create({
104
+ type: "bigint",
105
+ tags: [],
106
+ }),
107
+ )[0]! as any,
108
+ );
109
+ else if (type === "number")
110
+ insert(
111
+ application_number(
112
+ MetadataAtomic.create({
113
+ type: "number",
114
+ tags: [],
115
+ }),
116
+ )[0]! as any,
117
+ );
118
+ else if (type === "string")
119
+ insert(
120
+ application_string(
121
+ MetadataAtomic.create({
122
+ type: "string",
123
+ tags: [],
124
+ }),
125
+ )[0]! as any,
126
+ );
127
+ } else insert(application_v31_native(components)(native));
128
+ if (meta.sets.length) insert(application_v31_native(components)(`Set`));
129
+ if (meta.maps.length) insert(application_v31_native(components)(`Map`));
130
+
131
+ // OBJECT
132
+ for (const obj of meta.objects)
133
+ insert(application_v31_object(components)(obj));
134
+
135
+ // ALIASES
136
+ for (const alias of meta.aliases)
137
+ insert(application_v31_alias(blockNever)(components)(alias));
138
+
139
+ //----
140
+ // RETURNS
141
+ //----
142
+ if (union.length === 0 && blockNever === true) return null!;
143
+ const schema: OpenApi.IJsonSchema =
144
+ union.length === 0
145
+ ? { type: undefined }
146
+ : union.length === 1
147
+ ? union[0]!
148
+ : {
149
+ oneOf: union,
150
+ discriminator: application_union_discriminator(meta),
151
+ };
152
+ return {
153
+ ...schema,
154
+ ...attribute,
155
+ title: attribute.title ?? schema.title,
156
+ description: attribute.description ?? schema.description,
157
+ deprecated: attribute.deprecated ?? schema.deprecated,
158
+ };
159
+ };
@@ -1,82 +1,82 @@
1
- import { OpenApi, OpenApiV3 } from "@samchon/openapi";
2
-
3
- import { IJsonApplication } from "../../schemas/json/IJsonApplication";
4
- import { Metadata } from "../../schemas/metadata/Metadata";
5
-
6
- import { TransformerError } from "../../transformers/TransformerError";
7
-
8
- import { AtomicPredicator } from "../helpers/AtomicPredicator";
9
- import { application_v30_schema } from "../internal/application_v30_schema";
10
- import { application_v31_schema } from "../internal/application_v31_schema";
11
-
12
- export namespace JsonApplicationProgrammer {
13
- export const validate = (meta: Metadata) => {
14
- const output: string[] = [];
15
- if (
16
- meta.atomics.some((a) => a.type === "bigint") ||
17
- meta.constants.some((c) => c.type === "bigint")
18
- )
19
- output.push("JSON schema does not support bigint type.");
20
- if (
21
- meta.tuples.some((t) =>
22
- t.type.elements.some((e) => e.isRequired() === false),
23
- ) ||
24
- meta.arrays.some((a) => a.type.value.isRequired() === false)
25
- )
26
- output.push("JSON schema does not support undefined type in array.");
27
- if (meta.maps.length) output.push("JSON schema does not support Map type.");
28
- if (meta.sets.length) output.push("JSON schema does not support Set type.");
29
- for (const native of meta.natives)
30
- if (
31
- AtomicPredicator.native(native) === false &&
32
- native !== "Date" &&
33
- native !== "Blob" &&
34
- native !== "File"
35
- )
36
- output.push(`JSON schema does not support ${native} type.`);
37
- return output;
38
- };
39
-
40
- export const write = <Version extends "3.0" | "3.1">(version: Version) =>
41
- version === "3.0" ? v30 : v31;
42
-
43
- const v30 = (metadatas: Array<Metadata>): IJsonApplication<"3.0"> => {
44
- const components: OpenApiV3.IComponents = {};
45
- const generator = (meta: Metadata): OpenApiV3.IJsonSchema | null =>
46
- application_v30_schema(true)(components)({})(meta);
47
- return {
48
- version: "3.0",
49
- components,
50
- schemas: metadatas.map((meta, i) => {
51
- const schema: OpenApiV3.IJsonSchema | null = generator(meta);
52
- if (schema === null)
53
- throw new TransformerError({
54
- code: "typia.json.application",
55
- message: `invalid type on argument - (${meta.getName()}, ${i})`,
56
- });
57
- return schema;
58
- }),
59
- };
60
- };
61
-
62
- const v31 = (metadatas: Array<Metadata>): IJsonApplication<"3.1"> => {
63
- const components: OpenApi.IComponents = {
64
- schemas: {},
65
- };
66
- const generator = (meta: Metadata): OpenApi.IJsonSchema | null =>
67
- application_v31_schema(true)(components)({})(meta);
68
- return {
69
- version: "3.1",
70
- components,
71
- schemas: metadatas.map((meta, i) => {
72
- const schema: OpenApi.IJsonSchema | null = generator(meta);
73
- if (schema === null)
74
- throw new TransformerError({
75
- code: "typia.json.application",
76
- message: `invalid type on argument - (${meta.getName()}, ${i})`,
77
- });
78
- return schema;
79
- }),
80
- };
81
- };
82
- }
1
+ import { OpenApi, OpenApiV3 } from "@samchon/openapi";
2
+
3
+ import { IJsonApplication } from "../../schemas/json/IJsonApplication";
4
+ import { Metadata } from "../../schemas/metadata/Metadata";
5
+
6
+ import { TransformerError } from "../../transformers/TransformerError";
7
+
8
+ import { AtomicPredicator } from "../helpers/AtomicPredicator";
9
+ import { application_v30_schema } from "../internal/application_v30_schema";
10
+ import { application_v31_schema } from "../internal/application_v31_schema";
11
+
12
+ export namespace JsonApplicationProgrammer {
13
+ export const validate = (meta: Metadata) => {
14
+ const output: string[] = [];
15
+ if (
16
+ meta.atomics.some((a) => a.type === "bigint") ||
17
+ meta.constants.some((c) => c.type === "bigint")
18
+ )
19
+ output.push("JSON schema does not support bigint type.");
20
+ if (
21
+ meta.tuples.some((t) =>
22
+ t.type.elements.some((e) => e.isRequired() === false),
23
+ ) ||
24
+ meta.arrays.some((a) => a.type.value.isRequired() === false)
25
+ )
26
+ output.push("JSON schema does not support undefined type in array.");
27
+ if (meta.maps.length) output.push("JSON schema does not support Map type.");
28
+ if (meta.sets.length) output.push("JSON schema does not support Set type.");
29
+ for (const native of meta.natives)
30
+ if (
31
+ AtomicPredicator.native(native) === false &&
32
+ native !== "Date" &&
33
+ native !== "Blob" &&
34
+ native !== "File"
35
+ )
36
+ output.push(`JSON schema does not support ${native} type.`);
37
+ return output;
38
+ };
39
+
40
+ export const write = <Version extends "3.0" | "3.1">(version: Version) =>
41
+ version === "3.0" ? v30 : v31;
42
+
43
+ const v30 = (metadatas: Array<Metadata>): IJsonApplication<"3.0"> => {
44
+ const components: OpenApiV3.IComponents = {};
45
+ const generator = (meta: Metadata): OpenApiV3.IJsonSchema | null =>
46
+ application_v30_schema(true)(components)({})(meta);
47
+ return {
48
+ version: "3.0",
49
+ components,
50
+ schemas: metadatas.map((meta, i) => {
51
+ const schema: OpenApiV3.IJsonSchema | null = generator(meta);
52
+ if (schema === null)
53
+ throw new TransformerError({
54
+ code: "typia.json.application",
55
+ message: `invalid type on argument - (${meta.getName()}, ${i})`,
56
+ });
57
+ return schema;
58
+ }),
59
+ };
60
+ };
61
+
62
+ const v31 = (metadatas: Array<Metadata>): IJsonApplication<"3.1"> => {
63
+ const components: OpenApi.IComponents = {
64
+ schemas: {},
65
+ };
66
+ const generator = (meta: Metadata): OpenApi.IJsonSchema | null =>
67
+ application_v31_schema(true)(components)({})(meta);
68
+ return {
69
+ version: "3.1",
70
+ components,
71
+ schemas: metadatas.map((meta, i) => {
72
+ const schema: OpenApi.IJsonSchema | null = generator(meta);
73
+ if (schema === null)
74
+ throw new TransformerError({
75
+ code: "typia.json.application",
76
+ message: `invalid type on argument - (${meta.getName()}, ${i})`,
77
+ });
78
+ return schema;
79
+ }),
80
+ };
81
+ };
82
+ }
@@ -1,11 +1,11 @@
1
- import { Atomic } from "../../typings/Atomic";
2
-
3
- import { IJsDocTagInfo } from "./IJsDocTagInfo";
4
- import { IMetadataTypeTag } from "./IMetadataTypeTag";
5
-
6
- export interface IMetadataConstantValue<T extends Atomic.Type> {
7
- value: T;
8
- tags?: IMetadataTypeTag[][] | undefined;
9
- description?: string | null;
10
- jsDocTags?: IJsDocTagInfo[];
11
- }
1
+ import { Atomic } from "../../typings/Atomic";
2
+
3
+ import { IJsDocTagInfo } from "./IJsDocTagInfo";
4
+ import { IMetadataTypeTag } from "./IMetadataTypeTag";
5
+
6
+ export interface IMetadataConstantValue<T extends Atomic.Type> {
7
+ value: T;
8
+ tags?: IMetadataTypeTag[][] | undefined;
9
+ description?: string | null;
10
+ jsDocTags?: IJsDocTagInfo[];
11
+ }
@@ -1,7 +1,7 @@
1
- import { IMetadata } from "./IMetadata";
2
- import { IMetadataTypeTag } from "./IMetadataTypeTag";
3
-
4
- export interface IMetadataTemplate {
5
- row: IMetadata[];
6
- tags?: IMetadataTypeTag[][] | undefined;
7
- }
1
+ import { IMetadata } from "./IMetadata";
2
+ import { IMetadataTypeTag } from "./IMetadataTypeTag";
3
+
4
+ export interface IMetadataTemplate {
5
+ row: IMetadata[];
6
+ tags?: IMetadataTypeTag[][] | undefined;
7
+ }
@@ -1,14 +1,14 @@
1
1
  import { TagBase } from "./TagBase";
2
2
 
3
3
  export type Constant<
4
- Value extends boolean | number | string,
4
+ Value extends boolean | number | string | bigint,
5
5
  Content extends {
6
6
  title?: string | undefined;
7
7
  description?: string | undefined;
8
8
  },
9
9
  > = Value &
10
10
  TagBase<{
11
- target: "string" | "boolean" | "number";
11
+ target: "string" | "boolean" | "number" | "bigint";
12
12
  kind: "constant";
13
13
  value: undefined;
14
14
  schema: Content;
@@ -12,7 +12,11 @@ export type Default<Value extends boolean | bigint | number | string> =
12
12
  kind: "default";
13
13
  value: Value;
14
14
  exclusive: true;
15
- schema: {
16
- default: Value;
17
- };
15
+ schema: Value extends bigint
16
+ ? { default: Numeric<Value> }
17
+ : { default: Value };
18
18
  }>;
19
+
20
+ type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
21
+ ? N
22
+ : never;
@@ -1,19 +1,25 @@
1
1
  import { TagBase } from "./TagBase";
2
2
 
3
3
  export type ExclusiveMaximum<Value extends number | bigint> = TagBase<{
4
- target: Value extends number ? "number" : "bigint";
4
+ target: Value extends bigint ? "bigint" : "number";
5
5
  kind: "exclusiveMaximum";
6
6
  value: Value;
7
- validate: `$input < ${Numeric<Value>}`;
7
+ validate: `$input < ${Cast<Value>}`;
8
8
  exclusive: ["exclusiveMaximum", "maximum"];
9
- schema: Value extends number
9
+ schema: Value extends bigint
10
10
  ? {
11
11
  exclusiveMaximum: true;
12
- maximum: Value;
12
+ maximum: Numeric<Value>;
13
13
  }
14
- : undefined;
14
+ : {
15
+ exclusiveMaximum: true;
16
+ maximum: Value;
17
+ };
15
18
  }>;
16
19
 
17
- type Numeric<Value extends number | bigint> = Value extends number
20
+ type Cast<Value extends number | bigint> = Value extends number
18
21
  ? Value
19
22
  : `BigInt(${Value})`;
23
+ type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
24
+ ? N
25
+ : never;
@@ -1,19 +1,25 @@
1
1
  import { TagBase } from "./TagBase";
2
2
 
3
3
  export type ExclusiveMinimum<Value extends number | bigint> = TagBase<{
4
- target: Value extends number ? "number" : "bigint";
4
+ target: Value extends bigint ? "bigint" : "number";
5
5
  kind: "exclusiveMinimum";
6
6
  value: Value;
7
- validate: `${Numeric<Value>} < $input`;
7
+ validate: `${Cast<Value>} < $input`;
8
8
  exclusive: ["exclusiveMinimum", "minimum"];
9
- schema: Value extends number
9
+ schema: Value extends bigint
10
10
  ? {
11
11
  exclusiveMinimum: true;
12
- minimum: Value;
12
+ minimum: Numeric<Value>;
13
13
  }
14
- : undefined;
14
+ : {
15
+ exclusiveMinimum: true;
16
+ minimum: Value;
17
+ };
15
18
  }>;
16
19
 
17
- type Numeric<Value extends number | bigint> = Value extends number
20
+ type Cast<Value extends number | bigint> = Value extends number
18
21
  ? Value
19
22
  : `BigInt(${Value})`;
23
+ type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
24
+ ? N
25
+ : never;
@@ -1,7 +1,7 @@
1
1
  import { TagBase } from "./TagBase";
2
2
 
3
3
  export type JsonSchemaPlugin<Schema extends object> = TagBase<{
4
- target: "string" | "boolean" | "number" | "array";
4
+ target: "string" | "boolean" | "bigint" | "number" | "array";
5
5
  kind: "jsonPlugin";
6
6
  value: undefined;
7
7
  schema: Schema;