@kubb/adapter-oas 5.18.8 → 5.19.0

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.js CHANGED
@@ -14,7 +14,7 @@ var compatibility = {
14
14
  "node": ">=22.22"
15
15
  };
16
16
  // package.json
17
- var version = "5.18.8";
17
+ var version = "5.19.0";
18
18
  // src/constants.ts
19
19
  /**
20
20
  * Default parser options applied when no explicit options are provided.
@@ -222,6 +222,47 @@ function patchDiscriminatorNode(node, entry) {
222
222
  members: newMembers
223
223
  };
224
224
  }
225
+ // ../../internals/utils/src/promise.ts
226
+ /**
227
+ * Returns the value cached under `key` in `store`, computing and storing it on the first call.
228
+ * Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
229
+ * keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
230
+ *
231
+ * @example
232
+ * `const refs = memo(refCache, node, () => collectRefs(node))`
233
+ */
234
+ function memo(store, key, compute) {
235
+ const cached = store.get(key);
236
+ if (cached !== void 0 || store.has(key)) return cached;
237
+ const value = compute();
238
+ store.set(key, value);
239
+ return value;
240
+ }
241
+ function createStore({ weak, max } = {}) {
242
+ if (weak) return /* @__PURE__ */ new WeakMap();
243
+ const entry = /* @__PURE__ */ new Map();
244
+ if (max === void 0) return entry;
245
+ const set = (key, value) => {
246
+ if (entry.size >= max) entry.clear();
247
+ entry.set(key, value);
248
+ };
249
+ if (max !== 1) return {
250
+ has: (key) => entry.has(key),
251
+ get: (key) => entry.get(key),
252
+ set
253
+ };
254
+ const touch = (key) => {
255
+ if (!entry.has(key)) return false;
256
+ set(key, entry.get(key));
257
+ return true;
258
+ };
259
+ return {
260
+ has: touch,
261
+ get: (key) => touch(key) ? entry.get(key) : void 0,
262
+ set
263
+ };
264
+ }
265
+ memo.create = createStore;
225
266
  // ../../internals/utils/src/casing.ts
226
267
  /**
227
268
  * Shared implementation for camelCase and PascalCase conversion.
@@ -236,16 +277,10 @@ function convert(text, pascal) {
236
277
  return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
237
278
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
238
279
  }
239
- const cache = /* @__PURE__ */ new Map();
240
- const cacheLimit = 1e5;
280
+ const cache = memo.create({ max: 1e5 });
241
281
  function toCamelOrPascal(text, pascal) {
242
282
  const key = `${pascal ? "P" : "c"}${text}`;
243
- const cached = cache.get(key);
244
- if (cached !== void 0) return cached;
245
- const result = convert(text, pascal);
246
- if (cache.size >= cacheLimit) cache.clear();
247
- cache.set(key, result);
248
- return result;
283
+ return memo(cache, key, () => convert(text, pascal));
249
284
  }
250
285
  /**
251
286
  * Converts `text` to PascalCase.
@@ -363,42 +398,6 @@ async function read(path) {
363
398
  if (runtime.isBun) return Bun.file(path).text();
364
399
  return new Promise((resolvePromise, reject) => readFile(path, { encoding: "utf8" }, (error, data) => error ? reject(error) : resolvePromise(data)));
365
400
  }
366
- // ../../internals/utils/src/promise.ts
367
- /**
368
- * Returns the value cached under `key` in `store`, computing and storing it on the first call.
369
- * Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
370
- * keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
371
- *
372
- * @example
373
- * `const refs = memo(refCache, node, () => collectRefs(node))`
374
- */
375
- function memo(store, key, compute) {
376
- const cached = store.get(key);
377
- if (cached !== void 0 || store.has(key)) return cached;
378
- const value = compute();
379
- store.set(key, value);
380
- return value;
381
- }
382
- function createStore({ type }) {
383
- if (type === "weak") return /* @__PURE__ */ new WeakMap();
384
- const entry = /* @__PURE__ */ new Map();
385
- if (type === "map") return entry;
386
- const set = (key, value) => {
387
- entry.clear();
388
- entry.set(key, value);
389
- };
390
- const touch = (key) => {
391
- if (!entry.has(key)) return false;
392
- set(key, entry.get(key));
393
- return true;
394
- };
395
- return {
396
- has: touch,
397
- get: (key) => touch(key) ? entry.get(key) : void 0,
398
- set
399
- };
400
- }
401
- memo.create = createStore;
402
401
  // src/oas.ts
