typia 9.7.2 → 10.0.0-dev.20251107

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 (116) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +153 -153
  3. package/lib/factories/ProtobufFactory.js +1 -1
  4. package/lib/factories/ProtobufFactory.mjs +1 -1
  5. package/lib/programmers/internal/json_schema_station.d.mts +2 -2
  6. package/lib/programmers/internal/json_schema_station.d.ts +2 -2
  7. package/lib/programmers/llm/LlmApplicationProgrammer.js +5 -1
  8. package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -1
  9. package/lib/programmers/llm/LlmApplicationProgrammer.mjs +5 -1
  10. package/lib/programmers/llm/LlmSchemaProgrammer.js +1 -4
  11. package/lib/programmers/llm/LlmSchemaProgrammer.js.map +1 -1
  12. package/lib/programmers/llm/LlmSchemaProgrammer.mjs +1 -35
  13. package/package.json +121 -121
  14. package/src/AssertionGuard.ts +41 -41
  15. package/src/CamelCase.ts +75 -75
  16. package/src/IRandomGenerator.ts +337 -337
  17. package/src/IReadableURLSearchParams.ts +9 -9
  18. package/src/PascalCase.ts +71 -71
  19. package/src/Primitive.ts +90 -90
  20. package/src/Resolved.ts +72 -72
  21. package/src/SnakeCase.ts +127 -127
  22. package/src/TypeGuardError.ts +216 -216
  23. package/src/factories/MetadataCollection.ts +270 -270
  24. package/src/factories/MetadataCommentTagFactory.ts +632 -632
  25. package/src/factories/MetadataFactory.ts +402 -402
  26. package/src/factories/ProtobufFactory.ts +873 -873
  27. package/src/functional.ts +705 -705
  28. package/src/http.ts +972 -972
  29. package/src/internal/_ProtobufReader.ts +188 -188
  30. package/src/internal/_ProtobufSizer.ts +137 -137
  31. package/src/internal/_ProtobufWriter.ts +135 -135
  32. package/src/internal/_jsonStringifyString.ts +42 -42
  33. package/src/json.ts +643 -643
  34. package/src/llm.ts +615 -615
  35. package/src/misc.ts +594 -594
  36. package/src/module.ts +889 -889
  37. package/src/notations.ts +751 -751
  38. package/src/programmers/FeatureProgrammer.ts +605 -605
  39. package/src/programmers/ImportProgrammer.ts +179 -179
  40. package/src/programmers/RandomProgrammer.ts +1195 -1195
  41. package/src/programmers/helpers/ProtobufWire.ts +34 -34
  42. package/src/programmers/internal/check_array_length.ts +43 -43
  43. package/src/programmers/internal/check_bigint.ts +46 -46
  44. package/src/programmers/internal/check_dynamic_key.ts +197 -197
  45. package/src/programmers/internal/check_dynamic_properties.ts +231 -231
  46. package/src/programmers/internal/check_everything.ts +21 -21
  47. package/src/programmers/internal/check_native.ts +23 -23
  48. package/src/programmers/internal/check_number.ts +108 -108
  49. package/src/programmers/internal/check_object.ts +72 -72
  50. package/src/programmers/internal/check_string.ts +46 -46
  51. package/src/programmers/internal/check_template.ts +46 -46
  52. package/src/programmers/internal/check_union_array_like.ts +331 -331
  53. package/src/programmers/internal/decode_union_object.ts +110 -110
  54. package/src/programmers/internal/feature_object_entries.ts +59 -59
  55. package/src/programmers/internal/json_schema_escaped.ts +78 -78
  56. package/src/programmers/internal/json_schema_object.ts +150 -150
  57. package/src/programmers/internal/json_schema_station.ts +2 -2
  58. package/src/programmers/internal/metadata_to_pattern.ts +40 -40
  59. package/src/programmers/internal/postfix_of_tuple.ts +3 -3
  60. package/src/programmers/internal/prune_object_properties.ts +69 -69
  61. package/src/programmers/internal/stringify_dynamic_properties.ts +158 -158
  62. package/src/programmers/internal/stringify_native.ts +5 -5
  63. package/src/programmers/internal/stringify_regular_properties.ts +77 -77
  64. package/src/programmers/internal/template_to_pattern.ts +21 -21
  65. package/src/programmers/internal/wrap_metadata_rest_tuple.ts +21 -21
  66. package/src/programmers/json/JsonStringifyProgrammer.ts +1124 -1124
  67. package/src/programmers/llm/LlmApplicationProgrammer.ts +10 -1
  68. package/src/programmers/llm/LlmSchemaProgrammer.ts +2 -7
  69. package/src/protobuf.ts +820 -820
  70. package/src/reflect.ts +46 -46
  71. package/src/schemas/json/IJsonApplication.ts +77 -77
  72. package/src/schemas/json/IJsonSchemaCollection.ts +212 -212
  73. package/src/schemas/json/IJsonSchemaUnit.ts +263 -263
  74. package/src/schemas/metadata/IMetadataTypeTag.ts +14 -14
  75. package/src/schemas/metadata/Metadata.ts +669 -669
  76. package/src/schemas/metadata/MetadataAliasType.ts +57 -57
  77. package/src/schemas/metadata/MetadataApplication.ts +40 -40
  78. package/src/schemas/metadata/MetadataArray.ts +47 -47
  79. package/src/schemas/metadata/MetadataArrayType.ts +51 -51
  80. package/src/schemas/metadata/MetadataAtomic.ts +85 -85
  81. package/src/schemas/metadata/MetadataEscaped.ts +45 -45
  82. package/src/schemas/metadata/MetadataFunction.ts +45 -45
  83. package/src/schemas/metadata/MetadataObject.ts +46 -46
  84. package/src/schemas/metadata/MetadataObjectType.ts +137 -137
  85. package/src/schemas/metadata/MetadataParameter.ts +52 -52
  86. package/src/schemas/metadata/MetadataProperty.ts +53 -53
  87. package/src/schemas/metadata/MetadataTemplate.ts +78 -78
  88. package/src/schemas/metadata/MetadataTuple.ts +28 -28
  89. package/src/schemas/metadata/MetadataTupleType.ts +61 -61
  90. package/src/tags/Constant.ts +47 -47
  91. package/src/tags/ContentMediaType.ts +27 -27
  92. package/src/tags/Default.ts +52 -52
  93. package/src/tags/Example.ts +56 -56
  94. package/src/tags/Examples.ts +56 -56
  95. package/src/tags/ExclusiveMaximum.ts +44 -44
  96. package/src/tags/ExclusiveMinimum.ts +44 -44
  97. package/src/tags/Format.ts +78 -78
  98. package/src/tags/JsonSchemaPlugin.ts +36 -36
  99. package/src/tags/MaxItems.ts +31 -31
  100. package/src/tags/MaxLength.ts +25 -25
  101. package/src/tags/Maximum.ts +39 -39
  102. package/src/tags/MinItems.ts +31 -31
  103. package/src/tags/MinLength.ts +25 -25
  104. package/src/tags/Minimum.ts +39 -39
  105. package/src/tags/MultipleOf.ts +42 -42
  106. package/src/tags/Pattern.ts +49 -49
  107. package/src/tags/Sequence.ts +37 -37
  108. package/src/tags/TagBase.ts +102 -102
  109. package/src/tags/Type.ts +64 -64
  110. package/src/tags/UniqueItems.ts +34 -34
  111. package/src/tags/internal/FormatCheatSheet.ts +71 -71
  112. package/src/transformers/ITransformOptions.ts +70 -70
  113. package/src/transformers/ImportTransformer.ts +253 -253
  114. package/src/transformers/NoTransformConfigurationError.ts +16 -16
  115. package/src/transformers/features/llm/LlmApplicationTransformer.ts +224 -224
  116. package/src/typings/Equal.ts +18 -18
