Milestone 47 G: mesh-sdk's part of the one release #189

Merged
mesh-tools merged 166 commits from feat/47-G-join11 into main 2026-11-13 10:00:28 +00:00
2 changed files with 20 additions and 2 deletions
Showing only changes of commit 0319b4c309 - Show all commits
+15 -2
View File
@@ -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 });
},
+5
View File
@@ -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/);
});