@astrale-os/kernel-client 1.0.0-beta.23 → 1.0.0-beta.25
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/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.d.ts +5 -1
- package/dist/execution/execution.js +2 -7
- package/dist/execution/index.d.ts +1 -1
- package/dist/execution/index.js +1 -1
- 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/admission.js +6 -1
- package/dist/session/bound.d.ts +10 -3
- package/dist/session/bound.js +8 -1
- package/dist/session/context/operation.js +2 -16
- package/dist/session/discovery/discovery.js +1 -1
- package/dist/session/discovery/snapshot.d.ts +5 -1
- package/dist/session/index.d.ts +2 -1
- package/dist/session/routing/dispatch.js +11 -8
- package/dist/session/routing/envelope.d.ts +3 -3
- package/dist/session/routing/legacy/release-route.d.ts +12 -0
- package/dist/session/routing/legacy/release-route.js +6 -0
- package/dist/session/session.d.ts +24 -5
- package/dist/session/session.js +31 -7
- package/dist/session/views/index.d.ts +2 -2
- package/dist/session/views/index.js +2 -2
- 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 +153 -0
- package/dist/session/views/view.d.ts +48 -0
- package/dist/session/views/view.js +79 -0
- package/dist/transport/deadline.d.ts +2 -0
- package/dist/transport/deadline.js +18 -0
- package/dist/transport/index.d.ts +1 -1
- package/dist/transport/index.js +1 -1
- package/package.json +5 -5
- 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
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Node } from '@astrale-os/kernel-core/graph/node';
|
|
2
|
+
import type { EdgeBinding, QueryAST, QueryGraphSelect } from '@astrale-os/kernel-core/graph/query';
|
|
3
|
+
import type { NodeTarget, PathLike } from '@astrale-os/kernel-core/path';
|
|
4
|
+
import type { Key } from '@astrale-os/kernel-dsl/v1';
|
|
5
|
+
import type { QueryPageRequest, QueryResponse } from '../../graph/index.js';
|
|
6
|
+
import type { SessionOperation } from '../context/index.js';
|
|
7
|
+
import type { Declaration, View } from './view.js';
|
|
8
|
+
/** The Views one Domain declares, named by its Domain Path `/:<origin>` or by its origin. */
|
|
9
|
+
export interface ViewsOf {
|
|
10
|
+
readonly domain: PathLike | Key.Origin;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* What one read of Views answers: the Views it places, or, when the declared Views it locates carry
|
|
14
|
+
* no placement, what it located. A Release binds every View its Domain declares and projection
|
|
15
|
+
* places each binding, so a Kernel that places no View answers `unplaced`.
|
|
16
|
+
*/
|
|
17
|
+
export type ViewAnswer<Placed, Located> = {
|
|
18
|
+
readonly placed: Placed;
|
|
19
|
+
} | {
|
|
20
|
+
readonly unplaced: Located;
|
|
21
|
+
};
|
|
22
|
+
/** A Query whose answer is the of_domain Edges of Views, with both endpoints. */
|
|
23
|
+
export type ViewsQuery = QueryAST<QueryGraphSelect<EdgeBinding>>;
|
|
24
|
+
/** How a Session reads Views: through the graph, under the caller's own read authority. */
|
|
25
|
+
export interface ViewReader {
|
|
26
|
+
/** Read one page of a Views Query. */
|
|
27
|
+
query(ast: ViewsQuery, page: QueryPageRequest, operation: SessionOperation): Promise<QueryResponse>;
|
|
28
|
+
/** Read one Node; a missing or masked Node rejects with NodeUnavailableError. */
|
|
29
|
+
read(target: NodeTarget, operation: SessionOperation): Promise<Node>;
|
|
30
|
+
/** Admit one View from its Node and its Declaration, or none for an instance. */
|
|
31
|
+
admit(node: Node, declaration: Declaration | undefined): View;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Read one View by any Path: an exact `@<id>`, its declaration `/:<origin>:view.<name>`, or a
|
|
35
|
+
* traversal such as `Path.domain(origin).in(K.classes.entrypoint.key)`. One Query selects the
|
|
36
|
+
* of_domain Edge of the View it reaches, which only projection writes: with it, its Domain declares
|
|
37
|
+
* the View; without it, a second read returns the instance. A declared View without a placement
|
|
38
|
+
* is answered `unplaced`, with its Path and Domain.
|
|
39
|
+
*/
|
|
40
|
+
export declare function readView(reader: ViewReader, target: NodeTarget, operation: SessionOperation): Promise<ViewAnswer<View, Pick<View, 'path' | 'domain'>>>;
|
|
41
|
+
/**
|
|
42
|
+
* Read the Views one Domain declares, in Path order, from the graph alone: one Query selects the
|
|
43
|
+
* of_domain Edges of its Views, which the answer closes with their View Nodes and the Domain Node.
|
|
44
|
+
* Only an exact Domain Path `/:<origin>` or an origin is accepted; any other Path is refused before
|
|
45
|
+
* the Query. A caller that may not read them meets the Query's own refusal or an empty list. An
|
|
46
|
+
* answer that locates declared Views and places none of them is answered `unplaced`, with the
|
|
47
|
+
* Domain.
|
|
48
|
+
*/
|
|
49
|
+
export declare function readDomainViews(reader: ViewReader, domain: ViewsOf['domain'], operation: SessionOperation): Promise<ViewAnswer<readonly View[], Key.Origin>>;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { equal } from '@astrale-os/kernel-core/graph/properties';
|
|
2
|
+
import { Query } from '@astrale-os/kernel-core/graph/query';
|
|
3
|
+
import { Path } from '@astrale-os/kernel-core/path';
|
|
4
|
+
import { K } from '@astrale-os/kernel-core/schema';
|
|
5
|
+
import { patterns } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
6
|
+
import { ClientError } from '../../errors/index.js';
|
|
7
|
+
import { declaredView } from './view.js';
|
|
8
|
+
const OF_DOMAIN = K.classes.of_domain.key;
|
|
9
|
+
const MEMBER = K.classes.of_domain.properties.member.key;
|
|
10
|
+
const DOMAIN = K.classes.Domain.key;
|
|
11
|
+
const ORIGIN = K.classes.Domain.properties.origin.key;
|
|
12
|
+
const PLACEMENT = K.classes.View.properties.placement.key;
|
|
13
|
+
/** Reads of one answer before giving up, the bound View.resolve put on its Registry reads. */
|
|
14
|
+
const ATTEMPTS = 3;
|
|
15
|
+
/** Selected Edges per page: one of_domain Edge per View the Domain declares. */
|
|
16
|
+
const PAGE_SIZE = 100;
|
|
17
|
+
/**
|
|
18
|
+
* Read one View by any Path: an exact `@<id>`, its declaration `/:<origin>:view.<name>`, or a
|
|
19
|
+
* traversal such as `Path.domain(origin).in(K.classes.entrypoint.key)`. One Query selects the
|
|
20
|
+
* of_domain Edge of the View it reaches, which only projection writes: with it, its Domain declares
|
|
21
|
+
* the View; without it, a second read returns the instance. A declared View without a placement
|
|
22
|
+
* is answered `unplaced`, with its Path and Domain.
|
|
23
|
+
*/
|
|
24
|
+
export async function readView(reader, target, operation) {
|
|
25
|
+
const { nodes, edges } = await readCoherent(reader, declarationQuery(target), operation);
|
|
26
|
+
const edge = edges[0];
|
|
27
|
+
if (edge === undefined) {
|
|
28
|
+
return { placed: reader.admit(await reader.read(target, operation), undefined) };
|
|
29
|
+
}
|
|
30
|
+
const view = nodes.find(({ id }) => id === edge.source);
|
|
31
|
+
const domain = nodes.find(({ id }) => id === edge.target);
|
|
32
|
+
if (edges.length !== 1 || edge.class !== OF_DOMAIN || !view || domain?.class !== DOMAIN) {
|
|
33
|
+
throw new ClientError('View answer is invalid.');
|
|
34
|
+
}
|
|
35
|
+
const declaration = Object.freeze({ domain, member: edge.props[MEMBER] });
|
|
36
|
+
if (view.props[PLACEMENT] === undefined)
|
|
37
|
+
return { unplaced: declaredView(declaration) };
|
|
38
|
+
return { placed: reader.admit(view, declaration) };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Read the Views one Domain declares, in Path order, from the graph alone: one Query selects the
|
|
42
|
+
* of_domain Edges of its Views, which the answer closes with their View Nodes and the Domain Node.
|
|
43
|
+
* Only an exact Domain Path `/:<origin>` or an origin is accepted; any other Path is refused before
|
|
44
|
+
* the Query. A caller that may not read them meets the Query's own refusal or an empty list. An
|
|
45
|
+
* answer that locates declared Views and places none of them is answered `unplaced`, with the
|
|
46
|
+
* Domain.
|
|
47
|
+
*/
|
|
48
|
+
export async function readDomainViews(reader, domain, operation) {
|
|
49
|
+
const origin = domainOrigin(domain);
|
|
50
|
+
const located = locateDomainViews(await readCoherent(reader, domainViewsQuery(origin), operation), origin);
|
|
51
|
+
if (located === undefined)
|
|
52
|
+
return { placed: Object.freeze([]) };
|
|
53
|
+
const { owner, members } = located;
|
|
54
|
+
const declarations = [...members].map(([node, member]) => [node, Object.freeze({ domain: owner, member })]);
|
|
55
|
+
const paths = declarations.map(([, declared]) => declaredView(declared).path);
|
|
56
|
+
if (new Set(paths).size !== paths.length) {
|
|
57
|
+
throw new ClientError('Declared View keys are not unique.');
|
|
58
|
+
}
|
|
59
|
+
// Projection places each View the active Release binds. One no binding places has nothing a
|
|
60
|
+
// Shell could mount, and refusing it would let one unplaced View hide every other: it is skipped.
|
|
61
|
+
const placed = declarations.filter(([node]) => node.props[PLACEMENT] !== undefined);
|
|
62
|
+
if (declarations.length > 0 && placed.length === 0)
|
|
63
|
+
return { unplaced: origin };
|
|
64
|
+
const views = placed.map(([node, declared]) => reader.admit(node, declared));
|
|
65
|
+
return { placed: Object.freeze(views.sort((left, right) => compareText(left.path, right.path))) };
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Locate the Views of one Domain in one coherent answer, refusing an answer that is not of it. An
|
|
69
|
+
* empty answer is a Domain the caller may not read or that does not exist, as View.resolve
|
|
70
|
+
* answered for a Domain it did not know.
|
|
71
|
+
*/
|
|
72
|
+
function locateDomainViews(graph, domain) {
|
|
73
|
+
const nodes = new Map(graph.nodes.map((node) => [node.id, node]));
|
|
74
|
+
const owner = graph.nodes.find((node) => node.class === DOMAIN);
|
|
75
|
+
if (owner !== undefined && owner.props[ORIGIN] !== domain) {
|
|
76
|
+
throw new ClientError('Domain View answer is not of the requested Domain.');
|
|
77
|
+
}
|
|
78
|
+
const members = new Map();
|
|
79
|
+
for (const edge of graph.edges) {
|
|
80
|
+
const view = nodes.get(edge.source);
|
|
81
|
+
if (edge.target !== owner?.id || view === undefined) {
|
|
82
|
+
throw new ClientError('Domain View answer is not of the requested Domain.');
|
|
83
|
+
}
|
|
84
|
+
if (edge.class !== OF_DOMAIN)
|
|
85
|
+
throw new ClientError('Domain View answer is invalid.');
|
|
86
|
+
members.set(view, edge.props[MEMBER]);
|
|
87
|
+
}
|
|
88
|
+
if (owner === undefined)
|
|
89
|
+
return undefined;
|
|
90
|
+
return Object.freeze({ owner, members });
|
|
91
|
+
}
|
|
92
|
+
/** Read one answer whose pages agree, at most ATTEMPTS times. */
|
|
93
|
+
async function readCoherent(reader, ast, operation) {
|
|
94
|
+
for (let attempt = 0; attempt < ATTEMPTS; attempt++) {
|
|
95
|
+
const graph = await readAnswer(reader, ast, operation);
|
|
96
|
+
if (graph !== undefined)
|
|
97
|
+
return graph;
|
|
98
|
+
}
|
|
99
|
+
throw new ClientError('Views could not be read from one coherent graph.');
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Read every page of one answer, or nothing when its pages disagree. Each page is its own Query
|
|
103
|
+
* and every page carries the target of each selected Edge, so two pages that differ on a Node they
|
|
104
|
+
* share were read from different snapshots: the answer is read again.
|
|
105
|
+
*/
|
|
106
|
+
async function readAnswer(reader, ast, operation) {
|
|
107
|
+
const nodes = new Map();
|
|
108
|
+
const edges = [];
|
|
109
|
+
let after;
|
|
110
|
+
do {
|
|
111
|
+
const { result, page } = await reader.query(ast, after === undefined ? { size: PAGE_SIZE } : { size: PAGE_SIZE, after }, operation);
|
|
112
|
+
if (result.kind !== 'graph' || result.selection.kind !== 'edge') {
|
|
113
|
+
throw new ClientError('View query returned a non-Edge graph result.');
|
|
114
|
+
}
|
|
115
|
+
for (const node of result.graph.nodes) {
|
|
116
|
+
const seen = nodes.get(node.id);
|
|
117
|
+
if (seen === undefined)
|
|
118
|
+
nodes.set(node.id, node);
|
|
119
|
+
else if (seen.class !== node.class || !equal(seen.props, node.props))
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
edges.push(...result.graph.edges);
|
|
123
|
+
after = page.next;
|
|
124
|
+
} while (after !== undefined);
|
|
125
|
+
return Object.freeze({ nodes: Object.freeze([...nodes.values()]), edges: Object.freeze(edges) });
|
|
126
|
+
}
|
|
127
|
+
/** The of_domain Edge from the View a Path reaches to the Domain that declares it, if any. */
|
|
128
|
+
function declarationQuery(target) {
|
|
129
|
+
const declared = Query.from({ nodes: [target] })
|
|
130
|
+
.filter({ class: K.classes.View.ref })
|
|
131
|
+
.expand({ via: [K.classes.of_domain.ref], direction: 'outgoing' });
|
|
132
|
+
return declared.select({ kind: 'graph', binding: declared.edge });
|
|
133
|
+
}
|
|
134
|
+
/** The of_domain Edges that reach a Domain from its Views, with both endpoints. */
|
|
135
|
+
function domainViewsQuery(origin) {
|
|
136
|
+
const views = Query.from({ nodes: [Path.domain(origin)] })
|
|
137
|
+
.expand({ via: [K.classes.of_domain.ref], direction: 'incoming' })
|
|
138
|
+
.filter({ class: K.classes.View.ref });
|
|
139
|
+
return views.select({ kind: 'graph', binding: views.edge });
|
|
140
|
+
}
|
|
141
|
+
/** The origin of a Domain, named by itself or by its exact Domain Path. */
|
|
142
|
+
function domainOrigin(input) {
|
|
143
|
+
if (typeof input === 'string' && patterns.origin.test(input))
|
|
144
|
+
return input;
|
|
145
|
+
const { anchor, steps } = Path.from(input).ast;
|
|
146
|
+
if (anchor.kind !== 'domain' || steps.length !== 0) {
|
|
147
|
+
throw new TypeError('Domain Views are read for a Domain Path /:<origin> or its origin.');
|
|
148
|
+
}
|
|
149
|
+
return anchor.origin;
|
|
150
|
+
}
|
|
151
|
+
function compareText(left, right) {
|
|
152
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
153
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { IssuerId } from '@astrale-os/kernel-core/auth';
|
|
2
|
+
import type { Node } from '@astrale-os/kernel-core/graph/node';
|
|
3
|
+
import type { NodePath } from '@astrale-os/kernel-core/path';
|
|
4
|
+
import type { Key } from '@astrale-os/kernel-dsl/v1';
|
|
5
|
+
import type { ViewPlacement } from '@astrale-os/kernel-protocol/placement';
|
|
6
|
+
import type { SessionPolicy } from '../context/index.js';
|
|
7
|
+
/** One View, read from its Node, whoever wrote it. */
|
|
8
|
+
export interface View {
|
|
9
|
+
/**
|
|
10
|
+
* The Path that names it, which `view` reads it by: `/:<origin>:view.<name>` for a View its
|
|
11
|
+
* Domain declares, `@<id>` for an instance of a Domain Class that extends View.
|
|
12
|
+
*/
|
|
13
|
+
readonly path: NodePath;
|
|
14
|
+
/** The Domain that declares it, or the Domain of the Class it is an instance of. */
|
|
15
|
+
readonly domain: Key.Origin;
|
|
16
|
+
readonly description?: string;
|
|
17
|
+
/** Where and how a Shell mounts it, as its Release binds it or a Mutation wrote it. */
|
|
18
|
+
readonly placement: ViewPlacement;
|
|
19
|
+
/**
|
|
20
|
+
* The Identity that answers for its code: the `iss` of the Domain that declares it, or for an
|
|
21
|
+
* instance its own `iss`, self-issued by this Kernel. Absent when it has none.
|
|
22
|
+
*/
|
|
23
|
+
readonly issuer?: IssuerId;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* What declares a View its Domain declares: the Domain Node its of_domain Edge reaches, and the
|
|
27
|
+
* member that Edge names it by. Only projection writes an of_domain Edge.
|
|
28
|
+
*/
|
|
29
|
+
export interface Declaration {
|
|
30
|
+
readonly domain: Node;
|
|
31
|
+
readonly member: unknown;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Admit one View from its Node, with the Declaration that names it, or none for an instance. The
|
|
35
|
+
* placement passes the Protocol placement codec, which a Release View binding composes, then Session
|
|
36
|
+
* endpoint policy; the client interprets neither its handshake nor its host. The issuer is whoever
|
|
37
|
+
* answers for the View's code: the Domain that declares it, or for an instance its own Identity,
|
|
38
|
+
* self-issued by this Kernel (`register` mode `self`), never its Class Domain nor an external
|
|
39
|
+
* issuer other Identities share.
|
|
40
|
+
*/
|
|
41
|
+
export declare function admitView(node: Node, declaration: Declaration | undefined, kernel: IssuerId, policy: Readonly<SessionPolicy>): View;
|
|
42
|
+
/** The Path and Domain of a View its Domain declares, from its Declaration. */
|
|
43
|
+
export declare function declaredView(declaration: Declaration): Pick<View, 'path' | 'domain'>;
|
|
44
|
+
/**
|
|
45
|
+
* Admit the placement a View Node carries with the Protocol placement codec, which a Release View
|
|
46
|
+
* binding composes, then Session endpoint policy.
|
|
47
|
+
*/
|
|
48
|
+
export declare function admitViewPlacement(value: unknown, policy: Readonly<SessionPolicy>): ViewPlacement;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { issuer, register } from '@astrale-os/kernel-core/auth';
|
|
2
|
+
import { Path } from '@astrale-os/kernel-core/path';
|
|
3
|
+
import { K } from '@astrale-os/kernel-core/schema';
|
|
4
|
+
import { Key as DefinitionKey } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
5
|
+
import { acceptViewPlacement, PlacementError } from '@astrale-os/kernel-protocol/placement';
|
|
6
|
+
import { ClientError } from '../../errors/index.js';
|
|
7
|
+
import { allowEndpoint } from '../context/index.js';
|
|
8
|
+
const VIEW = K.classes.View.key;
|
|
9
|
+
const PLACEMENT = K.classes.View.properties.placement.key;
|
|
10
|
+
const DESCRIPTION = K.classes.Descriptable.properties.description.key;
|
|
11
|
+
const ISSUER = K.classes.Identity.properties.iss.key;
|
|
12
|
+
const ORIGIN = K.classes.Domain.properties.origin.key;
|
|
13
|
+
const MEMBER = /^view\.([A-Za-z][A-Za-z0-9_]*)$/u;
|
|
14
|
+
/**
|
|
15
|
+
* Admit one View from its Node, with the Declaration that names it, or none for an instance. The
|
|
16
|
+
* placement passes the Protocol placement codec, which a Release View binding composes, then Session
|
|
17
|
+
* endpoint policy; the client interprets neither its handshake nor its host. The issuer is whoever
|
|
18
|
+
* answers for the View's code: the Domain that declares it, or for an instance its own Identity,
|
|
19
|
+
* self-issued by this Kernel (`register` mode `self`), never its Class Domain nor an external
|
|
20
|
+
* issuer other Identities share.
|
|
21
|
+
*/
|
|
22
|
+
export function admitView(node, declaration, kernel, policy) {
|
|
23
|
+
// A Kernel View Node is declared by projection, which attaches it to its Domain; an instance is
|
|
24
|
+
// a Node of a Domain Class. One read without its of_domain Edge cannot name it.
|
|
25
|
+
if (declaration === undefined && node.class === VIEW) {
|
|
26
|
+
throw new ClientError('The Domain that declares this View is not readable.');
|
|
27
|
+
}
|
|
28
|
+
const value = node.props[PLACEMENT];
|
|
29
|
+
if (value === undefined)
|
|
30
|
+
throw new ClientError('Node is not a placed View.');
|
|
31
|
+
const placement = admitViewPlacement(value, policy);
|
|
32
|
+
const named = declaration === undefined
|
|
33
|
+
? { path: Path.id(node.id).raw, domain: DefinitionKey.origin(node.class) }
|
|
34
|
+
: declaredView(declaration);
|
|
35
|
+
const answerer = declaration === undefined ? selfIssuer(node, kernel) : domainIssuer(declaration);
|
|
36
|
+
const description = node.props[DESCRIPTION];
|
|
37
|
+
return Object.freeze({
|
|
38
|
+
...named,
|
|
39
|
+
...(typeof description === 'string' ? { description } : {}),
|
|
40
|
+
placement,
|
|
41
|
+
...(answerer === undefined ? {} : { issuer: answerer }),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/** The Path and Domain of a View its Domain declares, from its Declaration. */
|
|
45
|
+
export function declaredView(declaration) {
|
|
46
|
+
const origin = declaration.domain.props[ORIGIN];
|
|
47
|
+
const name = typeof declaration.member === 'string' ? MEMBER.exec(declaration.member)?.[1] : undefined;
|
|
48
|
+
const key = `${String(origin)}:${String(declaration.member)}`;
|
|
49
|
+
if (typeof origin !== 'string' || name === undefined || !DefinitionKey.is(key)) {
|
|
50
|
+
throw new ClientError('Declared View member is invalid.');
|
|
51
|
+
}
|
|
52
|
+
const domain = DefinitionKey.origin(key);
|
|
53
|
+
return Object.freeze({ path: Path.project({ origin: domain, kind: 'view', name }).raw, domain });
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Admit the placement a View Node carries with the Protocol placement codec, which a Release View
|
|
57
|
+
* binding composes, then Session endpoint policy.
|
|
58
|
+
*/
|
|
59
|
+
export function admitViewPlacement(value, policy) {
|
|
60
|
+
let placement;
|
|
61
|
+
try {
|
|
62
|
+
placement = acceptViewPlacement(value);
|
|
63
|
+
}
|
|
64
|
+
catch (cause) {
|
|
65
|
+
if (!(cause instanceof PlacementError))
|
|
66
|
+
throw cause;
|
|
67
|
+
throw new ClientError('View placement is invalid.', { cause });
|
|
68
|
+
}
|
|
69
|
+
allowEndpoint(placement.href, policy);
|
|
70
|
+
return placement;
|
|
71
|
+
}
|
|
72
|
+
function domainIssuer({ domain }) {
|
|
73
|
+
const served = domain.props[ISSUER];
|
|
74
|
+
return issuer.is(served) ? served : undefined;
|
|
75
|
+
}
|
|
76
|
+
function selfIssuer(node, kernel) {
|
|
77
|
+
const registered = node.props[ISSUER];
|
|
78
|
+
return issuer.is(registered) && register.isSelfIssuer(kernel, registered) ? registered : undefined;
|
|
79
|
+
}
|
|
@@ -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();
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export type { RequestOptions, DeploymentRetired, MissControl, StaleControl, Transport, TransportRequest, TransportResult, } from './transport.js';
|
|
2
|
-
export { asError, controlledSignal, positiveInteger, requireLive, type ControlledSignal, } from './deadline.js';
|
|
2
|
+
export { asError, controlledSignal, pause, positiveInteger, requireLive, type ControlledSignal, } from './deadline.js';
|
package/dist/transport/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { asError, controlledSignal, positiveInteger, requireLive, } from './deadline.js';
|
|
1
|
+
export { asError, controlledSignal, pause, positiveInteger, requireLive, } from './deadline.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrale-os/kernel-client",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.25",
|
|
4
4
|
"description": "Universal Client — protocol-first, transport-agnostic",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astrale",
|
|
@@ -65,13 +65,13 @@
|
|
|
65
65
|
"access": "public"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@astrale-os/kernel-core": "1.0.0-beta.
|
|
69
|
-
"@astrale-os/kernel-dsl": "1.0.0-beta.
|
|
70
|
-
"@astrale-os/kernel-protocol": "1.0.0-beta.
|
|
68
|
+
"@astrale-os/kernel-core": "1.0.0-beta.22",
|
|
69
|
+
"@astrale-os/kernel-dsl": "1.0.0-beta.15",
|
|
70
|
+
"@astrale-os/kernel-protocol": "1.0.0-beta.22",
|
|
71
71
|
"@tanstack/pacer": "0.20.1"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@astrale-os/kernel-server": "1.0.0-beta.
|
|
74
|
+
"@astrale-os/kernel-server": "1.0.0-beta.22",
|
|
75
75
|
"@astrale/typescript-config": "npm:@jsr/astrale__typescript-config@~1.1.0",
|
|
76
76
|
"@types/node": "^22.0.0",
|
|
77
77
|
"typescript": "7.0.2",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Key, bundle } from '@astrale-os/kernel-dsl/v1';
|
|
2
|
-
import type { DomainRelease } from '@astrale-os/kernel-protocol/release';
|
|
3
|
-
import { type ResolvedView } from '@astrale-os/kernel-core/schema/kernel/syscalls/view-resolution';
|
|
4
|
-
export type { ResolvedView } from '@astrale-os/kernel-core/schema/kernel/syscalls/view-resolution';
|
|
5
|
-
import type { SessionPolicy } from '../context/index.js';
|
|
6
|
-
/** One verified View declaration joined with its owning Release and provenance. */
|
|
7
|
-
/** Immutable canonical-key-ordered inventory of Views resolved under one Session revision. */
|
|
8
|
-
export interface ViewCatalog {
|
|
9
|
-
readonly entrypoint?: ResolvedView;
|
|
10
|
-
readonly views: readonly ResolvedView[];
|
|
11
|
-
}
|
|
12
|
-
/** Join each root Domain View to its exact release binding. */
|
|
13
|
-
export declare function rootViewCatalog(release: DomainRelease, artifact: bundle.Bundle, policy: Readonly<SessionPolicy>): ViewCatalog;
|
|
14
|
-
export declare function catalogFromKeys(root: ViewCatalog, keys: readonly Key.View[]): ViewCatalog;
|
|
15
|
-
/**
|
|
16
|
-
* Re-admit one Runtime-resolved Domain View catalog at the Client trust boundary. Only Views that
|
|
17
|
-
* the requested Domain declares for itself are kept.
|
|
18
|
-
*/
|
|
19
|
-
export declare function domainViewCatalog(input: unknown, domain: Key.Origin, policy: Readonly<SessionPolicy>): ViewCatalog;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { PathLike } from '@astrale-os/kernel-core/path';
|
|
2
|
-
import type { Key } from '@astrale-os/kernel-dsl/v1';
|
|
3
|
-
import type { Call, Input } from '../../client/index.js';
|
|
4
|
-
import type { SessionOperation } from '../context/index.js';
|
|
5
|
-
import type { ViewCatalog } from './catalog.js';
|
|
6
|
-
export type ViewInvoker = (call: Call, operation: SessionOperation) => Promise<Input>;
|
|
7
|
-
export type ViewCatalogAdmission = (input: unknown, domain: Key.Origin) => ViewCatalog;
|
|
8
|
-
/**
|
|
9
|
-
* Resolve the per-Domain View catalog through the canonical source Kernel call, then admit its
|
|
10
|
-
* installed Release evidence. Every View targets its owning Domain, so only an exact Domain
|
|
11
|
-
* Path `/:<origin>` is meaningful; any other Path is refused before the call.
|
|
12
|
-
*/
|
|
13
|
-
export declare function resolveViewsFor(invoke: ViewInvoker, admitCatalog: ViewCatalogAdmission, domain: PathLike, operation: SessionOperation): Promise<ViewCatalog>;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Path } from '@astrale-os/kernel-core/path';
|
|
2
|
-
import { view } from '@astrale-os/kernel-core/schema/kernel/syscalls/references';
|
|
3
|
-
import { call } from '../../client/index.js';
|
|
4
|
-
/**
|
|
5
|
-
* Resolve the per-Domain View catalog through the canonical source Kernel call, then admit its
|
|
6
|
-
* installed Release evidence. Every View targets its owning Domain, so only an exact Domain
|
|
7
|
-
* Path `/:<origin>` is meaningful; any other Path is refused before the call.
|
|
8
|
-
*/
|
|
9
|
-
export async function resolveViewsFor(invoke, admitCatalog, domain, operation) {
|
|
10
|
-
const origin = domainOrigin(domain);
|
|
11
|
-
const owner = Path.project(view.resolve.owner);
|
|
12
|
-
const resolve = Path.staticMethod(owner, view.resolve.name);
|
|
13
|
-
return admitCatalog(await invoke(call(resolve, { target: Path.domain(origin).raw }), operation), origin);
|
|
14
|
-
}
|
|
15
|
-
function domainOrigin(input) {
|
|
16
|
-
const { anchor, steps } = Path.from(input).ast;
|
|
17
|
-
if (anchor.kind !== 'domain' || steps.length !== 0) {
|
|
18
|
-
throw new TypeError('View catalog requires a Domain Path /:<origin>; Views never target a Node.');
|
|
19
|
-
}
|
|
20
|
-
return anchor.origin;
|
|
21
|
-
}
|