zenko 0.1.10-beta.3 → 0.1.10

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/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // ../zenko-core/src/utils/topological-sort.ts
1
+ // src/utils/topological-sort.ts
2
2
  function topologicalSort(schemas) {
3
3
  const visited = /* @__PURE__ */ new Set();
4
4
  const visiting = /* @__PURE__ */ new Set();
@@ -47,7 +47,7 @@ function extractRefName(ref) {
47
47
  return ref.split("/").pop() || "Unknown";
48
48
  }
49
49
 
50
- // ../zenko-core/src/utils/property-name.ts
50
+ // src/utils/property-name.ts
51
51
  function isValidJSIdentifier(name) {
52
52
  if (!name) return false;
53
53
  const firstChar = name.at(0);
@@ -127,7 +127,7 @@ function formatPropertyName(name) {
127
127
  return isValidJSIdentifier(name) ? name : `"${name}"`;
128
128
  }
129
129
 
130
- // ../zenko-core/src/utils/string-utils.ts
130
+ // src/utils/string-utils.ts
131
131
  function toCamelCase(str) {
132
132
  return str.replace(/-([a-zA-Z])/g, (_, letter) => letter.toUpperCase()).replace(/-+$/, "");
133
133
  }
@@ -135,7 +135,7 @@ function capitalize(str) {
135
135
  return str.charAt(0).toUpperCase() + str.slice(1);
136
136
  }
137
137
 
138
- // ../zenko-core/src/utils/http-status.ts
138
+ // src/utils/http-status.ts
139
139
  var statusNameMap = {
140
140
  "400": "badRequest",
141
141
  "401": "unauthorized",
@@ -201,7 +201,7 @@ function isErrorStatus(status) {
201
201
  return code >= 400;
202
202
  }
203
203
 
204
- // ../zenko-core/src/utils/tree-shaking.ts
204
+ // src/utils/tree-shaking.ts
205
205
  function analyzeZenkoUsage(operations) {
206
206
  const usage = {
207
207
  usesHeaderFn: false,
@@ -241,7 +241,7 @@ function hasAnyErrors(errors) {
241
241
  return Boolean(errors && Object.keys(errors).length > 0);
242
242
  }
243
243
 
244
- // ../zenko-core/src/utils/collect-inline-types.ts
244
+ // src/utils/collect-inline-types.ts
245
245
  function collectInlineRequestTypes(operations, spec) {
246
246
  const requestTypesToGenerate = /* @__PURE__ */ new Map();
247
247
  const operationLookup = /* @__PURE__ */ new Map();
@@ -318,48 +318,8 @@ function collectInlineResponseTypes(operations, spec) {
318
318
  }
319
319
  return responseTypesToGenerate;
320
320
  }
321
- function collectInlineErrorTypes(operations, spec) {
322
- const errorTypesToGenerate = /* @__PURE__ */ new Map();
323
- const operationLookup = /* @__PURE__ */ new Map();
324
- for (const [, pathItem] of Object.entries(spec.paths || {})) {
325
- for (const [, operation] of Object.entries(pathItem)) {
326
- const op = operation;
327
- if (op.operationId) {
328
- operationLookup.set(op.operationId, op);
329
- }
330
- }
331
- }
332
- for (const [, pathItem] of Object.entries(spec.webhooks || {})) {
333
- for (const [, operation] of Object.entries(pathItem)) {
334
- const op = operation;
335
- if (op.operationId) {
336
- operationLookup.set(op.operationId, op);
337
- }
338
- }
339
- }
340
- for (const op of operations) {
341
- const operation = operationLookup.get(op.operationId);
342
- if (!operation) continue;
343
- const responses = operation.responses || {};
344
- for (const [statusCode, response] of Object.entries(responses)) {
345
- if (isErrorStatus(statusCode) && response.content) {
346
- const content = response.content;
347
- const jsonContent = content["application/json"];
348
- if (jsonContent && jsonContent.schema) {
349
- const schema = jsonContent.schema;
350
- const identifier = mapStatusToIdentifier(statusCode);
351
- const typeName = `${capitalize(toCamelCase(op.operationId))}${capitalize(identifier)}`;
352
- if (!schema.$ref || schema.allOf || schema.oneOf || schema.anyOf) {
353
- errorTypesToGenerate.set(typeName, schema);
354
- }
355
- }
356
- }
357
- }
358
- }
359
- return errorTypesToGenerate;
360
- }
361
321
 
362
- // ../zenko-core/src/utils/collect-referenced-schemas.ts
322
+ // src/utils/collect-referenced-schemas.ts
363
323
  function findContentType(content) {
364
324
  const contentTypes = Object.keys(content);
365
325
  if (contentTypes.includes("application/json")) {
@@ -497,7 +457,7 @@ function collectReferencedSchemas(operations, spec) {
497
457
  return referenced;
498
458
  }
499
459
 
500
- // ../zenko-core/src/utils/generate-helper-file.ts
460
+ // src/utils/generate-helper-file.ts
501
461
  function generateHelperFile() {
502
462
  const output = [];
503
463
  output.push("// Generated helper types for Zenko");
@@ -539,7 +499,7 @@ function generateHelperFile() {
539
499
  return output.join("\n");
540
500
  }
541
501
 
542
- // ../zenko-core/src/zenko.ts
502
+ // src/zenko.ts
543
503
  function generateWithMetadata(spec, options = {}) {
544
504
  const output = [];
545
505
  const generatedTypes = /* @__PURE__ */ new Set();
@@ -765,9 +725,6 @@ function generateWithMetadata(spec, options = {}) {
765
725
  }
766
726
  return result;
767
727
  }
768
- function generateFromDocument(spec, options = {}) {
769
- return generateWithMetadata(spec, options);
770
- }
771
728
  function generateRequestTypes(output, operations, spec, nameMap, schemaOptions) {
772
729
  const requestTypesToGenerate = collectInlineRequestTypes(operations, spec);
773
730
  if (requestTypesToGenerate.size > 0) {
@@ -790,8 +747,7 @@ function generateRequestTypes(output, operations, spec, nameMap, schemaOptions)
790
747
  }
791
748
  function generateResponseTypes(output, operations, spec, nameMap, schemaOptions) {
792
749
  const responseTypesToGenerate = collectInlineResponseTypes(operations, spec);
793
- const errorTypesToGenerate = collectInlineErrorTypes(operations, spec);
794
- if (responseTypesToGenerate.size > 0 || errorTypesToGenerate.size > 0) {
750
+ if (responseTypesToGenerate.size > 0) {
795
751
  output.push("// Generated Response Types");
796
752
  output.push("");
797
753
  for (const [typeName, schema] of responseTypesToGenerate) {
@@ -807,23 +763,10 @@ function generateResponseTypes(output, operations, spec, nameMap, schemaOptions)
807
763
  output.push(`export type ${typeName} = z.infer<typeof ${typeName}>;`);
808
764
  output.push("");
809
765
  }
810
- for (const [typeName, schema] of errorTypesToGenerate) {
811
- const generatedSchema = generateZodSchema(
812
- typeName,
813
- schema,
814
- /* @__PURE__ */ new Set(),
815
- schemaOptions,
816
- nameMap
817
- );
818
- output.push(generatedSchema);
819
- output.push("");
820
- output.push(`export type ${typeName} = z.infer<typeof ${typeName}>;`);
821
- output.push("");
822
- }
823
766
  }
824
767
  }
825
768
  function generate(spec, options = {}) {
826
- return generateFromDocument(spec, options).output;
769
+ return generateWithMetadata(spec, options).output;
827
770
  }
828
771
  function appendOperationField(buffer, key, value) {
829
772
  if (!value) return;
@@ -1552,8 +1495,6 @@ function applyNumericBounds(schema, builder) {
1552
1495
  return builder;
1553
1496
  }
1554
1497
  export {
1555
- generate,
1556
- generateFromDocument,
1557
- generateWithMetadata
1498
+ generate
1558
1499
  };
1559
1500
  //# sourceMappingURL=index.mjs.map