zinfer 0.0.1 → 0.1.2

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 (79) hide show
  1. package/README.md +477 -28
  2. package/bin/zinfer +2 -0
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +486 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/core/brand-detector.d.ts +32 -0
  8. package/dist/core/brand-detector.d.ts.map +1 -0
  9. package/dist/core/brand-detector.js +121 -0
  10. package/dist/core/brand-detector.js.map +1 -0
  11. package/dist/core/config-loader.d.ts +87 -0
  12. package/dist/core/config-loader.d.ts.map +1 -0
  13. package/dist/core/config-loader.js +105 -0
  14. package/dist/core/config-loader.js.map +1 -0
  15. package/dist/core/description-extractor.d.ts +54 -0
  16. package/dist/core/description-extractor.d.ts.map +1 -0
  17. package/dist/core/description-extractor.js +180 -0
  18. package/dist/core/description-extractor.js.map +1 -0
  19. package/dist/core/errors.d.ts +35 -0
  20. package/dist/core/errors.d.ts.map +1 -0
  21. package/dist/core/errors.js +96 -0
  22. package/dist/core/errors.js.map +1 -0
  23. package/dist/core/extractor.d.ts +121 -0
  24. package/dist/core/extractor.d.ts.map +1 -0
  25. package/dist/core/extractor.js +504 -0
  26. package/dist/core/extractor.js.map +1 -0
  27. package/dist/core/file-resolver.d.ts +41 -0
  28. package/dist/core/file-resolver.d.ts.map +1 -0
  29. package/dist/core/file-resolver.js +95 -0
  30. package/dist/core/file-resolver.js.map +1 -0
  31. package/dist/core/getter-resolver.d.ts +67 -0
  32. package/dist/core/getter-resolver.d.ts.map +1 -0
  33. package/dist/core/getter-resolver.js +234 -0
  34. package/dist/core/getter-resolver.js.map +1 -0
  35. package/dist/core/import-resolver.d.ts +51 -0
  36. package/dist/core/import-resolver.d.ts.map +1 -0
  37. package/dist/core/import-resolver.js +158 -0
  38. package/dist/core/import-resolver.js.map +1 -0
  39. package/dist/core/index.d.ts +14 -0
  40. package/dist/core/index.d.ts.map +1 -0
  41. package/dist/core/index.js +13 -0
  42. package/dist/core/index.js.map +1 -0
  43. package/dist/core/logger.d.ts +20 -0
  44. package/dist/core/logger.d.ts.map +1 -0
  45. package/dist/core/logger.js +36 -0
  46. package/dist/core/logger.js.map +1 -0
  47. package/dist/core/name-mapper.d.ts +45 -0
  48. package/dist/core/name-mapper.d.ts.map +1 -0
  49. package/dist/core/name-mapper.js +82 -0
  50. package/dist/core/name-mapper.js.map +1 -0
  51. package/dist/core/normalizer.d.ts +24 -0
  52. package/dist/core/normalizer.d.ts.map +1 -0
  53. package/dist/core/normalizer.js +50 -0
  54. package/dist/core/normalizer.js.map +1 -0
  55. package/dist/core/schema-detector.d.ts +49 -0
  56. package/dist/core/schema-detector.d.ts.map +1 -0
  57. package/dist/core/schema-detector.js +272 -0
  58. package/dist/core/schema-detector.js.map +1 -0
  59. package/dist/core/schema-reference-analyzer.d.ts +77 -0
  60. package/dist/core/schema-reference-analyzer.d.ts.map +1 -0
  61. package/dist/core/schema-reference-analyzer.js +269 -0
  62. package/dist/core/schema-reference-analyzer.js.map +1 -0
  63. package/dist/core/test-generator.d.ts +97 -0
  64. package/dist/core/test-generator.d.ts.map +1 -0
  65. package/dist/core/test-generator.js +177 -0
  66. package/dist/core/test-generator.js.map +1 -0
  67. package/dist/core/type-printer.d.ts +46 -0
  68. package/dist/core/type-printer.d.ts.map +1 -0
  69. package/dist/core/type-printer.js +519 -0
  70. package/dist/core/type-printer.js.map +1 -0
  71. package/dist/core/types.d.ts +124 -0
  72. package/dist/core/types.d.ts.map +1 -0
  73. package/dist/core/types.js +5 -0
  74. package/dist/core/types.js.map +1 -0
  75. package/dist/index.d.ts +66 -0
  76. package/dist/index.d.ts.map +1 -0
  77. package/dist/index.js +79 -0
  78. package/dist/index.js.map +1 -0
  79. package/package.json +63 -7
