G §643: a TypeScript bundle's value over one call's limit fails at once, naming the limit
Builds: design 47 G §643, §518, A-21 Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
This commit is contained in:
+15
-2
@@ -122,6 +122,17 @@ function refusedUnannounced(name: string): void {
|
||||
}
|
||||
}
|
||||
|
||||
/** The size of one chunk of the Go side's put and get sessions, the most a call carries (design 47 G §518, A-21). */
|
||||
export const CHUNK_BYTES = 512 * 1024;
|
||||
|
||||
/** A TypeScript bundle runs no put or get session in G (design 47 G §643): a value over one call's limit fails at once, naming it. */
|
||||
function withinOneCall(key: string, value: unknown): void {
|
||||
const size = Buffer.byteLength(JSON.stringify(value) ?? "");
|
||||
if (size > CHUNK_BYTES) {
|
||||
throw new Error(`the value of "${key}" is ${size} bytes, over the ${CHUNK_BYTES} bytes (512 KiB) one call carries: a TypeScript bundle puts no value larger than that`);
|
||||
}
|
||||
}
|
||||
|
||||
/** A state this module keeps (by its local name) or reads (`<module>.<name>`). */
|
||||
export function state<T = unknown>(name: string): State<T> {
|
||||
const bound = (): StateChannel => {
|
||||
@@ -130,8 +141,10 @@ export function state<T = unknown>(name: string): State<T> {
|
||||
};
|
||||
return {
|
||||
get: async (key) => (await bound().ask("mesh/state.get", { state: name, key })) as StateEntry<T> | null,
|
||||
put: async (key, value) =>
|
||||
((await bound().ask("mesh/state.put", { state: name, key, value })) as { revision: number }).revision,
|
||||
put: async (key, value) => {
|
||||
withinOneCall(key, value);
|
||||
return ((await bound().ask("mesh/state.put", { state: name, key, value })) as { revision: number }).revision;
|
||||
},
|
||||
delete: async (key) => {
|
||||
await bound().ask("mesh/state.delete", { state: name, key });
|
||||
},
|
||||
|
||||
@@ -1005,3 +1005,8 @@ test("a bundle reads its tool runner's capability words once, reads an unknown c
|
||||
if (was === undefined) delete process.env.MESH_NODE;
|
||||
else process.env.MESH_NODE = was;
|
||||
});
|
||||
|
||||
test("a TypeScript bundle's value over one call's limit fails at once, naming the limit (design 47 G §643)", async () => {
|
||||
const { state, CHUNK_BYTES } = await import("../dist/state/index.js");
|
||||
await assert.rejects(state("s").put("k", { text: "x".repeat(CHUNK_BYTES) }), /512 KiB/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user