@astrale-os/kernel-client 1.0.0-beta.5 → 1.0.0-beta.50

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 (206) hide show
  1. package/dist/auth/authorization.d.ts +10 -5
  2. package/dist/auth/authorization.js +14 -1
  3. package/dist/auth/index.d.ts +1 -0
  4. package/dist/client/admission.js +3 -1
  5. package/dist/client/client.d.ts +70 -4
  6. package/dist/client/client.js +209 -32
  7. package/dist/client/index.d.ts +3 -3
  8. package/dist/client/index.js +2 -2
  9. package/dist/client/level.d.ts +58 -0
  10. package/dist/client/level.js +159 -0
  11. package/dist/client/request.d.ts +7 -2
  12. package/dist/client/request.js +11 -7
  13. package/dist/client/result.d.ts +14 -1
  14. package/dist/client/result.js +19 -8
  15. package/dist/client/routing-control.d.ts +11 -15
  16. package/dist/client/routing-control.js +21 -29
  17. package/dist/errors/index.d.ts +3 -0
  18. package/dist/errors/index.js +3 -0
  19. package/dist/errors/inexpressible-error.d.ts +23 -0
  20. package/dist/errors/inexpressible-error.js +26 -0
  21. package/dist/errors/query-input.d.ts +47 -0
  22. package/dist/errors/query-input.js +85 -0
  23. package/dist/errors/refusal.d.ts +12 -0
  24. package/dist/errors/refusal.js +44 -6
  25. package/dist/errors/response-too-large-error.d.ts +11 -0
  26. package/dist/errors/response-too-large-error.js +15 -0
  27. package/dist/errors/stale-route-error.d.ts +1 -1
  28. package/dist/errors/stale-route-error.js +1 -1
  29. package/dist/{schema → execution}/admission.d.ts +2 -2
  30. package/dist/{schema → execution}/admission.js +2 -2
  31. package/dist/{session/execution.d.ts → execution/contracts.d.ts} +22 -34
  32. package/dist/execution/contracts.js +1 -0
  33. package/dist/execution/deadline.d.ts +18 -0
  34. package/dist/execution/deadline.js +25 -0
  35. package/dist/execution/execution.d.ts +61 -0
  36. package/dist/execution/execution.js +132 -0
  37. package/dist/execution/index.d.ts +4 -0
  38. package/dist/execution/index.js +3 -0
  39. package/dist/graph/domain/binding.d.ts +2 -2
  40. package/dist/graph/domain/binding.js +20 -17
  41. package/dist/graph/domain/conformance.d.ts +12 -0
  42. package/dist/graph/domain/conformance.js +18 -0
  43. package/dist/graph/domain/index.d.ts +1 -0
  44. package/dist/graph/domain/index.js +1 -1
  45. package/dist/graph/domain/provenance.d.ts +0 -2
  46. package/dist/graph/domain/provenance.js +0 -4
  47. package/dist/graph/graph.d.ts +17 -3
  48. package/dist/graph/graph.js +4 -1
  49. package/dist/graph/index.d.ts +3 -3
  50. package/dist/graph/index.js +1 -1
  51. package/dist/graph/page-contract.d.ts +66 -1
  52. package/dist/graph/provenance.d.ts +4 -5
  53. package/dist/graph/provenance.js +5 -6
  54. package/dist/graph/query.d.ts +10 -4
  55. package/dist/graph/query.js +144 -5
  56. package/dist/graph/query.typecheck.d.ts +81 -0
  57. package/dist/graph/query.typecheck.js +34 -0
  58. package/dist/index.d.ts +1 -1
  59. package/dist/index.js +1 -1
  60. package/dist/schema/contracts.d.ts +54 -79
  61. package/dist/schema/index.d.ts +2 -2
  62. package/dist/schema/index.js +1 -1
  63. package/dist/schema/installation.d.ts +36 -64
  64. package/dist/schema/installation.js +67 -131
  65. package/dist/schema/schema.d.ts +10 -16
  66. package/dist/schema/schema.js +57 -34
  67. package/dist/session/admission.js +10 -3
  68. package/dist/session/bound.d.ts +12 -3
  69. package/dist/session/bound.js +36 -32
  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 +2 -2
  80. package/dist/session/context/index.js +2 -2
  81. package/dist/session/context/operation.d.ts +2 -0
  82. package/dist/session/context/operation.js +5 -0
  83. package/dist/session/context/policy.d.ts +2 -0
  84. package/dist/session/context/policy.js +6 -3
  85. package/dist/session/credential/credentials.d.ts +2 -1
  86. package/dist/session/credential/credentials.js +62 -29
  87. package/dist/session/discovery/bundle.d.ts +13 -4
  88. package/dist/session/discovery/bundle.js +85 -36
  89. package/dist/session/discovery/discovery.d.ts +1 -1
  90. package/dist/session/discovery/discovery.js +8 -11
  91. package/dist/session/discovery/index.d.ts +1 -0
  92. package/dist/session/discovery/index.js +5 -1
  93. package/dist/session/discovery/release.d.ts +2 -0
  94. package/dist/session/discovery/release.js +34 -31
  95. package/dist/session/discovery/response.d.ts +4 -0
  96. package/dist/session/discovery/response.js +10 -6
  97. package/dist/session/discovery/snapshot.d.ts +5 -1
  98. package/dist/session/discovery/transport.d.ts +37 -3
  99. package/dist/session/discovery/transport.js +62 -1
  100. package/dist/session/durable.d.ts +13 -0
  101. package/dist/session/durable.js +39 -0
  102. package/dist/session/exchange/exchange.d.ts +3 -2
  103. package/dist/session/exchange/exchange.js +10 -7
  104. package/dist/session/exchange/index.d.ts +1 -1
  105. package/dist/session/exchange/index.js +1 -1
  106. package/dist/session/exchange/presentation.js +28 -10
  107. package/dist/session/exchange/source.d.ts +7 -7
  108. package/dist/session/exchange/source.js +26 -27
  109. package/dist/session/index.d.ts +5 -4
  110. package/dist/session/index.js +0 -1
  111. package/dist/session/options.d.ts +4 -2
  112. package/dist/session/options.js +3 -3
  113. package/dist/session/reference.d.ts +27 -6
  114. package/dist/session/reference.js +18 -3
  115. package/dist/session/retry.d.ts +12 -0
  116. package/dist/session/retry.js +23 -0
  117. package/dist/session/routing/auth.d.ts +9 -3
  118. package/dist/session/routing/auth.js +4 -3
  119. package/dist/session/routing/cache.d.ts +12 -5
  120. package/dist/session/routing/cache.js +56 -48
  121. package/dist/session/routing/dispatch.d.ts +26 -3
  122. package/dist/session/routing/dispatch.js +112 -69
  123. package/dist/session/routing/envelope.d.ts +3 -3
  124. package/dist/session/routing/index.d.ts +1 -1
  125. package/dist/session/routing/legacy/release-route.d.ts +12 -0
  126. package/dist/session/routing/legacy/release-route.js +6 -0
  127. package/dist/session/routing/recovery.d.ts +3 -6
  128. package/dist/session/routing/recovery.js +3 -14
  129. package/dist/session/routing/request.d.ts +2 -1
  130. package/dist/session/routing/request.js +2 -1
  131. package/dist/session/routing/result.d.ts +1 -1
  132. package/dist/session/routing/result.js +5 -1
  133. package/dist/session/routing/store.js +4 -5
  134. package/dist/session/session.d.ts +31 -5
  135. package/dist/session/session.js +70 -22
  136. package/dist/session/session.typecheck.js +20 -6
  137. package/dist/session/views/index.d.ts +2 -2
  138. package/dist/session/views/index.js +2 -2
  139. package/dist/session/views/kernel.d.ts +31 -0
  140. package/dist/session/views/kernel.js +30 -0
  141. package/dist/session/views/legacy/catalog.d.ts +21 -0
  142. package/dist/session/views/{catalog.js → legacy/catalog.js} +7 -31
  143. package/dist/session/views/legacy/index.d.ts +14 -0
  144. package/dist/session/views/legacy/index.js +14 -0
  145. package/dist/session/views/legacy/resolve.d.ts +46 -0
  146. package/dist/session/views/legacy/resolve.js +83 -0
  147. package/dist/session/views/legacy/unplaced.d.ts +22 -0
  148. package/dist/session/views/legacy/unplaced.js +26 -0
  149. package/dist/session/views/read.d.ts +49 -0
  150. package/dist/session/views/read.js +148 -0
  151. package/dist/session/views/view.d.ts +48 -0
  152. package/dist/session/views/view.js +74 -0
  153. package/dist/store/memory.d.ts +1 -3
  154. package/dist/store/memory.js +61 -112
  155. package/dist/store/shape.d.ts +33 -12
  156. package/dist/store/shape.js +125 -16
  157. package/dist/store/store.d.ts +6 -6
  158. package/dist/store/store.js +1 -1
  159. package/dist/transport/auto/decision.d.ts +28 -14
  160. package/dist/transport/auto/decision.js +39 -32
  161. package/dist/transport/auto/fallback.d.ts +1 -1
  162. package/dist/transport/auto/fallback.js +5 -10
  163. package/dist/transport/auto/transport.d.ts +10 -3
  164. package/dist/transport/auto/transport.js +41 -32
  165. package/dist/transport/deadline.d.ts +2 -0
  166. package/dist/transport/deadline.js +18 -0
  167. package/dist/transport/failure.d.ts +28 -1
  168. package/dist/transport/failure.js +63 -1
  169. package/dist/transport/http/admission.js +8 -35
  170. package/dist/transport/http/binary-request.d.ts +44 -0
  171. package/dist/transport/http/binary-request.js +110 -0
  172. package/dist/transport/http/binary.js +3 -3
  173. package/dist/transport/http/byte-stream.d.ts +2 -1
  174. package/dist/transport/http/byte-stream.js +12 -8
  175. package/dist/transport/http/configuration.d.ts +7 -0
  176. package/dist/transport/http/configuration.js +2 -0
  177. package/dist/transport/http/index.d.ts +1 -1
  178. package/dist/transport/http/index.js +1 -1
  179. package/dist/transport/http/response.d.ts +13 -1
  180. package/dist/transport/http/response.js +22 -9
  181. package/dist/transport/http/stream.d.ts +8 -13
  182. package/dist/transport/http/stream.js +34 -81
  183. package/dist/transport/http/transport.d.ts +14 -1
  184. package/dist/transport/http/transport.js +110 -35
  185. package/dist/transport/http/unprocessed.d.ts +5 -0
  186. package/dist/transport/http/unprocessed.js +28 -0
  187. package/dist/transport/index.d.ts +2 -1
  188. package/dist/transport/index.js +2 -1
  189. package/dist/transport/level.d.ts +42 -0
  190. package/dist/transport/level.js +58 -0
  191. package/dist/transport/stream.d.ts +52 -0
  192. package/dist/transport/stream.js +101 -0
  193. package/dist/transport/transport.d.ts +33 -0
  194. package/dist/transport/unary.d.ts +9 -0
  195. package/dist/transport/unary.js +36 -0
  196. package/dist/transport/websocket/connection.d.ts +13 -4
  197. package/dist/transport/websocket/connection.js +123 -96
  198. package/dist/transport/websocket/exchange.d.ts +15 -19
  199. package/dist/transport/websocket/exchange.js +87 -183
  200. package/dist/transport/websocket/transport.d.ts +19 -1
  201. package/dist/transport/websocket/transport.js +50 -21
  202. package/package.json +9 -7
  203. package/dist/session/execution.js +0 -34
  204. package/dist/session/views/catalog.d.ts +0 -19
  205. package/dist/session/views/resolve.d.ts +0 -13
  206. package/dist/session/views/resolve.js +0 -21
