@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
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/utils/join/merge-objects.ts"],
4
+ "sourcesContent": ["/**\n * Deep merges two objects, combining their properties recursively.\n *\n * \u26A0\uFE0F Note: This operation assumes there are no key collisions between the objects.\n * @param a - Target object to merge into\n * @param b - Source object to merge from\n * @returns The merged object (mutates and returns a)\n *\n * @example\n * // Simple merge\n * const a = { name: 'John' }\n * const b = { age: 30 }\n * mergeObjects(a, b) // { name: 'John', age: 30 }\n *\n * // Nested merge\n * const a = { user: { name: 'John' } }\n * const b = { user: { age: 30 } }\n * mergeObjects(a, b) // { user: { name: 'John', age: 30 } }\n */\nexport const mergeObjects = <R>(a: Record<string, unknown>, b: Record<string, unknown>): R => {\n for (const key in b) {\n if (!(key in a)) {\n a[key] = b[key]\n } else {\n const aValue = a[key]\n const bValue = b[key]\n\n if (typeof aValue === 'object' && aValue !== null && typeof bValue === 'object' && bValue !== null) {\n mergeObjects(aValue as Record<string, unknown>, bValue as Record<string, unknown>)\n } else {\n a[key] = bValue // Overwrite with b's value if not an object\n }\n }\n }\n\n return a as R\n}\n"],
5
+ "mappings": "AAmBO,MAAM,eAAe,CAAI,GAA4B,MAAkC;AAC5F,aAAW,OAAO,GAAG;AACnB,QAAI,EAAE,OAAO,IAAI;AACf,QAAE,GAAG,IAAI,EAAE,GAAG;AAAA,IAChB,OAAO;AACL,YAAM,SAAS,EAAE,GAAG;AACpB,YAAM,SAAS,EAAE,GAAG;AAEpB,UAAI,OAAO,WAAW,YAAY,WAAW,QAAQ,OAAO,WAAW,YAAY,WAAW,MAAM;AAClG,qBAAa,QAAmC,MAAiC;AAAA,MACnF,OAAO;AACL,UAAE,GAAG,IAAI;AAAA,MACX;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -77,23 +77,27 @@ const applyChangesToDocument = (schema, path) => {
77
77
  if (path.includes("content") && path.includes("application/octet-stream")) {
78
78
  return {};
79
79
  }
