@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.cjs CHANGED
@@ -21,7 +21,7 @@ var compatibility = {
21
21
  "node": ">=22.22"
22
22
  };
23
23
  // package.json
24
- var version = "5.18.8";
24
+ var version = "5.19.0";
25
25
  // src/constants.ts
26
26
  /**
27
27
  * Default parser options applied when no explicit options are provided.
@@ -229,6 +229,47 @@ function patchDiscriminatorNode(node, entry) {
229
229
  members: newMembers
230
230
  };
231
231
  }
232
+ // ../../internals/utils/src/promise.ts
233
+ /**
234
+ * Returns the value cached under `key` in `store`, computing and storing it on the first call.
235
+ * Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
236
+ * keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
237
+ *
238
+ * @example
239
+ * `const refs = memo(refCache, node, () => collectRefs(node))`
240
+ */
241
+ function memo(store, key, compute) {
242
+ const cached = store.get(key);
243
+ if (cached !== void 0 || store.has(key)) return cached;
244
+ const value = compute();
245
+ store.set(key, value);
246
+ return value;
247
+ }
248
+ function createStore({ weak, max } = {}) {
249
+ if (weak) return /* @__PURE__ */ new WeakMap();
250
+ const entry = /* @__PURE__ */ new Map();
251
+ if (max === void 0) return entry;
252
+ const set = (key, value) => {
253
+ if (entry.size >= max) entry.clear();
254
+ entry.set(key, value);
255
+ };
256
+ if (max !== 1) return {
257
+ has: (key) => entry.has(key),
258
+ get: (key) => entry.get(key),
259
+ set
260
+ };
261
+ const touch = (key) => {
262
+ if (!entry.has(key)) return false;
263
+ set(key, entry.get(key));
264
+ return true;
265
+ };
266
+ return {
267
+ has: touch,
268
+ get: (key) => touch(key) ? entry.get(key) : void 0,
269
+ set
270
+ };
271
+ }
272
+ memo.create = createStore;
232
273
  // ../../internals/utils/src/casing.ts
233
274
  /**
234
275
  * Shared implementation for camelCase and PascalCase conversion.
@@ -243,16 +284,10 @@ function convert(text, pascal) {
243
284
  return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
244
285
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
245
286
  }
246
- const cache = /* @__PURE__ */ new Map();
247
- const cacheLimit = 1e5;
287
+ const cache = memo.create({ max: 1e5 });
248
288
  function toCamelOrPascal(text, pascal) {
249
289
  const key = `${pascal ? "P" : "c"}${text}`;
250
- const cached = cache.get(key);
251
- if (cached !== void 0) return cached;
252
- const result = convert(text, pascal);
253
- if (cache.size >= cacheLimit) cache.clear();
254
- cache.set(key, result);
255
- return result;
290
+ return memo(cache, key, () => convert(text, pascal));
256
291
  }
257
292
  /**
258
293
  * Converts `text` to PascalCase.
@@ -370,42 +405,6 @@ async function read(path) {
370
405
  if (runtime.isBun) return Bun.file(path).text();
371
406
  return new Promise((resolvePromise, reject) => (0, node_fs.readFile)(path, { encoding: "utf8" }, (error, data) => error ? reject(error) : resolvePromise(data)));
372
407
  }
373
- // ../../internals/utils/src/promise.ts
374
- /**
375
- * Returns the value cached under `key` in `store`, computing and storing it on the first call.
376
- * Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
377
- * keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
378
- *
379
- * @example
380
- * `const refs = memo(refCache, node, () => collectRefs(node))`
381
- */
382
- function memo(store, key, compute) {
383
- const cached = store.get(key);
384
- if (cached !== void 0 || store.has(key)) return cached;
385
- const value = compute();
386
- store.set(key, value);
387
- return value;
388
- }
389
- function createStore({ type }) {
390
- if (type === "weak") return /* @__PURE__ */ new WeakMap();
391
- const entry = /* @__PURE__ */ new Map();
392
- if (type === "map") return entry;
393
- const set = (key, value) => {
394
- entry.clear();
395
- entry.set(key, value);
396
- };
397
- const touch = (key) => {
398
- if (!entry.has(key)) return false;
399
- set(key, entry.get(key));
400
- return true;
401
- };
402
- return {
403
- has: touch,
404
- get: (key) => touch(key) ? entry.get(key) : void 0,
405
- set
406
- };
407
- }
408
- memo.create = createStore;
409
408
  // src/oas.ts
