@spooky-sync/core 0.0.1-canary.38 → 0.0.1-canary.381
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/AGENTS.md +91 -0
- package/README.md +59 -16
- package/dist/index.d.ts +2238 -144
- package/dist/index.js +18149 -2475
- package/dist/live.d.ts +149 -0
- package/dist/live.js +739 -0
- package/dist/otel/index.d.ts +1 -1
- package/dist/pure.d.ts +401 -0
- package/dist/pure.js +24 -0
- package/dist/sqlite-open.js +392 -0
- package/dist/sqlite-worker.d.ts +1 -0
- package/dist/sqlite-worker.js +439 -0
- package/dist/sw.d.ts +207 -0
- package/dist/sw.js +393 -0
- package/dist/tabs-broker-worker.d.ts +8 -0
- package/dist/tabs-broker-worker.js +477 -0
- package/dist/types.d.ts +2082 -39
- package/dist/worker-edges.js +498 -0
- package/dist/worker-impersonation.js +60 -0
- package/dist/worker-ref-tables.d.ts +48 -0
- package/dist/worker-types.d.ts +112 -0
- package/dist/worker-types.js +73 -0
- package/package.json +28 -7
- package/scripts/check-broker-bundle.mjs +33 -0
- package/scripts/check-worker-entries.mjs +173 -0
- package/skills/sp00ky-core/SKILL.md +42 -8
- package/skills/sp00ky-core/references/config.md +8 -2
- package/src/boot/auth-flip.saga.test.ts +174 -0
- package/src/boot/auth-flip.saga.ts +77 -0
- package/src/boot/boot.saga.test.ts +203 -0
- package/src/boot/boot.saga.ts +146 -0
- package/src/boot/bucket-switch.saga.test.ts +191 -0
- package/src/boot/bucket-switch.saga.ts +151 -0
- package/src/boot/preload.saga.test.ts +96 -0
- package/src/boot/preload.saga.ts +45 -0
- package/src/bucket-blurhash.test.ts +148 -0
- package/src/build-globals.d.ts +12 -0
- package/src/client/bucket-handle.test.ts +195 -0
- package/src/client/bucket-handle.ts +352 -0
- package/src/client/router.test.ts +59 -0
- package/src/client/router.ts +104 -0
- package/src/client/runtime.test.ts +319 -0
- package/src/client/runtime.ts +307 -0
- package/src/client/services.test.ts +74 -0
- package/src/client/services.ts +437 -0
- package/src/client/sp00ky-client.test.ts +428 -0
- package/src/client/sp00ky-client.ts +737 -0
- package/src/events/index.ts +3 -0
- package/src/index.ts +86 -1
- package/src/kernel/constants.test.ts +19 -0
- package/src/kernel/constants.ts +94 -0
- package/src/kernel/effects.test.ts +40 -0
- package/src/kernel/effects.ts +171 -0
- package/src/kernel/events.ts +60 -0
- package/src/kernel/interpreter.test.ts +116 -0
- package/src/kernel/interpreter.ts +148 -0
- package/src/kernel/saga.test.ts +89 -0
- package/src/kernel/saga.ts +73 -0
- package/src/live/index.test.ts +512 -0
- package/src/live/index.ts +1059 -0
- package/src/modules/app-release/index.test.ts +125 -0
- package/src/modules/app-release/index.ts +209 -0
- package/src/modules/auth/auth.local-first.test.ts +228 -0
- package/src/modules/auth/auth.session-recheck.test.ts +140 -0
- package/src/modules/auth/events/index.ts +7 -1
- package/src/modules/auth/impersonation-banner.ts +443 -0
- package/src/modules/auth/impersonation.integration.test.ts +209 -0
- package/src/modules/auth/impersonation.test.ts +377 -0
- package/src/modules/auth/impersonation.ts +179 -0
- package/src/modules/auth/index.ts +538 -14
- package/src/modules/channel/channel.test.ts +752 -0
- package/src/modules/channel/index.ts +1153 -0
- package/src/modules/channel/webrtc.ts +472 -0
- package/src/modules/crdt/acceptance.ts +75 -0
- package/src/modules/crdt/bytes.ts +50 -0
- package/src/modules/crdt/crdt-field.ts +125 -0
- package/src/modules/crdt/crdt.test.ts +546 -0
- package/src/modules/crdt/hash.ts +103 -0
- package/src/modules/crdt/index.ts +821 -0
- package/src/modules/crdt/loro-loader.ts +25 -0
- package/src/modules/crdt/mirror.ts +37 -0
- package/src/modules/devtools/flags.ts +349 -0
- package/src/modules/devtools/index.ts +746 -93
- package/src/modules/devtools/mutations.test.ts +92 -0
- package/src/modules/devtools/mutations.ts +160 -0
- package/src/modules/devtools/notify-throttle.test.ts +166 -0
- package/src/modules/devtools/state-shape.test.ts +263 -0
- package/src/modules/devtools/storage-info.test.ts +79 -0
- package/src/modules/devtools/storage-info.ts +168 -0
- package/src/modules/devtools/versions.test.ts +74 -0
- package/src/modules/devtools/versions.ts +110 -0
- package/src/modules/feature-flag/index.test.ts +298 -0
- package/src/modules/feature-flag/index.ts +316 -0
- package/src/modules/ref-tables.test.ts +93 -0
- package/src/modules/ref-tables.ts +91 -0
- package/src/modules/web-push/index.test.ts +824 -0
- package/src/modules/web-push/index.ts +1027 -0
- package/src/mutation/ingest-outage.integration.test.ts +400 -0
- package/src/mutation/jobs.test.ts +25 -0
- package/src/mutation/jobs.ts +41 -0
- package/src/mutation/mutation-id.test.ts +37 -0
- package/src/mutation/mutation-id.ts +35 -0
- package/src/mutation/pending-writes.integration.test.ts +175 -0
- package/src/mutation/push.saga.test.ts +361 -0
- package/src/mutation/push.saga.ts +245 -0
- package/src/mutation/rows.test.ts +278 -0
- package/src/mutation/rows.ts +515 -0
- package/src/mutation/tray.saga.test.ts +63 -0
- package/src/mutation/tray.saga.ts +48 -0
- package/src/mutation/write.saga.test.ts +436 -0
- package/src/mutation/write.saga.ts +384 -0
- package/src/pure.ts +66 -0
- package/src/push/types.ts +174 -0
- package/src/query/anon-query-isolation.integration.test.ts +531 -0
- package/src/query/env.test.ts +23 -0
- package/src/query/env.ts +65 -0
- package/src/query/fetch.saga.test.ts +199 -0
- package/src/query/fetch.saga.ts +120 -0
- package/src/query/hash.test.ts +14 -0
- package/src/query/hash.ts +18 -0
- package/src/query/id-set-plan.test.ts +132 -0
- package/src/query/lifecycle.saga.test.ts +274 -0
- package/src/query/lifecycle.saga.ts +186 -0
- package/src/query/list-ref-live.integration.test.ts +203 -0
- package/src/query/materialize.saga.test.ts +200 -0
- package/src/query/materialize.saga.ts +102 -0
- package/src/query/materialize.test.ts +58 -0
- package/src/query/materialize.ts +57 -0
- package/src/query/membership.saga.test.ts +514 -0
- package/src/query/membership.saga.ts +339 -0
- package/src/query/membership.test.ts +151 -0
- package/src/query/membership.ts +234 -0
- package/src/query/register.saga.test.ts +369 -0
- package/src/query/register.saga.ts +293 -0
- package/src/query/render-set.test.ts +47 -0
- package/src/query/render-set.ts +71 -0
- package/src/query/session-guard.integration.test.ts +304 -0
- package/src/query/sql.test.ts +118 -0
- package/src/query/sql.ts +174 -0
- package/src/query/window-query.test.ts +70 -0
- package/src/query/window-query.ts +208 -0
- package/src/services/blobs/blob-cache.test.ts +359 -0
- package/src/services/blobs/blob-cache.ts +603 -0
- package/src/services/blobs/blob-manifest.ts +227 -0
- package/src/services/blobs/blob-store.test.ts +77 -0
- package/src/services/blobs/blob-store.ts +359 -0
- package/src/services/blobs/blob.fixture.ts +90 -0
- package/src/services/blobs/index.ts +70 -0
- package/src/services/database/cache-engine.ts +209 -0
- package/src/services/database/connection-supervisor.test.ts +318 -0
- package/src/services/database/connection-supervisor.ts +422 -0
- package/src/services/database/database.query-timeout.test.ts +140 -0
- package/src/services/database/database.responses.test.ts +43 -0
- package/src/services/database/database.ts +151 -56
- package/src/services/database/engine-factory.ts +33 -0
- package/src/services/database/errors.ts +34 -0
- package/src/services/database/index.ts +7 -0
- package/src/services/database/landed-body-clear.integration.test.ts +236 -0
- package/src/services/database/local-migrator.integration.test.ts +110 -0
- package/src/services/database/local-migrator.ts +54 -9
- package/src/services/database/local.test.ts +150 -0
- package/src/services/database/local.ts +503 -59
- package/src/services/database/plan-render.test.ts +159 -0
- package/src/services/database/plan-render.ts +108 -0
- package/src/services/database/relation-resolver.test.ts +484 -0
- package/src/services/database/relation-resolver.ts +0 -0
- package/src/services/database/remote.ts +283 -4
- package/src/services/database/sqlite-cache-engine.test.ts +628 -0
- package/src/services/database/sqlite-cache-engine.timeout.test.ts +61 -0
- package/src/services/database/sqlite-cache-engine.ts +1401 -0
- package/src/services/database/sqlite-column-reset.integration.test.ts +100 -0
- package/src/services/database/sqlite-column-reset.ts +91 -0
- package/src/services/database/sqlite-devtools-queries.integration.test.ts +143 -0
- package/src/services/database/sqlite-devtools-queries.test.ts +154 -0
- package/src/services/database/sqlite-lock-verify.test.ts +33 -0
- package/src/services/database/sqlite-lock-verify.ts +45 -0
- package/src/services/database/sqlite-open.test.ts +150 -0
- package/src/services/database/sqlite-open.ts +164 -0
- package/src/services/database/sqlite-plan-sql.test.ts +164 -0
- package/src/services/database/sqlite-plan-sql.ts +196 -0
- package/src/services/database/sqlite-projection.test.ts +121 -0
- package/src/services/database/sqlite-select.integration.test.ts +185 -0
- package/src/services/database/sqlite-select.test.ts +261 -0
- package/src/services/database/sqlite-select.ts +131 -0
- package/src/services/database/sqlite-transport.fixture.ts +30 -0
- package/src/services/database/sqlite-transport.ts +224 -0
- package/src/services/database/sqlite-worker.ts +437 -0
- package/src/services/database/surql-translate.ts +417 -0
- package/src/services/database/surreal-cache-engine.ts +163 -0
- package/src/services/logger/index.test.ts +132 -0
- package/src/services/logger/index.ts +187 -6
- package/src/services/persistence/resilient.ts +8 -1
- package/src/services/persistence/surrealdb.ts +2 -2
- package/src/services/stream-processor/index.ts +801 -63
- package/src/services/stream-processor/permissions.test.ts +47 -0
- package/src/services/stream-processor/permissions.ts +53 -0
- package/src/services/stream-processor/stream-processor.batch.test.ts +186 -0
- package/src/services/stream-processor/stream-processor.prime.test.ts +234 -0
- package/src/services/stream-processor/stream-processor.reset.test.ts +226 -0
- package/src/services/stream-processor/wasm-types.ts +57 -1
- package/src/services/tabs/broker-client.ts +284 -0
- package/src/services/tabs/broker.test.ts +381 -0
- package/src/services/tabs/coordinator.test.ts +386 -0
- package/src/services/tabs/coordinator.ts +646 -0
- package/src/services/tabs/fake-ports.fixture.ts +112 -0
- package/src/services/tabs/leader-locks.ts +75 -0
- package/src/services/tabs/protocol.ts +262 -0
- package/src/services/tabs/support.ts +36 -0
- package/src/services/tabs/tabs-broker-worker.ts +652 -0
- package/src/sp00ky.ts +5 -394
- package/src/state/client-state.ts +231 -0
- package/src/state/lifecycle.test.ts +184 -0
- package/src/state/lifecycle.ts +127 -0
- package/src/state/reducers.test.ts +337 -0
- package/src/state/reducers.ts +571 -0
- package/src/state/selectors.test.ts +203 -0
- package/src/state/selectors.ts +264 -0
- package/src/sw/index.test.ts +582 -0
- package/src/sw/index.ts +607 -0
- package/src/sw/store.ts +96 -0
- package/src/sync/connection.saga.test.ts +97 -0
- package/src/sync/connection.saga.ts +89 -0
- package/src/sync/live.saga.test.ts +229 -0
- package/src/sync/live.saga.ts +116 -0
- package/src/sync/policy.health.test.ts +56 -0
- package/src/sync/policy.test.ts +663 -0
- package/src/sync/policy.ts +515 -0
- package/src/sync/poll.saga.test.ts +51 -0
- package/src/sync/poll.saga.ts +36 -0
- package/src/sync/tabs.saga.test.ts +78 -0
- package/src/sync/tabs.saga.ts +96 -0
- package/src/testing/adapters.ts +137 -0
- package/src/testing/build.ts +63 -0
- package/src/testing/fake-services.ts +63 -0
- package/src/testing/run-pure.test.ts +92 -0
- package/src/testing/run-pure.ts +128 -0
- package/src/testing/services.ts +17 -0
- package/src/types.ts +694 -7
- package/src/utils/blurhash.ts +90 -0
- package/src/utils/edges.ts +57 -0
- package/src/utils/error-classification.test.ts +116 -0
- package/src/utils/error-classification.ts +74 -0
- package/src/utils/index.ts +83 -6
- package/src/utils/parser.test.ts +67 -102
- package/src/utils/parser.ts +63 -2
- package/src/utils/semver.test.ts +32 -0
- package/src/utils/semver.ts +30 -0
- package/src/utils/sha256.ts +15 -0
- package/src/utils/surql.ts +22 -11
- package/src/utils/utils.test.ts +3 -2
- package/tsdown.config.ts +117 -3
- package/vitest.config.ts +48 -0
- package/src/modules/cache/index.ts +0 -241
- package/src/modules/cache/types.ts +0 -19
- package/src/modules/data/data.test.ts +0 -58
- package/src/modules/data/index.ts +0 -882
- package/src/modules/sync/engine.ts +0 -173
- package/src/modules/sync/events/index.ts +0 -78
- package/src/modules/sync/index.ts +0 -3
- package/src/modules/sync/queue/index.ts +0 -2
- package/src/modules/sync/queue/queue-down.ts +0 -90
- package/src/modules/sync/queue/queue-up.ts +0 -224
- package/src/modules/sync/scheduler.ts +0 -84
- package/src/modules/sync/sync.ts +0 -422
- package/src/modules/sync/utils.test.ts +0 -311
- package/src/modules/sync/utils.ts +0 -169
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { RecordId } from 'surrealdb';
|
|
3
|
+
import { runPure } from '../testing/run-pure';
|
|
4
|
+
import { buildEntry, buildOutboxItem, buildState } from '../testing/build';
|
|
5
|
+
import { defaultEnv } from '../query/env';
|
|
6
|
+
import { adoptPendingWrites, flushPendingWrites, flushWrite, peerCreate, peerDelete, peerWriteExpired, readRow, write } from './write.saga';
|
|
7
|
+
import * as R from '../state/reducers';
|
|
8
|
+
|
|
9
|
+
const env = defaultEnv({ tables: [{ name: 'thing', columns: { a: {}, b: {} } }] } as any);
|
|
10
|
+
const rid = new RecordId('thing', '1');
|
|
11
|
+
const withQuery = () => buildState([buildEntry({ def: { hash: 'q', tableName: 'thing' } })]);
|
|
12
|
+
|
|
13
|
+
describe('write', () => {
|
|
14
|
+
it('rejects unknown tables', async () => {
|
|
15
|
+
await expect(runPure(write(env, { kind: 'create', recordId: 'nope:1', data: {} }))).rejects.toThrow('Table nope not found');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('create: local tx, outbox item, circuit ingest, version 1, event, drain; dirties the table', async () => {
|
|
19
|
+
const out = await runPure(write(env, { kind: 'create', recordId: 'thing:1', data: { a: 1, junk: 2 } }), {
|
|
20
|
+
state: withQuery(),
|
|
21
|
+
handlers: {
|
|
22
|
+
'local.execute': (e: any) => {
|
|
23
|
+
expect(e.query.sql).toContain("mutationType = 'create'");
|
|
24
|
+
expect(e.vars.data).toEqual({ a: 1 });
|
|
25
|
+
return { id: rid, a: 1 };
|
|
26
|
+
},
|
|
27
|
+
'ssp.ingest': (e: any) => {
|
|
28
|
+
expect(e.records).toEqual([{ table: 'thing', op: 'CREATE', id: 'thing:1', record: { id: rid, a: 1, _00_rv: 1 } }]);
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
expect(out.result).toEqual({ mutationId: 'mutation-1', record: { id: rid, a: 1 } });
|
|
33
|
+
expect(out.state.outbox).toEqual([{ id: 'mutation-1', type: 'create', recordId: 'thing:1', table: 'thing', status: 'pending', ackedAt: null, attempts: 0 }]);
|
|
34
|
+
expect(out.state.versions.get('thing:1')).toBe(1);
|
|
35
|
+
expect(out.state.dirty.has('q')).toBe(true);
|
|
36
|
+
expect(out.emitted[0]).toMatchObject({ type: 'mutation:event', event: { type: 'create', tableName: 'thing' } });
|
|
37
|
+
expect(out.dispatched).toEqual([{ type: 'Drain' }]);
|
|
38
|
+
expect(out.log.filter((e) => e.kind === 'local.query')).toHaveLength(0);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('update: reads before, tx with beforeRecord, version from the returned row; delete: before feeds the circuit', async () => {
|
|
42
|
+
const upd = await runPure(write(env, { kind: 'update', recordId: 'thing:1', data: { a: 2 } }), {
|
|
43
|
+
state: withQuery(),
|
|
44
|
+
handlers: {
|
|
45
|
+
'local.query': () => [{ id: rid, a: 1, _00_rv: 4 }],
|
|
46
|
+
'local.execute': (e: any) => {
|
|
47
|
+
expect(e.vars.before).toEqual({ id: rid, a: 1, _00_rv: 4 });
|
|
48
|
+
return { target: { id: rid, a: 2, _00_rv: 5 } };
|
|
49
|
+
},
|
|
50
|
+
'ssp.ingest': (e: any) => expect(e.records[0]).toMatchObject({ op: 'UPDATE', record: { a: 2, _00_rv: 5 } }),
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
expect(upd.result.record).toEqual({ id: rid, a: 2, _00_rv: 5 });
|
|
54
|
+
expect(upd.state.versions.get('thing:1')).toBe(5);
|
|
55
|
+
expect(upd.emitted[0]).toMatchObject({ event: { beforeRecord: { a: 1 } } });
|
|
56
|
+
const noRow = await runPure(write(env, { kind: 'update', recordId: 'thing:1', data: { a: 2 } }), {
|
|
57
|
+
state: withQuery(),
|
|
58
|
+
handlers: { 'local.query': () => [null], 'local.execute': () => ({ target: null }), 'ssp.ingest': () => undefined },
|
|
59
|
+
});
|
|
60
|
+
expect(noRow.result.record).toBeNull();
|
|
61
|
+
expect(noRow.state.versions.get('thing:1')).toBe(1);
|
|
62
|
+
const del = await runPure(write(env, { kind: 'delete', recordId: 'thing:1' }), {
|
|
63
|
+
state: buildState([], (s) => ({ ...s, versions: new Map([['thing:1', 3]]) })),
|
|
64
|
+
handlers: {
|
|
65
|
+
'local.query': () => [{ id: rid, a: 1, _00_rv: 3 }],
|
|
66
|
+
'local.execute': () => undefined,
|
|
67
|
+
'ssp.ingest': (e: any) => expect(e.records[0]).toEqual({ table: 'thing', op: 'DELETE', id: 'thing:1', record: { id: rid, a: 1, _00_rv: 3 } }),
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
expect(del.result.record).toBeNull();
|
|
71
|
+
expect(del.state.versions.has('thing:1')).toBe(false);
|
|
72
|
+
expect(del.state.outbox[0].type).toBe('delete');
|
|
73
|
+
const delNoRow = await runPure(write(env, { kind: 'delete', recordId: 'thing:1' }), {
|
|
74
|
+
state: buildState(),
|
|
75
|
+
handlers: {
|
|
76
|
+
'local.query': () => [[]],
|
|
77
|
+
'local.execute': () => undefined,
|
|
78
|
+
'ssp.ingest': (e: any) => expect(e.records[0].record).toEqual({}),
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
expect(delNoRow.emitted[0]).toMatchObject({ event: { beforeRecord: undefined } });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('a failing circuit ingest is logged, the write still stands; a follower broadcasts instead of draining', async () => {
|
|
85
|
+
const out = await runPure(write(env, { kind: 'create', recordId: 'thing:1', data: {} }), {
|
|
86
|
+
state: { ...buildState(), tabRole: 'follower' },
|
|
87
|
+
handlers: {
|
|
88
|
+
'local.execute': () => ({ id: rid }),
|
|
89
|
+
'ssp.ingest': () => {
|
|
90
|
+
throw new Error('wasm');
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
expect(out.emitted.some((e) => e.type === 'log' && e.level === 'error')).toBe(true);
|
|
95
|
+
expect(out.emitted).toContainEqual({ type: 'tabs:broadcast', message: { type: 'outbox-changed', mutationId: 'mutation-1' } });
|
|
96
|
+
expect(out.emitted).toContainEqual({ type: 'tabs:broadcast', message: { type: 'ingest', records: [expect.objectContaining({ id: 'thing:1', op: 'CREATE' })] } });
|
|
97
|
+
expect(out.dispatched).toEqual([]);
|
|
98
|
+
expect(out.state.outbox).toHaveLength(1);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('debounced update: applies locally, merges the patch per key, arms the flush timer; flush writes one outbox row', async () => {
|
|
102
|
+
const first = await runPure(write(env, { kind: 'update', recordId: 'thing:1', data: { a: 1 }, options: { debounced: true } }), {
|
|
103
|
+
state: withQuery(),
|
|
104
|
+
handlers: {
|
|
105
|
+
'local.query': () => [{ id: rid, a: 0, _00_rv: 1 }],
|
|
106
|
+
'local.execute': () => ({ target: { id: rid, a: 1, _00_rv: 2 } }),
|
|
107
|
+
'ssp.ingest': () => undefined,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
expect(first.result).toEqual({ mutationId: '', record: { id: rid, a: 1, _00_rv: 2 } });
|
|
111
|
+
expect(first.state.outbox).toEqual([]);
|
|
112
|
+
const key = 'thing:1::a';
|
|
113
|
+
expect(first.state.pendingWrites.get(key)).toMatchObject({ data: { a: 1 }, before: { a: 0 } });
|
|
114
|
+
expect(first.timers.get(`debounce:${key}`)).toEqual({ ms: 300, event: { type: 'FlushWrite', key } });
|
|
115
|
+
expect(first.state.dirty.has('q')).toBe(true);
|
|
116
|
+
const second = await runPure(write(env, { kind: 'update', recordId: 'thing:1', data: { a: 5 }, options: { debounced: { delay: 50, key: 'recordId_x_fields' } } }), {
|
|
117
|
+
state: first.state,
|
|
118
|
+
handlers: {
|
|
119
|
+
'local.execute': () => ({ target: { id: rid, a: 5, _00_rv: 3 } }),
|
|
120
|
+
'ssp.ingest': () => {
|
|
121
|
+
throw new Error('wasm');
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
expect(second.log.filter((e) => e.kind === 'local.query')).toHaveLength(0);
|
|
126
|
+
expect(second.state.pendingWrites.get(key)).toMatchObject({ data: { a: 5 }, before: { a: 0 } });
|
|
127
|
+
expect(second.timers.get(`debounce:${key}`)!.ms).toBe(50);
|
|
128
|
+
const byRecord = await runPure(write(env, { kind: 'update', recordId: 'thing:1', data: { b: 1 }, options: { debounced: { key: 'recordId' } } }), {
|
|
129
|
+
state: withQuery(),
|
|
130
|
+
handlers: { 'local.query': () => [], 'local.execute': () => undefined, 'ssp.ingest': () => undefined },
|
|
131
|
+
});
|
|
132
|
+
expect(byRecord.state.pendingWrites.has('thing:1')).toBe(true);
|
|
133
|
+
expect(byRecord.result.record).toBeNull();
|
|
134
|
+
const noData = await runPure(write(env, { kind: 'update', recordId: 'thing:1', options: { debounced: true } }), {
|
|
135
|
+
state: withQuery(),
|
|
136
|
+
handlers: { 'local.query': () => undefined, 'local.execute': () => undefined, 'ssp.ingest': () => undefined },
|
|
137
|
+
});
|
|
138
|
+
expect(noData.state.pendingWrites.has('thing:1::')).toBe(true);
|
|
139
|
+
const flushedNoBefore = await runPure(flushWrite(env, 'thing:1'), { state: byRecord.state, handlers: { 'local.execute': () => undefined } });
|
|
140
|
+
expect(flushedNoBefore.emitted[0]).toMatchObject({ event: { beforeRecord: undefined } });
|
|
141
|
+
const flushed = await runPure(flushWrite(env, key), {
|
|
142
|
+
state: second.state,
|
|
143
|
+
handlers: {
|
|
144
|
+
'local.execute': (e: any) => {
|
|
145
|
+
expect(e.query.sql).toContain("mutationType = 'update'");
|
|
146
|
+
expect(e.vars).toMatchObject({ data: { a: 5 }, before: { id: rid, a: 0, _00_rv: 1 }, table: 'thing' });
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
expect(flushed.state.pendingWrites.size).toBe(0);
|
|
151
|
+
expect(flushed.state.outbox).toEqual([expect.objectContaining({ id: 'mutation-1', type: 'update', recordId: 'thing:1' })]);
|
|
152
|
+
expect(flushed.emitted[0]).toMatchObject({ type: 'mutation:event', event: { type: 'update', data: { a: 5 } } });
|
|
153
|
+
expect(flushed.dispatched).toEqual([{ type: 'Drain' }]);
|
|
154
|
+
const nothing = await runPure(flushWrite(env, 'missing'), { state: buildState() });
|
|
155
|
+
expect(nothing.dispatched).toEqual([]);
|
|
156
|
+
const follower = await runPure(flushWrite(env, key), { state: { ...second.state, tabRole: 'follower' }, handlers: { 'local.execute': () => undefined } });
|
|
157
|
+
expect(follower.emitted).toContainEqual(expect.objectContaining({ type: 'tabs:broadcast' }));
|
|
158
|
+
const leaderDebounced = await runPure(write(env, { kind: 'update', recordId: 'thing:1', data: { a: 1 }, options: { debounced: true } }), {
|
|
159
|
+
state: { ...withQuery(), tabRole: 'leader' },
|
|
160
|
+
handlers: { 'local.query': () => [], 'local.execute': () => undefined, 'ssp.ingest': () => undefined },
|
|
161
|
+
});
|
|
162
|
+
expect(leaderDebounced.emitted).toContainEqual({ type: 'tabs:broadcast', message: { type: 'ingest', records: [expect.objectContaining({ op: 'UPDATE' })] } });
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('flushOnHide (default): the merged patch is mirrored in the same tx, and the flush moves it into the outbox', async () => {
|
|
166
|
+
const now = 1_000;
|
|
167
|
+
const first = await runPure(write(env, { kind: 'update', recordId: 'thing:1', data: { a: 1 }, options: { debounced: true } }), {
|
|
168
|
+
state: withQuery(),
|
|
169
|
+
now,
|
|
170
|
+
handlers: {
|
|
171
|
+
'local.query': () => [{ id: rid, a: 0, _00_rv: 1 }],
|
|
172
|
+
'local.execute': (e: any) => {
|
|
173
|
+
expect(e.query.sql).toContain('UPSERT ONLY $wid REPLACE $wrow');
|
|
174
|
+
expect(e.vars.wid).toEqual(new RecordId('_00_pending_writes', 'mutation-1'));
|
|
175
|
+
expect(e.vars.wrow).toEqual({ recordId: rid, tableName: 'thing', data: { a: 1 }, beforeRecord: { id: rid, a: 0, _00_rv: 1 }, flushBy: now + 300 });
|
|
176
|
+
return { target: { id: rid, a: 1, _00_rv: 2 } };
|
|
177
|
+
},
|
|
178
|
+
'ssp.ingest': () => undefined,
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
const key = 'thing:1::a';
|
|
182
|
+
expect(first.state.pendingWrites.get(key)!.mirrorId).toBe('_00_pending_writes:mutation-1');
|
|
183
|
+
const second = await runPure(write(env, { kind: 'update', recordId: 'thing:1', data: { a: 7 }, options: { debounced: { delay: 50 } } }), {
|
|
184
|
+
state: first.state,
|
|
185
|
+
now: now + 10,
|
|
186
|
+
handlers: {
|
|
187
|
+
'local.execute': (e: any) => {
|
|
188
|
+
expect(e.vars.wid).toEqual(new RecordId('_00_pending_writes', 'mutation-1'));
|
|
189
|
+
expect(e.vars.wrow).toMatchObject({ data: { a: 7 }, flushBy: now + 60 });
|
|
190
|
+
return { target: { id: rid, a: 7, _00_rv: 3 } };
|
|
191
|
+
},
|
|
192
|
+
'ssp.ingest': () => undefined,
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
expect(second.log.filter((e) => e.kind === 'id')).toHaveLength(0);
|
|
196
|
+
const flushed = await runPure(flushWrite(env, key), {
|
|
197
|
+
state: second.state,
|
|
198
|
+
handlers: {
|
|
199
|
+
'local.execute': (e: any) => {
|
|
200
|
+
expect(e.query.sql).toContain('DELETE $wid');
|
|
201
|
+
expect(e.vars).toMatchObject({ data: { a: 7 }, wid: new RecordId('_00_pending_writes', 'mutation-1') });
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
expect(flushed.state.pendingWrites.size).toBe(0);
|
|
206
|
+
expect(flushed.state.outbox).toHaveLength(1);
|
|
207
|
+
const armed: unknown[] = [];
|
|
208
|
+
const closed = runPure(flushWrite(env, key), {
|
|
209
|
+
state: second.state,
|
|
210
|
+
handlers: {
|
|
211
|
+
'local.execute': () => {
|
|
212
|
+
throw new Error('store closed');
|
|
213
|
+
},
|
|
214
|
+
'timer.set': (e: any) => void armed.push([e.key, e.ms, e.event]),
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
await expect(closed).rejects.toThrow('store closed');
|
|
218
|
+
expect(armed).toEqual([['adopt-writes', 3_000, { type: 'AdoptPendingWrites' }]]);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('flushOnHide: false keeps the patch in memory only', async () => {
|
|
222
|
+
const out = await runPure(write(env, { kind: 'update', recordId: 'thing:1', data: { a: 1 }, options: { debounced: { flushOnHide: false } } }), {
|
|
223
|
+
state: withQuery(),
|
|
224
|
+
handlers: {
|
|
225
|
+
'local.query': () => [],
|
|
226
|
+
'local.execute': (e: any) => {
|
|
227
|
+
expect(e.query.sql).not.toContain('UPSERT');
|
|
228
|
+
expect(e.vars.wid).toBeUndefined();
|
|
229
|
+
},
|
|
230
|
+
'ssp.ingest': () => undefined,
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
expect(out.state.pendingWrites.get('thing:1::a')!.mirrorId).toBeNull();
|
|
234
|
+
const flushed = await runPure(flushWrite(env, 'thing:1::a'), {
|
|
235
|
+
state: out.state,
|
|
236
|
+
handlers: { 'local.execute': (e: any) => expect(e.query.sql).not.toContain('DELETE') },
|
|
237
|
+
});
|
|
238
|
+
expect(flushed.state.outbox).toHaveLength(1);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
describe('flushPendingWrites', () => {
|
|
243
|
+
it('flushes every mirrored pending write now, leaves memory-only ones to their timer', async () => {
|
|
244
|
+
const base = { table: 'thing', recordId: 'thing:1', data: { a: 1 }, before: null, firstAt: 0 };
|
|
245
|
+
const state = R.compose(
|
|
246
|
+
R.mergePendingWrite({ ...base, key: 'k1', mirrorId: '_00_pending_writes:1' }),
|
|
247
|
+
R.mergePendingWrite({ ...base, key: 'k2', mirrorId: null }),
|
|
248
|
+
R.mergePendingWrite({ ...base, key: 'k3', mirrorId: '_00_pending_writes:3' })
|
|
249
|
+
)(buildState());
|
|
250
|
+
const out = await runPure(flushPendingWrites(), { state });
|
|
251
|
+
expect(out.log.filter((e) => e.kind === 'timer.clear').map((e: any) => e.key)).toEqual(['debounce:k1', 'debounce:k3']);
|
|
252
|
+
expect(out.dispatched).toEqual([{ type: 'FlushWrite', key: 'k1' }, { type: 'FlushWrite', key: 'k3' }]);
|
|
253
|
+
const none = await runPure(flushPendingWrites(), { state: buildState() });
|
|
254
|
+
expect(none.dispatched).toEqual([]);
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
describe('adoptPendingWrites', () => {
|
|
259
|
+
const now = 100_000;
|
|
260
|
+
const row = (id: string, flushBy: number) => ({ id: `_00_pending_writes:${id}`, recordId: rid, tableName: 'thing', data: { a: 1 }, beforeRecord: { a: 0 }, flushBy });
|
|
261
|
+
const held = R.mergePendingWrite({ key: 'k', table: 'thing', recordId: 'thing:1', data: {}, before: null, firstAt: 0, mirrorId: '_00_pending_writes:mine' })(buildState());
|
|
262
|
+
|
|
263
|
+
it('moves overdue rows nobody here holds into the outbox, re-checks rows that may still be live', async () => {
|
|
264
|
+
const moved: any[] = [];
|
|
265
|
+
const out = await runPure(adoptPendingWrites(), {
|
|
266
|
+
state: held,
|
|
267
|
+
now,
|
|
268
|
+
handlers: {
|
|
269
|
+
'local.query': (e: any) => {
|
|
270
|
+
expect(e.sql).toBe('SELECT * FROM _00_pending_writes');
|
|
271
|
+
return [[row('mine', 0), row('dead', now - 3_000), row('live', now + 500), row('other-live', now + 2_000), 'junk']];
|
|
272
|
+
},
|
|
273
|
+
'local.execute': (e: any) => {
|
|
274
|
+
moved.push(e.vars);
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
});
|
|
278
|
+
expect(moved).toHaveLength(1);
|
|
279
|
+
expect(moved[0]).toMatchObject({ id: rid, table: 'thing', data: { a: 1 }, before: { a: 0 }, createdAt: now, wid: new RecordId('_00_pending_writes', 'dead') });
|
|
280
|
+
expect(out.state.outbox).toEqual([{ id: 'mutation-1', type: 'update', recordId: 'thing:1', table: 'thing', status: 'pending', ackedAt: null, attempts: 0 }]);
|
|
281
|
+
expect(out.dispatched).toEqual([{ type: 'Drain' }]);
|
|
282
|
+
expect(out.timers.get('adopt-writes')).toEqual({ ms: 3_500, event: { type: 'AdoptPendingWrites' } });
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('a follower nudges the leader instead; a failed move is logged and skipped; no table means nothing to do', async () => {
|
|
286
|
+
const follower = await runPure(adoptPendingWrites(), { state: { ...buildState(), tabRole: 'follower' }, now, handlers: { 'local.query': () => [[row('dead', 0)]] } });
|
|
287
|
+
expect(follower.log.some((e) => e.kind === 'local.execute')).toBe(false);
|
|
288
|
+
expect(follower.emitted).toEqual([{ type: 'tabs:broadcast', message: { type: 'outbox-changed', mutationId: '' } }]);
|
|
289
|
+
const quietFollower = await runPure(adoptPendingWrites(), { state: { ...held, tabRole: 'follower' }, now, handlers: { 'local.query': () => [[row('mine', 0)]] } });
|
|
290
|
+
expect(quietFollower.emitted).toEqual([]);
|
|
291
|
+
const failing = await runPure(adoptPendingWrites(), {
|
|
292
|
+
state: buildState(),
|
|
293
|
+
now,
|
|
294
|
+
handlers: {
|
|
295
|
+
'local.query': () => [[row('dead', 0)]],
|
|
296
|
+
'local.execute': () => {
|
|
297
|
+
throw new Error('closed');
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
});
|
|
301
|
+
expect(failing.state.outbox).toEqual([]);
|
|
302
|
+
expect(failing.dispatched).toEqual([]);
|
|
303
|
+
expect(failing.emitted).toContainEqual(expect.objectContaining({ type: 'log', level: 'warn' }));
|
|
304
|
+
const noTable = await runPure(adoptPendingWrites(), {
|
|
305
|
+
state: buildState(),
|
|
306
|
+
handlers: {
|
|
307
|
+
'local.query': () => {
|
|
308
|
+
throw new Error('no table');
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
});
|
|
312
|
+
expect(noTable.dispatched).toEqual([]);
|
|
313
|
+
const empty = await runPure(adoptPendingWrites(), { state: buildState(), handlers: { 'local.query': () => [[]] } });
|
|
314
|
+
expect(empty.timers.size).toBe(0);
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
describe('channel peer writes', () => {
|
|
319
|
+
const row = { id: rid, a: 1 };
|
|
320
|
+
const local = (existing: unknown) => ({ 'local.query': () => [existing] });
|
|
321
|
+
|
|
322
|
+
it('readRow: the stored row, or null', async () => {
|
|
323
|
+
expect((await runPure(readRow('thing:1'), { handlers: local(row) })).result).toEqual(row);
|
|
324
|
+
expect((await runPure(readRow('thing:1'), { handlers: local(null) })).result).toBeNull();
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it('peerCreate: inserts without an outbox entry, feeds the circuit unversioned, shows it, arms the expiry', async () => {
|
|
328
|
+
const out = await runPure(peerCreate(env, { recordId: 'thing:1', data: { a: 1, junk: 2 }, ttlMs: 5000 }), {
|
|
329
|
+
state: withQuery(),
|
|
330
|
+
handlers: {
|
|
331
|
+
...local(null),
|
|
332
|
+
'local.execute': (e: any) => {
|
|
333
|
+
expect(e.query.sql).not.toContain('mutationType');
|
|
334
|
+
expect(e.vars).toEqual({ id: rid, data_a: 1 });
|
|
335
|
+
return row;
|
|
336
|
+
},
|
|
337
|
+
'ssp.ingest': (e: any) => expect(e.records).toEqual([{ table: 'thing', op: 'CREATE', id: 'thing:1', record: { ...row, _00_rv: 0 } }]),
|
|
338
|
+
},
|
|
339
|
+
});
|
|
340
|
+
expect(out.result).toBe(true);
|
|
341
|
+
expect(out.state.outbox).toEqual([]);
|
|
342
|
+
expect(out.state.versions.has('thing:1')).toBe(false);
|
|
343
|
+
expect(out.state.peerWrites.get('thing:1')).toEqual({ kind: 'create', table: 'thing', expiresAt: 1_700_000_005_000 });
|
|
344
|
+
expect(out.state.dirty.has('q')).toBe(true);
|
|
345
|
+
expect(out.timers.get('peer:thing:1')).toEqual({ ms: 5000, event: { type: 'PeerWriteExpired', id: 'thing:1' } });
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it('peerCreate: refuses unknown tables, confirmed rows, own pending writes and a second create', async () => {
|
|
349
|
+
expect((await runPure(peerCreate(env, { recordId: 'nope:1', ttlMs: 1 }))).result).toBe(false);
|
|
350
|
+
const confirmed = buildState([], (s) => ({ ...s, versions: new Map([['thing:1', 2]]) }));
|
|
351
|
+
expect((await runPure(peerCreate(env, { recordId: 'thing:1', ttlMs: 1 }), { state: confirmed })).result).toBe(false);
|
|
352
|
+
const own = buildState([], R.outboxReplace([buildOutboxItem({ id: 'm', type: 'update', recordId: 'thing:1' })]));
|
|
353
|
+
expect((await runPure(peerCreate(env, { recordId: 'thing:1', ttlMs: 1 }), { state: own })).result).toBe(false);
|
|
354
|
+
const twice = R.setPeerWrite('thing:1', { kind: 'create', table: 'thing', expiresAt: 1 })(buildState());
|
|
355
|
+
expect((await runPure(peerCreate(env, { recordId: 'thing:1', ttlMs: 1 }), { state: twice })).result).toBe(false);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it("peerCreate: an existing unconfirmed row (another tab's copy) is shown without a second insert", async () => {
|
|
359
|
+
const out = await runPure(peerCreate(env, { recordId: 'thing:1', ttlMs: 10 }), {
|
|
360
|
+
state: withQuery(),
|
|
361
|
+
handlers: { ...local(row), 'ssp.ingest': () => undefined },
|
|
362
|
+
});
|
|
363
|
+
expect(out.result).toBe(true);
|
|
364
|
+
expect(out.log.some((e) => e.kind === 'local.execute')).toBe(false);
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
it('peerCreate: a store refusal or an empty answer applies nothing; a circuit failure is logged and still shows', async () => {
|
|
368
|
+
const refused = await runPure(peerCreate(env, { recordId: 'thing:1', ttlMs: 10 }), {
|
|
369
|
+
handlers: { ...local(null), 'local.execute': () => { throw new Error('schema'); } },
|
|
370
|
+
});
|
|
371
|
+
expect(refused.result).toBe(false);
|
|
372
|
+
expect(refused.emitted[0]).toMatchObject({ type: 'log', level: 'debug' });
|
|
373
|
+
const empty = await runPure(peerCreate(env, { recordId: 'thing:1', ttlMs: 10 }), { handlers: { ...local(null), 'local.execute': () => [] } });
|
|
374
|
+
expect(empty.result).toBe(false);
|
|
375
|
+
const circuit = await runPure(peerCreate(env, { recordId: 'thing:1', data: { a: 1 }, ttlMs: 10 }), {
|
|
376
|
+
handlers: { ...local(null), 'local.execute': () => row, 'ssp.ingest': () => { throw new Error('wasm'); } },
|
|
377
|
+
});
|
|
378
|
+
expect(circuit.result).toBe(true);
|
|
379
|
+
expect(circuit.emitted[0]).toMatchObject({ type: 'log', level: 'error' });
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it('peerDelete: hides an existing row, keeps it in the store, arms the expiry', async () => {
|
|
383
|
+
const out = await runPure(peerDelete(env, { recordId: 'thing:1', ttlMs: 3000 }), { state: withQuery(), handlers: local(row) });
|
|
384
|
+
expect(out.result).toBe(true);
|
|
385
|
+
expect(out.state.peerWrites.get('thing:1')).toMatchObject({ kind: 'delete' });
|
|
386
|
+
expect(out.log.some((e) => e.kind === 'local.execute')).toBe(false);
|
|
387
|
+
expect(out.timers.get('peer:thing:1')?.ms).toBe(3000);
|
|
388
|
+
expect((await runPure(peerDelete(env, { recordId: 'thing:1', ttlMs: 1 }), { handlers: local(null) })).result).toBe(false);
|
|
389
|
+
expect((await runPure(peerDelete(env, { recordId: 'nope:1', ttlMs: 1 }))).result).toBe(false);
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it("peerDelete: of the peer's own unconfirmed create undoes it; of a confirmed one hides it", async () => {
|
|
393
|
+
const created = R.setPeerWrite('thing:1', { kind: 'create', table: 'thing', expiresAt: 1 })(withQuery());
|
|
394
|
+
const undo = await runPure(peerDelete(env, { recordId: 'thing:1', ttlMs: 1 }), {
|
|
395
|
+
state: created,
|
|
396
|
+
handlers: {
|
|
397
|
+
...local(row),
|
|
398
|
+
'local.execute': (e: any) => expect(e.query.sql).toContain('DELETE'),
|
|
399
|
+
'ssp.ingest': (e: any) => expect(e.records).toEqual([{ table: 'thing', op: 'DELETE', id: 'thing:1', record: row }]),
|
|
400
|
+
},
|
|
401
|
+
});
|
|
402
|
+
expect(undo.result).toBe(true);
|
|
403
|
+
expect(undo.state.peerWrites.size).toBe(0);
|
|
404
|
+
const confirmed = { ...created, versions: new Map([['thing:1', 1]]) };
|
|
405
|
+
const hide = await runPure(peerDelete(env, { recordId: 'thing:1', ttlMs: 1 }), { state: confirmed, handlers: local(row) });
|
|
406
|
+
expect(hide.state.peerWrites.get('thing:1')).toMatchObject({ kind: 'delete' });
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
it('peerWriteExpired: undoes an unconfirmed create, keeps a confirmed or own one, forgets a delete', async () => {
|
|
410
|
+
expect((await runPure(peerWriteExpired('thing:1'))).log.filter((e) => e.kind !== 'state.read')).toEqual([]);
|
|
411
|
+
const created = R.setPeerWrite('thing:1', { kind: 'create', table: 'thing', expiresAt: 1 })(withQuery());
|
|
412
|
+
const undone = await runPure(peerWriteExpired('thing:1'), {
|
|
413
|
+
state: created,
|
|
414
|
+
handlers: { ...local(null), 'local.execute': () => undefined },
|
|
415
|
+
});
|
|
416
|
+
expect(undone.state.peerWrites.size).toBe(0);
|
|
417
|
+
expect(undone.log.some((e) => e.kind === 'ssp.ingest')).toBe(false);
|
|
418
|
+
const failed = await runPure(peerWriteExpired('thing:1'), {
|
|
419
|
+
state: created,
|
|
420
|
+
handlers: { ...local(row), 'local.execute': () => { throw new Error('locked'); } },
|
|
421
|
+
});
|
|
422
|
+
expect(failed.emitted[0]).toMatchObject({ type: 'log', level: 'warn' });
|
|
423
|
+
expect(failed.state.peerWrites.size).toBe(0);
|
|
424
|
+
const confirmed = await runPure(peerWriteExpired('thing:1'), { state: { ...created, versions: new Map([['thing:1', 1]]) } });
|
|
425
|
+
expect(confirmed.state.peerWrites.size).toBe(0);
|
|
426
|
+
expect(confirmed.log.some((e) => e.kind === 'local.execute')).toBe(false);
|
|
427
|
+
const own = await runPure(peerWriteExpired('thing:1'), {
|
|
428
|
+
state: R.outboxReplace([buildOutboxItem({ id: 'm', type: 'update', recordId: 'thing:1' })])(created),
|
|
429
|
+
});
|
|
430
|
+
expect(own.state.peerWrites.size).toBe(0);
|
|
431
|
+
const deleted = await runPure(peerWriteExpired('thing:1'), {
|
|
432
|
+
state: R.setPeerWrite('thing:1', { kind: 'delete', table: 'thing', expiresAt: 1 })(withQuery()),
|
|
433
|
+
});
|
|
434
|
+
expect(deleted.state.peerWrites.size).toBe(0);
|
|
435
|
+
});
|
|
436
|
+
});
|