@scalar/openapi-parser 0.18.2 → 0.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +0 -202
  3. package/dist/index.d.ts +0 -1
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +0 -2
  6. package/dist/index.js.map +2 -2
  7. package/dist/utils/openapi/utils/workThroughQueue.d.ts.map +1 -1
  8. package/dist/utils/openapi/utils/workThroughQueue.js +1 -0
  9. package/dist/utils/openapi/utils/workThroughQueue.js.map +2 -2
  10. package/package.json +6 -26
  11. package/dist/plugins-browser.d.ts +0 -4
  12. package/dist/plugins-browser.d.ts.map +0 -1
  13. package/dist/plugins-browser.js +0 -9
  14. package/dist/plugins-browser.js.map +0 -7
  15. package/dist/plugins.d.ts +0 -5
  16. package/dist/plugins.d.ts.map +0 -1
  17. package/dist/plugins.js +0 -11
  18. package/dist/plugins.js.map +0 -7
  19. package/dist/utils/bundle/bundle.d.ts +0 -286
  20. package/dist/utils/bundle/bundle.d.ts.map +0 -1
  21. package/dist/utils/bundle/bundle.js +0 -251
  22. package/dist/utils/bundle/bundle.js.map +0 -7
  23. package/dist/utils/bundle/create-limiter.d.ts +0 -21
  24. package/dist/utils/bundle/create-limiter.d.ts.map +0 -1
  25. package/dist/utils/bundle/create-limiter.js +0 -31
  26. package/dist/utils/bundle/create-limiter.js.map +0 -7
  27. package/dist/utils/bundle/plugins/fetch-urls/index.d.ts +0 -39
  28. package/dist/utils/bundle/plugins/fetch-urls/index.d.ts.map +0 -1
  29. package/dist/utils/bundle/plugins/fetch-urls/index.js +0 -48
  30. package/dist/utils/bundle/plugins/fetch-urls/index.js.map +0 -7
  31. package/dist/utils/bundle/plugins/parse-json/index.d.ts +0 -13
  32. package/dist/utils/bundle/plugins/parse-json/index.d.ts.map +0 -1
  33. package/dist/utils/bundle/plugins/parse-json/index.js +0 -22
  34. package/dist/utils/bundle/plugins/parse-json/index.js.map +0 -7
  35. package/dist/utils/bundle/plugins/parse-yaml/index.d.ts +0 -13
  36. package/dist/utils/bundle/plugins/parse-yaml/index.d.ts.map +0 -1
  37. package/dist/utils/bundle/plugins/parse-yaml/index.js +0 -23
  38. package/dist/utils/bundle/plugins/parse-yaml/index.js.map +0 -7
  39. package/dist/utils/bundle/plugins/read-files/index.d.ts +0 -29
  40. package/dist/utils/bundle/plugins/read-files/index.d.ts.map +0 -1
  41. package/dist/utils/bundle/plugins/read-files/index.js +0 -30
  42. package/dist/utils/bundle/plugins/read-files/index.js.map +0 -7
  43. package/dist/utils/bundle/value-generator.d.ts +0 -79
  44. package/dist/utils/bundle/value-generator.d.ts.map +0 -1
  45. package/dist/utils/bundle/value-generator.js +0 -55
  46. package/dist/utils/bundle/value-generator.js.map +0 -7
