@astrale-os/kernel-client 0.6.0-beta.86 → 0.6.0-beta.87
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/identity.d.ts +2 -1
- package/dist/client/credential.d.ts +2 -1
- package/dist/errors/stale-route-error.d.ts +4 -14
- package/dist/errors/stale-route-error.js +2 -13
- package/dist/errors/transport-error.d.ts +1 -1
- package/dist/graph/domain/domain.typecheck.js +1 -0
- package/dist/graph/index.d.ts +1 -1
- package/dist/graph/index.js +1 -1
- package/dist/schema/introspection.js +1 -5
- package/dist/schema/schema.js +4 -8
- package/dist/session/bound.d.ts +1 -1
- package/dist/session/bound.js +2 -1
- package/dist/session/content/api.d.ts +45 -0
- package/dist/session/content/api.js +28 -0
- package/dist/session/content/batch.d.ts +5 -0
- package/dist/session/content/batch.js +93 -0
- package/dist/session/content/index.d.ts +1 -0
- package/dist/session/content/index.js +1 -0
- package/dist/session/content/input.d.ts +9 -0
- package/dist/session/content/input.js +33 -0
- package/dist/session/content/parts.d.ts +36 -0
- package/dist/session/content/parts.js +154 -0
- package/dist/session/content/retry.d.ts +3 -0
- package/dist/session/content/retry.js +41 -0
- package/dist/session/content/wire.d.ts +12 -0
- package/dist/session/content/wire.js +60 -0
- package/dist/session/context/index.d.ts +1 -1
- package/dist/session/context/index.js +1 -1
- package/dist/session/context/limits.d.ts +0 -1
- package/dist/session/context/limits.js +0 -1
- package/dist/session/context/operation.d.ts +0 -1
- package/dist/session/context/operation.js +1 -1
- package/dist/session/context/policy.d.ts +0 -1
- package/dist/session/context/policy.js +0 -16
- package/dist/session/discovery/bundle.d.ts +4 -3
- package/dist/session/discovery/bundle.js +20 -21
- package/dist/session/discovery/discovery.d.ts +0 -3
- package/dist/session/discovery/discovery.js +6 -14
- package/dist/session/discovery/index.d.ts +0 -5
- package/dist/session/discovery/index.js +1 -2
- package/dist/session/discovery/release.d.ts +6 -5
- package/dist/session/discovery/release.js +3 -3
- package/dist/session/discovery/snapshot.d.ts +1 -8
- package/dist/session/discovery/snapshot.js +2 -2
- package/dist/session/exchange/domain.js +1 -1
- package/dist/session/exchange/source.d.ts +2 -1
- package/dist/session/index.d.ts +3 -2
- package/dist/session/index.js +1 -1
- package/dist/session/options.d.ts +65 -0
- package/dist/session/options.js +132 -0
- package/dist/session/routing/cache.d.ts +9 -14
- package/dist/session/routing/cache.js +17 -178
- package/dist/session/routing/dispatch.d.ts +4 -3
- package/dist/session/routing/dispatch.js +63 -113
- package/dist/session/routing/envelope.d.ts +3 -3
- package/dist/session/routing/expiry.d.ts +4 -0
- package/dist/session/routing/expiry.js +32 -0
- package/dist/session/routing/index.d.ts +4 -2
- package/dist/session/routing/index.js +4 -2
- package/dist/session/routing/integrity.d.ts +7 -0
- package/dist/session/routing/integrity.js +44 -0
- package/dist/session/routing/recovery.d.ts +16 -0
- package/dist/session/routing/recovery.js +41 -0
- package/dist/session/routing/result.d.ts +5 -0
- package/dist/session/routing/result.js +12 -0
- package/dist/session/routing/store.d.ts +23 -0
- package/dist/session/routing/store.js +99 -0
- package/dist/session/session.d.ts +6 -50
- package/dist/session/session.js +28 -134
- package/dist/session/session.typecheck.js +8 -3
- package/dist/session/views/catalog.d.ts +5 -9
- package/dist/session/views/catalog.js +12 -24
- package/dist/session/views/resolve.d.ts +1 -1
- package/dist/session/views/resolve.js +1 -1
- package/dist/store/entity-index.d.ts +1 -2
- package/dist/store/entity-index.js +0 -3
- package/dist/store/memory.js +2 -2
- package/dist/store/shape.d.ts +2 -1
- package/dist/transport/auto/decision.d.ts +3 -2
- package/dist/transport/http/admission.d.ts +5 -0
- package/dist/transport/http/admission.js +101 -0
- package/dist/transport/http/binary.d.ts +5 -0
- package/dist/transport/http/binary.js +70 -0
- package/dist/transport/http/configuration.d.ts +24 -0
- package/dist/transport/http/configuration.js +116 -0
- package/dist/transport/http/index.d.ts +2 -1
- package/dist/transport/http/response.d.ts +7 -0
- package/dist/transport/http/response.js +9 -0
- package/dist/transport/http/retired.d.ts +8 -0
- package/dist/transport/http/retired.js +28 -0
- package/dist/transport/http/transport.d.ts +1 -19
- package/dist/transport/http/transport.js +17 -299
- package/dist/transport/websocket/connection.d.ts +2 -1
- package/package.json +5 -5
- package/dist/session/content.d.ts +0 -27
- package/dist/session/content.js +0 -135
- package/dist/session/discovery/legacy/index.d.ts +0 -38
- package/dist/session/discovery/legacy/index.js +0 -38
- package/dist/session/discovery/legacy/intrinsic.d.ts +0 -33
- package/dist/session/discovery/legacy/intrinsic.js +0 -67
- package/dist/session/discovery/legacy/projection.d.ts +0 -8
- package/dist/session/discovery/legacy/projection.js +0 -17
- package/dist/session/discovery/legacy/publication.d.ts +0 -26
- package/dist/session/discovery/legacy/publication.js +0 -76
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import { canonicalMediaType } from '@astrale-os/kernel-protocol/artifact';
|
|
2
1
|
import * as codecs from '@astrale-os/kernel-protocol/codecs';
|
|
3
2
|
import * as protocol from '@astrale-os/kernel-protocol/invocation';
|
|
4
|
-
import * as retirement from '@astrale-os/kernel-protocol/routes/deployment-retired';
|
|
5
3
|
import { ProtocolError, ResponseError, TransportError } from '../../errors/index.js';
|
|
6
4
|
import { invocationFailure } from '../failure.js';
|
|
7
5
|
import { asError, controlledSignal, positiveInteger, requireLive, } from '../index.js';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { HttpStream } from './stream.js';
|
|
11
|
-
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
12
|
-
const DEFAULT_MAXIMUM_REQUEST_BYTES = 16 * 1024 * 1024;
|
|
13
|
-
const DEFAULT_MAXIMUM_RESPONSE_BYTES = 16 * 1024 * 1024;
|
|
6
|
+
import { admitResponse } from './admission.js';
|
|
7
|
+
import { capture } from './configuration.js';
|
|
14
8
|
/** HTTP implementation of the universal invocation protocol. */
|
|
15
9
|
export class HttpTransport {
|
|
16
10
|
url;
|
|
@@ -21,15 +15,13 @@ export class HttpTransport {
|
|
|
21
15
|
maximumResponseBytes;
|
|
22
16
|
nextId = 1;
|
|
23
17
|
constructor(options) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
30
|
-
this.
|
|
31
|
-
this.maximumRequestBytes = positiveInteger(options.maximumRequestBytes ?? DEFAULT_MAXIMUM_REQUEST_BYTES, 'maximumRequestBytes');
|
|
32
|
-
this.maximumResponseBytes = positiveInteger(options.maximumResponseBytes ?? DEFAULT_MAXIMUM_RESPONSE_BYTES, 'maximumResponseBytes');
|
|
18
|
+
const configuration = capture(options);
|
|
19
|
+
this.url = configuration.url;
|
|
20
|
+
this.fetchImpl = configuration.fetch;
|
|
21
|
+
this.headers = configuration.headers;
|
|
22
|
+
this.timeoutMs = configuration.timeoutMs;
|
|
23
|
+
this.maximumRequestBytes = configuration.maximumRequestBytes;
|
|
24
|
+
this.maximumResponseBytes = configuration.maximumResponseBytes;
|
|
33
25
|
}
|
|
34
26
|
async dispatch(input, options = {}) {
|
|
35
27
|
return this.dispatchWith(input, options);
|
|
@@ -72,90 +64,14 @@ export class HttpTransport {
|
|
|
72
64
|
const response = await this.fetchResponse(codec, encoded, trace, control, binaryBody);
|
|
73
65
|
phase = 'receive';
|
|
74
66
|
requireLive(control);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const hasBinarySignal = binaryId !== null || binaryManifest !== null || binaryDelivery !== null;
|
|
84
|
-
const responseCodec = codecForResponse(response.headers.get('content-type'));
|
|
85
|
-
if (response.headers.has(retirement.HTTP_DEPLOYMENT_RETIRED)) {
|
|
86
|
-
if (hasStreamSignal || hasBinarySignal) {
|
|
87
|
-
throw new ProtocolError('server returned a deployment-retired control with a stream or binary signal.');
|
|
88
|
-
}
|
|
89
|
-
const retired = await this.decodeDeploymentRetired(response, responseCodec, control);
|
|
90
|
-
requireLive(control);
|
|
91
|
-
return retired;
|
|
92
|
-
}
|
|
93
|
-
if (!response.ok && responseCodec === undefined && !hasStreamSignal && !hasBinarySignal) {
|
|
94
|
-
throw invocationFailure(`server returned HTTP ${response.status} without an invocation response.`, 'receive', { delivery: 'unknown' });
|
|
95
|
-
}
|
|
96
|
-
requireNoStore(response);
|
|
97
|
-
if (hasStreamSignal && hasBinarySignal) {
|
|
98
|
-
throw new ProtocolError('server returned conflicting stream and binary response signals.');
|
|
99
|
-
}
|
|
100
|
-
if (hasBinarySignal) {
|
|
101
|
-
if (binaryId === null || binaryManifest === null) {
|
|
102
|
-
throw new ProtocolError('server returned an incomplete binary response signal.');
|
|
103
|
-
}
|
|
104
|
-
if (binaryDelivery !== null && binaryDelivery !== protocol.http.STREAMING_BINARY_DELIVERY) {
|
|
105
|
-
throw new ProtocolError('server returned an unsupported binary delivery signal.');
|
|
106
|
-
}
|
|
107
|
-
const binary = await this.decodeBinary(response, requestId, binaryId, binaryDelivery !== null, control);
|
|
108
|
-
if (!(binary.value.body instanceof Uint8Array))
|
|
109
|
-
handedOff = true;
|
|
110
|
-
return binary;
|
|
111
|
-
}
|
|
112
|
-
if (responseCodec === undefined) {
|
|
113
|
-
throw new ProtocolError(`server returned unsupported Content-Type ${JSON.stringify(response.headers.get('content-type'))}.`);
|
|
114
|
-
}
|
|
115
|
-
if (hasStreamSignal) {
|
|
116
|
-
if (streamFraming !== protocol.http.LENGTH_PREFIX_V1) {
|
|
117
|
-
throw new ProtocolError(`server returned unsupported stream framing ${JSON.stringify(streamFraming)}.`);
|
|
118
|
-
}
|
|
119
|
-
if (!response.ok) {
|
|
120
|
-
throw new ProtocolError('server returned a non-success stream response.');
|
|
121
|
-
}
|
|
122
|
-
const stream = await HttpStream.open(response, responseCodec, requestId, this.maximumResponseBytes, control);
|
|
123
|
-
requireLive(control);
|
|
124
|
-
handedOff = true;
|
|
125
|
-
return { kind: 'stream', stream, invocation: stream.invocation };
|
|
126
|
-
}
|
|
127
|
-
const body = await readBoundedBody(response, this.maximumResponseBytes, control.signal);
|
|
128
|
-
requireLive(control);
|
|
129
|
-
const decoded = decodeProtocol('response body', () => responseCodec.decode(body));
|
|
130
|
-
const envelope = decodeProtocol('response envelope', () => protocol.decodeResponse(decoded));
|
|
131
|
-
if (envelope.requestId === null && 'error' in envelope) {
|
|
132
|
-
throw new ResponseError(envelope.error.code, envelope.error.message, envelope.invocation, envelope.error.data);
|
|
133
|
-
}
|
|
134
|
-
requireId(requestId, envelope.requestId);
|
|
135
|
-
if ('kind' in envelope && envelope.kind === 'stale') {
|
|
136
|
-
const stale = decodeProtocol('stale response', () => protocol.decodeStale(envelope));
|
|
137
|
-
requireLive(control);
|
|
138
|
-
return Object.freeze({
|
|
139
|
-
kind: 'stale',
|
|
140
|
-
current: stale.current,
|
|
141
|
-
invocation: stale.invocation,
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
if ('kind' in envelope && envelope.kind === 'miss') {
|
|
145
|
-
decodeProtocol('miss response', () => protocol.decodeMiss(envelope));
|
|
146
|
-
requireLive(control);
|
|
147
|
-
return Object.freeze({ kind: 'miss', invocation: envelope.invocation });
|
|
148
|
-
}
|
|
149
|
-
if ('kind' in envelope && envelope.kind === 'redirect') {
|
|
150
|
-
const response = decodeProtocol('redirect response', () => protocol.decodeRedirectResponse(envelope));
|
|
151
|
-
requireLive(control);
|
|
152
|
-
return redirectResult(response);
|
|
153
|
-
}
|
|
154
|
-
if ('error' in envelope) {
|
|
155
|
-
throw new ResponseError(envelope.error.code, envelope.error.message, envelope.invocation, envelope.error.data);
|
|
156
|
-
}
|
|
157
|
-
requireLive(control);
|
|
158
|
-
return { kind: 'value', value: envelope.result, invocation: envelope.invocation };
|
|
67
|
+
const result = await admitResponse(response, requestId, {
|
|
68
|
+
maximumBytes: this.maximumResponseBytes,
|
|
69
|
+
control,
|
|
70
|
+
});
|
|
71
|
+
handedOff =
|
|
72
|
+
result.kind === 'stream' ||
|
|
73
|
+
(result.kind === 'binary' && !(result.value.body instanceof Uint8Array));
|
|
74
|
+
return result;
|
|
159
75
|
}
|
|
160
76
|
catch (error) {
|
|
161
77
|
throw transportFailure(error, control, options.signal, timeoutMs, this.url, phase, delivery);
|
|
@@ -189,148 +105,12 @@ export class HttpTransport {
|
|
|
189
105
|
};
|
|
190
106
|
return this.fetchImpl(this.url, init);
|
|
191
107
|
}
|
|
192
|
-
/**
|
|
193
|
-
* Admit the reserved retirement control only as the exact 410, header and envelope triple; the
|
|
194
|
-
* header beside any other status, value or body is an invalid response, never an ordinary error.
|
|
195
|
-
*/
|
|
196
|
-
async decodeDeploymentRetired(response, codec, control) {
|
|
197
|
-
if (codec === undefined) {
|
|
198
|
-
throw new ProtocolError('server returned a deployment-retired control without an envelope.');
|
|
199
|
-
}
|
|
200
|
-
requireNoStore(response);
|
|
201
|
-
const body = await readBoundedBody(response, this.maximumResponseBytes, control.signal);
|
|
202
|
-
const decoded = decodeProtocol('deployment-retired body', () => codec.decode(body));
|
|
203
|
-
const retired = decodeProtocol('deployment-retired control', () => retirement.decodeDeploymentRetired(response.status, response.headers, decoded));
|
|
204
|
-
const envelope = decodeProtocol('deployment-retired envelope', () => protocol.decodeResponse(decoded));
|
|
205
|
-
if (retired === undefined || !('error' in envelope)) {
|
|
206
|
-
throw new ProtocolError('server returned an invalid deployment-retired control.');
|
|
207
|
-
}
|
|
208
|
-
return Object.freeze({
|
|
209
|
-
kind: 'deployment-retired',
|
|
210
|
-
reason: retired.reason,
|
|
211
|
-
message: envelope.error.message,
|
|
212
|
-
invocation: envelope.invocation,
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
async decodeBinary(response, requestId, binaryId, streaming, control) {
|
|
216
|
-
if (binaryId !== String(requestId)) {
|
|
217
|
-
throw new ProtocolError(`binary response requestId ${JSON.stringify(binaryId)} does not match request requestId ${requestId}.`);
|
|
218
|
-
}
|
|
219
|
-
const contentType = response.headers.get('content-type');
|
|
220
|
-
if (contentType === null) {
|
|
221
|
-
throw new ProtocolError('binary response has no media type.');
|
|
222
|
-
}
|
|
223
|
-
const mediaType = decodeProtocol('binary media type', () => canonicalMediaType(contentType));
|
|
224
|
-
const headerNames = decodeProtocol('binary application-header manifest', () => protocol.http.decodeBinaryHeaderNames(response.headers.get(protocol.http.BINARY_HEADERS_FIELD)));
|
|
225
|
-
const headers = binaryHeaders(response.headers, headerNames);
|
|
226
|
-
const invocation = decodeProtocol('binary InvocationId field', () => protocol.http.decodeInvocationId(response.headers.get(protocol.http.INVOCATION_FIELD)));
|
|
227
|
-
if (streaming) {
|
|
228
|
-
if (response.body === null)
|
|
229
|
-
throw new ProtocolError('streaming binary has no body.');
|
|
230
|
-
// An intermediary may rewrite Content-Length (for example when it compresses the body), so
|
|
231
|
-
// only the protocol length counts.
|
|
232
|
-
const length = response.headers.get(protocol.http.BINARY_LENGTH_FIELD);
|
|
233
|
-
const expectedBytes = length === null ? undefined : protocol.http.decodeBinaryLength(length);
|
|
234
|
-
if (length !== null && expectedBytes === undefined) {
|
|
235
|
-
throw new ProtocolError(`streaming binary has an invalid ${protocol.http.BINARY_LENGTH_FIELD}.`);
|
|
236
|
-
}
|
|
237
|
-
if (expectedBytes !== undefined && expectedBytes > this.maximumResponseBytes) {
|
|
238
|
-
throw new ProtocolError(`streaming binary exceeds maximumResponseBytes (${this.maximumResponseBytes}).`);
|
|
239
|
-
}
|
|
240
|
-
requireLive(control);
|
|
241
|
-
return {
|
|
242
|
-
kind: 'binary',
|
|
243
|
-
invocation,
|
|
244
|
-
value: {
|
|
245
|
-
body: new HttpByteStream(response.body, this.maximumResponseBytes, control, expectedBytes),
|
|
246
|
-
// The byte stream enforces this exact count through its final read.
|
|
247
|
-
...(expectedBytes === undefined ? {} : { length: expectedBytes }),
|
|
248
|
-
mediaType,
|
|
249
|
-
...(response.status === 200 ? {} : { status: response.status }),
|
|
250
|
-
...(Object.keys(headers).length === 0 ? {} : { headers }),
|
|
251
|
-
},
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
const body = await readBoundedBody(response, this.maximumResponseBytes, control.signal);
|
|
255
|
-
requireLive(control);
|
|
256
|
-
const binary = decodeProtocol('binary response', () => protocol.decodeBinaryResponse({
|
|
257
|
-
kind: 'binary',
|
|
258
|
-
requestId,
|
|
259
|
-
invocation,
|
|
260
|
-
body,
|
|
261
|
-
mediaType,
|
|
262
|
-
status: response.status,
|
|
263
|
-
...(Object.keys(headers).length === 0 ? {} : { headers }),
|
|
264
|
-
}));
|
|
265
|
-
requireLive(control);
|
|
266
|
-
return {
|
|
267
|
-
kind: 'binary',
|
|
268
|
-
invocation: binary.invocation,
|
|
269
|
-
value: {
|
|
270
|
-
body: binary.body,
|
|
271
|
-
mediaType: binary.mediaType,
|
|
272
|
-
...(binary.status === 200 ? {} : { status: binary.status }),
|
|
273
|
-
...(binary.headers === undefined ? {} : { headers: binary.headers }),
|
|
274
|
-
},
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
108
|
nextRequestId() {
|
|
278
109
|
const requestId = this.nextId;
|
|
279
110
|
this.nextId = requestId === Number.MAX_SAFE_INTEGER ? 1 : requestId + 1;
|
|
280
111
|
return requestId;
|
|
281
112
|
}
|
|
282
113
|
}
|
|
283
|
-
function redirectResult(response) {
|
|
284
|
-
return Object.freeze({
|
|
285
|
-
kind: 'redirect',
|
|
286
|
-
invocation: response.invocation,
|
|
287
|
-
redirect: response.redirect,
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
function normalizeUrl(input) {
|
|
291
|
-
if (typeof input !== 'string')
|
|
292
|
-
throw new TypeError('server URL must be a string.');
|
|
293
|
-
let parsed;
|
|
294
|
-
try {
|
|
295
|
-
parsed = new URL(input);
|
|
296
|
-
}
|
|
297
|
-
catch (error) {
|
|
298
|
-
throw new TypeError(`Invalid server URL ${JSON.stringify(input)}.`, { cause: asError(error) });
|
|
299
|
-
}
|
|
300
|
-
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
301
|
-
throw new TypeError('server URL must use http or https.');
|
|
302
|
-
}
|
|
303
|
-
if (parsed.username !== '' || parsed.password !== '' || parsed.hash !== '') {
|
|
304
|
-
throw new TypeError('server URL cannot contain credentials or a fragment.');
|
|
305
|
-
}
|
|
306
|
-
return parsed.toString();
|
|
307
|
-
}
|
|
308
|
-
function admitHeaders(input) {
|
|
309
|
-
if (input === null || typeof input !== 'object' || Array.isArray(input)) {
|
|
310
|
-
throw new TypeError('HTTP headers must be an object.');
|
|
311
|
-
}
|
|
312
|
-
const output = {};
|
|
313
|
-
for (const [name, value] of Object.entries(input)) {
|
|
314
|
-
if (!HEADER_NAME.test(name)) {
|
|
315
|
-
throw new TypeError(`HTTP header name ${JSON.stringify(name)} is invalid.`);
|
|
316
|
-
}
|
|
317
|
-
const normalized = name.toLowerCase();
|
|
318
|
-
if (Object.hasOwn(output, normalized)) {
|
|
319
|
-
throw new TypeError(`HTTP header ${JSON.stringify(name)} occurs more than once.`);
|
|
320
|
-
}
|
|
321
|
-
if (isReservedRequestHeader(normalized)) {
|
|
322
|
-
throw new TypeError(`HTTP header ${JSON.stringify(name)} is owned by transport.`);
|
|
323
|
-
}
|
|
324
|
-
if (typeof value !== 'string') {
|
|
325
|
-
throw new TypeError(`HTTP header ${JSON.stringify(name)} must be a string.`);
|
|
326
|
-
}
|
|
327
|
-
if (hasControlCharacter(value)) {
|
|
328
|
-
throw new TypeError(`HTTP header ${JSON.stringify(name)} contains a control character.`);
|
|
329
|
-
}
|
|
330
|
-
output[normalized] = value;
|
|
331
|
-
}
|
|
332
|
-
return Object.freeze(output);
|
|
333
|
-
}
|
|
334
114
|
function toBody(input) {
|
|
335
115
|
if (typeof input === 'string')
|
|
336
116
|
return input;
|
|
@@ -340,15 +120,6 @@ function toBody(input) {
|
|
|
340
120
|
function encodedByteLength(input) {
|
|
341
121
|
return typeof input === 'string' ? new TextEncoder().encode(input).byteLength : input.byteLength;
|
|
342
122
|
}
|
|
343
|
-
function requireNoStore(response) {
|
|
344
|
-
const directives = response.headers
|
|
345
|
-
.get('cache-control')
|
|
346
|
-
?.split(',')
|
|
347
|
-
.map((directive) => directive.trim().toLowerCase()) ?? [];
|
|
348
|
-
if (!directives.includes('no-store')) {
|
|
349
|
-
throw new ProtocolError('server response is missing Cache-Control: no-store.');
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
123
|
function transportFailure(input, control, parent, timeoutMs, url, phase, delivery) {
|
|
353
124
|
if (input instanceof ResponseError || input instanceof ProtocolError)
|
|
354
125
|
return input;
|
|
@@ -367,56 +138,3 @@ function transportFailure(input, control, parent, timeoutMs, url, phase, deliver
|
|
|
367
138
|
delivery,
|
|
368
139
|
});
|
|
369
140
|
}
|
|
370
|
-
function admitFetch(input) {
|
|
371
|
-
const implementation = input ?? globalThis.fetch;
|
|
372
|
-
if (typeof implementation !== 'function') {
|
|
373
|
-
throw new TypeError('HttpTransport requires a Fetch implementation.');
|
|
374
|
-
}
|
|
375
|
-
return input === undefined ? implementation.bind(globalThis) : implementation;
|
|
376
|
-
}
|
|
377
|
-
const HEADER_NAME = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
378
|
-
const RESERVED_REQUEST_HEADERS = new Set([
|
|
379
|
-
'accept',
|
|
380
|
-
'accept-encoding',
|
|
381
|
-
'authorization',
|
|
382
|
-
'cache-control',
|
|
383
|
-
'connection',
|
|
384
|
-
'content-length',
|
|
385
|
-
'content-type',
|
|
386
|
-
'cookie',
|
|
387
|
-
'forwarded',
|
|
388
|
-
'host',
|
|
389
|
-
'keep-alive',
|
|
390
|
-
'origin',
|
|
391
|
-
'pragma',
|
|
392
|
-
'proxy-authenticate',
|
|
393
|
-
'proxy-authorization',
|
|
394
|
-
'referer',
|
|
395
|
-
'referrer-policy',
|
|
396
|
-
'set-cookie',
|
|
397
|
-
'te',
|
|
398
|
-
protocol.http.TRACEPARENT_FIELD,
|
|
399
|
-
protocol.http.TRACESTATE_FIELD,
|
|
400
|
-
protocol.http.BAGGAGE_FIELD,
|
|
401
|
-
'trailer',
|
|
402
|
-
'transfer-encoding',
|
|
403
|
-
'upgrade',
|
|
404
|
-
'via',
|
|
405
|
-
]);
|
|
406
|
-
function isReservedRequestHeader(name) {
|
|
407
|
-
return (RESERVED_REQUEST_HEADERS.has(name) ||
|
|
408
|
-
name.startsWith('access-control-') ||
|
|
409
|
-
name.startsWith('content-') ||
|
|
410
|
-
name.startsWith('proxy-') ||
|
|
411
|
-
name.startsWith('sec-websocket-') ||
|
|
412
|
-
name.startsWith('x-astrale-') ||
|
|
413
|
-
name.startsWith('x-forwarded-'));
|
|
414
|
-
}
|
|
415
|
-
function hasControlCharacter(input) {
|
|
416
|
-
for (let index = 0; index < input.length; index += 1) {
|
|
417
|
-
const code = input.charCodeAt(index);
|
|
418
|
-
if (code <= 0x1f || code === 0x7f)
|
|
419
|
-
return true;
|
|
420
|
-
}
|
|
421
|
-
return false;
|
|
422
|
-
}
|
|
@@ -5,7 +5,7 @@ import type { TransportResult } from '../index.js';
|
|
|
5
5
|
import type { ExchangeOwner } from './exchange.js';
|
|
6
6
|
import type { WebSocketConstructor } from './transport.js';
|
|
7
7
|
import { WebSocketExchange } from './exchange.js';
|
|
8
|
-
|
|
8
|
+
interface ConnectionOwner {
|
|
9
9
|
closed(connection: WebSocketConnection): void;
|
|
10
10
|
}
|
|
11
11
|
export declare class WebSocketConnection implements ExchangeOwner {
|
|
@@ -36,3 +36,4 @@ export declare class WebSocketConnection implements ExchangeOwner {
|
|
|
36
36
|
private onMessage;
|
|
37
37
|
private onFailure;
|
|
38
38
|
}
|
|
39
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrale-os/kernel-client",
|
|
3
|
-
"version": "0.6.0-beta.
|
|
3
|
+
"version": "0.6.0-beta.87",
|
|
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": "0.9.0-beta.
|
|
69
|
-
"@astrale-os/kernel-dsl": "0.2.0-beta.
|
|
70
|
-
"@astrale-os/kernel-protocol": "0.5.0-beta.
|
|
68
|
+
"@astrale-os/kernel-core": "0.9.0-beta.66",
|
|
69
|
+
"@astrale-os/kernel-dsl": "0.2.0-beta.48",
|
|
70
|
+
"@astrale-os/kernel-protocol": "0.5.0-beta.72",
|
|
71
71
|
"@tanstack/pacer": "0.20.1"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@astrale-os/kernel-server": "0.5.0-beta.
|
|
74
|
+
"@astrale-os/kernel-server": "0.5.0-beta.74",
|
|
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",
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { schema } from '@astrale-os/kernel-dsl/v1';
|
|
2
|
-
import type { Ref } from '@astrale-os/kernel-protocol/artifact';
|
|
3
|
-
import { Path } from '@astrale-os/kernel-core/path';
|
|
4
|
-
import type { Binary, Input, Result } from '../client/index.js';
|
|
5
|
-
import type { SessionControlOptions, SessionOperation } from './context/index.js';
|
|
6
|
-
export interface ContentLocation {
|
|
7
|
-
readonly node: string;
|
|
8
|
-
readonly property: string;
|
|
9
|
-
}
|
|
10
|
-
export interface ContentUploadOptions extends SessionControlOptions {
|
|
11
|
-
readonly mediaType: string;
|
|
12
|
-
}
|
|
13
|
-
export interface ContentUploadResult {
|
|
14
|
-
readonly receipt: schema.values.BlobReceipt;
|
|
15
|
-
readonly ref: Ref;
|
|
16
|
-
readonly expiresAt: string;
|
|
17
|
-
}
|
|
18
|
-
export interface ContentApi {
|
|
19
|
-
upload(source: Blob | Uint8Array, options: ContentUploadOptions): Promise<ContentUploadResult>;
|
|
20
|
-
download(location: ContentLocation, options?: SessionControlOptions): Promise<Binary>;
|
|
21
|
-
}
|
|
22
|
-
export interface ContentSessionDependencies {
|
|
23
|
-
readonly operation: (options: SessionControlOptions) => SessionOperation;
|
|
24
|
-
readonly dispatch: (target: Path, input: Input, operation: SessionOperation, body?: Blob) => Promise<Result>;
|
|
25
|
-
}
|
|
26
|
-
/** Transfer immutable content over the authenticated Session routing conversation. */
|
|
27
|
-
export declare function createContentApi(dependencies: ContentSessionDependencies): ContentApi;
|
package/dist/session/content.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { NodeId } from '@astrale-os/kernel-core/graph/node';
|
|
2
|
-
import { Path } from '@astrale-os/kernel-core/path';
|
|
3
|
-
import { download, upload } from '@astrale-os/kernel-core/schema/kernel/syscalls/references';
|
|
4
|
-
import { PropertyKey } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
5
|
-
import * as artifact from '@astrale-os/kernel-protocol/artifact';
|
|
6
|
-
import { CODES } from '@astrale-os/kernel-protocol/errors';
|
|
7
|
-
import { ClientError, ProtocolError, ResponseError, TransportError } from '../errors/index.js';
|
|
8
|
-
import { admitControlOptions, runSessionOperation } from './context/index.js';
|
|
9
|
-
import { requireResultKind } from './routing/index.js';
|
|
10
|
-
const UPLOAD = Path.project(upload);
|
|
11
|
-
const DOWNLOAD = Path.project(download);
|
|
12
|
-
const CONTENT_TIMEOUT_MS = 30 * 60 * 1_000;
|
|
13
|
-
const MAXIMUM_ATTEMPTS = 3;
|
|
14
|
-
/** Transfer immutable content over the authenticated Session routing conversation. */
|
|
15
|
-
export function createContentApi(dependencies) {
|
|
16
|
-
async function upload(source, options) {
|
|
17
|
-
const body = admitBody(source);
|
|
18
|
-
const mediaType = admitMediaType(options?.mediaType);
|
|
19
|
-
const operation = dependencies.operation(contentControls(options));
|
|
20
|
-
let last;
|
|
21
|
-
for (let attempt = 0; attempt < MAXIMUM_ATTEMPTS; attempt++) {
|
|
22
|
-
try {
|
|
23
|
-
const result = await dependencies.dispatch(UPLOAD, { mediaType }, operation, body);
|
|
24
|
-
return uploadResult(requireResultKind('value', result).value);
|
|
25
|
-
}
|
|
26
|
-
catch (cause) {
|
|
27
|
-
last = cause;
|
|
28
|
-
if (!retryable(cause) || attempt + 1 === MAXIMUM_ATTEMPTS || operation.signal.aborted) {
|
|
29
|
-
throw cause;
|
|
30
|
-
}
|
|
31
|
-
await runSessionOperation(operation, (signal) => delay(200 * 2 ** attempt, signal));
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
throw last;
|
|
35
|
-
}
|
|
36
|
-
async function download(location, options) {
|
|
37
|
-
const operation = dependencies.operation(contentControls(options));
|
|
38
|
-
const result = await dependencies.dispatch(DOWNLOAD, admitLocation(location), operation);
|
|
39
|
-
return verifiedDownload(requireResultKind('binary', result).value);
|
|
40
|
-
}
|
|
41
|
-
return Object.freeze({ upload, download });
|
|
42
|
-
}
|
|
43
|
-
function admitLocation(input) {
|
|
44
|
-
if (input === null || typeof input !== 'object' || Array.isArray(input)) {
|
|
45
|
-
throw new TypeError('Content location is invalid.');
|
|
46
|
-
}
|
|
47
|
-
return Object.freeze({ node: NodeId(input.node), property: PropertyKey(input.property) });
|
|
48
|
-
}
|
|
49
|
-
function admitBody(input) {
|
|
50
|
-
if (typeof Blob !== 'undefined' && input instanceof Blob)
|
|
51
|
-
return input;
|
|
52
|
-
if (input instanceof Uint8Array) {
|
|
53
|
-
// Blob snapshots an ArrayBuffer view; a SharedArrayBuffer view needs an owned copy.
|
|
54
|
-
const bytes = input.buffer instanceof ArrayBuffer
|
|
55
|
-
? input
|
|
56
|
-
: new Uint8Array(input);
|
|
57
|
-
return new Blob([bytes]);
|
|
58
|
-
}
|
|
59
|
-
throw new TypeError('Content upload source must be a Blob, File, or Uint8Array.');
|
|
60
|
-
}
|
|
61
|
-
function admitMediaType(input) {
|
|
62
|
-
if (typeof input !== 'string')
|
|
63
|
-
throw new TypeError('Content upload mediaType is required.');
|
|
64
|
-
return artifact.identify(new Uint8Array(), input).mediaType;
|
|
65
|
-
}
|
|
66
|
-
function contentControls(input) {
|
|
67
|
-
const controls = admitControlOptions(input);
|
|
68
|
-
return Object.freeze({ ...controls, timeoutMs: controls.timeoutMs ?? CONTENT_TIMEOUT_MS });
|
|
69
|
-
}
|
|
70
|
-
function uploadResult(input) {
|
|
71
|
-
if (input === null || typeof input !== 'object' || Array.isArray(input)) {
|
|
72
|
-
throw new ClientError('Content upload returned an invalid receipt.');
|
|
73
|
-
}
|
|
74
|
-
const value = input;
|
|
75
|
-
if (typeof value.receipt !== 'string' ||
|
|
76
|
-
value.receipt.length === 0 ||
|
|
77
|
-
typeof value.expiresAt !== 'string' ||
|
|
78
|
-
!Number.isFinite(Date.parse(value.expiresAt))) {
|
|
79
|
-
throw new ClientError('Content upload returned an invalid receipt.');
|
|
80
|
-
}
|
|
81
|
-
let ref;
|
|
82
|
-
try {
|
|
83
|
-
ref = artifact.accept(value.ref);
|
|
84
|
-
}
|
|
85
|
-
catch (cause) {
|
|
86
|
-
throw new ClientError('Content upload returned an invalid Ref.', { cause });
|
|
87
|
-
}
|
|
88
|
-
return Object.freeze({
|
|
89
|
-
receipt: value.receipt,
|
|
90
|
-
ref,
|
|
91
|
-
expiresAt: value.expiresAt,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
function retryable(cause) {
|
|
95
|
-
return ((cause instanceof TransportError && cause.context.kind === 'invocation') ||
|
|
96
|
-
(cause instanceof ResponseError &&
|
|
97
|
-
(cause.reason?.code === 'BLOB_UNAVAILABLE' ||
|
|
98
|
-
cause.code === CODES.CANCELLED ||
|
|
99
|
-
cause.code === CODES.DEADLINE_EXCEEDED ||
|
|
100
|
-
cause.code === CODES.OUTCOME_UNKNOWN)));
|
|
101
|
-
}
|
|
102
|
-
function delay(ms, signal) {
|
|
103
|
-
return new Promise((resolve, reject) => {
|
|
104
|
-
if (signal.aborted)
|
|
105
|
-
return reject(signal.reason);
|
|
106
|
-
const timer = setTimeout(() => {
|
|
107
|
-
signal.removeEventListener('abort', abort);
|
|
108
|
-
resolve();
|
|
109
|
-
}, ms);
|
|
110
|
-
const abort = () => {
|
|
111
|
-
clearTimeout(timer);
|
|
112
|
-
reject(signal.reason);
|
|
113
|
-
};
|
|
114
|
-
signal.addEventListener('abort', abort, { once: true });
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
async function verifiedDownload(input) {
|
|
118
|
-
// The HTTP transport sets `length` only from an admitted declared length, and its byte stream
|
|
119
|
-
// enforces that exact count through the final read.
|
|
120
|
-
if (input.body instanceof Uint8Array || !('length' in input) || input.length === undefined) {
|
|
121
|
-
await cancelBinary(input);
|
|
122
|
-
throw new ProtocolError('Content download omitted its exact content size.');
|
|
123
|
-
}
|
|
124
|
-
return input;
|
|
125
|
-
}
|
|
126
|
-
async function cancelBinary(input) {
|
|
127
|
-
if (input.body instanceof Uint8Array)
|
|
128
|
-
return;
|
|
129
|
-
try {
|
|
130
|
-
await input.body[Symbol.asyncIterator]().return?.();
|
|
131
|
-
}
|
|
132
|
-
catch {
|
|
133
|
-
// Preserve the admission error after the response stream has been closed.
|
|
134
|
-
}
|
|
135
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compatibility discovery for Hosts without `release.json` and callers of the Publication API.
|
|
3
|
-
* Release-backed Hosts expose a locally computed v3 projection to those callers.
|
|
4
|
-
*
|
|
5
|
-
* Superseded by `ClientSession.release()` and `SessionSnapshot.release` (`ReleaseDiscovery`,
|
|
6
|
-
* `IntrinsicRelease`), and, for the stale hint, by `StaleRouteError.current`.
|
|
7
|
-
*
|
|
8
|
-
* Short-term consumers:
|
|
9
|
-
* - Hosts whose Kernel predates intrinsic `release.json`: they answer it with 404 (a browser sees
|
|
10
|
-
* a `TypeError`, the 404 carrying no CORS headers) and serve only their version 3 Publication at
|
|
11
|
-
* `domain.json`. Every Host does until it runs a Kernel release that serves `release.json`; the
|
|
12
|
-
* 1Pact path keeps one, because the client in GUI and Admin reads the Kernel .117 Host;
|
|
13
|
-
* - callers of the Publication API: Shell's `KernelClient.publication()` (and shell-react's graph
|
|
14
|
-
* store through it) and Admin's remote instance gateway (`SessionSnapshot.publication`), until
|
|
15
|
-
* each reads `release()` / `release`;
|
|
16
|
-
* - the snapshot's bundle and root Views, whose provenance (`ResolvedView.etag`) keeps the v3 ETag
|
|
17
|
-
* until the breaking release (AM-1).
|
|
18
|
-
*
|
|
19
|
-
* Removal, in a separate breaking release: no supported Host predates intrinsic `release.json`
|
|
20
|
-
* (never while GUI and Admin talk to the Kernel .117 Host), no supported consumer reads the
|
|
21
|
-
* Publication API, and the breaking release of AM-1 emits release digests on every
|
|
22
|
-
* Kernel-to-client wire value. Then delete, in the same PR:
|
|
23
|
-
* - this folder, its tests (the pre-v4 cases of `session/__tests__/release.test.ts`) and its laws;
|
|
24
|
-
* `SessionDiscovery` then reads `ReleaseDiscovery` directly, reports its 404 as a Client failure
|
|
25
|
-
* and designates a snapshot by release digest, so canonical code only narrows `IntrinsicRelease`
|
|
26
|
-
* to the `DomainRelease`;
|
|
27
|
-
* - the `'publication'` acquisition resource of `TransportError`, and the `domain.json` bound of
|
|
28
|
-
* `ClientSessionOptions.maximumPublicationBytes`, which keeps bounding the Publications Schema
|
|
29
|
-
* results carry until those name releases;
|
|
30
|
-
* - `ClientSession.publication()`, `SessionDiscovery.publication` and `SessionSnapshot.publication`
|
|
31
|
-
* with their `.spec` entries; `BundleDiscovery` and `rootViewCatalog` then take the release,
|
|
32
|
-
* whose View provenance is `ResolvedView.release`;
|
|
33
|
-
* - `StaleRouteError.currentEtag`, from law CLIENT-LEGACY-WIRE-FIELDS and its test, with the
|
|
34
|
-
* Protocol fields of law PROTOCOL-LEGACY-WIRE-FIELDS.
|
|
35
|
-
*/
|
|
36
|
-
export { designation, IntrinsicReleaseDiscovery, type ReleaseReader } from './intrinsic.js';
|
|
37
|
-
export { PublicationDiscovery, type PublicationDiscoveryOptions } from './publication.js';
|
|
38
|
-
export { publicationOf } from './projection.js';
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compatibility discovery for Hosts without `release.json` and callers of the Publication API.
|
|
3
|
-
* Release-backed Hosts expose a locally computed v3 projection to those callers.
|
|
4
|
-
*
|
|
5
|
-
* Superseded by `ClientSession.release()` and `SessionSnapshot.release` (`ReleaseDiscovery`,
|
|
6
|
-
* `IntrinsicRelease`), and, for the stale hint, by `StaleRouteError.current`.
|
|
7
|
-
*
|
|
8
|
-
* Short-term consumers:
|
|
9
|
-
* - Hosts whose Kernel predates intrinsic `release.json`: they answer it with 404 (a browser sees
|
|
10
|
-
* a `TypeError`, the 404 carrying no CORS headers) and serve only their version 3 Publication at
|
|
11
|
-
* `domain.json`. Every Host does until it runs a Kernel release that serves `release.json`; the
|
|
12
|
-
* 1Pact path keeps one, because the client in GUI and Admin reads the Kernel .117 Host;
|
|
13
|
-
* - callers of the Publication API: Shell's `KernelClient.publication()` (and shell-react's graph
|
|
14
|
-
* store through it) and Admin's remote instance gateway (`SessionSnapshot.publication`), until
|
|
15
|
-
* each reads `release()` / `release`;
|
|
16
|
-
* - the snapshot's bundle and root Views, whose provenance (`ResolvedView.etag`) keeps the v3 ETag
|
|
17
|
-
* until the breaking release (AM-1).
|
|
18
|
-
*
|
|
19
|
-
* Removal, in a separate breaking release: no supported Host predates intrinsic `release.json`
|
|
20
|
-
* (never while GUI and Admin talk to the Kernel .117 Host), no supported consumer reads the
|
|
21
|
-
* Publication API, and the breaking release of AM-1 emits release digests on every
|
|
22
|
-
* Kernel-to-client wire value. Then delete, in the same PR:
|
|
23
|
-
* - this folder, its tests (the pre-v4 cases of `session/__tests__/release.test.ts`) and its laws;
|
|
24
|
-
* `SessionDiscovery` then reads `ReleaseDiscovery` directly, reports its 404 as a Client failure
|
|
25
|
-
* and designates a snapshot by release digest, so canonical code only narrows `IntrinsicRelease`
|
|
26
|
-
* to the `DomainRelease`;
|
|
27
|
-
* - the `'publication'` acquisition resource of `TransportError`, and the `domain.json` bound of
|
|
28
|
-
* `ClientSessionOptions.maximumPublicationBytes`, which keeps bounding the Publications Schema
|
|
29
|
-
* results carry until those name releases;
|
|
30
|
-
* - `ClientSession.publication()`, `SessionDiscovery.publication` and `SessionSnapshot.publication`
|
|
31
|
-
* with their `.spec` entries; `BundleDiscovery` and `rootViewCatalog` then take the release,
|
|
32
|
-
* whose View provenance is `ResolvedView.release`;
|
|
33
|
-
* - `StaleRouteError.currentEtag`, from law CLIENT-LEGACY-WIRE-FIELDS and its test, with the
|
|
34
|
-
* Protocol fields of law PROTOCOL-LEGACY-WIRE-FIELDS.
|
|
35
|
-
*/
|
|
36
|
-
export { designation, IntrinsicReleaseDiscovery } from './intrinsic.js';
|
|
37
|
-
export { PublicationDiscovery } from './publication.js';
|
|
38
|
-
export { publicationOf } from './projection.js';
|