@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
package/dist/session/bound.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { createAuth } from '../auth/auth.js';
|
|
2
2
|
import { call as createCall, } from '../client/index.js';
|
|
3
|
+
import { createExecution } from '../execution/index.js';
|
|
3
4
|
import { createGraph } from '../graph/index.js';
|
|
5
|
+
import { unavailableViewCatalog } from './views/legacy/index.js';
|
|
4
6
|
/** Capture one Session into the ordinary graph, auth, and invocation Kernel journey. */
|
|
5
7
|
export function bindSession(source, controls) {
|
|
6
8
|
if (source === null || typeof source !== 'object')
|
|
@@ -17,46 +19,73 @@ export function bindSession(source, controls) {
|
|
|
17
19
|
invalid();
|
|
18
20
|
const uploadSource = capture(contentSource, 'upload');
|
|
19
21
|
const downloadSource = capture(contentSource, 'download');
|
|
20
|
-
const
|
|
22
|
+
const viewSource = capture(source, 'view');
|
|
23
|
+
const viewsForSource = source.viewsFor === undefined ? unavailableViewCatalog : capture(source, 'viewsFor');
|
|
21
24
|
const schemaSource = captureSchema(source.schema);
|
|
22
|
-
const dispatch = ((input, options) => dispatchSource(input,
|
|
25
|
+
const dispatch = ((input, options) => dispatchSource(input, mergeOptions(options, admittedControls)));
|
|
23
26
|
const admit = (input, options) => admitSource(input, mergeOptions(options, admittedControls));
|
|
24
|
-
const call = ((input, options) => callSource(input,
|
|
25
|
-
const invoke = ((reference, input, options) => invokeSource(reference, input,
|
|
26
|
-
const stream = (input, options) => streamSource(input,
|
|
27
|
-
const binary = (input, options) => binarySource(input,
|
|
27
|
+
const call = ((input, options) => callSource(input, mergeOptions(options, admittedControls)));
|
|
28
|
+
const invoke = ((reference, input, options) => invokeSource(reference, input, mergeOptions(options, admittedControls)));
|
|
29
|
+
const stream = (input, options) => streamSource(input, mergeOptions(options, admittedControls));
|
|
30
|
+
const binary = (input, options) => binarySource(input, mergeOptions(options, admittedControls));
|
|
28
31
|
const upload = (input, options) => uploadSource(input, mergeOptions(options, admittedControls));
|
|
29
32
|
// Both forms share the bound controls; the source selects the form from its argument.
|
|
30
|
-
const download = ((input, options) => downloadSource(input,
|
|
33
|
+
const download = ((input, options) => downloadSource(input, mergeOptions(options, admittedControls)));
|
|
31
34
|
const content = Object.freeze({ upload, download });
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
35
|
+
// Both forms share the bound controls; the source selects the form from its argument.
|
|
36
|
+
const view = ((input, options) => viewSource(input, mergeOptions(options, admittedControls)));
|
|
37
|
+
const viewsFor = (domain, options) => viewsForSource(domain, mergeOptions(options, admittedControls));
|
|
38
|
+
const install = (request, options) => schemaSource.install(request, mergeOptions(options, admittedControls));
|
|
39
|
+
const uninstall = (request, options) => schemaSource.uninstall(request, mergeOptions(options, admittedControls));
|
|
40
|
+
const inspect = (origin, options) => schemaSource.inspect(origin, mergeOptions(options, admittedControls));
|
|
41
|
+
const bundle = (origin, options) => schemaSource.bundle(origin, mergeOptions(options, admittedControls));
|
|
42
|
+
const dependencies = (origin, options) => schemaSource.dependencies(origin, mergeOptions(options, admittedControls));
|
|
43
|
+
const installed = (options) => schemaSource.installed(mergeOptions(options, admittedControls));
|
|
44
|
+
const installs = schemaSource.installation;
|
|
45
|
+
const installation = Object.freeze({
|
|
46
|
+
status: (execution, options) => installs.status(execution, mergeOptions(options, admittedControls)),
|
|
47
|
+
result: (execution, wait, options) => installs.result(execution, wait, mergeOptions(options, admittedControls)),
|
|
48
|
+
watch: (execution, watch, options) => installs.watch(execution, watch, mergeOptions(options, admittedControls)),
|
|
49
|
+
apply: (execution, command, options) => installs.apply(execution, command, mergeOptions(options, admittedControls)),
|
|
50
|
+
abort: (execution, attempt, options) => installs.abort(execution, attempt, mergeOptions(options, admittedControls)),
|
|
51
|
+
cancel: (execution, input, options) => installs.cancel(execution, input, mergeOptions(options, admittedControls)),
|
|
52
|
+
resume: (execution, options) => installs.resume(execution, mergeOptions(options, admittedControls)),
|
|
53
|
+
delete: (execution, options) => installs.delete(execution, mergeOptions(options, admittedControls)),
|
|
54
|
+
});
|
|
55
|
+
const uninstalls = schemaSource.uninstallation;
|
|
56
|
+
const uninstallation = Object.freeze({
|
|
57
|
+
status: (execution, options) => uninstalls.status(execution, mergeOptions(options, admittedControls)),
|
|
58
|
+
result: (execution, wait, options) => uninstalls.result(execution, wait, mergeOptions(options, admittedControls)),
|
|
59
|
+
cancel: (execution, input, options) => uninstalls.cancel(execution, input, mergeOptions(options, admittedControls)),
|
|
60
|
+
resume: (execution, options) => uninstalls.resume(execution, mergeOptions(options, admittedControls)),
|
|
61
|
+
delete: (execution, options) => uninstalls.delete(execution, mergeOptions(options, admittedControls)),
|
|
62
|
+
});
|
|
39
63
|
const schema = Object.freeze({
|
|
40
64
|
install,
|
|
65
|
+
installation,
|
|
41
66
|
uninstall,
|
|
67
|
+
uninstallation,
|
|
42
68
|
inspect,
|
|
43
69
|
bundle,
|
|
44
70
|
dependencies,
|
|
45
71
|
installed,
|
|
46
72
|
});
|
|
47
73
|
const graph = createGraph(call);
|
|
74
|
+
const execution = createExecution(dispatch);
|
|
48
75
|
const auth = createAuth((target, input, options) => call(createCall(target, input), options), admit);
|
|
49
76
|
return Object.freeze({
|
|
50
77
|
...graph,
|
|
51
78
|
kernel: source.kernel,
|
|
52
79
|
auth,
|
|
53
80
|
schema,
|
|
81
|
+
execution,
|
|
54
82
|
dispatch,
|
|
55
83
|
call,
|
|
56
84
|
invoke,
|
|
57
85
|
stream,
|
|
58
86
|
binary,
|
|
59
87
|
content,
|
|
88
|
+
view,
|
|
60
89
|
viewsFor,
|
|
61
90
|
});
|
|
62
91
|
}
|
|
@@ -79,12 +108,6 @@ function admitControls(input) {
|
|
|
79
108
|
}
|
|
80
109
|
return Object.freeze({ signal: input.signal, deadline: input.deadline });
|
|
81
110
|
}
|
|
82
|
-
function requestOptions(options, controls) {
|
|
83
|
-
return mergeOptions(options, controls);
|
|
84
|
-
}
|
|
85
|
-
function controlOptions(options, controls) {
|
|
86
|
-
return mergeOptions(options, controls);
|
|
87
|
-
}
|
|
88
111
|
function mergeOptions(options, controls) {
|
|
89
112
|
if (controls === undefined)
|
|
90
113
|
return options;
|
|
@@ -106,9 +129,32 @@ function capture(source, key) {
|
|
|
106
129
|
function captureSchema(input) {
|
|
107
130
|
if (input === null || typeof input !== 'object')
|
|
108
131
|
invalid();
|
|
132
|
+
const installation = input.installation;
|
|
133
|
+
if (installation === null || typeof installation !== 'object')
|
|
134
|
+
invalid();
|
|
135
|
+
const uninstallation = input.uninstallation;
|
|
136
|
+
if (uninstallation === null || typeof uninstallation !== 'object')
|
|
137
|
+
invalid();
|
|
109
138
|
return Object.freeze({
|
|
110
139
|
install: capture(input, 'install'),
|
|
140
|
+
installation: Object.freeze({
|
|
141
|
+
status: capture(installation, 'status'),
|
|
142
|
+
result: capture(installation, 'result'),
|
|
143
|
+
watch: capture(installation, 'watch'),
|
|
144
|
+
apply: capture(installation, 'apply'),
|
|
145
|
+
abort: capture(installation, 'abort'),
|
|
146
|
+
cancel: capture(installation, 'cancel'),
|
|
147
|
+
resume: capture(installation, 'resume'),
|
|
148
|
+
delete: capture(installation, 'delete'),
|
|
149
|
+
}),
|
|
111
150
|
uninstall: capture(input, 'uninstall'),
|
|
151
|
+
uninstallation: Object.freeze({
|
|
152
|
+
status: capture(uninstallation, 'status'),
|
|
153
|
+
result: capture(uninstallation, 'result'),
|
|
154
|
+
cancel: capture(uninstallation, 'cancel'),
|
|
155
|
+
resume: capture(uninstallation, 'resume'),
|
|
156
|
+
delete: capture(uninstallation, 'delete'),
|
|
157
|
+
}),
|
|
112
158
|
inspect: capture(input, 'inspect'),
|
|
113
159
|
bundle: capture(input, 'bundle'),
|
|
114
160
|
dependencies: capture(input, 'dependencies'),
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import type { BinaryRequestBody } from '@astrale-os/kernel-core/callable';
|
|
1
2
|
import type { Path } from '@astrale-os/kernel-core/path';
|
|
2
3
|
import type { schema } from '@astrale-os/kernel-dsl/v1';
|
|
3
4
|
import type { Ref } from '@astrale-os/kernel-protocol/artifact';
|
|
4
5
|
import type { Binary, Input, Result } from '../../client/index.js';
|
|
6
|
+
import type { BinaryBody } from '../../transport/http/binary-request.js';
|
|
5
7
|
import type { SessionControlOptions, SessionOperation } from '../context/index.js';
|
|
6
8
|
export interface ContentLocation {
|
|
7
9
|
readonly node: string;
|
|
@@ -27,8 +29,14 @@ export type ContentDownload = {
|
|
|
27
29
|
readonly outcome: 'rejected';
|
|
28
30
|
readonly code: ContentRejection;
|
|
29
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* The bytes one upload stores. A Blob, File, or Uint8Array is read again by every attempt. A stream
|
|
34
|
+
* must yield exactly `length` bytes; the upload consumes it in one attempt, and cancels it if it
|
|
35
|
+
* fails before reading it through its end. A Domain's own binary input has this shape.
|
|
36
|
+
*/
|
|
37
|
+
export type ContentSource = Blob | Uint8Array | BinaryRequestBody;
|
|
30
38
|
export interface ContentApi {
|
|
31
|
-
upload(source:
|
|
39
|
+
upload(source: ContentSource, options: ContentUploadOptions): Promise<ContentUploadResult>;
|
|
32
40
|
download(location: ContentLocation, options?: SessionControlOptions): Promise<Binary>;
|
|
33
41
|
/**
|
|
34
42
|
* One outcome per location, in order, within one time budget for the whole list. Consume each
|
|
@@ -39,7 +47,7 @@ export interface ContentApi {
|
|
|
39
47
|
/** What the Session lends the content transfer: its time budgets and its routed dispatch. */
|
|
40
48
|
export interface ContentDependencies {
|
|
41
49
|
readonly operation: (options: SessionControlOptions) => SessionOperation;
|
|
42
|
-
readonly dispatch: (target: Path, input: Input, operation: SessionOperation, body?:
|
|
50
|
+
readonly dispatch: (target: Path, input: Input, operation: SessionOperation, body?: BinaryBody) => Promise<Result>;
|
|
43
51
|
}
|
|
44
52
|
/** Transfer immutable content over the authenticated Session routing conversation. */
|
|
45
53
|
export declare function createContentApi(dependencies: ContentDependencies): ContentApi;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { cancelUnsent } from '../../transport/http/binary-request.js';
|
|
1
2
|
import { requireResultKind } from '../routing/index.js';
|
|
2
3
|
import { downloadBatch } from './batch.js';
|
|
3
4
|
import { acceptBody, acceptControls, acceptLocation, acceptMediaType } from './input.js';
|
|
@@ -7,10 +8,18 @@ import { DOWNLOAD, UPLOAD, decodeDownload, decodeUploadResult } from './wire.js'
|
|
|
7
8
|
export function createContentApi(dependencies) {
|
|
8
9
|
async function upload(source, options) {
|
|
9
10
|
const body = acceptBody(source);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
try {
|
|
12
|
+
const mediaType = acceptMediaType(options?.mediaType);
|
|
13
|
+
const operation = dependencies.operation(acceptControls(options));
|
|
14
|
+
const send = () => dependencies.dispatch(UPLOAD, { mediaType }, operation, body);
|
|
15
|
+
// A stream cannot be read twice: it has one attempt.
|
|
16
|
+
const result = await (body.kind === 'replayable' ? retry(operation, send) : send());
|
|
17
|
+
return decodeUploadResult(requireResultKind('value', result).value);
|
|
18
|
+
}
|
|
19
|
+
catch (cause) {
|
|
20
|
+
cancelUnsent(body);
|
|
21
|
+
throw cause;
|
|
22
|
+
}
|
|
14
23
|
}
|
|
15
24
|
function download(input, options) {
|
|
16
25
|
if (Array.isArray(input)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createContentApi, type ContentApi, type ContentDownload, type ContentLocation, type ContentRejection, type ContentUploadOptions, type ContentUploadResult, } from './api.js';
|
|
1
|
+
export { createContentApi, type ContentApi, type ContentDownload, type ContentLocation, type ContentRejection, type ContentSource, type ContentUploadOptions, type ContentUploadResult, } from './api.js';
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import type { BinaryBody } from '../../transport/http/binary-request.js';
|
|
1
2
|
import type { SessionControlOptions } from '../context/index.js';
|
|
2
3
|
import type { ContentLocation } from './api.js';
|
|
3
4
|
/** One canonical content location, as a download request carries it. */
|
|
4
5
|
export type Slot = Readonly<Record<'node' | 'property', string>>;
|
|
5
6
|
export declare function acceptLocation(input: ContentLocation): Slot;
|
|
6
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The bytes of one upload: a Blob, an owned snapshot of a Uint8Array, or a byte stream with its
|
|
9
|
+
* exact length, which the upload consumes.
|
|
10
|
+
*/
|
|
11
|
+
export declare function acceptBody(input: unknown): BinaryBody;
|
|
7
12
|
export declare function acceptMediaType(input: unknown): string;
|
|
8
13
|
/** The caller's controls, with the content transfer's own default time budget. */
|
|
9
14
|
export declare function acceptControls(input: SessionControlOptions | undefined): SessionControlOptions;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NodeId } from '@astrale-os/kernel-core/graph/node';
|
|
2
2
|
import { PropertyKey } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
3
3
|
import * as artifact from '@astrale-os/kernel-protocol/artifact';
|
|
4
|
+
import { acceptBinaryBody, replayableBody } from '../../transport/http/binary-request.js';
|
|
4
5
|
import { admitControlOptions } from '../context/index.js';
|
|
5
6
|
const CONTENT_TIMEOUT_MS = 30 * 60 * 1_000;
|
|
6
7
|
export function acceptLocation(input) {
|
|
@@ -9,17 +10,24 @@ export function acceptLocation(input) {
|
|
|
9
10
|
}
|
|
10
11
|
return Object.freeze({ node: NodeId(input.node), property: PropertyKey(input.property) });
|
|
11
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* The bytes of one upload: a Blob, an owned snapshot of a Uint8Array, or a byte stream with its
|
|
15
|
+
* exact length, which the upload consumes.
|
|
16
|
+
*/
|
|
12
17
|
export function acceptBody(input) {
|
|
13
|
-
if (typeof Blob !== 'undefined' && input instanceof Blob)
|
|
14
|
-
return input;
|
|
15
18
|
if (input instanceof Uint8Array) {
|
|
16
19
|
// Blob snapshots an ArrayBuffer view; a SharedArrayBuffer view needs an owned copy.
|
|
17
20
|
const bytes = input.buffer instanceof ArrayBuffer
|
|
18
21
|
? input
|
|
19
22
|
: new Uint8Array(input);
|
|
20
|
-
return new Blob([bytes]);
|
|
23
|
+
return replayableBody(new Blob([bytes]));
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
return acceptBinaryBody(input);
|
|
27
|
+
}
|
|
28
|
+
catch (cause) {
|
|
29
|
+
throw new TypeError('Content upload source must be a Blob, File, Uint8Array, or { body: ReadableStream, length }.', { cause });
|
|
21
30
|
}
|
|
22
|
-
throw new TypeError('Content upload source must be a Blob, File, or Uint8Array.');
|
|
23
31
|
}
|
|
24
32
|
export function acceptMediaType(input) {
|
|
25
33
|
if (typeof input !== 'string')
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import type { SessionOperation } from '../context/index.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Repeat one content request that failed before any of its result was delivered: after a pause of
|
|
4
|
+
* at least 100 ms, then 200 ms, or of the delay a refusal prescribes when it is longer, each
|
|
5
|
+
* lengthened by a random share of up to as much again.
|
|
6
|
+
*/
|
|
3
7
|
export declare function retry<Result>(operation: SessionOperation, request: () => Promise<Result>): Promise<Result>;
|
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import { CODES } from '@astrale-os/kernel-protocol/errors';
|
|
2
|
-
import { ResponseError, TransportError } from '../../errors/index.js';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
2
|
+
import { ResponseError, retryAfterOf, TransportError } from '../../errors/index.js';
|
|
3
|
+
import { retrySessionRequest } from '../retry.js';
|
|
4
|
+
/**
|
|
5
|
+
* Repeat one content request that failed before any of its result was delivered: after a pause of
|
|
6
|
+
* at least 100 ms, then 200 ms, or of the delay a refusal prescribes when it is longer, each
|
|
7
|
+
* lengthened by a random share of up to as much again.
|
|
8
|
+
*/
|
|
9
|
+
export function retry(operation, request) {
|
|
10
|
+
return retrySessionRequest(operation, pause, request);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The pause after failed attempt `failed`: at least 100 ms doubled at each attempt, or the delay a
|
|
14
|
+
* refusal prescribes when it is longer, and up to as much again drawn at random, so that clients
|
|
15
|
+
* refused together do not all come back at once.
|
|
16
|
+
*/
|
|
17
|
+
function pause(cause, failed) {
|
|
18
|
+
const after = retryAfterOf(cause);
|
|
19
|
+
if (after === undefined && !retryable(cause))
|
|
20
|
+
return undefined;
|
|
21
|
+
const least = Math.max(after ?? 0, 100 * 2 ** (failed - 1));
|
|
22
|
+
return least + Math.random() * least;
|
|
18
23
|
}
|
|
19
24
|
function retryable(cause) {
|
|
20
25
|
return ((cause instanceof TransportError && cause.context.kind === 'invocation') ||
|
|
@@ -24,18 +29,3 @@ function retryable(cause) {
|
|
|
24
29
|
cause.code === CODES.DEADLINE_EXCEEDED ||
|
|
25
30
|
cause.code === CODES.OUTCOME_UNKNOWN)));
|
|
26
31
|
}
|
|
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
|
-
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { admitControlOptions, type SessionControlOptions } from './control.js';
|
|
2
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
|
-
export { createSessionOperation, remainingSessionTime, runSessionOperation, sessionTransportOptions, type SessionOperation, } from './operation.js';
|
|
3
|
+
export { createSessionOperation, pauseSessionOperation, 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
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
|
-
export { createSessionOperation, remainingSessionTime, runSessionOperation, sessionTransportOptions, } from './operation.js';
|
|
3
|
+
export { createSessionOperation, pauseSessionOperation, remainingSessionTime, runSessionOperation, sessionTransportOptions, } from './operation.js';
|
|
4
4
|
export { admitKernel, admitPolicy, allowEndpoint, kernelInvocationEndpoint, } from './policy.js';
|
|
@@ -20,3 +20,5 @@ 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
|
+
/** Wait `ms` before another attempt, ending early with the operation's interruption. */
|
|
24
|
+
export declare function pauseSessionOperation(operation: SessionOperation, ms: number): Promise<void>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SessionError } from '../../errors/index.js';
|
|
2
|
+
import { pause } from '../../transport/index.js';
|
|
2
3
|
/** Create one total wall-clock budget for a complete public Client Session operation. */
|
|
3
4
|
export function createSessionOperation(lifecycle, input, defaultTimeoutMs) {
|
|
4
5
|
const timeoutMs = input?.timeoutMs ?? defaultTimeoutMs;
|
|
@@ -54,6 +55,10 @@ export async function runSessionOperation(operation, task) {
|
|
|
54
55
|
operation.signal.removeEventListener('abort', abort);
|
|
55
56
|
});
|
|
56
57
|
}
|
|
58
|
+
/** Wait `ms` before another attempt, ending early with the operation's interruption. */
|
|
59
|
+
export function pauseSessionOperation(operation, ms) {
|
|
60
|
+
return runSessionOperation(operation, (signal) => pause(ms, signal));
|
|
61
|
+
}
|
|
57
62
|
function requireSessionOperation(operation) {
|
|
58
63
|
if (!operation.signal.aborted)
|
|
59
64
|
return;
|
|
@@ -31,13 +31,14 @@ export function credentials(source) {
|
|
|
31
31
|
const notify = options.onChange?.bind(options);
|
|
32
32
|
// The threshold is the coverage the caller already declared, never a separate guessed constant.
|
|
33
33
|
const marginMs = delegationCoverageMs(ttlSeconds);
|
|
34
|
-
|
|
35
|
-
let state = Object.freeze(
|
|
34
|
+
const initial = options.initial === undefined ? undefined : admitInitial(options.initial);
|
|
35
|
+
let state = Object.freeze(initial === undefined
|
|
36
36
|
? { status: 'empty' }
|
|
37
|
-
: { status: 'valid', credential:
|
|
38
|
-
let
|
|
39
|
-
let controller;
|
|
37
|
+
: { status: 'valid', credential: initial });
|
|
38
|
+
let minting;
|
|
40
39
|
let waiting = 0;
|
|
40
|
+
/** A caller without a signal keeps the mint in flight alive; anticipation does not. */
|
|
41
|
+
let unsignalled = false;
|
|
41
42
|
let anticipating = false;
|
|
42
43
|
let refreshTimer;
|
|
43
44
|
let expiryTimer;
|
|
@@ -54,7 +55,12 @@ export function credentials(source) {
|
|
|
54
55
|
async function resolve(_call, signal) {
|
|
55
56
|
return { credential: (await acquire(signal)).credential };
|
|
56
57
|
}
|
|
58
|
+
/** The credential the published state holds, if any. */
|
|
59
|
+
function held() {
|
|
60
|
+
return 'credential' in state ? state.credential : undefined;
|
|
61
|
+
}
|
|
57
62
|
function acquire(signal) {
|
|
63
|
+
const current = held();
|
|
58
64
|
if (current !== undefined && covers(current))
|
|
59
65
|
return Promise.resolve(current);
|
|
60
66
|
return share(signal);
|
|
@@ -75,9 +81,11 @@ export function credentials(source) {
|
|
|
75
81
|
function share(signal) {
|
|
76
82
|
if (signal?.aborted === true)
|
|
77
83
|
return Promise.reject(signal.reason);
|
|
78
|
-
const
|
|
79
|
-
if (signal === undefined)
|
|
80
|
-
|
|
84
|
+
const flight = minting ?? begin();
|
|
85
|
+
if (signal === undefined) {
|
|
86
|
+
unsignalled = true;
|
|
87
|
+
return flight.promise;
|
|
88
|
+
}
|
|
81
89
|
waiting += 1;
|
|
82
90
|
let settled = false;
|
|
83
91
|
return new Promise((complete, fail) => {
|
|
@@ -88,8 +96,8 @@ export function credentials(source) {
|
|
|
88
96
|
waiting -= 1;
|
|
89
97
|
signal.removeEventListener('abort', cancel);
|
|
90
98
|
// Nobody is waiting and nobody is anticipating: the mint has no beneficiary left.
|
|
91
|
-
if (waiting === 0 && !anticipating)
|
|
92
|
-
controller
|
|
99
|
+
if (waiting === 0 && !anticipating && !unsignalled)
|
|
100
|
+
minting?.controller.abort(signal.reason);
|
|
93
101
|
};
|
|
94
102
|
const cancel = () => {
|
|
95
103
|
const reason = signal.reason;
|
|
@@ -97,7 +105,7 @@ export function credentials(source) {
|
|
|
97
105
|
fail(reason);
|
|
98
106
|
};
|
|
99
107
|
signal.addEventListener('abort', cancel, { once: true });
|
|
100
|
-
|
|
108
|
+
flight.promise.then((credential) => {
|
|
101
109
|
if (settled)
|
|
102
110
|
return;
|
|
103
111
|
settled = true;
|
|
@@ -114,21 +122,28 @@ export function credentials(source) {
|
|
|
114
122
|
});
|
|
115
123
|
});
|
|
116
124
|
}
|
|
125
|
+
/** Begin a mint; without a mint capability, the returned one has already failed and is not held. */
|
|
117
126
|
function begin() {
|
|
127
|
+
const controller = new AbortController();
|
|
118
128
|
if (mint === undefined) {
|
|
119
129
|
const error = new ClientError('Session credential needs renewal, but no mint was supplied.');
|
|
120
130
|
settleFailure(error);
|
|
121
|
-
return Promise.reject(error);
|
|
131
|
+
return { promise: Promise.reject(error), controller };
|
|
122
132
|
}
|
|
123
133
|
const renew = mint;
|
|
134
|
+
const current = held();
|
|
124
135
|
publish({ status: 'refreshing', ...(current === undefined ? {} : { credential: current }) });
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
const pending = (async () => {
|
|
136
|
+
unsignalled = false;
|
|
137
|
+
const signal = AbortSignal.any([controller.signal, AbortSignal.timeout(MINT_TIMEOUT_MS)]);
|
|
138
|
+
const promise = (async () => {
|
|
129
139
|
try {
|
|
130
|
-
|
|
131
|
-
|
|
140
|
+
// A mint that throws instead of rejecting fails this attempt alike: the executor turns the
|
|
141
|
+
// throw into a rejection, so the attempt settles only after it yields, once `minting`
|
|
142
|
+
// holds it, and the cleanup below releases it for the next acquisition.
|
|
143
|
+
const returned = new Promise((complete) => {
|
|
144
|
+
complete(renew(signal));
|
|
145
|
+
});
|
|
146
|
+
const minted = admitMinted(await returned);
|
|
132
147
|
attempt = 0;
|
|
133
148
|
publish({ status: 'valid', credential: minted });
|
|
134
149
|
if (anticipating)
|
|
@@ -140,21 +155,20 @@ export function credentials(source) {
|
|
|
140
155
|
throw error;
|
|
141
156
|
}
|
|
142
157
|
finally {
|
|
143
|
-
|
|
144
|
-
controller = undefined;
|
|
158
|
+
minting = undefined;
|
|
145
159
|
}
|
|
146
160
|
})();
|
|
147
|
-
|
|
161
|
+
minting = { promise, controller };
|
|
148
162
|
// A rejection reaches every waiter; keep an unattached one from surfacing as unhandled.
|
|
149
|
-
|
|
150
|
-
return
|
|
163
|
+
promise.catch(() => undefined);
|
|
164
|
+
return minting;
|
|
151
165
|
}
|
|
152
166
|
function settleFailure(error) {
|
|
167
|
+
const current = held();
|
|
153
168
|
if (current !== undefined && current.expiresAt > Date.now()) {
|
|
154
169
|
publish({ status: 'degraded', credential: current, error });
|
|
155
170
|
}
|
|
156
171
|
else {
|
|
157
|
-
current = undefined;
|
|
158
172
|
publish({ status: 'expired', error });
|
|
159
173
|
}
|
|
160
174
|
if (anticipating)
|
|
@@ -165,8 +179,9 @@ export function credentials(source) {
|
|
|
165
179
|
clearTimers();
|
|
166
180
|
if (!anticipating)
|
|
167
181
|
return;
|
|
182
|
+
const current = held();
|
|
168
183
|
if (current === undefined) {
|
|
169
|
-
void
|
|
184
|
+
void (minting ?? begin()).promise.catch(() => undefined);
|
|
170
185
|
return;
|
|
171
186
|
}
|
|
172
187
|
// The threshold itself, with no extra lead: chained providers sharing this rule must not
|
|
@@ -177,6 +192,7 @@ export function credentials(source) {
|
|
|
177
192
|
function retry() {
|
|
178
193
|
if (refreshTimer !== undefined)
|
|
179
194
|
return;
|
|
195
|
+
const current = held();
|
|
180
196
|
if (current !== undefined)
|
|
181
197
|
armExpiry(current);
|
|
182
198
|
// Without a mint nothing can replace the held credential; only its expiry remains to report.
|
|
@@ -189,7 +205,7 @@ export function credentials(source) {
|
|
|
189
205
|
function armRefresh(delay) {
|
|
190
206
|
refreshTimer = setTimeout(() => {
|
|
191
207
|
refreshTimer = undefined;
|
|
192
|
-
void
|
|
208
|
+
void (minting ?? begin()).promise.catch(() => undefined);
|
|
193
209
|
}, delay);
|
|
194
210
|
}
|
|
195
211
|
function armExpiry(credential) {
|
|
@@ -197,9 +213,8 @@ export function credentials(source) {
|
|
|
197
213
|
clearTimeout(expiryTimer);
|
|
198
214
|
expiryTimer = setTimeout(() => {
|
|
199
215
|
expiryTimer = undefined;
|
|
200
|
-
if (!anticipating ||
|
|
216
|
+
if (!anticipating || held() !== credential)
|
|
201
217
|
return;
|
|
202
|
-
current = undefined;
|
|
203
218
|
publish({ status: 'expired', error: new ClientError('Session credential expired.') });
|
|
204
219
|
}, clamp(credential.expiresAt - Date.now()));
|
|
205
220
|
}
|
|
@@ -8,14 +8,19 @@ interface BundleDiscoveryOptions {
|
|
|
8
8
|
readonly policy: Readonly<SessionPolicy>;
|
|
9
9
|
readonly maximumBytes: number;
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
12
|
-
export
|
|
13
|
-
|
|
11
|
+
/** A Release's Bundle, or evidence that its digest-addressed artifact is no longer served. */
|
|
12
|
+
export type BundleRead = {
|
|
13
|
+
readonly kind: 'bundle';
|
|
14
|
+
readonly bundle: bundle.Bundle;
|
|
15
|
+
} | {
|
|
16
|
+
readonly kind: 'unavailable';
|
|
17
|
+
readonly error: ClientError;
|
|
18
|
+
};
|
|
14
19
|
export declare class BundleDiscovery {
|
|
15
20
|
private readonly options;
|
|
16
21
|
private retained?;
|
|
17
22
|
constructor(options: BundleDiscoveryOptions);
|
|
18
|
-
get(release: DomainRelease, operation: SessionOperation): Promise<
|
|
23
|
+
get(release: DomainRelease, operation: SessionOperation): Promise<BundleRead>;
|
|
19
24
|
clear(): void;
|
|
20
25
|
private fetch;
|
|
21
26
|
}
|