@astrale-os/kernel-client 1.0.0-beta.24 → 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.
@@ -21,7 +21,11 @@ export interface ExecutionApi {
21
21
  readonly name: string;
22
22
  readonly value: Value;
23
23
  }, options?: RequestOptions): Promise<void>;
24
- /** A cooperative cancel; `force` kills the run without compensation. */
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>>;
@@ -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
- const callable = Key(output.callable);
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
  }
@@ -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
- viewsFor(domain: Parameters<ClientSession['viewsFor']>[0], options?: SessionControlOptions): Promise<ViewCatalog>;
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
- viewsFor: BoundSessionSource['viewsFor'];
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;
@@ -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 viewsForSource = capture(source, 'viewsFor');
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;
@@ -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 { ResolvedView, ViewCatalog } from './views/index.js';
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
- requireTargetRelease(redirect.route, state.call.target);
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
- requireTargetRelease(learned.route, target);
161
+ requireRouteForTarget(learned.route, target);
162
162
  }
163
- function requireTargetRelease(route, target) {
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 actual = route.via.release;
167
- if (actual.origin !== Key.origin(target.callable)) {
168
- throw new ClientError('Resolved route does not match the Target origin.');
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 release from '@astrale-os/kernel-protocol/release';
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: release.InvocationEndpoints, preference: SessionEnvelopeTransport, websocketAvailable: boolean, pool: ClientPoolCapability, policy: Readonly<SessionPolicy>): EnvelopeSelection;
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: release.InvocationEndpoints, preference: SessionEnvelopeTransport, websocketAvailable: boolean, policy: Readonly<SessionPolicy>): ClientTarget;
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 { ViewCatalog } from './views/index.js';
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 admitDomainViews;
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
- * Resolve the View catalog of one installed Domain. Only an exact Domain Path `/:<origin>` is
57
- * accepted; any other Path rejects with a TypeError before the call.
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>;
@@ -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 { domainViewCatalog, resolveViewsFor } from './views/index.js';
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
- admitDomainViews;
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.admitDomainViews = (input, domain) => domainViewCatalog(input, domain, policy);
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
- * Resolve the View catalog of one installed Domain. Only an exact Domain Path `/:<origin>` is
131
- * accepted; any other Path rejects with a TypeError before the call.
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 resolveViewsFor(async (call, operation) => requireResultKind('value', await this.dispatcher.dispatch(call, {}, operation)).value, this.admitDomainViews, domain, this.operation(admitControlOptions(options)));
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 { catalogFromKeys, domainViewCatalog, rootViewCatalog, type ResolvedView, type ViewCatalog, } from './catalog.js';
2
- export { resolveViewsFor, type ViewCatalogAdmission, type ViewInvoker } from './resolve.js';
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 { catalogFromKeys, domainViewCatalog, rootViewCatalog, } from './catalog.js';
2
- export { resolveViewsFor } from './resolve.js';
1
+ export { admitView, admitViewPlacement, declaredView } from './view.js';
2
+ export { readDomainViews, readView, } from './read.js';
@@ -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 '../../errors/index.js';
4
- import { allowEndpoint } from '../context/index.js';
5
- /** Join each root Domain View to its exact release binding. */
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,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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrale-os/kernel-client",
3
- "version": "1.0.0-beta.24",
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.21",
69
- "@astrale-os/kernel-dsl": "1.0.0-beta.14",
70
- "@astrale-os/kernel-protocol": "1.0.0-beta.21",
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.21",
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
- }