@@ -1,224 +1,224 @@
1
- import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
2
- import ts from "typescript";
3
-
4
- import { ExpressionFactory } from "../../../factories/ExpressionFactory";
5
- import { LiteralFactory } from "../../../factories/LiteralFactory";
6
- import { MetadataCollection } from "../../../factories/MetadataCollection";
7
- import { MetadataFactory } from "../../../factories/MetadataFactory";
8
- import { StatementFactory } from "../../../factories/StatementFactory";
9
-
10
- import { Metadata } from "../../../schemas/metadata/Metadata";
11
-
12
- import { LlmApplicationProgrammer } from "../../../programmers/llm/LlmApplicationProgrammer";
13
- import { LlmModelPredicator } from "../../../programmers/llm/LlmModelPredicator";
14
-
15
- import { ValidationPipe } from "../../../typings/ValidationPipe";
16
-
17
- import { ITransformProps } from "../../ITransformProps";
18
- import { ITypiaContext } from "../../ITypiaContext";
19
- import { TransformerError } from "../../TransformerError";
20
-
21
- export namespace LlmApplicationTransformer {
22
- export const transform = (props: ITransformProps): ts.Expression => {
23
- const dec = decompose("application", props);
24
- if (dec === null) return props.expression;
25
-
26
- const literal: ts.Expression = ts.factory.createAsExpression(
27
- LiteralFactory.write(dec.application),
28
- props.context.importer.type({
29
- file: "@samchon/openapi",
30
- name: "ILlmApplication",
31
- arguments: [
32
- ts.factory.createLiteralTypeNode(
33
- ts.factory.createStringLiteral(dec.application.model),
34
- ),
35
- ],
36
- }),
37
- );
38
- if (!props.expression.arguments?.[0]) return literal;
39
- return ExpressionFactory.selfCall(
40
- ts.factory.createBlock(
41
- [
42
- StatementFactory.constant({
43
- name: "application",
44
- value: literal,
45
- }),
46
- ts.factory.createExpressionStatement(
47
- finalize({
48
- context: props.context,
49
- value: ts.factory.createIdentifier("application"),
50
- argument: props.expression.arguments[0]!,
51
- equals: dec.config?.equals,
52
- model: dec.application.model,
53
- }),
54
- ),
55
- ts.factory.createReturnStatement(
56
- ts.factory.createIdentifier("application"),
57
- ),
58
- ],
59
- true,
60
- ),
61
- );
62
- };
63
-
64
- /** @internal */
65
- export const decompose = (
66
- method: string,
67
- props: ITransformProps,
68
- ): {
69
- application: ILlmApplication<ILlmSchema.Model>;
70
- type: ts.Type;
71
- node: ts.TypeNode;
72
- config:
73
- | Partial<
74
- ILlmSchema.IConfig & {
75
- equals: boolean;
76
- }
77
- >
78
- | undefined;
79
- } | null => {
80
- // GET GENERIC ARGUMENT
81
- if (!props.expression.typeArguments?.length)
82
- throw new TransformerError({
83
- code: `typia.llm.${method}`,
84
- message: "no generic argument.",
85
- });
86
- const top: ts.Node = props.expression.typeArguments[0]!;
87
- if (ts.isTypeNode(top) === false) return null;
88
-
89
- // GET TYPE
90
- const model: ILlmSchema.Model = LlmModelPredicator.getModel({
91
- checker: props.context.checker,
92
- method,
93
- node: props.expression.typeArguments[1],
94
- });
95
- const config:
96
- | Partial<
97
- ILlmSchema.IConfig & {
98
- equals: boolean;
99
- }
100
- >
101
- | undefined = LlmModelPredicator.getConfig({
102
- context: props.context,
103
- method,
104
- model,
105
- node: props.expression.typeArguments[2],
106
- });
107
- const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
108
-
109
- // VALIDATE TYPE
110
- const analyze = (validate: boolean): Metadata => {
111
- const result: ValidationPipe<Metadata, MetadataFactory.IError> =
112
- MetadataFactory.analyze({
113
- checker: props.context.checker,
114
- transformer: props.context.transformer,
115
- options: {
116
- absorb: validate,
117
- escape: true,
118
- constant: true,
119
- functional: true,
120
- validate:
121
- validate === true
122
- ? LlmApplicationProgrammer.validate({
123
- model,
124
- config,
125
- })
126
- : undefined,
127
- },
128
- collection: new MetadataCollection({
129
- replace: MetadataCollection.replace,
130
- }),
131
- type,
132
- });
133
- if (result.success === false)
134
- throw TransformerError.from({
135
- code: `typia.llm.${method}`,
136
- errors: result.errors,
137
- });
138
- return result.data;
139
- };
140
- analyze(true);
141
-
142
- // GENERATE LLM APPLICATION
143
- return {
144
- application: LlmApplicationProgrammer.write({
145
- model,
146
- context: props.context,
147
- modulo: props.modulo,
148
- metadata: analyze(false),
149
- config,
150
- name: top.getFullText().trim(),
151
- }),
152
- node: top,
153
- type,
154
- config,
155
- };
156
- };
157
-
158
- export const finalize = (props: {
159
- context: ITypiaContext;
160
- value: ts.Expression;
161
- argument: ts.Expression;
162
- equals?: boolean;
163
- model: ILlmSchema.Model;
164
- }) => {
165
- const satisfiesTypeNode: ts.TypeNode = ts.factory.createTypeReferenceNode(
166
- ts.factory.createIdentifier("Partial"),
167
- [
168
- ts.factory.createTypeReferenceNode(
169
- ts.factory.createIdentifier("Pick"),
170
- [
171
- ts.factory.createImportTypeNode(
172
- ts.factory.createLiteralTypeNode(
173
- ts.factory.createStringLiteral("@samchon/openapi"),
174
- ),
175
- undefined,
176
- ts.factory.createQualifiedName(
177
- ts.factory.createIdentifier("ILlmApplication"),
178
- ts.factory.createIdentifier("IOptions"),
179
- ),
180
- [
181
- ts.factory.createLiteralTypeNode(
182
- ts.factory.createStringLiteral(props.model),
183
- ),
184
- ],
185
- false,
186
- ),
187
- ts.factory.createUnionTypeNode([
188
- ts.factory.createLiteralTypeNode(
189
- ts.factory.createStringLiteral("separate"),
190
- ),
191
- ts.factory.createLiteralTypeNode(
192
- ts.factory.createStringLiteral("validate"),
193
- ),
194
- ]),
195
- ],
196
- ),
197
- ],
198
- );
199
- return ts.factory.createCallExpression(
200
- props.context.importer.internal("llmApplicationFinalize"),
201
- undefined,
202
- [
203
- props.value,
204
- ts.factory.createObjectLiteralExpression(
205
- [
206
- ts.factory.createSpreadAssignment(
207
- ts.factory.createSatisfiesExpression(
208
- props.argument,
209
- satisfiesTypeNode,
210
- ),
211
- ),
212
- ts.factory.createPropertyAssignment(
213
- "equals",
214
- props.equals === true
215
- ? ts.factory.createTrue()
216
- : ts.factory.createFalse(),
217
- ),
218
- ],
219
- true,
220
- ),
221
- ],
222
- );
223
- };
224
- }
1
+ import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
2
+ import ts from "typescript";
3
+
4
+ import { ExpressionFactory } from "../../../factories/ExpressionFactory";
5
+ import { LiteralFactory } from "../../../factories/LiteralFactory";
6
+ import { MetadataCollection } from "../../../factories/MetadataCollection";
7
+ import { MetadataFactory } from "../../../factories/MetadataFactory";
8
+ import { StatementFactory } from "../../../factories/StatementFactory";
9
+
10
+ import { Metadata } from "../../../schemas/metadata/Metadata";
11
+
12
+ import { LlmApplicationProgrammer } from "../../../programmers/llm/LlmApplicationProgrammer";
13
+ import { LlmModelPredicator } from "../../../programmers/llm/LlmModelPredicator";
14
+
15
+ import { ValidationPipe } from "../../../typings/ValidationPipe";
16
+
17
+ import { ITransformProps } from "../../ITransformProps";
18
+ import { ITypiaContext } from "../../ITypiaContext";
19
+ import { TransformerError } from "../../TransformerError";
20
+
21
+ export namespace LlmApplicationTransformer {
22
+ export const transform = (props: ITransformProps): ts.Expression => {
23
+ const dec = decompose("application", props);
24
+ if (dec === null) return props.expression;
25
+
26
+ const literal: ts.Expression = ts.factory.createAsExpression(
27
+ LiteralFactory.write(dec.application),
28
+ props.context.importer.type({
29
+ file: "@samchon/openapi",
30
+ name: "ILlmApplication",
31
+ arguments: [
32
+ ts.factory.createLiteralTypeNode(
33
+ ts.factory.createStringLiteral(dec.application.model),
34
+ ),
35
+ ],
36
+ }),
37
+ );
38
+ if (!props.expression.arguments?.[0]) return literal;
39
+ return ExpressionFactory.selfCall(
40
+ ts.factory.createBlock(
41
+ [
42
+ StatementFactory.constant({
43
+ name: "application",
44
+ value: literal,
45
+ }),
46
+ ts.factory.createExpressionStatement(
47
+ finalize({
48
+ context: props.context,
49
+ value: ts.factory.createIdentifier("application"),
50
+ argument: props.expression.arguments[0]!,
51
+ equals: dec.config?.equals,
52
+ model: dec.application.model,
53
+ }),
54
+ ),
55
+ ts.factory.createReturnStatement(
56
+ ts.factory.createIdentifier("application"),
57
+ ),
58
+ ],
59
+ true,
60
+ ),
61
+ );
62
+ };
63
+
64
+ /** @internal */
65
+ export const decompose = (
66
+ method: string,
67
+ props: ITransformProps,
68
+ ): {
69
+ application: ILlmApplication<ILlmSchema.Model>;
70
+ type: ts.Type;
71
+ node: ts.TypeNode;
72
+ config:
73
+ | Partial<
74
+ ILlmSchema.IConfig & {
75
+ equals: boolean;
76
+ }
77
+ >
78
+ | undefined;
79
+ } | null => {
80
+ // GET GENERIC ARGUMENT
81
+ if (!props.expression.typeArguments?.length)
82
+ throw new TransformerError({
83
+ code: `typia.llm.${method}`,
84
+ message: "no generic argument.",
85
+ });
86
+ const top: ts.Node = props.expression.typeArguments[0]!;
87
+ if (ts.isTypeNode(top) === false) return null;
88
+
89
+ // GET TYPE
90
+ const model: ILlmSchema.Model = LlmModelPredicator.getModel({
91
+ checker: props.context.checker,
92
+ method,
93
+ node: props.expression.typeArguments[1],
94
+ });
95
+ const config:
96
+ | Partial<
97
+ ILlmSchema.IConfig & {
98
+ equals: boolean;
99
+ }
100
+ >
101
+ | undefined = LlmModelPredicator.getConfig({
102
+ context: props.context,
103
+ method,
104
+ model,
105
+ node: props.expression.typeArguments[2],
106
+ });
107
+ const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
108
+
109
+ // VALIDATE TYPE
110
+ const analyze = (validate: boolean): Metadata => {
111
+ const result: ValidationPipe<Metadata, MetadataFactory.IError> =
112
+ MetadataFactory.analyze({
113
+ checker: props.context.checker,
114
+ transformer: props.context.transformer,
115
+ options: {
116
+ absorb: validate,
117
+ escape: true,
118
+ constant: true,
119
+ functional: true,
120
+ validate:
121
+ validate === true
122
+ ? LlmApplicationProgrammer.validate({
123
+ model,
124
+ config,
125
+ })
126
+ : undefined,
127
+ },
128
+ collection: new MetadataCollection({
129
+ replace: MetadataCollection.replace,
130
+ }),
131
+ type,
132
+ });
133
+ if (result.success === false)
134
+ throw TransformerError.from({
135
+ code: `typia.llm.${method}`,
136
+ errors: result.errors,
137
+ });
138
+ return result.data;
139
+ };
140
+ analyze(true);
141
+
142
+ // GENERATE LLM APPLICATION
143
+ return {
144
+ application: LlmApplicationProgrammer.write({
145
+ model,
146
+ context: props.context,
147
+ modulo: props.modulo,
148
+ metadata: analyze(false),
149
+ config,
150
+ name: top.getFullText().trim(),
151
+ }),
152
+ node: top,
153
+ type,
154
+ config,
155
+ };
156
+ };
157
+
158
+ export const finalize = (props: {
159
+ context: ITypiaContext;
160
+ value: ts.Expression;
161
+ argument: ts.Expression;
162
+ equals?: boolean;
163
+ model: ILlmSchema.Model;
164
+ }) => {
165
+ const satisfiesTypeNode: ts.TypeNode = ts.factory.createTypeReferenceNode(
166
+ ts.factory.createIdentifier("Partial"),
167
+ [
168
+ ts.factory.createTypeReferenceNode(
169
+ ts.factory.createIdentifier("Pick"),
170
+ [
171
+ ts.factory.createImportTypeNode(
172
+ ts.factory.createLiteralTypeNode(
173
+ ts.factory.createStringLiteral("@samchon/openapi"),
174
+ ),
175
+ undefined,
176
+ ts.factory.createQualifiedName(
177
+ ts.factory.createIdentifier("ILlmApplication"),
178
+ ts.factory.createIdentifier("IOptions"),
179
+ ),
180
+ [
181
+ ts.factory.createLiteralTypeNode(
182
+ ts.factory.createStringLiteral(props.model),
183
+ ),
184
+ ],
185
+ false,
186
+ ),
187
+ ts.factory.createUnionTypeNode([
188
+ ts.factory.createLiteralTypeNode(
189
+ ts.factory.createStringLiteral("separate"),
190
+ ),
191
+ ts.factory.createLiteralTypeNode(
192
+ ts.factory.createStringLiteral("validate"),
193
+ ),
194
+ ]),
195
+ ],
196
+ ),
197
+ ],
198
+ );
199
+ return ts.factory.createCallExpression(
200
+ props.context.importer.internal("llmApplicationFinalize"),
201
+ undefined,
202
+ [
203
+ props.value,
204
+ ts.factory.createObjectLiteralExpression(
205
+ [
206
+ ts.factory.createSpreadAssignment(
207
+ ts.factory.createSatisfiesExpression(
208
+ props.argument,
209
+ satisfiesTypeNode,
210
+ ),
211
+ ),
212
+ ts.factory.createPropertyAssignment(
213
+ "equals",
214
+ props.equals === true
215
+ ? ts.factory.createTrue()
216
+ : ts.factory.createFalse(),
217
+ ),
218
+ ],
219
+ true,
220
+ ),
221
+ ],
222
+ );
223
+ };
224
+ }
@@ -1,18 +1,18 @@
1
- /**
2
- * Compare the equivalence of the two types X and Y.
3
- *
4
- * The two types X and Y refer to any type that can be expressed in the
5
- * TypeScript, such as the union type and the object type.
6
- *
7
- * @author Kyungsu Kang - https://github.com/kakasoo
8
- * @template X One of the types to compare
9
- * @template Y One of the types to compare
10
- *
11
- * ```ts
12
- * type Answer = Equal<1 | 2, 1 | 2>; // true
13
- * ```
14
- */
15
- export type Equal<X, Y> =
16
- (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2
17
- ? true
18
- : false;
1
+ /**
2
+ * Compare the equivalence of the two types X and Y.
3
+ *
4
+ * The two types X and Y refer to any type that can be expressed in the
5
+ * TypeScript, such as the union type and the object type.
6
+ *
7
+ * @author Kyungsu Kang - https://github.com/kakasoo
8
+ * @template X One of the types to compare
9
+ * @template Y One of the types to compare
10
+ *
11
+ * ```ts
12
+ * type Answer = Equal<1 | 2, 1 | 2>; // true
13
+ * ```
14
+ */
15
+ export type Equal<X, Y> =
16
+ (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2
17
+ ? true
18
+ : false;