@astrale-os/kernel-client 1.0.0-beta.47 → 1.0.0-beta.49
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/session/context/index.d.ts +1 -1
- package/dist/session/context/index.js +1 -1
- package/dist/session/context/policy.d.ts +2 -0
- package/dist/session/context/policy.js +6 -3
- package/dist/session/discovery/bundle.d.ts +4 -0
- package/dist/session/discovery/bundle.js +61 -5
- package/dist/session/discovery/index.d.ts +1 -0
- package/dist/session/discovery/index.js +5 -1
- package/dist/session/discovery/release.d.ts +2 -0
- package/dist/session/discovery/release.js +17 -4
- package/dist/session/discovery/response.d.ts +4 -0
- package/dist/session/discovery/response.js +10 -6
- package/dist/session/discovery/transport.d.ts +3 -1
- package/dist/session/discovery/transport.js +27 -5
- package/dist/session/options.d.ts +4 -0
- package/dist/session/options.js +3 -0
- package/dist/session/session.js +3 -2
- package/package.json +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { admitControlOptions, type SessionControlOptions } from './control.js';
|
|
2
2
|
export { DEFAULT_MAXIMUM_BUNDLE_BYTES, DEFAULT_MAXIMUM_RELEASE_BYTES, DEFAULT_MAXIMUM_RESPONSE_BYTES, DEFAULT_MAXIMUM_ROUTES, DEFAULT_TIMEOUT_MS, platformDuration, positive, } from './limits.js';
|
|
3
3
|
export { createSessionOperation, pauseSessionOperation, remainingSessionTime, runSessionOperation, sessionTransportOptions, type SessionOperation, } from './operation.js';
|
|
4
|
-
export { admitKernel, admitPolicy, allowEndpoint, kernelInvocationEndpoint, type SessionPolicy, } from './policy.js';
|
|
4
|
+
export { admitKernel, admitPolicy, allowEndpoint, endpointAllowed, kernelInvocationEndpoint, type SessionPolicy, } from './policy.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { admitControlOptions } from './control.js';
|
|
2
2
|
export { DEFAULT_MAXIMUM_BUNDLE_BYTES, DEFAULT_MAXIMUM_RELEASE_BYTES, DEFAULT_MAXIMUM_RESPONSE_BYTES, DEFAULT_MAXIMUM_ROUTES, DEFAULT_TIMEOUT_MS, platformDuration, positive, } from './limits.js';
|
|
3
3
|
export { createSessionOperation, pauseSessionOperation, remainingSessionTime, runSessionOperation, sessionTransportOptions, } from './operation.js';
|
|
4
|
-
export { admitKernel, admitPolicy, allowEndpoint, kernelInvocationEndpoint, } from './policy.js';
|
|
4
|
+
export { admitKernel, admitPolicy, allowEndpoint, endpointAllowed, kernelInvocationEndpoint, } from './policy.js';
|
|
@@ -8,3 +8,5 @@ export declare function admitPolicy(input: SessionPolicy): Readonly<SessionPolic
|
|
|
8
8
|
export declare function admitKernel(input: string, insecure: boolean): IssuerId;
|
|
9
9
|
export declare function kernelInvocationEndpoint(input: IssuerId): string;
|
|
10
10
|
export declare function allowEndpoint(url: string, policy: Readonly<SessionPolicy>): void;
|
|
11
|
+
/** Apply transport policy and ask whether the caller allows this exact URL. */
|
|
12
|
+
export declare function endpointAllowed(url: string, policy: Readonly<SessionPolicy>): boolean;
|
|
@@ -40,6 +40,11 @@ export function kernelInvocationEndpoint(input) {
|
|
|
40
40
|
return `${input}/invoke`;
|
|
41
41
|
}
|
|
42
42
|
export function allowEndpoint(url, policy) {
|
|
43
|
+
if (!endpointAllowed(url, policy))
|
|
44
|
+
throw new ClientError('Endpoint is denied by Session policy.');
|
|
45
|
+
}
|
|
46
|
+
/** Apply transport policy and ask whether the caller allows this exact URL. */
|
|
47
|
+
export function endpointAllowed(url, policy) {
|
|
43
48
|
const parsed = new URL(url);
|
|
44
49
|
if (parsed.protocol !== 'https:' && parsed.protocol !== 'wss:') {
|
|
45
50
|
if ((parsed.protocol !== 'http:' && parsed.protocol !== 'ws:') ||
|
|
@@ -47,7 +52,5 @@ export function allowEndpoint(url, policy) {
|
|
|
47
52
|
throw new ClientError('Insecure or unsupported endpoint is not allowed.');
|
|
48
53
|
}
|
|
49
54
|
}
|
|
50
|
-
|
|
51
|
-
throw new ClientError('Endpoint is denied by Session policy.');
|
|
52
|
-
}
|
|
55
|
+
return policy.allowEndpoint?.(parsed.toString()) !== false;
|
|
53
56
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { bundle } from '@astrale-os/kernel-dsl/v1';
|
|
2
2
|
import type { DomainRelease } from '@astrale-os/kernel-protocol/release';
|
|
3
|
+
import { type CompactBundleHint } from '@astrale-os/kernel-protocol/release';
|
|
3
4
|
import type { Fetch } from '../../transport/http/index.js';
|
|
4
5
|
import type { SessionOperation, SessionPolicy } from '../context/index.js';
|
|
5
6
|
import { ClientError } from '../../errors/index.js';
|
|
@@ -7,6 +8,8 @@ interface BundleDiscoveryOptions {
|
|
|
7
8
|
readonly fetch: Fetch;
|
|
8
9
|
readonly policy: Readonly<SessionPolicy>;
|
|
9
10
|
readonly maximumBytes: number;
|
|
11
|
+
readonly maximumLogicalBytes: number;
|
|
12
|
+
readonly hintFor: (release: DomainRelease) => CompactBundleHint | undefined;
|
|
10
13
|
}
|
|
11
14
|
/** A Release's Bundle, or evidence that its digest-addressed artifact is no longer served. */
|
|
12
15
|
export type BundleRead = {
|
|
@@ -23,5 +26,6 @@ export declare class BundleDiscovery {
|
|
|
23
26
|
get(release: DomainRelease, operation: SessionOperation): Promise<BundleRead>;
|
|
24
27
|
clear(): void;
|
|
25
28
|
private fetch;
|
|
29
|
+
private compact;
|
|
26
30
|
}
|
|
27
31
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { bundleUrl, decodeBundle } from '@astrale-os/kernel-protocol/release';
|
|
1
|
+
import { bundleUrl, COMPACT_BUNDLE_MEDIA_TYPE, decodeBundle, decodeCompactBundle, isCompactBundleRepresentationError, verifyBundleInventory, } from '@astrale-os/kernel-protocol/release';
|
|
2
2
|
import { ClientError } from '../../errors/index.js';
|
|
3
|
-
import { allowEndpoint } from '../context/index.js';
|
|
3
|
+
import { allowEndpoint, endpointAllowed } from '../context/index.js';
|
|
4
|
+
import { DocumentRepresentationError } from './response.js';
|
|
4
5
|
import { fetchDocument } from './transport.js';
|
|
5
6
|
export class BundleDiscovery {
|
|
6
7
|
options;
|
|
@@ -11,11 +12,17 @@ export class BundleDiscovery {
|
|
|
11
12
|
async get(release, operation) {
|
|
12
13
|
const key = bundleKey(release);
|
|
13
14
|
allowEndpoint(release.schema.bundle.href, this.options.policy);
|
|
14
|
-
if (this.retained?.key === key)
|
|
15
|
-
|
|
15
|
+
if (this.retained?.key === key) {
|
|
16
|
+
const { value } = this.retained;
|
|
17
|
+
if (this.retained.release !== release.digest) {
|
|
18
|
+
verifyBundleInventory(release, value);
|
|
19
|
+
this.retained = { key, release: release.digest, value };
|
|
20
|
+
}
|
|
21
|
+
return { kind: 'bundle', bundle: value };
|
|
22
|
+
}
|
|
16
23
|
const read = await this.fetch(release, operation);
|
|
17
24
|
if (read.kind === 'bundle')
|
|
18
|
-
this.retained = { key, value: read.bundle };
|
|
25
|
+
this.retained = { key, release: release.digest, value: read.bundle };
|
|
19
26
|
return read;
|
|
20
27
|
}
|
|
21
28
|
clear() {
|
|
@@ -23,6 +30,22 @@ export class BundleDiscovery {
|
|
|
23
30
|
}
|
|
24
31
|
async fetch(release, operation) {
|
|
25
32
|
const { href, ref } = release.schema.bundle;
|
|
33
|
+
if (ref.size > this.options.maximumLogicalBytes) {
|
|
34
|
+
throw new ClientError('Bundle artifact exceeds its byte limit.');
|
|
35
|
+
}
|
|
36
|
+
const hint = this.options.hintFor(release);
|
|
37
|
+
if (hint !== undefined && endpointAllowed(hint.href, this.options.policy)) {
|
|
38
|
+
try {
|
|
39
|
+
const result = await this.compact(release, hint, operation);
|
|
40
|
+
if (result.kind === 'bundle' || ref.size > this.options.maximumBytes)
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
const unusable = error instanceof DocumentRepresentationError || isCompactBundleRepresentationError(error);
|
|
45
|
+
if (!unusable || ref.size > this.options.maximumBytes)
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
26
49
|
if (ref.size > this.options.maximumBytes) {
|
|
27
50
|
throw new ClientError('Bundle artifact exceeds its byte limit.');
|
|
28
51
|
}
|
|
@@ -51,6 +74,39 @@ export class BundleDiscovery {
|
|
|
51
74
|
}
|
|
52
75
|
return { kind: 'bundle', bundle: decodeBundle(release, bytes) };
|
|
53
76
|
}
|
|
77
|
+
async compact(release, hint, operation) {
|
|
78
|
+
const fetched = await fetchDocument(operation, this.options.fetch, {
|
|
79
|
+
resource: 'bundle',
|
|
80
|
+
label: 'Compact Bundle retrieval',
|
|
81
|
+
status: 200,
|
|
82
|
+
url: hint.href,
|
|
83
|
+
mediaType: COMPACT_BUNDLE_MEDIA_TYPE,
|
|
84
|
+
mediaTypeMismatch: 'Compact Bundle response media type differs from its advertisement.',
|
|
85
|
+
maximumBytes: this.options.maximumBytes,
|
|
86
|
+
notModified: false,
|
|
87
|
+
unavailable: [404, 410],
|
|
88
|
+
});
|
|
89
|
+
if (fetched.kind !== 'document')
|
|
90
|
+
return fetched;
|
|
91
|
+
const etag = fetched.headers.get('etag');
|
|
92
|
+
const encoding = fetched.headers.get('content-encoding');
|
|
93
|
+
if ((etag !== null && etag !== `"${hint.digest}"`) ||
|
|
94
|
+
(encoding !== null && encoding.toLowerCase() !== 'identity')) {
|
|
95
|
+
fetched.discard();
|
|
96
|
+
throw new DocumentRepresentationError('Compact Bundle response validators or encoding differ from its advertisement.');
|
|
97
|
+
}
|
|
98
|
+
const bytes = await fetched.read();
|
|
99
|
+
const length = fetched.headers.get('content-length');
|
|
100
|
+
if (length !== null && (!/^\d+$/u.test(length) || Number(length) !== bytes.byteLength)) {
|
|
101
|
+
throw new DocumentRepresentationError('Compact Bundle size differs from its Content-Length.');
|
|
102
|
+
}
|
|
103
|
+
const physical = {
|
|
104
|
+
digest: hint.digest,
|
|
105
|
+
mediaType: COMPACT_BUNDLE_MEDIA_TYPE,
|
|
106
|
+
size: bytes.byteLength,
|
|
107
|
+
};
|
|
108
|
+
return { kind: 'bundle', bundle: await decodeCompactBundle(release, physical, bytes) };
|
|
109
|
+
}
|
|
54
110
|
}
|
|
55
111
|
function bundleKey(release) {
|
|
56
112
|
const { href, ref } = release.schema.bundle;
|
|
@@ -19,6 +19,7 @@ export interface SessionDiscoveryOptions {
|
|
|
19
19
|
/** Bounds the source Kernel's own `release.json`. */
|
|
20
20
|
readonly maximumReleaseBytes: number;
|
|
21
21
|
readonly maximumBundleBytes: number;
|
|
22
|
+
readonly maximumLogicalBundleBytes?: number;
|
|
22
23
|
readonly requireOpen: () => void;
|
|
23
24
|
readonly acquisitionOperation: () => SessionOperation;
|
|
24
25
|
}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import { defaultLimits } from '@astrale-os/kernel-dsl/value';
|
|
1
2
|
import { BundleDiscovery } from './bundle.js';
|
|
2
3
|
import { SessionDiscovery as SessionDiscoveryImplementation } from './discovery.js';
|
|
3
4
|
import { ReleaseDiscovery } from './release.js';
|
|
4
5
|
export { boundedResponse, requireExactResponse } from './response.js';
|
|
5
6
|
export function createSessionDiscovery(options) {
|
|
6
7
|
const source = { kernel: options.kernel, fetch: options.fetch, policy: options.policy };
|
|
7
|
-
|
|
8
|
+
const releases = new ReleaseDiscovery({ ...source, maximumBytes: options.maximumReleaseBytes });
|
|
9
|
+
return new SessionDiscoveryImplementation(options.kernel, options.policy, releases, new BundleDiscovery({
|
|
8
10
|
fetch: options.fetch,
|
|
9
11
|
policy: options.policy,
|
|
10
12
|
maximumBytes: options.maximumBundleBytes,
|
|
13
|
+
maximumLogicalBytes: Math.min(options.maximumLogicalBundleBytes ?? options.maximumBundleBytes, defaultLimits.maxBytes),
|
|
14
|
+
hintFor: (release) => releases.hintFor(release),
|
|
11
15
|
}), options.requireOpen, options.acquisitionOperation);
|
|
12
16
|
}
|
|
@@ -17,6 +17,8 @@ interface ReleaseDiscoveryOptions {
|
|
|
17
17
|
*/
|
|
18
18
|
export declare class ReleaseDiscovery {
|
|
19
19
|
private readonly options;
|
|
20
|
+
private readonly hints;
|
|
21
|
+
hintFor(release: IntrinsicRelease): release.CompactBundleHint | undefined;
|
|
20
22
|
private release;
|
|
21
23
|
private revision;
|
|
22
24
|
constructor(options: ReleaseDiscoveryOptions);
|
|
@@ -9,6 +9,10 @@ import { fetchDocument } from './transport.js';
|
|
|
9
9
|
*/
|
|
10
10
|
export class ReleaseDiscovery {
|
|
11
11
|
options;
|
|
12
|
+
hints = new WeakMap();
|
|
13
|
+
hintFor(release) {
|
|
14
|
+
return this.hints.get(release);
|
|
15
|
+
}
|
|
12
16
|
release;
|
|
13
17
|
revision = 0;
|
|
14
18
|
constructor(options) {
|
|
@@ -25,7 +29,15 @@ export class ReleaseDiscovery {
|
|
|
25
29
|
const discovered = await this.fetch(operation, previous);
|
|
26
30
|
if (revision !== this.revision)
|
|
27
31
|
return this.revalidate(operation);
|
|
28
|
-
const retained = previous?.digest === discovered.digest ? previous : discovered;
|
|
32
|
+
const retained = previous?.digest === discovered.release.digest ? previous : discovered.release;
|
|
33
|
+
// A 304 updates cached response headers only when the validator actually supplies them.
|
|
34
|
+
if (discovered.link !== undefined) {
|
|
35
|
+
const hint = releaseCodec.compactBundleHint(this.options.kernel, retained.schema.bundle.href, discovered.link);
|
|
36
|
+
if (hint === undefined)
|
|
37
|
+
this.hints.delete(retained);
|
|
38
|
+
else
|
|
39
|
+
this.hints.set(retained, hint);
|
|
40
|
+
}
|
|
29
41
|
this.release = retained;
|
|
30
42
|
return retained;
|
|
31
43
|
}
|
|
@@ -53,10 +65,11 @@ export class ReleaseDiscovery {
|
|
|
53
65
|
if (previous === undefined) {
|
|
54
66
|
throw new ClientError('Release discovery returned an unexpected not-modified response.');
|
|
55
67
|
}
|
|
56
|
-
if (fetched.etag
|
|
68
|
+
if (fetched.headers.has('etag') && fetched.headers.get('etag') !== `"${previous.digest}"`) {
|
|
57
69
|
throw new ClientError('Release not-modified ETag differs from the retained release digest.');
|
|
58
70
|
}
|
|
59
|
-
|
|
71
|
+
const link = fetched.headers.get('link');
|
|
72
|
+
return link === null ? { release: previous } : { release: previous, link };
|
|
60
73
|
}
|
|
61
74
|
const admitted = releaseCodec.accept(codecs.json.decode(await fetched.read()));
|
|
62
75
|
if (admitted.identity.issuer !== this.options.kernel) {
|
|
@@ -66,6 +79,6 @@ export class ReleaseDiscovery {
|
|
|
66
79
|
if (etag !== null && etag !== `"${admitted.digest}"`) {
|
|
67
80
|
throw new ClientError('Release response ETag differs from its release digest.');
|
|
68
81
|
}
|
|
69
|
-
return admitted;
|
|
82
|
+
return { release: admitted, link: fetched.headers.get('link') };
|
|
70
83
|
}
|
|
71
84
|
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { ClientError } from '../../errors/index.js';
|
|
2
|
+
/** A malformed or oversized artifact response whose alternate can be discarded. */
|
|
3
|
+
export declare class DocumentRepresentationError extends ClientError {
|
|
4
|
+
}
|
|
1
5
|
/** Read external bytes within one Session operation's byte and lifetime bounds. */
|
|
2
6
|
export declare function boundedResponse(response: Response, maximum: number, signal: AbortSignal): Promise<Uint8Array>;
|
|
3
7
|
export declare function requireExactResponse(response: Response, expected: string, label: string): void;
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { ClientError } from '../../errors/index.js';
|
|
2
|
+
/** A malformed or oversized artifact response whose alternate can be discarded. */
|
|
3
|
+
export class DocumentRepresentationError extends ClientError {
|
|
4
|
+
}
|
|
2
5
|
/** Read external bytes within one Session operation's byte and lifetime bounds. */
|
|
3
6
|
export async function boundedResponse(response, maximum, signal) {
|
|
4
7
|
const declared = response.headers.get('content-length');
|
|
5
8
|
if (declared !== null) {
|
|
6
9
|
const length = Number(declared);
|
|
7
|
-
if (!Number.isSafeInteger(length) || length
|
|
8
|
-
|
|
10
|
+
if (!/^\d+$/u.test(declared) || !Number.isSafeInteger(length) || length > maximum) {
|
|
11
|
+
void response.body?.cancel().catch(() => undefined);
|
|
12
|
+
throw new DocumentRepresentationError(length > maximum
|
|
13
|
+
? 'Response exceeds its byte limit.'
|
|
14
|
+
: 'Response Content-Length is invalid.');
|
|
9
15
|
}
|
|
10
|
-
if (length > maximum)
|
|
11
|
-
throw new ClientError('Response exceeds its byte limit.');
|
|
12
16
|
}
|
|
13
17
|
if (response.body === null)
|
|
14
18
|
return new Uint8Array();
|
|
@@ -29,8 +33,8 @@ export async function boundedResponse(response, maximum, signal) {
|
|
|
29
33
|
break;
|
|
30
34
|
total += next.value.byteLength;
|
|
31
35
|
if (total > maximum) {
|
|
32
|
-
|
|
33
|
-
throw new
|
|
36
|
+
void reader.cancel('response exceeds byte limit').catch(() => undefined);
|
|
37
|
+
throw new DocumentRepresentationError('Response exceeds its byte limit.');
|
|
34
38
|
}
|
|
35
39
|
chunks.push(next.value);
|
|
36
40
|
}
|
|
@@ -12,6 +12,7 @@ export interface DocumentRequest<NotModified extends boolean = boolean> {
|
|
|
12
12
|
readonly mediaType: string;
|
|
13
13
|
readonly mediaTypeMismatch: string;
|
|
14
14
|
readonly maximumBytes: number;
|
|
15
|
+
readonly status?: 200;
|
|
15
16
|
readonly ifNoneMatch?: string;
|
|
16
17
|
readonly cache?: 'no-cache';
|
|
17
18
|
/** Whether a 304 answers the request instead of failing it. */
|
|
@@ -23,6 +24,7 @@ export interface DocumentRequest<NotModified extends boolean = boolean> {
|
|
|
23
24
|
export type DocumentResponse<NotModified extends boolean = boolean> = {
|
|
24
25
|
readonly kind: 'document';
|
|
25
26
|
readonly headers: Headers;
|
|
27
|
+
discard(): void;
|
|
26
28
|
/** Read the body within the request's byte bound. */
|
|
27
29
|
read(): Promise<Uint8Array>;
|
|
28
30
|
} | {
|
|
@@ -30,7 +32,7 @@ export type DocumentResponse<NotModified extends boolean = boolean> = {
|
|
|
30
32
|
readonly error: ClientError;
|
|
31
33
|
} | (NotModified extends true ? {
|
|
32
34
|
readonly kind: 'not-modified';
|
|
33
|
-
readonly
|
|
35
|
+
readonly headers: Headers;
|
|
34
36
|
} : never);
|
|
35
37
|
/** Fetch one public Session document and admit its exact URL, status and media type. */
|
|
36
38
|
export declare function fetchDocument<NotModified extends boolean>(operation: SessionOperation, fetch: Fetch, request: DocumentRequest<NotModified>): Promise<DocumentResponse<NotModified>>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { canonicalMediaType } from '@astrale-os/kernel-protocol/artifact';
|
|
2
|
+
import { COMPACT_BUNDLE_MEDIA_TYPE } from '@astrale-os/kernel-protocol/release';
|
|
1
3
|
import { ClientError, TransportError } from '../../errors/index.js';
|
|
2
4
|
import { runSessionOperation } from '../context/index.js';
|
|
3
|
-
import { boundedResponse, requireExactResponse } from './response.js';
|
|
5
|
+
import { boundedResponse, DocumentRepresentationError, requireExactResponse } from './response.js';
|
|
4
6
|
/** Fetch one public Session document and admit its exact URL, status and media type. */
|
|
5
7
|
export async function fetchDocument(operation, fetch, request) {
|
|
6
8
|
const { resource, label, url } = request;
|
|
@@ -25,20 +27,40 @@ export async function fetchDocument(operation, fetch, request) {
|
|
|
25
27
|
// `notModified` is true here, so the conditional member is present.
|
|
26
28
|
return {
|
|
27
29
|
kind: 'not-modified',
|
|
28
|
-
|
|
30
|
+
headers: response.headers,
|
|
29
31
|
};
|
|
30
32
|
}
|
|
31
|
-
if (!response.ok)
|
|
33
|
+
if (!response.ok || (request.status !== undefined && response.status !== request.status)) {
|
|
34
|
+
void response.body?.cancel().catch(() => undefined);
|
|
32
35
|
throw new ClientError(status);
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
}
|
|
37
|
+
if (!matchesMediaType(response.headers.get('content-type'), request.mediaType)) {
|
|
38
|
+
void response.body?.cancel().catch(() => undefined);
|
|
39
|
+
throw new DocumentRepresentationError(request.mediaTypeMismatch);
|
|
35
40
|
}
|
|
36
41
|
return {
|
|
37
42
|
kind: 'document',
|
|
38
43
|
headers: response.headers,
|
|
44
|
+
discard: () => {
|
|
45
|
+
void response.body?.cancel().catch(() => undefined);
|
|
46
|
+
},
|
|
39
47
|
read: () => runAcquisition(operation, resource, 'receive', `Kernel ${resource} response could not be read.`, (signal) => boundedResponse(response, request.maximumBytes, signal)),
|
|
40
48
|
};
|
|
41
49
|
}
|
|
50
|
+
function matchesMediaType(actual, expected) {
|
|
51
|
+
if (actual === expected)
|
|
52
|
+
return true;
|
|
53
|
+
if (actual === null || expected !== COMPACT_BUNDLE_MEDIA_TYPE)
|
|
54
|
+
return false;
|
|
55
|
+
try {
|
|
56
|
+
return canonicalMediaType(actual) === expected;
|
|
57
|
+
}
|
|
58
|
+
catch (cause) {
|
|
59
|
+
if (cause instanceof TypeError)
|
|
60
|
+
return false;
|
|
61
|
+
throw cause;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
42
64
|
/** Normalize only unknown failures from one injected acquisition capability. */
|
|
43
65
|
async function runAcquisition(operation, resource, phase, message, task) {
|
|
44
66
|
try {
|
|
@@ -30,7 +30,10 @@ export interface ClientSessionOptions {
|
|
|
30
30
|
readonly onWarning?: (warning: ClientWarning) => void;
|
|
31
31
|
/** Bounds the source Kernel's own `release.json`. */
|
|
32
32
|
readonly maximumReleaseBytes?: number;
|
|
33
|
+
/** Bytes fetched for the selected Bundle representation. */
|
|
33
34
|
readonly maximumBundleBytes?: number;
|
|
35
|
+
/** Maximum decoded Bundle bytes. Defaults to the physical limit, capped at the DSL ceiling. */
|
|
36
|
+
readonly maximumLogicalBundleBytes?: number;
|
|
34
37
|
readonly maximumResponseBytes?: number;
|
|
35
38
|
readonly timeoutMs?: number;
|
|
36
39
|
}
|
|
@@ -42,6 +45,7 @@ export interface SessionConfiguration {
|
|
|
42
45
|
readonly fetch: Fetch;
|
|
43
46
|
readonly maximumReleaseBytes: number;
|
|
44
47
|
readonly maximumBundleBytes: number;
|
|
48
|
+
readonly maximumLogicalBundleBytes: number;
|
|
45
49
|
readonly maximumResponseBytes: number;
|
|
46
50
|
readonly timeoutMs: number;
|
|
47
51
|
readonly websocketAvailable: boolean;
|
package/dist/session/options.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { defaultLimits } from '@astrale-os/kernel-dsl/value';
|
|
1
2
|
import { Client } from '../client/index.js';
|
|
2
3
|
import { ClientPool } from '../pool/index.js';
|
|
3
4
|
import { AutoTransport } from '../transport/auto/index.js';
|
|
@@ -27,6 +28,7 @@ export function acceptSessionOptions(options) {
|
|
|
27
28
|
}
|
|
28
29
|
const maximumReleaseBytes = positive(options.maximumReleaseBytes ?? DEFAULT_MAXIMUM_RELEASE_BYTES, 'maximumReleaseBytes');
|
|
29
30
|
const maximumBundleBytes = positive(options.maximumBundleBytes ?? DEFAULT_MAXIMUM_BUNDLE_BYTES, 'maximumBundleBytes');
|
|
31
|
+
const maximumLogicalBundleBytes = Math.min(defaultLimits.maxBytes, positive(options.maximumLogicalBundleBytes ?? maximumBundleBytes, 'maximumLogicalBundleBytes'));
|
|
30
32
|
const maximumResponseBytes = positive(options.maximumResponseBytes ?? DEFAULT_MAXIMUM_RESPONSE_BYTES, 'maximumResponseBytes');
|
|
31
33
|
const timeoutMs = platformDuration(options.timeoutMs ?? DEFAULT_TIMEOUT_MS, 'timeoutMs');
|
|
32
34
|
let ownedPool;
|
|
@@ -58,6 +60,7 @@ export function acceptSessionOptions(options) {
|
|
|
58
60
|
fetch: fetchImpl,
|
|
59
61
|
maximumReleaseBytes,
|
|
60
62
|
maximumBundleBytes,
|
|
63
|
+
maximumLogicalBundleBytes,
|
|
61
64
|
maximumResponseBytes,
|
|
62
65
|
timeoutMs,
|
|
63
66
|
websocketAvailable: options.client !== undefined ||
|
package/dist/session/session.js
CHANGED
|
@@ -61,6 +61,7 @@ export class ClientSession {
|
|
|
61
61
|
policy,
|
|
62
62
|
maximumReleaseBytes,
|
|
63
63
|
maximumBundleBytes,
|
|
64
|
+
maximumLogicalBundleBytes: settled.maximumLogicalBundleBytes,
|
|
64
65
|
requireOpen: () => this.requireOpen(),
|
|
65
66
|
acquisitionOperation: () => this.operation(undefined),
|
|
66
67
|
});
|
|
@@ -73,7 +74,7 @@ export class ClientSession {
|
|
|
73
74
|
...(auth === undefined ? {} : { auth }),
|
|
74
75
|
fetch,
|
|
75
76
|
policy,
|
|
76
|
-
limits: { maximumReleaseBytes, maximumBundleBytes },
|
|
77
|
+
limits: { maximumReleaseBytes, maximumBundleBytes: settled.maximumLogicalBundleBytes },
|
|
77
78
|
maximumResponseBytes,
|
|
78
79
|
operation: (signal) => this.operation(signal === undefined ? undefined : { signal }),
|
|
79
80
|
});
|
|
@@ -104,7 +105,7 @@ export class ClientSession {
|
|
|
104
105
|
});
|
|
105
106
|
this.schema = createSchema((request, options) => this.dispatch(request, options), {
|
|
106
107
|
maximumReleaseBytes,
|
|
107
|
-
maximumBundleBytes,
|
|
108
|
+
maximumBundleBytes: settled.maximumLogicalBundleBytes,
|
|
108
109
|
});
|
|
109
110
|
this.execution = createExecution((request, options) => this.dispatch(request, options));
|
|
110
111
|
this.graph = createGraph((call, options) => this.call(call, options));
|
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.49",
|
|
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.46",
|
|
69
|
+
"@astrale-os/kernel-dsl": "1.0.0-beta.34",
|
|
70
|
+
"@astrale-os/kernel-protocol": "1.0.0-beta.46",
|
|
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.46",
|
|
75
75
|
"@astrale/typescript-config": "npm:@jsr/astrale__typescript-config@~1.1.0",
|
|
76
76
|
"@types/node": "^24.10.0",
|
|
77
77
|
"esbuild": "0.28.1",
|