@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
|
@@ -4,21 +4,20 @@ import { runSessionOperation, sessionTransportOptions } from '../context/index.j
|
|
|
4
4
|
import { requireResultKind, resolveAuth } from '../routing/index.js';
|
|
5
5
|
import { ISSUANCE_MARGIN_SECONDS } from './limits.js';
|
|
6
6
|
/** The source credential can no longer grant a delegation that covers what its exchange carries. */
|
|
7
|
+
export const EXHAUSTED = Symbol('exhausted');
|
|
8
|
+
/** The public failure of an exhausted source, once no renewal can replace it. */
|
|
7
9
|
export function sourceExhausted() {
|
|
8
10
|
return new ExchangeError('The source credential expires too soon for a Domain token exchange.', {
|
|
9
11
|
failure: 'source-exhausted',
|
|
10
12
|
});
|
|
11
13
|
}
|
|
12
|
-
export function isAuthority(auth) {
|
|
13
|
-
return auth.credential !== undefined && auth.delegate !== undefined;
|
|
14
|
-
}
|
|
15
14
|
/** The source Kernel conversation of one exchange, acting as exactly the admitted source caller. */
|
|
16
15
|
export function sourceCaller(dependencies, auth, operation) {
|
|
17
16
|
const client = dependencies.source();
|
|
18
|
-
const caller = auth.
|
|
17
|
+
const caller = auth.kind === 'anonymous' ? client : client.as(auth.credential);
|
|
19
18
|
const dispatch = (input) => runSessionOperation(operation, () => caller.dispatch(input, {
|
|
20
19
|
...sessionTransportOptions(operation),
|
|
21
|
-
...(auth.
|
|
20
|
+
...(auth.kind === 'anonymous' ? {} : { delegate: auth.delegate }),
|
|
22
21
|
}));
|
|
23
22
|
const call = async (target, input) => requireResultKind('value', await dispatch({ target, input })).value;
|
|
24
23
|
return Object.freeze({ dispatch, call });
|
|
@@ -29,42 +28,42 @@ export function sourceCaller(dependencies, auth, operation) {
|
|
|
29
28
|
* transport-held source leaves the bound to the Kernel. A source that cannot grant one second, or
|
|
30
29
|
* bounds the delegation within `coverageMs`, is exhausted.
|
|
31
30
|
*/
|
|
32
|
-
export function delegationTtl(
|
|
33
|
-
const remaining = remainingSeconds(credential);
|
|
31
|
+
export function delegationTtl(source, ttlSeconds, coverageMs = 0) {
|
|
32
|
+
const remaining = source.kind === 'anonymous' ? undefined : remainingSeconds(source.credential);
|
|
34
33
|
if (remaining === undefined || remaining >= ttlSeconds)
|
|
35
34
|
return ttlSeconds;
|
|
36
35
|
if (remaining < 1 || remaining * 1_000 <= coverageMs)
|
|
37
|
-
|
|
36
|
+
return EXHAUSTED;
|
|
38
37
|
return remaining;
|
|
39
38
|
}
|
|
40
39
|
/**
|
|
41
40
|
* Run `attempt` with the resolved source, and once more with a renewed source if that one proved
|
|
42
41
|
* exhausted. The Session auth is refreshed only while it still resolves the exhausted credential, so
|
|
43
|
-
* concurrent Calls share one renewal; an auth that cannot refresh
|
|
42
|
+
* concurrent Calls share one renewal; an auth that cannot refresh fails as `sourceExhausted`.
|
|
44
43
|
*/
|
|
45
44
|
export async function renewing(auth, call, source, operation, attempt) {
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
const first = await attempt(source);
|
|
46
|
+
if (first !== EXHAUSTED)
|
|
47
|
+
return first;
|
|
48
|
+
let renewed = await resolveAuth(auth, call, operation);
|
|
49
|
+
const refresh = auth.refresh;
|
|
50
|
+
if (renewed.kind === 'authenticated' &&
|
|
51
|
+
renewed.credential === source.credential &&
|
|
52
|
+
refresh !== undefined) {
|
|
53
|
+
await runSessionOperation(operation, async (signal) => {
|
|
54
|
+
await refresh(signal);
|
|
55
|
+
});
|
|
56
|
+
renewed = await resolveAuth(auth, call, operation);
|
|
48
57
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
throw cause;
|
|
52
|
-
let renewed = await resolveAuth(auth, call, operation);
|
|
53
|
-
if (renewed.credential === source.credential && auth.refresh !== undefined) {
|
|
54
|
-
const refresh = auth.refresh;
|
|
55
|
-
await runSessionOperation(operation, async (signal) => {
|
|
56
|
-
await refresh(signal);
|
|
57
|
-
});
|
|
58
|
-
renewed = await resolveAuth(auth, call, operation);
|
|
59
|
-
}
|
|
60
|
-
if (!isAuthority(renewed) || renewed.credential === source.credential)
|
|
61
|
-
throw cause;
|
|
62
|
-
return attempt(renewed);
|
|
58
|
+
if (renewed.kind === 'anonymous' || renewed.credential === source.credential) {
|
|
59
|
+
throw sourceExhausted();
|
|
63
60
|
}
|
|
61
|
+
const second = await attempt(renewed);
|
|
62
|
+
if (second === EXHAUSTED)
|
|
63
|
+
throw sourceExhausted();
|
|
64
|
+
return second;
|
|
64
65
|
}
|
|
65
66
|
function remainingSeconds(credential) {
|
|
66
|
-
if (credential === undefined)
|
|
67
|
-
return undefined;
|
|
68
67
|
let expiresAt;
|
|
69
68
|
try {
|
|
70
69
|
expiresAt = inspect(credential).claims.exp;
|
package/dist/session/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { SessionControlOptions, SessionPolicy } from './context/index.js';
|
|
2
|
-
export type { ContentApi, ContentDownload, ContentLocation, ContentRejection, ContentUploadOptions, ContentUploadResult, } from './content/index.js';
|
|
2
|
+
export type { ContentApi, ContentDownload, ContentLocation, ContentRejection, ContentSource, ContentUploadOptions, ContentUploadResult, } from './content/index.js';
|
|
3
3
|
export { bindSession, type BoundClientSession, type BoundSessionControls, type BoundSessionSource, } from './bound.js';
|
|
4
4
|
export { credentials, type Credentials, type CredentialsMint, type CredentialsOptions, type CredentialsState, type SessionCredential, } from './credential/index.js';
|
|
5
5
|
export type { IntrinsicRelease, SessionSnapshot } from './discovery/index.js';
|
|
@@ -9,6 +9,7 @@ export type { ClientSessionOptions } from './options.js';
|
|
|
9
9
|
export { ClientSession, connect, type ConnectOptions } from './session.js';
|
|
10
10
|
export type { CallableReference, InputOfReference, InputModeOfReference, InstanceCallableReference, OutputOfReference, } from './reference.js';
|
|
11
11
|
export { reference } from './reference.js';
|
|
12
|
-
export {
|
|
13
|
-
export type {
|
|
12
|
+
export type { DeletedExecutionStatus, ExecutionApi, ExecutionFailure, ExecutionNodeStatus, ExecutionOutcome, ExecutionRef, ExecutionState, ExecutionStatus, ExecutionTarget, ExecutionWait, } from '../execution/index.js';
|
|
13
|
+
export type { View, ViewsOf } from './views/index.js';
|
|
14
|
+
export type { ResolvedView, ViewCatalog } from './views/legacy/index.js';
|
|
14
15
|
export type { DomainBinding } from '../graph/domain/index.js';
|
package/dist/session/index.js
CHANGED
|
@@ -33,7 +33,6 @@ export interface ClientSessionOptions {
|
|
|
33
33
|
readonly maximumBundleBytes?: number;
|
|
34
34
|
readonly maximumResponseBytes?: number;
|
|
35
35
|
readonly timeoutMs?: number;
|
|
36
|
-
readonly schemaLifecycleTimeoutMs?: number;
|
|
37
36
|
}
|
|
38
37
|
/** The caller's options once admitted, defaulted and captured, ready for the Session to wire. */
|
|
39
38
|
export interface SessionConfiguration {
|
|
@@ -45,7 +44,6 @@ export interface SessionConfiguration {
|
|
|
45
44
|
readonly maximumBundleBytes: number;
|
|
46
45
|
readonly maximumResponseBytes: number;
|
|
47
46
|
readonly timeoutMs: number;
|
|
48
|
-
readonly schemaLifecycleTimeoutMs: number;
|
|
49
47
|
readonly websocketAvailable: boolean;
|
|
50
48
|
/** Present when the Session created, and therefore closes, its own pool. */
|
|
51
49
|
readonly ownedPool?: ClientPool;
|
package/dist/session/options.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Client } from '../client/index.js';
|
|
2
2
|
import { ClientPool } from '../pool/index.js';
|
|
3
|
-
import { DEFAULT_SCHEMA_LIFECYCLE_TIMEOUT_MS } from '../schema/index.js';
|
|
4
3
|
import { AutoTransport } from '../transport/auto/index.js';
|
|
5
4
|
import { HttpTransport } from '../transport/http/index.js';
|
|
6
5
|
import { WebSocketTransport } from '../transport/websocket/index.js';
|
|
@@ -30,7 +29,6 @@ export function acceptSessionOptions(options) {
|
|
|
30
29
|
const maximumBundleBytes = positive(options.maximumBundleBytes ?? DEFAULT_MAXIMUM_BUNDLE_BYTES, 'maximumBundleBytes');
|
|
31
30
|
const maximumResponseBytes = positive(options.maximumResponseBytes ?? DEFAULT_MAXIMUM_RESPONSE_BYTES, 'maximumResponseBytes');
|
|
32
31
|
const timeoutMs = platformDuration(options.timeoutMs ?? DEFAULT_TIMEOUT_MS, 'timeoutMs');
|
|
33
|
-
const schemaLifecycleTimeoutMs = platformDuration(options.schemaLifecycleTimeoutMs ?? DEFAULT_SCHEMA_LIFECYCLE_TIMEOUT_MS, 'schemaLifecycleTimeoutMs');
|
|
34
32
|
let ownedPool;
|
|
35
33
|
let pool;
|
|
36
34
|
if (options.pool === undefined) {
|
|
@@ -62,7 +60,6 @@ export function acceptSessionOptions(options) {
|
|
|
62
60
|
maximumBundleBytes,
|
|
63
61
|
maximumResponseBytes,
|
|
64
62
|
timeoutMs,
|
|
65
|
-
schemaLifecycleTimeoutMs,
|
|
66
63
|
websocketAvailable: options.client !== undefined ||
|
|
67
64
|
options.pool !== undefined ||
|
|
68
65
|
options.websocket !== undefined ||
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { Path as PathValue, PathLike } from '@astrale-os/kernel-core/path';
|
|
2
|
-
import type { CallableInputOf, CallableInputModeOf, CallableOutputOf, CallableResultOf, Domain, ResolvedFunction, ExecutableMethod } from '@astrale-os/kernel-dsl/v1';
|
|
2
|
+
import type { CallableInputOf, CallableInputModeOf, CallableOutputOf, CallableResultOf, Domain, ResolvedFunction, ExecutableMethod, ResolvedMethod } from '@astrale-os/kernel-dsl/v1';
|
|
3
3
|
import type { MethodAddress } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
4
4
|
import type { MeaningFingerprint } from '@astrale-os/kernel-dsl/v1/schema/fingerprint';
|
|
5
5
|
import { type Key as KeyType } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
6
|
-
import type { Binary, Input } from '../client/index.js';
|
|
7
|
-
import type { ExecutionRef } from '
|
|
6
|
+
import type { Binary, Input, Result } from '../client/index.js';
|
|
7
|
+
import type { ExecutionRef } from '../execution/index.js';
|
|
8
|
+
/** Result kind a reference expects: a durable callable answers with its Execution. */
|
|
9
|
+
type OutputMode = Exclude<Result['kind'], 'redirect'>;
|
|
8
10
|
declare const REFERENCE_INPUT: unique symbol;
|
|
9
11
|
declare const REFERENCE_INPUT_MODE: unique symbol;
|
|
10
12
|
declare const REFERENCE_OUTPUT: unique symbol;
|
|
@@ -14,7 +16,7 @@ export interface CallableReference<InputValue = Input, Output = unknown, InputMo
|
|
|
14
16
|
readonly fingerprint?: MeaningFingerprint;
|
|
15
17
|
readonly callable: KeyType.Callable;
|
|
16
18
|
readonly target: PathValue;
|
|
17
|
-
readonly outputMode:
|
|
19
|
+
readonly outputMode: OutputMode;
|
|
18
20
|
readonly [REFERENCE_INPUT]?: InputValue;
|
|
19
21
|
readonly [REFERENCE_INPUT_MODE]?: InputMode;
|
|
20
22
|
readonly [REFERENCE_OUTPUT]?: Output;
|
|
@@ -24,7 +26,7 @@ export interface InstanceCallableReference<InputValue = Input, Output = unknown>
|
|
|
24
26
|
readonly origin: KeyType.Origin;
|
|
25
27
|
readonly fingerprint?: MeaningFingerprint;
|
|
26
28
|
readonly callable: KeyType.Callable;
|
|
27
|
-
readonly outputMode:
|
|
29
|
+
readonly outputMode: OutputMode;
|
|
28
30
|
}
|
|
29
31
|
export type InputOfReference<Reference extends CallableReference<unknown>> = Reference extends CallableReference<infer InputValue, unknown> ? InputValue : never;
|
|
30
32
|
export type OutputOfReference<Reference extends CallableReference<unknown>> = Reference extends CallableReference<infer _Input, infer Output> ? Output : never;
|
|
@@ -47,6 +49,8 @@ export declare function reference<const Callable extends ExecutableInstanceMetho
|
|
|
47
49
|
* addresses every Kernel syscall. Loading the Session therefore never resolves the Kernel Schema.
|
|
48
50
|
*/
|
|
49
51
|
export declare function kernelReference(method: MethodAddress): InstanceCallableReference<unknown>;
|
|
52
|
+
/** The result kind invoking this callable yields. */
|
|
53
|
+
export declare function outputModeOf(callable: ResolvedFunction | ResolvedMethod): OutputMode;
|
|
50
54
|
export declare function admitReference(input: CallableReference<unknown>): CallableReference<unknown>;
|
|
51
55
|
export declare function matchesCallable(target: PathValue, callable: KeyType.Callable): boolean;
|
|
52
56
|
export {};
|
|
@@ -2,6 +2,7 @@ import { Path } from '@astrale-os/kernel-core/path';
|
|
|
2
2
|
import { callableAddress, Key, MethodKey, patterns, } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
3
3
|
import { callableFingerprint } from '@astrale-os/kernel-dsl/v1/schema/fingerprint';
|
|
4
4
|
const FINGERPRINT_PATTERN = /^sha256:[0-9a-f]{64}$/u;
|
|
5
|
+
const OUTPUT_MODES = ['value', 'stream', 'binary', 'execution'];
|
|
5
6
|
export function reference(domain, callable) {
|
|
6
7
|
if (Key.origin(callable.key) !== domain.origin)
|
|
7
8
|
invalid();
|
|
@@ -11,7 +12,7 @@ export function reference(domain, callable) {
|
|
|
11
12
|
origin: domain.origin,
|
|
12
13
|
fingerprint: callableFingerprint(callable),
|
|
13
14
|
callable: callable.key,
|
|
14
|
-
outputMode: callable
|
|
15
|
+
outputMode: outputModeOf(callable),
|
|
15
16
|
});
|
|
16
17
|
if ('owner' in callable && !callable.static) {
|
|
17
18
|
const bind = (receiver) => admitReference({
|
|
@@ -39,6 +40,10 @@ export function kernelReference(method) {
|
|
|
39
40
|
const bind = (receiver) => admitReference({ ...common, target: Path.instanceMethod(Path.from(receiver), callable) });
|
|
40
41
|
return Object.assign(bind, common);
|
|
41
42
|
}
|
|
43
|
+
/** The result kind invoking this callable yields. */
|
|
44
|
+
export function outputModeOf(callable) {
|
|
45
|
+
return callable.execution?.durable === true ? 'execution' : callable.output.mode;
|
|
46
|
+
}
|
|
42
47
|
export function admitReference(input) {
|
|
43
48
|
if (input === null || typeof input !== 'object')
|
|
44
49
|
invalid();
|
|
@@ -47,7 +52,7 @@ export function admitReference(input) {
|
|
|
47
52
|
typeof input.callable !== 'string' ||
|
|
48
53
|
!Key.is(input.callable) ||
|
|
49
54
|
Key.origin(input.callable) !== input.origin ||
|
|
50
|
-
!
|
|
55
|
+
!OUTPUT_MODES.includes(input.outputMode) ||
|
|
51
56
|
(input.fingerprint !== undefined &&
|
|
52
57
|
(typeof input.fingerprint !== 'string' || !FINGERPRINT_PATTERN.test(input.fingerprint))))
|
|
53
58
|
invalid();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SessionOperation } from './context/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The pause before another attempt of a request whose attempt `failed` (counted from 1) threw
|
|
4
|
+
* `cause`, or `undefined` when that failure must not be retried.
|
|
5
|
+
*/
|
|
6
|
+
export type RetryPause = (cause: unknown, failed: number, operation: SessionOperation) => number | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Attempt `request` until it settles, its operation is interrupted, it has been attempted
|
|
9
|
+
* {@link MAXIMUM_ATTEMPTS} times, or `pause` declines its failure, pausing through the operation
|
|
10
|
+
* between attempts. A request that is not retried throws its last cause.
|
|
11
|
+
*/
|
|
12
|
+
export declare function retrySessionRequest<Result>(operation: SessionOperation, pause: RetryPause, request: () => Promise<Result>): Promise<Result>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { pauseSessionOperation } from './context/index.js';
|
|
2
|
+
/** The first attempt of a session request and at most two more. */
|
|
3
|
+
const MAXIMUM_ATTEMPTS = 3;
|
|
4
|
+
/**
|
|
5
|
+
* Attempt `request` until it settles, its operation is interrupted, it has been attempted
|
|
6
|
+
* {@link MAXIMUM_ATTEMPTS} times, or `pause` declines its failure, pausing through the operation
|
|
7
|
+
* between attempts. A request that is not retried throws its last cause.
|
|
8
|
+
*/
|
|
9
|
+
export async function retrySessionRequest(operation, pause, request) {
|
|
10
|
+
for (let failed = 1;; failed++) {
|
|
11
|
+
try {
|
|
12
|
+
return await request();
|
|
13
|
+
}
|
|
14
|
+
catch (cause) {
|
|
15
|
+
if (failed === MAXIMUM_ATTEMPTS || operation.signal.aborted)
|
|
16
|
+
throw cause;
|
|
17
|
+
const ms = pause(cause, failed, operation);
|
|
18
|
+
if (ms === undefined)
|
|
19
|
+
throw cause;
|
|
20
|
+
await pauseSessionOperation(operation, ms);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -16,10 +16,16 @@ export interface SessionAuth {
|
|
|
16
16
|
*/
|
|
17
17
|
refresh?(signal: AbortSignal): PromiseLike<unknown> | void;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
readonly
|
|
19
|
+
/** A credential with the delegation it carries. */
|
|
20
|
+
export interface Authenticated {
|
|
21
|
+
readonly kind: 'authenticated';
|
|
22
|
+
readonly credential: string;
|
|
23
|
+
readonly delegate: invocation.Delegate;
|
|
22
24
|
}
|
|
25
|
+
/** The authority one Call presents: none, or a credential with its delegation. */
|
|
26
|
+
export type EffectiveAuth = {
|
|
27
|
+
readonly kind: 'anonymous';
|
|
28
|
+
} | Authenticated;
|
|
23
29
|
/** Replace the resolved source authority of one Call before routing partitions and presents it. */
|
|
24
30
|
export interface AuthExchange {
|
|
25
31
|
resolve(call: invocation.Call, auth: EffectiveAuth, operation: SessionOperation): Promise<EffectiveAuth>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as protocol from '@astrale-os/kernel-protocol/invocation';
|
|
2
2
|
import { ClientError } from '../../errors/index.js';
|
|
3
3
|
import { runSessionOperation } from '../context/index.js';
|
|
4
|
+
const ANONYMOUS = Object.freeze({ kind: 'anonymous' });
|
|
4
5
|
export function admitSessionAuth(input) {
|
|
5
6
|
if (input === undefined)
|
|
6
7
|
return undefined;
|
|
@@ -21,7 +22,7 @@ export function admitSessionAuth(input) {
|
|
|
21
22
|
}
|
|
22
23
|
export async function resolveAuth(resolver, call, operation) {
|
|
23
24
|
if (resolver === undefined)
|
|
24
|
-
return
|
|
25
|
+
return ANONYMOUS;
|
|
25
26
|
const input = await runSessionOperation(operation, (signal) => resolver.resolve(call, signal));
|
|
26
27
|
if (input === null || typeof input !== 'object' || Array.isArray(input)) {
|
|
27
28
|
throw new ClientError('Session auth resolver returned an invalid value.');
|
|
@@ -38,9 +39,9 @@ export async function resolveAuth(resolver, call, operation) {
|
|
|
38
39
|
throw new ClientError('Session delegation overrides require a source credential.');
|
|
39
40
|
}
|
|
40
41
|
if (credential === undefined)
|
|
41
|
-
return
|
|
42
|
+
return ANONYMOUS;
|
|
42
43
|
const delegate = input.delegate === undefined
|
|
43
44
|
? protocol.acceptDelegate({ ttlSeconds: resolver.ttlSeconds })
|
|
44
45
|
: protocol.acceptDelegate(input.delegate);
|
|
45
|
-
return Object.freeze({ credential, delegate });
|
|
46
|
+
return Object.freeze({ kind: 'authenticated', credential, delegate });
|
|
46
47
|
}
|
|
@@ -6,20 +6,22 @@ export interface LearnedRoute {
|
|
|
6
6
|
readonly credential?: string;
|
|
7
7
|
readonly expiresAt: number;
|
|
8
8
|
}
|
|
9
|
-
/** One warm entry; `
|
|
9
|
+
/** One warm entry; `persisted` is present only when it can be persisted. */
|
|
10
10
|
export interface CachedRoute {
|
|
11
11
|
readonly learned: LearnedRoute;
|
|
12
12
|
/** Separate from route age; derived only from a supported finite carrier expiry. */
|
|
13
13
|
readonly credentialRefreshBoundary?: number;
|
|
14
|
-
|
|
15
|
-
readonly
|
|
14
|
+
/** The entry as it was sealed, with the HMAC binding it to its key. */
|
|
15
|
+
readonly persisted?: {
|
|
16
|
+
readonly sealed: LearnedRoute;
|
|
17
|
+
readonly integrity: string;
|
|
18
|
+
};
|
|
16
19
|
}
|
|
17
20
|
/** Confidential warm routing state owned by exactly one ClientSession. */
|
|
18
21
|
export declare class RouteCache {
|
|
19
22
|
private readonly maximumAgeMs;
|
|
20
23
|
private readonly maximumSize;
|
|
21
24
|
private readonly entries;
|
|
22
|
-
private readonly keyTokens;
|
|
23
25
|
private readonly store?;
|
|
24
26
|
constructor(maximumAgeMs: number, maximumSize?: number, store?: SessionRouteStore);
|
|
25
27
|
key(source: string, call: invocation.Call, auth: EffectiveAuth): Promise<string>;
|
|
@@ -28,8 +30,13 @@ export declare class RouteCache {
|
|
|
28
30
|
delete(key: string): void;
|
|
29
31
|
/** Clear this Session's memory without deleting caller-owned persistent state. */
|
|
30
32
|
clear(): void;
|
|
31
|
-
|
|
33
|
+
/** Mark the key's entry most recently used. */
|
|
34
|
+
private touch;
|
|
35
|
+
/** Fence any check in flight on the key; its warm route, if any, stays usable in place. */
|
|
32
36
|
private reserve;
|
|
37
|
+
/** Make the key the newest warm entry, evicting the least recently used beyond the bound. */
|
|
38
|
+
private warm;
|
|
39
|
+
private invalidate;
|
|
33
40
|
private restore;
|
|
34
41
|
private persist;
|
|
35
42
|
}
|
|
@@ -7,7 +7,6 @@ export class RouteCache {
|
|
|
7
7
|
maximumAgeMs;
|
|
8
8
|
maximumSize;
|
|
9
9
|
entries = new Map();
|
|
10
|
-
keyTokens = new Map();
|
|
11
10
|
store;
|
|
12
11
|
constructor(maximumAgeMs, maximumSize = DEFAULT_MAXIMUM_ROUTES, store) {
|
|
13
12
|
this.maximumAgeMs = maximumAgeMs;
|
|
@@ -16,27 +15,27 @@ export class RouteCache {
|
|
|
16
15
|
this.restore();
|
|
17
16
|
}
|
|
18
17
|
async key(source, call, auth) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
if (auth.kind === 'anonymous') {
|
|
19
|
+
return JSON.stringify([source, call.target, 'anonymous', 'anonymous']);
|
|
20
|
+
}
|
|
21
|
+
const credential = await digestText(auth.credential);
|
|
22
|
+
const delegate = await digestText(JSON.stringify({ ttlSeconds: auth.delegate.ttlSeconds }));
|
|
23
23
|
return JSON.stringify([source, call.target, credential, delegate]);
|
|
24
24
|
}
|
|
25
25
|
async get(key, sourceCredential, now, operationDeadline) {
|
|
26
|
-
const
|
|
27
|
-
|
|
26
|
+
const entry = this.entries.get(key);
|
|
27
|
+
const cached = entry?.cached;
|
|
28
|
+
if (entry === undefined || cached === undefined)
|
|
28
29
|
return undefined;
|
|
29
|
-
const token = this.keyTokens.get(key);
|
|
30
30
|
if (cached.learned.expiresAt <= (now ?? Date.now())) {
|
|
31
31
|
this.invalidate(key);
|
|
32
32
|
return undefined;
|
|
33
33
|
}
|
|
34
|
-
if (cached.
|
|
34
|
+
if (cached.persisted !== undefined) {
|
|
35
35
|
const matches = sourceCredential !== undefined &&
|
|
36
|
-
(await matchesIntegrity(sourceCredential, key, cached.sealed
|
|
37
|
-
if (this.
|
|
36
|
+
(await matchesIntegrity(sourceCredential, key, cached.persisted.sealed, cached.persisted.integrity));
|
|
37
|
+
if (this.entries.get(key) !== entry)
|
|
38
38
|
return undefined;
|
|
39
|
-
}
|
|
40
39
|
if (!matches) {
|
|
41
40
|
this.invalidate(key);
|
|
42
41
|
return undefined;
|
|
@@ -53,91 +52,100 @@ export class RouteCache {
|
|
|
53
52
|
// This operation needs a fresh carrier; a shorter concurrent operation may still reuse it.
|
|
54
53
|
return undefined;
|
|
55
54
|
}
|
|
56
|
-
this.
|
|
57
|
-
this.entries.set(key, cached);
|
|
55
|
+
this.touch(key, entry);
|
|
58
56
|
return cached.learned;
|
|
59
57
|
}
|
|
60
58
|
async learn(key, route, credential, sourceCredential, now = Date.now()) {
|
|
61
59
|
const expiry = credential === undefined ? undefined : credentialExpiry(credential);
|
|
62
60
|
const credentialRefreshBoundary = expiry === undefined ? undefined : refreshBoundary(expiry);
|
|
63
61
|
const expiresAt = Math.min(now + this.maximumAgeMs, refreshBoundary(expiry));
|
|
64
|
-
const
|
|
62
|
+
const learned = Object.freeze({
|
|
65
63
|
route,
|
|
66
64
|
...(credential === undefined ? {} : { credential }),
|
|
67
65
|
expiresAt,
|
|
68
66
|
});
|
|
69
67
|
// A carrier with no supported finite expiry may be used for this follow, but never warmed.
|
|
70
68
|
if (credential !== undefined && expiry === undefined)
|
|
71
|
-
return
|
|
69
|
+
return learned;
|
|
72
70
|
if (expiresAt <= now)
|
|
73
|
-
return
|
|
74
|
-
const
|
|
71
|
+
return learned;
|
|
72
|
+
const reserved = this.reserve(key);
|
|
75
73
|
let integrity;
|
|
76
74
|
if (this.store !== undefined && sourceCredential !== undefined) {
|
|
77
75
|
try {
|
|
78
|
-
integrity = await routeIntegrity(sourceCredential, key,
|
|
76
|
+
integrity = await routeIntegrity(sourceCredential, key, learned);
|
|
79
77
|
}
|
|
80
78
|
catch {
|
|
81
79
|
// Integrity support is a persistence optimization; the learned route remains usable in memory.
|
|
82
80
|
}
|
|
83
81
|
}
|
|
84
|
-
if (this.
|
|
85
|
-
return
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
while (this.entries.size >= this.maximumSize) {
|
|
89
|
-
const oldest = this.entries.keys().next().value;
|
|
90
|
-
if (oldest === undefined)
|
|
91
|
-
break;
|
|
92
|
-
this.entries.delete(oldest);
|
|
93
|
-
this.keyTokens.delete(oldest);
|
|
94
|
-
}
|
|
95
|
-
this.entries.set(key, Object.freeze({
|
|
96
|
-
learned: entry,
|
|
82
|
+
if (this.entries.get(key) !== reserved)
|
|
83
|
+
return learned;
|
|
84
|
+
this.warm(key, Object.freeze({
|
|
85
|
+
learned,
|
|
97
86
|
...(credentialRefreshBoundary === undefined ? {} : { credentialRefreshBoundary }),
|
|
98
|
-
...(integrity === undefined
|
|
87
|
+
...(integrity === undefined
|
|
88
|
+
? {}
|
|
89
|
+
: { persisted: Object.freeze({ sealed: learned, integrity }) }),
|
|
99
90
|
}));
|
|
100
91
|
this.persist();
|
|
101
|
-
return
|
|
92
|
+
return learned;
|
|
102
93
|
}
|
|
103
94
|
delete(key) {
|
|
104
95
|
this.invalidate(key);
|
|
105
96
|
}
|
|
106
97
|
/** Clear this Session's memory without deleting caller-owned persistent state. */
|
|
107
98
|
clear() {
|
|
108
|
-
this.keyTokens.clear();
|
|
109
99
|
this.entries.clear();
|
|
110
100
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
101
|
+
/** Mark the key's entry most recently used. */
|
|
102
|
+
touch(key, entry) {
|
|
103
|
+
this.entries.delete(key);
|
|
104
|
+
this.entries.set(key, entry);
|
|
115
105
|
}
|
|
106
|
+
/** Fence any check in flight on the key; its warm route, if any, stays usable in place. */
|
|
116
107
|
reserve(key) {
|
|
117
|
-
const
|
|
118
|
-
this.
|
|
119
|
-
return
|
|
108
|
+
const reserved = Object.freeze({ ...this.entries.get(key) });
|
|
109
|
+
this.entries.set(key, reserved);
|
|
110
|
+
return reserved;
|
|
111
|
+
}
|
|
112
|
+
/** Make the key the newest warm entry, evicting the least recently used beyond the bound. */
|
|
113
|
+
warm(key, cached) {
|
|
114
|
+
this.entries.delete(key);
|
|
115
|
+
const warmKeys = [...this.entries].flatMap(([other, entry]) => entry.cached === undefined ? [] : [other]);
|
|
116
|
+
while (warmKeys.length >= this.maximumSize) {
|
|
117
|
+
const oldest = warmKeys.shift();
|
|
118
|
+
if (oldest === undefined)
|
|
119
|
+
break;
|
|
120
|
+
this.entries.delete(oldest);
|
|
121
|
+
}
|
|
122
|
+
this.entries.set(key, Object.freeze({ cached }));
|
|
123
|
+
}
|
|
124
|
+
invalidate(key) {
|
|
125
|
+
const entry = this.entries.get(key);
|
|
126
|
+
this.entries.delete(key);
|
|
127
|
+
if (entry?.cached !== undefined)
|
|
128
|
+
this.persist();
|
|
120
129
|
}
|
|
121
130
|
restore(now = Date.now()) {
|
|
122
131
|
if (this.store === undefined)
|
|
123
132
|
return;
|
|
124
133
|
try {
|
|
125
134
|
const restored = restoreRoutes(this.store.read(), now, this.maximumAgeMs, this.maximumSize);
|
|
126
|
-
for (const [key,
|
|
127
|
-
this.
|
|
128
|
-
this.entries.set(key, entry);
|
|
129
|
-
}
|
|
135
|
+
for (const [key, cached] of restored)
|
|
136
|
+
this.entries.set(key, Object.freeze({ cached }));
|
|
130
137
|
}
|
|
131
138
|
catch {
|
|
132
|
-
|
|
139
|
+
// An unreadable store restores nothing; the Session starts cold.
|
|
133
140
|
this.entries.clear();
|
|
134
141
|
}
|
|
135
142
|
}
|
|
136
143
|
persist() {
|
|
137
144
|
if (this.store === undefined)
|
|
138
145
|
return;
|
|
146
|
+
const warmRoutes = [...this.entries].flatMap(([key, entry]) => entry.cached === undefined ? [] : [[key, entry.cached]]);
|
|
139
147
|
try {
|
|
140
|
-
this.store.write(routeArtifact(
|
|
148
|
+
this.store.write(routeArtifact(warmRoutes));
|
|
141
149
|
}
|
|
142
150
|
catch {
|
|
143
151
|
// A cache-store outage must not turn a valid invocation into a product failure.
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { IssuerId } from '@astrale-os/kernel-core/auth/issuer';
|
|
2
|
+
import type * as invocation from '@astrale-os/kernel-protocol/invocation';
|
|
2
3
|
import type { Result } from '../../client/index.js';
|
|
4
|
+
import type { BinaryBody } from '../../transport/http/binary-request.js';
|
|
3
5
|
import type { Fetch } from '../../transport/http/index.js';
|
|
4
6
|
import type { SessionOperation, SessionPolicy } from '../context/index.js';
|
|
5
|
-
import type { AuthExchange, SessionAuth } from './auth.js';
|
|
7
|
+
import type { AuthExchange, SessionAuth, EffectiveAuth } from './auth.js';
|
|
6
8
|
import type { RouteCache } from './cache.js';
|
|
7
9
|
import type { ClientPoolCapability } from './envelope.js';
|
|
8
10
|
import type { SessionEnvelopeTransport, SessionRequestOptions } from './request.js';
|
|
@@ -24,16 +26,37 @@ export interface SessionDispatcherOptions {
|
|
|
24
26
|
readonly timeoutMs: number;
|
|
25
27
|
};
|
|
26
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* A streaming call is forced over HTTP and may carry an admitted binary body, whose kind says
|
|
31
|
+
* whether it can be sent again: a Blob is read anew by every send, a stream only by the first.
|
|
32
|
+
*/
|
|
33
|
+
export interface Streaming {
|
|
34
|
+
readonly body?: BinaryBody;
|
|
35
|
+
}
|
|
36
|
+
/** One Call with the authority it presents on every dispatch, and the route partition it selects. */
|
|
37
|
+
export interface ResolvedCall {
|
|
38
|
+
readonly call: invocation.Call;
|
|
39
|
+
readonly auth: EffectiveAuth;
|
|
40
|
+
readonly source: IssuerId;
|
|
41
|
+
readonly cacheKey: string;
|
|
42
|
+
}
|
|
27
43
|
export declare class SessionDispatcher {
|
|
28
44
|
private readonly state;
|
|
29
45
|
constructor(state: SessionDispatcherOptions);
|
|
30
46
|
dispatch(input: Parameters<typeof acceptCall>[0], options: SessionRequestOptions, operation: SessionOperation): Promise<Result>;
|
|
31
47
|
/** Reuse Session authority and route recovery while forcing HTTP for streaming calls. */
|
|
32
|
-
dispatchHttp(input: Parameters<typeof acceptCall>[0], options: SessionRequestOptions, operation: SessionOperation, body?:
|
|
33
|
-
|
|
48
|
+
dispatchHttp(input: Parameters<typeof acceptCall>[0], options: SessionRequestOptions, operation: SessionOperation, body?: BinaryBody): Promise<Result>;
|
|
49
|
+
/** Resolve the Session authority of one Call: each dispatch of the result presents it. */
|
|
50
|
+
resolve(input: Parameters<typeof acceptCall>[0], operation: SessionOperation): Promise<ResolvedCall>;
|
|
51
|
+
/**
|
|
52
|
+
* Dispatch a resolved Call. Sending it again presents the same principal and caller, which an
|
|
53
|
+
* idempotency key needs to name the same Execution.
|
|
54
|
+
*/
|
|
55
|
+
dispatchResolved(resolved: ResolvedCall, options: SessionRequestOptions, operation: SessionOperation, streaming?: Streaming): Promise<Result>;
|
|
34
56
|
/** The cached route for this partition, evicted when it no longer passes delivery checks. */
|
|
35
57
|
private warmRoute;
|
|
36
58
|
private dispatchSource;
|
|
59
|
+
/** The source answers routing control only as the public error: it has no route to recover. */
|
|
37
60
|
private followSource;
|
|
38
61
|
private dispatchDestinationWithRecovery;
|
|
39
62
|
private dispatchDestination;
|