@astrale-os/kernel-client 1.0.0-beta.3 → 1.0.0-beta.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) 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 +19 -0
  18. package/dist/errors/refusal.js +63 -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 +64 -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 +145 -7
  50. package/dist/graph/query.typecheck.d.ts +77 -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 +10 -2
  71. package/dist/session/content/api.js +13 -4
  72. package/dist/session/content/index.d.ts +1 -1
  73. package/dist/session/content/input.d.ts +6 -1
  74. package/dist/session/content/input.js +12 -4
  75. package/dist/session/content/retry.d.ts +5 -1
  76. package/dist/session/content/retry.js +21 -31
  77. package/dist/session/context/index.d.ts +1 -1
  78. package/dist/session/context/index.js +1 -1
  79. package/dist/session/context/operation.d.ts +2 -0
  80. package/dist/session/context/operation.js +5 -0
  81. package/dist/session/credential/credentials.js +43 -28
  82. package/dist/session/discovery/bundle.d.ts +9 -4
  83. package/dist/session/discovery/bundle.js +28 -35
  84. package/dist/session/discovery/discovery.d.ts +1 -1
  85. package/dist/session/discovery/discovery.js +8 -11
  86. package/dist/session/discovery/release.js +18 -28
  87. package/dist/session/discovery/snapshot.d.ts +5 -1
  88. package/dist/session/discovery/transport.d.ts +35 -3
  89. package/dist/session/discovery/transport.js +40 -1
  90. package/dist/session/durable.d.ts +13 -0
  91. package/dist/session/durable.js +39 -0
  92. package/dist/session/exchange/exchange.d.ts +3 -2
  93. package/dist/session/exchange/exchange.js +10 -7
  94. package/dist/session/exchange/index.d.ts +1 -1
  95. package/dist/session/exchange/index.js +1 -1
  96. package/dist/session/exchange/presentation.js +28 -10
  97. package/dist/session/exchange/source.d.ts +7 -7
  98. package/dist/session/exchange/source.js +26 -27
  99. package/dist/session/index.d.ts +4 -3
  100. package/dist/session/index.js +0 -1
  101. package/dist/session/options.d.ts +0 -2
  102. package/dist/session/options.js +0 -3
  103. package/dist/session/reference.d.ts +9 -5
  104. package/dist/session/reference.js +7 -2
  105. package/dist/session/retry.d.ts +12 -0
  106. package/dist/session/retry.js +23 -0
  107. package/dist/session/routing/auth.d.ts +9 -3
  108. package/dist/session/routing/auth.js +4 -3
  109. package/dist/session/routing/cache.d.ts +12 -5
  110. package/dist/session/routing/cache.js +56 -48
  111. package/dist/session/routing/dispatch.d.ts +26 -3
  112. package/dist/session/routing/dispatch.js +112 -67
  113. package/dist/session/routing/envelope.d.ts +3 -3
  114. package/dist/session/routing/index.d.ts +1 -1
  115. package/dist/session/routing/legacy/release-route.d.ts +12 -0
  116. package/dist/session/routing/legacy/release-route.js +6 -0
  117. package/dist/session/routing/recovery.d.ts +3 -6
  118. package/dist/session/routing/recovery.js +3 -14
  119. package/dist/session/routing/request.d.ts +6 -1
  120. package/dist/session/routing/request.js +13 -2
  121. package/dist/session/routing/result.d.ts +1 -1
  122. package/dist/session/routing/result.js +5 -1
  123. package/dist/session/routing/store.js +4 -5
  124. package/dist/session/session.d.ts +31 -5
  125. package/dist/session/session.js +60 -19
  126. package/dist/session/session.typecheck.js +20 -6
  127. package/dist/session/views/index.d.ts +2 -2
  128. package/dist/session/views/index.js +2 -2
  129. package/dist/session/views/kernel.d.ts +31 -0
  130. package/dist/session/views/kernel.js +30 -0
  131. package/dist/session/views/legacy/catalog.d.ts +21 -0
  132. package/dist/session/views/{catalog.js → legacy/catalog.js} +7 -31
  133. package/dist/session/views/legacy/index.d.ts +14 -0
  134. package/dist/session/views/legacy/index.js +14 -0
  135. package/dist/session/views/legacy/resolve.d.ts +46 -0
  136. package/dist/session/views/legacy/resolve.js +83 -0
  137. package/dist/session/views/legacy/unplaced.d.ts +22 -0
  138. package/dist/session/views/legacy/unplaced.js +26 -0
  139. package/dist/session/views/read.d.ts +49 -0
  140. package/dist/session/views/read.js +148 -0
  141. package/dist/session/views/view.d.ts +48 -0
  142. package/dist/session/views/view.js +74 -0
  143. package/dist/store/memory.d.ts +1 -3
  144. package/dist/store/memory.js +73 -105
  145. package/dist/store/shape.d.ts +33 -12
  146. package/dist/store/shape.js +125 -16
  147. package/dist/store/store.d.ts +6 -6
  148. package/dist/store/store.js +1 -1
  149. package/dist/transport/auto/decision.d.ts +26 -14
  150. package/dist/transport/auto/decision.js +35 -32
  151. package/dist/transport/auto/fallback.d.ts +1 -1
  152. package/dist/transport/auto/fallback.js +5 -10
  153. package/dist/transport/auto/transport.d.ts +0 -2
  154. package/dist/transport/auto/transport.js +24 -32
  155. package/dist/transport/deadline.d.ts +2 -0
  156. package/dist/transport/deadline.js +18 -0
  157. package/dist/transport/failure.d.ts +28 -1
  158. package/dist/transport/failure.js +63 -1
  159. package/dist/transport/http/admission.js +7 -34
  160. package/dist/transport/http/binary-request.d.ts +44 -0
  161. package/dist/transport/http/binary-request.js +110 -0
  162. package/dist/transport/http/binary.js +3 -3
  163. package/dist/transport/http/byte-stream.d.ts +2 -1
  164. package/dist/transport/http/byte-stream.js +12 -8
  165. package/dist/transport/http/index.d.ts +1 -1
  166. package/dist/transport/http/index.js +1 -1
  167. package/dist/transport/http/response.d.ts +3 -1
  168. package/dist/transport/http/response.js +7 -9
  169. package/dist/transport/http/stream.d.ts +8 -13
  170. package/dist/transport/http/stream.js +34 -81
  171. package/dist/transport/http/transport.d.ts +10 -0
  172. package/dist/transport/http/transport.js +87 -32
  173. package/dist/transport/http/unprocessed.d.ts +5 -0
  174. package/dist/transport/http/unprocessed.js +28 -0
  175. package/dist/transport/index.d.ts +1 -1
  176. package/dist/transport/index.js +1 -1
  177. package/dist/transport/stream.d.ts +52 -0
  178. package/dist/transport/stream.js +101 -0
  179. package/dist/transport/transport.d.ts +10 -0
  180. package/dist/transport/unary.d.ts +8 -0
  181. package/dist/transport/unary.js +34 -0
  182. package/dist/transport/websocket/connection.d.ts +7 -3
  183. package/dist/transport/websocket/connection.js +103 -92
  184. package/dist/transport/websocket/exchange.d.ts +12 -19
  185. package/dist/transport/websocket/exchange.js +86 -184
  186. package/dist/transport/websocket/transport.js +11 -19
  187. package/package.json +7 -5
  188. package/dist/session/execution.d.ts +0 -65
  189. package/dist/session/execution.js +0 -34
  190. package/dist/session/views/catalog.d.ts +0 -19
  191. package/dist/session/views/resolve.d.ts +0 -13
  192. package/dist/session/views/resolve.js +0 -21