80
+ const { format: _, ...rest } = schema;
80
81
  if (schema.type === "string") {
81
82
  if (schema.format === "binary") {
82
83
  return {
84
+ ...rest,
83
85
  type: "string",
84
86
  contentMediaType: "application/octet-stream"
85
87
  };
86
88
  }
87
89
  if (schema.format === "base64") {
88
90
  return {
91
+ ...rest,
89
92
  type: "string",
90
93
  contentEncoding: "base64"
91
94
  };
92
95
  }
93
96
  if (schema.format === "byte") {
94
97
  const parentPath = path.slice(0, -1);
95
- const contentMediaType = parentPath.find((_, index) => path[index - 1] === "content");
98
+ const contentMediaType = parentPath.find((_2, index) => path[index - 1] === "content");
96
99
  return {
100
+ ...rest,
97
101
  type: "string",
98
102
  contentEncoding: "base64",
99
103
  contentMediaType
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/upgrade-from-three-to-three-one.ts"],
4
- "sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\nimport type { UnknownObject } from '@scalar/types/utils'\n\nimport { traverse } from './traverse'\n\n// Create Sets for faster schema path lookups\nconst SCHEMA_SEGMENTS = new Set([\n 'properties',\n 'items',\n 'allOf',\n 'anyOf',\n 'oneOf',\n 'not',\n 'additionalProperties',\n 'schema',\n])\n\n/** Determine if the current path is within a schema - optimized version */\nexport function isSchemaPath(path: string[]): boolean {\n // Check for schema segments first (most common case)\n if (path.some((segment) => SCHEMA_SEGMENTS.has(segment))) {\n return true\n }\n\n // Check for schema suffix\n if (path.some((segment) => segment.endsWith('Schema'))) {\n return true\n }\n\n // Check for components/schemas path\n if (path.length >= 2 && path[0] === 'components' && path[1] === 'schemas') {\n return true\n }\n\n return false\n}\n\n/**\n * Upgrade from OpenAPI 3.0.x to 3.1.1\n *\n * https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0\n */\nexport function upgradeFromThreeToThreeOne(originalContent: UnknownObject) {\n let content = originalContent\n\n // Version check - early return if not 3.0.x\n if (content === null || typeof content.openapi !== 'string' || !content.openapi.startsWith('3.0')) {\n return content\n }\n\n content.openapi = '3.1.1'\n\n // Single traversal that handles all transformations\n content = traverse(content, applyChangesToDocument)\n\n return content as OpenAPIV3_1.Document\n}\n\nconst applyChangesToDocument = (schema: UnknownObject, path: string[]) => {\n // 1. Handle nullable types\n if (schema.type !== undefined && schema.nullable === true) {\n schema.type = [schema.type, 'null']\n delete schema.nullable\n }\n\n // 2. Handle exclusiveMinimum and exclusiveMaximum\n if (schema.exclusiveMinimum === true) {\n schema.exclusiveMinimum = schema.minimum\n delete schema.minimum\n } else if (schema.exclusiveMinimum === false) {\n delete schema.exclusiveMinimum\n }\n\n if (schema.exclusiveMaximum === true) {\n schema.exclusiveMaximum = schema.maximum\n delete schema.maximum\n } else if (schema.exclusiveMaximum === false) {\n delete schema.exclusiveMaximum\n }\n\n // 3. Handle examples\n if (schema.example !== undefined) {\n if (isSchemaPath(path)) {\n schema.examples = [schema.example]\n } else {\n schema.examples = {\n default: {\n value: schema.example,\n },\n }\n }\n delete schema.example\n }\n\n // 4. Handle multipart file uploads\n if (schema.type === 'object' && schema.properties !== undefined) {\n const parentPath = path.slice(0, -1)\n const isMultipart = parentPath.some((segment, index) => {\n return segment === 'content' && path[index + 1] === 'multipart/form-data'\n })\n\n if (isMultipart) {\n for (const value of Object.values(schema.properties)) {\n if (\n typeof value === 'object' &&\n value !== null &&\n 'type' in value &&\n 'format' in value &&\n value.type === 'string' &&\n value.format === 'binary'\n ) {\n ;(value as any).contentMediaType = 'application/octet-stream'\n delete (value as any).format\n }\n }\n }\n }\n\n // 5. Handle binary file uploads\n if (path.includes('content') && path.includes('application/octet-stream')) {\n return {}\n }\n\n if (schema.type === 'string') {\n if (schema.format === 'binary') {\n return {\n type: 'string',\n contentMediaType: 'application/octet-stream',\n }\n }\n\n if (schema.format === 'base64') {\n return {\n type: 'string',\n contentEncoding: 'base64',\n }\n }\n\n if (schema.format === 'byte') {\n const parentPath = path.slice(0, -1)\n const contentMediaType = parentPath.find((_, index) => path[index - 1] === 'content')\n return {\n type: 'string',\n contentEncoding: 'base64',\n contentMediaType,\n }\n }\n }\n\n // 6. Handle x-webhooks\n if (schema['x-webhooks'] !== undefined) {\n schema.webhooks = schema['x-webhooks']\n delete schema['x-webhooks']\n }\n\n return schema\n}\n"],
5
- "mappings": "AAGA,SAAS,gBAAgB;AAGzB,MAAM,kBAAkB,oBAAI,IAAI;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGM,SAAS,aAAa,MAAyB;AAEpD,MAAI,KAAK,KAAK,CAAC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e,QAAW;AAC/D,UAAM,aAAa,KAAK,MAAM,GAAG,EAAE;AACnC,UAAM,cAAc,WAAW,KAAK,CAAC,SAAS,UAAU;AACtD,aAAO,YAAY,aAAa,KAAK,QAAQ,CAAC,MAAM;AAAA,IACtD,CAAC;AAED,QAAI,aAAa;AACf,iBAAW,SAAS,OAAO,OAAO,OAAO,UAAU,GAAG;AACpD,YACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,YAAY,SACZ,MAAM,SAAS,YACf,MAAM,WAAW,UACjB;AACA;AAAC,UAAC,MAAc,mBAAmB;AACnC,iBAAQ,MAAc;AAAA,QACxB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAGA,MAAI,KAAK,SAAS,SAAS,KAAK,KAAK,SAAS,0BAA0B,GAAG;AACzE,WAAO,CAAC;AAAA,EACV;AAEA,MAAI,OAAO,SAAS,UAAU;AAC5B,QAAI,OAAO,WAAW,UAAU;AAC9B,aAAO;AAAA,QACL,MAAM;AAAA,QACN,kBAAkB;AAAA,MACpB;AAAA,IACF;AAEA,QAAI,OAAO,WAAW,UAAU;AAC9B,aAAO;AAAA,QACL,MAAM;AAAA,QACN,iBAAiB;AAAA,MACnB;AAAA,IACF;AAEA,QAAI,OAAO,WAAW,QAAQ;AAC5B,YAAM,aAAa,KAAK,MAAM,GAAG,EAAE;AACnC,YAAM,mBAAmB,WAAW,KAAK,CAAC,GAAG,UAAU,KAAK,QAAQ,CAAC,MAAM,SAAS;AACpF,aAAO;AAAA,QACL,MAAM;AAAA,QACN,iBAAiB;AAAA,QACjB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAGA,MAAI,OAAO,YAAY,MAAM,QAAW;AACtC,WAAO,WAAW,OAAO,YAAY;AACrC,WAAO,OAAO,YAAY;AAAA,EAC5B;AAEA,SAAO;AACT;",
6
- "names": []
4
+ "sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\nimport type { UnknownObject } from '@scalar/types/utils'\n\nimport { traverse } from './traverse'\n\n// Create Sets for faster schema path lookups\nconst SCHEMA_SEGMENTS = new Set([\n 'properties',\n 'items',\n 'allOf',\n 'anyOf',\n 'oneOf',\n 'not',\n 'additionalProperties',\n 'schema',\n])\n\n/** Determine if the current path is within a schema - optimized version */\nexport function isSchemaPath(path: string[]): boolean {\n // Check for schema segments first (most common case)\n if (path.some((segment) => SCHEMA_SEGMENTS.has(segment))) {\n return true\n }\n\n // Check for schema suffix\n if (path.some((segment) => segment.endsWith('Schema'))) {\n return true\n }\n\n // Check for components/schemas path\n if (path.length >= 2 && path[0] === 'components' && path[1] === 'schemas') {\n return true\n }\n\n return false\n}\n\n/**\n * Upgrade from OpenAPI 3.0.x to 3.1.1\n *\n * https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0\n */\nexport function upgradeFromThreeToThreeOne(originalContent: UnknownObject) {\n let content = originalContent\n\n // Version check - early return if not 3.0.x\n if (content === null || typeof content.openapi !== 'string' || !content.openapi.startsWith('3.0')) {\n return content\n }\n\n content.openapi = '3.1.1'\n\n // Single traversal that handles all transformations\n content = traverse(content, applyChangesToDocument)\n\n return content as OpenAPIV3_1.Document\n}\n\nconst applyChangesToDocument = (schema: UnknownObject, path: string[]) => {\n // 1. Handle nullable types\n if (schema.type !== undefined && schema.nullable === true) {\n schema.type = [schema.type, 'null']\n delete schema.nullable\n }\n\n // 2. Handle exclusiveMinimum and exclusiveMaximum\n if (schema.exclusiveMinimum === true) {\n schema.exclusiveMinimum = schema.minimum\n delete schema.minimum\n } else if (schema.exclusiveMinimum === false) {\n delete schema.exclusiveMinimum\n }\n\n if (schema.exclusiveMaximum === true) {\n schema.exclusiveMaximum = schema.maximum\n delete schema.maximum\n } else if (schema.exclusiveMaximum === false) {\n delete schema.exclusiveMaximum\n }\n\n // 3. Handle examples\n if (schema.example !== undefined) {\n if (isSchemaPath(path)) {\n schema.examples = [schema.example]\n } else {\n schema.examples = {\n default: {\n value: schema.example,\n },\n }\n }\n delete schema.example\n }\n\n // 4. Handle multipart file uploads\n if (schema.type === 'object' && schema.properties !== undefined) {\n const parentPath = path.slice(0, -1)\n const isMultipart = parentPath.some((segment, index) => {\n return segment === 'content' && path[index + 1] === 'multipart/form-data'\n })\n\n if (isMultipart) {\n for (const value of Object.values(schema.properties)) {\n if (\n typeof value === 'object' &&\n value !== null &&\n 'type' in value &&\n 'format' in value &&\n value.type === 'string' &&\n value.format === 'binary'\n ) {\n ;(value as any).contentMediaType = 'application/octet-stream'\n delete (value as any).format\n }\n }\n }\n }\n\n // 5. Handle binary file uploads\n if (path.includes('content') && path.includes('application/octet-stream')) {\n return {}\n }\n\n // 6. Handle older formats\n const { format: _, ...rest } = schema\n\n if (schema.type === 'string') {\n if (schema.format === 'binary') {\n return {\n ...rest,\n type: 'string',\n contentMediaType: 'application/octet-stream',\n }\n }\n\n if (schema.format === 'base64') {\n return {\n ...rest,\n type: 'string',\n contentEncoding: 'base64',\n }\n }\n\n if (schema.format === 'byte') {\n const parentPath = path.slice(0, -1)\n const contentMediaType = parentPath.find((_, index) => path[index - 1] === 'content')\n return {\n ...rest,\n type: 'string',\n contentEncoding: 'base64',\n contentMediaType,\n }\n }\n }\n\n // 7. Handle x-webhooks\n if (schema['x-webhooks'] !== undefined) {\n schema.webhooks = schema['x-webhooks']\n delete schema['x-webhooks']\n }\n\n return schema\n}\n"],
5
+ "mappings": "AAGA,SAAS,gBAAgB;AAGzB,MAAM,kBAAkB,oBAAI,IAAI;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGM,SAAS,aAAa,MAAyB;AAEpD,MAAI,KAAK,KAAK,CAAC,YAAY,gBAAgB,IAAI,OAAO,CAAC,GAAG;AACxD,WAAO;AAAA,EACT;AAGA,MAAI,KAAK,KAAK,CAAC,YAAY,QAAQ,SAAS,QAAQ,CAAC,GAAG;AACtD,WAAO;AAAA,EACT;AAGA,MAAI,KAAK,UAA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I,aAAa;AACf,iBAAW,SAAS,OAAO,OAAO,OAAO,UAAU,GAAG;AACpD,YACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,YAAY,SACZ,MAAM,SAAS,YACf,MAAM,WAAW,UACjB;AACA;AAAC,UAAC,MAAc,mBAAmB;AACnC,iBAAQ,MAAc;AAAA,QACxB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAGA,MAAI,KAAK,SAAS,SAAS,KAAK,KAAK,SAAS,0BAA0B,GAAG;AACzE,WAAO,CAAC;AAAA,EACV;AAGA,QAAM,EAAE,QAAQ,GAAG,GAAG,KAAK,IAAI;AAE/B,MAAI,OAAO,SAAS,UAAU;AAC5B,QAAI,OAAO,WAAW,UAAU;AAC9B,aAAO;AAAA,QACL,GAAG;AAAA,QACH,MAAM;AAAA,QACN,kBAAkB;AAAA,MACpB;AAAA,IACF;AAEA,QAAI,OAAO,WAAW,UAAU;AAC9B,aAAO;AAAA,QACL,GAAG;AAAA,QACH,MAAM;AAAA,QACN,iBAAiB;AAAA,MACnB;AAAA,IACF;AAEA,QAAI,OAAO,WAAW,QAAQ;AAC5B,YAAM,aAAa,KAAK,MAAM,GAAG,EAAE;AACnC,YAAM,mBAAmB,WAAW,KAAK,CAACA,IAAG,UAAU,KAAK,QAAQ,CAAC,MAAM,SAAS;AACpF,aAAO;AAAA,QACL,GAAG;AAAA,QACH,MAAM;AAAA,QACN,iBAAiB;AAAA,QACjB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAGA,MAAI,OAAO,YAAY,MAAM,QAAW;AACtC,WAAO,WAAW,OAAO,YAAY;AACrC,WAAO,OAAO,YAAY;AAAA,EAC5B;AAEA,SAAO;AACT;",
6
+ "names": ["_"]
7
7
  }
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "parser",
18
18
  "typescript"
