@astrale-os/kernel-client 1.0.0-beta.4 → 1.0.0-beta.41

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.
Files changed (194) hide show
  1. package/dist/auth/index.d.ts +1 -0
  2. package/dist/client/admission.js +3 -1
  3. package/dist/client/client.d.ts +19 -2
  4. package/dist/client/client.js +62 -30
  5. package/dist/client/index.d.ts +3 -3
  6. package/dist/client/index.js +2 -2
  7. package/dist/client/request.d.ts +8 -2
  8. package/dist/client/request.js +28 -7
  9. package/dist/client/result.d.ts +10 -1
  10. package/dist/client/result.js +10 -4
  11. package/dist/client/routing-control.d.ts +11 -15
  12. package/dist/client/routing-control.js +21 -29
  13. package/dist/errors/index.d.ts +3 -0
  14. package/dist/errors/index.js +3 -0
  15. package/dist/errors/query-input.d.ts +47 -0
  16. package/dist/errors/query-input.js +85 -0
  17. package/dist/errors/refusal.d.ts +24 -0
  18. package/dist/errors/refusal.js +78 -0
  19. package/dist/errors/response-too-large-error.d.ts +11 -0
  20. package/dist/errors/response-too-large-error.js +15 -0
  21. package/dist/errors/stale-route-error.d.ts +1 -1
  22. package/dist/errors/stale-route-error.js +1 -1
  23. package/dist/{schema → execution}/admission.d.ts +2 -2
  24. package/dist/{schema → execution}/admission.js +3 -3
  25. package/dist/execution/contracts.d.ts +76 -0
  26. package/dist/execution/contracts.js +1 -0
  27. package/dist/execution/deadline.d.ts +18 -0
  28. package/dist/execution/deadline.js +25 -0
  29. package/dist/execution/execution.d.ts +61 -0
  30. package/dist/execution/execution.js +132 -0
  31. package/dist/execution/index.d.ts +4 -0
  32. package/dist/execution/index.js +3 -0
  33. package/dist/graph/domain/binding.d.ts +2 -2
  34. package/dist/graph/domain/binding.js +24 -17
  35. package/dist/graph/domain/conformance.d.ts +12 -0
  36. package/dist/graph/domain/conformance.js +18 -0
  37. package/dist/graph/domain/index.d.ts +1 -0
  38. package/dist/graph/domain/index.js +1 -1
  39. package/dist/graph/domain/provenance.d.ts +0 -2
  40. package/dist/graph/domain/provenance.js +0 -4
  41. package/dist/graph/graph.d.ts +17 -3
  42. package/dist/graph/graph.js +4 -1
  43. package/dist/graph/index.d.ts +3 -3
  44. package/dist/graph/index.js +1 -1
  45. package/dist/graph/page-contract.d.ts +66 -1
  46. package/dist/graph/provenance.d.ts +4 -5
  47. package/dist/graph/provenance.js +5 -6
  48. package/dist/graph/query.d.ts +10 -4
  49. package/dist/graph/query.js +149 -7
  50. package/dist/graph/query.typecheck.d.ts +79 -0
  51. package/dist/graph/query.typecheck.js +34 -0
  52. package/dist/pacer/index.d.ts +1 -1
  53. package/dist/pacer/index.js +1 -1
  54. package/dist/pacer/retry/index.d.ts +1 -0
  55. package/dist/pacer/retry/index.js +1 -0
  56. package/dist/pacer/retry/refusals.d.ts +7 -0
  57. package/dist/pacer/retry/refusals.js +10 -0
  58. package/dist/pacer/retry/retry.d.ts +2 -0
  59. package/dist/pacer/retry/retry.js +33 -1
  60. package/dist/schema/contracts.d.ts +77 -9
  61. package/dist/schema/index.d.ts +3 -2
  62. package/dist/schema/index.js +1 -1
  63. package/dist/schema/installation.d.ts +76 -0
  64. package/dist/schema/installation.js +82 -0
  65. package/dist/schema/schema.d.ts +22 -13
  66. package/dist/schema/schema.js +67 -48
  67. package/dist/session/admission.js +10 -3
  68. package/dist/session/bound.d.ts +12 -3
  69. package/dist/session/bound.js +66 -20
  70. package/dist/session/content/api.d.ts +20 -2
  71. package/dist/session/content/api.js +17 -7
  72. package/dist/session/content/files.d.ts +12 -0
  73. package/dist/session/content/files.js +47 -0
  74. package/dist/session/content/index.d.ts +1 -1
  75. package/dist/session/content/input.d.ts +13 -2
  76. package/dist/session/content/input.js +25 -4
  77. package/dist/session/content/retry.d.ts +5 -1
  78. package/dist/session/content/retry.js +21 -31
  79. package/dist/session/context/index.d.ts +1 -1
  80. package/dist/session/context/index.js +1 -1
  81. package/dist/session/context/operation.d.ts +2 -0
  82. package/dist/session/context/operation.js +5 -0
  83. package/dist/session/credential/credentials.js +43 -28
  84. package/dist/session/discovery/bundle.d.ts +9 -4
  85. package/dist/session/discovery/bundle.js +28 -35
  86. package/dist/session/discovery/discovery.d.ts +1 -1
  87. package/dist/session/discovery/discovery.js +8 -11
  88. package/dist/session/discovery/release.js +18 -28
  89. package/dist/session/discovery/snapshot.d.ts +5 -1
  90. package/dist/session/discovery/transport.d.ts +35 -3
  91. package/dist/session/discovery/transport.js +40 -1
  92. package/dist/session/durable.d.ts +13 -0
  93. package/dist/session/durable.js +39 -0
  94. package/dist/session/exchange/exchange.d.ts +3 -2
  95. package/dist/session/exchange/exchange.js +10 -7
  96. package/dist/session/exchange/index.d.ts +1 -1
  97. package/dist/session/exchange/index.js +1 -1
  98. package/dist/session/exchange/presentation.js +28 -10
  99. package/dist/session/exchange/source.d.ts +7 -7
  100. package/dist/session/exchange/source.js +26 -27
  101. package/dist/session/index.d.ts +5 -4
  102. package/dist/session/index.js +0 -1
  103. package/dist/session/options.d.ts +0 -2
  104. package/dist/session/options.js +0 -3
  105. package/dist/session/reference.d.ts +27 -6
  106. package/dist/session/reference.js +18 -3
  107. package/dist/session/retry.d.ts +12 -0
  108. package/dist/session/retry.js +23 -0
  109. package/dist/session/routing/auth.d.ts +9 -3
  110. package/dist/session/routing/auth.js +4 -3
  111. package/dist/session/routing/cache.d.ts +12 -5
  112. package/dist/session/routing/cache.js +56 -48
  113. package/dist/session/routing/dispatch.d.ts +26 -3
  114. package/dist/session/routing/dispatch.js +112 -67
  115. package/dist/session/routing/envelope.d.ts +3 -3
  116. package/dist/session/routing/index.d.ts +1 -1
  117. package/dist/session/routing/legacy/release-route.d.ts +12 -0
  118. package/dist/session/routing/legacy/release-route.js +6 -0
  119. package/dist/session/routing/recovery.d.ts +3 -6
  120. package/dist/session/routing/recovery.js +3 -14
  121. package/dist/session/routing/request.d.ts +6 -1
  122. package/dist/session/routing/request.js +13 -2
  123. package/dist/session/routing/result.d.ts +1 -1
  124. package/dist/session/routing/result.js +5 -1
  125. package/dist/session/routing/store.js +4 -5
  126. package/dist/session/session.d.ts +31 -5
  127. package/dist/session/session.js +67 -20
  128. package/dist/session/session.typecheck.js +20 -6
  129. package/dist/session/views/index.d.ts +2 -2
  130. package/dist/session/views/index.js +2 -2
  131. package/dist/session/views/kernel.d.ts +31 -0
  132. package/dist/session/views/kernel.js +30 -0
  133. package/dist/session/views/legacy/catalog.d.ts +21 -0
  134. package/dist/session/views/{catalog.js → legacy/catalog.js} +7 -31
  135. package/dist/session/views/legacy/index.d.ts +14 -0
  136. package/dist/session/views/legacy/index.js +14 -0
  137. package/dist/session/views/legacy/resolve.d.ts +46 -0
  138. package/dist/session/views/legacy/resolve.js +83 -0
  139. package/dist/session/views/legacy/unplaced.d.ts +22 -0
  140. package/dist/session/views/legacy/unplaced.js +26 -0
  141. package/dist/session/views/read.d.ts +49 -0
  142. package/dist/session/views/read.js +148 -0
  143. package/dist/session/views/view.d.ts +48 -0
  144. package/dist/session/views/view.js +74 -0
  145. package/dist/store/memory.d.ts +1 -3
  146. package/dist/store/memory.js +73 -105
  147. package/dist/store/shape.d.ts +33 -12
  148. package/dist/store/shape.js +125 -16
  149. package/dist/store/store.d.ts +6 -6
  150. package/dist/store/store.js +1 -1
  151. package/dist/transport/auto/decision.d.ts +26 -14
  152. package/dist/transport/auto/decision.js +35 -32
  153. package/dist/transport/auto/fallback.d.ts +1 -1
  154. package/dist/transport/auto/fallback.js +5 -10
  155. package/dist/transport/auto/transport.d.ts +0 -2
  156. package/dist/transport/auto/transport.js +24 -32
  157. package/dist/transport/deadline.d.ts +2 -0
  158. package/dist/transport/deadline.js +18 -0
  159. package/dist/transport/failure.d.ts +28 -1
  160. package/dist/transport/failure.js +63 -1
  161. package/dist/transport/http/admission.js +7 -34
  162. package/dist/transport/http/binary-request.d.ts +44 -0
  163. package/dist/transport/http/binary-request.js +110 -0
  164. package/dist/transport/http/binary.js +3 -3
  165. package/dist/transport/http/byte-stream.d.ts +2 -1
  166. package/dist/transport/http/byte-stream.js +12 -8
  167. package/dist/transport/http/index.d.ts +1 -1
  168. package/dist/transport/http/index.js +1 -1
  169. package/dist/transport/http/response.d.ts +3 -1
  170. package/dist/transport/http/response.js +7 -9
  171. package/dist/transport/http/stream.d.ts +8 -13
  172. package/dist/transport/http/stream.js +34 -81
  173. package/dist/transport/http/transport.d.ts +10 -0
  174. package/dist/transport/http/transport.js +87 -32
  175. package/dist/transport/http/unprocessed.d.ts +5 -0
  176. package/dist/transport/http/unprocessed.js +28 -0
  177. package/dist/transport/index.d.ts +1 -1
  178. package/dist/transport/index.js +1 -1
  179. package/dist/transport/stream.d.ts +52 -0
  180. package/dist/transport/stream.js +101 -0
  181. package/dist/transport/transport.d.ts +10 -0
  182. package/dist/transport/unary.d.ts +8 -0
  183. package/dist/transport/unary.js +34 -0
  184. package/dist/transport/websocket/connection.d.ts +7 -3
  185. package/dist/transport/websocket/connection.js +103 -92
  186. package/dist/transport/websocket/exchange.d.ts +12 -19
  187. package/dist/transport/websocket/exchange.js +86 -184
  188. package/dist/transport/websocket/transport.js +11 -19
  189. package/package.json +9 -7
  190. package/dist/session/execution.d.ts +0 -65
  191. package/dist/session/execution.js +0 -34
  192. package/dist/session/views/catalog.d.ts +0 -19
  193. package/dist/session/views/resolve.d.ts +0 -13
  194. package/dist/session/views/resolve.js +0 -21
@@ -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
+ }
@@ -34,15 +34,13 @@ export declare class GraphMemory {
34
34
  optimistic(): void;
35
35
  settleOptimistic(): void;
36
36
  sweep(): void;
37
+ private rematerialize;
37
38
  private releaseExpired;
38
39
  private evictLeastRecentlyUsed;
39
- private releasable;
40
- private touch;
41
40
  private sweepEntities;
42
41
  close(error: ClientError): void;
43
42
  private materialize;
44
43
  private materializeResult;
45
- private publish;
46
44
  private schedule;
47
45
  private drain;
48
46
  private report;