typia 7.0.0-dev.20241010-2 → 7.0.0-dev.20241011
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.
- package/lib/index.mjs +7 -0
- package/lib/index.mjs.map +1 -1
- package/lib/json.d.ts +47 -13
- package/lib/json.js +7 -0
- package/lib/json.js.map +1 -1
- package/lib/module.d.ts +1 -0
- package/lib/module.js +1 -0
- package/lib/module.js.map +1 -1
- package/lib/programmers/json/JsonApplicationProgrammer.d.ts +6 -2
- package/lib/programmers/json/JsonApplicationProgrammer.js +200 -75
- package/lib/programmers/json/JsonApplicationProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonSchemasProgrammer.d.ts +6 -0
- package/lib/programmers/json/JsonSchemasProgrammer.js +109 -0
- package/lib/programmers/json/JsonSchemasProgrammer.js.map +1 -0
- package/lib/programmers/llm/LlmApplicationProgrammer.d.ts +1 -1
- package/lib/programmers/llm/LlmApplicationProgrammer.js +57 -39
- package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -1
- package/lib/schemas/json/IJsonApplication.d.ts +31 -12
- package/lib/schemas/json/IJsonSchemaList.d.ts +16 -0
- package/lib/schemas/json/IJsonSchemaList.js +3 -0
- package/lib/schemas/json/IJsonSchemaList.js.map +1 -0
- package/lib/transformers/CallExpressionTransformer.js +3 -1
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/features/json/JsonApplicationTransformer.d.ts +1 -1
- package/lib/transformers/features/json/JsonApplicationTransformer.js +27 -97
- package/lib/transformers/features/json/JsonApplicationTransformer.js.map +1 -1
- package/lib/transformers/features/json/JsonSchemasTransformer.d.ts +5 -0
- package/lib/transformers/features/json/JsonSchemasTransformer.js +159 -0
- package/lib/transformers/features/json/JsonSchemasTransformer.js.map +1 -0
- package/lib/transformers/features/llm/LlmApplicationTransformer.js +1 -1
- package/lib/transformers/features/llm/LlmApplicationTransformer.js.map +1 -1
- package/package.json +1 -1
- package/src/factories/MetadataFactory.ts +400 -400
- package/src/factories/internal/metadata/IMetadataIteratorProps.ts +16 -16
- package/src/factories/internal/metadata/emplace_metadata_object.ts +206 -206
- package/src/factories/internal/metadata/iterate_metadata_collection.ts +145 -145
- package/src/factories/internal/metadata/iterate_metadata_comment_tags.ts +32 -32
- package/src/factories/internal/metadata/iterate_metadata_function.ts +88 -88
- package/src/json.ts +63 -17
- package/src/module.ts +1 -0
- package/src/programmers/json/JsonApplicationProgrammer.ts +249 -72
- package/src/programmers/json/JsonSchemasProgrammer.ts +94 -0
- package/src/programmers/llm/LlmApplicationProgrammer.ts +66 -41
- package/src/schemas/json/IJsonApplication.ts +61 -22
- package/src/schemas/json/IJsonSchemaList.ts +22 -0
- package/src/transformers/CallExpressionTransformer.ts +3 -1
- package/src/transformers/features/json/JsonApplicationTransformer.ts +29 -54
- package/src/transformers/features/json/JsonSchemasTransformer.ts +130 -0
- package/src/transformers/features/llm/LlmApplicationTransformer.ts +1 -1
|
@@ -62,6 +62,7 @@ import { JsonCreateValidateParseTransformer } from "./features/json/JsonCreateVa
|
|
|
62
62
|
import { JsonCreateValidateStringifyTransformer } from "./features/json/JsonCreateValidateStringifyProgrammer";
|
|
63
63
|
import { JsonIsParseTransformer } from "./features/json/JsonIsParseTransformer";
|
|
64
64
|
import { JsonIsStringifyTransformer } from "./features/json/JsonIsStringifyTransformer";
|
|
65
|
+
import { JsonSchemasTransformer } from "./features/json/JsonSchemasTransformer";
|
|
65
66
|
import { JsonStringifyTransformer } from "./features/json/JsonStringifyTransformer";
|
|
66
67
|
import { JsonValidateParseTransformer } from "./features/json/JsonValidateParseTransformer";
|
|
67
68
|
import { JsonValidateStringifyTransformer } from "./features/json/JsonValidateStringifyTransformer";
|
|
@@ -396,8 +397,9 @@ const FUNCTORS: Record<string, Record<string, () => Task>> = {
|
|
|
396
397
|
schema: () => LlmSchemaTransformer.transform,
|
|
397
398
|
},
|
|
398
399
|
json: {
|
|
399
|
-
//
|
|
400
|
+
// METADATA
|
|
400
401
|
application: () => JsonApplicationTransformer.transform,
|
|
402
|
+
schemas: () => JsonSchemasTransformer.transform,
|
|
401
403
|
|
|
402
404
|
// PARSER
|
|
403
405
|
isParse: () => JsonIsParseTransformer.transform,
|
|
@@ -15,35 +15,17 @@ import { ITransformProps } from "../../ITransformProps";
|
|
|
15
15
|
import { TransformerError } from "../../TransformerError";
|
|
16
16
|
|
|
17
17
|
export namespace JsonApplicationTransformer {
|
|
18
|
-
export const transform = (
|
|
19
|
-
|
|
20
|
-
): ts.Expression => {
|
|
18
|
+
export const transform = (props: ITransformProps): ts.Expression => {
|
|
19
|
+
// GET GENERIC ARGUMENT
|
|
21
20
|
if (!props.expression.typeArguments?.length)
|
|
22
21
|
throw new TransformerError({
|
|
23
22
|
code: "typia.json.application",
|
|
24
23
|
message: "no generic argument.",
|
|
25
24
|
});
|
|
26
25
|
|
|
27
|
-
//----
|
|
28
|
-
// GET ARGUMENTS
|
|
29
|
-
//----
|
|
30
|
-
// VALIDATE TUPLE ARGUMENTS
|
|
31
26
|
const top: ts.Node = props.expression.typeArguments[0]!;
|
|
32
|
-
if (
|
|
33
|
-
else if (top.elements.some((child) => !ts.isTypeNode(child)))
|
|
34
|
-
return props.expression;
|
|
27
|
+
if (ts.isTypeNode(top) === false) return props.expression;
|
|
35
28
|
|
|
36
|
-
// GET TYPES
|
|
37
|
-
const types: ts.Type[] = top.elements.map((child) =>
|
|
38
|
-
props.context.checker.getTypeFromTypeNode(child as ts.TypeNode),
|
|
39
|
-
);
|
|
40
|
-
if (types.some((t) => t.isTypeParameter()))
|
|
41
|
-
throw new TransformerError({
|
|
42
|
-
code: "typia.json.application",
|
|
43
|
-
message: "non-specified generic argument(s).",
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// ADDITIONAL PARAMETERS
|
|
47
29
|
const version: "3.0" | "3.1" = get_parameter<"3.0" | "3.1">({
|
|
48
30
|
checker: props.context.checker,
|
|
49
31
|
name: "Version",
|
|
@@ -52,46 +34,39 @@ export namespace JsonApplicationTransformer {
|
|
|
52
34
|
default: () => "3.1",
|
|
53
35
|
})(props.expression.typeArguments[1]);
|
|
54
36
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
//----
|
|
58
|
-
// METADATA
|
|
37
|
+
// GET TYPE
|
|
38
|
+
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
59
39
|
const collection: MetadataCollection = new MetadataCollection({
|
|
60
40
|
replace: MetadataCollection.replace,
|
|
61
41
|
});
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// REPORT BUG IF REQUIRED
|
|
79
|
-
const metadatas: Metadata[] = [];
|
|
80
|
-
const errors: MetadataFactory.IError[] = [];
|
|
81
|
-
for (const r of results) {
|
|
82
|
-
if (r.success === false) errors.push(...r.errors);
|
|
83
|
-
else metadatas.push(r.data);
|
|
84
|
-
}
|
|
85
|
-
if (errors.length)
|
|
42
|
+
const result: ValidationPipe<Metadata, MetadataFactory.IError> =
|
|
43
|
+
MetadataFactory.analyze({
|
|
44
|
+
checker: props.context.checker,
|
|
45
|
+
transformer: props.context.transformer,
|
|
46
|
+
options: {
|
|
47
|
+
escape: true,
|
|
48
|
+
constant: true,
|
|
49
|
+
absorb: false,
|
|
50
|
+
functional: true,
|
|
51
|
+
validate: JsonApplicationProgrammer.validate,
|
|
52
|
+
},
|
|
53
|
+
collection,
|
|
54
|
+
type,
|
|
55
|
+
});
|
|
56
|
+
if (result.success === false)
|
|
86
57
|
throw TransformerError.from({
|
|
87
58
|
code: "typia.json.application",
|
|
88
|
-
errors,
|
|
59
|
+
errors: result.errors,
|
|
89
60
|
});
|
|
90
61
|
|
|
91
|
-
// APPLICATION
|
|
92
|
-
const app: IJsonApplication<
|
|
93
|
-
JsonApplicationProgrammer.write(
|
|
94
|
-
|
|
62
|
+
// GENERATE LLM APPLICATION
|
|
63
|
+
const app: IJsonApplication<"3.0" | "3.1"> =
|
|
64
|
+
JsonApplicationProgrammer.write({
|
|
65
|
+
version,
|
|
66
|
+
metadata: result.data,
|
|
67
|
+
});
|
|
68
|
+
const literal: ts.Expression = LiteralFactory.write(app);
|
|
69
|
+
return literal;
|
|
95
70
|
};
|
|
96
71
|
|
|
97
72
|
const get_parameter =
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { LiteralFactory } from "../../../factories/LiteralFactory";
|
|
4
|
+
import { MetadataCollection } from "../../../factories/MetadataCollection";
|
|
5
|
+
import { MetadataFactory } from "../../../factories/MetadataFactory";
|
|
6
|
+
|
|
7
|
+
import { IJsonSchemaCollection } from "../../../schemas/json/IJsonSchemaList";
|
|
8
|
+
import { Metadata } from "../../../schemas/metadata/Metadata";
|
|
9
|
+
|
|
10
|
+
import { JsonSchemasProgrammer } from "../../../programmers/json/JsonSchemasProgrammer";
|
|
11
|
+
|
|
12
|
+
import { ValidationPipe } from "../../../typings/ValidationPipe";
|
|
13
|
+
|
|
14
|
+
import { ITransformProps } from "../../ITransformProps";
|
|
15
|
+
import { TransformerError } from "../../TransformerError";
|
|
16
|
+
|
|
17
|
+
export namespace JsonSchemasTransformer {
|
|
18
|
+
export const transform = (
|
|
19
|
+
props: Pick<ITransformProps, "context" | "expression">,
|
|
20
|
+
): ts.Expression => {
|
|
21
|
+
if (!props.expression.typeArguments?.length)
|
|
22
|
+
throw new TransformerError({
|
|
23
|
+
code: "typia.json.application",
|
|
24
|
+
message: "no generic argument.",
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
//----
|
|
28
|
+
// GET ARGUMENTS
|
|
29
|
+
//----
|
|
30
|
+
// VALIDATE TUPLE ARGUMENTS
|
|
31
|
+
const top: ts.Node = props.expression.typeArguments[0]!;
|
|
32
|
+
if (!ts.isTupleTypeNode(top)) return props.expression;
|
|
33
|
+
else if (top.elements.some((child) => !ts.isTypeNode(child)))
|
|
34
|
+
return props.expression;
|
|
35
|
+
|
|
36
|
+
// GET TYPES
|
|
37
|
+
const types: ts.Type[] = top.elements.map((child) =>
|
|
38
|
+
props.context.checker.getTypeFromTypeNode(child as ts.TypeNode),
|
|
39
|
+
);
|
|
40
|
+
if (types.some((t) => t.isTypeParameter()))
|
|
41
|
+
throw new TransformerError({
|
|
42
|
+
code: "typia.json.application",
|
|
43
|
+
message: "non-specified generic argument(s).",
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// ADDITIONAL PARAMETERS
|
|
47
|
+
const version: "3.0" | "3.1" = get_parameter<"3.0" | "3.1">({
|
|
48
|
+
checker: props.context.checker,
|
|
49
|
+
name: "Version",
|
|
50
|
+
is: (str) => str === "3.0" || str === "3.1",
|
|
51
|
+
cast: (str) => str as "3.0" | "3.1",
|
|
52
|
+
default: () => "3.1",
|
|
53
|
+
})(props.expression.typeArguments[1]);
|
|
54
|
+
|
|
55
|
+
//----
|
|
56
|
+
// GENERATORS
|
|
57
|
+
//----
|
|
58
|
+
// METADATA
|
|
59
|
+
const collection: MetadataCollection = new MetadataCollection({
|
|
60
|
+
replace: MetadataCollection.replace,
|
|
61
|
+
});
|
|
62
|
+
const results: ValidationPipe<Metadata, MetadataFactory.IError>[] =
|
|
63
|
+
types.map((type) =>
|
|
64
|
+
MetadataFactory.analyze({
|
|
65
|
+
checker: props.context.checker,
|
|
66
|
+
transformer: props.context.transformer,
|
|
67
|
+
options: {
|
|
68
|
+
escape: true,
|
|
69
|
+
constant: true,
|
|
70
|
+
absorb: false,
|
|
71
|
+
validate: JsonSchemasProgrammer.validate,
|
|
72
|
+
},
|
|
73
|
+
collection,
|
|
74
|
+
type,
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
// REPORT BUG IF REQUIRED
|
|
79
|
+
const metadatas: Metadata[] = [];
|
|
80
|
+
const errors: MetadataFactory.IError[] = [];
|
|
81
|
+
for (const r of results) {
|
|
82
|
+
if (r.success === false) errors.push(...r.errors);
|
|
83
|
+
else metadatas.push(r.data);
|
|
84
|
+
}
|
|
85
|
+
if (errors.length)
|
|
86
|
+
throw TransformerError.from({
|
|
87
|
+
code: "typia.json.application",
|
|
88
|
+
errors,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// APPLICATION
|
|
92
|
+
const app: IJsonSchemaCollection<any> =
|
|
93
|
+
JsonSchemasProgrammer.write(version)(metadatas);
|
|
94
|
+
return LiteralFactory.write(app);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const get_parameter =
|
|
98
|
+
<Value>(props: {
|
|
99
|
+
checker: ts.TypeChecker;
|
|
100
|
+
name: string;
|
|
101
|
+
is: (value: string) => boolean;
|
|
102
|
+
cast: (value: string) => Value;
|
|
103
|
+
default: () => Value;
|
|
104
|
+
}) =>
|
|
105
|
+
(node: ts.TypeNode | undefined): Value => {
|
|
106
|
+
if (!node) return props.default();
|
|
107
|
+
|
|
108
|
+
// CHECK LITERAL TYPE
|
|
109
|
+
const type: ts.Type = props.checker.getTypeFromTypeNode(node);
|
|
110
|
+
if (
|
|
111
|
+
!type.isLiteral() &&
|
|
112
|
+
(type.getFlags() & ts.TypeFlags.BooleanLiteral) === 0
|
|
113
|
+
)
|
|
114
|
+
throw new TransformerError({
|
|
115
|
+
code: "typia.json.application",
|
|
116
|
+
message: `generic argument "${props.name}" must be constant.`,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// GET VALUE AND VALIDATE IT
|
|
120
|
+
const value = type.isLiteral()
|
|
121
|
+
? type.value
|
|
122
|
+
: props.checker.typeToString(type);
|
|
123
|
+
if (typeof value !== "string" || props.is(value) === false)
|
|
124
|
+
throw new TransformerError({
|
|
125
|
+
code: "typia.json.application",
|
|
126
|
+
message: `invalid value on generic argument "${props.name}".`,
|
|
127
|
+
});
|
|
128
|
+
return props.cast(value);
|
|
129
|
+
};
|
|
130
|
+
}
|