@1kbgz/transports 0.7.0 → 0.8.4
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 +1 -841
- package/dist/cdn/index.js.map +3 -3
- package/dist/cdn/widget.js +1 -660
- package/dist/cdn/widget.js.map +3 -3
- package/dist/esm/client.d.ts +180 -0
- package/dist/esm/{src/ts/index.d.ts → index.d.ts} +9 -1
- package/dist/esm/index.js +1 -841
- package/dist/esm/index.js.map +3 -3
- package/dist/esm/widget.d.ts +14 -0
- package/dist/pkg/transports.d.ts +43 -0
- package/dist/pkg/transports.js +250 -5
- package/dist/pkg/transports_bg.wasm +0 -0
- package/dist/pkg/transports_bg.wasm.d.ts +12 -0
- package/package.json +12 -11
- package/dist/esm/src/ts/client.d.ts +0 -99
- /package/dist/esm/{src/ts/bridge.d.ts → bridge.d.ts} +0 -0
- /package/dist/esm/{src/ts/codecs.d.ts → codecs.d.ts} +0 -0
package/dist/pkg/transports.js
CHANGED
|
@@ -1,5 +1,164 @@
|
|
|
1
1
|
/* @ts-self-types="./transports.d.ts" */
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Shared revision and proposal reducer for a language-level client adapter.
|
|
5
|
+
*/
|
|
6
|
+
export class ClientState {
|
|
7
|
+
__destroy_into_raw() {
|
|
8
|
+
const ptr = this.__wbg_ptr;
|
|
9
|
+
this.__wbg_ptr = 0;
|
|
10
|
+
ClientStateFinalization.unregister(this);
|
|
11
|
+
return ptr;
|
|
12
|
+
}
|
|
13
|
+
free() {
|
|
14
|
+
const ptr = this.__destroy_into_raw();
|
|
15
|
+
wasm.__wbg_clientstate_free(ptr, 0);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @param {string} proposal
|
|
19
|
+
* @returns {boolean}
|
|
20
|
+
*/
|
|
21
|
+
abandon(proposal) {
|
|
22
|
+
const ptr0 = passStringToWasm0(proposal, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
23
|
+
const len0 = WASM_VECTOR_LEN;
|
|
24
|
+
const ret = wasm.clientstate_abandon(this.__wbg_ptr, ptr0, len0);
|
|
25
|
+
return ret !== 0;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @param {string} effect_json
|
|
29
|
+
*/
|
|
30
|
+
commit(effect_json) {
|
|
31
|
+
const ptr0 = passStringToWasm0(effect_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
32
|
+
const len0 = WASM_VECTOR_LEN;
|
|
33
|
+
const ret = wasm.clientstate_commit(this.__wbg_ptr, ptr0, len0);
|
|
34
|
+
if (ret[1]) {
|
|
35
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @returns {string}
|
|
40
|
+
*/
|
|
41
|
+
disconnect() {
|
|
42
|
+
let deferred2_0;
|
|
43
|
+
let deferred2_1;
|
|
44
|
+
try {
|
|
45
|
+
const ret = wasm.clientstate_disconnect(this.__wbg_ptr);
|
|
46
|
+
var ptr1 = ret[0];
|
|
47
|
+
var len1 = ret[1];
|
|
48
|
+
if (ret[3]) {
|
|
49
|
+
ptr1 = 0; len1 = 0;
|
|
50
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
51
|
+
}
|
|
52
|
+
deferred2_0 = ptr1;
|
|
53
|
+
deferred2_1 = len1;
|
|
54
|
+
return getStringFromWasm0(ptr1, len1);
|
|
55
|
+
} finally {
|
|
56
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
constructor() {
|
|
60
|
+
const ret = wasm.clientstate_new();
|
|
61
|
+
this.__wbg_ptr = ret;
|
|
62
|
+
ClientStateFinalization.register(this, this.__wbg_ptr, this);
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @returns {string}
|
|
67
|
+
*/
|
|
68
|
+
pending() {
|
|
69
|
+
let deferred2_0;
|
|
70
|
+
let deferred2_1;
|
|
71
|
+
try {
|
|
72
|
+
const ret = wasm.clientstate_pending(this.__wbg_ptr);
|
|
73
|
+
var ptr1 = ret[0];
|
|
74
|
+
var len1 = ret[1];
|
|
75
|
+
if (ret[3]) {
|
|
76
|
+
ptr1 = 0; len1 = 0;
|
|
77
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
78
|
+
}
|
|
79
|
+
deferred2_0 = ptr1;
|
|
80
|
+
deferred2_1 = len1;
|
|
81
|
+
return getStringFromWasm0(ptr1, len1);
|
|
82
|
+
} finally {
|
|
83
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* @param {string} message_json
|
|
88
|
+
* @returns {string}
|
|
89
|
+
*/
|
|
90
|
+
prepare(message_json) {
|
|
91
|
+
let deferred3_0;
|
|
92
|
+
let deferred3_1;
|
|
93
|
+
try {
|
|
94
|
+
const ptr0 = passStringToWasm0(message_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
95
|
+
const len0 = WASM_VECTOR_LEN;
|
|
96
|
+
const ret = wasm.clientstate_prepare(this.__wbg_ptr, ptr0, len0);
|
|
97
|
+
var ptr2 = ret[0];
|
|
98
|
+
var len2 = ret[1];
|
|
99
|
+
if (ret[3]) {
|
|
100
|
+
ptr2 = 0; len2 = 0;
|
|
101
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
102
|
+
}
|
|
103
|
+
deferred3_0 = ptr2;
|
|
104
|
+
deferred3_1 = len2;
|
|
105
|
+
return getStringFromWasm0(ptr2, len2);
|
|
106
|
+
} finally {
|
|
107
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* @param {bigint} id
|
|
112
|
+
* @param {string} ops_json
|
|
113
|
+
* @param {string | null} [proposal]
|
|
114
|
+
* @returns {string}
|
|
115
|
+
*/
|
|
116
|
+
proposal(id, ops_json, proposal) {
|
|
117
|
+
let deferred4_0;
|
|
118
|
+
let deferred4_1;
|
|
119
|
+
try {
|
|
120
|
+
const ptr0 = passStringToWasm0(ops_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
121
|
+
const len0 = WASM_VECTOR_LEN;
|
|
122
|
+
var ptr1 = isLikeNone(proposal) ? 0 : passStringToWasm0(proposal, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
123
|
+
var len1 = WASM_VECTOR_LEN;
|
|
124
|
+
const ret = wasm.clientstate_proposal(this.__wbg_ptr, id, ptr0, len0, ptr1, len1);
|
|
125
|
+
var ptr3 = ret[0];
|
|
126
|
+
var len3 = ret[1];
|
|
127
|
+
if (ret[3]) {
|
|
128
|
+
ptr3 = 0; len3 = 0;
|
|
129
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
130
|
+
}
|
|
131
|
+
deferred4_0 = ptr3;
|
|
132
|
+
deferred4_1 = len3;
|
|
133
|
+
return getStringFromWasm0(ptr3, len3);
|
|
134
|
+
} finally {
|
|
135
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* @returns {string}
|
|
140
|
+
*/
|
|
141
|
+
revisions() {
|
|
142
|
+
let deferred2_0;
|
|
143
|
+
let deferred2_1;
|
|
144
|
+
try {
|
|
145
|
+
const ret = wasm.clientstate_revisions(this.__wbg_ptr);
|
|
146
|
+
var ptr1 = ret[0];
|
|
147
|
+
var len1 = ret[1];
|
|
148
|
+
if (ret[3]) {
|
|
149
|
+
ptr1 = 0; len1 = 0;
|
|
150
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
151
|
+
}
|
|
152
|
+
deferred2_0 = ptr1;
|
|
153
|
+
deferred2_1 = len1;
|
|
154
|
+
return getStringFromWasm0(ptr1, len1);
|
|
155
|
+
} finally {
|
|
156
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (Symbol.dispose) ClientState.prototype[Symbol.dispose] = ClientState.prototype.free;
|
|
161
|
+
|
|
3
162
|
/**
|
|
4
163
|
* In-process model store: host / mutate → patch / apply / snapshot.
|
|
5
164
|
*/
|
|
@@ -61,7 +220,7 @@ export class Store {
|
|
|
61
220
|
}
|
|
62
221
|
let v2;
|
|
63
222
|
if (ret[0] !== 0) {
|
|
64
|
-
v2 = getStringFromWasm0(ret[0], ret[1])
|
|
223
|
+
v2 = getStringFromWasm0(ret[0], ret[1]);
|
|
65
224
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
66
225
|
}
|
|
67
226
|
return v2;
|
|
@@ -81,7 +240,7 @@ export class Store {
|
|
|
81
240
|
const ret = wasm.store_snapshot(this.__wbg_ptr, id);
|
|
82
241
|
let v1;
|
|
83
242
|
if (ret[0] !== 0) {
|
|
84
|
-
v1 = getStringFromWasm0(ret[0], ret[1])
|
|
243
|
+
v1 = getStringFromWasm0(ret[0], ret[1]);
|
|
85
244
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
86
245
|
}
|
|
87
246
|
return v1;
|
|
@@ -199,6 +358,35 @@ export function decode_as(data, codec) {
|
|
|
199
358
|
}
|
|
200
359
|
}
|
|
201
360
|
|
|
361
|
+
/**
|
|
362
|
+
* Decode one built-in connection-codec payload as a typed live protocol message JSON string.
|
|
363
|
+
* @param {Uint8Array} data
|
|
364
|
+
* @param {string} codec
|
|
365
|
+
* @returns {string}
|
|
366
|
+
*/
|
|
367
|
+
export function decode_message(data, codec) {
|
|
368
|
+
let deferred4_0;
|
|
369
|
+
let deferred4_1;
|
|
370
|
+
try {
|
|
371
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
372
|
+
const len0 = WASM_VECTOR_LEN;
|
|
373
|
+
const ptr1 = passStringToWasm0(codec, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
374
|
+
const len1 = WASM_VECTOR_LEN;
|
|
375
|
+
const ret = wasm.decode_message(ptr0, len0, ptr1, len1);
|
|
376
|
+
var ptr3 = ret[0];
|
|
377
|
+
var len3 = ret[1];
|
|
378
|
+
if (ret[3]) {
|
|
379
|
+
ptr3 = 0; len3 = 0;
|
|
380
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
381
|
+
}
|
|
382
|
+
deferred4_0 = ptr3;
|
|
383
|
+
deferred4_1 = len3;
|
|
384
|
+
return getStringFromWasm0(ptr3, len3);
|
|
385
|
+
} finally {
|
|
386
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
202
390
|
/**
|
|
203
391
|
* Diff two JSON-encoded models, returning the JSON-encoded patch.
|
|
204
392
|
* @param {string} old
|
|
@@ -265,6 +453,26 @@ export function encode_as(value, codec) {
|
|
|
265
453
|
return v3;
|
|
266
454
|
}
|
|
267
455
|
|
|
456
|
+
/**
|
|
457
|
+
* Encode one JSON live protocol message with a built-in connection codec.
|
|
458
|
+
* @param {string} json
|
|
459
|
+
* @param {string} codec
|
|
460
|
+
* @returns {Uint8Array}
|
|
461
|
+
*/
|
|
462
|
+
export function encode_message(json, codec) {
|
|
463
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
464
|
+
const len0 = WASM_VECTOR_LEN;
|
|
465
|
+
const ptr1 = passStringToWasm0(codec, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
466
|
+
const len1 = WASM_VECTOR_LEN;
|
|
467
|
+
const ret = wasm.encode_message(ptr0, len0, ptr1, len1);
|
|
468
|
+
if (ret[3]) {
|
|
469
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
470
|
+
}
|
|
471
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
472
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
473
|
+
return v3;
|
|
474
|
+
}
|
|
475
|
+
|
|
268
476
|
/**
|
|
269
477
|
* Convert an arbitrary JSON document to CBOR bytes (a `Uint8Array` in JS).
|
|
270
478
|
* @param {string} json
|
|
@@ -324,14 +532,40 @@ export function msgpack_to_json(data) {
|
|
|
324
532
|
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
325
533
|
}
|
|
326
534
|
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Parse and serialize one typed live protocol message as compact JSON.
|
|
538
|
+
* @param {string} json
|
|
539
|
+
* @returns {string}
|
|
540
|
+
*/
|
|
541
|
+
export function normalize_message(json) {
|
|
542
|
+
let deferred3_0;
|
|
543
|
+
let deferred3_1;
|
|
544
|
+
try {
|
|
545
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
546
|
+
const len0 = WASM_VECTOR_LEN;
|
|
547
|
+
const ret = wasm.normalize_message(ptr0, len0);
|
|
548
|
+
var ptr2 = ret[0];
|
|
549
|
+
var len2 = ret[1];
|
|
550
|
+
if (ret[3]) {
|
|
551
|
+
ptr2 = 0; len2 = 0;
|
|
552
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
553
|
+
}
|
|
554
|
+
deferred3_0 = ptr2;
|
|
555
|
+
deferred3_1 = len2;
|
|
556
|
+
return getStringFromWasm0(ptr2, len2);
|
|
557
|
+
} finally {
|
|
558
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
327
561
|
function __wbg_get_imports() {
|
|
328
562
|
const import0 = {
|
|
329
563
|
__proto__: null,
|
|
330
|
-
|
|
564
|
+
__wbg_Error_408e67f47ca7b58b: function(arg0, arg1) {
|
|
331
565
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
332
566
|
return ret;
|
|
333
567
|
},
|
|
334
|
-
|
|
568
|
+
__wbg___wbindgen_throw_bb96b2010945f0bc: function(arg0, arg1) {
|
|
335
569
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
336
570
|
},
|
|
337
571
|
__wbindgen_init_externref_table: function() {
|
|
@@ -350,6 +584,9 @@ function __wbg_get_imports() {
|
|
|
350
584
|
};
|
|
351
585
|
}
|
|
352
586
|
|
|
587
|
+
const ClientStateFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
588
|
+
? { register: () => {}, unregister: () => {} }
|
|
589
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_clientstate_free(ptr, 1));
|
|
353
590
|
const StoreFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
354
591
|
? { register: () => {}, unregister: () => {} }
|
|
355
592
|
: new FinalizationRegistry(ptr => wasm.__wbg_store_free(ptr, 1));
|
|
@@ -371,6 +608,10 @@ function getUint8ArrayMemory0() {
|
|
|
371
608
|
return cachedUint8ArrayMemory0;
|
|
372
609
|
}
|
|
373
610
|
|
|
611
|
+
function isLikeNone(x) {
|
|
612
|
+
return x === undefined || x === null;
|
|
613
|
+
}
|
|
614
|
+
|
|
374
615
|
function passArray8ToWasm0(arg, malloc) {
|
|
375
616
|
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
376
617
|
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
@@ -462,11 +703,15 @@ function __wbg_finalize_init(instance, module) {
|
|
|
462
703
|
|
|
463
704
|
async function __wbg_load(module, imports) {
|
|
464
705
|
if (typeof Response === 'function' && module instanceof Response) {
|
|
706
|
+
if (!module.ok) {
|
|
707
|
+
throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
|
|
708
|
+
}
|
|
709
|
+
|
|
465
710
|
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
466
711
|
try {
|
|
467
712
|
return await WebAssembly.instantiateStreaming(module, imports);
|
|
468
713
|
} catch (e) {
|
|
469
|
-
const validResponse =
|
|
714
|
+
const validResponse = expectedResponseType(module.type);
|
|
470
715
|
|
|
471
716
|
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
472
717
|
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);
|
|
Binary file
|
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_clientstate_free: (a: number, b: number) => void;
|
|
4
5
|
export const __wbg_store_free: (a: number, b: number) => void;
|
|
5
6
|
export const apply: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
6
7
|
export const cbor_to_json: (a: number, b: number) => [number, number, number, number];
|
|
8
|
+
export const clientstate_abandon: (a: number, b: number, c: number) => number;
|
|
9
|
+
export const clientstate_commit: (a: number, b: number, c: number) => [number, number];
|
|
10
|
+
export const clientstate_disconnect: (a: number) => [number, number, number, number];
|
|
11
|
+
export const clientstate_new: () => number;
|
|
12
|
+
export const clientstate_pending: (a: number) => [number, number, number, number];
|
|
13
|
+
export const clientstate_prepare: (a: number, b: number, c: number) => [number, number, number, number];
|
|
14
|
+
export const clientstate_proposal: (a: number, b: bigint, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
|
15
|
+
export const clientstate_revisions: (a: number) => [number, number, number, number];
|
|
7
16
|
export const decode: (a: number, b: number) => [number, number, number, number];
|
|
8
17
|
export const decode_as: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
18
|
+
export const decode_message: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
9
19
|
export const diff: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
10
20
|
export const encode: (a: number, b: number) => [number, number, number, number];
|
|
11
21
|
export const encode_as: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
22
|
+
export const encode_message: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
12
23
|
export const json_to_cbor: (a: number, b: number) => [number, number, number, number];
|
|
13
24
|
export const json_to_msgpack: (a: number, b: number) => [number, number, number, number];
|
|
14
25
|
export const msgpack_to_json: (a: number, b: number) => [number, number, number, number];
|
|
26
|
+
export const normalize_message: (a: number, b: number) => [number, number, number, number];
|
|
15
27
|
export const store_apply: (a: number, b: bigint, c: number, d: number) => [number, number, number];
|
|
16
28
|
export const store_host: (a: number, b: number, c: number, d: number, e: number) => [bigint, number, number];
|
|
17
29
|
export const store_mutate: (a: number, b: bigint, c: number, d: number) => [number, number, number, number];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1kbgz/transports",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.4",
|
|
4
4
|
"description": "Generic communication library",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,32 +20,33 @@
|
|
|
20
20
|
"./package.json": "./package.json"
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
23
|
-
"dist/**/*"
|
|
24
|
-
"index.d.ts"
|
|
23
|
+
"dist/**/*"
|
|
25
24
|
],
|
|
26
25
|
"types": "./dist/esm/index.d.ts",
|
|
27
26
|
"publishConfig": {
|
|
28
27
|
"access": "public"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
31
|
-
"@playwright/test": "^1.62.
|
|
32
|
-
"cpy": "^13.2.
|
|
33
|
-
"esbuild": "^0.28.
|
|
34
|
-
"lightningcss": "^1.33.0",
|
|
30
|
+
"@playwright/test": "^1.62.1",
|
|
31
|
+
"cpy": "^13.2.3",
|
|
32
|
+
"esbuild": "^0.28.2",
|
|
35
33
|
"http-server": "^14.1.1",
|
|
34
|
+
"lightningcss": "^1.33.0",
|
|
36
35
|
"nodemon": "^3.1.14",
|
|
37
36
|
"npm-run-all": "^4.1.5",
|
|
38
|
-
"oxfmt": "^0.
|
|
39
|
-
"oxlint": "^1.
|
|
37
|
+
"oxfmt": "^0.66.0",
|
|
38
|
+
"oxlint": "^1.81.0",
|
|
40
39
|
"typescript": "^7.0.2"
|
|
41
40
|
},
|
|
42
41
|
"scripts": {
|
|
43
|
-
"setup": "cargo install -f wasm-bindgen-cli --version 0.2.
|
|
42
|
+
"setup": "cargo install -f wasm-bindgen-cli --version 0.2.127 --locked",
|
|
43
|
+
"build:clean": "node -e \"const fs=require('fs'); fs.rmSync('dist',{recursive:true,force:true}); fs.rmSync('../transports/extension',{recursive:true,force:true})\"",
|
|
44
44
|
"build:debug": "node build.mjs --debug",
|
|
45
45
|
"build:rust": "cargo build --release --all-features --target wasm32-unknown-unknown --target-dir ../target",
|
|
46
46
|
"build:wasm-bindgen": "wasm-bindgen ../target/wasm32-unknown-unknown/release/transports.wasm --out-dir ./dist/pkg --target web",
|
|
47
47
|
"build:prod": "node build.mjs",
|
|
48
|
-
"build
|
|
48
|
+
"build:types": "tsc",
|
|
49
|
+
"build": "npm-run-all build:clean build:rust build:wasm-bindgen build:prod build:types",
|
|
49
50
|
"clean": "rm -rf dist lib playwright-report ../transports/extension",
|
|
50
51
|
"dev": "npm-run-all -p start watch",
|
|
51
52
|
"lint:js": "oxlint . && oxfmt --check \"src/**/*.{js,ts,jsx,tsx,css}\" \"tests/**/*.{js,ts,jsx,tsx}\" \"*.mjs\" \"*.json\"",
|
|
@@ -1,99 +0,0 @@
|
|
|
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 {};
|
|
File without changes
|
|
File without changes
|