@spooky-sync/core 0.0.1-canary.15 → 0.0.1-canary.151
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 +56 -0
- package/dist/index.d.ts +1192 -372
- package/dist/index.js +5772 -1270
- package/dist/otel/index.d.ts +21 -0
- package/dist/otel/index.js +86 -0
- package/dist/sqlite-plan-sql.js +194 -0
- package/dist/sqlite-worker.d.ts +1 -0
- package/dist/sqlite-worker.js +202 -0
- package/dist/types.d.ts +755 -0
- package/package.json +40 -8
- package/skills/sp00ky-core/SKILL.md +258 -0
- package/skills/sp00ky-core/references/auth.md +98 -0
- package/skills/sp00ky-core/references/config.md +76 -0
- package/src/build-globals.d.ts +12 -0
- package/src/events/events.test.ts +2 -1
- package/src/events/index.ts +3 -0
- package/src/index.ts +16 -2
- package/src/modules/app-release/index.test.ts +125 -0
- package/src/modules/app-release/index.ts +201 -0
- package/src/modules/auth/events/index.ts +2 -1
- package/src/modules/auth/index.ts +59 -20
- package/src/modules/cache/index.ts +77 -32
- package/src/modules/cache/types.ts +2 -2
- package/src/modules/crdt/crdt-field.ts +294 -0
- package/src/modules/crdt/crdt-hydration.test.ts +206 -0
- package/src/modules/crdt/index.ts +361 -0
- package/src/modules/crdt/loro-loader.ts +25 -0
- package/src/modules/data/data.hydration.test.ts +142 -0
- package/src/modules/data/data.rebind.test.ts +147 -0
- package/src/modules/data/data.run.test.ts +113 -0
- package/src/modules/data/data.status.test.ts +249 -0
- package/src/modules/data/index.ts +1134 -128
- package/src/modules/data/window-query.test.ts +52 -0
- package/src/modules/data/window-query.ts +154 -0
- package/src/modules/devtools/index.ts +191 -30
- package/src/modules/devtools/versions.test.ts +74 -0
- package/src/modules/devtools/versions.ts +81 -0
- package/src/modules/feature-flag/index.test.ts +120 -0
- package/src/modules/feature-flag/index.ts +209 -0
- package/src/modules/ref-tables.test.ts +91 -0
- package/src/modules/ref-tables.ts +88 -0
- package/src/modules/sync/engine.ts +101 -37
- package/src/modules/sync/events/index.ts +9 -2
- package/src/modules/sync/queue/queue-down.ts +12 -5
- package/src/modules/sync/queue/queue-up.ts +29 -14
- package/src/modules/sync/scheduler.pause.test.ts +109 -0
- package/src/modules/sync/scheduler.ts +73 -7
- package/src/modules/sync/sync.health.test.ts +149 -0
- package/src/modules/sync/sync.subquery.test.ts +82 -0
- package/src/modules/sync/sync.ts +1017 -62
- package/src/modules/sync/utils.test.ts +269 -2
- package/src/modules/sync/utils.ts +182 -17
- package/src/otel/index.ts +127 -0
- package/src/services/database/cache-engine.ts +143 -0
- package/src/services/database/database.ts +11 -11
- package/src/services/database/engine-factory.ts +32 -0
- package/src/services/database/events/index.ts +2 -1
- package/src/services/database/index.ts +6 -0
- package/src/services/database/local-migrator.ts +28 -27
- package/src/services/database/local.test.ts +64 -0
- package/src/services/database/local.ts +478 -67
- 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 +413 -0
- package/src/services/database/relation-resolver.ts +0 -0
- package/src/services/database/remote.ts +13 -13
- package/src/services/database/sqlite-cache-engine.test.ts +215 -0
- package/src/services/database/sqlite-cache-engine.ts +829 -0
- package/src/services/database/sqlite-plan-sql.test.ts +104 -0
- package/src/services/database/sqlite-plan-sql.ts +106 -0
- package/src/services/database/sqlite-select.integration.test.ts +185 -0
- package/src/services/database/sqlite-select.test.ts +279 -0
- package/src/services/database/sqlite-select.ts +113 -0
- package/src/services/database/sqlite-worker.ts +160 -0
- package/src/services/database/surql-translate.ts +291 -0
- package/src/services/database/surreal-cache-engine.ts +139 -0
- package/src/services/logger/index.ts +6 -101
- package/src/services/persistence/localstorage.ts +2 -2
- package/src/services/persistence/resilient.ts +11 -4
- package/src/services/persistence/surrealdb.ts +10 -10
- package/src/services/stream-processor/index.ts +295 -38
- 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 +136 -0
- package/src/services/stream-processor/stream-processor.reset.test.ts +104 -0
- package/src/services/stream-processor/stream-processor.test.ts +1 -1
- package/src/services/stream-processor/wasm-types.ts +18 -2
- package/src/sp00ky.auth-order.test.ts +92 -0
- package/src/sp00ky.init-query.test.ts +183 -0
- package/src/sp00ky.ts +1000 -0
- package/src/types.ts +267 -15
- package/src/utils/error-classification.test.ts +44 -0
- package/src/utils/error-classification.ts +7 -0
- package/src/utils/index.ts +35 -13
- package/src/utils/parser.ts +3 -2
- package/src/utils/semver.test.ts +32 -0
- package/src/utils/semver.ts +30 -0
- package/src/utils/surql.ts +24 -15
- package/src/utils/withRetry.test.ts +1 -1
- package/tsdown.config.ts +77 -1
- package/src/spooky.ts +0 -395
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { DataModule } from './index';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Tests for `DataModule.run`, the one-shot outbox API.
|
|
6
|
+
*
|
|
7
|
+
* Recurring jobs used to live here too (`runRecurring` / `pokeRecurring` /
|
|
8
|
+
* `cancelRecurring`, which wrote a single durable row the runner re-armed
|
|
9
|
+
* forever). They are gone: schedules are now declared server-side under
|
|
10
|
+
* `schedules:` in sp00ky.yml, and the scheduler creates a fresh job row per
|
|
11
|
+
* cycle — so every row this API writes is exactly one execution.
|
|
12
|
+
*
|
|
13
|
+
* The create/update pipeline is spied, so these assert the orchestration
|
|
14
|
+
* (table resolution, argument validation, field building) without a real engine.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
function makeLogger(): any {
|
|
18
|
+
const noop = () => {};
|
|
19
|
+
const logger: any = { debug: noop, info: noop, warn: noop, error: noop, trace: noop };
|
|
20
|
+
logger.child = () => logger;
|
|
21
|
+
return logger;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const schema = {
|
|
25
|
+
tables: [{ name: 'job', columns: {} }],
|
|
26
|
+
backends: {
|
|
27
|
+
gamesync: {
|
|
28
|
+
outboxTable: 'job',
|
|
29
|
+
routes: {
|
|
30
|
+
'/syncGames': {
|
|
31
|
+
args: { connection: { optional: false }, since: { optional: true } },
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
noOutbox: {
|
|
36
|
+
routes: { '/whatever': { args: {} } },
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const CONN = 'connection:CONN_abc';
|
|
42
|
+
|
|
43
|
+
function makeDm() {
|
|
44
|
+
const local = { query: vi.fn().mockResolvedValue([]) };
|
|
45
|
+
const dm = new DataModule({} as any, local as any, schema as any, makeLogger(), 100);
|
|
46
|
+
const create = vi.spyOn(dm, 'create').mockResolvedValue(undefined as any);
|
|
47
|
+
return { dm, local, create };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe('DataModule.run', () => {
|
|
51
|
+
it('creates the one-shot job with status pending so the optimistic row reads in-flight', async () => {
|
|
52
|
+
const { dm, create } = makeDm();
|
|
53
|
+
await dm.run('gamesync' as any, '/syncGames' as any, { connection: CONN } as any, {
|
|
54
|
+
assignedTo: CONN,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
expect(create).toHaveBeenCalledTimes(1);
|
|
58
|
+
const [id, record] = create.mock.calls[0] as [string, any];
|
|
59
|
+
expect(id.startsWith('job:')).toBe(true);
|
|
60
|
+
// The schema's DEFAULT ALWAYS "pending" only runs server-side; without the
|
|
61
|
+
// explicit field the local optimistic row has status undefined and
|
|
62
|
+
// in-flight indicators miss it until the first server echo.
|
|
63
|
+
expect(record.status).toBe('pending');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('gives each call its own row', async () => {
|
|
67
|
+
const { dm, create } = makeDm();
|
|
68
|
+
await dm.run('gamesync' as any, '/syncGames' as any, { connection: CONN } as any);
|
|
69
|
+
await dm.run('gamesync' as any, '/syncGames' as any, { connection: CONN } as any);
|
|
70
|
+
|
|
71
|
+
const [firstId] = create.mock.calls[0] as [string, any];
|
|
72
|
+
const [secondId] = create.mock.calls[1] as [string, any];
|
|
73
|
+
expect(firstId).not.toBe(secondId);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('carries the retry, timeout and delay options onto the row', async () => {
|
|
77
|
+
const { dm, create } = makeDm();
|
|
78
|
+
await dm.run('gamesync' as any, '/syncGames' as any, { connection: CONN } as any, {
|
|
79
|
+
assignedTo: CONN,
|
|
80
|
+
max_retries: 5,
|
|
81
|
+
retry_strategy: 'exponential',
|
|
82
|
+
timeout: 30,
|
|
83
|
+
delay: 60_000,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const [, record] = create.mock.calls[0] as [string, any];
|
|
87
|
+
expect(record.max_retries).toBe(5);
|
|
88
|
+
expect(record.retry_strategy).toBe('exponential');
|
|
89
|
+
expect(record.timeout).toBe(30);
|
|
90
|
+
expect(record.delay).toBe(60_000);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('serializes the payload and rejects a missing required argument', async () => {
|
|
94
|
+
const { dm, create } = makeDm();
|
|
95
|
+
await dm.run('gamesync' as any, '/syncGames' as any, { connection: CONN } as any);
|
|
96
|
+
const [, record] = create.mock.calls[0] as [string, any];
|
|
97
|
+
expect(JSON.parse(record.payload)).toEqual({ connection: CONN });
|
|
98
|
+
|
|
99
|
+
await expect(
|
|
100
|
+
dm.run('gamesync' as any, '/syncGames' as any, {} as any)
|
|
101
|
+
).rejects.toThrow(/connection/);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('rejects an unknown route and a backend with no outbox table', async () => {
|
|
105
|
+
const { dm } = makeDm();
|
|
106
|
+
await expect(
|
|
107
|
+
dm.run('gamesync' as any, '/nope' as any, {} as any)
|
|
108
|
+
).rejects.toThrow(/not found/);
|
|
109
|
+
await expect(
|
|
110
|
+
dm.run('noOutbox' as any, '/whatever' as any, {} as any)
|
|
111
|
+
).rejects.toThrow(/Outbox table/);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -0,0 +1,249 @@
|
|
|
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
|
+
});
|