@astrale-os/kernel-client 1.0.0-beta.27 → 1.0.0-beta.29
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.
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/errors/response-too-large-error.d.ts +11 -0
- package/dist/errors/response-too-large-error.js +15 -0
- package/dist/transport/failure.js +7 -1
- package/dist/transport/http/binary.js +2 -2
- package/dist/transport/http/byte-stream.js +2 -1
- package/dist/transport/http/response.d.ts +3 -0
- package/dist/transport/http/response.js +7 -3
- package/dist/transport/http/stream.js +2 -2
- package/package.json +5 -5
package/dist/errors/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './protocol-error.js';
|
|
|
5
5
|
export * from './query-input.js';
|
|
6
6
|
export * from './refusal.js';
|
|
7
7
|
export * from './response-error.js';
|
|
8
|
+
export * from './response-too-large-error.js';
|
|
8
9
|
export * from './session-error.js';
|
|
9
10
|
export * from './stale-route-error.js';
|
|
10
11
|
export * from './transport-error.js';
|
package/dist/errors/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export * from './protocol-error.js';
|
|
|
5
5
|
export * from './query-input.js';
|
|
6
6
|
export * from './refusal.js';
|
|
7
7
|
export * from './response-error.js';
|
|
8
|
+
export * from './response-too-large-error.js';
|
|
8
9
|
export * from './session-error.js';
|
|
9
10
|
export * from './stale-route-error.js';
|
|
10
11
|
export * from './transport-error.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ProtocolError, type ProtocolErrorOptions } from './protocol-error.js';
|
|
2
|
+
/**
|
|
3
|
+
* The answer to one invocation, a body, a streamed binary or one frame of a stream, is larger than
|
|
4
|
+
* the client's `maximumResponseBytes`, and the client stopped reading it. A WebSocket frame past
|
|
5
|
+
* the bound names no request the client could read, so it ends its connection instead.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ResponseTooLargeError extends ProtocolError {
|
|
8
|
+
/** The bound the answer passed, in bytes. */
|
|
9
|
+
readonly maximumResponseBytes: number;
|
|
10
|
+
constructor(message: string, maximumResponseBytes: number, options?: ProtocolErrorOptions);
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ProtocolError } from './protocol-error.js';
|
|
2
|
+
/**
|
|
3
|
+
* The answer to one invocation, a body, a streamed binary or one frame of a stream, is larger than
|
|
4
|
+
* the client's `maximumResponseBytes`, and the client stopped reading it. A WebSocket frame past
|
|
5
|
+
* the bound names no request the client could read, so it ends its connection instead.
|
|
6
|
+
*/
|
|
7
|
+
export class ResponseTooLargeError extends ProtocolError {
|
|
8
|
+
/** The bound the answer passed, in bytes. */
|
|
9
|
+
maximumResponseBytes;
|
|
10
|
+
constructor(message, maximumResponseBytes, options) {
|
|
11
|
+
super(message, options);
|
|
12
|
+
this.name = 'ResponseTooLargeError';
|
|
13
|
+
this.maximumResponseBytes = maximumResponseBytes;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProtocolError, ResponseError, TransportError, } from '../errors/index.js';
|
|
1
|
+
import { ProtocolError, ResponseError, ResponseTooLargeError, TransportError, } from '../errors/index.js';
|
|
2
2
|
import { asError } from './deadline.js';
|
|
3
3
|
/** Create invocation transport evidence with the common not-sent default. */
|
|
4
4
|
export function invocationFailure(message, phase, evidence = {}) {
|
|
@@ -49,6 +49,12 @@ export function requestFailure(input, control, stop) {
|
|
|
49
49
|
export function withInvocation(input, invocation) {
|
|
50
50
|
if (invocation === undefined)
|
|
51
51
|
return input;
|
|
52
|
+
if (input instanceof ResponseTooLargeError && input.invocation === undefined) {
|
|
53
|
+
return new ResponseTooLargeError(input.message, input.maximumResponseBytes, {
|
|
54
|
+
cause: input,
|
|
55
|
+
invocation,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
52
58
|
if (input instanceof ProtocolError && input.invocation === undefined) {
|
|
53
59
|
return new ProtocolError(input.message, { cause: input, invocation });
|
|
54
60
|
}
|
|
@@ -3,7 +3,7 @@ import * as protocol from '@astrale-os/kernel-protocol/invocation';
|
|
|
3
3
|
import { ProtocolError } from '../../errors/index.js';
|
|
4
4
|
import { requireLive } from '../index.js';
|
|
5
5
|
import { HttpByteStream } from './byte-stream.js';
|
|
6
|
-
import { binaryHeaders, decodeProtocol, readBoundedBody } from './response.js';
|
|
6
|
+
import { binaryHeaders, decodeProtocol, readBoundedBody, tooLarge, } from './response.js';
|
|
7
7
|
/** Admit buffered or streaming binary output within the invocation's lifetime. */
|
|
8
8
|
export async function decodeBinary(response, requestId, binaryId, streaming, context) {
|
|
9
9
|
const { control, maximumBytes } = context;
|
|
@@ -29,7 +29,7 @@ export async function decodeBinary(response, requestId, binaryId, streaming, con
|
|
|
29
29
|
throw new ProtocolError(`streaming binary has an invalid ${protocol.http.BINARY_LENGTH_FIELD}.`);
|
|
30
30
|
}
|
|
31
31
|
if (expectedBytes !== undefined && expectedBytes > maximumBytes) {
|
|
32
|
-
throw
|
|
32
|
+
throw tooLarge('streaming binary', maximumBytes);
|
|
33
33
|
}
|
|
34
34
|
requireLive(control);
|
|
35
35
|
return {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ProtocolError } from '../../errors/index.js';
|
|
2
2
|
import { abortFailure } from '../failure.js';
|
|
3
|
+
import { tooLarge } from './response.js';
|
|
3
4
|
/** Single-consumer HTTP byte stream preserving invocation lifetime and backpressure. */
|
|
4
5
|
export class HttpByteStream {
|
|
5
6
|
maximumBytes;
|
|
@@ -67,7 +68,7 @@ export class HttpByteStream {
|
|
|
67
68
|
throw new ProtocolError(`streaming binary exceeded its declared length (${this.expectedBytes}).`);
|
|
68
69
|
}
|
|
69
70
|
if (this.bytes > this.maximumBytes) {
|
|
70
|
-
throw
|
|
71
|
+
throw tooLarge('streaming binary', this.maximumBytes);
|
|
71
72
|
}
|
|
72
73
|
return { done: false, value: new Uint8Array(next.value) };
|
|
73
74
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as codecs from '@astrale-os/kernel-protocol/codecs';
|
|
2
2
|
import * as protocol from '@astrale-os/kernel-protocol/invocation';
|
|
3
|
+
import { ResponseTooLargeError } from '../../errors/index.js';
|
|
3
4
|
import { type ControlledSignal } from '../index.js';
|
|
4
5
|
/** The body budget and cancellation lifetime shared by all response representations. */
|
|
5
6
|
export interface ResponseContext {
|
|
@@ -8,6 +9,8 @@ export interface ResponseContext {
|
|
|
8
9
|
}
|
|
9
10
|
export declare function codecForResponse(contentType: string | null): codecs.Codec | undefined;
|
|
10
11
|
export declare function readBoundedBody(response: Response, maximumBytes: number, signal: AbortSignal): Promise<Uint8Array>;
|
|
12
|
+
/** The failure of an answer that passed the client's `maximumResponseBytes`. */
|
|
13
|
+
export declare function tooLarge(what: string, maximumBytes: number): ResponseTooLargeError;
|
|
11
14
|
export declare function requireId(expected: protocol.RequestId, received: protocol.RequestId): void;
|
|
12
15
|
export declare function decodeProtocol<T>(label: string, decode: () => T): T;
|
|
13
16
|
export declare function binaryHeaders(input: Headers, names: readonly string[]): Readonly<Record<string, string>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as codecs from '@astrale-os/kernel-protocol/codecs';
|
|
2
2
|
import * as protocol from '@astrale-os/kernel-protocol/invocation';
|
|
3
|
-
import { ProtocolError, ResponseError } from '../../errors/index.js';
|
|
3
|
+
import { ProtocolError, ResponseError, ResponseTooLargeError } from '../../errors/index.js';
|
|
4
4
|
import { asError } from '../index.js';
|
|
5
5
|
export function codecForResponse(contentType) {
|
|
6
6
|
return protocol.http.codecForContentType(contentType, [codecs.json]);
|
|
@@ -8,7 +8,7 @@ export function codecForResponse(contentType) {
|
|
|
8
8
|
export async function readBoundedBody(response, maximumBytes, signal) {
|
|
9
9
|
const declared = response.headers.get('content-length');
|
|
10
10
|
if (declared !== null && Number(declared) > maximumBytes) {
|
|
11
|
-
throw
|
|
11
|
+
throw tooLarge('response', maximumBytes);
|
|
12
12
|
}
|
|
13
13
|
if (response.body === null)
|
|
14
14
|
return new Uint8Array();
|
|
@@ -24,7 +24,7 @@ export async function readBoundedBody(response, maximumBytes, signal) {
|
|
|
24
24
|
break;
|
|
25
25
|
total += next.value.byteLength;
|
|
26
26
|
if (total > maximumBytes) {
|
|
27
|
-
throw
|
|
27
|
+
throw tooLarge('response', maximumBytes);
|
|
28
28
|
}
|
|
29
29
|
chunks.push(next.value);
|
|
30
30
|
}
|
|
@@ -41,6 +41,10 @@ export async function readBoundedBody(response, maximumBytes, signal) {
|
|
|
41
41
|
}
|
|
42
42
|
return output;
|
|
43
43
|
}
|
|
44
|
+
/** The failure of an answer that passed the client's `maximumResponseBytes`. */
|
|
45
|
+
export function tooLarge(what, maximumBytes) {
|
|
46
|
+
return new ResponseTooLargeError(`${what} exceeds maximumResponseBytes (${maximumBytes}).`, maximumBytes);
|
|
47
|
+
}
|
|
44
48
|
export function requireId(expected, received) {
|
|
45
49
|
if (received !== expected) {
|
|
46
50
|
throw new ProtocolError(`response id ${JSON.stringify(received)} does not match request id ${JSON.stringify(expected)}.`);
|
|
@@ -2,7 +2,7 @@ import * as protocol from '@astrale-os/kernel-protocol/invocation';
|
|
|
2
2
|
import { ProtocolError } from '../../errors/index.js';
|
|
3
3
|
import { abortFailure, withInvocation } from '../failure.js';
|
|
4
4
|
import { FrameStream } from '../stream.js';
|
|
5
|
-
import { decodeProtocol, requireId } from './response.js';
|
|
5
|
+
import { decodeProtocol, requireId, tooLarge } from './response.js';
|
|
6
6
|
/** The HTTP binding of one value stream: reads its length-prefixed frames as its consumer reads. */
|
|
7
7
|
export class HttpStream {
|
|
8
8
|
frames;
|
|
@@ -118,7 +118,7 @@ class LengthPrefixedFrames {
|
|
|
118
118
|
return null;
|
|
119
119
|
const length = new DataView(header.buffer, header.byteOffset, header.byteLength).getUint32(0);
|
|
120
120
|
if (length > this.maximumFrameBytes) {
|
|
121
|
-
throw
|
|
121
|
+
throw tooLarge('stream frame', this.maximumFrameBytes);
|
|
122
122
|
}
|
|
123
123
|
return (await this.take(length, false));
|
|
124
124
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrale-os/kernel-client",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.29",
|
|
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.
|
|
69
|
-
"@astrale-os/kernel-dsl": "1.0.0-beta.
|
|
70
|
-
"@astrale-os/kernel-protocol": "1.0.0-beta.
|
|
68
|
+
"@astrale-os/kernel-core": "1.0.0-beta.26",
|
|
69
|
+
"@astrale-os/kernel-dsl": "1.0.0-beta.18",
|
|
70
|
+
"@astrale-os/kernel-protocol": "1.0.0-beta.26",
|
|
71
71
|
"@tanstack/pacer": "0.20.1"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@astrale-os/kernel-server": "1.0.0-beta.
|
|
74
|
+
"@astrale-os/kernel-server": "1.0.0-beta.26",
|
|
75
75
|
"@astrale/typescript-config": "npm:@jsr/astrale__typescript-config@~1.1.0",
|
|
76
76
|
"@types/node": "^22.0.0",
|
|
77
77
|
"esbuild": "0.28.1",
|