@spooky-sync/core 0.0.1-canary.240 → 0.0.1-canary.241
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 +34 -15
- package/README.md +56 -16
- package/dist/index.d.ts +1136 -1846
- package/dist/index.js +10168 -11267
- package/dist/types.d.ts +22 -79
- package/package.json +8 -4
- package/skills/sp00ky-core/SKILL.md +18 -0
- package/src/boot/auth-flip.saga.test.ts +82 -0
- package/src/boot/auth-flip.saga.ts +62 -0
- package/src/boot/boot.saga.test.ts +151 -0
- package/src/boot/boot.saga.ts +128 -0
- package/src/boot/bucket-switch.saga.test.ts +158 -0
- package/src/boot/bucket-switch.saga.ts +115 -0
- package/src/boot/preload.saga.test.ts +51 -0
- package/src/boot/preload.saga.ts +31 -0
- package/src/client/bucket-handle.test.ts +117 -0
- package/src/client/bucket-handle.ts +227 -0
- package/src/client/router.test.ts +56 -0
- package/src/client/router.ts +94 -0
- package/src/client/runtime.test.ts +192 -0
- package/src/client/runtime.ts +296 -0
- package/src/client/services.ts +349 -0
- package/src/client/sp00ky-client.test.ts +241 -0
- package/src/client/sp00ky-client.ts +482 -0
- package/src/index.ts +1 -0
- package/src/kernel/constants.test.ts +19 -0
- package/src/kernel/constants.ts +54 -0
- package/src/kernel/effects.test.ts +40 -0
- package/src/kernel/effects.ts +159 -0
- package/src/kernel/events.ts +55 -0
- package/src/kernel/interpreter.test.ts +116 -0
- package/src/kernel/interpreter.ts +143 -0
- package/src/kernel/saga.test.ts +89 -0
- package/src/kernel/saga.ts +73 -0
- package/src/modules/app-release/index.ts +13 -5
- package/src/modules/devtools/index.ts +10 -3
- package/src/modules/devtools/state-shape.test.ts +4 -1
- package/src/modules/feature-flag/index.ts +13 -5
- package/src/mutation/jobs.test.ts +25 -0
- package/src/mutation/jobs.ts +41 -0
- package/src/{modules/data → mutation}/mutation-id.test.ts +12 -0
- package/src/mutation/push.saga.test.ts +285 -0
- package/src/mutation/push.saga.ts +215 -0
- package/src/mutation/rows.test.ts +201 -0
- package/src/mutation/rows.ts +377 -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 +163 -0
- package/src/mutation/write.saga.ts +166 -0
- package/src/query/env.test.ts +23 -0
- package/src/query/env.ts +56 -0
- package/src/query/fetch.saga.test.ts +156 -0
- package/src/query/fetch.saga.ts +109 -0
- package/src/query/hash.test.ts +14 -0
- package/src/query/hash.ts +18 -0
- package/src/{modules/data → query}/id-set-plan.test.ts +12 -2
- package/src/query/lifecycle.saga.test.ts +122 -0
- package/src/query/lifecycle.saga.ts +101 -0
- package/src/query/materialize.saga.test.ts +82 -0
- package/src/query/materialize.saga.ts +75 -0
- package/src/query/materialize.test.ts +50 -0
- package/src/query/materialize.ts +44 -0
- package/src/query/membership.saga.test.ts +246 -0
- package/src/query/membership.saga.ts +208 -0
- package/src/query/membership.test.ts +118 -0
- package/src/query/membership.ts +158 -0
- package/src/query/register.saga.test.ts +251 -0
- package/src/query/register.saga.ts +190 -0
- package/src/query/render-set.test.ts +36 -0
- package/src/query/render-set.ts +60 -0
- package/src/query/sql.test.ts +62 -0
- package/src/query/sql.ts +79 -0
- package/src/{modules/data → query}/window-query.test.ts +18 -0
- package/src/{modules/data → query}/window-query.ts +2 -1
- package/src/services/database/connection-supervisor.test.ts +29 -0
- package/src/services/database/connection-supervisor.ts +7 -0
- package/src/services/database/database.responses.test.ts +43 -0
- package/src/services/database/database.ts +25 -10
- package/src/services/database/local-migrator.ts +2 -2
- package/src/services/database/plan-render.test.ts +1 -1
- package/src/services/database/sqlite-cache-engine.test.ts +4 -3
- package/src/services/database/sqlite-cache-engine.ts +2 -11
- package/src/services/database/sqlite-devtools-queries.integration.test.ts +1 -1
- package/src/services/tabs/protocol.ts +7 -3
- package/src/sp00ky.ts +5 -1854
- package/src/state/client-state.ts +184 -0
- package/src/state/lifecycle.test.ts +118 -0
- package/src/state/lifecycle.ts +86 -0
- package/src/state/reducers.test.ts +280 -0
- package/src/state/reducers.ts +476 -0
- package/src/state/selectors.test.ts +149 -0
- package/src/state/selectors.ts +184 -0
- package/src/sync/connection.saga.test.ts +86 -0
- package/src/sync/connection.saga.ts +85 -0
- package/src/sync/live.saga.test.ts +69 -0
- package/src/sync/live.saga.ts +49 -0
- package/src/sync/policy.health.test.ts +56 -0
- package/src/{modules/sync/utils.test.ts → sync/policy.test.ts} +31 -3
- package/src/{modules/sync/utils.ts → sync/policy.ts} +67 -5
- package/src/sync/poll.saga.test.ts +51 -0
- package/src/sync/poll.saga.ts +36 -0
- package/src/sync/tabs.saga.test.ts +74 -0
- package/src/sync/tabs.saga.ts +92 -0
- package/src/testing/adapters.ts +133 -0
- package/src/testing/build.ts +61 -0
- package/src/testing/fake-services.ts +34 -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 +8 -7
- package/src/utils/utils.test.ts +2 -1
- package/vitest.config.ts +48 -0
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -476
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/src/boot/auth-flip.saga.ts.html +0 -271
- package/coverage/lcov-report/src/boot/boot.saga.ts.html +0 -469
- package/coverage/lcov-report/src/boot/bucket-switch.saga.ts.html +0 -430
- package/coverage/lcov-report/src/boot/index.html +0 -161
- package/coverage/lcov-report/src/boot/preload.saga.ts.html +0 -178
- package/coverage/lcov-report/src/client/bucket-handle.ts.html +0 -766
- package/coverage/lcov-report/src/client/index.html +0 -161
- package/coverage/lcov-report/src/client/router.ts.html +0 -367
- package/coverage/lcov-report/src/client/runtime.ts.html +0 -940
- package/coverage/lcov-report/src/client/sp00ky-client.ts.html +0 -1531
- package/coverage/lcov-report/src/events/index.html +0 -116
- package/coverage/lcov-report/src/events/index.ts.html +0 -877
- package/coverage/lcov-report/src/index.html +0 -146
- package/coverage/lcov-report/src/index.ts.html +0 -202
- package/coverage/lcov-report/src/kernel/constants.ts.html +0 -247
- package/coverage/lcov-report/src/kernel/effects.ts.html +0 -562
- package/coverage/lcov-report/src/kernel/events.ts.html +0 -250
- package/coverage/lcov-report/src/kernel/index.html +0 -176
- package/coverage/lcov-report/src/kernel/interpreter.ts.html +0 -514
- package/coverage/lcov-report/src/kernel/saga.ts.html +0 -304
- package/coverage/lcov-report/src/modules/app-release/index.html +0 -116
- package/coverage/lcov-report/src/modules/app-release/index.ts.html +0 -712
- package/coverage/lcov-report/src/modules/auth/events/index.html +0 -116
- package/coverage/lcov-report/src/modules/auth/events/index.ts.html +0 -142
- package/coverage/lcov-report/src/modules/auth/index.html +0 -116
- package/coverage/lcov-report/src/modules/auth/index.ts.html +0 -1225
- package/coverage/lcov-report/src/modules/crdt/crdt-field.ts.html +0 -967
- package/coverage/lcov-report/src/modules/crdt/index.html +0 -146
- package/coverage/lcov-report/src/modules/crdt/index.ts.html +0 -1474
- package/coverage/lcov-report/src/modules/crdt/loro-loader.ts.html +0 -160
- package/coverage/lcov-report/src/modules/devtools/flags.ts.html +0 -1132
- package/coverage/lcov-report/src/modules/devtools/index.html +0 -161
- package/coverage/lcov-report/src/modules/devtools/index.ts.html +0 -2413
- package/coverage/lcov-report/src/modules/devtools/storage-info.ts.html +0 -589
- package/coverage/lcov-report/src/modules/devtools/versions.ts.html +0 -415
- package/coverage/lcov-report/src/modules/feature-flag/index.html +0 -116
- package/coverage/lcov-report/src/modules/feature-flag/index.ts.html +0 -1033
- package/coverage/lcov-report/src/modules/index.html +0 -116
- package/coverage/lcov-report/src/modules/ref-tables.ts.html +0 -349
- package/coverage/lcov-report/src/mutation/index.html +0 -191
- package/coverage/lcov-report/src/mutation/jobs.ts.html +0 -208
- package/coverage/lcov-report/src/mutation/mutation-id.ts.html +0 -190
- package/coverage/lcov-report/src/mutation/push.saga.ts.html +0 -730
- package/coverage/lcov-report/src/mutation/rows.ts.html +0 -1216
- package/coverage/lcov-report/src/mutation/tray.saga.ts.html +0 -229
- package/coverage/lcov-report/src/mutation/write.saga.ts.html +0 -583
- package/coverage/lcov-report/src/otel/index.html +0 -116
- package/coverage/lcov-report/src/otel/index.ts.html +0 -466
- package/coverage/lcov-report/src/query/env.ts.html +0 -253
- package/coverage/lcov-report/src/query/fetch.saga.ts.html +0 -412
- package/coverage/lcov-report/src/query/hash.ts.html +0 -139
- package/coverage/lcov-report/src/query/index.html +0 -281
- package/coverage/lcov-report/src/query/lifecycle.saga.ts.html +0 -388
- package/coverage/lcov-report/src/query/materialize.saga.ts.html +0 -310
- package/coverage/lcov-report/src/query/materialize.ts.html +0 -217
- package/coverage/lcov-report/src/query/membership.saga.ts.html +0 -709
- package/coverage/lcov-report/src/query/membership.ts.html +0 -559
- package/coverage/lcov-report/src/query/register.saga.ts.html +0 -655
- package/coverage/lcov-report/src/query/render-set.ts.html +0 -265
- package/coverage/lcov-report/src/query/sql.ts.html +0 -322
- package/coverage/lcov-report/src/query/window-query.ts.html +0 -670
- package/coverage/lcov-report/src/services/blobs/blob-cache.ts.html +0 -1894
- package/coverage/lcov-report/src/services/blobs/blob-manifest.ts.html +0 -766
- package/coverage/lcov-report/src/services/blobs/blob-store.ts.html +0 -1162
- package/coverage/lcov-report/src/services/blobs/index.html +0 -161
- package/coverage/lcov-report/src/services/blobs/index.ts.html +0 -295
- package/coverage/lcov-report/src/services/database/cache-engine.ts.html +0 -664
- package/coverage/lcov-report/src/services/database/connection-supervisor.ts.html +0 -1330
- package/coverage/lcov-report/src/services/database/database.ts.html +0 -658
- package/coverage/lcov-report/src/services/database/engine-factory.ts.html +0 -184
- package/coverage/lcov-report/src/services/database/errors.ts.html +0 -187
- package/coverage/lcov-report/src/services/database/events/index.html +0 -116
- package/coverage/lcov-report/src/services/database/events/index.ts.html +0 -184
- package/coverage/lcov-report/src/services/database/index.html +0 -386
- package/coverage/lcov-report/src/services/database/index.ts.html +0 -121
- package/coverage/lcov-report/src/services/database/local-migrator.ts.html +0 -703
- package/coverage/lcov-report/src/services/database/local.ts.html +0 -1633
- package/coverage/lcov-report/src/services/database/plan-render.ts.html +0 -409
- package/coverage/lcov-report/src/services/database/relation-resolver.ts.html +0 -682
- package/coverage/lcov-report/src/services/database/remote.ts.html +0 -1036
- package/coverage/lcov-report/src/services/database/sqlite-cache-engine.ts.html +0 -4132
- package/coverage/lcov-report/src/services/database/sqlite-lock-verify.ts.html +0 -220
- package/coverage/lcov-report/src/services/database/sqlite-open.ts.html +0 -577
- package/coverage/lcov-report/src/services/database/sqlite-plan-sql.ts.html +0 -499
- package/coverage/lcov-report/src/services/database/sqlite-select.ts.html +0 -478
- package/coverage/lcov-report/src/services/database/sqlite-transport.ts.html +0 -757
- package/coverage/lcov-report/src/services/database/surql-translate.ts.html +0 -1333
- package/coverage/lcov-report/src/services/database/surreal-cache-engine.ts.html +0 -568
- package/coverage/lcov-report/src/services/logger/index.html +0 -116
- package/coverage/lcov-report/src/services/logger/index.ts.html +0 -154
- package/coverage/lcov-report/src/services/persistence/index.html +0 -146
- package/coverage/lcov-report/src/services/persistence/localstorage.ts.html +0 -163
- package/coverage/lcov-report/src/services/persistence/resilient.ts.html +0 -208
- package/coverage/lcov-report/src/services/persistence/surrealdb.ts.html +0 -271
- package/coverage/lcov-report/src/services/stream-processor/index.html +0 -146
- package/coverage/lcov-report/src/services/stream-processor/index.ts.html +0 -3313
- package/coverage/lcov-report/src/services/stream-processor/permissions.ts.html +0 -244
- package/coverage/lcov-report/src/services/stream-processor/wasm-types.ts.html +0 -346
- package/coverage/lcov-report/src/services/tabs/broker-client.ts.html +0 -934
- package/coverage/lcov-report/src/services/tabs/coordinator.ts.html +0 -1984
- package/coverage/lcov-report/src/services/tabs/index.html +0 -191
- package/coverage/lcov-report/src/services/tabs/leader-locks.ts.html +0 -310
- package/coverage/lcov-report/src/services/tabs/protocol.ts.html +0 -871
- package/coverage/lcov-report/src/services/tabs/support.ts.html +0 -193
- package/coverage/lcov-report/src/services/tabs/tabs-broker-worker.ts.html +0 -2005
- package/coverage/lcov-report/src/sp00ky.ts.html +0 -100
- package/coverage/lcov-report/src/state/client-state.ts.html +0 -637
- package/coverage/lcov-report/src/state/index.html +0 -161
- package/coverage/lcov-report/src/state/lifecycle.ts.html +0 -343
- package/coverage/lcov-report/src/state/reducers.ts.html +0 -1471
- package/coverage/lcov-report/src/state/selectors.ts.html +0 -637
- package/coverage/lcov-report/src/sync/connection.saga.ts.html +0 -343
- package/coverage/lcov-report/src/sync/index.html +0 -176
- package/coverage/lcov-report/src/sync/live.saga.ts.html +0 -232
- package/coverage/lcov-report/src/sync/policy.ts.html +0 -1606
- package/coverage/lcov-report/src/sync/poll.saga.ts.html +0 -193
- package/coverage/lcov-report/src/sync/tabs.saga.ts.html +0 -361
- package/coverage/lcov-report/src/types.ts.html +0 -2419
- package/coverage/lcov-report/src/utils/blurhash.ts.html +0 -355
- package/coverage/lcov-report/src/utils/error-classification.ts.html +0 -244
- package/coverage/lcov-report/src/utils/index.html +0 -191
- package/coverage/lcov-report/src/utils/index.ts.html +0 -820
- package/coverage/lcov-report/src/utils/parser.ts.html +0 -313
- package/coverage/lcov-report/src/utils/semver.ts.html +0 -175
- package/coverage/lcov-report/src/utils/surql.ts.html +0 -667
- package/coverage/lcov.info +0 -19079
- package/src/modules/cache/cache.relay.test.ts +0 -95
- package/src/modules/cache/index.ts +0 -361
- package/src/modules/cache/types.ts +0 -19
- package/src/modules/data/data.activity.test.ts +0 -109
- package/src/modules/data/data.authority.test.ts +0 -122
- package/src/modules/data/data.heartbeat-wake.test.ts +0 -115
- package/src/modules/data/data.hydration.test.ts +0 -142
- package/src/modules/data/data.membership.test.ts +0 -623
- package/src/modules/data/data.notify-table.test.ts +0 -41
- package/src/modules/data/data.pending-ids.test.ts +0 -199
- package/src/modules/data/data.rebind.test.ts +0 -170
- package/src/modules/data/data.rematerialize.test.ts +0 -114
- package/src/modules/data/data.run.test.ts +0 -113
- package/src/modules/data/data.settled-writes.test.ts +0 -235
- package/src/modules/data/data.status.test.ts +0 -249
- package/src/modules/data/data.test.ts +0 -58
- package/src/modules/data/index.ts +0 -2745
- package/src/modules/sync/engine.ts +0 -250
- package/src/modules/sync/events/index.ts +0 -84
- package/src/modules/sync/index.ts +0 -3
- package/src/modules/sync/queue/index.ts +0 -2
- package/src/modules/sync/queue/queue-down.test.ts +0 -228
- package/src/modules/sync/queue/queue-down.ts +0 -184
- package/src/modules/sync/queue/queue-up.forwarded.test.ts +0 -164
- package/src/modules/sync/queue/queue-up.ts +0 -407
- package/src/modules/sync/scheduler.pause.test.ts +0 -109
- package/src/modules/sync/scheduler.retry.test.ts +0 -237
- package/src/modules/sync/scheduler.ts +0 -286
- package/src/modules/sync/sync.cleanup.test.ts +0 -116
- package/src/modules/sync/sync.health.test.ts +0 -167
- package/src/modules/sync/sync.heartbeat.test.ts +0 -80
- package/src/modules/sync/sync.list-ref-meta.test.ts +0 -193
- package/src/modules/sync/sync.live-removal.test.ts +0 -289
- package/src/modules/sync/sync.reconnect.test.ts +0 -145
- package/src/modules/sync/sync.rematerialize-after-fetch.test.ts +0 -93
- package/src/modules/sync/sync.settled-poll.test.ts +0 -58
- package/src/modules/sync/sync.subquery.test.ts +0 -82
- package/src/modules/sync/sync.tabs.test.ts +0 -249
- package/src/modules/sync/sync.ts +0 -2626
- package/src/sp00ky.auth-order.test.ts +0 -112
- package/src/sp00ky.init-query.test.ts +0 -183
- package/src/sp00ky.local-first.test.ts +0 -60
- /package/src/{modules/data → mutation}/mutation-id.ts +0 -0
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
2
|
-
import { RecordId } from 'surrealdb';
|
|
3
|
-
import { DataModule } from './index';
|
|
4
|
-
import type { QueryPlan } from '@spooky-sync/query-builder';
|
|
5
|
-
import type { QueryState, RecordVersionArray } from '../../types';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* A write is visible before the server confirms it because it sits in the
|
|
9
|
-
* outbox: the render set is
|
|
10
|
-
* `(membership ∪ (pendingWrites ∩ localArray)) − pendingDeletes`.
|
|
11
|
-
*
|
|
12
|
-
* The outbox row is deleted the instant the push succeeds, but the row does not
|
|
13
|
-
* enter membership until the SSP has ingested it, materialized the view, written
|
|
14
|
-
* the `_00_list_ref` edge, and this client has read that back. In between it is
|
|
15
|
-
* in NEITHER term, so it renders, disappears, and returns.
|
|
16
|
-
*
|
|
17
|
-
* Reported from production as "the comment shows up on every other client in
|
|
18
|
-
* realtime but not on the one that wrote it" — other clients don't blink because
|
|
19
|
-
* a client that never established membership renders from the predicate scan
|
|
20
|
-
* instead. The gap is invisible when the round trip is fast and glaring when the
|
|
21
|
-
* edge path is backed up.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
const noop = () => {};
|
|
25
|
-
|
|
26
|
-
function makeLogger(): any {
|
|
27
|
-
const logger: any = { debug: noop, info: noop, warn: noop, error: noop, trace: noop };
|
|
28
|
-
logger.child = () => logger;
|
|
29
|
-
return logger;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const schema = { tables: [{ name: 'comment', columns: {} }] } as any;
|
|
33
|
-
const plan: QueryPlan = { table: 'comment', where: [['game', '=', 'game:g1']] } as any;
|
|
34
|
-
|
|
35
|
-
function makeQueryState(
|
|
36
|
-
hash: string,
|
|
37
|
-
opts: { remoteArray?: RecordVersionArray; localArray?: RecordVersionArray } = {}
|
|
38
|
-
): QueryState {
|
|
39
|
-
return {
|
|
40
|
-
config: {
|
|
41
|
-
id: new RecordId('_00_query', hash),
|
|
42
|
-
surql: 'SELECT * FROM comment WHERE game = $game;',
|
|
43
|
-
plan,
|
|
44
|
-
params: { game: 'game:g1' },
|
|
45
|
-
localArray: opts.localArray ?? [],
|
|
46
|
-
remoteArray: opts.remoteArray ?? [],
|
|
47
|
-
membershipKnown: true,
|
|
48
|
-
ttl: '10m',
|
|
49
|
-
lastActiveAt: new Date(),
|
|
50
|
-
tableName: 'comment',
|
|
51
|
-
},
|
|
52
|
-
records: [],
|
|
53
|
-
ttlTimer: null,
|
|
54
|
-
ttlDurationMs: 0,
|
|
55
|
-
updateCount: 0,
|
|
56
|
-
lastUpdatedAt: null,
|
|
57
|
-
materializationSamples: [],
|
|
58
|
-
lastIngestLatencyMs: null,
|
|
59
|
-
errorCount: 0,
|
|
60
|
-
status: 'idle',
|
|
61
|
-
phaseSamples: {},
|
|
62
|
-
phaseLast: {},
|
|
63
|
-
registrationTimings: { parseMs: null, planMs: null, snapshotMs: null, wallMs: null },
|
|
64
|
-
} as QueryState;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function setup(
|
|
68
|
-
stateOpts: Parameters<typeof makeQueryState>[1] = {},
|
|
69
|
-
pendingRows: Array<{ recordId: RecordId; mutationType: string }> = []
|
|
70
|
-
) {
|
|
71
|
-
const bodies = new Map(
|
|
72
|
-
['old', 'new'].map((k) => [`comment:${k}`, { id: new RecordId('comment', k), body: k }])
|
|
73
|
-
);
|
|
74
|
-
const local: any = {
|
|
75
|
-
epoch: 1,
|
|
76
|
-
select: vi.fn(async (p: QueryPlan) => {
|
|
77
|
-
if ((p as any).ids) {
|
|
78
|
-
return ((p as any).ids as RecordId[])
|
|
79
|
-
.map((id) => bodies.get(id.toString()))
|
|
80
|
-
.filter((r): r is NonNullable<typeof r> => r !== undefined);
|
|
81
|
-
}
|
|
82
|
-
return Array.from(bodies.values());
|
|
83
|
-
}),
|
|
84
|
-
query: vi.fn(async (sql: string) => {
|
|
85
|
-
if (sql.includes('_00_pending_mutations')) return [pendingRows];
|
|
86
|
-
if (sql.includes('FROM ONLY')) return [null];
|
|
87
|
-
return [Array.from(bodies.values())];
|
|
88
|
-
}),
|
|
89
|
-
getById: vi.fn(async () => null),
|
|
90
|
-
upsert: vi.fn(async () => {}),
|
|
91
|
-
};
|
|
92
|
-
const dm = new DataModule({ saveBatch: async () => {} } as any, local, schema, makeLogger(), 100);
|
|
93
|
-
const state = makeQueryState('h1', stateOpts);
|
|
94
|
-
(dm as any).activeQueries.set('h1', state);
|
|
95
|
-
return { dm, state };
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const ids = (rows: Array<Record<string, any>>) => rows.map((r) => String(r.id));
|
|
99
|
-
const materialize = (dm: DataModule<any>, state: QueryState, ssp?: RecordVersionArray) =>
|
|
100
|
-
(dm as any).materializeRecords(state, ssp) as Promise<Record<string, any>[]>;
|
|
101
|
-
|
|
102
|
-
describe('settled-write grace window', () => {
|
|
103
|
-
afterEach(() => vi.useRealTimers());
|
|
104
|
-
|
|
105
|
-
it('keeps an accepted write rendered while membership has not caught up', async () => {
|
|
106
|
-
// Membership still only knows the old comment; the outbox row for the new
|
|
107
|
-
// one is already gone because the push succeeded.
|
|
108
|
-
const { dm, state } = setup({
|
|
109
|
-
remoteArray: [['comment:old', 1]],
|
|
110
|
-
localArray: [
|
|
111
|
-
['comment:old', 1],
|
|
112
|
-
['comment:new', 1],
|
|
113
|
-
],
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
dm.noteWriteSettled('comment:new', 'create');
|
|
117
|
-
|
|
118
|
-
expect(ids(await materialize(dm, state))).toEqual(['comment:new', 'comment:old']);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('renders nothing extra for a write the server never accepted', async () => {
|
|
122
|
-
// The rollback path never reports a mutation settled, so a rejected write
|
|
123
|
-
// has no grace at all. This is what keeps the window from showing rows the
|
|
124
|
-
// server refused.
|
|
125
|
-
const { dm, state } = setup({
|
|
126
|
-
remoteArray: [['comment:old', 1]],
|
|
127
|
-
localArray: [
|
|
128
|
-
['comment:old', 1],
|
|
129
|
-
['comment:new', 1],
|
|
130
|
-
],
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
expect(ids(await materialize(dm, state))).toEqual(['comment:old']);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('stops granting grace once membership names the row', async () => {
|
|
137
|
-
const { dm, state } = setup({
|
|
138
|
-
remoteArray: [['comment:old', 1]],
|
|
139
|
-
localArray: [
|
|
140
|
-
['comment:old', 1],
|
|
141
|
-
['comment:new', 1],
|
|
142
|
-
],
|
|
143
|
-
});
|
|
144
|
-
dm.noteWriteSettled('comment:new', 'create');
|
|
145
|
-
await materialize(dm, state);
|
|
146
|
-
|
|
147
|
-
// Membership catches up; the id must not be double-counted…
|
|
148
|
-
state.config.remoteArray = [
|
|
149
|
-
['comment:old', 1],
|
|
150
|
-
['comment:new', 1],
|
|
151
|
-
];
|
|
152
|
-
expect(ids(await materialize(dm, state))).toEqual(['comment:new', 'comment:old']);
|
|
153
|
-
expect((dm as any).settledWrites.size).toBe(0);
|
|
154
|
-
|
|
155
|
-
// …and once the server later drops it from the window, it goes away rather
|
|
156
|
-
// than being resurrected by a stale grace entry.
|
|
157
|
-
state.config.remoteArray = [['comment:old', 1]];
|
|
158
|
-
expect(ids(await materialize(dm, state))).toEqual(['comment:old']);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('expires the grace so a write whose membership never arrives cannot linger', async () => {
|
|
162
|
-
vi.useFakeTimers();
|
|
163
|
-
const { dm, state } = setup({
|
|
164
|
-
remoteArray: [['comment:old', 1]],
|
|
165
|
-
localArray: [
|
|
166
|
-
['comment:old', 1],
|
|
167
|
-
['comment:new', 1],
|
|
168
|
-
],
|
|
169
|
-
});
|
|
170
|
-
dm.noteWriteSettled('comment:new', 'create');
|
|
171
|
-
expect(ids(await materialize(dm, state))).toContain('comment:new');
|
|
172
|
-
expect(dm.hasSettledWritesPending()).toBe(true);
|
|
173
|
-
|
|
174
|
-
// A scheduler drain plus one stalled database commit fit inside the
|
|
175
|
-
// window: at 11 s the row is still the user's own message, not a ghost.
|
|
176
|
-
vi.advanceTimersByTime(11_000);
|
|
177
|
-
expect(ids(await materialize(dm, state))).toContain('comment:new');
|
|
178
|
-
expect(dm.hasSettledWritesPending()).toBe(true);
|
|
179
|
-
|
|
180
|
-
vi.advanceTimersByTime(20_000);
|
|
181
|
-
expect(ids(await materialize(dm, state))).toEqual(['comment:old']);
|
|
182
|
-
expect(dm.hasSettledWritesPending()).toBe(false);
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it('reports no pending settled write once membership has caught up', async () => {
|
|
186
|
-
const { dm, state } = setup({
|
|
187
|
-
remoteArray: [['comment:old', 1]],
|
|
188
|
-
localArray: [
|
|
189
|
-
['comment:old', 1],
|
|
190
|
-
['comment:new', 1],
|
|
191
|
-
],
|
|
192
|
-
});
|
|
193
|
-
expect(dm.hasSettledWritesPending()).toBe(false);
|
|
194
|
-
|
|
195
|
-
dm.noteWriteSettled('comment:new', 'create');
|
|
196
|
-
expect(dm.hasSettledWritesPending()).toBe(true);
|
|
197
|
-
|
|
198
|
-
state.config.remoteArray = [
|
|
199
|
-
['comment:old', 1],
|
|
200
|
-
['comment:new', 1],
|
|
201
|
-
];
|
|
202
|
-
await materialize(dm, state);
|
|
203
|
-
expect(dm.hasSettledWritesPending()).toBe(false);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it('keeps an accepted delete subtracted until membership drops the row', async () => {
|
|
207
|
-
// The mirror case: membership still lists the row until the SSP publishes
|
|
208
|
-
// its removal, so without this the deleted row flashes back.
|
|
209
|
-
const { dm, state } = setup({
|
|
210
|
-
remoteArray: [
|
|
211
|
-
['comment:old', 1],
|
|
212
|
-
['comment:new', 1],
|
|
213
|
-
],
|
|
214
|
-
localArray: [['comment:old', 1]],
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
dm.noteWriteSettled('comment:new', 'delete');
|
|
218
|
-
|
|
219
|
-
expect(ids(await materialize(dm, state))).toEqual(['comment:old']);
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
it('only grants grace to rows the local view still says match', async () => {
|
|
223
|
-
// `localArray` is the local SSP's answer to "does this row match the
|
|
224
|
-
// predicate". A settled write that does NOT match must not be forced into
|
|
225
|
-
// the render set — same rule the pending-write union already follows.
|
|
226
|
-
const { dm, state } = setup({
|
|
227
|
-
remoteArray: [['comment:old', 1]],
|
|
228
|
-
localArray: [['comment:old', 1]],
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
dm.noteWriteSettled('comment:new', 'create');
|
|
232
|
-
|
|
233
|
-
expect(ids(await materialize(dm, state))).toEqual(['comment:old']);
|
|
234
|
-
});
|
|
235
|
-
});
|
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
|
|
2
|
-
import { RecordId } from 'surrealdb';
|
|
3
|
-
import { DataModule } from './index';
|
|
4
|
-
import type { QueryState, QueryStatus } from '../../types';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Tests for the per-query fetch status (idle/fetching) added to DataModule:
|
|
8
|
-
* setQueryStatus updates the query object and notifies both the DevTools
|
|
9
|
-
* observer hook and subscribeStatus listeners; beginFetching/endFetching
|
|
10
|
-
* refcount overlapping fetch cycles; flushPendingStreamUpdate lands the
|
|
11
|
-
* debounced result before a query flips back to idle.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
function makeLogger(): any {
|
|
15
|
-
const noop = () => {};
|
|
16
|
-
const logger: any = { debug: noop, info: noop, warn: noop, error: noop, trace: noop };
|
|
17
|
-
logger.child = () => logger;
|
|
18
|
-
return logger;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function makeDataModule(): DataModule<any> {
|
|
22
|
-
return new DataModule(
|
|
23
|
-
{} as any, // cache — unused by status methods
|
|
24
|
-
{} as any, // local — unused by status methods
|
|
25
|
-
{ tables: [] } as any, // schema — unused by status methods
|
|
26
|
-
makeLogger(),
|
|
27
|
-
100
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function makeQueryState(hash: string): QueryState {
|
|
32
|
-
return {
|
|
33
|
-
config: {
|
|
34
|
-
id: new RecordId('_00_query', hash),
|
|
35
|
-
surql: 'SELECT * FROM user',
|
|
36
|
-
params: {},
|
|
37
|
-
localArray: [],
|
|
38
|
-
remoteArray: [],
|
|
39
|
-
ttl: '10m',
|
|
40
|
-
lastActiveAt: new Date(),
|
|
41
|
-
tableName: 'user',
|
|
42
|
-
},
|
|
43
|
-
records: [],
|
|
44
|
-
ttlTimer: null,
|
|
45
|
-
ttlDurationMs: 0,
|
|
46
|
-
updateCount: 0,
|
|
47
|
-
lastUpdatedAt: null,
|
|
48
|
-
materializationSamples: [],
|
|
49
|
-
lastIngestLatencyMs: null,
|
|
50
|
-
errorCount: 0,
|
|
51
|
-
status: 'idle',
|
|
52
|
-
phaseSamples: {},
|
|
53
|
-
phaseLast: {},
|
|
54
|
-
registrationTimings: { parseMs: null, planMs: null, snapshotMs: null, wallMs: null },
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
describe('DataModule query fetch status', () => {
|
|
59
|
-
let dm: DataModule<any>;
|
|
60
|
-
const hash = 'h1';
|
|
61
|
-
|
|
62
|
-
beforeEach(() => {
|
|
63
|
-
dm = makeDataModule();
|
|
64
|
-
(dm as any).activeQueries.set(hash, makeQueryState(hash));
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('subscribeStatus with immediate reports the current status', () => {
|
|
68
|
-
const seen: QueryStatus[] = [];
|
|
69
|
-
dm.subscribeStatus(hash, (s) => seen.push(s), { immediate: true });
|
|
70
|
-
expect(seen).toEqual(['idle']);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('setQueryStatus updates the query object and notifies subscribers + observer', () => {
|
|
74
|
-
const observed: Array<[string, QueryStatus]> = [];
|
|
75
|
-
dm.onQueryStatusChange = (h, s) => observed.push([h, s]);
|
|
76
|
-
|
|
77
|
-
const seen: QueryStatus[] = [];
|
|
78
|
-
dm.subscribeStatus(hash, (s) => seen.push(s));
|
|
79
|
-
|
|
80
|
-
dm.setQueryStatus(hash, 'fetching');
|
|
81
|
-
expect((dm as any).activeQueries.get(hash).status).toBe('fetching');
|
|
82
|
-
expect(seen).toEqual(['fetching']);
|
|
83
|
-
expect(observed).toEqual([[hash, 'fetching']]);
|
|
84
|
-
|
|
85
|
-
dm.setQueryStatus(hash, 'idle');
|
|
86
|
-
expect(seen).toEqual(['fetching', 'idle']);
|
|
87
|
-
expect(observed).toEqual([[hash, 'fetching'], [hash, 'idle']]);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('setQueryStatus is a no-op when the status is unchanged', () => {
|
|
91
|
-
const seen: QueryStatus[] = [];
|
|
92
|
-
dm.subscribeStatus(hash, (s) => seen.push(s));
|
|
93
|
-
dm.setQueryStatus(hash, 'idle'); // already idle
|
|
94
|
-
expect(seen).toEqual([]);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('setQueryStatus is a no-op for an unknown query', () => {
|
|
98
|
-
let called = false;
|
|
99
|
-
dm.onQueryStatusChange = () => {
|
|
100
|
-
called = true;
|
|
101
|
-
};
|
|
102
|
-
dm.setQueryStatus('does-not-exist', 'fetching');
|
|
103
|
-
expect(called).toBe(false);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('unsubscribe stops further status notifications', () => {
|
|
107
|
-
const seen: QueryStatus[] = [];
|
|
108
|
-
const unsub = dm.subscribeStatus(hash, (s) => seen.push(s));
|
|
109
|
-
dm.setQueryStatus(hash, 'fetching');
|
|
110
|
-
unsub();
|
|
111
|
-
dm.setQueryStatus(hash, 'idle');
|
|
112
|
-
expect(seen).toEqual(['fetching']);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
describe('DataModule beginFetching/endFetching refcount', () => {
|
|
117
|
-
let dm: DataModule<any>;
|
|
118
|
-
const hash = 'h1';
|
|
119
|
-
let seen: QueryStatus[];
|
|
120
|
-
|
|
121
|
-
beforeEach(() => {
|
|
122
|
-
dm = makeDataModule();
|
|
123
|
-
(dm as any).activeQueries.set(hash, makeQueryState(hash));
|
|
124
|
-
seen = [];
|
|
125
|
-
dm.subscribeStatus(hash, (s) => seen.push(s));
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('emits fetching on 0→1 and idle only on the last exit', () => {
|
|
129
|
-
dm.beginFetching(hash); // registration
|
|
130
|
-
dm.beginFetching(hash); // overlapping poll round
|
|
131
|
-
expect(seen).toEqual(['fetching']);
|
|
132
|
-
|
|
133
|
-
dm.endFetching(hash); // inner cycle finishes — must NOT emit idle
|
|
134
|
-
expect(seen).toEqual(['fetching']);
|
|
135
|
-
expect((dm as any).activeQueries.get(hash).status).toBe('fetching');
|
|
136
|
-
|
|
137
|
-
dm.endFetching(hash);
|
|
138
|
-
expect(seen).toEqual(['fetching', 'idle']);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('unbalanced endFetching settles to idle without going negative', () => {
|
|
142
|
-
dm.endFetching(hash); // already idle → no-op notification
|
|
143
|
-
expect(seen).toEqual([]);
|
|
144
|
-
dm.beginFetching(hash);
|
|
145
|
-
dm.endFetching(hash);
|
|
146
|
-
expect(seen).toEqual(['fetching', 'idle']);
|
|
147
|
-
expect((dm as any).fetchDepth.has(hash)).toBe(false);
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('DataModule pending stream-update flush', () => {
|
|
152
|
-
let dm: DataModule<any>;
|
|
153
|
-
const hash = 'h1';
|
|
154
|
-
let processed: any[];
|
|
155
|
-
|
|
156
|
-
const makeUpdate = (op: 'CREATE' | 'UPDATE' | 'DELETE') =>
|
|
157
|
-
({ queryHash: hash, op, localArray: [] }) as any;
|
|
158
|
-
|
|
159
|
-
beforeEach(() => {
|
|
160
|
-
vi.useFakeTimers();
|
|
161
|
-
dm = makeDataModule();
|
|
162
|
-
(dm as any).activeQueries.set(hash, makeQueryState(hash));
|
|
163
|
-
processed = [];
|
|
164
|
-
(dm as any).processStreamUpdate = async (u: any) => {
|
|
165
|
-
processed.push(u);
|
|
166
|
-
};
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
afterEach(() => {
|
|
170
|
-
vi.useRealTimers();
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('flushPendingStreamUpdate processes the debounced update exactly once', async () => {
|
|
174
|
-
const update = makeUpdate('CREATE');
|
|
175
|
-
await dm.onStreamUpdate(update);
|
|
176
|
-
expect(processed).toEqual([]); // still debounced
|
|
177
|
-
|
|
178
|
-
await dm.flushPendingStreamUpdate(hash);
|
|
179
|
-
expect(processed).toEqual([update]);
|
|
180
|
-
expect((dm as any).debounceTimers.has(hash)).toBe(false);
|
|
181
|
-
expect((dm as any).pendingStreamUpdates.has(hash)).toBe(false);
|
|
182
|
-
|
|
183
|
-
// The cancelled timer must not process it a second time.
|
|
184
|
-
await vi.runAllTimersAsync();
|
|
185
|
-
expect(processed).toEqual([update]);
|
|
186
|
-
|
|
187
|
-
// Nothing pending → flush is a no-op.
|
|
188
|
-
await dm.flushPendingStreamUpdate(hash);
|
|
189
|
-
expect(processed).toEqual([update]);
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it('the trailing-edge timer clears the pending entry itself', async () => {
|
|
193
|
-
const update = makeUpdate('UPDATE');
|
|
194
|
-
await dm.onStreamUpdate(update);
|
|
195
|
-
await vi.runAllTimersAsync();
|
|
196
|
-
expect(processed).toEqual([update]);
|
|
197
|
-
expect((dm as any).pendingStreamUpdates.has(hash)).toBe(false);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it('a DELETE supersedes and drops the pending coalesced update', async () => {
|
|
201
|
-
const create = makeUpdate('CREATE');
|
|
202
|
-
const del = makeUpdate('DELETE');
|
|
203
|
-
await dm.onStreamUpdate(create);
|
|
204
|
-
await dm.onStreamUpdate(del); // immediate, drops the pending CREATE
|
|
205
|
-
expect(processed).toEqual([del]);
|
|
206
|
-
expect((dm as any).pendingStreamUpdates.has(hash)).toBe(false);
|
|
207
|
-
await vi.runAllTimersAsync();
|
|
208
|
-
expect(processed).toEqual([del]);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it('finalizeDeregister clears pending update and fetch depth', async () => {
|
|
212
|
-
(dm as any).cache = { unregisterQuery: () => {} };
|
|
213
|
-
await dm.onStreamUpdate(makeUpdate('CREATE'));
|
|
214
|
-
dm.beginFetching(hash);
|
|
215
|
-
dm.finalizeDeregister(hash);
|
|
216
|
-
expect((dm as any).pendingStreamUpdates.has(hash)).toBe(false);
|
|
217
|
-
expect((dm as any).debounceTimers.has(hash)).toBe(false);
|
|
218
|
-
expect((dm as any).fetchDepth.has(hash)).toBe(false);
|
|
219
|
-
await vi.runAllTimersAsync();
|
|
220
|
-
expect(processed).toEqual([]);
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
describe('DataModule notifyQuerySynced', () => {
|
|
225
|
-
const hash = 'h1';
|
|
226
|
-
|
|
227
|
-
function makeDmWithLocal(rows: any[]): DataModule<any> {
|
|
228
|
-
const local: any = { query: async () => [rows] };
|
|
229
|
-
return new DataModule({} as any, local, { tables: [] } as any, makeLogger(), 100);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
it('notifies once per registration lifetime even when records are unchanged and updateCount > 0', async () => {
|
|
233
|
-
const dm = makeDmWithLocal([]);
|
|
234
|
-
const state = makeQueryState(hash);
|
|
235
|
-
state.updateCount = 7; // persisted from a previous registration
|
|
236
|
-
(dm as any).activeQueries.set(hash, state);
|
|
237
|
-
|
|
238
|
-
let notified = 0;
|
|
239
|
-
dm.subscribe(hash, () => {
|
|
240
|
-
notified++;
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
await dm.notifyQuerySynced(hash); // empty result, unchanged — must still emit
|
|
244
|
-
expect(notified).toBe(1);
|
|
245
|
-
|
|
246
|
-
await dm.notifyQuerySynced(hash); // already notified this lifetime → silent
|
|
247
|
-
expect(notified).toBe(1);
|
|
248
|
-
});
|
|
249
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { parseUpdateOptions } from './index';
|
|
3
|
-
|
|
4
|
-
describe('parseUpdateOptions', () => {
|
|
5
|
-
it('returns empty options when no debounce', () => {
|
|
6
|
-
const result = parseUpdateOptions('user:1', { name: 'Alice' });
|
|
7
|
-
expect(result).toEqual({});
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('returns empty options when options is undefined', () => {
|
|
11
|
-
const result = parseUpdateOptions('user:1', { name: 'Alice' }, undefined);
|
|
12
|
-
expect(result).toEqual({});
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('returns empty options when debounced is false', () => {
|
|
16
|
-
const result = parseUpdateOptions('user:1', { name: 'Alice' }, { debounced: false });
|
|
17
|
-
expect(result).toEqual({});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('debounced: true uses default delay (200) and key = id', () => {
|
|
21
|
-
const result = parseUpdateOptions('user:1', { name: 'Alice' }, { debounced: true });
|
|
22
|
-
expect(result).toEqual({
|
|
23
|
-
debounced: {
|
|
24
|
-
delay: 200,
|
|
25
|
-
key: 'user:1',
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('supports custom delay', () => {
|
|
31
|
-
const result = parseUpdateOptions('user:1', { name: 'Alice' }, {
|
|
32
|
-
debounced: { delay: 500 },
|
|
33
|
-
});
|
|
34
|
-
expect(result.debounced?.delay).toBe(500);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('supports custom key type recordId', () => {
|
|
38
|
-
const result = parseUpdateOptions('user:1', { name: 'Alice', age: 30 }, {
|
|
39
|
-
debounced: { key: 'recordId' },
|
|
40
|
-
});
|
|
41
|
-
expect(result.debounced?.key).toBe('user:1');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('key: recordId_x_fields generates composite key from id + sorted field names', () => {
|
|
45
|
-
const result = parseUpdateOptions(
|
|
46
|
-
'user:1',
|
|
47
|
-
{ name: 'Alice', age: 30, email: 'a@b.com' },
|
|
48
|
-
{ debounced: { key: 'recordId_x_fields' } }
|
|
49
|
-
);
|
|
50
|
-
expect(result.debounced?.key).toBe('user:1::age#email#name');
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('uses defaults when debounced is object with no key or delay', () => {
|
|
54
|
-
const result = parseUpdateOptions('user:1', { name: 'Alice' }, { debounced: {} });
|
|
55
|
-
expect(result.debounced?.delay).toBe(200);
|
|
56
|
-
expect(result.debounced?.key).toBe('user:1');
|
|
57
|
-
});
|
|
58
|
-
});
|