@astrale-os/kernel-client 1.0.0-beta.3 → 1.0.0-beta.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/index.d.ts +1 -0
- package/dist/client/admission.js +3 -1
- package/dist/client/client.d.ts +19 -2
- package/dist/client/client.js +62 -30
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.js +2 -2
- package/dist/client/request.d.ts +8 -2
- package/dist/client/request.js +28 -7
- package/dist/client/result.d.ts +10 -1
- package/dist/client/result.js +10 -4
- package/dist/client/routing-control.d.ts +11 -15
- package/dist/client/routing-control.js +21 -29
- package/dist/errors/index.d.ts +3 -0
- package/dist/errors/index.js +3 -0
- package/dist/errors/query-input.d.ts +47 -0
- package/dist/errors/query-input.js +85 -0
- package/dist/errors/refusal.d.ts +19 -0
- package/dist/errors/refusal.js +63 -0
- package/dist/errors/response-too-large-error.d.ts +11 -0
- package/dist/errors/response-too-large-error.js +15 -0
- package/dist/errors/stale-route-error.d.ts +1 -1
- package/dist/errors/stale-route-error.js +1 -1
- package/dist/{schema → execution}/admission.d.ts +2 -2
- package/dist/{schema → execution}/admission.js +3 -3
- package/dist/execution/contracts.d.ts +76 -0
- package/dist/execution/contracts.js +1 -0
- package/dist/execution/deadline.d.ts +18 -0
- package/dist/execution/deadline.js +25 -0
- package/dist/execution/execution.d.ts +61 -0
- package/dist/execution/execution.js +132 -0
- package/dist/execution/index.d.ts +4 -0
- package/dist/execution/index.js +3 -0
- package/dist/graph/domain/binding.d.ts +2 -2
- package/dist/graph/domain/binding.js +24 -17
- package/dist/graph/domain/conformance.d.ts +12 -0
- package/dist/graph/domain/conformance.js +18 -0
- package/dist/graph/domain/index.d.ts +1 -0
- package/dist/graph/domain/index.js +1 -1
- package/dist/graph/domain/provenance.d.ts +0 -2
- package/dist/graph/domain/provenance.js +0 -4
- package/dist/graph/graph.d.ts +17 -3
- package/dist/graph/graph.js +4 -1
- package/dist/graph/index.d.ts +3 -3
- package/dist/graph/index.js +1 -1
- package/dist/graph/page-contract.d.ts +64 -1
- package/dist/graph/provenance.d.ts +4 -5
- package/dist/graph/provenance.js +5 -6
- package/dist/graph/query.d.ts +10 -4
- package/dist/graph/query.js +145 -7
- package/dist/graph/query.typecheck.d.ts +77 -0
- package/dist/graph/query.typecheck.js +34 -0
- package/dist/pacer/index.d.ts +1 -1
- package/dist/pacer/index.js +1 -1
- package/dist/pacer/retry/index.d.ts +1 -0
- package/dist/pacer/retry/index.js +1 -0
- package/dist/pacer/retry/refusals.d.ts +7 -0
- package/dist/pacer/retry/refusals.js +10 -0
- package/dist/pacer/retry/retry.d.ts +2 -0
- package/dist/pacer/retry/retry.js +33 -1
- package/dist/schema/contracts.d.ts +77 -9
- package/dist/schema/index.d.ts +3 -2
- package/dist/schema/index.js +1 -1
- package/dist/schema/installation.d.ts +76 -0
- package/dist/schema/installation.js +82 -0
- package/dist/schema/schema.d.ts +22 -13
- package/dist/schema/schema.js +67 -48
- package/dist/session/admission.js +10 -3
- package/dist/session/bound.d.ts +12 -3
- package/dist/session/bound.js +66 -20
- package/dist/session/content/api.d.ts +10 -2
- package/dist/session/content/api.js +13 -4
- package/dist/session/content/index.d.ts +1 -1
- package/dist/session/content/input.d.ts +6 -1
- package/dist/session/content/input.js +12 -4
- package/dist/session/content/retry.d.ts +5 -1
- package/dist/session/content/retry.js +21 -31
- package/dist/session/context/index.d.ts +1 -1
- package/dist/session/context/index.js +1 -1
- package/dist/session/context/operation.d.ts +2 -0
- package/dist/session/context/operation.js +5 -0
- package/dist/session/credential/credentials.js +43 -28
- package/dist/session/discovery/bundle.d.ts +9 -4
- package/dist/session/discovery/bundle.js +28 -35
- package/dist/session/discovery/discovery.d.ts +1 -1
- package/dist/session/discovery/discovery.js +8 -11
- package/dist/session/discovery/release.js +18 -28
- package/dist/session/discovery/snapshot.d.ts +5 -1
- package/dist/session/discovery/transport.d.ts +35 -3
- package/dist/session/discovery/transport.js +40 -1
- package/dist/session/durable.d.ts +13 -0
- package/dist/session/durable.js +39 -0
- package/dist/session/exchange/exchange.d.ts +3 -2
- package/dist/session/exchange/exchange.js +10 -7
- package/dist/session/exchange/index.d.ts +1 -1
- package/dist/session/exchange/index.js +1 -1
- package/dist/session/exchange/presentation.js +28 -10
- package/dist/session/exchange/source.d.ts +7 -7
- package/dist/session/exchange/source.js +26 -27
- package/dist/session/index.d.ts +4 -3
- package/dist/session/index.js +0 -1
- package/dist/session/options.d.ts +0 -2
- package/dist/session/options.js +0 -3
- package/dist/session/reference.d.ts +9 -5
- package/dist/session/reference.js +7 -2
- package/dist/session/retry.d.ts +12 -0
- package/dist/session/retry.js +23 -0
- package/dist/session/routing/auth.d.ts +9 -3
- package/dist/session/routing/auth.js +4 -3
- package/dist/session/routing/cache.d.ts +12 -5
- package/dist/session/routing/cache.js +56 -48
- package/dist/session/routing/dispatch.d.ts +26 -3
- package/dist/session/routing/dispatch.js +112 -67
- package/dist/session/routing/envelope.d.ts +3 -3
- package/dist/session/routing/index.d.ts +1 -1
- package/dist/session/routing/legacy/release-route.d.ts +12 -0
- package/dist/session/routing/legacy/release-route.js +6 -0
- package/dist/session/routing/recovery.d.ts +3 -6
- package/dist/session/routing/recovery.js +3 -14
- package/dist/session/routing/request.d.ts +6 -1
- package/dist/session/routing/request.js +13 -2
- package/dist/session/routing/result.d.ts +1 -1
- package/dist/session/routing/result.js +5 -1
- package/dist/session/routing/store.js +4 -5
- package/dist/session/session.d.ts +31 -5
- package/dist/session/session.js +60 -19
- package/dist/session/session.typecheck.js +20 -6
- package/dist/session/views/index.d.ts +2 -2
- package/dist/session/views/index.js +2 -2
- package/dist/session/views/kernel.d.ts +31 -0
- package/dist/session/views/kernel.js +30 -0
- package/dist/session/views/legacy/catalog.d.ts +21 -0
- package/dist/session/views/{catalog.js → legacy/catalog.js} +7 -31
- package/dist/session/views/legacy/index.d.ts +14 -0
- package/dist/session/views/legacy/index.js +14 -0
- package/dist/session/views/legacy/resolve.d.ts +46 -0
- package/dist/session/views/legacy/resolve.js +83 -0
- package/dist/session/views/legacy/unplaced.d.ts +22 -0
- package/dist/session/views/legacy/unplaced.js +26 -0
- package/dist/session/views/read.d.ts +49 -0
- package/dist/session/views/read.js +148 -0
- package/dist/session/views/view.d.ts +48 -0
- package/dist/session/views/view.js +74 -0
- package/dist/store/memory.d.ts +1 -3
- package/dist/store/memory.js +73 -105
- package/dist/store/shape.d.ts +33 -12
- package/dist/store/shape.js +125 -16
- package/dist/store/store.d.ts +6 -6
- package/dist/store/store.js +1 -1
- package/dist/transport/auto/decision.d.ts +26 -14
- package/dist/transport/auto/decision.js +35 -32
- package/dist/transport/auto/fallback.d.ts +1 -1
- package/dist/transport/auto/fallback.js +5 -10
- package/dist/transport/auto/transport.d.ts +0 -2
- package/dist/transport/auto/transport.js +24 -32
- package/dist/transport/deadline.d.ts +2 -0
- package/dist/transport/deadline.js +18 -0
- package/dist/transport/failure.d.ts +28 -1
- package/dist/transport/failure.js +63 -1
- package/dist/transport/http/admission.js +7 -34
- package/dist/transport/http/binary-request.d.ts +44 -0
- package/dist/transport/http/binary-request.js +110 -0
- package/dist/transport/http/binary.js +3 -3
- package/dist/transport/http/byte-stream.d.ts +2 -1
- package/dist/transport/http/byte-stream.js +12 -8
- package/dist/transport/http/index.d.ts +1 -1
- package/dist/transport/http/index.js +1 -1
- package/dist/transport/http/response.d.ts +3 -1
- package/dist/transport/http/response.js +7 -9
- package/dist/transport/http/stream.d.ts +8 -13
- package/dist/transport/http/stream.js +34 -81
- package/dist/transport/http/transport.d.ts +10 -0
- package/dist/transport/http/transport.js +87 -32
- package/dist/transport/http/unprocessed.d.ts +5 -0
- package/dist/transport/http/unprocessed.js +28 -0
- package/dist/transport/index.d.ts +1 -1
- package/dist/transport/index.js +1 -1
- package/dist/transport/stream.d.ts +52 -0
- package/dist/transport/stream.js +101 -0
- package/dist/transport/transport.d.ts +10 -0
- package/dist/transport/unary.d.ts +8 -0
- package/dist/transport/unary.js +34 -0
- package/dist/transport/websocket/connection.d.ts +7 -3
- package/dist/transport/websocket/connection.js +103 -92
- package/dist/transport/websocket/exchange.d.ts +12 -19
- package/dist/transport/websocket/exchange.js +86 -184
- package/dist/transport/websocket/transport.js +11 -19
- package/package.json +7 -5
- package/dist/session/execution.d.ts +0 -65
- package/dist/session/execution.js +0 -34
- package/dist/session/views/catalog.d.ts +0 -19
- package/dist/session/views/resolve.d.ts +0 -13
- package/dist/session/views/resolve.js +0 -21
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type { Domain } from '@astrale-os/kernel-dsl/v1/domain';
|
|
2
1
|
import type { QueryProvenance } from '../provenance.js';
|
|
3
2
|
export declare function retainProjectedProvenance(value: object, provenance: QueryProvenance): void;
|
|
4
3
|
export declare function provenanceOfProjectedValue(value: object): QueryProvenance | undefined;
|
|
5
|
-
export declare function sameClosure(left: Domain['closure'], right: Domain['closure']): boolean;
|
|
6
4
|
export type { QueryProvenance };
|
|
@@ -5,7 +5,3 @@ export function retainProjectedProvenance(value, provenance) {
|
|
|
5
5
|
export function provenanceOfProjectedValue(value) {
|
|
6
6
|
return projectedValues.get(value);
|
|
7
7
|
}
|
|
8
|
-
export function sameClosure(left, right) {
|
|
9
|
-
return (left.length === right.length &&
|
|
10
|
-
left.every((identity, index) => identity.origin === right[index]?.origin && identity.revision === right[index]?.revision));
|
|
11
|
-
}
|
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,6 +1,6 @@
|
|
|
1
|
-
export { createGraph, type GraphApi, type GraphCall, type GraphMutationOptions, type
|
|
2
|
-
export type { QueryPageRequest, QueryResponse } from './page-contract.js';
|
|
3
|
-
export { type BoundEdge, type BoundEdgePage, type BoundGraphValue, type BoundNode, type BoundNodeFor, type BoundNodePage, type BoundQueryPage, type DomainBinding, type DomainQueryOptions, } from './domain/index.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
|
+
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';
|
|
6
6
|
export { LocalAlias, type GraphSpec } from '@astrale-os/kernel-core/graph/graph';
|
package/dist/graph/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { createGraph, } from './graph.js';
|
|
2
|
-
export {} from './domain/index.js';
|
|
2
|
+
export { definedClass, validateDefinedProperties, } from './domain/index.js';
|
|
3
3
|
export { NodeUnavailableError } from './errors.js';
|
|
4
4
|
export { LocalAlias } from '@astrale-os/kernel-core/graph/graph';
|
|
5
5
|
export { MutationAST, MutationResult, } from '@astrale-os/kernel-core/graph/mutate';
|
|
@@ -1,4 +1,7 @@
|
|
|
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';
|
|
4
|
+
import type { ClassKey } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
2
5
|
/** Caller-selected bounds and continuation for one graph query page. */
|
|
3
6
|
export interface QueryPageRequest {
|
|
4
7
|
readonly size: number;
|
|
@@ -10,4 +13,64 @@ export interface QueryResponse<Result extends QueryResult = QueryResult> {
|
|
|
10
13
|
readonly page: {
|
|
11
14
|
readonly next?: string;
|
|
12
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Present only for a repair-session read made without conformance admission: its facts may
|
|
18
|
+
* violate the active schema, so it is raw Core data only. The Store keeps it out of its shared
|
|
19
|
+
* cache and a Domain binding refuses to type it.
|
|
20
|
+
*/
|
|
21
|
+
readonly certification?: 'uncertified';
|
|
13
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* One Page of a Query's answer (page "Fondations Query v7", § Résultats): the exact prefix of its
|
|
25
|
+
* list, and the opaque cursor that continues it when an item follows (W2, W3).
|
|
26
|
+
*/
|
|
27
|
+
export type QueryPage = {
|
|
28
|
+
readonly items: readonly QueryItem[];
|
|
29
|
+
readonly undecided?: Undecided;
|
|
30
|
+
} & ({
|
|
31
|
+
readonly complete: true;
|
|
32
|
+
} | {
|
|
33
|
+
readonly complete: false;
|
|
34
|
+
readonly cursor: string;
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* One delivered item: its fact, its Class when the fact is a Node, the Edge its Branch followed,
|
|
38
|
+
* the ends it renders, its Branches.
|
|
39
|
+
*/
|
|
40
|
+
export interface QueryItem {
|
|
41
|
+
readonly fact: FactId;
|
|
42
|
+
readonly class?: ClassKey;
|
|
43
|
+
readonly edge?: EdgeKey;
|
|
44
|
+
readonly source?: QueryItem;
|
|
45
|
+
readonly target?: QueryItem;
|
|
46
|
+
readonly branches: Readonly<Record<string, QueryPage | Exclude<Answer, {
|
|
47
|
+
readonly list: unknown;
|
|
48
|
+
}>>>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* What a Query answers, by its family: a list's Page, the table of the facts it
|
|
52
|
+
* renders as values, the revision it was read at and whether its cursor came from another (W6);
|
|
53
|
+
* an `exists`; or a `count`.
|
|
54
|
+
*/
|
|
55
|
+
export type QueryAnswer = {
|
|
56
|
+
readonly list: QueryPage;
|
|
57
|
+
readonly facts: Extract<Answer, {
|
|
58
|
+
readonly list: unknown;
|
|
59
|
+
}>['facts'];
|
|
60
|
+
readonly revision: string;
|
|
61
|
+
readonly revised?: true;
|
|
62
|
+
} | Exclude<Answer, {
|
|
63
|
+
readonly list: unknown;
|
|
64
|
+
}>;
|
|
65
|
+
/** The answer of the family a Query names: `list`, `exists` or `count`. */
|
|
66
|
+
export type QueryAnswerFor<Query extends wire.Document> = Query extends {
|
|
67
|
+
readonly list: unknown;
|
|
68
|
+
} ? Extract<QueryAnswer, {
|
|
69
|
+
readonly list: unknown;
|
|
70
|
+
}> : Query extends {
|
|
71
|
+
readonly exists: unknown;
|
|
72
|
+
} ? Extract<QueryAnswer, {
|
|
73
|
+
readonly exists: unknown;
|
|
74
|
+
}> : Extract<QueryAnswer, {
|
|
75
|
+
readonly count: unknown;
|
|
76
|
+
}>;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import type { Edge } from '@astrale-os/kernel-core/graph/edge';
|
|
2
2
|
import type { Node } from '@astrale-os/kernel-core/graph/node';
|
|
3
|
-
import type { DomainDependency } from '@astrale-os/kernel-dsl/v1/schema';
|
|
4
3
|
import type { QueryResponse } from './page-contract.js';
|
|
4
|
+
/** A certified Query response this client received from the Kernel; `page` identifies it. */
|
|
5
5
|
export interface QueryProvenance {
|
|
6
|
-
readonly closure: readonly DomainDependency[];
|
|
7
6
|
readonly page: object;
|
|
8
7
|
}
|
|
9
|
-
/** Retain
|
|
10
|
-
export declare function retainQueryProvenance(response: QueryResponse
|
|
11
|
-
/** Reattach
|
|
8
|
+
/** Retain the provenance of a certified Query response without adding serialized metadata. */
|
|
9
|
+
export declare function retainQueryProvenance(response: QueryResponse): QueryResponse;
|
|
10
|
+
/** Reattach provenance when Store materialization replaces response objects. */
|
|
12
11
|
export declare function retainDerivedQueryProvenance(source: QueryResponse, derived: QueryResponse): QueryResponse;
|
|
13
12
|
export declare function provenanceOfGraphValue(value: Node | Edge): QueryProvenance | undefined;
|
|
14
13
|
export declare function provenanceOfResponse(value: QueryResponse): QueryProvenance | undefined;
|
package/dist/graph/provenance.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const graphValues = new WeakMap();
|
|
2
2
|
const responses = new WeakMap();
|
|
3
|
-
/** Retain
|
|
4
|
-
export function retainQueryProvenance(response
|
|
5
|
-
const provenance = Object.freeze({
|
|
3
|
+
/** Retain the provenance of a certified Query response without adding serialized metadata. */
|
|
4
|
+
export function retainQueryProvenance(response) {
|
|
5
|
+
const provenance = Object.freeze({ page: Object.freeze({}) });
|
|
6
6
|
responses.set(response, provenance);
|
|
7
7
|
const { result } = response;
|
|
8
8
|
if (result.kind === 'graph') {
|
|
@@ -29,10 +29,9 @@ export function retainQueryProvenance(response, closure) {
|
|
|
29
29
|
}
|
|
30
30
|
return response;
|
|
31
31
|
}
|
|
32
|
-
/** Reattach
|
|
32
|
+
/** Reattach provenance when Store materialization replaces response objects. */
|
|
33
33
|
export function retainDerivedQueryProvenance(source, derived) {
|
|
34
|
-
|
|
35
|
-
return provenance === undefined ? derived : retainQueryProvenance(derived, provenance.closure);
|
|
34
|
+
return responses.has(source) ? retainQueryProvenance(derived) : derived;
|
|
36
35
|
}
|
|
37
36
|
export function provenanceOfGraphValue(value) {
|
|
38
37
|
return graphValues.get(value);
|
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>>>;
|
package/dist/graph/query.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { QueryAST, QueryASTDecodeError, QueryResult } from '@astrale-os/kernel-core/graph/query';
|
|
1
|
+
import { QUERY, QueryAST, QueryASTDecodeError, QueryResult, } from '@astrale-os/kernel-core/graph/query';
|
|
2
2
|
import { Path, PathError } from '@astrale-os/kernel-core/path';
|
|
3
|
+
import { queryOutput } from '@astrale-os/kernel-core/schema/kernel/syscalls/contracts';
|
|
3
4
|
import { query } from '@astrale-os/kernel-core/schema/kernel/syscalls/references';
|
|
5
|
+
import * as portable from '@astrale-os/kernel-dsl/value';
|
|
6
|
+
import { ENVELOPE_LIMITS } from '@astrale-os/kernel-protocol/codecs';
|
|
4
7
|
import { call as invocation } from '../client/index.js';
|
|
5
8
|
import { captureExpected } from './expectation.js';
|
|
6
9
|
import { retainQueryProvenance } from './provenance.js';
|
|
@@ -17,7 +20,133 @@ export function queryNodePath(target) {
|
|
|
17
20
|
throw new QueryASTDecodeError('/source/nodes/0', 'Invalid Node target', { cause });
|
|
18
21
|
}
|
|
19
22
|
}
|
|
20
|
-
export
|
|
23
|
+
export function queryGraph(call, input, options) {
|
|
24
|
+
return isQuery(input)
|
|
25
|
+
? queryV7(call, input, options)
|
|
26
|
+
: queryLegacyAST(call, input, options);
|
|
27
|
+
}
|
|
28
|
+
/** A Query: an object naming `"query": "astrale.query/7"`. */
|
|
29
|
+
function isQuery(input) {
|
|
30
|
+
return isRecord(input) && input.query === QUERY;
|
|
31
|
+
}
|
|
32
|
+
// ─── Query v7 ───────────────────────────────────────────────────────────────────────────────
|
|
33
|
+
/**
|
|
34
|
+
* Send one Query (page "Fondations Query v7", § Wire v7) as the operation's request `{document,
|
|
35
|
+
* paging?, expected?}`, and admit the answer of its family. The Kernel decodes the Query against
|
|
36
|
+
* its Registry; the Client admits its structure only, before any I/O. A continuation is the same
|
|
37
|
+
* Query with `paging.after` set to a Page's cursor.
|
|
38
|
+
*/
|
|
39
|
+
async function queryV7(call, input, options) {
|
|
40
|
+
const admitted = admitQuery(input);
|
|
41
|
+
const { expected, paging, ...request } = options ?? {};
|
|
42
|
+
const admittedPaging = admitPaging(paging);
|
|
43
|
+
const capturedExpected = captureExpected(expected);
|
|
44
|
+
const output = await call(invocation(KERNEL_QUERY_PATH, Object.freeze({
|
|
45
|
+
document: admitted,
|
|
46
|
+
...(admittedPaging === undefined ? {} : { paging: admittedPaging }),
|
|
47
|
+
...(capturedExpected === undefined ? {} : { expected: capturedExpected }),
|
|
48
|
+
})), options === undefined ? undefined : request);
|
|
49
|
+
return decodeAnswer(output, familyOf(admitted));
|
|
50
|
+
}
|
|
51
|
+
/** A detached, frozen Query of exactly one family; its names are the Kernel's to decode. */
|
|
52
|
+
function admitQuery(input) {
|
|
53
|
+
const query = snapshot(input, 'query');
|
|
54
|
+
if (!isRecord(query) || familyOf(query) === undefined) {
|
|
55
|
+
return invalid('query', 'it holds exactly one of list, exists, count');
|
|
56
|
+
}
|
|
57
|
+
return query;
|
|
58
|
+
}
|
|
59
|
+
/** A detached, frozen paging: sizes per list path, each at least 1, and a Page's cursor. */
|
|
60
|
+
function admitPaging(input) {
|
|
61
|
+
if (input === undefined)
|
|
62
|
+
return undefined;
|
|
63
|
+
const paging = snapshot(input, 'paging');
|
|
64
|
+
if (!isRecord(paging) || !hasOnlyKeys(paging, ['sizes', 'after'])) {
|
|
65
|
+
return invalid('paging', 'it is {sizes?, after?}');
|
|
66
|
+
}
|
|
67
|
+
const { sizes, after } = paging;
|
|
68
|
+
if (sizes !== undefined &&
|
|
69
|
+
(!Array.isArray(sizes) ||
|
|
70
|
+
!sizes.every((entry) => isRecord(entry) &&
|
|
71
|
+
hasExactKeys(entry, ['at', 'size']) &&
|
|
72
|
+
Array.isArray(entry.at) &&
|
|
73
|
+
entry.at.every((name) => typeof name === 'string') &&
|
|
74
|
+
Number.isSafeInteger(entry.size) &&
|
|
75
|
+
entry.size >= 1))) {
|
|
76
|
+
return invalid('paging', 'each size is {at: [Branch names], size: an integer of at least 1}');
|
|
77
|
+
}
|
|
78
|
+
if (after !== undefined && (typeof after !== 'string' || after.length === 0)) {
|
|
79
|
+
return invalid('paging', 'after is the cursor of a Page');
|
|
80
|
+
}
|
|
81
|
+
return paging;
|
|
82
|
+
}
|
|
83
|
+
/** A detached, frozen portable snapshot of one caller value. */
|
|
84
|
+
function snapshot(input, what) {
|
|
85
|
+
try {
|
|
86
|
+
// As deep as an envelope carries it: the Kernel refuses a document past its nesting bound.
|
|
87
|
+
return portable.acceptImmutable(input, { limits: ENVELOPE_LIMITS });
|
|
88
|
+
}
|
|
89
|
+
catch (cause) {
|
|
90
|
+
if (!(cause instanceof portable.BoundaryError))
|
|
91
|
+
throw cause;
|
|
92
|
+
return invalid(what, 'it is not a portable JSON value', cause);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function invalid(what, detail, cause) {
|
|
96
|
+
const subject = what === 'query' ? 'Graph query' : 'Graph query paging';
|
|
97
|
+
throw new TypeError(`${subject} is invalid: ${detail}.`, { cause });
|
|
98
|
+
}
|
|
99
|
+
/** The family a Query names (`list`, `exists` or `count`); undefined unless it names one. */
|
|
100
|
+
function familyOf(query) {
|
|
101
|
+
const families = ['list', 'exists', 'count'].filter((family) => family in query);
|
|
102
|
+
return families.length === 1 ? families[0] : undefined;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The Kernel's answer, admitted by the query operation's contract as a detached frozen value, of
|
|
106
|
+
* the family the Query asked for.
|
|
107
|
+
*/
|
|
108
|
+
function decodeAnswer(input, family) {
|
|
109
|
+
const refuse = (cause) => {
|
|
110
|
+
throw new TypeError('Graph query answer is invalid.', { cause });
|
|
111
|
+
};
|
|
112
|
+
let value;
|
|
113
|
+
try {
|
|
114
|
+
value = portable.acceptImmutable(input);
|
|
115
|
+
}
|
|
116
|
+
catch (cause) {
|
|
117
|
+
if (!(cause instanceof portable.BoundaryError))
|
|
118
|
+
throw cause;
|
|
119
|
+
return refuse(cause);
|
|
120
|
+
}
|
|
121
|
+
if (!isRecord(value) || !(family in value) || !queryOutput.safeParse(value).success) {
|
|
122
|
+
return refuse();
|
|
123
|
+
}
|
|
124
|
+
const answer = value;
|
|
125
|
+
return 'list' in answer && !pagesClosed(answer.list) ? refuse() : answer;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Every Page, its Branches' included, carries a cursor exactly when an item follows it (W3), and
|
|
129
|
+
* only a Node item carries a Class.
|
|
130
|
+
*/
|
|
131
|
+
function pagesClosed(page) {
|
|
132
|
+
const continued = 'cursor' in page;
|
|
133
|
+
return page.complete !== continued && page.items.every(itemClosed);
|
|
134
|
+
}
|
|
135
|
+
function itemClosed(item) {
|
|
136
|
+
return ((!('class' in item) || typeof item.fact === 'string') &&
|
|
137
|
+
(item.source === undefined || itemClosed(item.source)) &&
|
|
138
|
+
(item.target === undefined || itemClosed(item.target)) &&
|
|
139
|
+
Object.values(item.branches).every((branch) => !('items' in branch) || pagesClosed(branch)));
|
|
140
|
+
}
|
|
141
|
+
function isRecord(input) {
|
|
142
|
+
return input !== null && typeof input === 'object' && !Array.isArray(input);
|
|
143
|
+
}
|
|
144
|
+
function hasOnlyKeys(input, allowed) {
|
|
145
|
+
return Object.keys(input).every((key) => allowed.includes(key));
|
|
146
|
+
}
|
|
147
|
+
// ─── Legacy: V6 QueryAST ────────────────────────────────────────────────────────────────────
|
|
148
|
+
/** The legacy path: one V6 QueryAST and its page, answered `{result, page}`. */
|
|
149
|
+
async function queryLegacyAST(call, input, options) {
|
|
21
150
|
const ast = QueryAST.decode(input);
|
|
22
151
|
const { expected, page, ...request } = options;
|
|
23
152
|
const admittedPage = admitPage(page);
|
|
@@ -28,9 +157,10 @@ export async function queryGraph(call, input, options) {
|
|
|
28
157
|
page: admittedPage,
|
|
29
158
|
})), request);
|
|
30
159
|
const response = decodeResponse(output);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
160
|
+
// A repair-session read may hold facts the Domain refutes: it carries no provenance.
|
|
161
|
+
return response.certification === undefined
|
|
162
|
+
? retainQueryProvenance(response)
|
|
163
|
+
: response;
|
|
34
164
|
}
|
|
35
165
|
function admitPage(input) {
|
|
36
166
|
if (input === null || typeof input !== 'object' || Array.isArray(input)) {
|
|
@@ -52,9 +182,13 @@ function decodeResponse(input) {
|
|
|
52
182
|
throw new TypeError('Graph query response is invalid.');
|
|
53
183
|
}
|
|
54
184
|
const value = input;
|
|
55
|
-
|
|
185
|
+
const uncertified = value.certification !== undefined;
|
|
186
|
+
if (!hasExactKeys(value, uncertified ? ['result', 'page', 'certification'] : ['result', 'page'])) {
|
|
56
187
|
throw new TypeError('Graph query response is invalid.');
|
|
57
188
|
}
|
|
189
|
+
if (uncertified && value.certification !== 'uncertified') {
|
|
190
|
+
throw new TypeError('Graph query response certification is invalid.');
|
|
191
|
+
}
|
|
58
192
|
const pageInput = value.page;
|
|
59
193
|
if (pageInput === null || typeof pageInput !== 'object' || Array.isArray(pageInput)) {
|
|
60
194
|
throw new TypeError('Graph query response page is invalid.');
|
|
@@ -69,7 +203,11 @@ function decodeResponse(input) {
|
|
|
69
203
|
}
|
|
70
204
|
const result = QueryResult.decode(value.result);
|
|
71
205
|
const page = Object.freeze(pageValue.next === undefined ? {} : { next: pageValue.next });
|
|
72
|
-
return Object.freeze({
|
|
206
|
+
return Object.freeze({
|
|
207
|
+
result,
|
|
208
|
+
page,
|
|
209
|
+
...(uncertified ? { certification: 'uncertified' } : {}),
|
|
210
|
+
});
|
|
73
211
|
}
|
|
74
212
|
function hasExactKeys(input, expected) {
|
|
75
213
|
const keys = Object.keys(input);
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { QueryAST, QueryResultFor } from '@astrale-os/kernel-core/graph/query';
|
|
2
|
+
import type { GraphApi, GraphQueryV6Options } from './graph.js';
|
|
3
|
+
import type { QueryAnswer, QueryAnswerFor, QueryResponse } from './index.js';
|
|
4
|
+
type Equal<Left, Right> = (<Value>() => Value extends Left ? 1 : 2) extends <Value>() => (Value extends Right ? 1 : 2) ? true : false;
|
|
5
|
+
type Assert<Condition extends true> = Condition;
|
|
6
|
+
type ListAnswer = Extract<QueryAnswer, {
|
|
7
|
+
readonly list: unknown;
|
|
8
|
+
}>;
|
|
9
|
+
type ExistsAnswer = Extract<QueryAnswer, {
|
|
10
|
+
readonly exists: unknown;
|
|
11
|
+
}>;
|
|
12
|
+
type CountAnswer = Extract<QueryAnswer, {
|
|
13
|
+
readonly count: unknown;
|
|
14
|
+
}>;
|
|
15
|
+
declare const ast: QueryAST<import("@astrale-os/kernel-core/graph/query").QueryNodeSelect<{
|
|
16
|
+
kind: "value";
|
|
17
|
+
}>, never>;
|
|
18
|
+
declare const list: {
|
|
19
|
+
readonly query: "astrale.query/7";
|
|
20
|
+
readonly list: {
|
|
21
|
+
readonly nodes: readonly [`${string}:class.${string}`];
|
|
22
|
+
readonly orderBy: readonly [{
|
|
23
|
+
readonly property: `${string}:class.${string}.property.${string}`;
|
|
24
|
+
readonly direction: 'asc';
|
|
25
|
+
readonly missing: 'last';
|
|
26
|
+
}];
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
declare const exists: {
|
|
30
|
+
readonly query: "astrale.query/7";
|
|
31
|
+
readonly exists: {
|
|
32
|
+
readonly nodes: readonly [`${string}:class.${string}`];
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
declare const count: {
|
|
36
|
+
readonly query: "astrale.query/7";
|
|
37
|
+
readonly count: {
|
|
38
|
+
readonly nodes: readonly [`${string}:class.${string}`];
|
|
39
|
+
};
|
|
40
|
+
readonly upTo: 10;
|
|
41
|
+
};
|
|
42
|
+
declare function overloads(): Promise<readonly [QueryResponse<import("@astrale-os/kernel-core/graph/query").QueryNodeResult<{
|
|
43
|
+
kind: "value";
|
|
44
|
+
}>>, {
|
|
45
|
+
readonly list: import("./page-contract.js").QueryPage;
|
|
46
|
+
readonly facts: Extract<import("@astrale-os/kernel-core/graph/query").Answer, {
|
|
47
|
+
readonly list: unknown;
|
|
48
|
+
}>['facts'];
|
|
49
|
+
readonly revision: string;
|
|
50
|
+
readonly revised?: true;
|
|
51
|
+
}, {
|
|
52
|
+
readonly exists: boolean;
|
|
53
|
+
readonly undecided?: boolean;
|
|
54
|
+
}, {
|
|
55
|
+
readonly count: number;
|
|
56
|
+
readonly more: boolean;
|
|
57
|
+
readonly undecided?: import("@astrale-os/kernel-core/graph/query").Undecided;
|
|
58
|
+
}]>;
|
|
59
|
+
export type pickedByInput = Assert<Equal<Awaited<ReturnType<typeof overloads>>, readonly [QueryResponse<QueryResultFor<typeof ast>>, ListAnswer, ExistsAnswer, CountAnswer]>>;
|
|
60
|
+
export type answerByFamily = Assert<Equal<[
|
|
61
|
+
QueryAnswerFor<typeof list>,
|
|
62
|
+
QueryAnswerFor<typeof exists>,
|
|
63
|
+
QueryAnswerFor<typeof count>
|
|
64
|
+
], [
|
|
65
|
+
ListAnswer,
|
|
66
|
+
ExistsAnswer,
|
|
67
|
+
CountAnswer
|
|
68
|
+
]>>;
|
|
69
|
+
/** The legacy overload stays last: `Parameters` and `ReturnType` keep reading V6. */
|
|
70
|
+
export type legacyLast = Assert<Equal<[
|
|
71
|
+
Parameters<GraphApi['query']>,
|
|
72
|
+
Awaited<ReturnType<GraphApi['query']>>
|
|
73
|
+
], [
|
|
74
|
+
[QueryAST, GraphQueryV6Options],
|
|
75
|
+
QueryResponse<QueryResultFor<QueryAST>>
|
|
76
|
+
]>>;
|
|
77
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Query, QUERY } from '@astrale-os/kernel-core/graph/query';
|
|
2
|
+
const ast = Query.from({ nodes: [task] }).select({ kind: 'nodes', projection: { kind: 'value' } });
|
|
3
|
+
const list = {
|
|
4
|
+
query: QUERY,
|
|
5
|
+
list: { nodes: [Task], orderBy: [{ property: title, direction: 'asc', missing: 'last' }] },
|
|
6
|
+
};
|
|
7
|
+
const exists = { query: QUERY, exists: { nodes: [Task] } };
|
|
8
|
+
const count = { query: QUERY, count: { nodes: [Task] }, upTo: 10 };
|
|
9
|
+
async function overloads() {
|
|
10
|
+
// A V6 QueryAST picks the legacy overload and its result; a Query the answer of its family.
|
|
11
|
+
const legacy = await graph.query(ast, { page: { size: 10 } });
|
|
12
|
+
const listed = await graph.query(list, { paging: { sizes: [{ at: [], size: 10 }] } });
|
|
13
|
+
const decided = await graph.query(exists);
|
|
14
|
+
const counted = await graph.query(count, { expected: [] });
|
|
15
|
+
return [legacy, listed, decided, counted];
|
|
16
|
+
}
|
|
17
|
+
async function refusals() {
|
|
18
|
+
// @ts-expect-error A Query takes its paging in `paging`, not V6's `page`.
|
|
19
|
+
await graph.query(list, { page: { size: 10 } });
|
|
20
|
+
// @ts-expect-error A V6 QueryAST needs its `page`; v7 `paging` is not one.
|
|
21
|
+
await graph.query(ast, { paging: { sizes: [{ at: [], size: 10 }] } });
|
|
22
|
+
// @ts-expect-error A V6 QueryAST has no default page.
|
|
23
|
+
await graph.query(ast);
|
|
24
|
+
// @ts-expect-error A Query names the v7 version.
|
|
25
|
+
await graph.query({ query: 'astrale.query/6', list: { nodes: [Task] } });
|
|
26
|
+
// @ts-expect-error A Query is a list, an exists or a count.
|
|
27
|
+
await graph.query({ query: QUERY, nodes: [Task] });
|
|
28
|
+
// @ts-expect-error A count needs its bound.
|
|
29
|
+
await graph.query({ query: QUERY, count: { nodes: [Task] } });
|
|
30
|
+
// @ts-expect-error An input is a Query or a V6 QueryAST.
|
|
31
|
+
await graph.query({ ...ast, query: QUERY });
|
|
32
|
+
}
|
|
33
|
+
void overloads;
|
|
34
|
+
void refusals;
|
package/dist/pacer/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { retry, type RetryOptions } from './retry/index.js';
|
|
1
|
+
export { RETRY_REFUSALS, retry, type RetryOptions } from './retry/index.js';
|
|
2
2
|
export { createQueue, type QueueOptions } from './queue/index.js';
|
|
3
3
|
export { createBatcher, type BatchOptions } from './batcher/index.js';
|
|
4
4
|
export { createRateLimiter, type RateLimitOptions } from './limiter/index.js';
|
package/dist/pacer/index.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RetryOptions } from './retry.js';
|
|
2
|
+
/**
|
|
3
|
+
* Opt-in policy for refusals proven to have run nothing. A back-pressure, draining or maintenance
|
|
4
|
+
* refusal is resent no earlier than its prescribed delay; a stale-snapshot conflict is resent after
|
|
5
|
+
* ordinary backoff. Every other failure ends the retry.
|
|
6
|
+
*/
|
|
7
|
+
export declare const RETRY_REFUSALS: Readonly<Required<Pick<RetryOptions, 'shouldRetry' | 'retryAfter'>>>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isSnapshotStale, retryAfterOf } from '../../errors/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Opt-in policy for refusals proven to have run nothing. A back-pressure, draining or maintenance
|
|
4
|
+
* refusal is resent no earlier than its prescribed delay; a stale-snapshot conflict is resent after
|
|
5
|
+
* ordinary backoff. Every other failure ends the retry.
|
|
6
|
+
*/
|
|
7
|
+
export const RETRY_REFUSALS = Object.freeze({
|
|
8
|
+
shouldRetry: (error) => retryAfterOf(error) !== undefined || isSnapshotStale(error),
|
|
9
|
+
retryAfter: (error) => retryAfterOf(error),
|
|
10
|
+
});
|
|
@@ -4,6 +4,8 @@ export interface RetryOptions {
|
|
|
4
4
|
readonly maxWait?: number;
|
|
5
5
|
readonly jitter?: number;
|
|
6
6
|
readonly shouldRetry?: (error: Error, attempt: number) => boolean;
|
|
7
|
+
/** Least delay in milliseconds a failure prescribes before the next attempt; backoff still applies. */
|
|
8
|
+
readonly retryAfter?: (error: Error, attempt: number) => number | undefined;
|
|
7
9
|
}
|
|
8
10
|
/** Retry with bounded exponential backoff and never swallow the final failure. */
|
|
9
11
|
export declare function retry<Result>(operation: () => Promise<Result>, options?: RetryOptions): Promise<Result>;
|