typia 9.0.1 → 9.1.0
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/functional.js +19 -27
- package/lib/functional.js.map +1 -1
- package/lib/functional.mjs +20 -27
- package/lib/http.js +27 -32
- package/lib/http.js.map +1 -1
- package/lib/http.mjs +28 -32
- package/lib/json.d.mts +66 -4
- package/lib/json.d.ts +66 -4
- package/lib/json.js +23 -21
- package/lib/json.js.map +1 -1
- package/lib/json.mjs +24 -22
- package/lib/llm.js +4 -9
- package/lib/llm.js.map +1 -1
- package/lib/llm.mjs +5 -9
- package/lib/misc.js +27 -23
- package/lib/misc.js.map +1 -1
- package/lib/misc.mjs +28 -23
- package/lib/module.d.mts +1 -0
- package/lib/module.d.ts +1 -0
- package/lib/module.js +20 -24
- package/lib/module.js.map +1 -1
- package/lib/module.mjs +19 -24
- package/lib/notations.js +25 -30
- package/lib/notations.js.map +1 -1
- package/lib/notations.mjs +26 -30
- package/lib/programmers/json/JsonSchemaProgrammer.d.mts +9 -0
- package/lib/programmers/json/JsonSchemaProgrammer.d.ts +9 -0
- package/lib/programmers/json/JsonSchemaProgrammer.js +20 -0
- package/lib/programmers/json/JsonSchemaProgrammer.js.map +1 -0
- package/lib/programmers/json/JsonSchemaProgrammer.mjs +20 -0
- package/lib/programmers/json/JsonSchemaProgrammer.mjs.map +1 -0
- package/lib/programmers/json/JsonSchemasProgrammer.js +1 -1
- package/lib/programmers/json/JsonSchemasProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonSchemasProgrammer.mjs +1 -1
- package/lib/protobuf.js +18 -23
- package/lib/protobuf.js.map +1 -1
- package/lib/protobuf.mjs +19 -23
- package/lib/reflect.js +3 -8
- package/lib/reflect.js.map +1 -1
- package/lib/reflect.mjs +4 -8
- package/lib/schemas/json/IJsonSchemaUnit.d.mts +26 -0
- package/lib/schemas/json/IJsonSchemaUnit.d.ts +26 -0
- package/lib/schemas/json/IJsonSchemaUnit.js +3 -0
- package/lib/schemas/json/IJsonSchemaUnit.js.map +1 -0
- package/lib/schemas/json/IJsonSchemaUnit.mjs +2 -0
- package/lib/schemas/json/IJsonSchemaUnit.mjs.map +1 -0
- package/lib/transformers/CallExpressionTransformer.js +2 -2
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/CallExpressionTransformer.mjs +2 -2
- package/lib/transformers/NoTransformConfigurationError.d.mts +1 -0
- package/lib/transformers/NoTransformConfigurationError.d.ts +1 -0
- package/lib/transformers/NoTransformConfigurationError.js +20 -0
- package/lib/transformers/NoTransformConfigurationError.js.map +1 -0
- package/lib/transformers/NoTransformConfigurationError.mjs +19 -0
- package/lib/transformers/NoTransformConfigurationError.mjs.map +1 -0
- package/lib/transformers/features/json/JsonSchemaTransformer.d.mts +5 -0
- package/lib/transformers/features/json/JsonSchemaTransformer.d.ts +5 -0
- package/lib/transformers/features/json/JsonSchemaTransformer.js +108 -0
- package/lib/transformers/features/json/JsonSchemaTransformer.js.map +1 -0
- package/lib/transformers/features/json/JsonSchemaTransformer.mjs +104 -0
- package/lib/transformers/features/json/JsonSchemaTransformer.mjs.map +1 -0
- package/lib/transformers/features/json/JsonSchemasTransformer.js +9 -9
- package/lib/transformers/features/json/JsonSchemasTransformer.js.map +1 -1
- package/lib/transformers/features/json/JsonSchemasTransformer.mjs +9 -9
- package/package.json +1 -1
- package/src/functional.ts +20 -30
- package/src/http.ts +28 -35
- package/src/json.ts +73 -73
- package/src/llm.ts +5 -12
- package/src/misc.ts +19 -26
- package/src/module.ts +21 -27
- package/src/notations.ts +26 -33
- package/src/programmers/json/JsonSchemaProgrammer.ts +26 -0
- package/src/programmers/json/JsonSchemasProgrammer.ts +1 -1
- package/src/protobuf.ts +19 -26
- package/src/reflect.ts +4 -11
- package/src/schemas/json/IJsonSchemaUnit.ts +32 -0
- package/src/transformers/CallExpressionTransformer.ts +2 -2
- package/src/transformers/NoTransformConfigurationError.ts +18 -0
- package/src/transformers/features/json/JsonSchemaTransformer.ts +135 -0
- package/src/transformers/features/json/JsonSchemasTransformer.ts +9 -9
package/src/protobuf.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { NoTransformConfigurationError } from "./transformers/NoTransformConfigurationError";
|
|
2
|
+
|
|
1
3
|
import { IValidation } from "./IValidation";
|
|
2
4
|
import { Resolved } from "./Resolved";
|
|
3
5
|
import { TypeGuardError } from "./TypeGuardError";
|
|
@@ -57,7 +59,7 @@ export function message<T>(): string;
|
|
|
57
59
|
* @internal
|
|
58
60
|
*/
|
|
59
61
|
export function message(): never {
|
|
60
|
-
|
|
62
|
+
NoTransformConfigurationError("protobuf.message");
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
/* -----------------------------------------------------------
|
|
@@ -129,7 +131,7 @@ export function decode<T>(input: Uint8Array): Resolved<T>;
|
|
|
129
131
|
* @internal
|
|
130
132
|
*/
|
|
131
133
|
export function decode(): never {
|
|
132
|
-
|
|
134
|
+
NoTransformConfigurationError("protobuf.decode");
|
|
133
135
|
}
|
|
134
136
|
|
|
135
137
|
/**
|
|
@@ -204,7 +206,7 @@ export function assertDecode<T>(
|
|
|
204
206
|
* @internal
|
|
205
207
|
*/
|
|
206
208
|
export function assertDecode(): never {
|
|
207
|
-
|
|
209
|
+
NoTransformConfigurationError("protobuf.assertDecode");
|
|
208
210
|
}
|
|
209
211
|
|
|
210
212
|
/**
|
|
@@ -271,7 +273,7 @@ export function isDecode<T>(input: Uint8Array): Resolved<T> | null;
|
|
|
271
273
|
* @internal
|
|
272
274
|
*/
|
|
273
275
|
export function isDecode(): never {
|
|
274
|
-
|
|
276
|
+
NoTransformConfigurationError("protobuf.isDecode");
|
|
275
277
|
}
|
|
276
278
|
|
|
277
279
|
/**
|
|
@@ -340,7 +342,7 @@ export function validateDecode<T>(input: Uint8Array): IValidation<Resolved<T>>;
|
|
|
340
342
|
* @internal
|
|
341
343
|
*/
|
|
342
344
|
export function validateDecode(): never {
|
|
343
|
-
|
|
345
|
+
NoTransformConfigurationError("protobuf.validateDecode");
|
|
344
346
|
}
|
|
345
347
|
|
|
346
348
|
/* -----------------------------------------------------------
|
|
@@ -379,7 +381,7 @@ export function encode<T>(input: T): Uint8Array;
|
|
|
379
381
|
* @internal
|
|
380
382
|
*/
|
|
381
383
|
export function encode(): never {
|
|
382
|
-
|
|
384
|
+
NoTransformConfigurationError("protobuf.encode");
|
|
383
385
|
}
|
|
384
386
|
|
|
385
387
|
/**
|
|
@@ -460,7 +462,7 @@ export function assertEncode<T>(
|
|
|
460
462
|
* @internal
|
|
461
463
|
*/
|
|
462
464
|
export function assertEncode(): never {
|
|
463
|
-
|
|
465
|
+
NoTransformConfigurationError("protobuf.assertEncode");
|
|
464
466
|
}
|
|
465
467
|
|
|
466
468
|
/**
|
|
@@ -533,7 +535,7 @@ export function isEncode<T>(input: unknown): Uint8Array | null;
|
|
|
533
535
|
* @internal
|
|
534
536
|
*/
|
|
535
537
|
export function isEncode(): never {
|
|
536
|
-
|
|
538
|
+
NoTransformConfigurationError("protobuf.isEncode");
|
|
537
539
|
}
|
|
538
540
|
|
|
539
541
|
/**
|
|
@@ -608,7 +610,7 @@ export function validateEncode<T>(input: unknown): IValidation<Uint8Array>;
|
|
|
608
610
|
* @internal
|
|
609
611
|
*/
|
|
610
612
|
export function validateEncode(): never {
|
|
611
|
-
|
|
613
|
+
NoTransformConfigurationError("protobuf.validateEncode");
|
|
612
614
|
}
|
|
613
615
|
|
|
614
616
|
/* -----------------------------------------------------------
|
|
@@ -639,7 +641,7 @@ export function createDecode<T>(): (input: Uint8Array) => Resolved<T>;
|
|
|
639
641
|
* @internal
|
|
640
642
|
*/
|
|
641
643
|
export function createDecode<T>(): (input: Uint8Array) => Resolved<T> {
|
|
642
|
-
|
|
644
|
+
NoTransformConfigurationError("protobuf.createDecode");
|
|
643
645
|
}
|
|
644
646
|
|
|
645
647
|
/**
|
|
@@ -667,7 +669,7 @@ export function createIsDecode<T>(): (input: Uint8Array) => Resolved<T> | null;
|
|
|
667
669
|
* @internal
|
|
668
670
|
*/
|
|
669
671
|
export function createIsDecode<T>(): (input: Uint8Array) => Resolved<T> | null {
|
|
670
|
-
|
|
672
|
+
NoTransformConfigurationError("protobuf.createIsDecode");
|
|
671
673
|
}
|
|
672
674
|
|
|
673
675
|
/**
|
|
@@ -701,7 +703,7 @@ export function createAssertDecode<T>(
|
|
|
701
703
|
* @internal
|
|
702
704
|
*/
|
|
703
705
|
export function createAssertDecode<T>(): (input: Uint8Array) => Resolved<T> {
|
|
704
|
-
|
|
706
|
+
NoTransformConfigurationError("protobuf.createAssertDecode");
|
|
705
707
|
}
|
|
706
708
|
|
|
707
709
|
/**
|
|
@@ -733,7 +735,7 @@ export function createValidateDecode<T>(): (
|
|
|
733
735
|
export function createValidateDecode<T>(): (
|
|
734
736
|
input: Uint8Array,
|
|
735
737
|
) => IValidation<Resolved<T>> {
|
|
736
|
-
|
|
738
|
+
NoTransformConfigurationError("protobuf.createValidateDecode");
|
|
737
739
|
}
|
|
738
740
|
|
|
739
741
|
/**
|
|
@@ -761,7 +763,7 @@ export function createEncode<T>(): (input: T) => Uint8Array;
|
|
|
761
763
|
* @internal
|
|
762
764
|
*/
|
|
763
765
|
export function createEncode<T>(): (input: T) => Uint8Array {
|
|
764
|
-
|
|
766
|
+
NoTransformConfigurationError("protobuf.createEncode");
|
|
765
767
|
}
|
|
766
768
|
|
|
767
769
|
/**
|
|
@@ -789,7 +791,7 @@ export function createIsEncode<T>(): (input: T) => Uint8Array | null;
|
|
|
789
791
|
* @internal
|
|
790
792
|
*/
|
|
791
793
|
export function createIsEncode<T>(): (input: T) => Uint8Array | null {
|
|
792
|
-
|
|
794
|
+
NoTransformConfigurationError("protobuf.createIsEncode");
|
|
793
795
|
}
|
|
794
796
|
|
|
795
797
|
/**
|
|
@@ -823,7 +825,7 @@ export function createAssertEncode<T>(
|
|
|
823
825
|
* @internal
|
|
824
826
|
*/
|
|
825
827
|
export function createAssertEncode<T>(): (input: T) => Uint8Array {
|
|
826
|
-
|
|
828
|
+
NoTransformConfigurationError("protobuf.createAssertEncode");
|
|
827
829
|
}
|
|
828
830
|
|
|
829
831
|
/**
|
|
@@ -855,14 +857,5 @@ export function createValidateEncode<T>(): (
|
|
|
855
857
|
export function createValidateEncode<T>(): (
|
|
856
858
|
input: T,
|
|
857
859
|
) => IValidation<Uint8Array> {
|
|
858
|
-
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
/**
|
|
862
|
-
* @internal
|
|
863
|
-
*/
|
|
864
|
-
function halt(name: string): never {
|
|
865
|
-
throw new Error(
|
|
866
|
-
`Error on typia.protobuf.${name}(): no transform has been configured. Read and follow https://typia.io/docs/setup please.`,
|
|
867
|
-
);
|
|
860
|
+
NoTransformConfigurationError("protobuf.createValidateEncode");
|
|
868
861
|
}
|
package/src/reflect.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { IMetadataApplication } from "./schemas/metadata/IMetadataApplication";
|
|
2
2
|
|
|
3
|
+
import { NoTransformConfigurationError } from "./transformers/NoTransformConfigurationError";
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* > You must configure the generic argument `Types`.
|
|
5
7
|
*
|
|
@@ -38,20 +40,11 @@ export function metadata<Types extends unknown[]>(): IMetadataApplication;
|
|
|
38
40
|
* @internal
|
|
39
41
|
*/
|
|
40
42
|
export function metadata(): never {
|
|
41
|
-
|
|
43
|
+
NoTransformConfigurationError("reflect.metadata");
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
export function name<T, Regular extends boolean = false>(): string;
|
|
45
47
|
export function name(): never;
|
|
46
48
|
export function name(): never {
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @internal
|
|
52
|
-
*/
|
|
53
|
-
function halt(name: string): never {
|
|
54
|
-
throw new Error(
|
|
55
|
-
`Error on typia.reflect.${name}(): no transform has been configured. Read and follow https://typia.io/docs/setup please.`,
|
|
56
|
-
);
|
|
49
|
+
NoTransformConfigurationError("reflect.name");
|
|
57
50
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { OpenApi, OpenApiV3 } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Unit of JSON schema.
|
|
5
|
+
*
|
|
6
|
+
* `IJsonSchemaUnit` is a type that represents a single JSON schema unit
|
|
7
|
+
* containing the schema and components.
|
|
8
|
+
*
|
|
9
|
+
* @template Version Version of the OpenAPI specification
|
|
10
|
+
* @template Type Original TypeScript type used in the JSON schema
|
|
11
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
12
|
+
*/
|
|
13
|
+
export type IJsonSchemaUnit<
|
|
14
|
+
Version extends "3.0" | "3.1" = "3.1",
|
|
15
|
+
Type = unknown,
|
|
16
|
+
> = Version extends "3.0"
|
|
17
|
+
? IJsonSchemaUnit.IV3_0<Type>
|
|
18
|
+
: IJsonSchemaUnit.IV3_1<Type>;
|
|
19
|
+
export namespace IJsonSchemaUnit {
|
|
20
|
+
export interface IV3_0<Type> {
|
|
21
|
+
version: "3.0";
|
|
22
|
+
schema: OpenApiV3.IJsonSchema;
|
|
23
|
+
components: OpenApiV3.IComponents;
|
|
24
|
+
__type?: Type | undefined;
|
|
25
|
+
}
|
|
26
|
+
export interface IV3_1<Type> {
|
|
27
|
+
version: "3.1";
|
|
28
|
+
schema: OpenApi.IJsonSchema;
|
|
29
|
+
components: OpenApi.IComponents;
|
|
30
|
+
__type?: Type | undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -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 { JsonSchemaTransformer } from "./features/json/JsonSchemaTransformer";
|
|
65
66
|
import { JsonSchemasTransformer } from "./features/json/JsonSchemasTransformer";
|
|
66
67
|
import { JsonStringifyTransformer } from "./features/json/JsonStringifyTransformer";
|
|
67
68
|
import { JsonValidateParseTransformer } from "./features/json/JsonValidateParseTransformer";
|
|
@@ -401,9 +402,8 @@ const FUNCTORS: Record<string, Record<string, () => Task>> = {
|
|
|
401
402
|
},
|
|
402
403
|
json: {
|
|
403
404
|
// METADATA
|
|
404
|
-
// application: () => JsonApplicationTransformer.transform,
|
|
405
|
-
application: () => JsonSchemasTransformer.transform,
|
|
406
405
|
schemas: () => JsonSchemasTransformer.transform,
|
|
406
|
+
schema: () => JsonSchemaTransformer.transform,
|
|
407
407
|
|
|
408
408
|
// PARSER
|
|
409
409
|
isParse: () => JsonIsParseTransformer.transform,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
*/
|
|
4
|
+
export function NoTransformConfigurationError(name: string): never {
|
|
5
|
+
throw new Error(
|
|
6
|
+
[
|
|
7
|
+
`Error on typia.${name}(): no transform has been configured.`,
|
|
8
|
+
"",
|
|
9
|
+
"Read and follow https://typia.io/docs/setup please.",
|
|
10
|
+
"",
|
|
11
|
+
[
|
|
12
|
+
"If you've already completed the setup, it means there's",
|
|
13
|
+
"a bug in your code. Run `tsc` command so that check what",
|
|
14
|
+
"is wrong with your code.",
|
|
15
|
+
].join(" "),
|
|
16
|
+
].join("\n"),
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
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 { Metadata } from "../../../schemas/metadata/Metadata";
|
|
8
|
+
|
|
9
|
+
import { JsonSchemaProgrammer } from "../../../programmers/json/JsonSchemaProgrammer";
|
|
10
|
+
import { JsonSchemasProgrammer } from "../../../programmers/json/JsonSchemasProgrammer";
|
|
11
|
+
|
|
12
|
+
import { ValidationPipe } from "../../../typings/ValidationPipe";
|
|
13
|
+
|
|
14
|
+
import { IJsonSchemaUnit } from "../../../module";
|
|
15
|
+
import { ITransformProps } from "../../ITransformProps";
|
|
16
|
+
import { TransformerError } from "../../TransformerError";
|
|
17
|
+
|
|
18
|
+
export namespace JsonSchemaTransformer {
|
|
19
|
+
export const transform = (
|
|
20
|
+
props: Pick<ITransformProps, "context" | "expression">,
|
|
21
|
+
): ts.Expression => {
|
|
22
|
+
if (!props.expression.typeArguments?.length)
|
|
23
|
+
throw new TransformerError({
|
|
24
|
+
code: "typia.json.schema",
|
|
25
|
+
message: "no generic argument.",
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
//----
|
|
29
|
+
// GET ARGUMENTS
|
|
30
|
+
//----
|
|
31
|
+
// VALIDATE TUPLE ARGUMENTS
|
|
32
|
+
const top: ts.Node | undefined = props.expression.typeArguments[0];
|
|
33
|
+
if (top === undefined || ts.isTypeNode(top) === false)
|
|
34
|
+
return props.expression;
|
|
35
|
+
|
|
36
|
+
// GET TYPES
|
|
37
|
+
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
38
|
+
if (type.isTypeParameter())
|
|
39
|
+
throw new TransformerError({
|
|
40
|
+
code: "typia.json.schema",
|
|
41
|
+
message: "non-specified generic argument.",
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// ADDITIONAL PARAMETERS
|
|
45
|
+
const version: "3.0" | "3.1" = getParameter<"3.0" | "3.1">({
|
|
46
|
+
checker: props.context.checker,
|
|
47
|
+
name: "Version",
|
|
48
|
+
is: (str) => str === "3.0" || str === "3.1",
|
|
49
|
+
cast: (str) => str as "3.0" | "3.1",
|
|
50
|
+
default: () => "3.1",
|
|
51
|
+
})(props.expression.typeArguments[1]);
|
|
52
|
+
|
|
53
|
+
//----
|
|
54
|
+
// GENERATORS
|
|
55
|
+
//----
|
|
56
|
+
// METADATA
|
|
57
|
+
const analyze = (validate: boolean): Metadata => {
|
|
58
|
+
const results: ValidationPipe<Metadata, MetadataFactory.IError> =
|
|
59
|
+
MetadataFactory.analyze({
|
|
60
|
+
checker: props.context.checker,
|
|
61
|
+
transformer: props.context.transformer,
|
|
62
|
+
options: {
|
|
63
|
+
absorb: validate,
|
|
64
|
+
constant: true,
|
|
65
|
+
escape: true,
|
|
66
|
+
validate:
|
|
67
|
+
validate === true ? JsonSchemasProgrammer.validate : undefined,
|
|
68
|
+
},
|
|
69
|
+
collection: new MetadataCollection({
|
|
70
|
+
replace: MetadataCollection.replace,
|
|
71
|
+
}),
|
|
72
|
+
type,
|
|
73
|
+
});
|
|
74
|
+
if (results.success === false)
|
|
75
|
+
throw TransformerError.from({
|
|
76
|
+
code: "typia.json.schema",
|
|
77
|
+
errors: results.errors,
|
|
78
|
+
});
|
|
79
|
+
return results.data;
|
|
80
|
+
};
|
|
81
|
+
analyze(true);
|
|
82
|
+
|
|
83
|
+
// APPLICATION
|
|
84
|
+
const app: IJsonSchemaUnit<any> = JsonSchemaProgrammer.write({
|
|
85
|
+
version,
|
|
86
|
+
metadata: analyze(false),
|
|
87
|
+
});
|
|
88
|
+
return ts.factory.createAsExpression(
|
|
89
|
+
LiteralFactory.write(app),
|
|
90
|
+
props.context.importer.type({
|
|
91
|
+
file: "typia",
|
|
92
|
+
name: "IJsonSchemaUnit",
|
|
93
|
+
arguments: [
|
|
94
|
+
ts.factory.createLiteralTypeNode(
|
|
95
|
+
ts.factory.createStringLiteral(version),
|
|
96
|
+
),
|
|
97
|
+
],
|
|
98
|
+
}),
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const getParameter =
|
|
103
|
+
<Value>(props: {
|
|
104
|
+
checker: ts.TypeChecker;
|
|
105
|
+
name: string;
|
|
106
|
+
is: (value: string) => boolean;
|
|
107
|
+
cast: (value: string) => Value;
|
|
108
|
+
default: () => Value;
|
|
109
|
+
}) =>
|
|
110
|
+
(node: ts.TypeNode | undefined): Value => {
|
|
111
|
+
if (!node) return props.default();
|
|
112
|
+
|
|
113
|
+
// CHECK LITERAL TYPE
|
|
114
|
+
const type: ts.Type = props.checker.getTypeFromTypeNode(node);
|
|
115
|
+
if (
|
|
116
|
+
!type.isLiteral() &&
|
|
117
|
+
(type.getFlags() & ts.TypeFlags.BooleanLiteral) === 0
|
|
118
|
+
)
|
|
119
|
+
throw new TransformerError({
|
|
120
|
+
code: "typia.json.schema",
|
|
121
|
+
message: `generic argument "${props.name}" must be constant.`,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// GET VALUE AND VALIDATE IT
|
|
125
|
+
const value = type.isLiteral()
|
|
126
|
+
? type.value
|
|
127
|
+
: props.checker.typeToString(type);
|
|
128
|
+
if (typeof value !== "string" || props.is(value) === false)
|
|
129
|
+
throw new TransformerError({
|
|
130
|
+
code: "typia.json.schema",
|
|
131
|
+
message: `invalid value on generic argument "${props.name}".`,
|
|
132
|
+
});
|
|
133
|
+
return props.cast(value);
|
|
134
|
+
};
|
|
135
|
+
}
|
|
@@ -20,7 +20,7 @@ export namespace JsonSchemasTransformer {
|
|
|
20
20
|
): ts.Expression => {
|
|
21
21
|
if (!props.expression.typeArguments?.length)
|
|
22
22
|
throw new TransformerError({
|
|
23
|
-
code: "typia.json.
|
|
23
|
+
code: "typia.json.schemas",
|
|
24
24
|
message: "no generic argument.",
|
|
25
25
|
});
|
|
26
26
|
|
|
@@ -39,12 +39,12 @@ export namespace JsonSchemasTransformer {
|
|
|
39
39
|
);
|
|
40
40
|
if (types.some((t) => t.isTypeParameter()))
|
|
41
41
|
throw new TransformerError({
|
|
42
|
-
code: "typia.json.
|
|
42
|
+
code: "typia.json.schemas",
|
|
43
43
|
message: "non-specified generic argument(s).",
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
// ADDITIONAL PARAMETERS
|
|
47
|
-
const version: "3.0" | "3.1" =
|
|
47
|
+
const version: "3.0" | "3.1" = getParameter<"3.0" | "3.1">({
|
|
48
48
|
checker: props.context.checker,
|
|
49
49
|
name: "Version",
|
|
50
50
|
is: (str) => str === "3.0" || str === "3.1",
|
|
@@ -83,7 +83,7 @@ export namespace JsonSchemasTransformer {
|
|
|
83
83
|
}
|
|
84
84
|
if (errors.length)
|
|
85
85
|
throw TransformerError.from({
|
|
86
|
-
code: "typia.json.
|
|
86
|
+
code: "typia.json.schemas",
|
|
87
87
|
errors,
|
|
88
88
|
});
|
|
89
89
|
return metadatas;
|
|
@@ -91,12 +91,12 @@ export namespace JsonSchemasTransformer {
|
|
|
91
91
|
analyze(true);
|
|
92
92
|
|
|
93
93
|
// APPLICATION
|
|
94
|
-
const
|
|
94
|
+
const collection: IJsonSchemaCollection<any> = JsonSchemasProgrammer.write({
|
|
95
95
|
version,
|
|
96
96
|
metadatas: analyze(false),
|
|
97
97
|
});
|
|
98
98
|
return ts.factory.createAsExpression(
|
|
99
|
-
LiteralFactory.write(
|
|
99
|
+
LiteralFactory.write(collection),
|
|
100
100
|
props.context.importer.type({
|
|
101
101
|
file: "typia",
|
|
102
102
|
name: "IJsonSchemaCollection",
|
|
@@ -109,7 +109,7 @@ export namespace JsonSchemasTransformer {
|
|
|
109
109
|
);
|
|
110
110
|
};
|
|
111
111
|
|
|
112
|
-
const
|
|
112
|
+
const getParameter =
|
|
113
113
|
<Value>(props: {
|
|
114
114
|
checker: ts.TypeChecker;
|
|
115
115
|
name: string;
|
|
@@ -127,7 +127,7 @@ export namespace JsonSchemasTransformer {
|
|
|
127
127
|
(type.getFlags() & ts.TypeFlags.BooleanLiteral) === 0
|
|
128
128
|
)
|
|
129
129
|
throw new TransformerError({
|
|
130
|
-
code: "typia.json.
|
|
130
|
+
code: "typia.json.schemas",
|
|
131
131
|
message: `generic argument "${props.name}" must be constant.`,
|
|
132
132
|
});
|
|
133
133
|
|
|
@@ -137,7 +137,7 @@ export namespace JsonSchemasTransformer {
|
|
|
137
137
|
: props.checker.typeToString(type);
|
|
138
138
|
if (typeof value !== "string" || props.is(value) === false)
|
|
139
139
|
throw new TransformerError({
|
|
140
|
-
code: "typia.json.
|
|
140
|
+
code: "typia.json.schemas",
|
|
141
141
|
message: `invalid value on generic argument "${props.name}".`,
|
|
142
142
|
});
|
|
143
143
|
return props.cast(value);
|