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,272 +1,272 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../schemas/metadata/Metadata";
4
- import { MetadataAlias } from "../schemas/metadata/MetadataAlias";
5
- import { MetadataArrayType } from "../schemas/metadata/MetadataArrayType";
6
- import { MetadataConstant } from "../schemas/metadata/MetadataConstant";
7
- import { MetadataObject } from "../schemas/metadata/MetadataObject";
8
- import { MetadataTupleType } from "../schemas/metadata/MetadataTupleType";
9
- import { explore_metadata } from "./internal/metadata/explore_metadata";
10
- import { iterate_metadata_collection } from "./internal/metadata/iterate_metadata_collection";
11
- import { iterate_metadata_sort } from "./internal/metadata/iterate_metadata_sort";
12
-
13
- import { ValidationPipe } from "../typings/ValidationPipe";
14
-
15
- import { ExpressionFactory } from "./ExpressionFactory";
16
- import { MetadataCollection } from "./MetadataCollection";
17
-
18
- export namespace MetadataFactory {
19
- export type Validator = (meta: Metadata, explore: IExplore) => string[];
20
-
21
- export interface IOptions {
22
- escape: boolean;
23
- constant: boolean;
24
- absorb: boolean;
25
- validate?: Validator;
26
- onError?: (node: ts.Node | undefined, message: string) => void;
27
- }
28
-
29
- export interface IExplore {
30
- top: boolean;
31
- object: MetadataObject | null;
32
- property: string | object | null;
33
- nested: null | MetadataAlias | MetadataArrayType | MetadataTupleType;
34
- escaped: boolean;
35
- aliased: boolean;
36
- }
37
-
38
- export interface IError {
39
- name: string;
40
- explore: IExplore;
41
- messages: string[];
42
- }
43
-
44
- export const analyze =
45
- (checker: ts.TypeChecker, context?: ts.TransformationContext) =>
46
- (options: IOptions) =>
47
- (collection: MetadataCollection) =>
48
- (type: ts.Type | null): ValidationPipe<Metadata, IError> => {
49
- const errors: IError[] = [];
50
- const meta: Metadata = explore_metadata(checker)(options)(collection)(
51
- errors,
52
- )(type, {
53
- top: true,
54
- object: null,
55
- property: null,
56
- nested: null,
57
- escaped: false,
58
- aliased: false,
59
- });
60
- iterate_metadata_collection(errors)(collection);
61
- iterate_metadata_sort(collection)(meta);
62
-
63
- if (options.validate)
64
- errors.push(...validate(context)(options)(options.validate)(meta));
65
- return errors.length
66
- ? {
67
- success: false,
68
- errors,
69
- }
70
- : {
71
- success: true,
72
- data: meta,
73
- };
74
- };
75
-
76
- /**
77
- * @internal
78
- */
79
- export const soleLiteral = (value: string): Metadata => {
80
- const meta: Metadata = Metadata.initialize();
81
- meta.constants.push(
82
- MetadataConstant.from({
83
- values: [
84
- {
85
- value,
86
- tags: undefined,
87
- },
88
- ],
89
- type: "string",
90
- }),
91
- );
92
- return meta;
93
- };
94
-
95
- const validate =
96
- (context?: ts.TransformationContext) =>
97
- (options: IOptions) =>
98
- (functor: Validator) =>
99
- (meta: Metadata): IError[] => {
100
- const visitor: IValidationVisitor = {
101
- functor,
102
- errors: [],
103
- objects: new Set(),
104
- arrays: new Set(),
105
- tuples: new Set(),
106
- aliases: new Set(),
107
- };
108
- validateMeta(context)(options)(visitor)(meta, {
109
- object: null,
110
- property: null,
111
- nested: null,
112
- top: true,
113
- aliased: false,
114
- escaped: false,
115
- });
116
- return visitor.errors;
117
- };
118
-
119
- const validateMeta =
120
- (context?: ts.TransformationContext) =>
121
- (options: IOptions) =>
122
- (visitor: IValidationVisitor) =>
123
- (meta: Metadata, explore: IExplore) => {
124
- const result: string[] = [];
125
- if (context !== undefined)
126
- for (const atomic of meta.atomics)
127
- for (const row of atomic.tags)
128
- for (const tag of row.filter(
129
- (t) => t.validate !== undefined && t.predicate === undefined,
130
- ))
131
- try {
132
- tag.predicate = ExpressionFactory.transpile(context)(
133
- tag.validate!,
134
- );
135
- } catch {
136
- result.push(
137
- `Unable to transpile type tag script: ${JSON.stringify(
138
- tag.validate,
139
- )}`,
140
- );
141
- tag.predicate = () => ts.factory.createTrue();
142
- }
143
- result.push(...visitor.functor(meta, explore));
144
- if (result.length)
145
- visitor.errors.push({
146
- name: meta.getName(),
147
- explore: { ...explore },
148
- messages: [...new Set(result)],
149
- });
150
-
151
- for (const alias of meta.aliases)
152
- validateAlias(context)(options)(visitor)(alias, explore);
153
- for (const array of meta.arrays)
154
- validateArray(context)(options)(visitor)(array.type, explore);
155
- for (const tuple of meta.tuples)
156
- validateTuple(context)(options)(visitor)(tuple.type, explore);
157
- for (const obj of meta.objects)
158
- validateObject(context)(options)(visitor)(obj);
159
- for (const set of meta.sets)
160
- validateMeta(context)(options)(visitor)(set, explore);
161
- for (const map of meta.maps) {
162
- validateMeta(context)(options)(visitor)(map.key, explore);
163
- validateMeta(context)(options)(visitor)(map.value, explore);
164
- }
165
-
166
- if (options.escape === true && meta.escaped !== null)
167
- validateMeta(context)(options)(visitor)(meta.escaped.returns, {
168
- ...explore,
169
- escaped: true,
170
- });
171
- };
172
-
173
- const validateAlias =
174
- (context?: ts.TransformationContext) =>
175
- (options: IOptions) =>
176
- (visitor: IValidationVisitor) =>
177
- (alias: MetadataAlias, explore: IExplore) => {
178
- if (visitor.aliases.has(alias)) return;
179
- visitor.aliases.add(alias);
180
-
181
- validateMeta(context)(options)(visitor)(alias.value, {
182
- ...explore,
183
- nested: alias,
184
- aliased: true,
185
- });
186
- };
187
-
188
- const validateArray =
189
- (context?: ts.TransformationContext) =>
190
- (options: IOptions) =>
191
- (visitor: IValidationVisitor) =>
192
- (array: MetadataArrayType, explore: IExplore) => {
193
- if (visitor.arrays.has(array)) return;
194
- visitor.arrays.add(array);
195
-
196
- validateMeta(context)(options)(visitor)(array.value, {
197
- ...explore,
198
- nested: array,
199
- top: false,
200
- });
201
- };
202
-
203
- const validateTuple =
204
- (context?: ts.TransformationContext) =>
205
- (options: IOptions) =>
206
- (visitor: IValidationVisitor) =>
207
- (tuple: MetadataTupleType, explore: IExplore) => {
208
- if (visitor.tuples.has(tuple)) return;
209
- visitor.tuples.add(tuple);
210
-
211
- for (const elem of tuple.elements)
212
- validateMeta(context)(options)(visitor)(elem, {
213
- ...explore,
214
- nested: tuple,
215
- top: false,
216
- });
217
- };
218
-
219
- const validateObject =
220
- (context?: ts.TransformationContext) =>
221
- (options: IOptions) =>
222
- (visitor: IValidationVisitor) =>
223
- (object: MetadataObject) => {
224
- if (visitor.objects.has(object)) return;
225
- visitor.objects.add(object);
226
-
227
- if (options.validate) {
228
- const explore: IExplore = {
229
- object,
230
- top: false,
231
- property: null,
232
- nested: null,
233
- escaped: false,
234
- aliased: false,
235
- };
236
- const errors: string[] = options.validate(
237
- Metadata.create({
238
- ...Metadata.initialize(),
239
- objects: [object],
240
- }),
241
- explore,
242
- );
243
- if (errors.length)
244
- visitor.errors.push({
245
- name: object.name,
246
- explore,
247
- messages: [...new Set(errors)],
248
- });
249
- }
250
-
251
- for (const property of object.properties)
252
- validateMeta(context)(options)(visitor)(property.value, {
253
- object,
254
- property: property.key.isSoleLiteral()
255
- ? property.key.getSoleLiteral()!
256
- : {},
257
- nested: null,
258
- top: false,
259
- aliased: false,
260
- escaped: false,
261
- });
262
- };
263
-
264
- interface IValidationVisitor {
265
- functor: Validator;
266
- errors: IError[];
267
- objects: Set<MetadataObject>;
268
- arrays: Set<MetadataArrayType>;
269
- tuples: Set<MetadataTupleType>;
270
- aliases: Set<MetadataAlias>;
271
- }
272
- }
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../schemas/metadata/Metadata";
4
+ import { MetadataAlias } from "../schemas/metadata/MetadataAlias";
5
+ import { MetadataArrayType } from "../schemas/metadata/MetadataArrayType";
6
+ import { MetadataConstant } from "../schemas/metadata/MetadataConstant";
7
+ import { MetadataObject } from "../schemas/metadata/MetadataObject";
8
+ import { MetadataTupleType } from "../schemas/metadata/MetadataTupleType";
9
+ import { explore_metadata } from "./internal/metadata/explore_metadata";
10
+ import { iterate_metadata_collection } from "./internal/metadata/iterate_metadata_collection";
11
+ import { iterate_metadata_sort } from "./internal/metadata/iterate_metadata_sort";
12
+
13
+ import { ValidationPipe } from "../typings/ValidationPipe";
14
+
15
+ import { ExpressionFactory } from "./ExpressionFactory";
16
+ import { MetadataCollection } from "./MetadataCollection";
17
+
18
+ export namespace MetadataFactory {
19
+ export type Validator = (meta: Metadata, explore: IExplore) => string[];
20
+
21
+ export interface IOptions {
22
+ escape: boolean;
23
+ constant: boolean;
24
+ absorb: boolean;
25
+ validate?: Validator;
26
+ onError?: (node: ts.Node | undefined, message: string) => void;
27
+ }
28
+
29
+ export interface IExplore {
30
+ top: boolean;
31
+ object: MetadataObject | null;
32
+ property: string | object | null;
33
+ nested: null | MetadataAlias | MetadataArrayType | MetadataTupleType;
34
+ escaped: boolean;
35
+ aliased: boolean;
36
+ }
37
+
38
+ export interface IError {
39
+ name: string;
40
+ explore: IExplore;
41
+ messages: string[];
42
+ }
43
+
44
+ export const analyze =
45
+ (checker: ts.TypeChecker, context?: ts.TransformationContext) =>
46
+ (options: IOptions) =>
47
+ (collection: MetadataCollection) =>
48
+ (type: ts.Type | null): ValidationPipe<Metadata, IError> => {
49
+ const errors: IError[] = [];
50
+ const meta: Metadata = explore_metadata(checker)(options)(collection)(
51
+ errors,
52
+ )(type, {
53
+ top: true,
54
+ object: null,
55
+ property: null,
56
+ nested: null,
57
+ escaped: false,
58
+ aliased: false,
59
+ });
60
+ iterate_metadata_collection(errors)(collection);
61
+ iterate_metadata_sort(collection)(meta);
62
+
63
+ if (options.validate)
64
+ errors.push(...validate(context)(options)(options.validate)(meta));
65
+ return errors.length
66
+ ? {
67
+ success: false,
68
+ errors,
69
+ }
70
+ : {
71
+ success: true,
72
+ data: meta,
73
+ };
74
+ };
75
+
76
+ /**
77
+ * @internal
78
+ */
79
+ export const soleLiteral = (value: string): Metadata => {
80
+ const meta: Metadata = Metadata.initialize();
81
+ meta.constants.push(
82
+ MetadataConstant.from({
83
+ values: [
84
+ {
85
+ value,
86
+ tags: undefined,
87
+ },
88
+ ],
89
+ type: "string",
90
+ }),
91
+ );
92
+ return meta;
93
+ };
94
+
95
+ const validate =
96
+ (context?: ts.TransformationContext) =>
97
+ (options: IOptions) =>
98
+ (functor: Validator) =>
99
+ (meta: Metadata): IError[] => {
100
+ const visitor: IValidationVisitor = {
101
+ functor,
102
+ errors: [],
103
+ objects: new Set(),
104
+ arrays: new Set(),
105
+ tuples: new Set(),
106
+ aliases: new Set(),
107
+ };
108
+ validateMeta(context)(options)(visitor)(meta, {
109
+ object: null,
110
+ property: null,
111
+ nested: null,
112
+ top: true,
113
+ aliased: false,
114
+ escaped: false,
115
+ });
116
+ return visitor.errors;
117
+ };
118
+
119
+ const validateMeta =
120
+ (context?: ts.TransformationContext) =>
121
+ (options: IOptions) =>
122
+ (visitor: IValidationVisitor) =>
123
+ (meta: Metadata, explore: IExplore) => {
124
+ const result: string[] = [];
125
+ if (context !== undefined)
126
+ for (const atomic of meta.atomics)
127
+ for (const row of atomic.tags)
128
+ for (const tag of row.filter(
129
+ (t) => t.validate !== undefined && t.predicate === undefined,
130
+ ))
131
+ try {
132
+ tag.predicate = ExpressionFactory.transpile(context)(
133
+ tag.validate!,
134
+ );
135
+ } catch {
136
+ result.push(
137
+ `Unable to transpile type tag script: ${JSON.stringify(
138
+ tag.validate,
139
+ )}`,
140
+ );
141
+ tag.predicate = () => ts.factory.createTrue();
142
+ }
143
+ result.push(...visitor.functor(meta, explore));
144
+ if (result.length)
145
+ visitor.errors.push({
146
+ name: meta.getName(),
147
+ explore: { ...explore },
148
+ messages: [...new Set(result)],
149
+ });
150
+
151
+ for (const alias of meta.aliases)
152
+ validateAlias(context)(options)(visitor)(alias, explore);
153
+ for (const array of meta.arrays)
154
+ validateArray(context)(options)(visitor)(array.type, explore);
155
+ for (const tuple of meta.tuples)
156
+ validateTuple(context)(options)(visitor)(tuple.type, explore);
157
+ for (const obj of meta.objects)
158
+ validateObject(context)(options)(visitor)(obj);
159
+ for (const set of meta.sets)
160
+ validateMeta(context)(options)(visitor)(set, explore);
161
+ for (const map of meta.maps) {
162
+ validateMeta(context)(options)(visitor)(map.key, explore);
163
+ validateMeta(context)(options)(visitor)(map.value, explore);
164
+ }
165
+
166
+ if (options.escape === true && meta.escaped !== null)
167
+ validateMeta(context)(options)(visitor)(meta.escaped.returns, {
168
+ ...explore,
169
+ escaped: true,
170
+ });
171
+ };
172
+
173
+ const validateAlias =
174
+ (context?: ts.TransformationContext) =>
175
+ (options: IOptions) =>
176
+ (visitor: IValidationVisitor) =>
177
+ (alias: MetadataAlias, explore: IExplore) => {
178
+ if (visitor.aliases.has(alias)) return;
179
+ visitor.aliases.add(alias);
180
+
181
+ validateMeta(context)(options)(visitor)(alias.value, {
182
+ ...explore,
183
+ nested: alias,
184
+ aliased: true,
185
+ });
186
+ };
187
+
188
+ const validateArray =
189
+ (context?: ts.TransformationContext) =>
190
+ (options: IOptions) =>
191
+ (visitor: IValidationVisitor) =>
192
+ (array: MetadataArrayType, explore: IExplore) => {
193
+ if (visitor.arrays.has(array)) return;
194
+ visitor.arrays.add(array);
195
+
196
+ validateMeta(context)(options)(visitor)(array.value, {
197
+ ...explore,
198
+ nested: array,
199
+ top: false,
200
+ });
201
+ };
202
+
203
+ const validateTuple =
204
+ (context?: ts.TransformationContext) =>
205
+ (options: IOptions) =>
206
+ (visitor: IValidationVisitor) =>
207
+ (tuple: MetadataTupleType, explore: IExplore) => {
208
+ if (visitor.tuples.has(tuple)) return;
209
+ visitor.tuples.add(tuple);
210
+
211
+ for (const elem of tuple.elements)
212
+ validateMeta(context)(options)(visitor)(elem, {
213
+ ...explore,
214
+ nested: tuple,
215
+ top: false,
216
+ });
217
+ };
218
+
219
+ const validateObject =
220
+ (context?: ts.TransformationContext) =>
221
+ (options: IOptions) =>
222
+ (visitor: IValidationVisitor) =>
223
+ (object: MetadataObject) => {
224
+ if (visitor.objects.has(object)) return;
225
+ visitor.objects.add(object);
226
+
227
+ if (options.validate) {
228
+ const explore: IExplore = {
229
+ object,
230
+ top: false,
231
+ property: null,
232
+ nested: null,
233
+ escaped: false,
234
+ aliased: false,
235
+ };
236
+ const errors: string[] = options.validate(
237
+ Metadata.create({
238
+ ...Metadata.initialize(),
239
+ objects: [object],
240
+ }),
241
+ explore,
242
+ );
243
+ if (errors.length)
244
+ visitor.errors.push({
245
+ name: object.name,
246
+ explore,
247
+ messages: [...new Set(errors)],
248
+ });
249
+ }
250
+
251
+ for (const property of object.properties)
252
+ validateMeta(context)(options)(visitor)(property.value, {
253
+ object,
254
+ property: property.key.isSoleLiteral()
255
+ ? property.key.getSoleLiteral()!
256
+ : {},
257
+ nested: null,
258
+ top: false,
259
+ aliased: false,
260
+ escaped: false,
261
+ });
262
+ };
263
+
264
+ interface IValidationVisitor {
265
+ functor: Validator;
266
+ errors: IError[];
267
+ objects: Set<MetadataObject>;
268
+ arrays: Set<MetadataArrayType>;
269
+ tuples: Set<MetadataTupleType>;
270
+ aliases: Set<MetadataAlias>;
271
+ }
272
+ }