@scalar/workspace-store 0.60.0 → 0.61.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 +48 -0
- package/README.md +6 -0
- package/dist/channel-example/build-connection-url.d.ts.map +1 -1
- package/dist/channel-example/build-connection-url.js +3 -3
- package/dist/channel-example/dedupe-requirements.d.ts +1 -1
- package/dist/channel-example/get-async-api-protocols.js +2 -2
- package/dist/channel-example/get-asyncapi-security-requirements.d.ts +1 -1
- package/dist/channel-example/get-channel-connection-security.d.ts +1 -1
- package/dist/channel-example/get-channel-operations.d.ts.map +1 -1
- package/dist/channel-example/get-channel-operations.js +4 -1
- package/dist/channel-example/get-channel-parameters.d.ts.map +1 -1
- package/dist/channel-example/get-channel-parameters.js +3 -1
- package/dist/channel-example/resolve-channel.d.ts.map +1 -1
- package/dist/channel-example/resolve-channel.js +2 -0
- package/dist/channel-example/resolve-operation-channel.d.ts.map +1 -1
- package/dist/channel-example/resolve-operation-channel.js +4 -0
- package/dist/channel-example/resolve-operation-with-traits.js +2 -2
- package/dist/channel-example/servers.d.ts.map +1 -1
- package/dist/channel-example/servers.js +3 -1
- package/dist/channel-example/types.d.ts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +3 -3
- package/dist/entities/auth/schema.d.ts +460 -20
- package/dist/entities/auth/schema.d.ts.map +1 -1
- package/dist/entities/auth/schema.js +2 -2
- package/dist/events/definitions/auth.d.ts +2 -2
- package/dist/events/definitions/document.d.ts +1 -1
- package/dist/events/definitions/operation.d.ts +3 -2
- package/dist/events/definitions/operation.d.ts.map +1 -1
- package/dist/events/definitions/server.d.ts +1 -1
- package/dist/events/old-definitions.d.ts +1 -1
- package/dist/helpers/create-chunk-writer.d.ts +6 -0
- package/dist/helpers/create-chunk-writer.d.ts.map +1 -0
- package/dist/helpers/create-chunk-writer.js +44 -0
- package/dist/helpers/dynamic-ref.d.ts +13 -2
- package/dist/helpers/dynamic-ref.d.ts.map +1 -1
- package/dist/helpers/dynamic-ref.js +20 -7
- package/dist/helpers/encode-chunk-name.d.ts +3 -0
- package/dist/helpers/encode-chunk-name.d.ts.map +1 -0
- package/dist/helpers/encode-chunk-name.js +9 -0
- package/dist/helpers/for-each-path-item-operation.d.ts +2 -2
- package/dist/helpers/get-first-server.d.ts +1 -1
- package/dist/helpers/get-resolved-ref.d.ts +6 -1
- package/dist/helpers/get-resolved-ref.d.ts.map +1 -1
- package/dist/helpers/get-resolved-ref.js +3 -10
- package/dist/helpers/is-non-optional-security-requirement.d.ts +1 -1
- package/dist/helpers/merge-object.d.ts +2 -2
- package/dist/helpers/merge-object.d.ts.map +1 -1
- package/dist/helpers/merge-object.js +2 -5
- package/dist/mutators/auth.d.ts +1 -1
- package/dist/mutators/auth.d.ts.map +1 -1
- package/dist/mutators/auth.js +9 -4
- package/dist/mutators/index.d.ts +10 -10
- package/dist/mutators/operation/body.js +2 -2
- package/dist/mutators/operation/helpers/fetch-request-to-har.d.ts.map +1 -1
- package/dist/mutators/operation/helpers/fetch-request-to-har.js +12 -2
- package/dist/mutators/operation/helpers/har-to-operation.d.ts +1 -1
- package/dist/mutators/operation/helpers/har-to-operation.d.ts.map +1 -1
- package/dist/mutators/operation/helpers/har-to-operation.js +9 -5
- package/dist/mutators/operation/helpers/sync-path-parameters.d.ts +2 -2
- package/dist/mutators/operation/history.js +2 -2
- package/dist/mutators/operation/operation.d.ts.map +1 -1
- package/dist/mutators/operation/operation.js +4 -0
- package/dist/mutators/operation/parameters.js +1 -1
- package/dist/mutators/server.d.ts +3 -3
- package/dist/mutators/server.js +1 -1
- package/dist/mutators/tag.d.ts.map +1 -1
- package/dist/mutators/tag.js +4 -0
- package/dist/navigation/helpers/get-openapi-object.d.ts +1 -1
- package/dist/navigation/helpers/traverse-asyncapi-document.d.ts.map +1 -1
- package/dist/navigation/helpers/traverse-asyncapi-document.js +2 -2
- package/dist/navigation/helpers/traverse-description.d.ts +1 -1
- package/dist/navigation/helpers/traverse-document.d.ts +1 -1
- package/dist/navigation/helpers/traverse-examples.d.ts +12 -1
- package/dist/navigation/helpers/traverse-examples.d.ts.map +1 -1
- package/dist/navigation/helpers/traverse-examples.js +22 -1
- package/dist/navigation/helpers/traverse-paths.d.ts +1 -1
- package/dist/navigation/helpers/traverse-schemas.d.ts +1 -1
- package/dist/navigation/helpers/traverse-tags.d.ts +1 -1
- package/dist/navigation/helpers/traverse-webhooks.d.ts +1 -1
- package/dist/navigation/helpers/update-order-ids.d.ts +2 -2
- package/dist/navigation/index.d.ts +1 -0
- package/dist/navigation/index.d.ts.map +1 -1
- package/dist/navigation/index.js +1 -0
- package/dist/navigation/types.d.ts +1 -1
- package/dist/persistence/index.d.ts.map +1 -1
- package/dist/persistence/index.js +10 -10
- package/dist/persistence/indexdb.d.ts.map +1 -1
- package/dist/persistence/indexdb.js +7 -5
- package/dist/persistence/migrations/v2-team-to-local.d.ts.map +1 -1
- package/dist/persistence/migrations/v2-team-to-local.js +3 -4
- package/dist/plugins/bundler/index.d.ts +5 -2
- package/dist/plugins/bundler/index.d.ts.map +1 -1
- package/dist/plugins/bundler/index.js +24 -26
- package/dist/request-example/builder/body/build-request-body.d.ts +2 -1
- package/dist/request-example/builder/body/build-request-body.d.ts.map +1 -1
- package/dist/request-example/builder/body/build-request-body.js +41 -5
- package/dist/request-example/builder/body/encode-multipart-body.d.ts +9 -0
- package/dist/request-example/builder/body/encode-multipart-body.d.ts.map +1 -0
- package/dist/request-example/builder/body/encode-multipart-body.js +29 -0
- package/dist/request-example/builder/body/get-request-body-example.d.ts +1 -1
- package/dist/request-example/builder/body/get-selected-body-content-type.d.ts +1 -1
- package/dist/request-example/builder/body/schema-value-coercion.d.ts +1 -1
- package/dist/request-example/builder/body/schema-value-coercion.js +1 -1
- package/dist/request-example/builder/body/serialize-form-property.d.ts +1 -1
- package/dist/request-example/builder/body/serialize-multipart-array.d.ts +16 -0
- package/dist/request-example/builder/body/serialize-multipart-array.d.ts.map +1 -0
- package/dist/request-example/builder/body/serialize-multipart-array.js +37 -0
- package/dist/request-example/builder/build-request.d.ts.map +1 -1
- package/dist/request-example/builder/build-request.js +12 -7
- package/dist/request-example/builder/header/build-request-parameters.d.ts +1 -1
- package/dist/request-example/builder/header/build-request-parameters.d.ts.map +1 -1
- package/dist/request-example/builder/header/build-request-parameters.js +7 -1
- package/dist/request-example/builder/header/de-serialize-parameter.d.ts +1 -1
- package/dist/request-example/builder/header/de-serialize-parameter.d.ts.map +1 -1
- package/dist/request-example/builder/header/de-serialize-parameter.js +2 -1
- package/dist/request-example/builder/header/is-param-disabled.d.ts +1 -1
- package/dist/request-example/builder/header/serialize-parameter.d.ts.map +1 -1
- package/dist/request-example/builder/header/serialize-parameter.js +13 -14
- package/dist/request-example/builder/helpers/get-example-from-schema.d.ts +9 -1
- package/dist/request-example/builder/helpers/get-example-from-schema.d.ts.map +1 -1
- package/dist/request-example/builder/helpers/get-example-from-schema.js +255 -20
- package/dist/request-example/builder/helpers/get-example.d.ts +1 -1
- package/dist/request-example/builder/helpers/get-example.js +2 -2
- package/dist/request-example/builder/helpers/get-resolved-url.d.ts +1 -1
- package/dist/request-example/builder/helpers/get-server-variables.d.ts +1 -1
- package/dist/request-example/builder/index.d.ts +1 -0
- package/dist/request-example/builder/index.d.ts.map +1 -1
- package/dist/request-example/builder/index.js +1 -0
- package/dist/request-example/builder/request-factory.d.ts +2 -2
- package/dist/request-example/builder/security/broker-scheme-types.d.ts.map +1 -1
- package/dist/request-example/builder/security/broker-scheme-types.js +2 -2
- package/dist/request-example/builder/security/build-request-security.d.ts.map +1 -1
- package/dist/request-example/builder/security/build-request-security.js +3 -4
- package/dist/request-example/builder/security/secret-types.d.ts +13 -4
- package/dist/request-example/builder/security/secret-types.d.ts.map +1 -1
- package/dist/request-example/context/get-request-example-context.d.ts +3 -3
- package/dist/request-example/context/get-request-example-context.js +1 -1
- package/dist/request-example/context/headers.d.ts +1 -1
- package/dist/request-example/context/headers.js +1 -1
- package/dist/request-example/context/helpers/combine-params.d.ts +1 -1
- package/dist/request-example/context/security/extract-security-scheme-secrets.d.ts +16 -3
- package/dist/request-example/context/security/extract-security-scheme-secrets.d.ts.map +1 -1
- package/dist/request-example/context/security/extract-security-scheme-secrets.js +21 -19
- package/dist/request-example/context/security/get-security-requirements.d.ts +2 -2
- package/dist/request-example/context/security/get-security-schemes.d.ts +1 -1
- package/dist/request-example/context/security/get-selected-security.d.ts +1 -1
- package/dist/request-example/context/security/is-auth-optional.d.ts +1 -1
- package/dist/request-example/context/security/merge-security.d.ts +3 -3
- package/dist/request-example/context/security/merge-security.d.ts.map +1 -1
- package/dist/request-example/context/security/merge-security.js +40 -11
- package/dist/request-example/context/servers.d.ts +2 -2
- package/dist/request-example/functions.d.ts.map +1 -1
- package/dist/request-example/index.d.ts +1 -1
- package/dist/request-example/index.d.ts.map +1 -1
- package/dist/request-example/index.js +1 -1
- package/dist/resolve.d.ts +1 -1
- package/dist/resolve.js +1 -1
- package/dist/schemas/navigation.d.ts +4 -4
- package/dist/schemas/navigation.js +1 -1
- package/dist/schemas/reference-config/index.d.ts +92 -4
- package/dist/schemas/reference-config/index.d.ts.map +1 -1
- package/dist/schemas/reference-config/settings.d.ts +93 -5
- package/dist/schemas/reference-config/settings.d.ts.map +1 -1
- package/dist/schemas/reference-config/settings.js +1 -1
- package/dist/schemas/type-guards.d.ts +1 -1
- package/dist/schemas/v3.1/openapi/index.d.ts.map +1 -1
- package/dist/schemas/v3.1/openapi/index.js +11 -1
- package/dist/schemas/v3.1/strict/openapi-document.d.ts +210 -0
- package/dist/schemas/v3.1/strict/openapi-document.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/security-scheme.d.ts +13 -1
- package/dist/schemas/v3.1/strict/security-scheme.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/security-scheme.js +11 -1
- package/dist/schemas/v3.2/openapi/index.d.ts +2 -0
- package/dist/schemas/v3.2/openapi/index.d.ts.map +1 -1
- package/dist/schemas/v3.2/openapi/index.js +13 -1
- package/dist/schemas/v3.2/strict/oauth-flow.d.ts +23 -1
- package/dist/schemas/v3.2/strict/oauth-flow.d.ts.map +1 -1
- package/dist/schemas/v3.2/strict/oauth-flow.js +6 -1
- package/dist/schemas/v3.2/strict/oauthflows.d.ts +20 -0
- package/dist/schemas/v3.2/strict/oauthflows.d.ts.map +1 -1
- package/dist/schemas/v3.2/strict/openapi-document.d.ts +1439 -141
- package/dist/schemas/v3.2/strict/openapi-document.d.ts.map +1 -1
- package/dist/schemas/v3.2/strict/openapi-document.js +2 -1
- package/dist/schemas/v3.2/strict/security-scheme.d.ts +29 -6
- package/dist/schemas/v3.2/strict/security-scheme.d.ts.map +1 -1
- package/dist/schemas/v3.2/strict/security-scheme.js +16 -3
- package/dist/schemas/workspace-specification/index.d.ts +1 -1
- package/dist/schemas/workspace.d.ts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +23 -27
- package/package.json +8 -8
package/dist/server.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import fs from 'node:fs/promises';
|
|
2
1
|
import { cwd } from 'node:process';
|
|
3
2
|
import { upgrade as upgradeAsyncApi } from '@scalar/asyncapi-upgrader';
|
|
3
|
+
import { isHttpMethod } from '@scalar/helpers/http/is-http-method';
|
|
4
4
|
import { parseJsonPointerSegments } from '@scalar/helpers/json/parse-json-pointer-segments';
|
|
5
5
|
import { getValueAtPath } from '@scalar/helpers/object/get-value-at-path';
|
|
6
6
|
import { preventPollution } from '@scalar/helpers/object/prevent-pollution';
|
|
7
7
|
import { extensions as bundleExtensions } from '@scalar/json-magic/bundle';
|
|
8
8
|
import { fetchUrls, readFiles } from '@scalar/json-magic/bundle/plugins/node';
|
|
9
9
|
import { escapeJsonPointer } from '@scalar/json-magic/helpers/escape-json-pointer';
|
|
10
|
+
import { unescapeJsonPointer } from '@scalar/json-magic/helpers/unescape-json-pointer';
|
|
10
11
|
import { createMagicProxy, getRaw } from '@scalar/json-magic/magic-proxy';
|
|
11
12
|
import { upgrade } from '@scalar/openapi-upgrader';
|
|
12
13
|
import { asyncApiObjectSchema } from '@scalar/schemas/asyncapi/3.1';
|
|
13
14
|
import { coerce } from '@scalar/validation';
|
|
15
|
+
import { createChunkWriter } from './helpers/create-chunk-writer.js';
|
|
14
16
|
import { deepClone } from './helpers/deep-clone.js';
|
|
17
|
+
import { encodeChunkName } from './helpers/encode-chunk-name.js';
|
|
15
18
|
import { forEachPathItemOperation, getResolvedPathItem } from './helpers/for-each-path-item-operation.js';
|
|
16
19
|
import { keyOf } from './helpers/general.js';
|
|
17
20
|
import { getResolvedRef } from './helpers/get-resolved-ref.js';
|
|
@@ -20,10 +23,9 @@ import { createNavigation, traverseAsyncApiDocument } from './navigation/index.j
|
|
|
20
23
|
import { extensions } from './schemas/extensions.js';
|
|
21
24
|
import { isAsyncApiDocument } from './schemas/type-guards.js';
|
|
22
25
|
import { coerceValue } from './schemas/typebox-coerce.js';
|
|
23
|
-
import { OpenAPIDocumentSchema, } from './schemas/v3.
|
|
26
|
+
import { OpenAPIDocumentSchema, } from './schemas/v3.2/strict/openapi-document.js';
|
|
24
27
|
const DEFAULT_ASSETS_FOLDER = 'assets';
|
|
25
28
|
export const WORKSPACE_FILE_NAME = 'scalar-workspace.json';
|
|
26
|
-
const httpMethods = new Set(['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace']);
|
|
27
29
|
/**
|
|
28
30
|
* Wraps a document so local `$ref`s resolve while the store inspects it.
|
|
29
31
|
*
|
|
@@ -100,11 +102,14 @@ const preserveBundledExternals = (source, target) => {
|
|
|
100
102
|
*/
|
|
101
103
|
export function filterHttpMethodsOnly(paths) {
|
|
102
104
|
const result = {};
|
|
103
|
-
// Todo: skip extension properties
|
|
104
105
|
for (const [path, pathItemRef] of Object.entries(paths)) {
|
|
106
|
+
// Paths Object extensions can contain objects that resemble HTTP operations.
|
|
107
|
+
if (path.startsWith('x-')) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
105
110
|
const filteredMethods = {};
|
|
106
111
|
forEachPathItemOperation(pathItemRef, (method, operation) => {
|
|
107
|
-
if (
|
|
112
|
+
if (isHttpMethod(method)) {
|
|
108
113
|
// Unwrapped because the caller hands us a resolved document. A magic proxy enumerates a
|
|
109
114
|
// virtual `$ref-value`, so storing one would inline every referenced component beside its
|
|
110
115
|
// `$ref` when the chunk is written — and a self-referential schema would never finish
|
|
@@ -153,10 +158,7 @@ export function externalizeComponentReferences(document, meta) {
|
|
|
153
158
|
Object.keys(component).forEach((name) => {
|
|
154
159
|
const ref = meta.mode === 'ssr'
|
|
155
160
|
? `${meta.baseUrl}/${meta.name}/components/${type}/${name}#`
|
|
156
|
-
:
|
|
157
|
-
// by generateWorkspaceChunks, and so a key like `../../evil` cannot point outside the
|
|
158
|
-
// chunks directory.
|
|
159
|
-
`./chunks/${meta.name}/components/${escapeJsonPointer(type)}/${escapeJsonPointer(name)}.json#`;
|
|
161
|
+
: `./chunks/${encodeChunkName(meta.name)}/components/${encodeChunkName(type)}/${encodeChunkName(name)}.json#`;
|
|
160
162
|
result[type][name] = { '$ref': ref, $global: true };
|
|
161
163
|
});
|
|
162
164
|
});
|
|
@@ -179,10 +181,10 @@ export function externalizePathReferences(document, meta) {
|
|
|
179
181
|
result[path] = {};
|
|
180
182
|
const escapedPath = escapeJsonPointer(path);
|
|
181
183
|
keyOf(pathItemRecord).forEach((type) => {
|
|
182
|
-
if (
|
|
184
|
+
if (isHttpMethod(type)) {
|
|
183
185
|
const ref = meta.mode === 'ssr'
|
|
184
186
|
? `${meta.baseUrl}/${meta.name}/operations/${escapedPath}/${type}#`
|
|
185
|
-
: `./chunks/${meta.name}/operations/${
|
|
187
|
+
: `./chunks/${encodeChunkName(meta.name)}/operations/${encodeChunkName(path)}/${type}.json#`;
|
|
186
188
|
result[path][type] = { '$ref': ref, $global: true };
|
|
187
189
|
}
|
|
188
190
|
else if (type !== '$ref' && type !== '$ref-value') {
|
|
@@ -415,32 +417,26 @@ export async function createServerWorkspaceStore(workspaceProps) {
|
|
|
415
417
|
}
|
|
416
418
|
// Write the workspace document
|
|
417
419
|
const basePath = `${cwd()}/${workspaceProps.directory ?? DEFAULT_ASSETS_FOLDER}`;
|
|
418
|
-
await
|
|
419
|
-
|
|
420
|
-
await fs.writeFile(`${basePath}/${WORKSPACE_FILE_NAME}`, JSON.stringify(workspace));
|
|
421
|
-
// Write the chunks
|
|
420
|
+
const writeChunk = await createChunkWriter(basePath);
|
|
421
|
+
await writeChunk([WORKSPACE_FILE_NAME], workspace);
|
|
422
422
|
for (const [name, { components, operations }] of Object.entries(assets)) {
|
|
423
|
-
// Write the components chunks
|
|
424
423
|
if (components) {
|
|
425
424
|
for (const [type, component] of Object.entries(components)) {
|
|
426
|
-
// Escape the component type and key the same way operation paths are escaped. Component
|
|
427
|
-
// keys come from the OpenAPI document, so a key like `../../evil` would otherwise let a
|
|
428
|
-
// document write chunk files outside the assets directory. escapeJsonPointer turns every
|
|
429
|
-
// `/` into `~1`, collapsing the value into a single safe path segment.
|
|
430
|
-
const componentPath = `${basePath}/chunks/${name}/components/${escapeJsonPointer(type)}`;
|
|
431
|
-
await fs.mkdir(componentPath, { recursive: true });
|
|
432
425
|
for (const [key, value] of Object.entries(component)) {
|
|
433
|
-
await
|
|
426
|
+
await writeChunk(['chunks', encodeChunkName(name), 'components', encodeChunkName(type), `${encodeChunkName(key)}.json`], value);
|
|
434
427
|
}
|
|
435
428
|
}
|
|
436
429
|
}
|
|
437
|
-
// Write the operations chunks
|
|
438
430
|
if (operations) {
|
|
439
431
|
for (const [path, methods] of Object.entries(operations)) {
|
|
440
|
-
const operationPath = `${basePath}/chunks/${name}/operations/${path}`;
|
|
441
|
-
await fs.mkdir(operationPath, { recursive: true });
|
|
442
432
|
for (const [method, operation] of Object.entries(methods)) {
|
|
443
|
-
await
|
|
433
|
+
await writeChunk([
|
|
434
|
+
'chunks',
|
|
435
|
+
encodeChunkName(name),
|
|
436
|
+
'operations',
|
|
437
|
+
encodeChunkName(unescapeJsonPointer(path)),
|
|
438
|
+
`${encodeChunkName(method)}.json`,
|
|
439
|
+
], operation);
|
|
444
440
|
}
|
|
445
441
|
}
|
|
446
442
|
}
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"openapi",
|
|
17
17
|
"scalar"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.
|
|
19
|
+
"version": "0.61.0",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=22"
|
|
22
22
|
},
|
|
@@ -148,14 +148,14 @@
|
|
|
148
148
|
"type-fest": "^5.8.0",
|
|
149
149
|
"vue": "^3.5.40",
|
|
150
150
|
"yaml": "^2.9.0",
|
|
151
|
-
"@scalar/
|
|
152
|
-
"@scalar/
|
|
153
|
-
"@scalar/
|
|
154
|
-
"@scalar/
|
|
155
|
-
"@scalar/
|
|
156
|
-
"@scalar/
|
|
151
|
+
"@scalar/helpers": "0.12.0",
|
|
152
|
+
"@scalar/asyncapi-upgrader": "0.1.10",
|
|
153
|
+
"@scalar/openapi-upgrader": "0.2.16",
|
|
154
|
+
"@scalar/schemas": "0.10.0",
|
|
155
|
+
"@scalar/snippetz": "0.9.31",
|
|
156
|
+
"@scalar/types": "0.20.0",
|
|
157
157
|
"@scalar/validation": "0.6.3",
|
|
158
|
-
"@scalar/
|
|
158
|
+
"@scalar/json-magic": "0.13.5"
|
|
159
159
|
},
|
|
160
160
|
"devDependencies": {
|
|
161
161
|
"@google-cloud/storage": "7.21.0",
|