@@ -0,0 +1,519 @@
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
+ // Emit aliases for input/output names that differ from the unified name
330
+ if (typeName.inputName !== typeName.unifiedName) {
331
+ lines.push(`${exportKeyword}type ${typeName.inputName} = ${typeName.unifiedName};`);
332
+ }
333
+ if (typeName.outputName !== typeName.unifiedName &&
334
+ typeName.outputName !== typeName.inputName) {
335
+ lines.push(`${exportKeyword}type ${typeName.outputName} = ${typeName.unifiedName};`);
336
+ }
337
+ return lines.join("\n");
338
+ }
339
+ // Input type
340
+ if (!outputOnly) {
341
+ lines.push(`${schemaComment}${exportKeyword}type ${typeName.inputName} = ${inputFormatted};`);
342
+ }
343
+ // Output type
344
+ if (!inputOnly) {
345
+ if (lines.length > 0) {
346
+ lines.push("");
347
+ }
348
+ // Only add schema comment to output if input was not added
349
+ const outputComment = outputOnly ? schemaComment : "";
350
+ lines.push(`${outputComment}${exportKeyword}type ${typeName.outputName} = ${outputFormatted};`);
351
+ }
352
+ return lines.join("\n");
353
+ }
354
+ /**
355
+ * Formats multiple extraction results as TypeScript type declarations.
356
+ *
357
+ * @param results - Array of extraction results
358
+ * @param mapName - Function to map schema name to type names
359
+ * @param options - Declaration options
360
+ * @returns TypeScript type declarations string
361
+ */
362
+ /**
363
+ * Escapes special characters in a string for use in a RegExp.
364
+ */
365
+ function escapeRegExp(str) {
366
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
367
+ }
368
+ export function formatMultipleAsDeclarations(results, mapName, options = {}) {
369
+ // Build a map of schema names to their mapped type names (exported only)
370
+ const typeNameMap = new Map();
371
+ for (const result of results) {
372
+ if (!result.isExported)
373
+ continue;
374
+ typeNameMap.set(result.schemaName, mapName(result.schemaName));
375
+ }
376
+ // Pass 1: Replace schema references with correct type names
377
+ let fixedResults = results.map((result) => {
378
+ let input = result.input;
379
+ let output = result.output;
380
+ for (const [schemaName, mappedName] of typeNameMap) {
381
+ const escapedSchemaName = escapeRegExp(schemaName);
382
+ const inputPattern = new RegExp(`\\b${escapedSchemaName}Input\\b`, "g");
383
+ input = input.replace(inputPattern, mappedName.inputName);
384
+ const outputPattern = new RegExp(`\\b${escapedSchemaName}Output\\b`, "g");
385
+ output = output.replace(outputPattern, mappedName.outputName);
386
+ }
387
+ return { ...result, input, output };
388
+ });
389
+ // Pass 2: When mergeSame is enabled, determine which schemas can be merged and
390
+ // replace input/output-specific names with unified names.
391
+ // Uses topological sort to process schemas in dependency order so that
392
+ // transitive merges (A → B → C) are resolved in a single pass.
393
+ if (options.mergeSame) {
394
+ // Build dependency graph: which schemas does each schema reference?
395
+ const deps = new Map();
396
+ for (const result of fixedResults) {
397
+ const refSet = new Set();
398
+ for (const [, mapped] of typeNameMap) {
399
+ if (mapped.inputName === mapped.unifiedName)
400
+ continue;
401
+ const inputRe = new RegExp(`\\b${escapeRegExp(mapped.inputName)}\\b`);
402
+ const outputRe = new RegExp(`\\b${escapeRegExp(mapped.outputName)}\\b`);
403
+ if (inputRe.test(result.input) || outputRe.test(result.output)) {
404
+ refSet.add(mapped.inputName);
405
+ }
406
+ }
407
+ deps.set(result.schemaName, refSet);
408
+ }
409
+ // Map inputName back to schemaName for dependency lookup
410
+ const inputNameToSchema = new Map();
411
+ for (const [schemaName, mapped] of typeNameMap) {
412
+ inputNameToSchema.set(mapped.inputName, schemaName);
413
+ }
414
+ // Topological sort (Kahn's algorithm)
415
+ const inDegree = new Map();
416
+ const graph = new Map();
417
+ for (const result of fixedResults) {
418
+ inDegree.set(result.schemaName, 0);
419
+ graph.set(result.schemaName, []);
420
+ }
421
+ for (const [schemaName, refInputNames] of deps) {
422
+ let count = 0;
423
+ for (const refInputName of refInputNames) {
424
+ const depSchema = inputNameToSchema.get(refInputName);
425
+ if (depSchema && graph.has(depSchema)) {
426
+ graph.get(depSchema).push(schemaName);
427
+ count++;
428
+ }
429
+ }
430
+ inDegree.set(schemaName, count);
431
+ }
432
+ const order = [];
433
+ const queue = [...inDegree.entries()].filter(([, d]) => d === 0).map(([n]) => n);
434
+ while (queue.length > 0) {
435
+ const node = queue.shift();
436
+ order.push(node);
437
+ for (const next of graph.get(node) ?? []) {
438
+ const d = inDegree.get(next) - 1;
439
+ inDegree.set(next, d);
440
+ if (d === 0)
441
+ queue.push(next);
442
+ }
443
+ }
444
+ // Append any remaining (cyclic) schemas at the end
445
+ for (const result of fixedResults) {
446
+ if (!order.includes(result.schemaName))
447
+ order.push(result.schemaName);
448
+ }
449
+ // Process in topological order, accumulating merged schemas
450
+ const mergedSet = new Set();
451
+ const resultMap = new Map(fixedResults.map((r) => [r.schemaName, r]));
452
+ for (const schemaName of order) {
453
+ const result = resultMap.get(schemaName);
454
+ if (!result)
455
+ continue;
456
+ let { input, output } = result;
457
+ // Apply unifications from already-determined merged schemas
458
+ for (const mergedSchema of mergedSet) {
459
+ const mapped = typeNameMap.get(mergedSchema);
460
+ if (!mapped)
461
+ continue;
462
+ const escapedInput = escapeRegExp(mapped.inputName);
463
+ const escapedOutput = escapeRegExp(mapped.outputName);
464
+ input = input.replace(new RegExp(`\\b${escapedInput}\\b`, "g"), mapped.unifiedName);
465
+ output = output.replace(new RegExp(`\\b${escapedOutput}\\b`, "g"), mapped.unifiedName);
466
+ }
467
+ resultMap.set(schemaName, { ...result, input, output });
468
+ // Check if this schema is now mergeable
469
+ if (input === output && !(result.brands && result.brands.length > 0)) {
470
+ const mapped = typeNameMap.get(schemaName);
471
+ if (mapped && mapped.inputName !== mapped.unifiedName) {
472
+ mergedSet.add(schemaName);
473
+ }
474
+ }
475
+ }
476
+ fixedResults = fixedResults.map((r) => resultMap.get(r.schemaName) ?? r);
477
+ }
478
+ const declarations = [];
479
+ // Only generate declarations for exported schemas
480
+ for (const result of fixedResults) {
481
+ if (!result.isExported) {
482
+ continue;
483
+ }
484
+ const typeName = mapName(result.schemaName);
485
+ const declaration = formatAsDeclaration(result, typeName, options);
486
+ declarations.push(declaration);
487
+ }
488
+ return declarations.join("\n\n");
489
+ }
490
+ /**
491
+ * Checks if any results have brand information.
492
+ */
493
+ function hasBrands(results) {
494
+ return results.some((r) => r.brands && r.brands.length > 0);
495
+ }
496
+ /**
497
+ * Generates a complete TypeScript declaration file content.
498
+ *
499
+ * @param results - Array of extraction results
500
+ * @param mapName - Function to map schema name to type names
501
+ * @param options - Declaration options
502
+ * @returns Complete .d.ts or .ts file content
503
+ */
504
+ export function generateDeclarationFile(results, mapName, options = {}) {
505
+ const lines = [];
506
+ // Add header comment
507
+ lines.push("// Generated by zinfer - Do not edit manually");
508
+ lines.push("");
509
+ // Add BRAND import if any result has brands
510
+ if (hasBrands(results)) {
511
+ lines.push('import type { BRAND } from "zod";');
512
+ lines.push("");
513
+ }
514
+ // Add type declarations
515
+ lines.push(formatMultipleAsDeclarations(results, mapName, options));
516
+ lines.push("");
517
+ return lines.join("\n");
518
+ }
519
+ //# 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,EAAE,iBAAiB,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAC7D,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,IAAI,iBAAiB,EAAE,CAAC;QACtB,KAAK,CAAC,IAAI,CAAC,cAAc,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QAC9C,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACvB,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IAC/C,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACxB,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAEhD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,YAAY,CACnB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C,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,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