@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/store/shape.d.ts
CHANGED
|
@@ -5,25 +5,46 @@ import type { QueryPageRequest } from '../graph/index.js';
|
|
|
5
5
|
import type { FactReferences } from './entity-index.js';
|
|
6
6
|
import type { StoreQueryResponse, StoreSnapshot } from './store.js';
|
|
7
7
|
type ShapeState = StoreSnapshot['state'];
|
|
8
|
+
/** A confirmed server response with the facts it references and the response displayed from it. */
|
|
9
|
+
export interface QueryAnswer {
|
|
10
|
+
readonly confirmed: StoreQueryResponse;
|
|
11
|
+
readonly references: FactReferences;
|
|
12
|
+
readonly response: StoreQueryResponse;
|
|
13
|
+
readonly refreshedAt: number;
|
|
14
|
+
}
|
|
15
|
+
/** One cached query: its answer, snapshot, observers, in-flight read and retention clock. */
|
|
8
16
|
export declare class QueryShape {
|
|
17
|
+
#private;
|
|
9
18
|
readonly key: string;
|
|
10
19
|
readonly ast: QueryAST;
|
|
11
20
|
readonly page: QueryPageRequest;
|
|
12
21
|
readonly expected: readonly DomainDependency[] | undefined;
|
|
13
|
-
readonly
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
releasedAt?: number;
|
|
21
|
-
accessedAt: number;
|
|
22
|
-
refreshedAt?: number;
|
|
23
|
-
snapshot: StoreSnapshot;
|
|
24
|
-
constructor(key: string, ast: QueryAST, page: QueryPageRequest, expected: readonly DomainDependency[] | undefined, now: number);
|
|
22
|
+
constructor(key: string, ast: QueryAST, page: QueryPageRequest, expected: readonly DomainDependency[] | undefined, now: number, report: (error: unknown) => void);
|
|
23
|
+
get snapshot(): StoreSnapshot;
|
|
24
|
+
get state(): ShapeState;
|
|
25
|
+
get answer(): QueryAnswer | undefined;
|
|
26
|
+
get inflight(): Promise<StoreQueryResponse> | undefined;
|
|
27
|
+
get invalidation(): number;
|
|
28
|
+
get accessedAt(): number;
|
|
25
29
|
get observed(): boolean;
|
|
30
|
+
/** When the shape became unobserved and idle, or undefined while it is observed or reading. */
|
|
31
|
+
idleSince(): number | undefined;
|
|
26
32
|
referencesAny(nodes: ReadonlySet<NodeId>, edges: ReadonlySet<string>): boolean;
|
|
33
|
+
touch(now: number): void;
|
|
34
|
+
listen(listener: () => void, now: number): void;
|
|
35
|
+
/** Removes a listener; the caller releases the shape once it is no longer observed. */
|
|
36
|
+
unlisten(listener: () => void): void;
|
|
37
|
+
release(now: number): void;
|
|
38
|
+
begin(read: Promise<StoreQueryResponse>): void;
|
|
39
|
+
/** Ends `read` if it is still the shape's read and reports whether it was. */
|
|
40
|
+
finish(read: Promise<StoreQueryResponse>): boolean;
|
|
41
|
+
invalidate(): void;
|
|
42
|
+
/** Records a newly confirmed answer, then publishes `state`. */
|
|
43
|
+
settle(answer: QueryAnswer, state: ShapeState): void;
|
|
44
|
+
/** Replaces the displayed answer without a new server confirmation, then publishes `state`. */
|
|
45
|
+
show(answer: QueryAnswer, state: ShapeState): void;
|
|
46
|
+
publish(state: ShapeState, error?: unknown): void;
|
|
47
|
+
close(): void;
|
|
27
48
|
}
|
|
28
49
|
export declare const COLD_SNAPSHOT: StoreSnapshot;
|
|
29
50
|
export {};
|
package/dist/store/shape.js
CHANGED
|
@@ -1,32 +1,141 @@
|
|
|
1
|
+
/** One cached query: its answer, snapshot, observers, in-flight read and retention clock. */
|
|
1
2
|
export class QueryShape {
|
|
2
3
|
key;
|
|
3
4
|
ast;
|
|
4
5
|
page;
|
|
5
6
|
expected;
|
|
6
|
-
listeners = new Set();
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
releasedAt;
|
|
14
|
-
|
|
15
|
-
refreshedAt;
|
|
16
|
-
snapshot = COLD_SNAPSHOT;
|
|
17
|
-
constructor(key, ast, page, expected, now) {
|
|
7
|
+
#listeners = new Set();
|
|
8
|
+
#report;
|
|
9
|
+
#snapshot = COLD_SNAPSHOT;
|
|
10
|
+
#answer;
|
|
11
|
+
#inflight;
|
|
12
|
+
#invalidation = 0;
|
|
13
|
+
#accessedAt;
|
|
14
|
+
#releasedAt;
|
|
15
|
+
constructor(key, ast, page, expected, now, report) {
|
|
18
16
|
this.key = key;
|
|
19
17
|
this.ast = ast;
|
|
20
18
|
this.page = page;
|
|
21
19
|
this.expected = expected;
|
|
22
|
-
this
|
|
20
|
+
this.#accessedAt = now;
|
|
21
|
+
this.#releasedAt = now;
|
|
22
|
+
this.#report = report;
|
|
23
|
+
}
|
|
24
|
+
get snapshot() {
|
|
25
|
+
return this.#snapshot;
|
|
26
|
+
}
|
|
27
|
+
get state() {
|
|
28
|
+
return this.#snapshot.state;
|
|
29
|
+
}
|
|
30
|
+
get answer() {
|
|
31
|
+
return this.#answer;
|
|
32
|
+
}
|
|
33
|
+
get inflight() {
|
|
34
|
+
return this.#inflight;
|
|
35
|
+
}
|
|
36
|
+
get invalidation() {
|
|
37
|
+
return this.#invalidation;
|
|
38
|
+
}
|
|
39
|
+
get accessedAt() {
|
|
40
|
+
return this.#accessedAt;
|
|
23
41
|
}
|
|
24
42
|
get observed() {
|
|
25
|
-
return this
|
|
43
|
+
return this.#listeners.size > 0;
|
|
44
|
+
}
|
|
45
|
+
/** When the shape became unobserved and idle, or undefined while it is observed or reading. */
|
|
46
|
+
idleSince() {
|
|
47
|
+
return this.observed || this.#inflight !== undefined ? undefined : this.#releasedAt;
|
|
26
48
|
}
|
|
27
49
|
referencesAny(nodes, edges) {
|
|
28
|
-
|
|
29
|
-
|
|
50
|
+
const references = this.#answer?.references;
|
|
51
|
+
return (references?.nodes.some((id) => nodes.has(id)) === true ||
|
|
52
|
+
references?.edges.some((key) => edges.has(key)) === true);
|
|
53
|
+
}
|
|
54
|
+
touch(now) {
|
|
55
|
+
this.#accessedAt = now;
|
|
56
|
+
if (!this.observed)
|
|
57
|
+
this.#releasedAt = now;
|
|
58
|
+
}
|
|
59
|
+
listen(listener, now) {
|
|
60
|
+
this.#listeners.add(listener);
|
|
61
|
+
this.#accessedAt = now;
|
|
62
|
+
this.#releasedAt = undefined;
|
|
63
|
+
}
|
|
64
|
+
/** Removes a listener; the caller releases the shape once it is no longer observed. */
|
|
65
|
+
unlisten(listener) {
|
|
66
|
+
this.#listeners.delete(listener);
|
|
67
|
+
}
|
|
68
|
+
release(now) {
|
|
69
|
+
this.#releasedAt = now;
|
|
70
|
+
}
|
|
71
|
+
begin(read) {
|
|
72
|
+
this.#inflight = read;
|
|
73
|
+
}
|
|
74
|
+
/** Ends `read` if it is still the shape's read and reports whether it was. */
|
|
75
|
+
finish(read) {
|
|
76
|
+
if (this.#inflight !== read)
|
|
77
|
+
return false;
|
|
78
|
+
this.#inflight = undefined;
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
invalidate() {
|
|
82
|
+
this.#invalidation += 1;
|
|
83
|
+
}
|
|
84
|
+
/** Records a newly confirmed answer, then publishes `state`. */
|
|
85
|
+
settle(answer, state) {
|
|
86
|
+
this.#answer = answer;
|
|
87
|
+
this.touch(answer.refreshedAt);
|
|
88
|
+
this.publish(state);
|
|
89
|
+
}
|
|
90
|
+
/** Replaces the displayed answer without a new server confirmation, then publishes `state`. */
|
|
91
|
+
show(answer, state) {
|
|
92
|
+
this.#answer = answer;
|
|
93
|
+
this.publish(state);
|
|
94
|
+
}
|
|
95
|
+
publish(state, error) {
|
|
96
|
+
const next = snapshotFor(state, this.#answer?.response, error);
|
|
97
|
+
if (sameSnapshot(this.#snapshot, next))
|
|
98
|
+
return;
|
|
99
|
+
this.#snapshot = next;
|
|
100
|
+
for (const listener of Array.from(this.#listeners)) {
|
|
101
|
+
try {
|
|
102
|
+
listener();
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
this.#report(error);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
close() {
|
|
110
|
+
this.#listeners.clear();
|
|
111
|
+
this.#inflight?.catch(() => undefined);
|
|
30
112
|
}
|
|
31
113
|
}
|
|
32
114
|
export const COLD_SNAPSHOT = Object.freeze({ state: 'cold' });
|
|
115
|
+
function snapshotFor(state, response, error) {
|
|
116
|
+
switch (state) {
|
|
117
|
+
case 'cold':
|
|
118
|
+
return Object.freeze({ state });
|
|
119
|
+
case 'loading':
|
|
120
|
+
return Object.freeze({ state });
|
|
121
|
+
case 'failed':
|
|
122
|
+
return Object.freeze({ state, error, ...(response === undefined ? {} : { response }) });
|
|
123
|
+
case 'ready':
|
|
124
|
+
case 'stale':
|
|
125
|
+
case 'refreshing':
|
|
126
|
+
case 'optimistic':
|
|
127
|
+
if (response === undefined)
|
|
128
|
+
throw new TypeError(`Store ${state} snapshot requires a response.`);
|
|
129
|
+
return Object.freeze({ state, response });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function sameSnapshot(left, right) {
|
|
133
|
+
if (left.state !== right.state)
|
|
134
|
+
return false;
|
|
135
|
+
if ('response' in left || 'response' in right) {
|
|
136
|
+
if (!('response' in left) || !('response' in right) || left.response !== right.response) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return left.state !== 'failed' || right.state !== 'failed' || left.error === right.error;
|
|
141
|
+
}
|
package/dist/store/store.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { MutationAST, MutationInput, MutationResult } from '@astrale-os/kernel-core/graph/mutate';
|
|
2
2
|
import type { QueryAST, QueryResultFor } from '@astrale-os/kernel-core/graph/query';
|
|
3
3
|
import type { QueryResponse } from '../graph/index.js';
|
|
4
|
-
import type { GraphApi, GraphMutationOptions,
|
|
4
|
+
import type { GraphApi, GraphMutationOptions, GraphQueryV6Options, MutationAuthor } from '../graph/index.js';
|
|
5
5
|
export type StoreQuery = QueryAST;
|
|
6
6
|
export type StoreQueryResponse<Query extends StoreQuery = StoreQuery> = QueryResponse<QueryResultFor<Query>>;
|
|
7
|
-
export interface StoreReadOptions extends
|
|
7
|
+
export interface StoreReadOptions extends GraphQueryV6Options {
|
|
8
8
|
readonly freshness?: 'cached' | 'refresh';
|
|
9
9
|
}
|
|
10
10
|
export interface StoreMutationOptions extends GraphMutationOptions {
|
|
@@ -50,15 +50,15 @@ export declare class GraphStore {
|
|
|
50
50
|
private closed;
|
|
51
51
|
constructor(options: StoreOptions);
|
|
52
52
|
read<Query extends StoreQuery>(query: Query, options: StoreReadOptions): Promise<StoreQueryResponse<Query>>;
|
|
53
|
-
peek<Query extends StoreQuery>(query: Query, options:
|
|
53
|
+
peek<Query extends StoreQuery>(query: Query, options: GraphQueryV6Options): StoreQueryResponse<Query> | undefined;
|
|
54
54
|
preload<Query extends StoreQuery>(query: Query, options: StoreReadOptions): Promise<void>;
|
|
55
|
-
subscribe<Query extends StoreQuery>(query: Query, listener: () => void, options:
|
|
56
|
-
getSnapshot<Query extends StoreQuery>(query: Query, options:
|
|
55
|
+
subscribe<Query extends StoreQuery>(query: Query, listener: () => void, options: GraphQueryV6Options): () => void;
|
|
56
|
+
getSnapshot<Query extends StoreQuery>(query: Query, options: GraphQueryV6Options): StoreSnapshot<Query>;
|
|
57
57
|
observe<Query extends StoreQuery>(query: Query, listener: (snapshot: StoreSnapshot<Query>) => void, options: StoreReadOptions): () => void;
|
|
58
58
|
mutate(author: MutationAuthor, options?: StoreMutationOptions): Promise<MutationResult>;
|
|
59
59
|
mutate(input: MutationAST | MutationInput, options?: StoreMutationOptions): Promise<MutationResult>;
|
|
60
60
|
invalidate(): void;
|
|
61
|
-
invalidate(query: StoreQuery, options:
|
|
61
|
+
invalidate(query: StoreQuery, options: GraphQueryV6Options): void;
|
|
62
62
|
sweep(): void;
|
|
63
63
|
close(): void;
|
|
64
64
|
private admit;
|
package/dist/store/store.js
CHANGED
|
@@ -56,7 +56,7 @@ export class GraphStore {
|
|
|
56
56
|
}
|
|
57
57
|
peek(query, options) {
|
|
58
58
|
const { key } = this.identity(query, options);
|
|
59
|
-
return this.memory.get(key)?.response;
|
|
59
|
+
return this.memory.get(key)?.answer?.response;
|
|
60
60
|
}
|
|
61
61
|
async preload(query, options) {
|
|
62
62
|
await this.read(query, options);
|
|
@@ -1,23 +1,37 @@
|
|
|
1
|
-
type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
readonly
|
|
1
|
+
export type AutoVia = 'websocket' | 'http';
|
|
2
|
+
/** A state the Auto transport choice can rest in. */
|
|
3
|
+
export type AutoSettled = {
|
|
4
|
+
readonly kind: 'undecided';
|
|
5
5
|
} | {
|
|
6
|
-
readonly kind: '
|
|
7
|
-
readonly
|
|
6
|
+
readonly kind: 'chosen';
|
|
7
|
+
readonly via: AutoVia;
|
|
8
8
|
} | {
|
|
9
|
-
readonly kind: '
|
|
9
|
+
readonly kind: 'closed';
|
|
10
10
|
};
|
|
11
|
+
/** What `begin` grants: the probe itself, or the state the caller must follow. */
|
|
12
|
+
export type AutoTicket = {
|
|
13
|
+
readonly kind: 'probe';
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: 'probing';
|
|
16
|
+
readonly settled: Promise<AutoSettled>;
|
|
17
|
+
} | Exclude<AutoSettled, {
|
|
18
|
+
kind: 'undecided';
|
|
19
|
+
}>;
|
|
11
20
|
/** Serializes the one initial transport decision without retaining invocation values. */
|
|
12
21
|
export declare class AutoDecision {
|
|
13
|
-
private
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
private state;
|
|
23
|
+
get closed(): boolean;
|
|
24
|
+
/** The route every request follows, once one is chosen. */
|
|
25
|
+
get route(): 'websocket' | 'http' | undefined;
|
|
26
|
+
/** Claim the probe when undecided; otherwise report the state to follow. */
|
|
27
|
+
begin(): AutoTicket;
|
|
28
|
+
/** The probe proved WebSocket usable. */
|
|
29
|
+
selectWebSocket(): void;
|
|
18
30
|
/** Permanently degrade a prior or pending WebSocket selection to HTTP. */
|
|
19
31
|
demote(): void;
|
|
32
|
+
/** The probe proved nothing; the next caller probes again. */
|
|
20
33
|
release(): void;
|
|
21
|
-
|
|
34
|
+
/** Returns whether this call closed the decision. */
|
|
35
|
+
close(): boolean;
|
|
36
|
+
private move;
|
|
22
37
|
}
|
|
23
|
-
export {};
|
|
@@ -1,48 +1,55 @@
|
|
|
1
|
+
const UNDECIDED = Object.freeze({ kind: 'undecided' });
|
|
2
|
+
const CLOSED = Object.freeze({ kind: 'closed' });
|
|
1
3
|
/** Serializes the one initial transport decision without retaining invocation values. */
|
|
2
4
|
export class AutoDecision {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
state = UNDECIDED;
|
|
6
|
+
get closed() {
|
|
7
|
+
return this.state.kind === 'closed';
|
|
8
|
+
}
|
|
9
|
+
/** The route every request follows, once one is chosen. */
|
|
10
|
+
get route() {
|
|
11
|
+
return this.state.kind === 'chosen' ? this.state.via : undefined;
|
|
12
|
+
}
|
|
13
|
+
/** Claim the probe when undecided; otherwise report the state to follow. */
|
|
6
14
|
begin() {
|
|
7
|
-
if (this.
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return { kind: 'wait', selection: this.pending.promise };
|
|
13
|
-
let resolve;
|
|
14
|
-
const promise = new Promise((settle) => {
|
|
15
|
-
resolve = settle;
|
|
15
|
+
if (this.state.kind !== 'undecided')
|
|
16
|
+
return this.state;
|
|
17
|
+
let settle;
|
|
18
|
+
const settled = new Promise((resolve) => {
|
|
19
|
+
settle = resolve;
|
|
16
20
|
});
|
|
17
|
-
this.
|
|
21
|
+
this.state = { kind: 'probing', settled, settle };
|
|
18
22
|
return { kind: 'probe' };
|
|
19
23
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this.pending?.resolve(selection);
|
|
25
|
-
this.pending = undefined;
|
|
24
|
+
/** The probe proved WebSocket usable. */
|
|
25
|
+
selectWebSocket() {
|
|
26
|
+
if (this.state.kind === 'probing')
|
|
27
|
+
this.move({ kind: 'chosen', via: 'websocket' });
|
|
26
28
|
}
|
|
27
29
|
/** Permanently degrade a prior or pending WebSocket selection to HTTP. */
|
|
28
30
|
demote() {
|
|
29
|
-
if (this.
|
|
31
|
+
if (this.state.kind === 'closed')
|
|
32
|
+
return;
|
|
33
|
+
if (this.state.kind === 'chosen' && this.state.via === 'http')
|
|
30
34
|
return;
|
|
31
|
-
this.
|
|
32
|
-
this.pending?.resolve('http');
|
|
33
|
-
this.pending = undefined;
|
|
35
|
+
this.move({ kind: 'chosen', via: 'http' });
|
|
34
36
|
}
|
|
37
|
+
/** The probe proved nothing; the next caller probes again. */
|
|
35
38
|
release() {
|
|
36
|
-
if (this.
|
|
37
|
-
|
|
38
|
-
this.pending?.resolve(undefined);
|
|
39
|
-
this.pending = undefined;
|
|
39
|
+
if (this.state.kind === 'probing')
|
|
40
|
+
this.move(UNDECIDED);
|
|
40
41
|
}
|
|
42
|
+
/** Returns whether this call closed the decision. */
|
|
41
43
|
close() {
|
|
42
|
-
if (this.closed)
|
|
43
|
-
return;
|
|
44
|
-
this.
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
if (this.state.kind === 'closed')
|
|
45
|
+
return false;
|
|
46
|
+
this.move(CLOSED);
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
move(next) {
|
|
50
|
+
const previous = this.state;
|
|
51
|
+
this.state = next;
|
|
52
|
+
if (previous.kind === 'probing')
|
|
53
|
+
previous.settle(next);
|
|
47
54
|
}
|
|
48
55
|
}
|
|
@@ -10,7 +10,7 @@ export declare class InvocationBudget {
|
|
|
10
10
|
options(): RequestOptions;
|
|
11
11
|
get cancelled(): boolean;
|
|
12
12
|
get idempotency(): 'supplied' | 'absent';
|
|
13
|
-
wait(decision: Promise<
|
|
13
|
+
wait<T>(decision: Promise<T>): Promise<T>;
|
|
14
14
|
private remaining;
|
|
15
15
|
}
|
|
16
16
|
export declare function mayFallback(error: unknown): error is TransportError;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { targetPath } from '@astrale-os/kernel-core/callable';
|
|
2
2
|
import { TransportError } from '../../errors/index.js';
|
|
3
|
-
import {
|
|
3
|
+
import { abortError, timeoutFailure } from '../failure.js';
|
|
4
4
|
import { positiveInteger } from '../index.js';
|
|
5
5
|
const MAXIMUM_TIMEOUT_MS = 2_147_483_647;
|
|
6
6
|
/** One invocation-owned total timeout budget shared by selection and fallback. */
|
|
@@ -30,14 +30,14 @@ export class InvocationBudget {
|
|
|
30
30
|
}
|
|
31
31
|
async wait(decision) {
|
|
32
32
|
if (this.input?.signal?.aborted)
|
|
33
|
-
throw
|
|
33
|
+
throw abortError(this.input.signal.reason, new Error('request was cancelled'));
|
|
34
34
|
const remaining = this.remaining();
|
|
35
35
|
let timer;
|
|
36
36
|
let abort;
|
|
37
37
|
const interrupted = new Promise((_resolve, reject) => {
|
|
38
|
-
timer = setTimeout(() => reject(
|
|
38
|
+
timer = setTimeout(() => reject(timeoutFailure('Automatic transport decision exceeded its timeout.')), remaining);
|
|
39
39
|
if (this.input?.signal) {
|
|
40
|
-
abort = () => reject(
|
|
40
|
+
abort = () => reject(abortError(this.input.signal.reason, new Error('request was cancelled')));
|
|
41
41
|
this.input.signal.addEventListener('abort', abort, { once: true });
|
|
42
42
|
}
|
|
43
43
|
});
|
|
@@ -54,7 +54,7 @@ export class InvocationBudget {
|
|
|
54
54
|
remaining() {
|
|
55
55
|
const remaining = Math.min(MAXIMUM_TIMEOUT_MS, this.timeoutMs - (Date.now() - this.started));
|
|
56
56
|
if (remaining < 1) {
|
|
57
|
-
throw
|
|
57
|
+
throw timeoutFailure('Automatic transport invocation exceeded its timeout.');
|
|
58
58
|
}
|
|
59
59
|
return remaining;
|
|
60
60
|
}
|
|
@@ -69,8 +69,3 @@ export function mayFallback(error) {
|
|
|
69
69
|
export function warningTarget(input) {
|
|
70
70
|
return targetPath(input.call.target);
|
|
71
71
|
}
|
|
72
|
-
function abortReason(signal) {
|
|
73
|
-
return signal.reason instanceof Error
|
|
74
|
-
? signal.reason
|
|
75
|
-
: new Error(signal.reason === undefined ? 'request was cancelled' : String(signal.reason));
|
|
76
|
-
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Level } from '@astrale-os/kernel-core/wire';
|
|
2
|
+
import type * as protocol from '@astrale-os/kernel-protocol/invocation';
|
|
1
3
|
import type { Fetch } from '../http/index.js';
|
|
2
4
|
import type { RequestOptions, Transport, TransportRequest, TransportResult } from '../index.js';
|
|
3
5
|
import type { WebSocketConstructor } from '../websocket/index.js';
|
|
@@ -17,20 +19,25 @@ export interface AutoTransportOptions {
|
|
|
17
19
|
readonly maximumActiveInvocations?: number;
|
|
18
20
|
readonly maximumBufferedStreamItems?: number;
|
|
19
21
|
readonly onWarning?: (warning: ClientWarning) => void;
|
|
22
|
+
/** The wire History both bindings state; absent, the Invocation History of this build. */
|
|
23
|
+
readonly levels?: protocol.Levels;
|
|
20
24
|
}
|
|
21
25
|
/** Sticky WebSocket-first Transport with one delivery-aware HTTP fallback decision. */
|
|
22
26
|
export declare class AutoTransport implements Transport {
|
|
23
27
|
private readonly websocket;
|
|
24
28
|
private readonly http;
|
|
25
29
|
private readonly decision;
|
|
26
|
-
|
|
30
|
+
readonly timeoutMs: number;
|
|
27
31
|
private readonly onWarning;
|
|
28
|
-
private closed;
|
|
29
32
|
constructor(options: AutoTransportOptions);
|
|
30
33
|
dispatch(input: TransportRequest, options?: RequestOptions): Promise<TransportResult>;
|
|
34
|
+
/**
|
|
35
|
+
* The level of the WebSocket connection once WebSocket is the chosen route; none over HTTP, and
|
|
36
|
+
* none before the route is chosen: the first request probes it.
|
|
37
|
+
*/
|
|
38
|
+
fixed(options?: RequestOptions): Promise<Level | undefined>;
|
|
31
39
|
private dispatchWithBudget;
|
|
32
40
|
close(): void;
|
|
33
|
-
private determine;
|
|
34
41
|
private tryWebsocket;
|
|
35
42
|
private requireOpen;
|
|
36
43
|
}
|
|
@@ -14,7 +14,6 @@ export class AutoTransport {
|
|
|
14
14
|
decision = new AutoDecision();
|
|
15
15
|
timeoutMs;
|
|
16
16
|
onWarning;
|
|
17
|
-
closed = false;
|
|
18
17
|
constructor(options) {
|
|
19
18
|
if (options === null || typeof options !== 'object') {
|
|
20
19
|
throw new TypeError('AutoTransport options must be an object.');
|
|
@@ -35,6 +34,7 @@ export class AutoTransport {
|
|
|
35
34
|
...(options.maximumResponseBytes === undefined
|
|
36
35
|
? {}
|
|
37
36
|
: { maximumResponseBytes: options.maximumResponseBytes }),
|
|
37
|
+
...(options.levels === undefined ? {} : { levels: options.levels }),
|
|
38
38
|
});
|
|
39
39
|
this.websocket = new WebSocketTransport({
|
|
40
40
|
url: options.endpoints.websocket,
|
|
@@ -55,6 +55,7 @@ export class AutoTransport {
|
|
|
55
55
|
...(options.maximumBufferedStreamItems === undefined
|
|
56
56
|
? {}
|
|
57
57
|
: { maximumBufferedStreamItems: options.maximumBufferedStreamItems }),
|
|
58
|
+
...(options.levels === undefined ? {} : { levels: options.levels }),
|
|
58
59
|
});
|
|
59
60
|
}
|
|
60
61
|
async dispatch(input, options) {
|
|
@@ -62,45 +63,53 @@ export class AutoTransport {
|
|
|
62
63
|
const budget = new InvocationBudget(options, this.timeoutMs);
|
|
63
64
|
return this.dispatchWithBudget(input, budget);
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
/**
|
|
67
|
+
* The level of the WebSocket connection once WebSocket is the chosen route; none over HTTP, and
|
|
68
|
+
* none before the route is chosen: the first request probes it.
|
|
69
|
+
*/
|
|
70
|
+
async fixed(options) {
|
|
71
|
+
if (this.decision.route !== 'websocket')
|
|
72
|
+
return undefined;
|
|
73
|
+
try {
|
|
74
|
+
return await this.websocket.fixed(options);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// The dispatch that follows meets the same failure and reports it.
|
|
78
|
+
return undefined;
|
|
71
79
|
}
|
|
72
|
-
|
|
73
|
-
|
|
80
|
+
}
|
|
81
|
+
async dispatchWithBudget(input, budget) {
|
|
82
|
+
let ticket = this.decision.begin();
|
|
83
|
+
while (ticket.kind === 'probing') {
|
|
84
|
+
const settled = await budget.wait(ticket.settled);
|
|
74
85
|
this.requireOpen();
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
86
|
+
ticket = settled.kind === 'undecided' ? this.decision.begin() : settled;
|
|
87
|
+
}
|
|
88
|
+
switch (ticket.kind) {
|
|
89
|
+
case 'closed':
|
|
90
|
+
throw closedFailure();
|
|
91
|
+
case 'probe':
|
|
92
|
+
return this.tryWebsocket(input, budget);
|
|
93
|
+
case 'chosen':
|
|
94
|
+
return ticket.via === 'websocket'
|
|
95
|
+
? this.tryWebsocket(input, budget)
|
|
96
|
+
: this.http.dispatch(input, budget.options());
|
|
80
97
|
}
|
|
81
|
-
return this.determine(input, budget);
|
|
82
98
|
}
|
|
83
99
|
close() {
|
|
84
|
-
if (this.
|
|
100
|
+
if (!this.decision.close())
|
|
85
101
|
return;
|
|
86
|
-
this.closed = true;
|
|
87
|
-
this.decision.close();
|
|
88
102
|
this.websocket.close();
|
|
89
103
|
}
|
|
90
|
-
async
|
|
91
|
-
return this.tryWebsocket(input, budget, true);
|
|
92
|
-
}
|
|
93
|
-
async tryWebsocket(input, budget, probing) {
|
|
104
|
+
async tryWebsocket(input, budget) {
|
|
94
105
|
try {
|
|
95
106
|
const result = await this.websocket.dispatch(input, budget.options());
|
|
96
|
-
|
|
97
|
-
this.decision.select('websocket');
|
|
107
|
+
this.decision.selectWebSocket();
|
|
98
108
|
return result;
|
|
99
109
|
}
|
|
100
110
|
catch (error) {
|
|
101
111
|
if (budget.cancelled) {
|
|
102
|
-
|
|
103
|
-
this.decision.release();
|
|
112
|
+
this.decision.release();
|
|
104
113
|
throw error;
|
|
105
114
|
}
|
|
106
115
|
if (error instanceof TransportError &&
|
|
@@ -110,9 +119,7 @@ export class AutoTransport {
|
|
|
110
119
|
throw error;
|
|
111
120
|
}
|
|
112
121
|
if (!mayFallback(error)) {
|
|
113
|
-
|
|
114
|
-
this.decision.select('websocket');
|
|
115
|
-
}
|
|
122
|
+
this.decision.selectWebSocket();
|
|
116
123
|
throw error;
|
|
117
124
|
}
|
|
118
125
|
const idempotency = budget.idempotency;
|
|
@@ -131,8 +138,10 @@ export class AutoTransport {
|
|
|
131
138
|
}
|
|
132
139
|
}
|
|
133
140
|
requireOpen() {
|
|
134
|
-
if (
|
|
135
|
-
|
|
136
|
-
throw invocationFailure('AutoTransport is closed.', 'closed');
|
|
141
|
+
if (this.decision.closed)
|
|
142
|
+
throw closedFailure();
|
|
137
143
|
}
|
|
138
144
|
}
|
|
145
|
+
function closedFailure() {
|
|
146
|
+
return invocationFailure('AutoTransport is closed.', 'closed');
|
|
147
|
+
}
|
|
@@ -4,6 +4,8 @@ export interface ControlledSignal {
|
|
|
4
4
|
cancel(reason?: unknown): void;
|
|
5
5
|
close(): void;
|
|
6
6
|
}
|
|
7
|
+
/** Wait `ms`, or until `signal` aborts, which rejects with its reason. */
|
|
8
|
+
export declare function pause(ms: number, signal?: AbortSignal): Promise<void>;
|
|
7
9
|
/** One caller signal plus one transport-owned lifetime deadline. */
|
|
8
10
|
export declare function controlledSignal(parent: AbortSignal | undefined, timeoutMs: number): ControlledSignal;
|
|
9
11
|
export declare function positiveInteger(input: number, label: string): number;
|
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
/** Wait `ms`, or until `signal` aborts, which rejects with its reason. */
|
|
2
|
+
export function pause(ms, signal) {
|
|
3
|
+
return new Promise((resolve, reject) => {
|
|
4
|
+
if (signal?.aborted) {
|
|
5
|
+
reject(signal.reason);
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const abort = () => {
|
|
9
|
+
clearTimeout(timer);
|
|
10
|
+
reject(signal.reason);
|
|
11
|
+
};
|
|
12
|
+
const timer = setTimeout(() => {
|
|
13
|
+
signal?.removeEventListener('abort', abort);
|
|
14
|
+
resolve();
|
|
15
|
+
}, ms);
|
|
16
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
17
|
+
});
|
|
18
|
+
}
|
|
1
19
|
/** One caller signal plus one transport-owned lifetime deadline. */
|
|
2
20
|
export function controlledSignal(parent, timeoutMs) {
|
|
3
21
|
const controller = new AbortController();
|