@astrale-os/kernel-client 0.6.0 → 1.0.0-beta.10
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/client/result.d.ts +8 -2
- package/dist/{schema → execution}/admission.d.ts +2 -2
- package/dist/{schema → execution}/admission.js +2 -2
- package/dist/{session/execution.d.ts → execution/contracts.d.ts} +22 -34
- package/dist/execution/contracts.js +1 -0
- package/dist/execution/deadline.d.ts +8 -0
- package/dist/execution/deadline.js +13 -0
- package/dist/execution/execution.d.ts +57 -0
- package/dist/execution/execution.js +137 -0
- package/dist/execution/index.d.ts +4 -0
- package/dist/execution/index.js +3 -0
- package/dist/schema/contracts.d.ts +34 -70
- package/dist/schema/index.d.ts +2 -2
- package/dist/schema/index.js +1 -1
- package/dist/schema/installation.d.ts +26 -64
- package/dist/schema/installation.js +23 -129
- package/dist/schema/schema.d.ts +8 -10
- package/dist/schema/schema.js +46 -33
- package/dist/session/bound.d.ts +2 -0
- package/dist/session/bound.js +3 -0
- package/dist/session/index.d.ts +1 -1
- 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 +1 -1
- package/dist/session/session.d.ts +3 -0
- package/dist/session/session.js +8 -2
- package/dist/session/session.typecheck.js +5 -4
- package/dist/transport/http/admission.js +6 -1
- package/dist/transport/websocket/exchange.js +1 -0
- package/package.json +5 -5
- package/dist/session/execution.js +0 -34
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { NodeId } from '@astrale-os/kernel-core/graph/node';
|
|
2
2
|
import type { InstallValidation } from '@astrale-os/kernel-core/schema/kernel/syscalls/contracts';
|
|
3
|
+
import type { ExecutionCall, ExecutionWait } from '../execution/index.js';
|
|
3
4
|
import type { RequestOptions } from '../transport/index.js';
|
|
4
|
-
import type {
|
|
5
|
-
import type { SchemaCall } from './schema.js';
|
|
5
|
+
import type { InstallOutcome, InstallStatus, UninstallOutcome, UninstallStatus } from './contracts.js';
|
|
6
6
|
/**
|
|
7
7
|
* The install executions of one Instance, through the `K.Execution` Methods of each. Observing
|
|
8
8
|
* and a cooperative cancel are Root's or the initiator's; signals, a forced cancel, resume and
|
|
@@ -10,16 +10,14 @@ import type { SchemaCall } from './schema.js';
|
|
|
10
10
|
*/
|
|
11
11
|
export interface InstallationApi {
|
|
12
12
|
/** The status of one install or repair session. */
|
|
13
|
-
status(execution:
|
|
14
|
-
/** The terminal outcome, waiting at most `waitMs
|
|
15
|
-
result(execution:
|
|
16
|
-
readonly waitMs?: number;
|
|
17
|
-
}, options?: RequestOptions): Promise<InstallOutcome>;
|
|
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>;
|
|
18
16
|
/**
|
|
19
17
|
* A waiting repair session attempts its target: the `command:<index>` signal, `index` being
|
|
20
18
|
* the `detail.command` its status announces. A signal already resolved is refused.
|
|
21
19
|
*/
|
|
22
|
-
apply(execution:
|
|
20
|
+
apply(execution: NodeId, command: {
|
|
23
21
|
readonly index: number;
|
|
24
22
|
readonly validation?: InstallValidation;
|
|
25
23
|
}, options?: RequestOptions): Promise<void>;
|
|
@@ -27,19 +25,22 @@ export interface InstallationApi {
|
|
|
27
25
|
* Stop the attempt a repair session runs, `detail.attempt.number`, through its `abort:<attempt>`
|
|
28
26
|
* signal; the session waits again.
|
|
29
27
|
*/
|
|
30
|
-
abort(execution:
|
|
28
|
+
abort(execution: NodeId, attempt: number, options?: RequestOptions): Promise<void>;
|
|
31
29
|
/**
|
|
32
30
|
* A cooperative cancel ends an install before its point of no return with nothing changed, and
|
|
33
|
-
* has a repair session attempt its source schema. `force` kills the run; a live session
|
|
34
|
-
*
|
|
31
|
+
* has a repair session attempt its source schema. `force` kills the run; a live session refuses
|
|
32
|
+
* it `EXECUTION_EXIT_REFUSED`: cancel it cooperatively or apply it.
|
|
35
33
|
*/
|
|
36
|
-
cancel(execution:
|
|
34
|
+
cancel(execution: NodeId, input?: {
|
|
37
35
|
readonly force?: boolean;
|
|
38
36
|
}, options?: RequestOptions): Promise<InstallStatus>;
|
|
39
37
|
/** Resume a paused install or session; a running one is unchanged. */
|
|
40
|
-
resume(execution:
|
|
41
|
-
/**
|
|
42
|
-
|
|
38
|
+
resume(execution: NodeId, options?: RequestOptions): Promise<InstallStatus>;
|
|
39
|
+
/**
|
|
40
|
+
* Delete the Execution, then kill and purge its run; a live session refuses it
|
|
41
|
+
* `EXECUTION_EXIT_REFUSED`: cancel or apply it first.
|
|
42
|
+
*/
|
|
43
|
+
delete(execution: NodeId, options?: RequestOptions): Promise<void>;
|
|
43
44
|
}
|
|
44
45
|
/**
|
|
45
46
|
* The uninstall executions of one Instance, through the same `K.Execution` Methods: a completed
|
|
@@ -47,58 +48,19 @@ export interface InstallationApi {
|
|
|
47
48
|
*/
|
|
48
49
|
export interface UninstallationApi {
|
|
49
50
|
/** The status of one uninstall. */
|
|
50
|
-
status(execution:
|
|
51
|
-
/** The terminal outcome, waiting at most `waitMs
|
|
52
|
-
result(execution:
|
|
53
|
-
readonly waitMs?: number;
|
|
54
|
-
}, options?: RequestOptions): Promise<UninstallOutcome>;
|
|
51
|
+
status(execution: NodeId, options?: RequestOptions): Promise<UninstallStatus>;
|
|
52
|
+
/** The terminal outcome, waiting at most `waitMs` in total; `EXECUTION_PENDING` once it lapses. */
|
|
53
|
+
result(execution: NodeId, wait?: ExecutionWait, options?: RequestOptions): Promise<UninstallOutcome>;
|
|
55
54
|
/** A cooperative cancel ends it before its point of no return; `force` kills the run. */
|
|
56
|
-
cancel(execution:
|
|
55
|
+
cancel(execution: NodeId, input?: {
|
|
57
56
|
readonly force?: boolean;
|
|
58
|
-
}, options?: RequestOptions): Promise<
|
|
57
|
+
}, options?: RequestOptions): Promise<UninstallStatus>;
|
|
59
58
|
/** Resume a paused uninstall; a running one is unchanged. */
|
|
60
|
-
resume(execution:
|
|
59
|
+
resume(execution: NodeId, options?: RequestOptions): Promise<UninstallStatus>;
|
|
61
60
|
/** Delete the Execution, then kill and purge its run. */
|
|
62
|
-
delete(execution:
|
|
61
|
+
delete(execution: NodeId, options?: RequestOptions): Promise<void>;
|
|
63
62
|
}
|
|
64
|
-
/** Admit a completed outcome's value; anything else of the outcome is kept as admitted. */
|
|
65
|
-
export type AcceptValue<Value> = (input: unknown) => Value;
|
|
66
|
-
export type ExecutionOutcomeOf<Value> = {
|
|
67
|
-
readonly kind: 'completed';
|
|
68
|
-
readonly value: Value;
|
|
69
|
-
} | {
|
|
70
|
-
readonly kind: 'failed';
|
|
71
|
-
readonly error: InstallFailure;
|
|
72
|
-
} | {
|
|
73
|
-
readonly kind: 'cancelled';
|
|
74
|
-
};
|
|
75
|
-
/** The `K.Execution` Methods of one Execution, over one call capability; package-private. */
|
|
76
|
-
export declare function executionMethods(call: SchemaCall, options: (input: RequestOptions | undefined) => RequestOptions): Readonly<{
|
|
77
|
-
status: <Value>(id: InstallExecutionId, accept: AcceptValue<Value>, request?: RequestOptions) => Promise<InstallStatus<ExecutionOutcomeOf<Value>>>;
|
|
78
|
-
result<Value>(id: InstallExecutionId, accept: AcceptValue<Value>, wait?: {
|
|
79
|
-
readonly waitMs?: number;
|
|
80
|
-
}, request?: RequestOptions): Promise<ExecutionOutcomeOf<Value>>;
|
|
81
|
-
signal(id: InstallExecutionId, name: string, signalled: unknown, request?: RequestOptions): Promise<void>;
|
|
82
|
-
cancel: <Value>(id: InstallExecutionId, accept: AcceptValue<Value>, input: {
|
|
83
|
-
readonly force?: boolean;
|
|
84
|
-
}, request?: RequestOptions) => Promise<InstallStatus<ExecutionOutcomeOf<Value>>>;
|
|
85
|
-
resume: <Value>(id: InstallExecutionId, accept: AcceptValue<Value>, request?: RequestOptions) => Promise<InstallStatus<ExecutionOutcomeOf<Value>>>;
|
|
86
|
-
delete(id: InstallExecutionId, request?: RequestOptions): Promise<void>;
|
|
87
|
-
/** Admit what a durable call answers at once: the Execution it created or recovered. */
|
|
88
|
-
start(path: PathLike, input: unknown, request?: RequestOptions): Promise<InstallExecutionId>;
|
|
89
|
-
/**
|
|
90
|
-
* Wait within the request deadline for the outcome. A wait that lapsed after waiting, while
|
|
91
|
-
* time remains, waits again; a wait a closing process or a gap with no process failed is sent
|
|
92
|
-
* again. Every other end of the wait, or its deadline, leaves the Execution as it is: its
|
|
93
|
-
* status, read next, says where it is, so the caller never loses the Execution.
|
|
94
|
-
*/
|
|
95
|
-
settle(id: InstallExecutionId, request?: RequestOptions): Promise<void>;
|
|
96
|
-
/** The status after a wait, read again as `settle` sends its wait again, within the deadline. */
|
|
97
|
-
observe<Value>(id: InstallExecutionId, accept: AcceptValue<Value>, request?: RequestOptions): Promise<InstallStatus<ExecutionOutcomeOf<Value>>>;
|
|
98
|
-
}>;
|
|
99
|
-
export type ExecutionMethods = ReturnType<typeof executionMethods>;
|
|
100
63
|
/** The install Methods: a completed outcome carries the result its Protocol owner admits. */
|
|
101
|
-
export declare function createInstallation(
|
|
64
|
+
export declare function createInstallation(call: ExecutionCall): InstallationApi;
|
|
102
65
|
/** The uninstall Methods: a completed outcome carries the receipt Core's contract admits. */
|
|
103
|
-
export declare function createUninstallation(
|
|
104
|
-
export declare function acceptUninstallReceipt(input: unknown): UninstallReceipt;
|
|
66
|
+
export declare function createUninstallation(call: ExecutionCall): UninstallationApi;
|
|
@@ -1,140 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { abortSignal, commandSignal, executionOutcome, executionStatus, uninstallOutput, } from '@astrale-os/kernel-core/schema/kernel/syscalls/contracts';
|
|
3
|
-
import { execution as methods } from '@astrale-os/kernel-core/schema/kernel/syscalls/references';
|
|
4
|
-
import { MethodKey } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
1
|
+
import { abortSignal, commandSignal, uninstallOutput, } from '@astrale-os/kernel-core/schema/kernel/syscalls/contracts';
|
|
5
2
|
import * as protocolSchema from '@astrale-os/kernel-protocol/schema';
|
|
6
|
-
import {
|
|
7
|
-
import { ResponseError, TransportError } from '../errors/index.js';
|
|
8
|
-
import { RETRY_REFUSALS, retry } from '../pacer/index.js';
|
|
9
|
-
import { acceptOutput } from './admission.js';
|
|
10
|
-
/** Attempts of one effect-free Execution read; the wait's deadline bounds them too. */
|
|
11
|
-
const READ_ATTEMPTS = 8;
|
|
12
|
-
/** A pending answer sooner than this did not wait: the Kernel answers now, so waiting ends. */
|
|
13
|
-
const LAPSED_WAIT_MS = 1_000;
|
|
14
|
-
/** No wait starts with less time left than this before its deadline. */
|
|
15
|
-
const MINIMUM_WAIT_MS = 1_000;
|
|
16
|
-
/** The `K.Execution` Methods of one Execution, over one call capability; package-private. */
|
|
17
|
-
export function executionMethods(call, options) {
|
|
18
|
-
const value = async (id, method, input, request) => {
|
|
19
|
-
const target = Path.instanceMethod(Path.id(id), MethodKey.of(method.owner, method.name));
|
|
20
|
-
const result = await call(invocation(target, input), options(request));
|
|
21
|
-
if (result.kind !== 'value')
|
|
22
|
-
throw new TypeError('Execution Method returned a non-value result.');
|
|
23
|
-
return result.value;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* An Execution read has no effect: one a process refused with a retry delay, or a gap with no
|
|
27
|
-
* process on the port failed, is sent again through the pacer, each attempt within `deadline`.
|
|
28
|
-
*/
|
|
29
|
-
const read = (deadline, request, work) => retry(() => work({ ...request, timeoutMs: Math.max(1, deadline - Date.now()) }), {
|
|
30
|
-
maxAttempts: READ_ATTEMPTS,
|
|
31
|
-
shouldRetry: (error, attempt) => Date.now() < deadline &&
|
|
32
|
-
(error instanceof TransportError || RETRY_REFUSALS.shouldRetry(error, attempt)),
|
|
33
|
-
retryAfter: RETRY_REFUSALS.retryAfter,
|
|
34
|
-
});
|
|
35
|
-
const status = async (id, accept, answer) => {
|
|
36
|
-
const admitted = acceptOutput(executionStatus, await answer, 'Execution status');
|
|
37
|
-
if (admitted.id !== id)
|
|
38
|
-
throw new TypeError('Kernel returned the status of another Execution.');
|
|
39
|
-
const outcome = admitted.outcome === undefined ? undefined : outcomeOf(admitted.outcome, accept);
|
|
40
|
-
// A deleted Execution carries the outcome its lifecycle record keeps, whatever its kind.
|
|
41
|
-
if (admitted.state !== 'deleted' &&
|
|
42
|
-
(admitted.state === 'completed') !== (outcome?.kind === 'completed')) {
|
|
43
|
-
throw new TypeError('Execution status and outcome disagree.');
|
|
44
|
-
}
|
|
45
|
-
if (admitted.state === 'deleted')
|
|
46
|
-
return Object.freeze({ id, state: 'deleted', outcome: outcome });
|
|
47
|
-
const { outcome: _outcome, ...rest } = admitted;
|
|
48
|
-
return Object.freeze({ ...rest, ...(outcome === undefined ? {} : { outcome }) });
|
|
49
|
-
};
|
|
50
|
-
return Object.freeze({
|
|
51
|
-
status: (id, accept, request) => status(id, accept, value(id, methods.status, {}, request)),
|
|
52
|
-
async result(id, accept, wait = {}, request) {
|
|
53
|
-
const answer = await value(id, methods.result, { ...wait }, request);
|
|
54
|
-
return outcomeOf(acceptOutput(executionOutcome, answer, 'Execution outcome'), accept);
|
|
55
|
-
},
|
|
56
|
-
async signal(id, name, signalled, request) {
|
|
57
|
-
await value(id, methods.signal, { name, value: signalled }, request);
|
|
58
|
-
},
|
|
59
|
-
cancel: (id, accept, input, request) => status(id, accept, value(id, methods.cancel, { ...input }, request)),
|
|
60
|
-
resume: (id, accept, request) => status(id, accept, value(id, methods.resume, {}, request)),
|
|
61
|
-
async delete(id, request) {
|
|
62
|
-
await value(id, methods.delete, {}, request);
|
|
63
|
-
},
|
|
64
|
-
/** Admit what a durable call answers at once: the Execution it created or recovered. */
|
|
65
|
-
async start(path, input, request) {
|
|
66
|
-
const result = await call(invocation(path, input), options(request));
|
|
67
|
-
if (result.kind !== 'execution')
|
|
68
|
-
throw new TypeError('Schema syscall did not answer with an Execution.');
|
|
69
|
-
return result.execution;
|
|
70
|
-
},
|
|
71
|
-
/**
|
|
72
|
-
* Wait within the request deadline for the outcome. A wait that lapsed after waiting, while
|
|
73
|
-
* time remains, waits again; a wait a closing process or a gap with no process failed is sent
|
|
74
|
-
* again. Every other end of the wait, or its deadline, leaves the Execution as it is: its
|
|
75
|
-
* status, read next, says where it is, so the caller never loses the Execution.
|
|
76
|
-
*/
|
|
77
|
-
async settle(id, request) {
|
|
78
|
-
const deadline = Date.now() + (options(request).timeoutMs ?? 0);
|
|
79
|
-
while (deadline - Date.now() >= MINIMUM_WAIT_MS) {
|
|
80
|
-
const started = Date.now();
|
|
81
|
-
try {
|
|
82
|
-
await read(deadline, request, (attempt) => value(id, methods.result, { waitMs: attempt.timeoutMs }, attempt));
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
const pending = error instanceof ResponseError && error.reason?.code === 'EXECUTION_PENDING';
|
|
87
|
-
if (!pending || Date.now() - started < LAPSED_WAIT_MS)
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
/** The status after a wait, read again as `settle` sends its wait again, within the deadline. */
|
|
93
|
-
observe(id, accept, request) {
|
|
94
|
-
const deadline = Date.now() + (options(request).timeoutMs ?? 0);
|
|
95
|
-
return read(deadline, request, (attempt) => status(id, accept, value(id, methods.status, {}, attempt)));
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
}
|
|
3
|
+
import { acceptOutput, executionMethods } from '../execution/index.js';
|
|
99
4
|
/** The install Methods: a completed outcome carries the result its Protocol owner admits. */
|
|
100
|
-
export function createInstallation(
|
|
101
|
-
const
|
|
102
|
-
if (uninstallOutput.safeParse(input).success) {
|
|
103
|
-
throw new TypeError('The Execution is an uninstall: read it through SchemaApi.uninstallation.');
|
|
104
|
-
}
|
|
105
|
-
return protocolSchema.installation.acceptResult(input);
|
|
106
|
-
};
|
|
5
|
+
export function createInstallation(call) {
|
|
6
|
+
const { signal, ...methods } = executionMethods(call, acceptInstallResult);
|
|
107
7
|
return Object.freeze({
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
delete: (execution, request) => executions.delete(execution, request),
|
|
8
|
+
...methods,
|
|
9
|
+
apply: async (execution, command, options) => signal(execution, {
|
|
10
|
+
name: commandSignal(ordinal(command.index)),
|
|
11
|
+
value: Object.freeze({
|
|
12
|
+
kind: 'apply',
|
|
13
|
+
...(command.validation === undefined ? {} : { validation: command.validation }),
|
|
14
|
+
}),
|
|
15
|
+
}, options),
|
|
16
|
+
abort: async (execution, attempt, options) => signal(execution, { name: abortSignal(ordinal(attempt)), value: Object.freeze({ kind: 'abort' }) }, options),
|
|
118
17
|
});
|
|
119
18
|
}
|
|
120
19
|
/** The uninstall Methods: a completed outcome carries the receipt Core's contract admits. */
|
|
121
|
-
export function createUninstallation(
|
|
122
|
-
const
|
|
123
|
-
return Object.freeze(
|
|
124
|
-
status: (execution, request) => executions.status(execution, accept, request),
|
|
125
|
-
result: (execution, wait, request) => executions.result(execution, accept, wait, request),
|
|
126
|
-
cancel: (execution, input = {}, request) => executions.cancel(execution, accept, input, request),
|
|
127
|
-
resume: (execution, request) => executions.resume(execution, accept, request),
|
|
128
|
-
delete: (execution, request) => executions.delete(execution, request),
|
|
129
|
-
});
|
|
20
|
+
export function createUninstallation(call) {
|
|
21
|
+
const { signal: _signal, ...methods } = executionMethods(call, acceptUninstallReceipt);
|
|
22
|
+
return Object.freeze(methods);
|
|
130
23
|
}
|
|
131
|
-
|
|
132
|
-
|
|
24
|
+
function acceptInstallResult(input) {
|
|
25
|
+
if (uninstallOutput.safeParse(input).success) {
|
|
26
|
+
throw new TypeError('The Execution is an uninstall: read it through SchemaApi.uninstallation.');
|
|
27
|
+
}
|
|
28
|
+
return protocolSchema.installation.acceptResult(input);
|
|
133
29
|
}
|
|
134
|
-
function
|
|
135
|
-
|
|
136
|
-
return outcome;
|
|
137
|
-
return Object.freeze({ kind: 'completed', value: accept(outcome.value) });
|
|
30
|
+
function acceptUninstallReceipt(input) {
|
|
31
|
+
return acceptOutput(uninstallOutput, input, 'uninstall receipt');
|
|
138
32
|
}
|
|
139
33
|
function ordinal(input) {
|
|
140
34
|
if (!Number.isSafeInteger(input) || input < 1) {
|
package/dist/schema/schema.d.ts
CHANGED
|
@@ -1,32 +1,31 @@
|
|
|
1
1
|
import type { Key } from '@astrale-os/kernel-dsl/v1';
|
|
2
|
-
import * as protocolSchema from '@astrale-os/kernel-protocol/schema';
|
|
2
|
+
import type * as protocolSchema from '@astrale-os/kernel-protocol/schema';
|
|
3
3
|
import type { Call, Result } from '../client/index.js';
|
|
4
4
|
import type { RequestOptions } from '../transport/index.js';
|
|
5
5
|
import type { Installation, InstallRequest, Uninstallation, UninstallRequest } from './contracts.js';
|
|
6
6
|
import { type InstallationApi, type UninstallationApi } from './installation.js';
|
|
7
7
|
export type SchemaCall = (call: Call, options?: RequestOptions) => Promise<Result>;
|
|
8
8
|
export interface SchemaOptions extends protocolSchema.installation.introspection.Limits {
|
|
9
|
-
readonly lifecycleTimeoutMs?: number;
|
|
10
9
|
}
|
|
11
10
|
export type DomainInfo = protocolSchema.installation.introspection.DomainInfo;
|
|
12
11
|
export type DomainBundle = protocolSchema.installation.introspection.DomainBundle;
|
|
13
12
|
export type DomainDependencies = protocolSchema.installation.introspection.DomainDependencies;
|
|
14
13
|
export type InstalledRelease = protocolSchema.installation.introspection.InstalledRelease;
|
|
15
14
|
export type InstalledPin = protocolSchema.installation.introspection.InstalledPin;
|
|
16
|
-
export type InstallResult = protocolSchema.installation.InstallResult;
|
|
17
15
|
export interface SchemaApi {
|
|
18
16
|
/**
|
|
19
|
-
* Install Domains: start the durable Execution the install is,
|
|
20
|
-
* the mode is `maintenance`,
|
|
21
|
-
* the Execution with its status; `result` is
|
|
22
|
-
* terminal `failed` status, never a failed
|
|
17
|
+
* Install Domains: start the durable Execution the install is, wait at most `waitMs` (110 s by
|
|
18
|
+
* default) for its outcome unless the mode is `maintenance`, and read its status. `timeoutMs`,
|
|
19
|
+
* when given, bounds the whole call. The answer names the Execution with its status; `result` is
|
|
20
|
+
* present once it completed. A rejected install is a terminal `failed` status, never a failed
|
|
21
|
+
* call.
|
|
23
22
|
*/
|
|
24
23
|
install(request: InstallRequest, options?: RequestOptions): Promise<Installation>;
|
|
25
24
|
/** The install executions and repair sessions, through their `K.Execution` Methods. */
|
|
26
25
|
readonly installation: InstallationApi;
|
|
27
26
|
/**
|
|
28
|
-
* Uninstall Domains: start the durable Execution the uninstall is
|
|
29
|
-
*
|
|
27
|
+
* Uninstall Domains: start the durable Execution the uninstall is, wait at most `waitMs` (110 s
|
|
28
|
+
* by default) for its outcome and read its status. `result` is the receipt once it completed.
|
|
30
29
|
*/
|
|
31
30
|
uninstall(request: UninstallRequest, options?: RequestOptions): Promise<Uninstallation>;
|
|
32
31
|
/** The uninstall executions, through their `K.Execution` Methods. */
|
|
@@ -36,6 +35,5 @@ export interface SchemaApi {
|
|
|
36
35
|
dependencies(origin: Key.Origin, options?: RequestOptions): Promise<DomainDependencies>;
|
|
37
36
|
installed(options?: RequestOptions): Promise<readonly InstalledRelease[]>;
|
|
38
37
|
}
|
|
39
|
-
export declare const DEFAULT_SCHEMA_LIFECYCLE_TIMEOUT_MS = 110000;
|
|
40
38
|
/** Bind the canonical Schema lifecycle syscalls to one caller-scoped value-call capability. */
|
|
41
39
|
export declare function createSchema(call: SchemaCall, limits: SchemaOptions): SchemaApi;
|
package/dist/schema/schema.js
CHANGED
|
@@ -1,41 +1,39 @@
|
|
|
1
1
|
import { Path } from '@astrale-os/kernel-core/path';
|
|
2
2
|
import { install, uninstall } from '@astrale-os/kernel-core/schema/kernel/syscalls/references';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
3
|
+
import { call as invocation } from '../client/index.js';
|
|
4
|
+
import { acceptWait, deadlineOf, within } from '../execution/index.js';
|
|
5
|
+
import { createInstallation, createUninstallation, } from './installation.js';
|
|
5
6
|
import { introspect } from './introspection.js';
|
|
6
7
|
const INSTALL_PATH = Path.project(install).raw;
|
|
7
8
|
const UNINSTALL_PATH = Path.project(uninstall).raw;
|
|
8
|
-
|
|
9
|
+
/** How long an install or uninstall waits for its outcome unless its request says otherwise. */
|
|
10
|
+
const DEFAULT_LIFECYCLE_WAIT_MS = 110_000;
|
|
9
11
|
/** Bind the canonical Schema lifecycle syscalls to one caller-scoped value-call capability. */
|
|
10
12
|
export function createSchema(call, limits) {
|
|
11
13
|
if (typeof call !== 'function')
|
|
12
14
|
throw new TypeError('Schema call capability is invalid.');
|
|
13
15
|
const admittedLimits = admitLimits(limits);
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const uninstallation = createUninstallation(executions);
|
|
16
|
+
const installation = createInstallation(call);
|
|
17
|
+
const uninstallation = createUninstallation(call);
|
|
17
18
|
return Object.freeze({
|
|
18
19
|
async install(request, options) {
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
const execution = await executions.start(INSTALL_PATH, input, options);
|
|
20
|
+
const { waitMs, ...input } = request;
|
|
21
|
+
const wait = lifecycleWait(waitMs);
|
|
22
22
|
// A maintenance session awaits Root's commands: its outcome is not the call's to wait for.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
const status = await executions.observe(execution, protocolSchema.installation.acceptResult, options);
|
|
27
|
-
return admitInstallation(request, execution, status);
|
|
23
|
+
const started = await lifecycle(call, installation, INSTALL_PATH, input, input.mode === 'maintenance' ? 0 : wait, options);
|
|
24
|
+
return admitInstallation(request, started);
|
|
28
25
|
},
|
|
29
26
|
installation,
|
|
30
27
|
async uninstall(request, options) {
|
|
28
|
+
const wait = lifecycleWait(request.waitMs);
|
|
31
29
|
const snapshot = snapshotUninstallRequest(request);
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
const status =
|
|
30
|
+
const started = await lifecycle(call, uninstallation, UNINSTALL_PATH, snapshot, wait, options);
|
|
31
|
+
const answer = { execution: started.status.id, ...started };
|
|
32
|
+
const { status } = started;
|
|
35
33
|
if (status.outcome?.kind !== 'completed')
|
|
36
|
-
return Object.freeze(
|
|
34
|
+
return Object.freeze(answer);
|
|
37
35
|
proveUninstallReceipt(snapshot, status.outcome.value);
|
|
38
|
-
return Object.freeze({
|
|
36
|
+
return Object.freeze({ ...answer, result: status.outcome.value });
|
|
39
37
|
},
|
|
40
38
|
uninstallation,
|
|
41
39
|
async inspect(origin, options) {
|
|
@@ -52,6 +50,28 @@ export function createSchema(call, limits) {
|
|
|
52
50
|
},
|
|
53
51
|
});
|
|
54
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* One lifecycle syscall, before the call's deadline: start the durable Execution it is, wait at
|
|
55
|
+
* most `waitMs` for its outcome, and read its status. Any end of the wait leaves the status to say
|
|
56
|
+
* where the Execution is, so the caller never loses it.
|
|
57
|
+
*/
|
|
58
|
+
async function lifecycle(call, executions, path, input, waitMs, options) {
|
|
59
|
+
const deadline = deadlineOf(options);
|
|
60
|
+
const started = await call(invocation(path, input), within(deadline, options));
|
|
61
|
+
if (started.kind !== 'execution') {
|
|
62
|
+
throw new TypeError('Schema syscall did not answer with an Execution.');
|
|
63
|
+
}
|
|
64
|
+
if (waitMs > 0) {
|
|
65
|
+
await executions
|
|
66
|
+
.result(started.execution, { waitMs }, within(deadline, options))
|
|
67
|
+
.catch(() => undefined);
|
|
68
|
+
}
|
|
69
|
+
const status = await executions.status(started.execution, within(deadline, options));
|
|
70
|
+
return started.replayed === undefined ? { status } : { status, replayed: started.replayed };
|
|
71
|
+
}
|
|
72
|
+
function lifecycleWait(waitMs) {
|
|
73
|
+
return acceptWait({ waitMs: waitMs ?? DEFAULT_LIFECYCLE_WAIT_MS });
|
|
74
|
+
}
|
|
55
75
|
function snapshotUninstallRequest(request) {
|
|
56
76
|
return Object.freeze({
|
|
57
77
|
operation: request.operation,
|
|
@@ -76,12 +96,14 @@ function compare(left, right) {
|
|
|
76
96
|
* The answer of one install, proved against its request: a completed status carries the result of
|
|
77
97
|
* exactly this operation, admitted by its Protocol owner.
|
|
78
98
|
*/
|
|
79
|
-
function admitInstallation(request,
|
|
99
|
+
function admitInstallation(request, started) {
|
|
100
|
+
const answer = { execution: started.status.id, ...started };
|
|
101
|
+
const { status } = started;
|
|
80
102
|
if (status.outcome?.kind !== 'completed')
|
|
81
|
-
return Object.freeze(
|
|
103
|
+
return Object.freeze(answer);
|
|
82
104
|
const result = status.outcome.value;
|
|
83
105
|
proveInstallResult(request, result);
|
|
84
|
-
return Object.freeze({
|
|
106
|
+
return Object.freeze({ ...answer, result });
|
|
85
107
|
}
|
|
86
108
|
function proveInstallResult(request, result) {
|
|
87
109
|
if (result.changed) {
|
|
@@ -98,22 +120,13 @@ function proveInstallResult(request, result) {
|
|
|
98
120
|
}
|
|
99
121
|
}
|
|
100
122
|
function admitLimits(input) {
|
|
101
|
-
const lifecycleTimeoutMs = input?.lifecycleTimeoutMs ?? DEFAULT_SCHEMA_LIFECYCLE_TIMEOUT_MS;
|
|
102
123
|
if (input === null ||
|
|
103
124
|
typeof input !== 'object' ||
|
|
104
125
|
!Number.isSafeInteger(input.maximumReleaseBytes) ||
|
|
105
126
|
input.maximumReleaseBytes < 1 ||
|
|
106
127
|
!Number.isSafeInteger(input.maximumBundleBytes) ||
|
|
107
|
-
input.maximumBundleBytes < 1
|
|
108
|
-
!Number.isSafeInteger(lifecycleTimeoutMs) ||
|
|
109
|
-
lifecycleTimeoutMs < 1 ||
|
|
110
|
-
lifecycleTimeoutMs > 2_147_483_647) {
|
|
128
|
+
input.maximumBundleBytes < 1) {
|
|
111
129
|
throw new TypeError('Schema introspection limits are invalid.');
|
|
112
130
|
}
|
|
113
|
-
return Object.freeze({ ...input
|
|
114
|
-
}
|
|
115
|
-
function lifecycleOptions(options, timeoutMs) {
|
|
116
|
-
if (options?.timeoutMs !== undefined)
|
|
117
|
-
return options;
|
|
118
|
-
return Object.freeze({ ...options, timeoutMs });
|
|
131
|
+
return Object.freeze({ ...input });
|
|
119
132
|
}
|
package/dist/session/bound.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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';
|
|
@@ -36,6 +37,7 @@ export interface BoundClientSession extends GraphApi {
|
|
|
36
37
|
readonly kernel: IssuerId;
|
|
37
38
|
readonly auth: AuthApi;
|
|
38
39
|
readonly schema: SchemaApi;
|
|
40
|
+
readonly execution: ExecutionApi;
|
|
39
41
|
readonly content: ContentApi;
|
|
40
42
|
dispatch: ClientSession['dispatch'];
|
|
41
43
|
call: ClientSession['call'];
|
package/dist/session/bound.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createAuth } from '../auth/auth.js';
|
|
2
2
|
import { call as createCall, } from '../client/index.js';
|
|
3
|
+
import { createExecution } from '../execution/index.js';
|
|
3
4
|
import { createGraph } from '../graph/index.js';
|
|
4
5
|
/** Capture one Session into the ordinary graph, auth, and invocation Kernel journey. */
|
|
5
6
|
export function bindSession(source, controls) {
|
|
@@ -65,12 +66,14 @@ export function bindSession(source, controls) {
|
|
|
65
66
|
installed,
|
|
66
67
|
});
|
|
67
68
|
const graph = createGraph(call);
|
|
69
|
+
const execution = createExecution(dispatch);
|
|
68
70
|
const auth = createAuth((target, input, options) => call(createCall(target, input), options), admit);
|
|
69
71
|
return Object.freeze({
|
|
70
72
|
...graph,
|
|
71
73
|
kernel: source.kernel,
|
|
72
74
|
auth,
|
|
73
75
|
schema,
|
|
76
|
+
execution,
|
|
74
77
|
dispatch,
|
|
75
78
|
call,
|
|
76
79
|
invoke,
|
package/dist/session/index.d.ts
CHANGED
|
@@ -9,6 +9,6 @@ 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 {
|
|
12
|
+
export type { DeletedExecutionStatus, ExecutionApi, ExecutionFailure, ExecutionNodeStatus, ExecutionOutcome, ExecutionRef, ExecutionState, ExecutionStatus, ExecutionTarget, ExecutionWait, } from '../execution/index.js';
|
|
13
13
|
export type { ResolvedView, ViewCatalog } from './views/index.js';
|
|
14
14
|
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 ||
|
|
@@ -4,7 +4,7 @@ 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
6
|
import type { Binary, Input, Result } from '../client/index.js';
|
|
7
|
-
import type { ExecutionRef } from '
|
|
7
|
+
import type { ExecutionRef } from '../execution/index.js';
|
|
8
8
|
/** Result kind a reference expects: a durable callable answers with its Execution. */
|
|
9
9
|
type OutputMode = Exclude<Result['kind'], 'redirect'>;
|
|
10
10
|
declare const REFERENCE_INPUT: unique symbol;
|
|
@@ -3,6 +3,7 @@ import type { PathLike } from '@astrale-os/kernel-core/path';
|
|
|
3
3
|
import type { Domain } from '@astrale-os/kernel-dsl/v1/domain';
|
|
4
4
|
import type { AuthApi } from '../auth/index.js';
|
|
5
5
|
import type { Call, Input, Result } from '../client/index.js';
|
|
6
|
+
import type { ExecutionApi } from '../execution/index.js';
|
|
6
7
|
import type { DomainBinding, GraphApi } from '../graph/index.js';
|
|
7
8
|
import type { SchemaApi } from '../schema/index.js';
|
|
8
9
|
import type { ContentApi } from './content/index.js';
|
|
@@ -22,6 +23,8 @@ export type ConnectOptions = Omit<ClientSessionOptions, 'kernel' | 'policy'> & {
|
|
|
22
23
|
export declare class ClientSession {
|
|
23
24
|
readonly kernel: IssuerId;
|
|
24
25
|
readonly schema: SchemaApi;
|
|
26
|
+
/** The `K.Execution` Methods of any Execution, a durable call's or an install's. */
|
|
27
|
+
readonly execution: ExecutionApi;
|
|
25
28
|
readonly graph: GraphApi;
|
|
26
29
|
readonly auth: AuthApi;
|
|
27
30
|
readonly content: ContentApi;
|
package/dist/session/session.js
CHANGED
|
@@ -3,6 +3,7 @@ import { callableFingerprint } from '@astrale-os/kernel-dsl/v1/schema/fingerprin
|
|
|
3
3
|
import { createAuth } from '../auth/auth.js';
|
|
4
4
|
import { acceptCall } from '../client/index.js';
|
|
5
5
|
import { SessionError } from '../errors/index.js';
|
|
6
|
+
import { createExecution } from '../execution/index.js';
|
|
6
7
|
import { createDomainBinding } from '../graph/domain/binding.js';
|
|
7
8
|
import { createGraph } from '../graph/index.js';
|
|
8
9
|
import { createSchema } from '../schema/index.js';
|
|
@@ -20,6 +21,8 @@ const DEFAULT_SESSION_POLICY = Object.freeze({ maximumRouteAgeMs: 60_000 });
|
|
|
20
21
|
export class ClientSession {
|
|
21
22
|
kernel;
|
|
22
23
|
schema;
|
|
24
|
+
/** The `K.Execution` Methods of any Execution, a durable call's or an install's. */
|
|
25
|
+
execution;
|
|
23
26
|
graph;
|
|
24
27
|
auth;
|
|
25
28
|
content;
|
|
@@ -92,8 +95,8 @@ export class ClientSession {
|
|
|
92
95
|
this.schema = createSchema((request, options) => this.dispatch(request, options), {
|
|
93
96
|
maximumReleaseBytes,
|
|
94
97
|
maximumBundleBytes,
|
|
95
|
-
lifecycleTimeoutMs: settled.schemaLifecycleTimeoutMs,
|
|
96
98
|
});
|
|
99
|
+
this.execution = createExecution((request, options) => this.dispatch(request, options));
|
|
97
100
|
this.graph = createGraph((call, options) => this.call(call, options));
|
|
98
101
|
this.auth = createAuth((target, input, options) => this.call({ target, input }, options), (call, options) => {
|
|
99
102
|
const operation = this.operation(admitControlOptions(options));
|
|
@@ -166,7 +169,10 @@ export class ClientSession {
|
|
|
166
169
|
case 'stream':
|
|
167
170
|
return narrowed.stream;
|
|
168
171
|
case 'execution':
|
|
169
|
-
return Object.freeze({
|
|
172
|
+
return Object.freeze({
|
|
173
|
+
id: narrowed.execution,
|
|
174
|
+
...(narrowed.replayed === undefined ? {} : { replayed: narrowed.replayed }),
|
|
175
|
+
});
|
|
170
176
|
default:
|
|
171
177
|
return narrowed.value;
|
|
172
178
|
}
|