@astrale-os/kernel-client 1.0.0-beta.4 → 1.0.0-beta.6

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.
Files changed (44) hide show
  1. package/dist/client/index.d.ts +1 -1
  2. package/dist/client/request.d.ts +1 -0
  3. package/dist/client/request.js +17 -0
  4. package/dist/client/result.d.ts +4 -1
  5. package/dist/client/result.js +10 -4
  6. package/dist/errors/index.d.ts +1 -0
  7. package/dist/errors/index.js +1 -0
  8. package/dist/errors/refusal.d.ts +12 -0
  9. package/dist/errors/refusal.js +40 -0
  10. package/dist/graph/domain/binding.js +4 -0
  11. package/dist/graph/page-contract.d.ts +6 -0
  12. package/dist/graph/query.js +10 -2
  13. package/dist/pacer/index.d.ts +1 -1
  14. package/dist/pacer/index.js +1 -1
  15. package/dist/pacer/retry/index.d.ts +1 -0
  16. package/dist/pacer/retry/index.js +1 -0
  17. package/dist/pacer/retry/refusals.d.ts +7 -0
  18. package/dist/pacer/retry/refusals.js +10 -0
  19. package/dist/pacer/retry/retry.d.ts +2 -0
  20. package/dist/pacer/retry/retry.js +33 -1
  21. package/dist/schema/admission.d.ts +1 -1
  22. package/dist/schema/admission.js +2 -2
  23. package/dist/schema/contracts.d.ts +95 -2
  24. package/dist/schema/index.d.ts +2 -1
  25. package/dist/schema/installation.d.ts +104 -0
  26. package/dist/schema/installation.js +144 -0
  27. package/dist/schema/schema.d.ts +18 -3
  28. package/dist/schema/schema.js +31 -35
  29. package/dist/session/bound.js +42 -0
  30. package/dist/session/execution.d.ts +24 -1
  31. package/dist/session/index.d.ts +1 -1
  32. package/dist/session/reference.d.ts +8 -4
  33. package/dist/session/reference.js +7 -2
  34. package/dist/session/routing/dispatch.js +2 -0
  35. package/dist/session/routing/request.d.ts +4 -0
  36. package/dist/session/routing/request.js +11 -1
  37. package/dist/session/routing/result.d.ts +1 -1
  38. package/dist/session/routing/result.js +5 -1
  39. package/dist/session/session.js +10 -7
  40. package/dist/store/memory.js +20 -1
  41. package/dist/transport/http/admission.js +3 -0
  42. package/dist/transport/transport.d.ts +10 -0
  43. package/dist/transport/websocket/exchange.js +8 -0
  44. package/package.json +4 -4
@@ -2,5 +2,5 @@ export { Client, dispatchTrace, type ClientOptions } from './client.js';
2
2
  export { acceptCall } from './admission.js';
3
3
  export type { AuthenticatedClient, RemoteCredential } from './credential.js';
4
4
  export { call, type Call, type ClientDispatchOptions, type ClientDispatchOptionsWithBody, } from './request.js';
5
- export type { Binary, BinaryResponse, Input, RedirectResult, Result, Stream, StreamResult, ValueResult, } from './result.js';
5
+ export type { Binary, BinaryResponse, ExecutionResult, Input, RedirectResult, Result, Stream, StreamResult, ValueResult, } from './result.js';
6
6
  export { isAdmittedDeploymentRetiredError, isAdmittedMissError, isAdmittedStaleRouteError, } from './routing-control.js';
@@ -25,6 +25,7 @@ export interface AdmittedRequest {
25
25
  readonly delegate?: protocol.Delegate;
26
26
  readonly routing?: protocol.Routing;
27
27
  readonly schema?: protocol.SchemaTarget;
28
+ readonly maintenance?: protocol.Maintenance;
28
29
  readonly options: RequestOptions;
29
30
  readonly body?: Blob;
30
31
  }
