@scalar/openapi-parser 0.18.3 → 0.20.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +2 -204
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +2 -2
  6. package/dist/index.js.map +2 -2
  7. package/dist/utils/join/index.d.ts +3 -0
  8. package/dist/utils/join/index.d.ts.map +1 -0
  9. package/dist/utils/join/index.js +5 -0
  10. package/dist/utils/join/index.js.map +7 -0
  11. package/dist/utils/join/join.d.ts +59 -0
  12. package/dist/utils/join/join.d.ts.map +1 -0
  13. package/dist/utils/join/join.js +178 -0
  14. package/dist/utils/join/join.js.map +7 -0
  15. package/dist/utils/join/merge-objects.d.ts +21 -0
  16. package/dist/utils/join/merge-objects.d.ts.map +1 -0
  17. package/dist/utils/join/merge-objects.js +20 -0
  18. package/dist/utils/join/merge-objects.js.map +7 -0
  19. package/dist/utils/upgrade-from-three-to-three-one.js +5 -1
  20. package/dist/utils/upgrade-from-three-to-three-one.js.map +3 -3
  21. package/package.json +4 -13
  22. package/dist/plugins-browser.d.ts +0 -4
  23. package/dist/plugins-browser.d.ts.map +0 -1
  24. package/dist/plugins-browser.js +0 -9
  25. package/dist/plugins-browser.js.map +0 -7
  26. package/dist/plugins.d.ts +0 -5
  27. package/dist/plugins.d.ts.map +0 -1
  28. package/dist/plugins.js +0 -11
  29. package/dist/plugins.js.map +0 -7
  30. package/dist/utils/bundle/bundle.d.ts +0 -286
  31. package/dist/utils/bundle/bundle.d.ts.map +0 -1
  32. package/dist/utils/bundle/bundle.js +0 -251
  33. package/dist/utils/bundle/bundle.js.map +0 -7
  34. package/dist/utils/bundle/create-limiter.d.ts +0 -21
  35. package/dist/utils/bundle/create-limiter.d.ts.map +0 -1
  36. package/dist/utils/bundle/create-limiter.js +0 -31
  37. package/dist/utils/bundle/create-limiter.js.map +0 -7
  38. package/dist/utils/bundle/plugins/fetch-urls/index.d.ts +0 -39
  39. package/dist/utils/bundle/plugins/fetch-urls/index.d.ts.map +0 -1
  40. package/dist/utils/bundle/plugins/fetch-urls/index.js +0 -48
  41. package/dist/utils/bundle/plugins/fetch-urls/index.js.map +0 -7
  42. package/dist/utils/bundle/plugins/parse-json/index.d.ts +0 -13
  43. package/dist/utils/bundle/plugins/parse-json/index.d.ts.map +0 -1
  44. package/dist/utils/bundle/plugins/parse-json/index.js +0 -22
  45. package/dist/utils/bundle/plugins/parse-json/index.js.map +0 -7
  46. package/dist/utils/bundle/plugins/parse-yaml/index.d.ts +0 -13
  47. package/dist/utils/bundle/plugins/parse-yaml/index.d.ts.map +0 -1
  48. package/dist/utils/bundle/plugins/parse-yaml/index.js +0 -23
  49. package/dist/utils/bundle/plugins/parse-yaml/index.js.map +0 -7
  50. package/dist/utils/bundle/plugins/read-files/index.d.ts +0 -29
  51. package/dist/utils/bundle/plugins/read-files/index.d.ts.map +0 -1
  52. package/dist/utils/bundle/plugins/read-files/index.js +0 -30
  53. package/dist/utils/bundle/plugins/read-files/index.js.map +0 -7
  54. package/dist/utils/bundle/value-generator.d.ts +0 -79
  55. package/dist/utils/bundle/value-generator.d.ts.map +0 -1
  56. package/dist/utils/bundle/value-generator.js +0 -55
  57. package/dist/utils/bundle/value-generator.js.map +0 -7
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/utils/bundle/plugins/read-files/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,KAAK,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAEnF;;;;;;;;;;;;;GAaG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAmBnE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAKlC"}
@@ -1,30 +0,0 @@
1
- import { normalize } from "../../../../utils/normalize.js";
2
- import { isFilePath } from "../../../../utils/bundle/bundle.js";
3
- async function readFile(path) {
4
- const fs = typeof window === "undefined" ? await import("node:fs/promises") : void 0;
5
- if (fs === void 0) {
6
- throw "Can not use readFiles plugin outside of a node environment";
7
- }
8
- try {
9
- const fileContents = await fs.readFile(path, { encoding: "utf-8" });
10
- return {
11
- ok: true,
12
- data: normalize(fileContents)
13
- };
14
- } catch {
15
- return {
16
- ok: false
17
- };
18
- }
19
- }
20
- function readFiles() {
21
- return {
22
- validate: isFilePath,
23
- exec: readFile
24
- };
25
- }
26
- export {
27
- readFile,
28
- readFiles
29
- };
30
- //# sourceMappingURL=index.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../../src/utils/bundle/plugins/read-files/index.ts"],
4
- "sourcesContent": ["import { normalize } from '@/utils/normalize'\nimport { isFilePath, type Plugin, type ResolveResult } from '@/utils/bundle/bundle'\n\n/**\n * Reads and normalizes data from a local file\n * @param path - The file path to read from\n * @returns A promise that resolves to either the normalized data or an error result\n * @example\n * ```ts\n * const result = await readFile('./schemas/user.json')\n * if (result.ok) {\n * console.log(result.data) // The normalized data\n * } else {\n * console.log('Failed to read file')\n * }\n * ```\n */\nexport async function readFile(path: string): Promise<ResolveResult> {\n const fs = typeof window === 'undefined' ? await import('node:fs/promises') : undefined\n\n if (fs === undefined) {\n throw 'Can not use readFiles plugin outside of a node environment'\n }\n\n try {\n const fileContents = await fs.readFile(path, { encoding: 'utf-8' })\n\n return {\n ok: true,\n data: normalize(fileContents),\n }\n } catch {\n return {\n ok: false,\n }\n }\n}\n\n/**\n * Creates a plugin for handling local file references.\n * This plugin validates and reads data from local filesystem paths.\n *\n * @returns A plugin object with validate and exec functions\n * @example\n * const filePlugin = readFiles()\n * if (filePlugin.validate('./local-schema.json')) {\n * const result = await filePlugin.exec('./local-schema.json')\n * }\n */\nexport function readFiles(): Plugin {\n return {\n validate: isFilePath,\n exec: readFile,\n }\n}\n"],
5
- "mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,kBAAmD;AAgB5D,eAAsB,SAAS,MAAsC;AACnE,QAAM,KAAK,OAAO,WAAW,cAAc,MAAM,OAAO,kBAAkB,IAAI;AAE9E,MAAI,OAAO,QAAW;AACpB,UAAM;AAAA,EACR;AAEA,MAAI;AACF,UAAM,eAAe,MAAM,GAAG,SAAS,MAAM,EAAE,UAAU,QAAQ,CAAC;AAElE,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,MAAM,UAAU,YAAY;AAAA,IAC9B;AAAA,EACF,QAAQ;AACN,WAAO;AAAA,MACL,IAAI;AAAA,IACN;AAAA,EACF;AACF;AAaO,SAAS,YAAoB;AAClC,SAAO;AAAA,IACL,UAAU;AAAA,IACV,MAAM;AAAA,EACR;AACF;",
6
- "names": []
7
- }
@@ -1,79 +0,0 @@
1
- /**
2
- * Generates a short SHA-1 hash from a string value.
3
- * This function is used to create unique identifiers for external references
4
- * while keeping the hash length manageable. It uses the Web Crypto API to
5
- * generate a SHA-1 hash and returns the first 7 characters of the hex string.
6
- * If the hash would be all numbers, it ensures at least one letter is included.
7
- *
8
- * @param value - The string to hash
9
- * @returns A 7-character hexadecimal hash with at least one letter
10
- * @example
11
- * // Returns "2ae91d7"
12
- * await getHash("https://example.com/schema.json")
13
- */
14
- export declare function getHash(value: string): Promise<string>;
15
- /**
16
- * Generates a unique compressed value for a string, handling collisions by recursively compressing
17
- * until a unique value is found. This is used to create unique identifiers for external
18
- * references in the bundled OpenAPI document.
19
- *
20
- * @param compress - Function that generates a compressed value from a string
21
- * @param value - The original string value to compress
22
- * @param compressedToValue - Object mapping compressed values to their original values
23
- * @param prevCompressedValue - Optional previous compressed value to use as input for generating a new value
24
- * @param depth - Current recursion depth to prevent infinite loops
25
- * @returns A unique compressed value that doesn't conflict with existing values
26
- *
27
- * @example
28
- * const valueMap = {}
29
- * // First call generates compressed value for "example.com/schema.json"
30
- * const value1 = await generateUniqueValue(compress, "example.com/schema.json", valueMap)
31
- * // Returns something like "2ae91d7"
32
- *
33
- * // Second call with same value returns same compressed value
34
- * const value2 = await generateUniqueValue(compress, "example.com/schema.json", valueMap)
35
- * // Returns same value as value1
36
- *
37
- * // Call with different value generates new unique compressed value
38
- * const value3 = await generateUniqueValue(compress, "example.com/other.json", valueMap)
39
- * // Returns different value like "3bf82e9"
40
- */
41
- export declare function generateUniqueValue(compress: (value: string) => Promise<string> | string, value: string, compressedToValue: Record<string, string>, prevCompressedValue?: string, depth?: number): Promise<string>;
42
- /**
43
- * Factory function that creates a value generator with caching capabilities.
44
- * The generator maintains a bidirectional mapping between original values and their compressed forms.
45
- *
46
- * @param compress - Function that generates a compressed value from a string
47
- * @param compressedToValue - Initial mapping of compressed values to their original values
48
- * @returns An object with a generate method that produces unique compressed values
49
- *
50
- * @example
51
- * const compress = (value) => value.substring(0, 6) // Simple compression example
52
- * const initialMap = { 'abc123': 'example.com/schema.json' }
53
- * const generator = uniqueValueGeneratorFactory(compress, initialMap)
54
- *
55
- * // Generate compressed value for new string
56
- * const compressed = await generator.generate('example.com/other.json')
57
- * // Returns something like 'example'
58
- *
59
- * // Generate compressed value for existing string
60
- * const cached = await generator.generate('example.com/schema.json')
61
- * // Returns 'abc123' from cache
62
- */
63
- export declare const uniqueValueGeneratorFactory: (compress: (value: string) => Promise<string> | string, compressedToValue: Record<string, string>) => {
64
- /**
65
- * Generates a unique compressed value for the given input string.
66
- * First checks if a compressed value already exists in the cache.
67
- * If not, generates a new unique compressed value and stores it in the cache.
68
- *
69
- * @param value - The original string value to compress
70
- * @returns A Promise that resolves to the compressed string value
71
- *
72
- * @example
73
- * const generator = uniqueValueGeneratorFactory(compress, {})
74
- * const compressed = await generator.generate('example.com/schema.json')
75
- * // Returns a unique compressed value like 'example'
76
- */
77
- generate: (value: string) => Promise<string>;
78
- };
79
- //# sourceMappingURL=value-generator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"value-generator.d.ts","sourceRoot":"","sources":["../../../src/utils/bundle/value-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAsB,OAAO,CAAC,KAAK,EAAE,MAAM,mBAe1C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,EACrD,KAAK,EAAE,MAAM,EACb,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACzC,mBAAmB,CAAC,EAAE,MAAM,EAC5B,KAAK,SAAI,mBAoBV;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,2BAA2B,aAC5B,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,qBAClC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAMvC;;;;;;;;;;;;OAYG;sBACqB,MAAM;CAqBjC,CAAA"}
@@ -1,55 +0,0 @@
1
- async function getHash(value) {
2
- const encoder = new TextEncoder();
3
- const data = encoder.encode(value);
4
- const hashBuffer = await crypto.subtle.digest("SHA-1", data);
5
- const hashArray = Array.from(new Uint8Array(hashBuffer));
6
- const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
7
- const hash = hashHex.substring(0, 7);
8
- return hash.match(/^\d+$/) ? "a" + hash.substring(1) : hash;
9
- }
10
- async function generateUniqueValue(compress, value, compressedToValue, prevCompressedValue, depth = 0) {
11
- const MAX_DEPTH = 100;
12
- if (depth >= MAX_DEPTH) {
13
- throw "Can not generate unique compressed values";
14
- }
15
- const compressedValue = await compress(prevCompressedValue ?? value);
16
- if (compressedToValue[compressedValue] !== void 0 && compressedToValue[compressedValue] !== value) {
17
- return generateUniqueValue(compress, value, compressedToValue, compressedValue, depth + 1);
18
- }
19
- compressedToValue[compressedValue] = value;
20
- return compressedValue;
21
- }
22
- const uniqueValueGeneratorFactory = (compress, compressedToValue) => {
23
- const valueToCompressed = Object.fromEntries(Object.entries(compressedToValue).map(([key, value]) => [value, key]));
24
- return {
25
- /**
26
- * Generates a unique compressed value for the given input string.
27
- * First checks if a compressed value already exists in the cache.
28
- * If not, generates a new unique compressed value and stores it in the cache.
29
- *
30
- * @param value - The original string value to compress
31
- * @returns A Promise that resolves to the compressed string value
32
- *
33
- * @example
34
- * const generator = uniqueValueGeneratorFactory(compress, {})
35
- * const compressed = await generator.generate('example.com/schema.json')
36
- * // Returns a unique compressed value like 'example'
37
- */
38
- generate: async (value) => {
39
- const cache = valueToCompressed[value];
40
- if (cache) {
41
- return cache;
42
- }
43
- const generatedValue = await generateUniqueValue(compress, value, compressedToValue);
44
- const compressedValue = generatedValue.match(/^\d+$/) ? `a${generatedValue}` : generatedValue;
45
- valueToCompressed[value] = compressedValue;
46
- return compressedValue;
47
- }
48
- };
49
- };
50
- export {
51
- generateUniqueValue,
52
- getHash,
53
- uniqueValueGeneratorFactory
54
- };
55
- //# sourceMappingURL=value-generator.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/utils/bundle/value-generator.ts"],
4
- "sourcesContent": ["/**\n * Generates a short SHA-1 hash from a string value.\n * This function is used to create unique identifiers for external references\n * while keeping the hash length manageable. It uses the Web Crypto API to\n * generate a SHA-1 hash and returns the first 7 characters of the hex string.\n * If the hash would be all numbers, it ensures at least one letter is included.\n *\n * @param value - The string to hash\n * @returns A 7-character hexadecimal hash with at least one letter\n * @example\n * // Returns \"2ae91d7\"\n * await getHash(\"https://example.com/schema.json\")\n */\nexport async function getHash(value: string) {\n // Convert string to ArrayBuffer\n const encoder = new TextEncoder()\n const data = encoder.encode(value)\n\n // Hash the data\n const hashBuffer = await crypto.subtle.digest('SHA-1', data)\n\n // Convert buffer to hex string\n const hashArray = Array.from(new Uint8Array(hashBuffer))\n const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join('')\n\n // Return first 7 characters of the hash, ensuring at least one letter\n const hash = hashHex.substring(0, 7)\n return hash.match(/^\\d+$/) ? 'a' + hash.substring(1) : hash\n}\n\n/**\n * Generates a unique compressed value for a string, handling collisions by recursively compressing\n * until a unique value is found. This is used to create unique identifiers for external\n * references in the bundled OpenAPI document.\n *\n * @param compress - Function that generates a compressed value from a string\n * @param value - The original string value to compress\n * @param compressedToValue - Object mapping compressed values to their original values\n * @param prevCompressedValue - Optional previous compressed value to use as input for generating a new value\n * @param depth - Current recursion depth to prevent infinite loops\n * @returns A unique compressed value that doesn't conflict with existing values\n *\n * @example\n * const valueMap = {}\n * // First call generates compressed value for \"example.com/schema.json\"\n * const value1 = await generateUniqueValue(compress, \"example.com/schema.json\", valueMap)\n * // Returns something like \"2ae91d7\"\n *\n * // Second call with same value returns same compressed value\n * const value2 = await generateUniqueValue(compress, \"example.com/schema.json\", valueMap)\n * // Returns same value as value1\n *\n * // Call with different value generates new unique compressed value\n * const value3 = await generateUniqueValue(compress, \"example.com/other.json\", valueMap)\n * // Returns different value like \"3bf82e9\"\n */\nexport async function generateUniqueValue(\n compress: (value: string) => Promise<string> | string,\n value: string,\n compressedToValue: Record<string, string>,\n prevCompressedValue?: string,\n depth = 0,\n) {\n // Prevent infinite recursion by limiting depth\n const MAX_DEPTH = 100\n\n if (depth >= MAX_DEPTH) {\n throw 'Can not generate unique compressed values'\n }\n\n // Compress the value, using previous compressed value if provided\n const compressedValue = await compress(prevCompressedValue ?? value)\n\n // Handle collision by recursively trying with compressed value as input\n if (compressedToValue[compressedValue] !== undefined && compressedToValue[compressedValue] !== value) {\n return generateUniqueValue(compress, value, compressedToValue, compressedValue, depth + 1)\n }\n\n // Store mapping and return unique compressed value\n compressedToValue[compressedValue] = value\n return compressedValue\n}\n\n/**\n * Factory function that creates a value generator with caching capabilities.\n * The generator maintains a bidirectional mapping between original values and their compressed forms.\n *\n * @param compress - Function that generates a compressed value from a string\n * @param compressedToValue - Initial mapping of compressed values to their original values\n * @returns An object with a generate method that produces unique compressed values\n *\n * @example\n * const compress = (value) => value.substring(0, 6) // Simple compression example\n * const initialMap = { 'abc123': 'example.com/schema.json' }\n * const generator = uniqueValueGeneratorFactory(compress, initialMap)\n *\n * // Generate compressed value for new string\n * const compressed = await generator.generate('example.com/other.json')\n * // Returns something like 'example'\n *\n * // Generate compressed value for existing string\n * const cached = await generator.generate('example.com/schema.json')\n * // Returns 'abc123' from cache\n */\nexport const uniqueValueGeneratorFactory = (\n compress: (value: string) => Promise<string> | string,\n compressedToValue: Record<string, string>,\n) => {\n // Create a reverse mapping from original values to their compressed forms\n const valueToCompressed = Object.fromEntries(Object.entries(compressedToValue).map(([key, value]) => [value, key]))\n\n return {\n /**\n * Generates a unique compressed value for the given input string.\n * First checks if a compressed value already exists in the cache.\n * If not, generates a new unique compressed value and stores it in the cache.\n *\n * @param value - The original string value to compress\n * @returns A Promise that resolves to the compressed string value\n *\n * @example\n * const generator = uniqueValueGeneratorFactory(compress, {})\n * const compressed = await generator.generate('example.com/schema.json')\n * // Returns a unique compressed value like 'example'\n */\n generate: async (value: string) => {\n // Check if we already have a compressed value for this input\n const cache = valueToCompressed[value]\n if (cache) {\n return cache\n }\n\n // Generate a new unique compressed value\n const generatedValue = await generateUniqueValue(compress, value, compressedToValue)\n\n // Ensure the generated string contains at least one non-numeric character\n // This prevents the `setValueAtPath` function from interpreting the value as an array index\n // by forcing it to be treated as an object property name\n const compressedValue = generatedValue.match(/^\\d+$/) ? `a${generatedValue}` : generatedValue\n\n // Store the new mapping in our cache\n valueToCompressed[value] = compressedValue\n\n return compressedValue\n },\n }\n}\n"],
5
- "mappings": "AAaA,eAAsB,QAAQ,OAAe;AAE3C,QAAM,UAAU,IAAI,YAAY;AAChC,QAAM,OAAO,QAAQ,OAAO,KAAK;AAGjC,QAAM,aAAa,MAAM,OAAO,OAAO,OAAO,SAAS,IAAI;AAG3D,QAAM,YAAY,MAAM,KAAK,IAAI,WAAW,UAAU,CAAC;AACvD,QAAM,UAAU,UAAU,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AAG7E,QAAM,OAAO,QAAQ,UAAU,GAAG,CAAC;AACnC,SAAO,KAAK,MAAM,OAAO,IAAI,MAAM,KAAK,UAAU,CAAC,IAAI;AACzD;AA4BA,eAAsB,oBACpB,UACA,OACA,mBACA,qBACA,QAAQ,GACR;AAEA,QAAM,YAAY;AAElB,MAAI,SAAS,WAAW;AACtB,UAAM;AAAA,EACR;AAGA,QAAM,kBAAkB,MAAM,SAAS,uBAAuB,KAAK;AAGnE,MAAI,kBAAkB,eAAe,MAAM,UAAa,kBAAkB,eAAe,MAAM,OAAO;AACpG,WAAO,oBAAoB,UAAU,OAAO,mBAAmB,iBAAiB,QAAQ,CAAC;AAAA,EAC3F;AAGA,oBAAkB,eAAe,IAAI;AACrC,SAAO;AACT;AAuBO,MAAM,8BAA8B,CACzC,UACA,sBACG;AAEH,QAAM,oBAAoB,OAAO,YAAY,OAAO,QAAQ,iBAAiB,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,OAAO,GAAG,CAAC,CAAC;AAElH,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAcL,UAAU,OAAO,UAAkB;AAEjC,YAAM,QAAQ,kBAAkB,KAAK;AACrC,UAAI,OAAO;AACT,eAAO;AAAA,MACT;AAGA,YAAM,iBAAiB,MAAM,oBAAoB,UAAU,OAAO,iBAAiB;AAKnF,YAAM,kBAAkB,eAAe,MAAM,OAAO,IAAI,IAAI,cAAc,KAAK;AAG/E,wBAAkB,KAAK,IAAI;AAE3B,aAAO;AAAA,IACT;AAAA,EACF;AACF;",
6
- "names": []
7
- }