@@ -1,23 +1,24 @@
1
- import { Key } from '@astrale-os/kernel-dsl/v1/addressing';
2
- import { acceptCall, Client, dispatchTrace } from '../../client/index.js';
1
+ import { acceptCall, Client, dispatchInternal, isRoutingControl, routingControlError, } 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';
7
- import { isRouteCompatibilityConflict, recoveryRefresh, routingControl } from './recovery.js';
6
+ import { releaseRoutesDeclaration } from './legacy/release-route.js';
7
+ import { isRouteCompatibilityConflict, recoveryRefresh } from './recovery.js';
8
8
  export class SessionDispatcher {
9
9
  state;
10
10
  constructor(state) {
11
11
  this.state = state;
12
12
  }
13
13
  async dispatch(input, options, operation) {
14
- return this.dispatchWith(input, options, operation);
14
+ return this.dispatchResolved(await this.resolve(input, operation), options, operation);
15
15
  }
16
16
  /** Reuse Session authority and route recovery while forcing HTTP for streaming calls. */
17
17
  async dispatchHttp(input, options, operation, body) {
18
- return this.dispatchWith(input, options, operation, { body });
18
+ return this.dispatchResolved(await this.resolve(input, operation), options, operation, { body });
19
19
  }
20
- async dispatchWith(input, options, operation, streaming) {
20
+ /** Resolve the Session authority of one Call: each dispatch of the result presents it. */
21
+ async resolve(input, operation) {
21
22
  this.state.requireOpen();
22
23
  const call = acceptCall(input);
23
24
  // Authority is resolved before warm lookup so changed credentials or delegation cannot reuse a
@@ -28,83 +29,113 @@ export class SessionDispatcher {
28
29
  : await this.state.exchange.resolve(call, resolved, operation);
29
30
  const source = this.state.kernel;
30
31
  const cacheKey = await runSessionOperation(operation, () => this.state.cache.key(source, call, auth));
31
- const dispatch = Object.freeze({ call, auth, source, cacheKey });
32
- const learned = await this.warmRoute(dispatch, operation, streaming);
33
- if (learned !== undefined) {
34
- return this.dispatchDestinationWithRecovery(learned, dispatch, options, operation, undefined, streaming);
35
- }
36
- const result = await this.dispatchSource(dispatch, undefined, options, operation, streaming);
37
- return this.followSource(result, dispatch, options, operation, streaming);
32
+ return Object.freeze({ call, auth, source, cacheKey });
33
+ }
34
+ /**
35
+ * Dispatch a resolved Call. Sending it again presents the same principal and caller, which an
36
+ * idempotency key needs to name the same Execution.
37
+ */
38
+ async dispatchResolved(resolved, options, operation, streaming) {
39
+ this.state.requireOpen();
40
+ const attempt = Object.freeze({
41
+ resolved,
42
+ options,
43
+ operation,
44
+ ...(streaming === undefined ? {} : { streaming }),
45
+ });
46
+ const learned = await this.warmRoute(attempt);
47
+ if (learned !== undefined)
48
+ return this.dispatchDestinationWithRecovery(learned, attempt);
49
+ const result = await this.dispatchSource(attempt, undefined);
50
+ return this.followSource(result, attempt);
38
51
  }
39
52
  /** The cached route for this partition, evicted when it no longer passes delivery checks. */
40
- async warmRoute(state, operation, streaming) {
41
- const learned = await runSessionOperation(operation, () => this.state.cache.get(state.cacheKey, state.auth.credential, undefined, operation.deadline));
53
+ async warmRoute(attempt) {
54
+ const { resolved, operation, streaming } = attempt;
55
+ const learned = await runSessionOperation(operation, () => this.state.cache.get(resolved.cacheKey, presentedCredential(resolved.auth), undefined, operation.deadline));
42
56
  if (learned === undefined)
43
57
  return undefined;
44
58
  try {
45
- requireLearnedRoute(learned, state.source, state.call.target);
59
+ requireLearnedRoute(learned, resolved.source, resolved.call.target);
46
60
  selectEnvelopeTarget(learned.route.endpoint, streaming === undefined ? this.state.envelopeTransport : 'http', this.state.websocketAvailable, this.state.policy);
47
61
  return learned;
48
62
  }
49
63
  catch {
50
- this.state.cache.delete(state.cacheKey);
64
+ this.state.cache.delete(resolved.cacheKey);
51
65
  return undefined;
52
66
  }
53
67
  }
54
- async dispatchSource(state, routing, options, operation, streaming) {
68
+ async dispatchSource(attempt, routing) {
69
+ const { resolved, options, operation, streaming } = attempt;
55
70
  this.state.requireOpen();
56
71
  remainingSessionTime(operation);
57
72
  allowEndpoint(this.state.sourceEndpoint, this.state.policy);
58
73
  const client = streaming === undefined
59
74
  ? this.state.pool.clientFor(Object.freeze({ transport: 'http', url: this.state.sourceEndpoint }))
60
75
  : this.streamingClientFor(this.state.sourceEndpoint);
61
- return runSessionOperation(operation, () => send(client, state.auth.credential, state.call, {
62
- ...transportOptions(operation, options, streaming),
63
- ...(state.auth.delegate === undefined ? {} : { delegate: state.auth.delegate }),
64
- ...(routing === undefined ? {} : { routing }),
65
- // The guard is the source Kernel's: a routed destination request never carries it.
66
- ...(options.maintenance === undefined ? {} : { maintenance: options.maintenance }),
67
- }));
76
+ return sendWithin(operation, client, {
77
+ credential: presentedCredential(resolved.auth),
78
+ call: resolved.call,
79
+ options: {
80
+ ...transportOptions(attempt),
81
+ ...(resolved.auth.kind === 'anonymous' ? {} : { delegate: resolved.auth.delegate }),
82
+ ...(routing === undefined ? {} : { routing }),
83
+ // The guard is the source Kernel's: a routed destination request never carries it.
84
+ ...(options.maintenance === undefined ? {} : { maintenance: options.maintenance }),
85
+ },
86
+ body: streaming?.body,
87
+ });
68
88
  }
69
- async followSource(result, state, options, operation, streaming) {
89
+ /** The source answers routing control only as the public error: it has no route to recover. */
90
+ async followSource(result, attempt) {
91
+ if (isRoutingControl(result))
92
+ throw routingControlError(result);
70
93
  if (result.kind !== 'redirect')
71
94
  return result;
95
+ const { resolved, operation, streaming } = attempt;
96
+ requireResendable(streaming, 'follow a Redirect');
72
97
  const redirect = result.redirect;
73
- if (redirect.route.via.issuer !== state.source) {
98
+ if (redirect.route.via.issuer !== resolved.source) {
74
99
  throw new ClientError('Redirect issuer differs from the session-pinned source Kernel identity.');
75
100
  }
76
- requireTargetRelease(redirect.route, state.call.target);
77
- const learned = await runSessionOperation(operation, () => this.state.cache.learn(state.cacheKey, redirect.route, redirect.credential, state.auth.credential));
78
- return this.dispatchDestinationWithRecovery(learned, state, options, operation, redirect.trace, streaming);
101
+ requireRouteForTarget(redirect.route, resolved.call.target);
102
+ const learned = await runSessionOperation(operation, () => this.state.cache.learn(resolved.cacheKey, redirect.route, redirect.credential, presentedCredential(resolved.auth)));
103
+ return this.dispatchDestinationWithRecovery(learned, attempt, redirect.trace);
79
104
  }
80
- async dispatchDestinationWithRecovery(learned, state, options, operation, trace, streaming) {
105
+ async dispatchDestinationWithRecovery(learned, attempt, trace) {
106
+ const { resolved, operation, streaming } = attempt;
107
+ let result;
81
108
  try {
82
- return await this.dispatchDestination(learned, state.call, options, operation, state.source, trace, streaming);
109
+ result = await this.dispatchDestination(learned, attempt, trace);
83
110
  }
84
111
  catch (cause) {
85
- const control = routingControl(cause);
86
- if (control === undefined) {
87
- if (isRouteCompatibilityConflict(cause))
88
- this.state.cache.delete(state.cacheKey);
89
- throw cause;
90
- }
91
- this.state.cache.delete(state.cacheKey);
92
- if (!operation.claimRecovery())
93
- throw cause;
94
- const routing = recoveryRefresh(control, learned);
95
- const refreshed = await this.dispatchSource(state, routing, options, operation, streaming);
96
- return this.followSource(refreshed, state, options, operation, streaming);
112
+ if (isRouteCompatibilityConflict(cause))
113
+ this.state.cache.delete(resolved.cacheKey);
114
+ throw cause;
97
115
  }
116
+ if (!isRoutingControl(result))
117
+ return result;
118
+ this.state.cache.delete(resolved.cacheKey);
119
+ const failure = routingControlError(result);
120
+ if (!operation.claimRecovery())
121
+ throw failure;
122
+ requireResendable(streaming, 'recover its route', failure);
123
+ const refreshed = await this.dispatchSource(attempt, recoveryRefresh(result, learned));
124
+ return this.followSource(refreshed, attempt);
98
125
  }
99
- async dispatchDestination(learned, call, options, operation, source, trace, streaming) {
126
+ async dispatchDestination(learned, attempt, trace) {
127
+ const { resolved, operation, streaming } = attempt;
100
128
  remainingSessionTime(operation);
101
- requireLearnedRoute(learned, source, call.target);
129
+ requireLearnedRoute(learned, resolved.source, resolved.call.target);
102
130
  const client = this.destinationClient(learned, streaming);
103
- const request = {
104
- ...transportOptions(operation, options, streaming),
105
- routing: learned.route.via,
106
- };
107
- const result = await runSessionOperation(operation, () => send(client, learned.credential, call, request, trace));
131
+ const options = { ...transportOptions(attempt), routing: learned.route.via };
132
+ const result = await sendWithin(operation, client, {
133
+ credential: learned.credential,
134
+ call: resolved.call,
135
+ options,
136
+ trace,
137
+ body: streaming?.body,
138
+ });
108
139
  if (result.kind === 'redirect') {
109
140
  throw new ClientError('A destination redirect is invalid; only the source Kernel may redirect.');
110
141
  }
@@ -132,33 +163,45 @@ export class SessionDispatcher {
132
163
  });
133
164
  }
134
165
  }
166
+ /**
167
+ * Send one request within the operation. Routing control that answers an interrupted operation
168
+ * yields its interruption, exactly as a failure inside the operation does: it is never recovered.
169
+ */
170
+ async function sendWithin(operation, client, dispatch) {
171
+ const result = await runSessionOperation(operation, () => dispatchInternal(client, dispatch));
172
+ // Re-entering the operation is its own interruption check; it adds no work.
173
+ return isRoutingControl(result) ? runSessionOperation(operation, () => result) : result;
174
+ }
175
+ /** The credential a Call presents to the source Kernel; an anonymous Call presents none. */
176
+ function presentedCredential(auth) {
177
+ return auth.kind === 'anonymous' ? undefined : auth.credential;
178
+ }
135
179
  /** A body-carrying streaming call omits the idempotency key; every other call keeps it. */
136
- function transportOptions(operation, options, streaming) {
180
+ function transportOptions({ operation, options, streaming }) {
137
181
  return streaming?.body === undefined
138
182
  ? sessionTransportOptions(operation, options.idempotencyKey)
139
- : { ...sessionTransportOptions(operation), body: streaming.body };
183
+ : sessionTransportOptions(operation);
184
+ }
185
+ /** A stream body was consumed by the send that just answered: it is never sent again. */
186
+ function requireResendable(streaming, step, cause) {
187
+ if (streaming?.body?.kind !== 'once')
188
+ return;
189
+ throw new ClientError(`A call with a streamed binary body is sent once and cannot ${step}; send it again with a new stream.`, cause === undefined ? undefined : { cause });
140
190
  }
141
191
  function requireLearnedRoute(learned, source, target) {
142
192
  if (learned.route.via.issuer !== source) {
143
193
  throw new ClientError('Learned route issuer differs from the session-pinned source Kernel.');
144
194
  }
145
- requireTargetRelease(learned.route, target);
195
+ requireRouteForTarget(learned.route, target);
146
196
  }
147
- function requireTargetRelease(route, target) {
197
+ /** A Target names a declaration: only a witness of that declaration routes it. */
198
+ function requireRouteForTarget(route, target) {
148
199
  if (typeof target === 'string')
149
200
  return;
150
- const actual = route.via.release;
151
- if (actual.origin !== Key.origin(target.callable)) {
152
- throw new ClientError('Resolved route does not match the Target origin.');
153
- }
154
- }
155
- /** Send one call, presenting the Trace only on the attempt that carries it. */
156
- function send(client, credential, call, options, trace) {
157
- if (trace !== undefined)
158
- return dispatchTrace(client, credential, call, options, trace);
159
- const sender = credential === undefined ? client : client.as(credential);
160
- // Both branches are needed: each narrows `options` to one `Client.dispatch` overload.
161
- return options.body === undefined
162
- ? sender.dispatch(call, options)
163
- : sender.dispatch(call, options);
201
+ const { via } = route;
202
+ const routes = 'function' in via
203
+ ? via.function.declaration === target.callable
204
+ : releaseRoutesDeclaration(via, target.callable);
205
+ if (!routes)
206
+ throw new ClientError('Resolved route does not name the Target declaration.');
164
207
  }
@@ -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;
@@ -1,4 +1,4 @@
1
- export { admitSessionAuth, resolveAuth, type Auth, type AuthExchange, type EffectiveAuth, type SessionAuth, } from './auth.js';
1
+ export { admitSessionAuth, resolveAuth, type Auth, type Authenticated, type AuthExchange, type EffectiveAuth, type SessionAuth, } from './auth.js';
2
2
  export { RouteCache, type LearnedRoute } from './cache.js';
3
3
  export { SessionDispatcher, type SessionDispatcherOptions } from './dispatch.js';
4
4
  export { type ClientPoolCapability, type EnvelopeSelection } from './envelope.js';
@@ -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,16 +1,13 @@
1
1
  import type * as invocation from '@astrale-os/kernel-protocol/invocation';
2
+ import type { RoutingControl } from '../../client/index.js';
2
3
  import type { LearnedRoute } from './cache.js';
3
- /** The privately witnessed pre-handler control a destination failure carries, if any. */
4
- export type RoutingControl = 'stale' | 'miss' | 'retired';
5
- /** The routing control a destination failure witnesses, if any. */
6
- export declare function routingControl(input: unknown): RoutingControl | undefined;
7
4
  /**
8
5
  * The Refresh a recovery source hop carries. A stale or retired route names the release the
9
6
  * destination no longer serves; a miss names a Path, so the source receives no digest for it.
10
7
  */
11
8
  export declare function recoveryRefresh(control: RoutingControl, learned: LearnedRoute): invocation.Refresh | undefined;
12
9
  /**
13
- * A failure that proves the warm route can no longer serve this call without witnessing a
14
- * pre-handler control: the route is evicted for later calls, but the invocation is never replayed.
10
+ * A failure that proves the warm route can no longer serve this call without carrying routing
11
+ * control: the route is evicted for later calls, but the invocation is never replayed.
15
12
  */
16
13
  export declare function isRouteCompatibilityConflict(input: unknown): boolean;
@@ -1,22 +1,11 @@
1
1
  import * as invocationProtocol from '@astrale-os/kernel-protocol/invocation';
2
- import { isAdmittedDeploymentRetiredError, isAdmittedMissError, isAdmittedStaleRouteError, } from '../../client/index.js';
3
2
  import { ResponseError } from '../../errors/index.js';
4
- /** The routing control a destination failure witnesses, if any. */
5
- export function routingControl(input) {
6
- if (isAdmittedStaleRouteError(input))
7
- return 'stale';
8
- if (isAdmittedMissError(input))
9
- return 'miss';
10
- if (isAdmittedDeploymentRetiredError(input))
11
- return 'retired';
12
- return undefined;
13
- }
14
3
  /**
15
4
  * The Refresh a recovery source hop carries. A stale or retired route names the release the
16
5
  * destination no longer serves; a miss names a Path, so the source receives no digest for it.
17
6
  */
18
7
  export function recoveryRefresh(control, learned) {
19
- if (control === 'miss')
8
+ if (control.kind === 'miss')
20
9
  return undefined;
21
10
  return Object.freeze({
22
11
  kind: 'refresh',
@@ -24,8 +13,8 @@ export function recoveryRefresh(control, learned) {
24
13
  });
25
14
  }
26
15
  /**
27
- * A failure that proves the warm route can no longer serve this call without witnessing a
28
- * pre-handler control: the route is evicted for later calls, but the invocation is never replayed.
16
+ * A failure that proves the warm route can no longer serve this call without carrying routing
17
+ * control: the route is evicted for later calls, but the invocation is never replayed.
29
18
  */
30
19
  export function isRouteCompatibilityConflict(input) {
31
20
  if (!(input instanceof ResponseError))
@@ -1,4 +1,5 @@
1
1
  import type * as invocation from '@astrale-os/kernel-protocol/invocation';
2
+ import type { BinaryBody } from '../../transport/http/binary-request.js';
2
3
  import type { SessionControlOptions } from '../context/index.js';
3
4
  export type SessionEnvelopeTransport = 'auto' | 'http' | 'websocket';
4
5
  export interface SessionRequestOptions extends SessionControlOptions {
@@ -15,7 +16,7 @@ export type SessionRequestOptionsWithBody = Omit<SessionRequestOptions, 'body' |
15
16
  };
16
17
  export declare function admitInvocationOptions(input: SessionRequestOptions | SessionRequestOptionsWithBody | undefined): {
17
18
  readonly options: Readonly<SessionRequestOptions>;
18
- readonly body?: Blob;
19
+ readonly body?: BinaryBody;
19
20
  };
20
21
  export declare function admitRequestOptions(input?: SessionRequestOptions): Readonly<SessionRequestOptions>;
21
22
  export declare function admitEnvelopeTransport(input: SessionEnvelopeTransport): SessionEnvelopeTransport;
@@ -1,4 +1,5 @@
1
1
  import * as invocationProtocol from '@astrale-os/kernel-protocol/invocation';
2
+ import { replayableBody } from '../../transport/http/binary-request.js';
2
3
  import { admitControlOptions } from '../context/index.js';
3
4
  export function admitInvocationOptions(input) {
4
5
  if (input === undefined)
@@ -15,7 +16,7 @@ export function admitInvocationOptions(input) {
15
16
  if (options.idempotencyKey !== undefined) {
16
17
  throw new TypeError('Binary requests cannot carry an idempotency key.');
17
18
  }
18
- return Object.freeze({ options: admitRequestOptions(options), body });
19
+ return Object.freeze({ options: admitRequestOptions(options), body: replayableBody(body) });
19
20
  }
20
21
  export function admitRequestOptions(input = {}) {
21
22
  if (input === null || typeof input !== 'object' || Array.isArray(input)) {
@@ -1,5 +1,5 @@
1
1
  import type { Result } from '../../client/index.js';
2
2
  /** Narrow a Result to the kind a sugar requires, releasing a live body before rejecting it. */
3
- export declare function requireResultKind<Kind extends 'value' | 'stream' | 'binary'>(expected: Kind, result: Result): Extract<Result, {
3
+ export declare function requireResultKind<Kind extends Exclude<Result['kind'], 'redirect'>>(expected: Kind, result: Result): Extract<Result, {
4
4
  kind: Kind;
5
5
  }>;
@@ -8,5 +8,9 @@ export function requireResultKind(expected, result) {
8
8
  if (result.kind === 'binary' && !(result.value.body instanceof Uint8Array)) {
9
9
  void result.value.body[Symbol.asyncIterator]().return?.();
10
10
  }
11
- throw new ClientError(`Function returned ${result.kind}; ${expected} was required.`);
11
+ // A started Execution is named so its caller never starts it again.
12
+ const returned = result.kind === 'execution'
13
+ ? `Function started Execution ${result.execution}`
14
+ : `Function returned ${result.kind}`;
15
+ throw new ClientError(`${returned}; ${expected} was required.`);
12
16
  }
@@ -46,14 +46,14 @@ export function restoreRoutes(input, now, maximumAgeMs, maximumSize) {
46
46
  }
47
47
  /** The artifact persisting every integrity-bound entry, as it was sealed. */
48
48
  export function routeArtifact(entries) {
49
- const persisted = Object.fromEntries([...entries].flatMap(([key, cached]) => cached.integrity === undefined
49
+ const persisted = Object.fromEntries([...entries].flatMap(([key, cached]) => cached.persisted === undefined
50
50
  ? []
51
51
  : [
52
52
  [
53
53
  key,
54
54
  Object.freeze({
55
- ...(cached.sealed ?? cached.learned),
56
- integrity: cached.integrity,
55
+ ...cached.persisted.sealed,
56
+ integrity: cached.persisted.integrity,
57
57
  }),
58
58
  ],
59
59
  ]));
@@ -88,8 +88,7 @@ function admitStoredEntry(input, now, maximumAgeMs) {
88
88
  ...(sealed.credential === undefined ? {} : { credential: sealed.credential }),
89
89
  expiresAt,
90
90
  }),
91
- sealed,
92
- integrity: value.integrity,
91
+ persisted: Object.freeze({ sealed, integrity: value.integrity }),
93
92
  ...(expiry === undefined ? {} : { credentialRefreshBoundary: refreshBoundary(expiry) }),
94
93
  });
95
94
  }
@@ -1,8 +1,9 @@
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';
6
+ import type { ExecutionApi } from '../execution/index.js';
6
7
  import type { DomainBinding, GraphApi } from '../graph/index.js';
7
8
  import type { SchemaApi } from '../schema/index.js';
8
9
  import type { ContentApi } from './content/index.js';
@@ -12,7 +13,8 @@ import type { IntrinsicRelease, SessionSnapshot } from './discovery/index.js';
12
13
  import type { SessionExchangeRequest } from './exchange/index.js';
13
14
  import type { CallableReference, InputModeOfReference, InputOfReference, OutputOfReference } from './reference.js';
14
15
  import type { SessionRequestOptions, SessionRequestOptionsWithBody } from './routing/index.js';
15
- 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';
16
18
  import { type ClientSessionOptions } from './options.js';
17
19
  export type ConnectOptions = Omit<ClientSessionOptions, 'kernel' | 'policy'> & {
18
20
  readonly url: string;
@@ -22,6 +24,8 @@ export type ConnectOptions = Omit<ClientSessionOptions, 'kernel' | 'policy'> & {
22
24
  export declare class ClientSession {
23
25
  readonly kernel: IssuerId;
24
26
  readonly schema: SchemaApi;
27
+ /** The `K.Execution` Methods of any Execution, a durable call's or an install's. */
28
+ readonly execution: ExecutionApi;
25
29
  readonly graph: GraphApi;
26
30
  readonly auth: AuthApi;
27
31
  readonly content: ContentApi;
@@ -33,7 +37,9 @@ export declare class ClientSession {
33
37
  private readonly routes;
34
38
  private readonly exchangeDependencies;
35
39
  private readonly callExchange?;
36
- 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;
37
43
  private closed;
38
44
  constructor(options: ClientSessionOptions);
39
45
  /** Bind one admitted DSL Domain to authenticated graph projection and Method dispatch. */
@@ -50,14 +56,34 @@ export declare class ClientSession {
50
56
  release(options?: SessionControlOptions): Promise<IntrinsicRelease>;
51
57
  snapshot(options?: SessionControlOptions): Promise<SessionSnapshot>;
52
58
  /**
53
- * Resolve the View catalog of one installed Domain. Only an exact Domain Path `/:<origin>` is
54
- * 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.
55
77
  */
56
78
  viewsFor(domain: PathLike, options?: SessionControlOptions): Promise<ViewCatalog>;
57
79
  dispatch(call: Call, options?: SessionRequestOptions): Promise<Result>;
58
80
  dispatch(call: Call, options: SessionRequestOptionsWithBody): Promise<Result>;
59
81
  call(call: Call, options?: SessionRequestOptions): Promise<Input>;
60
82
  call(call: Call, options: SessionRequestOptionsWithBody): Promise<Input>;
83
+ /**
84
+ * Invoke one typed reference. A durable callable's call is keyed, by the caller's key or by one
85
+ * created for this call, and sent again with that key while its outcome is unknown.
86
+ */
61
87
  invoke<const Reference extends CallableReference<unknown>>(reference: InputModeOfReference<Reference> extends 'binary' ? never : Reference, input: InputOfReference<Reference>, options?: SessionRequestOptions): Promise<OutputOfReference<Reference>>;
62
88
  invoke<const Reference extends CallableReference<unknown, unknown, 'binary'>>(reference: Reference, input: InputOfReference<Reference>, options: SessionRequestOptionsWithBody): Promise<OutputOfReference<Reference>>;
63
89
  private dispatchWith;