@jsb188/graphql 1.1.10 → 1.1.11
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/cache/config.ts +64 -50
- package/cache/index.test.ts +671 -109
- package/cache/index.ts +1700 -1240
- package/cache/persist.ts +721 -0
- package/cache/store.ts +437 -0
- package/client/data-table-realtime-subscriptions.test.ts +740 -0
- package/client/data-table-realtime-subscriptions.ts +955 -0
- package/client/data-table-realtime.test.ts +792 -0
- package/client/data-table-realtime.ts +1218 -0
- package/client/fragment-realtime-sequence.ts +52 -0
- package/client/index.ts +2 -0
- package/client/open-sheet.ts +137 -0
- package/client/request-managed-session.test.ts +574 -0
- package/client/request-no-store.test.ts +157 -0
- package/client/request.ts +954 -163
- package/client/sse-ticket.test.ts +26 -0
- package/deno.lock +170 -0
- package/deno.test.json +8 -4
- package/drafts/index.ts +149 -0
- package/drafts/store.ts +397 -0
- package/gql/eagerQueryMap.ts +12 -0
- package/gql/fragments/accountAuthFragments.ts +5 -0
- package/gql/fragments/accountFragments.ts +0 -3
- package/gql/fragments/accountSessionFragments.ts +16 -0
- package/gql/fragments/agentDocFragments.ts +46 -0
- package/gql/fragments/agentMemoryFragments.ts +19 -0
- package/gql/fragments/aiChatFragments.ts +16 -0
- package/gql/fragments/billingFragments.ts +0 -11
- package/gql/fragments/campaignFragments.ts +277 -0
- package/gql/fragments/dataTableFragments.ts +18 -128
- package/gql/fragments/emailFragments.ts +19 -9
- package/gql/fragments/fieldDocFragments.ts +82 -0
- package/gql/fragments/logFragments.ts +20 -79
- package/gql/fragments/organizationFragments.ts +43 -5
- package/gql/fragments/scheduleFragments.ts +155 -0
- package/gql/fragments/sheetFragments.ts +552 -22
- package/gql/fragments/storageFragments.ts +21 -0
- package/gql/fragments/workflowFragments.ts +28 -4
- package/gql/mutations/accountMutations.ts +0 -2
- package/gql/mutations/agentDocMutations.ts +177 -0
- package/gql/mutations/agentMemoryMutations.ts +36 -0
- package/gql/mutations/aiChatMutations.ts +17 -4
- package/gql/mutations/authMutations.ts +158 -17
- package/gql/mutations/campaignMutations.ts +215 -0
- package/gql/mutations/dataTableMutations.ts +48 -26
- package/gql/mutations/fieldDocMutations.ts +24 -0
- package/gql/mutations/index.ts +6 -1
- package/gql/mutations/logMutations.ts +6 -29
- package/gql/mutations/organizationMutations.ts +13 -4
- package/gql/mutations/scheduleMutations.ts +423 -0
- package/gql/mutations/sheetMutations.ts +273 -56
- package/gql/mutations/storageMutations.ts +20 -0
- package/gql/mutations/workflowMutations.ts +42 -0
- package/gql/queries/agentDocQueries.ts +120 -0
- package/gql/queries/agentMemoryQueries.ts +22 -0
- package/gql/queries/aiChatQueries.ts +18 -2
- package/gql/queries/authQueries.ts +41 -0
- package/gql/queries/billingQueries.ts +23 -0
- package/gql/queries/campaignQueries.ts +127 -0
- package/gql/queries/dataTableQueries.ts +100 -11
- package/gql/queries/emailQueries.ts +55 -3
- package/gql/queries/fieldDocQueries.ts +158 -0
- package/gql/queries/index.ts +8 -2
- package/gql/queries/logQueries.ts +11 -28
- package/gql/queries/organizationQueries.ts +52 -1
- package/gql/queries/scheduleQueries.ts +315 -0
- package/gql/queries/sheetQueries.ts +336 -25
- package/gql/queries/storageQueries.ts +38 -0
- package/gql/queries/workflowQueries.ts +72 -3
- package/hooks/index.ts +2065 -971
- package/hooks/use-account-mtn.ts +76 -81
- package/hooks/use-agentDoc-mtn.ts +285 -0
- package/hooks/use-agentDoc-qry.ts +208 -0
- package/hooks/use-agentMemory-mtn.ts +73 -0
- package/hooks/use-agentMemory-qry.ts +44 -0
- package/hooks/use-aiChat-mtn.ts +232 -137
- package/hooks/use-aiChat-qry.ts +480 -222
- package/hooks/use-app-qry.ts +12 -9
- package/hooks/use-auth-mtn.ts +406 -252
- package/hooks/use-auth-qry.ts +51 -0
- package/hooks/use-campaign-mtn.ts +377 -0
- package/hooks/use-campaign-qry.ts +257 -0
- package/hooks/use-dataTable-mtn.ts +116 -33
- package/hooks/use-dataTable-qry.ts +859 -35
- package/hooks/use-email-qry.ts +194 -79
- package/hooks/use-fieldDoc-mtn.ts +50 -0
- package/hooks/use-fieldDoc-qry.ts +180 -0
- package/hooks/use-inboundContact-mtn.ts +19 -16
- package/hooks/use-inboundContact-qry.ts +63 -55
- package/hooks/use-integration-mtn.ts +56 -38
- package/hooks/use-integration-qry.ts +24 -9
- package/hooks/use-log-mtn.ts +72 -56
- package/hooks/use-log-qry.ts +93 -69
- package/hooks/use-organization-mtn.ts +334 -277
- package/hooks/use-organization-qry.ts +199 -129
- package/hooks/use-schedule-mtn.ts +416 -0
- package/hooks/use-schedule-qry.ts +157 -0
- package/hooks/use-sheet-mtn.ts +233 -47
- package/hooks/use-sheet-qry.ts +353 -70
- package/hooks/use-storage-mtn.ts +81 -41
- package/hooks/use-storage-qry.ts +104 -13
- package/hooks/use-workflow-mtn.ts +55 -0
- package/hooks/use-workflow-qry.ts +206 -48
- package/loaders/campaign.ts +137 -0
- package/package.json +94 -71
- package/sse.ts +157 -104
- package/tsconfig.json +11 -10
- package/types.d.ts +60 -30
- package/utils.ts +78 -49
- package/gql/fragments/productFragments.ts +0 -39
- package/gql/fragments/reportFragments.ts +0 -90
- package/gql/mutations/billingMutations.ts +0 -34
- package/gql/queries/productQueries.ts +0 -31
- package/gql/queries/reportQueries.ts +0 -134
- package/hooks/use-product-qry.ts +0 -67
- package/hooks/use-report-qry.ts +0 -153
|
@@ -0,0 +1,740 @@
|
|
|
1
|
+
import WS_ACTIONS from '@jsb188/app/constants/wsActions.ts';
|
|
2
|
+
import { DATA_TABLE_REALTIME_MAX_PAYLOAD_BYTES } from '@jsb188/mday/constants/dataTable.ts';
|
|
3
|
+
import {
|
|
4
|
+
buildDataTableRealtimeWatchTargets,
|
|
5
|
+
DATA_TABLE_REALTIME_SUBSCRIPTION_MAX,
|
|
6
|
+
DataTableRealtimeSubscriptionRegistry,
|
|
7
|
+
dataTableRealtimeWatchPayloadIsWithinLimit,
|
|
8
|
+
getDataTableRealtimeFragmentValue,
|
|
9
|
+
getDataTableRealtimeQuerySubscriptions,
|
|
10
|
+
normalizeDataTableRealtimeWatchAcknowledgement,
|
|
11
|
+
normalizeDataTableRealtimeWatchTargets,
|
|
12
|
+
resolveDataTableRealtimeQueryResult,
|
|
13
|
+
} from './data-table-realtime-subscriptions.ts';
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
* Assert JSON-compatible registry output without requiring a remote test dependency.
|
|
17
|
+
*/
|
|
18
|
+
function assertEquals(actual: unknown, expected: unknown) {
|
|
19
|
+
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
|
|
20
|
+
throw new Error(`Values differ: ${JSON.stringify(actual)}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
* Build one JWT-shaped value whose payload is used only as an untrusted client
|
|
26
|
+
* scheduling hint. No test or production client treats this as authorization.
|
|
27
|
+
*/
|
|
28
|
+
function createRealtimeCapabilityHint(expiresAtSeconds: number) {
|
|
29
|
+
return `header.${btoa(JSON.stringify({ exp: expiresAtSeconds }))}.signature`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/*
|
|
33
|
+
* Build one boundary-sized exact-set subscription for packet-budget tests.
|
|
34
|
+
*/
|
|
35
|
+
function buildBoundaryDataTableSubscriptions(tokenLength: number) {
|
|
36
|
+
return [
|
|
37
|
+
{
|
|
38
|
+
dataTableId: 'table-a',
|
|
39
|
+
lastSeq: '0',
|
|
40
|
+
organizationId: 'org-a',
|
|
41
|
+
realtimeToken: 'a'.repeat(tokenLength),
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/*
|
|
47
|
+
* Return the encoded watch packet size with or without the transport field.
|
|
48
|
+
*/
|
|
49
|
+
function getDataTableWatchPacketBytes(
|
|
50
|
+
tokenLength: number,
|
|
51
|
+
includeWatchId: boolean,
|
|
52
|
+
) {
|
|
53
|
+
return (
|
|
54
|
+
2 +
|
|
55
|
+
new TextEncoder().encode(
|
|
56
|
+
JSON.stringify([
|
|
57
|
+
WS_ACTIONS.data_table_watch,
|
|
58
|
+
{
|
|
59
|
+
tables: buildBoundaryDataTableSubscriptions(tokenLength),
|
|
60
|
+
...(includeWatchId ? { watchId: 'w'.repeat(200) } : {}),
|
|
61
|
+
},
|
|
62
|
+
]),
|
|
63
|
+
).byteLength
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
Deno.test('the singular DataTable query requests its realtime capability', async () => {
|
|
68
|
+
const querySource = await Deno.readTextFile(
|
|
69
|
+
new URL('../gql/queries/dataTableQueries.ts', import.meta.url),
|
|
70
|
+
);
|
|
71
|
+
const singularQuerySource = querySource.slice(
|
|
72
|
+
querySource.indexOf('export const dataTableQry'),
|
|
73
|
+
querySource.indexOf('export const dataTableMetadataQry'),
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
if (!/\.\.\.dataTableFragment\s+realtimeToken/.test(singularQuerySource)) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
'The direct DataTable route cannot join realtime rooms without a capability.',
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
Deno.test('DataTable capability rotation cannot be shadowed by recovered fragment metadata', () => {
|
|
84
|
+
const cachedDataTable = {
|
|
85
|
+
id: 'table-a',
|
|
86
|
+
realtimeToken: 'token-old',
|
|
87
|
+
title: 'Recovered title',
|
|
88
|
+
};
|
|
89
|
+
const queryDataTable = {
|
|
90
|
+
id: 'table-a',
|
|
91
|
+
realtimeToken: 'token-new',
|
|
92
|
+
title: 'Older query title',
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
assertEquals(getDataTableRealtimeFragmentValue(cachedDataTable), {
|
|
96
|
+
id: 'table-a',
|
|
97
|
+
title: 'Recovered title',
|
|
98
|
+
});
|
|
99
|
+
assertEquals(
|
|
100
|
+
resolveDataTableRealtimeQueryResult(queryDataTable, cachedDataTable),
|
|
101
|
+
{
|
|
102
|
+
id: 'table-a',
|
|
103
|
+
title: 'Recovered title',
|
|
104
|
+
realtimeToken: 'token-new',
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
assertEquals(resolveDataTableRealtimeQueryResult(null, cachedDataTable), {
|
|
108
|
+
id: 'table-a',
|
|
109
|
+
title: 'Recovered title',
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
Deno.test('DataTable realtime subscriptions batch, ref-count, and reconnect exactly', () => {
|
|
114
|
+
const registry = new DataTableRealtimeSubscriptionRegistry();
|
|
115
|
+
const events: Array<{ eventName: string; tables: unknown[] }> = [];
|
|
116
|
+
registry.setTransport((eventName, payload) => {
|
|
117
|
+
events.push({ eventName, tables: payload.tables });
|
|
118
|
+
});
|
|
119
|
+
const unregisterA1 = registry.register([
|
|
120
|
+
{
|
|
121
|
+
organizationId: 'org-a',
|
|
122
|
+
dataTableId: 'table-a',
|
|
123
|
+
realtimeToken: 'token-a',
|
|
124
|
+
},
|
|
125
|
+
]);
|
|
126
|
+
const unregisterA2 = registry.register([
|
|
127
|
+
{
|
|
128
|
+
organizationId: 'org-a',
|
|
129
|
+
dataTableId: 'table-a',
|
|
130
|
+
realtimeToken: 'token-a',
|
|
131
|
+
},
|
|
132
|
+
]);
|
|
133
|
+
const unregisterB = registry.register([
|
|
134
|
+
{
|
|
135
|
+
organizationId: 'org-a',
|
|
136
|
+
dataTableId: 'table-b',
|
|
137
|
+
realtimeToken: 'token-b',
|
|
138
|
+
},
|
|
139
|
+
]);
|
|
140
|
+
registry.flushNow();
|
|
141
|
+
|
|
142
|
+
assertEquals(events, [
|
|
143
|
+
{
|
|
144
|
+
eventName: WS_ACTIONS.data_table_watch,
|
|
145
|
+
tables: [
|
|
146
|
+
{
|
|
147
|
+
dataTableId: 'table-a',
|
|
148
|
+
lastSeq: '0',
|
|
149
|
+
organizationId: 'org-a',
|
|
150
|
+
realtimeToken: 'token-a',
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
dataTableId: 'table-b',
|
|
154
|
+
lastSeq: '0',
|
|
155
|
+
organizationId: 'org-a',
|
|
156
|
+
realtimeToken: 'token-b',
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
},
|
|
160
|
+
]);
|
|
161
|
+
|
|
162
|
+
unregisterA1();
|
|
163
|
+
registry.flushNow();
|
|
164
|
+
assertEquals(events.length, 1);
|
|
165
|
+
unregisterA2();
|
|
166
|
+
registry.flushNow();
|
|
167
|
+
assertEquals(events.slice(1), [
|
|
168
|
+
{
|
|
169
|
+
eventName: WS_ACTIONS.data_table_watch,
|
|
170
|
+
tables: [
|
|
171
|
+
{
|
|
172
|
+
dataTableId: 'table-b',
|
|
173
|
+
lastSeq: '0',
|
|
174
|
+
organizationId: 'org-a',
|
|
175
|
+
realtimeToken: 'token-b',
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
]);
|
|
180
|
+
|
|
181
|
+
events.length = 0;
|
|
182
|
+
registry.sync();
|
|
183
|
+
registry.flushNow();
|
|
184
|
+
assertEquals(events, [
|
|
185
|
+
{
|
|
186
|
+
eventName: WS_ACTIONS.data_table_watch,
|
|
187
|
+
tables: [
|
|
188
|
+
{
|
|
189
|
+
dataTableId: 'table-b',
|
|
190
|
+
lastSeq: '0',
|
|
191
|
+
organizationId: 'org-a',
|
|
192
|
+
realtimeToken: 'token-b',
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
},
|
|
196
|
+
]);
|
|
197
|
+
|
|
198
|
+
events.length = 0;
|
|
199
|
+
unregisterB();
|
|
200
|
+
registry.flushNow();
|
|
201
|
+
assertEquals(events, [
|
|
202
|
+
{
|
|
203
|
+
eventName: WS_ACTIONS.data_table_unwatch,
|
|
204
|
+
tables: [],
|
|
205
|
+
},
|
|
206
|
+
]);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
Deno.test('DataTable direct cutover leaves every room when replacement intent empties before acknowledgement', () => {
|
|
210
|
+
const registry = new DataTableRealtimeSubscriptionRegistry();
|
|
211
|
+
const events: Array<{ eventName: string; tables: unknown[] }> = [];
|
|
212
|
+
registry.setTransport((eventName, payload) => {
|
|
213
|
+
events.push({ eventName, tables: payload.tables });
|
|
214
|
+
});
|
|
215
|
+
const unregisterA = registry.register([
|
|
216
|
+
{
|
|
217
|
+
organizationId: 'org-a',
|
|
218
|
+
dataTableId: 'table-a',
|
|
219
|
+
realtimeToken: 'token-a',
|
|
220
|
+
},
|
|
221
|
+
]);
|
|
222
|
+
registry.flushNow();
|
|
223
|
+
|
|
224
|
+
unregisterA();
|
|
225
|
+
const unregisterB = registry.register([
|
|
226
|
+
{
|
|
227
|
+
organizationId: 'org-a',
|
|
228
|
+
dataTableId: 'table-b',
|
|
229
|
+
realtimeToken: 'token-b',
|
|
230
|
+
},
|
|
231
|
+
]);
|
|
232
|
+
registry.flushNow();
|
|
233
|
+
unregisterB();
|
|
234
|
+
registry.flushNow();
|
|
235
|
+
|
|
236
|
+
assertEquals(events.slice(1), [
|
|
237
|
+
{
|
|
238
|
+
eventName: WS_ACTIONS.data_table_watch,
|
|
239
|
+
tables: [
|
|
240
|
+
{
|
|
241
|
+
dataTableId: 'table-b',
|
|
242
|
+
lastSeq: '0',
|
|
243
|
+
organizationId: 'org-a',
|
|
244
|
+
realtimeToken: 'token-b',
|
|
245
|
+
},
|
|
246
|
+
],
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
eventName: WS_ACTIONS.data_table_unwatch,
|
|
250
|
+
tables: [],
|
|
251
|
+
},
|
|
252
|
+
]);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
Deno.test('DataTable watch cursors are resolved at each actual subscription flush', () => {
|
|
256
|
+
let cursor = '4';
|
|
257
|
+
const registry = new DataTableRealtimeSubscriptionRegistry(() => cursor);
|
|
258
|
+
const events: unknown[] = [];
|
|
259
|
+
registry.setTransport((eventName, payload) => {
|
|
260
|
+
events.push({ eventName, tables: payload.tables });
|
|
261
|
+
});
|
|
262
|
+
registry.register([
|
|
263
|
+
{
|
|
264
|
+
dataTableId: 'table-a',
|
|
265
|
+
organizationId: 'org-a',
|
|
266
|
+
realtimeToken: 'token-a',
|
|
267
|
+
},
|
|
268
|
+
]);
|
|
269
|
+
registry.flushNow();
|
|
270
|
+
cursor = '5';
|
|
271
|
+
registry.flushNow();
|
|
272
|
+
registry.sync();
|
|
273
|
+
registry.flushNow();
|
|
274
|
+
|
|
275
|
+
assertEquals(events, [
|
|
276
|
+
{
|
|
277
|
+
eventName: WS_ACTIONS.data_table_watch,
|
|
278
|
+
tables: [
|
|
279
|
+
{
|
|
280
|
+
dataTableId: 'table-a',
|
|
281
|
+
lastSeq: '4',
|
|
282
|
+
organizationId: 'org-a',
|
|
283
|
+
realtimeToken: 'token-a',
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
eventName: WS_ACTIONS.data_table_watch,
|
|
289
|
+
tables: [
|
|
290
|
+
{
|
|
291
|
+
dataTableId: 'table-a',
|
|
292
|
+
lastSeq: '5',
|
|
293
|
+
organizationId: 'org-a',
|
|
294
|
+
realtimeToken: 'token-a',
|
|
295
|
+
},
|
|
296
|
+
],
|
|
297
|
+
},
|
|
298
|
+
]);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
Deno.test('DataTable direct-cutover watch targets require exact canonical cursors', () => {
|
|
302
|
+
const target = {
|
|
303
|
+
dataTableId: 'table-a',
|
|
304
|
+
lastSeq: '9007199254740993',
|
|
305
|
+
organizationId: 'org-a',
|
|
306
|
+
realtimeToken: 'token-a',
|
|
307
|
+
};
|
|
308
|
+
assertEquals(normalizeDataTableRealtimeWatchTargets([target]), [target]);
|
|
309
|
+
assertEquals(
|
|
310
|
+
buildDataTableRealtimeWatchTargets(
|
|
311
|
+
[
|
|
312
|
+
{
|
|
313
|
+
dataTableId: 'table-a',
|
|
314
|
+
organizationId: 'org-a',
|
|
315
|
+
realtimeToken: 'token-a',
|
|
316
|
+
},
|
|
317
|
+
],
|
|
318
|
+
() => null,
|
|
319
|
+
),
|
|
320
|
+
[
|
|
321
|
+
{
|
|
322
|
+
dataTableId: 'table-a',
|
|
323
|
+
lastSeq: '0',
|
|
324
|
+
organizationId: 'org-a',
|
|
325
|
+
realtimeToken: 'token-a',
|
|
326
|
+
},
|
|
327
|
+
],
|
|
328
|
+
);
|
|
329
|
+
assertEquals(
|
|
330
|
+
normalizeDataTableRealtimeWatchTargets([{ ...target, lastSeq: '01' }]),
|
|
331
|
+
null,
|
|
332
|
+
);
|
|
333
|
+
assertEquals(normalizeDataTableRealtimeWatchTargets([target, target]), null);
|
|
334
|
+
assertEquals(
|
|
335
|
+
normalizeDataTableRealtimeWatchTargets([{ ...target, legacy: true }]),
|
|
336
|
+
null,
|
|
337
|
+
);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
Deno.test('DataTable watch acknowledgements accept only exact convergence statuses', () => {
|
|
341
|
+
const acknowledgement = {
|
|
342
|
+
errorCode: null,
|
|
343
|
+
status: 'OK',
|
|
344
|
+
tables: [
|
|
345
|
+
{
|
|
346
|
+
currentSeq: '12',
|
|
347
|
+
dataTableId: 'table-a',
|
|
348
|
+
organizationId: 'org-a',
|
|
349
|
+
syncStatus: 'SNAPSHOT_REQUIRED',
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
currentSeq: '4',
|
|
353
|
+
dataTableId: 'table-b',
|
|
354
|
+
organizationId: 'org-a',
|
|
355
|
+
syncStatus: 'UP_TO_DATE',
|
|
356
|
+
},
|
|
357
|
+
],
|
|
358
|
+
watchId: 'watch-a',
|
|
359
|
+
};
|
|
360
|
+
assertEquals(
|
|
361
|
+
normalizeDataTableRealtimeWatchAcknowledgement(acknowledgement),
|
|
362
|
+
acknowledgement,
|
|
363
|
+
);
|
|
364
|
+
assertEquals(
|
|
365
|
+
normalizeDataTableRealtimeWatchAcknowledgement({
|
|
366
|
+
errorCode: 'AUTHORIZATION_FAILED',
|
|
367
|
+
status: 'ERROR',
|
|
368
|
+
tables: [],
|
|
369
|
+
watchId: 'watch-b',
|
|
370
|
+
}),
|
|
371
|
+
{
|
|
372
|
+
errorCode: 'AUTHORIZATION_FAILED',
|
|
373
|
+
status: 'ERROR',
|
|
374
|
+
tables: [],
|
|
375
|
+
watchId: 'watch-b',
|
|
376
|
+
},
|
|
377
|
+
);
|
|
378
|
+
assertEquals(
|
|
379
|
+
normalizeDataTableRealtimeWatchAcknowledgement({
|
|
380
|
+
...acknowledgement,
|
|
381
|
+
tables: [acknowledgement.tables[0], acknowledgement.tables[0]],
|
|
382
|
+
}),
|
|
383
|
+
null,
|
|
384
|
+
);
|
|
385
|
+
assertEquals(
|
|
386
|
+
normalizeDataTableRealtimeWatchAcknowledgement({
|
|
387
|
+
...acknowledgement,
|
|
388
|
+
tables: [
|
|
389
|
+
{
|
|
390
|
+
...acknowledgement.tables[0],
|
|
391
|
+
currentSeq: '01',
|
|
392
|
+
},
|
|
393
|
+
],
|
|
394
|
+
}),
|
|
395
|
+
null,
|
|
396
|
+
);
|
|
397
|
+
assertEquals(
|
|
398
|
+
normalizeDataTableRealtimeWatchAcknowledgement({
|
|
399
|
+
...acknowledgement,
|
|
400
|
+
tables: [
|
|
401
|
+
{
|
|
402
|
+
...acknowledgement.tables[0],
|
|
403
|
+
syncStatus: 'REPLAY',
|
|
404
|
+
},
|
|
405
|
+
],
|
|
406
|
+
}),
|
|
407
|
+
null,
|
|
408
|
+
);
|
|
409
|
+
assertEquals(
|
|
410
|
+
normalizeDataTableRealtimeWatchAcknowledgement({
|
|
411
|
+
...acknowledgement,
|
|
412
|
+
legacy: true,
|
|
413
|
+
}),
|
|
414
|
+
null,
|
|
415
|
+
);
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
Deno.test('DataTable room readiness follows only exact correlated scope replacement', () => {
|
|
419
|
+
const registry = new DataTableRealtimeSubscriptionRegistry();
|
|
420
|
+
const tableA = { dataTableId: 'table-a', organizationId: 'org-a' };
|
|
421
|
+
const tableB = { dataTableId: 'table-b', organizationId: 'org-a' };
|
|
422
|
+
const unregisterA = registry.register([
|
|
423
|
+
{ ...tableA, realtimeToken: 'token-a' },
|
|
424
|
+
]);
|
|
425
|
+
const unregisterB = registry.register([
|
|
426
|
+
{ ...tableB, realtimeToken: 'token-b' },
|
|
427
|
+
]);
|
|
428
|
+
const observedA: boolean[] = [];
|
|
429
|
+
const observedB: boolean[] = [];
|
|
430
|
+
const unsubscribeA = registry.subscribeRoomReadiness(tableA, () => {
|
|
431
|
+
observedA.push(registry.getRoomReadiness(tableA));
|
|
432
|
+
});
|
|
433
|
+
const unsubscribeB = registry.subscribeRoomReadiness(tableB, () => {
|
|
434
|
+
observedB.push(registry.getRoomReadiness(tableB));
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
registry.replaceRoomReadiness([tableA, tableB]);
|
|
438
|
+
assertEquals(registry.getRoomReadiness(tableA), true);
|
|
439
|
+
assertEquals(registry.getRoomReadiness(tableB), true);
|
|
440
|
+
registry.replaceRoomReadiness([tableB]);
|
|
441
|
+
assertEquals(registry.getRoomReadiness(tableA), false);
|
|
442
|
+
assertEquals(registry.getRoomReadiness(tableB), true);
|
|
443
|
+
registry.replaceRoomReadiness([tableB]);
|
|
444
|
+
assertEquals(observedA, [true, false]);
|
|
445
|
+
assertEquals(observedB, [true]);
|
|
446
|
+
|
|
447
|
+
registry.clearRoomReadiness();
|
|
448
|
+
assertEquals(registry.getRoomReadiness(tableB), false);
|
|
449
|
+
assertEquals(observedB, [true, false]);
|
|
450
|
+
unregisterA();
|
|
451
|
+
unregisterB();
|
|
452
|
+
unsubscribeA();
|
|
453
|
+
unsubscribeB();
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
Deno.test('DataTable membership intent revisions invalidate async ACK work immediately', () => {
|
|
457
|
+
const registry = new DataTableRealtimeSubscriptionRegistry();
|
|
458
|
+
const table = {
|
|
459
|
+
dataTableId: 'table-a',
|
|
460
|
+
organizationId: 'org-a',
|
|
461
|
+
realtimeToken: 'token-a',
|
|
462
|
+
};
|
|
463
|
+
const unregister = registry.register([table]);
|
|
464
|
+
const registeredRevision = registry.getMembershipIntentRevision();
|
|
465
|
+
|
|
466
|
+
registry.setTransport(() => undefined);
|
|
467
|
+
const connectedRevision = registry.getMembershipIntentRevision();
|
|
468
|
+
registry.sync();
|
|
469
|
+
const synchronizedRevision = registry.getMembershipIntentRevision();
|
|
470
|
+
const unregisterRotated = registry.register([
|
|
471
|
+
{ ...table, realtimeToken: 'token-b' },
|
|
472
|
+
]);
|
|
473
|
+
const rotatedRevision = registry.getMembershipIntentRevision();
|
|
474
|
+
unregister();
|
|
475
|
+
unregisterRotated();
|
|
476
|
+
registry.setTransport(null);
|
|
477
|
+
|
|
478
|
+
if (
|
|
479
|
+
registeredRevision >= connectedRevision ||
|
|
480
|
+
connectedRevision >= synchronizedRevision ||
|
|
481
|
+
synchronizedRevision >= rotatedRevision
|
|
482
|
+
) {
|
|
483
|
+
throw new Error(
|
|
484
|
+
'Each transport, sync, and token boundary must invalidate older async acknowledgements.',
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
Deno.test('DataTable readiness fails closed at pending sync, capability, unregister, and transport boundaries', () => {
|
|
490
|
+
const registry = new DataTableRealtimeSubscriptionRegistry();
|
|
491
|
+
const table = { dataTableId: 'table-a', organizationId: 'org-a' };
|
|
492
|
+
registry.setTransport(() => {});
|
|
493
|
+
const unregisterOld = registry.register([
|
|
494
|
+
{ ...table, realtimeToken: 'token-old' },
|
|
495
|
+
]);
|
|
496
|
+
registry.flushNow();
|
|
497
|
+
registry.replaceRoomReadiness([table]);
|
|
498
|
+
assertEquals(registry.getRoomReadiness(table), true);
|
|
499
|
+
|
|
500
|
+
registry.sync();
|
|
501
|
+
assertEquals(registry.getRoomReadiness(table), false);
|
|
502
|
+
registry.flushNow();
|
|
503
|
+
registry.replaceRoomReadiness([table]);
|
|
504
|
+
const unregisterNew = registry.register([
|
|
505
|
+
{ ...table, realtimeToken: 'token-new' },
|
|
506
|
+
]);
|
|
507
|
+
assertEquals(registry.getRoomReadiness(table), false);
|
|
508
|
+
|
|
509
|
+
registry.replaceRoomReadiness([table]);
|
|
510
|
+
unregisterOld();
|
|
511
|
+
assertEquals(registry.getRoomReadiness(table), true);
|
|
512
|
+
unregisterNew();
|
|
513
|
+
assertEquals(registry.getRoomReadiness(table), false);
|
|
514
|
+
registry.setTransport(null);
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
Deno.test('singular DataTable query subscriptions require a signed capability and honor skip', () => {
|
|
518
|
+
assertEquals(
|
|
519
|
+
getDataTableRealtimeQuerySubscriptions('org-a', 'table-a', 'token-a'),
|
|
520
|
+
[
|
|
521
|
+
{
|
|
522
|
+
organizationId: 'org-a',
|
|
523
|
+
dataTableId: 'table-a',
|
|
524
|
+
realtimeToken: 'token-a',
|
|
525
|
+
},
|
|
526
|
+
],
|
|
527
|
+
);
|
|
528
|
+
assertEquals(
|
|
529
|
+
getDataTableRealtimeQuerySubscriptions('org-a', 'table-a', 'token-a', true),
|
|
530
|
+
[],
|
|
531
|
+
);
|
|
532
|
+
assertEquals(getDataTableRealtimeQuerySubscriptions('org-a', 'table-a'), []);
|
|
533
|
+
assertEquals(
|
|
534
|
+
getDataTableRealtimeQuerySubscriptions(null, 'table-a', 'token-a'),
|
|
535
|
+
[],
|
|
536
|
+
);
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
Deno.test('zero-subscription connect and focus sync emit no watch', () => {
|
|
540
|
+
const registry = new DataTableRealtimeSubscriptionRegistry();
|
|
541
|
+
const events: unknown[] = [];
|
|
542
|
+
registry.setTransport((eventName, payload) =>
|
|
543
|
+
events.push({ eventName, payload }),
|
|
544
|
+
);
|
|
545
|
+
registry.flushNow();
|
|
546
|
+
registry.sync();
|
|
547
|
+
registry.flushNow();
|
|
548
|
+
registry.setTransport(null);
|
|
549
|
+
assertEquals(events, []);
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
Deno.test('detaching a live transport leaves every joined DataTable room', () => {
|
|
553
|
+
const registry = new DataTableRealtimeSubscriptionRegistry();
|
|
554
|
+
const events: unknown[] = [];
|
|
555
|
+
registry.setTransport((eventName, payload) =>
|
|
556
|
+
events.push({ eventName, payload }),
|
|
557
|
+
);
|
|
558
|
+
registry.register([
|
|
559
|
+
{
|
|
560
|
+
dataTableId: 'table-a',
|
|
561
|
+
organizationId: 'org-a',
|
|
562
|
+
realtimeToken: 'token-a',
|
|
563
|
+
},
|
|
564
|
+
]);
|
|
565
|
+
registry.flushNow();
|
|
566
|
+
events.length = 0;
|
|
567
|
+
|
|
568
|
+
registry.setTransport(null);
|
|
569
|
+
|
|
570
|
+
assertEquals(events, [
|
|
571
|
+
{
|
|
572
|
+
eventName: WS_ACTIONS.data_table_unwatch,
|
|
573
|
+
payload: { tables: [] },
|
|
574
|
+
},
|
|
575
|
+
]);
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
Deno.test('replacing a capability immediately replaces the exact DataTable room set', () => {
|
|
579
|
+
const registry = new DataTableRealtimeSubscriptionRegistry();
|
|
580
|
+
const events: Array<{ eventName: string; tables: unknown[] }> = [];
|
|
581
|
+
registry.setTransport((eventName, payload) => {
|
|
582
|
+
events.push({ eventName, tables: payload.tables });
|
|
583
|
+
});
|
|
584
|
+
const unregisterOld = registry.register([
|
|
585
|
+
{
|
|
586
|
+
dataTableId: 'table-a',
|
|
587
|
+
organizationId: 'org-a',
|
|
588
|
+
realtimeToken: 'token-old',
|
|
589
|
+
},
|
|
590
|
+
]);
|
|
591
|
+
registry.flushNow();
|
|
592
|
+
events.length = 0;
|
|
593
|
+
|
|
594
|
+
unregisterOld();
|
|
595
|
+
const unregisterNew = registry.register([
|
|
596
|
+
{
|
|
597
|
+
dataTableId: 'table-a',
|
|
598
|
+
organizationId: 'org-a',
|
|
599
|
+
realtimeToken: 'token-new',
|
|
600
|
+
},
|
|
601
|
+
]);
|
|
602
|
+
registry.flushNow();
|
|
603
|
+
|
|
604
|
+
assertEquals(events, [
|
|
605
|
+
{
|
|
606
|
+
eventName: WS_ACTIONS.data_table_watch,
|
|
607
|
+
tables: [
|
|
608
|
+
{
|
|
609
|
+
dataTableId: 'table-a',
|
|
610
|
+
lastSeq: '0',
|
|
611
|
+
organizationId: 'org-a',
|
|
612
|
+
realtimeToken: 'token-new',
|
|
613
|
+
},
|
|
614
|
+
],
|
|
615
|
+
},
|
|
616
|
+
]);
|
|
617
|
+
unregisterNew();
|
|
618
|
+
registry.flushNow();
|
|
619
|
+
registry.setTransport(null);
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
Deno.test('DataTable capabilities renew before expiry and stop retrying after token replacement', async () => {
|
|
623
|
+
const registry = new DataTableRealtimeSubscriptionRegistry();
|
|
624
|
+
const nowSeconds = Math.floor(Date.now() / 1000);
|
|
625
|
+
registry.setTransport(() => {});
|
|
626
|
+
let unregister = registry.register([
|
|
627
|
+
{
|
|
628
|
+
dataTableId: 'table-a',
|
|
629
|
+
organizationId: 'org-a',
|
|
630
|
+
realtimeToken: createRealtimeCapabilityHint(nowSeconds + 30),
|
|
631
|
+
},
|
|
632
|
+
]);
|
|
633
|
+
let renewalCount = 0;
|
|
634
|
+
const stopRenewal = registry.startCapabilityRenewal(
|
|
635
|
+
() => {
|
|
636
|
+
renewalCount += 1;
|
|
637
|
+
unregister();
|
|
638
|
+
unregister = registry.register([
|
|
639
|
+
{
|
|
640
|
+
dataTableId: 'table-a',
|
|
641
|
+
organizationId: 'org-a',
|
|
642
|
+
realtimeToken: createRealtimeCapabilityHint(nowSeconds + 3_600),
|
|
643
|
+
},
|
|
644
|
+
]);
|
|
645
|
+
},
|
|
646
|
+
{ leadMs: 60_000, retryMs: 1 },
|
|
647
|
+
);
|
|
648
|
+
|
|
649
|
+
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
650
|
+
assertEquals(renewalCount, 1);
|
|
651
|
+
stopRenewal();
|
|
652
|
+
unregister();
|
|
653
|
+
registry.setTransport(null);
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
Deno.test('oversized exact DataTable subscription sets are surfaced without partial joins', () => {
|
|
657
|
+
const registry = new DataTableRealtimeSubscriptionRegistry();
|
|
658
|
+
const events: unknown[] = [];
|
|
659
|
+
registry.setTransport((eventName, payload) => {
|
|
660
|
+
events.push({ eventName, tableCount: payload.tables.length });
|
|
661
|
+
});
|
|
662
|
+
registry.register(
|
|
663
|
+
Array.from(
|
|
664
|
+
{ length: DATA_TABLE_REALTIME_SUBSCRIPTION_MAX + 1 },
|
|
665
|
+
(_value, index) => ({
|
|
666
|
+
dataTableId: `table-${index}`,
|
|
667
|
+
organizationId: 'org-a',
|
|
668
|
+
realtimeToken: `token-${index}`,
|
|
669
|
+
}),
|
|
670
|
+
),
|
|
671
|
+
);
|
|
672
|
+
registry.flushNow();
|
|
673
|
+
|
|
674
|
+
assertEquals(events, [
|
|
675
|
+
{
|
|
676
|
+
eventName: WS_ACTIONS.data_table_watch,
|
|
677
|
+
tableCount: DATA_TABLE_REALTIME_SUBSCRIPTION_MAX + 1,
|
|
678
|
+
},
|
|
679
|
+
]);
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
Deno.test('exact DataTable watches count UTF-8 bytes and suppress oversized retries', () => {
|
|
683
|
+
const ascii = [
|
|
684
|
+
{
|
|
685
|
+
dataTableId: 'table-a',
|
|
686
|
+
lastSeq: '0',
|
|
687
|
+
organizationId: 'org-a',
|
|
688
|
+
realtimeToken: 'a'.repeat(22_000),
|
|
689
|
+
},
|
|
690
|
+
];
|
|
691
|
+
const unicode = [
|
|
692
|
+
{
|
|
693
|
+
dataTableId: 'table-a',
|
|
694
|
+
lastSeq: '0',
|
|
695
|
+
organizationId: 'org-a',
|
|
696
|
+
realtimeToken: '界'.repeat(22_000),
|
|
697
|
+
},
|
|
698
|
+
];
|
|
699
|
+
assertEquals(dataTableRealtimeWatchPayloadIsWithinLimit(ascii), true);
|
|
700
|
+
assertEquals(dataTableRealtimeWatchPayloadIsWithinLimit(unicode), false);
|
|
701
|
+
|
|
702
|
+
const registry = new DataTableRealtimeSubscriptionRegistry();
|
|
703
|
+
const events: unknown[] = [];
|
|
704
|
+
registry.setTransport((eventName, payload) => {
|
|
705
|
+
events.push({ eventName, payload });
|
|
706
|
+
});
|
|
707
|
+
registry.register(unicode);
|
|
708
|
+
registry.flushNow();
|
|
709
|
+
registry.sync();
|
|
710
|
+
registry.flushNow();
|
|
711
|
+
assertEquals(events, []);
|
|
712
|
+
});
|
|
713
|
+
|
|
714
|
+
Deno.test('exact DataTable watch budget reserves the transport-added maximum watch id', () => {
|
|
715
|
+
const fullEnvelopeBaseBytes = getDataTableWatchPacketBytes(0, true);
|
|
716
|
+
const exactTokenLength =
|
|
717
|
+
DATA_TABLE_REALTIME_MAX_PAYLOAD_BYTES - fullEnvelopeBaseBytes;
|
|
718
|
+
|
|
719
|
+
assertEquals(
|
|
720
|
+
getDataTableWatchPacketBytes(exactTokenLength, true),
|
|
721
|
+
DATA_TABLE_REALTIME_MAX_PAYLOAD_BYTES,
|
|
722
|
+
);
|
|
723
|
+
assertEquals(
|
|
724
|
+
dataTableRealtimeWatchPayloadIsWithinLimit(
|
|
725
|
+
buildBoundaryDataTableSubscriptions(exactTokenLength),
|
|
726
|
+
),
|
|
727
|
+
true,
|
|
728
|
+
);
|
|
729
|
+
assertEquals(
|
|
730
|
+
getDataTableWatchPacketBytes(exactTokenLength + 1, false) <=
|
|
731
|
+
DATA_TABLE_REALTIME_MAX_PAYLOAD_BYTES,
|
|
732
|
+
true,
|
|
733
|
+
);
|
|
734
|
+
assertEquals(
|
|
735
|
+
dataTableRealtimeWatchPayloadIsWithinLimit(
|
|
736
|
+
buildBoundaryDataTableSubscriptions(exactTokenLength + 1),
|
|
737
|
+
),
|
|
738
|
+
false,
|
|
739
|
+
);
|
|
740
|
+
});
|