403
402
  /**
404
403
  * Returns `true` when a schema should be treated as nullable.
@@ -537,7 +536,7 @@ function isJsonMimeType(mimeType) {
537
536
  */
538
537
  function createRefs(document) {
539
538
  const pointerCache = /* @__PURE__ */ new Map();
540
- const resolvedNodeCache = /* @__PURE__ */ new Map();
539
+ const resolvedNodeCache = memo.create();
541
540
  const resolvingRefs = /* @__PURE__ */ new Set();
542
541
  function walkPointer($ref) {
543
542
  const trimmed = $ref.trim();
@@ -587,7 +586,7 @@ function createRefs(document) {
587
586
  */
588
587
  function resolveNode(refPath, parse) {
589
588
  if (resolvingRefs.has(refPath)) return null;
590
- if (!resolvedNodeCache.has(refPath)) {
589
+ return memo(resolvedNodeCache, refPath, () => {
591
590
  let resolved = null;
592
591
  try {
593
592
  const referenced = resolve(refPath);
@@ -597,9 +596,8 @@ function createRefs(document) {
597
596
  resolvingRefs.delete(refPath);
598
597
  }
599
598
  } catch {}
600
- resolvedNodeCache.set(refPath, resolved);
601
- }
602
- return resolvedNodeCache.get(refPath) ?? null;
599
+ return resolved;
600
+ });
603
601
  }
604
602
  /**
605
603
  * Resolves a `$ref` value without mutating anything: when `value` holds a `$ref`, returns the
@@ -706,8 +704,8 @@ function pick(declarations, pointer) {
706
704
  * enclosing anchor, so a relative `$id` base or a recursively extended schema is not followed, upgrade when a spec needs that.
707
705
  */
708
706
  function resolveSchemaIds(document) {
709
- const targets = /* @__PURE__ */ new Map();
710
- const declare = (key, pointer) => targets.set(key, [...targets.get(key) ?? [], pointer]);
707
+ const targets = memo.create();
708
+ const declare = (key, pointer) => memo(targets, key, () => []).push(pointer);
711
709
  walk(document, "#", (node, pointer) => {
712
710
  if (typeof node["$id"] === "string") declare(node["$id"], pointer);
713
711
  for (const key of ["$anchor", "$dynamicAnchor"]) if (typeof node[key] === "string") declare(`#${node[key]}`, pointer);
@@ -725,7 +723,7 @@ function resolveSchemaIds(document) {
725
723
  }
726
724
  // src/sourceLocator.ts
727
725
  const flowGap = /(?:[\s,]|#[^\n]*)*/y;
728
- const indexes = memo.create({ type: "last" });
726
+ const indexes = memo.create({ max: 1 });
729
727
  function toKeyText(text) {
730
728
  if (!/^[-+.~\d]|^(?:null|true|false)$/i.test(text)) return text;
731
729
  try {
@@ -1115,19 +1113,17 @@ function getBaseUri(pathOrUrl, root) {
1115
1113
  * `const document = await bundleDocument('https://example.com/openapi.yaml')`
1116
1114
  */
1117
1115
  async function bundleDocument(pathOrUrl, { document, sources = [] } = {}) {
1118
- const cache = /* @__PURE__ */ new Map();
1116
+ const cache = memo.create();
1119
1117
  const toKey = (sourcePath) => urlRegExp.test(sourcePath) ? new URL(sourcePath).href : sourcePath;
1120
1118
  let entry = pathOrUrl;
1121
1119
  let entryDocument = document;
1122
1120
  const resolver = (sourcePath) => {
1123
1121
  if (entryDocument !== void 0 && toKey(sourcePath) === toKey(entry)) return Promise.resolve(entryDocument);
1124
1122
  const key = toKey(sourcePath);
1125
- const cached = cache.get(key);
1126
- if (cached) return cached;
1127
- sources.push(key);
1128
- const result = resolveSource(sourcePath, { remember: key === toKey(pathOrUrl) });
1129
- cache.set(key, result);
1130
- return result;
1123
+ return memo(cache, key, () => {
1124
+ sources.push(key);
1125
+ return resolveSource(sourcePath, { remember: key === toKey(pathOrUrl) });
1126
+ });
1131
1127
  };
1132
1128
  const root = await resolver(pathOrUrl);
1133
1129
  const scan = resolveTargets(root);
@@ -1503,13 +1499,8 @@ function getSchemas(document, { contentType }, refs) {
1503
1499
  pointer: `${ref}/content/${escapePointerToken(extracted.contentType)}/schema`
1504
1500
  }];
1505
1501
  }))];
1506
- const normalizedNames = /* @__PURE__ */ new Map();
1507
- for (const item of candidates) {
1508
- const key = pascalCase(item.originalName);
1509
- const bucket = normalizedNames.get(key) ?? [];
1510
- bucket.push(item);
1511
- normalizedNames.set(key, bucket);
1512
- }
1502
+ const normalizedNames = memo.create();
1503
+ for (const item of candidates) memo(normalizedNames, pascalCase(item.originalName), () => []).push(item);
1513
1504
  const schemas = {};
1514
1505
  const renames = /* @__PURE__ */ new Map();
1515
1506
  const pointers = /* @__PURE__ */ new Map();
@@ -1907,7 +1898,7 @@ let formatTally;
1907
1898
  * thousands of warnings that say the same thing. `fn` must be synchronous.
1908
1899
  */
1909
1900
  function groupUnsupportedFormats(fn) {
1910
- formatTally = /* @__PURE__ */ new Map();
1901
+ formatTally = memo.create();
1911
1902
  try {
1912
1903
  return fn();
1913
1904
  } finally {
@@ -1918,7 +1909,7 @@ function groupUnsupportedFormats(fn) {
1918
1909
  }
1919
1910
  function tallyFormat(format, pointer) {
1920
1911
  if (!formatTally) return reportUnsupportedFormat(format, [pointer]);
1921
- formatTally.set(format, (formatTally.get(format) ?? /* @__PURE__ */ new Set()).add(pointer));
1912
+ memo(formatTally, format, () => /* @__PURE__ */ new Set()).add(pointer);
1922
1913
  }
1923
1914
  function reportUnsupportedFormat(format, pointers) {
1924
1915
  const count = pointers.length;
@@ -1975,10 +1966,10 @@ function visit(node, pointer) {
1975
1966
  */
1976
1967
  function reportDuplicateDiscriminators(node, propertyName, pointer) {
1977
1968
  const keyword = node.strategy === "any" ? "anyOf" : "oneOf";
1978
- const membersByValue = /* @__PURE__ */ new Map();
1969
+ const membersByValue = memo.create();
1979
1970
  for (const [index, member] of (node.members ?? []).entries()) {
1980
1971
  const label = memberName(member) ?? `${keyword}/${index}`;
1981
- for (const value of memberValues(member, propertyName)) membersByValue.set(value, [...membersByValue.get(value) ?? [], label]);
1972
+ for (const value of memberValues(member, propertyName)) memo(membersByValue, value, () => []).push(label);
1982
1973
  }
1983
1974
  const duplicates = [...membersByValue].filter(([, members]) => members.length > 1);
1984
1975
  if (!duplicates.length) return;