@typia/transform 12.0.0-dev.20260307-2 → 12.0.0-dev.20260310
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/CallExpressionTransformer.js +8 -0
- package/lib/CallExpressionTransformer.js.map +1 -1
- package/lib/CallExpressionTransformer.mjs +8 -0
- package/lib/CallExpressionTransformer.mjs.map +1 -1
- package/lib/features/json/JsonApplicationTransformer.js +3 -4
- package/lib/features/json/JsonApplicationTransformer.js.map +1 -1
- package/lib/features/json/JsonApplicationTransformer.mjs +4 -5
- package/lib/features/json/JsonApplicationTransformer.mjs.map +1 -1
- package/lib/features/json/JsonSchemaTransformer.js +2 -8
- package/lib/features/json/JsonSchemaTransformer.js.map +1 -1
- package/lib/features/json/JsonSchemaTransformer.mjs +3 -9
- package/lib/features/json/JsonSchemaTransformer.mjs.map +1 -1
- package/lib/features/json/JsonSchemasTransformer.js +2 -8
- package/lib/features/json/JsonSchemasTransformer.js.map +1 -1
- package/lib/features/json/JsonSchemasTransformer.mjs +3 -9
- package/lib/features/json/JsonSchemasTransformer.mjs.map +1 -1
- package/lib/features/llm/LlmApplicationTransformer.js +56 -20
- package/lib/features/llm/LlmApplicationTransformer.js.map +1 -1
- package/lib/features/llm/LlmApplicationTransformer.mjs +56 -20
- package/lib/features/llm/LlmApplicationTransformer.mjs.map +1 -1
- package/lib/features/llm/LlmCoerceTransformer.d.ts +5 -0
- package/lib/features/llm/LlmCoerceTransformer.js +81 -0
- package/lib/features/llm/LlmCoerceTransformer.js.map +1 -0
- package/lib/features/llm/LlmCoerceTransformer.mjs +77 -0
- package/lib/features/llm/LlmCoerceTransformer.mjs.map +1 -0
- package/lib/features/llm/LlmControllerTransformer.js +12 -10
- package/lib/features/llm/LlmControllerTransformer.js.map +1 -1
- package/lib/features/llm/LlmControllerTransformer.mjs +12 -10
- package/lib/features/llm/LlmControllerTransformer.mjs.map +1 -1
- package/lib/features/llm/LlmCreateCoerceTransformer.d.ts +5 -0
- package/lib/features/llm/LlmCreateCoerceTransformer.js +75 -0
- package/lib/features/llm/LlmCreateCoerceTransformer.js.map +1 -0
- package/lib/features/llm/LlmCreateCoerceTransformer.mjs +71 -0
- package/lib/features/llm/LlmCreateCoerceTransformer.mjs.map +1 -0
- package/lib/features/llm/LlmCreateParseTransformer.d.ts +5 -0
- package/lib/features/llm/LlmCreateParseTransformer.js +75 -0
- package/lib/features/llm/LlmCreateParseTransformer.js.map +1 -0
- package/lib/features/llm/LlmCreateParseTransformer.mjs +71 -0
- package/lib/features/llm/LlmCreateParseTransformer.mjs.map +1 -0
- package/lib/features/llm/LlmParametersTransformer.d.ts +1 -1
- package/lib/features/llm/LlmParametersTransformer.js +3 -6
- package/lib/features/llm/LlmParametersTransformer.js.map +1 -1
- package/lib/features/llm/LlmParametersTransformer.mjs +4 -7
- package/lib/features/llm/LlmParametersTransformer.mjs.map +1 -1
- package/lib/features/llm/LlmParseTransformer.d.ts +5 -0
- package/lib/features/llm/LlmParseTransformer.js +81 -0
- package/lib/features/llm/LlmParseTransformer.js.map +1 -0
- package/lib/features/llm/LlmParseTransformer.mjs +77 -0
- package/lib/features/llm/LlmParseTransformer.mjs.map +1 -0
- package/lib/features/llm/LlmSchemaTransformer.d.ts +1 -1
- package/lib/features/llm/LlmSchemaTransformer.js +10 -25
- package/lib/features/llm/LlmSchemaTransformer.js.map +1 -1
- package/lib/features/llm/LlmSchemaTransformer.mjs +11 -26
- package/lib/features/llm/LlmSchemaTransformer.mjs.map +1 -1
- package/package.json +4 -4
- package/src/CallExpressionTransformer.ts +579 -571
- package/src/FileTransformer.ts +143 -143
- package/src/ITransformProps.ts +20 -20
- package/src/ImportTransformer.ts +262 -262
- package/src/NodeTransformer.ts +25 -25
- package/src/TransformerError.ts +85 -85
- package/src/TypiaGenerator.ts +172 -172
- package/src/features/AssertTransformer.ts +24 -24
- package/src/features/CreateAssertTransformer.ts +24 -24
- package/src/features/CreateIsTransformer.ts +18 -18
- package/src/features/CreateRandomTransformer.ts +42 -42
- package/src/features/CreateValidateTransformer.ts +18 -18
- package/src/features/IsTransformer.ts +18 -18
- package/src/features/RandomTransformer.ts +40 -40
- package/src/features/ValidateTransformer.ts +18 -18
- package/src/features/functional/FunctionalGenericTransformer.ts +55 -55
- package/src/features/http/CreateHttpAssertFormDataTransformer.ts +13 -13
- package/src/features/http/CreateHttpAssertHeadersTransformer.ts +13 -13
- package/src/features/http/CreateHttpAssertQueryTransformer.ts +13 -13
- package/src/features/http/CreateHttpFormDataTransformer.ts +13 -13
- package/src/features/http/CreateHttpHeadersTransformer.ts +13 -13
- package/src/features/http/CreateHttpIsFormDataTransformer.ts +13 -13
- package/src/features/http/CreateHttpIsHeadersTransformer.ts +13 -13
- package/src/features/http/CreateHttpIsQueryTransformer.ts +13 -13
- package/src/features/http/CreateHttpParameterTransformer.ts +13 -13
- package/src/features/http/CreateHttpQueryTransformer.ts +13 -13
- package/src/features/http/CreateHttpValidateFormDataTransformer.ts +13 -13
- package/src/features/http/CreateHttpValidateHeadersTransformer.ts +13 -13
- package/src/features/http/CreateHttpValidateQueryTransformer.ts +13 -13
- package/src/features/http/HttpAssertFormDataTransformer.ts +13 -13
- package/src/features/http/HttpAssertHeadersTransformer.ts +13 -13
- package/src/features/http/HttpAssertQueryTransformer.ts +13 -13
- package/src/features/http/HttpFormDataTransformer.ts +13 -13
- package/src/features/http/HttpHeadersTransformer.ts +13 -13
- package/src/features/http/HttpIsFormDataTransformer.ts +13 -13
- package/src/features/http/HttpIsHeadersTransformer.ts +13 -13
- package/src/features/http/HttpIsQueryTransformer.ts +13 -13
- package/src/features/http/HttpParameterTransformer.ts +13 -13
- package/src/features/http/HttpQueryTransformer.ts +13 -13
- package/src/features/http/HttpValidateFormDataTransformer.ts +13 -13
- package/src/features/http/HttpValidateHeadersTransformer.ts +13 -13
- package/src/features/http/HttpValidateQueryTransformer.ts +13 -13
- package/src/features/json/JsonApplicationTransformer.ts +99 -102
- package/src/features/json/JsonAssertParseTransformer.ts +13 -13
- package/src/features/json/JsonAssertStringifyTransformer.ts +13 -13
- package/src/features/json/JsonCreateAssertParseTransformer.ts +13 -13
- package/src/features/json/JsonCreateAssertStringifyTransformer.ts +13 -13
- package/src/features/json/JsonCreateIsParseTransformer.ts +13 -13
- package/src/features/json/JsonCreateIsStringifyTransformer.ts +13 -13
- package/src/features/json/JsonCreateStringifyTransformer.ts +13 -13
- package/src/features/json/JsonCreateValidateParseTransformer.ts +13 -13
- package/src/features/json/JsonCreateValidateStringifyProgrammer.ts +13 -13
- package/src/features/json/JsonIsParseTransformer.ts +13 -13
- package/src/features/json/JsonIsStringifyTransformer.ts +13 -13
- package/src/features/json/JsonSchemaTransformer.ts +120 -132
- package/src/features/json/JsonSchemasTransformer.ts +130 -142
- package/src/features/json/JsonStringifyTransformer.ts +13 -13
- package/src/features/json/JsonValidateParseTransformer.ts +13 -13
- package/src/features/json/JsonValidateStringifyTransformer.ts +13 -13
- package/src/features/llm/LlmApplicationTransformer.ts +224 -184
- package/src/features/llm/LlmCoerceTransformer.ts +95 -0
- package/src/features/llm/LlmControllerTransformer.ts +81 -76
- package/src/features/llm/LlmCreateCoerceTransformer.ts +84 -0
- package/src/features/llm/LlmCreateParseTransformer.ts +84 -0
- package/src/features/llm/LlmParametersTransformer.ts +76 -88
- package/src/features/llm/LlmParseTransformer.ts +95 -0
- package/src/features/llm/LlmSchemaTransformer.ts +87 -133
- package/src/features/misc/MiscAssertCloneTransformer.ts +13 -13
- package/src/features/misc/MiscAssertPruneTransformer.ts +13 -13
- package/src/features/misc/MiscCloneTransformer.ts +13 -13
- package/src/features/misc/MiscCreateAssertCloneTransformer.ts +13 -13
- package/src/features/misc/MiscCreateAssertPruneTransformer.ts +13 -13
- package/src/features/misc/MiscCreateCloneTransformer.ts +13 -13
- package/src/features/misc/MiscCreateIsCloneTransformer.ts +13 -13
- package/src/features/misc/MiscCreateIsPruneTransformer.ts +13 -13
- package/src/features/misc/MiscCreatePruneTransformer.ts +13 -13
- package/src/features/misc/MiscCreateValidateCloneTransformer.ts +13 -13
- package/src/features/misc/MiscCreateValidatePruneTransformer.ts +13 -13
- package/src/features/misc/MiscIsCloneTransformer.ts +13 -13
- package/src/features/misc/MiscIsPruneTransformer.ts +13 -13
- package/src/features/misc/MiscLiteralsTransformer.ts +34 -34
- package/src/features/misc/MiscPruneTransformer.ts +13 -13
- package/src/features/misc/MiscValidateCloneTransformer.ts +13 -13
- package/src/features/misc/MiscValidatePruneTransformer.ts +13 -13
- package/src/features/notations/NotationAssertGeneralTransformer.ts +19 -19
- package/src/features/notations/NotationCreateAssertGeneralTransformer.ts +19 -19
- package/src/features/notations/NotationCreateGeneralTransformer.ts +19 -19
- package/src/features/notations/NotationCreateIsGeneralTransformer.ts +19 -19
- package/src/features/notations/NotationCreateValidateGeneralTransformer.ts +19 -19
- package/src/features/notations/NotationGeneralTransformer.ts +18 -18
- package/src/features/notations/NotationIsGeneralTransformer.ts +19 -19
- package/src/features/notations/NotationValidateGeneralTransformer.ts +19 -19
- package/src/features/protobuf/ProtobufAssertDecodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufAssertEncodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufCreateAssertDecodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufCreateAssertEncodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufCreateDecodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufCreateEncodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufCreateIsDecodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufCreateIsEncodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufCreateValidateDecodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufCreateValidateEncodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufDecodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufEncodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufIsDecodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufIsEncodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufMessageTransformer.ts +34 -34
- package/src/features/protobuf/ProtobufValidateDecodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufValidateEncodeTransformer.ts +13 -13
- package/src/features/reflect/ReflectMetadataTransformer.ts +69 -69
- package/src/features/reflect/ReflectNameTransformer.ts +81 -81
- package/src/features/reflect/ReflectSchemaTransformer.ts +65 -65
- package/src/features/reflect/ReflectSchemasTransformer.ts +69 -69
- package/src/index.ts +7 -7
- package/src/internal/GenericTransformer.ts +101 -101
- package/src/transform.ts +68 -68
package/src/TransformerError.ts
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
import { MetadataFactory, MetadataObjectType } from "@typia/core";
|
|
2
|
-
import { NamingConvention } from "@typia/utils";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Error thrown during typia transformation.
|
|
6
|
-
*
|
|
7
|
-
* `TransformerError` is thrown when `typia.*<T>()` receives unsupported types
|
|
8
|
-
* or invalid configurations at compile time. The error message details which
|
|
9
|
-
* types failed and why.
|
|
10
|
-
*
|
|
11
|
-
* Common causes:
|
|
12
|
-
*
|
|
13
|
-
* - Tuples in LLM schema (not supported by most LLMs)
|
|
14
|
-
* - Recursive types without `$ref` support
|
|
15
|
-
* - `any` types without explicit handling
|
|
16
|
-
* - Native classes not serializable to JSON
|
|
17
|
-
*
|
|
18
|
-
* Use {@link from} to create from {@link MetadataFactory.IError} instances.
|
|
19
|
-
*
|
|
20
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
21
|
-
*/
|
|
22
|
-
export class TransformerError extends Error {
|
|
23
|
-
/** Error code identifying the error type. */
|
|
24
|
-
public readonly code: string;
|
|
25
|
-
|
|
26
|
-
public constructor(props: TransformerError.IProps) {
|
|
27
|
-
super(props.message);
|
|
28
|
-
this.code = props.code;
|
|
29
|
-
|
|
30
|
-
// INHERITANCE POLYFILL
|
|
31
|
-
const proto = new.target.prototype;
|
|
32
|
-
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
|
|
33
|
-
else (this as any).__proto__ = proto;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
export namespace TransformerError {
|
|
37
|
-
/** Constructor properties for TransformerError. */
|
|
38
|
-
export interface IProps {
|
|
39
|
-
/** Error code identifying the error type. */
|
|
40
|
-
code: string;
|
|
41
|
-
|
|
42
|
-
/** Human-readable error message. */
|
|
43
|
-
message: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Create error from metadata factory errors.
|
|
48
|
-
*
|
|
49
|
-
* Formats multiple type errors into a single TransformerError.
|
|
50
|
-
*/
|
|
51
|
-
export const from = (props: {
|
|
52
|
-
code: string;
|
|
53
|
-
errors: MetadataFactory.IError[];
|
|
54
|
-
}): TransformerError => {
|
|
55
|
-
const body: string = props.errors
|
|
56
|
-
.map((e) => {
|
|
57
|
-
const subject: string =
|
|
58
|
-
e.explore.object === null
|
|
59
|
-
? ""
|
|
60
|
-
: join(e.explore.object)(e.explore.property);
|
|
61
|
-
const middle: string = e.explore.parameter
|
|
62
|
-
? `(parameter: ${JSON.stringify(e.explore.parameter)})`
|
|
63
|
-
: e.explore.output
|
|
64
|
-
? "(return type)"
|
|
65
|
-
: "";
|
|
66
|
-
const type: string = `${subject.length ? `${subject}: ` : ""}${e.name}`;
|
|
67
|
-
return `- ${type}${middle}\n${e.messages
|
|
68
|
-
.map((msg) => ` - ${msg}`)
|
|
69
|
-
.join("\n")}`;
|
|
70
|
-
})
|
|
71
|
-
.join("\n\n");
|
|
72
|
-
return new TransformerError({
|
|
73
|
-
code: props.code,
|
|
74
|
-
message: `unsupported type detected\n\n${body}`,
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const join =
|
|
79
|
-
(object: MetadataObjectType) => (key: string | object | null) => {
|
|
80
|
-
if (key === null) return object.name;
|
|
81
|
-
else if (typeof key === "object") return `${object.name}[key]`;
|
|
82
|
-
else if (NamingConvention.variable(key)) return `${object.name}.${key}`;
|
|
83
|
-
return `${object.name}[${JSON.stringify(key)}]`;
|
|
84
|
-
};
|
|
85
|
-
}
|
|
1
|
+
import { MetadataFactory, MetadataObjectType } from "@typia/core";
|
|
2
|
+
import { NamingConvention } from "@typia/utils";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown during typia transformation.
|
|
6
|
+
*
|
|
7
|
+
* `TransformerError` is thrown when `typia.*<T>()` receives unsupported types
|
|
8
|
+
* or invalid configurations at compile time. The error message details which
|
|
9
|
+
* types failed and why.
|
|
10
|
+
*
|
|
11
|
+
* Common causes:
|
|
12
|
+
*
|
|
13
|
+
* - Tuples in LLM schema (not supported by most LLMs)
|
|
14
|
+
* - Recursive types without `$ref` support
|
|
15
|
+
* - `any` types without explicit handling
|
|
16
|
+
* - Native classes not serializable to JSON
|
|
17
|
+
*
|
|
18
|
+
* Use {@link from} to create from {@link MetadataFactory.IError} instances.
|
|
19
|
+
*
|
|
20
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
21
|
+
*/
|
|
22
|
+
export class TransformerError extends Error {
|
|
23
|
+
/** Error code identifying the error type. */
|
|
24
|
+
public readonly code: string;
|
|
25
|
+
|
|
26
|
+
public constructor(props: TransformerError.IProps) {
|
|
27
|
+
super(props.message);
|
|
28
|
+
this.code = props.code;
|
|
29
|
+
|
|
30
|
+
// INHERITANCE POLYFILL
|
|
31
|
+
const proto = new.target.prototype;
|
|
32
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
|
|
33
|
+
else (this as any).__proto__ = proto;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export namespace TransformerError {
|
|
37
|
+
/** Constructor properties for TransformerError. */
|
|
38
|
+
export interface IProps {
|
|
39
|
+
/** Error code identifying the error type. */
|
|
40
|
+
code: string;
|
|
41
|
+
|
|
42
|
+
/** Human-readable error message. */
|
|
43
|
+
message: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Create error from metadata factory errors.
|
|
48
|
+
*
|
|
49
|
+
* Formats multiple type errors into a single TransformerError.
|
|
50
|
+
*/
|
|
51
|
+
export const from = (props: {
|
|
52
|
+
code: string;
|
|
53
|
+
errors: MetadataFactory.IError[];
|
|
54
|
+
}): TransformerError => {
|
|
55
|
+
const body: string = props.errors
|
|
56
|
+
.map((e) => {
|
|
57
|
+
const subject: string =
|
|
58
|
+
e.explore.object === null
|
|
59
|
+
? ""
|
|
60
|
+
: join(e.explore.object)(e.explore.property);
|
|
61
|
+
const middle: string = e.explore.parameter
|
|
62
|
+
? `(parameter: ${JSON.stringify(e.explore.parameter)})`
|
|
63
|
+
: e.explore.output
|
|
64
|
+
? "(return type)"
|
|
65
|
+
: "";
|
|
66
|
+
const type: string = `${subject.length ? `${subject}: ` : ""}${e.name}`;
|
|
67
|
+
return `- ${type}${middle}\n${e.messages
|
|
68
|
+
.map((msg) => ` - ${msg}`)
|
|
69
|
+
.join("\n")}`;
|
|
70
|
+
})
|
|
71
|
+
.join("\n\n");
|
|
72
|
+
return new TransformerError({
|
|
73
|
+
code: props.code,
|
|
74
|
+
message: `unsupported type detected\n\n${body}`,
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const join =
|
|
79
|
+
(object: MetadataObjectType) => (key: string | object | null) => {
|
|
80
|
+
if (key === null) return object.name;
|
|
81
|
+
else if (typeof key === "object") return `${object.name}[key]`;
|
|
82
|
+
else if (NamingConvention.variable(key)) return `${object.name}.${key}`;
|
|
83
|
+
return `${object.name}[${JSON.stringify(key)}]`;
|
|
84
|
+
};
|
|
85
|
+
}
|
package/src/TypiaGenerator.ts
CHANGED
|
@@ -1,172 +1,172 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import ts from "typescript";
|
|
4
|
-
|
|
5
|
-
import { ImportTransformer } from "./ImportTransformer";
|
|
6
|
-
import { transform } from "./transform";
|
|
7
|
-
|
|
8
|
-
export namespace TypiaGenerator {
|
|
9
|
-
export interface ILocation {
|
|
10
|
-
input: string;
|
|
11
|
-
output: string;
|
|
12
|
-
project: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const build = async (
|
|
16
|
-
location: TypiaGenerator.ILocation,
|
|
17
|
-
): Promise<void> => {
|
|
18
|
-
location.input = path.resolve(location.input);
|
|
19
|
-
location.output = path.resolve(location.output);
|
|
20
|
-
|
|
21
|
-
if ((await is_directory(location.input)) === false)
|
|
22
|
-
throw new URIError(
|
|
23
|
-
"Error on TypiaGenerator.generate(): input path is not a directory.",
|
|
24
|
-
);
|
|
25
|
-
else if (fs.existsSync(location.output) === false)
|
|
26
|
-
await fs.promises.mkdir(location.output, { recursive: true });
|
|
27
|
-
else if ((await is_directory(location.output)) === false) {
|
|
28
|
-
const parent: string = path.join(location.output, "..");
|
|
29
|
-
if ((await is_directory(parent)) === false)
|
|
30
|
-
throw new URIError(
|
|
31
|
-
"Error on TypiaGenerator.generate(): output path is not a directory.",
|
|
32
|
-
);
|
|
33
|
-
await fs.promises.mkdir(location.output);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// CREATE PROGRAM
|
|
37
|
-
const { options: compilerOptions } = ts.parseJsonConfigFileContent(
|
|
38
|
-
ts.readConfigFile(location.project, ts.sys.readFile).config,
|
|
39
|
-
{
|
|
40
|
-
fileExists: ts.sys.fileExists,
|
|
41
|
-
readFile: ts.sys.readFile,
|
|
42
|
-
readDirectory: ts.sys.readDirectory,
|
|
43
|
-
useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
|
|
44
|
-
},
|
|
45
|
-
path.dirname(location.project),
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
const program: ts.Program = ts.createProgram(
|
|
49
|
-
await (async () => {
|
|
50
|
-
const container: string[] = [];
|
|
51
|
-
await gather({
|
|
52
|
-
location,
|
|
53
|
-
container,
|
|
54
|
-
from: location.input,
|
|
55
|
-
to: location.output,
|
|
56
|
-
});
|
|
57
|
-
return container;
|
|
58
|
-
})(),
|
|
59
|
-
compilerOptions,
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
// DO TRANSFORM
|
|
63
|
-
const diagnostics: ts.Diagnostic[] = [];
|
|
64
|
-
const result: ts.TransformationResult<ts.SourceFile> = ts.transform(
|
|
65
|
-
program
|
|
66
|
-
.getSourceFiles()
|
|
67
|
-
.filter(
|
|
68
|
-
(file) =>
|
|
69
|
-
!file.isDeclarationFile &&
|
|
70
|
-
path.resolve(file.fileName).indexOf(location.input) !== -1,
|
|
71
|
-
),
|
|
72
|
-
[
|
|
73
|
-
ImportTransformer.transform({
|
|
74
|
-
from: location.input,
|
|
75
|
-
to: location.output,
|
|
76
|
-
}),
|
|
77
|
-
transform(
|
|
78
|
-
program,
|
|
79
|
-
((compilerOptions.plugins as any[]) ?? []).find(
|
|
80
|
-
(p: any) => p.transform === "typia/lib/transform",
|
|
81
|
-
) ?? {},
|
|
82
|
-
{
|
|
83
|
-
addDiagnostic: (diag) => diagnostics.push(diag),
|
|
84
|
-
},
|
|
85
|
-
),
|
|
86
|
-
],
|
|
87
|
-
program.getCompilerOptions(),
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
// TRACE ERRORS
|
|
91
|
-
for (const diag of diagnostics) {
|
|
92
|
-
const file: string = diag.file
|
|
93
|
-
? path.relative(diag.file.fileName, process.cwd())
|
|
94
|
-
: "(unknown file)";
|
|
95
|
-
const category: string =
|
|
96
|
-
diag.category === ts.DiagnosticCategory.Warning
|
|
97
|
-
? "warning"
|
|
98
|
-
: diag.category === ts.DiagnosticCategory.Error
|
|
99
|
-
? "error"
|
|
100
|
-
: diag.category === ts.DiagnosticCategory.Suggestion
|
|
101
|
-
? "suggestion"
|
|
102
|
-
: diag.category === ts.DiagnosticCategory.Message
|
|
103
|
-
? "message"
|
|
104
|
-
: "unknown";
|
|
105
|
-
const [line, pos] = diag.file
|
|
106
|
-
? (() => {
|
|
107
|
-
const lines: string[] = diag
|
|
108
|
-
.file!.text.substring(0, diag.start)
|
|
109
|
-
.split("\n");
|
|
110
|
-
if (lines.length === 0) return [0, 0];
|
|
111
|
-
return [lines.length, lines.at(-1)!.length + 1];
|
|
112
|
-
})()
|
|
113
|
-
: [0, 0];
|
|
114
|
-
console.error(
|
|
115
|
-
`${file}:${line}:${pos} - ${category} TS${diag.code}: ${diag.messageText}`,
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
if (diagnostics.length) process.exit(-1);
|
|
119
|
-
|
|
120
|
-
// ARCHIVE TRANSFORMED FILES
|
|
121
|
-
const printer: ts.Printer = ts.createPrinter({
|
|
122
|
-
newLine: ts.NewLineKind.LineFeed,
|
|
123
|
-
});
|
|
124
|
-
for (const file of result.transformed) {
|
|
125
|
-
const to: string = path
|
|
126
|
-
.resolve(file.fileName)
|
|
127
|
-
.replace(location.input, location.output);
|
|
128
|
-
|
|
129
|
-
const content: string = printer.printFile(file);
|
|
130
|
-
await fs.promises.writeFile(to, content, "utf8");
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
const is_directory = async (current: string): Promise<boolean> => {
|
|
135
|
-
const stat: fs.Stats = await fs.promises.stat(current);
|
|
136
|
-
return stat.isDirectory();
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
const gather = async (props: {
|
|
140
|
-
location: ILocation;
|
|
141
|
-
container: string[];
|
|
142
|
-
from: string;
|
|
143
|
-
to: string;
|
|
144
|
-
}) => {
|
|
145
|
-
if (props.from === props.location.output) return;
|
|
146
|
-
else if (fs.existsSync(props.to) === false)
|
|
147
|
-
await fs.promises.mkdir(props.to);
|
|
148
|
-
|
|
149
|
-
for (const file of await fs.promises.readdir(props.from)) {
|
|
150
|
-
const next: string = path.join(props.from, file);
|
|
151
|
-
const stat: fs.Stats = await fs.promises.stat(next);
|
|
152
|
-
|
|
153
|
-
if (stat.isDirectory()) {
|
|
154
|
-
await gather({
|
|
155
|
-
location: props.location,
|
|
156
|
-
container: props.container,
|
|
157
|
-
from: next,
|
|
158
|
-
to: path.join(props.to, file),
|
|
159
|
-
});
|
|
160
|
-
continue;
|
|
161
|
-
} else if (is_supported_extension(file)) props.container.push(next);
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
const is_supported_extension = (filename: string): boolean => {
|
|
166
|
-
// avoid using look-behind assertion as it is not marked as Baseline Widely Available
|
|
167
|
-
return TS_PATTERN.test(filename) && !DTS_PATTERN.test(filename);
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const TS_PATTERN = /\.[cm]?tsx?$/;
|
|
172
|
-
const DTS_PATTERN = /\.d\.[cm]?tsx?$/;
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
|
|
5
|
+
import { ImportTransformer } from "./ImportTransformer";
|
|
6
|
+
import { transform } from "./transform";
|
|
7
|
+
|
|
8
|
+
export namespace TypiaGenerator {
|
|
9
|
+
export interface ILocation {
|
|
10
|
+
input: string;
|
|
11
|
+
output: string;
|
|
12
|
+
project: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const build = async (
|
|
16
|
+
location: TypiaGenerator.ILocation,
|
|
17
|
+
): Promise<void> => {
|
|
18
|
+
location.input = path.resolve(location.input);
|
|
19
|
+
location.output = path.resolve(location.output);
|
|
20
|
+
|
|
21
|
+
if ((await is_directory(location.input)) === false)
|
|
22
|
+
throw new URIError(
|
|
23
|
+
"Error on TypiaGenerator.generate(): input path is not a directory.",
|
|
24
|
+
);
|
|
25
|
+
else if (fs.existsSync(location.output) === false)
|
|
26
|
+
await fs.promises.mkdir(location.output, { recursive: true });
|
|
27
|
+
else if ((await is_directory(location.output)) === false) {
|
|
28
|
+
const parent: string = path.join(location.output, "..");
|
|
29
|
+
if ((await is_directory(parent)) === false)
|
|
30
|
+
throw new URIError(
|
|
31
|
+
"Error on TypiaGenerator.generate(): output path is not a directory.",
|
|
32
|
+
);
|
|
33
|
+
await fs.promises.mkdir(location.output);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// CREATE PROGRAM
|
|
37
|
+
const { options: compilerOptions } = ts.parseJsonConfigFileContent(
|
|
38
|
+
ts.readConfigFile(location.project, ts.sys.readFile).config,
|
|
39
|
+
{
|
|
40
|
+
fileExists: ts.sys.fileExists,
|
|
41
|
+
readFile: ts.sys.readFile,
|
|
42
|
+
readDirectory: ts.sys.readDirectory,
|
|
43
|
+
useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
|
|
44
|
+
},
|
|
45
|
+
path.dirname(location.project),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const program: ts.Program = ts.createProgram(
|
|
49
|
+
await (async () => {
|
|
50
|
+
const container: string[] = [];
|
|
51
|
+
await gather({
|
|
52
|
+
location,
|
|
53
|
+
container,
|
|
54
|
+
from: location.input,
|
|
55
|
+
to: location.output,
|
|
56
|
+
});
|
|
57
|
+
return container;
|
|
58
|
+
})(),
|
|
59
|
+
compilerOptions,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
// DO TRANSFORM
|
|
63
|
+
const diagnostics: ts.Diagnostic[] = [];
|
|
64
|
+
const result: ts.TransformationResult<ts.SourceFile> = ts.transform(
|
|
65
|
+
program
|
|
66
|
+
.getSourceFiles()
|
|
67
|
+
.filter(
|
|
68
|
+
(file) =>
|
|
69
|
+
!file.isDeclarationFile &&
|
|
70
|
+
path.resolve(file.fileName).indexOf(location.input) !== -1,
|
|
71
|
+
),
|
|
72
|
+
[
|
|
73
|
+
ImportTransformer.transform({
|
|
74
|
+
from: location.input,
|
|
75
|
+
to: location.output,
|
|
76
|
+
}),
|
|
77
|
+
transform(
|
|
78
|
+
program,
|
|
79
|
+
((compilerOptions.plugins as any[]) ?? []).find(
|
|
80
|
+
(p: any) => p.transform === "typia/lib/transform",
|
|
81
|
+
) ?? {},
|
|
82
|
+
{
|
|
83
|
+
addDiagnostic: (diag) => diagnostics.push(diag),
|
|
84
|
+
},
|
|
85
|
+
),
|
|
86
|
+
],
|
|
87
|
+
program.getCompilerOptions(),
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
// TRACE ERRORS
|
|
91
|
+
for (const diag of diagnostics) {
|
|
92
|
+
const file: string = diag.file
|
|
93
|
+
? path.relative(diag.file.fileName, process.cwd())
|
|
94
|
+
: "(unknown file)";
|
|
95
|
+
const category: string =
|
|
96
|
+
diag.category === ts.DiagnosticCategory.Warning
|
|
97
|
+
? "warning"
|
|
98
|
+
: diag.category === ts.DiagnosticCategory.Error
|
|
99
|
+
? "error"
|
|
100
|
+
: diag.category === ts.DiagnosticCategory.Suggestion
|
|
101
|
+
? "suggestion"
|
|
102
|
+
: diag.category === ts.DiagnosticCategory.Message
|
|
103
|
+
? "message"
|
|
104
|
+
: "unknown";
|
|
105
|
+
const [line, pos] = diag.file
|
|
106
|
+
? (() => {
|
|
107
|
+
const lines: string[] = diag
|
|
108
|
+
.file!.text.substring(0, diag.start)
|
|
109
|
+
.split("\n");
|
|
110
|
+
if (lines.length === 0) return [0, 0];
|
|
111
|
+
return [lines.length, lines.at(-1)!.length + 1];
|
|
112
|
+
})()
|
|
113
|
+
: [0, 0];
|
|
114
|
+
console.error(
|
|
115
|
+
`${file}:${line}:${pos} - ${category} TS${diag.code}: ${diag.messageText}`,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
if (diagnostics.length) process.exit(-1);
|
|
119
|
+
|
|
120
|
+
// ARCHIVE TRANSFORMED FILES
|
|
121
|
+
const printer: ts.Printer = ts.createPrinter({
|
|
122
|
+
newLine: ts.NewLineKind.LineFeed,
|
|
123
|
+
});
|
|
124
|
+
for (const file of result.transformed) {
|
|
125
|
+
const to: string = path
|
|
126
|
+
.resolve(file.fileName)
|
|
127
|
+
.replace(location.input, location.output);
|
|
128
|
+
|
|
129
|
+
const content: string = printer.printFile(file);
|
|
130
|
+
await fs.promises.writeFile(to, content, "utf8");
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const is_directory = async (current: string): Promise<boolean> => {
|
|
135
|
+
const stat: fs.Stats = await fs.promises.stat(current);
|
|
136
|
+
return stat.isDirectory();
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const gather = async (props: {
|
|
140
|
+
location: ILocation;
|
|
141
|
+
container: string[];
|
|
142
|
+
from: string;
|
|
143
|
+
to: string;
|
|
144
|
+
}) => {
|
|
145
|
+
if (props.from === props.location.output) return;
|
|
146
|
+
else if (fs.existsSync(props.to) === false)
|
|
147
|
+
await fs.promises.mkdir(props.to);
|
|
148
|
+
|
|
149
|
+
for (const file of await fs.promises.readdir(props.from)) {
|
|
150
|
+
const next: string = path.join(props.from, file);
|
|
151
|
+
const stat: fs.Stats = await fs.promises.stat(next);
|
|
152
|
+
|
|
153
|
+
if (stat.isDirectory()) {
|
|
154
|
+
await gather({
|
|
155
|
+
location: props.location,
|
|
156
|
+
container: props.container,
|
|
157
|
+
from: next,
|
|
158
|
+
to: path.join(props.to, file),
|
|
159
|
+
});
|
|
160
|
+
continue;
|
|
161
|
+
} else if (is_supported_extension(file)) props.container.push(next);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const is_supported_extension = (filename: string): boolean => {
|
|
166
|
+
// avoid using look-behind assertion as it is not marked as Baseline Widely Available
|
|
167
|
+
return TS_PATTERN.test(filename) && !DTS_PATTERN.test(filename);
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const TS_PATTERN = /\.[cm]?tsx?$/;
|
|
172
|
+
const DTS_PATTERN = /\.d\.[cm]?tsx?$/;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { AssertProgrammer } from "@typia/core";
|
|
2
|
-
|
|
3
|
-
import { ITransformProps } from "../ITransformProps";
|
|
4
|
-
import { GenericTransformer } from "../internal/GenericTransformer";
|
|
5
|
-
|
|
6
|
-
export namespace AssertTransformer {
|
|
7
|
-
export const transform =
|
|
8
|
-
(config: AssertProgrammer.IConfig) => (props: ITransformProps) =>
|
|
9
|
-
GenericTransformer.scalar({
|
|
10
|
-
...props,
|
|
11
|
-
method: config.equals
|
|
12
|
-
? config.guard
|
|
13
|
-
? "assertGuardEquals"
|
|
14
|
-
: "assertEquals"
|
|
15
|
-
: config.guard
|
|
16
|
-
? "assertGuard"
|
|
17
|
-
: "assert",
|
|
18
|
-
write: (x) =>
|
|
19
|
-
AssertProgrammer.write({
|
|
20
|
-
...x,
|
|
21
|
-
config,
|
|
22
|
-
}),
|
|
23
|
-
});
|
|
24
|
-
}
|
|
1
|
+
import { AssertProgrammer } from "@typia/core";
|
|
2
|
+
|
|
3
|
+
import { ITransformProps } from "../ITransformProps";
|
|
4
|
+
import { GenericTransformer } from "../internal/GenericTransformer";
|
|
5
|
+
|
|
6
|
+
export namespace AssertTransformer {
|
|
7
|
+
export const transform =
|
|
8
|
+
(config: AssertProgrammer.IConfig) => (props: ITransformProps) =>
|
|
9
|
+
GenericTransformer.scalar({
|
|
10
|
+
...props,
|
|
11
|
+
method: config.equals
|
|
12
|
+
? config.guard
|
|
13
|
+
? "assertGuardEquals"
|
|
14
|
+
: "assertEquals"
|
|
15
|
+
: config.guard
|
|
16
|
+
? "assertGuard"
|
|
17
|
+
: "assert",
|
|
18
|
+
write: (x) =>
|
|
19
|
+
AssertProgrammer.write({
|
|
20
|
+
...x,
|
|
21
|
+
config,
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { AssertProgrammer } from "@typia/core";
|
|
2
|
-
|
|
3
|
-
import { ITransformProps } from "../ITransformProps";
|
|
4
|
-
import { GenericTransformer } from "../internal/GenericTransformer";
|
|
5
|
-
|
|
6
|
-
export namespace CreateAssertTransformer {
|
|
7
|
-
export const transform =
|
|
8
|
-
(config: AssertProgrammer.IConfig) => (props: ITransformProps) =>
|
|
9
|
-
GenericTransformer.factory({
|
|
10
|
-
...props,
|
|
11
|
-
method: config.equals
|
|
12
|
-
? config.guard
|
|
13
|
-
? "assertGuardEquals"
|
|
14
|
-
: "assertEquals"
|
|
15
|
-
: config.guard
|
|
16
|
-
? "assertGuard"
|
|
17
|
-
: "assert",
|
|
18
|
-
write: (x) =>
|
|
19
|
-
AssertProgrammer.write({
|
|
20
|
-
...x,
|
|
21
|
-
config,
|
|
22
|
-
}),
|
|
23
|
-
});
|
|
24
|
-
}
|
|
1
|
+
import { AssertProgrammer } from "@typia/core";
|
|
2
|
+
|
|
3
|
+
import { ITransformProps } from "../ITransformProps";
|
|
4
|
+
import { GenericTransformer } from "../internal/GenericTransformer";
|
|
5
|
+
|
|
6
|
+
export namespace CreateAssertTransformer {
|
|
7
|
+
export const transform =
|
|
8
|
+
(config: AssertProgrammer.IConfig) => (props: ITransformProps) =>
|
|
9
|
+
GenericTransformer.factory({
|
|
10
|
+
...props,
|
|
11
|
+
method: config.equals
|
|
12
|
+
? config.guard
|
|
13
|
+
? "assertGuardEquals"
|
|
14
|
+
: "assertEquals"
|
|
15
|
+
: config.guard
|
|
16
|
+
? "assertGuard"
|
|
17
|
+
: "assert",
|
|
18
|
+
write: (x) =>
|
|
19
|
+
AssertProgrammer.write({
|
|
20
|
+
...x,
|
|
21
|
+
config,
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { IsProgrammer } from "@typia/core";
|
|
2
|
-
|
|
3
|
-
import { ITransformProps } from "../ITransformProps";
|
|
4
|
-
import { GenericTransformer } from "../internal/GenericTransformer";
|
|
5
|
-
|
|
6
|
-
export namespace CreateIsTransformer {
|
|
7
|
-
export const transform =
|
|
8
|
-
(config: IsProgrammer.IConfig) => (props: ITransformProps) =>
|
|
9
|
-
GenericTransformer.factory({
|
|
10
|
-
...props,
|
|
11
|
-
method: config.equals ? "equals" : "is",
|
|
12
|
-
write: (x) =>
|
|
13
|
-
IsProgrammer.write({
|
|
14
|
-
...x,
|
|
15
|
-
config,
|
|
16
|
-
}),
|
|
17
|
-
});
|
|
18
|
-
}
|
|
1
|
+
import { IsProgrammer } from "@typia/core";
|
|
2
|
+
|
|
3
|
+
import { ITransformProps } from "../ITransformProps";
|
|
4
|
+
import { GenericTransformer } from "../internal/GenericTransformer";
|
|
5
|
+
|
|
6
|
+
export namespace CreateIsTransformer {
|
|
7
|
+
export const transform =
|
|
8
|
+
(config: IsProgrammer.IConfig) => (props: ITransformProps) =>
|
|
9
|
+
GenericTransformer.factory({
|
|
10
|
+
...props,
|
|
11
|
+
method: config.equals ? "equals" : "is",
|
|
12
|
+
write: (x) =>
|
|
13
|
+
IsProgrammer.write({
|
|
14
|
+
...x,
|
|
15
|
+
config,
|
|
16
|
+
}),
|
|
17
|
+
});
|
|
18
|
+
}
|