@medusajs/http-types-generator 2.13.6-preview-20260402101111
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/README.md +135 -0
- package/dist/__tests__/compatibility-checker.spec.d.ts +2 -0
- package/dist/__tests__/compatibility-checker.spec.d.ts.map +1 -0
- package/dist/__tests__/compatibility-checker.spec.js +231 -0
- package/dist/__tests__/compatibility-checker.spec.js.map +1 -0
- package/dist/__tests__/config.spec.d.ts +2 -0
- package/dist/__tests__/config.spec.d.ts.map +1 -0
- package/dist/__tests__/config.spec.js +78 -0
- package/dist/__tests__/config.spec.js.map +1 -0
- package/dist/__tests__/import-tracker.spec.d.ts +2 -0
- package/dist/__tests__/import-tracker.spec.d.ts.map +1 -0
- package/dist/__tests__/import-tracker.spec.js +25 -0
- package/dist/__tests__/import-tracker.spec.js.map +1 -0
- package/dist/__tests__/name-classifier.spec.d.ts +2 -0
- package/dist/__tests__/name-classifier.spec.d.ts.map +1 -0
- package/dist/__tests__/name-classifier.spec.js +77 -0
- package/dist/__tests__/name-classifier.spec.js.map +1 -0
- package/dist/__tests__/name-registry.spec.d.ts +2 -0
- package/dist/__tests__/name-registry.spec.d.ts.map +1 -0
- package/dist/__tests__/name-registry.spec.js +67 -0
- package/dist/__tests__/name-registry.spec.js.map +1 -0
- package/dist/__tests__/path-mapper.spec.d.ts +2 -0
- package/dist/__tests__/path-mapper.spec.d.ts.map +1 -0
- package/dist/__tests__/path-mapper.spec.js +98 -0
- package/dist/__tests__/path-mapper.spec.js.map +1 -0
- package/dist/__tests__/type-emitter.spec.d.ts +2 -0
- package/dist/__tests__/type-emitter.spec.d.ts.map +1 -0
- package/dist/__tests__/type-emitter.spec.js +173 -0
- package/dist/__tests__/type-emitter.spec.js.map +1 -0
- package/dist/__tests__/type-pipeline.spec.d.ts +2 -0
- package/dist/__tests__/type-pipeline.spec.d.ts.map +1 -0
- package/dist/__tests__/type-pipeline.spec.js +239 -0
- package/dist/__tests__/type-pipeline.spec.js.map +1 -0
- package/dist/__tests__/utils/ts-utils.d.ts +22 -0
- package/dist/__tests__/utils/ts-utils.d.ts.map +1 -0
- package/dist/__tests__/utils/ts-utils.js +66 -0
- package/dist/__tests__/utils/ts-utils.js.map +1 -0
- package/dist/commands/generate.d.ts +10 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +215 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/validate.d.ts +14 -0
- package/dist/commands/validate.d.ts.map +1 -0
- package/dist/commands/validate.js +201 -0
- package/dist/commands/validate.js.map +1 -0
- package/dist/config/index.d.ts +52 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +119 -0
- package/dist/config/index.js.map +1 -0
- package/dist/core/compatibility-checker.d.ts +92 -0
- package/dist/core/compatibility-checker.d.ts.map +1 -0
- package/dist/core/compatibility-checker.js +415 -0
- package/dist/core/compatibility-checker.js.map +1 -0
- package/dist/core/import-tracker.d.ts +11 -0
- package/dist/core/import-tracker.d.ts.map +1 -0
- package/dist/core/import-tracker.js +17 -0
- package/dist/core/import-tracker.js.map +1 -0
- package/dist/core/program-factory.d.ts +23 -0
- package/dist/core/program-factory.d.ts.map +1 -0
- package/dist/core/program-factory.js +80 -0
- package/dist/core/program-factory.js.map +1 -0
- package/dist/core/schema-extractor.d.ts +73 -0
- package/dist/core/schema-extractor.d.ts.map +1 -0
- package/dist/core/schema-extractor.js +205 -0
- package/dist/core/schema-extractor.js.map +1 -0
- package/dist/core/type-emitter.d.ts +73 -0
- package/dist/core/type-emitter.d.ts.map +1 -0
- package/dist/core/type-emitter.js +246 -0
- package/dist/core/type-emitter.js.map +1 -0
- package/dist/core/type-resolver.d.ts +64 -0
- package/dist/core/type-resolver.d.ts.map +1 -0
- package/dist/core/type-resolver.js +163 -0
- package/dist/core/type-resolver.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/mapping/name-classifier.d.ts +34 -0
- package/dist/mapping/name-classifier.d.ts.map +1 -0
- package/dist/mapping/name-classifier.js +72 -0
- package/dist/mapping/name-classifier.js.map +1 -0
- package/dist/mapping/name-registry.d.ts +54 -0
- package/dist/mapping/name-registry.d.ts.map +1 -0
- package/dist/mapping/name-registry.js +251 -0
- package/dist/mapping/name-registry.js.map +1 -0
- package/dist/mapping/path-mapper.d.ts +62 -0
- package/dist/mapping/path-mapper.d.ts.map +1 -0
- package/dist/mapping/path-mapper.js +116 -0
- package/dist/mapping/path-mapper.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utils/file-merger.d.ts +47 -0
- package/dist/utils/file-merger.d.ts.map +1 -0
- package/dist/utils/file-merger.js +164 -0
- package/dist/utils/file-merger.js.map +1 -0
- package/dist/utils/formatter.d.ts +12 -0
- package/dist/utils/formatter.d.ts.map +1 -0
- package/dist/utils/formatter.js +31 -0
- package/dist/utils/formatter.js.map +1 -0
- package/dist/utils/fs-helpers.d.ts +21 -0
- package/dist/utils/fs-helpers.d.ts.map +1 -0
- package/dist/utils/fs-helpers.js +42 -0
- package/dist/utils/fs-helpers.js.map +1 -0
- package/dist/utils/index-manager.d.ts +24 -0
- package/dist/utils/index-manager.d.ts.map +1 -0
- package/dist/utils/index-manager.js +95 -0
- package/dist/utils/index-manager.js.map +1 -0
- package/dist/utils/ts-helpers.d.ts +87 -0
- package/dist/utils/ts-helpers.d.ts.map +1 -0
- package/dist/utils/ts-helpers.js +216 -0
- package/dist/utils/ts-helpers.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileMerger = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const formatter_1 = require("./formatter");
|
|
6
|
+
const type_emitter_1 = require("../core/type-emitter");
|
|
7
|
+
/**
|
|
8
|
+
* Decides whether to create, merge, or overwrite a type file.
|
|
9
|
+
*/
|
|
10
|
+
class FileMerger {
|
|
11
|
+
/**
|
|
12
|
+
* Decides whether to create, merge, or overwrite a type file.
|
|
13
|
+
*
|
|
14
|
+
* - File does not exist → create (write all interfaces)
|
|
15
|
+
* - File exists + `force` → overwrite (write all interfaces, replacing existing)
|
|
16
|
+
* - File exists, not `force` → merge: add only interfaces not already declared
|
|
17
|
+
*
|
|
18
|
+
* Returns the final file content plus a status code.
|
|
19
|
+
*/
|
|
20
|
+
async resolveFileContent(file, interfaces, importTracker, force) {
|
|
21
|
+
const raw = type_emitter_1.TypeEmitter.assembleFile(interfaces, importTracker, file);
|
|
22
|
+
const generated = raw;
|
|
23
|
+
const { existsSync } = await import("fs");
|
|
24
|
+
if (!existsSync(file)) {
|
|
25
|
+
const content = await formatter_1.Formatter.format(generated, file);
|
|
26
|
+
return { content, status: "created", added: interfaces.length };
|
|
27
|
+
}
|
|
28
|
+
if (force) {
|
|
29
|
+
const content = await formatter_1.Formatter.format(generated, file);
|
|
30
|
+
return { content, status: "overwritten", added: interfaces.length };
|
|
31
|
+
}
|
|
32
|
+
const existingContent = (0, fs_1.readFileSync)(file, "utf-8");
|
|
33
|
+
const existingBlocks = this.extractInterfaceBlocks(existingContent);
|
|
34
|
+
const newInterfaces = interfaces.filter(({ name }) => !existingBlocks.has(name));
|
|
35
|
+
if (newInterfaces.length === 0) {
|
|
36
|
+
return { content: existingContent, status: "skipped", added: 0 };
|
|
37
|
+
}
|
|
38
|
+
const generatedBlocks = this.extractInterfaceBlocks(generated);
|
|
39
|
+
const existingBodyLines = existingContent
|
|
40
|
+
.split("\n")
|
|
41
|
+
.filter((l) => !l.trim().startsWith("import "));
|
|
42
|
+
const newBlocks = newInterfaces
|
|
43
|
+
.map(({ name }) => generatedBlocks.get(name) ?? "")
|
|
44
|
+
.filter(Boolean);
|
|
45
|
+
const existingImportLines = this.extractImportLines(existingContent);
|
|
46
|
+
const generatedImportLines = this.extractImportLines(generated);
|
|
47
|
+
const mergedImports = this.mergeImportLines(existingImportLines, generatedImportLines);
|
|
48
|
+
const parts = [];
|
|
49
|
+
if (mergedImports.length > 0) {
|
|
50
|
+
parts.push(mergedImports.join("\n"));
|
|
51
|
+
parts.push("");
|
|
52
|
+
}
|
|
53
|
+
parts.push(existingBodyLines.join("\n").trimStart());
|
|
54
|
+
parts.push("");
|
|
55
|
+
parts.push(newBlocks.join("\n\n"));
|
|
56
|
+
const merged = parts.join("\n");
|
|
57
|
+
const content = await formatter_1.Formatter.format(merged, file);
|
|
58
|
+
return { content, status: "updated", added: newInterfaces.length };
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Parses a named import line of the form:
|
|
62
|
+
* `import { A, B } from "source"`
|
|
63
|
+
* `import type { A, B } from "source"`
|
|
64
|
+
*
|
|
65
|
+
* Returns null for default imports, side-effect imports, or anything else.
|
|
66
|
+
*/
|
|
67
|
+
parseImportLine(line) {
|
|
68
|
+
const typeRe = /^import\s+type\s+\{\s*([^}]+)\}\s+from\s+["']([^"']+)["']/;
|
|
69
|
+
const normalRe = /^import\s+\{\s*([^}]+)\}\s+from\s+["']([^"']+)["']/;
|
|
70
|
+
const typeMatch = line.trim().match(typeRe);
|
|
71
|
+
const normalMatch = line.trim().match(normalRe);
|
|
72
|
+
const m = typeMatch ?? normalMatch;
|
|
73
|
+
if (!m)
|
|
74
|
+
return null;
|
|
75
|
+
return {
|
|
76
|
+
isType: !!typeMatch,
|
|
77
|
+
names: m[1]
|
|
78
|
+
.split(",")
|
|
79
|
+
.map((n) => n.trim())
|
|
80
|
+
.filter(Boolean),
|
|
81
|
+
source: m[2],
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Merges two sets of import lines, combining named imports for the same
|
|
86
|
+
* source so we never emit duplicate import statements.
|
|
87
|
+
*/
|
|
88
|
+
mergeImportLines(existingLines, newLines) {
|
|
89
|
+
const map = new Map();
|
|
90
|
+
const unparseable = [];
|
|
91
|
+
const process = (line) => {
|
|
92
|
+
const t = line.trim();
|
|
93
|
+
if (!t)
|
|
94
|
+
return;
|
|
95
|
+
const parsed = this.parseImportLine(t);
|
|
96
|
+
if (!parsed) {
|
|
97
|
+
if (t.startsWith("import ") && !unparseable.includes(t)) {
|
|
98
|
+
unparseable.push(t);
|
|
99
|
+
}
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const key = `${parsed.isType ? "type:" : ""}${parsed.source}`;
|
|
103
|
+
if (!map.has(key)) {
|
|
104
|
+
map.set(key, { isType: parsed.isType, names: new Set() });
|
|
105
|
+
}
|
|
106
|
+
for (const name of parsed.names) {
|
|
107
|
+
map.get(key).names.add(name);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
for (const l of existingLines)
|
|
111
|
+
process(l);
|
|
112
|
+
for (const l of newLines)
|
|
113
|
+
process(l);
|
|
114
|
+
const result = [];
|
|
115
|
+
for (const [key, { isType, names }] of map) {
|
|
116
|
+
const source = key.replace(/^type:/, "");
|
|
117
|
+
const namesList = [...names].sort().join(", ");
|
|
118
|
+
result.push(`${isType ? "import type" : "import"} { ${namesList} } from "${source}"`);
|
|
119
|
+
}
|
|
120
|
+
result.push(...unparseable);
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Scans `content` for `export interface Name ...` blocks and returns a map
|
|
125
|
+
* from interface name to the full block text.
|
|
126
|
+
*/
|
|
127
|
+
extractInterfaceBlocks(content) {
|
|
128
|
+
const blocks = new Map();
|
|
129
|
+
const lines = content.split("\n");
|
|
130
|
+
let i = 0;
|
|
131
|
+
while (i < lines.length) {
|
|
132
|
+
const m = lines[i].match(/^export\s+interface\s+(\w+)/);
|
|
133
|
+
if (m) {
|
|
134
|
+
const name = m[1];
|
|
135
|
+
let block = "";
|
|
136
|
+
let depth = 0;
|
|
137
|
+
while (i < lines.length) {
|
|
138
|
+
const line = lines[i];
|
|
139
|
+
block += line + "\n";
|
|
140
|
+
depth +=
|
|
141
|
+
(line.match(/\{/g) ?? []).length - (line.match(/\}/g) ?? []).length;
|
|
142
|
+
i++;
|
|
143
|
+
if (depth === 0 && block.trim())
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
blocks.set(name, block.trimEnd());
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
i++;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return blocks;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Extracts all `import ...` lines from the file content.
|
|
156
|
+
*/
|
|
157
|
+
extractImportLines(content) {
|
|
158
|
+
return content
|
|
159
|
+
.split("\n")
|
|
160
|
+
.filter((l) => l.trim().startsWith("import "));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.FileMerger = FileMerger;
|
|
164
|
+
//# sourceMappingURL=file-merger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-merger.js","sourceRoot":"","sources":["../../src/utils/file-merger.ts"],"names":[],"mappings":";;;AAAA,2BAAiC;AACjC,2CAAuC;AAEvC,uDAAkD;AAkBlD;;GAEG;AACH,MAAa,UAAU;IACrB;;;;;;;;OAQG;IACH,KAAK,CAAC,kBAAkB,CACtB,IAAY,EACZ,UAA8B,EAC9B,aAA4B,EAC5B,KAAc;QAEd,MAAM,GAAG,GAAG,0BAAW,CAAC,YAAY,CAAC,UAAU,EAAE,aAAa,EAAE,IAAI,CAAC,CAAA;QACrE,MAAM,SAAS,GAAG,GAAG,CAAA;QAErB,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,CAAA;QACzC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACtB,MAAM,OAAO,GAAG,MAAM,qBAAS,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAA;YACvD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK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,CAAC;gBACN,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;gBACjB,IAAI,KAAK,GAAG,EAAE,CAAA;gBACd,IAAI,KAAK,GAAG,CAAC,CAAA;gBAEb,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;oBACxB,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;oBACrB,KAAK,IAAI,IAAI,GAAG,IAAI,CAAA;oBACpB,KAAK;wBACH,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAA;oBACrE,CAAC,EAAE,CAAA;oBACH,IAAI,KAAK,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,EAAE;wBAAE,MAAK;gBACxC,CAAC;gBAED,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YACnC,CAAC;iBAAM,CAAC;gBACN,CAAC,EAAE,CAAA;YACL,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC;IAED;;OAEG;IACK,kBAAkB,CAAC,OAAe;QACxC,OAAO,OAAO;aACX,KAAK,CAAC,IAAI,CAAC;aACX,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAA;IAClD,CAAC;CACF;AA1LD,gCA0LC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class Formatter {
|
|
2
|
+
/**
|
|
3
|
+
* Formats `content` using the Prettier config resolved for `filePath`.
|
|
4
|
+
* The `filePath` is used both to resolve the nearest `.prettierrc` and
|
|
5
|
+
* to let Prettier pick the correct parser (e.g. `typescript` for `.ts`).
|
|
6
|
+
*
|
|
7
|
+
* Returns the formatted content, or the original content if Prettier
|
|
8
|
+
* cannot parse or format it.
|
|
9
|
+
*/
|
|
10
|
+
static format(content: string, filePath: string): Promise<string>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/utils/formatter.ts"],"names":[],"mappings":"AAEA,qBAAa,SAAS;IACpB;;;;;;;OAOG;WACU,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAWxE"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Formatter = void 0;
|
|
7
|
+
const prettier_1 = __importDefault(require("prettier"));
|
|
8
|
+
class Formatter {
|
|
9
|
+
/**
|
|
10
|
+
* Formats `content` using the Prettier config resolved for `filePath`.
|
|
11
|
+
* The `filePath` is used both to resolve the nearest `.prettierrc` and
|
|
12
|
+
* to let Prettier pick the correct parser (e.g. `typescript` for `.ts`).
|
|
13
|
+
*
|
|
14
|
+
* Returns the formatted content, or the original content if Prettier
|
|
15
|
+
* cannot parse or format it.
|
|
16
|
+
*/
|
|
17
|
+
static async format(content, filePath) {
|
|
18
|
+
try {
|
|
19
|
+
const config = (await prettier_1.default.resolveConfig(filePath)) || undefined;
|
|
20
|
+
if (config && !config.parser) {
|
|
21
|
+
config.parser = "babel-ts";
|
|
22
|
+
}
|
|
23
|
+
return await prettier_1.default.format(content, config);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return content;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.Formatter = Formatter;
|
|
31
|
+
//# sourceMappingURL=formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../src/utils/formatter.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA+B;AAE/B,MAAa,SAAS;IACpB;;;;;;;OAOG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAe,EAAE,QAAgB;QACnD,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,CAAC,MAAM,kBAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,IAAI,SAAS,CAAA;YACpE,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;gBAC7B,MAAM,CAAC,MAAM,GAAG,UAAU,CAAA;YAC5B,CAAC;YACD,OAAO,MAAM,kBAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QAC/C,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,OAAO,CAAA;QAChB,CAAC;IACH,CAAC;CACF;AApBD,8BAoBC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare class FsHelpers {
|
|
2
|
+
/**
|
|
3
|
+
* Returns the absolute path to the project root.
|
|
4
|
+
* Determined by searching upward for `http-types.config.json`; falls back
|
|
5
|
+
* to `process.cwd()` when no config file is found.
|
|
6
|
+
*/
|
|
7
|
+
static getProjectRoot(): string;
|
|
8
|
+
/**
|
|
9
|
+
* Ensures a directory exists, creating it recursively if needed.
|
|
10
|
+
*/
|
|
11
|
+
static ensureDir(dirPath: string): void;
|
|
12
|
+
/**
|
|
13
|
+
* Writes content to a file, creating intermediate directories as needed.
|
|
14
|
+
*/
|
|
15
|
+
static writeFile(filePath: string, content: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* Resolves a path relative to the project root.
|
|
18
|
+
*/
|
|
19
|
+
static fromRoot(...segments: string[]): string;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=fs-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs-helpers.d.ts","sourceRoot":"","sources":["../../src/utils/fs-helpers.ts"],"names":[],"mappings":"AAIA,qBAAa,SAAS;IACpB;;;;OAIG;IACH,MAAM,CAAC,cAAc,IAAI,MAAM;IAI/B;;OAEG;IACH,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAMvC;;OAEG;IACH,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAKzD;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM;CAG/C"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FsHelpers = void 0;
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const config_1 = require("../config");
|
|
10
|
+
class FsHelpers {
|
|
11
|
+
/**
|
|
12
|
+
* Returns the absolute path to the project root.
|
|
13
|
+
* Determined by searching upward for `http-types.config.json`; falls back
|
|
14
|
+
* to `process.cwd()` when no config file is found.
|
|
15
|
+
*/
|
|
16
|
+
static getProjectRoot() {
|
|
17
|
+
return config_1.Config.get().projectRoot;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Ensures a directory exists, creating it recursively if needed.
|
|
21
|
+
*/
|
|
22
|
+
static ensureDir(dirPath) {
|
|
23
|
+
if (!(0, fs_1.existsSync)(dirPath)) {
|
|
24
|
+
(0, fs_1.mkdirSync)(dirPath, { recursive: true });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Writes content to a file, creating intermediate directories as needed.
|
|
29
|
+
*/
|
|
30
|
+
static writeFile(filePath, content) {
|
|
31
|
+
FsHelpers.ensureDir(path_1.default.dirname(filePath));
|
|
32
|
+
(0, fs_1.writeFileSync)(filePath, content, "utf-8");
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Resolves a path relative to the project root.
|
|
36
|
+
*/
|
|
37
|
+
static fromRoot(...segments) {
|
|
38
|
+
return path_1.default.join(FsHelpers.getProjectRoot(), ...segments);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.FsHelpers = FsHelpers;
|
|
42
|
+
//# sourceMappingURL=fs-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs-helpers.js","sourceRoot":"","sources":["../../src/utils/fs-helpers.ts"],"names":[],"mappings":";;;;;;AAAA,2BAAyD;AACzD,gDAAuB;AACvB,sCAAkC;AAElC,MAAa,SAAS;IACpB;;;;OAIG;IACH,MAAM,CAAC,cAAc;QACnB,OAAO,eAAM,CAAC,GAAG,EAAE,CAAC,WAAW,CAAA;IACjC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,SAAS,CAAC,OAAe;QAC9B,IAAI,CAAC,IAAA,eAAU,EAAC,OAAO,CAAC,EAAE,CAAC;YACzB,IAAA,cAAS,EAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QACzC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,SAAS,CAAC,QAAgB,EAAE,OAAe;QAChD,SAAS,CAAC,SAAS,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;QAC3C,IAAA,kBAAa,EAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IAC3C,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,GAAG,QAAkB;QACnC,OAAO,cAAI,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,EAAE,GAAG,QAAQ,CAAC,CAAA;IAC3D,CAAC;CACF;AAjCD,8BAiCC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { PathMapping } from "../mapping/path-mapper";
|
|
2
|
+
/**
|
|
3
|
+
* Manages barrel export index files for the HTTP types package.
|
|
4
|
+
*/
|
|
5
|
+
export declare class IndexManager {
|
|
6
|
+
/**
|
|
7
|
+
* After a payloads.ts or queries.ts file is written, ensures all index files
|
|
8
|
+
* in the chain are up to date:
|
|
9
|
+
*
|
|
10
|
+
* 1. `{domain}/{area}/index.ts` — exports the written file stem
|
|
11
|
+
* 2. `{domain}/index.ts` — exports `./{area}`
|
|
12
|
+
* 3. `packages/core/types/src/http/index.ts` — exports `./{domain}`
|
|
13
|
+
*
|
|
14
|
+
* In dry-run mode nothing is written; changes are only logged.
|
|
15
|
+
*/
|
|
16
|
+
updateIndexFiles(mapping: PathMapping, writtenLabel: string, dryRun: boolean): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Ensures `export * from "./{stem}"` is present in `indexFile`.
|
|
19
|
+
* Creates the file if it doesn't exist; appends the line if it's missing.
|
|
20
|
+
* Returns true if a change was made (or would be made in dry-run).
|
|
21
|
+
*/
|
|
22
|
+
private ensureExport;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=index-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-manager.d.ts","sourceRoot":"","sources":["../../src/utils/index-manager.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAEzD;;GAEG;AACH,qBAAa,YAAY;IACvB;;;;;;;;;OASG;IACG,gBAAgB,CACpB,OAAO,EAAE,WAAW,EACpB,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,IAAI,CAAC;IA+DhB;;;;OAIG;YACW,YAAY;CA+B3B"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.IndexManager = void 0;
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
+
const fs_helpers_1 = require("./fs-helpers");
|
|
11
|
+
const formatter_1 = require("./formatter");
|
|
12
|
+
const config_1 = require("../config");
|
|
13
|
+
/**
|
|
14
|
+
* Manages barrel export index files for the HTTP types package.
|
|
15
|
+
*/
|
|
16
|
+
class IndexManager {
|
|
17
|
+
/**
|
|
18
|
+
* After a payloads.ts or queries.ts file is written, ensures all index files
|
|
19
|
+
* in the chain are up to date:
|
|
20
|
+
*
|
|
21
|
+
* 1. `{domain}/{area}/index.ts` — exports the written file stem
|
|
22
|
+
* 2. `{domain}/index.ts` — exports `./{area}`
|
|
23
|
+
* 3. `packages/core/types/src/http/index.ts` — exports `./{domain}`
|
|
24
|
+
*
|
|
25
|
+
* In dry-run mode nothing is written; changes are only logged.
|
|
26
|
+
*/
|
|
27
|
+
async updateIndexFiles(mapping, writtenLabel, dryRun) {
|
|
28
|
+
const HTTP_ROOT_INDEX = fs_helpers_1.FsHelpers.fromRoot(config_1.Config.get().outputBase, "index.ts");
|
|
29
|
+
const { outputDir, area, domain } = mapping;
|
|
30
|
+
const domainDir = path_1.default.dirname(outputDir);
|
|
31
|
+
const areaIndexFile = path_1.default.join(outputDir, "index.ts");
|
|
32
|
+
const domainIndexFile = path_1.default.join(domainDir, "index.ts");
|
|
33
|
+
const relArea = path_1.default.relative(process.cwd(), areaIndexFile);
|
|
34
|
+
const relDomain = path_1.default.relative(process.cwd(), domainIndexFile);
|
|
35
|
+
const relRoot = path_1.default.relative(process.cwd(), HTTP_ROOT_INDEX);
|
|
36
|
+
const areaChanged = await this.ensureExport(areaIndexFile, writtenLabel, dryRun);
|
|
37
|
+
if (areaChanged) {
|
|
38
|
+
if (dryRun) {
|
|
39
|
+
console.log(chalk_1.default.cyan(` [dry-run] ${relArea}`) +
|
|
40
|
+
chalk_1.default.gray(` ← add export * from "./${writtenLabel}"`));
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
console.log(chalk_1.default.green(` Update ${relArea}`));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const domainChanged = await this.ensureExport(domainIndexFile, area, dryRun);
|
|
47
|
+
if (domainChanged) {
|
|
48
|
+
if (dryRun) {
|
|
49
|
+
console.log(chalk_1.default.cyan(` [dry-run] ${relDomain}`) +
|
|
50
|
+
chalk_1.default.gray(` ← add export * from "./${area}"`));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
console.log(chalk_1.default.green(` Update ${relDomain}`));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const rootChanged = await this.ensureExport(HTTP_ROOT_INDEX, domain, dryRun);
|
|
57
|
+
if (rootChanged) {
|
|
58
|
+
if (dryRun) {
|
|
59
|
+
console.log(chalk_1.default.cyan(` [dry-run] ${relRoot}`) +
|
|
60
|
+
chalk_1.default.gray(` ← add export * from "./${domain}"`));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.log(chalk_1.default.green(` Update ${relRoot}`));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Ensures `export * from "./{stem}"` is present in `indexFile`.
|
|
69
|
+
* Creates the file if it doesn't exist; appends the line if it's missing.
|
|
70
|
+
* Returns true if a change was made (or would be made in dry-run).
|
|
71
|
+
*/
|
|
72
|
+
async ensureExport(indexFile, stem, dryRun) {
|
|
73
|
+
const exportLine = `export * from "./${stem}"`;
|
|
74
|
+
if (!(0, fs_1.existsSync)(indexFile)) {
|
|
75
|
+
const content = await formatter_1.Formatter.format(`${exportLine}\n`, indexFile);
|
|
76
|
+
if (!dryRun) {
|
|
77
|
+
fs_helpers_1.FsHelpers.writeFile(indexFile, content);
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
const existing = (0, fs_1.readFileSync)(indexFile, "utf-8");
|
|
82
|
+
const alreadyPresent = new RegExp(`export\\s+\\*\\s+from\\s+["']\\.\/${stem}["']`).test(existing);
|
|
83
|
+
if (alreadyPresent) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
const updated = existing.trimEnd() + "\n" + exportLine + "\n";
|
|
87
|
+
const content = await formatter_1.Formatter.format(updated, indexFile);
|
|
88
|
+
if (!dryRun) {
|
|
89
|
+
(0, fs_1.writeFileSync)(indexFile, content, "utf-8");
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.IndexManager = IndexManager;
|
|
95
|
+
//# sourceMappingURL=index-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-manager.js","sourceRoot":"","sources":["../../src/utils/index-manager.ts"],"names":[],"mappings":";;;;;;AAAA,2BAA4D;AAC5D,gDAAuB;AACvB,kDAAyB;AACzB,6CAAwC;AACxC,2CAAuC;AACvC,sCAAkC;AAGlC;;GAEG;AACH,MAAa,YAAY;IACvB;;;;;;;;;OASG;IACH,KAAK,CAAC,gBAAgB,CACpB,OAAoB,EACpB,YAAoB,EACpB,MAAe;QAEf,MAAM,eAAe,GAAG,sBAAS,CAAC,QAAQ,CACxC,eAAM,CAAC,GAAG,EAAE,CAAC,UAAU,EACvB,UAAU,CACX,CAAA;QACD,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;QAC3C,MAAM,SAAS,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;QACzC,MAAM,aAAa,GAAG,cAAI,CAAC,IAAI,C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GAAG,UAAU,GAAG,IAAI,CAAA;QAC7D,MAAM,OAAO,GAAG,MAAM,qBAAS,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;QAC1D,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,IAAA,kBAAa,EAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;QAC5C,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAlHD,oCAkHC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
export declare class TsHelpers {
|
|
3
|
+
private static readonly OPERATOR_MAP_PROPS;
|
|
4
|
+
/**
|
|
5
|
+
* Returns true if the given TypeScript type looks like a Zod schema,
|
|
6
|
+
* by checking for the presence of the `_input` and `_output` branded properties
|
|
7
|
+
* that all Zod types expose.
|
|
8
|
+
*/
|
|
9
|
+
static isZodType(type: ts.Type): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Returns true if the top-level Zod type IS a ZodEffects (i.e., has a `.transform()`
|
|
12
|
+
* applied at the outermost level). This is different from checking if the type string
|
|
13
|
+
* _contains_ "ZodEffects", which would also match ZodObject schemas whose shape
|
|
14
|
+
* contains ZodEffects-wrapped fields (e.g., via `z.preprocess()`).
|
|
15
|
+
*/
|
|
16
|
+
static isZodEffects(checker: ts.TypeChecker, type: ts.Type): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Resolves the `_input` type of a Zod schema — i.e. the pre-transform shape,
|
|
19
|
+
* which represents what a caller would send in an HTTP request.
|
|
20
|
+
*/
|
|
21
|
+
static getZodInputType(checker: ts.TypeChecker, zodType: ts.Type): ts.Type | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Resolves the `_output` type of a Zod schema — the post-transform inferred type,
|
|
24
|
+
* equivalent to `z.infer<typeof schema>`.
|
|
25
|
+
*/
|
|
26
|
+
static getZodOutputType(checker: ts.TypeChecker, zodType: ts.Type): ts.Type | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Returns true if a type has OperatorMap member properties ($eq, $ne, $in, etc.).
|
|
29
|
+
*/
|
|
30
|
+
private static isOperatorMapMember;
|
|
31
|
+
/**
|
|
32
|
+
* Detects if a resolved type looks like an `OperatorMap` — a union that
|
|
33
|
+
* includes an object with filter operator properties ($eq, $ne, $in, etc.).
|
|
34
|
+
*/
|
|
35
|
+
static isOperatorMapType(type: ts.Type): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Returns a simplified display string for a TypeScript type, suitable for
|
|
38
|
+
* use in error messages and diagnostics.
|
|
39
|
+
*/
|
|
40
|
+
static typeToDisplayString(checker: ts.TypeChecker, type: ts.Type): string;
|
|
41
|
+
/**
|
|
42
|
+
* Recursively walks a call expression chain to check if any call in the chain
|
|
43
|
+
* uses the given function name.
|
|
44
|
+
*/
|
|
45
|
+
static callChainIncludes(node: ts.Node, funcName: string): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Returns true if the given type is plain `string` (not a literal or union).
|
|
48
|
+
*/
|
|
49
|
+
static isPlainString(type: ts.Type): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Returns true if the type is a string literal or a union of string literals.
|
|
52
|
+
*/
|
|
53
|
+
static isStringLiteralOrUnion(type: ts.Type): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Returns true if the type is a TypeScript string enum or a union of string
|
|
56
|
+
* enum literals.
|
|
57
|
+
*/
|
|
58
|
+
static isStringEnumType(type: ts.Type): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Returns the set of string values from a string literal type or a union of
|
|
61
|
+
* string literals.
|
|
62
|
+
*/
|
|
63
|
+
static getStringLiteralValues(type: ts.Type): Set<string>;
|
|
64
|
+
/**
|
|
65
|
+
* Checks whether the given node has an `export` modifier.
|
|
66
|
+
*/
|
|
67
|
+
static isExported(node: ts.Node): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Returns the first VariableDeclaration inside a VariableStatement.
|
|
70
|
+
*/
|
|
71
|
+
static getVariableDeclaration(stmt: ts.VariableStatement): ts.VariableDeclaration | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Reads the `@http-type-name` JSDoc tag value from the leading comments
|
|
74
|
+
* of a VariableStatement node, if present.
|
|
75
|
+
*/
|
|
76
|
+
static readHttpTypeNameTag(node: ts.VariableStatement, sourceFile: ts.SourceFile): string | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Given a call expression like `WithAdditionalData(CreateCustomer)`,
|
|
79
|
+
* returns the text of the first argument identifier ("CreateCustomer").
|
|
80
|
+
*/
|
|
81
|
+
static getFirstCallArgName(node: ts.VariableDeclaration): string | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Checks whether a TypeScript type is a function type (as opposed to an object/Zod type).
|
|
84
|
+
*/
|
|
85
|
+
static isFunctionType(type: ts.Type): boolean;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=ts-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ts-helpers.d.ts","sourceRoot":"","sources":["../../src/utils/ts-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CASzC;IAED;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,OAAO;IAMxC;;;;;OAKG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,OAAO;IASpE;;;OAGG;IACH,MAAM,CAAC,eAAe,CACpB,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,OAAO,EAAE,EAAE,CAAC,IAAI,GACf,EAAE,CAAC,IAAI,GAAG,SAAS;IAQtB;;;OAGG;IACH,MAAM,CAAC,gBAAgB,CACrB,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,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