@astrale-os/kernel-client 1.0.0-beta.3 → 1.0.0-beta.30
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/dist/auth/index.d.ts +1 -0
- package/dist/client/admission.js +3 -1
- package/dist/client/client.d.ts +19 -2
- package/dist/client/client.js +62 -30
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.js +2 -2
- package/dist/client/request.d.ts +8 -2
- package/dist/client/request.js +28 -7
- package/dist/client/result.d.ts +10 -1
- package/dist/client/result.js +10 -4
- package/dist/client/routing-control.d.ts +11 -15
- package/dist/client/routing-control.js +21 -29
- package/dist/errors/index.d.ts +3 -0
- package/dist/errors/index.js +3 -0
- package/dist/errors/query-input.d.ts +47 -0
- package/dist/errors/query-input.js +85 -0
- package/dist/errors/refusal.d.ts +19 -0
- package/dist/errors/refusal.js +63 -0
- package/dist/errors/response-too-large-error.d.ts +11 -0
- package/dist/errors/response-too-large-error.js +15 -0
- package/dist/errors/stale-route-error.d.ts +1 -1
- package/dist/errors/stale-route-error.js +1 -1
- package/dist/{schema → execution}/admission.d.ts +2 -2
- package/dist/{schema → execution}/admission.js +3 -3
- package/dist/execution/contracts.d.ts +76 -0
- package/dist/execution/contracts.js +1 -0
- package/dist/execution/deadline.d.ts +18 -0
- package/dist/execution/deadline.js +25 -0
- package/dist/execution/execution.d.ts +61 -0
- package/dist/execution/execution.js +132 -0
- package/dist/execution/index.d.ts +4 -0
- package/dist/execution/index.js +3 -0
- package/dist/graph/domain/binding.d.ts +2 -2
- package/dist/graph/domain/binding.js +24 -17
- package/dist/graph/domain/conformance.d.ts +12 -0
- package/dist/graph/domain/conformance.js +18 -0
- package/dist/graph/domain/index.d.ts +1 -0
- package/dist/graph/domain/index.js +1 -1
- package/dist/graph/domain/provenance.d.ts +0 -2
- package/dist/graph/domain/provenance.js +0 -4
- package/dist/graph/graph.d.ts +17 -3
- package/dist/graph/graph.js +4 -1
- package/dist/graph/index.d.ts +3 -3
- package/dist/graph/index.js +1 -1
- package/dist/graph/page-contract.d.ts +64 -1
- package/dist/graph/provenance.d.ts +4 -5
- package/dist/graph/provenance.js +5 -6
- package/dist/graph/query.d.ts +10 -4
- package/dist/graph/query.js +145 -7
- package/dist/graph/query.typecheck.d.ts +77 -0
- package/dist/graph/query.typecheck.js +34 -0
- package/dist/pacer/index.d.ts +1 -1
- package/dist/pacer/index.js +1 -1
- package/dist/pacer/retry/index.d.ts +1 -0
- package/dist/pacer/retry/index.js +1 -0
- package/dist/pacer/retry/refusals.d.ts +7 -0
- package/dist/pacer/retry/refusals.js +10 -0
- package/dist/pacer/retry/retry.d.ts +2 -0
- package/dist/pacer/retry/retry.js +33 -1
- package/dist/schema/contracts.d.ts +77 -9
- package/dist/schema/index.d.ts +3 -2
- package/dist/schema/index.js +1 -1
- package/dist/schema/installation.d.ts +76 -0
- package/dist/schema/installation.js +82 -0
- package/dist/schema/schema.d.ts +22 -13
- package/dist/schema/schema.js +67 -48
- package/dist/session/admission.js +10 -3
- package/dist/session/bound.d.ts +12 -3
- package/dist/session/bound.js +66 -20
- package/dist/session/content/api.d.ts +10 -2
- package/dist/session/content/api.js +13 -4
- package/dist/session/content/index.d.ts +1 -1
- package/dist/session/content/input.d.ts +6 -1
- package/dist/session/content/input.js +12 -4
- package/dist/session/content/retry.d.ts +5 -1
- package/dist/session/content/retry.js +21 -31
- package/dist/session/context/index.d.ts +1 -1
- package/dist/session/context/index.js +1 -1
- package/dist/session/context/operation.d.ts +2 -0
- package/dist/session/context/operation.js +5 -0
- package/dist/session/credential/credentials.js +43 -28
- package/dist/session/discovery/bundle.d.ts +9 -4
- package/dist/session/discovery/bundle.js +28 -35
- package/dist/session/discovery/discovery.d.ts +1 -1
- package/dist/session/discovery/discovery.js +8 -11
- package/dist/session/discovery/release.js +18 -28
- package/dist/session/discovery/snapshot.d.ts +5 -1
- package/dist/session/discovery/transport.d.ts +35 -3
- package/dist/session/discovery/transport.js +40 -1
- package/dist/session/durable.d.ts +13 -0
- package/dist/session/durable.js +39 -0
- package/dist/session/exchange/exchange.d.ts +3 -2
- package/dist/session/exchange/exchange.js +10 -7
- package/dist/session/exchange/index.d.ts +1 -1
- package/dist/session/exchange/index.js +1 -1
- package/dist/session/exchange/presentation.js +28 -10
- package/dist/session/exchange/source.d.ts +7 -7
- package/dist/session/exchange/source.js +26 -27
- package/dist/session/index.d.ts +4 -3
- package/dist/session/index.js +0 -1
- package/dist/session/options.d.ts +0 -2
- package/dist/session/options.js +0 -3
- package/dist/session/reference.d.ts +9 -5
- package/dist/session/reference.js +7 -2
- package/dist/session/retry.d.ts +12 -0
- package/dist/session/retry.js +23 -0
- package/dist/session/routing/auth.d.ts +9 -3
- package/dist/session/routing/auth.js +4 -3
- package/dist/session/routing/cache.d.ts +12 -5
- package/dist/session/routing/cache.js +56 -48
- package/dist/session/routing/dispatch.d.ts +26 -3
- package/dist/session/routing/dispatch.js +112 -67
- package/dist/session/routing/envelope.d.ts +3 -3
- package/dist/session/routing/index.d.ts +1 -1
- package/dist/session/routing/legacy/release-route.d.ts +12 -0
- package/dist/session/routing/legacy/release-route.js +6 -0
- package/dist/session/routing/recovery.d.ts +3 -6
- package/dist/session/routing/recovery.js +3 -14
- package/dist/session/routing/request.d.ts +6 -1
- package/dist/session/routing/request.js +13 -2
- package/dist/session/routing/result.d.ts +1 -1
- package/dist/session/routing/result.js +5 -1
- package/dist/session/routing/store.js +4 -5
- package/dist/session/session.d.ts +31 -5
- package/dist/session/session.js +60 -19
- package/dist/session/session.typecheck.js +20 -6
- package/dist/session/views/index.d.ts +2 -2
- package/dist/session/views/index.js +2 -2
- package/dist/session/views/kernel.d.ts +31 -0
- package/dist/session/views/kernel.js +30 -0
- package/dist/session/views/legacy/catalog.d.ts +21 -0
- package/dist/session/views/{catalog.js → legacy/catalog.js} +7 -31
- package/dist/session/views/legacy/index.d.ts +14 -0
- package/dist/session/views/legacy/index.js +14 -0
- package/dist/session/views/legacy/resolve.d.ts +46 -0
- package/dist/session/views/legacy/resolve.js +83 -0
- package/dist/session/views/legacy/unplaced.d.ts +22 -0
- package/dist/session/views/legacy/unplaced.js +26 -0
- package/dist/session/views/read.d.ts +49 -0
- package/dist/session/views/read.js +148 -0
- package/dist/session/views/view.d.ts +48 -0
- package/dist/session/views/view.js +74 -0
- package/dist/store/memory.d.ts +1 -3
- package/dist/store/memory.js +73 -105
- package/dist/store/shape.d.ts +33 -12
- package/dist/store/shape.js +125 -16
- package/dist/store/store.d.ts +6 -6
- package/dist/store/store.js +1 -1
- package/dist/transport/auto/decision.d.ts +26 -14
- package/dist/transport/auto/decision.js +35 -32
- package/dist/transport/auto/fallback.d.ts +1 -1
- package/dist/transport/auto/fallback.js +5 -10
- package/dist/transport/auto/transport.d.ts +0 -2
- package/dist/transport/auto/transport.js +24 -32
- package/dist/transport/deadline.d.ts +2 -0
- package/dist/transport/deadline.js +18 -0
- package/dist/transport/failure.d.ts +28 -1
- package/dist/transport/failure.js +63 -1
- package/dist/transport/http/admission.js +7 -34
- package/dist/transport/http/binary-request.d.ts +44 -0
- package/dist/transport/http/binary-request.js +110 -0
- package/dist/transport/http/binary.js +3 -3
- package/dist/transport/http/byte-stream.d.ts +2 -1
- package/dist/transport/http/byte-stream.js +12 -8
- package/dist/transport/http/index.d.ts +1 -1
- package/dist/transport/http/index.js +1 -1
- package/dist/transport/http/response.d.ts +3 -1
- package/dist/transport/http/response.js +7 -9
- package/dist/transport/http/stream.d.ts +8 -13
- package/dist/transport/http/stream.js +34 -81
- package/dist/transport/http/transport.d.ts +10 -0
- package/dist/transport/http/transport.js +87 -32
- package/dist/transport/http/unprocessed.d.ts +5 -0
- package/dist/transport/http/unprocessed.js +28 -0
- package/dist/transport/index.d.ts +1 -1
- package/dist/transport/index.js +1 -1
- package/dist/transport/stream.d.ts +52 -0
- package/dist/transport/stream.js +101 -0
- package/dist/transport/transport.d.ts +10 -0
- package/dist/transport/unary.d.ts +8 -0
- package/dist/transport/unary.js +34 -0
- package/dist/transport/websocket/connection.d.ts +7 -3
- package/dist/transport/websocket/connection.js +103 -92
- package/dist/transport/websocket/exchange.d.ts +12 -19
- package/dist/transport/websocket/exchange.js +86 -184
- package/dist/transport/websocket/transport.js +11 -19
- package/package.json +7 -5
- package/dist/session/execution.d.ts +0 -65
- package/dist/session/execution.js +0 -34
- package/dist/session/views/catalog.d.ts +0 -19
- package/dist/session/views/resolve.d.ts +0 -13
- package/dist/session/views/resolve.js +0 -21
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type { AuthApi, AdmissionOptions, FunctionAdmission } from './auth.js';
|
|
2
|
+
export type { RequestOptions } from '../transport/index.js';
|
|
2
3
|
export { IDENTITY_CAN_PATH, type PolicyDecisionInput } from './authorization.js';
|
|
3
4
|
export { IDENTITY_MINT_PATH, IDENTITY_IMPERSONATE_PATH, type DelegateOptions, type MintOptions, type ImpersonateOptions, } from './credential.js';
|
|
4
5
|
export { IDENTITY_WHOAMI_PATH, IDENTITY_WHOIS_PATH, type WhoisInput } from './identity.js';
|
package/dist/client/admission.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Target } from '@astrale-os/kernel-core/callable';
|
|
2
2
|
import { Path } from '@astrale-os/kernel-core/path';
|
|
3
3
|
import * as portable from '@astrale-os/kernel-dsl/value';
|
|
4
|
+
import { ENVELOPE_LIMITS } from '@astrale-os/kernel-protocol/codecs';
|
|
4
5
|
/** Parent-private Call acceptance shared by Client and Client Session. */
|
|
5
6
|
export function acceptCall(input) {
|
|
6
7
|
if (input === null || typeof input !== 'object' || Array.isArray(input)) {
|
|
@@ -25,7 +26,8 @@ function admitPath(input) {
|
|
|
25
26
|
}
|
|
26
27
|
function admitInput(input) {
|
|
27
28
|
try {
|
|
28
|
-
|
|
29
|
+
// As deep as an envelope carries it: a Query document reaches its own nesting bound first.
|
|
30
|
+
return portable.acceptImmutable(input, { limits: ENVELOPE_LIMITS });
|
|
29
31
|
}
|
|
30
32
|
catch (cause) {
|
|
31
33
|
throw new TypeError('Client input must be a portable Value.', { cause });
|
package/dist/client/client.d.ts
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
import type { invocation as protocol } from '@astrale-os/kernel-protocol';
|
|
2
|
+
import type { BinaryBody } from '../transport/http/binary-request.js';
|
|
2
3
|
import type { Transport } from '../transport/index.js';
|
|
3
4
|
import type { AuthenticatedClient, RemoteCredential } from './credential.js';
|
|
4
5
|
import type { Call, ClientDispatchOptions, ClientDispatchOptionsWithBody } from './request.js';
|
|
5
6
|
import type { BinaryResponse, Result, StreamResult, ValueResult } from './result.js';
|
|
7
|
+
import type { RoutingControl } from './routing-control.js';
|
|
6
8
|
import { type HttpTransportOptions } from '../transport/http/index.js';
|
|
7
9
|
export type ClientOptions = HttpTransportOptions | {
|
|
8
10
|
readonly transport: Transport;
|
|
9
11
|
};
|
|
10
|
-
/**
|
|
11
|
-
export
|
|
12
|
+
/** One package-private send: the Trace of a redirect continuation and an admitted body, if any. */
|
|
13
|
+
export interface InternalDispatch {
|
|
14
|
+
readonly credential?: RemoteCredential;
|
|
15
|
+
readonly call: Call;
|
|
16
|
+
readonly options?: ClientDispatchOptions;
|
|
17
|
+
readonly trace?: protocol.Trace;
|
|
18
|
+
readonly body?: BinaryBody;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Package-private Session routing path: it presents a redirect continuation's Trace, sends an
|
|
22
|
+
* admitted body, which may be a one-shot stream, and answers routing control as a value.
|
|
23
|
+
* Intentionally absent from the public Client facade. A Client this package did not construct is
|
|
24
|
+
* reached through its public methods, so it never answers routing control.
|
|
25
|
+
*/
|
|
26
|
+
export declare function dispatchInternal(client: Client, dispatch: InternalDispatch): Promise<Result | RoutingControl>;
|
|
12
27
|
/** Pure client for the universal remote Function invocation boundary. */
|
|
13
28
|
export declare class Client implements AuthenticatedClient {
|
|
14
29
|
private readonly transport;
|
|
@@ -23,5 +38,7 @@ export declare class Client implements AuthenticatedClient {
|
|
|
23
38
|
binary(call: Call, options?: ClientDispatchOptions): Promise<BinaryResponse>;
|
|
24
39
|
as(credential: RemoteCredential): AuthenticatedClient;
|
|
25
40
|
close(): void;
|
|
41
|
+
/** The public path: routing control is reported as the error every Client raises for it. */
|
|
26
42
|
private dispatchWith;
|
|
43
|
+
private dispatchRouted;
|
|
27
44
|
}
|
package/dist/client/client.js
CHANGED
|
@@ -1,16 +1,40 @@
|
|
|
1
1
|
import { ClientError } from '../errors/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import { cancelUnsent } from '../transport/http/binary-request.js';
|
|
3
|
+
import { dispatchBinaryBody, HttpTransport, } from '../transport/http/index.js';
|
|
3
4
|
import { authenticated, resolveCredential } from './credential.js';
|
|
4
5
|
import { admitRequest, invocation } from './request.js';
|
|
5
6
|
import { requireBinary, requireStream, requireValue } from './result.js';
|
|
6
|
-
import {
|
|
7
|
+
import { isRoutingControl, raisedRoutingControl, routingControlError } from './routing-control.js';
|
|
7
8
|
const controlledDispatch = new WeakMap();
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Package-private Session routing path: it presents a redirect continuation's Trace, sends an
|
|
11
|
+
* admitted body, which may be a one-shot stream, and answers routing control as a value.
|
|
12
|
+
* Intentionally absent from the public Client facade. A Client this package did not construct is
|
|
13
|
+
* reached through its public methods, so it never answers routing control.
|
|
14
|
+
*/
|
|
15
|
+
export function dispatchInternal(client, dispatch) {
|
|
16
|
+
const controlled = controlledDispatch.get(client);
|
|
17
|
+
if (controlled !== undefined)
|
|
18
|
+
return controlled(dispatch);
|
|
19
|
+
if (dispatch.trace !== undefined || dispatch.body !== undefined) {
|
|
20
|
+
throw new TypeError('Internal dispatch requires an owned Client.');
|
|
21
|
+
}
|
|
22
|
+
return dispatchPublic(client, dispatch);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A caller-supplied pool may wrap a real Client, whose public dispatch raises routing control as
|
|
26
|
+
* an error: only the exact error a Client raised answers its control; any other error propagates.
|
|
27
|
+
*/
|
|
28
|
+
async function dispatchPublic(client, { credential, call, options }) {
|
|
29
|
+
try {
|
|
30
|
+
return await (credential === undefined ? client : client.as(credential)).dispatch(call, options);
|
|
31
|
+
}
|
|
32
|
+
catch (cause) {
|
|
33
|
+
const control = raisedRoutingControl(cause);
|
|
34
|
+
if (control === undefined)
|
|
35
|
+
throw cause;
|
|
36
|
+
return control;
|
|
37
|
+
}
|
|
14
38
|
}
|
|
15
39
|
/** Pure client for the universal remote Function invocation boundary. */
|
|
16
40
|
export class Client {
|
|
@@ -24,7 +48,7 @@ export class Client {
|
|
|
24
48
|
this.transport = Object.hasOwn(options, 'transport')
|
|
25
49
|
? admitTransport(options.transport)
|
|
26
50
|
: new HttpTransport(options);
|
|
27
|
-
controlledDispatch.set(this, (
|
|
51
|
+
controlledDispatch.set(this, (dispatch) => this.dispatchRouted(dispatch.credential, dispatch.call, dispatch.options, dispatch.trace, dispatch.body));
|
|
28
52
|
}
|
|
29
53
|
dispatch(call, options) {
|
|
30
54
|
return this.dispatchWith(undefined, call, options);
|
|
@@ -49,32 +73,40 @@ export class Client {
|
|
|
49
73
|
this.lifecycle.abort(failure);
|
|
50
74
|
this.transport.close?.();
|
|
51
75
|
}
|
|
52
|
-
|
|
76
|
+
/** The public path: routing control is reported as the error every Client raises for it. */
|
|
77
|
+
async dispatchWith(credential, input, options) {
|
|
78
|
+
const result = await this.dispatchRouted(credential, input, options);
|
|
79
|
+
if (isRoutingControl(result))
|
|
80
|
+
throw routingControlError(result);
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
async dispatchRouted(credential, input, options, trace, body) {
|
|
53
84
|
if (this.closed)
|
|
54
85
|
throw new ClientError('Client is closed.');
|
|
55
|
-
const request = admitRequest(input, options, this.lifecycle.signal);
|
|
56
|
-
const resolved = credential === undefined
|
|
57
|
-
? undefined
|
|
58
|
-
: await resolveCredential(credential, request.options.signal);
|
|
59
|
-
requireRequestLive(request.options.signal);
|
|
60
|
-
const envelope = invocation(request, resolved, trace);
|
|
86
|
+
const request = admitRequest(input, options, this.lifecycle.signal, body);
|
|
61
87
|
let result;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
88
|
+
try {
|
|
89
|
+
const resolved = credential === undefined
|
|
90
|
+
? undefined
|
|
91
|
+
: await resolveCredential(credential, request.options.signal);
|
|
92
|
+
requireRequestLive(request.options.signal);
|
|
93
|
+
const envelope = invocation(request, resolved, trace);
|
|
94
|
+
if (request.body === undefined) {
|
|
95
|
+
result = await this.transport.dispatch(envelope, request.options);
|
|
69
96
|
}
|
|
70
|
-
|
|
97
|
+
else {
|
|
98
|
+
const transport = this.transport;
|
|
99
|
+
if (!(transport instanceof HttpTransport)) {
|
|
100
|
+
throw new TypeError('Binary dispatch requires HTTP transport.');
|
|
101
|
+
}
|
|
102
|
+
result = await dispatchBinaryBody(transport, envelope, request.body, request.options);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (cause) {
|
|
106
|
+
// A stream body this request never started to send is cancelled with it.
|
|
107
|
+
cancelUnsent(request.body);
|
|
108
|
+
throw cause;
|
|
71
109
|
}
|
|
72
|
-
if (result.kind === 'stale')
|
|
73
|
-
throw admittedStaleRouteError(result.current, result.invocation);
|
|
74
|
-
if (result.kind === 'miss')
|
|
75
|
-
throw admittedMissError(result.invocation);
|
|
76
|
-
if (result.kind === 'deployment-retired')
|
|
77
|
-
throw admittedDeploymentRetiredError(result);
|
|
78
110
|
return result;
|
|
79
111
|
}
|
|
80
112
|
}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { Client,
|
|
1
|
+
export { Client, dispatchInternal, type ClientOptions, type InternalDispatch } from './client.js';
|
|
2
2
|
export { acceptCall } from './admission.js';
|
|
3
3
|
export type { AuthenticatedClient, RemoteCredential } from './credential.js';
|
|
4
4
|
export { call, type Call, type ClientDispatchOptions, type ClientDispatchOptionsWithBody, } from './request.js';
|
|
5
|
-
export type { Binary, BinaryResponse, Input, RedirectResult, Result, Stream, StreamResult, ValueResult, } from './result.js';
|
|
6
|
-
export {
|
|
5
|
+
export type { Binary, BinaryResponse, ExecutionResult, Input, RedirectResult, Result, Stream, StreamResult, ValueResult, } from './result.js';
|
|
6
|
+
export { isRoutingControl, routingControlError, type RoutingControl } from './routing-control.js';
|
package/dist/client/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Client,
|
|
1
|
+
export { Client, dispatchInternal } from './client.js';
|
|
2
2
|
export { acceptCall } from './admission.js';
|
|
3
3
|
export { call, } from './request.js';
|
|
4
|
-
export {
|
|
4
|
+
export { isRoutingControl, routingControlError } from './routing-control.js';
|
package/dist/client/request.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Target } from '@astrale-os/kernel-core/callable';
|
|
2
2
|
import type { PathLike } from '@astrale-os/kernel-core/path';
|
|
3
3
|
import type * as protocol from '@astrale-os/kernel-protocol/invocation';
|
|
4
|
+
import type { BinaryBody } from '../transport/http/binary-request.js';
|
|
4
5
|
import type { RequestOptions, TransportRequest } from '../transport/index.js';
|
|
5
6
|
import type { Input } from './result.js';
|
|
6
7
|
/** One portable call before Path canonicalization, correlation, and credential binding. */
|
|
@@ -25,9 +26,14 @@ export interface AdmittedRequest {
|
|
|
25
26
|
readonly delegate?: protocol.Delegate;
|
|
26
27
|
readonly routing?: protocol.Routing;
|
|
27
28
|
readonly schema?: protocol.SchemaTarget;
|
|
29
|
+
readonly maintenance?: protocol.Maintenance;
|
|
28
30
|
readonly options: RequestOptions;
|
|
29
|
-
readonly body?:
|
|
31
|
+
readonly body?: BinaryBody;
|
|
30
32
|
}
|
|
31
33
|
export declare function call(target: PathLike | Target, input: Input): Call;
|
|
32
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Admit one request. A public caller's body is a Blob in its options; the package-private path
|
|
36
|
+
* passes a body its owner already admitted, which may be a stream that only Session routing sends.
|
|
37
|
+
*/
|
|
38
|
+
export declare function admitRequest(input: Call, options: ClientDispatchOptions | ClientDispatchOptionsWithBody | undefined, lifecycle: AbortSignal, admittedBody?: BinaryBody): AdmittedRequest;
|
|
33
39
|
export declare function invocation(request: AdmittedRequest, credential?: string, trace?: protocol.Trace): TransportRequest;
|
package/dist/client/request.js
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
import * as invocationProtocol from '@astrale-os/kernel-protocol/invocation';
|
|
2
|
+
import { replayableBody } from '../transport/http/binary-request.js';
|
|
2
3
|
import { acceptCall } from './admission.js';
|
|
3
4
|
export function call(target, input) {
|
|
4
5
|
return Object.freeze({ target, input });
|
|
5
6
|
}
|
|
6
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Admit one request. A public caller's body is a Blob in its options; the package-private path
|
|
9
|
+
* passes a body its owner already admitted, which may be a stream that only Session routing sends.
|
|
10
|
+
*/
|
|
11
|
+
export function admitRequest(input, options, lifecycle, admittedBody) {
|
|
7
12
|
const call = acceptCall(input);
|
|
8
13
|
const admitted = admitRequestOptions(options);
|
|
14
|
+
const body = admittedBody ?? admitted.body;
|
|
9
15
|
const admittedOptions = lifecycleOptions(admitted.options, lifecycle);
|
|
10
16
|
const delegate = admitDelegate(options?.delegate);
|
|
11
17
|
const routing = admitRouting(options?.routing);
|
|
12
18
|
const schema = admitSchemaTarget(options?.schema);
|
|
19
|
+
const maintenance = admitMaintenance(options?.maintenance);
|
|
13
20
|
return Object.freeze({
|
|
14
21
|
call,
|
|
15
22
|
...(delegate === undefined ? {} : { delegate }),
|
|
16
23
|
...(routing === undefined ? {} : { routing }),
|
|
17
24
|
...(schema === undefined ? {} : { schema }),
|
|
18
|
-
...(
|
|
25
|
+
...(maintenance === undefined ? {} : { maintenance }),
|
|
26
|
+
...(body === undefined ? {} : { body }),
|
|
19
27
|
options: admittedOptions,
|
|
20
28
|
});
|
|
21
29
|
}
|
|
@@ -28,6 +36,9 @@ export function invocation(request, credential, trace) {
|
|
|
28
36
|
if (request.schema !== undefined) {
|
|
29
37
|
throw new TypeError('Destination Client requests cannot carry a Schema target.');
|
|
30
38
|
}
|
|
39
|
+
if (request.maintenance !== undefined) {
|
|
40
|
+
throw new TypeError('Destination Client requests cannot carry a maintenance guard.');
|
|
41
|
+
}
|
|
31
42
|
}
|
|
32
43
|
else if ((credential === undefined) !== (request.delegate === undefined)) {
|
|
33
44
|
throw new TypeError('Source Client credentials and delegation requests must occur together.');
|
|
@@ -38,6 +49,7 @@ export function invocation(request, credential, trace) {
|
|
|
38
49
|
...(request.delegate === undefined ? {} : { delegate: request.delegate }),
|
|
39
50
|
...(request.routing === undefined ? {} : { routing: request.routing }),
|
|
40
51
|
...(request.schema === undefined ? {} : { schema: request.schema }),
|
|
52
|
+
...(request.maintenance === undefined ? {} : { maintenance: request.maintenance }),
|
|
41
53
|
...(admittedTrace === undefined ? {} : { trace: admittedTrace }),
|
|
42
54
|
});
|
|
43
55
|
}
|
|
@@ -54,6 +66,7 @@ function admitRequestOptions(input) {
|
|
|
54
66
|
'delegate',
|
|
55
67
|
'routing',
|
|
56
68
|
'schema',
|
|
69
|
+
'maintenance',
|
|
57
70
|
'body',
|
|
58
71
|
].includes(String(field)))) {
|
|
59
72
|
throw new TypeError('Client request options contain unsupported fields.');
|
|
@@ -64,14 +77,12 @@ function admitRequestOptions(input) {
|
|
|
64
77
|
input.timeoutMs > 2_147_483_647)) {
|
|
65
78
|
throw new TypeError('Client request timeoutMs must be a positive safe platform integer.');
|
|
66
79
|
}
|
|
67
|
-
const hasBody = Object.hasOwn(input, 'body');
|
|
68
80
|
let body;
|
|
69
|
-
if (
|
|
81
|
+
if (Object.hasOwn(input, 'body')) {
|
|
70
82
|
const candidate = input.body;
|
|
71
|
-
if (!(candidate instanceof Blob))
|
|
83
|
+
if (!(candidate instanceof Blob))
|
|
72
84
|
throw new TypeError('Binary input must be a Blob or File.');
|
|
73
|
-
|
|
74
|
-
body = candidate;
|
|
85
|
+
body = replayableBody(candidate);
|
|
75
86
|
}
|
|
76
87
|
if (body !== undefined && input.idempotencyKey !== undefined) {
|
|
77
88
|
throw new TypeError('Binary requests cannot carry an idempotency key.');
|
|
@@ -118,6 +129,16 @@ function admitSchemaTarget(input) {
|
|
|
118
129
|
throw new TypeError('Client Schema target is invalid.', { cause });
|
|
119
130
|
}
|
|
120
131
|
}
|
|
132
|
+
function admitMaintenance(input) {
|
|
133
|
+
if (input === undefined)
|
|
134
|
+
return undefined;
|
|
135
|
+
try {
|
|
136
|
+
return invocationProtocol.acceptMaintenance(input);
|
|
137
|
+
}
|
|
138
|
+
catch (cause) {
|
|
139
|
+
throw new TypeError('Client maintenance guard is invalid.', { cause });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
121
142
|
function lifecycleOptions(input, lifecycle) {
|
|
122
143
|
const signal = input?.signal === undefined ? lifecycle : AbortSignal.any([input.signal, lifecycle]);
|
|
123
144
|
return Object.freeze({
|
package/dist/client/result.d.ts
CHANGED
|
@@ -23,12 +23,21 @@ export type StreamResult = Correlated<Extract<Callable, {
|
|
|
23
23
|
export type BinaryResponse = Correlated<Extract<Callable, {
|
|
24
24
|
readonly kind: 'binary';
|
|
25
25
|
}>>;
|
|
26
|
+
/**
|
|
27
|
+
* A durable call's answer. `replayed` is absent when the Host does not say whether the call
|
|
28
|
+
* replayed its Execution.
|
|
29
|
+
*/
|
|
30
|
+
export type ExecutionResult = Correlated<Omit<Extract<Callable, {
|
|
31
|
+
readonly kind: 'execution';
|
|
32
|
+
}>, 'replayed'> & {
|
|
33
|
+
readonly replayed?: boolean;
|
|
34
|
+
}>;
|
|
26
35
|
export interface RedirectResult {
|
|
27
36
|
readonly kind: 'redirect';
|
|
28
37
|
readonly redirect: protocol.Redirection;
|
|
29
38
|
readonly invocation: protocol.InvocationId;
|
|
30
39
|
}
|
|
31
|
-
export type Result = ValueResult | StreamResult | BinaryResponse | RedirectResult;
|
|
40
|
+
export type Result = ValueResult | StreamResult | BinaryResponse | ExecutionResult | RedirectResult;
|
|
32
41
|
export declare function requireValue(result: Promise<Result>): Promise<ValueResult>;
|
|
33
42
|
export declare function requireStream(result: Promise<Result>): Promise<StreamResult>;
|
|
34
43
|
export declare function requireBinary(result: Promise<Result>): Promise<BinaryResponse>;
|
package/dist/client/result.js
CHANGED
|
@@ -8,7 +8,7 @@ export async function requireValue(result) {
|
|
|
8
8
|
export async function requireStream(result) {
|
|
9
9
|
const settled = await result;
|
|
10
10
|
if (settled.kind !== 'stream')
|
|
11
|
-
mismatch('stream', settled
|
|
11
|
+
mismatch('stream', settled);
|
|
12
12
|
return settled;
|
|
13
13
|
}
|
|
14
14
|
export async function requireBinary(result) {
|
|
@@ -17,8 +17,14 @@ export async function requireBinary(result) {
|
|
|
17
17
|
return rejectMismatch('binary', settled);
|
|
18
18
|
return settled;
|
|
19
19
|
}
|
|
20
|
-
function mismatch(expected,
|
|
21
|
-
throw new ClientError(
|
|
20
|
+
function mismatch(expected, result) {
|
|
21
|
+
throw new ClientError(`${returned(result)}; ${expected} was required.`);
|
|
22
|
+
}
|
|
23
|
+
/** What the call did; a started Execution is named so its caller never starts it again. */
|
|
24
|
+
function returned(result) {
|
|
25
|
+
return result.kind === 'execution'
|
|
26
|
+
? `Function started Execution ${result.execution}`
|
|
27
|
+
: `Function returned ${result.kind}`;
|
|
22
28
|
}
|
|
23
29
|
async function rejectMismatch(expected, result) {
|
|
24
30
|
if (result.kind === 'stream') {
|
|
@@ -27,5 +33,5 @@ async function rejectMismatch(expected, result) {
|
|
|
27
33
|
if (result.kind === 'binary' && !(result.value.body instanceof Uint8Array)) {
|
|
28
34
|
await result.value.body[Symbol.asyncIterator]().return?.();
|
|
29
35
|
}
|
|
30
|
-
mismatch(expected, result
|
|
36
|
+
mismatch(expected, result);
|
|
31
37
|
}
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { DeploymentRetired, MissControl, StaleControl } from '../transport/index.js';
|
|
2
|
+
import type { Result } from './result.js';
|
|
3
3
|
import { MissError, ResponseError, StaleRouteError } from '../errors/index.js';
|
|
4
|
-
/**
|
|
5
|
-
export
|
|
6
|
-
/**
|
|
7
|
-
export declare function
|
|
4
|
+
/** A reserved pre-handler control the Transport decoded in place of a Function result. */
|
|
5
|
+
export type RoutingControl = StaleControl | MissControl | DeploymentRetired;
|
|
6
|
+
/** Whether a package-private dispatch answered with routing control rather than a result. */
|
|
7
|
+
export declare function isRoutingControl(input: Result | RoutingControl): input is RoutingControl;
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
* `ResponseError(3002, DEPLOYMENT_RETIRED)
|
|
9
|
+
* The public error every Client reports for one routing control; a retirement is
|
|
10
|
+
* `ResponseError(3002, DEPLOYMENT_RETIRED)`.
|
|
11
11
|
*/
|
|
12
|
-
export declare function
|
|
13
|
-
/**
|
|
14
|
-
export declare function
|
|
15
|
-
/** Distinguish decoded routing control from public or caller-supplied lookalike errors. */
|
|
16
|
-
export declare function isAdmittedStaleRouteError(input: unknown): input is StaleRouteError;
|
|
17
|
-
/** Distinguish a decoded retirement control from a lookalike `DEPLOYMENT_RETIRED` response. */
|
|
18
|
-
export declare function isAdmittedDeploymentRetiredError(input: unknown): input is ResponseError;
|
|
12
|
+
export declare function routingControlError(control: RoutingControl): StaleRouteError | MissError | ResponseError;
|
|
13
|
+
/** The routing control this exact error was raised for; a lookalike error carries none. */
|
|
14
|
+
export declare function raisedRoutingControl(input: unknown): RoutingControl | undefined;
|
|
@@ -1,38 +1,30 @@
|
|
|
1
1
|
import { CODES } from '@astrale-os/kernel-protocol/errors';
|
|
2
2
|
import { MissError, ResponseError, StaleRouteError } from '../errors/index.js';
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export function admittedMissError(invocation) {
|
|
8
|
-
const error = new MissError(invocation);
|
|
9
|
-
admittedMisses.add(error);
|
|
10
|
-
return error;
|
|
11
|
-
}
|
|
12
|
-
/** Create a private routing witness only after exact reserved-control decoding. */
|
|
13
|
-
export function admittedStaleRouteError(current, invocation) {
|
|
14
|
-
const error = new StaleRouteError(current, invocation);
|
|
15
|
-
admittedStaleRoutes.add(error);
|
|
16
|
-
return error;
|
|
3
|
+
const raised = new WeakMap();
|
|
4
|
+
/** Whether a package-private dispatch answered with routing control rather than a result. */
|
|
5
|
+
export function isRoutingControl(input) {
|
|
6
|
+
return input.kind === 'stale' || input.kind === 'miss' || input.kind === 'deployment-retired';
|
|
17
7
|
}
|
|
18
8
|
/**
|
|
19
|
-
*
|
|
20
|
-
* `ResponseError(3002, DEPLOYMENT_RETIRED)
|
|
9
|
+
* The public error every Client reports for one routing control; a retirement is
|
|
10
|
+
* `ResponseError(3002, DEPLOYMENT_RETIRED)`.
|
|
21
11
|
*/
|
|
22
|
-
export function
|
|
23
|
-
const error =
|
|
24
|
-
|
|
12
|
+
export function routingControlError(control) {
|
|
13
|
+
const error = publicError(control);
|
|
14
|
+
raised.set(error, control);
|
|
25
15
|
return error;
|
|
26
16
|
}
|
|
27
|
-
/**
|
|
28
|
-
export function
|
|
29
|
-
return input
|
|
30
|
-
}
|
|
31
|
-
/** Distinguish decoded routing control from public or caller-supplied lookalike errors. */
|
|
32
|
-
export function isAdmittedStaleRouteError(input) {
|
|
33
|
-
return input instanceof StaleRouteError && admittedStaleRoutes.has(input);
|
|
17
|
+
/** The routing control this exact error was raised for; a lookalike error carries none. */
|
|
18
|
+
export function raisedRoutingControl(input) {
|
|
19
|
+
return typeof input === 'object' && input !== null ? raised.get(input) : undefined;
|
|
34
20
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
21
|
+
function publicError(control) {
|
|
22
|
+
switch (control.kind) {
|
|
23
|
+
case 'stale':
|
|
24
|
+
return new StaleRouteError(control.current, control.invocation);
|
|
25
|
+
case 'miss':
|
|
26
|
+
return new MissError(control.invocation);
|
|
27
|
+
case 'deployment-retired':
|
|
28
|
+
return new ResponseError(CODES.NOT_FOUND, control.message, control.invocation, control.reason);
|
|
29
|
+
}
|
|
38
30
|
}
|
package/dist/errors/index.d.ts
CHANGED
|
@@ -2,7 +2,10 @@ export * from './client-error.js';
|
|
|
2
2
|
export * from './exchange-error.js';
|
|
3
3
|
export * from './miss-error.js';
|
|
4
4
|
export * from './protocol-error.js';
|
|
5
|
+
export * from './query-input.js';
|
|
6
|
+
export * from './refusal.js';
|
|
5
7
|
export * from './response-error.js';
|
|
8
|
+
export * from './response-too-large-error.js';
|
|
6
9
|
export * from './session-error.js';
|
|
7
10
|
export * from './stale-route-error.js';
|
|
8
11
|
export * from './transport-error.js';
|
package/dist/errors/index.js
CHANGED
|
@@ -2,7 +2,10 @@ export * from './client-error.js';
|
|
|
2
2
|
export * from './exchange-error.js';
|
|
3
3
|
export * from './miss-error.js';
|
|
4
4
|
export * from './protocol-error.js';
|
|
5
|
+
export * from './query-input.js';
|
|
6
|
+
export * from './refusal.js';
|
|
5
7
|
export * from './response-error.js';
|
|
8
|
+
export * from './response-too-large-error.js';
|
|
6
9
|
export * from './session-error.js';
|
|
7
10
|
export * from './stale-route-error.js';
|
|
8
11
|
export * from './transport-error.js';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Refusal } from '@astrale-os/kernel-core/graph/query';
|
|
2
|
+
import * as errors from '@astrale-os/kernel-protocol/errors';
|
|
3
|
+
import { ResponseError } from './response-error.js';
|
|
4
|
+
/**
|
|
5
|
+
* Why the Kernel refused a Query as input (`QUERY_INPUT_INVALID`), by the phase that refused it.
|
|
6
|
+
* Nothing was read, and the same request is refused again.
|
|
7
|
+
*/
|
|
8
|
+
export type QueryInputDetails =
|
|
9
|
+
/** A v7 Query the wire refused whole: each fault, where it is and how to fix it (§ Wire v7). */
|
|
10
|
+
{
|
|
11
|
+
readonly phase: 'decode';
|
|
12
|
+
readonly refusals: readonly Readonly<Refusal>[];
|
|
13
|
+
}
|
|
14
|
+
/** A Query its planning refused: the issue, and where in the request when it says. */
|
|
15
|
+
| {
|
|
16
|
+
readonly phase: 'plan';
|
|
17
|
+
readonly issue: string;
|
|
18
|
+
readonly path?: string;
|
|
19
|
+
}
|
|
20
|
+
/** A Query past a limit the Kernel sets for every caller: which, its maximum, what it needs. */
|
|
21
|
+
| {
|
|
22
|
+
readonly phase: 'plan';
|
|
23
|
+
readonly issue: 'QUERY_PLAN_LIMIT_EXCEEDED';
|
|
24
|
+
readonly limit: string;
|
|
25
|
+
readonly maximum: number;
|
|
26
|
+
readonly actual: number;
|
|
27
|
+
readonly path?: string;
|
|
28
|
+
}
|
|
29
|
+
/** An `expected` closure the Kernel cannot read, or a V6 page size: where. */
|
|
30
|
+
| {
|
|
31
|
+
readonly phase: 'input';
|
|
32
|
+
readonly path: string;
|
|
33
|
+
}
|
|
34
|
+
/** A V6 QueryAST the Kernel could not decode: where. */
|
|
35
|
+
| {
|
|
36
|
+
readonly phase: 'decode';
|
|
37
|
+
readonly path: string;
|
|
38
|
+
};
|
|
39
|
+
/** The reason of a Query the Kernel refused as input. */
|
|
40
|
+
export type QueryInputReason = errors.ErrorReason<'QUERY_INPUT_INVALID', QueryInputDetails>;
|
|
41
|
+
/**
|
|
42
|
+
* Whether the Kernel refused a Query as input: nothing was read, and resending it unchanged is
|
|
43
|
+
* refused again. Its `reason.details` then say where and why, typed by phase.
|
|
44
|
+
*/
|
|
45
|
+
export declare function isQueryInputInvalid(error: unknown): error is Omit<ResponseError, 'reason'> & {
|
|
46
|
+
readonly reason: QueryInputReason;
|
|
47
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { ENVELOPE_POINTER_LENGTH } from '@astrale-os/kernel-protocol/codecs';
|
|
2
|
+
import * as errors from '@astrale-os/kernel-protocol/errors';
|
|
3
|
+
import { ResponseError } from './response-error.js';
|
|
4
|
+
/**
|
|
5
|
+
* Whether the Kernel refused a Query as input: nothing was read, and resending it unchanged is
|
|
6
|
+
* refused again. Its `reason.details` then say where and why, typed by phase.
|
|
7
|
+
*/
|
|
8
|
+
export function isQueryInputInvalid(error) {
|
|
9
|
+
return (error instanceof ResponseError &&
|
|
10
|
+
error.code === errors.CODES.VALIDATION_ERROR &&
|
|
11
|
+
error.reason?.code === 'QUERY_INPUT_INVALID' &&
|
|
12
|
+
isQueryInputDetails(error.reason.details));
|
|
13
|
+
}
|
|
14
|
+
const REFUSAL_FIELDS = new Set([
|
|
15
|
+
'code',
|
|
16
|
+
'path',
|
|
17
|
+
'expected',
|
|
18
|
+
'fix',
|
|
19
|
+
'didYouMean',
|
|
20
|
+
'tier',
|
|
21
|
+
]);
|
|
22
|
+
const ISSUE = /^[A-Z][A-Z0-9_]{0,127}$/u;
|
|
23
|
+
/** The details the Kernel gives a refused Query, each phase with exactly its own fields. */
|
|
24
|
+
function isQueryInputDetails(details) {
|
|
25
|
+
const path = details.path === undefined ? [] : ['path'];
|
|
26
|
+
switch (details.phase) {
|
|
27
|
+
case 'decode':
|
|
28
|
+
return Object.hasOwn(details, 'refusals')
|
|
29
|
+
? exact(details, ['phase', 'refusals']) &&
|
|
30
|
+
Array.isArray(details.refusals) &&
|
|
31
|
+
details.refusals.length > 0 &&
|
|
32
|
+
details.refusals.every(isRefusal)
|
|
33
|
+
: exact(details, ['phase', 'path']) && isPointer(details.path);
|
|
34
|
+
case 'input':
|
|
35
|
+
return exact(details, ['phase', 'path']) && isPointer(details.path);
|
|
36
|
+
case 'plan':
|
|
37
|
+
if (typeof details.issue !== 'string' ||
|
|
38
|
+
!ISSUE.test(details.issue) ||
|
|
39
|
+
(details.path !== undefined && !isPointer(details.path))) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
if (!Object.hasOwn(details, 'limit'))
|
|
43
|
+
return exact(details, ['phase', 'issue', ...path]);
|
|
44
|
+
return (details.issue === 'QUERY_PLAN_LIMIT_EXCEEDED' &&
|
|
45
|
+
exact(details, ['phase', 'issue', 'limit', 'maximum', 'actual', ...path]) &&
|
|
46
|
+
typeof details.limit === 'string' &&
|
|
47
|
+
details.limit.length > 0 &&
|
|
48
|
+
isCount(details.maximum) &&
|
|
49
|
+
isCount(details.actual) &&
|
|
50
|
+
details.actual > details.maximum);
|
|
51
|
+
default:
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** One refusal of the v7 wire, as the Kernel carries it: `{code, path, expected, fix, …}`. */
|
|
56
|
+
function isRefusal(input) {
|
|
57
|
+
return (isObject(input) &&
|
|
58
|
+
Object.keys(input).every((field) => REFUSAL_FIELDS.has(field)) &&
|
|
59
|
+
typeof input.code === 'string' &&
|
|
60
|
+
/^QUERY_[A-Z_]{1,64}$/u.test(input.code) &&
|
|
61
|
+
isPointer(input.path) &&
|
|
62
|
+
typeof input.expected === 'string' &&
|
|
63
|
+
typeof input.fix === 'string' &&
|
|
64
|
+
(input.didYouMean === undefined ||
|
|
65
|
+
(Array.isArray(input.didYouMean) &&
|
|
66
|
+
input.didYouMean.every((name) => typeof name === 'string'))) &&
|
|
67
|
+
(input.tier === undefined || typeof input.tier === 'string'));
|
|
68
|
+
}
|
|
69
|
+
/** An RFC 6901 pointer into the request, as the Kernel bounds it. */
|
|
70
|
+
function isPointer(input) {
|
|
71
|
+
return (typeof input === 'string' &&
|
|
72
|
+
input.length <= ENVELOPE_POINTER_LENGTH &&
|
|
73
|
+
input.normalize('NFC') === input &&
|
|
74
|
+
(input === '' || input.startsWith('/')));
|
|
75
|
+
}
|
|
76
|
+
function isCount(input) {
|
|
77
|
+
return typeof input === 'number' && Number.isSafeInteger(input) && input >= 0;
|
|
78
|
+
}
|
|
79
|
+
function isObject(input) {
|
|
80
|
+
return input !== null && typeof input === 'object' && !Array.isArray(input);
|
|
81
|
+
}
|
|
82
|
+
function exact(input, fields) {
|
|
83
|
+
return (Object.keys(input).length === fields.length &&
|
|
84
|
+
fields.every((field) => Object.hasOwn(input, field)));
|
|
85
|
+
}
|