@astrale-os/kernel-client 1.0.0-beta.22 → 1.0.0-beta.24

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 (60) hide show
  1. package/dist/client/client.d.ts +5 -4
  2. package/dist/client/client.js +7 -7
  3. package/dist/client/index.d.ts +1 -1
  4. package/dist/client/request.d.ts +5 -9
  5. package/dist/client/request.js +13 -16
  6. package/dist/errors/index.d.ts +1 -0
  7. package/dist/errors/index.js +1 -0
  8. package/dist/errors/query-input.d.ts +47 -0
  9. package/dist/errors/query-input.js +84 -0
  10. package/dist/execution/deadline.d.ts +10 -0
  11. package/dist/execution/deadline.js +12 -0
  12. package/dist/execution/execution.js +2 -7
  13. package/dist/execution/index.d.ts +1 -1
  14. package/dist/execution/index.js +1 -1
  15. package/dist/graph/domain/binding.d.ts +2 -2
  16. package/dist/graph/graph.d.ts +17 -3
  17. package/dist/graph/graph.js +4 -1
  18. package/dist/graph/index.d.ts +2 -2
  19. package/dist/graph/page-contract.d.ts +53 -1
  20. package/dist/graph/query.d.ts +10 -4
  21. package/dist/graph/query.js +125 -2
  22. package/dist/graph/query.typecheck.d.ts +77 -0
  23. package/dist/graph/query.typecheck.js +34 -0
  24. package/dist/schema/contracts.d.ts +21 -10
  25. package/dist/schema/index.d.ts +1 -1
  26. package/dist/schema/installation.d.ts +11 -1
  27. package/dist/schema/installation.js +45 -1
  28. package/dist/schema/schema.d.ts +4 -4
  29. package/dist/schema/schema.js +34 -24
  30. package/dist/session/bound.js +27 -31
  31. package/dist/session/content/api.js +2 -2
  32. package/dist/session/content/input.js +2 -2
  33. package/dist/session/content/retry.d.ts +2 -1
  34. package/dist/session/content/retry.js +13 -23
  35. package/dist/session/context/operation.js +2 -16
  36. package/dist/session/durable.js +13 -19
  37. package/dist/session/retry.d.ts +12 -0
  38. package/dist/session/retry.js +23 -0
  39. package/dist/session/routing/dispatch.d.ts +2 -2
  40. package/dist/session/routing/dispatch.js +12 -20
  41. package/dist/session/routing/request.d.ts +2 -1
  42. package/dist/session/routing/request.js +2 -1
  43. package/dist/store/store.d.ts +6 -6
  44. package/dist/transport/deadline.d.ts +2 -0
  45. package/dist/transport/deadline.js +18 -0
  46. package/dist/transport/http/admission.js +7 -42
  47. package/dist/transport/http/binary-request.d.ts +23 -9
  48. package/dist/transport/http/binary-request.js +12 -10
  49. package/dist/transport/http/response.d.ts +0 -1
  50. package/dist/transport/http/response.js +0 -6
  51. package/dist/transport/http/transport.d.ts +3 -2
  52. package/dist/transport/http/transport.js +16 -20
  53. package/dist/transport/index.d.ts +1 -1
  54. package/dist/transport/index.js +1 -1
  55. package/dist/transport/unary.d.ts +7 -0
  56. package/dist/transport/unary.js +34 -0
  57. package/dist/transport/websocket/connection.js +1 -7
  58. package/dist/transport/websocket/exchange.d.ts +2 -0
  59. package/dist/transport/websocket/exchange.js +13 -43
  60. package/package.json +5 -5
@@ -4,13 +4,14 @@ import { ClientError, ProtocolError, ResponseError, TransportError } from '../..
4
4
  import { invocationFailure } from '../failure.js';
5
5
  import { asError, controlledSignal, positiveInteger, requireLive, } from '../index.js';
6
6
  import { admitResponse } from './admission.js';
7
- import { acceptBinaryBody, cancelUnsent, isReplayable, sendStream } from './binary-request.js';
7
+ import { cancelUnsent, replayableBody, sendStream } from './binary-request.js';
8
8
  import { capture } from './configuration.js';
9
9
  import { unprocessed } from './unprocessed.js';
10
10
  const bodyDispatch = new WeakMap();
