@scalar/openapi-parser 0.14.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +26 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +2 -2
- package/dist/plugins-browser.d.ts +2 -0
- package/dist/plugins-browser.d.ts.map +1 -0
- package/dist/plugins-browser.js +5 -0
- package/dist/plugins-browser.js.map +7 -0
- package/dist/plugins.d.ts +3 -0
- package/dist/plugins.d.ts.map +1 -0
- package/dist/plugins.js +7 -0
- package/dist/plugins.js.map +7 -0
- package/dist/utils/bundle/bundle.d.ts +94 -8
- package/dist/utils/bundle/bundle.d.ts.map +1 -1
- package/dist/utils/bundle/bundle.js +24 -6
- package/dist/utils/bundle/bundle.js.map +2 -2
- package/dist/utils/bundle/plugins/{fetch-urls.d.ts → fetch-urls/index.d.ts} +3 -2
- package/dist/utils/bundle/plugins/fetch-urls/index.d.ts.map +1 -0
- package/dist/utils/bundle/plugins/{fetch-urls.js → fetch-urls/index.js} +6 -5
- package/dist/utils/bundle/plugins/fetch-urls/index.js.map +7 -0
- package/dist/utils/bundle/plugins/{read-files.d.ts → read-files/index.d.ts} +2 -2
- package/dist/utils/bundle/plugins/read-files/index.d.ts.map +1 -0
- package/dist/utils/bundle/plugins/{read-files.js → read-files/index.js} +4 -4
- package/dist/utils/bundle/plugins/read-files/index.js.map +7 -0
- package/dist/utils/openapi/actions/details.d.ts +7 -0
- package/dist/utils/openapi/actions/details.d.ts.map +1 -0
- package/dist/utils/openapi/actions/details.js +11 -0
- package/dist/utils/openapi/actions/details.js.map +7 -0
- package/dist/utils/openapi/actions/files.d.ts +6 -0
- package/dist/utils/openapi/actions/files.d.ts.map +1 -0
- package/dist/utils/openapi/actions/files.js +9 -0
- package/dist/utils/openapi/actions/files.js.map +7 -0
- package/dist/utils/openapi/actions/get.d.ts +6 -0
- package/dist/utils/openapi/actions/get.d.ts.map +1 -0
- package/dist/utils/openapi/actions/get.js +11 -0
- package/dist/utils/openapi/actions/get.js.map +7 -0
- package/dist/utils/openapi/actions/toJson.d.ts +6 -0
- package/dist/utils/openapi/actions/toJson.d.ts.map +1 -0
- package/dist/utils/openapi/actions/toJson.js +11 -0
- package/dist/utils/openapi/actions/toJson.js.map +7 -0
- package/dist/utils/openapi/actions/toYaml.d.ts +6 -0
- package/dist/utils/openapi/actions/toYaml.d.ts.map +1 -0
- package/dist/utils/openapi/actions/toYaml.js +11 -0
- package/dist/utils/openapi/actions/toYaml.js.map +7 -0
- package/dist/utils/openapi/commands/dereferenceCommand.d.ts +27 -0
- package/dist/utils/openapi/commands/dereferenceCommand.d.ts.map +1 -0
- package/dist/utils/openapi/commands/dereferenceCommand.js +27 -0
- package/dist/utils/openapi/commands/dereferenceCommand.js.map +7 -0
- package/dist/utils/openapi/commands/filterCommand.d.ts +41 -0
- package/dist/utils/openapi/commands/filterCommand.d.ts.map +1 -0
- package/dist/utils/openapi/commands/filterCommand.js +26 -0
- package/dist/utils/openapi/commands/filterCommand.js.map +7 -0
- package/dist/utils/openapi/commands/loadCommand.d.ts +8321 -0
- package/dist/utils/openapi/commands/loadCommand.d.ts.map +1 -0
- package/dist/utils/openapi/commands/loadCommand.js +42 -0
- package/dist/utils/openapi/commands/loadCommand.js.map +7 -0
- package/dist/utils/openapi/commands/upgradeCommand.d.ts +3406 -0
- package/dist/utils/openapi/commands/upgradeCommand.d.ts.map +1 -0
- package/dist/utils/openapi/commands/upgradeCommand.js +29 -0
- package/dist/utils/openapi/commands/upgradeCommand.js.map +7 -0
- package/dist/utils/openapi/commands/validateCommand.d.ts +3451 -0
- package/dist/utils/openapi/commands/validateCommand.d.ts.map +1 -0
- package/dist/utils/openapi/commands/validateCommand.js +33 -0
- package/dist/utils/openapi/commands/validateCommand.js.map +7 -0
- package/dist/utils/openapi/openapi.d.ts +1272 -0
- package/dist/utils/openapi/openapi.d.ts.map +1 -0
- package/dist/utils/openapi/openapi.js +15 -0
- package/dist/utils/openapi/openapi.js.map +7 -0
- package/dist/utils/openapi/openapi.test-d.d.ts +2 -0
- package/dist/utils/openapi/openapi.test-d.d.ts.map +1 -0
- package/dist/utils/openapi/openapi.test-d.js +14 -0
- package/dist/utils/openapi/openapi.test-d.js.map +7 -0
- package/dist/utils/openapi/utils/queueTask.d.ts +6 -0
- package/dist/utils/openapi/utils/queueTask.d.ts.map +1 -0
- package/dist/utils/openapi/utils/queueTask.js +10 -0
- package/dist/utils/openapi/utils/queueTask.js.map +7 -0
- package/dist/utils/openapi/utils/workThroughQueue.d.ts +6 -0
- package/dist/utils/openapi/utils/workThroughQueue.d.ts.map +1 -0
- package/dist/utils/openapi/utils/workThroughQueue.js +52 -0
- package/dist/utils/openapi/utils/workThroughQueue.js.map +7 -0
- package/dist/utils/upgrade-from-two-to-three.js +45 -1
- package/dist/utils/upgrade-from-two-to-three.js.map +2 -2
- package/package.json +15 -6
- package/dist/utils/bundle/index.d.ts +0 -4
- package/dist/utils/bundle/index.d.ts.map +0 -1
- package/dist/utils/bundle/index.js +0 -9
- package/dist/utils/bundle/index.js.map +0 -7
- package/dist/utils/bundle/plugins/fetch-urls.d.ts.map +0 -1
- package/dist/utils/bundle/plugins/fetch-urls.js.map +0 -7
- package/dist/utils/bundle/plugins/read-files.d.ts.map +0 -1
- package/dist/utils/bundle/plugins/read-files.js.map +0 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../../src/utils/openapi/openapi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,cAAc,EAAS,MAAM,eAAe,CAAA;AAClF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAGpD;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,aAAa,CAAC,EAAE,cAAc;kBASpC,sBAAsB,YAAY,WAAW;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAE9D"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { loadCommand } from "./commands/loadCommand.js";
|
|
2
|
+
function openapi(globalOptions) {
|
|
3
|
+
const queue = {
|
|
4
|
+
input: null,
|
|
5
|
+
options: globalOptions,
|
|
6
|
+
tasks: []
|
|
7
|
+
};
|
|
8
|
+
return {
|
|
9
|
+
load: (input, options) => loadCommand(queue, input, options)
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
openapi
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=openapi.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utils/openapi/openapi.ts"],
|
|
4
|
+
"sourcesContent": ["import type { AnyApiDefinitionFormat, OpenApiOptions, Queue } from '@/types/index'\nimport type { LoadOptions } from '@/utils/load/load'\nimport { loadCommand } from './commands/loadCommand'\n\n/**\n * Creates a fluent OpenAPI pipeline\n *\n * @deprecated We are about to drop the pipeline syntax. Use the individual utilities instead.\n */\nexport function openapi(globalOptions?: OpenApiOptions) {\n // Create a new queue\n const queue = {\n input: null,\n options: globalOptions,\n tasks: [],\n } as Queue<[]>\n\n return {\n load: (input: AnyApiDefinitionFormat, options?: LoadOptions) => loadCommand(queue, input, options),\n }\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,mBAAmB;AAOrB,SAAS,QAAQ,eAAgC;AAEtD,QAAM,QAAQ;AAAA,IACZ,OAAO;AAAA,IACP,SAAS;AAAA,IACT,OAAO,CAAC;AAAA,EACV;AAEA,SAAO;AAAA,IACL,MAAM,CAAC,OAA+B,YAA0B,YAAY,OAAO,OAAO,OAAO;AAAA,EACnG;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi.test-d.d.ts","sourceRoot":"","sources":["../../../src/utils/openapi/openapi.test-d.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { describe, expectTypeOf, it } from "vitest";
|
|
2
|
+
import { openapi } from "./openapi.js";
|
|
3
|
+
describe("openapi", () => {
|
|
4
|
+
it("returns the correct type for load()", async () => {
|
|
5
|
+
const result = await openapi().load({}).get();
|
|
6
|
+
expectTypeOf(result.filesystem).toMatchTypeOf();
|
|
7
|
+
expectTypeOf(result.valid).toMatchTypeOf();
|
|
8
|
+
});
|
|
9
|
+
it("returns the correct type for validate()", async () => {
|
|
10
|
+
const result = await openapi().load({}).validate().get();
|
|
11
|
+
expectTypeOf(result.valid).toMatchTypeOf();
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=openapi.test-d.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utils/openapi/openapi.test-d.ts"],
|
|
4
|
+
"sourcesContent": ["import { describe, expectTypeOf, it } from 'vitest'\n\nimport type { Filesystem } from '../../types/index'\nimport { openapi } from './openapi'\n\ndescribe('openapi', () => {\n it('returns the correct type for load()', async () => {\n const result = await openapi().load({}).get()\n\n expectTypeOf(result.filesystem).toMatchTypeOf<Filesystem>()\n\n // @ts-expect-error `valid` should be undefined\n expectTypeOf(result.valid).toMatchTypeOf<boolean>()\n })\n\n it('returns the correct type for validate()', async () => {\n const result = await openapi().load({}).validate().get()\n\n expectTypeOf(result.valid).toMatchTypeOf<boolean>()\n })\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,UAAU,cAAc,UAAU;AAG3C,SAAS,eAAe;AAExB,SAAS,WAAW,MAAM;AACxB,KAAG,uCAAuC,YAAY;AACpD,UAAM,SAAS,MAAM,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,IAAI;AAE5C,iBAAa,OAAO,UAAU,EAAE,cAA0B;AAG1D,iBAAa,OAAO,KAAK,EAAE,cAAuB;AAAA,EACpD,CAAC;AAED,KAAG,2CAA2C,YAAY;AACxD,UAAM,SAAS,MAAM,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI;AAEvD,iBAAa,OAAO,KAAK,EAAE,cAAuB;AAAA,EACpD,CAAC;AACH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queueTask.d.ts","sourceRoot":"","sources":["../../../../src/utils/openapi/utils/queueTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAEhD;;GAEG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,GAI7D,KAAK,CAAC,CAAC,CAAC,CACd"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/utils/openapi/utils/queueTask.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Queue, Task } from '@/types/index'\n\n/**\n * Add a new task to the existing queue\n */\nexport function queueTask<T extends Task[]>(queue: Queue, task: Task) {\n return {\n ...queue,\n tasks: [...queue.tasks, task],\n } as Queue<T>\n}\n"],
|
|
5
|
+
"mappings": "AAKO,SAAS,UAA4B,OAAc,MAAY;AACpE,SAAO;AAAA,IACL,GAAG;AAAA,IACH,OAAO,CAAC,GAAG,MAAM,OAAO,IAAI;AAAA,EAC9B;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CommandChain, Queue, Task } from '../../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Takes a queue of tasks and works through them
|
|
4
|
+
*/
|
|
5
|
+
export declare function workThroughQueue<T extends Task[]>(queue: Queue<T>): Promise<CommandChain<T>>;
|
|
6
|
+
//# sourceMappingURL=workThroughQueue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workThroughQueue.d.ts","sourceRoot":"","sources":["../../../../src/utils/openapi/utils/workThroughQueue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAS,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAOrE;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,SAAS,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAkElG"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { dereference } from "../../../utils/dereference.js";
|
|
2
|
+
import { filter } from "../../../utils/filter.js";
|
|
3
|
+
import { load } from "../../../utils/load/load.js";
|
|
4
|
+
import { upgrade } from "../../../utils/upgrade.js";
|
|
5
|
+
import { validate } from "../../../utils/validate.js";
|
|
6
|
+
async function workThroughQueue(queue) {
|
|
7
|
+
const { input } = {
|
|
8
|
+
...queue
|
|
9
|
+
};
|
|
10
|
+
let result = {};
|
|
11
|
+
for (const task of queue.tasks) {
|
|
12
|
+
const name = task.name;
|
|
13
|
+
const options = "options" in task ? task.options : void 0;
|
|
14
|
+
const currentSpecification = result.specification ? result.specification : typeof input === "object" ? (
|
|
15
|
+
// Detach from the original object
|
|
16
|
+
structuredClone(input)
|
|
17
|
+
) : input;
|
|
18
|
+
if (name === "load") {
|
|
19
|
+
result = {
|
|
20
|
+
...result,
|
|
21
|
+
...await load(input, options)
|
|
22
|
+
};
|
|
23
|
+
} else if (name === "filter") {
|
|
24
|
+
result = {
|
|
25
|
+
...result,
|
|
26
|
+
...filter(currentSpecification, options)
|
|
27
|
+
};
|
|
28
|
+
} else if (name === "dereference") {
|
|
29
|
+
result = {
|
|
30
|
+
...result,
|
|
31
|
+
...await dereference(currentSpecification, options)
|
|
32
|
+
};
|
|
33
|
+
} else if (name === "upgrade") {
|
|
34
|
+
result = {
|
|
35
|
+
...result,
|
|
36
|
+
...upgrade(currentSpecification)
|
|
37
|
+
};
|
|
38
|
+
} else if (name === "validate") {
|
|
39
|
+
result = {
|
|
40
|
+
...result,
|
|
41
|
+
...await validate(currentSpecification, options)
|
|
42
|
+
};
|
|
43
|
+
} else {
|
|
44
|
+
const _ = name;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
workThroughQueue
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=workThroughQueue.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/utils/openapi/utils/workThroughQueue.ts"],
|
|
4
|
+
"sourcesContent": ["import type { CommandChain, Merge, Queue, Task } from '@/types/index'\nimport { dereference } from '@/utils/dereference'\nimport { filter } from '@/utils/filter'\nimport { load } from '@/utils/load/load'\nimport { upgrade } from '@/utils/upgrade'\nimport { validate } from '@/utils/validate'\n\n/**\n * Takes a queue of tasks and works through them\n */\nexport async function workThroughQueue<T extends Task[]>(queue: Queue<T>): Promise<CommandChain<T>> {\n const { input } = {\n ...queue,\n }\n let result = {} as CommandChain<T>\n\n // Work through the whole queue\n for (const task of queue.tasks) {\n const name: keyof Commands = task.name\n const options: any = 'options' in task ? task.options : undefined\n\n // Use the result of the previous task, or fall back to the original input\n const currentSpecification = result.specification\n ? result.specification\n : typeof input === 'object'\n ? // Detach from the original object\n structuredClone(input)\n : input\n\n // load\n if (name === 'load') {\n result = {\n ...result,\n ...(await load(input, options as Commands['load']['task']['options'])),\n } as Merge<typeof result, Awaited<typeof load>>\n }\n\n // validate\n else if (name === 'filter') {\n result = {\n ...result,\n ...filter(currentSpecification, options as Commands['filter']['task']['options']),\n } as Merge<typeof result, ReturnType<typeof filter>>\n }\n\n // dereference\n else if (name === 'dereference') {\n result = {\n ...result,\n ...(await dereference(currentSpecification, options as Commands['dereference']['task']['options'])),\n } as Merge<typeof result, Awaited<typeof dereference>>\n }\n\n // upgrade\n else if (name === 'upgrade') {\n result = {\n ...result,\n ...upgrade(currentSpecification),\n } as Merge<typeof result, ReturnType<typeof upgrade>>\n }\n\n // validate\n else if (name === 'validate') {\n result = {\n ...result,\n ...(await validate(currentSpecification, options as Commands['validate']['task']['options'])),\n } as Merge<typeof result, Awaited<typeof validate>>\n }\n\n // Make TS complain when we forgot to handle a command.\n else {\n const _: never = name\n }\n }\n\n return result\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,mBAAmB;AAC5B,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,SAAS,gBAAgB;AAKzB,eAAsB,iBAAmC,OAA2C;AAClG,QAAM,EAAE,MAAM,IAAI;AAAA,IAChB,GAAG;AAAA,EACL;AACA,MAAI,SAAS,CAAC;AAGd,aAAW,QAAQ,MAAM,OAAO;AAC9B,UAAM,OAAuB,KAAK;AAClC,UAAM,UAAe,aAAa,OAAO,KAAK,UAAU;AAGxD,UAAM,uBAAuB,OAAO,gBAChC,OAAO,gBACP,OAAO,UAAU;AAAA;AAAA,MAEf,gBAAgB,KAAK;AAAA,QACrB;AAGN,QAAI,SAAS,QAAQ;AACnB,eAAS;AAAA,QACP,GAAG;AAAA,QACH,GAAI,MAAM,KAAK,OAAO,OAA8C;AAAA,MACtE;AAAA,IACF,WAGS,SAAS,UAAU;AAC1B,eAAS;AAAA,QACP,GAAG;AAAA,QACH,GAAG,OAAO,sBAAsB,OAAgD;AAAA,MAClF;AAAA,IACF,WAGS,SAAS,eAAe;AAC/B,eAAS;AAAA,QACP,GAAG;AAAA,QACH,GAAI,MAAM,YAAY,sBAAsB,OAAqD;AAAA,MACnG;AAAA,IACF,WAGS,SAAS,WAAW;AAC3B,eAAS;AAAA,QACP,GAAG;AAAA,QACH,GAAG,QAAQ,oBAAoB;AAAA,MACjC;AAAA,IACF,WAGS,SAAS,YAAY;AAC5B,eAAS;AAAA,QACP,GAAG;AAAA,QACH,GAAI,MAAM,SAAS,sBAAsB,OAAkD;AAAA,MAC7F;AAAA,IACF,OAGK;AACH,YAAM,IAAW;AAAA,IACnB;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -215,13 +215,57 @@ function transformItemsObject(obj) {
|
|
|
215
215
|
}, {});
|
|
216
216
|
}
|
|
217
217
|
function transformParameterObject(parameter) {
|
|
218
|
+
const serializationStyle = getParameterSerializationStyle(parameter);
|
|
219
|
+
const schema = transformItemsObject(parameter);
|
|
218
220
|
delete parameter.collectionFormat;
|
|
219
221
|
delete parameter.default;
|
|
220
222
|
return {
|
|
221
|
-
schema
|
|
223
|
+
schema,
|
|
224
|
+
...serializationStyle,
|
|
222
225
|
...parameter
|
|
223
226
|
};
|
|
224
227
|
}
|
|
228
|
+
const querySerialization = {
|
|
229
|
+
ssv: {
|
|
230
|
+
style: "spaceDelimited",
|
|
231
|
+
explode: false
|
|
232
|
+
},
|
|
233
|
+
pipes: {
|
|
234
|
+
style: "pipeDelimited",
|
|
235
|
+
explode: false
|
|
236
|
+
},
|
|
237
|
+
multi: {
|
|
238
|
+
style: "form",
|
|
239
|
+
explode: true
|
|
240
|
+
},
|
|
241
|
+
csv: {
|
|
242
|
+
style: "form",
|
|
243
|
+
explode: false
|
|
244
|
+
},
|
|
245
|
+
tsv: {}
|
|
246
|
+
};
|
|
247
|
+
const pathAndHeaderSerialization = {
|
|
248
|
+
ssv: {},
|
|
249
|
+
pipes: {},
|
|
250
|
+
multi: {},
|
|
251
|
+
csv: {
|
|
252
|
+
style: "simple",
|
|
253
|
+
explode: false
|
|
254
|
+
},
|
|
255
|
+
tsv: {}
|
|
256
|
+
};
|
|
257
|
+
const serializationStyles = {
|
|
258
|
+
header: pathAndHeaderSerialization,
|
|
259
|
+
query: querySerialization,
|
|
260
|
+
path: pathAndHeaderSerialization
|
|
261
|
+
};
|
|
262
|
+
function getParameterSerializationStyle(parameter) {
|
|
263
|
+
if (parameter.type !== "array" || !(parameter.in === "query" || parameter.in === "path" || parameter.in === "header")) {
|
|
264
|
+
return {};
|
|
265
|
+
}
|
|
266
|
+
const collectionFormat = parameter.collectionFormat ?? "csv";
|
|
267
|
+
return serializationStyles[parameter.in][collectionFormat];
|
|
268
|
+
}
|
|
225
269
|
export {
|
|
226
270
|
upgradeFromTwoToThree
|
|
227
271
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/upgrade-from-two-to-three.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPIV2, OpenAPIV3 } from '@scalar/openapi-types'\nimport type { UnknownObject } from '@scalar/types/utils'\n\nimport { traverse } from './traverse'\n\n/**\n * Upgrade Swagger 2.0 to OpenAPI 3.0\n *\n * https://swagger.io/blog/news/whats-new-in-openapi-3-0/\n */\nexport function upgradeFromTwoToThree(originalSpecification: UnknownObject) {\n let specification = originalSpecification\n\n // Version\n if (\n specification !== null &&\n typeof specification === 'object' &&\n typeof specification.swagger === 'string' &&\n specification.swagger?.startsWith('2.0')\n ) {\n specification.openapi = '3.0.4'\n delete specification.swagger\n } else {\n // Skip if it\u2019s something else than 3.0.x\n return specification\n }\n\n // Servers\n if (specification.host) {\n const schemes =\n Array.isArray(specification.schemes) && specification.schemes?.length ? specification.schemes : ['http']\n\n specification.servers = schemes.map((scheme: string[]) => ({\n url: `${scheme}://${specification.host}${specification.basePath ?? ''}`,\n }))\n\n delete specification.basePath\n delete specification.schemes\n delete specification.host\n } else if (specification.basePath) {\n specification.servers = [{ url: specification.basePath }]\n delete specification.basePath\n }\n\n // Schemas\n if (specification.definitions) {\n specification.components = Object.assign({}, specification.components, {\n schemas: specification.definitions,\n })\n\n delete specification.definitions\n\n // Rewrite $refs to definitions\n specification = traverse(specification, (schema) => {\n // Rewrite $refs to components\n if (typeof schema.$ref === 'string' && schema.$ref.startsWith('#/definitions/')) {\n schema.$ref = schema.$ref.replace(/^#\\/definitions\\//, '#/components/schemas/')\n }\n\n return schema\n })\n }\n\n // Transform file type to string with binary format\n specification = traverse(specification, (schema) => {\n if (schema.type === 'file') {\n schema.type = 'string'\n schema.format = 'binary'\n }\n\n return schema\n })\n\n // Paths\n if (typeof specification.paths === 'object') {\n for (const path in specification.paths) {\n if (Object.hasOwn(specification.paths, path)) {\n const pathItem = specification.paths[path]\n\n for (const method in pathItem) {\n if (Object.hasOwn(pathItem, method)) {\n const operationItem = pathItem[method]\n\n // Request bodies\n if (operationItem.parameters) {\n const bodyParameter = structuredClone(\n operationItem.parameters.find((parameter: OpenAPIV3.ParameterObject) => parameter.in === 'body') ?? {},\n )\n\n if (bodyParameter && Object.keys(bodyParameter).length) {\n delete bodyParameter.name\n delete bodyParameter.in\n\n const consumes = specification.consumes ?? operationItem.consumes ?? ['application/json']\n\n if (typeof operationItem.requestBody !== 'object') {\n operationItem.requestBody = {}\n }\n\n if (typeof operationItem.requestBody.content !== 'object') {\n operationItem.requestBody.content = {}\n }\n\n const { schema, ...requestBody } = bodyParameter\n\n operationItem.requestBody = {\n ...operationItem.requestBody,\n ...requestBody,\n }\n\n for (const type of consumes) {\n operationItem.requestBody.content[type] = {\n schema: schema,\n }\n }\n }\n\n // Delete body parameter\n operationItem.parameters = operationItem.parameters.filter(\n (parameter: OpenAPIV2.ParameterObject) => parameter.in !== 'body',\n )\n\n delete operationItem.consumes\n\n // formData parameters\n const formDataParameters = operationItem.parameters.filter(\n (parameter: OpenAPIV2.ParameterObject) => parameter.in === 'formData',\n )\n\n if (formDataParameters.length > 0) {\n if (typeof operationItem.requestBody !== 'object') {\n operationItem.requestBody = {}\n }\n\n if (typeof operationItem.requestBody.content !== 'object') {\n operationItem.requestBody.content = {}\n }\n\n operationItem.requestBody.content['application/x-www-form-urlencoded'] = {\n schema: {\n type: 'object',\n properties: {},\n required: [], // Initialize required array\n },\n }\n\n for (const param of formDataParameters) {\n operationItem.requestBody.content['application/x-www-form-urlencoded'].schema.properties[param.name] =\n {\n type: param.type,\n description: param.description,\n }\n\n // Add to required array if param is required\n if (param.required) {\n operationItem.requestBody.content['application/x-www-form-urlencoded'].schema.required.push(\n param.name,\n )\n }\n }\n\n // Remove formData parameters from the parameters array\n operationItem.parameters = operationItem.parameters.filter(\n (parameter: OpenAPIV2.ParameterObject) => parameter.in !== 'formData',\n )\n }\n\n operationItem.parameters = operationItem.parameters.map((parameter) =>\n transformParameterObject(parameter),\n )\n }\n\n // Responses\n if (operationItem.responses) {\n for (const response in operationItem.responses) {\n if (Object.hasOwn(operationItem.responses, response)) {\n const responseItem = operationItem.responses[response]\n\n if (responseItem.headers) {\n responseItem.headers = Object.entries(responseItem.headers).reduce((acc, [name, header]) => {\n return {\n [name]: transformParameterObject(header),\n ...acc,\n }\n }, {})\n }\n if (responseItem.schema) {\n const produces = specification.produces ?? operationItem.produces ?? ['application/json']\n\n if (typeof responseItem.content !== 'object') {\n responseItem.content = {}\n }\n\n for (const type of produces) {\n responseItem.content[type] = {\n schema: responseItem.schema,\n }\n }\n\n delete responseItem.schema\n }\n }\n }\n }\n\n delete operationItem.produces\n\n // Delete empty parameters\n if (operationItem.parameters?.length === 0) {\n delete operationItem.parameters\n }\n }\n }\n }\n }\n }\n\n // Upgrade securityDefinitions\n if (specification.securityDefinitions) {\n if (typeof specification.components !== 'object') {\n specification.components = {}\n }\n\n // Assert that components is of type OpenAPIV3.ComponentsObject\n specification.components = specification.components as OpenAPIV3.ComponentsObject\n\n Object.assign(specification.components, { securitySchemes: {} })\n\n for (const [key, securityScheme] of Object.entries(specification.securityDefinitions)) {\n if (typeof securityScheme === 'object') {\n if ('type' in securityScheme && securityScheme.type === 'oauth2') {\n const { flow, authorizationUrl, tokenUrl, scopes } = securityScheme as {\n type: 'oauth2'\n flow?: string\n authorizationUrl?: string\n tokenUrl?: string\n scopes?: Record<string, string>\n }\n\n // Assert that securitySchemes is of type OpenAPIV3.SecuritySchemeObject\n Object.assign((specification.components as OpenAPIV3.ComponentsObject).securitySchemes, {\n [key]: {\n type: 'oauth2',\n flows: {\n [flow as string]: Object.assign(\n {},\n authorizationUrl && { authorizationUrl },\n tokenUrl && { tokenUrl },\n scopes && { scopes },\n ),\n },\n },\n })\n } else if ('type' in securityScheme && securityScheme.type === 'basic') {\n Object.assign((specification.components as OpenAPIV3.ComponentsObject).securitySchemes, {\n [key]: {\n type: 'http',\n scheme: 'basic',\n },\n })\n } else {\n Object.assign((specification.components as OpenAPIV3.ComponentsObject).securitySchemes, {\n [key]: securityScheme,\n })\n }\n }\n }\n\n delete specification.securityDefinitions\n }\n\n return specification as OpenAPIV3.Document\n}\n\nfunction transformItemsObject<T extends Record<PropertyKey, unknown>>(obj: T): OpenAPIV3.SchemaObject {\n const schemaProperties = [\n 'type',\n 'format',\n 'items',\n 'maximum',\n 'exclusiveMaximum',\n 'minimum',\n 'exclusiveMinimum',\n 'maxLength',\n 'minLength',\n 'pattern',\n 'maxItems',\n 'minItems',\n 'uniqueItems',\n 'enum',\n 'multipleOf',\n ]\n\n return schemaProperties.reduce((acc, property) => {\n if (Object.hasOwn(obj, property)) {\n acc[property] = obj[property]\n delete obj[property]\n }\n\n return acc\n }, {} as OpenAPIV3.SchemaObject)\n}\n\nfunction transformParameterObject(parameter: OpenAPIV2.ParameterObject): OpenAPIV3.ParameterObject {\n delete parameter.collectionFormat\n delete parameter.default\n\n return {\n schema: transformItemsObject(parameter),\n ...parameter,\n }\n}\n"],
|
|
5
|
-
"mappings": "AAGA,SAAS,gBAAgB;AAO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Q,cAAc,WAA0C,iBAAiB;AAAA,YACtF,CAAC,GAAG,GAAG;AAAA,UACT,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAEA,WAAO,cAAc;AAAA,EACvB;AAEA,SAAO;AACT;AAEA,SAAS,qBAA6D,KAAgC;AACpG,QAAM,mBAAmB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SAAO,iBAAiB,OAAO,CAAC,KAAK,aAAa;AAChD,QAAI,OAAO,OAAO,KAAK,QAAQ,GAAG;AAChC,UAAI,QAAQ,IAAI,IAAI,QAAQ;AAC5B,aAAO,IAAI,QAAQ;AAAA,IACrB;AAEA,WAAO;AAAA,EACT,GAAG,CAAC,CAA2B;AACjC;AAEA,SAAS,yBAAyB,WAAiE;
|
|
4
|
+
"sourcesContent": ["import type { OpenAPIV2, OpenAPIV3 } from '@scalar/openapi-types'\nimport type { UnknownObject } from '@scalar/types/utils'\n\nimport { traverse } from './traverse'\n\n/**\n * Upgrade Swagger 2.0 to OpenAPI 3.0\n *\n * https://swagger.io/blog/news/whats-new-in-openapi-3-0/\n */\nexport function upgradeFromTwoToThree(originalSpecification: UnknownObject) {\n let specification = originalSpecification\n\n // Version\n if (\n specification !== null &&\n typeof specification === 'object' &&\n typeof specification.swagger === 'string' &&\n specification.swagger?.startsWith('2.0')\n ) {\n specification.openapi = '3.0.4'\n delete specification.swagger\n } else {\n // Skip if it\u2019s something else than 3.0.x\n return specification\n }\n\n // Servers\n if (specification.host) {\n const schemes =\n Array.isArray(specification.schemes) && specification.schemes?.length ? specification.schemes : ['http']\n\n specification.servers = schemes.map((scheme: string[]) => ({\n url: `${scheme}://${specification.host}${specification.basePath ?? ''}`,\n }))\n\n delete specification.basePath\n delete specification.schemes\n delete specification.host\n } else if (specification.basePath) {\n specification.servers = [{ url: specification.basePath }]\n delete specification.basePath\n }\n\n // Schemas\n if (specification.definitions) {\n specification.components = Object.assign({}, specification.components, {\n schemas: specification.definitions,\n })\n\n delete specification.definitions\n\n // Rewrite $refs to definitions\n specification = traverse(specification, (schema) => {\n // Rewrite $refs to components\n if (typeof schema.$ref === 'string' && schema.$ref.startsWith('#/definitions/')) {\n schema.$ref = schema.$ref.replace(/^#\\/definitions\\//, '#/components/schemas/')\n }\n\n return schema\n })\n }\n\n // Transform file type to string with binary format\n specification = traverse(specification, (schema) => {\n if (schema.type === 'file') {\n schema.type = 'string'\n schema.format = 'binary'\n }\n\n return schema\n })\n\n // Paths\n if (typeof specification.paths === 'object') {\n for (const path in specification.paths) {\n if (Object.hasOwn(specification.paths, path)) {\n const pathItem = specification.paths[path]\n\n for (const method in pathItem) {\n if (Object.hasOwn(pathItem, method)) {\n const operationItem = pathItem[method]\n\n // Request bodies\n if (operationItem.parameters) {\n const bodyParameter = structuredClone(\n operationItem.parameters.find((parameter: OpenAPIV3.ParameterObject) => parameter.in === 'body') ?? {},\n )\n\n if (bodyParameter && Object.keys(bodyParameter).length) {\n delete bodyParameter.name\n delete bodyParameter.in\n\n const consumes = specification.consumes ?? operationItem.consumes ?? ['application/json']\n\n if (typeof operationItem.requestBody !== 'object') {\n operationItem.requestBody = {}\n }\n\n if (typeof operationItem.requestBody.content !== 'object') {\n operationItem.requestBody.content = {}\n }\n\n const { schema, ...requestBody } = bodyParameter\n\n operationItem.requestBody = {\n ...operationItem.requestBody,\n ...requestBody,\n }\n\n for (const type of consumes) {\n operationItem.requestBody.content[type] = {\n schema: schema,\n }\n }\n }\n\n // Delete body parameter\n operationItem.parameters = operationItem.parameters.filter(\n (parameter: OpenAPIV2.ParameterObject) => parameter.in !== 'body',\n )\n\n delete operationItem.consumes\n\n // formData parameters\n const formDataParameters = operationItem.parameters.filter(\n (parameter: OpenAPIV2.ParameterObject) => parameter.in === 'formData',\n )\n\n if (formDataParameters.length > 0) {\n if (typeof operationItem.requestBody !== 'object') {\n operationItem.requestBody = {}\n }\n\n if (typeof operationItem.requestBody.content !== 'object') {\n operationItem.requestBody.content = {}\n }\n\n operationItem.requestBody.content['application/x-www-form-urlencoded'] = {\n schema: {\n type: 'object',\n properties: {},\n required: [], // Initialize required array\n },\n }\n\n for (const param of formDataParameters) {\n operationItem.requestBody.content['application/x-www-form-urlencoded'].schema.properties[param.name] =\n {\n type: param.type,\n description: param.description,\n }\n\n // Add to required array if param is required\n if (param.required) {\n operationItem.requestBody.content['application/x-www-form-urlencoded'].schema.required.push(\n param.name,\n )\n }\n }\n\n // Remove formData parameters from the parameters array\n operationItem.parameters = operationItem.parameters.filter(\n (parameter: OpenAPIV2.ParameterObject) => parameter.in !== 'formData',\n )\n }\n\n operationItem.parameters = operationItem.parameters.map((parameter) =>\n transformParameterObject(parameter),\n )\n }\n\n // Responses\n if (operationItem.responses) {\n for (const response in operationItem.responses) {\n if (Object.hasOwn(operationItem.responses, response)) {\n const responseItem = operationItem.responses[response]\n\n if (responseItem.headers) {\n responseItem.headers = Object.entries(responseItem.headers).reduce((acc, [name, header]) => {\n return {\n [name]: transformParameterObject(header),\n ...acc,\n }\n }, {})\n }\n if (responseItem.schema) {\n const produces = specification.produces ?? operationItem.produces ?? ['application/json']\n\n if (typeof responseItem.content !== 'object') {\n responseItem.content = {}\n }\n\n for (const type of produces) {\n responseItem.content[type] = {\n schema: responseItem.schema,\n }\n }\n\n delete responseItem.schema\n }\n }\n }\n }\n\n delete operationItem.produces\n\n // Delete empty parameters\n if (operationItem.parameters?.length === 0) {\n delete operationItem.parameters\n }\n }\n }\n }\n }\n }\n\n // Upgrade securityDefinitions\n if (specification.securityDefinitions) {\n if (typeof specification.components !== 'object') {\n specification.components = {}\n }\n\n // Assert that components is of type OpenAPIV3.ComponentsObject\n specification.components = specification.components as OpenAPIV3.ComponentsObject\n\n Object.assign(specification.components, { securitySchemes: {} })\n\n for (const [key, securityScheme] of Object.entries(specification.securityDefinitions)) {\n if (typeof securityScheme === 'object') {\n if ('type' in securityScheme && securityScheme.type === 'oauth2') {\n const { flow, authorizationUrl, tokenUrl, scopes } = securityScheme as {\n type: 'oauth2'\n flow?: string\n authorizationUrl?: string\n tokenUrl?: string\n scopes?: Record<string, string>\n }\n\n // Assert that securitySchemes is of type OpenAPIV3.SecuritySchemeObject\n Object.assign((specification.components as OpenAPIV3.ComponentsObject).securitySchemes, {\n [key]: {\n type: 'oauth2',\n flows: {\n [flow as string]: Object.assign(\n {},\n authorizationUrl && { authorizationUrl },\n tokenUrl && { tokenUrl },\n scopes && { scopes },\n ),\n },\n },\n })\n } else if ('type' in securityScheme && securityScheme.type === 'basic') {\n Object.assign((specification.components as OpenAPIV3.ComponentsObject).securitySchemes, {\n [key]: {\n type: 'http',\n scheme: 'basic',\n },\n })\n } else {\n Object.assign((specification.components as OpenAPIV3.ComponentsObject).securitySchemes, {\n [key]: securityScheme,\n })\n }\n }\n }\n\n delete specification.securityDefinitions\n }\n\n return specification as OpenAPIV3.Document\n}\n\nfunction transformItemsObject<T extends Record<PropertyKey, unknown>>(obj: T): OpenAPIV3.SchemaObject {\n const schemaProperties = [\n 'type',\n 'format',\n 'items',\n 'maximum',\n 'exclusiveMaximum',\n 'minimum',\n 'exclusiveMinimum',\n 'maxLength',\n 'minLength',\n 'pattern',\n 'maxItems',\n 'minItems',\n 'uniqueItems',\n 'enum',\n 'multipleOf',\n ]\n\n return schemaProperties.reduce((acc, property) => {\n if (Object.hasOwn(obj, property)) {\n acc[property] = obj[property]\n delete obj[property]\n }\n\n return acc\n }, {} as OpenAPIV3.SchemaObject)\n}\n\nfunction transformParameterObject(parameter: OpenAPIV2.ParameterObject): OpenAPIV3.ParameterObject {\n // it is important to call getParameterSerializationStyle first because transformItemsObject modifies properties on which getParameterSerializationStyle rely on\n const serializationStyle = getParameterSerializationStyle(parameter)\n const schema = transformItemsObject(parameter)\n\n delete parameter.collectionFormat\n delete parameter.default\n\n return {\n schema,\n ...serializationStyle,\n ...parameter,\n }\n}\n\ntype CollectionFormat = 'csv' | 'ssv' | 'tsv' | 'pipes' | 'multi'\n\ntype ParameterSerializationStyle = { style?: string; explode?: boolean }\n\nconst querySerialization: Record<CollectionFormat, ParameterSerializationStyle> = {\n ssv: {\n style: 'spaceDelimited',\n explode: false,\n },\n pipes: {\n style: 'pipeDelimited',\n explode: false,\n },\n multi: {\n style: 'form',\n explode: true,\n },\n csv: {\n style: 'form',\n explode: false,\n },\n tsv: {},\n}\n\nconst pathAndHeaderSerialization: Record<CollectionFormat, ParameterSerializationStyle> = {\n ssv: {},\n pipes: {},\n multi: {},\n csv: {\n style: 'simple',\n explode: false,\n },\n tsv: {},\n}\n\nconst serializationStyles = {\n header: pathAndHeaderSerialization,\n query: querySerialization,\n path: pathAndHeaderSerialization,\n} as const\n\nfunction getParameterSerializationStyle(parameter: OpenAPIV2.ParameterObject): ParameterSerializationStyle {\n if (\n parameter.type !== 'array' ||\n !(parameter.in === 'query' || parameter.in === 'path' || parameter.in === 'header')\n ) {\n return {}\n }\n\n const collectionFormat = parameter.collectionFormat ?? 'csv'\n\n return serializationStyles[parameter.in][collectionFormat]\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,gBAAgB;AAOlB,SAAS,sBAAsB,uBAAsC;AAC1E,MAAI,gBAAgB;AAGpB,MACE,kBAAkB,QAClB,OAAO,kBAAkB,YACzB,OAAO,cAAc,YAAY,YACjC,cAAc,SAAS,WAAW,KAAK,GACvC;AACA,kBAAc,UAAU;AACxB,WAAO,cAAc;AAAA,EACvB,OAAO;AAEL,WAAO;AAAA,EACT;AAGA,MAAI,cAAc,MAAM;AACtB,UAAM,UACJ,MAAM,QAAQ,cAAc,OAAO,KAAK,cAAc,SAAS,SAAS,cAAc,UAAU,CAAC,MAAM;AAEzG,kBAAc,UAAU,QAAQ,IAAI,CAAC,YAAsB;AAAA,MACzD,KAAK,GAAG,MAAM,MAAM,cAAc,IAAI,GAAG,cAAc,YAAY,EAAE;AA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
|
|
19
19
|
],
|
|
20
|
-
"version": "0.
|
|
20
|
+
"version": "0.16.0",
|
|
21
21
|
"engines": {
|
|
22
22
|
"node": ">=20"
|
|
23
23
|
},
|
|
@@ -30,6 +30,16 @@
|
|
|
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
|
+
},
|
|
33
43
|
"./plugins/fetch-urls": {
|
|
34
44
|
"import": "./dist/plugins/fetch-urls/index.js",
|
|
35
45
|
"types": "./dist/plugins/fetch-urls/index.d.ts",
|
|
@@ -58,14 +68,14 @@
|
|
|
58
68
|
"devDependencies": {
|
|
59
69
|
"@apidevtools/swagger-parser": "^10.1.0",
|
|
60
70
|
"@types/node": "^20.17.10",
|
|
61
|
-
"fastify": "^
|
|
71
|
+
"fastify": "^5.3.3",
|
|
62
72
|
"json-to-ast": "^2.1.0",
|
|
63
73
|
"just-diff": "^6.0.2",
|
|
64
74
|
"tinybench": "^2.8.0",
|
|
65
75
|
"vite": "5.4.19",
|
|
66
|
-
"@scalar/
|
|
67
|
-
"@scalar/
|
|
68
|
-
"@scalar/
|
|
76
|
+
"@scalar/types": "0.2.2",
|
|
77
|
+
"@scalar/build-tooling": "0.2.2",
|
|
78
|
+
"@scalar/openapi-types": "0.3.2"
|
|
69
79
|
},
|
|
70
80
|
"scripts": {
|
|
71
81
|
"build": "scalar-build-esbuild",
|
|
@@ -74,7 +84,6 @@
|
|
|
74
84
|
"lint:fix": "eslint . --fix",
|
|
75
85
|
"test": "NODE_OPTIONS=--max_old_space_size=8192 vitest",
|
|
76
86
|
"test:prepare": "vite-node scripts/load-files.ts",
|
|
77
|
-
"test:unit": "vitest",
|
|
78
87
|
"types:build": "scalar-types-build",
|
|
79
88
|
"types:check": "scalar-types-check"
|
|
80
89
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/bundle/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/utils/bundle/index.ts"],
|
|
4
|
-
"sourcesContent": ["// biome-ignore lint/performance/noBarrelFile: This is the interface we expose for the bundler\nexport { bundle } from './bundle'\nexport { fetchUrls } from './plugins/fetch-urls'\nexport { readFiles } from './plugins/read-files'\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,cAAc;AACvB,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-urls.d.ts","sourceRoot":"","sources":["../../../../src/utils/bundle/plugins/fetch-urls.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;CACvD,CAAC,CAAA;AAEF;;;;;;;;;;;;;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,CA8BxB;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,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/utils/bundle/plugins/fetch-urls.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}>\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 domain = new URL(url).host\n\n // Get the headers that match the domain\n const headers = config?.headers?.find((a) => a.domains.find((d) => d === domain) !== undefined)?.headers\n\n const result = await limiter(() =>\n fetch(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: (value) => isRemoteUrl(value),\n exec: (value) => fetchUrl(value, limiter, config),\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,mBAAoD;AAC7D,SAAS,qBAAqB;AAoB9B,eAAsB,SACpB,KACA,SACA,QACwB;AACxB,MAAI;AACF,UAAM,SAAS,IAAI,IAAI,GAAG,EAAE;AAG5B,UAAM,UAAU,QAAQ,SAAS,KAAK,CAAC,MAAM,EAAE,QAAQ,KAAK,CAAC,MAAM,MAAM,MAAM,MAAM,MAAS,GAAG;AAEjG,UAAM,SAAS,MAAM;AAAA,MAAQ,MAC3B,MAAM,KAAK;AAAA,QACT;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,CAAC,UAAU,YAAY,KAAK;AAAA,IACtC,MAAM,CAAC,UAAU,SAAS,OAAO,SAAS,MAAM;AAAA,EAClD;AACF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"read-files.d.ts","sourceRoot":"","sources":["../../../../src/utils/bundle/plugins/read-files.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAIpF;;;;;;;;;;;;;GAaG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAiBnE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAKlC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/utils/bundle/plugins/read-files.ts"],
|
|
4
|
-
"sourcesContent": ["import { normalize } from '@/utils/normalize'\nimport { isRemoteUrl, type Plugin, type ResolveResult } from '@/utils/bundle/bundle'\n\nconst fs = typeof window === 'undefined' ? await import('node:fs/promises') : undefined\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 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: (value) => !isRemoteUrl(value),\n exec: (value) => readFile(value),\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,mBAAoD;AAE7D,MAAM,KAAK,OAAO,WAAW,cAAc,MAAM,OAAO,kBAAkB,IAAI;AAgB9E,eAAsB,SAAS,MAAsC;AACnE,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,CAAC,UAAU,CAAC,YAAY,KAAK;AAAA,IACvC,MAAM,CAAC,UAAU,SAAS,KAAK;AAAA,EACjC;AACF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|