@@ -10,11 +10,13 @@ export function admitRequest(input, options, lifecycle) {
10
10
  const delegate = admitDelegate(options?.delegate);
11
11
  const routing = admitRouting(options?.routing);
12
12
  const schema = admitSchemaTarget(options?.schema);
13
+ const maintenance = admitMaintenance(options?.maintenance);
13
14
  return Object.freeze({
14
15
  call,
15
16
  ...(delegate === undefined ? {} : { delegate }),
16
17
  ...(routing === undefined ? {} : { routing }),
17
18
  ...(schema === undefined ? {} : { schema }),
19
+ ...(maintenance === undefined ? {} : { maintenance }),
18
20
  ...(admitted.body === undefined ? {} : { body: admitted.body }),
19
21
  options: admittedOptions,
20
22
  });
@@ -28,6 +30,9 @@ export function invocation(request, credential, trace) {
28
30
  if (request.schema !== undefined) {
29
31
  throw new TypeError('Destination Client requests cannot carry a Schema target.');
30
32
  }
33
+ if (request.maintenance !== undefined) {
34
+ throw new TypeError('Destination Client requests cannot carry a maintenance guard.');
35
+ }
31
36
  }
32
37
  else if ((credential === undefined) !== (request.delegate === undefined)) {
33
38
  throw new TypeError('Source Client credentials and delegation requests must occur together.');
@@ -38,6 +43,7 @@ export function invocation(request, credential, trace) {
38
43
  ...(request.delegate === undefined ? {} : { delegate: request.delegate }),
39
44
  ...(request.routing === undefined ? {} : { routing: request.routing }),
40
45
  ...(request.schema === undefined ? {} : { schema: request.schema }),
46
+ ...(request.maintenance === undefined ? {} : { maintenance: request.maintenance }),
41
47
  ...(admittedTrace === undefined ? {} : { trace: admittedTrace }),
42
48
  });
43
49
  }
@@ -54,6 +60,7 @@ function admitRequestOptions(input) {
54
60
  'delegate',
55
61
  'routing',
56
62
  'schema',
63
+ 'maintenance',
57
64
  'body',
58
65
  ].includes(String(field)))) {
59
66
  throw new TypeError('Client request options contain unsupported fields.');
@@ -118,6 +125,16 @@ function admitSchemaTarget(input) {
118
125
  throw new TypeError('Client Schema target is invalid.', { cause });
119
126
  }
120
127
  }
