@astrale-os/kernel-client 0.6.0-beta.85 → 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/auth.d.ts +2 -8
- package/dist/auth/credential.d.ts +1 -7
- 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/admission.js +3 -3
- package/dist/session/bound.d.ts +2 -2
- package/dist/session/bound.js +3 -2
- 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/exchange.d.ts +1 -7
- package/dist/session/exchange/exchange.js +0 -4
- package/dist/session/exchange/index.d.ts +1 -1
- package/dist/session/exchange/index.js +1 -1
- package/dist/session/exchange/presentation.js +1 -2
- 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 -186
- 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 +11 -51
- package/dist/session/session.js +37 -139
- package/dist/session/session.typecheck.js +12 -4
- package/dist/session/views/catalog.d.ts +9 -5
- package/dist/session/views/catalog.js +29 -24
- package/dist/session/views/index.d.ts +1 -1
- package/dist/session/views/index.js +1 -1
- package/dist/session/views/resolve.d.ts +6 -4
- package/dist/session/views/resolve.js +14 -6
- 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 -300
- 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
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { DOWNLOAD_PARTS_MEDIA_TYPE } from '@astrale-os/kernel-core/schema/kernel/syscalls/contracts';
|
|
2
|
+
import * as artifact from '@astrale-os/kernel-protocol/artifact';
|
|
3
|
+
import { ClientError, ProtocolError } from '../../errors/index.js';
|
|
4
|
+
import { decodeRejection } from './wire.js';
|
|
5
|
+
// A media type fits one request envelope (8 KiB); a part header adds a few fixed fields to it.
|
|
6
|
+
const MAXIMUM_PART_HEADER_BYTES = 16 * 1_024;
|
|
7
|
+
/** Decode the parts of one multi-slot download body, in order, without buffering content. */
|
|
8
|
+
export class PartReader {
|
|
9
|
+
source;
|
|
10
|
+
/** Response fields of the transfer, which every content of it carries. */
|
|
11
|
+
fields;
|
|
12
|
+
buffered = new Uint8Array();
|
|
13
|
+
/** Bytes of the declared body that have not been decoded yet. */
|
|
14
|
+
undecoded;
|
|
15
|
+
/** Content bytes of the current part that its consumer has not read yet. */
|
|
16
|
+
unread = 0;
|
|
17
|
+
current;
|
|
18
|
+
constructor(binary) {
|
|
19
|
+
if (binary.body instanceof Uint8Array ||
|
|
20
|
+
binary.mediaType !== DOWNLOAD_PARTS_MEDIA_TYPE ||
|
|
21
|
+
!('length' in binary) ||
|
|
22
|
+
binary.length === undefined) {
|
|
23
|
+
throw new ProtocolError('Content download returned no part body for its slot list.');
|
|
24
|
+
}
|
|
25
|
+
this.source = binary.body[Symbol.asyncIterator]();
|
|
26
|
+
this.undecoded = binary.length;
|
|
27
|
+
this.fields = binary.headers ?? {};
|
|
28
|
+
}
|
|
29
|
+
async next() {
|
|
30
|
+
await this.skip();
|
|
31
|
+
const length = new DataView((await this.exactly(4)).buffer).getUint32(0);
|
|
32
|
+
if (length === 0 || length > MAXIMUM_PART_HEADER_BYTES) {
|
|
33
|
+
throw new ProtocolError('Content download part header length is invalid.');
|
|
34
|
+
}
|
|
35
|
+
let header;
|
|
36
|
+
try {
|
|
37
|
+
header = JSON.parse(new TextDecoder().decode(await this.exactly(length)));
|
|
38
|
+
}
|
|
39
|
+
catch (cause) {
|
|
40
|
+
throw new ProtocolError('Content download part header is not JSON.', { cause });
|
|
41
|
+
}
|
|
42
|
+
if (header === null || typeof header !== 'object' || Array.isArray(header)) {
|
|
43
|
+
throw new ProtocolError('Content download part header is invalid.');
|
|
44
|
+
}
|
|
45
|
+
const { outcome, mediaType, size, code, headers } = header;
|
|
46
|
+
if (outcome === 'deferred')
|
|
47
|
+
return { outcome };
|
|
48
|
+
if (outcome === 'rejected') {
|
|
49
|
+
const rejection = decodeRejection(code);
|
|
50
|
+
if (rejection === undefined) {
|
|
51
|
+
throw new ProtocolError('Content download part rejection is invalid.');
|
|
52
|
+
}
|
|
53
|
+
return { outcome, code: rejection };
|
|
54
|
+
}
|
|
55
|
+
if (outcome !== 'content' ||
|
|
56
|
+
typeof mediaType !== 'string' ||
|
|
57
|
+
!Number.isSafeInteger(size) ||
|
|
58
|
+
size < 0 ||
|
|
59
|
+
size > this.undecoded) {
|
|
60
|
+
throw new ProtocolError('Content download part header is invalid.');
|
|
61
|
+
}
|
|
62
|
+
let canonical;
|
|
63
|
+
try {
|
|
64
|
+
canonical = artifact.canonicalMediaType(mediaType);
|
|
65
|
+
}
|
|
66
|
+
catch (cause) {
|
|
67
|
+
throw new ProtocolError('Content download part media type is invalid.', { cause });
|
|
68
|
+
}
|
|
69
|
+
// A content carries what its own download would: the transfer's fields, then its own.
|
|
70
|
+
const fields = { ...this.fields, ...decodeFields(headers) };
|
|
71
|
+
this.unread = size;
|
|
72
|
+
this.current = {};
|
|
73
|
+
return {
|
|
74
|
+
outcome,
|
|
75
|
+
content: {
|
|
76
|
+
mediaType: canonical,
|
|
77
|
+
length: size,
|
|
78
|
+
body: this.body(this.current),
|
|
79
|
+
...(Object.keys(fields).length === 0 ? {} : { headers: Object.freeze(fields) }),
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
async *body(part) {
|
|
84
|
+
while (this.current === part && this.unread > 0) {
|
|
85
|
+
const bytes = await this.content();
|
|
86
|
+
// The caller owns its chunks: one that shares its buffer with later parts is copied.
|
|
87
|
+
yield bytes.byteLength === bytes.buffer.byteLength ? bytes : bytes.slice();
|
|
88
|
+
}
|
|
89
|
+
if (this.current !== part) {
|
|
90
|
+
throw new ClientError('Content was skipped: its body was not read before the next one.');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** The body ends exactly after its last part. */
|
|
94
|
+
async end() {
|
|
95
|
+
await this.skip();
|
|
96
|
+
if (this.buffered.byteLength > 0 || !(await this.source.next()).done) {
|
|
97
|
+
throw new ProtocolError('Content download continued after its last part.');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async cancel() {
|
|
101
|
+
this.current = undefined;
|
|
102
|
+
try {
|
|
103
|
+
await this.source.return?.();
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
// The transfer already ended with its own outcome.
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** Pass an unread body; its consumer then learns that it was skipped. */
|
|
110
|
+
async skip() {
|
|
111
|
+
this.current = undefined;
|
|
112
|
+
while (this.unread > 0)
|
|
113
|
+
await this.content();
|
|
114
|
+
}
|
|
115
|
+
/** The next unread bytes of the current content, as the transport delivered them. */
|
|
116
|
+
async content() {
|
|
117
|
+
const bytes = await this.read(this.unread);
|
|
118
|
+
this.unread -= bytes.byteLength;
|
|
119
|
+
return bytes;
|
|
120
|
+
}
|
|
121
|
+
async exactly(count) {
|
|
122
|
+
const bytes = new Uint8Array(count);
|
|
123
|
+
for (let filled = 0; filled < count;) {
|
|
124
|
+
const part = await this.read(count - filled);
|
|
125
|
+
bytes.set(part, filled);
|
|
126
|
+
filled += part.byteLength;
|
|
127
|
+
}
|
|
128
|
+
return bytes;
|
|
129
|
+
}
|
|
130
|
+
async read(maximum) {
|
|
131
|
+
if (this.buffered.byteLength === 0) {
|
|
132
|
+
const next = await this.source.next();
|
|
133
|
+
if (next.done)
|
|
134
|
+
throw new ProtocolError('Content download ended inside a part.');
|
|
135
|
+
this.buffered = next.value;
|
|
136
|
+
}
|
|
137
|
+
const bytes = this.buffered.subarray(0, maximum);
|
|
138
|
+
this.buffered = this.buffered.subarray(bytes.byteLength);
|
|
139
|
+
this.undecoded -= bytes.byteLength;
|
|
140
|
+
return bytes;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** The response fields a part header adds to those of its transfer. */
|
|
144
|
+
function decodeFields(input) {
|
|
145
|
+
if (input === undefined)
|
|
146
|
+
return {};
|
|
147
|
+
if (input === null ||
|
|
148
|
+
typeof input !== 'object' ||
|
|
149
|
+
Array.isArray(input) ||
|
|
150
|
+
!Object.values(input).every((value) => typeof value === 'string')) {
|
|
151
|
+
throw new ProtocolError('Content download part fields are invalid.');
|
|
152
|
+
}
|
|
153
|
+
return input;
|
|
154
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { CODES } from '@astrale-os/kernel-protocol/errors';
|
|
2
|
+
import { ResponseError, TransportError } from '../../errors/index.js';
|
|
3
|
+
import { runSessionOperation } from '../context/index.js';
|
|
4
|
+
const MAXIMUM_ATTEMPTS = 3;
|
|
5
|
+
/** Repeat one content request that failed before any of its result was delivered. */
|
|
6
|
+
export async function retry(operation, request) {
|
|
7
|
+
for (let attempt = 0;; attempt++) {
|
|
8
|
+
try {
|
|
9
|
+
return await request();
|
|
10
|
+
}
|
|
11
|
+
catch (cause) {
|
|
12
|
+
if (!retryable(cause) || attempt + 1 === MAXIMUM_ATTEMPTS || operation.signal.aborted) {
|
|
13
|
+
throw cause;
|
|
14
|
+
}
|
|
15
|
+
await runSessionOperation(operation, (signal) => delay(200 * 2 ** attempt, signal));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function retryable(cause) {
|
|
20
|
+
return ((cause instanceof TransportError && cause.context.kind === 'invocation') ||
|
|
21
|
+
(cause instanceof ResponseError &&
|
|
22
|
+
(cause.reason?.code === 'BLOB_UNAVAILABLE' ||
|
|
23
|
+
cause.code === CODES.CANCELLED ||
|
|
24
|
+
cause.code === CODES.DEADLINE_EXCEEDED ||
|
|
25
|
+
cause.code === CODES.OUTCOME_UNKNOWN)));
|
|
26
|
+
}
|
|
27
|
+
function delay(ms, signal) {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
if (signal.aborted)
|
|
30
|
+
return reject(signal.reason);
|
|
31
|
+
const timer = setTimeout(() => {
|
|
32
|
+
signal.removeEventListener('abort', abort);
|
|
33
|
+
resolve();
|
|
34
|
+
}, ms);
|
|
35
|
+
const abort = () => {
|
|
36
|
+
clearTimeout(timer);
|
|
37
|
+
reject(signal.reason);
|
|
38
|
+
};
|
|
39
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Path } from '@astrale-os/kernel-core/path';
|
|
2
|
+
import type { Binary } from '../../client/index.js';
|
|
3
|
+
import type { ContentRejection, ContentUploadResult } from './api.js';
|
|
4
|
+
export declare const UPLOAD: Path.Projection;
|
|
5
|
+
export declare const DOWNLOAD: Path.Projection;
|
|
6
|
+
export declare function decodeUploadResult(input: unknown): ContentUploadResult;
|
|
7
|
+
/** The rejection a code names, or `undefined` when it names none. */
|
|
8
|
+
export declare function decodeRejection(code: unknown): ContentRejection | undefined;
|
|
9
|
+
/** A download whose exact size is declared; anything else is closed and refused. */
|
|
10
|
+
export declare function decodeDownload(input: Binary): Promise<Binary>;
|
|
11
|
+
/** Close a streamed body nobody will read. */
|
|
12
|
+
export declare function cancelBinary(input: Binary): Promise<void>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Path } from '@astrale-os/kernel-core/path';
|
|
2
|
+
import { download, upload } from '@astrale-os/kernel-core/schema/kernel/syscalls/references';
|
|
3
|
+
import * as artifact from '@astrale-os/kernel-protocol/artifact';
|
|
4
|
+
import { ClientError, ProtocolError } from '../../errors/index.js';
|
|
5
|
+
export const UPLOAD = Path.project(upload);
|
|
6
|
+
export const DOWNLOAD = Path.project(download);
|
|
7
|
+
const REJECTIONS = [
|
|
8
|
+
'BLOB_NOT_FOUND',
|
|
9
|
+
'BLOB_UNAVAILABLE',
|
|
10
|
+
'BLOB_INTEGRITY',
|
|
11
|
+
];
|
|
12
|
+
export function decodeUploadResult(input) {
|
|
13
|
+
if (input === null || typeof input !== 'object' || Array.isArray(input)) {
|
|
14
|
+
throw new ClientError('Content upload returned an invalid receipt.');
|
|
15
|
+
}
|
|
16
|
+
const value = input;
|
|
17
|
+
if (typeof value.receipt !== 'string' ||
|
|
18
|
+
value.receipt.length === 0 ||
|
|
19
|
+
typeof value.expiresAt !== 'string' ||
|
|
20
|
+
!Number.isFinite(Date.parse(value.expiresAt))) {
|
|
21
|
+
throw new ClientError('Content upload returned an invalid receipt.');
|
|
22
|
+
}
|
|
23
|
+
let ref;
|
|
24
|
+
try {
|
|
25
|
+
ref = artifact.accept(value.ref);
|
|
26
|
+
}
|
|
27
|
+
catch (cause) {
|
|
28
|
+
throw new ClientError('Content upload returned an invalid Ref.', { cause });
|
|
29
|
+
}
|
|
30
|
+
return Object.freeze({
|
|
31
|
+
receipt: value.receipt,
|
|
32
|
+
ref,
|
|
33
|
+
expiresAt: value.expiresAt,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/** The rejection a code names, or `undefined` when it names none. */
|
|
37
|
+
export function decodeRejection(code) {
|
|
38
|
+
return REJECTIONS.find((candidate) => candidate === code);
|
|
39
|
+
}
|
|
40
|
+
/** A download whose exact size is declared; anything else is closed and refused. */
|
|
41
|
+
export async function decodeDownload(input) {
|
|
42
|
+
// The HTTP transport sets `length` only from an admitted declared length, and its byte stream
|
|
43
|
+
// enforces that exact count through the final read.
|
|
44
|
+
if (input.body instanceof Uint8Array || !('length' in input) || input.length === undefined) {
|
|
45
|
+
await cancelBinary(input);
|
|
46
|
+
throw new ProtocolError('Content download omitted its exact content size.');
|
|
47
|
+
}
|
|
48
|
+
return input;
|
|
49
|
+
}
|
|
50
|
+
/** Close a streamed body nobody will read. */
|
|
51
|
+
export async function cancelBinary(input) {
|
|
52
|
+
if (input.body instanceof Uint8Array)
|
|
53
|
+
return;
|
|
54
|
+
try {
|
|
55
|
+
await input.body[Symbol.asyncIterator]().return?.();
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// Preserve the admission error after the response stream has been closed.
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { admitControlOptions, type SessionControlOptions } from './control.js';
|
|
2
|
-
export { DEFAULT_MAXIMUM_BUNDLE_BYTES,
|
|
2
|
+
export { DEFAULT_MAXIMUM_BUNDLE_BYTES, DEFAULT_MAXIMUM_RELEASE_BYTES, DEFAULT_MAXIMUM_RESPONSE_BYTES, DEFAULT_MAXIMUM_ROUTES, DEFAULT_TIMEOUT_MS, platformDuration, positive, } from './limits.js';
|
|
3
3
|
export { createSessionOperation, remainingSessionTime, runSessionOperation, sessionTransportOptions, type SessionOperation, } from './operation.js';
|
|
4
4
|
export { admitKernel, admitPolicy, allowEndpoint, kernelInvocationEndpoint, type SessionPolicy, } from './policy.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { admitControlOptions } from './control.js';
|
|
2
|
-
export { DEFAULT_MAXIMUM_BUNDLE_BYTES,
|
|
2
|
+
export { DEFAULT_MAXIMUM_BUNDLE_BYTES, DEFAULT_MAXIMUM_RELEASE_BYTES, DEFAULT_MAXIMUM_RESPONSE_BYTES, DEFAULT_MAXIMUM_ROUTES, DEFAULT_TIMEOUT_MS, platformDuration, positive, } from './limits.js';
|
|
3
3
|
export { createSessionOperation, remainingSessionTime, runSessionOperation, sessionTransportOptions, } from './operation.js';
|
|
4
4
|
export { admitKernel, admitPolicy, allowEndpoint, kernelInvocationEndpoint, } from './policy.js';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export declare const DEFAULT_MAXIMUM_RELEASE_BYTES: number;
|
|
2
|
-
export declare const DEFAULT_MAXIMUM_PUBLICATION_BYTES: number;
|
|
3
2
|
export declare const DEFAULT_MAXIMUM_BUNDLE_BYTES: number;
|
|
4
3
|
export declare const DEFAULT_MAXIMUM_RESPONSE_BYTES: number;
|
|
5
4
|
export declare const DEFAULT_TIMEOUT_MS = 30000;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export const DEFAULT_MAXIMUM_RELEASE_BYTES = 1024 * 1024;
|
|
2
|
-
export const DEFAULT_MAXIMUM_PUBLICATION_BYTES = 1024 * 1024;
|
|
3
2
|
export const DEFAULT_MAXIMUM_BUNDLE_BYTES = 16 * 1024 * 1024;
|
|
4
3
|
export const DEFAULT_MAXIMUM_RESPONSE_BYTES = 16 * 1024 * 1024;
|
|
5
4
|
export const DEFAULT_TIMEOUT_MS = 30_000;
|
|
@@ -20,4 +20,3 @@ export declare function sessionTransportOptions(operation: SessionOperation): {
|
|
|
20
20
|
export declare function sessionTransportOptions(operation: SessionOperation, idempotencyKey: RequestOptions['idempotencyKey']): RequestOptions;
|
|
21
21
|
/** Settle independently of a caller capability that ignores its supplied AbortSignal. */
|
|
22
22
|
export declare function runSessionOperation<Result>(operation: SessionOperation, task: (signal: AbortSignal) => Result | PromiseLike<Result>): Promise<Result>;
|
|
23
|
-
export declare function requireSessionOperation(operation: SessionOperation): void;
|
|
@@ -54,7 +54,7 @@ export async function runSessionOperation(operation, task) {
|
|
|
54
54
|
operation.signal.removeEventListener('abort', abort);
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
function requireSessionOperation(operation) {
|
|
58
58
|
if (!operation.signal.aborted)
|
|
59
59
|
return;
|
|
60
60
|
throw sessionInterruption(operation.signal.reason);
|
|
@@ -7,5 +7,4 @@ export interface SessionPolicy {
|
|
|
7
7
|
export declare function admitPolicy(input: SessionPolicy): Readonly<SessionPolicy>;
|
|
8
8
|
export declare function admitKernel(input: string, insecure: boolean): IssuerId;
|
|
9
9
|
export declare function kernelInvocationEndpoint(input: IssuerId): string;
|
|
10
|
-
export declare function websocketEndpoint(input: string, insecure: boolean): string;
|
|
11
10
|
export declare function allowEndpoint(url: string, policy: Readonly<SessionPolicy>): void;
|
|
@@ -39,22 +39,6 @@ export function admitKernel(input, insecure) {
|
|
|
39
39
|
export function kernelInvocationEndpoint(input) {
|
|
40
40
|
return `${input}/invoke`;
|
|
41
41
|
}
|
|
42
|
-
export function websocketEndpoint(input, insecure) {
|
|
43
|
-
let url;
|
|
44
|
-
try {
|
|
45
|
-
url = new URL(input);
|
|
46
|
-
}
|
|
47
|
-
catch (cause) {
|
|
48
|
-
throw new TypeError('Session WebSocket endpoint is invalid.', { cause });
|
|
49
|
-
}
|
|
50
|
-
if (url.username !== '' ||
|
|
51
|
-
url.password !== '' ||
|
|
52
|
-
url.hash !== '' ||
|
|
53
|
-
(url.protocol !== 'wss:' && !(insecure && url.protocol === 'ws:'))) {
|
|
54
|
-
throw new TypeError('Session WebSocket endpoint is invalid.');
|
|
55
|
-
}
|
|
56
|
-
return url.toString();
|
|
57
|
-
}
|
|
58
42
|
export function allowEndpoint(url, policy) {
|
|
59
43
|
const parsed = new URL(url);
|
|
60
44
|
if (parsed.protocol !== 'https:' && parsed.protocol !== 'wss:') {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { bundle } from '@astrale-os/kernel-dsl/v1';
|
|
2
|
-
import type {
|
|
2
|
+
import type { DomainRelease } from '@astrale-os/kernel-protocol/release';
|
|
3
3
|
import type { Fetch } from '../../transport/http/index.js';
|
|
4
4
|
import type { SessionOperation, SessionPolicy } from '../context/index.js';
|
|
5
5
|
import { ClientError } from '../../errors/index.js';
|
|
6
|
-
|
|
6
|
+
interface BundleDiscoveryOptions {
|
|
7
7
|
readonly fetch: Fetch;
|
|
8
8
|
readonly policy: Readonly<SessionPolicy>;
|
|
9
9
|
readonly maximumBytes: number;
|
|
@@ -15,7 +15,8 @@ export declare class BundleDiscovery {
|
|
|
15
15
|
private readonly options;
|
|
16
16
|
private retained?;
|
|
17
17
|
constructor(options: BundleDiscoveryOptions);
|
|
18
|
-
get(
|
|
18
|
+
get(release: DomainRelease, operation: SessionOperation): Promise<bundle.Bundle>;
|
|
19
19
|
clear(): void;
|
|
20
20
|
private fetch;
|
|
21
21
|
}
|
|
22
|
+
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { bundleUrl } from '@astrale-os/kernel-protocol/
|
|
2
|
-
import { decodeBundleValue } from '@astrale-os/kernel-protocol/publication/bundle';
|
|
1
|
+
import { bundleUrl, decodeBundle } from '@astrale-os/kernel-protocol/release';
|
|
3
2
|
import { ClientError } from '../../errors/index.js';
|
|
4
3
|
import { allowEndpoint } from '../context/index.js';
|
|
5
4
|
import { boundedResponse, requireExactResponse } from './response.js';
|
|
@@ -13,26 +12,26 @@ export class BundleDiscovery {
|
|
|
13
12
|
constructor(options) {
|
|
14
13
|
this.options = options;
|
|
15
14
|
}
|
|
16
|
-
async get(
|
|
17
|
-
const key = bundleKey(
|
|
18
|
-
allowEndpoint(
|
|
15
|
+
async get(release, operation) {
|
|
16
|
+
const key = bundleKey(release);
|
|
17
|
+
allowEndpoint(release.schema.bundle.href, this.options.policy);
|
|
19
18
|
if (this.retained?.key === key)
|
|
20
19
|
return this.retained.value;
|
|
21
|
-
const value = await this.fetch(
|
|
20
|
+
const value = await this.fetch(release, operation);
|
|
22
21
|
this.retained = { key, value };
|
|
23
22
|
return value;
|
|
24
23
|
}
|
|
25
24
|
clear() {
|
|
26
25
|
this.retained = undefined;
|
|
27
26
|
}
|
|
28
|
-
async fetch(
|
|
29
|
-
if (
|
|
27
|
+
async fetch(release, operation) {
|
|
28
|
+
if (release.schema.bundle.ref.size > this.options.maximumBytes) {
|
|
30
29
|
throw new ClientError('Bundle artifact exceeds its byte limit.');
|
|
31
30
|
}
|
|
32
|
-
const href =
|
|
33
|
-
const immutable = href === bundleUrl(
|
|
31
|
+
const href = release.schema.bundle.href;
|
|
32
|
+
const immutable = href === bundleUrl(release.identity.issuer, release.schema.bundle.ref);
|
|
34
33
|
const response = await runAcquisition(operation, 'bundle', 'unknown', 'Kernel bundle could not be retrieved.', (signal) => this.options.fetch(href, {
|
|
35
|
-
headers: { accept:
|
|
34
|
+
headers: { accept: release.schema.bundle.ref.mediaType },
|
|
36
35
|
// Omitting `cache` is the browser default; Workers reject the DOM-only 'default' mode.
|
|
37
36
|
cache: immutable ? undefined : 'no-cache',
|
|
38
37
|
redirect: 'manual',
|
|
@@ -46,27 +45,27 @@ export class BundleDiscovery {
|
|
|
46
45
|
}
|
|
47
46
|
if (!response.ok)
|
|
48
47
|
throw new ClientError(`Bundle retrieval returned HTTP ${response.status}.`);
|
|
49
|
-
if (response.headers.get('content-type') !==
|
|
48
|
+
if (response.headers.get('content-type') !== release.schema.bundle.ref.mediaType) {
|
|
50
49
|
throw new ClientError('Bundle artifact media type differs from its descriptor.');
|
|
51
50
|
}
|
|
52
51
|
const etag = response.headers.get('etag');
|
|
53
|
-
if (etag !== null && etag !== `"${
|
|
52
|
+
if (etag !== null && etag !== `"${release.schema.bundle.ref.digest}"`) {
|
|
54
53
|
throw new ClientError('Bundle response ETag differs from its descriptor.');
|
|
55
54
|
}
|
|
56
|
-
const bytes = await runAcquisition(operation, 'bundle', 'receive', 'Kernel bundle response could not be read.', (signal) => boundedResponse(response,
|
|
57
|
-
if (bytes.byteLength !==
|
|
55
|
+
const bytes = await runAcquisition(operation, 'bundle', 'receive', 'Kernel bundle response could not be read.', (signal) => boundedResponse(response, release.schema.bundle.ref.size, signal));
|
|
56
|
+
if (bytes.byteLength !== release.schema.bundle.ref.size) {
|
|
58
57
|
throw new ClientError('Bundle artifact size differs from its descriptor.');
|
|
59
58
|
}
|
|
60
|
-
return
|
|
59
|
+
return decodeBundle(release, bytes);
|
|
61
60
|
}
|
|
62
61
|
}
|
|
63
|
-
function bundleKey(
|
|
64
|
-
const { href, ref } =
|
|
62
|
+
function bundleKey(release) {
|
|
63
|
+
const { href, ref } = release.schema.bundle;
|
|
65
64
|
return JSON.stringify([
|
|
66
|
-
|
|
65
|
+
release.identity.issuer,
|
|
67
66
|
new URL(href).origin,
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
release.origin,
|
|
68
|
+
release.schema.revision,
|
|
70
69
|
ref.digest,
|
|
71
70
|
ref.mediaType,
|
|
72
71
|
ref.size,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { IssuerId } from '@astrale-os/kernel-core/auth/issuer';
|
|
2
|
-
import type { publication } from '@astrale-os/kernel-protocol';
|
|
3
2
|
import type { SessionOperation, SessionPolicy } from '../context/index.js';
|
|
4
3
|
import type { IntrinsicRelease } from './release.js';
|
|
5
4
|
import type { SessionSnapshot } from './snapshot.js';
|
|
@@ -21,8 +20,6 @@ export declare class SessionDiscovery {
|
|
|
21
20
|
private releaseFlight?;
|
|
22
21
|
constructor(kernel: IssuerId, policy: Readonly<SessionPolicy>, releases: IntrinsicReleases, bundles: BundleDiscovery, requireOpen: () => void, acquisitionOperation: () => SessionOperation);
|
|
23
22
|
release(operation: SessionOperation): Promise<IntrinsicRelease>;
|
|
24
|
-
/** @deprecated Successor: `release`. The v3 document of the current release. */
|
|
25
|
-
publication(operation: SessionOperation): Promise<publication.Publication>;
|
|
26
23
|
snapshot(operation: SessionOperation): Promise<SessionSnapshot>;
|
|
27
24
|
clear(): void;
|
|
28
25
|
private acquireSnapshot;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { runSessionOperation } from '../context/index.js';
|
|
2
2
|
import { rootViewCatalog } from '../views/index.js';
|
|
3
3
|
import { BundleUnavailableError } from './bundle.js';
|
|
4
|
-
import { designation, publicationOf } from './legacy/index.js';
|
|
5
4
|
import { createSessionSnapshot } from './snapshot.js';
|
|
6
5
|
export class SessionDiscovery {
|
|
7
6
|
kernel;
|
|
@@ -39,10 +38,6 @@ export class SessionDiscovery {
|
|
|
39
38
|
.catch(() => undefined);
|
|
40
39
|
return runSessionOperation(operation, () => flight);
|
|
41
40
|
}
|
|
42
|
-
/** @deprecated Successor: `release`. The v3 document of the current release. */
|
|
43
|
-
async publication(operation) {
|
|
44
|
-
return publicationOf(await this.release(operation));
|
|
45
|
-
}
|
|
46
41
|
snapshot(operation) {
|
|
47
42
|
this.requireOpen();
|
|
48
43
|
const current = this.flight;
|
|
@@ -67,26 +62,23 @@ export class SessionDiscovery {
|
|
|
67
62
|
let release = await this.release(operation);
|
|
68
63
|
let artifact;
|
|
69
64
|
try {
|
|
70
|
-
artifact = await this.bundles.get(
|
|
65
|
+
artifact = await this.bundles.get(release, operation);
|
|
71
66
|
}
|
|
72
67
|
catch (cause) {
|
|
73
68
|
if (!(cause instanceof BundleUnavailableError))
|
|
74
69
|
throw cause;
|
|
75
70
|
const current = await this.release(operation);
|
|
76
|
-
if (
|
|
71
|
+
if (current.digest === release.digest)
|
|
77
72
|
throw cause;
|
|
78
73
|
release = current;
|
|
79
|
-
artifact = await this.bundles.get(
|
|
74
|
+
artifact = await this.bundles.get(release, operation);
|
|
80
75
|
}
|
|
81
76
|
this.requireOpen();
|
|
82
|
-
if (this.retained !== undefined &&
|
|
83
|
-
designation(this.retained.release) === designation(release)) {
|
|
77
|
+
if (this.retained !== undefined && this.retained.release.digest === release.digest) {
|
|
84
78
|
return this.retained;
|
|
85
79
|
}
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
const views = rootViewCatalog(publication, artifact, this.policy);
|
|
89
|
-
const snapshot = createSessionSnapshot(this.kernel, release, publication, artifact, views);
|
|
80
|
+
const views = rootViewCatalog(release, artifact, this.policy);
|
|
81
|
+
const snapshot = createSessionSnapshot(this.kernel, release, artifact, views);
|
|
90
82
|
this.retained = snapshot;
|
|
91
83
|
return snapshot;
|
|
92
84
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { IssuerId } from '@astrale-os/kernel-core/auth/issuer';
|
|
2
|
-
import type { publication } from '@astrale-os/kernel-protocol';
|
|
3
2
|
import type { Fetch } from '../../transport/http/index.js';
|
|
4
3
|
import type { SessionOperation, SessionPolicy } from '../context/index.js';
|
|
5
4
|
import type { IntrinsicRelease } from './release.js';
|
|
@@ -10,8 +9,6 @@ export { boundedResponse, requireExactResponse } from './response.js';
|
|
|
10
9
|
export interface SessionDiscovery {
|
|
11
10
|
readonly kernel: IssuerId;
|
|
12
11
|
release(operation: SessionOperation): Promise<IntrinsicRelease>;
|
|
13
|
-
/** @deprecated Successor: `release`. */
|
|
14
|
-
publication(operation: SessionOperation): Promise<publication.Publication>;
|
|
15
12
|
snapshot(operation: SessionOperation): Promise<SessionSnapshot>;
|
|
16
13
|
clear(): void;
|
|
17
14
|
}
|
|
@@ -21,8 +18,6 @@ export interface SessionDiscoveryOptions {
|
|
|
21
18
|
readonly policy: Readonly<SessionPolicy>;
|
|
22
19
|
/** Bounds the source Kernel's own `release.json`. */
|
|
23
20
|
readonly maximumReleaseBytes: number;
|
|
24
|
-
/** Bounds the version 3 Publication a Host that predates `release.json` serves at `domain.json`. */
|
|
25
|
-
readonly maximumPublicationBytes: number;
|
|
26
21
|
readonly maximumBundleBytes: number;
|
|
27
22
|
readonly requireOpen: () => void;
|
|
28
23
|
readonly acquisitionOperation: () => SessionOperation;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { BundleDiscovery } from './bundle.js';
|
|
2
2
|
import { SessionDiscovery as SessionDiscoveryImplementation } from './discovery.js';
|
|
3
|
-
import { IntrinsicReleaseDiscovery, PublicationDiscovery } from './legacy/index.js';
|
|
4
3
|
import { ReleaseDiscovery } from './release.js';
|
|
5
4
|
export { boundedResponse, requireExactResponse } from './response.js';
|
|
6
5
|
export function createSessionDiscovery(options) {
|
|
7
6
|
const source = { kernel: options.kernel, fetch: options.fetch, policy: options.policy };
|
|
8
|
-
return new SessionDiscoveryImplementation(options.kernel, options.policy, new
|
|
7
|
+
return new SessionDiscoveryImplementation(options.kernel, options.policy, new ReleaseDiscovery({ ...source, maximumBytes: options.maximumReleaseBytes }), new BundleDiscovery({
|
|
9
8
|
fetch: options.fetch,
|
|
10
9
|
policy: options.policy,
|
|
11
10
|
maximumBytes: options.maximumBundleBytes,
|
|
@@ -3,9 +3,9 @@ import type { release } from '@astrale-os/kernel-protocol';
|
|
|
3
3
|
import type { Fetch } from '../../transport/http/index.js';
|
|
4
4
|
import type { SessionOperation } from '../context/index.js';
|
|
5
5
|
import { type SessionPolicy } from '../context/index.js';
|
|
6
|
-
/** The source Kernel's
|
|
7
|
-
export type IntrinsicRelease = release.DomainRelease
|
|
8
|
-
|
|
6
|
+
/** The source Kernel's exact intrinsic DomainRelease. */
|
|
7
|
+
export type IntrinsicRelease = release.DomainRelease;
|
|
8
|
+
interface ReleaseDiscoveryOptions {
|
|
9
9
|
readonly kernel: IssuerId;
|
|
10
10
|
readonly fetch: Fetch;
|
|
11
11
|
readonly policy: Readonly<SessionPolicy>;
|
|
@@ -22,8 +22,9 @@ export declare class ReleaseDiscovery {
|
|
|
22
22
|
constructor(options: ReleaseDiscoveryOptions);
|
|
23
23
|
/** The release admitted since construction, the last `invalidate()` or the last 404, if any. */
|
|
24
24
|
current(): release.DomainRelease | undefined;
|
|
25
|
-
/**
|
|
26
|
-
revalidate(operation: SessionOperation): Promise<release.DomainRelease
|
|
25
|
+
/** Revalidate the intrinsic release; an absent release is a discovery error. */
|
|
26
|
+
revalidate(operation: SessionOperation): Promise<release.DomainRelease>;
|
|
27
27
|
invalidate(): void;
|
|
28
28
|
private fetch;
|
|
29
29
|
}
|
|
30
|
+
export {};
|
|
@@ -19,14 +19,14 @@ export class ReleaseDiscovery {
|
|
|
19
19
|
current() {
|
|
20
20
|
return this.release;
|
|
21
21
|
}
|
|
22
|
-
/**
|
|
22
|
+
/** Revalidate the intrinsic release; an absent release is a discovery error. */
|
|
23
23
|
async revalidate(operation) {
|
|
24
24
|
const revision = this.revision;
|
|
25
25
|
const previous = this.release;
|
|
26
26
|
const discovered = await this.fetch(operation, previous);
|
|
27
27
|
if (revision !== this.revision)
|
|
28
28
|
return this.revalidate(operation);
|
|
29
|
-
const retained =
|
|
29
|
+
const retained = previous?.digest === discovered.digest ? previous : discovered;
|
|
30
30
|
this.release = retained;
|
|
31
31
|
return retained;
|
|
32
32
|
}
|
|
@@ -49,7 +49,7 @@ export class ReleaseDiscovery {
|
|
|
49
49
|
if (response.status === 404) {
|
|
50
50
|
// Cleanup must not hold discovery open on an injected body cancellation.
|
|
51
51
|
void response.body?.cancel().catch(() => undefined);
|
|
52
|
-
|
|
52
|
+
throw new ClientError('Release discovery returned HTTP 404.');
|
|
53
53
|
}
|
|
54
54
|
if (response.status === 304) {
|
|
55
55
|
if (previous === undefined) {
|
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import type { IssuerId } from '@astrale-os/kernel-core/auth/issuer';
|
|
2
2
|
import type { bundle } from '@astrale-os/kernel-dsl/v1';
|
|
3
|
-
import type { publication } from '@astrale-os/kernel-protocol';
|
|
4
3
|
import type { ViewCatalog } from '../views/index.js';
|
|
5
4
|
import type { IntrinsicRelease } from './release.js';
|
|
6
5
|
/** Coherent public observation acquired through one Client Session at one intrinsic release. */
|
|
7
6
|
export interface SessionSnapshot {
|
|
8
7
|
readonly kernel: IssuerId;
|
|
9
8
|
readonly release: IntrinsicRelease;
|
|
10
|
-
/**
|
|
11
|
-
* Bundle and root View provenance use this v3 document's ETag.
|
|
12
|
-
*
|
|
13
|
-
* @deprecated Use `release`.
|
|
14
|
-
*/
|
|
15
|
-
readonly publication: publication.Publication;
|
|
16
9
|
readonly bundle: bundle.Bundle;
|
|
17
10
|
readonly views: ViewCatalog;
|
|
18
11
|
}
|
|
19
|
-
export declare function createSessionSnapshot(kernel: IssuerId, release: IntrinsicRelease,
|
|
12
|
+
export declare function createSessionSnapshot(kernel: IssuerId, release: IntrinsicRelease, artifact: bundle.Bundle, views: ViewCatalog): SessionSnapshot;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export function createSessionSnapshot(kernel, release,
|
|
2
|
-
return Object.freeze({ kernel, release,
|
|
1
|
+
export function createSessionSnapshot(kernel, release, artifact, views) {
|
|
2
|
+
return Object.freeze({ kernel, release, bundle: artifact, views });
|
|
3
3
|
}
|