@procedures/client 0.8.0 → 0.9.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 +78 -0
- package/README.md +95 -8
- package/dist/.tsbuildinfo +1 -1
- package/dist/adapters/http/client/transport.d.ts +4 -0
- package/dist/adapters/http/client/transport.d.ts.map +1 -1
- package/dist/adapters/http/client/transport.js +11 -1
- package/dist/adapters/http/client/transport.js.map +1 -1
- package/dist/adapters/http/client/types.d.ts +19 -0
- package/dist/adapters/http/client/types.d.ts.map +1 -1
- package/dist/adapters/http/server/cors.d.ts +64 -0
- package/dist/adapters/http/server/cors.d.ts.map +1 -0
- package/dist/adapters/http/server/cors.js +113 -0
- package/dist/adapters/http/server/cors.js.map +1 -0
- package/dist/adapters/http/server/handler.d.ts +136 -0
- package/dist/adapters/http/server/handler.d.ts.map +1 -0
- package/dist/adapters/http/server/handler.js +495 -0
- package/dist/adapters/http/server/handler.js.map +1 -0
- package/dist/adapters/http/server/strategies.d.ts +14 -5
- package/dist/adapters/http/server/strategies.d.ts.map +1 -1
- package/dist/adapters/http/server/strategies.js.map +1 -1
- package/dist/adapters/http/server/transport.d.ts +30 -46
- package/dist/adapters/http/server/transport.d.ts.map +1 -1
- package/dist/adapters/http/server/transport.js +48 -432
- package/dist/adapters/http/server/transport.js.map +1 -1
- package/dist/adapters/http/server/types.d.ts +13 -0
- package/dist/adapters/http/server/types.d.ts.map +1 -1
- package/dist/adapters/websocket/client/transport.d.ts.map +1 -1
- package/dist/adapters/websocket/client/transport.js +4 -12
- package/dist/adapters/websocket/client/transport.js.map +1 -1
- package/dist/adapters/websocket/server/transport.d.ts +46 -1
- package/dist/adapters/websocket/server/transport.d.ts.map +1 -1
- package/dist/adapters/websocket/server/transport.js +152 -15
- package/dist/adapters/websocket/server/transport.js.map +1 -1
- package/dist/adapters/websocket/server/types.d.ts +10 -3
- package/dist/adapters/websocket/server/types.d.ts.map +1 -1
- package/dist/adapters/websocket/server/upgrade-router.d.ts +28 -0
- package/dist/adapters/websocket/server/upgrade-router.d.ts.map +1 -0
- package/dist/adapters/websocket/server/upgrade-router.js +62 -0
- package/dist/adapters/websocket/server/upgrade-router.js.map +1 -0
- package/dist/adapters/websocket/server/upgrade.d.ts +68 -0
- package/dist/adapters/websocket/server/upgrade.d.ts.map +1 -0
- package/dist/adapters/websocket/server/upgrade.js +49 -0
- package/dist/adapters/websocket/server/upgrade.js.map +1 -0
- package/dist/adapters/websocket/shared/rpc.d.ts +2 -0
- package/dist/adapters/websocket/shared/rpc.d.ts.map +1 -1
- package/dist/adapters/websocket/shared/rpc.js +8 -2
- package/dist/adapters/websocket/shared/rpc.js.map +1 -1
- package/dist/browser.d.ts +12 -4
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +13 -2
- package/dist/browser.js.map +1 -1
- package/dist/client/client.d.ts +43 -0
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +69 -1
- package/dist/client/client.js.map +1 -1
- package/dist/events/publisher.d.ts +25 -1
- package/dist/events/publisher.d.ts.map +1 -1
- package/dist/events/publisher.js +66 -9
- package/dist/events/publisher.js.map +1 -1
- package/dist/events/rows.d.ts +31 -0
- package/dist/events/rows.d.ts.map +1 -0
- package/dist/events/rows.js +39 -0
- package/dist/events/rows.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +14 -0
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +9 -0
- package/dist/node.js.map +1 -1
- package/dist/procedures/capability.d.ts +6 -0
- package/dist/procedures/capability.d.ts.map +1 -1
- package/dist/procedures/capability.js +25 -0
- package/dist/procedures/capability.js.map +1 -1
- package/dist/procedures/collection/changes.d.ts +94 -0
- package/dist/procedures/collection/changes.d.ts.map +1 -0
- package/dist/procedures/collection/changes.js +182 -0
- package/dist/procedures/collection/changes.js.map +1 -0
- package/dist/procedures/collection/index.d.ts +10 -3
- package/dist/procedures/collection/index.d.ts.map +1 -1
- package/dist/procedures/collection/index.js +8 -1
- package/dist/procedures/collection/index.js.map +1 -1
- package/dist/procedures/collection/partition.d.ts +67 -0
- package/dist/procedures/collection/partition.d.ts.map +1 -0
- package/dist/procedures/collection/partition.js +82 -0
- package/dist/procedures/collection/partition.js.map +1 -0
- package/dist/procedures/collection/procedures.d.ts +39 -2
- package/dist/procedures/collection/procedures.d.ts.map +1 -1
- package/dist/procedures/collection/procedures.js +147 -44
- package/dist/procedures/collection/procedures.js.map +1 -1
- package/dist/procedures/collection/query.d.ts +246 -0
- package/dist/procedures/collection/query.d.ts.map +1 -0
- package/dist/procedures/collection/query.js +854 -0
- package/dist/procedures/collection/query.js.map +1 -0
- package/dist/procedures/collection/schemas.d.ts +50 -0
- package/dist/procedures/collection/schemas.d.ts.map +1 -1
- package/dist/procedures/collection/schemas.js +144 -6
- package/dist/procedures/collection/schemas.js.map +1 -1
- package/dist/procedures/collection/storage.d.ts +58 -6
- package/dist/procedures/collection/storage.d.ts.map +1 -1
- package/dist/procedures/collection/storage.js +23 -0
- package/dist/procedures/collection/storage.js.map +1 -1
- package/dist/procedures/elicit.d.ts +190 -0
- package/dist/procedures/elicit.d.ts.map +1 -0
- package/dist/procedures/elicit.js +127 -0
- package/dist/procedures/elicit.js.map +1 -0
- package/dist/procedures/hints.d.ts +43 -0
- package/dist/procedures/hints.d.ts.map +1 -0
- package/dist/procedures/hints.js +74 -0
- package/dist/procedures/hints.js.map +1 -0
- package/dist/procedures/index.d.ts +9 -2
- package/dist/procedures/index.d.ts.map +1 -1
- package/dist/procedures/index.js +5 -1
- package/dist/procedures/index.js.map +1 -1
- package/dist/procedures/invoke.d.ts +24 -2
- package/dist/procedures/invoke.d.ts.map +1 -1
- package/dist/procedures/invoke.js +14 -1
- package/dist/procedures/invoke.js.map +1 -1
- package/dist/procedures/progress.d.ts +24 -0
- package/dist/procedures/progress.d.ts.map +1 -0
- package/dist/procedures/progress.js +11 -0
- package/dist/procedures/progress.js.map +1 -0
- package/dist/procedures/registry.d.ts.map +1 -1
- package/dist/procedures/registry.js +5 -0
- package/dist/procedures/registry.js.map +1 -1
- package/dist/procedures/types.d.ts +55 -0
- package/dist/procedures/types.d.ts.map +1 -1
- package/dist/procedures/types.js.map +1 -1
- package/dist/procedures/untrusted.d.ts +28 -0
- package/dist/procedures/untrusted.d.ts.map +1 -0
- package/dist/procedures/untrusted.js +32 -0
- package/dist/procedures/untrusted.js.map +1 -0
- package/dist/server/browser-guard.d.ts +12 -2
- package/dist/server/browser-guard.d.ts.map +1 -1
- package/dist/server/browser-guard.js +43 -6
- package/dist/server/browser-guard.js.map +1 -1
- package/dist/server/host-policy.d.ts +10 -1
- package/dist/server/host-policy.d.ts.map +1 -1
- package/dist/server/host-policy.js +5 -0
- package/dist/server/host-policy.js.map +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/procedure-server.d.ts +68 -7
- package/dist/server/procedure-server.d.ts.map +1 -1
- package/dist/server/procedure-server.js +124 -24
- package/dist/server/procedure-server.js.map +1 -1
- package/dist/server/request-auth.d.ts +51 -4
- package/dist/server/request-auth.d.ts.map +1 -1
- package/dist/server/request-auth.js +116 -5
- package/dist/server/request-auth.js.map +1 -1
- package/dist/server/types.d.ts +73 -5
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/types.js.map +1 -1
- package/package.json +7 -3
- package/src/adapters/http/client/transport.ts +11 -1
- package/src/adapters/http/client/types.ts +22 -0
- package/src/adapters/http/server/cors.ts +144 -0
- package/src/adapters/http/server/handler.ts +624 -0
- package/src/adapters/http/server/strategies.ts +16 -6
- package/src/adapters/http/server/transport.ts +55 -478
- package/src/adapters/http/server/types.ts +15 -0
- package/src/adapters/websocket/client/transport.ts +4 -12
- package/src/adapters/websocket/server/transport.ts +166 -16
- package/src/adapters/websocket/server/types.ts +11 -3
- package/src/adapters/websocket/server/upgrade-router.ts +77 -0
- package/src/adapters/websocket/server/upgrade.ts +88 -0
- package/src/adapters/websocket/shared/rpc.ts +9 -2
- package/src/browser.ts +85 -2
- package/src/client/client.ts +83 -1
- package/src/events/publisher.ts +75 -11
- package/src/events/rows.ts +48 -0
- package/src/index.ts +1 -1
- package/src/node.ts +21 -0
- package/src/procedures/capability.ts +21 -0
- package/src/procedures/collection/changes.ts +245 -0
- package/src/procedures/collection/index.ts +57 -1
- package/src/procedures/collection/partition.ts +123 -0
- package/src/procedures/collection/procedures.ts +206 -51
- package/src/procedures/collection/query.ts +1009 -0
- package/src/procedures/collection/schemas.ts +196 -7
- package/src/procedures/collection/storage.ts +78 -6
- package/src/procedures/elicit.ts +320 -0
- package/src/procedures/hints.ts +91 -0
- package/src/procedures/index.ts +83 -2
- package/src/procedures/invoke.ts +33 -2
- package/src/procedures/progress.ts +25 -0
- package/src/procedures/registry.ts +4 -0
- package/src/procedures/types.ts +65 -0
- package/src/procedures/untrusted.ts +50 -0
- package/src/server/browser-guard.ts +48 -6
- package/src/server/host-policy.ts +13 -1
- package/src/server/index.ts +3 -0
- package/src/server/procedure-server.ts +147 -26
- package/src/server/request-auth.ts +128 -6
- package/src/server/types.ts +82 -5
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
* procedures (a host for an outside caller sets it).
|
|
13
13
|
* - `timeout`: the time limit of each call from a caller (not of its nested calls).
|
|
14
14
|
* - `token`, `browser`: the checks of the network transports (`client-server` applies them).
|
|
15
|
+
* - `principalOf`: the request hook. It reads the credentials of a network request (a cookie, a
|
|
16
|
+
* header, the query) and gives a bearer token, a principal and a narrowing.
|
|
15
17
|
* - `capability`, `readOnly`, `clearanceOrder`, `resources`, `admitItem`: the capability of each
|
|
16
18
|
* call and what the host gives for it (CAPABILITIES-2026-10).
|
|
17
19
|
* - `events`: the remote events of the host (`documentation/EVENTS.md`). The server pins
|
|
@@ -19,7 +21,7 @@
|
|
|
19
21
|
*/
|
|
20
22
|
import type { Capability, ClearanceOrder, ProcedurePath, ResourcesOf } from "../procedures/types.js";
|
|
21
23
|
import type { AdmitItem, Interceptor, Invocation } from "../procedures/invoke.js";
|
|
22
|
-
import type { ServerRequest } from "./types.js";
|
|
24
|
+
import type { PrincipalOf, ServerRequest } from "./types.js";
|
|
23
25
|
import type { BrowserGuardOptions } from "./browser-guard.js";
|
|
24
26
|
import type { ProcedureRegistry } from "../procedures/registry.js";
|
|
25
27
|
import type { ProcedureServerOptions } from "./procedure-server.js";
|
|
@@ -48,6 +50,11 @@ export interface HostPolicyOptions {
|
|
|
48
50
|
interceptors?: readonly Interceptor[] | undefined;
|
|
49
51
|
/** The token that each network request must send (HTTP and WebSocket transports). */
|
|
50
52
|
token?: string | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* The request hook: it reads the credentials of each network request (a cookie, a header, the
|
|
55
|
+
* query) and gives a bearer token, a principal and a narrowing (`ProcedureServerOptions`).
|
|
56
|
+
*/
|
|
57
|
+
principalOf?: PrincipalOf | undefined;
|
|
51
58
|
/** The browser checks of the network transports (`allowedOrigins`, `allowedHosts`, `allowGet`). */
|
|
52
59
|
browser?: BrowserGuardOptions | undefined;
|
|
53
60
|
/**
|
|
@@ -77,6 +84,8 @@ export interface HostPolicy {
|
|
|
77
84
|
readonly strictCalls: boolean;
|
|
78
85
|
readonly interceptors: readonly Interceptor[];
|
|
79
86
|
readonly token: string | undefined;
|
|
87
|
+
/** The request hook of the network requests, or undefined for none. */
|
|
88
|
+
readonly principalOf?: PrincipalOf | undefined;
|
|
80
89
|
readonly browser: BrowserGuardOptions;
|
|
81
90
|
/** The capability of a call from a caller, or undefined for no limits. */
|
|
82
91
|
readonly capabilityOf: ((request?: ServerRequest<unknown>) => Capability | undefined) | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-policy.d.ts","sourceRoot":"","sources":["../../src/server/host-policy.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"host-policy.d.ts","sourceRoot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ACvE,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IAC/C,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAC;IACtC,0EAA0E;IAC1E,QAAQ,CAAC,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,KAAK,UAAU,GAAG,SAAS,CAAC,GAAG,SAAS,CAAC;IAClG,QAAQ,CAAC,cAAc,EAAE,cAAc,GAAG,SAAS,CAAC;IACpD,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,UAAU,EAAE,UAAU,KAAK,WAAW,CAAC,GAAG,SAAS,CAAC;IAC1E,QAAQ,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,CAAC;IAC1C,+FAA+F;IAC/F,QAAQ,CAAC,MAAM,EAAE,qBAAqB,GAAG,SAAS,CAAC;CACpD;AA4BD,kEAAkE;AAClE,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,UAAU,CAmBtE;AAED,gFAAgF;AAChF,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,iBAAiB,GAAG,sBAAsB,CAkB/G"}
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
* procedures (a host for an outside caller sets it).
|
|
13
13
|
* - `timeout`: the time limit of each call from a caller (not of its nested calls).
|
|
14
14
|
* - `token`, `browser`: the checks of the network transports (`client-server` applies them).
|
|
15
|
+
* - `principalOf`: the request hook. It reads the credentials of a network request (a cookie, a
|
|
16
|
+
* header, the query) and gives a bearer token, a principal and a narrowing.
|
|
15
17
|
* - `capability`, `readOnly`, `clearanceOrder`, `resources`, `admitItem`: the capability of each
|
|
16
18
|
* call and what the host gives for it (CAPABILITIES-2026-10).
|
|
17
19
|
* - `events`: the remote events of the host (`documentation/EVENTS.md`). The server pins
|
|
@@ -83,6 +85,7 @@ export function hostPolicy(options = {}) {
|
|
|
83
85
|
strictCalls: options.strictCalls ?? false,
|
|
84
86
|
interceptors,
|
|
85
87
|
token: options.token,
|
|
88
|
+
...(options.principalOf ? { principalOf: options.principalOf } : {}),
|
|
86
89
|
browser: options.browser ?? {},
|
|
87
90
|
capabilityOf: capabilityOfOptions(options),
|
|
88
91
|
clearanceOrder: options.clearanceOrder,
|
|
@@ -100,6 +103,8 @@ export function procedureServerOptions(policy, registry) {
|
|
|
100
103
|
strictCalls: policy.strictCalls,
|
|
101
104
|
// The token of the policy: ProcedureServer examines it for each network request (R18)
|
|
102
105
|
...(policy.token !== undefined ? { token: policy.token } : {}),
|
|
106
|
+
// The request hook of the policy: the credentials of a cookie, a header or the query (CLI-2a)
|
|
107
|
+
...(policy.principalOf ? { principalOf: policy.principalOf } : {}),
|
|
103
108
|
...(policy.interceptors.length > 0 ? { interceptors: policy.interceptors } : {}),
|
|
104
109
|
...(policy.capabilityOf ? { capability: policy.capabilityOf } : {}),
|
|
105
110
|
...(policy.clearanceOrder ? { clearanceOrder: policy.clearanceOrder } : {}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-policy.js","sourceRoot":"","sources":["../../src/server/host-policy.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"host-policy.js","sourceRoot":"","sources":["../../src/server/host-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAKnE,OAAO,EAAE,IAAI,EAAiB,MAAM,gBAAgB,CAAC;AAQrD,8FAA8F;AAC9F,MAAM,UAAU,cAAc,CAAC,QAA2B;IACxD,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,IAAI,GAAG,GAAG,KAAK,CAAC;IAChB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;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CHANGED
|
@@ -38,7 +38,7 @@ export type { ServerOptions } from "./server.js";
|
|
|
38
38
|
export { ProcedureServer, createProcedureServer, STREAM_METADATA_KEY, isUnboundedStream } from "./procedure-server.js";
|
|
39
39
|
export type { ProcedureServerOptions, StorageConfig, StopOptions, UseStorageOptions } from "./procedure-server.js";
|
|
40
40
|
export { pathToMethod, methodToPath } from "./method.js";
|
|
41
|
-
export { HandlerNotFoundError, ServerError, type ServerRequest, type ServerResponse, type RequestHandler, type Credentials, type Principal, type ServerHandler, type ServerMiddleware, type ServerContext, type ServerRunner, type ServerTransport, } from "./types.js";
|
|
41
|
+
export { HandlerNotFoundError, ServerError, type ServerRequest, type ServerResponse, type RequestHandler, type Credentials, type Principal, type PrincipalOf, type RequestIdentity, type AmbientCredentials, type ServerHandler, type ServerMiddleware, type ServerContext, type ServerRunner, type ServerTransport, } from "./types.js";
|
|
42
42
|
export { HttpServerTransport, defaultServerUrlStrategy, rpcServerUrlStrategy, } from "../adapters/http/server/index.js";
|
|
43
43
|
export type { HttpServerTransportOptions, HttpUrlStrategy, } from "../adapters/http/server/index.js";
|
|
44
44
|
export { WebSocketServerTransport } from "../adapters/websocket/server/index.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AACvH,YAAY,EAAE,sBAAsB,EAAE,aAAa,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AACnH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACzD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ACrB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,eAAe,GACrB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,kCAAkC,CAAC;AAC1C,YAAY,EACV,0BAA0B,EAC1B,eAAe,GAChB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AACjF,YAAY,EACV,+BAA+B,EAC/B,oBAAoB,EACpB,0BAA0B,EAC1B,gBAAgB,GACjB,MAAM,uCAAuC,CAAC"}
|
package/dist/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAEvH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EACL,oBAAoB,EACpB,WAAW,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAEvH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EACL,oBAAoB,EACpB,WAAW,GAcZ,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,kCAAkC,CAAC;AAK1C,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC"}
|
|
@@ -5,16 +5,18 @@
|
|
|
5
5
|
* Integrates with ProcedureRegistry and CollectionStorage backends.
|
|
6
6
|
*/
|
|
7
7
|
import { Server, type ServerOptions } from "./server.js";
|
|
8
|
-
import type { Method, Principal, ServerHandler, ServerRequest, ServerResponse } from "./types.js";
|
|
8
|
+
import type { AmbientCredentials, Method, Principal, PrincipalOf, ServerHandler, ServerRequest, ServerResponse } from "./types.js";
|
|
9
9
|
import type { AnyProcedure, ProcedurePath, RepositoryProvider, ProcedureModule } from "../procedures/types.js";
|
|
10
10
|
import { ProcedureRegistry } from "../procedures/registry.js";
|
|
11
11
|
import { type AdmitItem, type Interceptor, type Invocation } from "../procedures/invoke.js";
|
|
12
|
-
import type { Capability, ClearanceOrder, ResourcesOf } from "../procedures/types.js";
|
|
12
|
+
import type { Capability, ClearanceOrder, ProcedureContext, ResourcesOf } from "../procedures/types.js";
|
|
13
|
+
import type { CollectionPartitions } from "../procedures/collection/partition.js";
|
|
13
14
|
import { type IdempotencyOptions } from "../procedures/idempotency.js";
|
|
14
15
|
import { type Duration } from "../duration.js";
|
|
15
16
|
import type { CollectionStorage } from "../procedures/collection/storage.js";
|
|
16
17
|
import { type Clock } from "../clock.js";
|
|
17
18
|
import { EventPublisher, type EventPublisherOptions } from "../events/publisher.js";
|
|
19
|
+
import type { CollectionProceduresOptions } from "../procedures/collection/procedures.js";
|
|
18
20
|
/**
|
|
19
21
|
* Storage configuration for a collection.
|
|
20
22
|
*/
|
|
@@ -108,6 +110,22 @@ export interface ProcedureServerOptions extends ServerOptions {
|
|
|
108
110
|
* `request.principal`.
|
|
109
111
|
*/
|
|
110
112
|
authenticate?: ((request: ServerRequest<unknown>) => Principal | undefined | Promise<Principal | undefined>) | undefined;
|
|
113
|
+
/**
|
|
114
|
+
* The request hook of the server: it reads the credentials of each network request (a cookie, a
|
|
115
|
+
* header, the query) and gives a bearer token, a principal and a narrowing. It runs before the
|
|
116
|
+
* token check: its bearer token replaces the bearer token of the credentials. Its principal
|
|
117
|
+
* replaces the principal of the token check. `authenticate` runs after it and can read
|
|
118
|
+
* `request.principal`. Undefined or an error refuses the request with `UNAUTHORIZED`. A request
|
|
119
|
+
* without credentials (from this process) does not go through the hook.
|
|
120
|
+
*/
|
|
121
|
+
principalOf?: PrincipalOf | undefined;
|
|
122
|
+
/**
|
|
123
|
+
* How the server can authenticate a request with ambient credentials (cookies), for the CSRF
|
|
124
|
+
* checks of the network faces. The default is `"always"` with `principalOf`, `"cookies"` with
|
|
125
|
+
* `authenticate`, and none without them. `false`: the server reads no cookies, for example an
|
|
126
|
+
* `authenticate` function that reads only the bearer token.
|
|
127
|
+
*/
|
|
128
|
+
ambientCredentials?: AmbientCredentials | false | undefined;
|
|
111
129
|
/**
|
|
112
130
|
* The remote events of the server (`documentation/EVENTS.md`): a bus and its topic rule, or an
|
|
113
131
|
* `EventPublisher`. The server pins the procedure `events.subscribe`, outside its registry, so a
|
|
@@ -177,6 +195,8 @@ export declare function errorResponse(id: string, error: unknown): ServerRespons
|
|
|
177
195
|
export declare class ProcedureServer extends Server implements RepositoryProvider {
|
|
178
196
|
private readonly procedureRegistry;
|
|
179
197
|
private readonly storages;
|
|
198
|
+
/** The partitions of each partitioned collection: their storages and their resolver (roadmap CLI-17) */
|
|
199
|
+
private readonly partitions;
|
|
180
200
|
/** For each storage: the calls in flight that took it, and the closes that wait for them */
|
|
181
201
|
private readonly storageUses;
|
|
182
202
|
/** The clock of the wait of `useStorage` */
|
|
@@ -206,13 +226,19 @@ export declare class ProcedureServer extends Server implements RepositoryProvide
|
|
|
206
226
|
private draining;
|
|
207
227
|
/** The calls in flight, a stream until its end */
|
|
208
228
|
private inFlight;
|
|
209
|
-
/** The token of the server, and its authenticate function (R18) */
|
|
229
|
+
/** The token of the server, its request hook and its authenticate function (R18) */
|
|
210
230
|
private readonly token;
|
|
231
|
+
private readonly principalOf;
|
|
211
232
|
private readonly authenticate;
|
|
212
233
|
/** The functions that `stop()` waits on: each one runs when no call is in flight */
|
|
213
234
|
private idleWaiters;
|
|
214
235
|
/** The publisher of the remote events, from the option `events`, or undefined. */
|
|
215
236
|
readonly publisher: EventPublisher | undefined;
|
|
237
|
+
/**
|
|
238
|
+
* How the server can authenticate a request with ambient credentials (cookies). The network faces
|
|
239
|
+
* read it: they trust such a request only from a named origin (CSRF).
|
|
240
|
+
*/
|
|
241
|
+
readonly ambientCredentials: AmbientCredentials | undefined;
|
|
216
242
|
constructor(options?: ProcedureServerOptions);
|
|
217
243
|
/**
|
|
218
244
|
* Get storage for a collection.
|
|
@@ -228,6 +254,32 @@ export declare class ProcedureServer extends Server implements RepositoryProvide
|
|
|
228
254
|
* @param collection - Collection name
|
|
229
255
|
*/
|
|
230
256
|
hasCollection(collection: string): boolean;
|
|
257
|
+
/**
|
|
258
|
+
* The storage of one partition of a collection (roadmap CLI-17).
|
|
259
|
+
*
|
|
260
|
+
* @throws Error if the collection has no partitions
|
|
261
|
+
*/
|
|
262
|
+
getPartitionStorage<T>(collection: string, partition: string): CollectionStorage<T>;
|
|
263
|
+
/** True when the collection has partitions (roadmap CLI-17). */
|
|
264
|
+
hasPartitions(collection: string): boolean;
|
|
265
|
+
/**
|
|
266
|
+
* The partition of a call to a partitioned collection (roadmap CLI-17), from the resolver of
|
|
267
|
+
* `usePartitions`. `null` refuses the call.
|
|
268
|
+
*
|
|
269
|
+
* @throws Error if the collection has no partitions
|
|
270
|
+
*/
|
|
271
|
+
resolvePartition(collection: string, ctx: ProcedureContext, requested: string | undefined): string | undefined | null | Promise<string | undefined | null>;
|
|
272
|
+
/**
|
|
273
|
+
* Configure the partitions of a collection (roadmap CLI-17). `resolve` gives the partition of
|
|
274
|
+
* each call from its context (the tenant of `ctx.principal`) and the partition that the call asks
|
|
275
|
+
* for: the collection procedures and the subscriptions of `EventPublisher` use it. `storageOf`
|
|
276
|
+
* gives the storage of a partition: give the same storage for the same partition each time.
|
|
277
|
+
*
|
|
278
|
+
* @param name - Collection name
|
|
279
|
+
* @param partitions - The storage of each partition, and the resolver
|
|
280
|
+
* @returns this (for chaining)
|
|
281
|
+
*/
|
|
282
|
+
usePartitions<T>(name: string, partitions: CollectionPartitions<T>): this;
|
|
231
283
|
/**
|
|
232
284
|
* Configure storage for a collection.
|
|
233
285
|
*
|
|
@@ -316,9 +368,11 @@ export declare class ProcedureServer extends Server implements RepositoryProvide
|
|
|
316
368
|
*/
|
|
317
369
|
private invoke;
|
|
318
370
|
/**
|
|
319
|
-
* The token check and the principal of a request (roadmap R18).
|
|
320
|
-
* credentials
|
|
321
|
-
*
|
|
371
|
+
* The token check and the principal of a request (roadmap R18). The request hook reads the
|
|
372
|
+
* credentials of a network request first: a bearer token, a principal and a narrowing. A
|
|
373
|
+
* network request (with credentials) must present the token. The authenticate function gives
|
|
374
|
+
* the principal. The function gives an UNAUTHORIZED response, or undefined when the request
|
|
375
|
+
* passes.
|
|
322
376
|
*/
|
|
323
377
|
private admit;
|
|
324
378
|
/** One call in flight ended: `stop()` can go on when it was the last one. */
|
|
@@ -333,6 +387,12 @@ export declare class ProcedureServer extends Server implements RepositoryProvide
|
|
|
333
387
|
* still stops with its caller, because nobody can read it again.
|
|
334
388
|
*/
|
|
335
389
|
private runKeyed;
|
|
390
|
+
/**
|
|
391
|
+
* The capability of a request. It comes from the server, never from the request. The remaining
|
|
392
|
+
* time of the caller and the narrowing of the request can only make it narrower
|
|
393
|
+
* (CAPABILITIES-2026-10, decision 9). Two different clearances without an order throw.
|
|
394
|
+
*/
|
|
395
|
+
private capabilityOf;
|
|
336
396
|
/** Run a procedure for a request with a signal. */
|
|
337
397
|
private run;
|
|
338
398
|
/**
|
|
@@ -340,8 +400,9 @@ export declare class ProcedureServer extends Server implements RepositoryProvide
|
|
|
340
400
|
* Creates standard CRUD procedures using the configured storage.
|
|
341
401
|
*
|
|
342
402
|
* @param collectionName - Collection name
|
|
403
|
+
* @param options - The query policy of `find`. `$regex` is off unless the policy permits it.
|
|
343
404
|
*/
|
|
344
|
-
registerCollectionProcedures(collectionName: string): void;
|
|
405
|
+
registerCollectionProcedures(collectionName: string, options?: CollectionProceduresOptions): void;
|
|
345
406
|
/** The paths that the server serves now. */
|
|
346
407
|
private servedKeys;
|
|
347
408
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"procedure-server.d.ts","sourceRoot":"","sources":["../../src/server/procedure-server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"procedure-server.d.ts","sourceRoot":"","sources":["../../src/server/procedure-server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAmB,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEpJ,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,eAAe,EAChB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,iBAAiB,EAAsB,MAAM,2BAA2B,CAAC;AAElF,OAAO,EAAoC,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC9H,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACxG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAElF,OAAO,EAAoD,KAAK,kBAAkB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D,4CAA4C;IAC5C,OAAO,CAAC,UAAU;IAYlB;;OAEG;IACH,IAAI,cAAc,IAAI,MAAM,CAE3B;IAED;;;;OAIG;IACH;;;;OAIG;IACH,WAAW,IAAI,iBAAiB,CAE/B;IAED,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAEzC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,CAEvC;IAED;;;;OAIG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAMnC;IAED;;;;OAIG;IACY,IAAI,CAAC,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAsB5D;CACF;AAMD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,GAAE,sBAA2B,GACnC,eAAe,CAEjB"}
|
|
@@ -10,7 +10,7 @@ import { pathToKey } from "../procedures/types.js";
|
|
|
10
10
|
import { ProcedureRegistry, PROCEDURE_REGISTRY } from "../procedures/registry.js";
|
|
11
11
|
import { createCollectionProcedures } from "../procedures/collection/procedures.js";
|
|
12
12
|
import { InvocationError, invokeProcedure } from "../procedures/invoke.js";
|
|
13
|
-
import { TIMEOUT_METADATA_KEY, effectsOf, narrowCapability } from "../procedures/capability.js";
|
|
13
|
+
import { TIMEOUT_METADATA_KEY, effectsOf, joinNarrowing, narrowCapability } from "../procedures/capability.js";
|
|
14
14
|
import { IdempotencyCache, idempotencyKeyOf, isRepeatable } from "../procedures/idempotency.js";
|
|
15
15
|
import { optionalMs } from "../duration.js";
|
|
16
16
|
import { TIMER_DEFAULTS } from "../timers.js";
|
|
@@ -151,6 +151,8 @@ export function errorResponse(id, error) {
|
|
|
151
151
|
export class ProcedureServer extends Server {
|
|
152
152
|
procedureRegistry;
|
|
153
153
|
storages = new Map();
|
|
154
|
+
/** The partitions of each partitioned collection: their storages and their resolver (roadmap CLI-17) */
|
|
155
|
+
partitions = new Map();
|
|
154
156
|
/** For each storage: the calls in flight that took it, and the closes that wait for them */
|
|
155
157
|
storageUses = new Map();
|
|
156
158
|
/** The clock of the wait of `useStorage` */
|
|
@@ -180,13 +182,19 @@ export class ProcedureServer extends Server {
|
|
|
180
182
|
draining = false;
|
|
181
183
|
/** The calls in flight, a stream until its end */
|
|
182
184
|
inFlight = 0;
|
|
183
|
-
/** The token of the server, and its authenticate function (R18) */
|
|
185
|
+
/** The token of the server, its request hook and its authenticate function (R18) */
|
|
184
186
|
token;
|
|
187
|
+
principalOf;
|
|
185
188
|
authenticate;
|
|
186
189
|
/** The functions that `stop()` waits on: each one runs when no call is in flight */
|
|
187
190
|
idleWaiters = [];
|
|
188
191
|
/** The publisher of the remote events, from the option `events`, or undefined. */
|
|
189
192
|
publisher;
|
|
193
|
+
/**
|
|
194
|
+
* How the server can authenticate a request with ambient credentials (cookies). The network faces
|
|
195
|
+
* read it: they trust such a request only from a named origin (CSRF).
|
|
196
|
+
*/
|
|
197
|
+
ambientCredentials;
|
|
190
198
|
constructor(options = {}) {
|
|
191
199
|
super(options);
|
|
192
200
|
this.procedureRegistry = options.registry ?? PROCEDURE_REGISTRY;
|
|
@@ -202,7 +210,10 @@ export class ProcedureServer extends Server {
|
|
|
202
210
|
};
|
|
203
211
|
this.idempotency = options.idempotency === false ? undefined : new IdempotencyCache(options.idempotency ?? {});
|
|
204
212
|
this.token = options.token;
|
|
213
|
+
this.principalOf = options.principalOf;
|
|
205
214
|
this.authenticate = options.authenticate;
|
|
215
|
+
const ambient = options.ambientCredentials ?? (this.principalOf ? "always" : this.authenticate ? "cookies" : undefined);
|
|
216
|
+
this.ambientCredentials = ambient === false ? undefined : ambient;
|
|
206
217
|
// The remote events: the server pins events.subscribe, as it pins host.health (EVENTS.md)
|
|
207
218
|
this.publisher = options.events instanceof EventPublisher ? options.events : options.events ? new EventPublisher(options.events) : undefined;
|
|
208
219
|
if (this.publisher)
|
|
@@ -241,7 +252,50 @@ export class ProcedureServer extends Server {
|
|
|
241
252
|
* @param collection - Collection name
|
|
242
253
|
*/
|
|
243
254
|
hasCollection(collection) {
|
|
244
|
-
return this.storages.has(collection);
|
|
255
|
+
return this.storages.has(collection) || this.partitions.has(collection);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* The storage of one partition of a collection (roadmap CLI-17).
|
|
259
|
+
*
|
|
260
|
+
* @throws Error if the collection has no partitions
|
|
261
|
+
*/
|
|
262
|
+
getPartitionStorage(collection, partition) {
|
|
263
|
+
const partitions = this.partitions.get(collection);
|
|
264
|
+
if (!partitions) {
|
|
265
|
+
throw new Error(`Collection has no partitions: ${collection}`);
|
|
266
|
+
}
|
|
267
|
+
return partitions.storageOf(partition);
|
|
268
|
+
}
|
|
269
|
+
/** True when the collection has partitions (roadmap CLI-17). */
|
|
270
|
+
hasPartitions(collection) {
|
|
271
|
+
return this.partitions.has(collection);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* The partition of a call to a partitioned collection (roadmap CLI-17), from the resolver of
|
|
275
|
+
* `usePartitions`. `null` refuses the call.
|
|
276
|
+
*
|
|
277
|
+
* @throws Error if the collection has no partitions
|
|
278
|
+
*/
|
|
279
|
+
resolvePartition(collection, ctx, requested) {
|
|
280
|
+
const partitions = this.partitions.get(collection);
|
|
281
|
+
if (!partitions) {
|
|
282
|
+
throw new Error(`Collection has no partitions: ${collection}`);
|
|
283
|
+
}
|
|
284
|
+
return partitions.resolve(ctx, requested);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Configure the partitions of a collection (roadmap CLI-17). `resolve` gives the partition of
|
|
288
|
+
* each call from its context (the tenant of `ctx.principal`) and the partition that the call asks
|
|
289
|
+
* for: the collection procedures and the subscriptions of `EventPublisher` use it. `storageOf`
|
|
290
|
+
* gives the storage of a partition: give the same storage for the same partition each time.
|
|
291
|
+
*
|
|
292
|
+
* @param name - Collection name
|
|
293
|
+
* @param partitions - The storage of each partition, and the resolver
|
|
294
|
+
* @returns this (for chaining)
|
|
295
|
+
*/
|
|
296
|
+
usePartitions(name, partitions) {
|
|
297
|
+
this.partitions.set(name, partitions);
|
|
298
|
+
return this;
|
|
245
299
|
}
|
|
246
300
|
useStorage(name, storage, options) {
|
|
247
301
|
if (options === undefined) {
|
|
@@ -294,17 +348,20 @@ export class ProcedureServer extends Server {
|
|
|
294
348
|
callRepository() {
|
|
295
349
|
const taken = new Set();
|
|
296
350
|
let released = false;
|
|
351
|
+
const take = (storage) => {
|
|
352
|
+
if (!released && !taken.has(storage)) {
|
|
353
|
+
taken.add(storage);
|
|
354
|
+
const use = this.storageUses.get(storage) ?? { calls: 0, waiters: [] };
|
|
355
|
+
use.calls++;
|
|
356
|
+
this.storageUses.set(storage, use);
|
|
357
|
+
}
|
|
358
|
+
return storage;
|
|
359
|
+
};
|
|
297
360
|
const repository = {
|
|
298
|
-
getStorage: (collection) =>
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
const use = this.storageUses.get(storage) ?? { calls: 0, waiters: [] };
|
|
303
|
-
use.calls++;
|
|
304
|
-
this.storageUses.set(storage, use);
|
|
305
|
-
}
|
|
306
|
-
return storage;
|
|
307
|
-
},
|
|
361
|
+
getStorage: (collection) => take(this.getStorage(collection)),
|
|
362
|
+
getPartitionStorage: (collection, partition) => take(this.getPartitionStorage(collection, partition)),
|
|
363
|
+
hasPartitions: (collection) => this.hasPartitions(collection),
|
|
364
|
+
resolvePartition: (collection, ctx, requested) => this.resolvePartition(collection, ctx, requested),
|
|
308
365
|
hasCollection: (collection) => this.hasCollection(collection),
|
|
309
366
|
};
|
|
310
367
|
const release = () => {
|
|
@@ -458,9 +515,11 @@ export class ProcedureServer extends Server {
|
|
|
458
515
|
return response;
|
|
459
516
|
}
|
|
460
517
|
/**
|
|
461
|
-
* The token check and the principal of a request (roadmap R18).
|
|
462
|
-
* credentials
|
|
463
|
-
*
|
|
518
|
+
* The token check and the principal of a request (roadmap R18). The request hook reads the
|
|
519
|
+
* credentials of a network request first: a bearer token, a principal and a narrowing. A
|
|
520
|
+
* network request (with credentials) must present the token. The authenticate function gives
|
|
521
|
+
* the principal. The function gives an UNAUTHORIZED response, or undefined when the request
|
|
522
|
+
* passes.
|
|
464
523
|
*/
|
|
465
524
|
async admit(request) {
|
|
466
525
|
const unauthorized = (message) => ({
|
|
@@ -468,11 +527,30 @@ export class ProcedureServer extends Server {
|
|
|
468
527
|
status: { type: "error", code: "UNAUTHORIZED", message, retryable: false },
|
|
469
528
|
metadata: {},
|
|
470
529
|
});
|
|
471
|
-
|
|
472
|
-
|
|
530
|
+
const credentials = request.credentials;
|
|
531
|
+
let identity;
|
|
532
|
+
if (this.principalOf && credentials !== undefined) {
|
|
533
|
+
try {
|
|
534
|
+
identity = await this.principalOf(credentials, request);
|
|
535
|
+
}
|
|
536
|
+
catch {
|
|
537
|
+
identity = undefined;
|
|
538
|
+
}
|
|
539
|
+
if (!identity)
|
|
540
|
+
return unauthorized("Unauthorized: the server did not accept the credentials");
|
|
541
|
+
}
|
|
542
|
+
if (this.token !== undefined && credentials !== undefined) {
|
|
543
|
+
const bearer = identity?.bearer ?? credentials.bearer;
|
|
544
|
+
if (!tokenMatches(this.token, bearer))
|
|
473
545
|
return unauthorized("Unauthorized: this server requires its token");
|
|
474
546
|
request.principal = { id: "token", via: "token" };
|
|
475
547
|
}
|
|
548
|
+
if (identity?.principal)
|
|
549
|
+
request.principal = identity.principal;
|
|
550
|
+
if (identity?.narrowing) {
|
|
551
|
+
const order = this.capabilityOptions.clearanceOrder;
|
|
552
|
+
request.narrowing = request.narrowing ? joinNarrowing(request.narrowing, identity.narrowing, order) : identity.narrowing;
|
|
553
|
+
}
|
|
476
554
|
if (this.authenticate) {
|
|
477
555
|
let principal;
|
|
478
556
|
try {
|
|
@@ -551,6 +629,16 @@ export class ProcedureServer extends Server {
|
|
|
551
629
|
}
|
|
552
630
|
return { ...response, id: request.id };
|
|
553
631
|
}
|
|
632
|
+
/**
|
|
633
|
+
* The capability of a request. It comes from the server, never from the request. The remaining
|
|
634
|
+
* time of the caller and the narrowing of the request can only make it narrower
|
|
635
|
+
* (CAPABILITIES-2026-10, decision 9). Two different clearances without an order throw.
|
|
636
|
+
*/
|
|
637
|
+
capabilityOf(request) {
|
|
638
|
+
const { capability, clearanceOrder } = this.capabilityOptions;
|
|
639
|
+
const base = withRequestTimeout(typeof capability === "function" ? capability(request) : capability, request, clearanceOrder);
|
|
640
|
+
return request.narrowing ? narrowCapability(base, request.narrowing, clearanceOrder) : base;
|
|
641
|
+
}
|
|
554
642
|
/** Run a procedure for a request with a signal. */
|
|
555
643
|
async run(procedure, request, signal) {
|
|
556
644
|
// The call uses the storages that it takes until its end: the end of a stream, for a stream
|
|
@@ -559,21 +647,32 @@ export class ProcedureServer extends Server {
|
|
|
559
647
|
try {
|
|
560
648
|
// One invocation path for every host (ARCHITECTURE-PROPOSALS P1): input validation, the
|
|
561
649
|
// context, the expose rule for nested calls (BUGS-2026-07 H18) and output validation
|
|
562
|
-
const {
|
|
650
|
+
const { clearanceOrder, resources, admitItem } = this.capabilityOptions;
|
|
651
|
+
let capability;
|
|
652
|
+
try {
|
|
653
|
+
capability = this.capabilityOf(request);
|
|
654
|
+
}
|
|
655
|
+
catch (error) {
|
|
656
|
+
const message = `The server cannot narrow the capability of the request: ${error instanceof Error ? error.message : String(error)}`;
|
|
657
|
+
return errorResponse(request.id, Object.assign(new Error(message), { code: "INTERNAL_ERROR" }));
|
|
658
|
+
}
|
|
563
659
|
const output = await invokeProcedure(procedure, request.payload, {
|
|
564
660
|
registry: this.procedureRegistry,
|
|
565
661
|
metadata: request.metadata,
|
|
566
662
|
signal,
|
|
663
|
+
// What the face of the call offers: it asks the person, and it shows the progress (CLI-12)
|
|
664
|
+
...(request.elicit ? { elicit: request.elicit } : {}),
|
|
665
|
+
...(request.progress ? { progress: request.progress } : {}),
|
|
567
666
|
repository,
|
|
568
667
|
expose: this.expose,
|
|
569
668
|
strictCalls: this.strictCalls,
|
|
570
669
|
interceptors: this.interceptors,
|
|
571
|
-
|
|
572
|
-
// the caller can only make the deadline earlier (CAPABILITIES-2026-10, decision 9).
|
|
573
|
-
capability: withRequestTimeout(typeof capability === "function" ? capability(request) : capability, request, clearanceOrder),
|
|
670
|
+
capability,
|
|
574
671
|
clearanceOrder,
|
|
575
672
|
resources,
|
|
576
673
|
admitItem,
|
|
674
|
+
// The principal of the authentication: ctx.principal, and the nested calls (R18)
|
|
675
|
+
...(request.principal !== undefined ? { principal: request.principal } : {}),
|
|
577
676
|
// The bus of the remote events is the bus of the procedures (EVENTS.md)
|
|
578
677
|
...(this.publisher ? { bus: this.publisher.bus } : {}),
|
|
579
678
|
});
|
|
@@ -603,11 +702,12 @@ export class ProcedureServer extends Server {
|
|
|
603
702
|
* Creates standard CRUD procedures using the configured storage.
|
|
604
703
|
*
|
|
605
704
|
* @param collectionName - Collection name
|
|
705
|
+
* @param options - The query policy of `find`. `$regex` is off unless the policy permits it.
|
|
606
706
|
*/
|
|
607
|
-
registerCollectionProcedures(collectionName) {
|
|
707
|
+
registerCollectionProcedures(collectionName, options) {
|
|
608
708
|
// Uses a top-level import; require() is not available in this ESM package and
|
|
609
709
|
// previously threw "Cannot find module" on every call. See BUGS-2026-07 H13.
|
|
610
|
-
const procedures = createCollectionProcedures(collectionName);
|
|
710
|
+
const procedures = createCollectionProcedures(collectionName, options);
|
|
611
711
|
// Register with the procedure registry first
|
|
612
712
|
this.procedureRegistry.registerAll(procedures);
|
|
613
713
|
// Then register as server handlers
|