@scalar/workspace-store 0.54.4 → 0.55.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 +22 -0
- package/dist/channel-example/build-connection-url.d.ts +7 -0
- package/dist/channel-example/build-connection-url.d.ts.map +1 -1
- package/dist/channel-example/build-connection-url.js +10 -0
- package/dist/channel-example/get-async-api-protocols.d.ts +86 -0
- package/dist/channel-example/get-async-api-protocols.d.ts.map +1 -0
- package/dist/channel-example/get-async-api-protocols.js +110 -0
- package/dist/channel-example/index.d.ts +2 -0
- package/dist/channel-example/index.d.ts.map +1 -1
- package/dist/channel-example/index.js +1 -0
- package/dist/channel-example/servers.d.ts +7 -0
- package/dist/channel-example/servers.d.ts.map +1 -1
- package/dist/channel-example/servers.js +1 -1
- package/dist/entities/auth/schema.d.ts +260 -235
- package/dist/entities/auth/schema.d.ts.map +1 -1
- package/dist/events/definitions/workspace.d.ts +8 -0
- package/dist/events/definitions/workspace.d.ts.map +1 -1
- package/dist/helpers/get-first-server.d.ts +9 -0
- package/dist/helpers/get-first-server.d.ts.map +1 -0
- package/dist/helpers/get-first-server.js +30 -0
- package/dist/mutators/index.d.ts +1 -0
- package/dist/mutators/index.d.ts.map +1 -1
- package/dist/mutators/workspace.d.ts +8 -0
- package/dist/mutators/workspace.d.ts.map +1 -1
- package/dist/mutators/workspace.js +13 -0
- package/dist/request-example/builder/header/de-serialize-parameter.d.ts +14 -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 +10 -4
- package/dist/request-example/builder/header/is-param-disabled.d.ts +2 -1
- package/dist/request-example/builder/header/is-param-disabled.d.ts.map +1 -1
- package/dist/request-example/builder/header/is-param-disabled.js +6 -1
- package/dist/request-example/builder/header/serialize-parameter.d.ts +1 -0
- package/dist/request-example/builder/header/serialize-parameter.d.ts.map +1 -1
- package/dist/request-example/builder/header/serialize-parameter.js +22 -9
- package/dist/request-example/builder/index.d.ts +2 -1
- package/dist/request-example/builder/index.d.ts.map +1 -1
- package/dist/request-example/builder/index.js +2 -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/schemas/extensions/document/x-scalar-links.d.ts +25 -0
- package/dist/schemas/extensions/document/x-scalar-links.d.ts.map +1 -0
- package/dist/schemas/extensions/document/x-scalar-links.js +24 -0
- package/dist/schemas/extensions.d.ts +1 -0
- package/dist/schemas/extensions.d.ts.map +1 -1
- package/dist/schemas/extensions.js +1 -0
- package/dist/schemas/reference-config/index.d.ts +52 -47
- package/dist/schemas/reference-config/index.d.ts.map +1 -1
- package/dist/schemas/reference-config/settings.d.ts +52 -47
- package/dist/schemas/reference-config/settings.d.ts.map +1 -1
- package/dist/schemas/v3.1/openapi/index.d.ts +5 -0
- package/dist/schemas/v3.1/openapi/index.d.ts.map +1 -1
- package/dist/schemas/v3.1/openapi/index.js +2 -0
- package/dist/schemas/v3.1/strict/info.d.ts +7 -1
- package/dist/schemas/v3.1/strict/info.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/info.js +2 -1
- package/dist/schemas/v3.1/strict/openapi-document.d.ts +1820 -1645
- package/dist/schemas/v3.1/strict/openapi-document.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/schema.d.ts +48 -48
- package/dist/schemas/v3.1/strict/schema.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/schema.js +16 -1
- package/dist/schemas/workspace-specification/index.d.ts +1 -0
- package/dist/schemas/workspace-specification/index.d.ts.map +1 -1
- package/dist/schemas/workspace.d.ts +2 -0
- package/dist/schemas/workspace.d.ts.map +1 -1
- package/dist/schemas/workspace.js +3 -0
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @scalar/workspace-store
|
|
2
2
|
|
|
3
|
+
## 0.55.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#9568](https://github.com/scalar/scalar/pull/9568): Add AsyncAPI protocol and server pickers to the sidebar (like the multi-document picker) that filter the navigation down to the operations reachable over the selected protocol/server
|
|
8
|
+
- [#8519](https://github.com/scalar/scalar/pull/8519): refactor: extract the code example block into `@scalar/blocks/code-example`. `api-client`, `api-client-react`, and `api-reference` now import `CodeExample`, `findClient`, `generateClientOptions`, and the related helpers from the new package. `workspace-store` exports `isParamDisabled` with an optional `defaultDisabled` argument.
|
|
9
|
+
|
|
10
|
+
**Breaking (`@scalar/api-client`):** the `@scalar/api-client/blocks/operation-code-sample` and `@scalar/api-client/v2/blocks/operation-code-sample` export paths have been removed. Import from `@scalar/blocks/code-example` instead, and use the renamed `CodeExample` / `CodeExampleProps` (previously `OperationCodeSample` / `OperationCodeSampleProps`).
|
|
11
|
+
|
|
12
|
+
- [#9543](https://github.com/scalar/scalar/pull/9543): Add the `x-scalar-links` OpenAPI extension to render extra named links (like a privacy policy or imprint) next to the contact, license and terms of service links in the introduction.
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#9583](https://github.com/scalar/scalar/pull/9583): Serialize array values inside `deepObject` query parameters with the trailing bracket convention (`filter[ids][]=1&filter[ids][]=2`) instead of collapsing them into a single comma-joined value
|
|
17
|
+
- [#9548](https://github.com/scalar/scalar/pull/9548): Keep request and response example pickers in sync across operations. Selecting an example (e.g. "Use case 1") now selects the example with the same key on every other operation that defines it, mirroring how the programming-language selection already syncs. Operations that do not have a matching example keep their current selection.
|
|
18
|
+
|
|
19
|
+
## 0.54.5
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- [#9549](https://github.com/scalar/scalar/pull/9549): Preserve `$ref` reference objects when coercing schemas, so unresolved chunk references (from the server-side workspace store) survive instead of being dropped. This is a prerequisite for resolving lazily-loaded chunks transitively (an operation chunk can now reference component chunks).
|
|
24
|
+
|
|
3
25
|
## 0.54.4
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
|
@@ -14,6 +14,13 @@ export type BuildConnectionUrlInput = {
|
|
|
14
14
|
* Extracts default values of variables defined on an AsyncAPI Server Object.
|
|
15
15
|
*/
|
|
16
16
|
export declare const getAsyncApiServerVariables: (server: AsyncApiServerObject | null) => Record<string, string>;
|
|
17
|
+
/**
|
|
18
|
+
* Normalizes an AsyncAPI `protocol` for comparison: trimmed and lowercased.
|
|
19
|
+
*
|
|
20
|
+
* Returns `undefined` when the protocol is missing or blank, so callers can treat
|
|
21
|
+
* "no protocol" distinctly instead of comparing against an empty string.
|
|
22
|
+
*/
|
|
23
|
+
export declare const normalizeProtocol: (protocol: string | undefined) => string | undefined;
|
|
17
24
|
/** Maps AsyncAPI `server.protocol` to a URL scheme (MVP: ws and wss). */
|
|
18
25
|
export declare const getUrlSchemeFromProtocol: (protocol: string) => string;
|
|
19
26
|
export declare const isWebSocketProtocol: (protocol: string) => protocol is AsyncApiWebSocketProtocol;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-connection-url.d.ts","sourceRoot":"","sources":["../../src/channel-example/build-connection-url.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,4BAA4B,CAAA;AAInC,2FAA2F;AAC3F,eAAO,MAAM,4BAA4B,wBAAyB,CAAA;AAElE,MAAM,MAAM,yBAAyB,GAAG,CAAC,OAAO,4BAA4B,CAAC,CAAC,MAAM,CAAC,CAAA;AAErF,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,EAAE,oBAAoB,CAAA;IAC5B,OAAO,EAAE,qBAAqB,CAAA;IAC9B,SAAS,CAAC,EAAE,uBAAuB,GAAG,IAAI,CAAA;IAC1C,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACvC,eAAe,CAAC,EAAE,MAAM,CAAC,MA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AC,KACvC,eAoBF,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,GAAI,wFAOhC,uBAAuB,KAAG,MAkB5B,CAAA"}
|
|
@@ -33,6 +33,16 @@ const substituteTemplate = (template, options) => {
|
|
|
33
33
|
}
|
|
34
34
|
return result;
|
|
35
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* Normalizes an AsyncAPI `protocol` for comparison: trimmed and lowercased.
|
|
38
|
+
*
|
|
39
|
+
* Returns `undefined` when the protocol is missing or blank, so callers can treat
|
|
40
|
+
* "no protocol" distinctly instead of comparing against an empty string.
|
|
41
|
+
*/
|
|
42
|
+
export const normalizeProtocol = (protocol) => {
|
|
43
|
+
const normalized = protocol?.trim().toLowerCase();
|
|
44
|
+
return normalized ? normalized : undefined;
|
|
45
|
+
};
|
|
36
46
|
/** Maps AsyncAPI `server.protocol` to a URL scheme (MVP: ws and wss). */
|
|
37
47
|
export const getUrlSchemeFromProtocol = (protocol) => protocol.trim().toLowerCase();
|
|
38
48
|
export const isWebSocketProtocol = (protocol) => ASYNCAPI_WEBSOCKET_PROTOCOLS.includes(protocol.trim().toLowerCase());
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { AsyncApiDocument, AsyncApiOperationObject } from '@scalar/types/asyncapi/3.1';
|
|
2
|
+
/** Sentinel used by the protocol and server pickers to mean "don't filter". */
|
|
3
|
+
export declare const ALL: "all";
|
|
4
|
+
/** A single protocol option for the picker (e.g. `{ id: 'mqtt', label: 'MQTT' }`). */
|
|
5
|
+
export type AsyncApiProtocolOption = {
|
|
6
|
+
/** The normalized protocol id (lowercase), or {@link ALL}. */
|
|
7
|
+
id: string;
|
|
8
|
+
/** Human-friendly label shown in the dropdown. */
|
|
9
|
+
label: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Builds the protocol options for the picker from a document's servers.
|
|
13
|
+
*
|
|
14
|
+
* Always prepends an "All protocols" entry so the picker can clear the filter,
|
|
15
|
+
* matching how the document picker always offers every document. Protocols are
|
|
16
|
+
* de-duplicated and sorted alphabetically for a stable order.
|
|
17
|
+
*/
|
|
18
|
+
export declare const getAsyncApiProtocols: (document: AsyncApiDocument) => AsyncApiProtocolOption[];
|
|
19
|
+
/** A single server option for the picker (e.g. `{ id: 'mqtt-prod', label: 'mqtt-prod (mqtt)' }`). */
|
|
20
|
+
export type AsyncApiServerOption = {
|
|
21
|
+
/** The server name (its key in `document.servers`), or {@link ALL}. */
|
|
22
|
+
id: string;
|
|
23
|
+
/** Human-friendly label: the server name, suffixed with its protocol when known. */
|
|
24
|
+
label: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Builds the server options for the picker from a document's servers.
|
|
28
|
+
*
|
|
29
|
+
* Like {@link getAsyncApiProtocols}, always prepends an "All servers" entry so the
|
|
30
|
+
* filter can be cleared. Each option is labelled with the server name and its
|
|
31
|
+
* protocol so the picker reads as `mqtt-prod (mqtt)`.
|
|
32
|
+
*/
|
|
33
|
+
export declare const getAsyncApiServerOptions: (document: AsyncApiDocument) => AsyncApiServerOption[];
|
|
34
|
+
/**
|
|
35
|
+
* Document-level lookups the per-operation reachability check needs.
|
|
36
|
+
*
|
|
37
|
+
* Building this once per filter pass (instead of recomputing it for every operation)
|
|
38
|
+
* keeps sidebar filtering at O(operations + servers) rather than O(operations × servers).
|
|
39
|
+
*/
|
|
40
|
+
export type AsyncApiReachabilityContext = {
|
|
41
|
+
/** Normalized protocol of every named server, keyed by server name. */
|
|
42
|
+
serverProtocols: Map<string, string>;
|
|
43
|
+
/** Every server name declared on the document. */
|
|
44
|
+
allServerNames: Set<string>;
|
|
45
|
+
};
|
|
46
|
+
/** Precomputes the document-level data shared across every operation in a filter pass. */
|
|
47
|
+
export declare const createReachabilityContext: (document: AsyncApiDocument) => AsyncApiReachabilityContext;
|
|
48
|
+
/** The servers (and the protocols they speak) a single operation is reachable through. */
|
|
49
|
+
export type OperationReachability = {
|
|
50
|
+
/** Server names the operation's channel can be reached through. */
|
|
51
|
+
serverNames: Set<string>;
|
|
52
|
+
/** Protocols those servers use. */
|
|
53
|
+
protocols: Set<string>;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Resolves the servers and protocols a single operation is reachable over.
|
|
57
|
+
*
|
|
58
|
+
* Resolves the operation's channel once, then intersects the channel's servers
|
|
59
|
+
* (or all servers, when the channel pins none) with the document's servers. The
|
|
60
|
+
* shared {@link AsyncApiReachabilityContext} is built once per filter pass; a fresh
|
|
61
|
+
* one is created when called standalone.
|
|
62
|
+
*/
|
|
63
|
+
export declare const getOperationReachability: (document: AsyncApiDocument, operation: AsyncApiOperationObject, context?: AsyncApiReachabilityContext) => OperationReachability;
|
|
64
|
+
/**
|
|
65
|
+
* Returns the set of protocols an operation is reachable over.
|
|
66
|
+
*/
|
|
67
|
+
export declare const getOperationProtocols: (document: AsyncApiDocument, operation: AsyncApiOperationObject, context?: AsyncApiReachabilityContext) => Set<string>;
|
|
68
|
+
/**
|
|
69
|
+
* Returns the names of the servers an operation is reachable through.
|
|
70
|
+
*/
|
|
71
|
+
export declare const getOperationServerNames: (document: AsyncApiDocument, operation: AsyncApiOperationObject, context?: AsyncApiReachabilityContext) => Set<string>;
|
|
72
|
+
/**
|
|
73
|
+
* Whether an operation should be shown for the currently selected protocol.
|
|
74
|
+
*
|
|
75
|
+
* Selecting {@link ALL} (or nothing) matches every operation; otherwise the
|
|
76
|
+
* operation is kept only when one of its channel's servers uses that protocol.
|
|
77
|
+
*/
|
|
78
|
+
export declare const operationMatchesProtocol: (document: AsyncApiDocument, operation: AsyncApiOperationObject, protocol: string | undefined, context?: AsyncApiReachabilityContext) => boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Whether an operation should be shown for the currently selected server.
|
|
81
|
+
*
|
|
82
|
+
* Selecting {@link ALL} (or nothing) matches every operation; otherwise the
|
|
83
|
+
* operation is kept only when its channel is reachable through that server.
|
|
84
|
+
*/
|
|
85
|
+
export declare const operationMatchesServer: (document: AsyncApiDocument, operation: AsyncApiOperationObject, serverName: string | undefined, context?: AsyncApiReachabilityContext) => boolean;
|
|
86
|
+
//# sourceMappingURL=get-async-api-protocols.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-async-api-protocols.d.ts","sourceRoot":"","sources":["../../src/channel-example/get-async-api-protocols.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAA;AAQ3F,+EAA+E;AAC/E,eAAO,MAAM,GAAG,EAAG,KAAc,CAAA;AAEjC,sFAAsF;AACtF,MAAM,MAAM,sBAAsB,GAAG;IACnC,8DAA8D;IAC9D,EAAE,EAAE,MAAM,CAAA;IACV,kDAAkD;IAClD,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAmBD;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAAI,UAAU,gBAAgB,KAAG,sBAAsB,EAQvF,CAAA;AAED,qGAAqG;AACrG,MAAM,MAAM,oBAAoB,GAAG;IACjC,uEAAuE;IACvE,EAAE,EAAE,MAAM,CAAA;IACV,oFAAoF;IACpF,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,GAAI,UAAU,gBAAgB,KAAG,oBAAoB,EAOzF,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC,uEAAuE;IACvE,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACpC,kDAAkD;IAClD,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CAC5B,CAAA;AAED,0FAA0F;AAC1F,eAAO,MAAM,yBAAyB,GAAI,UAAU,gBAAgB,KAAG,2BAGrE,CAAA;AAEF,0FAA0F;AAC1F,MAAM,MAAM,qBAAqB,GAAG;IAClC,mEAAmE;IACnE,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACxB,mCAAmC;IACnC,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CACvB,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,GACnC,UAAU,gBAAgB,EAC1B,WAAW,uBAAuB,EAClC,UAAS,2BAAiE,KACzE,qBAiBF,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAChC,UAAU,gBAAgB,EAC1B,WAAW,uBAAuB,EAClC,UAAU,2BAA2B,KACpC,GAAG,CAAC,MAAM,CAAqE,CAAA;AAElF;;GAEG;AACH,eAAO,MAAM,uBAAuB,GAClC,UAAU,gBAAgB,EAC1B,WAAW,uBAAuB,EAClC,UAAU,2BAA2B,KACpC,GAAG,CAAC,MAAM,CAAuE,CAAA;AAEpF;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GACnC,UAAU,gBAAgB,EAC1B,WAAW,uBAAuB,EAClC,UAAU,MAAM,GAAG,SAAS,EAC5B,UAAU,2BAA2B,KACpC,OAMF,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,GACjC,UAAU,gBAAgB,EAC1B,WAAW,uBAAuB,EAClC,YAAY,MAAM,GAAG,SAAS,EAC9B,UAAU,2BAA2B,KACpC,OAMF,CAAA"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { objectEntries } from '@scalar/helpers/object/object-entries';
|
|
2
|
+
import { objectKeys } from '@scalar/helpers/object/object-keys';
|
|
3
|
+
import { getResolvedRef } from '../helpers/get-resolved-ref.js';
|
|
4
|
+
import { normalizeProtocol } from './build-connection-url.js';
|
|
5
|
+
import { resolveOperationChannel } from './resolve-operation-channel.js';
|
|
6
|
+
import { getChannelServerNames } from './servers.js';
|
|
7
|
+
/** Sentinel used by the protocol and server pickers to mean "don't filter". */
|
|
8
|
+
export const ALL = 'all';
|
|
9
|
+
/**
|
|
10
|
+
* Returns the protocol of every named server, keyed by server name.
|
|
11
|
+
* References are resolved so a `$ref`-only server still contributes its protocol.
|
|
12
|
+
*/
|
|
13
|
+
const getServerProtocols = (document) => {
|
|
14
|
+
const protocols = new Map();
|
|
15
|
+
for (const [name, serverNode] of objectEntries(document.servers ?? {})) {
|
|
16
|
+
const protocol = normalizeProtocol(getResolvedRef(serverNode).protocol);
|
|
17
|
+
if (protocol) {
|
|
18
|
+
protocols.set(name, protocol);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return protocols;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Builds the protocol options for the picker from a document's servers.
|
|
25
|
+
*
|
|
26
|
+
* Always prepends an "All protocols" entry so the picker can clear the filter,
|
|
27
|
+
* matching how the document picker always offers every document. Protocols are
|
|
28
|
+
* de-duplicated and sorted alphabetically for a stable order.
|
|
29
|
+
*/
|
|
30
|
+
export const getAsyncApiProtocols = (document) => {
|
|
31
|
+
const unique = new Set(getServerProtocols(document).values());
|
|
32
|
+
const options = [...unique]
|
|
33
|
+
.sort((a, b) => a.localeCompare(b))
|
|
34
|
+
.map((protocol) => ({ id: protocol, label: protocol.toUpperCase() }));
|
|
35
|
+
return [{ id: ALL, label: 'All protocols' }, ...options];
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Builds the server options for the picker from a document's servers.
|
|
39
|
+
*
|
|
40
|
+
* Like {@link getAsyncApiProtocols}, always prepends an "All servers" entry so the
|
|
41
|
+
* filter can be cleared. Each option is labelled with the server name and its
|
|
42
|
+
* protocol so the picker reads as `mqtt-prod (mqtt)`.
|
|
43
|
+
*/
|
|
44
|
+
export const getAsyncApiServerOptions = (document) => {
|
|
45
|
+
const options = objectEntries(document.servers ?? {}).map(([name, serverNode]) => {
|
|
46
|
+
const protocol = normalizeProtocol(getResolvedRef(serverNode).protocol);
|
|
47
|
+
return { id: name, label: protocol ? `${name} (${protocol})` : name };
|
|
48
|
+
});
|
|
49
|
+
return [{ id: ALL, label: 'All servers' }, ...options];
|
|
50
|
+
};
|
|
51
|
+
/** Precomputes the document-level data shared across every operation in a filter pass. */
|
|
52
|
+
export const createReachabilityContext = (document) => ({
|
|
53
|
+
serverProtocols: getServerProtocols(document),
|
|
54
|
+
allServerNames: new Set(objectKeys(document.servers ?? {})),
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* Resolves the servers and protocols a single operation is reachable over.
|
|
58
|
+
*
|
|
59
|
+
* Resolves the operation's channel once, then intersects the channel's servers
|
|
60
|
+
* (or all servers, when the channel pins none) with the document's servers. The
|
|
61
|
+
* shared {@link AsyncApiReachabilityContext} is built once per filter pass; a fresh
|
|
62
|
+
* one is created when called standalone.
|
|
63
|
+
*/
|
|
64
|
+
export const getOperationReachability = (document, operation, context = createReachabilityContext(document)) => {
|
|
65
|
+
const channel = resolveOperationChannel(document, operation)?.channel ?? null;
|
|
66
|
+
const channelServerNames = getChannelServerNames(document, channel);
|
|
67
|
+
// A channel without declared servers is reachable on every server.
|
|
68
|
+
const serverNames = channelServerNames
|
|
69
|
+
? new Set([...channelServerNames].filter((name) => context.allServerNames.has(name)))
|
|
70
|
+
: new Set(context.allServerNames);
|
|
71
|
+
const protocols = new Set();
|
|
72
|
+
for (const [name, protocol] of context.serverProtocols) {
|
|
73
|
+
if (serverNames.has(name)) {
|
|
74
|
+
protocols.add(protocol);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return { serverNames, protocols };
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Returns the set of protocols an operation is reachable over.
|
|
81
|
+
*/
|
|
82
|
+
export const getOperationProtocols = (document, operation, context) => getOperationReachability(document, operation, context).protocols;
|
|
83
|
+
/**
|
|
84
|
+
* Returns the names of the servers an operation is reachable through.
|
|
85
|
+
*/
|
|
86
|
+
export const getOperationServerNames = (document, operation, context) => getOperationReachability(document, operation, context).serverNames;
|
|
87
|
+
/**
|
|
88
|
+
* Whether an operation should be shown for the currently selected protocol.
|
|
89
|
+
*
|
|
90
|
+
* Selecting {@link ALL} (or nothing) matches every operation; otherwise the
|
|
91
|
+
* operation is kept only when one of its channel's servers uses that protocol.
|
|
92
|
+
*/
|
|
93
|
+
export const operationMatchesProtocol = (document, operation, protocol, context) => {
|
|
94
|
+
if (!protocol || protocol === ALL) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
return getOperationProtocols(document, operation, context).has(protocol);
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Whether an operation should be shown for the currently selected server.
|
|
101
|
+
*
|
|
102
|
+
* Selecting {@link ALL} (or nothing) matches every operation; otherwise the
|
|
103
|
+
* operation is kept only when its channel is reachable through that server.
|
|
104
|
+
*/
|
|
105
|
+
export const operationMatchesServer = (document, operation, serverName, context) => {
|
|
106
|
+
if (!serverName || serverName === ALL) {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
return getOperationServerNames(document, operation, context).has(serverName);
|
|
110
|
+
};
|
|
@@ -2,6 +2,8 @@ export type { AsyncApiWebSocketProtocol, BuildConnectionUrlInput } from './build
|
|
|
2
2
|
export { ASYNCAPI_WEBSOCKET_PROTOCOLS, buildAsyncApiServerBaseUrl, buildConnectionUrl, buildWsQueryParams, getAsyncApiServerVariables, getUrlSchemeFromProtocol, isWebSocketProtocol, mergeWsBindings, } from './build-connection-url.js';
|
|
3
3
|
export type { ChannelMessageEntry } from './get-all-channel-messages.js';
|
|
4
4
|
export { getAllChannelMessages } from './get-all-channel-messages.js';
|
|
5
|
+
export type { AsyncApiProtocolOption, AsyncApiReachabilityContext, AsyncApiServerOption, OperationReachability, } from './get-async-api-protocols.js';
|
|
6
|
+
export { ALL, createReachabilityContext, getAsyncApiProtocols, getAsyncApiServerOptions, getOperationProtocols, getOperationReachability, getOperationServerNames, operationMatchesProtocol, operationMatchesServer, } from './get-async-api-protocols.js';
|
|
5
7
|
export { getAsyncApiSecurityRequirements } from './get-asyncapi-security-requirements.js';
|
|
6
8
|
export { getChannelConnectionContext } from './get-channel-connection-context.js';
|
|
7
9
|
export { getChannelConnectionSecurityRequirements } from './get-channel-connection-security.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/channel-example/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AAChG,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,kBAAkB,EAClB,kBAAkB,EAClB,0BAA0B,EAC1B,wBAAwB,EACxB,mBAAmB,EACnB,eAAe,GAChB,MAAM,wBAAwB,CAAA;AAC/B,YAAY,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAA;AACtF,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAA;AAC9E,OAAO,EAAE,wCAAwC,EAAE,MAAM,mCAAmC,CAAA;AAC5F,YAAY,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAC/D,YAAY,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAA;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAC/D,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,YAAY,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAA;AAC3E,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAA;AACrE,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAA;AAC5E,YAAY,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;AAC/E,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;AACzE,YAAY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,MAAM,6BAA6B,CAAA;AAC3E,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAA;AACrE,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAA;AAC5E,YAAY,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;AAC/E,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;AACzE,YAAY,EAAE,6BAA6B,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { ASYNCAPI_WEBSOCKET_PROTOCOLS, buildAsyncApiServerBaseUrl, buildConnectionUrl, buildWsQueryParams, getAsyncApiServerVariables, getUrlSchemeFromProtocol, isWebSocketProtocol, mergeWsBindings, } from './build-connection-url.js';
|
|
2
2
|
export { getAllChannelMessages } from './get-all-channel-messages.js';
|
|
3
|
+
export { ALL, createReachabilityContext, getAsyncApiProtocols, getAsyncApiServerOptions, getOperationProtocols, getOperationReachability, getOperationServerNames, operationMatchesProtocol, operationMatchesServer, } from './get-async-api-protocols.js';
|
|
3
4
|
export { getAsyncApiSecurityRequirements } from './get-asyncapi-security-requirements.js';
|
|
4
5
|
export { getChannelConnectionContext } from './get-channel-connection-context.js';
|
|
5
6
|
export { getChannelConnectionSecurityRequirements } from './get-channel-connection-security.js';
|
|
@@ -25,6 +25,13 @@ export type AsyncApiServerEntry = {
|
|
|
25
25
|
/** Whether this server uses a WebSocket protocol (`ws` / `wss`). */
|
|
26
26
|
isWebSocket: boolean;
|
|
27
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* Collects the names of `document.servers` entries that the channel is restricted to.
|
|
30
|
+
*
|
|
31
|
+
* Returns `undefined` when the channel does not declare `servers`, signaling that every
|
|
32
|
+
* top-level server is allowed.
|
|
33
|
+
*/
|
|
34
|
+
export declare const getChannelServerNames: (document: AsyncApiDocument, channel: AsyncApiChannelObject | null) => Set<string> | undefined;
|
|
28
35
|
/**
|
|
29
36
|
* Returns a normalized list of AsyncAPI servers with computed base `url` and optional `connectionUrl`.
|
|
30
37
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"servers.d.ts","sourceRoot":"","sources":["../../src/channel-example/servers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,4BAA4B,CAAA;AAEnC,OAAO,EACL,KAAK,uBAAuB,EAI7B,MAAM,wCAAwC,CAAA;AAI/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAE5D,MAAM,MAAM,yBAAyB,GAAG;IACtC,OAAO,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAAA;IACtC,SAAS,CAAC,EAAE,uBAAuB,GAAG,IAAI,CAAA;IAC1C,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACvC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxC,oBAAoB,CAAC,EAAE,uBAAuB,CAAC,sBAAsB,CAAC,CAAA;IACtE,kFAAkF;IAClF,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,oBAAoB,CAAA;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,uEAAuE;IACvE,GAAG,EAAE,MAAM,CAAA;IACX,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,oEAAoE;IACpE,WAAW,EAAE,OAAO,CAAA;CACrB,CAAA;
|
|
1
|
+
{"version":3,"file":"servers.d.ts","sour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GAC7B,UAAU,gBAAgB,EAC1B,UAAS,yBAA8B,KACtC,mBAAmB,EA8CrB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,yBAAyB,GACpC,UAAU,iBAAiB,GAAG,IAAI,EAClC,SAAS,mBAAmB,EAAE,EAC9B,aAAa,uBAAuB,GAAG,IAAI,KAC1C,mBAAmB,GAAG,IAYxB,CAAA"}
|
|
@@ -11,7 +11,7 @@ const getServerNameFromRef = (ref) => getNameFromRef(ref, ['servers']);
|
|
|
11
11
|
* Returns `undefined` when the channel does not declare `servers`, signaling that every
|
|
12
12
|
* top-level server is allowed.
|
|
13
13
|
*/
|
|
14
|
-
const getChannelServerNames = (document, channel) => {
|
|
14
|
+
export const getChannelServerNames = (document, channel) => {
|
|
15
15
|
if (!channel?.servers) {
|
|
16
16
|
return undefined;
|
|
17
17
|
}
|