@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
|
@@ -10,6 +10,9 @@ export async function retry(operation, options = {}) {
|
|
|
10
10
|
if (options.shouldRetry !== undefined && typeof options.shouldRetry !== 'function') {
|
|
11
11
|
throw new TypeError('Retry classifier is invalid.');
|
|
12
12
|
}
|
|
13
|
+
if (options.retryAfter !== undefined && typeof options.retryAfter !== 'function') {
|
|
14
|
+
throw new TypeError('Retry delay classifier is invalid.');
|
|
15
|
+
}
|
|
13
16
|
const attempts = positive(options.maxAttempts ?? DEFAULT_RETRY_ATTEMPTS, 'maxAttempts');
|
|
14
17
|
const baseWait = nonNegative(options.baseWait ?? DEFAULT_RETRY_BASE_WAIT_MS, 'baseWait');
|
|
15
18
|
const maxWait = nonNegative(options.maxWait ?? DEFAULT_RETRY_MAX_WAIT_MS, 'maxWait');
|
|
@@ -19,7 +22,11 @@ export async function retry(operation, options = {}) {
|
|
|
19
22
|
}
|
|
20
23
|
let succeeded = false;
|
|
21
24
|
let failure;
|
|
25
|
+
// Earliest instant the last failure allows the next attempt; backoff has already waited part of it.
|
|
26
|
+
let notBefore = 0;
|
|
27
|
+
let invalidDelay;
|
|
22
28
|
const retryer = new AsyncRetryer(async () => {
|
|
29
|
+
await waitUntil(notBefore);
|
|
23
30
|
try {
|
|
24
31
|
const result = await operation();
|
|
25
32
|
succeeded = true;
|
|
@@ -29,6 +36,15 @@ export async function retry(operation, options = {}) {
|
|
|
29
36
|
catch (error) {
|
|
30
37
|
succeeded = false;
|
|
31
38
|
failure = error;
|
|
39
|
+
if (error instanceof Error && options.retryAfter !== undefined) {
|
|
40
|
+
const delay = options.retryAfter(error, retryer.store.state.currentAttempt);
|
|
41
|
+
if (delay !== undefined && (!Number.isFinite(delay) || delay < 0)) {
|
|
42
|
+
invalidDelay = new TypeError('retryAfter must return a finite non-negative number.');
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
notBefore = delay === undefined ? 0 : Date.now() + delay;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
32
48
|
throw error;
|
|
33
49
|
}
|
|
34
50
|
}, {
|
|
@@ -39,13 +55,23 @@ export async function retry(operation, options = {}) {
|
|
|
39
55
|
maxAttempts: (current) => {
|
|
40
56
|
const error = current.store.state.lastError;
|
|
41
57
|
const attempt = current.store.state.currentAttempt;
|
|
58
|
+
if (invalidDelay !== undefined)
|
|
59
|
+
return attempt;
|
|
42
60
|
if (error !== undefined && options.shouldRetry?.(error, attempt) === false)
|
|
43
61
|
return attempt;
|
|
44
62
|
return attempts;
|
|
45
63
|
},
|
|
46
64
|
throwOnError: 'last',
|
|
47
65
|
});
|
|
48
|
-
|
|
66
|
+
let result;
|
|
67
|
+
try {
|
|
68
|
+
result = await retryer.execute();
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
throw invalidDelay ?? error;
|
|
72
|
+
}
|
|
73
|
+
if (invalidDelay !== undefined)
|
|
74
|
+
throw invalidDelay;
|
|
49
75
|
if (!succeeded) {
|
|
50
76
|
if (failure !== undefined)
|
|
51
77
|
throw failure;
|
|
@@ -53,3 +79,9 @@ export async function retry(operation, options = {}) {
|
|
|
53
79
|
}
|
|
54
80
|
return result;
|
|
55
81
|
}
|
|
82
|
+
/** Timers may fire early against the wall clock, so wait again until the instant has passed. */
|
|
83
|
+
async function waitUntil(instant) {
|
|
84
|
+
for (let remaining = instant - Date.now(); remaining > 0; remaining = instant - Date.now()) {
|
|
85
|
+
await new Promise((resolve) => setTimeout(resolve, remaining));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -1,12 +1,80 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
1
|
+
import type { NodeId } from '@astrale-os/kernel-core/graph/node';
|
|
2
|
+
import type { OperationId } from '@astrale-os/kernel-core/schema/installation';
|
|
3
|
+
import type { AttemptReport as InstallAttemptReport, DomainRequest, InstallClass, InstallInput, InstallMode, InstallReceipt, SystemExecutionDetail as InstallDetail, UninstallInput, UninstallOutput as UninstallReceipt, ValidationOptions as InstallValidationOptions } from '@astrale-os/kernel-core/schema/kernel/syscalls/contracts';
|
|
4
|
+
import type { InstallResult } from '@astrale-os/kernel-protocol/schema/installation';
|
|
5
|
+
import type { ExecutionOutcome, ExecutionStatus } from '../execution/index.js';
|
|
6
|
+
export type { OperationId };
|
|
4
7
|
/** Canonical caller input accepted by the Kernel install syscall. */
|
|
5
|
-
export type DomainRequest
|
|
6
|
-
|
|
8
|
+
export type { DomainRequest };
|
|
9
|
+
/**
|
|
10
|
+
* How long an install, an uninstall or a watch of an install waits at most, `waitMs`, in
|
|
11
|
+
* milliseconds: 110 s by default; `0` reads the status once and answers it. The wait is the
|
|
12
|
+
* Client's own: it is never sent, so it is no part of the operation's intent.
|
|
13
|
+
*/
|
|
14
|
+
export interface LifecycleWait {
|
|
15
|
+
readonly waitMs?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* One install: its Kernel input, plus how long the Client waits for its outcome, or, in mode
|
|
19
|
+
* `maintenance`, until its repair session awaits Root's first command.
|
|
20
|
+
*/
|
|
21
|
+
export type InstallRequest = InstallInput & LifecycleWait;
|
|
7
22
|
/** Admitted terminal install receipt returned by the Kernel. */
|
|
8
|
-
export type InstallReceipt
|
|
9
|
-
/**
|
|
10
|
-
export type
|
|
23
|
+
export type { InstallReceipt };
|
|
24
|
+
/** The committed result of an install: its receipt, or the generations it proved unchanged. */
|
|
25
|
+
export type { InstallResult };
|
|
26
|
+
/** What an install does to the stored data: nothing, applied at once, or revalidated first. */
|
|
27
|
+
export type { InstallClass };
|
|
28
|
+
export type { InstallMode };
|
|
29
|
+
/** The validation options of an install, defaults filled in. */
|
|
30
|
+
export type { InstallValidationOptions };
|
|
31
|
+
/** The last attempt of a repair session that ended without activating, with its report. */
|
|
32
|
+
export type { InstallAttemptReport };
|
|
33
|
+
/** What an install or session shows beside its engine state, as Core shapes it. */
|
|
34
|
+
export type { InstallDetail };
|
|
35
|
+
/** A terminal install: its committed result, its rejection, or its cancellation. */
|
|
36
|
+
export type InstallOutcome = ExecutionOutcome<InstallResult>;
|
|
37
|
+
/**
|
|
38
|
+
* The status of one install or repair session: the engine `state` the CLI decides on, and the
|
|
39
|
+
* Core `detail` (phase, class, progress, the next command index, the running attempt and the last
|
|
40
|
+
* attempt report).
|
|
41
|
+
*/
|
|
42
|
+
export type InstallStatus = ExecutionStatus<InstallResult>;
|
|
43
|
+
/**
|
|
44
|
+
* How long a watch of an install lasts at most, and, for a repair session, the index the command
|
|
45
|
+
* it awaits must pass, `after` (`0` by default: any).
|
|
46
|
+
*/
|
|
47
|
+
export interface InstallationWatch extends LifecycleWait {
|
|
48
|
+
readonly after?: number;
|
|
49
|
+
}
|
|
50
|
+
/** One admitted install answer: its Execution, its status, and its result once completed. */
|
|
51
|
+
export interface Installation {
|
|
52
|
+
readonly execution: NodeId;
|
|
53
|
+
/**
|
|
54
|
+
* True when the operation id already named this Execution, so the call replayed it and changed
|
|
55
|
+
* nothing; false when this call started it; absent when the Host does not say.
|
|
56
|
+
*/
|
|
57
|
+
readonly replayed?: boolean;
|
|
58
|
+
readonly status: InstallStatus;
|
|
59
|
+
/** The committed result, present exactly when the status is completed. */
|
|
60
|
+
readonly result?: InstallResult;
|
|
61
|
+
}
|
|
62
|
+
/** One uninstall: its Kernel input, plus how long the Client waits for its outcome. */
|
|
63
|
+
export type UninstallRequest = UninstallInput & LifecycleWait;
|
|
11
64
|
/** Admitted terminal uninstall receipt returned by the Kernel. */
|
|
12
|
-
export type UninstallReceipt
|
|
65
|
+
export type { UninstallReceipt };
|
|
66
|
+
/** A terminal uninstall: its committed receipt, its rejection, or its cancellation. */
|
|
67
|
+
export type UninstallOutcome = ExecutionOutcome<UninstallReceipt>;
|
|
68
|
+
/** The status of one uninstall. */
|
|
69
|
+
export type UninstallStatus = ExecutionStatus<UninstallReceipt>;
|
|
70
|
+
/** One admitted uninstall answer: its Execution, its status, and its receipt once completed. */
|
|
71
|
+
export interface Uninstallation {
|
|
72
|
+
readonly execution: NodeId;
|
|
73
|
+
/**
|
|
74
|
+
* True when the operation id already named this Execution; false when this call started it;
|
|
75
|
+
* absent when the Host does not say.
|
|
76
|
+
*/
|
|
77
|
+
readonly replayed?: boolean;
|
|
78
|
+
readonly status: UninstallStatus;
|
|
79
|
+
readonly result?: UninstallReceipt;
|
|
80
|
+
}
|
package/dist/schema/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { createSchema,
|
|
1
|
+
export { createSchema, type SchemaApi, type SchemaCall, type SchemaOptions, type DomainBundle, type DomainDependencies, type DomainInfo, type InstalledPin, type InstalledRelease, } from './schema.js';
|
|
2
2
|
export { acceptOperationId, createOperationId } from './operation.js';
|
|
3
|
-
export type {
|
|
3
|
+
export type { InstallationApi, UninstallationApi } from './installation.js';
|
|
4
|
+
export type { DomainRequest, InstallAttemptReport, InstallClass, InstallDetail, InstallMode, InstallOutcome, InstallResult, InstallStatus, InstallValidationOptions, Installation, InstallationWatch, InstallReceipt, InstallRequest, LifecycleWait, OperationId, Uninstallation, UninstallOutcome, UninstallReceipt, UninstallRequest, UninstallStatus, } from './contracts.js';
|
package/dist/schema/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createSchema,
|
|
1
|
+
export { createSchema, } from './schema.js';
|
|
2
2
|
export { acceptOperationId, createOperationId } from './operation.js';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { NodeId } from '@astrale-os/kernel-core/graph/node';
|
|
2
|
+
import type { InstallValidation } from '@astrale-os/kernel-core/schema/kernel/syscalls/contracts';
|
|
3
|
+
import type { ExecutionCall, ExecutionWait } from '../execution/index.js';
|
|
4
|
+
import type { RequestOptions } from '../transport/index.js';
|
|
5
|
+
import type { InstallationWatch, InstallOutcome, InstallStatus, LifecycleWait, UninstallOutcome, UninstallStatus } from './contracts.js';
|
|
6
|
+
/**
|
|
7
|
+
* The install executions of one Instance, through the `K.Execution` Methods of each. Observing
|
|
8
|
+
* and a cooperative cancel are Root's or the initiator's; signals, a forced cancel, resume and
|
|
9
|
+
* delete are Root's.
|
|
10
|
+
*/
|
|
11
|
+
export interface InstallationApi {
|
|
12
|
+
/** The status of one install or repair session. */
|
|
13
|
+
status(execution: NodeId, options?: RequestOptions): Promise<InstallStatus>;
|
|
14
|
+
/** The terminal outcome, waiting at most `waitMs` in total; `EXECUTION_PENDING` once it lapses. */
|
|
15
|
+
result(execution: NodeId, wait?: ExecutionWait, options?: RequestOptions): Promise<InstallOutcome>;
|
|
16
|
+
/**
|
|
17
|
+
* Read the status until the repair session awaits a command whose index passes `after`, or the
|
|
18
|
+
* install ends, pauses or expires, or `waitMs` lapses, or the deadline `timeoutMs` sets is within
|
|
19
|
+
* the answer margin (2 s), and answer the last status read. Each read
|
|
20
|
+
* follows the last one after a quarter of the time the watch has lasted, at most one second and
|
|
21
|
+
* never less than that read took: a change is seen within a quarter of the time it took to come.
|
|
22
|
+
*/
|
|
23
|
+
watch(execution: NodeId, watch?: InstallationWatch, options?: RequestOptions): Promise<InstallStatus>;
|
|
24
|
+
/**
|
|
25
|
+
* A waiting repair session attempts its target: the `command:<index>` signal, `index` being
|
|
26
|
+
* the `detail.command` its status announces. A signal already resolved is refused.
|
|
27
|
+
*/
|
|
28
|
+
apply(execution: NodeId, command: {
|
|
29
|
+
readonly index: number;
|
|
30
|
+
readonly validation?: InstallValidation;
|
|
31
|
+
}, options?: RequestOptions): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Stop the attempt a repair session runs, `detail.attempt.number`, through its `abort:<attempt>`
|
|
34
|
+
* signal; the session waits again.
|
|
35
|
+
*/
|
|
36
|
+
abort(execution: NodeId, attempt: number, options?: RequestOptions): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* A cooperative cancel ends an install before its point of no return with nothing changed, and
|
|
39
|
+
* has a repair session attempt its source schema. `force` kills the run; a live session refuses
|
|
40
|
+
* it `EXECUTION_EXIT_REFUSED`: cancel it cooperatively or apply it.
|
|
41
|
+
*/
|
|
42
|
+
cancel(execution: NodeId, input?: {
|
|
43
|
+
readonly force?: boolean;
|
|
44
|
+
}, options?: RequestOptions): Promise<InstallStatus>;
|
|
45
|
+
/** Resume a paused install or session; a running one is unchanged. */
|
|
46
|
+
resume(execution: NodeId, options?: RequestOptions): Promise<InstallStatus>;
|
|
47
|
+
/**
|
|
48
|
+
* Delete the Execution, then kill and purge its run; a live session refuses it
|
|
49
|
+
* `EXECUTION_EXIT_REFUSED`: cancel or apply it first.
|
|
50
|
+
*/
|
|
51
|
+
delete(execution: NodeId, options?: RequestOptions): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The uninstall executions of one Instance, through the same `K.Execution` Methods: a completed
|
|
55
|
+
* outcome carries the uninstall receipt. An uninstall has no repair session, so no signal.
|
|
56
|
+
*/
|
|
57
|
+
export interface UninstallationApi {
|
|
58
|
+
/** The status of one uninstall. */
|
|
59
|
+
status(execution: NodeId, options?: RequestOptions): Promise<UninstallStatus>;
|
|
60
|
+
/** The terminal outcome, waiting at most `waitMs` in total; `EXECUTION_PENDING` once it lapses. */
|
|
61
|
+
result(execution: NodeId, wait?: ExecutionWait, options?: RequestOptions): Promise<UninstallOutcome>;
|
|
62
|
+
/** A cooperative cancel ends it before its point of no return; `force` kills the run. */
|
|
63
|
+
cancel(execution: NodeId, input?: {
|
|
64
|
+
readonly force?: boolean;
|
|
65
|
+
}, options?: RequestOptions): Promise<UninstallStatus>;
|
|
66
|
+
/** Resume a paused uninstall; a running one is unchanged. */
|
|
67
|
+
resume(execution: NodeId, options?: RequestOptions): Promise<UninstallStatus>;
|
|
68
|
+
/** Delete the Execution, then kill and purge its run. */
|
|
69
|
+
delete(execution: NodeId, options?: RequestOptions): Promise<void>;
|
|
70
|
+
}
|
|
71
|
+
/** The install Methods: a completed outcome carries the result its Protocol owner admits. */
|
|
72
|
+
export declare function createInstallation(call: ExecutionCall): InstallationApi;
|
|
73
|
+
/** The uninstall Methods: a completed outcome carries the receipt Core's contract admits. */
|
|
74
|
+
export declare function createUninstallation(call: ExecutionCall): UninstallationApi;
|
|
75
|
+
/** The wait `wait` asks for, in milliseconds: its `waitMs`, or the default. */
|
|
76
|
+
export declare function lifecycleWait(wait: LifecycleWait | undefined): number;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { abortSignal, commandSignal, uninstallOutput, } from '@astrale-os/kernel-core/schema/kernel/syscalls/contracts';
|
|
2
|
+
import * as protocolSchema from '@astrale-os/kernel-protocol/schema';
|
|
3
|
+
import { acceptOutput, acceptWait, deadlineOf, executionMethods, waitEnd, within, } from '../execution/index.js';
|
|
4
|
+
import { pause } from '../transport/index.js';
|
|
5
|
+
/** How long an install or uninstall waits for what it waits for unless its request says otherwise. */
|
|
6
|
+
const DEFAULT_LIFECYCLE_WAIT_MS = 110_000;
|
|
7
|
+
/** The longest pause between two reads of a watch: a long watch reads once a second. */
|
|
8
|
+
const WATCH_PAUSE_MS = 1_000;
|
|
9
|
+
/** The install Methods: a completed outcome carries the result its Protocol owner admits. */
|
|
10
|
+
export function createInstallation(call) {
|
|
11
|
+
const { signal, ...methods } = executionMethods(call, acceptInstallResult);
|
|
12
|
+
return Object.freeze({
|
|
13
|
+
...methods,
|
|
14
|
+
watch: (execution, watch, options) => watchInstall(methods.status, execution, watch, options),
|
|
15
|
+
apply: async (execution, command, options) => signal(execution, {
|
|
16
|
+
name: commandSignal(ordinal(command.index)),
|
|
17
|
+
value: Object.freeze({
|
|
18
|
+
kind: 'apply',
|
|
19
|
+
...(command.validation === undefined ? {} : { validation: command.validation }),
|
|
20
|
+
}),
|
|
21
|
+
}, options),
|
|
22
|
+
abort: async (execution, attempt, options) => signal(execution, { name: abortSignal(ordinal(attempt)), value: Object.freeze({ kind: 'abort' }) }, options),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/** The uninstall Methods: a completed outcome carries the receipt Core's contract admits. */
|
|
26
|
+
export function createUninstallation(call) {
|
|
27
|
+
const { signal: _signal, ...methods } = executionMethods(call, acceptUninstallReceipt);
|
|
28
|
+
return Object.freeze(methods);
|
|
29
|
+
}
|
|
30
|
+
/** The watch `InstallationApi.watch` describes, over the `status` Method. */
|
|
31
|
+
async function watchInstall(status, execution, watch, options) {
|
|
32
|
+
const waitMs = lifecycleWait(watch);
|
|
33
|
+
const after = watch?.after ?? 0;
|
|
34
|
+
if (!Number.isSafeInteger(after) || after < 0) {
|
|
35
|
+
throw new TypeError('A watched command index is a nonnegative integer.');
|
|
36
|
+
}
|
|
37
|
+
const deadline = deadlineOf(options);
|
|
38
|
+
const started = Date.now();
|
|
39
|
+
// Each read after the first has the answer margin left before the call's deadline to come back.
|
|
40
|
+
const ends = waitEnd(deadline, waitMs);
|
|
41
|
+
for (;;) {
|
|
42
|
+
const read = Date.now();
|
|
43
|
+
const current = await status(execution, within(deadline, options));
|
|
44
|
+
const now = Date.now();
|
|
45
|
+
if (settled(current, after) || now >= ends)
|
|
46
|
+
return current;
|
|
47
|
+
// In whole milliseconds, a timer's own resolution: an instant read never reads again at once.
|
|
48
|
+
await pause(Math.min(WATCH_PAUSE_MS, Math.max(1, now - read, Math.ceil((now - started) / 4)), ends - now), options?.signal);
|
|
49
|
+
// A read starts by the end of the watch at the latest: a timer that woke past it reads no more.
|
|
50
|
+
if (Date.now() > ends)
|
|
51
|
+
return current;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Whether a watch ends at `status`: its session awaits a command past `after`, or nothing changes
|
|
56
|
+
* it any more without a command: it ended, paused or expired.
|
|
57
|
+
*/
|
|
58
|
+
function settled(status, after) {
|
|
59
|
+
if (status.outcome !== undefined || status.state === 'paused' || status.state === 'expired')
|
|
60
|
+
return true;
|
|
61
|
+
const detail = status.detail;
|
|
62
|
+
return detail?.phase === 'awaiting' && (detail.command ?? 0) > after;
|
|
63
|
+
}
|
|
64
|
+
/** The wait `wait` asks for, in milliseconds: its `waitMs`, or the default. */
|
|
65
|
+
export function lifecycleWait(wait) {
|
|
66
|
+
return acceptWait({ waitMs: wait?.waitMs ?? DEFAULT_LIFECYCLE_WAIT_MS });
|
|
67
|
+
}
|
|
68
|
+
function acceptInstallResult(input) {
|
|
69
|
+
if (uninstallOutput.safeParse(input).success) {
|
|
70
|
+
throw new TypeError('The Execution is an uninstall: read it through SchemaApi.uninstallation.');
|
|
71
|
+
}
|
|
72
|
+
return protocolSchema.installation.acceptResult(input);
|
|
73
|
+
}
|
|
74
|
+
function acceptUninstallReceipt(input) {
|
|
75
|
+
return acceptOutput(uninstallOutput, input, 'uninstall receipt');
|
|
76
|
+
}
|
|
77
|
+
function ordinal(input) {
|
|
78
|
+
if (!Number.isSafeInteger(input) || input < 1) {
|
|
79
|
+
throw new TypeError('A session signal index is a positive integer.');
|
|
80
|
+
}
|
|
81
|
+
return input;
|
|
82
|
+
}
|
package/dist/schema/schema.d.ts
CHANGED
|
@@ -1,26 +1,35 @@
|
|
|
1
1
|
import type { Key } from '@astrale-os/kernel-dsl/v1';
|
|
2
|
-
import
|
|
2
|
+
import type { DomainBundle, DomainDependencies, DomainInfo, InstalledPin, InstalledRelease, Limits } from '@astrale-os/kernel-protocol/schema/installation/introspection';
|
|
3
3
|
import type { Call, Result } from '../client/index.js';
|
|
4
4
|
import type { RequestOptions } from '../transport/index.js';
|
|
5
|
-
import type { InstallRequest,
|
|
5
|
+
import type { Installation, InstallRequest, Uninstallation, UninstallRequest } from './contracts.js';
|
|
6
|
+
import { type InstallationApi, type UninstallationApi } from './installation.js';
|
|
6
7
|
export type SchemaCall = (call: Call, options?: RequestOptions) => Promise<Result>;
|
|
7
|
-
export interface SchemaOptions extends
|
|
8
|
-
readonly lifecycleTimeoutMs?: number;
|
|
8
|
+
export interface SchemaOptions extends Limits {
|
|
9
9
|
}
|
|
10
|
-
export type DomainInfo
|
|
11
|
-
export type DomainBundle = protocolSchema.installation.introspection.DomainBundle;
|
|
12
|
-
export type DomainDependencies = protocolSchema.installation.introspection.DomainDependencies;
|
|
13
|
-
export type InstalledRelease = protocolSchema.installation.introspection.InstalledRelease;
|
|
14
|
-
export type InstalledPin = protocolSchema.installation.introspection.InstalledPin;
|
|
15
|
-
export type InstallResult = protocolSchema.installation.InstallResult;
|
|
10
|
+
export type { DomainBundle, DomainDependencies, DomainInfo, InstalledPin, InstalledRelease };
|
|
16
11
|
export interface SchemaApi {
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Install Domains: start the durable Execution the install is, wait at most `waitMs` (110 s by
|
|
14
|
+
* default) for its outcome, or, in mode `maintenance`, until its repair session awaits Root's
|
|
15
|
+
* first command (`installation.watch`), and answer its status. `timeoutMs`, when given, bounds the
|
|
16
|
+
* whole call. The answer names the Execution with its status; `result` is present once it
|
|
17
|
+
* completed. A rejected install is a terminal `failed` status, never a failed call.
|
|
18
|
+
*/
|
|
19
|
+
install(request: InstallRequest, options?: RequestOptions): Promise<Installation>;
|
|
20
|
+
/** The install executions and repair sessions, through their `K.Execution` Methods. */
|
|
21
|
+
readonly installation: InstallationApi;
|
|
22
|
+
/**
|
|
23
|
+
* Uninstall Domains: start the durable Execution the uninstall is, wait at most `waitMs` (110 s
|
|
24
|
+
* by default) for its outcome and read its status. `result` is the receipt once it completed.
|
|
25
|
+
*/
|
|
26
|
+
uninstall(request: UninstallRequest, options?: RequestOptions): Promise<Uninstallation>;
|
|
27
|
+
/** The uninstall executions, through their `K.Execution` Methods. */
|
|
28
|
+
readonly uninstallation: UninstallationApi;
|
|
19
29
|
inspect(origin: Key.Origin, options?: RequestOptions): Promise<DomainInfo>;
|
|
20
30
|
bundle(origin: Key.Origin, options?: RequestOptions): Promise<DomainBundle>;
|
|
21
31
|
dependencies(origin: Key.Origin, options?: RequestOptions): Promise<DomainDependencies>;
|
|
22
32
|
installed(options?: RequestOptions): Promise<readonly InstalledRelease[]>;
|
|
23
33
|
}
|
|
24
|
-
export declare const DEFAULT_SCHEMA_LIFECYCLE_TIMEOUT_MS = 110000;
|
|
25
34
|
/** Bind the canonical Schema lifecycle syscalls to one caller-scoped value-call capability. */
|
|
26
35
|
export declare function createSchema(call: SchemaCall, limits: SchemaOptions): SchemaApi;
|
package/dist/schema/schema.js
CHANGED
|
@@ -1,46 +1,41 @@
|
|
|
1
1
|
import { Path } from '@astrale-os/kernel-core/path';
|
|
2
|
-
import { uninstallOutput } from '@astrale-os/kernel-core/schema/kernel/syscalls/contracts';
|
|
3
2
|
import { install, uninstall } from '@astrale-os/kernel-core/schema/kernel/syscalls/references';
|
|
4
|
-
import * as protocolSchema from '@astrale-os/kernel-protocol/schema';
|
|
5
3
|
import { call as invocation } from '../client/index.js';
|
|
6
|
-
import {
|
|
4
|
+
import { deadlineOf, within } from '../execution/index.js';
|
|
5
|
+
import { createInstallation, createUninstallation, lifecycleWait, } from './installation.js';
|
|
7
6
|
import { introspect } from './introspection.js';
|
|
8
7
|
const INSTALL_PATH = Path.project(install).raw;
|
|
9
8
|
const UNINSTALL_PATH = Path.project(uninstall).raw;
|
|
10
|
-
export const DEFAULT_SCHEMA_LIFECYCLE_TIMEOUT_MS = 110_000;
|
|
11
9
|
/** Bind the canonical Schema lifecycle syscalls to one caller-scoped value-call capability. */
|
|
12
10
|
export function createSchema(call, limits) {
|
|
13
11
|
if (typeof call !== 'function')
|
|
14
12
|
throw new TypeError('Schema call capability is invalid.');
|
|
15
13
|
const admittedLimits = admitLimits(limits);
|
|
14
|
+
const installation = createInstallation(call);
|
|
15
|
+
const uninstallation = createUninstallation(call);
|
|
16
16
|
return Object.freeze({
|
|
17
17
|
async install(request, options) {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
: undefined;
|
|
26
|
-
if (decode === undefined) {
|
|
27
|
-
throw new TypeError('Schema install returned an unsupported media type.');
|
|
28
|
-
}
|
|
29
|
-
if (!(result.value.body instanceof Uint8Array)) {
|
|
30
|
-
await result.value.body[Symbol.asyncIterator]().return?.();
|
|
31
|
-
throw new TypeError('Schema install returned a streaming binary result.');
|
|
32
|
-
}
|
|
33
|
-
const decoded = await decode(result.value.body, installationResultLimit(admittedLimits.maximumReleaseBytes, request.domains.length));
|
|
34
|
-
proveInstallResult(request, decoded);
|
|
35
|
-
return decoded;
|
|
18
|
+
const { waitMs: _waitMs, ...input } = request;
|
|
19
|
+
const waitMs = lifecycleWait(request);
|
|
20
|
+
// A maintenance session's outcome is Root's to decide: the call waits until it awaits Root.
|
|
21
|
+
const wait = input.mode === 'maintenance'
|
|
22
|
+
? sessionWait(installation, waitMs)
|
|
23
|
+
: outcomeWait(installation, waitMs);
|
|
24
|
+
return admitInstallation(request, await lifecycle(call, INSTALL_PATH, input, wait, options));
|
|
36
25
|
},
|
|
26
|
+
installation,
|
|
37
27
|
async uninstall(request, options) {
|
|
28
|
+
const wait = outcomeWait(uninstallation, lifecycleWait(request));
|
|
38
29
|
const snapshot = snapshotUninstallRequest(request);
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
30
|
+
const started = await lifecycle(call, UNINSTALL_PATH, snapshot, wait, options);
|
|
31
|
+
const answer = { execution: started.status.id, ...started };
|
|
32
|
+
const { status } = started;
|
|
33
|
+
if (status.outcome?.kind !== 'completed')
|
|
34
|
+
return Object.freeze(answer);
|
|
35
|
+
proveUninstallReceipt(snapshot, status.outcome.value);
|
|
36
|
+
return Object.freeze({ ...answer, result: status.outcome.value });
|
|
43
37
|
},
|
|
38
|
+
uninstallation,
|
|
44
39
|
async inspect(origin, options) {
|
|
45
40
|
return introspect(call, admittedLimits, { kind: 'inspect', origin }, options);
|
|
46
41
|
},
|
|
@@ -55,6 +50,38 @@ export function createSchema(call, limits) {
|
|
|
55
50
|
},
|
|
56
51
|
});
|
|
57
52
|
}
|
|
53
|
+
/** Wait at most `waitMs` for the outcome, however that wait ends, then read the status. */
|
|
54
|
+
function outcomeWait(executions, waitMs) {
|
|
55
|
+
return async (execution, deadline, options) => {
|
|
56
|
+
if (waitMs > 0)
|
|
57
|
+
await executions
|
|
58
|
+
.result(execution, { waitMs }, within(deadline, options))
|
|
59
|
+
.catch(() => undefined);
|
|
60
|
+
return executions.status(execution, within(deadline, options));
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Watch a repair session at most `waitMs`, until it awaits Root's first command, and answer the
|
|
65
|
+
* last status read; a watch that fails reads the status once.
|
|
66
|
+
*/
|
|
67
|
+
function sessionWait(installation, waitMs) {
|
|
68
|
+
return (execution, deadline, options) => installation
|
|
69
|
+
.watch(execution, { waitMs }, within(deadline, options))
|
|
70
|
+
.catch(() => installation.status(execution, within(deadline, options)));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* One lifecycle syscall, before the call's deadline: start the durable Execution it is and answer
|
|
74
|
+
* the status `wait` ends on.
|
|
75
|
+
*/
|
|
76
|
+
async function lifecycle(call, path, input, wait, options) {
|
|
77
|
+
const deadline = deadlineOf(options);
|
|
78
|
+
const started = await call(invocation(path, input), within(deadline, options));
|
|
79
|
+
if (started.kind !== 'execution') {
|
|
80
|
+
throw new TypeError('Schema syscall did not answer with an Execution.');
|
|
81
|
+
}
|
|
82
|
+
const status = await wait(started.execution, deadline, options);
|
|
83
|
+
return started.replayed === undefined ? { status } : { status, replayed: started.replayed };
|
|
84
|
+
}
|
|
58
85
|
function snapshotUninstallRequest(request) {
|
|
59
86
|
return Object.freeze({
|
|
60
87
|
operation: request.operation,
|
|
@@ -75,12 +102,18 @@ function proveUninstallReceipt(request, receipt) {
|
|
|
75
102
|
function compare(left, right) {
|
|
76
103
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
77
104
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
105
|
+
/**
|
|
106
|
+
* The answer of one install, proved against its request: a completed status carries the result of
|
|
107
|
+
* exactly this operation, admitted by its Protocol owner.
|
|
108
|
+
*/
|
|
109
|
+
function admitInstallation(request, started) {
|
|
110
|
+
const answer = { execution: started.status.id, ...started };
|
|
111
|
+
const { status } = started;
|
|
112
|
+
if (status.outcome?.kind !== 'completed')
|
|
113
|
+
return Object.freeze(answer);
|
|
114
|
+
const result = status.outcome.value;
|
|
115
|
+
proveInstallResult(request, result);
|
|
116
|
+
return Object.freeze({ ...answer, result });
|
|
84
117
|
}
|
|
85
118
|
function proveInstallResult(request, result) {
|
|
86
119
|
if (result.changed) {
|
|
@@ -96,28 +129,14 @@ function proveInstallResult(request, result) {
|
|
|
96
129
|
throw new TypeError('Schema unchanged result does not match the requested Domain count.');
|
|
97
130
|
}
|
|
98
131
|
}
|
|
99
|
-
function value(result) {
|
|
100
|
-
if (result.kind !== 'value')
|
|
101
|
-
throw new TypeError('Schema syscall returned a non-value result.');
|
|
102
|
-
return result.value;
|
|
103
|
-
}
|
|
104
132
|
function admitLimits(input) {
|
|
105
|
-
const lifecycleTimeoutMs = input?.lifecycleTimeoutMs ?? DEFAULT_SCHEMA_LIFECYCLE_TIMEOUT_MS;
|
|
106
133
|
if (input === null ||
|
|
107
134
|
typeof input !== 'object' ||
|
|
108
135
|
!Number.isSafeInteger(input.maximumReleaseBytes) ||
|
|
109
136
|
input.maximumReleaseBytes < 1 ||
|
|
110
137
|
!Number.isSafeInteger(input.maximumBundleBytes) ||
|
|
111
|
-
input.maximumBundleBytes < 1
|
|
112
|
-
!Number.isSafeInteger(lifecycleTimeoutMs) ||
|
|
113
|
-
lifecycleTimeoutMs < 1 ||
|
|
114
|
-
lifecycleTimeoutMs > 2_147_483_647) {
|
|
138
|
+
input.maximumBundleBytes < 1) {
|
|
115
139
|
throw new TypeError('Schema introspection limits are invalid.');
|
|
116
140
|
}
|
|
117
|
-
return Object.freeze({ ...input
|
|
118
|
-
}
|
|
119
|
-
function lifecycleOptions(options, timeoutMs) {
|
|
120
|
-
if (options?.timeoutMs !== undefined)
|
|
121
|
-
return options;
|
|
122
|
-
return Object.freeze({ ...options, timeoutMs });
|
|
141
|
+
return Object.freeze({ ...input });
|
|
123
142
|
}
|
|
@@ -5,7 +5,7 @@ import { function as functions } from '@astrale-os/kernel-core/schema/kernel/sys
|
|
|
5
5
|
import { Key } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
6
6
|
import { ClientError } from '../errors/index.js';
|
|
7
7
|
import { runSessionOperation, sessionTransportOptions } from './context/index.js';
|
|
8
|
-
import { callableOrigin, exchangeDomainCredential, installedIssuer,
|
|
8
|
+
import { callableOrigin, exchangeDomainCredential, EXHAUSTED, installedIssuer, sourceExhausted, } from './exchange/index.js';
|
|
9
9
|
import { matchesCallable } from './reference.js';
|
|
10
10
|
import { requireResultKind, resolveAuth } from './routing/index.js';
|
|
11
11
|
const ADMIT = Path.staticMethod(Path.project(functions.admit.owner), functions.admit.name);
|
|
@@ -17,7 +17,7 @@ export async function admitFunction(dependencies, call, operation) {
|
|
|
17
17
|
throw new ClientError('Function admission requires a Domain-qualified callable target.');
|
|
18
18
|
}
|
|
19
19
|
const effective = await resolveAuth(dependencies.auth, call, operation);
|
|
20
|
-
if (
|
|
20
|
+
if (effective.kind === 'anonymous') {
|
|
21
21
|
throw new ClientError('Function admission requires an authenticated session.');
|
|
22
22
|
}
|
|
23
23
|
// Resolve once for the intended Call, then retain that exact caller across every helper syscall.
|
|
@@ -27,12 +27,19 @@ export async function admitFunction(dependencies, call, operation) {
|
|
|
27
27
|
}
|
|
28
28
|
// The Kernel preserves the session caller when issuing the delegation.
|
|
29
29
|
const exchanged = await exchangeDomainCredential(dependencies, effective, { issuer: domain, ttlSeconds: effective.delegate.ttlSeconds }, operation);
|
|
30
|
+
if (exchanged === EXHAUSTED)
|
|
31
|
+
throw sourceExhausted();
|
|
30
32
|
const result = await runSessionOperation(operation, () => dependencies
|
|
31
33
|
.source()
|
|
32
34
|
.as(exchanged.credential)
|
|
33
35
|
.dispatch({ target: ADMIT, input: { call, credential: exchanged.delegation } }, { ...sessionTransportOptions(operation), delegate: effective.delegate }));
|
|
34
36
|
const output = admitOutput.parse(requireResultKind('value', result).value);
|
|
35
|
-
|
|
37
|
+
// A Domain-qualified target names a declaration, by its key and without a definition: only an
|
|
38
|
+
// instance is named by its NodeId and defined by its Node.
|
|
39
|
+
if (output.definition !== undefined || !Key.is(output.callable)) {
|
|
40
|
+
throw new ClientError('Function admission returned a different callable.');
|
|
41
|
+
}
|
|
42
|
+
const callable = output.callable;
|
|
36
43
|
if (!matchesCallable(target, callable)) {
|
|
37
44
|
throw new ClientError('Function admission returned a different callable.');
|
|
38
45
|
}
|
package/dist/session/bound.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { IssuerId } from '@astrale-os/kernel-core/auth';
|
|
2
2
|
import type { AuthApi } from '../auth/index.js';
|
|
3
|
+
import type { ExecutionApi } from '../execution/index.js';
|
|
3
4
|
import type { SchemaApi } from '../schema/index.js';
|
|
4
5
|
import type { ContentApi } from './content/index.js';
|
|
5
6
|
import type { SessionControlOptions } from './context/index.js';
|
|
6
7
|
import type { SessionRequestOptions } from './routing/index.js';
|
|
7
8
|
import type { ClientSession } from './session.js';
|
|
8
|
-
import type { ViewCatalog } from './views/index.js';
|
|
9
|
+
import type { ViewCatalog } from './views/legacy/index.js';
|
|
9
10
|
import { type Binary, type Call, type Stream } from '../client/index.js';
|
|
10
11
|
import { type GraphApi } from '../graph/index.js';
|
|
11
12
|
/** Exact live Session surface captured by one credential-bound Kernel view. */
|
|
@@ -19,7 +20,12 @@ export interface BoundSessionSource {
|
|
|
19
20
|
invoke: ClientSession['invoke'];
|
|
20
21
|
stream(call: Call, options?: SessionRequestOptions): Promise<Stream>;
|
|
21
22
|
binary(call: Call, options?: SessionRequestOptions): Promise<Binary>;
|
|
22
|
-
|
|
23
|
+
view: ClientSession['view'];
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated Read a Domain's Views with `view({ domain })`. A source need not serve it: the
|
|
26
|
+
* bound `viewsFor` of one that does not throws a TypeError.
|
|
27
|
+
*/
|
|
28
|
+
viewsFor?(domain: Parameters<ClientSession['viewsFor']>[0], options?: SessionControlOptions): Promise<ViewCatalog>;
|
|
23
29
|
}
|
|
24
30
|
export interface BoundSessionControls {
|
|
25
31
|
readonly signal: AbortSignal;
|
|
@@ -36,13 +42,16 @@ export interface BoundClientSession extends GraphApi {
|
|
|
36
42
|
readonly kernel: IssuerId;
|
|
37
43
|
readonly auth: AuthApi;
|
|
38
44
|
readonly schema: SchemaApi;
|
|
45
|
+
readonly execution: ExecutionApi;
|
|
39
46
|
readonly content: ContentApi;
|
|
40
47
|
dispatch: ClientSession['dispatch'];
|
|
41
48
|
call: ClientSession['call'];
|
|
42
49
|
invoke: ClientSession['invoke'];
|
|
43
50
|
stream(call: Call, options?: SessionRequestOptions): Promise<Stream>;
|
|
44
51
|
binary(call: Call, options?: SessionRequestOptions): Promise<Binary>;
|
|
45
|
-
|
|
52
|
+
view: BoundSessionSource['view'];
|
|
53
|
+
/** @deprecated Read a Domain's Views with `view({ domain })`. */
|
|
54
|
+
viewsFor: NonNullable<BoundSessionSource['viewsFor']>;
|
|
46
55
|
}
|
|
47
56
|
/** Capture one Session into the ordinary graph, auth, and invocation Kernel journey. */
|
|
48
57
|
export declare function bindSession(source: BoundSessionSource, controls?: BoundSessionControls): BoundClientSession;
|