@astrale-os/kernel-client 1.0.0-beta.4 → 1.0.0-beta.41
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 +24 -0
- package/dist/errors/refusal.js +78 -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 +66 -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 +149 -7
- package/dist/graph/query.typecheck.d.ts +79 -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 +20 -2
- package/dist/session/content/api.js +17 -7
- package/dist/session/content/files.d.ts +12 -0
- package/dist/session/content/files.js +47 -0
- package/dist/session/content/index.d.ts +1 -1
- package/dist/session/content/input.d.ts +13 -2
- package/dist/session/content/input.js +25 -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 +5 -4
- 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 +27 -6
- package/dist/session/reference.js +18 -3
- 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 +67 -20
- 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 +9 -7
- 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
|
@@ -2,4 +2,4 @@ export { callableOrigin, installedIssuer } from './domain.js';
|
|
|
2
2
|
export { acquireDomainCredential, exchangeDomainCredential, } from './exchange.js';
|
|
3
3
|
export { admitExchangeOptions, admitExchangeRequest, } from './options.js';
|
|
4
4
|
export { createSessionExchange } from './presentation.js';
|
|
5
|
-
export {
|
|
5
|
+
export { EXHAUSTED, sourceExhausted } from './source.js';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ClientError } from '../../errors/index.js';
|
|
1
|
+
import { ClientError, ExchangeError } from '../../errors/index.js';
|
|
2
2
|
import { runSessionOperation } from '../context/index.js';
|
|
3
3
|
import { credentials, delegationCoverageMs } from '../credential/index.js';
|
|
4
4
|
import { createInstallations, declaringOrigin, isKernelOrigin } from './domain.js';
|
|
5
5
|
import { exchangeDomainCredential } from './exchange.js';
|
|
6
6
|
import { MAXIMUM_EXCHANGE_SOURCES } from './limits.js';
|
|
7
|
-
import {
|
|
7
|
+
import { EXHAUSTED, renewing, sourceExhausted } from './source.js';
|
|
8
8
|
/**
|
|
9
9
|
* Present each Call whose callable a remote installed Domain declares with the credential that
|
|
10
10
|
* Domain exchanged for the Call's source caller.
|
|
@@ -20,7 +20,7 @@ export function createSessionExchange(dependencies, options) {
|
|
|
20
20
|
const sources = new Map();
|
|
21
21
|
return Object.freeze({ resolve, clear });
|
|
22
22
|
async function resolve(call, effective, operation) {
|
|
23
|
-
if (
|
|
23
|
+
if (effective.kind === 'anonymous')
|
|
24
24
|
return effective;
|
|
25
25
|
const origin = declaringOrigin(call.target);
|
|
26
26
|
if (origin === undefined || isKernelOrigin(origin))
|
|
@@ -33,8 +33,21 @@ export function createSessionExchange(dependencies, options) {
|
|
|
33
33
|
throw new ClientError('Session delegation outlives the Domain credential it would carry.');
|
|
34
34
|
}
|
|
35
35
|
const domainCredentials = credentialsFor(source, domain);
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
let exchanged;
|
|
37
|
+
try {
|
|
38
|
+
exchanged = await runSessionOperation(operation, (signal) => domainCredentials.acquire(signal));
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
// Credentials settles a mint by value or rejection, so exhaustion crosses it as the error.
|
|
42
|
+
if (error instanceof ExchangeError && error.failure === 'source-exhausted')
|
|
43
|
+
return EXHAUSTED;
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
return Object.freeze({
|
|
47
|
+
kind: 'authenticated',
|
|
48
|
+
credential: exchanged.credential,
|
|
49
|
+
delegate: source.delegate,
|
|
50
|
+
});
|
|
38
51
|
});
|
|
39
52
|
}
|
|
40
53
|
function clear() {
|
|
@@ -48,11 +61,16 @@ export function createSessionExchange(dependencies, options) {
|
|
|
48
61
|
return known;
|
|
49
62
|
const domainCredentials = credentials({
|
|
50
63
|
ttlSeconds: auth.ttlSeconds,
|
|
51
|
-
mint: (signal) =>
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
64
|
+
mint: async (signal) => {
|
|
65
|
+
const exchanged = await exchangeDomainCredential(dependencies, source, {
|
|
66
|
+
issuer: domain,
|
|
67
|
+
ttlSeconds: options.ttlSeconds,
|
|
68
|
+
coverageMs,
|
|
69
|
+
}, dependencies.operation(signal));
|
|
70
|
+
if (exchanged === EXHAUSTED)
|
|
71
|
+
throw sourceExhausted();
|
|
72
|
+
return exchanged;
|
|
73
|
+
},
|
|
56
74
|
});
|
|
57
75
|
held.set(domain, domainCredentials);
|
|
58
76
|
return domainCredentials;
|
|
@@ -2,19 +2,19 @@ import type { invocation } from '@astrale-os/kernel-protocol';
|
|
|
2
2
|
import type { AuthCall } from '../../auth/auth.js';
|
|
3
3
|
import type { Call, Result } from '../../client/index.js';
|
|
4
4
|
import type { SessionOperation } from '../context/index.js';
|
|
5
|
-
import type { EffectiveAuth, SessionAuth } from '../routing/index.js';
|
|
5
|
+
import type { Authenticated, EffectiveAuth, SessionAuth } from '../routing/index.js';
|
|
6
6
|
import type { ExchangeDependencies } from './exchange.js';
|
|
7
7
|
import { ExchangeError } from '../../errors/index.js';
|
|
8
|
-
/** A resolved source that carries both a credential and its delegation. */
|
|
9
|
-
export type SourceAuthority = Required<EffectiveAuth>;
|
|
10
8
|
/** Source Kernel syscalls issued as exactly one admitted source caller within one operation. */
|
|
11
9
|
interface SourceCaller {
|
|
12
10
|
dispatch(call: Call): Promise<Result>;
|
|
13
11
|
readonly call: AuthCall;
|
|
14
12
|
}
|
|
15
13
|
/** The source credential can no longer grant a delegation that covers what its exchange carries. */
|
|
14
|
+
export declare const EXHAUSTED: unique symbol;
|
|
15
|
+
export type Exhausted = typeof EXHAUSTED;
|
|
16
|
+
/** The public failure of an exhausted source, once no renewal can replace it. */
|
|
16
17
|
export declare function sourceExhausted(): ExchangeError;
|
|
17
|
-
export declare function isAuthority(auth: EffectiveAuth): auth is SourceAuthority;
|
|
18
18
|
/** The source Kernel conversation of one exchange, acting as exactly the admitted source caller. */
|
|
19
19
|
export declare function sourceCaller(dependencies: Pick<ExchangeDependencies, 'source'>, auth: EffectiveAuth, operation: SessionOperation): SourceCaller;
|
|
20
20
|
/**
|
|
@@ -23,11 +23,11 @@ export declare function sourceCaller(dependencies: Pick<ExchangeDependencies, 's
|
|
|
23
23
|
* transport-held source leaves the bound to the Kernel. A source that cannot grant one second, or
|
|
24
24
|
* bounds the delegation within `coverageMs`, is exhausted.
|
|
25
25
|
*/
|
|
26
|
-
export declare function delegationTtl(
|
|
26
|
+
export declare function delegationTtl(source: EffectiveAuth, ttlSeconds: number, coverageMs?: number): number | Exhausted;
|
|
27
27
|
/**
|
|
28
28
|
* Run `attempt` with the resolved source, and once more with a renewed source if that one proved
|
|
29
29
|
* exhausted. The Session auth is refreshed only while it still resolves the exhausted credential, so
|
|
30
|
-
* concurrent Calls share one renewal; an auth that cannot refresh
|
|
30
|
+
* concurrent Calls share one renewal; an auth that cannot refresh fails as `sourceExhausted`.
|
|
31
31
|
*/
|
|
32
|
-
export declare function renewing<T>(auth: SessionAuth, call: invocation.Call, source:
|
|
32
|
+
export declare function renewing<T>(auth: SessionAuth, call: invocation.Call, source: Authenticated, operation: SessionOperation, attempt: (source: Authenticated) => Promise<T | Exhausted>): Promise<T>;
|
|
33
33
|
export {};
|
|
@@ -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, ContentReceipt, 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';
|
|
@@ -7,8 +7,9 @@ export type { SessionExchangeOptions, SessionExchangeRequest } from './exchange/
|
|
|
7
7
|
export type { Auth, PersistedRoute, SessionRouteArtifact, SessionRouteStore, SessionAuth, SessionEnvelopeTransport, SessionRequestOptions, SessionRequestOptionsWithBody, } from './routing/index.js';
|
|
8
8
|
export type { ClientSessionOptions } from './options.js';
|
|
9
9
|
export { ClientSession, connect, type ConnectOptions } from './session.js';
|
|
10
|
-
export type { CallableReference, InputOfReference, InputModeOfReference, InstanceCallableReference, OutputOfReference, } from './reference.js';
|
|
10
|
+
export type { CallableReference, FileSourcesOf, 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,13 @@
|
|
|
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 { BlobReceipt, 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
|
+
import type { FilePosition } from '@astrale-os/kernel-dsl/v1/schema/values';
|
|
5
6
|
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 '
|
|
7
|
+
import type { Binary, Input, Result } from '../client/index.js';
|
|
8
|
+
import type { ExecutionRef } from '../execution/index.js';
|
|
9
|
+
/** Result kind a reference expects: a durable callable answers with its Execution. */
|
|
10
|
+
type OutputMode = Exclude<Result['kind'], 'redirect'>;
|
|
8
11
|
declare const REFERENCE_INPUT: unique symbol;
|
|
9
12
|
declare const REFERENCE_INPUT_MODE: unique symbol;
|
|
10
13
|
declare const REFERENCE_OUTPUT: unique symbol;
|
|
@@ -14,7 +17,12 @@ export interface CallableReference<InputValue = Input, Output = unknown, InputMo
|
|
|
14
17
|
readonly fingerprint?: MeaningFingerprint;
|
|
15
18
|
readonly callable: KeyType.Callable;
|
|
16
19
|
readonly target: PathValue;
|
|
17
|
-
readonly outputMode:
|
|
20
|
+
readonly outputMode: OutputMode;
|
|
21
|
+
/**
|
|
22
|
+
* Where the callable input holds file fields. `invoke` uploads a Blob or File found there and
|
|
23
|
+
* sends its receipt; a generated reference carries them, a Kernel reference none.
|
|
24
|
+
*/
|
|
25
|
+
readonly files?: readonly FilePosition[];
|
|
18
26
|
readonly [REFERENCE_INPUT]?: InputValue;
|
|
19
27
|
readonly [REFERENCE_INPUT_MODE]?: InputMode;
|
|
20
28
|
readonly [REFERENCE_OUTPUT]?: Output;
|
|
@@ -24,12 +32,21 @@ export interface InstanceCallableReference<InputValue = Input, Output = unknown>
|
|
|
24
32
|
readonly origin: KeyType.Origin;
|
|
25
33
|
readonly fingerprint?: MeaningFingerprint;
|
|
26
34
|
readonly callable: KeyType.Callable;
|
|
27
|
-
readonly outputMode:
|
|
35
|
+
readonly outputMode: OutputMode;
|
|
36
|
+
readonly files?: readonly FilePosition[];
|
|
28
37
|
}
|
|
29
38
|
export type InputOfReference<Reference extends CallableReference<unknown>> = Reference extends CallableReference<infer InputValue, unknown> ? InputValue : never;
|
|
30
39
|
export type OutputOfReference<Reference extends CallableReference<unknown>> = Reference extends CallableReference<infer _Input, infer Output> ? Output : never;
|
|
31
40
|
export type InputModeOfReference<Reference extends CallableReference<unknown>> = Reference extends CallableReference<infer _Input, infer _Output, infer Mode> ? Mode : never;
|
|
32
|
-
type ReferenceInput<Callable> = unknown extends CallableInputOf<Callable> ? Input : CallableInputOf<Callable
|
|
41
|
+
type ReferenceInput<Callable> = unknown extends CallableInputOf<Callable> ? Input : FileSourcesOf<CallableInputOf<Callable>>;
|
|
42
|
+
type ContainsReceipt<Value, Depth extends readonly unknown[] = []> = Depth['length'] extends 8 ? false : Value extends BlobReceipt ? true : Value extends object ? true extends {
|
|
43
|
+
[Key in keyof Value]-?: ContainsReceipt<Value[Key], readonly [...Depth, unknown]>;
|
|
44
|
+
}[keyof Value] ? true : false : false;
|
|
45
|
+
/** A typed input whose file fields also take the Blob or File `invoke` uploads first. */
|
|
46
|
+
export type FileSourcesOf<Value> = true extends ContainsReceipt<Value> ? FileSourcesIn<Value> : Value;
|
|
47
|
+
type FileSourcesIn<Value> = Value extends BlobReceipt ? Value | Blob : Value extends object ? {
|
|
48
|
+
[Key in keyof Value]: FileSourcesIn<Value[Key]>;
|
|
49
|
+
} : Value;
|
|
33
50
|
type HandlerOutput<Callable> = unknown extends CallableOutputOf<Callable> ? unknown : CallableResultOf<Callable, Binary>;
|
|
34
51
|
type ReferenceOutput<Callable> = Callable extends {
|
|
35
52
|
readonly execution: {
|
|
@@ -47,6 +64,10 @@ export declare function reference<const Callable extends ExecutableInstanceMetho
|
|
|
47
64
|
* addresses every Kernel syscall. Loading the Session therefore never resolves the Kernel Schema.
|
|
48
65
|
*/
|
|
49
66
|
export declare function kernelReference(method: MethodAddress): InstanceCallableReference<unknown>;
|
|
67
|
+
/** Where the input of this callable holds file fields. */
|
|
68
|
+
export declare function filesOf(callable: ResolvedFunction | ResolvedMethod): readonly FilePosition[];
|
|
69
|
+
/** The result kind invoking this callable yields. */
|
|
70
|
+
export declare function outputModeOf(callable: ResolvedFunction | ResolvedMethod): OutputMode;
|
|
50
71
|
export declare function admitReference(input: CallableReference<unknown>): CallableReference<unknown>;
|
|
51
72
|
export declare function matchesCallable(target: PathValue, callable: KeyType.Callable): boolean;
|
|
52
73
|
export {};
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { Path } from '@astrale-os/kernel-core/path';
|
|
2
2
|
import { callableAddress, Key, MethodKey, patterns, } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
3
|
+
import { isBinaryInput } from '@astrale-os/kernel-dsl/v1/language';
|
|
3
4
|
import { callableFingerprint } from '@astrale-os/kernel-dsl/v1/schema/fingerprint';
|
|
5
|
+
import { filePositions } from '@astrale-os/kernel-dsl/v1/schema/values';
|
|
4
6
|
const FINGERPRINT_PATTERN = /^sha256:[0-9a-f]{64}$/u;
|
|
7
|
+
const OUTPUT_MODES = ['value', 'stream', 'binary', 'execution'];
|
|
5
8
|
export function reference(domain, callable) {
|
|
6
9
|
if (Key.origin(callable.key) !== domain.origin)
|
|
7
10
|
invalid();
|
|
8
11
|
if ('owner' in callable && !callable.executable)
|
|
9
12
|
invalid();
|
|
13
|
+
const files = filesOf(callable);
|
|
10
14
|
const common = Object.freeze({
|
|
11
15
|
origin: domain.origin,
|
|
12
16
|
fingerprint: callableFingerprint(callable),
|
|
13
17
|
callable: callable.key,
|
|
14
|
-
outputMode: callable
|
|
18
|
+
outputMode: outputModeOf(callable),
|
|
19
|
+
...(files.length === 0 ? {} : { files }),
|
|
15
20
|
});
|
|
16
21
|
if ('owner' in callable && !callable.static) {
|
|
17
22
|
const bind = (receiver) => admitReference({
|
|
@@ -39,6 +44,14 @@ export function kernelReference(method) {
|
|
|
39
44
|
const bind = (receiver) => admitReference({ ...common, target: Path.instanceMethod(Path.from(receiver), callable) });
|
|
40
45
|
return Object.assign(bind, common);
|
|
41
46
|
}
|
|
47
|
+
/** Where the input of this callable holds file fields. */
|
|
48
|
+
export function filesOf(callable) {
|
|
49
|
+
return filePositions(isBinaryInput(callable.input) ? callable.input.metadata : callable.input);
|
|
50
|
+
}
|
|
51
|
+
/** The result kind invoking this callable yields. */
|
|
52
|
+
export function outputModeOf(callable) {
|
|
53
|
+
return callable.execution?.durable === true ? 'execution' : callable.output.mode;
|
|
54
|
+
}
|
|
42
55
|
export function admitReference(input) {
|
|
43
56
|
if (input === null || typeof input !== 'object')
|
|
44
57
|
invalid();
|
|
@@ -47,9 +60,10 @@ export function admitReference(input) {
|
|
|
47
60
|
typeof input.callable !== 'string' ||
|
|
48
61
|
!Key.is(input.callable) ||
|
|
49
62
|
Key.origin(input.callable) !== input.origin ||
|
|
50
|
-
!
|
|
63
|
+
!OUTPUT_MODES.includes(input.outputMode) ||
|
|
51
64
|
(input.fingerprint !== undefined &&
|
|
52
|
-
(typeof input.fingerprint !== 'string' || !FINGERPRINT_PATTERN.test(input.fingerprint)))
|
|
65
|
+
(typeof input.fingerprint !== 'string' || !FINGERPRINT_PATTERN.test(input.fingerprint))) ||
|
|
66
|
+
(input.files !== undefined && !Array.isArray(input.files)))
|
|
53
67
|
invalid();
|
|
54
68
|
const target = Path.from(input.target);
|
|
55
69
|
if (!matchesCallable(target, input.callable))
|
|
@@ -60,6 +74,7 @@ export function admitReference(input) {
|
|
|
60
74
|
callable: input.callable,
|
|
61
75
|
target,
|
|
62
76
|
outputMode: input.outputMode,
|
|
77
|
+
...(input.files === undefined || input.files.length === 0 ? {} : { files: input.files }),
|
|
63
78
|
});
|
|
64
79
|
}
|
|
65
80
|
export function matchesCallable(target, callable) {
|
|
@@ -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
|
}
|