410
409
  /**
411
410
  * Returns `true` when a schema should be treated as nullable.
@@ -544,7 +543,7 @@ function isJsonMimeType(mimeType) {
544
543
  */
545
544
  function createRefs(document) {
546
545
  const pointerCache = /* @__PURE__ */ new Map();
547
- const resolvedNodeCache = /* @__PURE__ */ new Map();
546
+ const resolvedNodeCache = memo.create();
548
547
  const resolvingRefs = /* @__PURE__ */ new Set();
549
548
  function walkPointer($ref) {
550
549
  const trimmed = $ref.trim();
@@ -594,7 +593,7 @@ function createRefs(document) {
594
593
  */
595
594
  function resolveNode(refPath, parse) {
596
595
  if (resolvingRefs.has(refPath)) return null;
597
- if (!resolvedNodeCache.has(refPath)) {
596
+ return memo(resolvedNodeCache, refPath, () => {
598
597
  let resolved = null;
599
598
  try {
600
599
  const referenced = resolve(refPath);
@@ -604,9 +603,8 @@ function createRefs(document) {
604
603
  resolvingRefs.delete(refPath);
605
604
  }
606
605
  } catch {}
607
- resolvedNodeCache.set(refPath, resolved);
608
- }
609
- return resolvedNodeCache.get(refPath) ?? null;
606
+ return resolved;
607
+ });
610
608
  }
611
609
  /**
612
610
  * Resolves a `$ref` value without mutating anything: when `value` holds a `$ref`, returns the
@@ -713,8 +711,8 @@ function pick(declarations, pointer) {
713
711
  * enclosing anchor, so a relative `$id` base or a recursively extended schema is not followed, upgrade when a spec needs that.
714
712
  */
715
713
  function resolveSchemaIds(document) {
716
- const targets = /* @__PURE__ */ new Map();
717
- const declare = (key, pointer) => targets.set(key, [...targets.get(key) ?? [], pointer]);
714
+ const targets = memo.create();
715
+ const declare = (key, pointer) => memo(targets, key, () => []).push(pointer);
718
716
  walk(document, "#", (node, pointer) => {
719
717
  if (typeof node["$id"] === "string") declare(node["$id"], pointer);
720
718
  for (const key of ["$anchor", "$dynamicAnchor"]) if (typeof node[key] === "string") declare(`#${node[key]}`, pointer);
@@ -732,7 +730,7 @@ function resolveSchemaIds(document) {
732
730
  }
733
731
  // src/sourceLocator.ts
734
732
  const flowGap = /(?:[\s,]|#[^\n]*)*/y;
735
- const indexes = memo.create({ type: "last" });
733
+ const indexes = memo.create({ max: 1 });
736
734
  function toKeyText(text) {
737
735
  if (!/^[-+.~\d]|^(?:null|true|false)$/i.test(text)) return text;
738
736
  try {
@@ -1123,19 +1121,17 @@ function getBaseUri(pathOrUrl, root) {
1123
1121
  * `const document = await bundleDocument('https://example.com/openapi.yaml')`
1124
1122
  */
1125
1123
  async function bundleDocument(pathOrUrl, { document, sources = [] } = {}) {
1126
- const cache = /* @__PURE__ */ new Map();
1124
+ const cache = memo.create();
1127
1125
  const toKey = (sourcePath) => urlRegExp.test(sourcePath) ? new URL(sourcePath).href : sourcePath;
1128
1126
  let entry = pathOrUrl;
1129
1127
  let entryDocument = document;
1130
1128
  const resolver = (sourcePath) => {
1131
1129
  if (entryDocument !== void 0 && toKey(sourcePath) === toKey(entry)) return Promise.resolve(entryDocument);
1132
1130
  const key = toKey(sourcePath);
1133
- const cached = cache.get(key);
1134
- if (cached) return cached;
1135
- sources.push(key);
1136
- const result = resolveSource(sourcePath, { remember: key === toKey(pathOrUrl) });
1137
- cache.set(key, result);
1138
- return result;
1131
+ return memo(cache, key, () => {
1132
+ sources.push(key);
1133
+ return resolveSource(sourcePath, { remember: key === toKey(pathOrUrl) });
1134
+ });
1139
1135
  };
1140
1136
  const root = await resolver(pathOrUrl);
1141
1137
  const scan = resolveTargets(root);
@@ -1511,13 +1507,8 @@ function getSchemas(document, { contentType }, refs) {
1511
1507
  pointer: `${ref}/content/${escapePointerToken(extracted.contentType)}/schema`
1512
1508
  }];
1513
1509
  }))];
1514
- const normalizedNames = /* @__PURE__ */ new Map();
1515
- for (const item of candidates) {
1516
- const key = pascalCase(item.originalName);
1517
- const bucket = normalizedNames.get(key) ?? [];
1518
- bucket.push(item);
1519
- normalizedNames.set(key, bucket);
1520
- }
1510
+ const normalizedNames = memo.create();
1511
+ for (const item of candidates) memo(normalizedNames, pascalCase(item.originalName), () => []).push(item);
1521
1512
  const schemas = {};
1522
1513
  const renames = /* @__PURE__ */ new Map();
1523
1514
  const pointers = /* @__PURE__ */ new Map();
@@ -1915,7 +1906,7 @@ let formatTally;
1915
1906
  * thousands of warnings that say the same thing. `fn` must be synchronous.
1916
1907
  */
1917
1908
  function groupUnsupportedFormats(fn) {
1918
- formatTally = /* @__PURE__ */ new Map();
1909
+ formatTally = memo.create();
1919
1910
  try {
1920
1911
  return fn();
1921
1912
  } finally {
@@ -1926,7 +1917,7 @@ function groupUnsupportedFormats(fn) {
1926
1917
  }
1927
1918
  function tallyFormat(format, pointer) {
1928
1919
  if (!formatTally) return reportUnsupportedFormat(format, [pointer]);
1929
- formatTally.set(format, (formatTally.get(format) ?? /* @__PURE__ */ new Set()).add(pointer));
1920
+ memo(formatTally, format, () => /* @__PURE__ */ new Set()).add(pointer);
1930
1921
  }
1931
1922
  function reportUnsupportedFormat(format, pointers) {
1932
1923
  const count = pointers.length;
@@ -1983,10 +1974,10 @@ function visit(node, pointer) {
1983
1974
  */
1984
1975
  function reportDuplicateDiscriminators(node, propertyName, pointer) {
1985
1976
  const keyword = node.strategy === "any" ? "anyOf" : "oneOf";
1986
- const membersByValue = /* @__PURE__ */ new Map();
1977
+ const membersByValue = memo.create();
1987
1978
  for (const [index, member] of (node.members ?? []).entries()) {
1988
1979
  const label = memberName(member) ?? `${keyword}/${index}`;
1989
- for (const value of memberValues(member, propertyName)) membersByValue.set(value, [...membersByValue.get(value) ?? [], label]);
1980
+ for (const value of memberValues(member, propertyName)) memo(membersByValue, value, () => []).push(label);
1990
1981
  }
1991
1982
  const duplicates = [...membersByValue].filter(([, members]) => members.length > 1);
1992
1983
  if (!duplicates.length) return;