@astrale-os/kernel-client 1.0.0-beta.22 → 1.0.0-beta.24
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/client/client.d.ts +5 -4
- package/dist/client/client.js +7 -7
- package/dist/client/index.d.ts +1 -1
- package/dist/client/request.d.ts +5 -9
- package/dist/client/request.js +13 -16
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/errors/query-input.d.ts +47 -0
- package/dist/errors/query-input.js +84 -0
- package/dist/execution/deadline.d.ts +10 -0
- package/dist/execution/deadline.js +12 -0
- package/dist/execution/execution.js +2 -7
- package/dist/execution/index.d.ts +1 -1
- package/dist/execution/index.js +1 -1
- package/dist/graph/domain/binding.d.ts +2 -2
- package/dist/graph/graph.d.ts +17 -3
- package/dist/graph/graph.js +4 -1
- package/dist/graph/index.d.ts +2 -2
- package/dist/graph/page-contract.d.ts +53 -1
- package/dist/graph/query.d.ts +10 -4
- package/dist/graph/query.js +125 -2
- package/dist/graph/query.typecheck.d.ts +77 -0
- package/dist/graph/query.typecheck.js +34 -0
- package/dist/schema/contracts.d.ts +21 -10
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/installation.d.ts +11 -1
- package/dist/schema/installation.js +45 -1
- package/dist/schema/schema.d.ts +4 -4
- package/dist/schema/schema.js +34 -24
- package/dist/session/bound.js +27 -31
- package/dist/session/content/api.js +2 -2
- package/dist/session/content/input.js +2 -2
- package/dist/session/content/retry.d.ts +2 -1
- package/dist/session/content/retry.js +13 -23
- package/dist/session/context/operation.js +2 -16
- package/dist/session/durable.js +13 -19
- package/dist/session/retry.d.ts +12 -0
- package/dist/session/retry.js +23 -0
- package/dist/session/routing/dispatch.d.ts +2 -2
- package/dist/session/routing/dispatch.js +12 -20
- package/dist/session/routing/request.d.ts +2 -1
- package/dist/session/routing/request.js +2 -1
- package/dist/store/store.d.ts +6 -6
- package/dist/transport/deadline.d.ts +2 -0
- package/dist/transport/deadline.js +18 -0
- package/dist/transport/http/admission.js +7 -42
- package/dist/transport/http/binary-request.d.ts +23 -9
- package/dist/transport/http/binary-request.js +12 -10
- package/dist/transport/http/response.d.ts +0 -1
- package/dist/transport/http/response.js +0 -6
- package/dist/transport/http/transport.d.ts +3 -2
- package/dist/transport/http/transport.js +16 -20
- package/dist/transport/index.d.ts +1 -1
- package/dist/transport/index.js +1 -1
- package/dist/transport/unary.d.ts +7 -0
- package/dist/transport/unary.js +34 -0
- package/dist/transport/websocket/connection.js +1 -7
- package/dist/transport/websocket/exchange.d.ts +2 -0
- package/dist/transport/websocket/exchange.js +13 -43
- package/package.json +5 -5
package/dist/client/client.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import type { invocation as protocol } from '@astrale-os/kernel-protocol';
|
|
2
|
+
import type { BinaryBody } from '../transport/http/binary-request.js';
|
|
2
3
|
import type { Transport } from '../transport/index.js';
|
|
3
4
|
import type { AuthenticatedClient, RemoteCredential } from './credential.js';
|
|
4
|
-
import type { Call, ClientDispatchOptions, ClientDispatchOptionsWithBody
|
|
5
|
+
import type { Call, ClientDispatchOptions, ClientDispatchOptionsWithBody } from './request.js';
|
|
5
6
|
import type { BinaryResponse, Result, StreamResult, ValueResult } from './result.js';
|
|
6
7
|
import { type HttpTransportOptions } from '../transport/http/index.js';
|
|
7
8
|
export type ClientOptions = HttpTransportOptions | {
|
|
8
9
|
readonly transport: Transport;
|
|
9
10
|
};
|
|
10
11
|
/**
|
|
11
|
-
* Package-private Session routing path: it presents a redirect continuation's Trace and
|
|
12
|
-
* one-shot stream
|
|
12
|
+
* Package-private Session routing path: it presents a redirect continuation's Trace and sends an
|
|
13
|
+
* admitted body, which may be a one-shot stream. Intentionally absent from the public Client facade.
|
|
13
14
|
*/
|
|
14
|
-
export declare function dispatchInternal(client: Client, credential: RemoteCredential | undefined, call: Call, options: ClientDispatchOptions |
|
|
15
|
+
export declare function dispatchInternal(client: Client, credential: RemoteCredential | undefined, call: Call, options: ClientDispatchOptions | undefined, trace?: protocol.Trace, body?: BinaryBody): Promise<Result>;
|
|
15
16
|
/** Pure client for the universal remote Function invocation boundary. */
|
|
16
17
|
export declare class Client implements AuthenticatedClient {
|
|
17
18
|
private readonly transport;
|
package/dist/client/client.js
CHANGED
|
@@ -7,14 +7,14 @@ import { requireBinary, requireStream, requireValue } from './result.js';
|
|
|
7
7
|
import { admittedDeploymentRetiredError, admittedMissError, admittedStaleRouteError, } from './routing-control.js';
|
|
8
8
|
const controlledDispatch = new WeakMap();
|
|
9
9
|
/**
|
|
10
|
-
* Package-private Session routing path: it presents a redirect continuation's Trace and
|
|
11
|
-
* one-shot stream
|
|
10
|
+
* Package-private Session routing path: it presents a redirect continuation's Trace and sends an
|
|
11
|
+
* admitted body, which may be a one-shot stream. Intentionally absent from the public Client facade.
|
|
12
12
|
*/
|
|
13
|
-
export function dispatchInternal(client, credential, call, options, trace) {
|
|
13
|
+
export function dispatchInternal(client, credential, call, options, trace, body) {
|
|
14
14
|
const dispatch = controlledDispatch.get(client);
|
|
15
15
|
if (dispatch === undefined)
|
|
16
16
|
throw new TypeError('Internal dispatch requires an owned Client.');
|
|
17
|
-
return dispatch(credential, call, options, trace);
|
|
17
|
+
return dispatch(credential, call, options, trace, body);
|
|
18
18
|
}
|
|
19
19
|
/** Pure client for the universal remote Function invocation boundary. */
|
|
20
20
|
export class Client {
|
|
@@ -28,7 +28,7 @@ export class Client {
|
|
|
28
28
|
this.transport = Object.hasOwn(options, 'transport')
|
|
29
29
|
? admitTransport(options.transport)
|
|
30
30
|
: new HttpTransport(options);
|
|
31
|
-
controlledDispatch.set(this, (credential, call, requestOptions, trace) => this.dispatchWith(credential, call, requestOptions, trace,
|
|
31
|
+
controlledDispatch.set(this, (credential, call, requestOptions, trace, body) => this.dispatchWith(credential, call, requestOptions, trace, body));
|
|
32
32
|
}
|
|
33
33
|
dispatch(call, options) {
|
|
34
34
|
return this.dispatchWith(undefined, call, options);
|
|
@@ -53,10 +53,10 @@ export class Client {
|
|
|
53
53
|
this.lifecycle.abort(failure);
|
|
54
54
|
this.transport.close?.();
|
|
55
55
|
}
|
|
56
|
-
async dispatchWith(credential, input, options, trace,
|
|
56
|
+
async dispatchWith(credential, input, options, trace, body) {
|
|
57
57
|
if (this.closed)
|
|
58
58
|
throw new ClientError('Client is closed.');
|
|
59
|
-
const request = admitRequest(input, options, this.lifecycle.signal,
|
|
59
|
+
const request = admitRequest(input, options, this.lifecycle.signal, body);
|
|
60
60
|
let result;
|
|
61
61
|
try {
|
|
62
62
|
const resolved = credential === undefined
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { Client, dispatchInternal, type ClientOptions } from './client.js';
|
|
2
2
|
export { acceptCall } from './admission.js';
|
|
3
3
|
export type { AuthenticatedClient, RemoteCredential } from './credential.js';
|
|
4
|
-
export { call, type Call, type ClientDispatchOptions, type ClientDispatchOptionsWithBody,
|
|
4
|
+
export { call, type Call, type ClientDispatchOptions, type ClientDispatchOptionsWithBody, } from './request.js';
|
|
5
5
|
export type { Binary, BinaryResponse, ExecutionResult, Input, RedirectResult, Result, Stream, StreamResult, ValueResult, } from './result.js';
|
|
6
6
|
export { isAdmittedDeploymentRetiredError, isAdmittedMissError, isAdmittedStaleRouteError, } from './routing-control.js';
|
package/dist/client/request.d.ts
CHANGED
|
@@ -21,13 +21,6 @@ export type ClientDispatchOptionsWithBody = Omit<ClientDispatchOptions, 'body' |
|
|
|
21
21
|
readonly body: Blob;
|
|
22
22
|
readonly idempotencyKey?: never;
|
|
23
23
|
};
|
|
24
|
-
/**
|
|
25
|
-
* Package-private: the body may also be a stream of exactly `length` bytes that one request
|
|
26
|
-
* consumes. Only Session routing sends one, because only it refuses a Redirect it cannot follow.
|
|
27
|
-
*/
|
|
28
|
-
export type ClientDispatchOptionsWithStream = Omit<ClientDispatchOptionsWithBody, 'body'> & {
|
|
29
|
-
readonly body: BinaryBody;
|
|
30
|
-
};
|
|
31
24
|
export interface AdmittedRequest {
|
|
32
25
|
readonly call: protocol.Call;
|
|
33
26
|
readonly delegate?: protocol.Delegate;
|
|
@@ -38,6 +31,9 @@ export interface AdmittedRequest {
|
|
|
38
31
|
readonly body?: BinaryBody;
|
|
39
32
|
}
|
|
40
33
|
export declare function call(target: PathLike | Target, input: Input): Call;
|
|
41
|
-
/**
|
|
42
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Admit one request. A public caller's body is a Blob in its options; the package-private path
|
|
36
|
+
* passes a body its owner already admitted, which may be a stream that only Session routing sends.
|
|
37
|
+
*/
|
|
38
|
+
export declare function admitRequest(input: Call, options: ClientDispatchOptions | ClientDispatchOptionsWithBody | undefined, lifecycle: AbortSignal, admittedBody?: BinaryBody): AdmittedRequest;
|
|
43
39
|
export declare function invocation(request: AdmittedRequest, credential?: string, trace?: protocol.Trace): TransportRequest;
|
package/dist/client/request.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import * as invocationProtocol from '@astrale-os/kernel-protocol/invocation';
|
|
2
|
-
import {
|
|
2
|
+
import { replayableBody } from '../transport/http/binary-request.js';
|
|
3
3
|
import { acceptCall } from './admission.js';
|
|
4
4
|
export function call(target, input) {
|
|
5
5
|
return Object.freeze({ target, input });
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Admit one request. A public caller's body is a Blob in its options; the package-private path
|
|
9
|
+
* passes a body its owner already admitted, which may be a stream that only Session routing sends.
|
|
10
|
+
*/
|
|
11
|
+
export function admitRequest(input, options, lifecycle, admittedBody) {
|
|
9
12
|
const call = acceptCall(input);
|
|
10
|
-
const admitted = admitRequestOptions(options
|
|
13
|
+
const admitted = admitRequestOptions(options);
|
|
14
|
+
const body = admittedBody ?? admitted.body;
|
|
11
15
|
const admittedOptions = lifecycleOptions(admitted.options, lifecycle);
|
|
12
16
|
const delegate = admitDelegate(options?.delegate);
|
|
13
17
|
const routing = admitRouting(options?.routing);
|
|
@@ -19,7 +23,7 @@ export function admitRequest(input, options, lifecycle, streams) {
|
|
|
19
23
|
...(routing === undefined ? {} : { routing }),
|
|
20
24
|
...(schema === undefined ? {} : { schema }),
|
|
21
25
|
...(maintenance === undefined ? {} : { maintenance }),
|
|
22
|
-
...(
|
|
26
|
+
...(body === undefined ? {} : { body }),
|
|
23
27
|
options: admittedOptions,
|
|
24
28
|
});
|
|
25
29
|
}
|
|
@@ -49,7 +53,7 @@ export function invocation(request, credential, trace) {
|
|
|
49
53
|
...(admittedTrace === undefined ? {} : { trace: admittedTrace }),
|
|
50
54
|
});
|
|
51
55
|
}
|
|
52
|
-
function admitRequestOptions(input
|
|
56
|
+
function admitRequestOptions(input) {
|
|
53
57
|
if (input === undefined)
|
|
54
58
|
return {};
|
|
55
59
|
if (input === null || typeof input !== 'object' || Array.isArray(input)) {
|
|
@@ -73,19 +77,12 @@ function admitRequestOptions(input, streams) {
|
|
|
73
77
|
input.timeoutMs > 2_147_483_647)) {
|
|
74
78
|
throw new TypeError('Client request timeoutMs must be a positive safe platform integer.');
|
|
75
79
|
}
|
|
76
|
-
const hasBody = Object.hasOwn(input, 'body');
|
|
77
80
|
let body;
|
|
78
|
-
if (
|
|
81
|
+
if (Object.hasOwn(input, 'body')) {
|
|
79
82
|
const candidate = input.body;
|
|
80
|
-
if (
|
|
81
|
-
body = acceptBinaryBody(candidate);
|
|
82
|
-
}
|
|
83
|
-
else if (candidate instanceof Blob) {
|
|
84
|
-
body = candidate;
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
83
|
+
if (!(candidate instanceof Blob))
|
|
87
84
|
throw new TypeError('Binary input must be a Blob or File.');
|
|
88
|
-
|
|
85
|
+
body = replayableBody(candidate);
|
|
89
86
|
}
|
|
90
87
|
if (body !== undefined && input.idempotencyKey !== undefined) {
|
|
91
88
|
throw new TypeError('Binary requests cannot carry an idempotency key.');
|
package/dist/errors/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './client-error.js';
|
|
|
2
2
|
export * from './exchange-error.js';
|
|
3
3
|
export * from './miss-error.js';
|
|
4
4
|
export * from './protocol-error.js';
|
|
5
|
+
export * from './query-input.js';
|
|
5
6
|
export * from './refusal.js';
|
|
6
7
|
export * from './response-error.js';
|
|
7
8
|
export * from './session-error.js';
|
package/dist/errors/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export * from './client-error.js';
|
|
|
2
2
|
export * from './exchange-error.js';
|
|
3
3
|
export * from './miss-error.js';
|
|
4
4
|
export * from './protocol-error.js';
|
|
5
|
+
export * from './query-input.js';
|
|
5
6
|
export * from './refusal.js';
|
|
6
7
|
export * from './response-error.js';
|
|
7
8
|
export * from './session-error.js';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Refusal } from '@astrale-os/kernel-core/graph/query';
|
|
2
|
+
import * as errors from '@astrale-os/kernel-protocol/errors';
|
|
3
|
+
import { ResponseError } from './response-error.js';
|
|
4
|
+
/**
|
|
5
|
+
* Why the Kernel refused a Query as input (`QUERY_INPUT_INVALID`), by the phase that refused it.
|
|
6
|
+
* Nothing was read, and the same request is refused again.
|
|
7
|
+
*/
|
|
8
|
+
export type QueryInputDetails =
|
|
9
|
+
/** A v7 Query the wire refused whole: each fault, where it is and how to fix it (§ Wire v7). */
|
|
10
|
+
{
|
|
11
|
+
readonly phase: 'decode';
|
|
12
|
+
readonly refusals: readonly Readonly<Refusal>[];
|
|
13
|
+
}
|
|
14
|
+
/** A Query its planning refused: the issue, and where in the request when it says. */
|
|
15
|
+
| {
|
|
16
|
+
readonly phase: 'plan';
|
|
17
|
+
readonly issue: string;
|
|
18
|
+
readonly path?: string;
|
|
19
|
+
}
|
|
20
|
+
/** A Query past a limit the Kernel sets for every caller: which, its maximum, what it needs. */
|
|
21
|
+
| {
|
|
22
|
+
readonly phase: 'plan';
|
|
23
|
+
readonly issue: 'QUERY_PLAN_LIMIT_EXCEEDED';
|
|
24
|
+
readonly limit: string;
|
|
25
|
+
readonly maximum: number;
|
|
26
|
+
readonly actual: number;
|
|
27
|
+
readonly path?: string;
|
|
28
|
+
}
|
|
29
|
+
/** An `expected` closure the Kernel cannot read, or a V6 page size: where. */
|
|
30
|
+
| {
|
|
31
|
+
readonly phase: 'input';
|
|
32
|
+
readonly path: string;
|
|
33
|
+
}
|
|
34
|
+
/** A V6 QueryAST the Kernel could not decode: where. */
|
|
35
|
+
| {
|
|
36
|
+
readonly phase: 'decode';
|
|
37
|
+
readonly path: string;
|
|
38
|
+
};
|
|
39
|
+
/** The reason of a Query the Kernel refused as input. */
|
|
40
|
+
export type QueryInputReason = errors.ErrorReason<'QUERY_INPUT_INVALID', QueryInputDetails>;
|
|
41
|
+
/**
|
|
42
|
+
* Whether the Kernel refused a Query as input: nothing was read, and resending it unchanged is
|
|
43
|
+
* refused again. Its `reason.details` then say where and why, typed by phase.
|
|
44
|
+
*/
|
|
45
|
+
export declare function isQueryInputInvalid(error: unknown): error is Omit<ResponseError, 'reason'> & {
|
|
46
|
+
readonly reason: QueryInputReason;
|
|
47
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as errors from '@astrale-os/kernel-protocol/errors';
|
|
2
|
+
import { ResponseError } from './response-error.js';
|
|
3
|
+
/**
|
|
4
|
+
* Whether the Kernel refused a Query as input: nothing was read, and resending it unchanged is
|
|
5
|
+
* refused again. Its `reason.details` then say where and why, typed by phase.
|
|
6
|
+
*/
|
|
7
|
+
export function isQueryInputInvalid(error) {
|
|
8
|
+
return (error instanceof ResponseError &&
|
|
9
|
+
error.code === errors.CODES.VALIDATION_ERROR &&
|
|
10
|
+
error.reason?.code === 'QUERY_INPUT_INVALID' &&
|
|
11
|
+
isQueryInputDetails(error.reason.details));
|
|
12
|
+
}
|
|
13
|
+
const REFUSAL_FIELDS = new Set([
|
|
14
|
+
'code',
|
|
15
|
+
'path',
|
|
16
|
+
'expected',
|
|
17
|
+
'fix',
|
|
18
|
+
'didYouMean',
|
|
19
|
+
'tier',
|
|
20
|
+
]);
|
|
21
|
+
const ISSUE = /^[A-Z][A-Z0-9_]{0,127}$/u;
|
|
22
|
+
/** The details the Kernel gives a refused Query, each phase with exactly its own fields. */
|
|
23
|
+
function isQueryInputDetails(details) {
|
|
24
|
+
const path = details.path === undefined ? [] : ['path'];
|
|
25
|
+
switch (details.phase) {
|
|
26
|
+
case 'decode':
|
|
27
|
+
return Object.hasOwn(details, 'refusals')
|
|
28
|
+
? exact(details, ['phase', 'refusals']) &&
|
|
29
|
+
Array.isArray(details.refusals) &&
|
|
30
|
+
details.refusals.length > 0 &&
|
|
31
|
+
details.refusals.every(isRefusal)
|
|
32
|
+
: exact(details, ['phase', 'path']) && isPointer(details.path);
|
|
33
|
+
case 'input':
|
|
34
|
+
return exact(details, ['phase', 'path']) && isPointer(details.path);
|
|
35
|
+
case 'plan':
|
|
36
|
+
if (typeof details.issue !== 'string' ||
|
|
37
|
+
!ISSUE.test(details.issue) ||
|
|
38
|
+
(details.path !== undefined && !isPointer(details.path))) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
if (!Object.hasOwn(details, 'limit'))
|
|
42
|
+
return exact(details, ['phase', 'issue', ...path]);
|
|
43
|
+
return (details.issue === 'QUERY_PLAN_LIMIT_EXCEEDED' &&
|
|
44
|
+
exact(details, ['phase', 'issue', 'limit', 'maximum', 'actual', ...path]) &&
|
|
45
|
+
typeof details.limit === 'string' &&
|
|
46
|
+
details.limit.length > 0 &&
|
|
47
|
+
isCount(details.maximum) &&
|
|
48
|
+
isCount(details.actual) &&
|
|
49
|
+
details.actual > details.maximum);
|
|
50
|
+
default:
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** One refusal of the v7 wire, as the Kernel carries it: `{code, path, expected, fix, …}`. */
|
|
55
|
+
function isRefusal(input) {
|
|
56
|
+
return (isObject(input) &&
|
|
57
|
+
Object.keys(input).every((field) => REFUSAL_FIELDS.has(field)) &&
|
|
58
|
+
typeof input.code === 'string' &&
|
|
59
|
+
/^QUERY_[A-Z_]{1,64}$/u.test(input.code) &&
|
|
60
|
+
isPointer(input.path) &&
|
|
61
|
+
typeof input.expected === 'string' &&
|
|
62
|
+
typeof input.fix === 'string' &&
|
|
63
|
+
(input.didYouMean === undefined ||
|
|
64
|
+
(Array.isArray(input.didYouMean) &&
|
|
65
|
+
input.didYouMean.every((name) => typeof name === 'string'))) &&
|
|
66
|
+
(input.tier === undefined || typeof input.tier === 'string'));
|
|
67
|
+
}
|
|
68
|
+
/** An RFC 6901 pointer into the request, as the Kernel bounds it. */
|
|
69
|
+
function isPointer(input) {
|
|
70
|
+
return (typeof input === 'string' &&
|
|
71
|
+
input.length <= 1_024 &&
|
|
72
|
+
input.normalize('NFC') === input &&
|
|
73
|
+
(input === '' || input.startsWith('/')));
|
|
74
|
+
}
|
|
75
|
+
function isCount(input) {
|
|
76
|
+
return typeof input === 'number' && Number.isSafeInteger(input) && input >= 0;
|
|
77
|
+
}
|
|
78
|
+
function isObject(input) {
|
|
79
|
+
return input !== null && typeof input === 'object' && !Array.isArray(input);
|
|
80
|
+
}
|
|
81
|
+
function exact(input, fields) {
|
|
82
|
+
return (Object.keys(input).length === fields.length &&
|
|
83
|
+
fields.every((field) => Object.hasOwn(input, field)));
|
|
84
|
+
}
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import type { RequestOptions } from '../transport/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The time a wait leaves its answer to come back. The Kernel bounds a wait by its own request
|
|
4
|
+
* deadline, never by this call's: the client ends each wait this long before its request times out.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ANSWER_MARGIN_MS = 2000;
|
|
2
7
|
/**
|
|
3
8
|
* The absolute deadline of one Client call, whatever number of Kernel requests it sends: its
|
|
4
9
|
* `timeoutMs` from now when given, otherwise none (`Infinity`), each request then taking its default.
|
|
5
10
|
*/
|
|
6
11
|
export declare function deadlineOf(options: RequestOptions | undefined): number;
|
|
12
|
+
/**
|
|
13
|
+
* When a wait of `waitMs` from now ends: then, or the answer margin before the call's `deadline`
|
|
14
|
+
* if that comes first, so that its answer comes back in time.
|
|
15
|
+
*/
|
|
16
|
+
export declare function waitEnd(deadline: number, waitMs: number): number;
|
|
7
17
|
/** The options of the call's next request: the time left before its deadline, at least 1 ms. */
|
|
8
18
|
export declare function within(deadline: number, options: RequestOptions | undefined): RequestOptions | undefined;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The time a wait leaves its answer to come back. The Kernel bounds a wait by its own request
|
|
3
|
+
* deadline, never by this call's: the client ends each wait this long before its request times out.
|
|
4
|
+
*/
|
|
5
|
+
export const ANSWER_MARGIN_MS = 2_000;
|
|
1
6
|
/**
|
|
2
7
|
* The absolute deadline of one Client call, whatever number of Kernel requests it sends: its
|
|
3
8
|
* `timeoutMs` from now when given, otherwise none (`Infinity`), each request then taking its default.
|
|
@@ -5,6 +10,13 @@
|
|
|
5
10
|
export function deadlineOf(options) {
|
|
6
11
|
return options?.timeoutMs === undefined ? Infinity : Date.now() + options.timeoutMs;
|
|
7
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* When a wait of `waitMs` from now ends: then, or the answer margin before the call's `deadline`
|
|
15
|
+
* if that comes first, so that its answer comes back in time.
|
|
16
|
+
*/
|
|
17
|
+
export function waitEnd(deadline, waitMs) {
|
|
18
|
+
return Math.min(Date.now() + waitMs, deadline - ANSWER_MARGIN_MS);
|
|
19
|
+
}
|
|
8
20
|
/** The options of the call's next request: the time left before its deadline, at least 1 ms. */
|
|
9
21
|
export function within(deadline, options) {
|
|
10
22
|
if (deadline === Infinity)
|
|
@@ -6,18 +6,13 @@ import { call as invocation } from '../client/index.js';
|
|
|
6
6
|
import { ResponseError, TransportError } from '../errors/index.js';
|
|
7
7
|
import { RETRY_REFUSALS, retry } from '../pacer/index.js';
|
|
8
8
|
import { acceptOutput } from './admission.js';
|
|
9
|
-
import { deadlineOf, within } from './deadline.js';
|
|
9
|
+
import { ANSWER_MARGIN_MS, deadlineOf, waitEnd, within } from './deadline.js';
|
|
10
10
|
/** Attempts of one effect-free Execution read; the call's deadline bounds them too. */
|
|
11
11
|
const READ_ATTEMPTS = 8;
|
|
12
12
|
/** A pending answer sooner than this did not wait: the Kernel answers now, so waiting ends. */
|
|
13
13
|
const LAPSED_WAIT_MS = 1_000;
|
|
14
14
|
/** No wait is sent again with less time left than this. */
|
|
15
15
|
const MINIMUM_WAIT_MS = 1_000;
|
|
16
|
-
/**
|
|
17
|
-
* The time a wait leaves its answer to come back. The Kernel bounds a wait by its own request
|
|
18
|
-
* deadline, never by this call's: the client ends each wait this long before its request times out.
|
|
19
|
-
*/
|
|
20
|
-
const ANSWER_MARGIN_MS = 2_000;
|
|
21
16
|
/** Bind the `K.Execution` Methods to one call capability. */
|
|
22
17
|
export function createExecution(call) {
|
|
23
18
|
// A completed value is the handler output, which only the reference types.
|
|
@@ -76,7 +71,7 @@ export function executionMethods(call, accept) {
|
|
|
76
71
|
async result(target, wait, options) {
|
|
77
72
|
const id = idOf(target);
|
|
78
73
|
const deadline = deadlineOf(options);
|
|
79
|
-
const end =
|
|
74
|
+
const end = waitEnd(deadline, acceptWait(wait));
|
|
80
75
|
for (;;) {
|
|
81
76
|
const sent = Date.now();
|
|
82
77
|
try {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type { DeletedExecutionStatus, ExecutionFailure, ExecutionNodeStatus, ExecutionOutcome, ExecutionRef, ExecutionState, ExecutionStatus, ExecutionTarget, ExecutionWait, } from './contracts.js';
|
|
2
2
|
export { acceptWait, createExecution, executionMethods, type ExecutionApi, type ExecutionCall, type ExecutionMethods, } from './execution.js';
|
|
3
3
|
export { acceptOutput } from './admission.js';
|
|
4
|
-
export { deadlineOf, within } from './deadline.js';
|
|
4
|
+
export { deadlineOf, waitEnd, within } from './deadline.js';
|
package/dist/execution/index.js
CHANGED
|
@@ -3,11 +3,11 @@ import type { Node } from '@astrale-os/kernel-core/graph/node';
|
|
|
3
3
|
import type { QueryAST, QuerySingleSourceClassOf } from '@astrale-os/kernel-core/graph/query';
|
|
4
4
|
import type { Domain } from '@astrale-os/kernel-dsl/v1/domain';
|
|
5
5
|
import type { AnyResolvedClass, ResolvedClass } from '@astrale-os/kernel-dsl/v1/language';
|
|
6
|
-
import type { GraphApi,
|
|
6
|
+
import type { GraphApi, GraphQueryV6Options } from '../graph.js';
|
|
7
7
|
import type { BoundEdge, BoundNode } from './model.js';
|
|
8
8
|
import type { BoundQueryPage } from './page.js';
|
|
9
9
|
import type { MethodCall } from './project.js';
|
|
10
|
-
export type DomainQueryOptions = Omit<
|
|
10
|
+
export type DomainQueryOptions = Omit<GraphQueryV6Options, 'expected'>;
|
|
11
11
|
type AdmittedSourceClasses<Query extends QueryAST> = [QuerySingleSourceClassOf<Query>] extends [
|
|
12
12
|
never
|
|
13
13
|
] ? never : QuerySingleSourceClassOf<Query> extends AnyResolvedClass ? unknown : never;
|
package/dist/graph/graph.d.ts
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
import type { GraphSpec } from '@astrale-os/kernel-core/graph/graph';
|
|
2
2
|
import type { MutationAST as MutationASTValue, MutationBuilder, MutationInput, MutationResult as MutationResultValue } from '@astrale-os/kernel-core/graph/mutate';
|
|
3
3
|
import type { Node } from '@astrale-os/kernel-core/graph/node';
|
|
4
|
-
import type { QueryAST as QueryASTValue, QueryEdgeClassInput, QueryResultFor } from '@astrale-os/kernel-core/graph/query';
|
|
4
|
+
import type { QueryAST as QueryASTValue, QueryEdgeClassInput, QueryResultFor, wire } from '@astrale-os/kernel-core/graph/query';
|
|
5
5
|
import type { NodeTarget } from '@astrale-os/kernel-core/path';
|
|
6
6
|
import type { DomainDependency } from '@astrale-os/kernel-dsl/v1/schema';
|
|
7
7
|
import type { Call, Input } from '../client/index.js';
|
|
8
8
|
import type { RequestOptions } from '../transport/index.js';
|
|
9
|
-
import type { QueryPageRequest, QueryResponse } from './page-contract.js';
|
|
9
|
+
import type { QueryAnswerFor, QueryPageRequest, QueryResponse } from './page-contract.js';
|
|
10
10
|
import type { NeighborsOptions, NodePage } from './page/index.js';
|
|
11
11
|
export type GraphCall = (call: Call, options?: RequestOptions) => Promise<Input>;
|
|
12
|
+
/**
|
|
13
|
+
* The delivery of one Query: its page sizes and cursor (`paging`, never meaning, W1), the exact
|
|
14
|
+
* Domain revisions it is planned against, and its transport options.
|
|
15
|
+
*/
|
|
12
16
|
export interface GraphQueryOptions extends RequestOptions {
|
|
17
|
+
readonly paging?: wire.Paging;
|
|
18
|
+
readonly expected?: readonly DomainDependency[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The options of a V6 QueryAST: its page and the exact Domain revisions it is planned against.
|
|
22
|
+
* @deprecated Query V6 is the legacy language: send a Query with `GraphQueryOptions`.
|
|
23
|
+
*/
|
|
24
|
+
export interface GraphQueryV6Options extends RequestOptions {
|
|
13
25
|
readonly expected?: readonly DomainDependency[];
|
|
14
26
|
readonly page: QueryPageRequest;
|
|
15
27
|
}
|
|
@@ -19,7 +31,9 @@ export interface GraphMutationOptions extends RequestOptions {
|
|
|
19
31
|
}
|
|
20
32
|
export type MutationAuthor = (mutation: MutationBuilder) => undefined;
|
|
21
33
|
export interface GraphApi {
|
|
22
|
-
query<Query extends
|
|
34
|
+
query<Query extends wire.Document>(query: Query, options?: GraphQueryOptions): Promise<QueryAnswerFor<Query>>;
|
|
35
|
+
/** The legacy V6 path; it stays the last overload, which `Parameters` and `ReturnType` read. */
|
|
36
|
+
query<Query extends QueryASTValue>(ast: Query, options: GraphQueryV6Options): Promise<QueryResponse<QueryResultFor<Query>>>;
|
|
23
37
|
mutate(author: MutationAuthor, options?: GraphMutationOptions): Promise<MutationResultValue>;
|
|
24
38
|
mutate(ast: MutationASTValue | MutationInput | GraphSpec, options?: GraphMutationOptions): Promise<MutationResultValue>;
|
|
25
39
|
get(target: NodeTarget, options?: RequestOptions): Promise<Node | null>;
|
package/dist/graph/graph.js
CHANGED
|
@@ -6,7 +6,10 @@ import { getNode, requireNode } from './read.js';
|
|
|
6
6
|
export function createGraph(call) {
|
|
7
7
|
if (typeof call !== 'function')
|
|
8
8
|
throw new TypeError('Graph call capability is invalid.');
|
|
9
|
-
|
|
9
|
+
function query(input, options) {
|
|
10
|
+
// The overloads above type the call; `queryGraph` dispatches on the input itself.
|
|
11
|
+
return queryGraph(call, input, options);
|
|
12
|
+
}
|
|
10
13
|
const mutate = (input, options) => mutateGraph(call, input, options);
|
|
11
14
|
return Object.freeze({
|
|
12
15
|
query,
|
package/dist/graph/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { createGraph, type GraphApi, type GraphCall, type GraphMutationOptions, type
|
|
2
|
-
export type { QueryPageRequest, QueryResponse } from './page-contract.js';
|
|
1
|
+
export { createGraph, type GraphApi, type GraphCall, type GraphQueryOptions, type GraphMutationOptions, type GraphQueryV6Options, type MutationAuthor, } from './graph.js';
|
|
2
|
+
export type { QueryAnswer, QueryAnswerFor, QueryItem, QueryPage, QueryPageRequest, QueryResponse, } from './page-contract.js';
|
|
3
3
|
export { type BoundEdge, type BoundEdgePage, type BoundGraphValue, type BoundNode, type BoundNodeFor, type BoundNodePage, type BoundQueryPage, type DomainBinding, type DomainQueryOptions, definedClass, validateDefinedProperties, } from './domain/index.js';
|
|
4
4
|
export { NodeUnavailableError } from './errors.js';
|
|
5
5
|
export type { NeighborsOptions, NodePage } from './page/index.js';
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EdgeKey } from '@astrale-os/kernel-core/graph/edge';
|
|
2
|
+
import type { FactId } from '@astrale-os/kernel-core/graph/formula';
|
|
3
|
+
import type { Answer, QueryResult, Undecided, wire } from '@astrale-os/kernel-core/graph/query';
|
|
2
4
|
/** Caller-selected bounds and continuation for one graph query page. */
|
|
3
5
|
export interface QueryPageRequest {
|
|
4
6
|
readonly size: number;
|
|
@@ -17,3 +19,53 @@ export interface QueryResponse<Result extends QueryResult = QueryResult> {
|
|
|
17
19
|
*/
|
|
18
20
|
readonly certification?: 'uncertified';
|
|
19
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* One Page of a Query's answer (page "Fondations Query v7", § Résultats): the exact prefix of its
|
|
24
|
+
* list, and the opaque cursor that continues it when an item follows (W2, W3).
|
|
25
|
+
*/
|
|
26
|
+
export type QueryPage = {
|
|
27
|
+
readonly items: readonly QueryItem[];
|
|
28
|
+
readonly undecided?: Undecided;
|
|
29
|
+
} & ({
|
|
30
|
+
readonly complete: true;
|
|
31
|
+
} | {
|
|
32
|
+
readonly complete: false;
|
|
33
|
+
readonly cursor: string;
|
|
34
|
+
});
|
|
35
|
+
/** One delivered item: its fact, the Edge its Branch followed, the ends it renders, its Branches. */
|
|
36
|
+
export interface QueryItem {
|
|
37
|
+
readonly fact: FactId;
|
|
38
|
+
readonly edge?: EdgeKey;
|
|
39
|
+
readonly source?: QueryItem;
|
|
40
|
+
readonly target?: QueryItem;
|
|
41
|
+
readonly branches: Readonly<Record<string, QueryPage | Exclude<Answer, {
|
|
42
|
+
readonly list: unknown;
|
|
43
|
+
}>>>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* What a Query answers, by the family of its root fold: a list's Page, the table of the facts it
|
|
47
|
+
* renders as values, the revision it was read at and whether its cursor came from another (W6);
|
|
48
|
+
* an `exists`; or a `count`.
|
|
49
|
+
*/
|
|
50
|
+
export type QueryAnswer = {
|
|
51
|
+
readonly list: QueryPage;
|
|
52
|
+
readonly facts: Extract<Answer, {
|
|
53
|
+
readonly list: unknown;
|
|
54
|
+
}>['facts'];
|
|
55
|
+
readonly revision: string;
|
|
56
|
+
readonly revised?: true;
|
|
57
|
+
} | Exclude<Answer, {
|
|
58
|
+
readonly list: unknown;
|
|
59
|
+
}>;
|
|
60
|
+
/** The answer of the family a Query's root fold names. */
|
|
61
|
+
export type QueryAnswerFor<Query extends wire.Document> = Query extends {
|
|
62
|
+
readonly list: unknown;
|
|
63
|
+
} ? Extract<QueryAnswer, {
|
|
64
|
+
readonly list: unknown;
|
|
65
|
+
}> : Query extends {
|
|
66
|
+
readonly exists: unknown;
|
|
67
|
+
} ? Extract<QueryAnswer, {
|
|
68
|
+
readonly exists: unknown;
|
|
69
|
+
}> : Extract<QueryAnswer, {
|
|
70
|
+
readonly count: unknown;
|
|
71
|
+
}>;
|
package/dist/graph/query.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import type { QueryAST as QueryASTValue, QueryResultFor } from '@astrale-os/kernel-core/graph/query';
|
|
1
|
+
import type { QueryAST as QueryASTValue, QueryResultFor, wire } from '@astrale-os/kernel-core/graph/query';
|
|
2
2
|
import { Path, type NodeTarget } from '@astrale-os/kernel-core/path';
|
|
3
|
-
import type { GraphCall, GraphQueryOptions } from './graph.js';
|
|
4
|
-
import type { QueryResponse } from './page-contract.js';
|
|
3
|
+
import type { GraphCall, GraphQueryOptions, GraphQueryV6Options } from './graph.js';
|
|
4
|
+
import type { QueryAnswerFor, QueryResponse } from './page-contract.js';
|
|
5
5
|
/** Point/neighbor reads are exact targets, unlike Query's overloaded Class sources. */
|
|
6
6
|
export declare function queryNodePath(target: NodeTarget): Path;
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Query the graph. A Query names its version in `query` (`"astrale.query/7"`); anything else
|
|
9
|
+
* takes the legacy V6 path, whose codec admits a QueryAST by its `format` and `version` and
|
|
10
|
+
* refuses the rest as it always has.
|
|
11
|
+
*/
|
|
12
|
+
export declare function queryGraph<Query extends wire.Document>(call: GraphCall, query: Query, options?: GraphQueryOptions): Promise<QueryAnswerFor<Query>>;
|
|
13
|
+
export declare function queryGraph<Query extends QueryASTValue>(call: GraphCall, ast: Query, options: GraphQueryV6Options): Promise<QueryResponse<QueryResultFor<Query>>>;
|