128
+ function admitMaintenance(input) {
129
+ if (input === undefined)
130
+ return undefined;
131
+ try {
132
+ return invocationProtocol.acceptMaintenance(input);
133
+ }
134
+ catch (cause) {
135
+ throw new TypeError('Client maintenance guard is invalid.', { cause });
136
+ }
137
+ }
121
138
  function lifecycleOptions(input, lifecycle) {
122
139
  const signal = input?.signal === undefined ? lifecycle : AbortSignal.any([input.signal, lifecycle]);
123
140
  return Object.freeze({
@@ -23,12 +23,15 @@ export type StreamResult = Correlated<Extract<Callable, {
23
23
  export type BinaryResponse = Correlated<Extract<Callable, {
24
24
  readonly kind: 'binary';
25
25
  }>>;
26
+ export type ExecutionResult = Correlated<Extract<Callable, {
27
+ readonly kind: 'execution';
28
+ }>>;
26
29
  export interface RedirectResult {
27
30
  readonly kind: 'redirect';
28
31
  readonly redirect: protocol.Redirection;
29
32
  readonly invocation: protocol.InvocationId;
30
33
  }
31
- export type Result = ValueResult | StreamResult | BinaryResponse | RedirectResult;
34
+ export type Result = ValueResult | StreamResult | BinaryResponse | ExecutionResult | RedirectResult;
32
35
  export declare function requireValue(result: Promise<Result>): Promise<ValueResult>;
33
36
  export declare function requireStream(result: Promise<Result>): Promise<StreamResult>;
34
37
  export declare function requireBinary(result: Promise<Result>): Promise<BinaryResponse>;
@@ -8,7 +8,7 @@ export async function requireValue(result) {
8
8
  export async function requireStream(result) {
9
9
  const settled = await result;
10
10
  if (settled.kind !== 'stream')
11
- mismatch('stream', settled.kind);
11
+ mismatch('stream', settled);
12
12
  return settled;
13
13
  }
14
14
  export async function requireBinary(result) {
@@ -17,8 +17,14 @@ export async function requireBinary(result) {
17
17
  return rejectMismatch('binary', settled);
18
18
  return settled;
19
19
  }
20
- function mismatch(expected, received) {
21
- throw new ClientError(`Function returned ${received}; ${expected} was required.`);
20
+ function mismatch(expected, result) {
21
+ throw new ClientError(`${returned(result)}; ${expected} was required.`);
22
+ }
23
+ /** What the call did; a started Execution is named so its caller never starts it again. */
24
+ function returned(result) {
25
+ return result.kind === 'execution'
26
+ ? `Function started Execution ${result.execution}`
27
+ : `Function returned ${result.kind}`;
22
28
  }
23
29
  async function rejectMismatch(expected, result) {
24
30
  if (result.kind === 'stream') {
@@ -27,5 +33,5 @@ async function rejectMismatch(expected, result) {
27
33
  if (result.kind === 'binary' && !(result.value.body instanceof Uint8Array)) {
28
34
  await result.value.body[Symbol.asyncIterator]().return?.();
29
35
  }
30
- mismatch(expected, result.kind);
36
+ mismatch(expected, result);
31
37
  }
@@ -2,6 +2,7 @@ export * from './client-error.js';
2
2
  export * from './exchange-error.js';
3
3
  export * from './miss-error.js';
4
4
  export * from './protocol-error.js';
5
+ export * from './refusal.js';
5
6
  export * from './response-error.js';
6
7
  export * from './session-error.js';
7
8
  export * from './stale-route-error.js';
@@ -2,6 +2,7 @@ export * from './client-error.js';
2
2
  export * from './exchange-error.js';
3
3
  export * from './miss-error.js';
4
4
  export * from './protocol-error.js';
5
+ export * from './refusal.js';
5
6
  export * from './response-error.js';
6
7
  export * from './session-error.js';
7
8
  export * from './stale-route-error.js';
@@ -0,0 +1,12 @@
1
+ import { ResponseError } from './response-error.js';
2
+ /** Return the delay a refused invocation prescribes before it is sent again, and nothing else. */
3
+ export declare function retryAfterOf(error: unknown): number | undefined;
4
+ /** Whether the Instance refused the invocation because a maintenance session admits only root. */
5
+ export declare function isMaintenance(error: unknown): error is ResponseError;
6
+ /**
7
+ * Whether the Kernel refused a request whose maintenance guard names a session that does not own
8
+ * the Instance: it ended, or another one owns it. Nothing ran; resending it unchanged cannot succeed.
9
+ */
10
+ export declare function isMaintenanceSessionStale(error: unknown): error is ResponseError;
11
+ /** Whether a sealed conflict ran nothing because the graph snapshot advanced; resend it at once. */
12
+ export declare function isSnapshotStale(error: unknown): error is ResponseError;
@@ -0,0 +1,40 @@
1
+ import * as errors from '@astrale-os/kernel-protocol/errors';
2
+ import { ResponseError } from './response-error.js';
3
+ /** Sealed conflicts whose plan met a checkpoint advanced past its pinned snapshot. */
4
+ const SNAPSHOT_STALE_REASONS = new Set([
5
+ 'SNAPSHOT_STALE',
6
+ 'QUERY_SNAPSHOT_STALE',
7
+ 'MUTATION_SNAPSHOT_STALE',
8
+ ]);
9
+ /** Return the delay a refused invocation prescribes before it is sent again, and nothing else. */
10
+ export function retryAfterOf(error) {
11
+ if (!(error instanceof ResponseError))
12
+ return undefined;
13
+ return errors.retryAfterOf({
14
+ code: error.code,
15
+ message: error.message,
16
+ ...(error.data === undefined ? {} : { data: error.data }),
17
+ });
18
+ }
19
+ /** Whether the Instance refused the invocation because a maintenance session admits only root. */
20
+ export function isMaintenance(error) {
21
+ return (error instanceof ResponseError &&
22
+ error.reason?.code === errors.RETRY_REASONS.INSTANCE_MAINTENANCE &&
23
+ retryAfterOf(error) !== undefined);
24
+ }
25
+ /**
26
+ * Whether the Kernel refused a request whose maintenance guard names a session that does not own
27
+ * the Instance: it ended, or another one owns it. Nothing ran; resending it unchanged cannot succeed.
28
+ */
29
+ export function isMaintenanceSessionStale(error) {
30
+ return (error instanceof ResponseError &&
31
+ error.code === errors.CODES.CONFLICT &&
32
+ error.reason?.code === 'MAINTENANCE_SESSION_STALE');
33
+ }
34
+ /** Whether a sealed conflict ran nothing because the graph snapshot advanced; resend it at once. */
35
+ export function isSnapshotStale(error) {
36
+ return (error instanceof ResponseError &&
37
+ error.code === errors.CODES.CONFLICT &&
38
+ error.reason !== undefined &&
39
+ SNAPSHOT_STALE_REASONS.has(error.reason.code));
40
+ }
@@ -35,6 +35,10 @@ export function createDomainBinding(domain, graph, call) {
35
35
  async query(query, options) {
36
36
  const selected = selectedSourceClass(domain, query);
37
37
  const response = await graph.query(query, { ...options, expected: domain.closure });
38
+ // A repair-session read may hold facts the bound Domain refutes: it is never typed by it.
39
+ if (response.certification === 'uncertified') {
40
+ throw new TypeError('An uncertified Query response cannot be bound to its Domain.');
41
+ }
38
42
  const provenance = provenanceOfResponse(response);
39
43
  if (provenance === undefined || !sameClosure(provenance.closure, domain.closure)) {
40
44
  throw new TypeError('Authenticated query provenance was not retained.');
@@ -10,4 +10,10 @@ export interface QueryResponse<Result extends QueryResult = QueryResult> {
10
10
  readonly page: {
11
11
  readonly next?: string;
12
12
  };
13
+ /**
14
+ * Present only for a repair-session read made without conformance admission: its facts may
15
+ * violate the active schema, so it is raw Core data only. The Store keeps it out of its shared
16
+ * cache and a Domain binding refuses to type it.
17
+ */
18
+ readonly certification?: 'uncertified';
13
19
  }
@@ -52,9 +52,13 @@ function decodeResponse(input) {
52
52
  throw new TypeError('Graph query response is invalid.');
53
53
  }
54
54
  const value = input;
55
- if (!hasExactKeys(value, ['result', 'page'])) {
55
+ const uncertified = value.certification !== undefined;
56
+ if (!hasExactKeys(value, uncertified ? ['result', 'page', 'certification'] : ['result', 'page'])) {
56
57
  throw new TypeError('Graph query response is invalid.');
57
58
  }
59
+ if (uncertified && value.certification !== 'uncertified') {
60
+ throw new TypeError('Graph query response certification is invalid.');
61
+ }
58
62
  const pageInput = value.page;
59
63
  if (pageInput === null || typeof pageInput !== 'object' || Array.isArray(pageInput)) {
60
64
  throw new TypeError('Graph query response page is invalid.');
@@ -69,7 +73,11 @@ function decodeResponse(input) {
69
73
  }
70
74
  const result = QueryResult.decode(value.result);
71
75
  const page = Object.freeze(pageValue.next === undefined ? {} : { next: pageValue.next });
72
- return Object.freeze({ result, page });
76
+ return Object.freeze({
77
+ result,
78
+ page,
79
+ ...(uncertified ? { certification: 'uncertified' } : {}),
80
+ });
73
81
  }
74
82
  function hasExactKeys(input, expected) {
75
83
  const keys = Object.keys(input);
@@ -1,4 +1,4 @@
1
- export { retry, type RetryOptions } from './retry/index.js';
1
+ export { RETRY_REFUSALS, retry, type RetryOptions } from './retry/index.js';
2
2
  export { createQueue, type QueueOptions } from './queue/index.js';
3
3
  export { createBatcher, type BatchOptions } from './batcher/index.js';
4
4
  export { createRateLimiter, type RateLimitOptions } from './limiter/index.js';
@@ -1,4 +1,4 @@
1
- export { retry } from './retry/index.js';
1
+ export { RETRY_REFUSALS, retry } from './retry/index.js';
2
2
  export { createQueue } from './queue/index.js';
3
3
  export { createBatcher } from './batcher/index.js';
4
4
  export { createRateLimiter } from './limiter/index.js';
@@ -1 +1,2 @@
1
+ export { RETRY_REFUSALS } from './refusals.js';
1
2
  export { retry, type RetryOptions } from './retry.js';
@@ -1 +1,2 @@
1
+ export { RETRY_REFUSALS } from './refusals.js';
1
2
  export { retry } from './retry.js';
@@ -0,0 +1,7 @@
1
+ import type { RetryOptions } from './retry.js';
2
+ /**
3
+ * Opt-in policy for refusals proven to have run nothing. A back-pressure, draining or maintenance
4
+ * refusal is resent no earlier than its prescribed delay; a stale-snapshot conflict is resent after
5
+ * ordinary backoff. Every other failure ends the retry.
6
+ */
7
+ export declare const RETRY_REFUSALS: Readonly<Required<Pick<RetryOptions, 'shouldRetry' | 'retryAfter'>>>;
@@ -0,0 +1,10 @@
1
+ import { isSnapshotStale, retryAfterOf } from '../../errors/index.js';
2
+ /**
3
+ * Opt-in policy for refusals proven to have run nothing. A back-pressure, draining or maintenance
4
+ * refusal is resent no earlier than its prescribed delay; a stale-snapshot conflict is resent after
5
+ * ordinary backoff. Every other failure ends the retry.
6
+ */
7
+ export const RETRY_REFUSALS = Object.freeze({
8
+ shouldRetry: (error) => retryAfterOf(error) !== undefined || isSnapshotStale(error),
9
+ retryAfter: (error) => retryAfterOf(error),
10
+ });
@@ -4,6 +4,8 @@ export interface RetryOptions {
4
4
  readonly maxWait?: number;
5
5
  readonly jitter?: number;
6
6
  readonly shouldRetry?: (error: Error, attempt: number) => boolean;
7
+ /** Least delay in milliseconds a failure prescribes before the next attempt; backoff still applies. */
8
+ readonly retryAfter?: (error: Error, attempt: number) => number | undefined;
7
9
  }
8
10
  /** Retry with bounded exponential backoff and never swallow the final failure. */
9
11
  export declare function retry<Result>(operation: () => Promise<Result>, options?: RetryOptions): Promise<Result>;
@@ -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
- const result = await retryer.execute();
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
+ }
@@ -8,5 +8,5 @@ interface OutputContract {
8
8
  };
9
9
  }
10
10
  /** Admit one value result through its Core-owned syscall contract. */
11
- export declare function acceptOutput<T>(contract: OutputContract, input: unknown): T;
11
+ export declare function acceptOutput<T>(contract: OutputContract, input: unknown, what?: string): T;
12
12
  export {};
@@ -1,10 +1,10 @@
1
1
  import * as portable from '@astrale-os/kernel-dsl/value';
2
2
  /** Admit one value result through its Core-owned syscall contract. */
3
- export function acceptOutput(contract, input) {
3
+ export function acceptOutput(contract, input, what = 'Schema result') {
4
4
  const value = portable.accept(input);
5
5
  const parsed = contract.safeParse(value);
6
6
  if (!parsed.success)
7
- throw new TypeError('Kernel returned an invalid Schema result.');
7
+ throw new TypeError(`Kernel returned an invalid ${what}.`);
8
8
  return freeze(parsed.data);
9
9
  }
10
10
  function freeze(input) {
@@ -1,12 +1,105 @@
1
+ import type { NodeId } from '@astrale-os/kernel-core/graph/node';
1
2
  import type { installation } from '@astrale-os/kernel-core/schema';
2
- import type { DomainRequest as CoreDomainRequest, InstallInput, InstallReceipt as CoreInstallReceipt, UninstallInput, UninstallOutput } from '@astrale-os/kernel-core/schema/kernel/syscalls/contracts';
3
+ import type { AttemptReport, DomainRequest as CoreDomainRequest, InstallClass as CoreInstallClass, InstallInput, InstallMode as CoreInstallMode, InstallReceipt as CoreInstallReceipt, SystemExecutionDetail, UninstallInput, UninstallOutput, ValidationOptions } from '@astrale-os/kernel-core/schema/kernel/syscalls/contracts';
4
+ import type { Value } from '@astrale-os/kernel-dsl/value';
5
+ import type { schema as protocolSchema } from '@astrale-os/kernel-protocol';
6
+ import type { ExecutionState } from '../session/execution.js';
3
7
  export type OperationId = installation.OperationId;
4
8
  /** Canonical caller input accepted by the Kernel install syscall. */
5
9
  export type DomainRequest = CoreDomainRequest;
6
- export type InstallRequest = InstallInput;
10
+ /**
11
+ * One install: its Kernel input, plus `wait`, which the Client alone reads: `false` answers at
12
+ * once, otherwise the Client waits for the outcome within the request deadline. It is never sent,
13
+ * so it is no part of the operation's intent.
14
+ */
15
+ export type InstallRequest = InstallInput & {
16
+ readonly wait?: boolean;
17
+ };
7
18
  /** Admitted terminal install receipt returned by the Kernel. */
8
19
  export type InstallReceipt = CoreInstallReceipt;
20
+ /** The `K.Execution` an install or uninstall is; a repair session's id is its Execution's. */
21
+ export type InstallExecutionId = NodeId;
22
+ /** What an install does to the stored data: nothing, applied at once, or revalidated first. */
23
+ export type InstallClass = CoreInstallClass;
24
+ export type InstallMode = CoreInstallMode;
25
+ /** The validation options of an install, defaults filled in. */
26
+ export type InstallValidationOptions = ValidationOptions;
27
+ /** The last attempt of a repair session that ended without activating, with its report. */
28
+ export type InstallAttemptReport = AttemptReport;
29
+ /** What an install or session shows beside its engine state, as Core shapes it. */
30
+ export type InstallDetail = SystemExecutionDetail;
31
+ /** The public failure a rejected install ended with, such as `DATA_MIGRATION_REQUIRED`. */
32
+ export interface InstallFailure {
33
+ readonly code: string;
34
+ readonly message: string;
35
+ readonly family?: string;
36
+ readonly details?: Value;
37
+ }
38
+ /** A terminal install: its committed result, its rejection, or its cancellation. */
39
+ export type InstallOutcome = {
40
+ readonly kind: 'completed';
41
+ readonly value: protocolSchema.installation.InstallResult;
42
+ } | {
43
+ readonly kind: 'failed';
44
+ readonly error: InstallFailure;
45
+ } | {
46
+ readonly kind: 'cancelled';
47
+ };
48
+ /**
49
+ * The status of one install, uninstall or repair session: the engine `state` the CLI decides on,
50
+ * and the Core `detail` (phase, class, progress, the next command index, the running attempt and
51
+ * the last attempt report).
52
+ */
53
+ export type InstallStatus<Outcome = InstallOutcome> = InstallNodeStatus<Outcome> | DeletedInstallStatus<Outcome>;
54
+ /** The status of an install, uninstall or session whose Execution node exists. */
55
+ export interface InstallNodeStatus<Outcome = InstallOutcome> {
56
+ readonly id: InstallExecutionId;
57
+ readonly function: NodeId;
58
+ readonly version: `sha256:${string}`;
59
+ readonly state: ExecutionState;
60
+ readonly createdAt: string;
61
+ readonly detail?: InstallDetail;
62
+ /** Present exactly once the Execution is terminal. */
63
+ readonly outcome?: Outcome;
64
+ }
65
+ /**
66
+ * What Root alone reads once the Execution node of an install, uninstall or session was deleted:
67
+ * the outcome its lifecycle record keeps, under the explicit state `deleted`.
68
+ */
69
+ export interface DeletedInstallStatus<Outcome = InstallOutcome> {
70
+ readonly id: InstallExecutionId;
71
+ readonly state: 'deleted';
72
+ readonly outcome: Outcome;
73
+ /** Absent: the node that recorded them is deleted. */
74
+ readonly function?: never;
75
+ readonly version?: never;
76
+ readonly createdAt?: never;
77
+ readonly detail?: never;
78
+ }
79
+ /** One admitted install answer: its Execution, its status, and its result once completed. */
80
+ export interface Installation {
81
+ readonly execution: InstallExecutionId;
82
+ readonly status: InstallStatus;
83
+ /** The committed result, present exactly when the status is completed. */
84
+ readonly result?: protocolSchema.installation.InstallResult;
85
+ }
9
86
  /** Canonical caller input accepted by the Kernel uninstall syscall. */
10
87
  export type UninstallRequest = UninstallInput;
11
88
  /** Admitted terminal uninstall receipt returned by the Kernel. */
12
89
  export type UninstallReceipt = UninstallOutput;
90
+ /** A terminal uninstall: its committed receipt, its rejection, or its cancellation. */
91
+ export type UninstallOutcome = {
92
+ readonly kind: 'completed';
93
+ readonly value: UninstallReceipt;
94
+ } | {
95
+ readonly kind: 'failed';
96
+ readonly error: InstallFailure;
97
+ } | {
98
+ readonly kind: 'cancelled';
99
+ };
100
+ /** One admitted uninstall answer: its Execution, its status, and its receipt once completed. */
101
+ export interface Uninstallation {
102
+ readonly execution: InstallExecutionId;
103
+ readonly status: InstallStatus<UninstallOutcome>;
104
+ readonly result?: UninstallReceipt;
105
+ }
@@ -1,3 +1,4 @@
1
1
  export { createSchema, DEFAULT_SCHEMA_LIFECYCLE_TIMEOUT_MS, type SchemaApi, type SchemaCall, type SchemaOptions, type DomainBundle, type DomainDependencies, type DomainInfo, type InstalledPin, type InstalledRelease, type InstallResult, } from './schema.js';
2
2
  export { acceptOperationId, createOperationId } from './operation.js';
3
- export type { DomainRequest, InstallReceipt, InstallRequest, OperationId, UninstallReceipt, UninstallRequest, } from './contracts.js';
3
+ export type { InstallationApi, UninstallationApi } from './installation.js';
4
+ export type { DomainRequest, InstallAttemptReport, InstallClass, InstallDetail, InstallExecutionId, InstallFailure, InstallMode, InstallOutcome, InstallStatus, InstallNodeStatus, DeletedInstallStatus, InstallValidationOptions, Installation, InstallReceipt, InstallRequest, OperationId, Uninstallation, UninstallOutcome, UninstallReceipt, UninstallRequest, } from './contracts.js';
@@ -0,0 +1,104 @@
1
+ import type { PathLike } from '@astrale-os/kernel-core/path';
2
+ import type { InstallValidation } from '@astrale-os/kernel-core/schema/kernel/syscalls/contracts';
3
+ import type { RequestOptions } from '../transport/index.js';
4
+ import type { InstallExecutionId, InstallFailure, InstallOutcome, InstallStatus, UninstallOutcome, UninstallReceipt } from './contracts.js';
5
+ import type { SchemaCall } from './schema.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: InstallExecutionId, options?: RequestOptions): Promise<InstallStatus>;
14
+ /** The terminal outcome, waiting at most `waitMs`; `EXECUTION_PENDING` once it lapses. */
15
+ result(execution: InstallExecutionId, wait?: {
16
+ readonly waitMs?: number;
17
+ }, options?: RequestOptions): Promise<InstallOutcome>;
18
+ /**
19
+ * A waiting repair session attempts its target: the `command:<index>` signal, `index` being
20
+ * the `detail.command` its status announces. A signal already resolved is refused.
21
+ */
22
+ apply(execution: InstallExecutionId, command: {
23
+ readonly index: number;
24
+ readonly validation?: InstallValidation;
25
+ }, options?: RequestOptions): Promise<void>;
26
+ /**
27
+ * Stop the attempt a repair session runs, `detail.attempt.number`, through its `abort:<attempt>`
28
+ * signal; the session waits again.
29
+ */
30
+ abort(execution: InstallExecutionId, attempt: number, options?: RequestOptions): Promise<void>;
31
+ /**
32
+ * 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 first
34
+ * takes the break-glass exit (the Instance reopens on its source, marked `uncertified`).
35
+ */
36
+ cancel(execution: InstallExecutionId, input?: {
37
+ readonly force?: boolean;
38
+ }, options?: RequestOptions): Promise<InstallStatus>;
39
+ /** Resume a paused install or session; a running one is unchanged. */
40
+ resume(execution: InstallExecutionId, options?: RequestOptions): Promise<InstallStatus>;
41
+ /** Delete the Execution, then kill and purge its run; a live session exits by break-glass. */
42
+ delete(execution: InstallExecutionId, options?: RequestOptions): Promise<void>;
43
+ }
44
+ /**
45
+ * The uninstall executions of one Instance, through the same `K.Execution` Methods: a completed
46
+ * outcome carries the uninstall receipt. An uninstall has no repair session, so no signal.
47
+ */
48
+ export interface UninstallationApi {
49
+ /** The status of one uninstall. */
50
+ status(execution: InstallExecutionId, options?: RequestOptions): Promise<InstallStatus<UninstallOutcome>>;
51
+ /** The terminal outcome, waiting at most `waitMs`; `EXECUTION_PENDING` once it lapses. */
52
+ result(execution: InstallExecutionId, wait?: {
53
+ readonly waitMs?: number;
54
+ }, options?: RequestOptions): Promise<UninstallOutcome>;
55
+ /** A cooperative cancel ends it before its point of no return; `force` kills the run. */
56
+ cancel(execution: InstallExecutionId, input?: {
57
+ readonly force?: boolean;
58
+ }, options?: RequestOptions): Promise<InstallStatus<UninstallOutcome>>;
59
+ /** Resume a paused uninstall; a running one is unchanged. */
60
+ resume(execution: InstallExecutionId, options?: RequestOptions): Promise<InstallStatus<UninstallOutcome>>;
61
+ /** Delete the Execution, then kill and purge its run. */
62
+ delete(execution: InstallExecutionId, options?: RequestOptions): Promise<void>;
63
+ }
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
+ /** The install Methods: a completed outcome carries the result its Protocol owner admits. */
101
+ export declare function createInstallation(executions: ExecutionMethods): InstallationApi;
102
+ /** The uninstall Methods: a completed outcome carries the receipt Core's contract admits. */
103
+ export declare function createUninstallation(executions: ExecutionMethods): UninstallationApi;
104
+ export declare function acceptUninstallReceipt(input: unknown): UninstallReceipt;