typia 5.2.5 → 5.2.6
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/factories/ExpressionFactory.d.ts +1 -0
- package/lib/factories/ExpressionFactory.js +5 -0
- package/lib/factories/ExpressionFactory.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.js +4 -4
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/RandomProgrammer.js +16 -18
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +2 -1
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/lib/programmers/helpers/RandomJoiner.js +4 -6
- package/lib/programmers/helpers/RandomJoiner.js.map +1 -1
- package/lib/programmers/helpers/RandomRanger.js +3 -2
- package/lib/programmers/helpers/RandomRanger.js.map +1 -1
- package/lib/programmers/http/HttpHeadersProgrammer.js +1 -1
- package/lib/programmers/http/HttpHeadersProgrammer.js.map +1 -1
- package/lib/programmers/internal/check_dynamic_properties.js +4 -3
- package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
- package/lib/programmers/internal/check_union_array_like.js +3 -2
- package/lib/programmers/internal/check_union_array_like.js.map +1 -1
- package/lib/programmers/json/JsonStringifyProgrammer.js +1 -3
- package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js +1 -3
- package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscLiteralsProgrammer.js +1 -1
- package/lib/programmers/misc/MiscLiteralsProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscPruneProgrammer.js +1 -3
- package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js +1 -3
- package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +6 -6
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js +2 -2
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js.map +1 -1
- package/package.json +1 -1
- package/src/Primitive.ts +135 -135
- package/src/executable/TypiaSetupWizard.ts +142 -142
- package/src/executable/setup/CommandExecutor.ts +8 -8
- package/src/factories/ExpressionFactory.ts +8 -0
- package/src/factories/JsonMetadataFactory.ts +50 -50
- package/src/factories/MetadataCollection.ts +282 -282
- package/src/factories/internal/metadata/emplace_metadata_object.ts +178 -178
- package/src/functional/$stoll.ts +8 -8
- package/src/functional/Namespace.ts +168 -168
- package/src/programmers/AssertProgrammer.ts +322 -322
- package/src/programmers/CheckerProgrammer.ts +4 -4
- package/src/programmers/IsProgrammer.ts +258 -258
- package/src/programmers/RandomProgrammer.ts +16 -17
- package/src/programmers/ValidateProgrammer.ts +350 -349
- package/src/programmers/helpers/AtomicPredicator.ts +31 -31
- package/src/programmers/helpers/RandomJoiner.ts +4 -6
- package/src/programmers/helpers/RandomRanger.ts +4 -2
- package/src/programmers/http/HttpHeadersProgrammer.ts +1 -1
- package/src/programmers/internal/check_dynamic_key.ts +178 -178
- package/src/programmers/internal/check_dynamic_properties.ts +202 -201
- package/src/programmers/internal/check_object.ts +62 -62
- package/src/programmers/internal/check_union_array_like.ts +4 -3
- package/src/programmers/json/JsonStringifyProgrammer.ts +960 -964
- package/src/programmers/misc/MiscCloneProgrammer.ts +786 -790
- package/src/programmers/misc/MiscLiteralsProgrammer.ts +1 -1
- package/src/programmers/misc/MiscPruneProgrammer.ts +548 -552
- package/src/programmers/notations/NotationGeneralProgrammer.ts +716 -720
- package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +7 -9
- package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +882 -882
- package/src/transform.ts +35 -35
|
@@ -1,142 +1,142 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
|
|
3
|
-
import { ArgumentParser } from "./setup/ArgumentParser";
|
|
4
|
-
import { CommandExecutor } from "./setup/CommandExecutor";
|
|
5
|
-
import { PackageManager } from "./setup/PackageManager";
|
|
6
|
-
import { PluginConfigurator } from "./setup/PluginConfigurator";
|
|
7
|
-
|
|
8
|
-
export namespace TypiaSetupWizard {
|
|
9
|
-
export interface IArguments {
|
|
10
|
-
manager: "npm" | "pnpm" | "yarn";
|
|
11
|
-
project: string | null;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function setup(): Promise<void> {
|
|
15
|
-
console.log("----------------------------------------");
|
|
16
|
-
console.log(" Typia Setup Wizard");
|
|
17
|
-
console.log("----------------------------------------");
|
|
18
|
-
|
|
19
|
-
// PREPARE ASSETS
|
|
20
|
-
const pack: PackageManager = await PackageManager.mount();
|
|
21
|
-
const args: IArguments = await ArgumentParser.parse(pack)(inquiry);
|
|
22
|
-
|
|
23
|
-
// INSTALL TYPESCRIPT COMPILERS
|
|
24
|
-
pack.install({ dev: true, modulo: "ts-patch", version: "latest" });
|
|
25
|
-
pack.install({ dev: true, modulo: "ts-node", version: "latest" });
|
|
26
|
-
pack.install({ dev: true, modulo: "typescript", version: "5.2.2" });
|
|
27
|
-
args.project ??= (() => {
|
|
28
|
-
const runner: string =
|
|
29
|
-
pack.manager === "npm" ? "npx" : pack.manager;
|
|
30
|
-
CommandExecutor.run(`${runner} tsc --init`);
|
|
31
|
-
return (args.project = "tsconfig.json");
|
|
32
|
-
})();
|
|
33
|
-
|
|
34
|
-
// SETUP TRANSFORMER
|
|
35
|
-
await pack.save((data) => {
|
|
36
|
-
// COMPOSE PREPARE COMMAND
|
|
37
|
-
data.scripts ??= {};
|
|
38
|
-
if (
|
|
39
|
-
typeof data.scripts.prepare === "string" &&
|
|
40
|
-
data.scripts.prepare.trim().length
|
|
41
|
-
) {
|
|
42
|
-
if (data.scripts.prepare.indexOf("ts-patch install") === -1)
|
|
43
|
-
data.scripts.prepare =
|
|
44
|
-
"ts-patch install && " + data.scripts.prepare;
|
|
45
|
-
} else data.scripts.prepare = "ts-patch install";
|
|
46
|
-
|
|
47
|
-
// FOR OLDER VERSIONS
|
|
48
|
-
if (typeof data.scripts.postinstall === "string") {
|
|
49
|
-
data.scripts.postinstall = data.scripts.postinstall
|
|
50
|
-
.split("&&")
|
|
51
|
-
.map((str) => str.trim())
|
|
52
|
-
.filter((str) => str.indexOf("ts-patch install") === -1)
|
|
53
|
-
.join(" && ");
|
|
54
|
-
if (data.scripts.postinstall.length === 0)
|
|
55
|
-
delete data.scripts.postinstall;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
CommandExecutor.run(`${pack.manager} run prepare`);
|
|
59
|
-
|
|
60
|
-
// CONFIGURE TYPIA
|
|
61
|
-
await PluginConfigurator.configure(args);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const inquiry: ArgumentParser.Inquiry<IArguments> = async (
|
|
65
|
-
pack,
|
|
66
|
-
command,
|
|
67
|
-
prompt,
|
|
68
|
-
action,
|
|
69
|
-
) => {
|
|
70
|
-
// PREPARE ASSETS
|
|
71
|
-
command.option("--manager [manager", "package manager");
|
|
72
|
-
command.option("--project [project]", "tsconfig.json file location");
|
|
73
|
-
|
|
74
|
-
// INTERNAL PROCEDURES
|
|
75
|
-
const questioned = { value: false };
|
|
76
|
-
const select =
|
|
77
|
-
(name: string) =>
|
|
78
|
-
(message: string) =>
|
|
79
|
-
async <Choice extends string>(
|
|
80
|
-
choices: Choice[],
|
|
81
|
-
filter?: (choice: string) => Choice,
|
|
82
|
-
): Promise<Choice> => {
|
|
83
|
-
questioned.value = true;
|
|
84
|
-
return (
|
|
85
|
-
await prompt()({
|
|
86
|
-
type: "list",
|
|
87
|
-
name: name,
|
|
88
|
-
message: message,
|
|
89
|
-
choices: choices,
|
|
90
|
-
...(filter
|
|
91
|
-
? {
|
|
92
|
-
filter,
|
|
93
|
-
}
|
|
94
|
-
: {}),
|
|
95
|
-
})
|
|
96
|
-
)[name];
|
|
97
|
-
};
|
|
98
|
-
const configure = async (): Promise<string | null> => {
|
|
99
|
-
const fileList: string[] = await (
|
|
100
|
-
await fs.promises.readdir(process.cwd())
|
|
101
|
-
)
|
|
102
|
-
.filter(
|
|
103
|
-
(str) =>
|
|
104
|
-
str.substring(0, 8) === "tsconfig" &&
|
|
105
|
-
str.substring(str.length - 5) === ".json",
|
|
106
|
-
)
|
|
107
|
-
.sort((x, y) =>
|
|
108
|
-
x === "tsconfig.json"
|
|
109
|
-
? -1
|
|
110
|
-
: y === "tsconfig.json"
|
|
111
|
-
? 1
|
|
112
|
-
: x < y
|
|
113
|
-
? -1
|
|
114
|
-
: 1,
|
|
115
|
-
);
|
|
116
|
-
if (fileList.length === 0) {
|
|
117
|
-
if (process.cwd() !== pack.directory)
|
|
118
|
-
throw new URIError(`Unable to find "tsconfig.json" file.`);
|
|
119
|
-
return null;
|
|
120
|
-
} else if (fileList.length === 1) return fileList[0]!;
|
|
121
|
-
return select("tsconfig")("TS Config File")(fileList);
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
// DO CONSTRUCT
|
|
125
|
-
return action(async (options) => {
|
|
126
|
-
pack.manager = options.manager ??= await select("manager")(
|
|
127
|
-
"Package Manager",
|
|
128
|
-
)(
|
|
129
|
-
[
|
|
130
|
-
"npm" as const,
|
|
131
|
-
"pnpm" as const,
|
|
132
|
-
"yarn (berry is not supported)" as "yarn",
|
|
133
|
-
],
|
|
134
|
-
(value) => value.split(" ")[0] as "yarn",
|
|
135
|
-
);
|
|
136
|
-
options.project ??= await configure();
|
|
137
|
-
|
|
138
|
-
if (questioned.value) console.log("");
|
|
139
|
-
return options as IArguments;
|
|
140
|
-
});
|
|
141
|
-
};
|
|
142
|
-
}
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
|
|
3
|
+
import { ArgumentParser } from "./setup/ArgumentParser";
|
|
4
|
+
import { CommandExecutor } from "./setup/CommandExecutor";
|
|
5
|
+
import { PackageManager } from "./setup/PackageManager";
|
|
6
|
+
import { PluginConfigurator } from "./setup/PluginConfigurator";
|
|
7
|
+
|
|
8
|
+
export namespace TypiaSetupWizard {
|
|
9
|
+
export interface IArguments {
|
|
10
|
+
manager: "npm" | "pnpm" | "yarn";
|
|
11
|
+
project: string | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function setup(): Promise<void> {
|
|
15
|
+
console.log("----------------------------------------");
|
|
16
|
+
console.log(" Typia Setup Wizard");
|
|
17
|
+
console.log("----------------------------------------");
|
|
18
|
+
|
|
19
|
+
// PREPARE ASSETS
|
|
20
|
+
const pack: PackageManager = await PackageManager.mount();
|
|
21
|
+
const args: IArguments = await ArgumentParser.parse(pack)(inquiry);
|
|
22
|
+
|
|
23
|
+
// INSTALL TYPESCRIPT COMPILERS
|
|
24
|
+
pack.install({ dev: true, modulo: "ts-patch", version: "latest" });
|
|
25
|
+
pack.install({ dev: true, modulo: "ts-node", version: "latest" });
|
|
26
|
+
pack.install({ dev: true, modulo: "typescript", version: "5.2.2" });
|
|
27
|
+
args.project ??= (() => {
|
|
28
|
+
const runner: string =
|
|
29
|
+
pack.manager === "npm" ? "npx" : pack.manager;
|
|
30
|
+
CommandExecutor.run(`${runner} tsc --init`);
|
|
31
|
+
return (args.project = "tsconfig.json");
|
|
32
|
+
})();
|
|
33
|
+
|
|
34
|
+
// SETUP TRANSFORMER
|
|
35
|
+
await pack.save((data) => {
|
|
36
|
+
// COMPOSE PREPARE COMMAND
|
|
37
|
+
data.scripts ??= {};
|
|
38
|
+
if (
|
|
39
|
+
typeof data.scripts.prepare === "string" &&
|
|
40
|
+
data.scripts.prepare.trim().length
|
|
41
|
+
) {
|
|
42
|
+
if (data.scripts.prepare.indexOf("ts-patch install") === -1)
|
|
43
|
+
data.scripts.prepare =
|
|
44
|
+
"ts-patch install && " + data.scripts.prepare;
|
|
45
|
+
} else data.scripts.prepare = "ts-patch install";
|
|
46
|
+
|
|
47
|
+
// FOR OLDER VERSIONS
|
|
48
|
+
if (typeof data.scripts.postinstall === "string") {
|
|
49
|
+
data.scripts.postinstall = data.scripts.postinstall
|
|
50
|
+
.split("&&")
|
|
51
|
+
.map((str) => str.trim())
|
|
52
|
+
.filter((str) => str.indexOf("ts-patch install") === -1)
|
|
53
|
+
.join(" && ");
|
|
54
|
+
if (data.scripts.postinstall.length === 0)
|
|
55
|
+
delete data.scripts.postinstall;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
CommandExecutor.run(`${pack.manager} run prepare`);
|
|
59
|
+
|
|
60
|
+
// CONFIGURE TYPIA
|
|
61
|
+
await PluginConfigurator.configure(args);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const inquiry: ArgumentParser.Inquiry<IArguments> = async (
|
|
65
|
+
pack,
|
|
66
|
+
command,
|
|
67
|
+
prompt,
|
|
68
|
+
action,
|
|
69
|
+
) => {
|
|
70
|
+
// PREPARE ASSETS
|
|
71
|
+
command.option("--manager [manager", "package manager");
|
|
72
|
+
command.option("--project [project]", "tsconfig.json file location");
|
|
73
|
+
|
|
74
|
+
// INTERNAL PROCEDURES
|
|
75
|
+
const questioned = { value: false };
|
|
76
|
+
const select =
|
|
77
|
+
(name: string) =>
|
|
78
|
+
(message: string) =>
|
|
79
|
+
async <Choice extends string>(
|
|
80
|
+
choices: Choice[],
|
|
81
|
+
filter?: (choice: string) => Choice,
|
|
82
|
+
): Promise<Choice> => {
|
|
83
|
+
questioned.value = true;
|
|
84
|
+
return (
|
|
85
|
+
await prompt()({
|
|
86
|
+
type: "list",
|
|
87
|
+
name: name,
|
|
88
|
+
message: message,
|
|
89
|
+
choices: choices,
|
|
90
|
+
...(filter
|
|
91
|
+
? {
|
|
92
|
+
filter,
|
|
93
|
+
}
|
|
94
|
+
: {}),
|
|
95
|
+
})
|
|
96
|
+
)[name];
|
|
97
|
+
};
|
|
98
|
+
const configure = async (): Promise<string | null> => {
|
|
99
|
+
const fileList: string[] = await (
|
|
100
|
+
await fs.promises.readdir(process.cwd())
|
|
101
|
+
)
|
|
102
|
+
.filter(
|
|
103
|
+
(str) =>
|
|
104
|
+
str.substring(0, 8) === "tsconfig" &&
|
|
105
|
+
str.substring(str.length - 5) === ".json",
|
|
106
|
+
)
|
|
107
|
+
.sort((x, y) =>
|
|
108
|
+
x === "tsconfig.json"
|
|
109
|
+
? -1
|
|
110
|
+
: y === "tsconfig.json"
|
|
111
|
+
? 1
|
|
112
|
+
: x < y
|
|
113
|
+
? -1
|
|
114
|
+
: 1,
|
|
115
|
+
);
|
|
116
|
+
if (fileList.length === 0) {
|
|
117
|
+
if (process.cwd() !== pack.directory)
|
|
118
|
+
throw new URIError(`Unable to find "tsconfig.json" file.`);
|
|
119
|
+
return null;
|
|
120
|
+
} else if (fileList.length === 1) return fileList[0]!;
|
|
121
|
+
return select("tsconfig")("TS Config File")(fileList);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// DO CONSTRUCT
|
|
125
|
+
return action(async (options) => {
|
|
126
|
+
pack.manager = options.manager ??= await select("manager")(
|
|
127
|
+
"Package Manager",
|
|
128
|
+
)(
|
|
129
|
+
[
|
|
130
|
+
"npm" as const,
|
|
131
|
+
"pnpm" as const,
|
|
132
|
+
"yarn (berry is not supported)" as "yarn",
|
|
133
|
+
],
|
|
134
|
+
(value) => value.split(" ")[0] as "yarn",
|
|
135
|
+
);
|
|
136
|
+
options.project ??= await configure();
|
|
137
|
+
|
|
138
|
+
if (questioned.value) console.log("");
|
|
139
|
+
return options as IArguments;
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import cp from "child_process";
|
|
2
|
-
|
|
3
|
-
export namespace CommandExecutor {
|
|
4
|
-
export const run = (str: string): void => {
|
|
5
|
-
console.log(`\n$ ${str}`);
|
|
6
|
-
cp.execSync(str, { stdio: "inherit" });
|
|
7
|
-
};
|
|
8
|
-
}
|
|
1
|
+
import cp from "child_process";
|
|
2
|
+
|
|
3
|
+
export namespace CommandExecutor {
|
|
4
|
+
export const run = (str: string): void => {
|
|
5
|
+
console.log(`\n$ ${str}`);
|
|
6
|
+
cp.execSync(str, { stdio: "inherit" });
|
|
7
|
+
};
|
|
8
|
+
}
|
|
@@ -3,6 +3,14 @@ import ts from "typescript";
|
|
|
3
3
|
import { RandomGenerator } from "../utils/RandomGenerator";
|
|
4
4
|
|
|
5
5
|
export namespace ExpressionFactory {
|
|
6
|
+
export const number = (value: number) =>
|
|
7
|
+
value < 0
|
|
8
|
+
? ts.factory.createPrefixUnaryExpression(
|
|
9
|
+
ts.SyntaxKind.MinusToken,
|
|
10
|
+
ts.factory.createNumericLiteral(Math.abs(value)),
|
|
11
|
+
)
|
|
12
|
+
: ts.factory.createNumericLiteral(value);
|
|
13
|
+
|
|
6
14
|
export const bigint = (value: number | bigint) =>
|
|
7
15
|
ts.factory.createCallExpression(
|
|
8
16
|
ts.factory.createIdentifier("BigInt"),
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../schemas/metadata/Metadata";
|
|
4
|
-
|
|
5
|
-
import { AtomicPredicator } from "../programmers/helpers/AtomicPredicator";
|
|
6
|
-
|
|
7
|
-
import { TransformerError } from "../transformers/TransformerError";
|
|
8
|
-
|
|
9
|
-
import { MetadataCollection } from "./MetadataCollection";
|
|
10
|
-
import { MetadataFactory } from "./MetadataFactory";
|
|
11
|
-
|
|
12
|
-
export namespace JsonMetadataFactory {
|
|
13
|
-
export const analyze =
|
|
14
|
-
(method: string) =>
|
|
15
|
-
(checker: ts.TypeChecker) =>
|
|
16
|
-
(type: ts.Type): [MetadataCollection, Metadata] => {
|
|
17
|
-
const collection = new MetadataCollection();
|
|
18
|
-
const result = MetadataFactory.analyze(checker)({
|
|
19
|
-
escape: true,
|
|
20
|
-
constant: true,
|
|
21
|
-
absorb: true,
|
|
22
|
-
validate,
|
|
23
|
-
})(collection)(type);
|
|
24
|
-
if (result.success === false)
|
|
25
|
-
throw TransformerError.from(method)(result.errors);
|
|
26
|
-
return [collection, result.data];
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const validate = (meta: Metadata) => {
|
|
30
|
-
const output: string[] = [];
|
|
31
|
-
if (
|
|
32
|
-
meta.atomics.some((a) => a.type === "bigint") ||
|
|
33
|
-
meta.constants.some((c) => c.type === "bigint")
|
|
34
|
-
)
|
|
35
|
-
output.push("JSON does not support bigint type.");
|
|
36
|
-
if (
|
|
37
|
-
meta.tuples.some((t) =>
|
|
38
|
-
t.type.elements.some((e) => e.isRequired() === false),
|
|
39
|
-
) ||
|
|
40
|
-
meta.arrays.some((a) => a.type.value.isRequired() === false)
|
|
41
|
-
)
|
|
42
|
-
output.push("JSON does not support undefined type in array.");
|
|
43
|
-
if (meta.maps.length) output.push("JSON does not support Map type.");
|
|
44
|
-
if (meta.sets.length) output.push("JSON does not support Set type.");
|
|
45
|
-
for (const native of meta.natives)
|
|
46
|
-
if (AtomicPredicator.native(native) === false && native !== "Date")
|
|
47
|
-
output.push(`JSON does not support ${native} type.`);
|
|
48
|
-
return output;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../schemas/metadata/Metadata";
|
|
4
|
+
|
|
5
|
+
import { AtomicPredicator } from "../programmers/helpers/AtomicPredicator";
|
|
6
|
+
|
|
7
|
+
import { TransformerError } from "../transformers/TransformerError";
|
|
8
|
+
|
|
9
|
+
import { MetadataCollection } from "./MetadataCollection";
|
|
10
|
+
import { MetadataFactory } from "./MetadataFactory";
|
|
11
|
+
|
|
12
|
+
export namespace JsonMetadataFactory {
|
|
13
|
+
export const analyze =
|
|
14
|
+
(method: string) =>
|
|
15
|
+
(checker: ts.TypeChecker) =>
|
|
16
|
+
(type: ts.Type): [MetadataCollection, Metadata] => {
|
|
17
|
+
const collection = new MetadataCollection();
|
|
18
|
+
const result = MetadataFactory.analyze(checker)({
|
|
19
|
+
escape: true,
|
|
20
|
+
constant: true,
|
|
21
|
+
absorb: true,
|
|
22
|
+
validate,
|
|
23
|
+
})(collection)(type);
|
|
24
|
+
if (result.success === false)
|
|
25
|
+
throw TransformerError.from(method)(result.errors);
|
|
26
|
+
return [collection, result.data];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const validate = (meta: Metadata) => {
|
|
30
|
+
const output: string[] = [];
|
|
31
|
+
if (
|
|
32
|
+
meta.atomics.some((a) => a.type === "bigint") ||
|
|
33
|
+
meta.constants.some((c) => c.type === "bigint")
|
|
34
|
+
)
|
|
35
|
+
output.push("JSON does not support bigint type.");
|
|
36
|
+
if (
|
|
37
|
+
meta.tuples.some((t) =>
|
|
38
|
+
t.type.elements.some((e) => e.isRequired() === false),
|
|
39
|
+
) ||
|
|
40
|
+
meta.arrays.some((a) => a.type.value.isRequired() === false)
|
|
41
|
+
)
|
|
42
|
+
output.push("JSON does not support undefined type in array.");
|
|
43
|
+
if (meta.maps.length) output.push("JSON does not support Map type.");
|
|
44
|
+
if (meta.sets.length) output.push("JSON does not support Set type.");
|
|
45
|
+
for (const native of meta.natives)
|
|
46
|
+
if (AtomicPredicator.native(native) === false && native !== "Date")
|
|
47
|
+
output.push(`JSON does not support ${native} type.`);
|
|
48
|
+
return output;
|
|
49
|
+
};
|
|
50
|
+
}
|