19
19
  ],
20
- "version": "0.18.3",
20
+ "version": "0.20.0",
21
21
  "engines": {
22
22
  "node": ">=20"
23
23
  },
@@ -30,16 +30,6 @@
30
30
  "types": "./dist/index.d.ts",
31
31
  "default": "./dist/index.js"
32
32
  },
33
- "./plugins": {
34
- "import": "./dist/plugins.js",
35
- "types": "./dist/plugins.d.ts",
36
- "default": "./dist/plugins.js"
37
- },
38
- "./plugins-browser": {
39
- "import": "./dist/plugins-browser.js",
40
- "types": "./dist/plugins-browser.d.ts",
41
- "default": "./dist/plugins-browser.js"
42
- },
43
33
  "./plugins/fetch-urls": {
44
34
  "import": "./dist/plugins/fetch-urls/index.js",
45
35
  "types": "./dist/plugins/fetch-urls/index.d.ts",
@@ -64,6 +54,7 @@
64
54
  "jsonpointer": "^5.0.1",
65
55
  "leven": "^4.0.0",
66
56
  "yaml": "2.8.0",
57
+ "@scalar/json-magic": "0.3.0",
67
58
  "@scalar/openapi-types": "0.3.7"
68
59
  },
69
60
  "devDependencies": {
@@ -74,8 +65,8 @@
74
65
  "just-diff": "^6.0.2",
75
66
  "tinybench": "^2.8.0",
76
67
  "vite": "6.1.6",
77
- "@scalar/build-tooling": "0.2.4",
78
- "@scalar/types": "0.2.11"
68
+ "@scalar/types": "0.2.12",
69
+ "@scalar/build-tooling": "0.2.6"
79
70
  },