@@ -1,31 +0,0 @@
1
- function createLimiter(maxConcurrent) {
2
- let activeCount = 0;
3
- const queue = [];
4
- const next = () => {
5
- if (queue.length === 0 || activeCount >= maxConcurrent) {
6
- return;
7
- }
8
- const resolve = queue.shift();
9
- if (resolve) {
10
- resolve();
11
- }
12
- };
13
- const run = async (fn) => {
14
- if (activeCount >= maxConcurrent) {
15
- await new Promise((resolve) => queue.push(resolve));
16
- }
17
- activeCount++;
18
- try {
19
- const result = await fn();
20
- return result;
21
- } finally {
22
- activeCount--;
23
- next();
24
- }
25
- };
26
- return run;
27
- }
28
- export {
29
- createLimiter
30
- };
31
- //# sourceMappingURL=create-limiter.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/utils/bundle/create-limiter.ts"],
4
- "sourcesContent": ["/**\n * Creates a function that limits the number of concurrent executions of async functions.\n *\n * @param maxConcurrent - Maximum number of concurrent executions allowed\n * @returns A function that wraps async functions to limit their concurrent execution\n *\n * @example\n * ```ts\n * const limiter = createLimiter(2) // Allow max 2 concurrent executions\n *\n * // These will run with max 2 at a time\n * const results = await Promise.all([\n * limiter(() => fetch('/api/1')),\n * limiter(() => fetch('/api/2')),\n * limiter(() => fetch('/api/3')),\n * limiter(() => fetch('/api/4'))\n * ])\n * ```\n */\nexport function createLimiter(maxConcurrent: number) {\n let activeCount = 0\n const queue: (() => void)[] = []\n\n const next = () => {\n if (queue.length === 0 || activeCount >= maxConcurrent) {\n return\n }\n\n const resolve = queue.shift()\n\n if (resolve) {\n resolve()\n }\n }\n\n const run = async <T>(fn: () => Promise<T>): Promise<T> => {\n if (activeCount >= maxConcurrent) {\n await new Promise<void>((resolve) => queue.push(resolve))\n }\n\n activeCount++\n try {\n const result = await fn()\n return result\n } finally {\n activeCount--\n next()\n }\n }\n\n return run\n}\n"],
5
- "mappings": "AAmBO,SAAS,cAAc,eAAuB;AACnD,MAAI,cAAc;AAClB,QAAM,QAAwB,CAAC;AAE/B,QAAM,OAAO,MAAM;AACjB,QAAI,MAAM,WAAW,KAAK,eAAe,eAAe;AACtD;AAAA,IACF;AAEA,UAAM,UAAU,MAAM,MAAM;AAE5B,QAAI,SAAS;AACX,cAAQ;AAAA,IACV;AAAA,EACF;AAEA,QAAM,MAAM,OAAU,OAAqC;AACzD,QAAI,eAAe,eAAe;AAChC,YAAM,IAAI,QAAc,CAAC,YAAY,MAAM,KAAK,OAAO,CAAC;AAAA,IAC1D;AAEA;AACA,QAAI;AACF,YAAM,SAAS,MAAM,GAAG;AACxB,aAAO;AAAA,IACT,UAAE;AACA;AACA,WAAK;AAAA,IACP;AAAA,EACF;AAEA,SAAO;AACT;",
6
- "names": []
7
- }
@@ -1,39 +0,0 @@
1
- import { type Plugin, type ResolveResult } from '../../../../utils/bundle/bundle.js';
2
- type FetchConfig = Partial<{
3
- headers: {
4
- headers: HeadersInit;
5
- domains: string[];
6
- }[];
7
- fetch: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
8
- }>;
9
- /**
10
- * Fetches and normalizes data from a remote URL
11
- * @param url - The URL to fetch data from
12
- * @returns A promise that resolves to either the normalized data or an error result
13
- * @example
14
- * ```ts
15
- * const result = await fetchUrl('https://api.example.com/data.json')
16
- * if (result.ok) {
17
- * console.log(result.data) // The normalized data
18
- * } else {
19
- * console.log('Failed to fetch data')
20
- * }
21
- * ```
22
- */
23
- export declare function fetchUrl(url: string, limiter: <T>(fn: () => Promise<T>) => Promise<T>, config?: FetchConfig): Promise<ResolveResult>;
24
- /**
25
- * Creates a plugin for handling remote URL references.
26
- * This plugin validates and fetches data from HTTP/HTTPS URLs.
27
- *
28
- * @returns A plugin object with validate and exec functions
29
- * @example
30
- * const urlPlugin = fetchUrls()
31
- * if (urlPlugin.validate('https://example.com/schema.json')) {
32
- * const result = await urlPlugin.exec('https://example.com/schema.json')
33
- * }
34
- */
35
- export declare function fetchUrls(config?: FetchConfig & Partial<{
36
- limit: number | null;
37
- }>): Plugin;
38
- export {};
39
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/utils/bundle/plugins/fetch-urls/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAGpF,KAAK,WAAW,GAAG,OAAO,CAAC;IACzB,OAAO,EAAE;QAAE,OAAO,EAAE,WAAW,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAA;IACtD,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAC3F,CAAC,CAAA;AAcF;;;;;;;;;;;;;GAaG;AACH,wBAAsB,QAAQ,CAC5B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAChD,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,aAAa,CAAC,CAgCxB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,GAAG,MAAM,CAQ1F"}
@@ -1,48 +0,0 @@
1
- import { normalize } from "../../../../utils/normalize.js";
2
- import { isRemoteUrl } from "../../../../utils/bundle/bundle.js";
3
- import { createLimiter } from "../../../../utils/bundle/create-limiter.js";
4
- const getHost = (url) => {
5
- try {
6
- return new URL(url).host;
7
- } catch {
8
- return null;
9
- }
10
- };
11
- async function fetchUrl(url, limiter, config) {
12
- try {
13
- const host = getHost(url);
14
- const headers = config?.headers?.find((a) => a.domains.find((d) => d === host) !== void 0)?.headers;
15
- const exec = config?.fetch ?? fetch;
16
- const result = await limiter(
17
- () => exec(url, {
18
- headers
19
- })
20
- );
21
- if (result.ok) {
22
- const body = await result.text();
23
- return {
24
- ok: true,
25
- data: normalize(body)
26
- };
27
- }
28
- return {
29
- ok: false
30
- };
31
- } catch {
32
- return {
33
- ok: false
34
- };
35
- }
36
- }
37
- function fetchUrls(config) {
38
- const limiter = config?.limit ? createLimiter(config.limit) : (fn) => fn();
39
- return {
40
- validate: isRemoteUrl,
41
- exec: (value) => fetchUrl(value, limiter, config)
42
- };
43
- }
44
- export {
45
- fetchUrl,
46
- fetchUrls
47
- };
48
- //# sourceMappingURL=index.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../../src/utils/bundle/plugins/fetch-urls/index.ts"],
4
- "sourcesContent": ["import { normalize } from '@/utils/normalize'\nimport { isRemoteUrl, type Plugin, type ResolveResult } from '@/utils/bundle/bundle'\nimport { createLimiter } from '@/utils/bundle/create-limiter'\n\ntype FetchConfig = Partial<{\n headers: { headers: HeadersInit; domains: string[] }[]\n fetch: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>\n}>\n\n/**\n * Safely checks for host from a URL\n * Needed because we cannot create a URL from a relative remote URL ex: examples/openapi.json\n */\nconst getHost = (url: string): string | null => {\n try {\n return new URL(url).host\n } catch {\n return null\n }\n}\n\n/**\n * Fetches and normalizes data from a remote URL\n * @param url - The URL to fetch data from\n * @returns A promise that resolves to either the normalized data or an error result\n * @example\n * ```ts\n * const result = await fetchUrl('https://api.example.com/data.json')\n * if (result.ok) {\n * console.log(result.data) // The normalized data\n * } else {\n * console.log('Failed to fetch data')\n * }\n * ```\n */\nexport async function fetchUrl(\n url: string,\n limiter: <T>(fn: () => Promise<T>) => Promise<T>,\n config?: FetchConfig,\n): Promise<ResolveResult> {\n try {\n const host = getHost(url)\n\n // Get the headers that match the domain\n const headers = config?.headers?.find((a) => a.domains.find((d) => d === host) !== undefined)?.headers\n\n const exec = config?.fetch ?? fetch\n\n const result = await limiter(() =>\n exec(url, {\n headers,\n }),\n )\n\n if (result.ok) {\n const body = await result.text()\n\n return {\n ok: true,\n data: normalize(body),\n }\n }\n\n return {\n ok: false,\n }\n } catch {\n return {\n ok: false,\n }\n }\n}\n\n/**\n * Creates a plugin for handling remote URL references.\n * This plugin validates and fetches data from HTTP/HTTPS URLs.\n *\n * @returns A plugin object with validate and exec functions\n * @example\n * const urlPlugin = fetchUrls()\n * if (urlPlugin.validate('https://example.com/schema.json')) {\n * const result = await urlPlugin.exec('https://example.com/schema.json')\n * }\n */\nexport function fetchUrls(config?: FetchConfig & Partial<{ limit: number | null }>): Plugin {\n // If there is a limit specified we limit the number of concurrent calls\n const limiter = config?.limit ? createLimiter(config.limit) : <T>(fn: () => Promise<T>) => fn()\n\n return {\n validate: isRemoteUrl,\n exec: (value) => fetchUrl(value, limiter, config),\n }\n}\n"],
5
- "mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,mBAAoD;AAC7D,SAAS,qBAAqB;AAW9B,MAAM,UAAU,CAAC,QAA+B;AAC9C,MAAI;AACF,WAAO,IAAI,IAAI,GAAG,EAAE;AAAA,EACtB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAgBA,eAAsB,SACpB,KACA,SACA,QACwB;AACxB,MAAI;AACF,UAAM,OAAO,QAAQ,GAAG;AAGxB,UAAM,UAAU,QAAQ,SAAS,KAAK,CAAC,MAAM,EAAE,QAAQ,KAAK,CAAC,MAAM,MAAM,IAAI,MAAM,MAAS,GAAG;AAE/F,UAAM,OAAO,QAAQ,SAAS;AAE9B,UAAM,SAAS,MAAM;AAAA,MAAQ,MAC3B,KAAK,KAAK;AAAA,QACR;AAAA,MACF,CAAC;AAAA,IACH;AAEA,QAAI,OAAO,IAAI;AACb,YAAM,OAAO,MAAM,OAAO,KAAK;AAE/B,aAAO;AAAA,QACL,IAAI;AAAA,QACJ,MAAM,UAAU,IAAI;AAAA,MACtB;AAAA,IACF;AAEA,WAAO;AAAA,MACL,IAAI;AAAA,IACN;AAAA,EACF,QAAQ;AACN,WAAO;AAAA,MACL,IAAI;AAAA,IACN;AAAA,EACF;AACF;AAaO,SAAS,UAAU,QAAkE;AAE1F,QAAM,UAAU,QAAQ,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAI,OAAyB,GAAG;AAE9F,SAAO;AAAA,IACL,UAAU;AAAA,IACV,MAAM,CAAC,UAAU,SAAS,OAAO,SAAS,MAAM;AAAA,EAClD;AACF;",
6
- "names": []
7
- }
@@ -1,13 +0,0 @@
1
- import type { Plugin } from '../../../../utils/bundle/bundle.js';
2
- /**
3
- * Creates a plugin that parses JSON strings into JavaScript objects.
4
- * @returns A plugin object with validate and exec functions
5
- * @example
6
- * ```ts
7
- * const jsonPlugin = parseJson()
8
- * const result = jsonPlugin.exec('{"name": "John", "age": 30}')
9
- * // result = { name: 'John', age: 30 }
10
- * ```
11
- */
12
- export declare function parseJson(): Plugin;
13
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/utils/bundle/plugins/parse-json/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,uBAAuB,CAAA;AAGlE;;;;;;;;;GASG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAgBlC"}
@@ -1,22 +0,0 @@
1
- import { isJson } from "../../../../utils/is-json.js";
2
- function parseJson() {
3
- return {
4
- validate: isJson,
5
- exec: async (value) => {
6
- try {
7
- return {
8
- ok: true,
9
- data: JSON.parse(value)
10
- };
11
- } catch {
12
- return {
13
- ok: false
14
- };
15
- }
16
- }
17
- };
18
- }
19
- export {
20
- parseJson
21
- };
22
- //# sourceMappingURL=index.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../../src/utils/bundle/plugins/parse-json/index.ts"],
4
- "sourcesContent": ["import type { Plugin, ResolveResult } from '@/utils/bundle/bundle'\nimport { isJson } from '@/utils/is-json'\n\n/**\n * Creates a plugin that parses JSON strings into JavaScript objects.\n * @returns A plugin object with validate and exec functions\n * @example\n * ```ts\n * const jsonPlugin = parseJson()\n * const result = jsonPlugin.exec('{\"name\": \"John\", \"age\": 30}')\n * // result = { name: 'John', age: 30 }\n * ```\n */\nexport function parseJson(): Plugin {\n return {\n validate: isJson,\n exec: async (value): Promise<ResolveResult> => {\n try {\n return {\n ok: true,\n data: JSON.parse(value),\n }\n } catch {\n return {\n ok: false,\n }\n }\n },\n }\n}\n"],
5
- "mappings": "AACA,SAAS,cAAc;AAYhB,SAAS,YAAoB;AAClC,SAAO;AAAA,IACL,UAAU;AAAA,IACV,MAAM,OAAO,UAAkC;AAC7C,UAAI;AACF,eAAO;AAAA,UACL,IAAI;AAAA,UACJ,MAAM,KAAK,MAAM,KAAK;AAAA,QACxB;AAAA,MACF,QAAQ;AACN,eAAO;AAAA,UACL,IAAI;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
6
- "names": []
7
- }
@@ -1,13 +0,0 @@
1
- import type { Plugin } from '../../../../utils/bundle/bundle.js';
2
- /**
3
- * Creates a plugin that parses YAML strings into JavaScript objects.
4
- * @returns A plugin object with validate and exec functions
5
- * @example
6
- * ```ts
7
- * const yamlPlugin = parseYaml()
8
- * const result = yamlPlugin.exec('name: John\nage: 30')
9
- * // result = { name: 'John', age: 30 }
10
- * ```
11
- */
12
- export declare function parseYaml(): Plugin;
13
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/utils/bundle/plugins/parse-yaml/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,uBAAuB,CAAA;AAIlE;;;;;;;;;GASG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAgBlC"}
@@ -1,23 +0,0 @@
1
- import { isYaml } from "../../../../utils/is-yaml.js";
2
- import YAML from "yaml";
3
- function parseYaml() {
4
- return {
5
- validate: isYaml,
6
- exec: async (value) => {
7
- try {
8
- return {
9
- ok: true,
10
- data: YAML.parse(value)
11
- };
12
- } catch {
13
- return {
14
- ok: false
15
- };
16
- }
17
- }
18
- };
19
- }
20
- export {
21
- parseYaml
22
- };
23
- //# sourceMappingURL=index.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../../src/utils/bundle/plugins/parse-yaml/index.ts"],
4
- "sourcesContent": ["import type { Plugin, ResolveResult } from '@/utils/bundle/bundle'\nimport { isYaml } from '@/utils/is-yaml'\nimport YAML from 'yaml'\n\n/**\n * Creates a plugin that parses YAML strings into JavaScript objects.\n * @returns A plugin object with validate and exec functions\n * @example\n * ```ts\n * const yamlPlugin = parseYaml()\n * const result = yamlPlugin.exec('name: John\\nage: 30')\n * // result = { name: 'John', age: 30 }\n * ```\n */\nexport function parseYaml(): Plugin {\n return {\n validate: isYaml,\n exec: async (value): Promise<ResolveResult> => {\n try {\n return {\n ok: true,\n data: YAML.parse(value),\n }\n } catch {\n return {\n ok: false,\n }\n }\n },\n }\n}\n"],
5
- "mappings": "AACA,SAAS,cAAc;AACvB,OAAO,UAAU;AAYV,SAAS,YAAoB;AAClC,SAAO;AAAA,IACL,UAAU;AAAA,IACV,MAAM,OAAO,UAAkC;AAC7C,UAAI;AACF,eAAO;AAAA,UACL,IAAI;AAAA,UACJ,MAAM,KAAK,MAAM,KAAK;AAAA,QACxB;AAAA,MACF,QAAQ;AACN,eAAO;AAAA,UACL,IAAI;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
6
- "names": []
7
- }
@@ -1,29 +0,0 @@
1
- import { type Plugin, type ResolveResult } from '../../../../utils/bundle/bundle.js';
2
- /**
3
- * Reads and normalizes data from a local file
4
- * @param path - The file path to read from
5
- * @returns A promise that resolves to either the normalized data or an error result
6
- * @example
7
- * ```ts
8
- * const result = await readFile('./schemas/user.json')
9
- * if (result.ok) {
10
- * console.log(result.data) // The normalized data
11
- * } else {
12
- * console.log('Failed to read file')
13
- * }
14
- * ```
15
- */
16
- export declare function readFile(path: string): Promise<ResolveResult>;
17
- /**
18
- * Creates a plugin for handling local file references.
19
- * This plugin validates and reads data from local filesystem paths.
20
- *
21
- * @returns A plugin object with validate and exec functions
22
- * @example
23
- * const filePlugin = readFiles()
24
- * if (filePlugin.validate('./local-schema.json')) {
25
- * const result = await filePlugin.exec('./local-schema.json')
26
- * }
27
- */
28
- export declare function readFiles(): Plugin;
29
- //# sourceMappingURL=index.d.ts.map
@@ -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
- }