@astrale-os/kernel-client 1.0.0-beta.24 → 1.0.0-beta.26
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/execution/execution.d.ts +5 -1
- package/dist/graph/page-contract.d.ts +2 -2
- package/dist/graph/query.js +1 -1
- package/dist/graph/query.typecheck.js +1 -1
- package/dist/session/admission.js +6 -1
- package/dist/session/bound.d.ts +10 -3
- package/dist/session/bound.js +6 -1
- 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/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/package.json +6 -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
|
@@ -21,7 +21,11 @@ export interface ExecutionApi {
|
|
|
21
21
|
readonly name: string;
|
|
22
22
|
readonly value: Value;
|
|
23
23
|
}, options?: RequestOptions): Promise<void>;
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* A cooperative cancel: the run sees it at its next await and may compensate; one that cannot
|
|
26
|
+
* reach an await ends `cancelled` without compensation. `force` kills the run without
|
|
27
|
+
* compensation.
|
|
28
|
+
*/
|
|
25
29
|
cancel<Output>(execution: ExecutionTarget<Output>, input?: {
|
|
26
30
|
readonly force?: boolean;
|
|
27
31
|
}, options?: RequestOptions): Promise<ExecutionStatus<Output>>;
|
|
@@ -43,7 +43,7 @@ export interface QueryItem {
|
|
|
43
43
|
}>>>;
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
|
-
* What a Query answers, by
|
|
46
|
+
* What a Query answers, by its family: a list's Page, the table of the facts it
|
|
47
47
|
* renders as values, the revision it was read at and whether its cursor came from another (W6);
|
|
48
48
|
* an `exists`; or a `count`.
|
|
49
49
|
*/
|
|
@@ -57,7 +57,7 @@ export type QueryAnswer = {
|
|
|
57
57
|
} | Exclude<Answer, {
|
|
58
58
|
readonly list: unknown;
|
|
59
59
|
}>;
|
|
60
|
-
/** The answer of the family a Query
|
|
60
|
+
/** The answer of the family a Query names: `list`, `exists` or `count`. */
|
|
61
61
|
export type QueryAnswerFor<Query extends wire.Document> = Query extends {
|
|
62
62
|
readonly list: unknown;
|
|
63
63
|
} ? Extract<QueryAnswer, {
|
package/dist/graph/query.js
CHANGED
|
@@ -94,7 +94,7 @@ function invalid(what, detail, cause) {
|
|
|
94
94
|
const subject = what === 'query' ? 'Graph query' : 'Graph query paging';
|
|
95
95
|
throw new TypeError(`${subject} is invalid: ${detail}.`, { cause });
|
|
96
96
|
}
|
|
97
|
-
/** The family a Query
|
|
97
|
+
/** The family a Query names (`list`, `exists` or `count`); undefined unless it names one. */
|
|
98
98
|
function familyOf(query) {
|
|
99
99
|
const families = ['list', 'exists', 'count'].filter((family) => family in query);
|
|
100
100
|
return families.length === 1 ? families[0] : undefined;
|
|
@@ -23,7 +23,7 @@ async function refusals() {
|
|
|
23
23
|
await graph.query(ast);
|
|
24
24
|
// @ts-expect-error A Query names the v7 version.
|
|
25
25
|
await graph.query({ query: 'astrale.query/6', list: { nodes: [Task] } });
|
|
26
|
-
// @ts-expect-error A Query
|
|
26
|
+
// @ts-expect-error A Query is a list, an exists or a count.
|
|
27
27
|
await graph.query({ query: QUERY, nodes: [Task] });
|
|
28
28
|
// @ts-expect-error A count needs its bound.
|
|
29
29
|
await graph.query({ query: QUERY, count: { nodes: [Task] } });
|
|
@@ -32,7 +32,12 @@ export async function admitFunction(dependencies, call, operation) {
|
|
|
32
32
|
.as(exchanged.credential)
|
|
33
33
|
.dispatch({ target: ADMIT, input: { call, credential: exchanged.delegation } }, { ...sessionTransportOptions(operation), delegate: effective.delegate }));
|
|
34
34
|
const output = admitOutput.parse(requireResultKind('value', result).value);
|
|
35
|
-
|
|
35
|
+
// A Domain-qualified target names a declaration, by its key and without a definition: only an
|
|
36
|
+
// instance is named by its NodeId and defined by its Node.
|
|
37
|
+
if (output.definition !== undefined || !Key.is(output.callable)) {
|
|
38
|
+
throw new ClientError('Function admission returned a different callable.');
|
|
39
|
+
}
|
|
40
|
+
const callable = output.callable;
|
|
36
41
|
if (!matchesCallable(target, callable)) {
|
|
37
42
|
throw new ClientError('Function admission returned a different callable.');
|
|
38
43
|
}
|
package/dist/session/bound.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { ContentApi } from './content/index.js';
|
|
|
6
6
|
import type { SessionControlOptions } from './context/index.js';
|
|
7
7
|
import type { SessionRequestOptions } from './routing/index.js';
|
|
8
8
|
import type { ClientSession } from './session.js';
|
|
9
|
-
import type { ViewCatalog } from './views/index.js';
|
|
9
|
+
import type { ViewCatalog } from './views/legacy/index.js';
|
|
10
10
|
import { type Binary, type Call, type Stream } from '../client/index.js';
|
|
11
11
|
import { type GraphApi } from '../graph/index.js';
|
|
12
12
|
/** Exact live Session surface captured by one credential-bound Kernel view. */
|
|
@@ -20,7 +20,12 @@ export interface BoundSessionSource {
|
|
|
20
20
|
invoke: ClientSession['invoke'];
|
|
21
21
|
stream(call: Call, options?: SessionRequestOptions): Promise<Stream>;
|
|
22
22
|
binary(call: Call, options?: SessionRequestOptions): Promise<Binary>;
|
|
23
|
-
|
|
23
|
+
view: ClientSession['view'];
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated Read a Domain's Views with `view({ domain })`. A source need not serve it: the
|
|
26
|
+
* bound `viewsFor` of one that does not throws a TypeError.
|
|
27
|
+
*/
|
|
28
|
+
viewsFor?(domain: Parameters<ClientSession['viewsFor']>[0], options?: SessionControlOptions): Promise<ViewCatalog>;
|
|
24
29
|
}
|
|
25
30
|
export interface BoundSessionControls {
|
|
26
31
|
readonly signal: AbortSignal;
|
|
@@ -44,7 +49,9 @@ export interface BoundClientSession extends GraphApi {
|
|
|
44
49
|
invoke: ClientSession['invoke'];
|
|
45
50
|
stream(call: Call, options?: SessionRequestOptions): Promise<Stream>;
|
|
46
51
|
binary(call: Call, options?: SessionRequestOptions): Promise<Binary>;
|
|
47
|
-
|
|
52
|
+
view: BoundSessionSource['view'];
|
|
53
|
+
/** @deprecated Read a Domain's Views with `view({ domain })`. */
|
|
54
|
+
viewsFor: NonNullable<BoundSessionSource['viewsFor']>;
|
|
48
55
|
}
|
|
49
56
|
/** Capture one Session into the ordinary graph, auth, and invocation Kernel journey. */
|
|
50
57
|
export declare function bindSession(source: BoundSessionSource, controls?: BoundSessionControls): BoundClientSession;
|
package/dist/session/bound.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createAuth } from '../auth/auth.js';
|
|
|
2
2
|
import { call as createCall, } from '../client/index.js';
|
|
3
3
|
import { createExecution } from '../execution/index.js';
|
|
4
4
|
import { createGraph } from '../graph/index.js';
|
|
5
|
+
import { unavailableViewCatalog } from './views/legacy/index.js';
|
|
5
6
|
/** Capture one Session into the ordinary graph, auth, and invocation Kernel journey. */
|
|
6
7
|
export function bindSession(source, controls) {
|
|
7
8
|
if (source === null || typeof source !== 'object')
|
|
@@ -18,7 +19,8 @@ export function bindSession(source, controls) {
|
|
|
18
19
|
invalid();
|
|
19
20
|
const uploadSource = capture(contentSource, 'upload');
|
|
20
21
|
const downloadSource = capture(contentSource, 'download');
|
|
21
|
-
const
|
|
22
|
+
const viewSource = capture(source, 'view');
|
|
23
|
+
const viewsForSource = source.viewsFor === undefined ? unavailableViewCatalog : capture(source, 'viewsFor');
|
|
22
24
|
const schemaSource = captureSchema(source.schema);
|
|
23
25
|
const dispatch = ((input, options) => dispatchSource(input, mergeOptions(options, admittedControls)));
|
|
24
26
|
const admit = (input, options) => admitSource(input, mergeOptions(options, admittedControls));
|
|
@@ -30,6 +32,8 @@ export function bindSession(source, controls) {
|
|
|
30
32
|
// Both forms share the bound controls; the source selects the form from its argument.
|
|
31
33
|
const download = ((input, options) => downloadSource(input, mergeOptions(options, admittedControls)));
|
|
32
34
|
const content = Object.freeze({ upload, download });
|
|
35
|
+
// Both forms share the bound controls; the source selects the form from its argument.
|
|
36
|
+
const view = ((input, options) => viewSource(input, mergeOptions(options, admittedControls)));
|
|
33
37
|
const viewsFor = (domain, options) => viewsForSource(domain, mergeOptions(options, admittedControls));
|
|
34
38
|
const install = (request, options) => schemaSource.install(request, mergeOptions(options, admittedControls));
|
|
35
39
|
const uninstall = (request, options) => schemaSource.uninstall(request, mergeOptions(options, admittedControls));
|
|
@@ -81,6 +85,7 @@ export function bindSession(source, controls) {
|
|
|
81
85
|
stream,
|
|
82
86
|
binary,
|
|
83
87
|
content,
|
|
88
|
+
view,
|
|
84
89
|
viewsFor,
|
|
85
90
|
});
|
|
86
91
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { runSessionOperation } from '../context/index.js';
|
|
2
|
-
import { rootViewCatalog } from '../views/index.js';
|
|
2
|
+
import { rootViewCatalog } from '../views/legacy/index.js';
|
|
3
3
|
import { BundleUnavailableError } from './bundle.js';
|
|
4
4
|
import { createSessionSnapshot } from './snapshot.js';
|
|
5
5
|
export class SessionDiscovery {
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import type { IssuerId } from '@astrale-os/kernel-core/auth/issuer';
|
|
2
2
|
import type { bundle } from '@astrale-os/kernel-dsl/v1';
|
|
3
|
-
import type { ViewCatalog } from '../views/index.js';
|
|
3
|
+
import type { ViewCatalog } from '../views/legacy/index.js';
|
|
4
4
|
import type { IntrinsicRelease } from './release.js';
|
|
5
5
|
/** Coherent public observation acquired through one Client Session at one intrinsic release. */
|
|
6
6
|
export interface SessionSnapshot {
|
|
7
7
|
readonly kernel: IssuerId;
|
|
8
8
|
readonly release: IntrinsicRelease;
|
|
9
9
|
readonly bundle: bundle.Bundle;
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated The root Domain's Views as its Release binds them, each with its Release digest.
|
|
12
|
+
* Read them with `ClientSession.view({ domain })`.
|
|
13
|
+
*/
|
|
10
14
|
readonly views: ViewCatalog;
|
|
11
15
|
}
|
|
12
16
|
export declare function createSessionSnapshot(kernel: IssuerId, release: IntrinsicRelease, artifact: bundle.Bundle, views: ViewCatalog): SessionSnapshot;
|
package/dist/session/index.d.ts
CHANGED
|
@@ -10,5 +10,6 @@ export { ClientSession, connect, type ConnectOptions } from './session.js';
|
|
|
10
10
|
export type { CallableReference, InputOfReference, InputModeOfReference, InstanceCallableReference, OutputOfReference, } from './reference.js';
|
|
11
11
|
export { reference } from './reference.js';
|
|
12
12
|
export type { DeletedExecutionStatus, ExecutionApi, ExecutionFailure, ExecutionNodeStatus, ExecutionOutcome, ExecutionRef, ExecutionState, ExecutionStatus, ExecutionTarget, ExecutionWait, } from '../execution/index.js';
|
|
13
|
-
export type {
|
|
13
|
+
export type { View, ViewsOf } from './views/index.js';
|
|
14
|
+
export type { ResolvedView, ViewCatalog } from './views/legacy/index.js';
|
|
14
15
|
export type { DomainBinding } from '../graph/domain/index.js';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Key } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
2
1
|
import { acceptCall, Client, dispatchInternal } from '../../client/index.js';
|
|
3
2
|
import { ClientError } from '../../errors/index.js';
|
|
4
3
|
import { runSessionOperation, remainingSessionTime, sessionTransportOptions, allowEndpoint, } from '../context/index.js';
|
|
5
4
|
import { resolveAuth } from './auth.js';
|
|
6
5
|
import { selectEnvelope, selectEnvelopeTarget } from './envelope.js';
|
|
6
|
+
import { releaseRoutesDeclaration } from './legacy/release-route.js';
|
|
7
7
|
import { isRouteCompatibilityConflict, recoveryRefresh, routingControl } from './recovery.js';
|
|
8
8
|
export class SessionDispatcher {
|
|
9
9
|
state;
|
|
@@ -82,7 +82,7 @@ export class SessionDispatcher {
|
|
|
82
82
|
if (redirect.route.via.issuer !== state.source) {
|
|
83
83
|
throw new ClientError('Redirect issuer differs from the session-pinned source Kernel identity.');
|
|
84
84
|
}
|
|
85
|
-
|
|
85
|
+
requireRouteForTarget(redirect.route, state.call.target);
|
|
86
86
|
const learned = await runSessionOperation(operation, () => this.state.cache.learn(state.cacheKey, redirect.route, redirect.credential, state.auth.credential));
|
|
87
87
|
return this.dispatchDestinationWithRecovery(learned, state, options, operation, redirect.trace, streaming);
|
|
88
88
|
}
|
|
@@ -158,15 +158,18 @@ function requireLearnedRoute(learned, source, target) {
|
|
|
158
158
|
if (learned.route.via.issuer !== source) {
|
|
159
159
|
throw new ClientError('Learned route issuer differs from the session-pinned source Kernel.');
|
|
160
160
|
}
|
|
161
|
-
|
|
161
|
+
requireRouteForTarget(learned.route, target);
|
|
162
162
|
}
|
|
163
|
-
|
|
163
|
+
/** A Target names a declaration: only a witness of that declaration routes it. */
|
|
164
|
+
function requireRouteForTarget(route, target) {
|
|
164
165
|
if (typeof target === 'string')
|
|
165
166
|
return;
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
const { via } = route;
|
|
168
|
+
const routes = 'function' in via
|
|
169
|
+
? via.function.declaration === target.callable
|
|
170
|
+
: releaseRoutesDeclaration(via, target.callable);
|
|
171
|
+
if (!routes)
|
|
172
|
+
throw new ClientError('Resolved route does not name the Target declaration.');
|
|
170
173
|
}
|
|
171
174
|
/**
|
|
172
175
|
* Send one call, presenting the Trace only on the attempt that carries it. A call with a body goes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type * as
|
|
1
|
+
import type * as placement from '@astrale-os/kernel-protocol/placement';
|
|
2
2
|
import type { Client } from '../../client/index.js';
|
|
3
3
|
import type { ClientTarget } from '../../pool/index.js';
|
|
4
4
|
import type { SessionPolicy } from '../context/index.js';
|
|
@@ -10,6 +10,6 @@ export interface EnvelopeSelection {
|
|
|
10
10
|
readonly client: Client;
|
|
11
11
|
readonly destination: ClientTarget;
|
|
12
12
|
}
|
|
13
|
-
export declare function selectEnvelope(endpoints:
|
|
13
|
+
export declare function selectEnvelope(endpoints: placement.InvocationEndpoints, preference: SessionEnvelopeTransport, websocketAvailable: boolean, pool: ClientPoolCapability, policy: Readonly<SessionPolicy>): EnvelopeSelection;
|
|
14
14
|
/** Resolve and admit one route endpoint without acquiring a transport Client. */
|
|
15
|
-
export declare function selectEnvelopeTarget(endpoints:
|
|
15
|
+
export declare function selectEnvelopeTarget(endpoints: placement.InvocationEndpoints, preference: SessionEnvelopeTransport, websocketAvailable: boolean, policy: Readonly<SessionPolicy>): ClientTarget;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Kernel routes a declaration by its Release witness while published destinations verify only it
|
|
3
|
+
* (`invocation/legacy/release-via.ts` of the Protocol). That witness names a Release, not the
|
|
4
|
+
* declaration: the Session can only check that the Release is of the origin that declares the
|
|
5
|
+
* Target.
|
|
6
|
+
*
|
|
7
|
+
* Retirement: once no supported Kernel routes a declaration by its Release, delete this folder.
|
|
8
|
+
*/
|
|
9
|
+
import type * as invocation from '@astrale-os/kernel-protocol/invocation';
|
|
10
|
+
import { Key } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
11
|
+
/** @deprecated Whether `via` is the Release witness of the origin that declares `callable`. */
|
|
12
|
+
export declare function releaseRoutesDeclaration(via: invocation.Via, callable: Key.Callable): boolean;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Key } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
2
|
+
import { isReleaseVia } from '@astrale-os/kernel-protocol/invocation';
|
|
3
|
+
/** @deprecated Whether `via` is the Release witness of the origin that declares `callable`. */
|
|
4
|
+
export function releaseRoutesDeclaration(via, callable) {
|
|
5
|
+
return isReleaseVia(via) && via.release.origin === Key.origin(callable);
|
|
6
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IssuerId } from '@astrale-os/kernel-core/auth/issuer';
|
|
2
|
-
import type { PathLike } from '@astrale-os/kernel-core/path';
|
|
2
|
+
import type { NodeTarget, PathLike } from '@astrale-os/kernel-core/path';
|
|
3
3
|
import type { Domain } from '@astrale-os/kernel-dsl/v1/domain';
|
|
4
4
|
import type { AuthApi } from '../auth/index.js';
|
|
5
5
|
import type { Call, Input, Result } from '../client/index.js';
|
|
@@ -13,7 +13,8 @@ import type { IntrinsicRelease, SessionSnapshot } from './discovery/index.js';
|
|
|
13
13
|
import type { SessionExchangeRequest } from './exchange/index.js';
|
|
14
14
|
import type { CallableReference, InputModeOfReference, InputOfReference, OutputOfReference } from './reference.js';
|
|
15
15
|
import type { SessionRequestOptions, SessionRequestOptionsWithBody } from './routing/index.js';
|
|
16
|
-
import type {
|
|
16
|
+
import type { View, ViewsOf } from './views/index.js';
|
|
17
|
+
import type { ViewCatalog } from './views/legacy/index.js';
|
|
17
18
|
import { type ClientSessionOptions } from './options.js';
|
|
18
19
|
export type ConnectOptions = Omit<ClientSessionOptions, 'kernel' | 'policy'> & {
|
|
19
20
|
readonly url: string;
|
|
@@ -36,7 +37,9 @@ export declare class ClientSession {
|
|
|
36
37
|
private readonly routes;
|
|
37
38
|
private readonly exchangeDependencies;
|
|
38
39
|
private readonly callExchange?;
|
|
39
|
-
private readonly
|
|
40
|
+
private readonly viewReader;
|
|
41
|
+
/** The deprecated View.resolve reads: `viewsFor`, and the Views of a Kernel that places none. */
|
|
42
|
+
private readonly resolvedViews;
|
|
40
43
|
private closed;
|
|
41
44
|
constructor(options: ClientSessionOptions);
|
|
42
45
|
/** Bind one admitted DSL Domain to authenticated graph projection and Method dispatch. */
|
|
@@ -53,8 +56,24 @@ export declare class ClientSession {
|
|
|
53
56
|
release(options?: SessionControlOptions): Promise<IntrinsicRelease>;
|
|
54
57
|
snapshot(options?: SessionControlOptions): Promise<SessionSnapshot>;
|
|
55
58
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
59
|
+
* Read one View by any Path, under the caller's own read authority, within one operation budget:
|
|
60
|
+
* its declaration `/:<origin>:view.<name>`, an exact `@<id>` or a traversal, such as the
|
|
61
|
+
* entrypoint `Path.domain(origin).in(K.classes.entrypoint.key)`, whether its Domain declares it or
|
|
62
|
+
* a Mutation created it. A missing or masked Node rejects with NodeUnavailableError, and a Node
|
|
63
|
+
* without a placement is refused.
|
|
64
|
+
*/
|
|
65
|
+
view(target: NodeTarget, options?: SessionControlOptions): Promise<View>;
|
|
66
|
+
/**
|
|
67
|
+
* Read the Views one Domain declares, in Path order, under the caller's own read authority, within
|
|
68
|
+
* one operation budget. The Domain is named by its origin or its exact Domain Path `/:<origin>`;
|
|
69
|
+
* any other Path rejects with a TypeError before the Query.
|
|
70
|
+
*/
|
|
71
|
+
view(of: ViewsOf, options?: SessionControlOptions): Promise<readonly View[]>;
|
|
72
|
+
/**
|
|
73
|
+
* @deprecated Read a Domain's Views with `view({ domain })`, or one View with `view(path)`. This
|
|
74
|
+
* lists them through the deprecated View.resolve, each with the Release digest that owns it, and
|
|
75
|
+
* never names the entrypoint. Only an exact Domain Path `/:<origin>` is accepted; any other Path
|
|
76
|
+
* rejects with a TypeError before the call.
|
|
58
77
|
*/
|
|
59
78
|
viewsFor(domain: PathLike, options?: SessionControlOptions): Promise<ViewCatalog>;
|
|
60
79
|
dispatch(call: Call, options?: SessionRequestOptions): Promise<Result>;
|
package/dist/session/session.js
CHANGED
|
@@ -9,14 +9,15 @@ import { createGraph } from '../graph/index.js';
|
|
|
9
9
|
import { createSchema } from '../schema/index.js';
|
|
10
10
|
import { admitFunction } from './admission.js';
|
|
11
11
|
import { createContentApi } from './content/index.js';
|
|
12
|
-
import { admitControlOptions, allowEndpoint, createSessionOperation } from './context/index.js';
|
|
12
|
+
import { admitControlOptions, allowEndpoint, createSessionOperation, sessionTransportOptions, } from './context/index.js';
|
|
13
13
|
import { createSessionDiscovery } from './discovery/index.js';
|
|
14
14
|
import { attemptDurable, durableOptions } from './durable.js';
|
|
15
15
|
import { acquireDomainCredential, admitExchangeRequest, createSessionExchange, } from './exchange/index.js';
|
|
16
16
|
import { acceptSessionOptions } from './options.js';
|
|
17
17
|
import { admitReference, outputModeOf } from './reference.js';
|
|
18
18
|
import { admitInvocationOptions, requireResultKind, SessionDispatcher } from './routing/index.js';
|
|
19
|
-
import {
|
|
19
|
+
import { admitView } from './views/index.js';
|
|
20
|
+
import { readDomainViewsOrResolved, readViewOrResolved, resolvedViewSource, } from './views/legacy/index.js';
|
|
20
21
|
const DEFAULT_SESSION_POLICY = Object.freeze({ maximumRouteAgeMs: 60_000 });
|
|
21
22
|
/** Caller-owned discovery and redirect-following conversation with one exact source Kernel. */
|
|
22
23
|
export class ClientSession {
|
|
@@ -35,7 +36,9 @@ export class ClientSession {
|
|
|
35
36
|
routes;
|
|
36
37
|
exchangeDependencies;
|
|
37
38
|
callExchange;
|
|
38
|
-
|
|
39
|
+
viewReader;
|
|
40
|
+
/** The deprecated View.resolve reads: `viewsFor`, and the Views of a Kernel that places none. */
|
|
41
|
+
resolvedViews;
|
|
39
42
|
closed = false;
|
|
40
43
|
constructor(options) {
|
|
41
44
|
const settled = acceptSessionOptions(options);
|
|
@@ -45,7 +48,12 @@ export class ClientSession {
|
|
|
45
48
|
this.timeoutMs = settled.timeoutMs;
|
|
46
49
|
this.ownedPool = settled.ownedPool;
|
|
47
50
|
this.routes = settled.routes;
|
|
48
|
-
this.
|
|
51
|
+
this.viewReader = Object.freeze({
|
|
52
|
+
query: (ast, page, operation) => this.graph.query(ast, { ...sessionTransportOptions(operation), page }),
|
|
53
|
+
read: (target, operation) => this.graph.getOrThrow(target, sessionTransportOptions(operation)),
|
|
54
|
+
admit: (node, declaration) => admitView(node, declaration, kernel, policy),
|
|
55
|
+
});
|
|
56
|
+
this.resolvedViews = resolvedViewSource(async (call, operation) => requireResultKind('value', await this.dispatcher.dispatch(call, {}, operation)).value, policy);
|
|
49
57
|
this.discovery = createSessionDiscovery({
|
|
50
58
|
kernel,
|
|
51
59
|
fetch,
|
|
@@ -126,13 +134,22 @@ export class ClientSession {
|
|
|
126
134
|
snapshot(options) {
|
|
127
135
|
return this.discovery.snapshot(this.operation(admitControlOptions(options)));
|
|
128
136
|
}
|
|
137
|
+
view(input, options) {
|
|
138
|
+
this.requireOpen();
|
|
139
|
+
const operation = this.operation(admitControlOptions(options));
|
|
140
|
+
return isViewsOf(input)
|
|
141
|
+
? readDomainViewsOrResolved(this.viewReader, this.resolvedViews.views, input.domain, operation)
|
|
142
|
+
: readViewOrResolved(this.viewReader, this.resolvedViews.views, input, operation);
|
|
143
|
+
}
|
|
129
144
|
/**
|
|
130
|
-
*
|
|
131
|
-
*
|
|
145
|
+
* @deprecated Read a Domain's Views with `view({ domain })`, or one View with `view(path)`. This
|
|
146
|
+
* lists them through the deprecated View.resolve, each with the Release digest that owns it, and
|
|
147
|
+
* never names the entrypoint. Only an exact Domain Path `/:<origin>` is accepted; any other Path
|
|
148
|
+
* rejects with a TypeError before the call.
|
|
132
149
|
*/
|
|
133
150
|
viewsFor(domain, options) {
|
|
134
151
|
this.requireOpen();
|
|
135
|
-
return
|
|
152
|
+
return this.resolvedViews.catalog(domain, this.operation(admitControlOptions(options)));
|
|
136
153
|
}
|
|
137
154
|
dispatch(call, options) {
|
|
138
155
|
return this.dispatchWith(call, options);
|
|
@@ -234,6 +251,13 @@ export class ClientSession {
|
|
|
234
251
|
return createSessionOperation(this.lifecycle.signal, options, this.timeoutMs);
|
|
235
252
|
}
|
|
236
253
|
}
|
|
254
|
+
/**
|
|
255
|
+
* Whether `view` reads a Domain's Views: its input is then a plain `{ domain }` object, while one
|
|
256
|
+
* View is read by a NodeId, a Path value or string, or a DefinitionRef.
|
|
257
|
+
*/
|
|
258
|
+
function isViewsOf(input) {
|
|
259
|
+
return typeof input === 'object' && !(input instanceof Path) && 'domain' in input;
|
|
260
|
+
}
|
|
237
261
|
/** Open a Kernel conversation with secure defaults and automatic Domain exchange when authenticated. */
|
|
238
262
|
export function connect(options) {
|
|
239
263
|
if (options === null || typeof options !== 'object') {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { admitView, admitViewPlacement, declaredView, type Declaration, type View } from './view.js';
|
|
2
|
+
export { readDomainViews, readView, type ViewAnswer, type ViewReader, type ViewsOf, type ViewsQuery, } from './read.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { admitView, admitViewPlacement, declaredView } from './view.js';
|
|
2
|
+
export { readDomainViews, readView, } from './read.js';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** The Kernel `View` Class. */
|
|
2
|
+
export declare const VIEW_CLASS: Readonly<{
|
|
3
|
+
origin: 'kernel.astrale.ai';
|
|
4
|
+
kind: 'class';
|
|
5
|
+
name: "View";
|
|
6
|
+
}>;
|
|
7
|
+
/** The Kernel `of_domain` Edge Class, which only projection writes. */
|
|
8
|
+
export declare const OF_DOMAIN_CLASS: Readonly<{
|
|
9
|
+
origin: 'kernel.astrale.ai';
|
|
10
|
+
kind: 'class';
|
|
11
|
+
name: "of_domain";
|
|
12
|
+
}>;
|
|
13
|
+
/** The Kernel `Domain` Class. */
|
|
14
|
+
export declare const DOMAIN_CLASS: Readonly<{
|
|
15
|
+
origin: 'kernel.astrale.ai';
|
|
16
|
+
kind: 'class';
|
|
17
|
+
name: "Domain";
|
|
18
|
+
}>;
|
|
19
|
+
export declare const VIEW: "kernel.astrale.ai:class.View";
|
|
20
|
+
export declare const OF_DOMAIN: "kernel.astrale.ai:class.of_domain";
|
|
21
|
+
export declare const DOMAIN: "kernel.astrale.ai:class.Domain";
|
|
22
|
+
/** `View.placement`: where and how a Shell mounts the View. */
|
|
23
|
+
export declare const PLACEMENT: "kernel.astrale.ai:class.View.property.placement";
|
|
24
|
+
/** `of_domain.member`: the member name under which a Domain declares the Node. */
|
|
25
|
+
export declare const MEMBER: "kernel.astrale.ai:class.of_domain.property.member";
|
|
26
|
+
/** `Domain.origin`. */
|
|
27
|
+
export declare const ORIGIN: "kernel.astrale.ai:class.Domain.property.origin";
|
|
28
|
+
/** `Descriptable.description`. */
|
|
29
|
+
export declare const DESCRIPTION: "kernel.astrale.ai:class.Descriptable.property.description";
|
|
30
|
+
/** `Identity.iss`. */
|
|
31
|
+
export declare const ISSUER: "kernel.astrale.ai:class.Identity.property.iss";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ClassKey, PropertyKey } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
2
|
+
// The Kernel Classes a View read names, by their coordinates. `K` is built by the DSL builder when
|
|
3
|
+
// its module loads, and the Session must not resolve the Kernel Schema on loading, so these are
|
|
4
|
+
// written out here and the tests hold them equal to `K`.
|
|
5
|
+
function kernelClass(name) {
|
|
6
|
+
return Object.freeze({
|
|
7
|
+
origin: 'kernel.astrale.ai',
|
|
8
|
+
kind: 'class',
|
|
9
|
+
name,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
/** The Kernel `View` Class. */
|
|
13
|
+
export const VIEW_CLASS = kernelClass('View');
|
|
14
|
+
/** The Kernel `of_domain` Edge Class, which only projection writes. */
|
|
15
|
+
export const OF_DOMAIN_CLASS = kernelClass('of_domain');
|
|
16
|
+
/** The Kernel `Domain` Class. */
|
|
17
|
+
export const DOMAIN_CLASS = kernelClass('Domain');
|
|
18
|
+
export const VIEW = ClassKey.of(VIEW_CLASS);
|
|
19
|
+
export const OF_DOMAIN = ClassKey.of(OF_DOMAIN_CLASS);
|
|
20
|
+
export const DOMAIN = ClassKey.of(DOMAIN_CLASS);
|
|
21
|
+
/** `View.placement`: where and how a Shell mounts the View. */
|
|
22
|
+
export const PLACEMENT = PropertyKey.of(VIEW_CLASS, 'placement');
|
|
23
|
+
/** `of_domain.member`: the member name under which a Domain declares the Node. */
|
|
24
|
+
export const MEMBER = PropertyKey.of(OF_DOMAIN_CLASS, 'member');
|
|
25
|
+
/** `Domain.origin`. */
|
|
26
|
+
export const ORIGIN = PropertyKey.of(DOMAIN_CLASS, 'origin');
|
|
27
|
+
/** `Descriptable.description`. */
|
|
28
|
+
export const DESCRIPTION = PropertyKey.of(kernelClass('Descriptable'), 'description');
|
|
29
|
+
/** `Identity.iss`. */
|
|
30
|
+
export const ISSUER = PropertyKey.of(kernelClass('Identity'), 'iss');
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The View catalog before Views carried their placement: `ResolvedView`, keyed by declaration and
|
|
3
|
+
* carrying the Release digest that owns it. `viewsFor` lists it through View.resolve
|
|
4
|
+
* (`resolve.ts`), and `SessionSnapshot.views` joins the source Kernel's Release to its root Schema.
|
|
5
|
+
* A client reads a View from its Node instead, as a `View` (`../view.ts`).
|
|
6
|
+
*/
|
|
7
|
+
import type * as resolution from '@astrale-os/kernel-core/schema/kernel/syscalls/view-resolution';
|
|
8
|
+
import type { bundle } from '@astrale-os/kernel-dsl/v1';
|
|
9
|
+
import type { DomainRelease } from '@astrale-os/kernel-protocol/release';
|
|
10
|
+
import type { SessionPolicy } from '../../context/index.js';
|
|
11
|
+
/** @deprecated One View as View.resolve lists it, with its Release digest; read it as a `View`. */
|
|
12
|
+
export type ResolvedView = resolution.ResolvedView;
|
|
13
|
+
/** @deprecated Immutable canonical-key-ordered inventory of Views; read them with `view`. */
|
|
14
|
+
export interface ViewCatalog {
|
|
15
|
+
readonly entrypoint?: ResolvedView;
|
|
16
|
+
readonly views: readonly ResolvedView[];
|
|
17
|
+
}
|
|
18
|
+
/** @deprecated The `viewsFor` of a bound Session whose source serves none: it throws. */
|
|
19
|
+
export declare function unavailableViewCatalog(): never;
|
|
20
|
+
/** @deprecated Join each root Domain View to its exact release binding. */
|
|
21
|
+
export declare function rootViewCatalog(release: DomainRelease, artifact: bundle.Bundle, policy: Readonly<SessionPolicy>): ViewCatalog;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { acceptViewResolution, } from '@astrale-os/kernel-core/schema/kernel/syscalls/view-resolution';
|
|
2
1
|
import { Key as ViewKey } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
3
|
-
import { ClientError } from '
|
|
4
|
-
import { allowEndpoint } from '
|
|
5
|
-
/**
|
|
2
|
+
import { ClientError } from '../../../errors/index.js';
|
|
3
|
+
import { allowEndpoint } from '../../context/index.js';
|
|
4
|
+
/** @deprecated The `viewsFor` of a bound Session whose source serves none: it throws. */
|
|
5
|
+
export function unavailableViewCatalog() {
|
|
6
|
+
throw new TypeError('The View catalog is unavailable from this bound Session source.');
|
|
7
|
+
}
|
|
8
|
+
/** @deprecated Join each root Domain View to its exact release binding. */
|
|
6
9
|
export function rootViewCatalog(release, artifact, policy) {
|
|
7
10
|
const views = release.bindings.views
|
|
8
11
|
.flatMap((binding) => {
|
|
@@ -38,33 +41,6 @@ export function rootViewCatalog(release, artifact, policy) {
|
|
|
38
41
|
views: catalogViews,
|
|
39
42
|
});
|
|
40
43
|
}
|
|
41
|
-
export function catalogFromKeys(root, keys) {
|
|
42
|
-
const selected = new Set(keys);
|
|
43
|
-
const views = Object.freeze(root.views.filter(({ key }) => selected.has(key)));
|
|
44
|
-
return Object.freeze({
|
|
45
|
-
...(root.entrypoint !== undefined && selected.has(root.entrypoint.key)
|
|
46
|
-
? { entrypoint: root.entrypoint }
|
|
47
|
-
: {}),
|
|
48
|
-
views,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Re-admit one Runtime-resolved Domain View catalog at the Client trust boundary. Only Views that
|
|
53
|
-
* the requested Domain declares for itself are kept.
|
|
54
|
-
*/
|
|
55
|
-
export function domainViewCatalog(input, domain, policy) {
|
|
56
|
-
let resolution;
|
|
57
|
-
try {
|
|
58
|
-
resolution = acceptViewResolution(input);
|
|
59
|
-
}
|
|
60
|
-
catch (cause) {
|
|
61
|
-
throw new ClientError('Resolved View catalog is invalid.', { cause });
|
|
62
|
-
}
|
|
63
|
-
const views = resolution.views.filter((view) => ViewKey.origin(view.key) === domain);
|
|
64
|
-
for (const view of views)
|
|
65
|
-
allowEndpoint(view.href, policy);
|
|
66
|
-
return Object.freeze({ views: Object.freeze(views) });
|
|
67
|
-
}
|
|
68
44
|
function compareKeys(left, right) {
|
|
69
45
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
70
46
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a client keeps only to stay compatible. Every export is deprecated, the Session composes
|
|
3
|
+
* them, and no durable View code imports them.
|
|
4
|
+
*
|
|
5
|
+
* - `unplaced.ts` answers `view` from View.resolve when the Kernel that answers places no View.
|
|
6
|
+
* Delete it, with the `unplaced` answer of `../read.ts` and `ResolvedViewSource.views`, when every
|
|
7
|
+
* Kernel a client may reach places Views.
|
|
8
|
+
* - `catalog.ts` and `resolve.ts` serve `viewsFor` and `SessionSnapshot.views`: the View catalog
|
|
9
|
+
* keyed by declaration, with the Release digest that owns each View. Delete them with those two
|
|
10
|
+
* members, and `resolve.ts` only once `unplaced.ts` is gone too, since it lists through it.
|
|
11
|
+
*/
|
|
12
|
+
export { rootViewCatalog, unavailableViewCatalog, type ResolvedView, type ViewCatalog, } from './catalog.js';
|
|
13
|
+
export { domainViewCatalog, resolvedViews, resolvedViewSource, resolveViewsFor, type ResolvedViews, type ResolvedViewSource, type ViewCatalogAdmission, type ViewInvoker, } from './resolve.js';
|
|
14
|
+
export { readDomainViewsOrResolved, readViewOrResolved } from './unplaced.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a client keeps only to stay compatible. Every export is deprecated, the Session composes
|
|
3
|
+
* them, and no durable View code imports them.
|
|
4
|
+
*
|
|
5
|
+
* - `unplaced.ts` answers `view` from View.resolve when the Kernel that answers places no View.
|
|
6
|
+
* Delete it, with the `unplaced` answer of `../read.ts` and `ResolvedViewSource.views`, when every
|
|
7
|
+
* Kernel a client may reach places Views.
|
|
8
|
+
* - `catalog.ts` and `resolve.ts` serve `viewsFor` and `SessionSnapshot.views`: the View catalog
|
|
9
|
+
* keyed by declaration, with the Release digest that owns each View. Delete them with those two
|
|
10
|
+
* members, and `resolve.ts` only once `unplaced.ts` is gone too, since it lists through it.
|
|
11
|
+
*/
|
|
12
|
+
export { rootViewCatalog, unavailableViewCatalog, } from './catalog.js';
|
|
13
|
+
export { domainViewCatalog, resolvedViews, resolvedViewSource, resolveViewsFor, } from './resolve.js';
|
|
14
|
+
export { readDomainViewsOrResolved, readViewOrResolved } from './unplaced.js';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every read through View.resolve, the one source of a Domain's Views before they carried their
|
|
3
|
+
* placement: the deprecated `viewsFor`, exactly as it listed them, each with the Release digest that
|
|
4
|
+
* owns it, and the same listing as Views for `unplaced.ts`. A Session composes both through
|
|
5
|
+
* `resolvedViewSource`.
|
|
6
|
+
*/
|
|
7
|
+
import type { PathLike } from '@astrale-os/kernel-core/path';
|
|
8
|
+
import type { Key } from '@astrale-os/kernel-dsl/v1';
|
|
9
|
+
import type { Call, Input } from '../../../client/index.js';
|
|
10
|
+
import type { SessionOperation, SessionPolicy } from '../../context/index.js';
|
|
11
|
+
import type { View } from '../view.js';
|
|
12
|
+
import type { ViewCatalog } from './catalog.js';
|
|
13
|
+
/** @deprecated How `viewsFor` sends its View.resolve call. */
|
|
14
|
+
export type ViewInvoker = (call: Call, operation: SessionOperation) => Promise<Input>;
|
|
15
|
+
/** @deprecated How `viewsFor` admits the catalog View.resolve answers for one Domain. */
|
|
16
|
+
export type ViewCatalogAdmission = (input: unknown, domain: Key.Origin) => ViewCatalog;
|
|
17
|
+
/** @deprecated The Views of one Domain as its Kernel's View.resolve lists them. */
|
|
18
|
+
export type ResolvedViews = (domain: Key.Origin, operation: SessionOperation) => Promise<readonly View[]>;
|
|
19
|
+
/** @deprecated What one Session reads through View.resolve. */
|
|
20
|
+
export interface ResolvedViewSource {
|
|
21
|
+
/** The catalog `viewsFor` answers for one exact Domain Path. */
|
|
22
|
+
readonly catalog: (domain: PathLike, operation: SessionOperation) => Promise<ViewCatalog>;
|
|
23
|
+
/** The Views of one Domain, for a Kernel that places none (`unplaced.ts`). */
|
|
24
|
+
readonly views: ResolvedViews;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated The View.resolve reads of one Session: each Call sent by `invoke`, each answer admitted
|
|
28
|
+
* under the Session endpoint policy.
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolvedViewSource(invoke: ViewInvoker, policy: Readonly<SessionPolicy>): ResolvedViewSource;
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Resolve the per-Domain View catalog through the canonical source Kernel call, then
|
|
33
|
+
* admit the Release evidence it answers with. Every View targets its owning Domain, so only an exact
|
|
34
|
+
* Domain Path `/:<origin>` is meaningful; any other Path is refused before the call.
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolveViewsFor(invoke: ViewInvoker, admitCatalog: ViewCatalogAdmission, domain: PathLike, operation: SessionOperation): Promise<ViewCatalog>;
|
|
37
|
+
/**
|
|
38
|
+
* @deprecated Re-admit one Runtime-resolved Domain View catalog at the Client trust boundary. Only
|
|
39
|
+
* Views that the requested Domain declares for itself are kept.
|
|
40
|
+
*/
|
|
41
|
+
export declare function domainViewCatalog(input: unknown, domain: Key.Origin, policy: Readonly<SessionPolicy>): ViewCatalog;
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated The Views View.resolve lists for one Domain, each named by its declaration and
|
|
44
|
+
* answered for by the issuer of the Release that binds it, its Domain's.
|
|
45
|
+
*/
|
|
46
|
+
export declare function resolvedViews(invoke: ViewInvoker, admitCatalog: ViewCatalogAdmission): ResolvedViews;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Path } from '@astrale-os/kernel-core/path';
|
|
2
|
+
import { view } from '@astrale-os/kernel-core/schema/kernel/syscalls/references';
|
|
3
|
+
import { acceptViewResolution, } from '@astrale-os/kernel-core/schema/kernel/syscalls/view-resolution';
|
|
4
|
+
import { Key as ViewKey } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
5
|
+
import { call } from '../../../client/index.js';
|
|
6
|
+
import { ClientError } from '../../../errors/index.js';
|
|
7
|
+
import { allowEndpoint } from '../../context/index.js';
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated The View.resolve reads of one Session: each Call sent by `invoke`, each answer admitted
|
|
10
|
+
* under the Session endpoint policy.
|
|
11
|
+
*/
|
|
12
|
+
export function resolvedViewSource(invoke, policy) {
|
|
13
|
+
const admit = (input, domain) => domainViewCatalog(input, domain, policy);
|
|
14
|
+
return Object.freeze({
|
|
15
|
+
catalog: (domain, operation) => resolveViewsFor(invoke, admit, domain, operation),
|
|
16
|
+
views: resolvedViews(invoke, admit),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Resolve the per-Domain View catalog through the canonical source Kernel call, then
|
|
21
|
+
* admit the Release evidence it answers with. Every View targets its owning Domain, so only an exact
|
|
22
|
+
* Domain Path `/:<origin>` is meaningful; any other Path is refused before the call.
|
|
23
|
+
*/
|
|
24
|
+
export async function resolveViewsFor(invoke, admitCatalog, domain, operation) {
|
|
25
|
+
const origin = domainOrigin(domain);
|
|
26
|
+
const owner = Path.project(view.resolve.owner);
|
|
27
|
+
const resolve = Path.staticMethod(owner, view.resolve.name);
|
|
28
|
+
return admitCatalog(await invoke(call(resolve, { target: Path.domain(origin).raw }), operation), origin);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated Re-admit one Runtime-resolved Domain View catalog at the Client trust boundary. Only
|
|
32
|
+
* Views that the requested Domain declares for itself are kept.
|
|
33
|
+
*/
|
|
34
|
+
export function domainViewCatalog(input, domain, policy) {
|
|
35
|
+
let resolution;
|
|
36
|
+
try {
|
|
37
|
+
resolution = acceptViewResolution(input);
|
|
38
|
+
}
|
|
39
|
+
catch (cause) {
|
|
40
|
+
throw new ClientError('Resolved View catalog is invalid.', { cause });
|
|
41
|
+
}
|
|
42
|
+
const views = resolution.views.filter((view) => ViewKey.origin(view.key) === domain);
|
|
43
|
+
for (const view of views)
|
|
44
|
+
allowEndpoint(view.href, policy);
|
|
45
|
+
return Object.freeze({ views: Object.freeze(views) });
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated The Views View.resolve lists for one Domain, each named by its declaration and
|
|
49
|
+
* answered for by the issuer of the Release that binds it, its Domain's.
|
|
50
|
+
*/
|
|
51
|
+
export function resolvedViews(invoke, admitCatalog) {
|
|
52
|
+
return async (domain, operation) => {
|
|
53
|
+
const { views } = await resolveViewsFor(invoke, admitCatalog, Path.domain(domain), operation);
|
|
54
|
+
return Object.freeze(views.map(viewOf));
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* One View View.resolve listed, as the graph places it. Its Release digest and revision name what
|
|
59
|
+
* owns the View, not where it is mounted, and a View carries neither.
|
|
60
|
+
*/
|
|
61
|
+
function viewOf(resolved) {
|
|
62
|
+
const domain = ViewKey.origin(resolved.key);
|
|
63
|
+
const name = resolved.key.slice(resolved.key.indexOf(':') + 1).slice('view.'.length);
|
|
64
|
+
const { description } = resolved.declaration;
|
|
65
|
+
return Object.freeze({
|
|
66
|
+
path: Path.project({ origin: domain, kind: 'view', name }).raw,
|
|
67
|
+
domain,
|
|
68
|
+
...(description === undefined ? {} : { description }),
|
|
69
|
+
placement: Object.freeze({
|
|
70
|
+
href: resolved.href,
|
|
71
|
+
handshake: resolved.handshake,
|
|
72
|
+
...(resolved.host === undefined ? {} : { host: resolved.host }),
|
|
73
|
+
}),
|
|
74
|
+
issuer: resolved.issuer,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function domainOrigin(input) {
|
|
78
|
+
const { anchor, steps } = Path.from(input).ast;
|
|
79
|
+
if (anchor.kind !== 'domain' || steps.length !== 0) {
|
|
80
|
+
throw new TypeError('View catalog requires a Domain Path /:<origin>; Views never target a Node.');
|
|
81
|
+
}
|
|
82
|
+
return anchor.origin;
|
|
83
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Kernel released before placement keeps no placement on its View Nodes and lists a Domain's
|
|
3
|
+
* Views only through View.resolve. A Release binds every View its Domain declares
|
|
4
|
+
* (`RELEASE_VIEW_INVALID`) and projection places each binding, so a read `../read.ts` answers
|
|
5
|
+
* `unplaced` comes from such a Kernel: these reads answer it from that Kernel's View.resolve, so a
|
|
6
|
+
* Shell built on this client keeps working against a Host not yet upgraded.
|
|
7
|
+
*/
|
|
8
|
+
import type { NodeTarget } from '@astrale-os/kernel-core/path';
|
|
9
|
+
import type { SessionOperation } from '../../context/index.js';
|
|
10
|
+
import type { ViewReader, ViewsOf } from '../read.js';
|
|
11
|
+
import type { View } from '../view.js';
|
|
12
|
+
import type { ResolvedViews } from './resolve.js';
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Read one View from the graph, or, when the graph declares it without a placement, as
|
|
15
|
+
* View.resolve lists it; a View it does not list is refused.
|
|
16
|
+
*/
|
|
17
|
+
export declare function readViewOrResolved(reader: ViewReader, resolved: ResolvedViews, target: NodeTarget, operation: SessionOperation): Promise<View>;
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Read the Views one Domain declares from the graph, or, when the graph places none of
|
|
20
|
+
* them, as View.resolve lists them: in canonical key order, which is their Path order.
|
|
21
|
+
*/
|
|
22
|
+
export declare function readDomainViewsOrResolved(reader: ViewReader, resolved: ResolvedViews, domain: ViewsOf['domain'], operation: SessionOperation): Promise<readonly View[]>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ClientError } from '../../../errors/index.js';
|
|
2
|
+
import { readDomainViews, readView } from '../read.js';
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated Read one View from the graph, or, when the graph declares it without a placement, as
|
|
5
|
+
* View.resolve lists it; a View it does not list is refused.
|
|
6
|
+
*/
|
|
7
|
+
export async function readViewOrResolved(reader, resolved, target, operation) {
|
|
8
|
+
const answer = await readView(reader, target, operation);
|
|
9
|
+
if ('placed' in answer)
|
|
10
|
+
return answer.placed;
|
|
11
|
+
const { path, domain } = answer.unplaced;
|
|
12
|
+
const listed = (await resolved(domain, operation)).find((view) => view.path === path);
|
|
13
|
+
if (listed === undefined)
|
|
14
|
+
throw new ClientError('Node is not a placed View.');
|
|
15
|
+
return listed;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Read the Views one Domain declares from the graph, or, when the graph places none of
|
|
19
|
+
* them, as View.resolve lists them: in canonical key order, which is their Path order.
|
|
20
|
+
*/
|
|
21
|
+
export async function readDomainViewsOrResolved(reader, resolved, domain, operation) {
|
|
22
|
+
const answer = await readDomainViews(reader, domain, operation);
|
|
23
|
+
if ('placed' in answer)
|
|
24
|
+
return answer.placed;
|
|
25
|
+
return resolved(answer.unplaced, operation);
|
|
26
|
+
}
|
|
@@ -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,148 @@
|
|
|
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 { patterns } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
5
|
+
import { ClientError } from '../../errors/index.js';
|
|
6
|
+
import { DOMAIN, MEMBER, OF_DOMAIN, OF_DOMAIN_CLASS, ORIGIN, PLACEMENT, VIEW_CLASS, } from './kernel.js';
|
|
7
|
+
import { declaredView } from './view.js';
|
|
8
|
+
/** Reads of one answer before giving up, the bound View.resolve put on its Registry reads. */
|
|
9
|
+
const ATTEMPTS = 3;
|
|
10
|
+
/** Selected Edges per page: one of_domain Edge per View the Domain declares. */
|
|
11
|
+
const PAGE_SIZE = 100;
|
|
12
|
+
/**
|
|
13
|
+
* Read one View by any Path: an exact `@<id>`, its declaration `/:<origin>:view.<name>`, or a
|
|
14
|
+
* traversal such as `Path.domain(origin).in(K.classes.entrypoint.key)`. One Query selects the
|
|
15
|
+
* of_domain Edge of the View it reaches, which only projection writes: with it, its Domain declares
|
|
16
|
+
* the View; without it, a second read returns the instance. A declared View without a placement
|
|
17
|
+
* is answered `unplaced`, with its Path and Domain.
|
|
18
|
+
*/
|
|
19
|
+
export async function readView(reader, target, operation) {
|
|
20
|
+
const { nodes, edges } = await readCoherent(reader, declarationQuery(target), operation);
|
|
21
|
+
const edge = edges[0];
|
|
22
|
+
if (edge === undefined) {
|
|
23
|
+
return { placed: reader.admit(await reader.read(target, operation), undefined) };
|
|
24
|
+
}
|
|
25
|
+
const view = nodes.find(({ id }) => id === edge.source);
|
|
26
|
+
const domain = nodes.find(({ id }) => id === edge.target);
|
|
27
|
+
if (edges.length !== 1 || edge.class !== OF_DOMAIN || !view || domain?.class !== DOMAIN) {
|
|
28
|
+
throw new ClientError('View answer is invalid.');
|
|
29
|
+
}
|
|
30
|
+
const declaration = Object.freeze({ domain, member: edge.props[MEMBER] });
|
|
31
|
+
if (view.props[PLACEMENT] === undefined)
|
|
32
|
+
return { unplaced: declaredView(declaration) };
|
|
33
|
+
return { placed: reader.admit(view, declaration) };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Read the Views one Domain declares, in Path order, from the graph alone: one Query selects the
|
|
37
|
+
* of_domain Edges of its Views, which the answer closes with their View Nodes and the Domain Node.
|
|
38
|
+
* Only an exact Domain Path `/:<origin>` or an origin is accepted; any other Path is refused before
|
|
39
|
+
* the Query. A caller that may not read them meets the Query's own refusal or an empty list. An
|
|
40
|
+
* answer that locates declared Views and places none of them is answered `unplaced`, with the
|
|
41
|
+
* Domain.
|
|
42
|
+
*/
|
|
43
|
+
export async function readDomainViews(reader, domain, operation) {
|
|
44
|
+
const origin = domainOrigin(domain);
|
|
45
|
+
const located = locateDomainViews(await readCoherent(reader, domainViewsQuery(origin), operation), origin);
|
|
46
|
+
if (located === undefined)
|
|
47
|
+
return { placed: Object.freeze([]) };
|
|
48
|
+
const { owner, members } = located;
|
|
49
|
+
const declarations = [...members].map(([node, member]) => [node, Object.freeze({ domain: owner, member })]);
|
|
50
|
+
const paths = declarations.map(([, declared]) => declaredView(declared).path);
|
|
51
|
+
if (new Set(paths).size !== paths.length) {
|
|
52
|
+
throw new ClientError('Declared View keys are not unique.');
|
|
53
|
+
}
|
|
54
|
+
// Projection places each View the active Release binds. One no binding places has nothing a
|
|
55
|
+
// Shell could mount, and refusing it would let one unplaced View hide every other: it is skipped.
|
|
56
|
+
const placed = declarations.filter(([node]) => node.props[PLACEMENT] !== undefined);
|
|
57
|
+
if (declarations.length > 0 && placed.length === 0)
|
|
58
|
+
return { unplaced: origin };
|
|
59
|
+
const views = placed.map(([node, declared]) => reader.admit(node, declared));
|
|
60
|
+
return { placed: Object.freeze(views.sort((left, right) => compareText(left.path, right.path))) };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Locate the Views of one Domain in one coherent answer, refusing an answer that is not of it. An
|
|
64
|
+
* empty answer is a Domain the caller may not read or that does not exist, as View.resolve
|
|
65
|
+
* answered for a Domain it did not know.
|
|
66
|
+
*/
|
|
67
|
+
function locateDomainViews(graph, domain) {
|
|
68
|
+
const nodes = new Map(graph.nodes.map((node) => [node.id, node]));
|
|
69
|
+
const owner = graph.nodes.find((node) => node.class === DOMAIN);
|
|
70
|
+
if (owner !== undefined && owner.props[ORIGIN] !== domain) {
|
|
71
|
+
throw new ClientError('Domain View answer is not of the requested Domain.');
|
|
72
|
+
}
|
|
73
|
+
const members = new Map();
|
|
74
|
+
for (const edge of graph.edges) {
|
|
75
|
+
const view = nodes.get(edge.source);
|
|
76
|
+
if (edge.target !== owner?.id || view === undefined) {
|
|
77
|
+
throw new ClientError('Domain View answer is not of the requested Domain.');
|
|
78
|
+
}
|
|
79
|
+
if (edge.class !== OF_DOMAIN)
|
|
80
|
+
throw new ClientError('Domain View answer is invalid.');
|
|
81
|
+
members.set(view, edge.props[MEMBER]);
|
|
82
|
+
}
|
|
83
|
+
if (owner === undefined)
|
|
84
|
+
return undefined;
|
|
85
|
+
return Object.freeze({ owner, members });
|
|
86
|
+
}
|
|
87
|
+
/** Read one answer whose pages agree, at most ATTEMPTS times. */
|
|
88
|
+
async function readCoherent(reader, ast, operation) {
|
|
89
|
+
for (let attempt = 0; attempt < ATTEMPTS; attempt++) {
|
|
90
|
+
const graph = await readAnswer(reader, ast, operation);
|
|
91
|
+
if (graph !== undefined)
|
|
92
|
+
return graph;
|
|
93
|
+
}
|
|
94
|
+
throw new ClientError('Views could not be read from one coherent graph.');
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Read every page of one answer, or nothing when its pages disagree. Each page is its own Query
|
|
98
|
+
* and every page carries the target of each selected Edge, so two pages that differ on a Node they
|
|
99
|
+
* share were read from different snapshots: the answer is read again.
|
|
100
|
+
*/
|
|
101
|
+
async function readAnswer(reader, ast, operation) {
|
|
102
|
+
const nodes = new Map();
|
|
103
|
+
const edges = [];
|
|
104
|
+
let after;
|
|
105
|
+
do {
|
|
106
|
+
const { result, page } = await reader.query(ast, after === undefined ? { size: PAGE_SIZE } : { size: PAGE_SIZE, after }, operation);
|
|
107
|
+
if (result.kind !== 'graph' || result.selection.kind !== 'edge') {
|
|
108
|
+
throw new ClientError('View query returned a non-Edge graph result.');
|
|
109
|
+
}
|
|
110
|
+
for (const node of result.graph.nodes) {
|
|
111
|
+
const seen = nodes.get(node.id);
|
|
112
|
+
if (seen === undefined)
|
|
113
|
+
nodes.set(node.id, node);
|
|
114
|
+
else if (seen.class !== node.class || !equal(seen.props, node.props))
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
edges.push(...result.graph.edges);
|
|
118
|
+
after = page.next;
|
|
119
|
+
} while (after !== undefined);
|
|
120
|
+
return Object.freeze({ nodes: Object.freeze([...nodes.values()]), edges: Object.freeze(edges) });
|
|
121
|
+
}
|
|
122
|
+
/** The of_domain Edge from the View a Path reaches to the Domain that declares it, if any. */
|
|
123
|
+
function declarationQuery(target) {
|
|
124
|
+
const declared = Query.from({ nodes: [target] })
|
|
125
|
+
.filter({ class: VIEW_CLASS })
|
|
126
|
+
.expand({ via: [OF_DOMAIN_CLASS], direction: 'outgoing' });
|
|
127
|
+
return declared.select({ kind: 'graph', binding: declared.edge });
|
|
128
|
+
}
|
|
129
|
+
/** The of_domain Edges that reach a Domain from its Views, with both endpoints. */
|
|
130
|
+
function domainViewsQuery(origin) {
|
|
131
|
+
const views = Query.from({ nodes: [Path.domain(origin)] })
|
|
132
|
+
.expand({ via: [OF_DOMAIN_CLASS], direction: 'incoming' })
|
|
133
|
+
.filter({ class: VIEW_CLASS });
|
|
134
|
+
return views.select({ kind: 'graph', binding: views.edge });
|
|
135
|
+
}
|
|
136
|
+
/** The origin of a Domain, named by itself or by its exact Domain Path. */
|
|
137
|
+
function domainOrigin(input) {
|
|
138
|
+
if (typeof input === 'string' && patterns.origin.test(input))
|
|
139
|
+
return input;
|
|
140
|
+
const { anchor, steps } = Path.from(input).ast;
|
|
141
|
+
if (anchor.kind !== 'domain' || steps.length !== 0) {
|
|
142
|
+
throw new TypeError('Domain Views are read for a Domain Path /:<origin> or its origin.');
|
|
143
|
+
}
|
|
144
|
+
return anchor.origin;
|
|
145
|
+
}
|
|
146
|
+
function compareText(left, right) {
|
|
147
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
148
|
+
}
|
|
@@ -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,74 @@
|
|
|
1
|
+
import { issuer, register } from '@astrale-os/kernel-core/auth';
|
|
2
|
+
import { Path } from '@astrale-os/kernel-core/path';
|
|
3
|
+
import { Key as DefinitionKey } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
4
|
+
import { acceptViewPlacement, PlacementError } from '@astrale-os/kernel-protocol/placement';
|
|
5
|
+
import { ClientError } from '../../errors/index.js';
|
|
6
|
+
import { allowEndpoint } from '../context/index.js';
|
|
7
|
+
import { DESCRIPTION, ISSUER, ORIGIN, PLACEMENT, VIEW } from './kernel.js';
|
|
8
|
+
const MEMBER = /^view\.([A-Za-z][A-Za-z0-9_]*)$/u;
|
|
9
|
+
/**
|
|
10
|
+
* Admit one View from its Node, with the Declaration that names it, or none for an instance. The
|
|
11
|
+
* placement passes the Protocol placement codec, which a Release View binding composes, then Session
|
|
12
|
+
* endpoint policy; the client interprets neither its handshake nor its host. The issuer is whoever
|
|
13
|
+
* answers for the View's code: the Domain that declares it, or for an instance its own Identity,
|
|
14
|
+
* self-issued by this Kernel (`register` mode `self`), never its Class Domain nor an external
|
|
15
|
+
* issuer other Identities share.
|
|
16
|
+
*/
|
|
17
|
+
export function admitView(node, declaration, kernel, policy) {
|
|
18
|
+
// A Kernel View Node is declared by projection, which attaches it to its Domain; an instance is
|
|
19
|
+
// a Node of a Domain Class. One read without its of_domain Edge cannot name it.
|
|
20
|
+
if (declaration === undefined && node.class === VIEW) {
|
|
21
|
+
throw new ClientError('The Domain that declares this View is not readable.');
|
|
22
|
+
}
|
|
23
|
+
const value = node.props[PLACEMENT];
|
|
24
|
+
if (value === undefined)
|
|
25
|
+
throw new ClientError('Node is not a placed View.');
|
|
26
|
+
const placement = admitViewPlacement(value, policy);
|
|
27
|
+
const named = declaration === undefined
|
|
28
|
+
? { path: Path.id(node.id).raw, domain: DefinitionKey.origin(node.class) }
|
|
29
|
+
: declaredView(declaration);
|
|
30
|
+
const answerer = declaration === undefined ? selfIssuer(node, kernel) : domainIssuer(declaration);
|
|
31
|
+
const description = node.props[DESCRIPTION];
|
|
32
|
+
return Object.freeze({
|
|
33
|
+
...named,
|
|
34
|
+
...(typeof description === 'string' ? { description } : {}),
|
|
35
|
+
placement,
|
|
36
|
+
...(answerer === undefined ? {} : { issuer: answerer }),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** The Path and Domain of a View its Domain declares, from its Declaration. */
|
|
40
|
+
export function declaredView(declaration) {
|
|
41
|
+
const origin = declaration.domain.props[ORIGIN];
|
|
42
|
+
const name = typeof declaration.member === 'string' ? MEMBER.exec(declaration.member)?.[1] : undefined;
|
|
43
|
+
const key = `${String(origin)}:${String(declaration.member)}`;
|
|
44
|
+
if (typeof origin !== 'string' || name === undefined || !DefinitionKey.is(key)) {
|
|
45
|
+
throw new ClientError('Declared View member is invalid.');
|
|
46
|
+
}
|
|
47
|
+
const domain = DefinitionKey.origin(key);
|
|
48
|
+
return Object.freeze({ path: Path.project({ origin: domain, kind: 'view', name }).raw, domain });
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Admit the placement a View Node carries with the Protocol placement codec, which a Release View
|
|
52
|
+
* binding composes, then Session endpoint policy.
|
|
53
|
+
*/
|
|
54
|
+
export function admitViewPlacement(value, policy) {
|
|
55
|
+
let placement;
|
|
56
|
+
try {
|
|
57
|
+
placement = acceptViewPlacement(value);
|
|
58
|
+
}
|
|
59
|
+
catch (cause) {
|
|
60
|
+
if (!(cause instanceof PlacementError))
|
|
61
|
+
throw cause;
|
|
62
|
+
throw new ClientError('View placement is invalid.', { cause });
|
|
63
|
+
}
|
|
64
|
+
allowEndpoint(placement.href, policy);
|
|
65
|
+
return placement;
|
|
66
|
+
}
|
|
67
|
+
function domainIssuer({ domain }) {
|
|
68
|
+
const served = domain.props[ISSUER];
|
|
69
|
+
return issuer.is(served) ? served : undefined;
|
|
70
|
+
}
|
|
71
|
+
function selfIssuer(node, kernel) {
|
|
72
|
+
const registered = node.props[ISSUER];
|
|
73
|
+
return issuer.is(registered) && register.isSelfIssuer(kernel, registered) ? registered : undefined;
|
|
74
|
+
}
|
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.26",
|
|
4
4
|
"description": "Universal Client — protocol-first, transport-agnostic",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astrale",
|
|
@@ -65,15 +65,16 @@
|
|
|
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.23",
|
|
69
|
+
"@astrale-os/kernel-dsl": "1.0.0-beta.16",
|
|
70
|
+
"@astrale-os/kernel-protocol": "1.0.0-beta.23",
|
|
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.23",
|
|
75
75
|
"@astrale/typescript-config": "npm:@jsr/astrale__typescript-config@~1.1.0",
|
|
76
76
|
"@types/node": "^22.0.0",
|
|
77
|
+
"esbuild": "0.28.1",
|
|
77
78
|
"typescript": "7.0.2",
|
|
78
79
|
"undici": "8.10.0",
|
|
79
80
|
"vitest": "^5.0.1"
|
|
@@ -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
|
-
}
|