@@ -3,23 +3,28 @@ import { callableFingerprint } from '@astrale-os/kernel-dsl/v1/schema/fingerprin
3
3
  import { createAuth } from '../auth/auth.js';
4
4
  import { acceptCall } from '../client/index.js';
5
5
  import { SessionError } from '../errors/index.js';
6
+ import { createExecution } from '../execution/index.js';
6
7
  import { createDomainBinding } from '../graph/domain/binding.js';
7
8
  import { createGraph } from '../graph/index.js';
8
9
  import { createSchema } from '../schema/index.js';
9
10
  import { admitFunction } from './admission.js';
10
11
  import { createContentApi } from './content/index.js';
11
- import { admitControlOptions, allowEndpoint, createSessionOperation } from './context/index.js';
12
+ import { admitControlOptions, allowEndpoint, createSessionOperation, sessionTransportOptions, } from './context/index.js';
12
13
  import { createSessionDiscovery } from './discovery/index.js';
14
+ import { attemptDurable, durableOptions } from './durable.js';
13
15
  import { acquireDomainCredential, admitExchangeRequest, createSessionExchange, } from './exchange/index.js';
14
16
  import { acceptSessionOptions } from './options.js';
15
- import { admitReference } from './reference.js';
17
+ import { admitReference, outputModeOf } from './reference.js';
16
18
  import { admitInvocationOptions, requireResultKind, SessionDispatcher } from './routing/index.js';
