@astrale-os/kernel-client 1.0.0-beta.5 → 1.0.0-beta.50
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/authorization.d.ts +10 -5
- package/dist/auth/authorization.js +14 -1
- package/dist/auth/index.d.ts +1 -0
- package/dist/client/admission.js +3 -1
- package/dist/client/client.d.ts +70 -4
- package/dist/client/client.js +209 -32
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.js +2 -2
- package/dist/client/level.d.ts +58 -0
- package/dist/client/level.js +159 -0
- package/dist/client/request.d.ts +7 -2
- package/dist/client/request.js +11 -7
- package/dist/client/result.d.ts +14 -1
- package/dist/client/result.js +19 -8
- 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/inexpressible-error.d.ts +23 -0
- package/dist/errors/inexpressible-error.js +26 -0
- package/dist/errors/query-input.d.ts +47 -0
- package/dist/errors/query-input.js +85 -0
- package/dist/errors/refusal.d.ts +12 -0
- package/dist/errors/refusal.js +44 -6
- 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 +2 -2
- package/dist/{session/execution.d.ts → execution/contracts.d.ts} +22 -34
- 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 +20 -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 +66 -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 +144 -5
- package/dist/graph/query.typecheck.d.ts +81 -0
- package/dist/graph/query.typecheck.js +34 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/schema/contracts.d.ts +54 -79
- package/dist/schema/index.d.ts +2 -2
- package/dist/schema/index.js +1 -1
- package/dist/schema/installation.d.ts +36 -64
- package/dist/schema/installation.js +67 -131
- package/dist/schema/schema.d.ts +10 -16
- package/dist/schema/schema.js +57 -34
- package/dist/session/admission.js +10 -3
- package/dist/session/bound.d.ts +12 -3
- package/dist/session/bound.js +36 -32
- package/dist/session/content/api.d.ts +20 -2
- package/dist/session/content/api.js +17 -7
- package/dist/session/content/files.d.ts +12 -0
- package/dist/session/content/files.js +47 -0
- package/dist/session/content/index.d.ts +1 -1
- package/dist/session/content/input.d.ts +13 -2
- package/dist/session/content/input.js +25 -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 +2 -2
- package/dist/session/context/index.js +2 -2
- package/dist/session/context/operation.d.ts +2 -0
- package/dist/session/context/operation.js +5 -0
- package/dist/session/context/policy.d.ts +2 -0
- package/dist/session/context/policy.js +6 -3
- package/dist/session/credential/credentials.d.ts +2 -1
- package/dist/session/credential/credentials.js +62 -29
- package/dist/session/discovery/bundle.d.ts +13 -4
- package/dist/session/discovery/bundle.js +85 -36
- package/dist/session/discovery/discovery.d.ts +1 -1
- package/dist/session/discovery/discovery.js +8 -11
- package/dist/session/discovery/index.d.ts +1 -0
- package/dist/session/discovery/index.js +5 -1
- package/dist/session/discovery/release.d.ts +2 -0
- package/dist/session/discovery/release.js +34 -31
- package/dist/session/discovery/response.d.ts +4 -0
- package/dist/session/discovery/response.js +10 -6
- package/dist/session/discovery/snapshot.d.ts +5 -1
- package/dist/session/discovery/transport.d.ts +37 -3
- package/dist/session/discovery/transport.js +62 -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 +5 -4
- package/dist/session/index.js +0 -1
- package/dist/session/options.d.ts +4 -2
- package/dist/session/options.js +3 -3
- package/dist/session/reference.d.ts +27 -6
- package/dist/session/reference.js +18 -3
- 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 -69
- 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 +2 -1
- package/dist/session/routing/request.js +2 -1
- 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 +70 -22
- 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 +61 -112
- 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 +28 -14
- package/dist/transport/auto/decision.js +39 -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 +10 -3
- package/dist/transport/auto/transport.js +41 -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 +8 -35
- 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/configuration.d.ts +7 -0
- package/dist/transport/http/configuration.js +2 -0
- package/dist/transport/http/index.d.ts +1 -1
- package/dist/transport/http/index.js +1 -1
- package/dist/transport/http/response.d.ts +13 -1
- package/dist/transport/http/response.js +22 -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 +14 -1
- package/dist/transport/http/transport.js +110 -35
- package/dist/transport/http/unprocessed.d.ts +5 -0
- package/dist/transport/http/unprocessed.js +28 -0
- package/dist/transport/index.d.ts +2 -1
- package/dist/transport/index.js +2 -1
- package/dist/transport/level.d.ts +42 -0
- package/dist/transport/level.js +58 -0
- package/dist/transport/stream.d.ts +52 -0
- package/dist/transport/stream.js +101 -0
- package/dist/transport/transport.d.ts +33 -0
- package/dist/transport/unary.d.ts +9 -0
- package/dist/transport/unary.js +36 -0
- package/dist/transport/websocket/connection.d.ts +13 -4
- package/dist/transport/websocket/connection.js +123 -96
- package/dist/transport/websocket/exchange.d.ts +15 -19
- package/dist/transport/websocket/exchange.js +87 -183
- package/dist/transport/websocket/transport.d.ts +19 -1
- package/dist/transport/websocket/transport.js +50 -21
- package/package.json +9 -7
- 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/schema/schema.js
CHANGED
|
@@ -1,41 +1,39 @@
|
|
|
1
1
|
import { Path } from '@astrale-os/kernel-core/path';
|
|
2
2
|
import { install, uninstall } from '@astrale-os/kernel-core/schema/kernel/syscalls/references';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
3
|
+
import { call as invocation } from '../client/index.js';
|
|
4
|
+
import { deadlineOf, within } from '../execution/index.js';
|
|
5
|
+
import { createInstallation, createUninstallation, lifecycleWait, } from './installation.js';
|
|
5
6
|
import { introspect } from './introspection.js';
|
|
6
7
|
const INSTALL_PATH = Path.project(install).raw;
|
|
7
8
|
const UNINSTALL_PATH = Path.project(uninstall).raw;
|
|
8
|
-
export const DEFAULT_SCHEMA_LIFECYCLE_TIMEOUT_MS = 110_000;
|
|
9
9
|
/** Bind the canonical Schema lifecycle syscalls to one caller-scoped value-call capability. */
|
|
10
10
|
export function createSchema(call, limits) {
|
|
11
11
|
if (typeof call !== 'function')
|
|
12
12
|
throw new TypeError('Schema call capability is invalid.');
|
|
13
13
|
const admittedLimits = admitLimits(limits);
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const uninstallation = createUninstallation(executions);
|
|
14
|
+
const installation = createInstallation(call);
|
|
15
|
+
const uninstallation = createUninstallation(call);
|
|
17
16
|
return Object.freeze({
|
|
18
17
|
async install(request, options) {
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const status = await executions.observe(execution, protocolSchema.installation.acceptResult, options);
|
|
27
|
-
return admitInstallation(request, execution, status);
|
|
18
|
+
const { waitMs: _waitMs, ...input } = request;
|
|
19
|
+
const waitMs = lifecycleWait(request);
|
|
20
|
+
// A maintenance session's outcome is Root's to decide: the call waits until it awaits Root.
|
|
21
|
+
const wait = input.mode === 'maintenance'
|
|
22
|
+
? sessionWait(installation, waitMs)
|
|
23
|
+
: outcomeWait(installation, waitMs);
|
|
24
|
+
return admitInstallation(request, await lifecycle(call, INSTALL_PATH, input, wait, options));
|
|
28
25
|
},
|
|
29
26
|
installation,
|
|
30
27
|
async uninstall(request, options) {
|
|
28
|
+
const wait = outcomeWait(uninstallation, lifecycleWait(request));
|
|
31
29
|
const snapshot = snapshotUninstallRequest(request);
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
const status =
|
|
30
|
+
const started = await lifecycle(call, UNINSTALL_PATH, snapshot, wait, options);
|
|
31
|
+
const answer = { execution: started.status.id, ...started };
|
|
32
|
+
const { status } = started;
|
|
35
33
|
if (status.outcome?.kind !== 'completed')
|
|
36
|
-
return Object.freeze(
|
|
34
|
+
return Object.freeze(answer);
|
|
37
35
|
proveUninstallReceipt(snapshot, status.outcome.value);
|
|
38
|
-
return Object.freeze({
|
|
36
|
+
return Object.freeze({ ...answer, result: status.outcome.value });
|
|
39
37
|
},
|
|
40
38
|
uninstallation,
|
|
41
39
|
async inspect(origin, options) {
|
|
@@ -52,6 +50,38 @@ export function createSchema(call, limits) {
|
|
|
52
50
|
},
|
|
53
51
|
});
|
|
54
52
|
}
|
|
53
|
+
/** Wait at most `waitMs` for the outcome, however that wait ends, then read the status. */
|
|
54
|
+
function outcomeWait(executions, waitMs) {
|
|
55
|
+
return async (execution, deadline, options) => {
|
|
56
|
+
if (waitMs > 0)
|
|
57
|
+
await executions
|
|
58
|
+
.result(execution, { waitMs }, within(deadline, options))
|
|
59
|
+
.catch(() => undefined);
|
|
60
|
+
return executions.status(execution, within(deadline, options));
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Watch a repair session at most `waitMs`, until it awaits Root's first command, and answer the
|
|
65
|
+
* last status read; a watch that fails reads the status once.
|
|
66
|
+
*/
|
|
67
|
+
function sessionWait(installation, waitMs) {
|
|
68
|
+
return (execution, deadline, options) => installation
|
|
69
|
+
.watch(execution, { waitMs }, within(deadline, options))
|
|
70
|
+
.catch(() => installation.status(execution, within(deadline, options)));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* One lifecycle syscall, before the call's deadline: start the durable Execution it is and answer
|
|
74
|
+
* the status `wait` ends on.
|
|
75
|
+
*/
|
|
76
|
+
async function lifecycle(call, path, input, wait, options) {
|
|
77
|
+
const deadline = deadlineOf(options);
|
|
78
|
+
const started = await call(invocation(path, input), within(deadline, options));
|
|
79
|
+
if (started.kind !== 'execution') {
|
|
80
|
+
throw new TypeError('Schema syscall did not answer with an Execution.');
|
|
81
|
+
}
|
|
82
|
+
const status = await wait(started.execution, deadline, options);
|
|
83
|
+
return started.replayed === undefined ? { status } : { status, replayed: started.replayed };
|
|
84
|
+
}
|
|
55
85
|
function snapshotUninstallRequest(request) {
|
|
56
86
|
return Object.freeze({
|
|
57
87
|
operation: request.operation,
|
|
@@ -76,12 +106,14 @@ function compare(left, right) {
|
|
|
76
106
|
* The answer of one install, proved against its request: a completed status carries the result of
|
|
77
107
|
* exactly this operation, admitted by its Protocol owner.
|
|
78
108
|
*/
|
|
79
|
-
function admitInstallation(request,
|
|
109
|
+
function admitInstallation(request, started) {
|
|
110
|
+
const answer = { execution: started.status.id, ...started };
|
|
111
|
+
const { status } = started;
|
|
80
112
|
if (status.outcome?.kind !== 'completed')
|
|
81
|
-
return Object.freeze(
|
|
113
|
+
return Object.freeze(answer);
|
|
82
114
|
const result = status.outcome.value;
|
|
83
115
|
proveInstallResult(request, result);
|
|
84
|
-
return Object.freeze({
|
|
116
|
+
return Object.freeze({ ...answer, result });
|
|
85
117
|
}
|
|
86
118
|
function proveInstallResult(request, result) {
|
|
87
119
|
if (result.changed) {
|
|
@@ -98,22 +130,13 @@ function proveInstallResult(request, result) {
|
|
|
98
130
|
}
|
|
99
131
|
}
|
|
100
132
|
function admitLimits(input) {
|
|
101
|
-
const lifecycleTimeoutMs = input?.lifecycleTimeoutMs ?? DEFAULT_SCHEMA_LIFECYCLE_TIMEOUT_MS;
|
|
102
133
|
if (input === null ||
|
|
103
134
|
typeof input !== 'object' ||
|
|
104
135
|
!Number.isSafeInteger(input.maximumReleaseBytes) ||
|
|
105
136
|
input.maximumReleaseBytes < 1 ||
|
|
106
137
|
!Number.isSafeInteger(input.maximumBundleBytes) ||
|
|
107
|
-
input.maximumBundleBytes < 1
|
|
108
|
-
!Number.isSafeInteger(lifecycleTimeoutMs) ||
|
|
109
|
-
lifecycleTimeoutMs < 1 ||
|
|
110
|
-
lifecycleTimeoutMs > 2_147_483_647) {
|
|
138
|
+
input.maximumBundleBytes < 1) {
|
|
111
139
|
throw new TypeError('Schema introspection limits are invalid.');
|
|
112
140
|
}
|
|
113
|
-
return Object.freeze({ ...input
|
|
114
|
-
}
|
|
115
|
-
function lifecycleOptions(options, timeoutMs) {
|
|
116
|
-
if (options?.timeoutMs !== undefined)
|
|
117
|
-
return options;
|
|
118
|
-
return Object.freeze({ ...options, timeoutMs });
|
|
141
|
+
return Object.freeze({ ...input });
|
|
119
142
|
}
|
|
@@ -5,7 +5,7 @@ import { function as functions } from '@astrale-os/kernel-core/schema/kernel/sys
|
|
|
5
5
|
import { Key } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
6
6
|
import { ClientError } from '../errors/index.js';
|
|
7
7
|
import { runSessionOperation, sessionTransportOptions } from './context/index.js';
|
|
8
|
-
import { callableOrigin, exchangeDomainCredential, installedIssuer,
|
|
8
|
+
import { callableOrigin, exchangeDomainCredential, EXHAUSTED, installedIssuer, sourceExhausted, } from './exchange/index.js';
|
|
9
9
|
import { matchesCallable } from './reference.js';
|
|
10
10
|
import { requireResultKind, resolveAuth } from './routing/index.js';
|
|
11
11
|
const ADMIT = Path.staticMethod(Path.project(functions.admit.owner), functions.admit.name);
|
|
@@ -17,7 +17,7 @@ export async function admitFunction(dependencies, call, operation) {
|
|
|
17
17
|
throw new ClientError('Function admission requires a Domain-qualified callable target.');
|
|
18
18
|
}
|
|
19
19
|
const effective = await resolveAuth(dependencies.auth, call, operation);
|
|
20
|
-
if (
|
|
20
|
+
if (effective.kind === 'anonymous') {
|
|
21
21
|
throw new ClientError('Function admission requires an authenticated session.');
|
|
22
22
|
}
|
|
23
23
|
// Resolve once for the intended Call, then retain that exact caller across every helper syscall.
|
|
@@ -27,12 +27,19 @@ export async function admitFunction(dependencies, call, operation) {
|
|
|
27
27
|
}
|
|
28
28
|
// The Kernel preserves the session caller when issuing the delegation.
|
|
29
29
|
const exchanged = await exchangeDomainCredential(dependencies, effective, { issuer: domain, ttlSeconds: effective.delegate.ttlSeconds }, operation);
|
|
30
|
+
if (exchanged === EXHAUSTED)
|
|
31
|
+
throw sourceExhausted();
|
|
30
32
|
const result = await runSessionOperation(operation, () => dependencies
|
|
31
33
|
.source()
|
|
32
34
|
.as(exchanged.credential)
|
|
33
35
|
.dispatch({ target: ADMIT, input: { call, credential: exchanged.delegation } }, { ...sessionTransportOptions(operation), delegate: effective.delegate }));
|
|
34
36
|
const output = admitOutput.parse(requireResultKind('value', result).value);
|
|
35
|
-
|
|
37
|
+
// A Domain-qualified target names a declaration, by its key and without a definition: only an
|
|
38
|
+
// instance is named by its NodeId and defined by its Node.
|
|
39
|
+
if (output.definition !== undefined || !Key.is(output.callable)) {
|
|
40
|
+
throw new ClientError('Function admission returned a different callable.');
|
|
41
|
+
}
|
|
42
|
+
const callable = output.callable;
|
|
36
43
|
if (!matchesCallable(target, callable)) {
|
|
37
44
|
throw new ClientError('Function admission returned a different callable.');
|
|
38
45
|
}
|
package/dist/session/bound.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { IssuerId } from '@astrale-os/kernel-core/auth';
|
|
2
2
|
import type { AuthApi } from '../auth/index.js';
|
|
3
|
+
import type { ExecutionApi } from '../execution/index.js';
|
|
3
4
|
import type { SchemaApi } from '../schema/index.js';
|
|
4
5
|
import type { ContentApi } from './content/index.js';
|
|
5
6
|
import type { SessionControlOptions } from './context/index.js';
|
|
6
7
|
import type { SessionRequestOptions } from './routing/index.js';
|
|
7
8
|
import type { ClientSession } from './session.js';
|
|
8
|
-
import type { ViewCatalog } from './views/index.js';
|
|
9
|
+
import type { ViewCatalog } from './views/legacy/index.js';
|
|
9
10
|
import { type Binary, type Call, type Stream } from '../client/index.js';
|
|
10
11
|
import { type GraphApi } from '../graph/index.js';
|
|
11
12
|
/** Exact live Session surface captured by one credential-bound Kernel view. */
|
|
@@ -19,7 +20,12 @@ export interface BoundSessionSource {
|
|
|
19
20
|
invoke: ClientSession['invoke'];
|
|
20
21
|
stream(call: Call, options?: SessionRequestOptions): Promise<Stream>;
|
|
21
22
|
binary(call: Call, options?: SessionRequestOptions): Promise<Binary>;
|
|
22
|
-
|
|
23
|
+
view: ClientSession['view'];
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated Read a Domain's Views with `view({ domain })`. A source need not serve it: the
|
|
26
|
+
* bound `viewsFor` of one that does not throws a TypeError.
|
|
27
|
+
*/
|
|
28
|
+
viewsFor?(domain: Parameters<ClientSession['viewsFor']>[0], options?: SessionControlOptions): Promise<ViewCatalog>;
|
|
23
29
|
}
|
|
24
30
|
export interface BoundSessionControls {
|
|
25
31
|
readonly signal: AbortSignal;
|
|
@@ -36,13 +42,16 @@ export interface BoundClientSession extends GraphApi {
|
|
|
36
42
|
readonly kernel: IssuerId;
|
|
37
43
|
readonly auth: AuthApi;
|
|
38
44
|
readonly schema: SchemaApi;
|
|
45
|
+
readonly execution: ExecutionApi;
|
|
39
46
|
readonly content: ContentApi;
|
|
40
47
|
dispatch: ClientSession['dispatch'];
|
|
41
48
|
call: ClientSession['call'];
|
|
42
49
|
invoke: ClientSession['invoke'];
|
|
43
50
|
stream(call: Call, options?: SessionRequestOptions): Promise<Stream>;
|
|
44
51
|
binary(call: Call, options?: SessionRequestOptions): Promise<Binary>;
|
|
45
|
-
|
|
52
|
+
view: BoundSessionSource['view'];
|
|
53
|
+
/** @deprecated Read a Domain's Views with `view({ domain })`. */
|
|
54
|
+
viewsFor: NonNullable<BoundSessionSource['viewsFor']>;
|
|
46
55
|
}
|
|
47
56
|
/** Capture one Session into the ordinary graph, auth, and invocation Kernel journey. */
|
|
48
57
|
export declare function bindSession(source: BoundSessionSource, controls?: BoundSessionControls): BoundClientSession;
|
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,42 +19,46 @@ 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));
|
|
39
44
|
const installs = schemaSource.installation;
|
|
40
45
|
const installation = Object.freeze({
|
|
41
|
-
status: (execution, options) => installs.status(execution,
|
|
42
|
-
result: (execution, wait, options) => installs.result(execution, wait,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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)),
|
|
48
54
|
});
|
|
49
55
|
const uninstalls = schemaSource.uninstallation;
|
|
50
56
|
const uninstallation = Object.freeze({
|
|
51
|
-
status: (execution, options) => uninstalls.status(execution,
|
|
52
|
-
result: (execution, wait, options) => uninstalls.result(execution, wait,
|
|
53
|
-
cancel: (execution, input, options) => uninstalls.cancel(execution, input,
|
|
54
|
-
resume: (execution, options) => uninstalls.resume(execution,
|
|
55
|
-
delete: (execution, options) => uninstalls.delete(execution,
|
|
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)),
|
|
56
62
|
});
|
|
57
63
|
const schema = Object.freeze({
|
|
58
64
|
install,
|
|
@@ -65,18 +71,21 @@ export function bindSession(source, controls) {
|
|
|
65
71
|
installed,
|
|
66
72
|
});
|
|
67
73
|
const graph = createGraph(call);
|
|
74
|
+
const execution = createExecution(dispatch);
|
|
68
75
|
const auth = createAuth((target, input, options) => call(createCall(target, input), options), admit);
|
|
69
76
|
return Object.freeze({
|
|
70
77
|
...graph,
|
|
71
78
|
kernel: source.kernel,
|
|
72
79
|
auth,
|
|
73
80
|
schema,
|
|
81
|
+
execution,
|
|
74
82
|
dispatch,
|
|
75
83
|
call,
|
|
76
84
|
invoke,
|
|
77
85
|
stream,
|
|
78
86
|
binary,
|
|
79
87
|
content,
|
|
88
|
+
view,
|
|
80
89
|
viewsFor,
|
|
81
90
|
});
|
|
82
91
|
}
|
|
@@ -99,12 +108,6 @@ function admitControls(input) {
|
|
|
99
108
|
}
|
|
100
109
|
return Object.freeze({ signal: input.signal, deadline: input.deadline });
|
|
101
110
|
}
|
|
102
|
-
function requestOptions(options, controls) {
|
|
103
|
-
return mergeOptions(options, controls);
|
|
104
|
-
}
|
|
105
|
-
function controlOptions(options, controls) {
|
|
106
|
-
return mergeOptions(options, controls);
|
|
107
|
-
}
|
|
108
111
|
function mergeOptions(options, controls) {
|
|
109
112
|
if (controls === undefined)
|
|
110
113
|
return options;
|
|
@@ -137,6 +140,7 @@ function captureSchema(input) {
|
|
|
137
140
|
installation: Object.freeze({
|
|
138
141
|
status: capture(installation, 'status'),
|
|
139
142
|
result: capture(installation, 'result'),
|
|
143
|
+
watch: capture(installation, 'watch'),
|
|
140
144
|
apply: capture(installation, 'apply'),
|
|
141
145
|
abort: capture(installation, 'abort'),
|
|
142
146
|
cancel: capture(installation, 'cancel'),
|
|
@@ -1,12 +1,18 @@
|
|
|
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;
|
|
8
10
|
readonly property: string;
|
|
9
11
|
}
|
|
12
|
+
/** The content one upload receipt of this Session's caller names, read back without a holder. */
|
|
13
|
+
export interface ContentReceipt {
|
|
14
|
+
readonly receipt: string;
|
|
15
|
+
}
|
|
10
16
|
export interface ContentUploadOptions extends SessionControlOptions {
|
|
11
17
|
readonly mediaType: string;
|
|
12
18
|
}
|
|
@@ -27,9 +33,21 @@ export type ContentDownload = {
|
|
|
27
33
|
readonly outcome: 'rejected';
|
|
28
34
|
readonly code: ContentRejection;
|
|
29
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* The bytes one upload stores. A Blob, File, or Uint8Array is read again by every attempt. A stream
|
|
38
|
+
* must yield exactly `length` bytes; the upload consumes it in one attempt, and cancels it if it
|
|
39
|
+
* fails before reading it through its end. A Domain's own binary input has this shape.
|
|
40
|
+
*/
|
|
41
|
+
export type ContentSource = Blob | Uint8Array | BinaryRequestBody;
|
|
30
42
|
export interface ContentApi {
|
|
31
|
-
upload(source:
|
|
43
|
+
upload(source: ContentSource, options: ContentUploadOptions): Promise<ContentUploadResult>;
|
|
32
44
|
download(location: ContentLocation, options?: SessionControlOptions): Promise<Binary>;
|
|
45
|
+
/**
|
|
46
|
+
* The content an upload receipt names, for the caller it was issued to, before or without any
|
|
47
|
+
* attachment. A receipt another caller received, an expired one, or a Ref is refused
|
|
48
|
+
* (`BLOB_RECEIPT_INVALID`).
|
|
49
|
+
*/
|
|
50
|
+
download(receipt: ContentReceipt, options?: SessionControlOptions): Promise<Binary>;
|
|
33
51
|
/**
|
|
34
52
|
* One outcome per location, in order, within one time budget for the whole list. Consume each
|
|
35
53
|
* content body before requesting the next outcome: an unread body is skipped.
|
|
@@ -39,7 +57,7 @@ export interface ContentApi {
|
|
|
39
57
|
/** What the Session lends the content transfer: its time budgets and its routed dispatch. */
|
|
40
58
|
export interface ContentDependencies {
|
|
41
59
|
readonly operation: (options: SessionControlOptions) => SessionOperation;
|
|
42
|
-
readonly dispatch: (target: Path, input: Input, operation: SessionOperation, body?:
|
|
60
|
+
readonly dispatch: (target: Path, input: Input, operation: SessionOperation, body?: BinaryBody) => Promise<Result>;
|
|
43
61
|
}
|
|
44
62
|
/** Transfer immutable content over the authenticated Session routing conversation. */
|
|
45
63
|
export declare function createContentApi(dependencies: ContentDependencies): ContentApi;
|
|
@@ -1,16 +1,25 @@
|
|
|
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
|
-
import { acceptBody, acceptControls, acceptLocation, acceptMediaType } from './input.js';
|
|
4
|
+
import { acceptBody, acceptControls, acceptLocation, acceptMediaType, acceptReceipt, isReceipt, } from './input.js';
|
|
4
5
|
import { retry } from './retry.js';
|
|
5
6
|
import { DOWNLOAD, UPLOAD, decodeDownload, decodeUploadResult } from './wire.js';
|
|
6
7
|
/** Transfer immutable content over the authenticated Session routing conversation. */
|
|
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)) {
|
|
@@ -19,9 +28,10 @@ export function createContentApi(dependencies) {
|
|
|
19
28
|
}
|
|
20
29
|
return downloadOne(input, options);
|
|
21
30
|
}
|
|
22
|
-
async function downloadOne(
|
|
31
|
+
async function downloadOne(source, options) {
|
|
32
|
+
const request = isReceipt(source) ? acceptReceipt(source) : acceptLocation(source);
|
|
23
33
|
const operation = dependencies.operation(acceptControls(options));
|
|
24
|
-
const result = await dependencies.dispatch(DOWNLOAD,
|
|
34
|
+
const result = await dependencies.dispatch(DOWNLOAD, request, operation);
|
|
25
35
|
return decodeDownload(requireResultKind('binary', result).value);
|
|
26
36
|
}
|
|
27
37
|
return Object.freeze({ upload, download });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { schema } from '@astrale-os/kernel-dsl/v1';
|
|
2
|
+
import type { ContentUploadOptions, ContentUploadResult } from './api.js';
|
|
3
|
+
type FilePosition = schema.values.FilePosition;
|
|
4
|
+
/** What sending a typed input's files needs: one upload per file. */
|
|
5
|
+
export type FileUpload = (source: Blob, options: ContentUploadOptions) => Promise<ContentUploadResult>;
|
|
6
|
+
/**
|
|
7
|
+
* `input` with every Blob or File at one of `positions` uploaded and replaced by its receipt. A
|
|
8
|
+
* file is checked against the constraints its field states before it is uploaded; a value that is
|
|
9
|
+
* not a Blob, a receipt already, is sent as it is. Without a Blob the input is returned unchanged.
|
|
10
|
+
*/
|
|
11
|
+
export declare function uploadFiles(positions: readonly FilePosition[], input: unknown, upload: FileUpload, options: Omit<ContentUploadOptions, 'mediaType'>): Promise<unknown>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { locateFiles } from '@astrale-os/kernel-dsl/v1/schema/values';
|
|
2
|
+
import { acceptMediaType } from './input.js';
|
|
3
|
+
/**
|
|
4
|
+
* `input` with every Blob or File at one of `positions` uploaded and replaced by its receipt. A
|
|
5
|
+
* file is checked against the constraints its field states before it is uploaded; a value that is
|
|
6
|
+
* not a Blob, a receipt already, is sent as it is. Without a Blob the input is returned unchanged.
|
|
7
|
+
*/
|
|
8
|
+
export async function uploadFiles(positions, input, upload, options) {
|
|
9
|
+
const files = locateFiles(positions, input).filter(({ value }) => value instanceof Blob);
|
|
10
|
+
if (files.length === 0)
|
|
11
|
+
return input;
|
|
12
|
+
let sent = input;
|
|
13
|
+
for (const { pointer, position, value } of files) {
|
|
14
|
+
const blob = value;
|
|
15
|
+
const mediaType = acceptMediaType(blob.type === '' ? 'application/octet-stream' : blob.type);
|
|
16
|
+
if (position.maxBytes !== undefined && blob.size > position.maxBytes) {
|
|
17
|
+
throw new TypeError(`File at ${pointer || '/'} exceeds its ${position.maxBytes} bytes.`);
|
|
18
|
+
}
|
|
19
|
+
if (position.mediaTypes !== undefined && !position.mediaTypes.includes(mediaType)) {
|
|
20
|
+
throw new TypeError(`File at ${pointer || '/'} has a media type its field refuses.`);
|
|
21
|
+
}
|
|
22
|
+
const { receipt } = await upload(blob, { ...options, mediaType });
|
|
23
|
+
sent = replaceAt(sent, tokensOf(pointer), receipt);
|
|
24
|
+
}
|
|
25
|
+
return sent;
|
|
26
|
+
}
|
|
27
|
+
/** A copy of `value` with `replacement` at `tokens`; only the containers on the way are copied. */
|
|
28
|
+
function replaceAt(value, tokens, replacement) {
|
|
29
|
+
if (tokens.length === 0)
|
|
30
|
+
return replacement;
|
|
31
|
+
const [token, ...rest] = tokens;
|
|
32
|
+
if (Array.isArray(value)) {
|
|
33
|
+
const copy = [...value];
|
|
34
|
+
copy[Number(token)] = replaceAt(value[Number(token)], rest, replacement);
|
|
35
|
+
return copy;
|
|
36
|
+
}
|
|
37
|
+
const record = value;
|
|
38
|
+
return { ...record, [token]: replaceAt(record[token], rest, replacement) };
|
|
39
|
+
}
|
|
40
|
+
function tokensOf(pointer) {
|
|
41
|
+
if (pointer === '')
|
|
42
|
+
return [];
|
|
43
|
+
return pointer
|
|
44
|
+
.slice(1)
|
|
45
|
+
.split('/')
|
|
46
|
+
.map((token) => token.replaceAll('~1', '/').replaceAll('~0', '~'));
|
|
47
|
+
}
|
|
@@ -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 ContentReceipt, type ContentRejection, type ContentSource, type ContentUploadOptions, type ContentUploadResult, } from './api.js';
|
|
@@ -1,9 +1,20 @@
|
|
|
1
|
+
import type { BinaryBody } from '../../transport/http/binary-request.js';
|
|
1
2
|
import type { SessionControlOptions } from '../context/index.js';
|
|
2
|
-
import type { ContentLocation } from './api.js';
|
|
3
|
+
import type { ContentLocation, ContentReceipt } 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
|
+
/** Whether a download names a receipt rather than a holder location. */
|
|
8
|
+
export declare function isReceipt(input: ContentLocation | ContentReceipt): input is ContentReceipt;
|
|
9
|
+
/** One receipt download, exactly as the request carries it; the Kernel admits the receipt. */
|
|
10
|
+
export declare function acceptReceipt(input: ContentReceipt): Readonly<{
|
|
11
|
+
receipt: string;
|
|
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
|
+
*/
|
|
17
|
+
export declare function acceptBody(input: unknown): BinaryBody;
|
|
7
18
|
export declare function acceptMediaType(input: unknown): string;
|
|
8
19
|
/** The caller's controls, with the content transfer's own default time budget. */
|
|
9
20
|
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,37 @@ export function acceptLocation(input) {
|
|
|
9
10
|
}
|
|
10
11
|
return Object.freeze({ node: NodeId(input.node), property: PropertyKey(input.property) });
|
|
11
12
|
}
|
|
13
|
+
/** Whether a download names a receipt rather than a holder location. */
|
|
14
|
+
export function isReceipt(input) {
|
|
15
|
+
return input !== null && typeof input === 'object' && Object.hasOwn(input, 'receipt');
|
|
16
|
+
}
|
|
17
|
+
/** One receipt download, exactly as the request carries it; the Kernel admits the receipt. */
|
|
18
|
+
export function acceptReceipt(input) {
|
|
19
|
+
if (Object.keys(input).length !== 1 ||
|
|
20
|
+
typeof input.receipt !== 'string' ||
|
|
21
|
+
input.receipt.length === 0) {
|
|
22
|
+
throw new TypeError('Content receipt is invalid.');
|
|
23
|
+
}
|
|
24
|
+
return Object.freeze({ receipt: input.receipt });
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The bytes of one upload: a Blob, an owned snapshot of a Uint8Array, or a byte stream with its
|
|
28
|
+
* exact length, which the upload consumes.
|
|
29
|
+
*/
|
|
12
30
|
export function acceptBody(input) {
|
|
13
|
-
if (typeof Blob !== 'undefined' && input instanceof Blob)
|
|
14
|
-
return input;
|
|
15
31
|
if (input instanceof Uint8Array) {
|
|
16
32
|
// Blob snapshots an ArrayBuffer view; a SharedArrayBuffer view needs an owned copy.
|
|
17
33
|
const bytes = input.buffer instanceof ArrayBuffer
|
|
18
34
|
? input
|
|
19
35
|
: new Uint8Array(input);
|
|
20
|
-
return new Blob([bytes]);
|
|
36
|
+
return replayableBody(new Blob([bytes]));
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
return acceptBinaryBody(input);
|
|
40
|
+
}
|
|
41
|
+
catch (cause) {
|
|
42
|
+
throw new TypeError('Content upload source must be a Blob, File, Uint8Array, or { body: ReadableStream, length }.', { cause });
|
|
21
43
|
}
|
|
22
|
-
throw new TypeError('Content upload source must be a Blob, File, or Uint8Array.');
|
|
23
44
|
}
|
|
24
45
|
export function acceptMediaType(input) {
|
|
25
46
|
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>;
|