80
71
  "scripts": {
81
72
  "build": "scalar-build-esbuild",
@@ -1,4 +0,0 @@
1
- export { fetchUrls } from './utils/bundle/plugins/fetch-urls/index.js';
2
- export { parseJson } from './utils/bundle/plugins/parse-json/index.js';
3
- export { parseYaml } from './utils/bundle/plugins/parse-yaml/index.js';
4
- //# sourceMappingURL=plugins-browser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugins-browser.d.ts","sourceRoot":"","sources":["../src/plugins-browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAA"}
@@ -1,9 +0,0 @@
1
- import { fetchUrls } from "./utils/bundle/plugins/fetch-urls/index.js";
2
- import { parseJson } from "./utils/bundle/plugins/parse-json/index.js";
3
- import { parseYaml } from "./utils/bundle/plugins/parse-yaml/index.js";
4
- export {
5
- fetchUrls,
6
- parseJson,
7
- parseYaml
8
- };
9
- //# sourceMappingURL=plugins-browser.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/plugins-browser.ts"],
4
- "sourcesContent": ["export { fetchUrls } from './utils/bundle/plugins/fetch-urls'\nexport { parseJson } from './utils/bundle/plugins/parse-json'\nexport { parseYaml } from './utils/bundle/plugins/parse-yaml'\n"],
5
- "mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;",
6
- "names": []
7
- }
package/dist/plugins.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export { fetchUrls } from './utils/bundle/plugins/fetch-urls/index.js';
2
- export { readFiles } from './utils/bundle/plugins/read-files/index.js';
3
- export { parseJson } from './utils/bundle/plugins/parse-json/index.js';
4
- export { parseYaml } from './utils/bundle/plugins/parse-yaml/index.js';
5
- //# sourceMappingURL=plugins.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAA"}
package/dist/plugins.js DELETED
@@ -1,11 +0,0 @@
1
- import { fetchUrls } from "./utils/bundle/plugins/fetch-urls/index.js";
2
- import { readFiles } from "./utils/bundle/plugins/read-files/index.js";
3
- import { parseJson } from "./utils/bundle/plugins/parse-json/index.js";
4
- import { parseYaml } from "./utils/bundle/plugins/parse-yaml/index.js";
5
- export {
6
- fetchUrls,
7
- parseJson,
8
- parseYaml,
9
- readFiles
10
- };
11
- //# sourceMappingURL=plugins.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/plugins.ts"],
4
- "sourcesContent": ["export { fetchUrls } from './utils/bundle/plugins/fetch-urls'\nexport { readFiles } from './utils/bundle/plugins/read-files'\nexport { parseJson } from './utils/bundle/plugins/parse-json'\nexport { parseYaml } from './utils/bundle/plugins/parse-yaml'\n"],
5
- "mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;",
6
- "names": []
7
- }
@@ -1,286 +0,0 @@
1
- import type { UnknownObject } from '../../types/index.js';
2
- /**
3
- * Checks if a string is a remote URL (starts with http:// or https://)
4
- * @param value - The URL string to check
5
- * @returns true if the string is a remote URL, false otherwise
6
- * @example
7
- * ```ts
8
- * isRemoteUrl('https://example.com/schema.json') // true
9
- * isRemoteUrl('http://api.example.com/schemas/user.json') // true
10
- * isRemoteUrl('#/components/schemas/User') // false
11
- * isRemoteUrl('./local-schema.json') // false
12
- * ```
13
- */
14
- export declare function isRemoteUrl(value: string): boolean;
15
- /**
16
- * Checks if a string represents a file path by ensuring it's not a remote URL,
17
- * YAML content, or JSON content.
18
- *
19
- * @param value - The string to check
20
- * @returns true if the string appears to be a file path, false otherwise
21
- * @example
22
- * ```ts
23
- * isFilePath('./schemas/user.json') // true
24
- * isFilePath('https://example.com/schema.json') // false
25
- * isFilePath('{"type": "object"}') // false
26
- * isFilePath('type: object') // false
27
- * ```
28
- */
29
- export declare function isFilePath(value: string): boolean;
30
- /**
31
- * Checks if a string is a local reference (starts with #)
32
- * @param value - The reference string to check
33
- * @returns true if the string is a local reference, false otherwise
34
- * @example
35
- * ```ts
36
- * isLocalRef('#/components/schemas/User') // true
37
- * isLocalRef('https://example.com/schema.json') // false
38
- * isLocalRef('./local-schema.json') // false
39
- * ```
40
- */
41
- export declare function isLocalRef(value: string): boolean;
42
- export type ResolveResult = {
43
- ok: true;
44
- data: unknown;
45
- } | {
46
- ok: false;
47
- };
48
- /**
49
- * Retrieves a nested value from an object using an array of property segments.
50
- * @param target - The target object to traverse
51
- * @param segments - Array of property names representing the path to the desired value
52
- * @returns The value at the specified path, or undefined if the path doesn't exist
53
- * @example
54
- * const obj = { foo: { bar: { baz: 42 } } };
55
- * getNestedValue(obj, ['foo', 'bar', 'baz']); // returns 42
56
- */
57
- export declare function getNestedValue(target: Record<string, any>, segments: string[]): any;
58
- /**
59
- * Sets a value at a specified path in an object, creating intermediate objects/arrays as needed.
60
- * This function traverses the object structure and creates any missing intermediate objects
61
- * or arrays based on the path segments. If the next segment is a numeric string, it creates
62
- * an array instead of an object.
63
- *
64
- * ⚠️ Warning: Be careful with object keys that look like numbers (e.g. "123") as this function
65
- * will interpret them as array indices and create arrays instead of objects. If you need to
66
- * use numeric-looking keys, consider prefixing them with a non-numeric character.
67
- *
68
- * @param obj - The target object to set the value in
69
- * @param path - The JSON pointer path where the value should be set
70
- * @param value - The value to set at the specified path
71
- * @throws {Error} If attempting to set a value at the root path ('')
72
- *
73
- * @example
74
- * const obj = {}
75
- * setValueAtPath(obj, '/foo/bar/0', 'value')
76
- * // Result:
77
- * // {
78
- * // foo: {
79
- * // bar: ['value']
80
- * // }
81
- * // }
82
- *
83
- * @example
84
- * const obj = { existing: { path: 'old' } }
85
- * setValueAtPath(obj, '/existing/path', 'new')
86
- * // Result:
87
- * // {
88
- * // existing: {
89
- * // path: 'new'
90
- * // }
91
- * // }
92
- *
93
- * @example
94
- * // ⚠️ Warning: This will create an array instead of an object with key "123"
95
- * setValueAtPath(obj, '/foo/123/bar', 'value')
96
- * // Result:
97
- * // {
98
- * // foo: [
99
- * // undefined,
100
- * // undefined,
101
- * // undefined,
102
- * // { bar: 'value' }
103
- * // ]
104
- * // }
105
- */
106
- export declare function setValueAtPath(obj: any, path: string, value: any): void;
107
- /**
108
- * Prefixes an internal JSON reference with a given path prefix.
109
- * Takes a local reference (starting with #) and prepends the provided prefix segments.
110
- *
111
- * @param input - The internal reference string to prefix (must start with #)
112
- * @param prefix - Array of path segments to prepend to the reference
113
- * @returns The prefixed reference string
114
- * @throws Error if input is not a local reference
115
- * @example
116
- * prefixInternalRef('#/components/schemas/User', ['definitions'])
117
- * // Returns: '#/definitions/components/schemas/User'
118
- */
119
- export declare function prefixInternalRef(input: string, prefix: string[]): string;
120
- /**
121
- * Updates internal references in an object by adding a prefix to their paths.
122
- * Recursively traverses the input object and modifies any local $ref references
123
- * by prepending the given prefix to their paths. This is used when embedding external
124
- * documents to maintain correct reference paths relative to the main document.
125
- *
126
- * @param input - The object to update references in
127
- * @param prefix - Array of path segments to prepend to internal reference paths
128
- * @returns void
129
- * @example
130
- * ```ts
131
- * const input = {
132
- * foo: {
133
- * $ref: '#/components/schemas/User'
134
- * }
135
- * }
136
- * prefixInternalRefRecursive(input, ['definitions'])
137
- * // Result:
138
- * // {
139
- * // foo: {
140
- * // $ref: '#/definitions/components/schemas/User'
141
- * // }
142
- * // }
143
- * ```
144
- */
145
- export declare function prefixInternalRefRecursive(input: unknown, prefix: string[]): void;
146
- /**
147
- * Represents a plugin that handles resolving references from external sources.
148
- * Plugins are responsible for fetching and processing data from different sources
149
- * like URLs or the filesystem. Each plugin must implement validation to determine
150
- * if it can handle a specific reference, and an execution function to perform
151
- * the actual resolution.
152
- *
153
- * @property validate - Determines if this plugin can handle the given reference
154
- * @property exec - Fetches and processes the reference, returning the resolved data
155
- */
156
- export type Plugin = {
157
- validate: (value: string) => boolean;
158
- exec: (value: string) => Promise<ResolveResult>;
159
- };
160
- /**
161
- * Configuration options for the bundler.
162
- * Controls how external references are resolved and processed during bundling.
163
- */
164
- type Config = {
165
- /**
166
- * Array of plugins that handle resolving references from different sources.
167
- * Each plugin is responsible for fetching and processing data from specific sources
168
- * like URLs or the filesystem.
169
- */
170
- plugins: Plugin[];
171
- /**
172
- * Optional root object that serves as the base document when bundling a subpart.
173
- * This allows resolving references relative to the root document's location,
174
- * ensuring proper path resolution for nested references.
175
- */
176
- root?: UnknownObject;
177
- /**
178
- * Optional cache to store promises of resolved references.
179
- * Helps avoid duplicate fetches/reads of the same resource by storing
180
- * the resolution promises for reuse.
181
- */
182
- cache?: Map<string, Promise<ResolveResult>>;
183
- /**
184
- * Cache of visited nodes during partial bundling.
185
- * Used to prevent re-bundling the same tree multiple times when doing partial bundling,
186
- * improving performance by avoiding redundant processing of already bundled sections.
187
- */
188
- visitedNodes?: Set<unknown>;
189
- /**
190
- * Enable tree shaking to optimize the bundle size.
191
- * When enabled, only the parts of external documents that are actually referenced
192
- * will be included in the final bundle.
193
- */
194
- treeShake: boolean;
195
- /**
196
- * Optional flag to generate a URL map.
197
- * When enabled, tracks the original source URLs of bundled references
198
- * in an x-ext-urls section for reference mapping.
199
- */
200
- urlMap?: boolean;
201
- /**
202
- * Optional function to compress input URLs or file paths before bundling.
203
- * Returns either a Promise resolving to the compressed string or the compressed string directly.
204
- */
205
- compress?: (value: string) => Promise<string> | string;
206
- /**
207
- * Optional hooks to monitor the bundler's lifecycle.
208
- * Allows tracking the progress and status of reference resolution.
209
- */
210
- hooks?: Partial<{
211
- /** Called when starting to resolve a reference */
212
- onResolveStart: (node: Record<string, unknown> & Record<'$ref', unknown>) => void;
213
- /** Called when a reference resolution fails */
214
- onResolveError: (node: Record<string, unknown> & Record<'$ref', unknown>) => void;
215
- /** Called when a reference is successfully resolved */
216
- onResolveSuccess: (node: Record<string, unknown> & Record<'$ref', unknown>) => void;
217
- }>;
218
- };
219
- /**
220
- * Bundles an OpenAPI specification by resolving all external references.
221
- * This function traverses the input object recursively and embeds external $ref
222
- * references into an x-ext section. External references can be URLs or local files.
223
- * The original $refs are updated to point to their embedded content in the x-ext section.
224
- * If the input is an object, it will be modified in place by adding an x-ext
225
- * property to store resolved external references.
226
- *
227
- * @param input - The OpenAPI specification to bundle. Can be either an object or string.
228
- * If a string is provided, it will be resolved using the provided plugins.
229
- * If no plugin can process the input, the onReferenceError hook will be invoked
230
- * and an error will be emitted to the console.
231
- * @param config - Configuration object containing plugins and options for bundling OpenAPI specifications
232
- * @returns A promise that resolves to the bundled specification with all references embedded
233
- * @example
234
- * // Example with object input
235
- * const spec = {
236
- * paths: {
237
- * '/users': {
238
- * $ref: 'https://example.com/schemas/users.yaml'
239
- * }
240
- * }
241
- * }
242
- *
243
- * const bundled = await bundle(spec, {
244
- * plugins: [fetchUrls()],
245
- * treeShake: true,
246
- * urlMap: true,
247
- * hooks: {
248
- * onResolveStart: (ref) => console.log('Resolving:', ref.$ref),
249
- * onResolveSuccess: (ref) => console.log('Resolved:', ref.$ref),
250
- * onResolveError: (ref) => console.log('Failed to resolve:', ref.$ref)
251
- * }
252
- * })
253
- * // Result:
254
- * // {
255
- * // paths: {
256
- * // '/users': {
257
- * // $ref: '#/x-ext/abc123'
258
- * // }
259
- * // },
260
- * // 'x-ext': {
261
- * // 'abc123': {
262
- * // // Resolved content from users.yaml
263
- * // }
264
- * // },
265
- * // 'x-ext-urls': {
266
- * // 'https://example.com/schemas/users.yaml': 'abc123'
267
- * // }
268
- * // }
269
- *
270
- * // Example with URL input
271
- * const bundledFromUrl = await bundle('https://example.com/openapi.yaml', {
272
- * plugins: [fetchUrls()],
273
- * treeShake: true,
274
- * urlMap: true,
275
- * hooks: {
276
- * onResolveStart: (ref) => console.log('Resolving:', ref.$ref),
277
- * onResolveSuccess: (ref) => console.log('Resolved:', ref.$ref),
278
- * onResolveError: (ref) => console.log('Failed to resolve:', ref.$ref)
279
- * }
280
- * })
281
- * // The function will first fetch the OpenAPI spec from the URL,
282
- * // then bundle all its external references into the x-ext section
283
- */
284
- export declare function bundle(input: UnknownObject | string, config: Config): Promise<object>;
285
- export {};
286
- //# sourceMappingURL=bundle.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../../src/utils/bundle/bundle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAA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