@jsb188/graphql 1.1.11 → 1.1.12
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/audience.d.ts +343 -0
- package/cache/config.ts +58 -24
- package/cache/index.chat-activity.test.ts +119 -0
- package/cache/index.chat.test.ts +92 -0
- package/cache/index.helpers.ts +96 -0
- package/cache/index.regression.test.ts +149 -0
- package/cache/index.test.ts +370 -42
- package/cache/index.ts +326 -799
- package/cache/optimistic-ui-runtime.ts +46 -0
- package/cache/optimistic-ui.ts +401 -0
- package/cache/persist.ts +98 -19
- package/cache/store.ts +22 -64
- package/cache/value.helpers.ts +17 -0
- package/{drafts/store.ts → client/draft-persistence-indexed-db.ts} +19 -3
- package/{drafts/index.ts → client/draft-persistence.ts} +5 -2
- package/client/index.ts +3 -2
- package/client/request.helpers.ts +14 -0
- package/client/request.ts +130 -215
- package/deno.lock +17 -0
- package/deno.test.json +2 -0
- package/gql/fragments/agentMemoryFragments.ts +5 -1
- package/gql/fragments/agentNoteFragments.ts +150 -0
- package/gql/fragments/aiChatFragments.ts +36 -10
- package/gql/fragments/audienceFragments.ts +141 -0
- package/gql/fragments/campaignFragments.ts +415 -126
- package/gql/fragments/dataTableFragments.ts +48 -80
- package/gql/fragments/emailFragments.ts +28 -23
- package/gql/fragments/fieldDocFragments.ts +222 -40
- package/gql/fragments/inboundContactFragments.ts +2 -0
- package/gql/fragments/logFragments.ts +93 -2
- package/gql/fragments/organizationFragments.ts +10 -0
- package/gql/fragments/qrCodeFragments.ts +29 -0
- package/gql/fragments/scheduleFragments.ts +652 -140
- package/gql/fragments/sheetFragments.ts +84 -373
- package/gql/fragments/storageFragments.ts +25 -1
- package/gql/fragments/workflowFragments.ts +13 -1
- package/gql/mutations/agentMemoryMutations.ts +32 -0
- package/gql/mutations/agentNoteMutations.ts +62 -0
- package/gql/mutations/aiChatMutations.ts +36 -4
- package/gql/mutations/audienceMutations.ts +71 -0
- package/gql/mutations/authMutations.ts +45 -1
- package/gql/mutations/billingMutations.ts +24 -0
- package/gql/mutations/campaignMutations.ts +170 -127
- package/gql/mutations/contactMutations.ts +23 -0
- package/gql/mutations/dataTableMutations.ts +18 -75
- package/gql/mutations/fieldDocMutations.ts +162 -13
- package/gql/mutations/index.ts +8 -5
- package/gql/mutations/organizationMutations.ts +6 -0
- package/gql/mutations/qrCodeMutations.ts +20 -0
- package/gql/mutations/scheduleMutations.ts +1052 -354
- package/gql/mutations/sheetMutations.ts +62 -118
- package/gql/mutations/storageMutations.ts +0 -1
- package/gql/mutations/workflowMutations.ts +18 -0
- package/gql/queries/agentMemoryQueries.ts +6 -0
- package/gql/queries/agentNoteQueries.ts +89 -0
- package/gql/queries/aiChatQueries.ts +56 -4
- package/gql/queries/audienceQueries.ts +128 -0
- package/gql/queries/authQueries.ts +6 -0
- package/gql/queries/billingQueries.ts +95 -6
- package/gql/queries/campaignQueries.ts +132 -23
- package/gql/queries/dataTableQueries.ts +24 -65
- package/gql/queries/emailQueries.ts +18 -61
- package/gql/queries/emailReplyReportQueries.ts +76 -0
- package/gql/queries/fieldDocQueries.ts +100 -92
- package/gql/queries/inboundContactQueries.ts +4 -0
- package/gql/queries/index.ts +3 -1
- package/gql/queries/logQueries.ts +62 -7
- package/gql/queries/organizationQueries.ts +13 -0
- package/gql/queries/qrCodeQueries.ts +20 -0
- package/gql/queries/scheduleQueries.ts +633 -257
- package/gql/queries/sheetQueries.ts +59 -152
- package/gql/queries/workflowQueries.ts +10 -4
- package/hooks/index.helpers.test.ts +50 -0
- package/hooks/index.helpers.ts +52 -0
- package/hooks/index.ts +863 -685
- package/hooks/use-agentMemory-mtn.ts +29 -31
- package/hooks/use-agentMemory-qry.ts +15 -3
- package/hooks/use-agentNote-mtn.ts +82 -0
- package/hooks/use-agentNote-qry.ts +190 -0
- package/hooks/use-agentNote-recovery.helpers.test.ts +68 -0
- package/hooks/use-agentNote-recovery.helpers.ts +58 -0
- package/hooks/use-agentNote-recovery.ts +72 -0
- package/hooks/use-aiChat-mtn.ts +96 -112
- package/hooks/use-aiChat-qry.helpers.test.ts +63 -0
- package/hooks/use-aiChat-qry.helpers.ts +124 -0
- package/hooks/use-aiChat-qry.ts +229 -383
- package/hooks/use-aiChat-stream-mtn.ts +14 -0
- package/hooks/use-audience-mtn.ts +194 -0
- package/hooks/use-audience-qry.helpers.test.ts +80 -0
- package/hooks/use-audience-qry.helpers.ts +63 -0
- package/hooks/use-audience-qry.ts +330 -0
- package/hooks/use-auth-mtn.ts +30 -1
- package/hooks/use-billing-mtn.ts +31 -0
- package/hooks/use-billing-qry.ts +76 -0
- package/hooks/use-campaign-generation-recovery.ts +53 -0
- package/hooks/use-campaign-mtn.ts +224 -165
- package/hooks/use-campaign-qry.helpers.ts +40 -0
- package/hooks/use-campaign-qry.ts +631 -54
- package/hooks/use-dataTable-mtn.ts +23 -115
- package/hooks/use-dataTable-qry.ts +66 -916
- package/hooks/use-email-qry.helpers.ts +37 -0
- package/hooks/use-email-qry.ts +33 -178
- package/hooks/use-emailCampaignReplyReport-qry.ts +27 -0
- package/hooks/use-fieldDoc-mtn.ts +244 -32
- package/hooks/use-fieldDoc-qry.helpers.test.ts +65 -0
- package/hooks/use-fieldDoc-qry.helpers.ts +49 -0
- package/hooks/use-fieldDoc-qry.ts +134 -102
- package/hooks/use-inboundContact-qry.ts +7 -9
- package/hooks/use-log-mtn.ts +25 -12
- package/hooks/use-log-qry.ts +99 -46
- package/hooks/use-organization-qry.ts +16 -60
- package/hooks/use-publicFormEmail-mtn.ts +27 -0
- package/hooks/use-qrCode-mtn.ts +40 -0
- package/hooks/use-qrCode-qry.ts +78 -0
- package/hooks/use-schedule-mtn.ts +506 -333
- package/hooks/use-schedule-qry.ts +682 -101
- package/hooks/use-schedule-reactive.ts +486 -0
- package/hooks/use-sheet-mtn.ts +91 -199
- package/hooks/use-sheet-qry.ts +84 -238
- package/hooks/use-storage-qry.ts +84 -61
- package/hooks/use-workflow-mtn.ts +39 -22
- package/hooks/use-workflow-qry.ts +40 -61
- package/libs/ai-chat-outgoing.helpers.ts +153 -0
- package/libs/ai-chat-outgoing.ts +11 -0
- package/libs/ai-chat-outgoing.types.ts +25 -0
- package/libs/ai-chat-run-realtime.ts +20 -0
- package/libs/ai-chat-submission-realtime.ts +150 -0
- package/libs/fragment-realtime-sequence.ts +55 -0
- package/libs/fragment-recovery.test.ts +326 -0
- package/libs/fragment-recovery.ts +325 -0
- package/libs/open-sheet.ts +138 -0
- package/libs/orchestrator-realtime.helpers.test.ts +229 -0
- package/libs/orchestrator-realtime.helpers.ts +317 -0
- package/libs/orchestrator-realtime.ts +433 -0
- package/libs/request-cache-regression.test.ts +122 -0
- package/{client → libs}/request-managed-session.test.ts +1 -1
- package/libs/request-no-store.test.ts +419 -0
- package/libs/sheet-command-batch.ts +44 -0
- package/libs/sheet-view-realtime-router.test.ts +214 -0
- package/libs/sheet-view-realtime-router.ts +99 -0
- package/loaders/campaign.test.ts +186 -0
- package/loaders/campaign.ts +56 -83
- package/loaders/emailPreference.ts +75 -0
- package/loaders/rest.ts +12 -0
- package/package.json +42 -17
- package/schedule.d.ts +1790 -0
- package/sse.helpers.ts +19 -0
- package/sse.ts +26 -115
- package/tests/agent-note-detail-cache.test.ts +120 -0
- package/tests/agent-note-search.test.ts +444 -0
- package/types.d.ts +46 -25
- package/client/data-table-realtime-subscriptions.test.ts +0 -740
- package/client/data-table-realtime-subscriptions.ts +0 -955
- package/client/data-table-realtime.test.ts +0 -792
- package/client/data-table-realtime.ts +0 -1218
- package/client/fragment-realtime-sequence.ts +0 -52
- package/client/open-sheet.ts +0 -137
- package/client/request-no-store.test.ts +0 -157
- package/gql/fragments/agentDocFragments.ts +0 -46
- package/gql/fragments/billingFragments.ts +0 -14
- package/gql/mutations/agentDocMutations.ts +0 -177
- package/gql/queries/agentDocQueries.ts +0 -120
- package/hooks/use-agentDoc-mtn.ts +0 -285
- package/hooks/use-agentDoc-qry.ts +0 -208
- /package/{client → libs}/sse-ticket.test.ts +0 -0
|
@@ -1,792 +0,0 @@
|
|
|
1
|
-
import type { WSDataUpdateObj } from '@jsb188/app/types/app.d.ts';
|
|
2
|
-
import {
|
|
3
|
-
DataTableRealtimeSequenceGate,
|
|
4
|
-
dataTableRealtimeAuthorityRegistry,
|
|
5
|
-
getDataTableRealtimeApplyFailureRecovery,
|
|
6
|
-
getDataTableRealtimeRequiredSnapshotRecovery,
|
|
7
|
-
resolveDataTableRealtimeTail,
|
|
8
|
-
} from './data-table-realtime.ts';
|
|
9
|
-
|
|
10
|
-
/*
|
|
11
|
-
* Throw one readable test failure when a condition is false.
|
|
12
|
-
*/
|
|
13
|
-
function expect(value: unknown, message: string) {
|
|
14
|
-
if (!value) {
|
|
15
|
-
throw new Error(message);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/*
|
|
20
|
-
* Build one sequence-bearing websocket fixture.
|
|
21
|
-
*/
|
|
22
|
-
function createUpdate(
|
|
23
|
-
params: {
|
|
24
|
-
batchId?: string;
|
|
25
|
-
chunkCount?: number;
|
|
26
|
-
chunkIndex?: number;
|
|
27
|
-
fromSeq?: string;
|
|
28
|
-
toSeq?: string;
|
|
29
|
-
} = {},
|
|
30
|
-
): WSDataUpdateObj {
|
|
31
|
-
return {
|
|
32
|
-
id: 'event-1',
|
|
33
|
-
route: [],
|
|
34
|
-
messageType: 'NORMAL',
|
|
35
|
-
dataTableChange: {
|
|
36
|
-
batchId: params.batchId || 'batch-1',
|
|
37
|
-
organizationId: 'org-1',
|
|
38
|
-
dataTableId: 'table-1',
|
|
39
|
-
fromSeq: params.fromSeq || '1',
|
|
40
|
-
toSeq: params.toSeq || params.fromSeq || '1',
|
|
41
|
-
chunkIndex: params.chunkIndex || 0,
|
|
42
|
-
chunkCount: params.chunkCount || 1,
|
|
43
|
-
},
|
|
44
|
-
fragments: [
|
|
45
|
-
{
|
|
46
|
-
name: '$dataTableFragment',
|
|
47
|
-
dataId: 'table-1',
|
|
48
|
-
data: { chunkIndex: params.chunkIndex || 0 },
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/*
|
|
55
|
-
* Build one valid RECORDS tail entry.
|
|
56
|
-
*/
|
|
57
|
-
function createTailChange(seq: string, changes: unknown[] = []) {
|
|
58
|
-
return {
|
|
59
|
-
dataTableId: 'table-1',
|
|
60
|
-
seq,
|
|
61
|
-
kind: 'RECORDS',
|
|
62
|
-
payload: {
|
|
63
|
-
v: 2,
|
|
64
|
-
requestFingerprint: 'a'.repeat(64),
|
|
65
|
-
changes,
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/*
|
|
71
|
-
* Build one exact RECORDS journal coordinate with matching row snapshots.
|
|
72
|
-
*/
|
|
73
|
-
function createRecordJournalChange() {
|
|
74
|
-
return {
|
|
75
|
-
cellKey: 'status',
|
|
76
|
-
columnId: '17',
|
|
77
|
-
dataTableRowId: '23',
|
|
78
|
-
previous: {
|
|
79
|
-
cellKey: 'status',
|
|
80
|
-
columnId: '17',
|
|
81
|
-
dataTableRowId: '23',
|
|
82
|
-
id: '31',
|
|
83
|
-
},
|
|
84
|
-
current: {
|
|
85
|
-
cellKey: 'status',
|
|
86
|
-
columnId: '17',
|
|
87
|
-
dataTableRowId: '23',
|
|
88
|
-
id: '32',
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
Deno.test('DataTable realtime gate never applies a partial or unordered chunk batch', () => {
|
|
94
|
-
const gate = new DataTableRealtimeSequenceGate();
|
|
95
|
-
gate.registerTable('org-1', 'table-1');
|
|
96
|
-
gate.acknowledgeSnapshot('org-1', 'table-1', '0');
|
|
97
|
-
const second = gate.consume(createUpdate({ chunkCount: 2, chunkIndex: 1 }));
|
|
98
|
-
const first = gate.consume(createUpdate({ chunkCount: 2, chunkIndex: 0 }));
|
|
99
|
-
|
|
100
|
-
expect(second.type === 'WAIT', 'An incomplete batch must remain buffered');
|
|
101
|
-
expect(
|
|
102
|
-
first.type === 'APPLY' &&
|
|
103
|
-
first.updates.length === 2 &&
|
|
104
|
-
first.updates[0].dataTableChange?.chunkIndex === 0 &&
|
|
105
|
-
first.updates[1].dataTableChange?.chunkIndex === 1,
|
|
106
|
-
'A completed batch must apply once in chunk order',
|
|
107
|
-
);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
Deno.test('DataTable realtime gate reassembles chunks before a rows page registers', () => {
|
|
111
|
-
const gate = new DataTableRealtimeSequenceGate();
|
|
112
|
-
const second = gate.consume(
|
|
113
|
-
createUpdate({ chunkCount: 2, chunkIndex: 1, fromSeq: '7' }),
|
|
114
|
-
);
|
|
115
|
-
const first = gate.consume(
|
|
116
|
-
createUpdate({ chunkCount: 2, chunkIndex: 0, fromSeq: '7' }),
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
expect(
|
|
120
|
-
second.type === 'WAIT',
|
|
121
|
-
'An inactive table must not apply a partial fragment or authority batch',
|
|
122
|
-
);
|
|
123
|
-
expect(
|
|
124
|
-
first.type === 'APPLY' &&
|
|
125
|
-
first.updates.length === 2 &&
|
|
126
|
-
first.updates[0].dataTableChange?.chunkIndex === 0 &&
|
|
127
|
-
first.updates[1].dataTableChange?.chunkIndex === 1,
|
|
128
|
-
'Metadata-only subscribers must receive every chunk in declared order',
|
|
129
|
-
);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
Deno.test('DataTable realtime gate preserves older disjoint inactive batches', () => {
|
|
133
|
-
const gate = new DataTableRealtimeSequenceGate();
|
|
134
|
-
const newer = gate.consume(createUpdate({ batchId: 'newer', fromSeq: '9' }));
|
|
135
|
-
const olderSecond = gate.consume(
|
|
136
|
-
createUpdate({
|
|
137
|
-
batchId: 'older',
|
|
138
|
-
chunkCount: 2,
|
|
139
|
-
chunkIndex: 1,
|
|
140
|
-
fromSeq: '8',
|
|
141
|
-
}),
|
|
142
|
-
);
|
|
143
|
-
const olderFirst = gate.consume(
|
|
144
|
-
createUpdate({
|
|
145
|
-
batchId: 'older',
|
|
146
|
-
chunkCount: 2,
|
|
147
|
-
chunkIndex: 0,
|
|
148
|
-
fromSeq: '8',
|
|
149
|
-
}),
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
expect(newer.type === 'APPLY', 'The newer inactive batch must apply');
|
|
153
|
-
expect(olderSecond.type === 'WAIT', 'The older partial batch must wait');
|
|
154
|
-
expect(
|
|
155
|
-
olderFirst.type === 'APPLY' && olderFirst.updates.length === 2,
|
|
156
|
-
'An older complete inactive batch can contain disjoint targets and must not be dropped',
|
|
157
|
-
);
|
|
158
|
-
expect(
|
|
159
|
-
!gate.canApplySnapshot('org-1', 'table-1', '8') &&
|
|
160
|
-
gate.canApplySnapshot('org-1', 'table-1', '9'),
|
|
161
|
-
'Out-of-order inactive delivery must retain the furthest observed watermark',
|
|
162
|
-
);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
Deno.test('DataTable snapshot markers wait for an authoritative watermark after ordered authority applies', () => {
|
|
166
|
-
const gate = new DataTableRealtimeSequenceGate();
|
|
167
|
-
gate.registerTable('org-1', 'table-1');
|
|
168
|
-
gate.acknowledgeSnapshot('org-1', 'table-1', '0');
|
|
169
|
-
const update = createUpdate();
|
|
170
|
-
update.dataTableSnapshotRequired = true;
|
|
171
|
-
update.dataTableWriteOrders = [
|
|
172
|
-
{
|
|
173
|
-
cellKey: 'status',
|
|
174
|
-
dataTableRowId: 'row-1',
|
|
175
|
-
kind: 'CELL',
|
|
176
|
-
serverSeq: '9',
|
|
177
|
-
tombstone: false,
|
|
178
|
-
},
|
|
179
|
-
];
|
|
180
|
-
const applied = gate.consume(update);
|
|
181
|
-
if (applied.type === 'APPLY') {
|
|
182
|
-
applied.updates.forEach((chunk) => {
|
|
183
|
-
gate.filterSequencedUpdate(
|
|
184
|
-
chunk,
|
|
185
|
-
applied.toSeq,
|
|
186
|
-
applied.organizationId,
|
|
187
|
-
applied.dataTableId,
|
|
188
|
-
);
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
const recovery = getDataTableRealtimeRequiredSnapshotRecovery(applied);
|
|
192
|
-
const authority = dataTableRealtimeAuthorityRegistry
|
|
193
|
-
.getSnapshot('org-1', 'table-1')
|
|
194
|
-
.orders.values()
|
|
195
|
-
.next().value;
|
|
196
|
-
|
|
197
|
-
expect(
|
|
198
|
-
recovery?.type === 'RECOVER' &&
|
|
199
|
-
recovery.reason === 'SNAPSHOT_REQUIRED' &&
|
|
200
|
-
recovery.observedToSeq === '1',
|
|
201
|
-
'A snapshot marker must enter the awaited watermark recovery path',
|
|
202
|
-
);
|
|
203
|
-
expect(
|
|
204
|
-
authority?.serverSeq === '9',
|
|
205
|
-
'Representable target authority must apply before the snapshot handoff',
|
|
206
|
-
);
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
Deno.test('DataTable failed durable application immediately requests fenced snapshot recovery', () => {
|
|
210
|
-
const recovery = getDataTableRealtimeApplyFailureRecovery({
|
|
211
|
-
dataTableId: 'table-1',
|
|
212
|
-
organizationId: 'org-1',
|
|
213
|
-
toSeq: '9007199254740993',
|
|
214
|
-
type: 'APPLY',
|
|
215
|
-
updates: [createUpdate()],
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
expect(
|
|
219
|
-
recovery.type === 'RECOVER' &&
|
|
220
|
-
recovery.dataTableId === 'table-1' &&
|
|
221
|
-
recovery.organizationId === 'org-1' &&
|
|
222
|
-
recovery.lastSeq === '9007199254740993' &&
|
|
223
|
-
recovery.observedToSeq === '9007199254740993' &&
|
|
224
|
-
recovery.reason === 'SNAPSHOT_REQUIRED',
|
|
225
|
-
'A failed accepted batch must recover at or beyond its exact durable watermark',
|
|
226
|
-
);
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
Deno.test('DataTable realtime gate recovers a final incomplete chunk batch after its deadline', () => {
|
|
230
|
-
const gate = new DataTableRealtimeSequenceGate();
|
|
231
|
-
gate.registerTable('org-1', 'table-1');
|
|
232
|
-
gate.acknowledgeSnapshot('org-1', 'table-1', '0');
|
|
233
|
-
const bufferedAt = Date.now();
|
|
234
|
-
const partial = gate.consume(createUpdate({ chunkCount: 2, chunkIndex: 0 }));
|
|
235
|
-
const recoveries = gate.takeExpiredRecoveries(bufferedAt + 6000, 5000);
|
|
236
|
-
|
|
237
|
-
expect(partial.type === 'WAIT', 'The first partial chunk must wait');
|
|
238
|
-
expect(
|
|
239
|
-
recoveries.length === 1 &&
|
|
240
|
-
recoveries[0].type === 'RECOVER' &&
|
|
241
|
-
recoveries[0].reason === 'CHUNK_TIMEOUT',
|
|
242
|
-
'An expired partial batch must request authoritative recovery',
|
|
243
|
-
);
|
|
244
|
-
expect(
|
|
245
|
-
gate.takeExpiredRecoveries(bufferedAt + 7000, 5000).length === 0,
|
|
246
|
-
'The expired batch must be drained exactly once',
|
|
247
|
-
);
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
Deno.test('DataTable realtime gate exposes only the earliest incomplete batch deadline', () => {
|
|
251
|
-
const gate = new DataTableRealtimeSequenceGate();
|
|
252
|
-
gate.registerTable('org-1', 'table-1');
|
|
253
|
-
gate.acknowledgeSnapshot('org-1', 'table-1', '0');
|
|
254
|
-
const startedAtLowerBound = Date.now();
|
|
255
|
-
const partial = gate.consume(createUpdate({ chunkCount: 2, chunkIndex: 0 }));
|
|
256
|
-
const startedAtUpperBound = Date.now();
|
|
257
|
-
const deadline = gate.getEarliestIncompleteBatchDeadline();
|
|
258
|
-
|
|
259
|
-
expect(partial.type === 'WAIT', 'The first chunk must remain incomplete');
|
|
260
|
-
expect(
|
|
261
|
-
typeof deadline === 'number' &&
|
|
262
|
-
deadline >= startedAtLowerBound + 5000 &&
|
|
263
|
-
deadline <= startedAtUpperBound + 5000,
|
|
264
|
-
'The scheduler must receive the exact absolute deadline for the oldest batch',
|
|
265
|
-
);
|
|
266
|
-
gate.consume(createUpdate({ chunkCount: 2, chunkIndex: 1 }));
|
|
267
|
-
expect(
|
|
268
|
-
gate.getEarliestIncompleteBatchDeadline() === null,
|
|
269
|
-
'Completing the final pending batch must disarm the one-shot scheduler',
|
|
270
|
-
);
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
Deno.test('DataTable transient disconnect drops only partial chunks', () => {
|
|
274
|
-
const gate = new DataTableRealtimeSequenceGate();
|
|
275
|
-
gate.registerTable('org-1', 'table-1');
|
|
276
|
-
gate.acknowledgeSnapshot('org-1', 'table-1', '4');
|
|
277
|
-
const applied = gate.consume(
|
|
278
|
-
createUpdate({ batchId: 'applied', fromSeq: '5' }),
|
|
279
|
-
);
|
|
280
|
-
gate.recordSnapshotFragments('org-1', 'table-1', {
|
|
281
|
-
currentSeq: '7',
|
|
282
|
-
dataTableId: 'table-1',
|
|
283
|
-
rows: [{ id: 'row-1', cells: [{ id: 'cell-1' }] }],
|
|
284
|
-
});
|
|
285
|
-
const partial = gate.consume(
|
|
286
|
-
createUpdate({
|
|
287
|
-
batchId: 'partial',
|
|
288
|
-
chunkCount: 2,
|
|
289
|
-
chunkIndex: 0,
|
|
290
|
-
fromSeq: '6',
|
|
291
|
-
}),
|
|
292
|
-
);
|
|
293
|
-
|
|
294
|
-
expect(applied.type === 'APPLY', 'The committed update must apply first');
|
|
295
|
-
expect(partial.type === 'WAIT', 'The next partial update must be buffered');
|
|
296
|
-
gate.discardIncompleteBatches();
|
|
297
|
-
expect(
|
|
298
|
-
gate.getLastSeq('org-1', 'table-1') === '5' &&
|
|
299
|
-
gate.getEarliestIncompleteBatchDeadline() === null,
|
|
300
|
-
'A transient disconnect must preserve the applied cursor and discard its partial batch',
|
|
301
|
-
);
|
|
302
|
-
|
|
303
|
-
const replacement = createUpdate({
|
|
304
|
-
batchId: 'replacement',
|
|
305
|
-
fromSeq: '6',
|
|
306
|
-
});
|
|
307
|
-
replacement.fragments = [
|
|
308
|
-
{
|
|
309
|
-
name: '$dataTableCellFragment',
|
|
310
|
-
dataId: 'cell-1',
|
|
311
|
-
data: { value: 'older-than-snapshot' },
|
|
312
|
-
},
|
|
313
|
-
];
|
|
314
|
-
const replacementResult = gate.consume(replacement);
|
|
315
|
-
const filtered =
|
|
316
|
-
replacementResult.type === 'APPLY'
|
|
317
|
-
? gate.filterSequencedUpdate(
|
|
318
|
-
replacementResult.updates[0],
|
|
319
|
-
replacementResult.toSeq,
|
|
320
|
-
'org-1',
|
|
321
|
-
'table-1',
|
|
322
|
-
)
|
|
323
|
-
: null;
|
|
324
|
-
expect(
|
|
325
|
-
replacementResult.type === 'APPLY' && filtered?.fragments?.length === 0,
|
|
326
|
-
'The next exact sequence must apply while the newer fragment fence survives reconnect',
|
|
327
|
-
);
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
Deno.test('DataTable UP_TO_DATE resume installs zero and preserves a newer local cursor', () => {
|
|
331
|
-
const gate = new DataTableRealtimeSequenceGate();
|
|
332
|
-
gate.registerTable('org-1', 'table-1');
|
|
333
|
-
expect(
|
|
334
|
-
gate.resumeFromAppliedCursor('org-1', 'table-1', '0') &&
|
|
335
|
-
gate.getLastSeq('org-1', 'table-1') === '0',
|
|
336
|
-
'An empty table ACK must install the canonical zero baseline',
|
|
337
|
-
);
|
|
338
|
-
expect(
|
|
339
|
-
!gate.resumeFromAppliedCursor('org-1', 'table-1', '00'),
|
|
340
|
-
'A noncanonical ACK cursor must fail closed',
|
|
341
|
-
);
|
|
342
|
-
const applied = gate.consume(
|
|
343
|
-
createUpdate({ batchId: 'live-before-ack', fromSeq: '1' }),
|
|
344
|
-
);
|
|
345
|
-
const partial = gate.consume(
|
|
346
|
-
createUpdate({
|
|
347
|
-
batchId: 'partial-before-ack',
|
|
348
|
-
chunkCount: 2,
|
|
349
|
-
chunkIndex: 0,
|
|
350
|
-
fromSeq: '2',
|
|
351
|
-
}),
|
|
352
|
-
);
|
|
353
|
-
expect(
|
|
354
|
-
applied.type === 'APPLY' && partial.type === 'WAIT',
|
|
355
|
-
'Live traffic may advance and buffer after the watch was sent',
|
|
356
|
-
);
|
|
357
|
-
expect(
|
|
358
|
-
gate.resumeFromAppliedCursor('org-1', 'table-1', '0') &&
|
|
359
|
-
gate.getLastSeq('org-1', 'table-1') === '1' &&
|
|
360
|
-
gate.getEarliestIncompleteBatchDeadline() === null,
|
|
361
|
-
'An older correlated ACK must clear partial chunks without moving applied state backward',
|
|
362
|
-
);
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
Deno.test('DataTable metadata-only subscriptions recover an expired partial batch', () => {
|
|
366
|
-
const gate = new DataTableRealtimeSequenceGate();
|
|
367
|
-
const bufferedAt = Date.now();
|
|
368
|
-
const partial = gate.consume(
|
|
369
|
-
createUpdate({ chunkCount: 2, chunkIndex: 0, fromSeq: '9' }),
|
|
370
|
-
);
|
|
371
|
-
const recoveries = gate.takeExpiredRecoveries(bufferedAt + 6000, 5000);
|
|
372
|
-
|
|
373
|
-
expect(partial.type === 'WAIT', 'The incomplete inactive batch must wait');
|
|
374
|
-
expect(
|
|
375
|
-
recoveries.length === 1 &&
|
|
376
|
-
recoveries[0].type === 'RECOVER' &&
|
|
377
|
-
recoveries[0].reason === 'CHUNK_TIMEOUT',
|
|
378
|
-
'A desired metadata-only subscription can use the common snapshot recovery path',
|
|
379
|
-
);
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
Deno.test('DataTable realtime recovery retains the furthest buffered watermark', () => {
|
|
383
|
-
const gate = new DataTableRealtimeSequenceGate();
|
|
384
|
-
gate.registerTable('org-1', 'table-1');
|
|
385
|
-
gate.acknowledgeSnapshot('org-1', 'table-1', '0');
|
|
386
|
-
const futurePartial = gate.consume(
|
|
387
|
-
createUpdate({
|
|
388
|
-
batchId: 'future-partial',
|
|
389
|
-
chunkCount: 2,
|
|
390
|
-
chunkIndex: 0,
|
|
391
|
-
fromSeq: '5',
|
|
392
|
-
}),
|
|
393
|
-
);
|
|
394
|
-
const earlierGap = gate.consume(
|
|
395
|
-
createUpdate({ batchId: 'earlier-gap', fromSeq: '2' }),
|
|
396
|
-
);
|
|
397
|
-
|
|
398
|
-
expect(
|
|
399
|
-
futurePartial.type === 'WAIT',
|
|
400
|
-
'The future batch must remain buffered',
|
|
401
|
-
);
|
|
402
|
-
expect(
|
|
403
|
-
earlierGap.type === 'RECOVER' &&
|
|
404
|
-
earlierGap.reason === 'GAP' &&
|
|
405
|
-
earlierGap.observedToSeq === '5',
|
|
406
|
-
'Clearing unsafe batches must recover through the furthest discarded journal coordinate',
|
|
407
|
-
);
|
|
408
|
-
});
|
|
409
|
-
|
|
410
|
-
Deno.test('DataTable inactive chunk timeout keeps a newer applied high-water', () => {
|
|
411
|
-
const gate = new DataTableRealtimeSequenceGate();
|
|
412
|
-
const bufferedAt = Date.now();
|
|
413
|
-
gate.consume(
|
|
414
|
-
createUpdate({
|
|
415
|
-
batchId: 'older-partial',
|
|
416
|
-
chunkCount: 2,
|
|
417
|
-
chunkIndex: 0,
|
|
418
|
-
fromSeq: '8',
|
|
419
|
-
}),
|
|
420
|
-
);
|
|
421
|
-
const newer = gate.consume(
|
|
422
|
-
createUpdate({ batchId: 'newer-complete', fromSeq: '9' }),
|
|
423
|
-
);
|
|
424
|
-
const recoveries = gate.takeExpiredRecoveries(bufferedAt + 6000, 5000);
|
|
425
|
-
|
|
426
|
-
expect(
|
|
427
|
-
newer.type === 'APPLY',
|
|
428
|
-
'The newer inactive batch must apply promptly',
|
|
429
|
-
);
|
|
430
|
-
expect(
|
|
431
|
-
recoveries.length === 1 &&
|
|
432
|
-
recoveries[0].type === 'RECOVER' &&
|
|
433
|
-
recoveries[0].observedToSeq === '9',
|
|
434
|
-
'An older partial batch must recover through the newer applied high-water',
|
|
435
|
-
);
|
|
436
|
-
});
|
|
437
|
-
|
|
438
|
-
Deno.test('DataTable realtime gate deduplicates applied sequences and detects gaps', () => {
|
|
439
|
-
const gate = new DataTableRealtimeSequenceGate();
|
|
440
|
-
gate.registerTable('org-1', 'table-1');
|
|
441
|
-
gate.acknowledgeSnapshot('org-1', 'table-1', '4');
|
|
442
|
-
const next = gate.consume(createUpdate({ batchId: 'next', fromSeq: '5' }));
|
|
443
|
-
const duplicate = gate.consume(
|
|
444
|
-
createUpdate({ batchId: 'duplicate', fromSeq: '5' }),
|
|
445
|
-
);
|
|
446
|
-
const gap = gate.consume(createUpdate({ batchId: 'gap', fromSeq: '7' }));
|
|
447
|
-
|
|
448
|
-
expect(next.type === 'APPLY', 'The exact next sequence must apply');
|
|
449
|
-
expect(
|
|
450
|
-
duplicate.type === 'DROP',
|
|
451
|
-
'An already applied sequence must be dropped',
|
|
452
|
-
);
|
|
453
|
-
expect(
|
|
454
|
-
gap.type === 'RECOVER' && gap.reason === 'GAP',
|
|
455
|
-
'A missing sequence must force recovery',
|
|
456
|
-
);
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
Deno.test('DataTable realtime gate recovers unknown baselines and malformed envelopes', () => {
|
|
460
|
-
const gate = new DataTableRealtimeSequenceGate();
|
|
461
|
-
gate.registerTable('org-1', 'table-1');
|
|
462
|
-
const unknown = gate.consume(createUpdate({ fromSeq: '12' }));
|
|
463
|
-
const malformedUpdate = createUpdate({ batchId: 'malformed' });
|
|
464
|
-
malformedUpdate.dataTableChange!.chunkCount = 0;
|
|
465
|
-
const malformed = gate.consume(malformedUpdate);
|
|
466
|
-
|
|
467
|
-
expect(
|
|
468
|
-
unknown.type === 'RECOVER' && unknown.reason === 'UNKNOWN_BASELINE',
|
|
469
|
-
'The first sequenced envelope must reconcile against an authoritative snapshot',
|
|
470
|
-
);
|
|
471
|
-
expect(
|
|
472
|
-
malformed.type === 'RECOVER' && malformed.reason === 'MALFORMED_ENVELOPE',
|
|
473
|
-
'Malformed sequence metadata must fail closed',
|
|
474
|
-
);
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
Deno.test('DataTable realtime tail validation accepts only exact contiguous replay contracts', () => {
|
|
478
|
-
const replayable = resolveDataTableRealtimeTail(
|
|
479
|
-
{
|
|
480
|
-
dataTableId: 'table-1',
|
|
481
|
-
currentSeq: '2',
|
|
482
|
-
requiresSnapshot: false,
|
|
483
|
-
changes: [createTailChange('1'), createTailChange('2')],
|
|
484
|
-
},
|
|
485
|
-
{
|
|
486
|
-
afterSeq: '0',
|
|
487
|
-
dataTableId: 'table-1',
|
|
488
|
-
observedToSeq: '2',
|
|
489
|
-
},
|
|
490
|
-
);
|
|
491
|
-
const malformed = resolveDataTableRealtimeTail(
|
|
492
|
-
{
|
|
493
|
-
dataTableId: 'table-1',
|
|
494
|
-
currentSeq: '2',
|
|
495
|
-
requiresSnapshot: false,
|
|
496
|
-
changes: [createTailChange('2')],
|
|
497
|
-
},
|
|
498
|
-
{
|
|
499
|
-
afterSeq: '0',
|
|
500
|
-
dataTableId: 'table-1',
|
|
501
|
-
observedToSeq: '2',
|
|
502
|
-
},
|
|
503
|
-
);
|
|
504
|
-
|
|
505
|
-
expect(
|
|
506
|
-
replayable.reason === 'REPLAYABLE' &&
|
|
507
|
-
replayable.targetSeq === '2' &&
|
|
508
|
-
replayable.requiresAuthoritativeSnapshot,
|
|
509
|
-
'An exact tail may target, but never acknowledge, its current watermark',
|
|
510
|
-
);
|
|
511
|
-
expect(
|
|
512
|
-
malformed.reason === 'MALFORMED' && malformed.targetSeq === '2',
|
|
513
|
-
'A partial tail must fall back to the observed committed sequence',
|
|
514
|
-
);
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
Deno.test('DataTable realtime rejects noncanonical sequence and identity strings', () => {
|
|
518
|
-
const gate = new DataTableRealtimeSequenceGate();
|
|
519
|
-
gate.registerTable('org-1', 'table-1');
|
|
520
|
-
expect(
|
|
521
|
-
!gate.acknowledgeSnapshot('org-1', 'table-1', '00'),
|
|
522
|
-
'A leading-zero snapshot sequence must be rejected',
|
|
523
|
-
);
|
|
524
|
-
const malformed = gate.consume(
|
|
525
|
-
createUpdate({ batchId: 'leading-zero', fromSeq: '01' }),
|
|
526
|
-
);
|
|
527
|
-
expect(
|
|
528
|
-
malformed.type === 'RECOVER' && malformed.reason === 'MALFORMED_ENVELOPE',
|
|
529
|
-
'A leading-zero websocket sequence must fail closed',
|
|
530
|
-
);
|
|
531
|
-
|
|
532
|
-
const invalidIdentityChange = createRecordJournalChange();
|
|
533
|
-
invalidIdentityChange.columnId = '017';
|
|
534
|
-
const tail = resolveDataTableRealtimeTail(
|
|
535
|
-
{
|
|
536
|
-
changes: [createTailChange('1', [invalidIdentityChange])],
|
|
537
|
-
currentSeq: '1',
|
|
538
|
-
dataTableId: 'table-1',
|
|
539
|
-
requiresSnapshot: false,
|
|
540
|
-
},
|
|
541
|
-
{ afterSeq: '0', dataTableId: 'table-1', observedToSeq: '1' },
|
|
542
|
-
);
|
|
543
|
-
expect(
|
|
544
|
-
tail.reason === 'MALFORMED',
|
|
545
|
-
'A leading-zero RECORDS column identity must force snapshot recovery',
|
|
546
|
-
);
|
|
547
|
-
});
|
|
548
|
-
|
|
549
|
-
Deno.test('DataTable realtime RECORDS snapshots must match the outer stable coordinate', () => {
|
|
550
|
-
const validChange = createRecordJournalChange();
|
|
551
|
-
const valid = resolveDataTableRealtimeTail(
|
|
552
|
-
{
|
|
553
|
-
changes: [createTailChange('1', [validChange])],
|
|
554
|
-
currentSeq: '1',
|
|
555
|
-
dataTableId: 'table-1',
|
|
556
|
-
requiresSnapshot: false,
|
|
557
|
-
},
|
|
558
|
-
{ afterSeq: '0', dataTableId: 'table-1', observedToSeq: '1' },
|
|
559
|
-
);
|
|
560
|
-
const mismatchedChange = createRecordJournalChange();
|
|
561
|
-
mismatchedChange.current.columnId = '18';
|
|
562
|
-
const mismatched = resolveDataTableRealtimeTail(
|
|
563
|
-
{
|
|
564
|
-
changes: [createTailChange('1', [mismatchedChange])],
|
|
565
|
-
currentSeq: '1',
|
|
566
|
-
dataTableId: 'table-1',
|
|
567
|
-
requiresSnapshot: false,
|
|
568
|
-
},
|
|
569
|
-
{ afterSeq: '0', dataTableId: 'table-1', observedToSeq: '1' },
|
|
570
|
-
);
|
|
571
|
-
|
|
572
|
-
expect(
|
|
573
|
-
valid.reason === 'REPLAYABLE',
|
|
574
|
-
'An exact RECORDS coordinate must pass',
|
|
575
|
-
);
|
|
576
|
-
expect(
|
|
577
|
-
mismatched.reason === 'MALFORMED',
|
|
578
|
-
'A snapshot columnId mismatch must force snapshot recovery',
|
|
579
|
-
);
|
|
580
|
-
});
|
|
581
|
-
|
|
582
|
-
Deno.test('DataTable realtime tail validation treats snapshot tails as reload-only', () => {
|
|
583
|
-
const result = resolveDataTableRealtimeTail(
|
|
584
|
-
{
|
|
585
|
-
dataTableId: 'table-1',
|
|
586
|
-
currentSeq: '9',
|
|
587
|
-
requiresSnapshot: true,
|
|
588
|
-
changes: [],
|
|
589
|
-
},
|
|
590
|
-
{
|
|
591
|
-
afterSeq: '5',
|
|
592
|
-
dataTableId: 'table-1',
|
|
593
|
-
observedToSeq: '8',
|
|
594
|
-
},
|
|
595
|
-
);
|
|
596
|
-
|
|
597
|
-
expect(
|
|
598
|
-
result.reason === 'SNAPSHOT_REQUIRED' && result.targetSeq === '9',
|
|
599
|
-
'Snapshot-required tails must use their watermark only after a full reload',
|
|
600
|
-
);
|
|
601
|
-
});
|
|
602
|
-
|
|
603
|
-
Deno.test('DataTable realtime gate stays recovery-only until a watermark-bearing snapshot is acknowledged', () => {
|
|
604
|
-
const gate = new DataTableRealtimeSequenceGate();
|
|
605
|
-
gate.registerTable('org-1', 'table-1');
|
|
606
|
-
const first = gate.consume(createUpdate({ batchId: 'first', fromSeq: '5' }));
|
|
607
|
-
const nextBeforeSnapshot = gate.consume(
|
|
608
|
-
createUpdate({
|
|
609
|
-
batchId: 'before-snapshot',
|
|
610
|
-
fromSeq: '6',
|
|
611
|
-
}),
|
|
612
|
-
);
|
|
613
|
-
const acknowledged = gate.acknowledgeSnapshot('org-1', 'table-1', '6');
|
|
614
|
-
const nextAfterSnapshot = gate.consume(
|
|
615
|
-
createUpdate({
|
|
616
|
-
batchId: 'after-snapshot',
|
|
617
|
-
fromSeq: '7',
|
|
618
|
-
}),
|
|
619
|
-
);
|
|
620
|
-
|
|
621
|
-
expect(
|
|
622
|
-
first.type === 'RECOVER' && nextBeforeSnapshot.type === 'RECOVER',
|
|
623
|
-
'A tail or fire-and-forget reload must never open the fragment apply gate',
|
|
624
|
-
);
|
|
625
|
-
expect(
|
|
626
|
-
acknowledged && nextAfterSnapshot.type === 'APPLY',
|
|
627
|
-
'Only an awaited snapshot watermark may establish the next safe sequence',
|
|
628
|
-
);
|
|
629
|
-
});
|
|
630
|
-
|
|
631
|
-
Deno.test('DataTable realtime gate tracks ordered traffic for unopened tables', () => {
|
|
632
|
-
const gate = new DataTableRealtimeSequenceGate();
|
|
633
|
-
const result = gate.consume(createUpdate({ fromSeq: '9' }));
|
|
634
|
-
|
|
635
|
-
expect(
|
|
636
|
-
result.type === 'APPLY' && result.toSeq === '9',
|
|
637
|
-
'An unopened table must retain the observed high-water without recovery',
|
|
638
|
-
);
|
|
639
|
-
});
|
|
640
|
-
|
|
641
|
-
Deno.test('DataTable realtime snapshots are monotonic and fence older page fragments', () => {
|
|
642
|
-
const gate = new DataTableRealtimeSequenceGate();
|
|
643
|
-
gate.registerTable('org-1', 'table-1');
|
|
644
|
-
gate.acknowledgeSnapshot('org-1', 'table-1', '4');
|
|
645
|
-
gate.recordSnapshotFragments('org-1', 'table-1', {
|
|
646
|
-
currentSeq: '6',
|
|
647
|
-
dataTableId: 'table-1',
|
|
648
|
-
rows: [
|
|
649
|
-
{
|
|
650
|
-
id: 'row-1',
|
|
651
|
-
cells: [{ id: 'cell-1' }],
|
|
652
|
-
},
|
|
653
|
-
],
|
|
654
|
-
});
|
|
655
|
-
|
|
656
|
-
const update = createUpdate({ batchId: 'next', fromSeq: '5' });
|
|
657
|
-
update.fragments = [
|
|
658
|
-
{
|
|
659
|
-
name: '$dataTableCellFragment',
|
|
660
|
-
dataId: 'cell-1',
|
|
661
|
-
data: { value: 'older' },
|
|
662
|
-
},
|
|
663
|
-
];
|
|
664
|
-
const result = gate.consume(update);
|
|
665
|
-
const filtered =
|
|
666
|
-
result.type === 'APPLY'
|
|
667
|
-
? gate.filterSequencedUpdate(
|
|
668
|
-
result.updates[0],
|
|
669
|
-
result.toSeq || '0',
|
|
670
|
-
'org-1',
|
|
671
|
-
'table-1',
|
|
672
|
-
)
|
|
673
|
-
: null;
|
|
674
|
-
|
|
675
|
-
expect(
|
|
676
|
-
result.type === 'APPLY' && filtered?.fragments?.length === 0,
|
|
677
|
-
'A page snapshot ahead of the socket cursor must reject older fragments',
|
|
678
|
-
);
|
|
679
|
-
expect(
|
|
680
|
-
!gate.acknowledgeSnapshot('org-1', 'table-1', '3'),
|
|
681
|
-
'An older snapshot must never move the table baseline backwards',
|
|
682
|
-
);
|
|
683
|
-
});
|
|
684
|
-
|
|
685
|
-
Deno.test('DataTable realtime pre-registration high-water rejects an older snapshot', () => {
|
|
686
|
-
const gate = new DataTableRealtimeSequenceGate();
|
|
687
|
-
const earlyEvent = gate.consume(createUpdate({ fromSeq: '5' }));
|
|
688
|
-
gate.registerTable('org-1', 'table-1');
|
|
689
|
-
|
|
690
|
-
expect(
|
|
691
|
-
earlyEvent.type === 'APPLY' && earlyEvent.toSeq === '5',
|
|
692
|
-
'Pre-registration traffic should advance the observed high-water',
|
|
693
|
-
);
|
|
694
|
-
expect(
|
|
695
|
-
!gate.canApplySnapshot('org-1', 'table-1', '4') &&
|
|
696
|
-
gate.canApplySnapshot('org-1', 'table-1', '5'),
|
|
697
|
-
'An initial snapshot must reach every committed event observed before registration',
|
|
698
|
-
);
|
|
699
|
-
});
|
|
700
|
-
|
|
701
|
-
Deno.test('DataTable realtime final unmount clears websocket fragment fences', () => {
|
|
702
|
-
const gate = new DataTableRealtimeSequenceGate();
|
|
703
|
-
const unregister = gate.registerTable('org-1', 'table-1');
|
|
704
|
-
const update = createUpdate({ fromSeq: '5' });
|
|
705
|
-
update.fragments = [
|
|
706
|
-
{
|
|
707
|
-
name: '$dataTableCellFragment',
|
|
708
|
-
dataId: 'cell-1',
|
|
709
|
-
data: { value: 'five' },
|
|
710
|
-
},
|
|
711
|
-
];
|
|
712
|
-
gate.acknowledgeSnapshot('org-1', 'table-1', '4');
|
|
713
|
-
const result = gate.consume(update);
|
|
714
|
-
if (result.type === 'APPLY') {
|
|
715
|
-
gate.filterSequencedUpdate(
|
|
716
|
-
result.updates[0],
|
|
717
|
-
result.toSeq || '0',
|
|
718
|
-
'org-1',
|
|
719
|
-
'table-1',
|
|
720
|
-
);
|
|
721
|
-
}
|
|
722
|
-
unregister();
|
|
723
|
-
gate.registerTable('org-1', 'table-1');
|
|
724
|
-
const older = gate.filterSequencedUpdate(update, '4', 'org-1', 'table-1');
|
|
725
|
-
|
|
726
|
-
expect(
|
|
727
|
-
older.fragments?.length === 1,
|
|
728
|
-
'The last unmount must remove fragment versions owned by the old table session',
|
|
729
|
-
);
|
|
730
|
-
});
|
|
731
|
-
|
|
732
|
-
Deno.test('DataTable realtime committed authority is exact, monotonic, and observable', () => {
|
|
733
|
-
const gate = new DataTableRealtimeSequenceGate();
|
|
734
|
-
dataTableRealtimeAuthorityRegistry.clear();
|
|
735
|
-
let notifications = 0;
|
|
736
|
-
const unsubscribe = dataTableRealtimeAuthorityRegistry.subscribe(
|
|
737
|
-
'org-1',
|
|
738
|
-
'table-1',
|
|
739
|
-
() => {
|
|
740
|
-
notifications += 1;
|
|
741
|
-
},
|
|
742
|
-
);
|
|
743
|
-
const update = createUpdate();
|
|
744
|
-
update.dataTableWriteOrders = [
|
|
745
|
-
{
|
|
746
|
-
cellKey: 'status',
|
|
747
|
-
dataTableRowId: 'row-1',
|
|
748
|
-
kind: 'CELL',
|
|
749
|
-
serverSeq: '10',
|
|
750
|
-
tombstone: false,
|
|
751
|
-
},
|
|
752
|
-
];
|
|
753
|
-
gate.filterSequencedUpdate(update, '10', 'org-1', 'table-1');
|
|
754
|
-
update.dataTableWriteOrders = [
|
|
755
|
-
{
|
|
756
|
-
...update.dataTableWriteOrders[0],
|
|
757
|
-
serverSeq: '9',
|
|
758
|
-
},
|
|
759
|
-
];
|
|
760
|
-
gate.filterSequencedUpdate(update, '10', 'org-1', 'table-1');
|
|
761
|
-
|
|
762
|
-
const snapshot = dataTableRealtimeAuthorityRegistry.getSnapshot(
|
|
763
|
-
'org-1',
|
|
764
|
-
'table-1',
|
|
765
|
-
);
|
|
766
|
-
expect(
|
|
767
|
-
notifications === 1 &&
|
|
768
|
-
snapshot.version === 1 &&
|
|
769
|
-
[...snapshot.orders.values()][0]?.serverSeq === '10',
|
|
770
|
-
'Committed write-order authority must advance monotonically and notify once',
|
|
771
|
-
);
|
|
772
|
-
|
|
773
|
-
update.dataTableWriteOrders = [
|
|
774
|
-
{
|
|
775
|
-
cellKey: 'status',
|
|
776
|
-
dataTableRowId: 'row-1',
|
|
777
|
-
extra: true,
|
|
778
|
-
kind: 'CELL',
|
|
779
|
-
serverSeq: '11',
|
|
780
|
-
tombstone: false,
|
|
781
|
-
},
|
|
782
|
-
] as any;
|
|
783
|
-
let malformedRejected = false;
|
|
784
|
-
try {
|
|
785
|
-
gate.filterSequencedUpdate(update, '11', 'org-1', 'table-1');
|
|
786
|
-
} catch {
|
|
787
|
-
malformedRejected = true;
|
|
788
|
-
}
|
|
789
|
-
expect(malformedRejected, 'Malformed write-order authority must fail closed');
|
|
790
|
-
unsubscribe();
|
|
791
|
-
dataTableRealtimeAuthorityRegistry.clear();
|
|
792
|
-
});
|