@scalar/openapi-parser 0.18.3 → 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 (43) hide show
  1. package/CHANGELOG.md +7 -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/package.json +3 -23
  8. package/dist/plugins-browser.d.ts +0 -4
  9. package/dist/plugins-browser.d.ts.map +0 -1
  10. package/dist/plugins-browser.js +0 -9
  11. package/dist/plugins-browser.js.map +0 -7
  12. package/dist/plugins.d.ts +0 -5
  13. package/dist/plugins.d.ts.map +0 -1
  14. package/dist/plugins.js +0 -11
  15. package/dist/plugins.js.map +0 -7
  16. package/dist/utils/bundle/bundle.d.ts +0 -286
  17. package/dist/utils/bundle/bundle.d.ts.map +0 -1
  18. package/dist/utils/bundle/bundle.js +0 -251
  19. package/dist/utils/bundle/bundle.js.map +0 -7
  20. package/dist/utils/bundle/create-limiter.d.ts +0 -21
  21. package/dist/utils/bundle/create-limiter.d.ts.map +0 -1
  22. package/dist/utils/bundle/create-limiter.js +0 -31
  23. package/dist/utils/bundle/create-limiter.js.map +0 -7
  24. package/dist/utils/bundle/plugins/fetch-urls/index.d.ts +0 -39
  25. package/dist/utils/bundle/plugins/fetch-urls/index.d.ts.map +0 -1
  26. package/dist/utils/bundle/plugins/fetch-urls/index.js +0 -48
  27. package/dist/utils/bundle/plugins/fetch-urls/index.js.map +0 -7
  28. package/dist/utils/bundle/plugins/parse-json/index.d.ts +0 -13
  29. package/dist/utils/bundle/plugins/parse-json/index.d.ts.map +0 -1
  30. package/dist/utils/bundle/plugins/parse-json/index.js +0 -22
  31. package/dist/utils/bundle/plugins/parse-json/index.js.map +0 -7
  32. package/dist/utils/bundle/plugins/parse-yaml/index.d.ts +0 -13
  33. package/dist/utils/bundle/plugins/parse-yaml/index.d.ts.map +0 -1
  34. package/dist/utils/bundle/plugins/parse-yaml/index.js +0 -23
  35. package/dist/utils/bundle/plugins/parse-yaml/index.js.map +0 -7
  36. package/dist/utils/bundle/plugins/read-files/index.d.ts +0 -29
  37. package/dist/utils/bundle/plugins/read-files/index.d.ts.map +0 -1
  38. package/dist/utils/bundle/plugins/read-files/index.js +0 -30
  39. package/dist/utils/bundle/plugins/read-files/index.js.map +0 -7
  40. package/dist/utils/bundle/value-generator.d.ts +0 -79
  41. package/dist/utils/bundle/value-generator.d.ts.map +0 -1
  42. package/dist/utils/bundle/value-generator.js +0 -55
  43. package/dist/utils/bundle/value-generator.js.map +0 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @scalar/openapi-parser
2
2
 
3
+ ## 0.19.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 952bde2: feat(json-magic): move json tooling to the new package
8
+ - 2888e18: feat(openapi-parser): partial bundle to a depth
9
+
3
10
  ## 0.18.3
4
11
 
5
12
  ### Patch Changes
package/README.md CHANGED
@@ -55,208 +55,6 @@ const specification = `{
55
55
  const { schema, errors } = await dereference(specification)
56
56
  ```
57
57
 
