Revert the revert of G's mesh-sdk merge (#191): G's sdk stands again over reader release 3
Main reverted G's half merge (#189, reverted by8afc3ebin #191) and then took the reader release's S1-S5, which copied G's code. G's form holds where they differ (process_bus.go, seats.go, state.go and their tests); the release's kept names stay so main's callers keep building: SeatViewPrefix beside SeatReadPrefix, and QueueInvoke's empty strings on not-ok (with its test TestQueueInvoke). The tree differs from G's headf30dee54only by those and the release's two tests (objects cap option, seat states and stream kinds). Builds: design 47 G (the milestone's sdk part, as atf30dee54) Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
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 });
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user