typia 13.2.0 → 14.0.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.
Files changed (135) hide show
  1. package/lib/http.d.ts +3 -3
  2. package/lib/http.js.map +1 -1
  3. package/lib/http.mjs.map +1 -1
  4. package/lib/internal/_assertGuard.js +13 -3
  5. package/lib/internal/_assertGuard.js.map +1 -1
  6. package/lib/internal/_assertGuard.mjs +4 -2
  7. package/lib/internal/_assertGuard.mjs.map +1 -1
  8. package/lib/internal/_isFormatIdnHostname.js +5 -1
  9. package/lib/internal/_isFormatIdnHostname.js.map +1 -1
  10. package/lib/internal/_isFormatIdnHostname.mjs +1 -1
  11. package/lib/internal/_isFormatIdnHostname.mjs.map +1 -1
  12. package/lib/internal/_isFormatTime.js +19 -2
  13. package/lib/internal/_isFormatTime.js.map +1 -1
  14. package/lib/internal/_isFormatTime.mjs +9 -2
  15. package/lib/internal/_isFormatTime.mjs.map +1 -1
  16. package/lib/internal/_randomArray.js +37 -4
  17. package/lib/internal/_randomArray.js.map +1 -1
  18. package/lib/internal/_randomArray.mjs +16 -3
  19. package/lib/internal/_randomArray.mjs.map +1 -1
  20. package/lib/internal/_randomFormatByte.js +15 -12
  21. package/lib/internal/_randomFormatByte.js.map +1 -1
  22. package/lib/internal/_randomFormatByte.mjs +11 -10
  23. package/lib/internal/_randomFormatByte.mjs.map +1 -1
  24. package/lib/internal/_randomFormatDatetime.mjs +1 -1
  25. package/lib/internal/_randomFormatHostname.d.ts +2 -2
  26. package/lib/internal/_randomFormatHostname.js +2 -2
  27. package/lib/internal/_randomFormatHostname.mjs +2 -2
  28. package/lib/internal/_randomFormatHostname.mjs.map +1 -1
  29. package/lib/internal/_randomFormatIdnHostname.js +9 -10
  30. package/lib/internal/_randomFormatIdnHostname.js.map +1 -1
  31. package/lib/internal/_randomFormatIdnHostname.mjs +3 -4
  32. package/lib/internal/_randomFormatIdnHostname.mjs.map +1 -1
  33. package/lib/internal/_randomFormatRegex.js +4 -4
  34. package/lib/internal/_randomFormatRegex.js.map +1 -1
  35. package/lib/internal/_randomFormatRegex.mjs +1 -2
  36. package/lib/internal/_randomFormatRegex.mjs.map +1 -1
  37. package/lib/internal/_randomFormatTime.js +15 -10
  38. package/lib/internal/_randomFormatTime.js.map +1 -1
  39. package/lib/internal/_randomFormatTime.mjs +6 -3
  40. package/lib/internal/_randomFormatTime.mjs.map +1 -1
  41. package/lib/internal/_randomPattern.js +20 -3
  42. package/lib/internal/_randomPattern.js.map +1 -1
  43. package/lib/internal/_randomPattern.mjs +5 -1
  44. package/lib/internal/_randomPattern.mjs.map +1 -1
  45. package/lib/internal/_randomStringLength.js +9 -2
  46. package/lib/internal/_randomStringLength.js.map +1 -1
  47. package/lib/internal/_randomStringLength.mjs +3 -1
  48. package/lib/internal/_randomStringLength.mjs.map +1 -1
  49. package/lib/internal/private/__randomComposition.d.ts +8 -0
  50. package/lib/internal/private/__randomComposition.js +21 -1
  51. package/lib/internal/private/__randomComposition.js.map +1 -1
  52. package/lib/internal/private/__randomComposition.mjs +18 -1
  53. package/lib/internal/private/__randomComposition.mjs.map +1 -1
  54. package/lib/json.d.ts +2 -2
  55. package/lib/json.js.map +1 -1
  56. package/lib/json.mjs.map +1 -1
  57. package/lib/module.d.ts +28 -13
  58. package/lib/module.js.map +1 -1
  59. package/lib/module.mjs.map +1 -1
  60. package/lib/notations.d.ts +4 -4
  61. package/lib/notations.js.map +1 -1
  62. package/lib/notations.mjs.map +1 -1
  63. package/lib/plain.d.ts +3 -3
  64. package/lib/plain.js.map +1 -1
  65. package/lib/plain.mjs.map +1 -1
  66. package/lib/protobuf.d.ts +2 -2
  67. package/lib/protobuf.js.map +1 -1
  68. package/lib/protobuf.mjs.map +1 -1
  69. package/lib/transform.mjs +1 -1
  70. package/native/cmd/ttsc-typia/assert_guard_factory_contract_test.go +17 -4
  71. package/native/cmd/ttsc-typia/create_assert_error_factory_arity_test.go +309 -0
  72. package/native/cmd/ttsc-typia/dynamic_key_tags_transform_test.go +206 -0
  73. package/native/cmd/ttsc-typia/local_function_named_like_typia_operation_transform_test.go +185 -0
  74. package/native/cmd/ttsc-typia/notation_kebab_case_transform_test.go +2 -2
  75. package/native/cmd/ttsc-typia/project_catalog_transform_coverage_test.go +84 -85
  76. package/native/cmd/ttsc-typia/recursive_conditional_alias_name_transform_test.go +307 -0
  77. package/native/cmd/ttsc-typia/shadowed_typia_module_declaration_diagnostic_test.go +152 -0
  78. package/native/cmd/ttsc-typia/transform.go +2 -2
  79. package/native/cmd/ttsc-typia/transform_helpers_test.go +96 -18
  80. package/native/core/factories/FormatCheatSheet.go +2 -2
  81. package/native/core/factories/MetadataCommentTagFactory.go +91 -7
  82. package/native/core/factories/factory_utility_coverage_test.go +896 -907
  83. package/native/core/factories/internal/metadata/MetadataHelper.go +5 -28
  84. package/native/core/factories/metadata_comment_tag_factory_rejects_out_of_range_integer_test.go +124 -0
  85. package/native/core/programmers/AssertProgrammer.go +20 -6
  86. package/native/core/programmers/RandomProgrammer.go +78 -3
  87. package/native/core/programmers/ValidateProgrammer.go +21 -6
  88. package/native/core/programmers/helpers/RandomJoiner.go +8 -1
  89. package/native/core/programmers/iterate/check_dynamic_properties.go +177 -3
  90. package/native/core/programmers/iterate/check_object.go +12 -1
  91. package/native/core/schemas/metadata/MetadataCollection.go +47 -5
  92. package/native/transform/CallExpressionTransformer.go +167 -0
  93. package/package.json +3 -12
  94. package/src/http.ts +18 -4
  95. package/src/internal/_assertGuard.ts +13 -2
  96. package/src/internal/_isFormatIdnHostname.ts +5 -1
  97. package/src/internal/_isFormatTime.ts +19 -2
  98. package/src/internal/_randomArray.ts +42 -6
  99. package/src/internal/_randomFormatByte.ts +17 -12
  100. package/src/internal/_randomFormatHostname.ts +2 -2
  101. package/src/internal/_randomFormatIdnHostname.ts +8 -9
  102. package/src/internal/_randomFormatRegex.ts +4 -6
  103. package/src/internal/_randomFormatTime.ts +15 -10
  104. package/src/internal/_randomPattern.ts +18 -3
  105. package/src/internal/_randomStringLength.ts +9 -2
  106. package/src/internal/private/__randomComposition.ts +24 -0
  107. package/src/json.ts +16 -4
  108. package/src/module.ts +56 -22
  109. package/src/notations.ts +16 -4
  110. package/src/plain.ts +12 -3
  111. package/src/protobuf.ts +16 -4
  112. package/lib/executable/FileSystemIdentity.d.ts +0 -44
  113. package/lib/executable/FileSystemIdentity.js +0 -213
  114. package/lib/executable/FileSystemIdentity.js.map +0 -1
  115. package/lib/executable/FileSystemIdentity.mjs +0 -133
  116. package/lib/executable/FileSystemIdentity.mjs.map +0 -1
  117. package/lib/executable/TypiaGenerateWizard.d.ts +0 -9
  118. package/lib/executable/TypiaGenerateWizard.js +0 -852
  119. package/lib/executable/TypiaGenerateWizard.js.map +0 -1
  120. package/lib/executable/TypiaGenerateWizard.mjs +0 -618
  121. package/lib/executable/TypiaGenerateWizard.mjs.map +0 -1
  122. package/lib/executable/generate/ttsc.d.ts +0 -1
  123. package/lib/executable/generate/ttsc.js +0 -53
  124. package/lib/executable/generate/ttsc.js.map +0 -1
  125. package/lib/executable/generate/ttsc.mjs +0 -37
  126. package/lib/executable/generate/ttsc.mjs.map +0 -1
  127. package/lib/executable/typia.d.ts +0 -2
  128. package/lib/executable/typia.js +0 -84
  129. package/lib/executable/typia.js.map +0 -1
  130. package/lib/executable/typia.mjs +0 -60
  131. package/lib/executable/typia.mjs.map +0 -1
  132. package/src/executable/FileSystemIdentity.ts +0 -222
  133. package/src/executable/TypiaGenerateWizard.ts +0 -1133
  134. package/src/executable/generate/ttsc.ts +0 -70
  135. package/src/executable/typia.ts +0 -80
