@astrale-os/kernel-client 1.0.0-beta.5 → 1.0.0-beta.7
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/index.d.ts +1 -1
- package/dist/client/result.d.ts +4 -1
- package/dist/client/result.js +10 -4
- package/dist/schema/installation.d.ts +6 -3
- package/dist/schema/installation.js +4 -6
- package/dist/session/reference.d.ts +8 -4
- package/dist/session/reference.js +7 -2
- package/dist/session/routing/result.d.ts +1 -1
- package/dist/session/routing/result.js +5 -1
- package/dist/session/session.js +10 -7
- package/dist/transport/http/admission.js +3 -0
- package/dist/transport/websocket/exchange.js +8 -0
- package/package.json +4 -4
package/dist/client/index.d.ts
CHANGED
|
@@ -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';
|
package/dist/client/result.d.ts
CHANGED
|
@@ -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>;
|
package/dist/client/result.js
CHANGED
|
@@ -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
|
|
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,
|
|
21
|
-
throw new ClientError(
|
|
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
|
|
36
|
+
mismatch(expected, result);
|
|
31
37
|
}
|
|
@@ -30,15 +30,18 @@ export interface InstallationApi {
|
|
|
30
30
|
abort(execution: InstallExecutionId, attempt: number, options?: RequestOptions): Promise<void>;
|
|
31
31
|
/**
|
|
32
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
|
|
34
|
-
*
|
|
33
|
+
* has a repair session attempt its source schema. `force` kills the run; a live session refuses
|
|
34
|
+
* it `EXECUTION_EXIT_REFUSED`: cancel it cooperatively or apply it.
|
|
35
35
|
*/
|
|
36
36
|
cancel(execution: InstallExecutionId, input?: {
|
|
37
37
|
readonly force?: boolean;
|
|
38
38
|
}, options?: RequestOptions): Promise<InstallStatus>;
|
|
39
39
|
/** Resume a paused install or session; a running one is unchanged. */
|
|
40
40
|
resume(execution: InstallExecutionId, options?: RequestOptions): Promise<InstallStatus>;
|
|
41
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* Delete the Execution, then kill and purge its run; a live session refuses it
|
|
43
|
+
* `EXECUTION_EXIT_REFUSED`: cancel or apply it first.
|
|
44
|
+
*/
|
|
42
45
|
delete(execution: InstallExecutionId, options?: RequestOptions): Promise<void>;
|
|
43
46
|
}
|
|
44
47
|
/**
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { NodeId } from '@astrale-os/kernel-core/graph/node';
|
|
2
1
|
import { Path } from '@astrale-os/kernel-core/path';
|
|
3
|
-
import { abortSignal, commandSignal, executionOutcome,
|
|
2
|
+
import { abortSignal, commandSignal, executionOutcome, executionStatus, uninstallOutput, } from '@astrale-os/kernel-core/schema/kernel/syscalls/contracts';
|
|
4
3
|
import { execution as methods } from '@astrale-os/kernel-core/schema/kernel/syscalls/references';
|
|
5
4
|
import { MethodKey } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
6
5
|
import * as protocolSchema from '@astrale-os/kernel-protocol/schema';
|
|
@@ -65,10 +64,9 @@ export function executionMethods(call, options) {
|
|
|
65
64
|
/** Admit what a durable call answers at once: the Execution it created or recovered. */
|
|
66
65
|
async start(path, input, request) {
|
|
67
66
|
const result = await call(invocation(path, input), options(request));
|
|
68
|
-
if (result.kind !== '
|
|
69
|
-
throw new TypeError('Schema syscall
|
|
70
|
-
|
|
71
|
-
return NodeId(ref.id);
|
|
67
|
+
if (result.kind !== 'execution')
|
|
68
|
+
throw new TypeError('Schema syscall did not answer with an Execution.');
|
|
69
|
+
return result.execution;
|
|
72
70
|
},
|
|
73
71
|
/**
|
|
74
72
|
* Wait within the request deadline for the outcome. A wait that lapsed after waiting, while
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { Path as PathValue, PathLike } from '@astrale-os/kernel-core/path';
|
|
2
|
-
import type { CallableInputOf, CallableInputModeOf, CallableOutputOf, CallableResultOf, Domain, ResolvedFunction, ExecutableMethod } from '@astrale-os/kernel-dsl/v1';
|
|
2
|
+
import type { CallableInputOf, CallableInputModeOf, CallableOutputOf, CallableResultOf, Domain, ResolvedFunction, ExecutableMethod, ResolvedMethod } from '@astrale-os/kernel-dsl/v1';
|
|
3
3
|
import type { MethodAddress } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
4
4
|
import type { MeaningFingerprint } from '@astrale-os/kernel-dsl/v1/schema/fingerprint';
|
|
5
5
|
import { type Key as KeyType } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
6
|
-
import type { Binary, Input } from '../client/index.js';
|
|
6
|
+
import type { Binary, Input, Result } from '../client/index.js';
|
|
7
7
|
import type { ExecutionRef } from './execution.js';
|
|
8
|
+
/** Result kind a reference expects: a durable callable answers with its Execution. */
|
|
9
|
+
type OutputMode = Exclude<Result['kind'], 'redirect'>;
|
|
8
10
|
declare const REFERENCE_INPUT: unique symbol;
|
|
9
11
|
declare const REFERENCE_INPUT_MODE: unique symbol;
|
|
10
12
|
declare const REFERENCE_OUTPUT: unique symbol;
|
|
@@ -14,7 +16,7 @@ export interface CallableReference<InputValue = Input, Output = unknown, InputMo
|
|
|
14
16
|
readonly fingerprint?: MeaningFingerprint;
|
|
15
17
|
readonly callable: KeyType.Callable;
|
|
16
18
|
readonly target: PathValue;
|
|
17
|
-
readonly outputMode:
|
|
19
|
+
readonly outputMode: OutputMode;
|
|
18
20
|
readonly [REFERENCE_INPUT]?: InputValue;
|
|
19
21
|
readonly [REFERENCE_INPUT_MODE]?: InputMode;
|
|
20
22
|
readonly [REFERENCE_OUTPUT]?: Output;
|
|
@@ -24,7 +26,7 @@ export interface InstanceCallableReference<InputValue = Input, Output = unknown>
|
|
|
24
26
|
readonly origin: KeyType.Origin;
|
|
25
27
|
readonly fingerprint?: MeaningFingerprint;
|
|
26
28
|
readonly callable: KeyType.Callable;
|
|
27
|
-
readonly outputMode:
|
|
29
|
+
readonly outputMode: OutputMode;
|
|
28
30
|
}
|
|
29
31
|
export type InputOfReference<Reference extends CallableReference<unknown>> = Reference extends CallableReference<infer InputValue, unknown> ? InputValue : never;
|
|
30
32
|
export type OutputOfReference<Reference extends CallableReference<unknown>> = Reference extends CallableReference<infer _Input, infer Output> ? Output : never;
|
|
@@ -47,6 +49,8 @@ export declare function reference<const Callable extends ExecutableInstanceMetho
|
|
|
47
49
|
* addresses every Kernel syscall. Loading the Session therefore never resolves the Kernel Schema.
|
|
48
50
|
*/
|
|
49
51
|
export declare function kernelReference(method: MethodAddress): InstanceCallableReference<unknown>;
|
|
52
|
+
/** The result kind invoking this callable yields. */
|
|
53
|
+
export declare function outputModeOf(callable: ResolvedFunction | ResolvedMethod): OutputMode;
|
|
50
54
|
export declare function admitReference(input: CallableReference<unknown>): CallableReference<unknown>;
|
|
51
55
|
export declare function matchesCallable(target: PathValue, callable: KeyType.Callable): boolean;
|
|
52
56
|
export {};
|
|
@@ -2,6 +2,7 @@ import { Path } from '@astrale-os/kernel-core/path';
|
|
|
2
2
|
import { callableAddress, Key, MethodKey, patterns, } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
3
3
|
import { callableFingerprint } from '@astrale-os/kernel-dsl/v1/schema/fingerprint';
|
|
4
4
|
const FINGERPRINT_PATTERN = /^sha256:[0-9a-f]{64}$/u;
|
|
5
|
+
const OUTPUT_MODES = ['value', 'stream', 'binary', 'execution'];
|
|
5
6
|
export function reference(domain, callable) {
|
|
6
7
|
if (Key.origin(callable.key) !== domain.origin)
|
|
7
8
|
invalid();
|
|
@@ -11,7 +12,7 @@ export function reference(domain, callable) {
|
|
|
11
12
|
origin: domain.origin,
|
|
12
13
|
fingerprint: callableFingerprint(callable),
|
|
13
14
|
callable: callable.key,
|
|
14
|
-
outputMode: callable
|
|
15
|
+
outputMode: outputModeOf(callable),
|
|
15
16
|
});
|
|
16
17
|
if ('owner' in callable && !callable.static) {
|
|
17
18
|
const bind = (receiver) => admitReference({
|
|
@@ -39,6 +40,10 @@ export function kernelReference(method) {
|
|
|
39
40
|
const bind = (receiver) => admitReference({ ...common, target: Path.instanceMethod(Path.from(receiver), callable) });
|
|
40
41
|
return Object.assign(bind, common);
|
|
41
42
|
}
|
|
43
|
+
/** The result kind invoking this callable yields. */
|
|
44
|
+
export function outputModeOf(callable) {
|
|
45
|
+
return callable.execution?.durable === true ? 'execution' : callable.output.mode;
|
|
46
|
+
}
|
|
42
47
|
export function admitReference(input) {
|
|
43
48
|
if (input === null || typeof input !== 'object')
|
|
44
49
|
invalid();
|
|
@@ -47,7 +52,7 @@ export function admitReference(input) {
|
|
|
47
52
|
typeof input.callable !== 'string' ||
|
|
48
53
|
!Key.is(input.callable) ||
|
|
49
54
|
Key.origin(input.callable) !== input.origin ||
|
|
50
|
-
!
|
|
55
|
+
!OUTPUT_MODES.includes(input.outputMode) ||
|
|
51
56
|
(input.fingerprint !== undefined &&
|
|
52
57
|
(typeof input.fingerprint !== 'string' || !FINGERPRINT_PATTERN.test(input.fingerprint))))
|
|
53
58
|
invalid();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Result } from '../../client/index.js';
|
|
2
2
|
/** Narrow a Result to the kind a sugar requires, releasing a live body before rejecting it. */
|
|
3
|
-
export declare function requireResultKind<Kind extends '
|
|
3
|
+
export declare function requireResultKind<Kind extends Exclude<Result['kind'], 'redirect'>>(expected: Kind, result: Result): Extract<Result, {
|
|
4
4
|
kind: Kind;
|
|
5
5
|
}>;
|
|
@@ -8,5 +8,9 @@ export function requireResultKind(expected, result) {
|
|
|
8
8
|
if (result.kind === 'binary' && !(result.value.body instanceof Uint8Array)) {
|
|
9
9
|
void result.value.body[Symbol.asyncIterator]().return?.();
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
// A started Execution is named so its caller never starts it again.
|
|
12
|
+
const returned = result.kind === 'execution'
|
|
13
|
+
? `Function started Execution ${result.execution}`
|
|
14
|
+
: `Function returned ${result.kind}`;
|
|
15
|
+
throw new ClientError(`${returned}; ${expected} was required.`);
|
|
12
16
|
}
|
package/dist/session/session.js
CHANGED
|
@@ -12,7 +12,7 @@ import { admitControlOptions, allowEndpoint, createSessionOperation } from './co
|
|
|
12
12
|
import { createSessionDiscovery } from './discovery/index.js';
|
|
13
13
|
import { acquireDomainCredential, admitExchangeRequest, createSessionExchange, } from './exchange/index.js';
|
|
14
14
|
import { acceptSessionOptions } from './options.js';
|
|
15
|
-
import { admitReference } from './reference.js';
|
|
15
|
+
import { admitReference, outputModeOf } from './reference.js';
|
|
16
16
|
import { admitInvocationOptions, requireResultKind, SessionDispatcher } from './routing/index.js';
|
|
17
17
|
import { domainViewCatalog, resolveViewsFor } from './views/index.js';
|
|
18
18
|
const DEFAULT_SESSION_POLICY = Object.freeze({ maximumRouteAgeMs: 60_000 });
|
|
@@ -162,11 +162,14 @@ export class ClientSession {
|
|
|
162
162
|
? this.dispatcher.dispatch(call, admitted.options, operation)
|
|
163
163
|
: this.dispatcher.dispatchHttp(call, admitted.options, operation, admitted.body));
|
|
164
164
|
const narrowed = requireResultKind(admittedReference.outputMode, result);
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
: narrowed.
|
|
165
|
+
switch (narrowed.kind) {
|
|
166
|
+
case 'stream':
|
|
167
|
+
return narrowed.stream;
|
|
168
|
+
case 'execution':
|
|
169
|
+
return Object.freeze({ id: narrowed.execution });
|
|
170
|
+
default:
|
|
171
|
+
return narrowed.value;
|
|
172
|
+
}
|
|
170
173
|
}
|
|
171
174
|
dispatchWith(call, options, requireHttp = false) {
|
|
172
175
|
const admitted = admitInvocationOptions(options);
|
|
@@ -209,7 +212,7 @@ export class ClientSession {
|
|
|
209
212
|
fingerprint: callableFingerprint(method),
|
|
210
213
|
callable: method.key,
|
|
211
214
|
target: Path.instanceMethod(Path.id(node.id), method.key),
|
|
212
|
-
outputMode: method
|
|
215
|
+
outputMode: outputModeOf(method),
|
|
213
216
|
}, input);
|
|
214
217
|
}
|
|
215
218
|
operation(options) {
|
|
@@ -90,6 +90,9 @@ export async function admitResponse(response, requestId, context) {
|
|
|
90
90
|
throw new ResponseError(envelope.error.code, envelope.error.message, envelope.invocation, envelope.error.data);
|
|
91
91
|
}
|
|
92
92
|
requireLive(control);
|
|
93
|
+
if ('execution' in envelope) {
|
|
94
|
+
return { kind: 'execution', execution: envelope.execution, invocation: envelope.invocation };
|
|
95
|
+
}
|
|
93
96
|
return { kind: 'value', value: envelope.result, invocation: envelope.invocation };
|
|
94
97
|
}
|
|
95
98
|
function redirectResult(response) {
|
|
@@ -153,6 +153,14 @@ export class WebSocketExchange {
|
|
|
153
153
|
this.reject(new ResponseError(response.error.code, response.error.message, response.invocation, response.error.data));
|
|
154
154
|
return;
|
|
155
155
|
}
|
|
156
|
+
if ('execution' in response) {
|
|
157
|
+
this.complete({
|
|
158
|
+
kind: 'execution',
|
|
159
|
+
execution: response.execution,
|
|
160
|
+
invocation: response.invocation,
|
|
161
|
+
});
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
156
164
|
this.complete({ kind: 'value', value: response.result, invocation: response.invocation });
|
|
157
165
|
}
|
|
158
166
|
receiveStreamFrame(frame) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrale-os/kernel-client",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.7",
|
|
4
4
|
"description": "Universal Client — protocol-first, transport-agnostic",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astrale",
|
|
@@ -65,13 +65,13 @@
|
|
|
65
65
|
"access": "public"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@astrale-os/kernel-core": "1.0.0-beta.
|
|
68
|
+
"@astrale-os/kernel-core": "1.0.0-beta.7",
|
|
69
69
|
"@astrale-os/kernel-dsl": "1.0.0-beta.3",
|
|
70
|
-
"@astrale-os/kernel-protocol": "1.0.0-beta.
|
|
70
|
+
"@astrale-os/kernel-protocol": "1.0.0-beta.7",
|
|
71
71
|
"@tanstack/pacer": "0.20.1"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@astrale-os/kernel-server": "1.0.0-beta.
|
|
74
|
+
"@astrale-os/kernel-server": "1.0.0-beta.7",
|
|
75
75
|
"@astrale/typescript-config": "npm:@jsr/astrale__typescript-config@~1.1.0",
|
|
76
76
|
"@types/node": "^22.0.0",
|
|
77
77
|
"typescript": "7.0.2",
|