@nichoth/simple-sync 0.0.0-stage → 0.0.5

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.
Files changed (67) hide show
  1. package/README.md +469 -2
  2. package/dist/client/db.d.ts +67 -0
  3. package/dist/client/db.d.ts.map +1 -0
  4. package/dist/client/db.js +1 -0
  5. package/dist/client/db.js.map +7 -0
  6. package/dist/client/idb.d.ts +12 -0
  7. package/dist/client/idb.d.ts.map +1 -0
  8. package/dist/client/idb.js +72 -0
  9. package/dist/client/idb.js.map +7 -0
  10. package/dist/client/index.d.ts +143 -0
  11. package/dist/client/index.d.ts.map +1 -0
  12. package/dist/client/index.js +362 -0
  13. package/dist/client/index.js.map +7 -0
  14. package/dist/client/sqlite-opfs-rpc.d.ts +21 -0
  15. package/dist/client/sqlite-opfs-rpc.d.ts.map +1 -0
  16. package/dist/client/sqlite-opfs-rpc.js +55 -0
  17. package/dist/client/sqlite-opfs-rpc.js.map +7 -0
  18. package/dist/client/sqlite-opfs.d.ts +15 -0
  19. package/dist/client/sqlite-opfs.d.ts.map +1 -0
  20. package/dist/client/sqlite-opfs.js +31 -0
  21. package/dist/client/sqlite-opfs.js.map +7 -0
  22. package/dist/client/sqlite-opfs.worker.d.ts +6 -0
  23. package/dist/client/sqlite-opfs.worker.d.ts.map +1 -0
  24. package/dist/client/sqlite-opfs.worker.js +47 -0
  25. package/dist/client/sqlite-opfs.worker.js.map +7 -0
  26. package/dist/client/sqlite.d.ts +25 -0
  27. package/dist/client/sqlite.d.ts.map +1 -0
  28. package/dist/client/sqlite.js +117 -0
  29. package/dist/client/sqlite.js.map +7 -0
  30. package/dist/client.d.ts +6 -0
  31. package/dist/client.d.ts.map +1 -0
  32. package/dist/client.js +11 -0
  33. package/dist/client.js.map +7 -0
  34. package/dist/hash.d.ts +23 -0
  35. package/dist/hash.d.ts.map +1 -0
  36. package/dist/hash.js +29 -0
  37. package/dist/hash.js.map +7 -0
  38. package/dist/index.d.ts +10 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +18 -0
  41. package/dist/index.js.map +7 -0
  42. package/dist/meta.json +511 -0
  43. package/dist/op.d.ts +41 -0
  44. package/dist/op.d.ts.map +1 -0
  45. package/dist/op.js +46 -0
  46. package/dist/op.js.map +7 -0
  47. package/dist/reduce.d.ts +55 -0
  48. package/dist/reduce.d.ts.map +1 -0
  49. package/dist/reduce.js +173 -0
  50. package/dist/reduce.js.map +7 -0
  51. package/dist/server/errors.d.ts +16 -0
  52. package/dist/server/errors.d.ts.map +1 -0
  53. package/dist/server/errors.js +14 -0
  54. package/dist/server/errors.js.map +7 -0
  55. package/dist/server/index.d.ts +75 -0
  56. package/dist/server/index.d.ts.map +1 -0
  57. package/dist/server/index.js +324 -0
  58. package/dist/server/index.js.map +7 -0
  59. package/dist/server.d.ts +2 -0
  60. package/dist/server.d.ts.map +1 -0
  61. package/dist/server.js +5 -0
  62. package/dist/server.js.map +7 -0
  63. package/dist/types.d.ts +105 -0
  64. package/dist/types.d.ts.map +1 -0
  65. package/dist/types.js +1 -0
  66. package/dist/types.js.map +7 -0
  67. package/package.json +118 -4