17
- import { domainViewCatalog, resolveViewsFor } from './views/index.js';
19
+ import { admitView } from './views/index.js';
20
+ import { readDomainViewsOrResolved, readViewOrResolved, resolvedViewSource, } from './views/legacy/index.js';
18
21
  const DEFAULT_SESSION_POLICY = Object.freeze({ maximumRouteAgeMs: 60_000 });
19
22
  /** Caller-owned discovery and redirect-following conversation with one exact source Kernel. */
20
23
  export class ClientSession {
21
24
  kernel;
22
25
  schema;
26
+ /** The `K.Execution` Methods of any Execution, a durable call's or an install's. */
27
+ execution;
23
28
  graph;
24
29
  auth;
25
30
  content;
@@ -31,7 +36,9 @@ export class ClientSession {
31
36
  routes;
32
37
  exchangeDependencies;
33
38
  callExchange;
34
- admitDomainViews;
39
+ viewReader;
40
+ /** The deprecated View.resolve reads: `viewsFor`, and the Views of a Kernel that places none. */
41
+ resolvedViews;
35
42
  closed = false;
36
43
  constructor(options) {
37
44
  const settled = acceptSessionOptions(options);
@@ -41,7 +48,12 @@ export class ClientSession {
41
48
  this.timeoutMs = settled.timeoutMs;
42
49
  this.ownedPool = settled.ownedPool;
43
50
  this.routes = settled.routes;
44
- 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);
45
57
  this.discovery = createSessionDiscovery({
46
58
  kernel,
47
59
  fetch,
@@ -92,8 +104,8 @@ export class ClientSession {
92
104
  this.schema = createSchema((request, options) => this.dispatch(request, options), {
93
105
  maximumReleaseBytes,
94
106
  maximumBundleBytes,
95
- lifecycleTimeoutMs: settled.schemaLifecycleTimeoutMs,
96
107
  });
108
+ this.execution = createExecution((request, options) => this.dispatch(request, options));
97
109
  this.graph = createGraph((call, options) => this.call(call, options));
98
110
  this.auth = createAuth((target, input, options) => this.call({ target, input }, options), (call, options) => {
99
111
  const operation = this.operation(admitControlOptions(options));
@@ -122,13 +134,22 @@ export class ClientSession {
122
134
  snapshot(options) {
123
135
  return this.discovery.snapshot(this.operation(admitControlOptions(options)));
124
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
+ }
125
144
  /**
126
- * Resolve the View catalog of one installed Domain. Only an exact Domain Path `/:<origin>` is
127
- * 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.
128
149
  */
129
150
  viewsFor(domain, options) {
130
151
  this.requireOpen();
131
- 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)));
132
153
  }
133
154
  dispatch(call, options) {
134
155
  return this.dispatchWith(call, options);
@@ -157,16 +178,29 @@ export class ClientSession {
157
178
  }),
158
179
  input,
159
180
  };
160
- const operation = this.operation(admitted.options);
161
- const result = await (admitted.body === undefined && admittedReference.outputMode !== 'binary'
162
- ? this.dispatcher.dispatch(call, admitted.options, operation)
163
- : this.dispatcher.dispatchHttp(call, admitted.options, operation, admitted.body));
181
+ // A durable call is keyed, so an attempt whose outcome is unknown can be sent again.
182
+ const durable = admittedReference.outputMode === 'execution';
183
+ const requested = durable ? durableOptions(admitted.options) : admitted.options;
184
+ const operation = this.operation(requested);
185
+ const streaming = admitted.body === undefined && admittedReference.outputMode !== 'binary'
186
+ ? undefined
187
+ : { body: admitted.body };
188
+ // Resolved once: every attempt presents the principal and caller its key names an Execution with.
189
+ const resolved = await this.dispatcher.resolve(call, operation);
190
+ const attempt = () => this.dispatcher.dispatchResolved(resolved, requested, operation, streaming);
191
+ const result = await (durable ? attemptDurable(operation, attempt) : attempt());
164
192
  const narrowed = requireResultKind(admittedReference.outputMode, result);
165
- return narrowed.kind === 'value'
166
- ? narrowed.value
167
- : narrowed.kind === 'stream'
168
- ? narrowed.stream
169
- : narrowed.value;
193
+ switch (narrowed.kind) {
194
+ case 'stream':
195
+ return narrowed.stream;
196
+ case 'execution':
197
+ return Object.freeze({
198
+ id: narrowed.execution,
199
+ ...(narrowed.replayed === undefined ? {} : { replayed: narrowed.replayed }),
200
+ });
201
+ default:
202
+ return narrowed.value;
203
+ }
170
204
  }
171
205
  dispatchWith(call, options, requireHttp = false) {
172
206
  const admitted = admitInvocationOptions(options);
@@ -209,7 +243,7 @@ export class ClientSession {
209
243
  fingerprint: callableFingerprint(method),
210
244
  callable: method.key,
211
245
  target: Path.instanceMethod(Path.id(node.id), method.key),
212
- outputMode: method.output.mode,
246
+ outputMode: outputModeOf(method),
213
247
  }, input);
214
248
  }
215
249
  operation(options) {
@@ -217,6 +251,13 @@ export class ClientSession {
217
251
  return createSessionOperation(this.lifecycle.signal, options, this.timeoutMs);
218
252
  }
219
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
+ }
220
261
  /** Open a Kernel conversation with secure defaults and automatic Domain exchange when authenticated. */
221
262
  export function connect(options) {
222
263
  if (options === null || typeof options !== 'object') {
@@ -4,7 +4,7 @@ import { K, KernelSchema } from '@astrale-os/kernel-core/schema';
4
4
  import { defineSchema, func, method, nodeClass, schema, valueSchema, } from '@astrale-os/kernel-dsl/v1';
5
5
  import { isBinaryInput } from '@astrale-os/kernel-dsl/v1/language';
6
6
  import { call } from '../client/index.js';
7
- import { ClientSession, credentials, execution, reference } from './index.js';
7
+ import { ClientSession, credentials, reference } from './index.js';
8
8
  void new ClientSession(options);
9
9
  void auth;
10
10
  void control;
@@ -110,6 +110,10 @@ const boundBlobReceipt = boundSession.content
110
110
  .then(({ receipt }) => receipt);
111
111
  void blobReceipt;
112
112
  void boundBlobReceipt;
113
+ void session.content.upload(received, { mediaType: 'image/png' });
114
+ void boundSession.content.upload({ body: new ReadableStream(), length: 0 }, { mediaType: 'image/png' });
115
+ // @ts-expect-error A stream upload declares its exact length.
116
+ void session.content.upload({ body: new ReadableStream() }, { mediaType: 'image/png' });
113
117
  void session.invoke(registerReference, registration);
114
118
  void boundSession.invoke(staticRegisterReference, registration);
115
119
  void session.invoke(renameReference, renameRequest);
@@ -121,6 +125,12 @@ void client.dispatch(rawBinaryCall, { body: new Blob() });
121
125
  void client.as('credential').call(rawBinaryCall, { body: new Blob() });
122
126
  // @ts-expect-error Binary Functions require a byte source.
123
127
  void session.invoke(binaryUploadReference, { mediaType: 'image/png' });
128
+ // @ts-expect-error A Session invocation sends a re-readable Blob: it may follow a Redirect.
129
+ void session.invoke(binaryUploadReference, { mediaType: 'image/png' }, { body: received });
130
+ // @ts-expect-error A raw Client sends a re-readable Blob: it cannot resend a stream a Redirect answers.
131
+ void client.dispatch(rawBinaryCall, { body: received });
132
+ // @ts-expect-error The public HTTP transport sends a re-readable Blob too.
133
+ void httpTransport.dispatchBinary(rawEnvelope, received);
124
134
  // @ts-expect-error Value Functions reject binary bodies.
125
135
  void session.invoke(registerReference, registration, { body: new Blob() });
126
136
  // @ts-expect-error Bound binary Functions require a byte source.
@@ -189,12 +199,13 @@ const durableDomain = schema.resolve(defineSchema('client.durable.typecheck', {
189
199
  }));
190
200
  const remindReference = reference(durableDomain, durableDomain.classes.Invoice.methods.remind)(Path.id(NodeId('invoice-1')));
191
201
  const durableReturnsExecution = true;
202
+ const outcome = session.execution.result(run, { waitMs: 1_000 });
192
203
  const outcomeIsTyped = true;
204
+ const status = session.execution.status(run);
193
205
  const statusIsTyped = true;
194
- void session.invoke(execution.result(run), { waitMs: 1_000 });
195
- void session.invoke(execution.signal(run), { name: 'approval', value: { by: 'billing' } });
206
+ void session.execution.signal(run, { name: 'approval', value: { by: 'billing' } });
196
207
  // @ts-expect-error Force is the only cancellation option.
197
- void session.invoke(execution.cancel(run), { waitMs: 1_000 });
208
+ void session.execution.cancel(run, { waitMs: 1_000 });
198
209
  void durableReturnsExecution;
199
210
  void outcomeIsTyped;
200
211
  void statusIsTyped;
@@ -206,5 +217,8 @@ void session.invoke(dynamicReference, dynamicInput, { expect: undefined });
206
217
  const unsupportedClientOptions = { expect: undefined };
207
218
  void unsupportedClientOptions;
208
219
  // @ts-expect-error Internal metadata dispatch is absent from the public package facade.
209
- import { dispatchTrace } from '../index.js';
210
- void dispatchTrace;
220
+ import { dispatchInternal } from '../index.js';
221
+ void dispatchInternal;
222
+ // @ts-expect-error The stream-capable HTTP binary path is absent from the public package facade.
223
+ import { dispatchBinaryBody } from '../index.js';
224
+ void dispatchBinaryBody;
@@ -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,31 @@
1
+ /** The Kernel `View` Class. */
2
+ export declare const VIEW_CLASS: Readonly<{
3
+ origin: 'kernel.astrale.ai';
4
+ kind: 'class';
5
+ name: "View";
6
+ }>;
7
+ /** The Kernel `of_domain` Edge Class, which only projection writes. */
8
+ export declare const OF_DOMAIN_CLASS: Readonly<{
9
+ origin: 'kernel.astrale.ai';
10
+ kind: 'class';
11
+ name: "of_domain";
12
+ }>;
13
+ /** The Kernel `Domain` Class. */
14
+ export declare const DOMAIN_CLASS: Readonly<{
15
+ origin: 'kernel.astrale.ai';
16
+ kind: 'class';
17
+ name: "Domain";
18
+ }>;
19
+ export declare const VIEW: "kernel.astrale.ai:class.View";
20
+ export declare const OF_DOMAIN: "kernel.astrale.ai:class.of_domain";
21
+ export declare const DOMAIN: "kernel.astrale.ai:class.Domain";
22
+ /** `View.placement`: where and how a Shell mounts the View. */
23
+ export declare const PLACEMENT: "kernel.astrale.ai:class.View.property.placement";
24
+ /** `of_domain.member`: the member name under which a Domain declares the Node. */
25
+ export declare const MEMBER: "kernel.astrale.ai:class.of_domain.property.member";
26
+ /** `Domain.origin`. */
27
+ export declare const ORIGIN: "kernel.astrale.ai:class.Domain.property.origin";
28
+ /** `Descriptable.description`. */
29
+ export declare const DESCRIPTION: "kernel.astrale.ai:class.Descriptable.property.description";
30
+ /** `Identity.iss`. */
31
+ export declare const ISSUER: "kernel.astrale.ai:class.Identity.property.iss";
@@ -0,0 +1,30 @@
1
+ import { ClassKey, PropertyKey } from '@astrale-os/kernel-dsl/v1/addressing';
2
+ // The Kernel Classes a View read names, by their coordinates. `K` is built by the DSL builder when
3
+ // its module loads, and the Session must not resolve the Kernel Schema on loading, so these are
4
+ // written out here and the tests hold them equal to `K`.
5
+ function kernelClass(name) {
6
+ return Object.freeze({
7
+ origin: 'kernel.astrale.ai',
8
+ kind: 'class',
9
+ name,
10
+ });
11
+ }
12
+ /** The Kernel `View` Class. */
13
+ export const VIEW_CLASS = kernelClass('View');
14
+ /** The Kernel `of_domain` Edge Class, which only projection writes. */
15
+ export const OF_DOMAIN_CLASS = kernelClass('of_domain');
16
+ /** The Kernel `Domain` Class. */
17
+ export const DOMAIN_CLASS = kernelClass('Domain');
18
+ export const VIEW = ClassKey.of(VIEW_CLASS);
19
+ export const OF_DOMAIN = ClassKey.of(OF_DOMAIN_CLASS);
20
+ export const DOMAIN = ClassKey.of(DOMAIN_CLASS);
21
+ /** `View.placement`: where and how a Shell mounts the View. */
22
+ export const PLACEMENT = PropertyKey.of(VIEW_CLASS, 'placement');
23
+ /** `of_domain.member`: the member name under which a Domain declares the Node. */
24
+ export const MEMBER = PropertyKey.of(OF_DOMAIN_CLASS, 'member');
25
+ /** `Domain.origin`. */
26
+ export const ORIGIN = PropertyKey.of(DOMAIN_CLASS, 'origin');
27
+ /** `Descriptable.description`. */
28
+ export const DESCRIPTION = PropertyKey.of(kernelClass('Descriptable'), 'description');
29
+ /** `Identity.iss`. */
30
+ export const ISSUER = PropertyKey.of(kernelClass('Identity'), 'iss');
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The View catalog before Views carried their placement: `ResolvedView`, keyed by declaration and
3
+ * carrying the Release digest that owns it. `viewsFor` lists it through View.resolve
4
+ * (`resolve.ts`), and `SessionSnapshot.views` joins the source Kernel's Release to its root Schema.
5
+ * A client reads a View from its Node instead, as a `View` (`../view.ts`).
6
+ */
7
+ import type { ResolvedView } 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 };
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>>;