zenko 0.1.10-beta.2 → 0.1.10-beta.4
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 +21 -11
- package/dist/cli.cjs +94 -176
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.mjs +94 -176
- package/dist/cli.mjs.map +1 -1
- package/dist/index.cjs +13 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +48 -1
- package/dist/index.d.ts +48 -1
- package/dist/index.mjs +12 -71
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -20,13 +20,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
generate: () => generate
|
|
24
|
-
generateFromDocument: () => generateFromDocument,
|
|
25
|
-
generateWithMetadata: () => generateWithMetadata
|
|
23
|
+
generate: () => generate
|
|
26
24
|
});
|
|
27
25
|
module.exports = __toCommonJS(index_exports);
|
|
28
26
|
|
|
29
|
-
//
|
|
27
|
+
// src/utils/topological-sort.ts
|
|
30
28
|
function topologicalSort(schemas) {
|
|
31
29
|
const visited = /* @__PURE__ */ new Set();
|
|
32
30
|
const visiting = /* @__PURE__ */ new Set();
|
|
@@ -75,7 +73,7 @@ function extractRefName(ref) {
|
|
|
75
73
|
return ref.split("/").pop() || "Unknown";
|
|
76
74
|
}
|
|
77
75
|
|
|
78
|
-
//
|
|
76
|
+
// src/utils/property-name.ts
|
|
79
77
|
function isValidJSIdentifier(name) {
|
|
80
78
|
if (!name) return false;
|
|
81
79
|
const firstChar = name.at(0);
|
|
@@ -155,7 +153,7 @@ function formatPropertyName(name) {
|
|
|
155
153
|
return isValidJSIdentifier(name) ? name : `"${name}"`;
|
|
156
154
|
}
|
|
157
155
|
|
|
158
|
-
//
|
|
156
|
+
// src/utils/string-utils.ts
|
|
159
157
|
function toCamelCase(str) {
|
|
160
158
|
return str.replace(/-([a-zA-Z])/g, (_, letter) => letter.toUpperCase()).replace(/-+$/, "");
|
|
161
159
|
}
|
|
@@ -163,7 +161,7 @@ function capitalize(str) {
|
|
|
163
161
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
164
162
|
}
|
|
165
163
|
|
|
166
|
-
//
|
|
164
|
+
// src/utils/http-status.ts
|
|
167
165
|
var statusNameMap = {
|
|
168
166
|
"400": "badRequest",
|
|
169
167
|
"401": "unauthorized",
|
|
@@ -229,7 +227,7 @@ function isErrorStatus(status) {
|
|
|
229
227
|
return code >= 400;
|
|
230
228
|
}
|
|
231
229
|
|
|
232
|
-
//
|
|
230
|
+
// src/utils/tree-shaking.ts
|
|
233
231
|
function analyzeZenkoUsage(operations) {
|
|
234
232
|
const usage = {
|
|
235
233
|
usesHeaderFn: false,
|
|
@@ -269,7 +267,7 @@ function hasAnyErrors(errors) {
|
|
|
269
267
|
return Boolean(errors && Object.keys(errors).length > 0);
|
|
270
268
|
}
|
|
271
269
|
|
|
272
|
-
//
|
|
270
|
+
// src/utils/collect-inline-types.ts
|
|
273
271
|
function collectInlineRequestTypes(operations, spec) {
|
|
274
272
|
const requestTypesToGenerate = /* @__PURE__ */ new Map();
|
|
275
273
|
const operationLookup = /* @__PURE__ */ new Map();
|
|
@@ -346,48 +344,8 @@ function collectInlineResponseTypes(operations, spec) {
|
|
|
346
344
|
}
|
|
347
345
|
return responseTypesToGenerate;
|
|
348
346
|
}
|
|
349
|
-
function collectInlineErrorTypes(operations, spec) {
|
|
350
|
-
const errorTypesToGenerate = /* @__PURE__ */ new Map();
|
|
351
|
-
const operationLookup = /* @__PURE__ */ new Map();
|
|
352
|
-
for (const [, pathItem] of Object.entries(spec.paths || {})) {
|
|
353
|
-
for (const [, operation] of Object.entries(pathItem)) {
|
|
354
|
-
const op = operation;
|
|
355
|
-
if (op.operationId) {
|
|
356
|
-
operationLookup.set(op.operationId, op);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
for (const [, pathItem] of Object.entries(spec.webhooks || {})) {
|
|
361
|
-
for (const [, operation] of Object.entries(pathItem)) {
|
|
362
|
-
const op = operation;
|
|
363
|
-
if (op.operationId) {
|
|
364
|
-
operationLookup.set(op.operationId, op);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
for (const op of operations) {
|
|
369
|
-
const operation = operationLookup.get(op.operationId);
|
|
370
|
-
if (!operation) continue;
|
|
371
|
-
const responses = operation.responses || {};
|
|
372
|
-
for (const [statusCode, response] of Object.entries(responses)) {
|
|
373
|
-
if (isErrorStatus(statusCode) && response.content) {
|
|
374
|
-
const content = response.content;
|
|
375
|
-
const jsonContent = content["application/json"];
|
|
376
|
-
if (jsonContent && jsonContent.schema) {
|
|
377
|
-
const schema = jsonContent.schema;
|
|
378
|
-
const identifier = mapStatusToIdentifier(statusCode);
|
|
379
|
-
const typeName = `${capitalize(toCamelCase(op.operationId))}${capitalize(identifier)}`;
|
|
380
|
-
if (!schema.$ref || schema.allOf || schema.oneOf || schema.anyOf) {
|
|
381
|
-
errorTypesToGenerate.set(typeName, schema);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
return errorTypesToGenerate;
|
|
388
|
-
}
|
|
389
347
|
|
|
390
|
-
//
|
|
348
|
+
// src/utils/collect-referenced-schemas.ts
|
|
391
349
|
function findContentType(content) {
|
|
392
350
|
const contentTypes = Object.keys(content);
|
|
393
351
|
if (contentTypes.includes("application/json")) {
|
|
@@ -525,7 +483,7 @@ function collectReferencedSchemas(operations, spec) {
|
|
|
525
483
|
return referenced;
|
|
526
484
|
}
|
|
527
485
|
|
|
528
|
-
//
|
|
486
|
+
// src/utils/generate-helper-file.ts
|
|
529
487
|
function generateHelperFile() {
|
|
530
488
|
const output = [];
|
|
531
489
|
output.push("// Generated helper types for Zenko");
|
|
@@ -567,7 +525,7 @@ function generateHelperFile() {
|
|
|
567
525
|
return output.join("\n");
|
|
568
526
|
}
|
|
569
527
|
|
|
570
|
-
//
|
|
528
|
+
// src/zenko.ts
|
|
571
529
|
function generateWithMetadata(spec, options = {}) {
|
|
572
530
|
const output = [];
|
|
573
531
|
const generatedTypes = /* @__PURE__ */ new Set();
|
|
@@ -793,9 +751,6 @@ function generateWithMetadata(spec, options = {}) {
|
|
|
793
751
|
}
|
|
794
752
|
return result;
|
|
795
753
|
}
|
|
796
|
-
function generateFromDocument(spec, options = {}) {
|
|
797
|
-
return generateWithMetadata(spec, options);
|
|
798
|
-
}
|
|
799
754
|
function generateRequestTypes(output, operations, spec, nameMap, schemaOptions) {
|
|
800
755
|
const requestTypesToGenerate = collectInlineRequestTypes(operations, spec);
|
|
801
756
|
if (requestTypesToGenerate.size > 0) {
|
|
@@ -818,8 +773,7 @@ function generateRequestTypes(output, operations, spec, nameMap, schemaOptions)
|
|
|
818
773
|
}
|
|
819
774
|
function generateResponseTypes(output, operations, spec, nameMap, schemaOptions) {
|
|
820
775
|
const responseTypesToGenerate = collectInlineResponseTypes(operations, spec);
|
|
821
|
-
|
|
822
|
-
if (responseTypesToGenerate.size > 0 || errorTypesToGenerate.size > 0) {
|
|
776
|
+
if (responseTypesToGenerate.size > 0) {
|
|
823
777
|
output.push("// Generated Response Types");
|
|
824
778
|
output.push("");
|
|
825
779
|
for (const [typeName, schema] of responseTypesToGenerate) {
|
|
@@ -835,23 +789,10 @@ function generateResponseTypes(output, operations, spec, nameMap, schemaOptions)
|
|
|
835
789
|
output.push(`export type ${typeName} = z.infer<typeof ${typeName}>;`);
|
|
836
790
|
output.push("");
|
|
837
791
|
}
|
|
838
|
-
for (const [typeName, schema] of errorTypesToGenerate) {
|
|
839
|
-
const generatedSchema = generateZodSchema(
|
|
840
|
-
typeName,
|
|
841
|
-
schema,
|
|
842
|
-
/* @__PURE__ */ new Set(),
|
|
843
|
-
schemaOptions,
|
|
844
|
-
nameMap
|
|
845
|
-
);
|
|
846
|
-
output.push(generatedSchema);
|
|
847
|
-
output.push("");
|
|
848
|
-
output.push(`export type ${typeName} = z.infer<typeof ${typeName}>;`);
|
|
849
|
-
output.push("");
|
|
850
|
-
}
|
|
851
792
|
}
|
|
852
793
|
}
|
|
853
794
|
function generate(spec, options = {}) {
|
|
854
|
-
return
|
|
795
|
+
return generateWithMetadata(spec, options).output;
|
|
855
796
|
}
|
|
856
797
|
function appendOperationField(buffer, key, value) {
|
|
857
798
|
if (!value) return;
|
|
@@ -1581,8 +1522,6 @@ function applyNumericBounds(schema, builder) {
|
|
|
1581
1522
|
}
|
|
1582
1523
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1583
1524
|
0 && (module.exports = {
|
|
1584
|
-
generate
|
|
1585
|
-
generateFromDocument,
|
|
1586
|
-
generateWithMetadata
|
|
1525
|
+
generate
|
|
1587
1526
|
});
|
|
1588
1527
|
//# sourceMappingURL=index.cjs.map
|