@astrale-os/kernel-client 1.0.0-beta.3 → 1.0.0-beta.30
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 +19 -0
- package/dist/errors/refusal.js +63 -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 +64 -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 +145 -7
- package/dist/graph/query.typecheck.d.ts +77 -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 +10 -2
- package/dist/session/content/api.js +13 -4
- package/dist/session/content/index.d.ts +1 -1
- package/dist/session/content/input.d.ts +6 -1
- package/dist/session/content/input.js +12 -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 +4 -3
- 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 +9 -5
- package/dist/session/reference.js +7 -2
- 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 +60 -19
- 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 +7 -5
- 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
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import * as errors from '@astrale-os/kernel-protocol/errors';
|
|
2
2
|
import { ProtocolError, ResponseError } from '../../errors/index.js';
|
|
3
|
-
import { invocationFailure } from '../failure.js';
|
|
3
|
+
import { abortFailure, invocationFailure, withInvocation } from '../failure.js';
|
|
4
4
|
import { asError } from '../index.js';
|
|
5
|
+
import { FrameStream } from '../stream.js';
|
|
6
|
+
import { responseError, unaryResult } from '../unary.js';
|
|
5
7
|
/** One correlated invocation within a multiplexed WebSocket connection. */
|
|
6
8
|
export class WebSocketExchange {
|
|
7
9
|
owner;
|
|
@@ -12,14 +14,7 @@ export class WebSocketExchange {
|
|
|
12
14
|
resolveResult;
|
|
13
15
|
rejectResult;
|
|
14
16
|
abort;
|
|
15
|
-
|
|
16
|
-
claimed = false;
|
|
17
|
-
index = 0;
|
|
18
|
-
values = [];
|
|
19
|
-
waiters = [];
|
|
20
|
-
terminal;
|
|
21
|
-
sent = false;
|
|
22
|
-
invocation;
|
|
17
|
+
phase = { kind: 'unsent' };
|
|
23
18
|
constructor(owner, requestId, control, maximumBufferedItems) {
|
|
24
19
|
this.owner = owner;
|
|
25
20
|
this.requestId = requestId;
|
|
@@ -29,12 +24,15 @@ export class WebSocketExchange {
|
|
|
29
24
|
this.resolveResult = resolve;
|
|
30
25
|
this.rejectResult = reject;
|
|
31
26
|
});
|
|
32
|
-
this.abort = () => this.
|
|
27
|
+
this.abort = () => this.fail(abortFailure(control, 'WebSocket invocation exceeded its timeout.', 'WebSocket invocation was cancelled.', {
|
|
28
|
+
delivery: this.phase.kind === 'unsent' ? 'not-sent' : 'unknown',
|
|
29
|
+
invocation: this.invocation,
|
|
30
|
+
}), { kind: 'cancel' });
|
|
33
31
|
if (!control.signal.aborted)
|
|
34
32
|
control.signal.addEventListener('abort', this.abort, { once: true });
|
|
35
33
|
}
|
|
36
34
|
start(send, encoded) {
|
|
37
|
-
if (this.
|
|
35
|
+
if (this.phase.kind === 'finished')
|
|
38
36
|
return this.result;
|
|
39
37
|
if (this.control.signal.aborted) {
|
|
40
38
|
this.abort();
|
|
@@ -42,63 +40,44 @@ export class WebSocketExchange {
|
|
|
42
40
|
}
|
|
43
41
|
try {
|
|
44
42
|
send(encoded);
|
|
45
|
-
|
|
43
|
+
// A socket may fail the exchange while it sends.
|
|
44
|
+
if (this.phase.kind === 'unsent')
|
|
45
|
+
this.phase = { kind: 'sent' };
|
|
46
46
|
}
|
|
47
47
|
catch (error) {
|
|
48
48
|
this.fail(invocationFailure('Failed to send the WebSocket invocation.', 'send', {
|
|
49
49
|
cause: asError(error),
|
|
50
|
-
}), 1011);
|
|
50
|
+
}), { kind: 'close', code: 1011 });
|
|
51
51
|
}
|
|
52
52
|
return this.result;
|
|
53
53
|
}
|
|
54
54
|
receive(input) {
|
|
55
55
|
try {
|
|
56
|
-
|
|
56
|
+
const phase = this.phase;
|
|
57
|
+
if (phase.kind === 'unsent' || phase.kind === 'sent') {
|
|
57
58
|
this.receiveResponse(input);
|
|
58
59
|
return;
|
|
59
60
|
}
|
|
60
|
-
if (
|
|
61
|
+
if (phase.kind !== 'stream' || !isStreamFrame(input)) {
|
|
61
62
|
throw new ProtocolError('server sent an unexpected WebSocket response.');
|
|
62
63
|
}
|
|
63
|
-
this.receiveStreamFrame(input);
|
|
64
|
+
this.receiveStreamFrame(phase.stream, input);
|
|
64
65
|
}
|
|
65
66
|
catch (error) {
|
|
66
|
-
|
|
67
|
-
this.fail(failure, failure instanceof WebSocketPolicyError ? 1008 : 1002);
|
|
67
|
+
this.fail(protocolFailure(error, this.invocation), { kind: 'close', code: 1002 });
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
connectionFailed(error) {
|
|
71
|
-
this.fail(this.
|
|
72
|
-
?
|
|
71
|
+
this.fail(this.phase.kind === 'unsent'
|
|
72
|
+
? error
|
|
73
|
+
: invocationFailure(error.message, 'receive', {
|
|
73
74
|
cause: error,
|
|
74
75
|
delivery: 'unknown',
|
|
75
76
|
...(this.invocation === undefined ? {} : { invocation: this.invocation }),
|
|
76
|
-
})
|
|
77
|
-
: error);
|
|
77
|
+
}), { kind: 'close', code: 1002 });
|
|
78
78
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
throw new TypeError('streams admit exactly one consumer.');
|
|
82
|
-
this.claimed = true;
|
|
83
|
-
return {
|
|
84
|
-
next: () => this.next(),
|
|
85
|
-
return: async () => {
|
|
86
|
-
await this.cancel('stream consumer stopped');
|
|
87
|
-
return { done: true, value: undefined };
|
|
88
|
-
},
|
|
89
|
-
throw: async (error) => {
|
|
90
|
-
await this.cancel('stream consumer failed');
|
|
91
|
-
throw error;
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
async cancel(_reason = 'stream cancelled') {
|
|
96
|
-
if (this.state === 'finished')
|
|
97
|
-
return;
|
|
98
|
-
this.values.length = 0;
|
|
99
|
-
this.terminal = true;
|
|
100
|
-
this.finishCancelled();
|
|
101
|
-
this.flushTerminal();
|
|
79
|
+
get invocation() {
|
|
80
|
+
return this.phase.kind === 'stream' ? this.phase.stream.invocation : undefined;
|
|
102
81
|
}
|
|
103
82
|
receiveResponse(input) {
|
|
104
83
|
if (isKind(input, 'binary')) {
|
|
@@ -115,184 +94,107 @@ export class WebSocketExchange {
|
|
|
115
94
|
});
|
|
116
95
|
return;
|
|
117
96
|
}
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (start.kind !== 'stream.start')
|
|
97
|
+
if (isStreamFrame(input)) {
|
|
98
|
+
requireId(this.requestId, input.requestId);
|
|
99
|
+
if (input.kind !== 'stream.start') {
|
|
122
100
|
throw new ProtocolError('stream did not begin with stream.start.');
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
this.
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
if (isKind(input, 'redirect')) {
|
|
129
|
-
const response = input;
|
|
130
|
-
requireId(this.requestId, response.requestId);
|
|
131
|
-
this.complete({
|
|
132
|
-
kind: 'redirect',
|
|
133
|
-
invocation: response.invocation,
|
|
134
|
-
redirect: response.redirect,
|
|
135
|
-
});
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
if (isKind(input, 'stale')) {
|
|
139
|
-
const stale = input;
|
|
140
|
-
requireId(this.requestId, stale.requestId);
|
|
141
|
-
this.complete(Object.freeze({ kind: 'stale', current: stale.current, invocation: stale.invocation }));
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
if (isKind(input, 'miss')) {
|
|
145
|
-
const miss = input;
|
|
146
|
-
requireId(this.requestId, miss.requestId);
|
|
147
|
-
this.complete(Object.freeze({ kind: 'miss', invocation: miss.invocation }));
|
|
101
|
+
}
|
|
102
|
+
const stream = new FrameStream(input.invocation, { cancel: async () => this.cancel() }, this.maximumBufferedItems);
|
|
103
|
+
this.phase = { kind: 'stream', stream };
|
|
104
|
+
this.resolveResult({ kind: 'stream', stream, invocation: input.invocation });
|
|
148
105
|
return;
|
|
149
106
|
}
|
|
150
107
|
const response = input;
|
|
151
108
|
requireId(this.requestId, response.requestId);
|
|
152
|
-
if ('error' in response)
|
|
153
|
-
this.reject(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
this.complete({ kind: 'value', value: response.result, invocation: response.invocation });
|
|
109
|
+
if ('error' in response)
|
|
110
|
+
this.reject(responseError(response.error, response.invocation));
|
|
111
|
+
else
|
|
112
|
+
this.complete(unaryResult(response));
|
|
157
113
|
}
|
|
158
|
-
receiveStreamFrame(frame) {
|
|
114
|
+
receiveStreamFrame(stream, frame) {
|
|
159
115
|
requireId(this.requestId, frame.requestId);
|
|
160
116
|
if (frame.kind === 'stream.start') {
|
|
161
117
|
throw new ProtocolError('server sent a duplicate stream.start frame.');
|
|
162
118
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const waiter = this.waiters.shift();
|
|
169
|
-
if (waiter !== undefined)
|
|
170
|
-
waiter.resolve({ done: false, value: frame.value });
|
|
171
|
-
else {
|
|
172
|
-
if (this.values.length >= this.maximumBufferedItems) {
|
|
173
|
-
throw new WebSocketPolicyError(`stream exceeds maximumBufferedStreamItems (${this.maximumBufferedItems}).`);
|
|
174
|
-
}
|
|
175
|
-
this.values.push(frame.value);
|
|
119
|
+
const step = stream.accept(frame);
|
|
120
|
+
if (step.kind === 'item') {
|
|
121
|
+
if (!stream.push(step.value)) {
|
|
122
|
+
const overflow = new ProtocolError(`stream exceeds maximumBufferedStreamItems (${this.maximumBufferedItems}).`);
|
|
123
|
+
this.fail(protocolFailure(overflow, this.invocation), { kind: 'close', code: 1008 });
|
|
176
124
|
}
|
|
177
125
|
return;
|
|
178
126
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
? new ResponseError(frame.error.code, frame.error.message, this.invocation, frame.error.data)
|
|
185
|
-
: true;
|
|
186
|
-
this.finish(true);
|
|
187
|
-
this.flushTerminal();
|
|
127
|
+
this.finish({ kind: 'reuse' });
|
|
128
|
+
if (step.kind === 'error')
|
|
129
|
+
stream.fail(step.error);
|
|
130
|
+
else
|
|
131
|
+
stream.end();
|
|
188
132
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return new Promise((resolve, reject) => this.waiters.push({ resolve, reject }));
|
|
133
|
+
/** The consumer's cancellation: drops what it has not read and tells the server. */
|
|
134
|
+
cancel() {
|
|
135
|
+
const phase = this.phase;
|
|
136
|
+
if (phase.kind !== 'stream')
|
|
137
|
+
return;
|
|
138
|
+
phase.stream.discard();
|
|
139
|
+
this.finish({ kind: 'cancel' });
|
|
140
|
+
phase.stream.end();
|
|
198
141
|
}
|
|
199
142
|
complete(result) {
|
|
200
|
-
this.finish(
|
|
143
|
+
this.finish({ kind: 'reuse' });
|
|
201
144
|
this.resolveResult(result);
|
|
202
145
|
}
|
|
203
146
|
reject(error) {
|
|
204
|
-
this.finish(
|
|
147
|
+
this.finish({ kind: 'reuse' });
|
|
205
148
|
this.rejectResult(error);
|
|
206
149
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
if (
|
|
211
|
-
this.rejectResult(error);
|
|
212
|
-
else {
|
|
213
|
-
this.terminal = error;
|
|
214
|
-
this.flushTerminal();
|
|
215
|
-
}
|
|
216
|
-
this.finish(false, closeCode);
|
|
217
|
-
}
|
|
218
|
-
cancelLocally(error) {
|
|
219
|
-
if (this.state === 'finished')
|
|
150
|
+
/** Fails the pending result or the stream; a cancelled exchange drops what was not read. */
|
|
151
|
+
fail(error, release) {
|
|
152
|
+
const phase = this.phase;
|
|
153
|
+
if (phase.kind === 'finished')
|
|
220
154
|
return;
|
|
221
|
-
if (
|
|
155
|
+
if (phase.kind !== 'stream')
|
|
222
156
|
this.rejectResult(error);
|
|
223
157
|
else {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
158
|
+
if (release.kind === 'cancel')
|
|
159
|
+
phase.stream.discard();
|
|
160
|
+
phase.stream.fail(error);
|
|
227
161
|
}
|
|
228
|
-
this.
|
|
162
|
+
this.finish(release);
|
|
229
163
|
}
|
|
230
|
-
finish(
|
|
231
|
-
if (this.
|
|
164
|
+
finish(release) {
|
|
165
|
+
if (this.phase.kind === 'finished')
|
|
232
166
|
return;
|
|
233
|
-
this.
|
|
167
|
+
this.phase = { kind: 'finished' };
|
|
234
168
|
this.control.signal.removeEventListener('abort', this.abort);
|
|
235
169
|
this.control.close();
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
this.control.signal.removeEventListener('abort', this.abort);
|
|
243
|
-
this.control.close();
|
|
244
|
-
this.owner.cancel(this, this.requestId);
|
|
245
|
-
}
|
|
246
|
-
flushTerminal() {
|
|
247
|
-
if (this.terminal === undefined)
|
|
248
|
-
return;
|
|
249
|
-
for (const waiter of this.waiters.splice(0)) {
|
|
250
|
-
if (this.terminal === true)
|
|
251
|
-
waiter.resolve({ done: true, value: undefined });
|
|
252
|
-
else
|
|
253
|
-
waiter.reject(this.terminal);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
abortFailure() {
|
|
257
|
-
if (this.control.timedOut) {
|
|
258
|
-
return invocationFailure('WebSocket invocation exceeded its timeout.', 'timeout', {
|
|
259
|
-
cause: asError(this.control.signal.reason),
|
|
260
|
-
delivery: this.sent ? 'unknown' : 'not-sent',
|
|
261
|
-
...(this.invocation === undefined ? {} : { invocation: this.invocation }),
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
return asError(this.control.signal.reason ?? new Error('WebSocket invocation was cancelled.'));
|
|
170
|
+
if (release.kind === 'cancel')
|
|
171
|
+
this.owner.cancel(this, this.requestId);
|
|
172
|
+
else if (release.kind === 'close')
|
|
173
|
+
this.owner.finish(this, release.code);
|
|
174
|
+
else
|
|
175
|
+
this.owner.finish(this);
|
|
265
176
|
}
|
|
266
177
|
}
|
|
267
|
-
|
|
268
|
-
}
|
|
178
|
+
/** The error of a frame the exchange cannot accept, naming the invocation it belongs to. */
|
|
269
179
|
function protocolFailure(input, invocation) {
|
|
270
|
-
if (input instanceof ResponseError)
|
|
271
|
-
return input;
|
|
272
|
-
if (input instanceof WebSocketPolicyError) {
|
|
273
|
-
return input.invocation !== undefined || invocation === undefined
|
|
274
|
-
? input
|
|
275
|
-
: new WebSocketPolicyError(input.message, { cause: input, invocation });
|
|
276
|
-
}
|
|
277
|
-
if (input instanceof ProtocolError) {
|
|
278
|
-
return input.invocation !== undefined || invocation === undefined
|
|
279
|
-
? input
|
|
280
|
-
: new ProtocolError(input.message, { cause: input, invocation });
|
|
180
|
+
if (input instanceof ResponseError || input instanceof ProtocolError) {
|
|
181
|
+
return withInvocation(input, invocation);
|
|
281
182
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
return new ProtocolError('server returned an invalid WebSocket frame.', {
|
|
286
|
-
cause: asError(input),
|
|
287
|
-
invocation,
|
|
288
|
-
});
|
|
183
|
+
return new ProtocolError(input instanceof errors.ProtocolError
|
|
184
|
+
? input.message
|
|
185
|
+
: 'server returned an invalid WebSocket frame.', { cause: asError(input), invocation });
|
|
289
186
|
}
|
|
290
187
|
function requireId(expected, received) {
|
|
291
188
|
if (received !== expected) {
|
|
292
189
|
throw new ProtocolError(`response requestId ${JSON.stringify(received)} does not match request requestId ${JSON.stringify(expected)}.`);
|
|
293
190
|
}
|
|
294
191
|
}
|
|
295
|
-
|
|
192
|
+
/** Only stream frames may follow `stream.start`; a unary response would end the stream unchecked. */
|
|
193
|
+
function isStreamFrame(input) {
|
|
194
|
+
return 'kind' in input && typeof input.kind === 'string' && input.kind.startsWith('stream.');
|
|
195
|
+
}
|
|
196
|
+
/** Whether `input` is a plain object whose `kind` is `kind`. */
|
|
197
|
+
export function isKind(input, kind) {
|
|
296
198
|
return (typeof input === 'object' &&
|
|
297
199
|
input !== null &&
|
|
298
200
|
!Array.isArray(input) &&
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as codecs from '@astrale-os/kernel-protocol/codecs';
|
|
2
2
|
import * as protocol from '@astrale-os/kernel-protocol/invocation';
|
|
3
|
-
import {
|
|
4
|
-
import { invocationFailure } from '../failure.js';
|
|
3
|
+
import { TransportError } from '../../errors/index.js';
|
|
4
|
+
import { invocationFailure, requestFailure } from '../failure.js';
|
|
5
5
|
import { asError, controlledSignal, positiveInteger, requireLive } from '../index.js';
|
|
6
6
|
import { WebSocketConnection } from './connection.js';
|
|
7
7
|
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
@@ -64,7 +64,15 @@ export class WebSocketTransport {
|
|
|
64
64
|
return await connection.dispatch(request, control, this.maximumBufferedStreamItems);
|
|
65
65
|
}
|
|
66
66
|
catch (error) {
|
|
67
|
-
|
|
67
|
+
// The connection and its exchange already judged their own failures, deadline included.
|
|
68
|
+
if (error instanceof TransportError)
|
|
69
|
+
throw error;
|
|
70
|
+
throw requestFailure(error, control, {
|
|
71
|
+
phase: 'connect',
|
|
72
|
+
delivery: 'not-sent',
|
|
73
|
+
timeout: `WebSocket invocation timed out after ${timeoutMs}ms.`,
|
|
74
|
+
failure: `Failed to communicate with the server at ${this.url}.`,
|
|
75
|
+
});
|
|
68
76
|
}
|
|
69
77
|
finally {
|
|
70
78
|
if (!owned)
|
|
@@ -131,19 +139,3 @@ function admitWebSocket(input) {
|
|
|
131
139
|
}
|
|
132
140
|
return implementation;
|
|
133
141
|
}
|
|
134
|
-
function transportFailure(input, control, parent, timeoutMs, url) {
|
|
135
|
-
if (input instanceof ResponseError || input instanceof ProtocolError)
|
|
136
|
-
return input;
|
|
137
|
-
if (input instanceof TransportError)
|
|
138
|
-
return input;
|
|
139
|
-
if (control.timedOut) {
|
|
140
|
-
return invocationFailure(`WebSocket invocation timed out after ${timeoutMs}ms.`, 'timeout', {
|
|
141
|
-
cause: asError(input),
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
if (parent?.aborted)
|
|
145
|
-
return asError(parent.reason ?? input);
|
|
146
|
-
return invocationFailure(`Failed to communicate with the server at ${url}.`, 'connect', {
|
|
147
|
-
cause: asError(input),
|
|
148
|
-
});
|
|
149
|
-
}
|
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.30",
|
|
4
4
|
"description": "Universal Client — protocol-first, transport-agnostic",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astrale",
|
|
@@ -65,16 +65,18 @@
|
|
|
65
65
|
"access": "public"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@astrale-os/kernel-core": "1.0.0-beta.
|
|
69
|
-
"@astrale-os/kernel-dsl": "1.0.0-beta.
|
|
70
|
-
"@astrale-os/kernel-protocol": "1.0.0-beta.
|
|
68
|
+
"@astrale-os/kernel-core": "1.0.0-beta.27",
|
|
69
|
+
"@astrale-os/kernel-dsl": "1.0.0-beta.19",
|
|
70
|
+
"@astrale-os/kernel-protocol": "1.0.0-beta.27",
|
|
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.27",
|
|
75
75
|
"@astrale/typescript-config": "npm:@jsr/astrale__typescript-config@~1.1.0",
|
|
76
76
|
"@types/node": "^22.0.0",
|
|
77
|
+
"esbuild": "0.28.1",
|
|
77
78
|
"typescript": "7.0.2",
|
|
79
|
+
"undici": "8.10.0",
|
|
78
80
|
"vitest": "^5.0.1"
|
|
79
81
|
},
|
|
80
82
|
"scripts": {
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type { NodeId } from '@astrale-os/kernel-core/graph/node';
|
|
2
|
-
import type { Value } from '@astrale-os/kernel-dsl/value';
|
|
3
|
-
import type { CallableReference } from './reference.js';
|
|
4
|
-
declare const EXECUTION_OUTPUT: unique symbol;
|
|
5
|
-
/**
|
|
6
|
-
* Immediate value of a durable call: the `K.Execution` it created or recovered. `Output` is the
|
|
7
|
-
* handler output of the called declaration, carried only by the type.
|
|
8
|
-
*/
|
|
9
|
-
export interface ExecutionRef<Output = unknown> {
|
|
10
|
-
readonly id: NodeId;
|
|
11
|
-
readonly [EXECUTION_OUTPUT]?: Output;
|
|
12
|
-
}
|
|
13
|
-
export type ExecutionOutcome<Output = unknown> = {
|
|
14
|
-
readonly kind: 'completed';
|
|
15
|
-
readonly value: Output;
|
|
16
|
-
} | {
|
|
17
|
-
readonly kind: 'failed';
|
|
18
|
-
readonly error: {
|
|
19
|
-
readonly code: string;
|
|
20
|
-
readonly message: string;
|
|
21
|
-
readonly family?: string;
|
|
22
|
-
readonly details?: Value;
|
|
23
|
-
};
|
|
24
|
-
} | {
|
|
25
|
-
readonly kind: 'cancelled';
|
|
26
|
-
};
|
|
27
|
-
export type ExecutionState = 'pending' | 'running' | 'waiting' | 'paused' | 'completed' | 'failed' | 'cancelled' | 'expired';
|
|
28
|
-
export interface ExecutionStatus<Output = unknown> {
|
|
29
|
-
readonly id: NodeId;
|
|
30
|
-
readonly function: NodeId;
|
|
31
|
-
readonly version: `sha256:${string}`;
|
|
32
|
-
readonly state: ExecutionState;
|
|
33
|
-
readonly createdAt: string;
|
|
34
|
-
readonly outcome?: ExecutionOutcome<Output>;
|
|
35
|
-
}
|
|
36
|
-
type Empty = Readonly<Record<string, never>>;
|
|
37
|
-
type ExecutionLike<Output> = ExecutionRef<Output> | NodeId;
|
|
38
|
-
/**
|
|
39
|
-
* Typed references to the methods of one Execution, for `session.invoke`:
|
|
40
|
-
*
|
|
41
|
-
* ```ts
|
|
42
|
-
* const run = await session.invoke(remind(invoice), { days: 3 })
|
|
43
|
-
* const outcome = await session.invoke(execution.result(run), { waitMs: 10_000 })
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
export declare const execution: Readonly<{
|
|
47
|
-
status: <Output>(target: ExecutionLike<Output>) => CallableReference<Empty, ExecutionStatus<Output>>;
|
|
48
|
-
/** Outcome once terminal; fails `EXECUTION_PENDING` when `waitMs` elapses first. */
|
|
49
|
-
result: <Output>(target: ExecutionLike<Output>) => CallableReference<{
|
|
50
|
-
readonly waitMs?: number;
|
|
51
|
-
}, ExecutionOutcome<Output>>;
|
|
52
|
-
/** Cooperative cancellation; `force` kills without compensation (owner Domain only). */
|
|
53
|
-
cancel: <Output>(target: ExecutionLike<Output>) => CallableReference<{
|
|
54
|
-
readonly force?: boolean;
|
|
55
|
-
}, ExecutionStatus<Output>>;
|
|
56
|
-
/** Resolve a named durable promise once (owner Domain only). */
|
|
57
|
-
signal: (target: ExecutionLike<unknown>) => CallableReference<{
|
|
58
|
-
readonly name: string;
|
|
59
|
-
readonly value: Value;
|
|
60
|
-
}, Empty>;
|
|
61
|
-
resume: <Output>(target: ExecutionLike<Output>) => CallableReference<Empty, ExecutionStatus<Output>>;
|
|
62
|
-
/** Forget the Execution and stop its run (owner Domain only). */
|
|
63
|
-
delete: (target: ExecutionLike<unknown>) => CallableReference<Empty, Empty>;
|
|
64
|
-
}>;
|
|
65
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Path } from '@astrale-os/kernel-core/path';
|
|
2
|
-
import { execution as methods } from '@astrale-os/kernel-core/schema/kernel/syscalls/references';
|
|
3
|
-
import { kernelReference } from './reference.js';
|
|
4
|
-
const bound = {
|
|
5
|
-
status: kernelReference(methods.status),
|
|
6
|
-
result: kernelReference(methods.result),
|
|
7
|
-
cancel: kernelReference(methods.cancel),
|
|
8
|
-
signal: kernelReference(methods.signal),
|
|
9
|
-
resume: kernelReference(methods.resume),
|
|
10
|
-
delete: kernelReference(methods.delete),
|
|
11
|
-
};
|
|
12
|
-
function receiver(execution) {
|
|
13
|
-
return Path.id(typeof execution === 'string' ? execution : execution.id);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Typed references to the methods of one Execution, for `session.invoke`:
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* const run = await session.invoke(remind(invoice), { days: 3 })
|
|
20
|
-
* const outcome = await session.invoke(execution.result(run), { waitMs: 10_000 })
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export const execution = Object.freeze({
|
|
24
|
-
status: (target) => bound.status(receiver(target)),
|
|
25
|
-
/** Outcome once terminal; fails `EXECUTION_PENDING` when `waitMs` elapses first. */
|
|
26
|
-
result: (target) => bound.result(receiver(target)),
|
|
27
|
-
/** Cooperative cancellation; `force` kills without compensation (owner Domain only). */
|
|
28
|
-
cancel: (target) => bound.cancel(receiver(target)),
|
|
29
|
-
/** Resolve a named durable promise once (owner Domain only). */
|
|
30
|
-
signal: (target) => bound.signal(receiver(target)),
|
|
31
|
-
resume: (target) => bound.resume(receiver(target)),
|
|
32
|
-
/** Forget the Execution and stop its run (owner Domain only). */
|
|
33
|
-
delete: (target) => bound.delete(receiver(target)),
|
|
34
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Key, bundle } from '@astrale-os/kernel-dsl/v1';
|
|
2
|
-
import type { DomainRelease } from '@astrale-os/kernel-protocol/release';
|
|
3
|
-
import { type ResolvedView } from '@astrale-os/kernel-core/schema/kernel/syscalls/view-resolution';
|
|
4
|
-
export type { ResolvedView } from '@astrale-os/kernel-core/schema/kernel/syscalls/view-resolution';
|
|
5
|
-
import type { SessionPolicy } from '../context/index.js';
|
|
6
|
-
/** One verified View declaration joined with its owning Release and provenance. */
|
|
7
|
-
/** Immutable canonical-key-ordered inventory of Views resolved under one Session revision. */
|
|
8
|
-
export interface ViewCatalog {
|
|
9
|
-
readonly entrypoint?: ResolvedView;
|
|
10
|
-
readonly views: readonly ResolvedView[];
|
|
11
|
-
}
|
|
12
|
-
/** Join each root Domain View to its exact release binding. */
|
|
13
|
-
export declare function rootViewCatalog(release: DomainRelease, artifact: bundle.Bundle, policy: Readonly<SessionPolicy>): ViewCatalog;
|
|
14
|
-
export declare function catalogFromKeys(root: ViewCatalog, keys: readonly Key.View[]): ViewCatalog;
|
|
15
|
-
/**
|
|
16
|
-
* Re-admit one Runtime-resolved Domain View catalog at the Client trust boundary. Only Views that
|
|
17
|
-
* the requested Domain declares for itself are kept.
|
|
18
|
-
*/
|
|
19
|
-
export declare function domainViewCatalog(input: unknown, domain: Key.Origin, policy: Readonly<SessionPolicy>): ViewCatalog;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { PathLike } from '@astrale-os/kernel-core/path';
|
|
2
|
-
import type { Key } from '@astrale-os/kernel-dsl/v1';
|
|
3
|
-
import type { Call, Input } from '../../client/index.js';
|
|
4
|
-
import type { SessionOperation } from '../context/index.js';
|
|
5
|
-
import type { ViewCatalog } from './catalog.js';
|
|
6
|
-
export type ViewInvoker = (call: Call, operation: SessionOperation) => Promise<Input>;
|
|
7
|
-
export type ViewCatalogAdmission = (input: unknown, domain: Key.Origin) => ViewCatalog;
|
|
8
|
-
/**
|
|
9
|
-
* Resolve the per-Domain View catalog through the canonical source Kernel call, then admit its
|
|
10
|
-
* installed Release evidence. Every View targets its owning Domain, so only an exact Domain
|
|
11
|
-
* Path `/:<origin>` is meaningful; any other Path is refused before the call.
|
|
12
|
-
*/
|
|
13
|
-
export declare function resolveViewsFor(invoke: ViewInvoker, admitCatalog: ViewCatalogAdmission, domain: PathLike, operation: SessionOperation): Promise<ViewCatalog>;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Path } from '@astrale-os/kernel-core/path';
|
|
2
|
-
import { view } from '@astrale-os/kernel-core/schema/kernel/syscalls/references';
|
|
3
|
-
import { call } from '../../client/index.js';
|
|
4
|
-
/**
|
|
5
|
-
* Resolve the per-Domain View catalog through the canonical source Kernel call, then admit its
|
|
6
|
-
* installed Release evidence. Every View targets its owning Domain, so only an exact Domain
|
|
7
|
-
* Path `/:<origin>` is meaningful; any other Path is refused before the call.
|
|
8
|
-
*/
|
|
9
|
-
export async function resolveViewsFor(invoke, admitCatalog, domain, operation) {
|
|
10
|
-
const origin = domainOrigin(domain);
|
|
11
|
-
const owner = Path.project(view.resolve.owner);
|
|
12
|
-
const resolve = Path.staticMethod(owner, view.resolve.name);
|
|
13
|
-
return admitCatalog(await invoke(call(resolve, { target: Path.domain(origin).raw }), operation), origin);
|
|
14
|
-
}
|
|
15
|
-
function domainOrigin(input) {
|
|
16
|
-
const { anchor, steps } = Path.from(input).ast;
|
|
17
|
-
if (anchor.kind !== 'domain' || steps.length !== 0) {
|
|
18
|
-
throw new TypeError('View catalog requires a Domain Path /:<origin>; Views never target a Node.');
|
|
19
|
-
}
|
|
20
|
-
return anchor.origin;
|
|
21
|
-
}
|