@1kbgz/transports 0.4.0 → 0.7.0
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/cdn/index.js +246 -14
- package/dist/cdn/index.js.map +3 -3
- package/dist/cdn/widget.js +661 -0
- package/dist/cdn/widget.js.map +7 -0
- package/dist/esm/index.js +246 -14
- package/dist/esm/index.js.map +3 -3
- package/dist/esm/src/ts/bridge.d.ts +26 -0
- package/dist/esm/src/ts/client.d.ts +99 -0
- package/dist/esm/src/ts/codecs.d.ts +17 -0
- package/dist/esm/src/ts/index.d.ts +31 -0
- package/dist/pkg/transports.d.ts +12 -0
- package/dist/pkg/transports.js +45 -2
- package/dist/pkg/transports_bg.wasm +0 -0
- package/dist/pkg/transports_bg.wasm.d.ts +2 -0
- package/package.json +16 -12
- package/dist/html/index.html +0 -13
package/dist/esm/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../pkg/transports.js", "../../src/ts/bridge.ts", "../../src/ts/codecs.ts", "../../src/ts/client.ts", "../../src/ts/index.ts"],
|
|
4
|
-
"sourcesContent": ["/* @ts-self-types=\"./transports.d.ts\" */\n\n/**\n * In-process model store: host / mutate \u2192 patch / apply / snapshot.\n */\nexport class Store {\n __destroy_into_raw() {\n const ptr = this.__wbg_ptr;\n this.__wbg_ptr = 0;\n StoreFinalization.unregister(this);\n return ptr;\n }\n free() {\n const ptr = this.__destroy_into_raw();\n wasm.__wbg_store_free(ptr, 0);\n }\n /**\n * Apply a JSON patch to a mirrored model; returns whether the id was known.\n * @param {bigint} id\n * @param {string} patch_json\n * @returns {boolean}\n */\n apply(id, patch_json) {\n const ptr0 = passStringToWasm0(patch_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.store_apply(this.__wbg_ptr, id, ptr0, len0);\n if (ret[2]) {\n throw takeFromExternrefTable0(ret[1]);\n }\n return ret[0] !== 0;\n }\n /**\n * Host a model from its JSON; returns the assigned id.\n * @param {string} type_name\n * @param {string} value_json\n * @returns {bigint}\n */\n host(type_name, value_json) {\n const ptr0 = passStringToWasm0(type_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(value_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len1 = WASM_VECTOR_LEN;\n const ret = wasm.store_host(this.__wbg_ptr, ptr0, len0, ptr1, len1);\n if (ret[2]) {\n throw takeFromExternrefTable0(ret[1]);\n }\n return BigInt.asUintN(64, ret[0]);\n }\n /**\n * Replace a hosted model from JSON; returns the JSON patch (or `undefined` if id unknown).\n * @param {bigint} id\n * @param {string} value_json\n * @returns {string | undefined}\n */\n mutate(id, value_json) {\n const ptr0 = passStringToWasm0(value_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.store_mutate(this.__wbg_ptr, id, ptr0, len0);\n if (ret[3]) {\n throw takeFromExternrefTable0(ret[2]);\n }\n let v2;\n if (ret[0] !== 0) {\n v2 = getStringFromWasm0(ret[0], ret[1]).slice();\n wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);\n }\n return v2;\n }\n constructor() {\n const ret = wasm.store_new();\n this.__wbg_ptr = ret;\n StoreFinalization.register(this, this.__wbg_ptr, this);\n return this;\n }\n /**\n * `{\"type_name\":..,\"rev\":..,\"value\":..}` for a hosted model, or `undefined`.\n * @param {bigint} id\n * @returns {string | undefined}\n */\n snapshot(id) {\n const ret = wasm.store_snapshot(this.__wbg_ptr, id);\n let v1;\n if (ret[0] !== 0) {\n v1 = getStringFromWasm0(ret[0], ret[1]).slice();\n wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);\n }\n return v1;\n }\n}\nif (Symbol.dispose) Store.prototype[Symbol.dispose] = Store.prototype.free;\n\n/**\n * Apply a JSON-encoded patch to a JSON-encoded model, returning the JSON-encoded result.\n * @param {string} value\n * @param {string} patch\n * @returns {string}\n */\nexport function apply(value, patch) {\n let deferred4_0;\n let deferred4_1;\n try {\n const ptr0 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(patch, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len1 = WASM_VECTOR_LEN;\n const ret = wasm.apply(ptr0, len0, ptr1, len1);\n var ptr3 = ret[0];\n var len3 = ret[1];\n if (ret[3]) {\n ptr3 = 0; len3 = 0;\n throw takeFromExternrefTable0(ret[2]);\n }\n deferred4_0 = ptr3;\n deferred4_1 = len3;\n return getStringFromWasm0(ptr3, len3);\n } finally {\n wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);\n }\n}\n\n/**\n * Decode codec bytes back to a JSON-encoded model string.\n * @param {Uint8Array} data\n * @returns {string}\n */\nexport function decode(data) {\n let deferred3_0;\n let deferred3_1;\n try {\n const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.decode(ptr0, len0);\n var ptr2 = ret[0];\n var len2 = ret[1];\n if (ret[3]) {\n ptr2 = 0; len2 = 0;\n throw takeFromExternrefTable0(ret[2]);\n }\n deferred3_0 = ptr2;\n deferred3_1 = len2;\n return getStringFromWasm0(ptr2, len2);\n } finally {\n wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);\n }\n}\n\n/**\n * Decode bytes (produced by `codec`'s codec) back to a JSON-encoded model string.\n * @param {Uint8Array} data\n * @param {string} codec\n * @returns {string}\n */\nexport function decode_as(data, codec) {\n let deferred4_0;\n let deferred4_1;\n try {\n const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(codec, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len1 = WASM_VECTOR_LEN;\n const ret = wasm.decode_as(ptr0, len0, ptr1, len1);\n var ptr3 = ret[0];\n var len3 = ret[1];\n if (ret[3]) {\n ptr3 = 0; len3 = 0;\n throw takeFromExternrefTable0(ret[2]);\n }\n deferred4_0 = ptr3;\n deferred4_1 = len3;\n return getStringFromWasm0(ptr3, len3);\n } finally {\n wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);\n }\n}\n\n/**\n * Diff two JSON-encoded models, returning the JSON-encoded patch.\n * @param {string} old\n * @param {string} _new\n * @returns {string}\n */\nexport function diff(old, _new) {\n let deferred4_0;\n let deferred4_1;\n try {\n const ptr0 = passStringToWasm0(old, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(_new, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len1 = WASM_VECTOR_LEN;\n const ret = wasm.diff(ptr0, len0, ptr1, len1);\n var ptr3 = ret[0];\n var len3 = ret[1];\n if (ret[3]) {\n ptr3 = 0; len3 = 0;\n throw takeFromExternrefTable0(ret[2]);\n }\n deferred4_0 = ptr3;\n deferred4_1 = len3;\n return getStringFromWasm0(ptr3, len3);\n } finally {\n wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);\n }\n}\n\n/**\n * Encode a JSON-encoded model to codec bytes (a `Uint8Array` in JS).\n * @param {string} value\n * @returns {Uint8Array}\n */\nexport function encode(value) {\n const ptr0 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.encode(ptr0, len0);\n if (ret[3]) {\n throw takeFromExternrefTable0(ret[2]);\n }\n var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();\n wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);\n return v2;\n}\n\n/**\n * Encode a JSON-encoded model with the codec named by `codec` (e.g. `\"application/msgpack\"`).\n * @param {string} value\n * @param {string} codec\n * @returns {Uint8Array}\n */\nexport function encode_as(value, codec) {\n const ptr0 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(codec, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len1 = WASM_VECTOR_LEN;\n const ret = wasm.encode_as(ptr0, len0, ptr1, len1);\n if (ret[3]) {\n throw takeFromExternrefTable0(ret[2]);\n }\n var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();\n wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);\n return v3;\n}\n\n/**\n * Convert an arbitrary JSON document to MessagePack bytes (a `Uint8Array` in JS).\n * @param {string} json\n * @returns {Uint8Array}\n */\nexport function json_to_msgpack(json) {\n const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.json_to_msgpack(ptr0, len0);\n if (ret[3]) {\n throw takeFromExternrefTable0(ret[2]);\n }\n var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();\n wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);\n return v2;\n}\n\n/**\n * Convert MessagePack bytes back to a JSON document.\n * @param {Uint8Array} data\n * @returns {string}\n */\nexport function msgpack_to_json(data) {\n let deferred3_0;\n let deferred3_1;\n try {\n const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.msgpack_to_json(ptr0, len0);\n var ptr2 = ret[0];\n var len2 = ret[1];\n if (ret[3]) {\n ptr2 = 0; len2 = 0;\n throw takeFromExternrefTable0(ret[2]);\n }\n deferred3_0 = ptr2;\n deferred3_1 = len2;\n return getStringFromWasm0(ptr2, len2);\n } finally {\n wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);\n }\n}\nfunction __wbg_get_imports() {\n const import0 = {\n __proto__: null,\n __wbg_Error_bce6d499ff0a4aff: function(arg0, arg1) {\n const ret = Error(getStringFromWasm0(arg0, arg1));\n return ret;\n },\n __wbg___wbindgen_throw_9c31b086c2b26051: function(arg0, arg1) {\n throw new Error(getStringFromWasm0(arg0, arg1));\n },\n __wbindgen_init_externref_table: function() {\n const table = wasm.__wbindgen_externrefs;\n const offset = table.grow(4);\n table.set(0, undefined);\n table.set(offset + 0, undefined);\n table.set(offset + 1, null);\n table.set(offset + 2, true);\n table.set(offset + 3, false);\n },\n };\n return {\n __proto__: null,\n \"./transports_bg.js\": import0,\n };\n}\n\nconst StoreFinalization = (typeof FinalizationRegistry === 'undefined')\n ? { register: () => {}, unregister: () => {} }\n : new FinalizationRegistry(ptr => wasm.__wbg_store_free(ptr, 1));\n\nfunction getArrayU8FromWasm0(ptr, len) {\n ptr = ptr >>> 0;\n return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);\n}\n\nfunction getStringFromWasm0(ptr, len) {\n return decodeText(ptr >>> 0, len);\n}\n\nlet cachedUint8ArrayMemory0 = null;\nfunction getUint8ArrayMemory0() {\n if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {\n cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);\n }\n return cachedUint8ArrayMemory0;\n}\n\nfunction passArray8ToWasm0(arg, malloc) {\n const ptr = malloc(arg.length * 1, 1) >>> 0;\n getUint8ArrayMemory0().set(arg, ptr / 1);\n WASM_VECTOR_LEN = arg.length;\n return ptr;\n}\n\nfunction passStringToWasm0(arg, malloc, realloc) {\n if (realloc === undefined) {\n const buf = cachedTextEncoder.encode(arg);\n const ptr = malloc(buf.length, 1) >>> 0;\n getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);\n WASM_VECTOR_LEN = buf.length;\n return ptr;\n }\n\n let len = arg.length;\n let ptr = malloc(len, 1) >>> 0;\n\n const mem = getUint8ArrayMemory0();\n\n let offset = 0;\n\n for (; offset < len; offset++) {\n const code = arg.charCodeAt(offset);\n if (code > 0x7F) break;\n mem[ptr + offset] = code;\n }\n if (offset !== len) {\n if (offset !== 0) {\n arg = arg.slice(offset);\n }\n ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;\n const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);\n const ret = cachedTextEncoder.encodeInto(arg, view);\n\n offset += ret.written;\n ptr = realloc(ptr, len, offset, 1) >>> 0;\n }\n\n WASM_VECTOR_LEN = offset;\n return ptr;\n}\n\nfunction takeFromExternrefTable0(idx) {\n const value = wasm.__wbindgen_externrefs.get(idx);\n wasm.__externref_table_dealloc(idx);\n return value;\n}\n\nlet cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });\ncachedTextDecoder.decode();\nconst MAX_SAFARI_DECODE_BYTES = 2146435072;\nlet numBytesDecoded = 0;\nfunction decodeText(ptr, len) {\n numBytesDecoded += len;\n if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {\n cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });\n cachedTextDecoder.decode();\n numBytesDecoded = len;\n }\n return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));\n}\n\nconst cachedTextEncoder = new TextEncoder();\n\nif (!('encodeInto' in cachedTextEncoder)) {\n cachedTextEncoder.encodeInto = function (arg, view) {\n const buf = cachedTextEncoder.encode(arg);\n view.set(buf);\n return {\n read: arg.length,\n written: buf.length\n };\n };\n}\n\nlet WASM_VECTOR_LEN = 0;\n\nlet wasmModule, wasmInstance, wasm;\nfunction __wbg_finalize_init(instance, module) {\n wasmInstance = instance;\n wasm = instance.exports;\n wasmModule = module;\n cachedUint8ArrayMemory0 = null;\n wasm.__wbindgen_start();\n return wasm;\n}\n\nasync function __wbg_load(module, imports) {\n if (typeof Response === 'function' && module instanceof Response) {\n if (typeof WebAssembly.instantiateStreaming === 'function') {\n try {\n return await WebAssembly.instantiateStreaming(module, imports);\n } catch (e) {\n const validResponse = module.ok && expectedResponseType(module.type);\n\n if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {\n console.warn(\"`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n\", e);\n\n } else { throw e; }\n }\n }\n\n const bytes = await module.arrayBuffer();\n return await WebAssembly.instantiate(bytes, imports);\n } else {\n const instance = await WebAssembly.instantiate(module, imports);\n\n if (instance instanceof WebAssembly.Instance) {\n return { instance, module };\n } else {\n return instance;\n }\n }\n\n function expectedResponseType(type) {\n switch (type) {\n case 'basic': case 'cors': case 'default': return true;\n }\n return false;\n }\n}\n\nfunction initSync(module) {\n if (wasm !== undefined) return wasm;\n\n\n if (module !== undefined) {\n if (Object.getPrototypeOf(module) === Object.prototype) {\n ({module} = module)\n } else {\n console.warn('using deprecated parameters for `initSync()`; pass a single object instead')\n }\n }\n\n const imports = __wbg_get_imports();\n if (!(module instanceof WebAssembly.Module)) {\n module = new WebAssembly.Module(module);\n }\n const instance = new WebAssembly.Instance(module, imports);\n return __wbg_finalize_init(instance, module);\n}\n\nasync function __wbg_init(module_or_path) {\n if (wasm !== undefined) return wasm;\n\n\n if (module_or_path !== undefined) {\n if (Object.getPrototypeOf(module_or_path) === Object.prototype) {\n ({module_or_path} = module_or_path)\n } else {\n console.warn('using deprecated parameters for the initialization function; pass a single object instead')\n }\n }\n\n if (module_or_path === undefined) {\n module_or_path = new URL('transports_bg.wasm', import.meta.url);\n }\n const imports = __wbg_get_imports();\n\n if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {\n module_or_path = fetch(module_or_path);\n }\n\n const { instance, module } = await __wbg_load(await module_or_path, imports);\n\n return __wbg_finalize_init(instance, module);\n}\n\nexport { initSync, __wbg_init as default };\n", "/** The core `Value` wire form: the externally-tagged enum the Rust core speaks. */\nexport type Value =\n | \"Null\"\n | { Bool: boolean }\n | { Int: number }\n | { Float: number }\n | { Str: string }\n | { List: Value[] }\n | { Map: { [k: string]: Value } }\n | { Submodel: number };\n\n/**\n * Convert a plain JS value to the core `Value` wire form.\n *\n * Note: JS has a single number type, so integers and whole-valued floats both encode as `Int`.\n */\nexport function toValue(v: unknown): Value {\n if (v === null || v === undefined) return \"Null\";\n if (typeof v === \"boolean\") return { Bool: v };\n if (typeof v === \"number\")\n return Number.isInteger(v) ? { Int: v } : { Float: v };\n if (typeof v === \"string\") return { Str: v };\n if (Array.isArray(v)) return { List: v.map(toValue) };\n if (typeof v === \"object\") {\n const m: { [k: string]: Value } = {};\n for (const [k, x] of Object.entries(v as object)) m[k] = toValue(x);\n return { Map: m };\n }\n throw new TypeError(`unsupported value for transports: ${typeof v}`);\n}\n\n/** Convert a core `Value` back to a plain JS value. */\nexport function fromValue(value: Value): unknown {\n if (value === \"Null\") return null;\n const [tag, inner] = Object.entries(value)[0];\n switch (tag) {\n case \"Bool\":\n case \"Int\":\n case \"Float\":\n case \"Str\":\n case \"Submodel\":\n return inner;\n case \"List\":\n return (inner as Value[]).map(fromValue);\n case \"Map\": {\n const o: { [k: string]: unknown } = {};\n for (const [k, x] of Object.entries(inner as { [k: string]: Value }))\n o[k] = fromValue(x);\n return o;\n }\n default:\n throw new Error(`unrecognized tagged value: ${JSON.stringify(value)}`);\n }\n}\n", "/** Custom wire codec registry (the JS analog of `transports.register_codec` in Python).\n *\n * A codec turns a JSON-able object (a protocol message, or a model `Value`) into a wire frame\n * (`string` or `Uint8Array`) and back. Register a matching implementation here for any content type\n * you also register on the server, then use it via `new Client(contentType)` / `?codec=`.\n */\n\nexport type CodecEncode = (obj: unknown) => string | Uint8Array;\nexport type CodecDecode = (data: string | Uint8Array) => unknown;\n\nconst BUILTIN = new Set([\n \"\",\n \"json\",\n \"application/json\",\n \"msgpack\",\n \"application/msgpack\",\n \"x-msgpack\",\n \"application/x-msgpack\",\n]);\n\nconst registry = new Map<\n string,\n { encode: CodecEncode; decode: CodecDecode }\n>();\n\n/** Register a custom codec under `contentType`. The built-in json/msgpack codecs cannot be overridden. */\nexport function registerCodec(\n contentType: string,\n encode: CodecEncode,\n decode: CodecDecode,\n): void {\n if (BUILTIN.has(contentType)) {\n throw new Error(`cannot override built-in codec: ${contentType}`);\n }\n registry.set(contentType, { encode, decode });\n}\n\n/** Remove a previously registered custom codec. */\nexport function unregisterCodec(contentType: string): void {\n registry.delete(contentType);\n}\n\n/** The currently registered custom codec for `contentType`, if any. */\nexport function codecFor(\n contentType: string,\n): { encode: CodecEncode; decode: CodecDecode } | undefined {\n return registry.get(contentType);\n}\n", "import { codecFor } from \"./codecs\";\nimport { apply, diff, jsonToMsgpack, msgpackToJson } from \"./index\";\n\ntype SnapshotMsg = {\n t: \"snapshot\";\n id: number;\n type: string;\n rev: number;\n value: unknown;\n};\ntype PatchMsg = {\n t: \"patch\";\n id: number;\n patch: { rev: number; ops: unknown[] };\n};\n\n/** Mirrors a remote transports `Session` from connection messages.\n *\n * Inbound frames are decoded by type \u2014 text frames are JSON, binary frames are MessagePack \u2014 so a\n * client transparently mirrors a server regardless of the negotiated codec. Requires the wasm core\n * to be initialized before applying patches.\n */\nexport class Client {\n private values = new Map<number, unknown>();\n private revs = new Map<number, number>();\n\n constructor(private codec: string = \"json\") {}\n\n /** Apply an inbound snapshot or patch frame to the mirror.\n *\n * Decodes by the client's codec: a registered custom codec, else built-in JSON (text) / msgpack\n * (binary).\n */\n recv(data: string | Uint8Array): void {\n const custom = codecFor(this.codec);\n const msg = (\n custom\n ? custom.decode(data)\n : JSON.parse(typeof data === \"string\" ? data : msgpackToJson(data))\n ) as SnapshotMsg | PatchMsg;\n if (msg.t === \"snapshot\") {\n this.values.set(msg.id, msg.value);\n this.revs.set(msg.id, msg.rev);\n } else if (msg.t === \"patch\") {\n // rev is the model's sequence number; ignore a patch already reflected in the mirror (e.g. one\n // the opening snapshot already captured, which the server then also broadcasts).\n const seen = this.revs.get(msg.id);\n if (seen !== undefined && msg.patch.rev <= seen) return;\n const cur = JSON.stringify(this.values.get(msg.id));\n this.values.set(\n msg.id,\n JSON.parse(apply(cur, JSON.stringify(msg.patch))),\n );\n this.revs.set(msg.id, msg.patch.rev);\n }\n }\n\n /** The current mirrored core `Value` of a model. */\n value(id: number): unknown {\n return this.values.get(id);\n }\n\n ids(): number[] {\n return [...this.values.keys()];\n }\n\n /** Propose an edit to a mirrored model; returns the patch frame to send (encoded in this codec).\n *\n * Server-authoritative: the local mirror updates when the server echoes the authoritative patch\n * back via `recv`, not optimistically.\n */\n edit(id: number, value: unknown): string | Uint8Array {\n const patch = JSON.parse(\n diff(JSON.stringify(this.values.get(id)), JSON.stringify(value)),\n );\n const msg = { t: \"patch\", id, patch };\n const custom = codecFor(this.codec);\n if (custom) return custom.encode(msg);\n const s = JSON.stringify(msg);\n return this.codec === \"msgpack\" ? jsonToMsgpack(s) : s;\n }\n\n /** Connect to a transports server and mirror it. Returns the `WebSocket`. */\n connect(url: string): WebSocket {\n const sep = url.includes(\"?\") ? \"&\" : \"?\";\n const ws = new WebSocket(`${url}${sep}codec=${this.codec}`);\n ws.binaryType = \"arraybuffer\";\n ws.addEventListener(\"message\", (e) => {\n const data = (e as MessageEvent).data;\n this.recv(\n typeof data === \"string\" ? data : new Uint8Array(data as ArrayBuffer),\n );\n });\n return ws;\n }\n\n /** Mirror a server over Server-Sent Events (receive-only, JSON). Returns the `EventSource`. */\n connectSSE(url: string): EventSource {\n const es = new EventSource(url);\n es.addEventListener(\"message\", (e) =>\n this.recv((e as MessageEvent).data as string),\n );\n return es;\n }\n}\n", "import * as wasm from \"../../dist/pkg/transports\";\n\nexport * as wasm from \"../../dist/pkg/transports\";\n\nexport const placeholder = \"\";\n\n/** Diff two JSON-encoded models, returning the JSON-encoded patch. */\nexport const diff = (oldModel: string, newModel: string): string =>\n wasm.diff(oldModel, newModel);\n\n/** Apply a JSON-encoded patch to a JSON-encoded model, returning the JSON-encoded result. */\nexport const apply = (model: string, patch: string): string =>\n wasm.apply(model, patch);\n\n/** Encode a JSON-encoded model to codec bytes. */\nexport const encode = (model: string): Uint8Array => wasm.encode(model);\n\n/** Decode codec bytes back to a JSON-encoded model string. */\nexport const decode = (bytes: Uint8Array): string => wasm.decode(bytes);\n\n/** Encode a JSON-encoded model with the codec named by `codec` (e.g. \"application/msgpack\"). */\nexport const encodeAs = (model: string, codec: string): Uint8Array =>\n wasm.encode_as(model, codec);\n\n/** Decode bytes (from `codec`'s codec) back to a JSON-encoded model string. */\nexport const decodeAs = (bytes: Uint8Array, codec: string): string =>\n wasm.decode_as(bytes, codec);\n\n/** Convert an arbitrary JSON document to MessagePack bytes (for whole protocol messages). */\nexport const jsonToMsgpack = (json: string): Uint8Array =>\n wasm.json_to_msgpack(json);\n\n/** Convert MessagePack bytes back to a JSON document. */\nexport const msgpackToJson = (bytes: Uint8Array): string =>\n wasm.msgpack_to_json(bytes);\n\n/** In-process model store: host / mutate \u2192 patch / apply / snapshot. */\nexport const Store = wasm.Store;\n\n// Plain JS object <-> core `Value` bridge (the JS analog of the Python bridge).\nexport { toValue, fromValue } from \"./bridge\";\nexport type { Value } from \"./bridge\";\n\n// WebSocket client that mirrors a remote Session.\nexport { Client } from \"./client\";\n\n// Custom wire codec registry.\nexport { registerCodec, unregisterCodec, codecFor } from \"./codecs\";\nexport type { CodecEncode, CodecDecode } from \"./codecs\";\n"],
|
|
5
|
-
"mappings": ";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,IAAM,QAAN,MAAY;AAAA,EACf,qBAAqB;AACjB,UAAM,MAAM,KAAK;AACjB,SAAK,YAAY;AACjB,sBAAkB,WAAW,IAAI;AACjC,WAAO;AAAA,EACX;AAAA,EACA,OAAO;AACH,UAAM,MAAM,KAAK,mBAAmB;AACpC,SAAK,iBAAiB,KAAK,CAAC;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,IAAI,YAAY;AAClB,UAAM,OAAO,kBAAk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**\n * In-process model store: host / mutate \u2192 patch / apply / snapshot.\n */\nexport class Store {\n __destroy_into_raw() {\n const ptr = this.__wbg_ptr;\n this.__wbg_ptr = 0;\n StoreFinalization.unregister(this);\n return ptr;\n }\n free() {\n const ptr = this.__destroy_into_raw();\n wasm.__wbg_store_free(ptr, 0);\n }\n /**\n * Apply a JSON patch to a mirrored model; returns whether the id was known.\n * @param {bigint} id\n * @param {string} patch_json\n * @returns {boolean}\n */\n apply(id, patch_json) {\n const ptr0 = passStringToWasm0(patch_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.store_apply(this.__wbg_ptr, id, ptr0, len0);\n if (ret[2]) {\n throw takeFromExternrefTable0(ret[1]);\n }\n return ret[0] !== 0;\n }\n /**\n * Host a model from its JSON; returns the assigned id.\n * @param {string} type_name\n * @param {string} value_json\n * @returns {bigint}\n */\n host(type_name, value_json) {\n const ptr0 = passStringToWasm0(type_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(value_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len1 = WASM_VECTOR_LEN;\n const ret = wasm.store_host(this.__wbg_ptr, ptr0, len0, ptr1, len1);\n if (ret[2]) {\n throw takeFromExternrefTable0(ret[1]);\n }\n return BigInt.asUintN(64, ret[0]);\n }\n /**\n * Replace a hosted model from JSON; returns the JSON patch (or `undefined` if id unknown).\n * @param {bigint} id\n * @param {string} value_json\n * @returns {string | undefined}\n */\n mutate(id, value_json) {\n const ptr0 = passStringToWasm0(value_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.store_mutate(this.__wbg_ptr, id, ptr0, len0);\n if (ret[3]) {\n throw takeFromExternrefTable0(ret[2]);\n }\n let v2;\n if (ret[0] !== 0) {\n v2 = getStringFromWasm0(ret[0], ret[1]).slice();\n wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);\n }\n return v2;\n }\n constructor() {\n const ret = wasm.store_new();\n this.__wbg_ptr = ret;\n StoreFinalization.register(this, this.__wbg_ptr, this);\n return this;\n }\n /**\n * `{\"type_name\":..,\"rev\":..,\"value\":..}` for a hosted model, or `undefined`.\n * @param {bigint} id\n * @returns {string | undefined}\n */\n snapshot(id) {\n const ret = wasm.store_snapshot(this.__wbg_ptr, id);\n let v1;\n if (ret[0] !== 0) {\n v1 = getStringFromWasm0(ret[0], ret[1]).slice();\n wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);\n }\n return v1;\n }\n}\nif (Symbol.dispose) Store.prototype[Symbol.dispose] = Store.prototype.free;\n\n/**\n * Apply a JSON-encoded patch to a JSON-encoded model, returning the JSON-encoded result.\n * @param {string} value\n * @param {string} patch\n * @returns {string}\n */\nexport function apply(value, patch) {\n let deferred4_0;\n let deferred4_1;\n try {\n const ptr0 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(patch, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len1 = WASM_VECTOR_LEN;\n const ret = wasm.apply(ptr0, len0, ptr1, len1);\n var ptr3 = ret[0];\n var len3 = ret[1];\n if (ret[3]) {\n ptr3 = 0; len3 = 0;\n throw takeFromExternrefTable0(ret[2]);\n }\n deferred4_0 = ptr3;\n deferred4_1 = len3;\n return getStringFromWasm0(ptr3, len3);\n } finally {\n wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);\n }\n}\n\n/**\n * Convert CBOR bytes back to a JSON document.\n * @param {Uint8Array} data\n * @returns {string}\n */\nexport function cbor_to_json(data) {\n let deferred3_0;\n let deferred3_1;\n try {\n const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.cbor_to_json(ptr0, len0);\n var ptr2 = ret[0];\n var len2 = ret[1];\n if (ret[3]) {\n ptr2 = 0; len2 = 0;\n throw takeFromExternrefTable0(ret[2]);\n }\n deferred3_0 = ptr2;\n deferred3_1 = len2;\n return getStringFromWasm0(ptr2, len2);\n } finally {\n wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);\n }\n}\n\n/**\n * Decode codec bytes back to a JSON-encoded model string.\n * @param {Uint8Array} data\n * @returns {string}\n */\nexport function decode(data) {\n let deferred3_0;\n let deferred3_1;\n try {\n const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.decode(ptr0, len0);\n var ptr2 = ret[0];\n var len2 = ret[1];\n if (ret[3]) {\n ptr2 = 0; len2 = 0;\n throw takeFromExternrefTable0(ret[2]);\n }\n deferred3_0 = ptr2;\n deferred3_1 = len2;\n return getStringFromWasm0(ptr2, len2);\n } finally {\n wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);\n }\n}\n\n/**\n * Decode bytes (produced by `codec`'s codec) back to a JSON-encoded model string.\n * @param {Uint8Array} data\n * @param {string} codec\n * @returns {string}\n */\nexport function decode_as(data, codec) {\n let deferred4_0;\n let deferred4_1;\n try {\n const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(codec, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len1 = WASM_VECTOR_LEN;\n const ret = wasm.decode_as(ptr0, len0, ptr1, len1);\n var ptr3 = ret[0];\n var len3 = ret[1];\n if (ret[3]) {\n ptr3 = 0; len3 = 0;\n throw takeFromExternrefTable0(ret[2]);\n }\n deferred4_0 = ptr3;\n deferred4_1 = len3;\n return getStringFromWasm0(ptr3, len3);\n } finally {\n wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);\n }\n}\n\n/**\n * Diff two JSON-encoded models, returning the JSON-encoded patch.\n * @param {string} old\n * @param {string} _new\n * @returns {string}\n */\nexport function diff(old, _new) {\n let deferred4_0;\n let deferred4_1;\n try {\n const ptr0 = passStringToWasm0(old, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(_new, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len1 = WASM_VECTOR_LEN;\n const ret = wasm.diff(ptr0, len0, ptr1, len1);\n var ptr3 = ret[0];\n var len3 = ret[1];\n if (ret[3]) {\n ptr3 = 0; len3 = 0;\n throw takeFromExternrefTable0(ret[2]);\n }\n deferred4_0 = ptr3;\n deferred4_1 = len3;\n return getStringFromWasm0(ptr3, len3);\n } finally {\n wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);\n }\n}\n\n/**\n * Encode a JSON-encoded model to codec bytes (a `Uint8Array` in JS).\n * @param {string} value\n * @returns {Uint8Array}\n */\nexport function encode(value) {\n const ptr0 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.encode(ptr0, len0);\n if (ret[3]) {\n throw takeFromExternrefTable0(ret[2]);\n }\n var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();\n wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);\n return v2;\n}\n\n/**\n * Encode a JSON-encoded model with the codec named by `codec` (e.g. `\"application/msgpack\"`).\n * @param {string} value\n * @param {string} codec\n * @returns {Uint8Array}\n */\nexport function encode_as(value, codec) {\n const ptr0 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(codec, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len1 = WASM_VECTOR_LEN;\n const ret = wasm.encode_as(ptr0, len0, ptr1, len1);\n if (ret[3]) {\n throw takeFromExternrefTable0(ret[2]);\n }\n var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();\n wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);\n return v3;\n}\n\n/**\n * Convert an arbitrary JSON document to CBOR bytes (a `Uint8Array` in JS).\n * @param {string} json\n * @returns {Uint8Array}\n */\nexport function json_to_cbor(json) {\n const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.json_to_cbor(ptr0, len0);\n if (ret[3]) {\n throw takeFromExternrefTable0(ret[2]);\n }\n var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();\n wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);\n return v2;\n}\n\n/**\n * Convert an arbitrary JSON document to MessagePack bytes (a `Uint8Array` in JS).\n * @param {string} json\n * @returns {Uint8Array}\n */\nexport function json_to_msgpack(json) {\n const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.json_to_msgpack(ptr0, len0);\n if (ret[3]) {\n throw takeFromExternrefTable0(ret[2]);\n }\n var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();\n wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);\n return v2;\n}\n\n/**\n * Convert MessagePack bytes back to a JSON document.\n * @param {Uint8Array} data\n * @returns {string}\n */\nexport function msgpack_to_json(data) {\n let deferred3_0;\n let deferred3_1;\n try {\n const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.msgpack_to_json(ptr0, len0);\n var ptr2 = ret[0];\n var len2 = ret[1];\n if (ret[3]) {\n ptr2 = 0; len2 = 0;\n throw takeFromExternrefTable0(ret[2]);\n }\n deferred3_0 = ptr2;\n deferred3_1 = len2;\n return getStringFromWasm0(ptr2, len2);\n } finally {\n wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);\n }\n}\nfunction __wbg_get_imports() {\n const import0 = {\n __proto__: null,\n __wbg_Error_92b29b0548f8b746: function(arg0, arg1) {\n const ret = Error(getStringFromWasm0(arg0, arg1));\n return ret;\n },\n __wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {\n throw new Error(getStringFromWasm0(arg0, arg1));\n },\n __wbindgen_init_externref_table: function() {\n const table = wasm.__wbindgen_externrefs;\n const offset = table.grow(4);\n table.set(0, undefined);\n table.set(offset + 0, undefined);\n table.set(offset + 1, null);\n table.set(offset + 2, true);\n table.set(offset + 3, false);\n },\n };\n return {\n __proto__: null,\n \"./transports_bg.js\": import0,\n };\n}\n\nconst StoreFinalization = (typeof FinalizationRegistry === 'undefined')\n ? { register: () => {}, unregister: () => {} }\n : new FinalizationRegistry(ptr => wasm.__wbg_store_free(ptr, 1));\n\nfunction getArrayU8FromWasm0(ptr, len) {\n ptr = ptr >>> 0;\n return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);\n}\n\nfunction getStringFromWasm0(ptr, len) {\n return decodeText(ptr >>> 0, len);\n}\n\nlet cachedUint8ArrayMemory0 = null;\nfunction getUint8ArrayMemory0() {\n if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {\n cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);\n }\n return cachedUint8ArrayMemory0;\n}\n\nfunction passArray8ToWasm0(arg, malloc) {\n const ptr = malloc(arg.length * 1, 1) >>> 0;\n getUint8ArrayMemory0().set(arg, ptr / 1);\n WASM_VECTOR_LEN = arg.length;\n return ptr;\n}\n\nfunction passStringToWasm0(arg, malloc, realloc) {\n if (realloc === undefined) {\n const buf = cachedTextEncoder.encode(arg);\n const ptr = malloc(buf.length, 1) >>> 0;\n getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);\n WASM_VECTOR_LEN = buf.length;\n return ptr;\n }\n\n let len = arg.length;\n let ptr = malloc(len, 1) >>> 0;\n\n const mem = getUint8ArrayMemory0();\n\n let offset = 0;\n\n for (; offset < len; offset++) {\n const code = arg.charCodeAt(offset);\n if (code > 0x7F) break;\n mem[ptr + offset] = code;\n }\n if (offset !== len) {\n if (offset !== 0) {\n arg = arg.slice(offset);\n }\n ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;\n const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);\n const ret = cachedTextEncoder.encodeInto(arg, view);\n\n offset += ret.written;\n ptr = realloc(ptr, len, offset, 1) >>> 0;\n }\n\n WASM_VECTOR_LEN = offset;\n return ptr;\n}\n\nfunction takeFromExternrefTable0(idx) {\n const value = wasm.__wbindgen_externrefs.get(idx);\n wasm.__externref_table_dealloc(idx);\n return value;\n}\n\nlet cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });\ncachedTextDecoder.decode();\nconst MAX_SAFARI_DECODE_BYTES = 2146435072;\nlet numBytesDecoded = 0;\nfunction decodeText(ptr, len) {\n numBytesDecoded += len;\n if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {\n cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });\n cachedTextDecoder.decode();\n numBytesDecoded = len;\n }\n return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));\n}\n\nconst cachedTextEncoder = new TextEncoder();\n\nif (!('encodeInto' in cachedTextEncoder)) {\n cachedTextEncoder.encodeInto = function (arg, view) {\n const buf = cachedTextEncoder.encode(arg);\n view.set(buf);\n return {\n read: arg.length,\n written: buf.length\n };\n };\n}\n\nlet WASM_VECTOR_LEN = 0;\n\nlet wasmModule, wasmInstance, wasm;\nfunction __wbg_finalize_init(instance, module) {\n wasmInstance = instance;\n wasm = instance.exports;\n wasmModule = module;\n cachedUint8ArrayMemory0 = null;\n wasm.__wbindgen_start();\n return wasm;\n}\n\nasync function __wbg_load(module, imports) {\n if (typeof Response === 'function' && module instanceof Response) {\n if (typeof WebAssembly.instantiateStreaming === 'function') {\n try {\n return await WebAssembly.instantiateStreaming(module, imports);\n } catch (e) {\n const validResponse = module.ok && expectedResponseType(module.type);\n\n if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {\n console.warn(\"`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n\", e);\n\n } else { throw e; }\n }\n }\n\n const bytes = await module.arrayBuffer();\n return await WebAssembly.instantiate(bytes, imports);\n } else {\n const instance = await WebAssembly.instantiate(module, imports);\n\n if (instance instanceof WebAssembly.Instance) {\n return { instance, module };\n } else {\n return instance;\n }\n }\n\n function expectedResponseType(type) {\n switch (type) {\n case 'basic': case 'cors': case 'default': return true;\n }\n return false;\n }\n}\n\nfunction initSync(module) {\n if (wasm !== undefined) return wasm;\n\n\n if (module !== undefined) {\n if (Object.getPrototypeOf(module) === Object.prototype) {\n ({module} = module)\n } else {\n console.warn('using deprecated parameters for `initSync()`; pass a single object instead')\n }\n }\n\n const imports = __wbg_get_imports();\n if (!(module instanceof WebAssembly.Module)) {\n module = new WebAssembly.Module(module);\n }\n const instance = new WebAssembly.Instance(module, imports);\n return __wbg_finalize_init(instance, module);\n}\n\nasync function __wbg_init(module_or_path) {\n if (wasm !== undefined) return wasm;\n\n\n if (module_or_path !== undefined) {\n if (Object.getPrototypeOf(module_or_path) === Object.prototype) {\n ({module_or_path} = module_or_path)\n } else {\n console.warn('using deprecated parameters for the initialization function; pass a single object instead')\n }\n }\n\n if (module_or_path === undefined) {\n module_or_path = new URL('transports_bg.wasm', import.meta.url);\n }\n const imports = __wbg_get_imports();\n\n if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {\n module_or_path = fetch(module_or_path);\n }\n\n const { instance, module } = await __wbg_load(await module_or_path, imports);\n\n return __wbg_finalize_init(instance, module);\n}\n\nexport { initSync, __wbg_init as default };\n", "/** The core `Value` wire form: the externally-tagged enum the Rust core speaks. */\nexport type Value =\n | \"Null\"\n | { Bool: boolean }\n | { Int: number }\n | { Float: number }\n | { Str: string }\n | { List: Value[] }\n | { Map: { [k: string]: Value } }\n | { Submodel: number };\n\n/**\n * Convert a plain JS value to the core `Value` wire form.\n *\n * Note: JS has a single number type, so integers and whole-valued floats both encode as `Int`.\n */\nexport function toValue(v: unknown): Value {\n if (v === null || v === undefined) return \"Null\";\n if (typeof v === \"boolean\") return { Bool: v };\n if (typeof v === \"number\")\n return Number.isInteger(v) ? { Int: v } : { Float: v };\n if (typeof v === \"string\") return { Str: v };\n if (Array.isArray(v)) return { List: v.map(toValue) };\n if (typeof v === \"object\") {\n const m: { [k: string]: Value } = {};\n for (const [k, x] of Object.entries(v as object)) m[k] = toValue(x);\n return { Map: m };\n }\n throw new TypeError(`unsupported value for transports: ${typeof v}`);\n}\n\n/** Convert a core `Value` back to a plain JS value. */\nexport function fromValue(value: Value): unknown {\n if (value === \"Null\") return null;\n const [tag, inner] = Object.entries(value)[0];\n switch (tag) {\n case \"Bool\":\n case \"Int\":\n case \"Float\":\n case \"Str\":\n case \"Submodel\":\n return inner;\n case \"List\":\n return (inner as Value[]).map(fromValue);\n case \"Map\": {\n const o: { [k: string]: unknown } = {};\n for (const [k, x] of Object.entries(inner as { [k: string]: Value }))\n o[k] = fromValue(x);\n return o;\n }\n default:\n throw new Error(`unrecognized tagged value: ${JSON.stringify(value)}`);\n }\n}\n", "/** Custom wire codec registry (the JS analog of `transports.register_codec` in Python).\n *\n * A codec turns a JSON-able object (a protocol message, or a model `Value`) into a wire frame\n * (`string` or `Uint8Array`) and back. Register a matching implementation here for any content type\n * you also register on the server, then use it via `new Client(contentType)` / `?codec=`.\n */\n\nexport type CodecEncode = (obj: unknown) => string | Uint8Array;\nexport type CodecDecode = (data: string | Uint8Array) => unknown;\n\nconst BUILTIN = new Set([\n \"\",\n \"json\",\n \"application/json\",\n \"msgpack\",\n \"application/msgpack\",\n \"x-msgpack\",\n \"application/x-msgpack\",\n \"cbor\",\n \"application/cbor\",\n]);\n\nconst registry = new Map<\n string,\n { encode: CodecEncode; decode: CodecDecode }\n>();\n\n/** Register a custom codec under `contentType`. The built-in json/msgpack codecs cannot be overridden. */\nexport function registerCodec(\n contentType: string,\n encode: CodecEncode,\n decode: CodecDecode,\n): void {\n if (BUILTIN.has(contentType)) {\n throw new Error(`cannot override built-in codec: ${contentType}`);\n }\n registry.set(contentType, { encode, decode });\n}\n\n/** Remove a previously registered custom codec. */\nexport function unregisterCodec(contentType: string): void {\n registry.delete(contentType);\n}\n\n/** The currently registered custom codec for `contentType`, if any. */\nexport function codecFor(\n contentType: string,\n): { encode: CodecEncode; decode: CodecDecode } | undefined {\n return registry.get(contentType);\n}\n", "import { codecFor } from \"./codecs\";\nimport {\n cborToJson,\n diff,\n jsonToCbor,\n jsonToMsgpack,\n msgpackToJson,\n} from \"./index\";\nimport type { Value } from \"./bridge\";\n\ntype SnapshotMsg = {\n t: \"snapshot\";\n id: number;\n type: string;\n rev: number;\n value: unknown;\n};\nexport type PathSeg = { Key: string } | { Index: number };\nexport type PatchOp =\n | { Set: { path: PathSeg[]; value: Value } }\n | { Remove: { path: PathSeg[] } }\n | { Insert: { path: PathSeg[]; index: number; value: Value } }\n | { RemoveAt: { path: PathSeg[]; index: number } };\nexport type ModelPatch = { rev: number; ops: PatchOp[] };\ntype PatchMsg = {\n t: \"patch\";\n id: number;\n patch: ModelPatch;\n};\n/** The server refused a proposed edit; `rev` is its current revision and `error` says why (the\n * model's validation message). Sent to the proposer only, after the authoritative revert. */\nexport type RejectMsg = { t: \"reject\"; id: number; rev: number; error: string };\n/** Frame metadata returned after the mirror accepts a snapshot or patch. */\nexport type ReceiveChange =\n | { t: \"snapshot\"; id: number; rev: number }\n | PatchMsg;\n\nfunction mapValue(value: Value | undefined): Record<string, Value> {\n if (\n value &&\n typeof value === \"object\" &&\n \"Map\" in value &&\n value.Map &&\n typeof value.Map === \"object\" &&\n !Array.isArray(value.Map)\n )\n return value.Map;\n throw new Error(\"patch path expected a map\");\n}\n\nfunction listValue(value: Value | undefined): Value[] {\n if (\n value &&\n typeof value === \"object\" &&\n \"List\" in value &&\n Array.isArray(value.List)\n )\n return value.List;\n throw new Error(\"patch path expected a list\");\n}\n\nfunction updateAt(\n value: Value | undefined,\n path: PathSeg[],\n update: (current: Value | undefined) => Value,\n): Value {\n if (!path.length) return update(value);\n const [segment, ...rest] = path;\n if (\"Key\" in segment) {\n const map = mapValue(value);\n if (rest.length && !Object.prototype.hasOwnProperty.call(map, segment.Key))\n throw new Error(\n `patch path key ${JSON.stringify(segment.Key)} not found`,\n );\n return {\n Map: {\n ...map,\n [segment.Key]: updateAt(map[segment.Key], rest, update),\n },\n };\n }\n const list = listValue(value);\n if (segment.Index < 0 || segment.Index >= list.length)\n throw new Error(\n `patch path index ${segment.Index} out of bounds (len ${list.length})`,\n );\n const next = [...list];\n next[segment.Index] = updateAt(next[segment.Index], rest, update);\n return { List: next };\n}\n\nfunction applyOp(value: Value, op: PatchOp): Value {\n if (\"Set\" in op) return updateAt(value, op.Set.path, () => op.Set.value);\n if (\"Remove\" in op) {\n const { path } = op.Remove;\n const segment = path[path.length - 1];\n if (!segment || !(\"Key\" in segment))\n throw new Error(\"remove path must end in a map key\");\n return updateAt(value, path.slice(0, -1), (container) => {\n const map = { ...mapValue(container) };\n delete map[segment.Key];\n return { Map: map };\n });\n }\n if (\"Insert\" in op) {\n const { path, index, value: inserted } = op.Insert;\n return updateAt(value, path, (container) => {\n const list = listValue(container);\n if (index < 0 || index > list.length)\n throw new Error(\n `insert index ${index} out of bounds (len ${list.length})`,\n );\n const next = [...list];\n next.splice(index, 0, inserted);\n return { List: next };\n });\n }\n if (\"RemoveAt\" in op) {\n const { path, index } = op.RemoveAt;\n return updateAt(value, path, (container) => {\n const list = listValue(container);\n if (index < 0 || index >= list.length)\n throw new Error(\n `remove index ${index} out of bounds (len ${list.length})`,\n );\n const next = [...list];\n next.splice(index, 1);\n return { List: next };\n });\n }\n throw new Error(\"unknown patch op\");\n}\n\nfunction applyPatch(value: Value, patch: ModelPatch): Value {\n let next = value;\n for (const op of patch.ops) next = applyOp(next, op);\n return next;\n}\n\n/** Mirrors a remote transports `Session` from connection messages.\n *\n * Inbound frames are decoded by type \u2014 text frames are JSON, binary frames are MessagePack \u2014 so a\n * client transparently mirrors a server regardless of the negotiated codec. Binary built-in codecs\n * and edit generation require the wasm core to be initialized.\n */\nexport class Client {\n private values = new Map<number, unknown>();\n private revs = new Map<number, number>();\n private changeListeners: Array<(change: ReceiveChange) => void> = [];\n private rejectListeners: Array<(reject: RejectMsg) => void> = [];\n\n constructor(private codec: string = \"json\") {}\n\n /** Register a listener fired when the server refuses a proposed edit, with the decoded `reject`\n * frame (model id, the server's current rev, and the validation error). The mirror itself reverts\n * via the authoritative snapshot the server sends alongside. Returns an unsubscribe function.\n */\n onReject(listener: (reject: RejectMsg) => void): () => void {\n this.rejectListeners.push(listener);\n return () => {\n const i = this.rejectListeners.indexOf(listener);\n if (i >= 0) this.rejectListeners.splice(i, 1);\n };\n }\n\n /** Register a listener fired after each accepted snapshot or patch \u2014 the same `ReceiveChange`\n * `recv` returns \u2014 so `connect`/`run`/`connectSSE` consumers get path-level changes without\n * managing the socket themselves. Not fired for ignored frames (stale revision, unknown message\n * type). Returns an unsubscribe function. A listener exception propagates to the `recv` caller;\n * the mirror has already updated by then.\n */\n onChange(listener: (change: ReceiveChange) => void): () => void {\n this.changeListeners.push(listener);\n return () => {\n const i = this.changeListeners.indexOf(listener);\n if (i >= 0) this.changeListeners.splice(i, 1);\n };\n }\n\n private accepted(change: ReceiveChange): ReceiveChange {\n for (const listener of [...this.changeListeners]) listener(change);\n return change;\n }\n\n /** Apply an inbound snapshot or patch frame to the mirror.\n *\n * Decodes by the client's codec: a registered custom codec, else built-in JSON (text) / msgpack\n * (binary). Returns the accepted change so reactive adapters can update only its paths; returns\n * `undefined` for a patch whose revision was already applied, and for an unrecognized message\n * type \u2014 ignored, not an error, so a newer server can add message types without breaking older\n * clients. The returned change and values from `value()` share immutable branches with the\n * mirror; consumers must not mutate them. Invalid frames throw without changing the mirror or its\n * accepted revision.\n */\n recv(data: string | Uint8Array): ReceiveChange | undefined {\n const custom = codecFor(this.codec);\n let msg: SnapshotMsg | PatchMsg | RejectMsg;\n if (custom) {\n msg = custom.decode(data) as SnapshotMsg | PatchMsg | RejectMsg;\n } else if (typeof data === \"string\") {\n msg = JSON.parse(data);\n } else {\n // binary frame: disambiguate by the connection's codec (msgpack vs cbor)\n msg = JSON.parse(\n this.codec === \"cbor\" ? cborToJson(data) : msgpackToJson(data),\n );\n }\n if (msg.t === \"snapshot\") {\n this.values.set(msg.id, msg.value);\n this.revs.set(msg.id, msg.rev);\n return this.accepted({ t: \"snapshot\", id: msg.id, rev: msg.rev });\n } else if (msg.t === \"patch\") {\n // rev is the model's sequence number; ignore a patch already reflected in the mirror (e.g. one\n // the opening snapshot already captured, which the server then also broadcasts).\n const seen = this.revs.get(msg.id);\n if (seen !== undefined && msg.patch.rev <= seen) return undefined;\n const current = this.values.get(msg.id);\n if (current === undefined)\n throw new Error(`patch received before snapshot for model ${msg.id}`);\n this.values.set(msg.id, applyPatch(current as Value, msg.patch));\n this.revs.set(msg.id, msg.patch.rev);\n return this.accepted(msg);\n } else if (msg.t === \"reject\") {\n // the mirror is untouched: the server reverts the proposer with the snapshot sent alongside\n for (const listener of [...this.rejectListeners]) listener(msg);\n return undefined;\n }\n // an unrecognized message type is ignored (not an error): the server may be newer than this\n // client and send types it predates (e.g. a future presence frame)\n return undefined;\n }\n\n /** The current mirrored core `Value` of a model. */\n value(id: number): unknown {\n return this.values.get(id);\n }\n\n ids(): number[] {\n return [...this.values.keys()];\n }\n\n /** Propose an edit to a mirrored model; returns the patch frame to send (encoded in this codec).\n *\n * Server-authoritative: the local mirror updates when the server echoes the authoritative patch\n * back via `recv`, not optimistically.\n */\n edit(id: number, value: unknown): string | Uint8Array {\n const patch = JSON.parse(\n diff(JSON.stringify(this.values.get(id)), JSON.stringify(value)),\n );\n const msg = { t: \"patch\", id, patch };\n const custom = codecFor(this.codec);\n if (custom) return custom.encode(msg);\n const s = JSON.stringify(msg);\n if (this.codec === \"msgpack\") return jsonToMsgpack(s);\n if (this.codec === \"cbor\") return jsonToCbor(s);\n return s;\n }\n\n /** Connect to a transports server and mirror it. Returns the `WebSocket`.\n *\n * On a reconnect (this client already mirrors models) it appends `?since=` with its last-seen rev per\n * model, so the server replays only the delta instead of re-sending each whole model.\n */\n connect(url: string): WebSocket {\n const sep = url.includes(\"?\") ? \"&\" : \"?\";\n let params = `codec=${this.codec}`;\n if (this.revs.size) {\n const since = encodeURIComponent(\n JSON.stringify(Object.fromEntries(this.revs)),\n );\n params += `&since=${since}`;\n }\n const ws = new WebSocket(`${url}${sep}${params}`);\n ws.binaryType = \"arraybuffer\";\n ws.addEventListener(\"message\", (e) => {\n const data = (e as MessageEvent).data;\n this.recv(\n typeof data === \"string\" ? data : new Uint8Array(data as ArrayBuffer),\n );\n });\n return ws;\n }\n\n /** Connect and mirror, **reconnecting** whenever the socket drops \u2014 so the client survives a server\n * restart or a refresh. `authority` decides reconciliation on each (re)connect:\n *\n * - `\"server\"` (default): the server is canonical; the client adopts its state (resuming via `?since=`\n * when it can, else a fresh snapshot) \u2014 the \"refetch on refresh\" behavior.\n * - `\"client\"`: the client is canonical; after the server's snapshot it pushes its last-known state\n * back as an edit, rectifying a server that came back stale/empty (merges under a CRDT, else\n * overwrites).\n *\n * `onMessage` fires after each applied frame (e.g. to re-render). Returns `{ stop() }`.\n */\n run(\n url: string,\n opts: {\n authority?: \"server\" | \"client\";\n retry?: number;\n onMessage?: () => void;\n } = {},\n ): { stop: () => void } {\n const { authority = \"server\", retry = 1000, onMessage } = opts;\n let stopped = false;\n const loop = () => {\n if (stopped) return;\n const pre = authority === \"client\" ? new Map(this.values) : null;\n const pushed = new Set<number>();\n const ws = this.connect(url); // reuses connect(): adds the recv listener + ?since= resume\n ws.addEventListener(\"message\", () => {\n onMessage?.();\n if (pre) {\n // rectify: once the server has (re)snapshotted a model, push our copy back to it\n for (const id of this.values.keys()) {\n if (!pushed.has(id) && pre.has(id)) {\n // cast, not copy: wasm-bindgen types its output Uint8Array<ArrayBufferLike>, but it\n // is always ArrayBuffer-backed, which is what WebSocket.send requires\n ws.send(\n this.edit(id, pre.get(id)) as string | Uint8Array<ArrayBuffer>,\n );\n pushed.add(id);\n }\n }\n }\n });\n ws.addEventListener(\"close\", () => {\n if (!stopped) setTimeout(loop, retry);\n });\n ws.addEventListener(\"error\", () => {\n try {\n ws.close();\n } catch {\n /* already closing */\n }\n });\n };\n loop();\n return {\n stop() {\n stopped = true;\n },\n };\n }\n\n /** Mirror a server over Server-Sent Events (receive-only, JSON). Returns the `EventSource`. */\n connectSSE(url: string): EventSource {\n const es = new EventSource(url);\n es.addEventListener(\"message\", (e) =>\n this.recv((e as MessageEvent).data as string),\n );\n return es;\n }\n}\n", "import * as wasm from \"../../dist/pkg/transports\";\n\nexport * as wasm from \"../../dist/pkg/transports\";\n\nexport const placeholder = \"\";\n\n/** Diff two JSON-encoded models, returning the JSON-encoded patch. */\nexport const diff = (oldModel: string, newModel: string): string =>\n wasm.diff(oldModel, newModel);\n\n/** Apply a JSON-encoded patch to a JSON-encoded model, returning the JSON-encoded result. */\nexport const apply = (model: string, patch: string): string =>\n wasm.apply(model, patch);\n\n/** Encode a JSON-encoded model to codec bytes. */\nexport const encode = (model: string): Uint8Array => wasm.encode(model);\n\n/** Decode codec bytes back to a JSON-encoded model string. */\nexport const decode = (bytes: Uint8Array): string => wasm.decode(bytes);\n\n/** Encode a JSON-encoded model with the codec named by `codec` (e.g. \"application/msgpack\"). */\nexport const encodeAs = (model: string, codec: string): Uint8Array =>\n wasm.encode_as(model, codec);\n\n/** Decode bytes (from `codec`'s codec) back to a JSON-encoded model string. */\nexport const decodeAs = (bytes: Uint8Array, codec: string): string =>\n wasm.decode_as(bytes, codec);\n\n/** Convert an arbitrary JSON document to MessagePack bytes (for whole protocol messages). */\nexport const jsonToMsgpack = (json: string): Uint8Array =>\n wasm.json_to_msgpack(json);\n\n/** Convert MessagePack bytes back to a JSON document. */\nexport const msgpackToJson = (bytes: Uint8Array): string =>\n wasm.msgpack_to_json(bytes);\n\n/** Convert an arbitrary JSON document to CBOR bytes (for whole protocol messages). */\nexport const jsonToCbor = (json: string): Uint8Array => wasm.json_to_cbor(json);\n\n/** Convert CBOR bytes back to a JSON document. */\nexport const cborToJson = (bytes: Uint8Array): string =>\n wasm.cbor_to_json(bytes);\n\n/** In-process model store: host / mutate \u2192 patch / apply / snapshot. */\nexport const Store = wasm.Store;\n\n// Plain JS object <-> core `Value` bridge (the JS analog of the Python bridge).\nexport { toValue, fromValue } from \"./bridge\";\nexport type { Value } from \"./bridge\";\n\n// WebSocket client that mirrors a remote Session.\nexport { Client } from \"./client\";\nexport type {\n ModelPatch,\n PatchOp,\n PathSeg,\n ReceiveChange,\n RejectMsg,\n} from \"./client\";\n\n// Custom wire codec registry.\nexport { registerCodec, unregisterCodec, codecFor } from \"./codecs\";\nexport type { CodecEncode, CodecDecode } from \"./codecs\";\n"],
|
|
5
|
+
"mappings": ";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,IAAM,QAAN,MAAY;AAAA,EACf,qBAAqB;AACjB,UAAM,MAAM,KAAK;AACjB,SAAK,YAAY;AACjB,sBAAkB,WAAW,IAAI;AACjC,WAAO;AAAA,EACX;AAAA,EACA,OAAO;AACH,UAAM,MAAM,KAAK,mBAAmB;AACpC,SAAK,iBAAiB,KAAK,CAAC;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,IAAI,YAAY;AAClB,UAAM,OAAO,kBAAkB,YAAY,KAAK,mBAAmB,KAAK,kBAAkB;AAC1F,UAAM,OAAO;AACb,UAAM,MAAM,KAAK,YAAY,KAAK,WAAW,IAAI,MAAM,IAAI;AAC3D,QAAI,IAAI,CAAC,GAAG;AACR,YAAM,wBAAwB,IAAI,CAAC,CAAC;AAAA,IACxC;AACA,WA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AAmB,IAAc;AAAA,IAC9C;AACA,WAAO;AAAA,EACT;AACF;;;AC7VO,IAAM,cAAc;AAGpB,IAAMC,QAAO,CAAC,UAAkB,aAChC,KAAK,UAAU,QAAQ;AAGvB,IAAMC,SAAQ,CAAC,OAAe,UAC9B,MAAM,OAAO,KAAK;AAGlB,IAAMC,UAAS,CAAC,UAAmC,OAAO,KAAK;AAG/D,IAAMC,UAAS,CAAC,UAAmC,OAAO,KAAK;AAG/D,IAAM,WAAW,CAAC,OAAe,UACjC,UAAU,OAAO,KAAK;AAGtB,IAAM,WAAW,CAAC,OAAmB,UACrC,UAAU,OAAO,KAAK;AAGtB,IAAM,gBAAgB,CAAC,SACvB,gBAAgB,IAAI;AAGpB,IAAM,gBAAgB,CAAC,UACvB,gBAAgB,KAAK;AAGrB,IAAM,aAAa,CAAC,SAAkC,aAAa,IAAI;AAGvE,IAAM,aAAa,CAAC,UACpB,aAAa,KAAK;AAGlB,IAAMC,SAAa;",
|
|
6
|
+
"names": ["ptr", "encode", "decode", "diff", "diff", "apply", "encode", "decode", "Store"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** The core `Value` wire form: the externally-tagged enum the Rust core speaks. */
|
|
2
|
+
export type Value = "Null" | {
|
|
3
|
+
Bool: boolean;
|
|
4
|
+
} | {
|
|
5
|
+
Int: number;
|
|
6
|
+
} | {
|
|
7
|
+
Float: number;
|
|
8
|
+
} | {
|
|
9
|
+
Str: string;
|
|
10
|
+
} | {
|
|
11
|
+
List: Value[];
|
|
12
|
+
} | {
|
|
13
|
+
Map: {
|
|
14
|
+
[k: string]: Value;
|
|
15
|
+
};
|
|
16
|
+
} | {
|
|
17
|
+
Submodel: number;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Convert a plain JS value to the core `Value` wire form.
|
|
21
|
+
*
|
|
22
|
+
* Note: JS has a single number type, so integers and whole-valued floats both encode as `Int`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function toValue(v: unknown): Value;
|
|
25
|
+
/** Convert a core `Value` back to a plain JS value. */
|
|
26
|
+
export declare function fromValue(value: Value): unknown;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { Value } from "./bridge";
|
|
2
|
+
export type PathSeg = {
|
|
3
|
+
Key: string;
|
|
4
|
+
} | {
|
|
5
|
+
Index: number;
|
|
6
|
+
};
|
|
7
|
+
export type PatchOp = {
|
|
8
|
+
Set: {
|
|
9
|
+
path: PathSeg[];
|
|
10
|
+
value: Value;
|
|
11
|
+
};
|
|
12
|
+
} | {
|
|
13
|
+
Remove: {
|
|
14
|
+
path: PathSeg[];
|
|
15
|
+
};
|
|
16
|
+
} | {
|
|
17
|
+
Insert: {
|
|
18
|
+
path: PathSeg[];
|
|
19
|
+
index: number;
|
|
20
|
+
value: Value;
|
|
21
|
+
};
|
|
22
|
+
} | {
|
|
23
|
+
RemoveAt: {
|
|
24
|
+
path: PathSeg[];
|
|
25
|
+
index: number;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export type ModelPatch = {
|
|
29
|
+
rev: number;
|
|
30
|
+
ops: PatchOp[];
|
|
31
|
+
};
|
|
32
|
+
type PatchMsg = {
|
|
33
|
+
t: "patch";
|
|
34
|
+
id: number;
|
|
35
|
+
patch: ModelPatch;
|
|
36
|
+
};
|
|
37
|
+
/** Frame metadata returned after the mirror accepts a snapshot or patch. */
|
|
38
|
+
export type ReceiveChange = {
|
|
39
|
+
t: "snapshot";
|
|
40
|
+
id: number;
|
|
41
|
+
rev: number;
|
|
42
|
+
} | PatchMsg;
|
|
43
|
+
/** Mirrors a remote transports `Session` from connection messages.
|
|
44
|
+
*
|
|
45
|
+
* Inbound frames are decoded by type — text frames are JSON, binary frames are MessagePack — so a
|
|
46
|
+
* client transparently mirrors a server regardless of the negotiated codec. Binary built-in codecs
|
|
47
|
+
* and edit generation require the wasm core to be initialized.
|
|
48
|
+
*/
|
|
49
|
+
export declare class Client {
|
|
50
|
+
private codec;
|
|
51
|
+
private values;
|
|
52
|
+
private revs;
|
|
53
|
+
constructor(codec?: string);
|
|
54
|
+
/** Apply an inbound snapshot or patch frame to the mirror.
|
|
55
|
+
*
|
|
56
|
+
* Decodes by the client's codec: a registered custom codec, else built-in JSON (text) / msgpack
|
|
57
|
+
* (binary). Returns the accepted change so reactive adapters can update only its paths; returns
|
|
58
|
+
* `undefined` for a patch whose revision was already applied. The returned change and values from
|
|
59
|
+
* `value()` share immutable branches with the mirror; consumers must not mutate them. Invalid frames
|
|
60
|
+
* throw without changing the mirror or its accepted revision.
|
|
61
|
+
*/
|
|
62
|
+
recv(data: string | Uint8Array): ReceiveChange | undefined;
|
|
63
|
+
/** The current mirrored core `Value` of a model. */
|
|
64
|
+
value(id: number): unknown;
|
|
65
|
+
ids(): number[];
|
|
66
|
+
/** Propose an edit to a mirrored model; returns the patch frame to send (encoded in this codec).
|
|
67
|
+
*
|
|
68
|
+
* Server-authoritative: the local mirror updates when the server echoes the authoritative patch
|
|
69
|
+
* back via `recv`, not optimistically.
|
|
70
|
+
*/
|
|
71
|
+
edit(id: number, value: unknown): string | Uint8Array;
|
|
72
|
+
/** Connect to a transports server and mirror it. Returns the `WebSocket`.
|
|
73
|
+
*
|
|
74
|
+
* On a reconnect (this client already mirrors models) it appends `?since=` with its last-seen rev per
|
|
75
|
+
* model, so the server replays only the delta instead of re-sending each whole model.
|
|
76
|
+
*/
|
|
77
|
+
connect(url: string): WebSocket;
|
|
78
|
+
/** Connect and mirror, **reconnecting** whenever the socket drops — so the client survives a server
|
|
79
|
+
* restart or a refresh. `authority` decides reconciliation on each (re)connect:
|
|
80
|
+
*
|
|
81
|
+
* - `"server"` (default): the server is canonical; the client adopts its state (resuming via `?since=`
|
|
82
|
+
* when it can, else a fresh snapshot) — the "refetch on refresh" behavior.
|
|
83
|
+
* - `"client"`: the client is canonical; after the server's snapshot it pushes its last-known state
|
|
84
|
+
* back as an edit, rectifying a server that came back stale/empty (merges under a CRDT, else
|
|
85
|
+
* overwrites).
|
|
86
|
+
*
|
|
87
|
+
* `onMessage` fires after each applied frame (e.g. to re-render). Returns `{ stop() }`.
|
|
88
|
+
*/
|
|
89
|
+
run(url: string, opts?: {
|
|
90
|
+
authority?: "server" | "client";
|
|
91
|
+
retry?: number;
|
|
92
|
+
onMessage?: () => void;
|
|
93
|
+
}): {
|
|
94
|
+
stop: () => void;
|
|
95
|
+
};
|
|
96
|
+
/** Mirror a server over Server-Sent Events (receive-only, JSON). Returns the `EventSource`. */
|
|
97
|
+
connectSSE(url: string): EventSource;
|
|
98
|
+
}
|
|
99
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Custom wire codec registry (the JS analog of `transports.register_codec` in Python).
|
|
2
|
+
*
|
|
3
|
+
* A codec turns a JSON-able object (a protocol message, or a model `Value`) into a wire frame
|
|
4
|
+
* (`string` or `Uint8Array`) and back. Register a matching implementation here for any content type
|
|
5
|
+
* you also register on the server, then use it via `new Client(contentType)` / `?codec=`.
|
|
6
|
+
*/
|
|
7
|
+
export type CodecEncode = (obj: unknown) => string | Uint8Array;
|
|
8
|
+
export type CodecDecode = (data: string | Uint8Array) => unknown;
|
|
9
|
+
/** Register a custom codec under `contentType`. The built-in json/msgpack codecs cannot be overridden. */
|
|
10
|
+
export declare function registerCodec(contentType: string, encode: CodecEncode, decode: CodecDecode): void;
|
|
11
|
+
/** Remove a previously registered custom codec. */
|
|
12
|
+
export declare function unregisterCodec(contentType: string): void;
|
|
13
|
+
/** The currently registered custom codec for `contentType`, if any. */
|
|
14
|
+
export declare function codecFor(contentType: string): {
|
|
15
|
+
encode: CodecEncode;
|
|
16
|
+
decode: CodecDecode;
|
|
17
|
+
} | undefined;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as wasm from "../../dist/pkg/transports";
|
|
2
|
+
export * as wasm from "../../dist/pkg/transports";
|
|
3
|
+
export declare const placeholder = "";
|
|
4
|
+
/** Diff two JSON-encoded models, returning the JSON-encoded patch. */
|
|
5
|
+
export declare const diff: (oldModel: string, newModel: string) => string;
|
|
6
|
+
/** Apply a JSON-encoded patch to a JSON-encoded model, returning the JSON-encoded result. */
|
|
7
|
+
export declare const apply: (model: string, patch: string) => string;
|
|
8
|
+
/** Encode a JSON-encoded model to codec bytes. */
|
|
9
|
+
export declare const encode: (model: string) => Uint8Array;
|
|
10
|
+
/** Decode codec bytes back to a JSON-encoded model string. */
|
|
11
|
+
export declare const decode: (bytes: Uint8Array) => string;
|
|
12
|
+
/** Encode a JSON-encoded model with the codec named by `codec` (e.g. "application/msgpack"). */
|
|
13
|
+
export declare const encodeAs: (model: string, codec: string) => Uint8Array;
|
|
14
|
+
/** Decode bytes (from `codec`'s codec) back to a JSON-encoded model string. */
|
|
15
|
+
export declare const decodeAs: (bytes: Uint8Array, codec: string) => string;
|
|
16
|
+
/** Convert an arbitrary JSON document to MessagePack bytes (for whole protocol messages). */
|
|
17
|
+
export declare const jsonToMsgpack: (json: string) => Uint8Array;
|
|
18
|
+
/** Convert MessagePack bytes back to a JSON document. */
|
|
19
|
+
export declare const msgpackToJson: (bytes: Uint8Array) => string;
|
|
20
|
+
/** Convert an arbitrary JSON document to CBOR bytes (for whole protocol messages). */
|
|
21
|
+
export declare const jsonToCbor: (json: string) => Uint8Array;
|
|
22
|
+
/** Convert CBOR bytes back to a JSON document. */
|
|
23
|
+
export declare const cborToJson: (bytes: Uint8Array) => string;
|
|
24
|
+
/** In-process model store: host / mutate → patch / apply / snapshot. */
|
|
25
|
+
export declare const Store: typeof wasm.Store;
|
|
26
|
+
export { toValue, fromValue } from "./bridge";
|
|
27
|
+
export type { Value } from "./bridge";
|
|
28
|
+
export { Client } from "./client";
|
|
29
|
+
export type { ModelPatch, PatchOp, PathSeg, ReceiveChange } from "./client";
|
|
30
|
+
export { registerCodec, unregisterCodec, codecFor } from "./codecs";
|
|
31
|
+
export type { CodecEncode, CodecDecode } from "./codecs";
|
package/dist/pkg/transports.d.ts
CHANGED
|
@@ -31,6 +31,11 @@ export class Store {
|
|
|
31
31
|
*/
|
|
32
32
|
export function apply(value: string, patch: string): string;
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Convert CBOR bytes back to a JSON document.
|
|
36
|
+
*/
|
|
37
|
+
export function cbor_to_json(data: Uint8Array): string;
|
|
38
|
+
|
|
34
39
|
/**
|
|
35
40
|
* Decode codec bytes back to a JSON-encoded model string.
|
|
36
41
|
*/
|
|
@@ -56,6 +61,11 @@ export function encode(value: string): Uint8Array;
|
|
|
56
61
|
*/
|
|
57
62
|
export function encode_as(value: string, codec: string): Uint8Array;
|
|
58
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Convert an arbitrary JSON document to CBOR bytes (a `Uint8Array` in JS).
|
|
66
|
+
*/
|
|
67
|
+
export function json_to_cbor(json: string): Uint8Array;
|
|
68
|
+
|
|
59
69
|
/**
|
|
60
70
|
* Convert an arbitrary JSON document to MessagePack bytes (a `Uint8Array` in JS).
|
|
61
71
|
*/
|
|
@@ -72,11 +82,13 @@ export interface InitOutput {
|
|
|
72
82
|
readonly memory: WebAssembly.Memory;
|
|
73
83
|
readonly __wbg_store_free: (a: number, b: number) => void;
|
|
74
84
|
readonly apply: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
85
|
+
readonly cbor_to_json: (a: number, b: number) => [number, number, number, number];
|
|
75
86
|
readonly decode: (a: number, b: number) => [number, number, number, number];
|
|
76
87
|
readonly decode_as: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
77
88
|
readonly diff: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
78
89
|
readonly encode: (a: number, b: number) => [number, number, number, number];
|
|
79
90
|
readonly encode_as: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
91
|
+
readonly json_to_cbor: (a: number, b: number) => [number, number, number, number];
|
|
80
92
|
readonly json_to_msgpack: (a: number, b: number) => [number, number, number, number];
|
|
81
93
|
readonly msgpack_to_json: (a: number, b: number) => [number, number, number, number];
|
|
82
94
|
readonly store_apply: (a: number, b: bigint, c: number, d: number) => [number, number, number];
|
package/dist/pkg/transports.js
CHANGED
|
@@ -118,6 +118,32 @@ export function apply(value, patch) {
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Convert CBOR bytes back to a JSON document.
|
|
123
|
+
* @param {Uint8Array} data
|
|
124
|
+
* @returns {string}
|
|
125
|
+
*/
|
|
126
|
+
export function cbor_to_json(data) {
|
|
127
|
+
let deferred3_0;
|
|
128
|
+
let deferred3_1;
|
|
129
|
+
try {
|
|
130
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
131
|
+
const len0 = WASM_VECTOR_LEN;
|
|
132
|
+
const ret = wasm.cbor_to_json(ptr0, len0);
|
|
133
|
+
var ptr2 = ret[0];
|
|
134
|
+
var len2 = ret[1];
|
|
135
|
+
if (ret[3]) {
|
|
136
|
+
ptr2 = 0; len2 = 0;
|
|
137
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
138
|
+
}
|
|
139
|
+
deferred3_0 = ptr2;
|
|
140
|
+
deferred3_1 = len2;
|
|
141
|
+
return getStringFromWasm0(ptr2, len2);
|
|
142
|
+
} finally {
|
|
143
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
121
147
|
/**
|
|
122
148
|
* Decode codec bytes back to a JSON-encoded model string.
|
|
123
149
|
* @param {Uint8Array} data
|
|
@@ -239,6 +265,23 @@ export function encode_as(value, codec) {
|
|
|
239
265
|
return v3;
|
|
240
266
|
}
|
|
241
267
|
|
|
268
|
+
/**
|
|
269
|
+
* Convert an arbitrary JSON document to CBOR bytes (a `Uint8Array` in JS).
|
|
270
|
+
* @param {string} json
|
|
271
|
+
* @returns {Uint8Array}
|
|
272
|
+
*/
|
|
273
|
+
export function json_to_cbor(json) {
|
|
274
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
275
|
+
const len0 = WASM_VECTOR_LEN;
|
|
276
|
+
const ret = wasm.json_to_cbor(ptr0, len0);
|
|
277
|
+
if (ret[3]) {
|
|
278
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
279
|
+
}
|
|
280
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
281
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
282
|
+
return v2;
|
|
283
|
+
}
|
|
284
|
+
|
|
242
285
|
/**
|
|
243
286
|
* Convert an arbitrary JSON document to MessagePack bytes (a `Uint8Array` in JS).
|
|
244
287
|
* @param {string} json
|
|
@@ -284,11 +327,11 @@ export function msgpack_to_json(data) {
|
|
|
284
327
|
function __wbg_get_imports() {
|
|
285
328
|
const import0 = {
|
|
286
329
|
__proto__: null,
|
|
287
|
-
|
|
330
|
+
__wbg_Error_92b29b0548f8b746: function(arg0, arg1) {
|
|
288
331
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
289
332
|
return ret;
|
|
290
333
|
},
|
|
291
|
-
|
|
334
|
+
__wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
|
|
292
335
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
293
336
|
},
|
|
294
337
|
__wbindgen_init_externref_table: function() {
|
|
Binary file
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
4
|
export const __wbg_store_free: (a: number, b: number) => void;
|
|
5
5
|
export const apply: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
6
|
+
export const cbor_to_json: (a: number, b: number) => [number, number, number, number];
|
|
6
7
|
export const decode: (a: number, b: number) => [number, number, number, number];
|
|
7
8
|
export const decode_as: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
8
9
|
export const diff: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
9
10
|
export const encode: (a: number, b: number) => [number, number, number, number];
|
|
10
11
|
export const encode_as: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
12
|
+
export const json_to_cbor: (a: number, b: number) => [number, number, number, number];
|
|
11
13
|
export const json_to_msgpack: (a: number, b: number) => [number, number, number, number];
|
|
12
14
|
export const msgpack_to_json: (a: number, b: number) => [number, number, number, number];
|
|
13
15
|
export const store_apply: (a: number, b: bigint, c: number, d: number) => [number, number, number];
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1kbgz/transports",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Generic communication library",
|
|
5
|
-
"repository":
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git@github.com:1kbgz/transports.git"
|
|
8
|
+
},
|
|
6
9
|
"author": "1kbgz <dev@1kbgz.com>",
|
|
7
10
|
"license": "Apache-2.0",
|
|
8
11
|
"type": "module",
|
|
@@ -25,34 +28,35 @@
|
|
|
25
28
|
"access": "public"
|
|
26
29
|
},
|
|
27
30
|
"devDependencies": {
|
|
28
|
-
"@playwright/test": "^1.
|
|
31
|
+
"@playwright/test": "^1.62.0",
|
|
29
32
|
"cpy": "^13.2.2",
|
|
30
|
-
"esbuild": "^0.28.
|
|
31
|
-
"lightningcss": "^1.
|
|
33
|
+
"esbuild": "^0.28.1",
|
|
34
|
+
"lightningcss": "^1.33.0",
|
|
32
35
|
"http-server": "^14.1.1",
|
|
33
36
|
"nodemon": "^3.1.14",
|
|
34
37
|
"npm-run-all": "^4.1.5",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
38
|
+
"oxfmt": "^0.63.0",
|
|
39
|
+
"oxlint": "^1.78.0",
|
|
40
|
+
"typescript": "^7.0.2"
|
|
37
41
|
},
|
|
38
42
|
"scripts": {
|
|
39
|
-
"setup": "cargo install -f wasm-bindgen-cli --version 0.2.
|
|
43
|
+
"setup": "cargo install -f wasm-bindgen-cli --version 0.2.126 --locked",
|
|
40
44
|
"build:debug": "node build.mjs --debug",
|
|
41
|
-
"build:rust": "cargo build --release --all-features --target wasm32-unknown-unknown",
|
|
45
|
+
"build:rust": "cargo build --release --all-features --target wasm32-unknown-unknown --target-dir ../target",
|
|
42
46
|
"build:wasm-bindgen": "wasm-bindgen ../target/wasm32-unknown-unknown/release/transports.wasm --out-dir ./dist/pkg --target web",
|
|
43
47
|
"build:prod": "node build.mjs",
|
|
44
48
|
"build": "npm-run-all build:rust build:wasm-bindgen build:prod",
|
|
45
49
|
"clean": "rm -rf dist lib playwright-report ../transports/extension",
|
|
46
50
|
"dev": "npm-run-all -p start watch",
|
|
47
|
-
"lint:js": "
|
|
51
|
+
"lint:js": "oxlint . && oxfmt --check \"src/**/*.{js,ts,jsx,tsx,css}\" \"tests/**/*.{js,ts,jsx,tsx}\" \"*.mjs\" \"*.json\"",
|
|
48
52
|
"lint:rust": "cargo clippy --all-features && cargo fmt --all -- --check",
|
|
49
53
|
"lint": "npm-run-all lint:*",
|
|
50
|
-
"fix:js": "
|
|
54
|
+
"fix:js": "oxlint --fix . && oxfmt --write \"src/**/*.{js,ts,jsx,tsx,css}\" \"tests/**/*.{js,ts,jsx,tsx}\" \"*.mjs\" \"*.json\"",
|
|
51
55
|
"fix:rust": "cargo fmt --all",
|
|
52
56
|
"fix": "npm-run-all fix:*",
|
|
53
57
|
"preinstall": "npx only-allow pnpm",
|
|
54
58
|
"start": "http-server -p 3000 -o examples/",
|
|
55
|
-
"start:tests": "http-server -p 3000
|
|
59
|
+
"start:tests": "http-server .. -p 3000",
|
|
56
60
|
"test:js": "playwright test",
|
|
57
61
|
"test:rust": "cargo test -- --show-output",
|
|
58
62
|
"test": "npm-run-all test:rust test:js",
|
package/dist/html/index.html
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<html lang="en">
|
|
2
|
-
<head>
|
|
3
|
-
<meta charset="UTF-8" />
|
|
4
|
-
<title>transports</title>
|
|
5
|
-
<meta name="description" content="Generic communication library" />
|
|
6
|
-
<meta name="author" content="1kbgz" />
|
|
7
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
8
|
-
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
|
9
|
-
<link rel="stylesheet" type="text/css" href="css/index.css" />
|
|
10
|
-
<script type="module" src="cdn/index.js"></script>
|
|
11
|
-
</head>
|
|
12
|
-
<body></body>
|
|
13
|
-
</html>
|