package/dist/meta.json ADDED
@@ -0,0 +1,511 @@
1
+ {
2
+ "inputs": {
3
+ "src/client.ts": {
4
+ "bytes": 338,
5
+ "imports": [],
6
+ "format": "esm"
7
+ },
8
+ "src/client/db.ts": {
9
+ "bytes": 2434,
10
+ "imports": [],
11
+ "format": "esm"
12
+ },
13
+ "src/client/idb.ts": {
14
+ "bytes": 2787,
15
+ "imports": [],
16
+ "format": "esm"
17
+ },
18
+ "src/client/index.ts": {
19
+ "bytes": 17826,
20
+ "imports": [],
21
+ "format": "esm"
22
+ },
23
+ "src/client/sqlite-opfs-rpc.ts": {
24
+ "bytes": 2427,
25
+ "imports": [],
26
+ "format": "esm"
27
+ },
28
+ "src/client/sqlite-opfs.ts": {
29
+ "bytes": 1362,
30
+ "imports": [],
31
+ "format": "esm"
32
+ },
33
+ "src/client/sqlite-opfs.worker.ts": {
34
+ "bytes": 2729,
35
+ "imports": [],
36
+ "format": "esm"
37
+ },
38
+ "src/client/sqlite.ts": {
39
+ "bytes": 5001,
40
+ "imports": [],
41
+ "format": "esm"
42
+ },
43
+ "src/hash.ts": {
44
+ "bytes": 1613,
45
+ "imports": [],
46
+ "format": "esm"
47
+ },
48
+ "src/index.ts": {
49
+ "bytes": 682,
50
+ "imports": [],
51
+ "format": "esm"
52
+ },
53
+ "src/op.ts": {
54
+ "bytes": 2143,
55
+ "imports": [],
56
+ "format": "esm"
57
+ },
58
+ "src/reduce.ts": {
59
+ "bytes": 10135,
60
+ "imports": [],
61
+ "format": "esm"
62
+ },
63
+ "src/server.ts": {
64
+ "bytes": 47,
65
+ "imports": [],
66
+ "format": "esm"
67
+ },
68
+ "src/server/errors.ts": {
69
+ "bytes": 1045,
70
+ "imports": [],
71
+ "format": "esm"
72
+ },
73
+ "src/server/index.ts": {
74
+ "bytes": 18380,
75
+ "imports": [],
76
+ "format": "esm"
77
+ },
78
+ "src/types.ts": {
79
+ "bytes": 3285,
80
+ "imports": [],
81
+ "format": "esm"
82
+ }
83
+ },
84
+ "outputs": {
85
+ "dist/client.js.map": {
86
+ "imports": [],
87
+ "exports": [],
88
+ "inputs": {},
89
+ "bytes": 518
90
+ },
91
+ "dist/client.js": {
92
+ "imports": [
93
+ {
94
+ "path": "./client/index.js",
95
+ "kind": "import-statement",
96
+ "external": true
97
+ },
98
+ {
99
+ "path": "./client/idb.js",
100
+ "kind": "import-statement",
101
+ "external": true
102
+ },
103
+ {
104
+ "path": "./client/sqlite.js",
105
+ "kind": "import-statement",
106
+ "external": true
107
+ }
108
+ ],
109
+ "exports": [
110
+ "SyncClient",
111
+ "idb",
112
+ "sqlite"
113
+ ],
114
+ "entryPoint": "src/client.ts",
115
+ "inputs": {
116
+ "src/client.ts": {
117
+ "bytesInOutput": 134
118
+ }
119
+ },
120
+ "bytes": 211
121
+ },
122
+ "dist/client/db.js.map": {
123
+ "imports": [],
124
+ "exports": [],
125
+ "inputs": {},
126
+ "bytes": 93
127
+ },
128
+ "dist/client/db.js": {
129
+ "imports": [],
130
+ "exports": [],
131
+ "entryPoint": "src/client/db.ts",
132
+ "inputs": {
133
+ "src/client/db.ts": {
134
+ "bytesInOutput": 0
135
+ }
136
+ },
137
+ "bytes": 31
138
+ },
139
+ "dist/client/idb.js.map": {
140
+ "imports": [],
141
+ "exports": [],
142
+ "inputs": {},
143
+ "bytes": 4416
144
+ },
145
+ "dist/client/idb.js": {
146
+ "imports": [
147
+ {
148
+ "path": "idb",
149
+ "kind": "import-statement",
150
+ "external": true
151
+ }
152
+ ],
153
+ "exports": [
154
+ "idb"
155
+ ],
156
+ "entryPoint": "src/client/idb.ts",
157
+ "inputs": {
158
+ "src/client/idb.ts": {
159
+ "bytesInOutput": 1714
160
+ }
161
+ },
162
+ "bytes": 1893
163
+ },
164
+ "dist/client/index.js.map": {
165
+ "imports": [],
166
+ "exports": [],
167
+ "inputs": {},
168
+ "bytes": 25714
169
+ },
170
+ "dist/client/index.js": {
171
+ "imports": [
172
+ {
173
+ "path": "mitt",
174
+ "kind": "import-statement",
175
+ "external": true
176
+ },
177
+ {
178
+ "path": "monotonic-timestamp",
179
+ "kind": "import-statement",
180
+ "external": true
181
+ },
182
+ {
183
+ "path": "../reduce.js",
184
+ "kind": "import-statement",
185
+ "external": true
186
+ }
187
+ ],
188
+ "exports": [
189
+ "SyncClient"
190
+ ],
191
+ "entryPoint": "src/client/index.ts",
192
+ "inputs": {
193
+ "src/client/index.ts": {
194
+ "bytesInOutput": 10313
195
+ }
196
+ },
197
+ "bytes": 10501
198
+ },
199
+ "dist/client/sqlite-opfs-rpc.js.map": {
200
+ "imports": [],
201
+ "exports": [],
202
+ "inputs": {},
203
+ "bytes": 3684
204
+ },
205
+ "dist/client/sqlite-opfs-rpc.js": {
206
+ "imports": [],
207
+ "exports": [
208
+ "rpcClient"
209
+ ],
210
+ "entryPoint": "src/client/sqlite-opfs-rpc.ts",
211
+ "inputs": {
212
+ "src/client/sqlite-opfs-rpc.ts": {
213
+ "bytesInOutput": 1268
214
+ }
215
+ },
216
+ "bytes": 1465
217
+ },
218
+ "dist/client/sqlite-opfs.js.map": {
219
+ "imports": [],
220
+ "exports": [],
221
+ "inputs": {},
222
+ "bytes": 2078
223
+ },
224
+ "dist/client/sqlite-opfs.js": {
225
+ "imports": [
226
+ {
227
+ "path": "./sqlite.js",
228
+ "kind": "import-statement",
229
+ "external": true
230
+ },
231
+ {
232
+ "path": "./sqlite-opfs-rpc.js",
233
+ "kind": "import-statement",
234
+ "external": true
235
+ }
236
+ ],
237
+ "exports": [
238
+ "opfsExecutor",
239
+ "sqliteOpfs"
240
+ ],
241
+ "entryPoint": "src/client/sqlite-opfs.ts",
242
+ "inputs": {
243
+ "src/client/sqlite-opfs.ts": {
244
+ "bytesInOutput": 775
245
+ }
246
+ },
247
+ "bytes": 985
248
+ },
249
+ "dist/client/sqlite-opfs.worker.js.map": {
250
+ "imports": [],
251
+ "exports": [],
252
+ "inputs": {},
253
+ "bytes": 4042
254
+ },
255
+ "dist/client/sqlite-opfs.worker.js": {
256
+ "imports": [
257
+ {
258
+ "path": "@sqlite.org/sqlite-wasm",
259
+ "kind": "import-statement",
260
+ "external": true
261
+ }
262
+ ],
263
+ "exports": [],
264
+ "entryPoint": "src/client/sqlite-opfs.worker.ts",
265
+ "inputs": {
266
+ "src/client/sqlite-opfs.worker.ts": {
267
+ "bytesInOutput": 1350
268
+ }
269
+ },
270
+ "bytes": 1526
271
+ },
272
+ "dist/client/sqlite.js.map": {
273
+ "imports": [],
274
+ "exports": [],
275
+ "inputs": {},
276
+ "bytes": 7266
277
+ },
278
+ "dist/client/sqlite.js": {
279
+ "imports": [],
280
+ "exports": [
281
+ "sqlite"
282
+ ],
283
+ "entryPoint": "src/client/sqlite.ts",
284
+ "inputs": {
285
+ "src/client/sqlite.ts": {
286
+ "bytesInOutput": 3133
287
+ }
288
+ },
289
+ "bytes": 3318
290
+ },
291
+ "dist/hash.js.map": {
292
+ "imports": [],
293
+ "exports": [],
294
+ "inputs": {},
295
+ "bytes": 2346
296
+ },
297
+ "dist/hash.js": {
298
+ "imports": [],
299
+ "exports": [
300
+ "canonicalJSON",
301
+ "hashState"
302
+ ],
303
+ "entryPoint": "src/hash.ts",
304
+ "inputs": {
305
+ "src/hash.ts": {
306
+ "bytesInOutput": 735
307
+ }
308
+ },
309
+ "bytes": 938
310
+ },
311
+ "dist/index.js.map": {
312
+ "imports": [],
313
+ "exports": [],
314
+ "inputs": {},
315
+ "bytes": 933
316
+ },
317
+ "dist/index.js": {
318
+ "imports": [
319
+ {
320
+ "path": "./op.js",
321
+ "kind": "import-statement",
322
+ "external": true
323
+ },
324
+ {
325
+ "path": "./reduce.js",
326
+ "kind": "import-statement",
327
+ "external": true
328
+ },
329
+ {
330
+ "path": "./hash.js",
331
+ "kind": "import-statement",
332
+ "external": true
333
+ },
334
+ {
335
+ "path": "./client/idb.js",
336
+ "kind": "import-statement",
337
+ "external": true
338
+ },
339
+ {
340
+ "path": "./client/sqlite.js",
341
+ "kind": "import-statement",
342
+ "external": true
343
+ },
344
+ {
345
+ "path": "./client/index.js",
346
+ "kind": "import-statement",
347
+ "external": true
348
+ }
349
+ ],
350
+ "exports": [
351
+ "SyncClient",
352
+ "canonicalJSON",
353
+ "hashState",
354
+ "idb",
355
+ "lastWriteWins",
356
+ "op",
357
+ "sqlite"
358
+ ],
359
+ "entryPoint": "src/index.ts",
360
+ "inputs": {
361
+ "src/index.ts": {
362
+ "bytesInOutput": 263
363
+ }
364
+ },
365
+ "bytes": 392
366
+ },
367
+ "dist/op.js.map": {
368
+ "imports": [],
369
+ "exports": [],
370
+ "inputs": {},
371
+ "bytes": 2841
372
+ },
373
+ "dist/op.js": {
374
+ "imports": [],
375
+ "exports": [
376
+ "op"
377
+ ],
378
+ "entryPoint": "src/op.ts",
379
+ "inputs": {
380
+ "src/op.ts": {
381
+ "bytesInOutput": 1163
382
+ }
383
+ },
384
+ "bytes": 1211
385
+ },
386
+ "dist/reduce.js.map": {
387
+ "imports": [],
388
+ "exports": [],
389
+ "inputs": {},
390
+ "bytes": 14629
391
+ },
392
+ "dist/reduce.js": {
393
+ "imports": [
394
+ {
395
+ "path": "./hash.js",
396
+ "kind": "import-statement",
397
+ "external": true
398
+ }
399
+ ],
400
+ "exports": [
401
+ "lastWriteWins",
402
+ "mergeReducedStates",
403
+ "parseOpId",
404
+ "parseStateId"
405
+ ],
406
+ "entryPoint": "src/reduce.ts",
407
+ "inputs": {
408
+ "src/reduce.ts": {
409
+ "bytesInOutput": 5302
410
+ }
411
+ },
412
+ "bytes": 5545
413
+ },
414
+ "dist/server.js.map": {
415
+ "imports": [],
416
+ "exports": [],
417
+ "inputs": {},
418
+ "bytes": 178
419
+ },
420
+ "dist/server.js": {
421
+ "imports": [
422
+ {
423
+ "path": "./server/index.js",
424
+ "kind": "import-statement",
425
+ "external": true
426
+ }
427
+ ],
428
+ "exports": [
429
+ "SyncServer"
430
+ ],
431
+ "entryPoint": "src/server.ts",
432
+ "inputs": {
433
+ "src/server.ts": {
434
+ "bytesInOutput": 48
435
+ }
436
+ },
437
+ "bytes": 108
438
+ },
439
+ "dist/server/errors.js.map": {
440
+ "imports": [],
441
+ "exports": [],
442
+ "inputs": {},
443
+ "bytes": 1418
444
+ },
445
+ "dist/server/errors.js": {
446
+ "imports": [],
447
+ "exports": [
448
+ "isBenignConnectionError"
449
+ ],
450
+ "entryPoint": "src/server/errors.ts",
451
+ "inputs": {
452
+ "src/server/errors.ts": {
453
+ "bytesInOutput": 380
454
+ }
455
+ },
456
+ "bytes": 582
457
+ },
458
+ "dist/server/index.js.map": {
459
+ "imports": [],
460
+ "exports": [],
461
+ "inputs": {},
462
+ "bytes": 24986
463
+ },
464
+ "dist/server/index.js": {
465
+ "imports": [
466
+ {
467
+ "path": "partyserver",
468
+ "kind": "import-statement",
469
+ "external": true
470
+ },
471
+ {
472
+ "path": "../hash.js",
473
+ "kind": "import-statement",
474
+ "external": true
475
+ },
476
+ {
477
+ "path": "./errors.js",
478
+ "kind": "import-statement",
479
+ "external": true
480
+ }
481
+ ],
482
+ "exports": [
483
+ "SyncServer"
484
+ ],
485
+ "entryPoint": "src/server/index.ts",
486
+ "inputs": {
487
+ "src/server/index.ts": {
488
+ "bytesInOutput": 10304
489
+ }
490
+ },
491
+ "bytes": 10492
492
+ },
493
+ "dist/types.js.map": {
494
+ "imports": [],
495
+ "exports": [],
496
+ "inputs": {},
497
+ "bytes": 93
498
+ },
499
+ "dist/types.js": {
500
+ "imports": [],
501
+ "exports": [],
502
+ "entryPoint": "src/types.ts",
503
+ "inputs": {
504
+ "src/types.ts": {
505
+ "bytesInOutput": 0
506
+ }
507
+ },
508
+ "bytes": 34
509
+ }
510
+ }
511
+ }
package/dist/op.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Operation builder factories for creating draft operations.
3
+ * These builders create the core CRUD operations for the sync system:
4
+ * create, patch, and delete. The resulting DraftOp is missing seq, id,
5
+ * and ts — those are filled in by SyncClient.write() at send time.
6
+ */
7
+ import type { Op } from './types.js';
8
+ /**
9
+ * The fields a caller provides to `SyncClient.write()`. The client
10
+ * fills in `seq`, `id`, and `ts` itself from local state.
11
+ */
12
+ export type DraftOp = Omit<Op, 'seq' | 'id' | 'ts'>;
13
+ /**
14
+ * Op builder namespace. Use op.create(), op.patch(), or op.delete()
15
+ * to build draft operations.
16
+ */
17
+ export declare const op: {
18
+ /**
19
+ * Creates a new state with the given value.
20
+ * @param value - Arbitrary JSON value for the new state
21
+ * @returns Draft op of type 'create'
22
+ */
23
+ create(value: unknown): DraftOp;
24
+ /**
25
+ * Patches an existing state by shallow-merging fields.
26
+ * @param target - State id to patch
27
+ * @param value - Object with fields to merge
28
+ * @returns Draft op of type 'patch'
29
+ */
30
+ patch(target: string, value: Record<string, unknown>): DraftOp;
31
+ /**
32
+ * Deletes a field or whole state.
33
+ * With one argument, signals whole-state delete (value: null).
34
+ * With two arguments, deletes a single field (value: { key }).
35
+ * @param target - State id to delete from
36
+ * @param key - Field key to remove (optional; undefined triggers whole-state)
37
+ * @returns Draft op of type 'delete'
38
+ */
39
+ delete(target: string, key?: string): DraftOp;
40
+ };
41
+ //# sourceMappingURL=op.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"op.d.ts","sourceRoot":"","sources":["../src/op.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EAAE,EAAe,MAAM,YAAY,CAAA;AAEjD;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,IAAI,CAAC,EAAE,EAAE,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC,CAAA;AAEnD;;;GAGG;AACH,eAAO,MAAM,EAAE;IACX;;;;OAIG;kBACW,OAAO,GAAE,OAAO;IAQ9B;;;;;OAKG;kBACW,MAAM,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAE,OAAO;IAQ5D;;;;;;;OAOG;mBACY,MAAM,QAAO,MAAM,GAAE,OAAO;CAS9C,CAAA"}
package/dist/op.js ADDED
@@ -0,0 +1,46 @@
1
+ const op = {
2
+ /**
3
+ * Creates a new state with the given value.
4
+ * @param value - Arbitrary JSON value for the new state
5
+ * @returns Draft op of type 'create'
6
+ */
7
+ create(value) {
8
+ return {
9
+ type: "create",
10
+ target: null,
11
+ value: value === void 0 ? null : value
12
+ };
13
+ },
14
+ /**
15
+ * Patches an existing state by shallow-merging fields.
16
+ * @param target - State id to patch
17
+ * @param value - Object with fields to merge
18
+ * @returns Draft op of type 'patch'
19
+ */
20
+ patch(target, value) {
21
+ return {
22
+ type: "patch",
23
+ target,
24
+ value: value === void 0 ? null : value
25
+ };
26
+ },
27
+ /**
28
+ * Deletes a field or whole state.
29
+ * With one argument, signals whole-state delete (value: null).
30
+ * With two arguments, deletes a single field (value: { key }).
31
+ * @param target - State id to delete from
32
+ * @param key - Field key to remove (optional; undefined triggers whole-state)
33
+ * @returns Draft op of type 'delete'
34
+ */
35
+ delete(target, key) {
36
+ if (key === void 0) {
37
+ return { type: "delete", target, value: null };
38
+ }
39
+ const v = { key };
40
+ return { type: "delete", target, value: v };
41
+ }
42
+ };
43
+ export {
44
+ op
45
+ };
46
+ //# sourceMappingURL=op.js.map
package/dist/op.js.map ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/op.ts"],
4
+ "sourcesContent": ["/**\n * Operation builder factories for creating draft operations.\n * These builders create the core CRUD operations for the sync system:\n * create, patch, and delete. The resulting DraftOp is missing seq, id,\n * and ts \u2014 those are filled in by SyncClient.write() at send time.\n */\n\nimport type { Op, DeleteValue } from './types.js'\n\n/**\n * The fields a caller provides to `SyncClient.write()`. The client\n * fills in `seq`, `id`, and `ts` itself from local state.\n */\nexport type DraftOp = Omit<Op, 'seq' | 'id' | 'ts'>\n\n/**\n * Op builder namespace. Use op.create(), op.patch(), or op.delete()\n * to build draft operations.\n */\nexport const op = {\n /**\n * Creates a new state with the given value.\n * @param value - Arbitrary JSON value for the new state\n * @returns Draft op of type 'create'\n */\n create (value:unknown):DraftOp {\n return {\n type: 'create',\n target: null,\n value: value === undefined ? null : value\n }\n },\n\n /**\n * Patches an existing state by shallow-merging fields.\n * @param target - State id to patch\n * @param value - Object with fields to merge\n * @returns Draft op of type 'patch'\n */\n patch (target:string, value:Record<string, unknown>):DraftOp {\n return {\n type: 'patch',\n target,\n value: value === undefined ? null : value\n }\n },\n\n /**\n * Deletes a field or whole state.\n * With one argument, signals whole-state delete (value: null).\n * With two arguments, deletes a single field (value: { key }).\n * @param target - State id to delete from\n * @param key - Field key to remove (optional; undefined triggers whole-state)\n * @returns Draft op of type 'delete'\n */\n delete (target:string, key?:string):DraftOp {\n if (key === undefined) {\n // Whole-state delete: value is null, signalling\n // \"remove this state entirely\" to the reducer.\n return { type: 'delete', target, value: null }\n }\n const v:DeleteValue = { key }\n return { type: 'delete', target, value: v }\n }\n}\n"],
5
+ "mappings": "AAmBO,MAAM,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMd,OAAQ,OAAuB;AAC3B,WAAO;AAAA,MACH,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,OAAO,UAAU,SAAY,OAAO;AAAA,IACxC;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAO,QAAe,OAAuC;AACzD,WAAO;AAAA,MACH,MAAM;AAAA,MACN;AAAA,MACA,OAAO,UAAU,SAAY,OAAO;AAAA,IACxC;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAQ,QAAe,KAAqB;AACxC,QAAI,QAAQ,QAAW;AAGnB,aAAO,EAAE,MAAM,UAAU,QAAQ,OAAO,KAAK;AAAA,IACjD;AACA,UAAM,IAAgB,EAAE,IAAI;AAC5B,WAAO,EAAE,MAAM,UAAU,QAAQ,OAAO,EAAE;AAAA,EAC9C;AACJ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Reducer functions for state mutations in Simple Sync.
3
+ * The default `lastWriteWins` resolver handles create, patch, and delete
4
+ * operations with per-field timestamp tracking for conflict resolution.
5
+ */
6
+ import type { Op, ReducedState } from './types.js';
7
+ /**
8
+ * Parse op.id to extract deviceId and seq.
9
+ * Returns null if the id format is invalid.
10
+ *
11
+ * Expected format: op:${deviceId}:${seq}
12
+ * Uses lastIndexOf(':') to support future deviceId schemes that
13
+ * may contain colons.
14
+ */
15
+ export declare function parseOpId(opId: string): {
16
+ deviceId: string;
17
+ seq: number;
18
+ } | null;
19
+ /**
20
+ * Parse a reduced-state id of the form state:<deviceId>:<seq>:<ts>.
21
+ * deviceId may contain any chars (incl. ':'), matching parseOpId.
22
+ * ts may be fractional. Returns null if the shape is invalid.
23
+ */
24
+ export declare function parseStateId(id: string): {
25
+ deviceId: string;
26
+ seq: number;
27
+ ts: number;
28
+ } | null;
29
+ /**
30
+ * Default reducer for Simple Sync. Pass directly to
31
+ * `SyncServer.reduce` or use as a building block in your own
32
+ * reducer.
33
+ *
34
+ * Handles create, patch, and delete operations with per-field
35
+ * timestamp-based Last-Write-Wins conflict resolution.
36
+ * Timestamps are stored in state.__ts (top-level, never in value).
37
+ * State ids are constructed as state:${deviceId}:${seq}:${ts}.
38
+ * Whole-state delete (op.value === null) returns null.
39
+ *
40
+ * @see https://github.com/substrate-system/simple-sync (v1)
41
+ */
42
+ export declare function lastWriteWins(state: ReducedState | null, incomingOp: Op): Promise<ReducedState | null>;
43
+ /**
44
+ * Per-field last-write-wins merge of two reduced-state snapshots.
45
+ * Used by the client to reconcile an inbound server `state` against
46
+ * its local (possibly newer, un-synced) projection without losing a
47
+ * newer local edit. The higher `__ts` wins per field; the winning
48
+ * side's presence in `value` decides live vs tombstoned. Returns
49
+ * `incoming` unchanged when there is no comparable local snapshot.
50
+ *
51
+ * @param local The local snapshot, or null if none is held.
52
+ * @param incoming The authoritative server snapshot.
53
+ */
54
+ export declare function mergeReducedStates(local: ReducedState | null, incoming: Readonly<ReducedState>): Promise<ReducedState>;
55
+ //# sourceMappingURL=reduce.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reduce.d.ts","sourceRoot":"","sources":["../src/reduce.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAGlD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAE,IAAI,EAAC,MAAM,GAAE;IAAE,QAAQ,EAAC,MAAM,CAAC;IAAC,GAAG,EAAC,MAAM,CAAA;CAAE,GAAC,IAAI,CAW3E;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAE,EAAE,EAAC,MAAM,GAAE;IACrC,QAAQ,EAAC,MAAM,CAAC;IAAC,GAAG,EAAC,MAAM,CAAC;IAAC,EAAE,EAAC,MAAM,CAAA;CACzC,GAAG,IAAI,CASP;AAeD;;;;;;;;;;;;GAYG;AACH,wBAAsB,aAAa,CAC/B,KAAK,EAAC,YAAY,GAAG,IAAI,EACzB,UAAU,EAAC,EAAE,GACf,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CA+J7B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,kBAAkB,CACpC,KAAK,EAAC,YAAY,GAAG,IAAI,EACzB,QAAQ,EAAC,QAAQ,CAAC,YAAY,CAAC,GACjC,OAAO,CAAC,YAAY,CAAC,CAiDtB"}