zinfer 0.0.1 → 0.1.1
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 +477 -28
- package/bin/zinfer +2 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +484 -0
- package/dist/cli.js.map +1 -0
- package/dist/core/brand-detector.d.ts +32 -0
- package/dist/core/brand-detector.d.ts.map +1 -0
- package/dist/core/brand-detector.js +121 -0
- package/dist/core/brand-detector.js.map +1 -0
- package/dist/core/config-loader.d.ts +85 -0
- package/dist/core/config-loader.d.ts.map +1 -0
- package/dist/core/config-loader.js +105 -0
- package/dist/core/config-loader.js.map +1 -0
- package/dist/core/description-extractor.d.ts +54 -0
- package/dist/core/description-extractor.d.ts.map +1 -0
- package/dist/core/description-extractor.js +180 -0
- package/dist/core/description-extractor.js.map +1 -0
- package/dist/core/errors.d.ts +35 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +96 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/extractor.d.ts +121 -0
- package/dist/core/extractor.d.ts.map +1 -0
- package/dist/core/extractor.js +494 -0
- package/dist/core/extractor.js.map +1 -0
- package/dist/core/file-resolver.d.ts +39 -0
- package/dist/core/file-resolver.d.ts.map +1 -0
- package/dist/core/file-resolver.js +88 -0
- package/dist/core/file-resolver.js.map +1 -0
- package/dist/core/getter-resolver.d.ts +67 -0
- package/dist/core/getter-resolver.d.ts.map +1 -0
- package/dist/core/getter-resolver.js +234 -0
- package/dist/core/getter-resolver.js.map +1 -0
- package/dist/core/import-resolver.d.ts +51 -0
- package/dist/core/import-resolver.d.ts.map +1 -0
- package/dist/core/import-resolver.js +158 -0
- package/dist/core/import-resolver.js.map +1 -0
- package/dist/core/index.d.ts +14 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +13 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/logger.d.ts +20 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +36 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/name-mapper.d.ts +45 -0
- package/dist/core/name-mapper.d.ts.map +1 -0
- package/dist/core/name-mapper.js +82 -0
- package/dist/core/name-mapper.js.map +1 -0
- package/dist/core/normalizer.d.ts +24 -0
- package/dist/core/normalizer.d.ts.map +1 -0
- package/dist/core/normalizer.js +50 -0
- package/dist/core/normalizer.js.map +1 -0
- package/dist/core/schema-detector.d.ts +49 -0
- package/dist/core/schema-detector.d.ts.map +1 -0
- package/dist/core/schema-detector.js +272 -0
- package/dist/core/schema-detector.js.map +1 -0
- package/dist/core/schema-reference-analyzer.d.ts +77 -0
- package/dist/core/schema-reference-analyzer.d.ts.map +1 -0
- package/dist/core/schema-reference-analyzer.js +269 -0
- package/dist/core/schema-reference-analyzer.js.map +1 -0
- package/dist/core/test-generator.d.ts +97 -0
- package/dist/core/test-generator.d.ts.map +1 -0
- package/dist/core/test-generator.js +177 -0
- package/dist/core/test-generator.js.map +1 -0
- package/dist/core/type-printer.d.ts +46 -0
- package/dist/core/type-printer.d.ts.map +1 -0
- package/dist/core/type-printer.js +424 -0
- package/dist/core/type-printer.js.map +1 -0
- package/dist/core/types.d.ts +124 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +5 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +79 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -7
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats the extraction result for console output.
|
|
3
|
+
*
|
|
4
|
+
* @param result - The extraction result containing input and output types
|
|
5
|
+
* @param options - Formatting options
|
|
6
|
+
* @returns Formatted string ready for console output
|
|
7
|
+
*/
|
|
8
|
+
export function formatResult(result, options = {}) {
|
|
9
|
+
const { indent = " ", includeSchemaName = false } = options;
|
|
10
|
+
const lines = [];
|
|
11
|
+
if (includeSchemaName) {
|
|
12
|
+
lines.push(`// Schema: ${result.schemaName}`);
|
|
13
|
+
lines.push("");
|
|
14
|
+
}
|
|
15
|
+
lines.push("// input");
|
|
16
|
+
lines.push(prettifyType(result.input, indent));
|
|
17
|
+
lines.push("");
|
|
18
|
+
lines.push("// output");
|
|
19
|
+
lines.push(prettifyType(result.output, indent));
|
|
20
|
+
return lines.join("\n");
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Prettifies a type string by formatting object types with proper indentation.
|
|
24
|
+
*
|
|
25
|
+
* @param typeStr - The type string to format
|
|
26
|
+
* @param indent - The indentation string to use
|
|
27
|
+
* @param descriptions - Optional field descriptions to insert as TSDoc comments
|
|
28
|
+
* @param prefix - Current path prefix for nested objects
|
|
29
|
+
* @returns The formatted type string
|
|
30
|
+
*/
|
|
31
|
+
function prettifyType(typeStr, indent, descriptions, prefix = "") {
|
|
32
|
+
// If it's not an object type, return as-is
|
|
33
|
+
if (!typeStr.startsWith("{") || !typeStr.endsWith("}")) {
|
|
34
|
+
return typeStr;
|
|
35
|
+
}
|
|
36
|
+
const prettified = prettifyObjectType(typeStr, indent, descriptions, prefix);
|
|
37
|
+
// Remove trailing spaces from each line
|
|
38
|
+
return prettified
|
|
39
|
+
.split("\n")
|
|
40
|
+
.map((line) => line.trimEnd())
|
|
41
|
+
.join("\n");
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates a TSDoc comment line.
|
|
45
|
+
*/
|
|
46
|
+
function createTsDocComment(description, indentStr) {
|
|
47
|
+
return `${indentStr}/** ${description} */\n`;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Gets description for a field path.
|
|
51
|
+
*/
|
|
52
|
+
function getFieldDescription(fieldName, prefix, descriptions) {
|
|
53
|
+
if (!descriptions) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
const path = prefix ? `${prefix}.${fieldName}` : fieldName;
|
|
57
|
+
const desc = descriptions.find((d) => d.path === path);
|
|
58
|
+
return desc?.description;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Creates initial parser state.
|
|
62
|
+
*/
|
|
63
|
+
function createParserState() {
|
|
64
|
+
return {
|
|
65
|
+
result: "",
|
|
66
|
+
depth: 0,
|
|
67
|
+
inString: false,
|
|
68
|
+
stringChar: "",
|
|
69
|
+
currentFieldName: "",
|
|
70
|
+
capturingFieldName: false,
|
|
71
|
+
pathStack: [],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Updates string literal tracking state.
|
|
76
|
+
* Returns true if currently inside a string literal.
|
|
77
|
+
*/
|
|
78
|
+
function updateStringState(state, char, prevChar) {
|
|
79
|
+
if ((char === '"' || char === "'" || char === "`") && prevChar !== "\\") {
|
|
80
|
+
if (!state.inString) {
|
|
81
|
+
state.inString = true;
|
|
82
|
+
state.stringChar = char;
|
|
83
|
+
}
|
|
84
|
+
else if (char === state.stringChar) {
|
|
85
|
+
state.inString = false;
|
|
86
|
+
state.stringChar = "";
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return state.inString;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Handles opening brace character.
|
|
93
|
+
*/
|
|
94
|
+
function handleOpenBrace(state, indent) {
|
|
95
|
+
state.depth++;
|
|
96
|
+
state.result += "{\n" + indent.repeat(state.depth);
|
|
97
|
+
state.capturingFieldName = true;
|
|
98
|
+
state.currentFieldName = "";
|
|
99
|
+
if (state.depth > 1 && state.currentFieldName) {
|
|
100
|
+
state.pathStack.push(state.currentFieldName);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Handles closing brace character.
|
|
105
|
+
*/
|
|
106
|
+
function handleCloseBrace(state, indent) {
|
|
107
|
+
state.depth--;
|
|
108
|
+
if (state.pathStack.length > 0 && state.depth >= 1) {
|
|
109
|
+
state.pathStack.pop();
|
|
110
|
+
}
|
|
111
|
+
state.result += "\n" + indent.repeat(state.depth) + "}";
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Handles colon character and inserts TSDoc comment if applicable.
|
|
115
|
+
*/
|
|
116
|
+
function handleColon(state, indent, descriptions, prefix) {
|
|
117
|
+
if (state.capturingFieldName && state.currentFieldName) {
|
|
118
|
+
const cleanFieldName = state.currentFieldName.replace(/\?$/, "").trim();
|
|
119
|
+
const currentPath = [...state.pathStack, prefix].filter(Boolean).join(".");
|
|
120
|
+
const desc = getFieldDescription(cleanFieldName, currentPath, descriptions);
|
|
121
|
+
if (desc) {
|
|
122
|
+
const lastNewlinePos = state.result.lastIndexOf("\n");
|
|
123
|
+
const beforeField = state.result.substring(0, lastNewlinePos + 1);
|
|
124
|
+
const fieldPart = state.result.substring(lastNewlinePos + 1);
|
|
125
|
+
state.result = beforeField + createTsDocComment(desc, indent.repeat(state.depth)) + fieldPart;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
state.result += ":";
|
|
129
|
+
state.capturingFieldName = false;
|
|
130
|
+
state.currentFieldName = "";
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Handles semicolon character.
|
|
134
|
+
*/
|
|
135
|
+
function handleSemicolon(state, indent, typeStr, index) {
|
|
136
|
+
const remaining = typeStr.slice(index + 1).trim();
|
|
137
|
+
if (remaining.startsWith("}")) {
|
|
138
|
+
state.result += ";";
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
state.result += ";\n" + indent.repeat(state.depth);
|
|
142
|
+
state.capturingFieldName = true;
|
|
143
|
+
state.currentFieldName = "";
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Handles space character, skipping extra spaces after newlines.
|
|
148
|
+
*/
|
|
149
|
+
function handleSpace(state, indent) {
|
|
150
|
+
if (state.result.endsWith("\n" + indent.repeat(state.depth)) ||
|
|
151
|
+
state.result.endsWith("{\n" + indent.repeat(state.depth))) {
|
|
152
|
+
return true; // Skip this space
|
|
153
|
+
}
|
|
154
|
+
state.result += " ";
|
|
155
|
+
if (state.capturingFieldName) {
|
|
156
|
+
state.currentFieldName += " ";
|
|
157
|
+
}
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Handles default character.
|
|
162
|
+
*/
|
|
163
|
+
function handleDefaultChar(state, char) {
|
|
164
|
+
state.result += char;
|
|
165
|
+
if (state.capturingFieldName) {
|
|
166
|
+
state.currentFieldName += char;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Handles character inside a string literal.
|
|
171
|
+
*/
|
|
172
|
+
function handleStringChar(state, char) {
|
|
173
|
+
state.result += char;
|
|
174
|
+
if (state.capturingFieldName) {
|
|
175
|
+
state.currentFieldName += char;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Formats an object type string with proper indentation and line breaks.
|
|
180
|
+
*/
|
|
181
|
+
function prettifyObjectType(typeStr, indent, descriptions, prefix = "") {
|
|
182
|
+
const state = createParserState();
|
|
183
|
+
for (let i = 0; i < typeStr.length; i++) {
|
|
184
|
+
const char = typeStr[i];
|
|
185
|
+
const prevChar = typeStr[i - 1];
|
|
186
|
+
const inString = updateStringState(state, char, prevChar);
|
|
187
|
+
if (inString) {
|
|
188
|
+
handleStringChar(state, char);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
switch (char) {
|
|
192
|
+
case "{":
|
|
193
|
+
handleOpenBrace(state, indent);
|
|
194
|
+
break;
|
|
195
|
+
case "}":
|
|
196
|
+
handleCloseBrace(state, indent);
|
|
197
|
+
break;
|
|
198
|
+
case ":":
|
|
199
|
+
handleColon(state, indent, descriptions, prefix);
|
|
200
|
+
break;
|
|
201
|
+
case ";":
|
|
202
|
+
handleSemicolon(state, indent, typeStr, i);
|
|
203
|
+
break;
|
|
204
|
+
case " ":
|
|
205
|
+
handleSpace(state, indent);
|
|
206
|
+
break;
|
|
207
|
+
default:
|
|
208
|
+
handleDefaultChar(state, char);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return state.result;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Formats the extraction result as input type only.
|
|
215
|
+
*/
|
|
216
|
+
export function formatInputOnly(result, options = {}) {
|
|
217
|
+
const { indent = " " } = options;
|
|
218
|
+
return prettifyType(result.input, indent);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Formats the extraction result as output type only.
|
|
222
|
+
*/
|
|
223
|
+
export function formatOutputOnly(result, options = {}) {
|
|
224
|
+
const { indent = " " } = options;
|
|
225
|
+
return prettifyType(result.output, indent);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Applies brand information to a type string.
|
|
229
|
+
*
|
|
230
|
+
* @param typeStr - The type string to apply brands to
|
|
231
|
+
* @param brands - Array of brand information
|
|
232
|
+
* @returns The type string with brands applied
|
|
233
|
+
*/
|
|
234
|
+
function applyBrands(typeStr, brands) {
|
|
235
|
+
if (!brands || brands.length === 0) {
|
|
236
|
+
return typeStr;
|
|
237
|
+
}
|
|
238
|
+
let result = typeStr;
|
|
239
|
+
for (const brand of brands) {
|
|
240
|
+
if (brand.fieldPath === "") {
|
|
241
|
+
// Root-level brand: wrap the entire type
|
|
242
|
+
result = `${result} & BRAND<"${brand.brandName}">`;
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
// Field-level brand: find the field and apply brand to its type
|
|
246
|
+
result = applyBrandToField(result, brand.fieldPath, brand.brandName);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return result;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Applies a brand to a specific field in an object type.
|
|
253
|
+
*/
|
|
254
|
+
function applyBrandToField(typeStr, fieldPath, brandName) {
|
|
255
|
+
// Handle nested field paths
|
|
256
|
+
const parts = fieldPath.split(".");
|
|
257
|
+
const fieldName = parts[parts.length - 1];
|
|
258
|
+
// Find the field pattern (fieldName: type or fieldName?: type)
|
|
259
|
+
const fieldPatterns = [`${fieldName}: `, `${fieldName}?: `];
|
|
260
|
+
for (const pattern of fieldPatterns) {
|
|
261
|
+
const idx = typeStr.indexOf(pattern);
|
|
262
|
+
if (idx === -1)
|
|
263
|
+
continue;
|
|
264
|
+
const valueStart = idx + pattern.length;
|
|
265
|
+
// Find the end of the field type by tracking braces/brackets/parentheses
|
|
266
|
+
let depth = 0;
|
|
267
|
+
let endIdx = valueStart;
|
|
268
|
+
let inString = false;
|
|
269
|
+
let stringChar = "";
|
|
270
|
+
while (endIdx < typeStr.length) {
|
|
271
|
+
const char = typeStr[endIdx];
|
|
272
|
+
const prevChar = typeStr[endIdx - 1];
|
|
273
|
+
// Track string literals
|
|
274
|
+
if ((char === '"' || char === "'" || char === "`") && prevChar !== "\\") {
|
|
275
|
+
if (!inString) {
|
|
276
|
+
inString = true;
|
|
277
|
+
stringChar = char;
|
|
278
|
+
}
|
|
279
|
+
else if (char === stringChar) {
|
|
280
|
+
inString = false;
|
|
281
|
+
stringChar = "";
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if (!inString) {
|
|
285
|
+
if (char === "{" || char === "[" || char === "(" || char === "<") {
|
|
286
|
+
depth++;
|
|
287
|
+
}
|
|
288
|
+
else if (char === "}" || char === "]" || char === ")" || char === ">") {
|
|
289
|
+
if (depth === 0)
|
|
290
|
+
break;
|
|
291
|
+
depth--;
|
|
292
|
+
}
|
|
293
|
+
else if (char === ";" && depth === 0) {
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
endIdx++;
|
|
298
|
+
}
|
|
299
|
+
// Extract the current type
|
|
300
|
+
const fieldType = typeStr.substring(valueStart, endIdx).trim();
|
|
301
|
+
const brandedType = `${fieldType} & BRAND<"${brandName}">`;
|
|
302
|
+
return typeStr.substring(0, valueStart) + brandedType + typeStr.substring(endIdx);
|
|
303
|
+
}
|
|
304
|
+
return typeStr;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Formats a single extraction result as TypeScript type declaration(s).
|
|
308
|
+
*
|
|
309
|
+
* @param result - The extraction result
|
|
310
|
+
* @param typeName - The mapped type names
|
|
311
|
+
* @param options - Declaration options
|
|
312
|
+
* @returns TypeScript type declaration string
|
|
313
|
+
*/
|
|
314
|
+
export function formatAsDeclaration(result, typeName, options = {}) {
|
|
315
|
+
const { inputOnly, outputOnly, mergeSame } = options;
|
|
316
|
+
const lines = [];
|
|
317
|
+
const indent = " ";
|
|
318
|
+
const inputFormatted = prettifyType(result.input, indent, result.fieldDescriptions);
|
|
319
|
+
// Apply brands to output type only (brands are runtime-only, not for input)
|
|
320
|
+
const outputWithBrands = applyBrands(result.output, result.brands);
|
|
321
|
+
const outputFormatted = prettifyType(outputWithBrands, indent, result.fieldDescriptions);
|
|
322
|
+
// Schema-level TSDoc comment
|
|
323
|
+
const schemaComment = result.description ? `/**\n * ${result.description}\n */\n` : "";
|
|
324
|
+
// Only export if the original schema was exported
|
|
325
|
+
const exportKeyword = result.isExported ? "export " : "";
|
|
326
|
+
// If mergeSame is enabled and types are identical (compare without brands for input)
|
|
327
|
+
if (mergeSame && result.input === result.output && !result.brands?.length) {
|
|
328
|
+
lines.push(`${schemaComment}${exportKeyword}type ${typeName.unifiedName} = ${inputFormatted};`);
|
|
329
|
+
return lines.join("\n");
|
|
330
|
+
}
|
|
331
|
+
// Input type
|
|
332
|
+
if (!outputOnly) {
|
|
333
|
+
lines.push(`${schemaComment}${exportKeyword}type ${typeName.inputName} = ${inputFormatted};`);
|
|
334
|
+
}
|
|
335
|
+
// Output type
|
|
336
|
+
if (!inputOnly) {
|
|
337
|
+
if (lines.length > 0) {
|
|
338
|
+
lines.push("");
|
|
339
|
+
}
|
|
340
|
+
// Only add schema comment to output if input was not added
|
|
341
|
+
const outputComment = outputOnly ? schemaComment : "";
|
|
342
|
+
lines.push(`${outputComment}${exportKeyword}type ${typeName.outputName} = ${outputFormatted};`);
|
|
343
|
+
}
|
|
344
|
+
return lines.join("\n");
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Formats multiple extraction results as TypeScript type declarations.
|
|
348
|
+
*
|
|
349
|
+
* @param results - Array of extraction results
|
|
350
|
+
* @param mapName - Function to map schema name to type names
|
|
351
|
+
* @param options - Declaration options
|
|
352
|
+
* @returns TypeScript type declarations string
|
|
353
|
+
*/
|
|
354
|
+
/**
|
|
355
|
+
* Escapes special characters in a string for use in a RegExp.
|
|
356
|
+
*/
|
|
357
|
+
function escapeRegExp(str) {
|
|
358
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
359
|
+
}
|
|
360
|
+
export function formatMultipleAsDeclarations(results, mapName, options = {}) {
|
|
361
|
+
// Build a map of schema names to their mapped type names
|
|
362
|
+
const typeNameMap = new Map();
|
|
363
|
+
for (const result of results) {
|
|
364
|
+
typeNameMap.set(result.schemaName, mapName(result.schemaName));
|
|
365
|
+
}
|
|
366
|
+
// Replace schema references with correct type names
|
|
367
|
+
const fixedResults = results.map((result) => {
|
|
368
|
+
let input = result.input;
|
|
369
|
+
let output = result.output;
|
|
370
|
+
// Replace all schema references in the type strings
|
|
371
|
+
for (const [schemaName, mappedName] of typeNameMap) {
|
|
372
|
+
// Escape special regex characters in schema name
|
|
373
|
+
const escapedSchemaName = escapeRegExp(schemaName);
|
|
374
|
+
// Replace SchemaNameInput -> MappedNameInput
|
|
375
|
+
const inputPattern = new RegExp(`\\b${escapedSchemaName}Input\\b`, "g");
|
|
376
|
+
input = input.replace(inputPattern, mappedName.inputName);
|
|
377
|
+
// Replace SchemaNameOutput -> MappedNameOutput
|
|
378
|
+
const outputPattern = new RegExp(`\\b${escapedSchemaName}Output\\b`, "g");
|
|
379
|
+
output = output.replace(outputPattern, mappedName.outputName);
|
|
380
|
+
}
|
|
381
|
+
return { ...result, input, output };
|
|
382
|
+
});
|
|
383
|
+
const declarations = [];
|
|
384
|
+
// Only generate declarations for exported schemas
|
|
385
|
+
for (const result of fixedResults) {
|
|
386
|
+
if (!result.isExported) {
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
const typeName = mapName(result.schemaName);
|
|
390
|
+
const declaration = formatAsDeclaration(result, typeName, options);
|
|
391
|
+
declarations.push(declaration);
|
|
392
|
+
}
|
|
393
|
+
return declarations.join("\n\n");
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Checks if any results have brand information.
|
|
397
|
+
*/
|
|
398
|
+
function hasBrands(results) {
|
|
399
|
+
return results.some((r) => r.brands && r.brands.length > 0);
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Generates a complete TypeScript declaration file content.
|
|
403
|
+
*
|
|
404
|
+
* @param results - Array of extraction results
|
|
405
|
+
* @param mapName - Function to map schema name to type names
|
|
406
|
+
* @param options - Declaration options
|
|
407
|
+
* @returns Complete .d.ts or .ts file content
|
|
408
|
+
*/
|
|
409
|
+
export function generateDeclarationFile(results, mapName, options = {}) {
|
|
410
|
+
const lines = [];
|
|
411
|
+
// Add header comment
|
|
412
|
+
lines.push("// Generated by zinfer - Do not edit manually");
|
|
413
|
+
lines.push("");
|
|
414
|
+
// Add BRAND import if any result has brands
|
|
415
|
+
if (hasBrands(results)) {
|
|
416
|
+
lines.push('import type { BRAND } from "zod";');
|
|
417
|
+
lines.push("");
|
|
418
|
+
}
|
|
419
|
+
// Add type declarations
|
|
420
|
+
lines.push(formatMultipleAsDeclarations(results, mapName, options));
|
|
421
|
+
lines.push("");
|
|
422
|
+
return lines.join("\n");
|
|
423
|
+
}
|
|
424
|
+
//# sourceMappingURL=type-printer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-printer.js","sourceRoot":"","sources":["../../src/core/type-printer.ts"],"names":[],"mappings":"AAkBA;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,MAAqB,EAAE,UAAwB,EAAE;IAC5E,MAAM,EAAE,MAAM,GAAG,IAAI,EA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AAO,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC;AAED;;GAEG;AACH,SAAS,SAAS,CAAC,OAAwB;IACzC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CACrC,OAAwB,EACxB,OAA+C,EAC/C,UAA8B,EAAE;IAEhC,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,qBAAqB;IACrB,KAAK,CAAC,IAAI,CAAC,+CAA+C,CAAC,CAAC;IAC5D,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEf,4CAA4C;IAC5C,IAAI,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;QACvB,KAAK,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;QAChD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjB,CAAC;IAED,wBAAwB;IACxB,KAAK,CAAC,IAAI,CAAC,4BAA4B,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IACpE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEf,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared type definitions for zinfer.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Information about a detected Zod schema in a source file.
|
|
6
|
+
*/
|
|
7
|
+
export interface DetectedSchema {
|
|
8
|
+
/** Variable name of the schema */
|
|
9
|
+
name: string;
|
|
10
|
+
/** Whether the schema is exported */
|
|
11
|
+
isExported: boolean;
|
|
12
|
+
/** Line number where the schema is defined */
|
|
13
|
+
line: number;
|
|
14
|
+
/** Explicit type annotation if present (e.g., "Category" from z.ZodType<Category>) */
|
|
15
|
+
explicitType?: string;
|
|
16
|
+
/** JSDoc comment if present */
|
|
17
|
+
jsDoc?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Field description from Zod .describe().
|
|
21
|
+
*/
|
|
22
|
+
export interface FieldDescription {
|
|
23
|
+
/** Field path (e.g., "user.name" for nested fields) */
|
|
24
|
+
path: string;
|
|
25
|
+
/** Description text */
|
|
26
|
+
description: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Information about a branded type.
|
|
30
|
+
*/
|
|
31
|
+
export interface BrandInfo {
|
|
32
|
+
/** The brand name (e.g., "UserId") */
|
|
33
|
+
brandName: string;
|
|
34
|
+
/** The field path where the brand is applied (empty string for root-level) */
|
|
35
|
+
fieldPath: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Result of extracting types from a single schema.
|
|
39
|
+
*/
|
|
40
|
+
export interface ExtractResult {
|
|
41
|
+
/** Name of the schema */
|
|
42
|
+
schemaName: string;
|
|
43
|
+
/** Extracted input type as string */
|
|
44
|
+
input: string;
|
|
45
|
+
/** Extracted output type as string */
|
|
46
|
+
output: string;
|
|
47
|
+
/** Whether the original schema was exported */
|
|
48
|
+
isExported: boolean;
|
|
49
|
+
/** Schema-level description from .describe() */
|
|
50
|
+
description?: string;
|
|
51
|
+
/** Field descriptions from .describe() */
|
|
52
|
+
fieldDescriptions?: FieldDescription[];
|
|
53
|
+
/** Brand information for output type */
|
|
54
|
+
brands?: BrandInfo[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Result of extracting types from a single file with multiple schemas.
|
|
58
|
+
*/
|
|
59
|
+
export interface FileExtractResult {
|
|
60
|
+
/** Path to the source file */
|
|
61
|
+
filePath: string;
|
|
62
|
+
/** Extracted schemas */
|
|
63
|
+
schemas: ExtractResult[];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Mapped type names for a schema.
|
|
67
|
+
*/
|
|
68
|
+
export interface MappedTypeName {
|
|
69
|
+
/** Original schema name */
|
|
70
|
+
originalName: string;
|
|
71
|
+
/** Generated input type name */
|
|
72
|
+
inputName: string;
|
|
73
|
+
/** Generated output type name */
|
|
74
|
+
outputName: string;
|
|
75
|
+
/** Unified name (when input === output) */
|
|
76
|
+
unifiedName: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Options for name mapping.
|
|
80
|
+
*/
|
|
81
|
+
export interface NameMappingOptions {
|
|
82
|
+
/** Suffix to remove from schema names (e.g., "Schema") */
|
|
83
|
+
removeSuffix?: string;
|
|
84
|
+
/** Suffix to add for input types (default: "Input") */
|
|
85
|
+
inputSuffix?: string;
|
|
86
|
+
/** Suffix to add for output types (default: "Output") */
|
|
87
|
+
outputSuffix?: string;
|
|
88
|
+
/** Custom name mappings */
|
|
89
|
+
customMap?: Record<string, string>;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Options for output generation.
|
|
93
|
+
*/
|
|
94
|
+
export interface OutputOptions {
|
|
95
|
+
/** Output directory */
|
|
96
|
+
outDir?: string;
|
|
97
|
+
/** Single output file path */
|
|
98
|
+
outFile?: string;
|
|
99
|
+
/** Output file naming pattern (e.g., "[name].types.ts") */
|
|
100
|
+
outPattern?: string;
|
|
101
|
+
/** Generate .d.ts declaration files */
|
|
102
|
+
declaration?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Generated file information.
|
|
106
|
+
*/
|
|
107
|
+
export interface GeneratedFile {
|
|
108
|
+
/** Output file path */
|
|
109
|
+
path: string;
|
|
110
|
+
/** File content */
|
|
111
|
+
content: string;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Options for type declaration formatting.
|
|
115
|
+
*/
|
|
116
|
+
export interface DeclarationOptions {
|
|
117
|
+
/** Output only input types */
|
|
118
|
+
inputOnly?: boolean;
|
|
119
|
+
/** Output only output types */
|
|
120
|
+
outputOnly?: boolean;
|
|
121
|
+
/** Merge input/output if they are identical */
|
|
122
|
+
mergeSame?: boolean;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,qCAAqC;IACrC,UAAU,EAAE,OAAO,CAAC;IACpB,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,sFAAsF;IACtF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+BAA+B;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,uBAAuB;IACvB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,8EAA8E;IAC9E,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,yBAAyB;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,qCAAqC;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,UAAU,EAAE,OAAO,CAAC;IACpB,gDAAgD;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0CAA0C;IAC1C,iBAAiB,CAAC,EAAE,gBAAgB,EAAE,CAAC;IACvC,wCAAwC;IACxC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,8BAA8B;IAC9B,Q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/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export { ZodTypeExtractor, type ExtractOptions, formatResult, formatInputOnly, formatOutputOnly, formatAsDeclaration, formatMultipleAsDeclarations, generateDeclarationFile, type PrintOptions, SchemaDetector, NameMapper, createNameMapper, FileResolver, defineConfig, type ZinferConfig, TestGenerator, generateTypeTests, generateImportPrefix, createTestSchemaInfo, toPascalCase, type TestSchemaInfo, type TestFileInfo, type TestGeneratorOptions, } from "./core/index.js";
|
|
2
|
+
export type { ExtractResult, FileExtractResult, DetectedSchema, MappedTypeName, NameMappingOptions, OutputOptions, GeneratedFile, DeclarationOptions, } from "./core/index.js";
|
|
3
|
+
import { type ExtractResult, type NameMappingOptions, type DeclarationOptions } from "./core/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Simple API to extract input and output types from a Zod schema.
|
|
6
|
+
*
|
|
7
|
+
* @param filePath - Path to the TypeScript file containing the Zod schema
|
|
8
|
+
* @param schemaName - Name of the exported Zod schema
|
|
9
|
+
* @param tsconfigPath - Optional path to tsconfig.json
|
|
10
|
+
* @returns Object containing input and output type strings
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { extractZodTypes } from 'zinfer';
|
|
15
|
+
*
|
|
16
|
+
* const { input, output } = extractZodTypes('./schemas.ts', 'UserSchema');
|
|
17
|
+
* console.log('Input:', input);
|
|
18
|
+
* console.log('Output:', output);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function extractZodTypes(filePath: string, schemaName: string, tsconfigPath?: string): {
|
|
22
|
+
input: string;
|
|
23
|
+
output: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Extracts types and returns a formatted string ready for console output.
|
|
27
|
+
*
|
|
28
|
+
* @param filePath - Path to the TypeScript file containing the Zod schema
|
|
29
|
+
* @param schemaName - Name of the exported Zod schema
|
|
30
|
+
* @param tsconfigPath - Optional path to tsconfig.json
|
|
31
|
+
* @returns Formatted string with input and output types
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* import { extractAndFormat } from 'zinfer';
|
|
36
|
+
*
|
|
37
|
+
* console.log(extractAndFormat('./schemas.ts', 'UserSchema'));
|
|
38
|
+
* // Output:
|
|
39
|
+
* // // input
|
|
40
|
+
* // { id: string; name: string; }
|
|
41
|
+
* //
|
|
42
|
+
* // // output
|
|
43
|
+
* // { id: string; name: string; }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function extractAndFormat(filePath: string, schemaName: string, tsconfigPath?: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Extracts all schemas from a file.
|
|
49
|
+
*
|
|
50
|
+
* @param filePath - Path to the TypeScript file
|
|
51
|
+
* @param tsconfigPath - Optional path to tsconfig.json
|
|
52
|
+
* @returns Array of extraction results
|
|
53
|
+
*/
|
|
54
|
+
export declare function extractAllSchemas(filePath: string, tsconfigPath?: string): ExtractResult[];
|
|
55
|
+
/**
|
|
56
|
+
* Generates TypeScript type declarations from extraction results.
|
|
57
|
+
*
|
|
58
|
+
* @param results - Array of extraction results
|
|
59
|
+
* @param options - Generation options
|
|
60
|
+
* @returns TypeScript declaration file content
|
|
61
|
+
*/
|
|
62
|
+
export declare function generateTypeDeclarations(results: ExtractResult[], options?: {
|
|
63
|
+
nameMapping?: NameMappingOptions;
|
|
64
|
+
declaration?: DeclarationOptions;
|
|
65
|
+
}): string;
|
|
66
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,KAAK,cAAc,EACnB,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,4BAA4B,EAC5B,uBAAuB,EACvB,K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