11
11
  /**
12
- * Package-private binary invocation whose body may be a one-shot stream; intentionally absent from
13
- * the public HttpTransport facade, whose callers could not resend a stream a Redirect answers.
12
+ * Package-private binary invocation of an admitted body, which may be a one-shot stream;
13
+ * intentionally absent from the public HttpTransport facade, whose callers could not resend a
14
+ * stream a Redirect answers.
14
15
  */
15
16
  export async function dispatchBinaryBody(transport, input, body, options = {}) {
16
17
  const dispatch = bodyDispatch.get(transport);
@@ -35,7 +36,7 @@ export class HttpTransport {
35
36
  this.timeoutMs = configuration.timeoutMs;
36
37
  this.maximumRequestBytes = configuration.maximumRequestBytes;
37
38
  this.maximumResponseBytes = configuration.maximumResponseBytes;
38
- bodyDispatch.set(this, (input, body, options) => this.dispatchBody(input, acceptBinaryBody(body), options));
39
+ bodyDispatch.set(this, (input, body, options) => this.dispatchBody(input, body, options));
39
40
  }
40
41
  async dispatch(input, options = {}) {
41
42
  return this.dispatchWith(input, options);
@@ -44,7 +45,7 @@ export class HttpTransport {
44
45
  async dispatchBinary(input, body, options = {}) {
45
46
  if (!(body instanceof Blob))
46
47
  throw new TypeError('Binary request body must be a Blob.');
47
- return this.dispatchBody(input, body, options);
48
+ return this.dispatchBody(input, replayableBody(body), options);
48
49
  }
49
50
  /** A Blob may be replayed; a stream is read once, by this call, and must yield its length. */
50
51
  async dispatchBody(input, body, options) {
@@ -55,24 +56,19 @@ export class HttpTransport {
55
56
  return this.dispatchWith(input, options, body);
56
57
  }
57
58
  async dispatchWith(input, options, binaryBody) {
58
- let sent;
59
- let streamed;
60
- if (binaryBody !== undefined && isReplayable(binaryBody)) {
61
- sent = { length: binaryBody.size, body: binaryBody, once: false };
62
- }
63
- else if (binaryBody !== undefined) {
64
- // The stream is claimed first: whatever ends this call before reading it through cancels it.
65
- streamed = sendStream(binaryBody);
66
- sent = { length: binaryBody.length, body: streamed.body, once: true };
67
- }
59
+ // The stream is claimed first: whatever ends this call before reading it through cancels it.
60
+ const sent = binaryBody?.kind === 'once' ? sendStream(binaryBody) : binaryBody;
68
61
  try {
69
- return await this.send(input, options, sent, streamed);
62
+ return await this.send(input, options, sent);
70
63
  }
71
64
  finally {
72
- streamed?.release(new ClientError('Binary request settled before its stream ended.'));
65
+ if (sent?.kind === 'once') {
66
+ sent.release(new ClientError('Binary request settled before its stream ended.'));
67
+ }
73
68
  }
74
69
  }
75
- async send(input, options, binary, streamed) {
70
+ async send(input, options, binary) {
71
+ const streamed = binary?.kind === 'once' ? binary : undefined;
76
72
  const requestId = this.nextRequestId();
77
73
  const timeoutMs = positiveInteger(options.timeoutMs ?? this.timeoutMs, 'timeoutMs');
78
74
  const codec = codecs.json;
@@ -160,7 +156,7 @@ export class HttpTransport {
160
156
  },
161
157
  body: binary === undefined ? toBody(encoded) : binary.body,
162
158
  // Fetch sends a stream body without buffering it only in half duplex.
163
- ...(binary?.once === true ? { duplex: 'half' } : {}),
159
+ ...(binary?.kind === 'once' ? { duplex: 'half' } : {}),
164
160
  signal: control.signal,
165
161
  };
166
162
  try {
@@ -170,7 +166,7 @@ export class HttpTransport {
170
166
  // The server processed none of it: send it once more, on the connection that replaces the
171
167
  // one that refused it, under the same timeout and signal (CLIENT-HTTP-UNPROCESSED-RESEND).
172
168
  // A stream body was consumed by the refused attempt: it is never sent again.
173
- if (!unprocessed(error) || control.signal.aborted || binary?.once === true) {
169
+ if (!unprocessed(error) || control.signal.aborted || binary?.kind === 'once') {
174
170
  throw error;
175
171
  }
176
172
  return this.fetchImpl(this.url, init);
@@ -1,2 +1,2 @@
1
1
  export type { RequestOptions, DeploymentRetired, MissControl, StaleControl, Transport, TransportRequest, TransportResult, } from './transport.js';
2
- export { asError, controlledSignal, positiveInteger, requireLive, type ControlledSignal, } from './deadline.js';
2
+ export { asError, controlledSignal, pause, positiveInteger, requireLive, type ControlledSignal, } from './deadline.js';
@@ -1 +1 @@
1
- export { asError, controlledSignal, positiveInteger, requireLive, } from './deadline.js';
1
+ export { asError, controlledSignal, pause, positiveInteger, requireLive, } from './deadline.js';
@@ -0,0 +1,7 @@
1
+ import type * as protocol from '@astrale-os/kernel-protocol/invocation';
2
+ import type { TransportResult } from './transport.js';
3
+ import { ResponseError } from '../errors/index.js';
4
+ /** The application error one decoded error response carries. */
5
+ export declare function responseError(response: protocol.ErrorResponse): ResponseError;
6
+ /** The Transport result of one decoded unary response that carries no application error. */
7
+ export declare function unaryResult(response: Exclude<protocol.Response, protocol.ErrorResponse>): TransportResult;
@@ -0,0 +1,34 @@
1
+ import { ResponseError } from '../errors/index.js';
2
+ /** The application error one decoded error response carries. */
3
+ export function responseError(response) {
4
+ return new ResponseError(response.error.code, response.error.message, response.invocation, response.error.data);
5
+ }
6
+ /** The Transport result of one decoded unary response that carries no application error. */
7
+ export function unaryResult(response) {
8
+ if ('kind' in response) {
9
+ if (response.kind === 'redirect') {
10
+ return Object.freeze({
11
+ kind: 'redirect',
12
+ invocation: response.invocation,
13
+ redirect: response.redirect,
14
+ });
15
+ }
16
+ if (response.kind === 'stale') {
17
+ return Object.freeze({
18
+ kind: 'stale',
19
+ current: response.current,
20
+ invocation: response.invocation,
21
+ });
22
+ }
23
+ return Object.freeze({ kind: 'miss', invocation: response.invocation });
24
+ }
25
+ if ('execution' in response) {
26
+ return {
27
+ kind: 'execution',
28
+ execution: response.execution,
29
+ ...(response.replayed === undefined ? {} : { replayed: response.replayed }),
30
+ invocation: response.invocation,
31
+ };
32
+ }
33
+ return { kind: 'value', value: response.result, invocation: response.invocation };
34
+ }
@@ -2,7 +2,7 @@ import * as protocol from '@astrale-os/kernel-protocol/invocation';
2
2
  import { ProtocolError } from '../../errors/index.js';
3
3
  import { invocationFailure } from '../failure.js';
4
4
  import { asError } from '../index.js';
5
- import { WebSocketExchange } from './exchange.js';
5
+ import { isKind, WebSocketExchange } from './exchange.js';
6
6
  const WS_CONNECTING = 0;
7
7
  const WS_OPEN = 1;
8
8
  export class WebSocketConnection {
@@ -268,12 +268,6 @@ function isStreamFrame(input) {
268
268
  : undefined;
269
269
  return typeof kind === 'string' && kind.startsWith('stream.');
270
270
  }
271
- function isKind(input, kind) {
272
- return (typeof input === 'object' &&
273
- input !== null &&
274
- !Array.isArray(input) &&
275
- input.kind === kind);
276
- }
277
271
  function requestKey(requestId) {
278
272
  return requestId === null ? 'null:' : `${typeof requestId}:${String(requestId)}`;
279
273
  }
@@ -44,3 +44,5 @@ export declare class WebSocketExchange implements Stream {
44
44
  private flushTerminal;
45
45
  private abortFailure;
46
46
  }
47
+ /** Whether `input` is a plain object whose `kind` is `kind`. */
48
+ export declare function isKind(input: unknown, kind: string): boolean;
@@ -2,6 +2,7 @@ import * as errors from '@astrale-os/kernel-protocol/errors';
2
2
  import { ProtocolError, ResponseError } from '../../errors/index.js';
3
3
  import { invocationFailure } from '../failure.js';
4
4
  import { asError } from '../index.js';
5
+ import { responseError, unaryResult } from '../unary.js';
5
6
  /** One correlated invocation within a multiplexed WebSocket connection. */
6
7
  export class WebSocketExchange {
7
8
  owner;
@@ -115,54 +116,22 @@ export class WebSocketExchange {
115
116
  });
116
117
  return;
117
118
  }
118
- if (isKind(input, 'stream.start')) {
119
- const start = input;
120
- requireId(this.requestId, start.requestId);
121
- if (start.kind !== 'stream.start')
119
+ if (isStreamFrame(input)) {
120
+ requireId(this.requestId, input.requestId);
121
+ if (input.kind !== 'stream.start') {
122
122
  throw new ProtocolError('stream did not begin with stream.start.');
123
+ }
123
124
  this.state = 'stream';
124
- this.invocation = start.invocation;
125
- this.resolveResult({ kind: 'stream', stream: this, invocation: start.invocation });
126
- return;
127
- }
128
- if (isKind(input, 'redirect')) {
129
- const response = input;
130
- requireId(this.requestId, response.requestId);
131
- this.complete({
132
- kind: 'redirect',
133
- invocation: response.invocation,
134
- redirect: response.redirect,
135
- });
136
- return;
137
- }
138
- if (isKind(input, 'stale')) {
139
- const stale = input;
140
- requireId(this.requestId, stale.requestId);
141
- this.complete(Object.freeze({ kind: 'stale', current: stale.current, invocation: stale.invocation }));
142
- return;
143
- }
144
- if (isKind(input, 'miss')) {
145
- const miss = input;
146
- requireId(this.requestId, miss.requestId);
147
- this.complete(Object.freeze({ kind: 'miss', invocation: miss.invocation }));
125
+ this.invocation = input.invocation;
126
+ this.resolveResult({ kind: 'stream', stream: this, invocation: input.invocation });
148
127
  return;
149
128
  }
150
129
  const response = input;
151
130
  requireId(this.requestId, response.requestId);
152
- if ('error' in response) {
153
- this.reject(new ResponseError(response.error.code, response.error.message, response.invocation, response.error.data));
154
- return;
155
- }
156
- if ('execution' in response) {
157
- this.complete({
158
- kind: 'execution',
159
- execution: response.execution,
160
- ...(response.replayed === undefined ? {} : { replayed: response.replayed }),
161
- invocation: response.invocation,
162
- });
163
- return;
164
- }
165
- this.complete({ kind: 'value', value: response.result, invocation: response.invocation });
131
+ if ('error' in response)
132
+ this.reject(responseError(response));
133
+ else
134
+ this.complete(unaryResult(response));
166
135
  }
167
136
  receiveStreamFrame(frame) {
168
137
  requireId(this.requestId, frame.requestId);
@@ -305,7 +274,8 @@ function requireId(expected, received) {
305
274
  function isStreamFrame(input) {
306
275
  return 'kind' in input && typeof input.kind === 'string' && input.kind.startsWith('stream.');
307
276
  }
308
- function isKind(input, kind) {
277
+ /** Whether `input` is a plain object whose `kind` is `kind`. */
278
+ export function isKind(input, kind) {
309
279
  return (typeof input === 'object' &&
310
280
  input !== null &&
311
281
  !Array.isArray(input) &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrale-os/kernel-client",
3
- "version": "1.0.0-beta.22",
3
+ "version": "1.0.0-beta.24",
4
4
  "description": "Universal Client — protocol-first, transport-agnostic",
5
5
  "keywords": [
6
6
  "astrale",
@@ -65,13 +65,13 @@
65
65
  "access": "public"
66
66
  },
67
67
  "dependencies": {
68
- "@astrale-os/kernel-core": "1.0.0-beta.19",
69
- "@astrale-os/kernel-dsl": "1.0.0-beta.12",
70
- "@astrale-os/kernel-protocol": "1.0.0-beta.19",
68
+ "@astrale-os/kernel-core": "1.0.0-beta.21",
69
+ "@astrale-os/kernel-dsl": "1.0.0-beta.14",
70
+ "@astrale-os/kernel-protocol": "1.0.0-beta.21",
71
71
  "@tanstack/pacer": "0.20.1"
72
72
  },
73
73
  "devDependencies": {
74
- "@astrale-os/kernel-server": "1.0.0-beta.19",
74
+ "@astrale-os/kernel-server": "1.0.0-beta.21",
75
75
  "@astrale/typescript-config": "npm:@jsr/astrale__typescript-config@~1.1.0",
76
76
  "@types/node": "^22.0.0",
77
77
  "typescript": "7.0.2",