typia 7.0.0-dev.20241010 → 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/internal/$httpParameterReadBigint.d.ts +1 -0
- package/lib/internal/{$httpParameterBigint.js → $httpParameterReadBigint.js} +4 -4
- package/lib/internal/$httpParameterReadBigint.js.map +1 -0
- package/lib/internal/$httpParameterReadBoolean.d.ts +1 -0
- package/lib/internal/{$httpParameterBoolean.js → $httpParameterReadBoolean.js} +4 -4
- package/lib/internal/$httpParameterReadBoolean.js.map +1 -0
- package/lib/internal/$httpParameterReadNumber.d.ts +1 -0
- package/lib/internal/{$httpParameterNumber.js → $httpParameterReadNumber.js} +4 -4
- package/lib/internal/$httpParameterReadNumber.js.map +1 -0
- package/lib/internal/$httpParameterReadString.d.ts +1 -0
- package/lib/internal/$httpParameterReadString.js +8 -0
- package/lib/internal/$httpParameterReadString.js.map +1 -0
- 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/internal/{$httpParameterBigint.ts → $httpParameterReadBigint.ts} +1 -1
- package/src/internal/{$httpParameterBoolean.ts → $httpParameterReadBoolean.ts} +1 -1
- package/src/internal/{$httpParameterNumber.ts → $httpParameterReadNumber.ts} +1 -1
- package/src/internal/$httpParameterReadString.ts +2 -0
- 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
- package/lib/internal/$httpParameterBigint.d.ts +0 -1
- package/lib/internal/$httpParameterBigint.js.map +0 -1
- package/lib/internal/$httpParameterBoolean.d.ts +0 -1
- package/lib/internal/$httpParameterBoolean.js.map +0 -1
- package/lib/internal/$httpParameterNumber.d.ts +0 -1
- package/lib/internal/$httpParameterNumber.js.map +0 -1
- package/lib/internal/$httpParameterString.d.ts +0 -1
- package/lib/internal/$httpParameterString.js +0 -8
- package/lib/internal/$httpParameterString.js.map +0 -1
- package/src/internal/$httpParameterString.ts +0 -2
|
@@ -11,56 +11,81 @@ import { IJsDocTagInfo } from "../../module";
|
|
|
11
11
|
import { LlmSchemaProgrammer } from "./LlmSchemaProgrammer";
|
|
12
12
|
|
|
13
13
|
export namespace LlmApplicationProgrammer {
|
|
14
|
-
export const validate = (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
export const validate = () => {
|
|
15
|
+
let top: Metadata | undefined;
|
|
16
|
+
return (
|
|
17
|
+
metadata: Metadata,
|
|
18
|
+
explore: MetadataFactory.IExplore,
|
|
19
|
+
): string[] => {
|
|
20
|
+
top ??= metadata;
|
|
21
|
+
if (explore.top === false)
|
|
22
|
+
if (
|
|
23
|
+
explore.object === top?.objects[0] &&
|
|
24
|
+
typeof explore.property === "string" &&
|
|
25
|
+
metadata.size() === 1 &&
|
|
26
|
+
metadata.nullable === false &&
|
|
27
|
+
metadata.isRequired() === true &&
|
|
28
|
+
metadata.functions.length === 1
|
|
29
|
+
)
|
|
30
|
+
return validateFunction(metadata.functions[0]!);
|
|
31
|
+
else return LlmSchemaProgrammer.validate(metadata);
|
|
19
32
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
const output: string[] = [];
|
|
34
|
+
const valid: boolean =
|
|
35
|
+
metadata.size() === 1 &&
|
|
36
|
+
metadata.objects.length === 1 &&
|
|
37
|
+
metadata.isRequired() === true &&
|
|
38
|
+
metadata.nullable === false;
|
|
39
|
+
if (valid === false)
|
|
40
|
+
output.push(
|
|
41
|
+
"LLM application's generic arugment must be a class/interface type.",
|
|
42
|
+
);
|
|
30
43
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
const object: MetadataObject | undefined = metadata.objects[0];
|
|
45
|
+
if (object !== undefined) {
|
|
46
|
+
if (object.properties.some((p) => p.key.isSoleLiteral() === false))
|
|
47
|
+
output.push("LLM application does not allow dynamic keys.");
|
|
48
|
+
let least: boolean = false;
|
|
49
|
+
for (const p of object.properties) {
|
|
50
|
+
const value: Metadata = p.value;
|
|
51
|
+
if (value.functions.length) {
|
|
52
|
+
least ||= true;
|
|
53
|
+
if (valid === false) {
|
|
54
|
+
if (value.functions.length !== 1 || value.size() !== 1)
|
|
55
|
+
output.push(
|
|
56
|
+
"LLM application's function type does not allow union type.",
|
|
57
|
+
);
|
|
58
|
+
if (value.isRequired() === false)
|
|
59
|
+
output.push(
|
|
60
|
+
"LLM application's function type must be required.",
|
|
61
|
+
);
|
|
62
|
+
if (value.nullable === true)
|
|
63
|
+
output.push(
|
|
64
|
+
"LLM application's function type must not be nullable.",
|
|
65
|
+
);
|
|
66
|
+
}
|
|
51
67
|
}
|
|
52
68
|
}
|
|
69
|
+
if (least === false)
|
|
70
|
+
output.push(
|
|
71
|
+
"LLM application's target type must have at least a function type.",
|
|
72
|
+
);
|
|
53
73
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
74
|
+
return output;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const validateFunction = (func: MetadataFunction): string[] => {
|
|
79
|
+
const output: string[] = [];
|
|
80
|
+
if (func.output.size() && func.output.isRequired() === false)
|
|
81
|
+
output.push(
|
|
82
|
+
"LLM application's function return type must not be union type with undefined.",
|
|
83
|
+
);
|
|
59
84
|
return output;
|
|
60
85
|
};
|
|
61
86
|
|
|
62
87
|
export const write = (metadata: Metadata): ILlmApplication => {
|
|
63
|
-
const errors: string[] = validate(metadata, {
|
|
88
|
+
const errors: string[] = validate()(metadata, {
|
|
64
89
|
top: true,
|
|
65
90
|
object: null,
|
|
66
91
|
property: null,
|
|
@@ -1,22 +1,61 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
Version extends "3.0" | "3.1" = "3.1",
|
|
5
|
-
|
|
6
|
-
>
|
|
7
|
-
|
|
8
|
-
: IJsonApplication.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import { OpenApi, OpenApiV3 } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
export interface IJsonApplication<
|
|
4
|
+
Version extends "3.0" | "3.1" = "3.1",
|
|
5
|
+
App extends any = object,
|
|
6
|
+
> {
|
|
7
|
+
version: Version;
|
|
8
|
+
components: IJsonApplication.IComponents<IJsonApplication.Schema<Version>>;
|
|
9
|
+
functions: IJsonApplication.IFunction<IJsonApplication.Schema<Version>>[];
|
|
10
|
+
__application?: App | undefined;
|
|
11
|
+
}
|
|
12
|
+
export namespace IJsonApplication {
|
|
13
|
+
export type Schema<Version extends "3.0" | "3.1"> = Version extends "3.1"
|
|
14
|
+
? OpenApi.IJsonSchema
|
|
15
|
+
: OpenApiV3.IJsonSchema;
|
|
16
|
+
|
|
17
|
+
export interface IComponents<
|
|
18
|
+
Schema extends
|
|
19
|
+
| OpenApi.IJsonSchema
|
|
20
|
+
| OpenApiV3.IJsonSchema = OpenApi.IJsonSchema,
|
|
21
|
+
> {
|
|
22
|
+
schemas?: Record<string, Schema>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface IFunction<
|
|
26
|
+
Schema extends
|
|
27
|
+
| OpenApi.IJsonSchema
|
|
28
|
+
| OpenApiV3.IJsonSchema = OpenApi.IJsonSchema,
|
|
29
|
+
> {
|
|
30
|
+
async: boolean;
|
|
31
|
+
name: string;
|
|
32
|
+
parameters: IParameter<Schema>[];
|
|
33
|
+
output: IOutput<Schema> | undefined;
|
|
34
|
+
summary?: string | undefined;
|
|
35
|
+
description?: string | undefined;
|
|
36
|
+
deprecated?: boolean;
|
|
37
|
+
tags?: string[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface IParameter<
|
|
41
|
+
Schema extends
|
|
42
|
+
| OpenApi.IJsonSchema
|
|
43
|
+
| OpenApiV3.IJsonSchema = OpenApi.IJsonSchema,
|
|
44
|
+
> {
|
|
45
|
+
name: string;
|
|
46
|
+
required: boolean;
|
|
47
|
+
schema: Schema;
|
|
48
|
+
title?: string | undefined;
|
|
49
|
+
description?: string | undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface IOutput<
|
|
53
|
+
Schema extends
|
|
54
|
+
| OpenApi.IJsonSchema
|
|
55
|
+
| OpenApiV3.IJsonSchema = OpenApi.IJsonSchema,
|
|
56
|
+
> {
|
|
57
|
+
schema: Schema;
|
|
58
|
+
required: boolean;
|
|
59
|
+
description?: string | undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { OpenApi, OpenApiV3 } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
export type IJsonSchemaCollection<
|
|
4
|
+
Version extends "3.0" | "3.1" = "3.1",
|
|
5
|
+
Types = unknown[],
|
|
6
|
+
> = Version extends "3.0"
|
|
7
|
+
? IJsonSchemaCollection.IV3_0<Types>
|
|
8
|
+
: IJsonSchemaCollection.IV3_1<Types>;
|
|
9
|
+
export namespace IJsonSchemaCollection {
|
|
10
|
+
export interface IV3_0<Types = unknown[]> {
|
|
11
|
+
version: "3.0";
|
|
12
|
+
schemas: OpenApiV3.IJsonSchema[];
|
|
13
|
+
components: OpenApiV3.IComponents;
|
|
14
|
+
__types?: Types | undefined;
|
|
15
|
+
}
|
|
16
|
+
export interface IV3_1<Types = unknown[]> {
|
|
17
|
+
version: "3.1";
|
|
18
|
+
components: OpenApi.IComponents;
|
|
19
|
+
schemas: OpenApi.IJsonSchema[];
|
|
20
|
+
__types?: Types | undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const $httpParameterBigint: (value: string) => string | bigint | null;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"$httpParameterBigint.js","sourceRoot":"","sources":["../../src/internal/$httpParameterBigint.ts"],"names":[],"mappings":";;;AAAO,IAAM,oBAAoB,GAAG,UAAC,KAAa;IAChD,OAAA,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI;AAAzC,CAAyC,CAAC;AAD/B,QAAA,oBAAoB,wBACW;AAE5C,IAAM,QAAQ,GAAG,UAAC,GAAW;IAC3B,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,GAAG,CAAC;IACb,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const $httpParameterBoolean: (value: string) => string | boolean | null;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"$httpParameterBoolean.js","sourceRoot":"","sources":["../../src/internal/$httpParameterBoolean.ts"],"names":[],"mappings":";;;AAAO,IAAM,qBAAqB,GAAG,UAAC,KAAa;IACjD,OAAA,KAAK,KAAK,MAAM;QACd,CAAC,CAAC,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,GAAG;YACjC,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,GAAG;gBAClC,CAAC,CAAC,KAAK;gBACP,CAAC,CAAC,KAAK;QACX,CAAC,CAAC,IAAI;AANR,CAMQ,CAAC;AAPE,QAAA,qBAAqB,yBAOvB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const $httpParameterNumber: (value: string) => string | number | null;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"$httpParameterNumber.js","sourceRoot":"","sources":["../../src/internal/$httpParameterNumber.ts"],"names":[],"mappings":";;;AAAO,IAAM,oBAAoB,GAAG,UAAC,KAAa;IAChD,OAAA,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI;AAAzC,CAAyC,CAAC;AAD/B,QAAA,oBAAoB,wBACW;AAE5C,IAAM,QAAQ,GAAG,UAAC,GAAW;IAC3B,IAAM,KAAK,GAAW,MAAM,CAAC,GAAG,CAAC,CAAC;IAClC,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC;AACpC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const $httpParameterString: (value: string) => string | null;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.$httpParameterString = void 0;
|
|
4
|
-
var $httpParameterString = function (value) {
|
|
5
|
-
return value !== "null" ? value : null;
|
|
6
|
-
};
|
|
7
|
-
exports.$httpParameterString = $httpParameterString;
|
|
8
|
-
//# sourceMappingURL=$httpParameterString.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"$httpParameterString.js","sourceRoot":"","sources":["../../src/internal/$httpParameterString.ts"],"names":[],"mappings":";;;AAAO,IAAM,oBAAoB,GAAG,UAAC,KAAa;IAChD,OAAA,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;AAA/B,CAA+B,CAAC;AADrB,QAAA,oBAAoB,wBACC"}
|