58
- ### Bundle external references
59
-
60
- The OpenAPI specification allows to point to external files (URLs or files). But sometimes, you just want to combine all files into one.
61
-
62
- #### Plugins
63
-
64
- If you are on a browser environment import plugins from `@scalar/openapi-parser/plugins-browser` while if you are on a node environment you can import from `@scalar/openapi-parser/plugins`
65
-
66
- ##### fetchUrls
67
- This plugins handles all external urls. It works for both node.js and browser environment
68
-
69
- ```ts
70
- import { bundle } from '@scalar/openapi-parser'
71
- import { fetchUrls } from '@scalar/openapi-parser/plugins-browser'
72
-
73
- const document = {
74
- openapi: '3.1.0',
75
- info: { title: 'Bundled API', version: '1.0.0' },
76
- paths: {},
77
- components: {
78
- schemas: {
79
- User: { $ref: 'https://example.com/user-schema.json#' }
80
- }
81
- }
82
- }
83
-
84
- // This will bundle all external documents and turn all references from external into internal
85
- await bundle(document, {
86
- plugins: [fetchUrls()],
87
- treeShake: true // <------ This flag will try to remove any unused part of the external document
88
- })
89
-
90
- console.log(document)
91
- ```
92
-
93
- ###### Limiting the number of concurrent requests
94
-
95
- ```ts
96
- await bundle(document, {
97
- plugins: [
98
- fetchUrls({
99
- limit: 10, // it should run at most 10 requests at the same time
100
- }),
101
- ],
102
- treeShake: false
103
- })
104
-
105
- ```
106
-
107
- ###### Custom headers
108
- To pass custom headers to requests for specific domains you can configure the fetch plugin like the example
109
-
110
- ```ts
111
- await bundle(
112
- document,
113
- {
114
- plugins: [
115
- fetchUrls({
116
- // Pass custom headers
117
- // The header will only be attached to the list of domains
118
- headers: [
119
- {
120
- domains: ['example.com'],
121
- headers: {
122
- 'Authorization': 'Bearer <TOKEN>'
123
- }
124
- }
125
- ]
126
- }),
127
- readFiles(),
128
- ],
129
- treeShake: false
130
- },
131
- )
132
- ```
133
-
134
- ###### Custom fetch function
135
- For advanced use cases like proxying requests or implementing custom network logic, you can provide your own fetch implementation. This allows you to handle things like CORS restrictions, custom authentication flows, or request/response transformations.
136
-
137
- ```ts
138
- await bundle(
139
- document,
140
- {
141
- plugins: [
142
- fetchUrls({
143
- // Custom fetcher function
144
- fetch: async (input, init) => {
145
- console.log('Custom fetch logic')
146
- return fetch(input, init)
147
- },
148
- })
149
- readFiles(),
150
- ],
151
- treeShake: false
152
- },
153
- )
154
- ```
155
-
156
- ###### Bundle from remote url
157
-
158
- ```ts
159
- const result = await bundle(
160
- 'https://example.com/openapi.json',
161
- {
162
- plugins: [
163
- fetchUrls(),
164
- ],
165
- treeShake: false
166
- },
167
- )
168
-
169
- // Bundled document
170
- console.log(result)
171
- ```
172
-
173
- ##### readFiles
174
- This plugins handles local files. Only works on node.js environment
175
-
176
- ```ts
177
- import { bundle } from '@scalar/openapi-parser'
178
- import { readFiles } from '@scalar/openapi-parser/plugins-browser'
179
-
180
- const document = {
181
- openapi: '3.1.0',
182
- info: { title: 'Bundled API', version: '1.0.0' },
183
- paths: {},
184
- components: {
185
- schemas: {
186
- User: { $ref: './user-schema.json#' }
187
- }
188
- }
189
- }
190
-
191
- // This will bundle all external documents and turn all references from external into internal
192
- await bundle(document, {
193
- plugins: [readFiles()],
194
- treeShake: false
195
- })
196
-
197
- console.log(document)
198
- ```
199
-
200
- ###### Bundle from local file
201
- You can pass the file path directly but make sure to have the correct plugins to handle reading from the local files
202
-
203
- ```ts
204
- const result = await bundle(
205
- './input.json',
206
- {
207
- plugins: [
208
- readFiles(),
209
- ],
210
- treeShake: false
211
- },
212
- )
213
-
214
- // Bundled document
215
- console.log(result)
216
- ```
217
-
218
- ##### parseJson
219
-
220
- You can pass raw json string as input
221
- ```ts
222
- import { bundle } from '@scalar/openapi-parser'
223
- import { parseJson } from '@scalar/openapi-parser/plugins-browser'
224
-
225
- const result = await bundle(
226
- '{ "openapi": "3.1.1" }',
227
- {
228
- plugins: [
229
- parseJson(),
230
- ],
231
- treeShake: false
232
- },
233
- )
234
-
235
- // Bundled document
236
- console.log(result)
237
- ```
238
-
239
- ##### parseYaml
240
-
241
- You can pass raw yaml string as input
242
- ```ts
243
- import { bundle } from '@scalar/openapi-parser'
244
- import { parseYaml } from '@scalar/openapi-parser/plugins-browser'
245
-
246
- const result = await bundle(
247
- 'openapi: "3.1.1"\n',
248
- {
249
- plugins: [
250
- parseYaml(),
251
- ],
252
- treeShake: false
253
- },
254
- )
255
-
256
- // Bundled document
257
- console.log(result)
258
- ```
259
-
260
58
  ### Track references
261
59
 
262
60
  The `dereference` function accepts an `onDereference` callback option that gets called whenever a reference is resolved. This can be useful for tracking which schemas are being dereferenced:
package/dist/index.d.ts CHANGED
@@ -14,7 +14,6 @@ export { upgrade } from './utils/upgrade.js';
14
14
  export { upgradeFromThreeToThreeOne } from './utils/upgrade-from-three-to-three-one.js';
15
15
  export { upgradeFromTwoToThree } from './utils/upgrade-from-two-to-three.js';
16
16
  export { validate } from './utils/validate.js';
17
- export { bundle } from './utils/bundle/bundle.js';
18
17
  export type { LoadResult, Filesystem, AnyObject, ErrorObject } from './types/index.js';
19
18
  export { openapi } from './utils/openapi/openapi.js';
20
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAA;AACpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAA;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAC9C,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAA;AACpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAA;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA"}
package/dist/index.js CHANGED
@@ -14,10 +14,8 @@ import { upgrade } from "./utils/upgrade.js";
14
14
  import { upgradeFromThreeToThreeOne } from "./utils/upgrade-from-three-to-three-one.js";
