@lostgradient/backchannel 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +62 -2
- package/dist/access-policy-metadata.d.ts +92 -0
- package/dist/access-policy-metadata.js +87 -0
- package/dist/asyncapi-channels.d.ts +46 -0
- package/dist/asyncapi-channels.js +399 -0
- package/dist/asyncapi.d.ts +40 -0
- package/dist/asyncapi.js +165 -0
- package/dist/authentication/api-key.d.ts +4 -0
- package/dist/authentication/api-key.js +114 -0
- package/dist/authentication/audit.d.ts +115 -0
- package/dist/authentication/audit.js +75 -0
- package/dist/authentication/credential-verifiers.d.ts +60 -0
- package/dist/authentication/credential-verifiers.js +102 -0
- package/dist/authentication/crypto.d.ts +7 -0
- package/dist/authentication/crypto.js +140 -0
- package/dist/authentication/index.d.ts +80 -0
- package/dist/authentication/index.js +212 -0
- package/dist/authentication/rate-limiter.d.ts +133 -0
- package/dist/authentication/rate-limiter.js +124 -0
- package/dist/authentication/redaction.d.ts +72 -0
- package/dist/authentication/redaction.js +118 -0
- package/dist/authentication/rotating-api-key-store.d.ts +127 -0
- package/dist/authentication/rotating-api-key-store.js +126 -0
- package/dist/authentication/types.d.ts +337 -0
- package/dist/authentication/types.js +26 -0
- package/dist/authentication.d.ts +1 -0
- package/dist/authentication.js +1 -0
- package/dist/authorization-scope.d.ts +109 -0
- package/dist/authorization-scope.js +144 -0
- package/dist/authorization.d.ts +55 -0
- package/dist/authorization.js +134 -0
- package/dist/bind-feed-lifetime.d.ts +45 -0
- package/dist/bind-feed-lifetime.js +55 -0
- package/dist/byte-arrays.d.ts +5 -0
- package/dist/byte-arrays.js +9 -0
- package/dist/client/catalog-client.d.ts +285 -0
- package/dist/client/catalog-client.js +74 -0
- package/dist/client/in-process-transport.d.ts +19 -0
- package/dist/client/in-process-transport.js +136 -0
- package/dist/client/index.d.ts +14 -0
- package/dist/client/index.js +14 -0
- package/dist/client/json-rpc-http-transport.d.ts +118 -0
- package/dist/client/json-rpc-http-transport.js +127 -0
- package/dist/client/server-sent-event-parser.d.ts +55 -0
- package/dist/client/server-sent-event-parser.js +78 -0
- package/dist/client/sse-subscription-transport.d.ts +72 -0
- package/dist/client/sse-subscription-transport.js +224 -0
- package/dist/client/subscription-client.d.ts +122 -0
- package/dist/client/subscription-client.js +28 -0
- package/dist/connection-lease.d.ts +10 -0
- package/dist/connection-lease.js +8 -0
- package/dist/discovery-filter.d.ts +13 -0
- package/dist/discovery-filter.js +16 -0
- package/dist/discovery-info.d.ts +94 -0
- package/dist/discovery-info.js +38 -0
- package/dist/event-selector.d.ts +7 -0
- package/dist/event-selector.js +7 -0
- package/dist/fault-code.d.ts +84 -0
- package/dist/fault-code.js +114 -0
- package/dist/fault-remediation.d.ts +30 -0
- package/dist/fault-remediation.js +52 -0
- package/dist/fault-to-http.d.ts +11 -0
- package/dist/fault-to-http.js +13 -0
- package/dist/fault-to-json-rpc.d.ts +53 -0
- package/dist/fault-to-json-rpc.js +143 -0
- package/dist/fault-wire-safety.d.ts +45 -0
- package/dist/fault-wire-safety.js +72 -0
- package/dist/generator.d.ts +9 -0
- package/dist/generator.js +9 -0
- package/dist/handler/auth-context-principal.d.ts +37 -0
- package/dist/handler/auth-context-principal.js +67 -0
- package/dist/handler/authentication-responses.d.ts +23 -0
- package/dist/handler/authentication-responses.js +34 -0
- package/dist/handler/json-responses.d.ts +15 -0
- package/dist/handler/json-responses.js +32 -0
- package/dist/handler/operation-handler-authentication.d.ts +64 -0
- package/dist/handler/operation-handler-authentication.js +58 -0
- package/dist/handler/operation-handler-discovery.d.ts +29 -0
- package/dist/handler/operation-handler-discovery.js +55 -0
- package/dist/handler/operation-handler-mounts.d.ts +100 -0
- package/dist/handler/operation-handler-mounts.js +134 -0
- package/dist/handler/operation-handler-subscription.d.ts +34 -0
- package/dist/handler/operation-handler-subscription.js +112 -0
- package/dist/handler/operation-handler.d.ts +162 -0
- package/dist/handler/operation-handler.js +236 -0
- package/dist/handler/workspace-release.d.ts +6 -0
- package/dist/handler/workspace-release.js +75 -0
- package/dist/in-memory-replay-live-backend.d.ts +47 -0
- package/dist/in-memory-replay-live-backend.js +129 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +30 -0
- package/dist/internal/cryptography/encryption.d.ts +108 -0
- package/dist/internal/cryptography/encryption.js +241 -0
- package/dist/internal/cryptography/hash.d.ts +72 -0
- package/dist/internal/cryptography/hash.js +233 -0
- package/dist/internal/cryptography/index.d.ts +4 -0
- package/dist/internal/cryptography/index.js +2 -0
- package/dist/internals.d.ts +58 -0
- package/dist/internals.js +54 -0
- package/dist/json-rpc-dispatch.d.ts +88 -0
- package/dist/json-rpc-dispatch.js +154 -0
- package/dist/json-rpc-framing.d.ts +42 -0
- package/dist/json-rpc-framing.js +50 -0
- package/dist/json-rpc-http.d.ts +36 -0
- package/dist/json-rpc-http.js +191 -0
- package/dist/json-rpc-parse.d.ts +69 -0
- package/dist/json-rpc-parse.js +206 -0
- package/dist/json-rpc-protocol.d.ts +76 -0
- package/dist/json-rpc-protocol.js +54 -0
- package/dist/json-rpc-session-runtime.d.ts +55 -0
- package/dist/json-rpc-session-runtime.js +111 -0
- package/dist/json-rpc-websocket-subscription-pump.d.ts +9 -0
- package/dist/json-rpc-websocket-subscription-pump.js +46 -0
- package/dist/json-rpc-websocket-subscriptions.d.ts +10 -0
- package/dist/json-rpc-websocket-subscriptions.js +33 -0
- package/dist/json-rpc-websocket-types.d.ts +34 -0
- package/dist/json-rpc-websocket-types.js +1 -0
- package/dist/json-rpc-websocket-validation.d.ts +45 -0
- package/dist/json-rpc-websocket-validation.js +154 -0
- package/dist/json-rpc-websocket.d.ts +20 -0
- package/dist/json-rpc-websocket.js +363 -0
- package/dist/json-schema-utilities.d.ts +5 -0
- package/dist/json-schema-utilities.js +17 -0
- package/dist/mcp-discovery-names.d.ts +11 -0
- package/dist/mcp-discovery-names.js +11 -0
- package/dist/openapi-canonical-json.d.ts +10 -0
- package/dist/openapi-canonical-json.js +23 -0
- package/dist/openapi-error-responses.d.ts +15 -0
- package/dist/openapi-error-responses.js +104 -0
- package/dist/openapi-schemas.d.ts +17 -0
- package/dist/openapi-schemas.js +94 -0
- package/dist/openapi.d.ts +60 -0
- package/dist/openapi.js +351 -0
- package/dist/openrpc-document-schema.d.ts +255 -0
- package/dist/openrpc-document-schema.js +84 -0
- package/dist/openrpc-errors.d.ts +93 -0
- package/dist/openrpc-errors.js +134 -0
- package/dist/openrpc.d.ts +66 -0
- package/dist/openrpc.js +260 -0
- package/dist/operation-catalog/behavior-types.d.ts +34 -0
- package/dist/operation-catalog/behavior-types.js +1 -0
- package/dist/operation-catalog/behavior-validation.d.ts +3 -0
- package/dist/operation-catalog/behavior-validation.js +298 -0
- package/dist/operation-catalog/dispatch-allowlist.d.ts +4 -0
- package/dist/operation-catalog/dispatch-allowlist.js +7 -0
- package/dist/operation-catalog/dispatch-preparation.d.ts +24 -0
- package/dist/operation-catalog/dispatch-preparation.js +49 -0
- package/dist/operation-catalog/index.d.ts +19 -0
- package/dist/operation-catalog/index.js +17 -0
- package/dist/operation-catalog/operation-dispatch.d.ts +14 -0
- package/dist/operation-catalog/operation-dispatch.js +115 -0
- package/dist/operation-catalog/operation-interceptors.d.ts +15 -0
- package/dist/operation-catalog/operation-interceptors.js +1 -0
- package/dist/operation-catalog/operation-metadata.d.ts +5 -0
- package/dist/operation-catalog/operation-metadata.js +104 -0
- package/dist/operation-catalog/pipeline-helpers.d.ts +70 -0
- package/dist/operation-catalog/pipeline-helpers.js +242 -0
- package/dist/operation-catalog/pipeline-stages.d.ts +23 -0
- package/dist/operation-catalog/pipeline-stages.js +226 -0
- package/dist/operation-catalog/pipeline.d.ts +7 -0
- package/dist/operation-catalog/pipeline.js +33 -0
- package/dist/operation-catalog/registry.d.ts +17 -0
- package/dist/operation-catalog/registry.js +132 -0
- package/dist/operation-catalog/stream-pipeline.d.ts +37 -0
- package/dist/operation-catalog/stream-pipeline.js +129 -0
- package/dist/operation-catalog/subscription-lifecycle.d.ts +6 -0
- package/dist/operation-catalog/subscription-lifecycle.js +27 -0
- package/dist/operation-catalog/types.d.ts +392 -0
- package/dist/operation-catalog/types.js +40 -0
- package/dist/operation-catalog/universal-faults.d.ts +11 -0
- package/dist/operation-catalog/universal-faults.js +15 -0
- package/dist/operation-catalog-snapshot.d.ts +215 -0
- package/dist/operation-catalog-snapshot.js +128 -0
- package/dist/operation-catalog.d.ts +1 -0
- package/dist/operation-catalog.js +1 -0
- package/dist/operation-description-audit.d.ts +44 -0
- package/dist/operation-description-audit.js +90 -0
- package/dist/operation-fault-helpers.d.ts +21 -0
- package/dist/operation-fault-helpers.js +32 -0
- package/dist/operation-fault.d.ts +245 -0
- package/dist/operation-fault.js +235 -0
- package/dist/operation-registry.d.ts +46 -0
- package/dist/operation-registry.js +46 -0
- package/dist/operations/closable-iterable.d.ts +23 -0
- package/dist/operations/closable-iterable.js +51 -0
- package/dist/operations/get-principal.d.ts +106 -0
- package/dist/operations/get-principal.js +107 -0
- package/dist/operations/sse-stream.d.ts +67 -0
- package/dist/operations/sse-stream.js +264 -0
- package/dist/principal.d.ts +253 -0
- package/dist/principal.js +254 -0
- package/dist/replay-live-feed-internals.d.ts +47 -0
- package/dist/replay-live-feed-internals.js +215 -0
- package/dist/replay-live-feed-types.d.ts +66 -0
- package/dist/replay-live-feed-types.js +7 -0
- package/dist/replay-live-feed.d.ts +49 -0
- package/dist/replay-live-feed.js +126 -0
- package/dist/rest-binding.d.ts +215 -0
- package/dist/rest-binding.js +95 -0
- package/dist/rest-body.d.ts +17 -0
- package/dist/rest-body.js +95 -0
- package/dist/route-model.d.ts +305 -0
- package/dist/route-model.js +320 -0
- package/dist/runtime/cors.d.ts +161 -0
- package/dist/runtime/cors.js +265 -0
- package/dist/scripts/generate-operation-client.d.ts +186 -0
- package/dist/scripts/generate-operation-client.js +561 -0
- package/dist/scripts/operation-behaviors.d.ts +3 -0
- package/dist/scripts/operation-behaviors.js +16 -0
- package/dist/scripts/operation-client-aliases.d.ts +32 -0
- package/dist/scripts/operation-client-aliases.js +255 -0
- package/dist/scripts/operation-client-domains.d.ts +21 -0
- package/dist/scripts/operation-client-domains.js +74 -0
- package/dist/scripts/operation-client-schema.d.ts +46 -0
- package/dist/scripts/operation-client-schema.js +310 -0
- package/dist/scripts/operation-client-svelte.d.ts +3 -0
- package/dist/scripts/operation-client-svelte.js +61 -0
- package/dist/sequence-cursor.d.ts +46 -0
- package/dist/sequence-cursor.js +62 -0
- package/dist/sse-error-payload-schema.d.ts +12 -0
- package/dist/sse-error-payload-schema.js +33 -0
- package/dist/stdio-session.d.ts +71 -0
- package/dist/stdio-session.js +347 -0
- package/dist/zod-json-schema.d.ts +22 -0
- package/dist/zod-json-schema.js +49 -0
- package/package.json +38 -3
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared direct-route definitions for REST-only HTTP endpoints.
|
|
3
|
+
*
|
|
4
|
+
* Operation-backed REST endpoints are modeled by `RestBinding` instances.
|
|
5
|
+
* These seven endpoints stay direct because they describe or expose the HTTP
|
|
6
|
+
* server itself rather than a durable workflow operation:
|
|
7
|
+
* - `GET /v1/health` — anonymous liveness probe (no catalog op)
|
|
8
|
+
* - `GET /v1/metrics` — Prometheus text exposition (text/plain, no catalog op)
|
|
9
|
+
* - `GET /.well-known/api-catalog` — RFC 9264 service-desc linkset
|
|
10
|
+
* - `GET /.well-known/mcp.json` — MCP transport discovery
|
|
11
|
+
* - `GET /asyncapi.json` — transport-meta endpoint (self-describing, no catalog op)
|
|
12
|
+
* - `GET /openapi.json` — transport-meta endpoint (self-describing, no catalog op)
|
|
13
|
+
* - `GET /openrpc.json` — transport-meta endpoint (self-describing, no catalog op)
|
|
14
|
+
*
|
|
15
|
+
* @module server/route-model
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* External URL prefix under which the functional HTTP/WebSocket API is served
|
|
19
|
+
* (REST workflows/schedules/tasks, `/mcp`, `/jsonrpc`, and the workflow/task
|
|
20
|
+
* WebSocket upgrades). Caller-supplied `serve({ routes })`, such as the page
|
|
21
|
+
* routes an application's page host registers, can occupy root-level paths, so the API is
|
|
22
|
+
* namespaced beneath this prefix on the wire.
|
|
23
|
+
*
|
|
24
|
+
* This is purely an *external* (wire) concern. Internal routing — the
|
|
25
|
+
* `DIRECT_HTTP_ROUTES` table, every `RestBinding`, the WebSocket-upgrade
|
|
26
|
+
* regexes, and the authentication allowlist — stays canonical and
|
|
27
|
+
* root-relative. The HTTP front door strips this prefix from incoming requests
|
|
28
|
+
* before any matching runs, and the spec/discovery generators reattach it via
|
|
29
|
+
* {@link externalApiPath} when advertising endpoints.
|
|
30
|
+
*
|
|
31
|
+
* Root-stable surfaces are deliberately **not** moved under this prefix:
|
|
32
|
+
* `/v1/health`, `/v1/metrics`, `/openapi.json`, `/openrpc.json`,
|
|
33
|
+
* `/asyncapi.json`, and `/.well-known/*` remain at the origin root per
|
|
34
|
+
* RFC 9264 / discovery convention.
|
|
35
|
+
*/
|
|
36
|
+
export declare const API_PREFIX = "/api";
|
|
37
|
+
/** Root-relative namespace for the functional REST and WebSocket API. */
|
|
38
|
+
export declare const ROOT_API_PREFIX = "/v1";
|
|
39
|
+
/**
|
|
40
|
+
* Canonical, root-relative MCP streamable-HTTP path. Runtime routing matches
|
|
41
|
+
* this form (after the front door strips the `/api` prefix), and the discovery
|
|
42
|
+
* document advertises the external `/api`-prefixed URL via `externalApiPath`.
|
|
43
|
+
*/
|
|
44
|
+
export declare const MCP_STREAMABLE_HTTP_PATH = "/mcp";
|
|
45
|
+
/**
|
|
46
|
+
* Canonical, root-relative JSON-RPC path, answered over HTTP `POST` and as a
|
|
47
|
+
* WebSocket upgrade. Like {@link MCP_STREAMABLE_HTTP_PATH}, it is dispatched
|
|
48
|
+
* by this literal path rather than through `DIRECT_HTTP_ROUTES` or a
|
|
49
|
+
* `RestBinding`.
|
|
50
|
+
*/
|
|
51
|
+
export declare const JSON_RPC_PATH = "/jsonrpc";
|
|
52
|
+
/**
|
|
53
|
+
* Map a canonical, root-relative server path to its external (`/api`-prefixed)
|
|
54
|
+
* form for emission in specs and discovery documents.
|
|
55
|
+
*
|
|
56
|
+
* Requires a leading slash and refuses an already-prefixed path so callers can
|
|
57
|
+
* never produce `/api/api/...`.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { externalApiPath } from './route-model.ts';
|
|
62
|
+
* externalApiPath('/v1/workflows'); // '/api/v1/workflows'
|
|
63
|
+
* externalApiPath('/mcp'); // '/api/mcp'
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare function externalApiPath(canonicalPath: string): string;
|
|
67
|
+
/** HTTP method for a route. */
|
|
68
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
69
|
+
export type DirectRouteResponseMediaType = 'application/json' | 'application/msgpack' | 'application/linkset+json' | 'text/plain';
|
|
70
|
+
export type DirectRouteResponseSchema = 'object' | 'string';
|
|
71
|
+
export type DirectRouteResponseContent = {
|
|
72
|
+
/** Media type advertised for this response body. */
|
|
73
|
+
mediaType: DirectRouteResponseMediaType;
|
|
74
|
+
/** Minimal OpenAPI schema shape for this response body. */
|
|
75
|
+
schema: DirectRouteResponseSchema;
|
|
76
|
+
};
|
|
77
|
+
export type DirectRouteResponse = {
|
|
78
|
+
/** HTTP status emitted by the direct route. */
|
|
79
|
+
status: number;
|
|
80
|
+
/** Human-readable response description for OpenAPI. */
|
|
81
|
+
description: string;
|
|
82
|
+
/** Response body variants advertised by the direct route, when it has a body. */
|
|
83
|
+
content?: readonly DirectRouteResponseContent[];
|
|
84
|
+
};
|
|
85
|
+
export type DirectRouteAccess = 'public' | 'authenticated';
|
|
86
|
+
/** A single direct HTTP route definition. */
|
|
87
|
+
export type DirectHttpRouteDefinition = {
|
|
88
|
+
/** HTTP method. */
|
|
89
|
+
method: HttpMethod;
|
|
90
|
+
/**
|
|
91
|
+
* Express-style path pattern (e.g. `/v1/workflows/:id/signal/:name`).
|
|
92
|
+
* Used to generate OpenAPI path items and regex patterns.
|
|
93
|
+
*/
|
|
94
|
+
path: string;
|
|
95
|
+
/** Internal handler function name. */
|
|
96
|
+
handler: string;
|
|
97
|
+
/** Ordered list of path parameter names. */
|
|
98
|
+
paramNames: string[];
|
|
99
|
+
/** Human-readable summary for OpenAPI. */
|
|
100
|
+
summary: string;
|
|
101
|
+
/** OpenAPI tags for grouping. */
|
|
102
|
+
tags: string[];
|
|
103
|
+
/** Response metadata shared by dispatch documentation. */
|
|
104
|
+
responses: readonly DirectRouteResponse[];
|
|
105
|
+
/** Direct route access policy for authentication and OpenAPI metadata. */
|
|
106
|
+
access: DirectRouteAccess;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Intentionally REST-only routes. These are not in the operation catalog.
|
|
110
|
+
*
|
|
111
|
+
* `as const` preserves the literal types of `handler` so consumers can
|
|
112
|
+
* derive a string-literal union for compile-time exhaustiveness on route
|
|
113
|
+
* executors.
|
|
114
|
+
*/
|
|
115
|
+
export declare const DIRECT_HTTP_ROUTES: readonly [{
|
|
116
|
+
readonly method: "GET";
|
|
117
|
+
readonly path: "/v1/health";
|
|
118
|
+
readonly handler: "healthCheck";
|
|
119
|
+
readonly paramNames: [];
|
|
120
|
+
readonly summary: "Health check";
|
|
121
|
+
readonly tags: ["System"];
|
|
122
|
+
readonly responses: readonly [{
|
|
123
|
+
readonly status: 200;
|
|
124
|
+
readonly description: "Service health status";
|
|
125
|
+
readonly content: readonly [{
|
|
126
|
+
readonly mediaType: "application/json";
|
|
127
|
+
readonly schema: "object";
|
|
128
|
+
}, {
|
|
129
|
+
readonly mediaType: "application/msgpack";
|
|
130
|
+
readonly schema: "object";
|
|
131
|
+
}];
|
|
132
|
+
}];
|
|
133
|
+
readonly access: "public";
|
|
134
|
+
}, {
|
|
135
|
+
readonly method: "GET";
|
|
136
|
+
readonly path: "/v1/metrics";
|
|
137
|
+
readonly handler: "getMetrics";
|
|
138
|
+
readonly paramNames: [];
|
|
139
|
+
readonly summary: "Prometheus metrics export";
|
|
140
|
+
readonly tags: ["Observability"];
|
|
141
|
+
readonly responses: readonly [{
|
|
142
|
+
readonly status: 200;
|
|
143
|
+
readonly description: "Prometheus metrics exposition";
|
|
144
|
+
readonly content: readonly [{
|
|
145
|
+
readonly mediaType: "text/plain";
|
|
146
|
+
readonly schema: "string";
|
|
147
|
+
}];
|
|
148
|
+
}, {
|
|
149
|
+
readonly status: 503;
|
|
150
|
+
readonly description: "Metrics exporter failure";
|
|
151
|
+
readonly content: readonly [{
|
|
152
|
+
readonly mediaType: "application/json";
|
|
153
|
+
readonly schema: "object";
|
|
154
|
+
}];
|
|
155
|
+
}];
|
|
156
|
+
readonly access: "public";
|
|
157
|
+
}, {
|
|
158
|
+
readonly method: "GET";
|
|
159
|
+
readonly path: "/.well-known/api-catalog";
|
|
160
|
+
readonly handler: "apiCatalog";
|
|
161
|
+
readonly paramNames: [];
|
|
162
|
+
readonly summary: "RFC 9264 API catalog linkset";
|
|
163
|
+
readonly tags: ["System"];
|
|
164
|
+
readonly responses: readonly [{
|
|
165
|
+
readonly status: 200;
|
|
166
|
+
readonly description: "RFC 9264 API catalog linkset";
|
|
167
|
+
readonly content: readonly [{
|
|
168
|
+
readonly mediaType: "application/linkset+json";
|
|
169
|
+
readonly schema: "object";
|
|
170
|
+
}];
|
|
171
|
+
}, {
|
|
172
|
+
readonly status: 421;
|
|
173
|
+
readonly description: "Request host rejected by trustedHosts";
|
|
174
|
+
readonly content: readonly [{
|
|
175
|
+
readonly mediaType: "application/json";
|
|
176
|
+
readonly schema: "object";
|
|
177
|
+
}];
|
|
178
|
+
}, {
|
|
179
|
+
readonly status: 503;
|
|
180
|
+
readonly description: "API catalog origin is not configured";
|
|
181
|
+
readonly content: readonly [{
|
|
182
|
+
readonly mediaType: "application/json";
|
|
183
|
+
readonly schema: "object";
|
|
184
|
+
}];
|
|
185
|
+
}];
|
|
186
|
+
readonly access: "public";
|
|
187
|
+
}, {
|
|
188
|
+
readonly method: "GET";
|
|
189
|
+
readonly path: "/.well-known/mcp.json";
|
|
190
|
+
readonly handler: "mcpDiscovery";
|
|
191
|
+
readonly paramNames: [];
|
|
192
|
+
readonly summary: "MCP discovery document";
|
|
193
|
+
readonly tags: ["System"];
|
|
194
|
+
readonly responses: readonly [{
|
|
195
|
+
readonly status: 200;
|
|
196
|
+
readonly description: "MCP transport discovery document";
|
|
197
|
+
readonly content: readonly [{
|
|
198
|
+
readonly mediaType: "application/json";
|
|
199
|
+
readonly schema: "object";
|
|
200
|
+
}];
|
|
201
|
+
}, {
|
|
202
|
+
readonly status: 421;
|
|
203
|
+
readonly description: "Request host rejected by trustedHosts";
|
|
204
|
+
readonly content: readonly [{
|
|
205
|
+
readonly mediaType: "application/json";
|
|
206
|
+
readonly schema: "object";
|
|
207
|
+
}];
|
|
208
|
+
}, {
|
|
209
|
+
readonly status: 503;
|
|
210
|
+
readonly description: "MCP discovery origin is not configured";
|
|
211
|
+
readonly content: readonly [{
|
|
212
|
+
readonly mediaType: "application/json";
|
|
213
|
+
readonly schema: "object";
|
|
214
|
+
}];
|
|
215
|
+
}];
|
|
216
|
+
readonly access: "public";
|
|
217
|
+
}, {
|
|
218
|
+
readonly method: "GET";
|
|
219
|
+
readonly path: "/openapi.json";
|
|
220
|
+
readonly handler: "openApiDocument";
|
|
221
|
+
readonly paramNames: [];
|
|
222
|
+
readonly summary: "OpenAPI 3.1 specification";
|
|
223
|
+
readonly tags: ["System"];
|
|
224
|
+
readonly responses: readonly [{
|
|
225
|
+
readonly status: 200;
|
|
226
|
+
readonly description: "OpenAPI 3.1 specification";
|
|
227
|
+
readonly content: readonly [{
|
|
228
|
+
readonly mediaType: "application/json";
|
|
229
|
+
readonly schema: "object";
|
|
230
|
+
}];
|
|
231
|
+
}];
|
|
232
|
+
readonly access: "public";
|
|
233
|
+
}, {
|
|
234
|
+
readonly method: "GET";
|
|
235
|
+
readonly path: "/openrpc.json";
|
|
236
|
+
readonly handler: "openRpcDocument";
|
|
237
|
+
readonly paramNames: [];
|
|
238
|
+
readonly summary: "OpenRPC 1.3.2 specification";
|
|
239
|
+
readonly tags: ["System"];
|
|
240
|
+
readonly responses: readonly [{
|
|
241
|
+
readonly status: 200;
|
|
242
|
+
readonly description: "OpenRPC 1.3.2 specification";
|
|
243
|
+
readonly content: readonly [{
|
|
244
|
+
readonly mediaType: "application/json";
|
|
245
|
+
readonly schema: "object";
|
|
246
|
+
}];
|
|
247
|
+
}];
|
|
248
|
+
readonly access: "public";
|
|
249
|
+
}, {
|
|
250
|
+
readonly method: "GET";
|
|
251
|
+
readonly path: "/asyncapi.json";
|
|
252
|
+
readonly handler: "asyncApiDocument";
|
|
253
|
+
readonly paramNames: [];
|
|
254
|
+
readonly summary: "AsyncAPI 3.0 specification";
|
|
255
|
+
readonly tags: ["System"];
|
|
256
|
+
readonly responses: readonly [{
|
|
257
|
+
readonly status: 200;
|
|
258
|
+
readonly description: "AsyncAPI 3.0 specification";
|
|
259
|
+
readonly content: readonly [{
|
|
260
|
+
readonly mediaType: "application/json";
|
|
261
|
+
readonly schema: "object";
|
|
262
|
+
}];
|
|
263
|
+
}];
|
|
264
|
+
readonly access: "public";
|
|
265
|
+
}];
|
|
266
|
+
/**
|
|
267
|
+
* Where the engine-independent operation handler serves a catalog
|
|
268
|
+
* subscription over Server-Sent Events: `GET <prefix>/<operationName>`.
|
|
269
|
+
* `handleRequest` and `serve()` do not serve it; their SSE routes are
|
|
270
|
+
* bindings of their own.
|
|
271
|
+
*/
|
|
272
|
+
export declare const GENERIC_SUBSCRIPTION_ROUTE_PREFIX = "/v1/subscriptions";
|
|
273
|
+
/**
|
|
274
|
+
* Report whether a caller-supplied Bun route key would claim a request that
|
|
275
|
+
* Weft serves itself.
|
|
276
|
+
*
|
|
277
|
+
* Bun matches its `routes` table before the `fetch` handler that dispatches
|
|
278
|
+
* every API and discovery request, so a route that overlaps Weft's own paths
|
|
279
|
+
* silently shadows them. A key without `*` or `:` overlaps when it equals a
|
|
280
|
+
* reserved path (either prefix, {@link MCP_STREAMABLE_HTTP_PATH},
|
|
281
|
+
* {@link JSON_RPC_PATH}, or a direct route) or falls under {@link API_PREFIX}
|
|
282
|
+
* or {@link ROOT_API_PREFIX}.
|
|
283
|
+
* A key with `*` or `:` can match many paths, so its static prefix (the text
|
|
284
|
+
* before its first `*` or `:`) overlaps when it equals or falls under one of
|
|
285
|
+
* those prefixes, or when any reserved path begins with it.
|
|
286
|
+
*/
|
|
287
|
+
export declare function overlapsReservedRoute(routeKey: string): boolean;
|
|
288
|
+
/**
|
|
289
|
+
* Convert an Express-style path to an OpenAPI path template.
|
|
290
|
+
* `/v1/workflows/:id/signal/:name` → `/v1/workflows/{id}/signal/{name}`
|
|
291
|
+
*/
|
|
292
|
+
export declare function toOpenApiPath(path: string): string;
|
|
293
|
+
/**
|
|
294
|
+
* Convert an Express-style path to a regex pattern for route matching.
|
|
295
|
+
*
|
|
296
|
+
* Each segment is either a literal (with regex metacharacters escaped) or a
|
|
297
|
+
* parameter placeholder:
|
|
298
|
+
* - `:step` becomes `(\\d+)` for numeric-only matching (checkpoint routes)
|
|
299
|
+
* - `:name` becomes `([^/]+)` for any non-slash token
|
|
300
|
+
*
|
|
301
|
+
* Escaping the literal segments prevents characters like `.` in paths such as
|
|
302
|
+
* `/openapi.json` from being treated as wildcards (which would match
|
|
303
|
+
* `/openapiXjson`).
|
|
304
|
+
*/
|
|
305
|
+
export declare function toRegex(path: string): RegExp;
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared direct-route definitions for REST-only HTTP endpoints.
|
|
3
|
+
*
|
|
4
|
+
* Operation-backed REST endpoints are modeled by `RestBinding` instances.
|
|
5
|
+
* These seven endpoints stay direct because they describe or expose the HTTP
|
|
6
|
+
* server itself rather than a durable workflow operation:
|
|
7
|
+
* - `GET /v1/health` — anonymous liveness probe (no catalog op)
|
|
8
|
+
* - `GET /v1/metrics` — Prometheus text exposition (text/plain, no catalog op)
|
|
9
|
+
* - `GET /.well-known/api-catalog` — RFC 9264 service-desc linkset
|
|
10
|
+
* - `GET /.well-known/mcp.json` — MCP transport discovery
|
|
11
|
+
* - `GET /asyncapi.json` — transport-meta endpoint (self-describing, no catalog op)
|
|
12
|
+
* - `GET /openapi.json` — transport-meta endpoint (self-describing, no catalog op)
|
|
13
|
+
* - `GET /openrpc.json` — transport-meta endpoint (self-describing, no catalog op)
|
|
14
|
+
*
|
|
15
|
+
* @module server/route-model
|
|
16
|
+
*/
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// External API prefix
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
/**
|
|
21
|
+
* External URL prefix under which the functional HTTP/WebSocket API is served
|
|
22
|
+
* (REST workflows/schedules/tasks, `/mcp`, `/jsonrpc`, and the workflow/task
|
|
23
|
+
* WebSocket upgrades). Caller-supplied `serve({ routes })`, such as the page
|
|
24
|
+
* routes an application's page host registers, can occupy root-level paths, so the API is
|
|
25
|
+
* namespaced beneath this prefix on the wire.
|
|
26
|
+
*
|
|
27
|
+
* This is purely an *external* (wire) concern. Internal routing — the
|
|
28
|
+
* `DIRECT_HTTP_ROUTES` table, every `RestBinding`, the WebSocket-upgrade
|
|
29
|
+
* regexes, and the authentication allowlist — stays canonical and
|
|
30
|
+
* root-relative. The HTTP front door strips this prefix from incoming requests
|
|
31
|
+
* before any matching runs, and the spec/discovery generators reattach it via
|
|
32
|
+
* {@link externalApiPath} when advertising endpoints.
|
|
33
|
+
*
|
|
34
|
+
* Root-stable surfaces are deliberately **not** moved under this prefix:
|
|
35
|
+
* `/v1/health`, `/v1/metrics`, `/openapi.json`, `/openrpc.json`,
|
|
36
|
+
* `/asyncapi.json`, and `/.well-known/*` remain at the origin root per
|
|
37
|
+
* RFC 9264 / discovery convention.
|
|
38
|
+
*/
|
|
39
|
+
export const API_PREFIX = '/api';
|
|
40
|
+
/** Root-relative namespace for the functional REST and WebSocket API. */
|
|
41
|
+
export const ROOT_API_PREFIX = '/v1';
|
|
42
|
+
/**
|
|
43
|
+
* Canonical, root-relative MCP streamable-HTTP path. Runtime routing matches
|
|
44
|
+
* this form (after the front door strips the `/api` prefix), and the discovery
|
|
45
|
+
* document advertises the external `/api`-prefixed URL via `externalApiPath`.
|
|
46
|
+
*/
|
|
47
|
+
export const MCP_STREAMABLE_HTTP_PATH = '/mcp';
|
|
48
|
+
/**
|
|
49
|
+
* Canonical, root-relative JSON-RPC path, answered over HTTP `POST` and as a
|
|
50
|
+
* WebSocket upgrade. Like {@link MCP_STREAMABLE_HTTP_PATH}, it is dispatched
|
|
51
|
+
* by this literal path rather than through `DIRECT_HTTP_ROUTES` or a
|
|
52
|
+
* `RestBinding`.
|
|
53
|
+
*/
|
|
54
|
+
export const JSON_RPC_PATH = '/jsonrpc';
|
|
55
|
+
/**
|
|
56
|
+
* Map a canonical, root-relative server path to its external (`/api`-prefixed)
|
|
57
|
+
* form for emission in specs and discovery documents.
|
|
58
|
+
*
|
|
59
|
+
* Requires a leading slash and refuses an already-prefixed path so callers can
|
|
60
|
+
* never produce `/api/api/...`.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* import { externalApiPath } from './route-model.ts';
|
|
65
|
+
* externalApiPath('/v1/workflows'); // '/api/v1/workflows'
|
|
66
|
+
* externalApiPath('/mcp'); // '/api/mcp'
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export function externalApiPath(canonicalPath) {
|
|
70
|
+
if (!canonicalPath.startsWith('/')) {
|
|
71
|
+
throw new Error(`externalApiPath requires a leading slash, received: ${canonicalPath}`);
|
|
72
|
+
}
|
|
73
|
+
if (canonicalPath === API_PREFIX || canonicalPath.startsWith(`${API_PREFIX}/`)) {
|
|
74
|
+
throw new Error(`externalApiPath received an already-prefixed path: ${canonicalPath}`);
|
|
75
|
+
}
|
|
76
|
+
return `${API_PREFIX}${canonicalPath}`;
|
|
77
|
+
}
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
// Route definitions
|
|
80
|
+
// ---------------------------------------------------------------------------
|
|
81
|
+
/**
|
|
82
|
+
* Intentionally REST-only routes. These are not in the operation catalog.
|
|
83
|
+
*
|
|
84
|
+
* `as const` preserves the literal types of `handler` so consumers can
|
|
85
|
+
* derive a string-literal union for compile-time exhaustiveness on route
|
|
86
|
+
* executors.
|
|
87
|
+
*/
|
|
88
|
+
export const DIRECT_HTTP_ROUTES = [
|
|
89
|
+
{
|
|
90
|
+
method: 'GET',
|
|
91
|
+
path: '/v1/health',
|
|
92
|
+
handler: 'healthCheck',
|
|
93
|
+
paramNames: [],
|
|
94
|
+
summary: 'Health check',
|
|
95
|
+
tags: ['System'],
|
|
96
|
+
responses: [
|
|
97
|
+
{
|
|
98
|
+
status: 200,
|
|
99
|
+
description: 'Service health status',
|
|
100
|
+
content: [
|
|
101
|
+
{ mediaType: 'application/json', schema: 'object' },
|
|
102
|
+
{ mediaType: 'application/msgpack', schema: 'object' },
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
access: 'public',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
method: 'GET',
|
|
110
|
+
path: '/v1/metrics',
|
|
111
|
+
handler: 'getMetrics',
|
|
112
|
+
paramNames: [],
|
|
113
|
+
summary: 'Prometheus metrics export',
|
|
114
|
+
tags: ['Observability'],
|
|
115
|
+
responses: [
|
|
116
|
+
{
|
|
117
|
+
status: 200,
|
|
118
|
+
description: 'Prometheus metrics exposition',
|
|
119
|
+
content: [{ mediaType: 'text/plain', schema: 'string' }],
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
status: 503,
|
|
123
|
+
description: 'Metrics exporter failure',
|
|
124
|
+
content: [{ mediaType: 'application/json', schema: 'object' }],
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
access: 'public',
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
method: 'GET',
|
|
131
|
+
path: '/.well-known/api-catalog',
|
|
132
|
+
handler: 'apiCatalog',
|
|
133
|
+
paramNames: [],
|
|
134
|
+
summary: 'RFC 9264 API catalog linkset',
|
|
135
|
+
tags: ['System'],
|
|
136
|
+
responses: [
|
|
137
|
+
{
|
|
138
|
+
status: 200,
|
|
139
|
+
description: 'RFC 9264 API catalog linkset',
|
|
140
|
+
content: [{ mediaType: 'application/linkset+json', schema: 'object' }],
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
status: 421,
|
|
144
|
+
description: 'Request host rejected by trustedHosts',
|
|
145
|
+
content: [{ mediaType: 'application/json', schema: 'object' }],
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
status: 503,
|
|
149
|
+
description: 'API catalog origin is not configured',
|
|
150
|
+
content: [{ mediaType: 'application/json', schema: 'object' }],
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
access: 'public',
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
method: 'GET',
|
|
157
|
+
path: '/.well-known/mcp.json',
|
|
158
|
+
handler: 'mcpDiscovery',
|
|
159
|
+
paramNames: [],
|
|
160
|
+
summary: 'MCP discovery document',
|
|
161
|
+
tags: ['System'],
|
|
162
|
+
responses: [
|
|
163
|
+
{
|
|
164
|
+
status: 200,
|
|
165
|
+
description: 'MCP transport discovery document',
|
|
166
|
+
content: [{ mediaType: 'application/json', schema: 'object' }],
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
status: 421,
|
|
170
|
+
description: 'Request host rejected by trustedHosts',
|
|
171
|
+
content: [{ mediaType: 'application/json', schema: 'object' }],
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
status: 503,
|
|
175
|
+
description: 'MCP discovery origin is not configured',
|
|
176
|
+
content: [{ mediaType: 'application/json', schema: 'object' }],
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
access: 'public',
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
method: 'GET',
|
|
183
|
+
path: '/openapi.json',
|
|
184
|
+
handler: 'openApiDocument',
|
|
185
|
+
paramNames: [],
|
|
186
|
+
summary: 'OpenAPI 3.1 specification',
|
|
187
|
+
tags: ['System'],
|
|
188
|
+
responses: [
|
|
189
|
+
{
|
|
190
|
+
status: 200,
|
|
191
|
+
description: 'OpenAPI 3.1 specification',
|
|
192
|
+
content: [{ mediaType: 'application/json', schema: 'object' }],
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
access: 'public',
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
method: 'GET',
|
|
199
|
+
path: '/openrpc.json',
|
|
200
|
+
handler: 'openRpcDocument',
|
|
201
|
+
paramNames: [],
|
|
202
|
+
summary: 'OpenRPC 1.3.2 specification',
|
|
203
|
+
tags: ['System'],
|
|
204
|
+
responses: [
|
|
205
|
+
{
|
|
206
|
+
status: 200,
|
|
207
|
+
description: 'OpenRPC 1.3.2 specification',
|
|
208
|
+
content: [{ mediaType: 'application/json', schema: 'object' }],
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
access: 'public',
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
method: 'GET',
|
|
215
|
+
path: '/asyncapi.json',
|
|
216
|
+
handler: 'asyncApiDocument',
|
|
217
|
+
paramNames: [],
|
|
218
|
+
summary: 'AsyncAPI 3.0 specification',
|
|
219
|
+
tags: ['System'],
|
|
220
|
+
responses: [
|
|
221
|
+
{
|
|
222
|
+
status: 200,
|
|
223
|
+
description: 'AsyncAPI 3.0 specification',
|
|
224
|
+
content: [{ mediaType: 'application/json', schema: 'object' }],
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
access: 'public',
|
|
228
|
+
},
|
|
229
|
+
];
|
|
230
|
+
/**
|
|
231
|
+
* Where the engine-independent operation handler serves a catalog
|
|
232
|
+
* subscription over Server-Sent Events: `GET <prefix>/<operationName>`.
|
|
233
|
+
* `handleRequest` and `serve()` do not serve it; their SSE routes are
|
|
234
|
+
* bindings of their own.
|
|
235
|
+
*/
|
|
236
|
+
export const GENERIC_SUBSCRIPTION_ROUTE_PREFIX = '/v1/subscriptions';
|
|
237
|
+
// ---------------------------------------------------------------------------
|
|
238
|
+
// Reserved route space
|
|
239
|
+
// ---------------------------------------------------------------------------
|
|
240
|
+
/**
|
|
241
|
+
* Prefixes whose whole subtree belongs to Weft: the external API namespace and
|
|
242
|
+
* the root-relative versioned namespace beneath it.
|
|
243
|
+
*/
|
|
244
|
+
const RESERVED_ROUTE_PREFIXES = [API_PREFIX, ROOT_API_PREFIX];
|
|
245
|
+
/**
|
|
246
|
+
* Every concrete path Weft answers itself: both prefixes, the MCP and JSON-RPC
|
|
247
|
+
* transports (which the front door also answers at the origin root, because it
|
|
248
|
+
* leaves a path without the `/api` prefix unchanged), and each direct route.
|
|
249
|
+
*/
|
|
250
|
+
const RESERVED_ROUTE_PATHS = [
|
|
251
|
+
...RESERVED_ROUTE_PREFIXES,
|
|
252
|
+
MCP_STREAMABLE_HTTP_PATH,
|
|
253
|
+
JSON_RPC_PATH,
|
|
254
|
+
...DIRECT_HTTP_ROUTES.map(({ path }) => path),
|
|
255
|
+
];
|
|
256
|
+
function isUnderReservedPrefix(path) {
|
|
257
|
+
return RESERVED_ROUTE_PREFIXES.some((prefix) => path === prefix || path.startsWith(`${prefix}/`));
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Report whether a caller-supplied Bun route key would claim a request that
|
|
261
|
+
* Weft serves itself.
|
|
262
|
+
*
|
|
263
|
+
* Bun matches its `routes` table before the `fetch` handler that dispatches
|
|
264
|
+
* every API and discovery request, so a route that overlaps Weft's own paths
|
|
265
|
+
* silently shadows them. A key without `*` or `:` overlaps when it equals a
|
|
266
|
+
* reserved path (either prefix, {@link MCP_STREAMABLE_HTTP_PATH},
|
|
267
|
+
* {@link JSON_RPC_PATH}, or a direct route) or falls under {@link API_PREFIX}
|
|
268
|
+
* or {@link ROOT_API_PREFIX}.
|
|
269
|
+
* A key with `*` or `:` can match many paths, so its static prefix (the text
|
|
270
|
+
* before its first `*` or `:`) overlaps when it equals or falls under one of
|
|
271
|
+
* those prefixes, or when any reserved path begins with it.
|
|
272
|
+
*/
|
|
273
|
+
export function overlapsReservedRoute(routeKey) {
|
|
274
|
+
const patternStart = routeKey.search(/[*:]/);
|
|
275
|
+
if (patternStart === -1) {
|
|
276
|
+
return RESERVED_ROUTE_PATHS.includes(routeKey) || isUnderReservedPrefix(routeKey);
|
|
277
|
+
}
|
|
278
|
+
const staticPrefix = routeKey.slice(0, patternStart);
|
|
279
|
+
return (isUnderReservedPrefix(staticPrefix) ||
|
|
280
|
+
RESERVED_ROUTE_PATHS.some((reservedPath) => reservedPath.startsWith(staticPrefix)));
|
|
281
|
+
}
|
|
282
|
+
// ---------------------------------------------------------------------------
|
|
283
|
+
// Helpers
|
|
284
|
+
// ---------------------------------------------------------------------------
|
|
285
|
+
/**
|
|
286
|
+
* Convert an Express-style path to an OpenAPI path template.
|
|
287
|
+
* `/v1/workflows/:id/signal/:name` → `/v1/workflows/{id}/signal/{name}`
|
|
288
|
+
*/
|
|
289
|
+
export function toOpenApiPath(path) {
|
|
290
|
+
return path.replace(/:([^/]+)/g, '{$1}');
|
|
291
|
+
}
|
|
292
|
+
/** Escape regex metacharacters in a literal path segment. */
|
|
293
|
+
function escapeRegexLiteral(value) {
|
|
294
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Convert an Express-style path to a regex pattern for route matching.
|
|
298
|
+
*
|
|
299
|
+
* Each segment is either a literal (with regex metacharacters escaped) or a
|
|
300
|
+
* parameter placeholder:
|
|
301
|
+
* - `:step` becomes `(\\d+)` for numeric-only matching (checkpoint routes)
|
|
302
|
+
* - `:name` becomes `([^/]+)` for any non-slash token
|
|
303
|
+
*
|
|
304
|
+
* Escaping the literal segments prevents characters like `.` in paths such as
|
|
305
|
+
* `/openapi.json` from being treated as wildcards (which would match
|
|
306
|
+
* `/openapiXjson`).
|
|
307
|
+
*/
|
|
308
|
+
export function toRegex(path) {
|
|
309
|
+
const regexStr = path
|
|
310
|
+
.split('/')
|
|
311
|
+
.map((segment) => {
|
|
312
|
+
if (segment === ':step')
|
|
313
|
+
return '(\\d+)';
|
|
314
|
+
if (segment.startsWith(':'))
|
|
315
|
+
return '([^/]+)';
|
|
316
|
+
return escapeRegexLiteral(segment);
|
|
317
|
+
})
|
|
318
|
+
.join('/');
|
|
319
|
+
return new RegExp(`^${regexStr}$`);
|
|
320
|
+
}
|