@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,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal committed Zod schema for the OpenRPC document shape that Weft emits.
|
|
3
|
+
*
|
|
4
|
+
* @module server/openrpc-document-schema
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { AccessPolicyMetadataSchema, ParameterizedAccessMetadataSchema, } from "./access-policy-metadata.js";
|
|
8
|
+
import { MCP_DISCOVERY_PATH, MCP_TOOLS_LIST_METHOD } from "./mcp-discovery-names.js";
|
|
9
|
+
export const ContentDescriptorSchema = z.strictObject({
|
|
10
|
+
name: z.string(),
|
|
11
|
+
schema: z.record(z.string(), z.unknown()),
|
|
12
|
+
required: z.boolean(),
|
|
13
|
+
});
|
|
14
|
+
const OpenRpcMcpMethodMetadataSchema = z.strictObject({
|
|
15
|
+
workflowType: z.string(),
|
|
16
|
+
toolName: z.string(),
|
|
17
|
+
toolDiscovery: z.strictObject({
|
|
18
|
+
method: z.literal(MCP_TOOLS_LIST_METHOD),
|
|
19
|
+
source: z.literal('live'),
|
|
20
|
+
}),
|
|
21
|
+
});
|
|
22
|
+
export const OpenRpcMethodSchema = z.strictObject({
|
|
23
|
+
name: z.string(),
|
|
24
|
+
summary: z.string().optional(),
|
|
25
|
+
description: z.string().optional(),
|
|
26
|
+
tags: z.array(z.strictObject({ name: z.string() })).optional(),
|
|
27
|
+
paramStructure: z.literal('by-name'),
|
|
28
|
+
params: z.array(ContentDescriptorSchema),
|
|
29
|
+
result: ContentDescriptorSchema,
|
|
30
|
+
errors: z.array(z.strictObject({ $ref: z.string() })).optional(),
|
|
31
|
+
'x-weft-paramsSchema': z.record(z.string(), z.unknown()),
|
|
32
|
+
'x-weft-access': AccessPolicyMetadataSchema,
|
|
33
|
+
'x-weft-mcp': OpenRpcMcpMethodMetadataSchema.optional(),
|
|
34
|
+
'x-weft-parameterizedAccess': ParameterizedAccessMetadataSchema.optional(),
|
|
35
|
+
});
|
|
36
|
+
const OpenRpcMcpMetadataSchema = z.strictObject({
|
|
37
|
+
discoveryPath: z.literal(MCP_DISCOVERY_PATH),
|
|
38
|
+
toolDiscoveryMethod: z.literal(MCP_TOOLS_LIST_METHOD),
|
|
39
|
+
toolNames: z.array(z.string()),
|
|
40
|
+
});
|
|
41
|
+
/** The Zod schema an OpenRPC document must satisfy. */
|
|
42
|
+
export const OpenRpcDocumentSchema = z.strictObject({
|
|
43
|
+
openrpc: z.literal('1.3.2'),
|
|
44
|
+
info: z.strictObject({
|
|
45
|
+
title: z.string(),
|
|
46
|
+
version: z.string(),
|
|
47
|
+
description: z.string().optional(),
|
|
48
|
+
contact: z
|
|
49
|
+
.strictObject({
|
|
50
|
+
name: z.string().optional(),
|
|
51
|
+
url: z.string().optional(),
|
|
52
|
+
email: z.string().optional(),
|
|
53
|
+
})
|
|
54
|
+
.optional(),
|
|
55
|
+
license: z
|
|
56
|
+
.strictObject({
|
|
57
|
+
name: z.string(),
|
|
58
|
+
url: z.string().optional(),
|
|
59
|
+
})
|
|
60
|
+
.optional(),
|
|
61
|
+
externalDocs: z
|
|
62
|
+
.strictObject({
|
|
63
|
+
description: z.string().optional(),
|
|
64
|
+
url: z.string(),
|
|
65
|
+
})
|
|
66
|
+
.optional(),
|
|
67
|
+
}),
|
|
68
|
+
methods: z.array(OpenRpcMethodSchema),
|
|
69
|
+
components: z
|
|
70
|
+
.strictObject({
|
|
71
|
+
errors: z
|
|
72
|
+
.record(z.string(), z.strictObject({
|
|
73
|
+
code: z.number(),
|
|
74
|
+
message: z.string(),
|
|
75
|
+
data: z.record(z.string(), z.unknown()).optional(),
|
|
76
|
+
'x-http-status': z.number().optional(),
|
|
77
|
+
}))
|
|
78
|
+
.optional(),
|
|
79
|
+
schemas: z.record(z.string(), z.unknown()).optional(),
|
|
80
|
+
})
|
|
81
|
+
.optional(),
|
|
82
|
+
servers: z.array(z.strictObject({ url: z.string() })).optional(),
|
|
83
|
+
'x-weft-mcp': OpenRpcMcpMetadataSchema.optional(),
|
|
84
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenRPC `components.errors` derived from the closed `FaultCode` union.
|
|
3
|
+
*
|
|
4
|
+
* @module server/openrpc-errors
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
export declare const UnauthorizedDataSchema: z.ZodObject<{
|
|
8
|
+
reason: z.ZodString;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
export declare const ForbiddenDataSchema: z.ZodObject<{
|
|
11
|
+
reason: z.ZodString;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
export declare const NotFoundDataSchema: z.ZodObject<{
|
|
14
|
+
resource: z.ZodString;
|
|
15
|
+
identifier: z.ZodOptional<z.ZodString>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
export declare const ConflictDataSchema: z.ZodObject<{
|
|
18
|
+
reason: z.ZodString;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
export declare const UnprocessableDataSchema: z.ZodObject<{
|
|
21
|
+
reason: z.ZodString;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
export declare const TimeoutDataSchema: z.ZodObject<{
|
|
24
|
+
operationName: z.ZodOptional<z.ZodString>;
|
|
25
|
+
updateId: z.ZodOptional<z.ZodString>;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
export declare const PayloadTooLargeDataSchema: z.ZodObject<{
|
|
28
|
+
maxBytes: z.ZodNumber;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
export declare const NotImplementedDataSchema: z.ZodObject<{}, z.core.$strip>;
|
|
31
|
+
export declare const UnsupportedTransportDataSchema: z.ZodObject<{
|
|
32
|
+
transport: z.ZodEnum<{
|
|
33
|
+
"http-rest": "http-rest";
|
|
34
|
+
jsonRpcHttp: "jsonRpcHttp";
|
|
35
|
+
jsonRpcWebSocket: "jsonRpcWebSocket";
|
|
36
|
+
jsonRpcStdio: "jsonRpcStdio";
|
|
37
|
+
mcp: "mcp";
|
|
38
|
+
}>;
|
|
39
|
+
supported: z.ZodReadonly<z.ZodArray<z.ZodEnum<{
|
|
40
|
+
"http-rest": "http-rest";
|
|
41
|
+
jsonRpcHttp: "jsonRpcHttp";
|
|
42
|
+
jsonRpcWebSocket: "jsonRpcWebSocket";
|
|
43
|
+
jsonRpcStdio: "jsonRpcStdio";
|
|
44
|
+
mcp: "mcp";
|
|
45
|
+
}>>>;
|
|
46
|
+
}, z.core.$strip>;
|
|
47
|
+
export declare const SubscriptionOverflowDataSchema: z.ZodObject<{
|
|
48
|
+
subscriptionId: z.ZodString;
|
|
49
|
+
droppedCount: z.ZodNumber;
|
|
50
|
+
}, z.core.$strip>;
|
|
51
|
+
export declare const InvalidParamsDataSchema: z.ZodObject<{
|
|
52
|
+
issues: z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
53
|
+
path: z.ZodReadonly<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
54
|
+
message: z.ZodString;
|
|
55
|
+
code: z.ZodString;
|
|
56
|
+
}, z.core.$strip>>>;
|
|
57
|
+
}, z.core.$strip>;
|
|
58
|
+
export declare const MethodNotFoundDataSchema: z.ZodObject<{
|
|
59
|
+
method: z.ZodString;
|
|
60
|
+
}, z.core.$strip>;
|
|
61
|
+
export declare const StaleRevisionDataSchema: z.ZodObject<{
|
|
62
|
+
expectedRevision: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
63
|
+
currentRevision: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
64
|
+
}, z.core.$strip>;
|
|
65
|
+
export declare const RateLimitedDataSchema: z.ZodObject<{
|
|
66
|
+
retryAfterSeconds: z.ZodOptional<z.ZodNumber>;
|
|
67
|
+
}, z.core.$strip>;
|
|
68
|
+
export declare const UnavailableDataSchema: z.ZodObject<{
|
|
69
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
70
|
+
retryAfterSeconds: z.ZodOptional<z.ZodNumber>;
|
|
71
|
+
}, z.core.$strip>;
|
|
72
|
+
export declare const UnsupportedCapabilityDataSchema: z.ZodObject<{
|
|
73
|
+
capability: z.ZodString;
|
|
74
|
+
}, z.core.$strip>;
|
|
75
|
+
export declare const EngineFailureDataSchema: z.ZodObject<{}, z.core.$strip>;
|
|
76
|
+
type OpenRpcError = {
|
|
77
|
+
code: number;
|
|
78
|
+
message: string;
|
|
79
|
+
data?: Record<string, unknown>;
|
|
80
|
+
'x-http-status': number;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Build the `components.errors` array for an OpenRPC document.
|
|
84
|
+
*
|
|
85
|
+
* Derived from `FAULT_CODE_TO_JSON_RPC_CODE` (the single source of truth).
|
|
86
|
+
* Every `FaultCode` in the closed union gets one entry with:
|
|
87
|
+
* - `code`: JSON-RPC error code
|
|
88
|
+
* - `message`: human-readable fault name
|
|
89
|
+
* - `data`: JSON Schema from the Zod schema for that fault's data payload
|
|
90
|
+
* - `x-http-status`: HTTP status code for REST callers
|
|
91
|
+
*/
|
|
92
|
+
export declare function buildOpenRpcComponentsErrors(): Record<string, OpenRpcError>;
|
|
93
|
+
export {};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenRPC `components.errors` derived from the closed `FaultCode` union.
|
|
3
|
+
*
|
|
4
|
+
* @module server/openrpc-errors
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { MAX_REMEDIATION_LENGTH } from "./fault-remediation.js";
|
|
8
|
+
import { FAULT_CODE_TO_HTTP_STATUS, FAULT_CODE_TO_JSON_RPC_CODE, } from "./operation-fault.js";
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// Per-fault data Zod schemas
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
export const UnauthorizedDataSchema = z.object({ reason: z.string() });
|
|
13
|
+
export const ForbiddenDataSchema = z.object({ reason: z.string() });
|
|
14
|
+
export const NotFoundDataSchema = z.object({
|
|
15
|
+
resource: z.string(),
|
|
16
|
+
identifier: z.string().optional(),
|
|
17
|
+
});
|
|
18
|
+
export const ConflictDataSchema = z.object({ reason: z.string() });
|
|
19
|
+
export const UnprocessableDataSchema = z.object({ reason: z.string() });
|
|
20
|
+
export const TimeoutDataSchema = z.object({
|
|
21
|
+
operationName: z.string().optional(),
|
|
22
|
+
updateId: z.string().optional(),
|
|
23
|
+
});
|
|
24
|
+
export const PayloadTooLargeDataSchema = z.object({ maxBytes: z.number() });
|
|
25
|
+
export const NotImplementedDataSchema = z.object({});
|
|
26
|
+
const TransportKindSchema = z.enum([
|
|
27
|
+
'http-rest',
|
|
28
|
+
'jsonRpcHttp',
|
|
29
|
+
'jsonRpcWebSocket',
|
|
30
|
+
'jsonRpcStdio',
|
|
31
|
+
'mcp',
|
|
32
|
+
]);
|
|
33
|
+
export const UnsupportedTransportDataSchema = z.object({
|
|
34
|
+
transport: TransportKindSchema,
|
|
35
|
+
supported: z.array(TransportKindSchema).readonly(),
|
|
36
|
+
});
|
|
37
|
+
export const SubscriptionOverflowDataSchema = z.object({
|
|
38
|
+
subscriptionId: z.string(),
|
|
39
|
+
droppedCount: z.number(),
|
|
40
|
+
});
|
|
41
|
+
export const InvalidParamsDataSchema = z.object({
|
|
42
|
+
issues: z
|
|
43
|
+
.array(z.object({
|
|
44
|
+
path: z.array(z.union([z.string(), z.number()])).readonly(),
|
|
45
|
+
message: z.string(),
|
|
46
|
+
code: z.string(),
|
|
47
|
+
}))
|
|
48
|
+
.readonly(),
|
|
49
|
+
});
|
|
50
|
+
export const MethodNotFoundDataSchema = z.object({ method: z.string() });
|
|
51
|
+
const RevisionTokenSchema = z.union([z.string(), z.number()]);
|
|
52
|
+
export const StaleRevisionDataSchema = z.object({
|
|
53
|
+
expectedRevision: RevisionTokenSchema.optional(),
|
|
54
|
+
currentRevision: RevisionTokenSchema,
|
|
55
|
+
});
|
|
56
|
+
export const RateLimitedDataSchema = z.object({ retryAfterSeconds: z.number().optional() });
|
|
57
|
+
export const UnavailableDataSchema = z.object({
|
|
58
|
+
reason: z.string().optional(),
|
|
59
|
+
retryAfterSeconds: z.number().optional(),
|
|
60
|
+
});
|
|
61
|
+
export const UnsupportedCapabilityDataSchema = z.object({ capability: z.string() });
|
|
62
|
+
export const EngineFailureDataSchema = z.object({});
|
|
63
|
+
const FAULT_DATA_SCHEMAS = {
|
|
64
|
+
Unauthorized: UnauthorizedDataSchema,
|
|
65
|
+
Forbidden: ForbiddenDataSchema,
|
|
66
|
+
NotFound: NotFoundDataSchema,
|
|
67
|
+
Conflict: ConflictDataSchema,
|
|
68
|
+
Unprocessable: UnprocessableDataSchema,
|
|
69
|
+
Timeout: TimeoutDataSchema,
|
|
70
|
+
PayloadTooLarge: PayloadTooLargeDataSchema,
|
|
71
|
+
NotImplemented: NotImplementedDataSchema,
|
|
72
|
+
UnsupportedTransport: UnsupportedTransportDataSchema,
|
|
73
|
+
SubscriptionOverflow: SubscriptionOverflowDataSchema,
|
|
74
|
+
InvalidParams: InvalidParamsDataSchema,
|
|
75
|
+
MethodNotFound: MethodNotFoundDataSchema,
|
|
76
|
+
StaleRevision: StaleRevisionDataSchema,
|
|
77
|
+
RateLimited: RateLimitedDataSchema,
|
|
78
|
+
Unavailable: UnavailableDataSchema,
|
|
79
|
+
UnsupportedCapability: UnsupportedCapabilityDataSchema,
|
|
80
|
+
EngineFailure: EngineFailureDataSchema,
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Add the two advice keys every JSON-RPC fault's `error.data` carries beside its payload:
|
|
84
|
+
* `retryable` always, `remediation` when the fault has one (see `faultWireAdvice`).
|
|
85
|
+
*/
|
|
86
|
+
function withFaultAdviceProperties(schema) {
|
|
87
|
+
const properties = (schema['properties'] ?? {});
|
|
88
|
+
const required = Array.isArray(schema['required']) ? schema['required'] : [];
|
|
89
|
+
return {
|
|
90
|
+
...schema,
|
|
91
|
+
properties: {
|
|
92
|
+
...properties,
|
|
93
|
+
retryable: {
|
|
94
|
+
type: 'boolean',
|
|
95
|
+
description: 'Whether repeating the identical call later can succeed',
|
|
96
|
+
},
|
|
97
|
+
remediation: {
|
|
98
|
+
type: 'string',
|
|
99
|
+
minLength: 1,
|
|
100
|
+
maxLength: MAX_REMEDIATION_LENGTH,
|
|
101
|
+
description: 'One line of plain text saying what to do next',
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
required: [...required, 'retryable'],
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Build the `components.errors` array for an OpenRPC document.
|
|
109
|
+
*
|
|
110
|
+
* Derived from `FAULT_CODE_TO_JSON_RPC_CODE` (the single source of truth).
|
|
111
|
+
* Every `FaultCode` in the closed union gets one entry with:
|
|
112
|
+
* - `code`: JSON-RPC error code
|
|
113
|
+
* - `message`: human-readable fault name
|
|
114
|
+
* - `data`: JSON Schema from the Zod schema for that fault's data payload
|
|
115
|
+
* - `x-http-status`: HTTP status code for REST callers
|
|
116
|
+
*/
|
|
117
|
+
export function buildOpenRpcComponentsErrors() {
|
|
118
|
+
const result = {};
|
|
119
|
+
for (const [faultCode, jsonRpcCode] of Object.entries(FAULT_CODE_TO_JSON_RPC_CODE)) {
|
|
120
|
+
const httpStatus = FAULT_CODE_TO_HTTP_STATUS[faultCode];
|
|
121
|
+
const dataSchema = FAULT_DATA_SCHEMAS[faultCode];
|
|
122
|
+
const jsonSchema = z.toJSONSchema(dataSchema, {
|
|
123
|
+
unrepresentable: 'any',
|
|
124
|
+
});
|
|
125
|
+
const { $schema: _unused, ...dataJsonSchema } = jsonSchema;
|
|
126
|
+
result[faultCode] = {
|
|
127
|
+
code: jsonRpcCode,
|
|
128
|
+
message: faultCode,
|
|
129
|
+
data: withFaultAdviceProperties(dataJsonSchema),
|
|
130
|
+
'x-http-status': httpStatus,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenRPC 1.3.2 document generator driven from the transport-neutral
|
|
3
|
+
* `OperationRegistry`. Produces a JSON-serializable OpenRPC document
|
|
4
|
+
* listing every operation whose transport availability intersects
|
|
5
|
+
* `OpenRpcOptions.transports`.
|
|
6
|
+
*
|
|
7
|
+
* - `transports: ['http']` → WebSocket-only methods are omitted
|
|
8
|
+
* (calling `weft.workflows.subscribe` over HTTP would return
|
|
9
|
+
* `UnsupportedTransport`, so the method should not appear in the
|
|
10
|
+
* HTTP-only document).
|
|
11
|
+
* - Every listed method carries `paramStructure: 'by-name'`, per-field
|
|
12
|
+
* `ContentDescriptor`s for human-readable surface, AND an
|
|
13
|
+
* `x-weft-paramsSchema` extension whose `additionalProperties` is
|
|
14
|
+
* computed from `unknownKeyPolicy.jsonRpc` (`'reject'` → false;
|
|
15
|
+
* `'strip'` / `'passthrough'` → true). The extension is the
|
|
16
|
+
* authoritative top-level object schema used by runtime enforcement
|
|
17
|
+
* and generator tooling; the per-field descriptors cannot drift
|
|
18
|
+
* from it by the "names match" invariant enforced in tests.
|
|
19
|
+
* - Every operation-catalog method carries the canonical `x-weft-access`
|
|
20
|
+
* metadata and, when applicable, `x-weft-parameterizedAccess`. The
|
|
21
|
+
* synthetic `rpc.discover` method is not an operation-catalog entry,
|
|
22
|
+
* but advertises its dispatcher-enforced public access posture explicitly.
|
|
23
|
+
* - `rpc.discover` is itself emitted as a method so clients can
|
|
24
|
+
* locate the document via JSON-RPC.
|
|
25
|
+
*
|
|
26
|
+
* @module server/openrpc
|
|
27
|
+
*/
|
|
28
|
+
import { type DiscoveryInfo } from "./discovery-info.js";
|
|
29
|
+
import type { OperationRegistry } from "./operation-catalog.js";
|
|
30
|
+
/** Transports that MAY be listed in `OpenRpcOptions.transports`. */
|
|
31
|
+
export type OpenRpcTransport = 'http' | 'websocket' | 'stdio';
|
|
32
|
+
export type OpenRpcOptions = {
|
|
33
|
+
/** Live operation registry. Only operations from this registry can be listed. */
|
|
34
|
+
readonly registry: OperationRegistry;
|
|
35
|
+
/** JSON-RPC transports whose methods should be included in the document. */
|
|
36
|
+
readonly transports: ReadonlyArray<OpenRpcTransport>;
|
|
37
|
+
/** Document title. Defaults to `discoveryInfo.title`, then to `'API'`. */
|
|
38
|
+
readonly title?: string;
|
|
39
|
+
/** Document version. Defaults to `discoveryInfo.version`, then to `'0.0.0'`. */
|
|
40
|
+
readonly version?: string;
|
|
41
|
+
/** Operator-supplied discovery metadata applied to the `info` object. */
|
|
42
|
+
readonly discoveryInfo?: DiscoveryInfo;
|
|
43
|
+
/** Optional server URL; emitted as a single-entry `servers` array. */
|
|
44
|
+
readonly serverUrl?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Live MCP `tools/list` output. Required when any listed operation is
|
|
47
|
+
* `mcpExposable`, because live MCP tool naming owns workflow-name collision
|
|
48
|
+
* handling.
|
|
49
|
+
*/
|
|
50
|
+
readonly mcpTools?: ReadonlyArray<{
|
|
51
|
+
readonly name: string;
|
|
52
|
+
readonly title?: string;
|
|
53
|
+
}>;
|
|
54
|
+
/**
|
|
55
|
+
* Whether the document carries the MCP discovery metadata (`x-weft-mcp`),
|
|
56
|
+
* which points at Weft's `/.well-known/mcp.json` and `tools/list`. Defaults
|
|
57
|
+
* to `true`. A server that does not serve MCP sets `false`, and the
|
|
58
|
+
* document lists no MCP route.
|
|
59
|
+
*/
|
|
60
|
+
readonly includeMcpMetadata?: boolean;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Generate an OpenRPC 1.3.2 document. See module doc-comment for the
|
|
64
|
+
* runtime-filtering contract.
|
|
65
|
+
*/
|
|
66
|
+
export declare function generateOpenRpcDocument(options: OpenRpcOptions): Record<string, unknown>;
|
package/dist/openrpc.js
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenRPC 1.3.2 document generator driven from the transport-neutral
|
|
3
|
+
* `OperationRegistry`. Produces a JSON-serializable OpenRPC document
|
|
4
|
+
* listing every operation whose transport availability intersects
|
|
5
|
+
* `OpenRpcOptions.transports`.
|
|
6
|
+
*
|
|
7
|
+
* - `transports: ['http']` → WebSocket-only methods are omitted
|
|
8
|
+
* (calling `weft.workflows.subscribe` over HTTP would return
|
|
9
|
+
* `UnsupportedTransport`, so the method should not appear in the
|
|
10
|
+
* HTTP-only document).
|
|
11
|
+
* - Every listed method carries `paramStructure: 'by-name'`, per-field
|
|
12
|
+
* `ContentDescriptor`s for human-readable surface, AND an
|
|
13
|
+
* `x-weft-paramsSchema` extension whose `additionalProperties` is
|
|
14
|
+
* computed from `unknownKeyPolicy.jsonRpc` (`'reject'` → false;
|
|
15
|
+
* `'strip'` / `'passthrough'` → true). The extension is the
|
|
16
|
+
* authoritative top-level object schema used by runtime enforcement
|
|
17
|
+
* and generator tooling; the per-field descriptors cannot drift
|
|
18
|
+
* from it by the "names match" invariant enforced in tests.
|
|
19
|
+
* - Every operation-catalog method carries the canonical `x-weft-access`
|
|
20
|
+
* metadata and, when applicable, `x-weft-parameterizedAccess`. The
|
|
21
|
+
* synthetic `rpc.discover` method is not an operation-catalog entry,
|
|
22
|
+
* but advertises its dispatcher-enforced public access posture explicitly.
|
|
23
|
+
* - `rpc.discover` is itself emitted as a method so clients can
|
|
24
|
+
* locate the document via JSON-RPC.
|
|
25
|
+
*
|
|
26
|
+
* @module server/openrpc
|
|
27
|
+
*/
|
|
28
|
+
import { z } from 'zod';
|
|
29
|
+
import { serializeAccessPolicy, serializeParameterizedAccess, } from "./access-policy-metadata.js";
|
|
30
|
+
import { isDiscoverable } from "./discovery-filter.js";
|
|
31
|
+
import { applyDiscoveryInfo, resolveDocumentTitleAndVersion, } from "./discovery-info.js";
|
|
32
|
+
import { asPlainObject, compareStrings } from "./json-schema-utilities.js";
|
|
33
|
+
import { MCP_DISCOVERY_PATH, MCP_TOOLS_LIST_METHOD } from "./mcp-discovery-names.js";
|
|
34
|
+
import { OpenRpcDocumentSchema } from "./openrpc-document-schema.js";
|
|
35
|
+
import { buildOpenRpcComponentsErrors } from "./openrpc-errors.js";
|
|
36
|
+
import { UNIVERSAL_FAULT_DEFAULTS } from "./operation-catalog/universal-faults.js";
|
|
37
|
+
import { zodToJsonSchema } from "./zod-json-schema.js";
|
|
38
|
+
/**
|
|
39
|
+
* Generate an OpenRPC 1.3.2 document. See module doc-comment for the
|
|
40
|
+
* runtime-filtering contract.
|
|
41
|
+
*/
|
|
42
|
+
export function generateOpenRpcDocument(options) {
|
|
43
|
+
const methods = [];
|
|
44
|
+
const mcpTools = [];
|
|
45
|
+
let registryProvidesDiscover = false;
|
|
46
|
+
for (const operation of options.registry.list()) {
|
|
47
|
+
if (!isOperationLiveOnJsonRpc(operation, options.transports))
|
|
48
|
+
continue;
|
|
49
|
+
if (!isDiscoverable(operation))
|
|
50
|
+
continue;
|
|
51
|
+
if (operation.name === DISCOVER_METHOD_NAME) {
|
|
52
|
+
// Consumers may register their own `rpc.discover` operation —
|
|
53
|
+
// use theirs verbatim and skip the synthetic one so we never
|
|
54
|
+
// emit duplicate method names.
|
|
55
|
+
registryProvidesDiscover = true;
|
|
56
|
+
}
|
|
57
|
+
const method = buildMethod(operation);
|
|
58
|
+
// Only an engine-served workflow tool (with `mcpTool`) has a live tool to resolve here.
|
|
59
|
+
if (operation.mcpTool !== undefined && options.includeMcpMetadata !== false) {
|
|
60
|
+
const metadata = buildMethodMcpMetadata(operation.name, operation.mcpTool.workflowType, options.mcpTools);
|
|
61
|
+
method['x-weft-mcp'] = metadata;
|
|
62
|
+
mcpTools.push({ toolName: metadata.toolName });
|
|
63
|
+
}
|
|
64
|
+
methods.push(method);
|
|
65
|
+
}
|
|
66
|
+
if (!registryProvidesDiscover && options.transports.length > 0) {
|
|
67
|
+
methods.push(buildDiscoverMethod());
|
|
68
|
+
}
|
|
69
|
+
const document = {
|
|
70
|
+
openrpc: '1.3.2',
|
|
71
|
+
info: buildOpenRpcInfo(options),
|
|
72
|
+
methods,
|
|
73
|
+
components: {
|
|
74
|
+
errors: buildOpenRpcComponentsErrors(),
|
|
75
|
+
},
|
|
76
|
+
...(options.includeMcpMetadata === false
|
|
77
|
+
? {}
|
|
78
|
+
: { 'x-weft-mcp': buildDocumentMcpMetadata(mcpTools) }),
|
|
79
|
+
};
|
|
80
|
+
applyOpenRpcServer(document, options.serverUrl);
|
|
81
|
+
return document;
|
|
82
|
+
}
|
|
83
|
+
const DISCOVER_METHOD_NAME = 'rpc.discover';
|
|
84
|
+
function buildOpenRpcInfo(options) {
|
|
85
|
+
const infoBlock = applyDiscoveryInfo(resolveDocumentTitleAndVersion(options, options.discoveryInfo), options.discoveryInfo);
|
|
86
|
+
if (options.discoveryInfo?.externalDocs !== undefined) {
|
|
87
|
+
infoBlock['externalDocs'] = { ...options.discoveryInfo.externalDocs };
|
|
88
|
+
}
|
|
89
|
+
return infoBlock;
|
|
90
|
+
}
|
|
91
|
+
function applyOpenRpcServer(document, serverUrl) {
|
|
92
|
+
if (serverUrl) {
|
|
93
|
+
document['servers'] = [{ url: serverUrl }];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function buildDocumentMcpMetadata(tools) {
|
|
97
|
+
return {
|
|
98
|
+
discoveryPath: MCP_DISCOVERY_PATH,
|
|
99
|
+
toolDiscoveryMethod: MCP_TOOLS_LIST_METHOD,
|
|
100
|
+
toolNames: [...tools].map((tool) => tool.toolName).toSorted(compareStrings),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function buildMethodMcpMetadata(operationName, workflowType, mcpTools) {
|
|
104
|
+
const toolName = resolveLiveMcpToolName(operationName, workflowType, mcpTools);
|
|
105
|
+
return {
|
|
106
|
+
workflowType,
|
|
107
|
+
toolName,
|
|
108
|
+
toolDiscovery: {
|
|
109
|
+
method: MCP_TOOLS_LIST_METHOD,
|
|
110
|
+
source: 'live',
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function resolveLiveMcpToolName(operationName, workflowType, mcpTools) {
|
|
115
|
+
if (mcpTools === undefined) {
|
|
116
|
+
throw new Error(`openrpc: operation ${operationName} is mcpExposable but no live MCP tools/list metadata was provided`);
|
|
117
|
+
}
|
|
118
|
+
const matches = mcpTools.filter((tool) => tool.title === workflowType);
|
|
119
|
+
if (matches.length !== 1) {
|
|
120
|
+
throw new Error(`openrpc: operation ${operationName} maps to workflow "${workflowType}", but live MCP tools/list returned ${matches.length} matching tools`);
|
|
121
|
+
}
|
|
122
|
+
return matches[0].name;
|
|
123
|
+
}
|
|
124
|
+
function isOperationLiveOnJsonRpc(operation, transports) {
|
|
125
|
+
const available = operation.transports;
|
|
126
|
+
for (const transport of transports) {
|
|
127
|
+
if (transportIsAvailable(transport, available))
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
function transportIsAvailable(transport, available) {
|
|
133
|
+
switch (transport) {
|
|
134
|
+
case 'http':
|
|
135
|
+
return available.jsonRpcHttp;
|
|
136
|
+
case 'websocket':
|
|
137
|
+
return available.jsonRpcWebSocket;
|
|
138
|
+
case 'stdio':
|
|
139
|
+
return available.jsonRpcStdio;
|
|
140
|
+
default:
|
|
141
|
+
// Exhaustiveness check: a new `OpenRpcTransport` literal will
|
|
142
|
+
// cause a compile error here instead of silently being
|
|
143
|
+
// blackholed as "unavailable" for every operation.
|
|
144
|
+
transport;
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function buildMethod(operation) {
|
|
149
|
+
// The registry's `createOperationRegistry` enforces that every
|
|
150
|
+
// `inputSchema` is a `z.ZodObject` at construction; this cast is
|
|
151
|
+
// safe by construction. Fail fast if something downstream ever
|
|
152
|
+
// violates that invariant — a silent `params: []` would produce a
|
|
153
|
+
// misleading discovery document.
|
|
154
|
+
if (!(operation.inputSchema instanceof z.ZodObject)) {
|
|
155
|
+
throw new Error(`openrpc: operation ${operation.name} has non-object inputSchema; generator requires z.ZodObject`);
|
|
156
|
+
}
|
|
157
|
+
const inputSchema = operation.inputSchema;
|
|
158
|
+
const paramsSchema = zodObjectToJsonSchema(inputSchema, operation.unknownKeyPolicy.jsonRpc);
|
|
159
|
+
const descriptors = buildContentDescriptors(paramsSchema);
|
|
160
|
+
const resultSchema = zodToJsonSchema(operation.outputSchema, 'output');
|
|
161
|
+
const method = {
|
|
162
|
+
name: operation.name,
|
|
163
|
+
paramStructure: 'by-name',
|
|
164
|
+
params: descriptors,
|
|
165
|
+
result: { name: 'result', schema: resultSchema, required: true },
|
|
166
|
+
'x-weft-paramsSchema': paramsSchema,
|
|
167
|
+
'x-weft-access': serializeAccessPolicy(operation.access),
|
|
168
|
+
};
|
|
169
|
+
if (operation.summary)
|
|
170
|
+
method.summary = operation.summary;
|
|
171
|
+
if (operation.description !== undefined)
|
|
172
|
+
method.description = operation.description;
|
|
173
|
+
if (operation.tags.length > 0) {
|
|
174
|
+
method.tags = [...operation.tags].toSorted(compareStrings).map((name) => ({ name }));
|
|
175
|
+
}
|
|
176
|
+
if (operation.parameterizedAccess !== undefined) {
|
|
177
|
+
method['x-weft-parameterizedAccess'] = serializeParameterizedAccess(operation.parameterizedAccess);
|
|
178
|
+
}
|
|
179
|
+
method.errors = buildMethodErrorReferences(operation);
|
|
180
|
+
return method;
|
|
181
|
+
}
|
|
182
|
+
function buildDiscoverMethod() {
|
|
183
|
+
return {
|
|
184
|
+
name: 'rpc.discover',
|
|
185
|
+
summary: 'Return the OpenRPC document for this server',
|
|
186
|
+
paramStructure: 'by-name',
|
|
187
|
+
params: [],
|
|
188
|
+
result: {
|
|
189
|
+
name: 'openRpcDocument',
|
|
190
|
+
schema: zodToJsonSchema(OpenRpcDocumentSchema),
|
|
191
|
+
required: true,
|
|
192
|
+
},
|
|
193
|
+
errors: buildUniversalErrorReferences(),
|
|
194
|
+
'x-weft-paramsSchema': {
|
|
195
|
+
type: 'object',
|
|
196
|
+
properties: {},
|
|
197
|
+
required: [],
|
|
198
|
+
additionalProperties: false,
|
|
199
|
+
},
|
|
200
|
+
'x-weft-access': { kind: 'public' },
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
const UNIVERSAL_FAULT_CODES = [...UNIVERSAL_FAULT_DEFAULTS];
|
|
204
|
+
function buildMethodErrorReferences(operation) {
|
|
205
|
+
const faultCodes = new Set(UNIVERSAL_FAULT_CODES);
|
|
206
|
+
for (const faultCode of operation.producibleFaults ?? []) {
|
|
207
|
+
faultCodes.add(faultCode);
|
|
208
|
+
}
|
|
209
|
+
return [...faultCodes].map((faultCode) => ({
|
|
210
|
+
$ref: `#/components/errors/${faultCode}`,
|
|
211
|
+
}));
|
|
212
|
+
}
|
|
213
|
+
function buildUniversalErrorReferences() {
|
|
214
|
+
return UNIVERSAL_FAULT_CODES.map((faultCode) => ({
|
|
215
|
+
$ref: `#/components/errors/${faultCode}`,
|
|
216
|
+
}));
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Convert a `z.ZodObject` to a top-level JSON Schema for OpenRPC
|
|
220
|
+
* `params`. The shape's own keys and required fields come from zod;
|
|
221
|
+
* `additionalProperties` is stamped per `unknownKeyPolicy.jsonRpc`.
|
|
222
|
+
* Nested objects retain whatever `additionalProperties` zod emits
|
|
223
|
+
* from their own strict / strip / passthrough modes.
|
|
224
|
+
*/
|
|
225
|
+
function zodObjectToJsonSchema(schema, jsonRpcPolicy) {
|
|
226
|
+
const base = zodToJsonSchema(schema);
|
|
227
|
+
return {
|
|
228
|
+
...base,
|
|
229
|
+
additionalProperties: jsonRpcPolicy !== 'reject',
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
function buildContentDescriptors(paramsSchema) {
|
|
233
|
+
const properties = asPlainObject(paramsSchema['properties']);
|
|
234
|
+
const requiredList = asStringArray(paramsSchema['required']);
|
|
235
|
+
// If the parent schema carries `$defs` (zod emits this for reused or
|
|
236
|
+
// recursive nested types), propagate it onto every descriptor so
|
|
237
|
+
// `$ref` pointers inside the property schema resolve locally. Without
|
|
238
|
+
// this, a property whose JSON Schema is `{ $ref: '#/$defs/X' }` would
|
|
239
|
+
// be emitted as a dangling reference under `params[].schema` while
|
|
240
|
+
// only the sibling `x-weft-paramsSchema` extension remained valid.
|
|
241
|
+
const defs = asPlainObjectOrUndefined(paramsSchema['$defs']);
|
|
242
|
+
const names = Object.keys(properties).toSorted(compareStrings);
|
|
243
|
+
const requiredSet = new Set(requiredList);
|
|
244
|
+
return names.map((name) => {
|
|
245
|
+
const baseSchema = asPlainObject(properties[name]);
|
|
246
|
+
const schema = defs ? { ...baseSchema, $defs: defs } : baseSchema;
|
|
247
|
+
return { name, schema, required: requiredSet.has(name) };
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
function asPlainObjectOrUndefined(value) {
|
|
251
|
+
if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
|
|
252
|
+
return value;
|
|
253
|
+
}
|
|
254
|
+
return undefined;
|
|
255
|
+
}
|
|
256
|
+
function asStringArray(value) {
|
|
257
|
+
if (!Array.isArray(value))
|
|
258
|
+
return [];
|
|
259
|
+
return value.filter((entry) => typeof entry === 'string');
|
|
260
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Serializable, producer-declared semantics for generated consumers. */
|
|
2
|
+
export type OperationBehavior = {
|
|
3
|
+
readonly kind: 'read';
|
|
4
|
+
readonly key?: readonly string[];
|
|
5
|
+
readonly pagination?: {
|
|
6
|
+
readonly items: string;
|
|
7
|
+
readonly cursorInput: string;
|
|
8
|
+
readonly nextCursor: string;
|
|
9
|
+
readonly total: string;
|
|
10
|
+
readonly cursorFilters: readonly string[];
|
|
11
|
+
readonly itemKey: readonly string[];
|
|
12
|
+
};
|
|
13
|
+
readonly cursor?: string;
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: 'command';
|
|
16
|
+
readonly invalidates?: readonly string[];
|
|
17
|
+
readonly observedInput?: {
|
|
18
|
+
readonly read: string;
|
|
19
|
+
readonly when: Readonly<Record<string, string>>;
|
|
20
|
+
readonly key: string;
|
|
21
|
+
readonly revision: string;
|
|
22
|
+
};
|
|
23
|
+
readonly conflictReasons?: readonly string[];
|
|
24
|
+
readonly replay?: {
|
|
25
|
+
readonly key: string;
|
|
26
|
+
readonly resource: string;
|
|
27
|
+
readonly read: string;
|
|
28
|
+
};
|
|
29
|
+
readonly responseDisposition?: 'one-time';
|
|
30
|
+
readonly effects?: {
|
|
31
|
+
readonly idempotent?: boolean;
|
|
32
|
+
readonly externalWorld?: boolean;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|