15
15
  import { upgradeFromTwoToThree } from "./utils/upgrade-from-two-to-three.js";
16
16
  import { validate } from "./utils/validate.js";
17
- import { bundle } from "./utils/bundle/bundle.js";
18
17
  import { openapi } from "./utils/openapi/openapi.js";
19
18
  export {
20
- bundle,
21
19
  dereference,
22
20
  escapeJsonPointer,
23
21
  filter,
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["export { dereference } from './utils/dereference'\nexport { escapeJsonPointer } from './utils/escape-json-pointer'\nexport { filter } from './utils/filter'\nexport { isJson } from './utils/is-json'\nexport { isYaml } from './utils/is-yaml'\nexport { load } from './utils/load'\nexport { normalize } from './utils/normalize'\nexport { sanitize } from './utils/transform/sanitize'\nexport { toJson } from './utils/to-json'\nexport { toYaml } from './utils/to-yaml'\nexport { traverse } from './utils/traverse'\nexport { unescapeJsonPointer } from './utils/unescape-json-pointer'\nexport { upgrade } from './utils/upgrade'\nexport { upgradeFromThreeToThreeOne } from './utils/upgrade-from-three-to-three-one'\nexport { upgradeFromTwoToThree } from './utils/upgrade-from-two-to-three'\nexport { validate } from './utils/validate'\nexport { bundle } from './utils/bundle/bundle'\nexport type { LoadResult, Filesystem, AnyObject, ErrorObject } from './types'\nexport { openapi } from './utils/openapi/openapi'\n"],
5
- "mappings": "AAAA,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,cAAc;AACvB,SAAS,cAAc;AACvB,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,cAAc;AACvB,SAAS,gBAAgB;AACzB,SAAS,2BAA2B;AACpC,SAAS,eAAe;AACxB,SAAS,kCAAkC;AAC3C,SAAS,6BAA6B;AACtC,SAAS,gBAAgB;AACzB,SAAS,cAAc;AAEvB,SAAS,eAAe;",
4
+ "sourcesContent": ["export { dereference } from './utils/dereference'\nexport { escapeJsonPointer } from './utils/escape-json-pointer'\nexport { filter } from './utils/filter'\nexport { isJson } from './utils/is-json'\nexport { isYaml } from './utils/is-yaml'\nexport { load } from './utils/load'\nexport { normalize } from './utils/normalize'\nexport { sanitize } from './utils/transform/sanitize'\nexport { toJson } from './utils/to-json'\nexport { toYaml } from './utils/to-yaml'\nexport { traverse } from './utils/traverse'\nexport { unescapeJsonPointer } from './utils/unescape-json-pointer'\nexport { upgrade } from './utils/upgrade'\nexport { upgradeFromThreeToThreeOne } from './utils/upgrade-from-three-to-three-one'\nexport { upgradeFromTwoToThree } from './utils/upgrade-from-two-to-three'\nexport { validate } from './utils/validate'\nexport type { LoadResult, Filesystem, AnyObject, ErrorObject } from './types'\nexport { openapi } from './utils/openapi/openapi'\n"],
5
+ "mappings": "AAAA,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,cAAc;AACvB,SAAS,cAAc;AACvB,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,cAAc;AACvB,SAAS,gBAAgB;AACzB,SAAS,2BAA2B;AACpC,SAAS,eAAe;AACxB,SAAS,kCAAkC;AAC3C,SAAS,6BAA6B;AACtC,SAAS,gBAAgB;AAEzB,SAAS,eAAe;",
6
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.19.0",
21
21
  "engines": {
22
22
  "node": ">=20"
23
23
  },
@@ -29,26 +29,6 @@
29
29
  "import": "./dist/index.js",
30
30
  "types": "./dist/index.d.ts",
31
31
  "default": "./dist/index.js"
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
- "./plugins/fetch-urls": {
44
- "import": "./dist/plugins/fetch-urls/index.js",
45
- "types": "./dist/plugins/fetch-urls/index.d.ts",
46
- "default": "./dist/plugins/fetch-urls/index.js"
47
- },
48
- "./plugins/read-files": {
49
- "import": "./dist/plugins/read-files/index.js",
50
- "types": "./dist/plugins/read-files/index.d.ts",
51
- "default": "./dist/plugins/read-files/index.js"
52
32
  }
53
33
  },
54
34
  "files": [
@@ -74,8 +54,8 @@
74
54
  "just-diff": "^6.0.2",
75
55
  "tinybench": "^2.8.0",
76
56
  "vite": "6.1.6",
77
- "@scalar/build-tooling": "0.2.4",
78
- "@scalar/types": "0.2.11"
57
+ "@scalar/types": "0.2.11",
58
+ "@scalar/build-tooling": "0.2.4"
79
59
  },
80
60
  "scripts": {
81
61
  "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":"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"}