@@ -1,852 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.TypiaGenerateWizard = void 0;
16
- const commander_1 = require("commander");
17
- const fs_1 = __importDefault(require("fs"));
18
- const inquirer_1 = __importDefault(require("inquirer"));
19
- const module_1 = require("module");
20
- const os_1 = __importDefault(require("os"));
21
- const path_1 = __importDefault(require("path"));
22
- const tinyglobby_1 = require("tinyglobby");
23
- const FileSystemIdentity_1 = require("./FileSystemIdentity");
24
- var TypiaGenerateWizard;
25
- (function (TypiaGenerateWizard) {
26
- function generate() {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- console.log("----------------------------------------");
29
- console.log(" Typia Generate Wizard");
30
- console.log("----------------------------------------");
31
- const options = yield parseArguments();
32
- yield build(options);
33
- });
34
- }
35
- TypiaGenerateWizard.generate = generate;
36
- function parseArguments() {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- const command = (0, commander_1.createCommand)("typia generate");
39
- command.usage("[options] [files...]");
40
- command.argument("[files...]", "input TypeScript source files or globs");
41
- command.option("--input <path>", "input directory");
42
- command.option("--output <directory>", "output directory");
43
- command.option("--project <project>", "tsconfig.json/jsconfig.json file or directory");
44
- const questioned = { value: false };
45
- const prompt = inquirer_1.default.createPromptModule;
46
- const input = (name) => (message) => __awaiter(this, void 0, void 0, function* () {
47
- questioned.value = true;
48
- const result = yield prompt()({
49
- type: "input",
50
- name,
51
- message,
52
- default: "",
53
- });
54
- return result[name];
55
- });
56
- const configure = () => __awaiter(this, void 0, void 0, function* () {
57
- const file = findProjectConfigFile(process.cwd());
58
- if (file === null) {
59
- throw new URIError(`Unable to find "tsconfig.json" or "jsconfig.json" file.`);
60
- }
61
- return file;
62
- });
63
- return new Promise((resolve, reject) => {
64
- command.action((files, options) => __awaiter(this, void 0, void 0, function* () {
65
- var _a, _b, _c;
66
- try {
67
- if (files.length !== 0 && options.input !== undefined) {
68
- throw new URIError("Error on TypiaGenerateWizard.generate(): file arguments cannot be combined with --input.");
69
- }
70
- if (files.length === 0) {
71
- (_a = options.input) !== null && _a !== void 0 ? _a : (options.input = yield input("input")("input directory"));
72
- }
73
- if (files.length !== 0 && options.output === undefined) {
74
- throw new URIError("Error on TypiaGenerateWizard.generate(): output directory is required when file arguments are used.");
75
- }
76
- const output = (_b = options.output) !== null && _b !== void 0 ? _b : (yield input("output")("output directory"));
77
- const project = (_c = options.project) !== null && _c !== void 0 ? _c : (yield configure());
78
- if (questioned.value)
79
- console.log("");
80
- resolve({
81
- input: options.input,
82
- output,
83
- project,
84
- files,
85
- });
86
- }
87
- catch (exp) {
88
- reject(exp);
89
- }
90
- }));
91
- command.parseAsync(process.argv.slice(3), { from: "user" }).catch(reject);
92
- });
93
- });
94
- }
95
- function build(location) {
96
- return __awaiter(this, void 0, void 0, function* () {
97
- location.output = path_1.default.resolve(location.output);
98
- location.project = resolveProjectConfigFile(location.project);
99
- const policy = new FileSystemIdentity_1.FileSystemIdentity.Policy();
100
- const outputProbe = yield nearestExistingAncestor(location.output);
101
- yield ensureExistingDirectoryPath({
102
- label: "output parent path",
103
- directory: outputProbe,
104
- });
105
- policy.observe(yield FileSystemIdentity_1.FileSystemIdentity.probeDirectory(outputProbe), outputProbe);
106
- policy.observe(yield FileSystemIdentity_1.FileSystemIdentity.inspectDirectory(path_1.default.dirname(location.project)), path_1.default.dirname(location.project));
107
- const entries = location.files.length === 0
108
- ? yield prepareDirectoryInput(location, policy)
109
- : yield prepareFileInputs(location, policy);
110
- const identity = policy.get();
111
- yield inspectTargetDirectories({
112
- identity,
113
- output: location.output,
114
- targets: entries.map((entry) => entry.target),
115
- });
116
- const binary = resolveTsgoBinary();
117
- const cwd = path_1.default.dirname(location.project);
118
- const temporaryProject = yield createTemporaryProject({
119
- entries,
120
- project: location.project,
121
- });
122
- let transformed;
123
- try {
124
- transformed = transformProject({
125
- binary,
126
- cwd,
127
- projectRoot: cwd,
128
- tsconfig: temporaryProject.config,
129
- });
130
- }
131
- finally {
132
- yield fs_1.default.promises.rm(temporaryProject.directory, {
133
- force: true,
134
- recursive: true,
135
- });
136
- }
137
- const outputByKey = indexTransformedOutputs(transformed, identity);
138
- const outputs = entries.map((entry) => {
139
- const output = getTransformedOutput({
140
- cwd,
141
- entry,
142
- identity,
143
- outputByKey,
144
- });
145
- if (output === undefined) {
146
- throw new URIError(`Error on TypiaGenerateWizard.generate(): no transformed output for ${entry.file}. Check that --project includes the file.`);
147
- }
148
- return { entry, output };
149
- });
150
- yield ensureOutputDirectory(location.output);
151
- yield ensureTargetDirectories({
152
- identity,
153
- output: location.output,
154
- targets: outputs.map(({ entry }) => entry.target),
155
- });
156
- yield ensurePhysicalTargets({
157
- identity,
158
- output: location.output,
159
- entries: outputs.map(({ entry }) => entry),
160
- });
161
- yield ensureTargetFiles(outputs.map(({ entry }) => entry), identity);
162
- for (const { entry, output } of outputs) {
163
- yield fs_1.default.promises.writeFile(entry.target, formatOutput(output), "utf8");
164
- }
165
- });
166
- }
167
- function createTemporaryProject(props) {
168
- return __awaiter(this, void 0, void 0, function* () {
169
- const directory = yield fs_1.default.promises.mkdtemp(path_1.default.join(os_1.default.tmpdir(), "typia-generate-project-"));
170
- const config = path_1.default.join(directory, "tsconfig.json");
171
- try {
172
- yield fs_1.default.promises.writeFile(config, JSON.stringify({
173
- extends: props.project,
174
- exclude: [],
175
- files: props.entries.map((entry) => compilerInputPath(entry.file)),
176
- include: [],
177
- }), "utf8");
178
- return { config, directory };
179
- }
180
- catch (error) {
181
- yield fs_1.default.promises.rm(directory, { force: true, recursive: true });
182
- throw new URIError(`Error on TypiaGenerateWizard.generate(): unable to prepare the bounded input project: ${formatUnknownError(error)}`);
183
- }
184
- });
185
- }
186
- function ensureOutputDirectory(output) {
187
- return __awaiter(this, void 0, void 0, function* () {
188
- if (fs_1.default.existsSync(output) === false) {
189
- yield ensureCreatableDirectory(output);
190
- yield fs_1.default.promises.mkdir(output, { recursive: true });
191
- }
192
- else {
193
- yield ensureExistingDirectory({
194
- label: "output path",
195
- directory: output,
196
- });
197
- }
198
- });
199
- }
200
- function ensureTargetDirectories(props) {
201
- return __awaiter(this, void 0, void 0, function* () {
202
- yield inspectTargetDirectories(props);
203
- const directories = targetDirectories(props);
204
- for (const directory of directories.values()) {
205
- try {
206
- yield fs_1.default.promises.mkdir(directory, { recursive: true });
207
- }
208
- catch (exp) {
209
- throw new URIError(`Error on TypiaGenerateWizard.generate(): unable to create output parent directory ${directory}: ${formatUnknownError(exp)}`);
210
- }
211
- yield ensureExistingDirectory({
212
- label: "output parent path",
213
- directory,
214
- });
215
- }
216
- });
217
- }
218
- function inspectTargetDirectories(props) {
219
- return __awaiter(this, void 0, void 0, function* () {
220
- const directories = targetDirectories(props);
221
- for (const directory of directories.values()) {
222
- yield ensureOutputAncestorDirectories({
223
- identity: props.identity,
224
- output: props.output,
225
- directory,
226
- });
227
- if (fs_1.default.existsSync(directory)) {
228
- yield ensureExistingDirectory({
229
- label: "output parent path",
230
- directory,
231
- });
232
- }
233
- }
234
- });
235
- }
236
- function targetDirectories(props) {
237
- const directories = new Map();
238
- for (const target of props.targets) {
239
- const directory = path_1.default.dirname(target);
240
- directories.set(props.identity.filesystemKey(directory), directory);
241
- }
242
- return directories;
243
- }
244
- function ensureCreatableDirectory(directory) {
245
- return __awaiter(this, void 0, void 0, function* () {
246
- const parent = yield nearestExistingAncestor(directory);
247
- yield ensureExistingDirectoryPath({
248
- label: "output parent path",
249
- directory: parent,
250
- });
251
- });
252
- }
253
- function nearestExistingAncestor(directory) {
254
- return __awaiter(this, void 0, void 0, function* () {
255
- let current = path_1.default.resolve(directory);
256
- while (fs_1.default.existsSync(current) === false) {
257
- const parent = path_1.default.dirname(current);
258
- if (parent === current) {
259
- throw new URIError(`Error on TypiaGenerateWizard.generate(): unable to find existing output parent path: ${directory}`);
260
- }
261
- current = parent;
262
- }
263
- return current;
264
- });
265
- }
266
- function ensureOutputAncestorDirectories(props) {
267
- return __awaiter(this, void 0, void 0, function* () {
268
- const output = path_1.default.resolve(props.output);
269
- const directory = path_1.default.resolve(props.directory);
270
- if (props.identity.contains(directory, output) === false) {
271
- throw new URIError(`Error on TypiaGenerateWizard.generate(): output parent path escapes output directory: ${props.directory}`);
272
- }
273
- const relative = path_1.default.relative(output, directory);
274
- if (relative === "") {
275
- return;
276
- }
277
- let current = output;
278
- for (const segment of relative.split(path_1.default.sep)) {
279
- current = path_1.default.join(current, segment);
280
- let stat;
281
- try {
282
- stat = yield fs_1.default.promises.lstat(current);
283
- }
284
- catch (exp) {
285
- if (isMissingFileError(exp)) {
286
- return;
287
- }
288
- throw new URIError(`Error on TypiaGenerateWizard.generate(): unable to inspect output parent path ${current}: ${formatUnknownError(exp)}`);
289
- }
290
- if (stat.isSymbolicLink()) {
291
- throw new URIError(`Error on TypiaGenerateWizard.generate(): output parent path contains a symbolic link: ${current}`);
292
- }
293
- if (stat.isDirectory() === false) {
294
- throw new URIError(`Error on TypiaGenerateWizard.generate(): output parent path is not a directory: ${current}`);
295
- }
296
- }
297
- });
298
- }
299
- function ensureExistingDirectory(props) {
300
- return __awaiter(this, void 0, void 0, function* () {
301
- yield ensureExistingDirectoryPath(props);
302
- });
303
- }
304
- function ensureExistingDirectoryPath(props) {
305
- return __awaiter(this, void 0, void 0, function* () {
306
- const directory = path_1.default.resolve(props.directory);
307
- const parsed = path_1.default.parse(directory);
308
- const relative = path_1.default.relative(parsed.root, directory);
309
- let current = parsed.root;
310
- for (const segment of relative === "" ? [] : relative.split(path_1.default.sep)) {
311
- current = path_1.default.join(current, segment);
312
- yield ensureExistingDirectorySegment({
313
- label: path_1.default.normalize(current) === path_1.default.normalize(directory)
314
- ? props.label
315
- : `${props.label} ancestor`,
316
- directory: current,
317
- });
318
- }
319
- });
320
- }
321
- function ensureExistingDirectorySegment(props) {
322
- return __awaiter(this, void 0, void 0, function* () {
323
- const stat = yield fs_1.default.promises.lstat(props.directory);
324
- if (stat.isSymbolicLink()) {
325
- throw new URIError(`Error on TypiaGenerateWizard.generate(): ${props.label} is a symbolic link: ${props.directory}`);
326
- }
327
- if (stat.isDirectory() === false) {
328
- throw new URIError(`Error on TypiaGenerateWizard.generate(): ${props.label} is not a directory: ${props.directory}`);
329
- }
330
- });
331
- }
332
- function ensurePhysicalTargets(props) {
333
- return __awaiter(this, void 0, void 0, function* () {
334
- const output = yield fs_1.default.promises.realpath(props.output);
335
- const inputs = new Set();
336
- for (const entry of props.entries) {
337
- inputs.add(props.identity.filesystemKey(yield fs_1.default.promises.realpath(entry.file)));
338
- }
339
- for (const entry of props.entries) {
340
- const parent = path_1.default.dirname(entry.target);
341
- const directory = yield fs_1.default.promises.realpath(parent);
342
- if (props.identity.contains(directory, output) === false) {
343
- throw new URIError(`Error on TypiaGenerateWizard.generate(): output parent path escapes output directory through a symbolic link: ${parent}`);
344
- }
345
- const target = path_1.default.join(directory, path_1.default.basename(entry.target));
346
- if (inputs.has(props.identity.filesystemKey(target))) {
347
- throw new URIError(`Error on TypiaGenerateWizard.generate(): output file would overwrite input file through a symbolic link: ${entry.target}`);
348
- }
349
- }
350
- });
351
- }
352
- function ensureTargetFiles(entries, identity) {
353
- return __awaiter(this, void 0, void 0, function* () {
354
- const inputs = new Set();
355
- const files = new Map();
356
- for (const entry of entries) {
357
- inputs.add(fileIdentityKey(yield fs_1.default.promises.stat(entry.file, { bigint: true }), yield fs_1.default.promises.realpath(entry.file)));
358
- files.set(identity.filesystemKey(entry.target), entry);
359
- }
360
- for (const entry of files.values()) {
361
- let stat;
362
- try {
363
- stat = yield fs_1.default.promises.lstat(entry.target, { bigint: true });
364
- }
365
- catch (exp) {
366
- if (isMissingFileError(exp)) {
367
- continue;
368
- }
369
- throw new URIError(`Error on TypiaGenerateWizard.generate(): unable to inspect output file ${entry.target}: ${formatUnknownError(exp)}`);
370
- }
371
- if (stat.isFile() === false) {
372
- throw new URIError(`Error on TypiaGenerateWizard.generate(): output file path is not a regular file: ${entry.target}`);
373
- }
374
- if (inputs.has(fileIdentityKey(stat, yield fs_1.default.promises.realpath(entry.target)))) {
375
- throw new URIError(`Error on TypiaGenerateWizard.generate(): output file would overwrite input file through a physical file alias: ${entry.target}`);
376
- }
377
- if (stat.nlink > BigInt(1)) {
378
- throw new URIError(`Error on TypiaGenerateWizard.generate(): output file has multiple hard links: ${entry.target}`);
379
- }
380
- }
381
- });
382
- }
383
- function prepareDirectoryInput(location, policy) {
384
- return __awaiter(this, void 0, void 0, function* () {
385
- if (location.input === undefined) {
386
- throw new URIError("Error on TypiaGenerateWizard.generate(): input path is required.");
387
- }
388
- const input = path_1.default.resolve(location.input);
389
- if (fs_1.default.existsSync(input) === false) {
390
- throw new URIError(`Error on TypiaGenerateWizard.generate(): input path does not exist: ${input}`);
391
- }
392
- if ((yield isDirectory(input)) === false) {
393
- throw new URIError("Error on TypiaGenerateWizard.generate(): input path is not a directory.");
394
- }
395
- const inputReal = yield fs_1.default.promises.realpath(input);
396
- const outputReal = yield optionalRealPath(location.output);
397
- const files = [];
398
- yield gather({
399
- container: files,
400
- from: input,
401
- inputReal,
402
- outputReal,
403
- policy,
404
- visitedDirectories: new Set(),
405
- visitedFiles: new Set(),
406
- });
407
- return files.map((file) => ({
408
- file,
409
- target: path_1.default.join(location.output, path_1.default.relative(input, file)),
410
- }));
411
- });
412
- }
413
- function prepareFileInputs(location, policy) {
414
- return __awaiter(this, void 0, void 0, function* () {
415
- const targets = new Set();
416
- const output = [];
417
- for (const input of yield expandFileInputs(location.files, location.output, policy)) {
418
- const file = path_1.default.resolve(input);
419
- policy.observe(yield FileSystemIdentity_1.FileSystemIdentity.inspectDirectory(path_1.default.dirname(file)), path_1.default.dirname(file));
420
- const identity = policy.get();
421
- if (fs_1.default.existsSync(file) === false) {
422
- throw new URIError(`Error on TypiaGenerateWizard.generate(): input file does not exist: ${input}`);
423
- }
424
- else if ((yield isFile(file)) === false) {
425
- throw new URIError(`Error on TypiaGenerateWizard.generate(): input path is not a file: ${input}`);
426
- }
427
- else if (identity.isDeclarationFile(file)) {
428
- continue;
429
- }
430
- else if (identity.isSupportedExtension(file) === false) {
431
- throw new URIError(`Error on TypiaGenerateWizard.generate(): input file is not a supported TypeScript source: ${input}`);
432
- }
433
- const target = path_1.default.join(location.output, path_1.default.basename(file));
434
- if (identity.isSamePath(file, target)) {
435
- throw new URIError(`Error on TypiaGenerateWizard.generate(): output file would overwrite input file: ${input}`);
436
- }
437
- const key = identity.filesystemKey(target);
438
- if (targets.has(key)) {
439
- throw new URIError(`Error on TypiaGenerateWizard.generate(): duplicate output filename for ${target}`);
440
- }
441
- targets.add(key);
442
- output.push({ file, target });
443
- }
444
- if (output.length === 0) {
445
- throw new URIError("Error on TypiaGenerateWizard.generate(): input files do not include any supported TypeScript source files outside the output directory.");
446
- }
447
- return output;
448
- });
449
- }
450
- function expandFileInputs(inputs, directory, policy) {
451
- return __awaiter(this, void 0, void 0, function* () {
452
- const output = [];
453
- for (const input of inputs) {
454
- const pattern = toGlobPattern(input);
455
- if ((0, tinyglobby_1.isDynamicPattern)(pattern, { caseSensitiveMatch: true })) {
456
- const searchDirectory = yield globSearchDirectory(input);
457
- const caseSensitive = yield FileSystemIdentity_1.FileSystemIdentity.inspectDirectory(searchDirectory);
458
- if (caseSensitive === undefined) {
459
- throw new URIError(`Error on TypiaGenerateWizard.generate(): unable to determine filesystem case behavior for input pattern base ${searchDirectory}.`);
460
- }
461
- policy.observe(caseSensitive, searchDirectory);
462
- const identity = policy.get();
463
- const matches = yield (0, tinyglobby_1.glob)(pattern, {
464
- absolute: true,
465
- caseSensitiveMatch: identity.caseSensitive,
466
- cwd: process.cwd(),
467
- onlyFiles: true,
468
- });
469
- if (matches.length === 0) {
470
- throw new URIError(`Error on TypiaGenerateWizard.generate(): input pattern does not match any files: ${input}`);
471
- }
472
- output.push(...excludeOutputFiles(matches, directory, identity).filter((file) => identity.isSupportedExtension(file)));
473
- }
474
- else {
475
- const file = path_1.default.resolve(input);
476
- policy.observe(yield FileSystemIdentity_1.FileSystemIdentity.inspectDirectory(path_1.default.dirname(file)), path_1.default.dirname(file));
477
- if (policy.get().contains(file, directory) === false) {
478
- output.push(file);
479
- }
480
- }
481
- }
482
- return output;
483
- });
484
- }
485
- function excludeOutputFiles(files, directory, identity) {
486
- return files.filter((file) => identity.contains(file, directory) === false);
487
- }
488
- function globSearchDirectory(input) {
489
- return __awaiter(this, void 0, void 0, function* () {
490
- let current = path_1.default.resolve(input);
491
- while ((0, tinyglobby_1.isDynamicPattern)(toGlobPattern(current), { caseSensitiveMatch: true })) {
492
- const parent = path_1.default.dirname(current);
493
- if (parent === current)
494
- break;
495
- current = parent;
496
- }
497
- if (fs_1.default.existsSync(current) && (yield isDirectory(current)))
498
- return current;
499
- return nearestExistingAncestor(path_1.default.dirname(current));
500
- });
501
- }
502
- function toGlobPattern(input) {
503
- return input.replace(/\\/g, "/");
504
- }
505
- function transformProject(props) {
506
- const TtscCompiler = loadTtscCompiler();
507
- const result = new TtscCompiler({
508
- binary: props.binary,
509
- cwd: props.cwd,
510
- projectRoot: props.projectRoot,
511
- tsconfig: props.tsconfig,
512
- }).transform();
513
- if (result.type === "success") {
514
- return result.typescript;
515
- }
516
- if (result.type === "failure") {
517
- throw new URIError(`Error on TypiaGenerateWizard.generate(): ${formatDiagnostics(result.diagnostics)}`);
518
- }
519
- throw new URIError(`Error on TypiaGenerateWizard.generate(): ${formatUnknownError(result.error)}`);
520
- }
521
- function resolveProjectConfigFile(project) {
522
- const resolved = path_1.default.resolve(project);
523
- if (fs_1.default.existsSync(resolved) === false) {
524
- throw new URIError(`Error on TypiaGenerateWizard.generate(): project path does not exist: ${resolved}`);
525
- }
526
- const stat = fs_1.default.statSync(resolved);
527
- if (stat.isDirectory()) {
528
- for (const filename of ["tsconfig.json", "jsconfig.json"]) {
529
- const candidate = path_1.default.join(resolved, filename);
530
- if (fs_1.default.existsSync(candidate) && fs_1.default.statSync(candidate).isFile()) {
531
- return resolveRealPath(candidate);
532
- }
533
- }
534
- throw new URIError(`Error on TypiaGenerateWizard.generate(): project directory has no tsconfig.json or jsconfig.json: ${resolved}`);
535
- }
536
- if (stat.isFile() === false) {
537
- throw new URIError(`Error on TypiaGenerateWizard.generate(): project path is not a file: ${resolved}`);
538
- }
539
- return resolveRealPath(resolved);
540
- }
541
- function findProjectConfigFile(directory) {
542
- let current = path_1.default.resolve(directory);
543
- while (true) {
544
- for (const filename of ["tsconfig.json", "jsconfig.json"]) {
545
- const candidate = path_1.default.join(current, filename);
546
- if (fs_1.default.existsSync(candidate) && fs_1.default.statSync(candidate).isFile()) {
547
- return resolveRealPath(candidate);
548
- }
549
- }
550
- const parent = path_1.default.dirname(current);
551
- if (parent === current) {
552
- return null;
553
- }
554
- current = parent;
555
- }
556
- }
557
- function loadTtscCompiler() {
558
- const packageRoot = resolveTypiaPackageRoot();
559
- const resolved = resolveFromRoots("ttsc", resolveRuntimeRoots(packageRoot));
560
- if (resolved === null) {
561
- throw new URIError(`Error on TypiaGenerateWizard.generate(): unable to resolve ttsc from the current project, typia package, or workspace root. Run "npm i -D ttsc typescript" before.`);
562
- }
563
- const imported = (0, module_1.createRequire)(resolved)(resolved);
564
- return imported.TtscCompiler;
565
- }
566
- function resolveTsgoBinary() {
567
- const explicit = process.env.TTSC_TSGO_BINARY;
568
- if (explicit !== undefined && explicit.length !== 0) {
569
- if (path_1.default.isAbsolute(explicit) && fs_1.default.existsSync(explicit)) {
570
- return explicit;
571
- }
572
- throw new URIError(`Error on TypiaGenerateWizard.generate(): TTSC_TSGO_BINARY must be an existing absolute path: ${explicit}`);
573
- }
574
- const packageRoot = resolveTypiaPackageRoot();
575
- const manifest = resolveFromRoots("typescript/package.json", resolveRuntimeRoots(packageRoot));
576
- if (manifest === null) {
577
- throw new URIError("Error on TypiaGenerateWizard.generate(): unable to resolve typescript from the current project, typia package, or workspace root.");
578
- }
579
- const platform = `@typescript/typescript-${process.platform}-${process.arch}`;
580
- const platformManifest = (0, module_1.createRequire)(manifest).resolve(`${platform}/package.json`);
581
- const binary = path_1.default.join(path_1.default.dirname(platformManifest), "lib", process.platform === "win32" ? "tsc.exe" : "tsc");
582
- if (fs_1.default.existsSync(binary) === false) {
583
- throw new URIError(`Error on TypiaGenerateWizard.generate(): TypeScript-Go executable not found: ${binary}`);
584
- }
585
- return binary;
586
- }
587
- function resolveTypiaPackageRoot() {
588
- var _a;
589
- // The CLI entrypoint (`lib/executable/typia.js`) lives in the same
590
- // directory as this module, so its `process.argv[1]` path anchors the
591
- // walk-up identically in both the CJS and ESM builds — `__dirname` does
592
- // not exist in the transcoded `.mjs`.
593
- const current = path_1.default.dirname(path_1.default.resolve((_a = process.argv[1]) !== null && _a !== void 0 ? _a : ""));
594
- for (const directory of [
595
- path_1.default.resolve(current, "..", ".."),
596
- path_1.default.resolve(current, ".."),
597
- ]) {
598
- const file = path_1.default.join(directory, "package.json");
599
- if (fs_1.default.existsSync(file) === false) {
600
- continue;
601
- }
602
- try {
603
- const pack = JSON.parse(fs_1.default.readFileSync(file, "utf8"));
604
- if (pack.name === "typia") {
605
- return directory;
606
- }
607
- }
608
- catch (_b) {
609
- continue;
610
- }
611
- }
612
- const resolved = resolveFromRoots("typia/package.json", [
613
- process.cwd(),
614
- current,
615
- ]);
616
- if (resolved === null) {
617
- throw new URIError("Error on TypiaGenerateWizard.generate(): unable to resolve typia package root.");
618
- }
619
- return path_1.default.dirname(resolved);
620
- }
621
- function resolveRuntimeRoots(packageRoot) {
622
- return [process.cwd(), packageRoot, path_1.default.resolve(packageRoot, "..", "..")];
623
- }
624
- function resolveFromRoots(request, roots) {
625
- for (const root of roots) {
626
- try {
627
- return (0, module_1.createRequire)(path_1.default.join(root, "package.json")).resolve(request);
628
- }
629
- catch (_a) {
630
- continue;
631
- }
632
- }
633
- return null;
634
- }
635
- function isDirectory(current) {
636
- return __awaiter(this, void 0, void 0, function* () {
637
- const stat = yield fs_1.default.promises.stat(current);
638
- return stat.isDirectory();
639
- });
640
- }
641
- function isFile(current) {
642
- return __awaiter(this, void 0, void 0, function* () {
643
- const stat = yield fs_1.default.promises.stat(current);
644
- return stat.isFile();
645
- });
646
- }
647
- function gather(props) {
648
- return __awaiter(this, void 0, void 0, function* () {
649
- const currentReal = yield resolveTraversalPath(props.from);
650
- if (props.outputReal !== undefined &&
651
- isPhysicalSameOrChildPath(currentReal, props.outputReal))
652
- return;
653
- ensurePhysicalInputContainment({
654
- file: props.from,
655
- input: props.inputReal,
656
- real: currentReal,
657
- });
658
- const currentStat = yield fs_1.default.promises.stat(props.from, {
659
- bigint: true,
660
- });
661
- const directoryIdentity = fileIdentityKey(currentStat, currentReal);
662
- if (props.visitedDirectories.has(directoryIdentity)) {
663
- const lexicalStat = yield fs_1.default.promises.lstat(props.from);
664
- if (lexicalStat.isSymbolicLink()) {
665
- throw new URIError(`Error on TypiaGenerateWizard.generate(): input directory link revisits a physical directory: ${props.from}.`);
666
- }
667
- return;
668
- }
669
- props.visitedDirectories.add(directoryIdentity);
670
- props.policy.observe(yield FileSystemIdentity_1.FileSystemIdentity.inspectDirectory(props.from), props.from);
671
- const identity = props.policy.get();
672
- const entries = yield Promise.all((yield fs_1.default.promises.readdir(props.from)).map((name) => __awaiter(this, void 0, void 0, function* () {
673
- const file = path_1.default.join(props.from, name);
674
- try {
675
- return { file, name, stat: yield fs_1.default.promises.lstat(file) };
676
- }
677
- catch (error) {
678
- throw new URIError(`Error on TypiaGenerateWizard.generate(): unable to inspect input path ${file}: ${formatUnknownError(error)}`);
679
- }
680
- })));
681
- entries.sort((x, y) => {
682
- const linkOrder = Number(x.stat.isSymbolicLink()) - Number(y.stat.isSymbolicLink());
683
- return linkOrder !== 0
684
- ? linkOrder
685
- : Buffer.compare(Buffer.from(x.name), Buffer.from(y.name));
686
- });
687
- for (const entry of entries) {
688
- let stat;
689
- let real;
690
- try {
691
- stat = yield fs_1.default.promises.stat(entry.file, { bigint: true });
692
- real = yield fs_1.default.promises.realpath(entry.file);
693
- }
694
- catch (error) {
695
- throw new URIError(`Error on TypiaGenerateWizard.generate(): input link target is missing or unreadable: ${entry.file}: ${formatUnknownError(error)}`);
696
- }
697
- if (props.outputReal !== undefined &&
698
- isPhysicalSameOrChildPath(real, props.outputReal))
699
- continue;
700
- ensurePhysicalInputContainment({
701
- file: entry.file,
702
- input: props.inputReal,
703
- real,
704
- });
705
- if (stat.isDirectory()) {
706
- yield gather(Object.assign(Object.assign({}, props), { from: entry.file }));
707
- continue;
708
- }
709
- if (stat.isFile() === false ||
710
- identity.isSupportedExtension(entry.name) === false)
711
- continue;
712
- const fileIdentity = fileIdentityKey(stat, real);
713
- if (props.visitedFiles.has(fileIdentity))
714
- continue;
715
- props.visitedFiles.add(fileIdentity);
716
- props.container.push(entry.file);
717
- }
718
- });
719
- }
720
- function formatOutput(output) {
721
- return output.startsWith("// @ts-nocheck")
722
- ? output
723
- : `// @ts-nocheck\n${output}`;
724
- }
725
- function indexTransformedOutputs(outputs, identity) {
726
- const map = new Map();
727
- for (const [file, output] of Object.entries(outputs)) {
728
- const key = identity.projectFileKey(file);
729
- if (map.has(key)) {
730
- throw new URIError(`Error on TypiaGenerateWizard.generate(): transformed outputs have ambiguous filesystem identities: ${file}.`);
731
- }
732
- map.set(key, output);
733
- }
734
- return map;
735
- }
736
- function getTransformedOutput(props) {
737
- const output = props.outputByKey.get(props.identity.projectFileKey(projectKey(props.cwd, props.entry.file)));
738
- if (output !== undefined) {
739
- return output;
740
- }
741
- const compilerFile = compilerInputPath(props.entry.file);
742
- if (props.identity.isSamePath(compilerFile, props.entry.file) === false &&
743
- props.identity.contains(compilerFile, props.cwd)) {
744
- const compiled = props.outputByKey.get(props.identity.projectFileKey(projectKey(props.cwd, compilerFile)));
745
- if (compiled !== undefined)
746
- return compiled;
747
- }
748
- const real = resolveRealPath(props.entry.file);
749
- if (props.identity.isSamePath(real, props.entry.file) ||
750
- props.identity.contains(real, props.cwd) === false) {
751
- return undefined;
752
- }
753
- return props.outputByKey.get(props.identity.projectFileKey(projectKey(props.cwd, real)));
754
- }
755
- function projectKey(root, file) {
756
- return path_1.default.relative(root, file).replace(/\\/g, "/");
757
- }
758
- function resolveRealPath(file) {
759
- try {
760
- return fs_1.default.realpathSync(file);
761
- }
762
- catch (_a) {
763
- return file;
764
- }
765
- }
766
- function compilerInputPath(file) {
767
- try {
768
- if (fs_1.default.lstatSync(file).isSymbolicLink()) {
769
- return path_1.default.join(resolveRealPath(path_1.default.dirname(file)), path_1.default.basename(file));
770
- }
771
- }
772
- catch (_a) {
773
- return file;
774
- }
775
- return resolveRealPath(file);
776
- }
777
- function optionalRealPath(file) {
778
- return __awaiter(this, void 0, void 0, function* () {
779
- try {
780
- return yield fs_1.default.promises.realpath(file);
781
- }
782
- catch (error) {
783
- if (isMissingFileError(error))
784
- return undefined;
785
- throw new URIError(`Error on TypiaGenerateWizard.generate(): unable to resolve path ${file}: ${formatUnknownError(error)}`);
786
- }
787
- });
788
- }
789
- function resolveTraversalPath(file) {
790
- return __awaiter(this, void 0, void 0, function* () {
791
- try {
792
- return yield fs_1.default.promises.realpath(file);
793
- }
794
- catch (error) {
795
- throw new URIError(`Error on TypiaGenerateWizard.generate(): unable to resolve input path ${file}: ${formatUnknownError(error)}`);
796
- }
797
- });
798
- }
799
- function ensurePhysicalInputContainment(props) {
800
- if (isPhysicalSameOrChildPath(props.real, props.input))
801
- return;
802
- throw new URIError(`Error on TypiaGenerateWizard.generate(): input path resolves outside the input directory: ${props.file}.`);
803
- }
804
- function isPhysicalSameOrChildPath(file, directory) {
805
- const relative = path_1.default.relative(directory, file);
806
- return (relative === "" ||
807
- (relative !== ".." &&
808
- relative.startsWith(`..${path_1.default.sep}`) === false &&
809
- path_1.default.isAbsolute(relative) === false));
810
- }
811
- function isMissingFileError(exp) {
812
- return (typeof exp === "object" &&
813
- exp !== null &&
814
- "code" in exp &&
815
- exp.code === "ENOENT");
816
- }
817
- /**
818
- * Delegates to {@link FileSystemIdentity.identityKey}, which owns the rule and
819
- * carries the reasoning for reading the identity as a `bigint`.
820
- */
821
- function fileIdentityKey(stat, realpath) {
822
- return FileSystemIdentity_1.FileSystemIdentity.identityKey(stat, realpath);
823
- }
824
- function formatDiagnostics(diagnostics) {
825
- return diagnostics.length === 0
826
- ? "transformation failed"
827
- : diagnostics
828
- .map((diag) => { var _a, _b; return [
829
- (_a = diag.file) !== null && _a !== void 0 ? _a : "ttsc",
830
- diag.line === undefined
831
- ? undefined
832
- : `${diag.line}:${(_b = diag.character) !== null && _b !== void 0 ? _b : 1}`,
833
- diag.messageText,
834
- ]
835
- .filter((part) => part !== undefined && part !== "")
836
- .join(": "); })
837
- .join("\n");
838
- }
839
- function formatUnknownError(error) {
840
- if (error instanceof Error) {
841
- return error.message;
842
- }
843
- if (typeof error === "object" &&
844
- error !== null &&
845
- "message" in error &&
846
- typeof error.message === "string") {
847
- return error.message;
848
- }
849
- return String(error);
850
- }
851
- })(TypiaGenerateWizard || (exports.TypiaGenerateWizard = TypiaGenerateWizard = {}));
852
- //# sourceMappingURL=TypiaGenerateWizard.js.map