@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
package/cache/index.test.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { makeQueryResetTarget } from '@jsb188/app/utils/queryReset.ts';
|
|
1
|
+
import { makeGraphQLVariablesKey } from '@jsb188/app/utils/logic.ts';
|
|
2
|
+
import { getQueryResetTargetId, makeQueryResetTarget } from '@jsb188/app/utils/queryReset.ts';
|
|
3
3
|
import {
|
|
4
4
|
addFragmentToCache,
|
|
5
5
|
clearGraphQLClientCache,
|
|
6
6
|
fetchCachedData,
|
|
7
|
-
loadDataFromCache,
|
|
8
|
-
loadFragment,
|
|
9
7
|
getNextQueryLastUpdatedCount,
|
|
10
8
|
getQueryRefreshTime,
|
|
9
|
+
loadDataFromCache,
|
|
10
|
+
loadFragment,
|
|
11
11
|
resetQuery,
|
|
12
12
|
resetQueryByTarget,
|
|
13
13
|
setDataToCache,
|
|
14
14
|
updateFragment,
|
|
15
15
|
updateQuery,
|
|
16
16
|
} from './index.ts';
|
|
17
|
+
import { beginOptimisticUITransaction } from './optimistic-ui.ts';
|
|
17
18
|
|
|
18
19
|
if (typeof (console as any).dev !== 'function') {
|
|
19
20
|
(console as any).dev = () => {};
|
|
@@ -147,6 +148,58 @@ function resetCacheState() {
|
|
|
147
148
|
clearGraphQLClientCache();
|
|
148
149
|
}
|
|
149
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Verify a shared realtime revision cannot produce a mixed editor session
|
|
153
|
+
* whose core is newer than its editor body.
|
|
154
|
+
*/
|
|
155
|
+
|
|
156
|
+
Deno.test('Editor sessions retain one atomic query snapshot', () => {
|
|
157
|
+
resetCacheState();
|
|
158
|
+
|
|
159
|
+
// Use a cacheable test-only root name because production edit sessions are
|
|
160
|
+
// intentionally uncached. The nested shape mirrors campaignTemplateEditSession:
|
|
161
|
+
// an inline core selection (no fragment spread) plus the editor body.
|
|
162
|
+
const cachedSessionQuery = makeQuery('cachedCampaignTemplateEditSession', [
|
|
163
|
+
makeField('organizationId'),
|
|
164
|
+
makeField('template', [
|
|
165
|
+
makeField('id'),
|
|
166
|
+
makeField('organizationId'),
|
|
167
|
+
makeField('editVersion'),
|
|
168
|
+
makeField('title'),
|
|
169
|
+
makeField('updatedAt'),
|
|
170
|
+
]),
|
|
171
|
+
makeField('editor', [makeField('content')]),
|
|
172
|
+
makeField('editable'),
|
|
173
|
+
]);
|
|
174
|
+
const session = {
|
|
175
|
+
organizationId: 'organization-1',
|
|
176
|
+
template: {
|
|
177
|
+
id: 'campaign-template-1',
|
|
178
|
+
organizationId: 'organization-1',
|
|
179
|
+
editVersion: 1,
|
|
180
|
+
title: 'Original title',
|
|
181
|
+
updatedAt: '2026-08-06T00:00:00.000Z',
|
|
182
|
+
},
|
|
183
|
+
editor: { content: '{"version":1,"type":"doc","content":[]}' },
|
|
184
|
+
editable: true,
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
setDataToCache(
|
|
188
|
+
{ cachedCampaignTemplateEditSession: session },
|
|
189
|
+
cachedSessionQuery,
|
|
190
|
+
);
|
|
191
|
+
addFragmentToCache('$campaignTemplateFragment:campaign-template-1', {
|
|
192
|
+
id: 'campaign-template-1',
|
|
193
|
+
editVersion: 2,
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
assertDeepEqual(
|
|
197
|
+
fetchCachedData(cachedSessionQuery, makeGraphQLVariablesKey(undefined)),
|
|
198
|
+
{ cachedCampaignTemplateEditSession: session },
|
|
199
|
+
'edit-session core and editor body should remain the original atomic snapshot',
|
|
200
|
+
);
|
|
201
|
+
});
|
|
202
|
+
|
|
150
203
|
Deno.test('loadFragment rebuilds nested list items without inner fragments', () => {
|
|
151
204
|
resetCacheState();
|
|
152
205
|
|
|
@@ -214,11 +267,7 @@ Deno.test('loadDataFromCache preserves mixed list items with fragment refs and i
|
|
|
214
267
|
|
|
215
268
|
setDataToCache(requestData, gqlQuery);
|
|
216
269
|
|
|
217
|
-
const cachedData = loadDataFromCache(
|
|
218
|
-
{},
|
|
219
|
-
gqlQuery,
|
|
220
|
-
makeVariablesKey(undefined),
|
|
221
|
-
);
|
|
270
|
+
const cachedData = loadDataFromCache({}, gqlQuery, makeGraphQLVariablesKey(undefined));
|
|
222
271
|
|
|
223
272
|
assertDeepEqual(
|
|
224
273
|
cachedData,
|
|
@@ -279,7 +328,7 @@ Deno.test('loadFragment uses newest spread list after same fragment id mutation'
|
|
|
279
328
|
'fragment cache should rebuild same-id Sheet with newest nested tabs spread list',
|
|
280
329
|
);
|
|
281
330
|
assertDeepEqual(
|
|
282
|
-
loadDataFromCache({}, sheetQuery,
|
|
331
|
+
loadDataFromCache({}, sheetQuery, makeGraphQLVariablesKey(sheetVariables)),
|
|
283
332
|
{ workbookSnapshot: updatedSheet },
|
|
284
333
|
'query cache should rebuild same-id Sheet with newest nested tabs spread list',
|
|
285
334
|
);
|
|
@@ -294,7 +343,6 @@ Deno.test('SheetView fragment patches preserve null state fields and clear volat
|
|
|
294
343
|
axisMoveOps: [{ commandId: 'move-1' }],
|
|
295
344
|
id: 'sheet-view-1',
|
|
296
345
|
originClientId: 'old-client',
|
|
297
|
-
ranges: [{ id: 'range-1' }],
|
|
298
346
|
sheetTab: { id: 'tab-1', title: 'Tab 1' },
|
|
299
347
|
structureOps: [{ index: 2, operation: 'INSERT_ROW' }],
|
|
300
348
|
},
|
|
@@ -309,7 +357,6 @@ Deno.test('SheetView fragment patches preserve null state fields and clear volat
|
|
|
309
357
|
axisMoveOps: null,
|
|
310
358
|
id: 'sheet-view-1',
|
|
311
359
|
originClientId: null,
|
|
312
|
-
ranges: null,
|
|
313
360
|
sheetTab: null,
|
|
314
361
|
structureOps: null,
|
|
315
362
|
},
|
|
@@ -325,7 +372,6 @@ Deno.test('SheetView fragment patches preserve null state fields and clear volat
|
|
|
325
372
|
axisMoveOps: null,
|
|
326
373
|
id: 'sheet-view-1',
|
|
327
374
|
originClientId: null,
|
|
328
|
-
ranges: [{ id: 'range-1' }],
|
|
329
375
|
sheetTab: { id: 'tab-1', title: 'Tab 1' },
|
|
330
376
|
structureOps: null,
|
|
331
377
|
},
|
|
@@ -355,13 +401,13 @@ Deno.test('updateFragment callback receives cleaned optimistic array fields', ()
|
|
|
355
401
|
id: 'temp-tab-1',
|
|
356
402
|
sheetId: 'sheet-optimistic-callback',
|
|
357
403
|
name: 'saving',
|
|
358
|
-
|
|
404
|
+
__optimisticPlaceholder: true,
|
|
359
405
|
};
|
|
360
406
|
const nextOptimisticTab = {
|
|
361
407
|
id: 'temp-tab-2',
|
|
362
408
|
sheetId: 'sheet-optimistic-callback',
|
|
363
409
|
name: 'still_saving',
|
|
364
|
-
|
|
410
|
+
__optimisticPlaceholder: true,
|
|
365
411
|
};
|
|
366
412
|
let callbackTabs: any[] = [];
|
|
367
413
|
|
|
@@ -395,7 +441,7 @@ Deno.test('updateFragment callback receives cleaned optimistic array fields', ()
|
|
|
395
441
|
);
|
|
396
442
|
});
|
|
397
443
|
|
|
398
|
-
Deno.test('updateFragment direct object preserves current optimistic
|
|
444
|
+
Deno.test('updateFragment direct object preserves current optimistic placeholders', () => {
|
|
399
445
|
resetCacheState();
|
|
400
446
|
|
|
401
447
|
const sheetQuery = makeQuery('workbookSnapshot', [
|
|
@@ -417,7 +463,7 @@ Deno.test('updateFragment direct object preserves current optimistic array objec
|
|
|
417
463
|
id: 'temp-tab',
|
|
418
464
|
sheetId: 'sheet-optimistic-direct',
|
|
419
465
|
name: 'saving',
|
|
420
|
-
|
|
466
|
+
__optimisticPlaceholder: true,
|
|
421
467
|
};
|
|
422
468
|
|
|
423
469
|
setDataToCache({ workbookSnapshot: sheet }, sheetQuery);
|
|
@@ -442,7 +488,7 @@ Deno.test('updateFragment direct object preserves current optimistic array objec
|
|
|
442
488
|
);
|
|
443
489
|
});
|
|
444
490
|
|
|
445
|
-
Deno.test('authoritative fragment writes remove or replace optimistic
|
|
491
|
+
Deno.test('authoritative fragment writes remove or replace optimistic placeholders by id', () => {
|
|
446
492
|
resetCacheState();
|
|
447
493
|
|
|
448
494
|
const sheetQuery = makeQuery('workbookSnapshot', [
|
|
@@ -465,13 +511,13 @@ Deno.test('authoritative fragment writes remove or replace optimistic array obje
|
|
|
465
511
|
id: 'tab-2',
|
|
466
512
|
sheetId: 'sheet-optimistic-authoritative',
|
|
467
513
|
name: 'saving_tab_2',
|
|
468
|
-
|
|
514
|
+
__optimisticPlaceholder: true,
|
|
469
515
|
};
|
|
470
516
|
const optimisticUnmatchedTab = {
|
|
471
517
|
id: 'temp-tab',
|
|
472
518
|
sheetId: 'sheet-optimistic-authoritative',
|
|
473
519
|
name: 'saving_temp',
|
|
474
|
-
|
|
520
|
+
__optimisticPlaceholder: true,
|
|
475
521
|
};
|
|
476
522
|
const realSheet = {
|
|
477
523
|
...sheet,
|
|
@@ -508,12 +554,299 @@ Deno.test('authoritative fragment writes remove or replace optimistic array obje
|
|
|
508
554
|
'real spread-backed tabs should replace matching optimistic tabs and remove unmatched optimistic tabs',
|
|
509
555
|
);
|
|
510
556
|
assertDeepEqual(
|
|
511
|
-
loadDataFromCache({}, sheetQuery,
|
|
557
|
+
loadDataFromCache({}, sheetQuery, makeGraphQLVariablesKey(sheetVariables)),
|
|
512
558
|
{ workbookSnapshot: realSheet },
|
|
513
559
|
'query cache should also return authoritative tabs without optimistic duplicates',
|
|
514
560
|
);
|
|
515
561
|
});
|
|
516
562
|
|
|
563
|
+
Deno.test('optimistic UI updates multiple fragments and rolls them back together', () => {
|
|
564
|
+
resetCacheState();
|
|
565
|
+
|
|
566
|
+
const logFragmentKey = '$logEntryFragment:optimistic-log';
|
|
567
|
+
const summaryFragmentKey = '$logSummaryFragment:optimistic-summary';
|
|
568
|
+
addFragmentToCache(logFragmentKey, {
|
|
569
|
+
flagColor: null,
|
|
570
|
+
id: 'optimistic-log',
|
|
571
|
+
summary: 'Original',
|
|
572
|
+
});
|
|
573
|
+
addFragmentToCache(summaryFragmentKey, {
|
|
574
|
+
flaggedCount: 0,
|
|
575
|
+
id: 'optimistic-summary',
|
|
576
|
+
});
|
|
577
|
+
const observerUpdates: any[] = [];
|
|
578
|
+
const transaction = beginOptimisticUITransaction(
|
|
579
|
+
[
|
|
580
|
+
{
|
|
581
|
+
action: 'update',
|
|
582
|
+
fragmentKey: logFragmentKey,
|
|
583
|
+
update: { flagColor: 'RED' },
|
|
584
|
+
},
|
|
585
|
+
{
|
|
586
|
+
action: 'update',
|
|
587
|
+
fragmentKey: summaryFragmentKey,
|
|
588
|
+
update: (summary: any) => ({
|
|
589
|
+
flaggedCount: summary.flaggedCount + 1,
|
|
590
|
+
}),
|
|
591
|
+
},
|
|
592
|
+
],
|
|
593
|
+
(update) => observerUpdates.push(update),
|
|
594
|
+
);
|
|
595
|
+
|
|
596
|
+
assertDeepEqual(
|
|
597
|
+
loadFragment(logFragmentKey),
|
|
598
|
+
{
|
|
599
|
+
flagColor: 'RED',
|
|
600
|
+
id: 'optimistic-log',
|
|
601
|
+
summary: 'Original',
|
|
602
|
+
},
|
|
603
|
+
'optimistic UI should patch the first fragment immediately',
|
|
604
|
+
);
|
|
605
|
+
assertDeepEqual(
|
|
606
|
+
loadFragment(summaryFragmentKey),
|
|
607
|
+
{ flaggedCount: 1, id: 'optimistic-summary' },
|
|
608
|
+
'optimistic UI should patch the second fragment immediately',
|
|
609
|
+
);
|
|
610
|
+
assertDeepEqual(
|
|
611
|
+
observerUpdates,
|
|
612
|
+
[{ fragmentIds: [logFragmentKey, summaryFragmentKey] }],
|
|
613
|
+
'optimistic UI should notify all affected fragments together',
|
|
614
|
+
);
|
|
615
|
+
|
|
616
|
+
transaction.transaction?.rollback();
|
|
617
|
+
|
|
618
|
+
assertDeepEqual(
|
|
619
|
+
loadFragment(logFragmentKey),
|
|
620
|
+
{
|
|
621
|
+
flagColor: null,
|
|
622
|
+
id: 'optimistic-log',
|
|
623
|
+
summary: 'Original',
|
|
624
|
+
},
|
|
625
|
+
'rollback should restore the first fragment',
|
|
626
|
+
);
|
|
627
|
+
assertDeepEqual(
|
|
628
|
+
loadFragment(summaryFragmentKey),
|
|
629
|
+
{ flaggedCount: 0, id: 'optimistic-summary' },
|
|
630
|
+
'rollback should restore the second fragment',
|
|
631
|
+
);
|
|
632
|
+
assertDeepEqual(
|
|
633
|
+
observerUpdates,
|
|
634
|
+
[
|
|
635
|
+
{ fragmentIds: [logFragmentKey, summaryFragmentKey] },
|
|
636
|
+
{ fragmentIds: [logFragmentKey, summaryFragmentKey] },
|
|
637
|
+
],
|
|
638
|
+
'rollback should notify restored fragments together',
|
|
639
|
+
);
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
Deno.test('optimistic UI creates marked placeholders without mutating caller data', () => {
|
|
643
|
+
resetCacheState();
|
|
644
|
+
|
|
645
|
+
const sheetFragmentKey = '$sheetFragment:optimistic-create';
|
|
646
|
+
const placeholderData = {
|
|
647
|
+
id: 'temporary-tab',
|
|
648
|
+
name: 'Saving',
|
|
649
|
+
};
|
|
650
|
+
addFragmentToCache(sheetFragmentKey, {
|
|
651
|
+
id: 'optimistic-create',
|
|
652
|
+
tabs: [{ id: 'tab-1', name: 'First' }],
|
|
653
|
+
});
|
|
654
|
+
const transaction = beginOptimisticUITransaction(
|
|
655
|
+
{
|
|
656
|
+
action: 'create-placeholder',
|
|
657
|
+
parentFragmentKey: sheetFragmentKey,
|
|
658
|
+
field: 'tabs',
|
|
659
|
+
data: placeholderData,
|
|
660
|
+
position: 'end',
|
|
661
|
+
},
|
|
662
|
+
() => undefined,
|
|
663
|
+
);
|
|
664
|
+
const optimisticTabs = loadFragment(sheetFragmentKey)?.tabs;
|
|
665
|
+
|
|
666
|
+
assertDeepEqual(
|
|
667
|
+
{
|
|
668
|
+
callerData: placeholderData,
|
|
669
|
+
placeholder: {
|
|
670
|
+
id: optimisticTabs?.[1]?.id,
|
|
671
|
+
isOptimisticPlaceholder: optimisticTabs?.[1]?.__optimisticPlaceholder,
|
|
672
|
+
name: optimisticTabs?.[1]?.name,
|
|
673
|
+
transactionTokenType:
|
|
674
|
+
typeof optimisticTabs?.[1]?.__optimisticTransactionId,
|
|
675
|
+
},
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
callerData: { id: 'temporary-tab', name: 'Saving' },
|
|
679
|
+
placeholder: {
|
|
680
|
+
id: 'temporary-tab',
|
|
681
|
+
isOptimisticPlaceholder: true,
|
|
682
|
+
name: 'Saving',
|
|
683
|
+
transactionTokenType: 'string',
|
|
684
|
+
},
|
|
685
|
+
},
|
|
686
|
+
'placeholder creation should add internal markers only to cached data',
|
|
687
|
+
);
|
|
688
|
+
|
|
689
|
+
addFragmentToCache(sheetFragmentKey, {
|
|
690
|
+
id: 'optimistic-create',
|
|
691
|
+
tabs: [
|
|
692
|
+
{ id: 'tab-1', name: 'First' },
|
|
693
|
+
{ id: 'tab-2', name: 'Created' },
|
|
694
|
+
],
|
|
695
|
+
});
|
|
696
|
+
transaction.transaction?.commit();
|
|
697
|
+
|
|
698
|
+
assertDeepEqual(
|
|
699
|
+
loadFragment(sheetFragmentKey)?.tabs,
|
|
700
|
+
[
|
|
701
|
+
{ id: 'tab-1', name: 'First' },
|
|
702
|
+
{ id: 'tab-2', name: 'Created' },
|
|
703
|
+
],
|
|
704
|
+
'authoritative collection data should survive placeholder settlement',
|
|
705
|
+
);
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
Deno.test('optimistic UI rollback preserves newer authoritative values', () => {
|
|
709
|
+
resetCacheState();
|
|
710
|
+
|
|
711
|
+
const fragmentKey = '$logEntryFragment:optimistic-authority';
|
|
712
|
+
addFragmentToCache(fragmentKey, {
|
|
713
|
+
flagColor: null,
|
|
714
|
+
id: 'optimistic-authority',
|
|
715
|
+
});
|
|
716
|
+
const transaction = beginOptimisticUITransaction(
|
|
717
|
+
{
|
|
718
|
+
action: 'update',
|
|
719
|
+
fragmentKey,
|
|
720
|
+
update: { flagColor: 'RED' },
|
|
721
|
+
},
|
|
722
|
+
() => undefined,
|
|
723
|
+
);
|
|
724
|
+
|
|
725
|
+
addFragmentToCache(fragmentKey, {
|
|
726
|
+
flagColor: 'BLUE',
|
|
727
|
+
id: 'optimistic-authority',
|
|
728
|
+
});
|
|
729
|
+
transaction.transaction?.rollback();
|
|
730
|
+
|
|
731
|
+
assertDeepEqual(
|
|
732
|
+
loadFragment(fragmentKey),
|
|
733
|
+
{ flagColor: 'BLUE', id: 'optimistic-authority' },
|
|
734
|
+
'a late rollback should not overwrite a newer authoritative value',
|
|
735
|
+
);
|
|
736
|
+
});
|
|
737
|
+
|
|
738
|
+
Deno.test('optimistic UI rejects a second transaction for the same fragment', () => {
|
|
739
|
+
resetCacheState();
|
|
740
|
+
|
|
741
|
+
const fragmentKey = '$logEntryFragment:optimistic-conflict';
|
|
742
|
+
addFragmentToCache(fragmentKey, {
|
|
743
|
+
flagColor: null,
|
|
744
|
+
id: 'optimistic-conflict',
|
|
745
|
+
});
|
|
746
|
+
const firstTransaction = beginOptimisticUITransaction(
|
|
747
|
+
{
|
|
748
|
+
action: 'update',
|
|
749
|
+
fragmentKey,
|
|
750
|
+
update: { flagColor: 'RED' },
|
|
751
|
+
},
|
|
752
|
+
() => undefined,
|
|
753
|
+
);
|
|
754
|
+
const secondTransaction = beginOptimisticUITransaction(
|
|
755
|
+
{
|
|
756
|
+
action: 'update',
|
|
757
|
+
fragmentKey,
|
|
758
|
+
update: { flagColor: 'BLUE' },
|
|
759
|
+
},
|
|
760
|
+
() => undefined,
|
|
761
|
+
);
|
|
762
|
+
|
|
763
|
+
assertDeepEqual(
|
|
764
|
+
{
|
|
765
|
+
flagColor: loadFragment(fragmentKey)?.flagColor,
|
|
766
|
+
firstStatus: firstTransaction.status,
|
|
767
|
+
secondStatus: secondTransaction.status,
|
|
768
|
+
},
|
|
769
|
+
{
|
|
770
|
+
flagColor: 'RED',
|
|
771
|
+
firstStatus: 'applied',
|
|
772
|
+
secondStatus: 'conflict',
|
|
773
|
+
},
|
|
774
|
+
'a same-fragment transaction should be rejected before it can overlap',
|
|
775
|
+
);
|
|
776
|
+
|
|
777
|
+
firstTransaction.transaction?.rollback();
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
Deno.test('optimistic UI rolls back collection updates before removing placeholders', () => {
|
|
781
|
+
resetCacheState();
|
|
782
|
+
|
|
783
|
+
const fragmentKey = '$sheetFragment:optimistic-mixed-collection';
|
|
784
|
+
addFragmentToCache(fragmentKey, {
|
|
785
|
+
id: 'optimistic-mixed-collection',
|
|
786
|
+
tabs: [{ id: 'tab-1', name: 'First' }],
|
|
787
|
+
});
|
|
788
|
+
const transaction = beginOptimisticUITransaction(
|
|
789
|
+
[
|
|
790
|
+
{
|
|
791
|
+
action: 'update',
|
|
792
|
+
fragmentKey,
|
|
793
|
+
update: (sheet: any) => ({
|
|
794
|
+
tabs: [...sheet.tabs, { id: 'tab-2', name: 'Second' }],
|
|
795
|
+
}),
|
|
796
|
+
},
|
|
797
|
+
{
|
|
798
|
+
action: 'create-placeholder',
|
|
799
|
+
parentFragmentKey: fragmentKey,
|
|
800
|
+
field: 'tabs',
|
|
801
|
+
data: { id: 'temporary-tab', name: 'Saving' },
|
|
802
|
+
},
|
|
803
|
+
],
|
|
804
|
+
() => undefined,
|
|
805
|
+
);
|
|
806
|
+
|
|
807
|
+
transaction.transaction?.rollback();
|
|
808
|
+
|
|
809
|
+
assertDeepEqual(
|
|
810
|
+
loadFragment(fragmentKey)?.tabs,
|
|
811
|
+
[{ id: 'tab-1', name: 'First' }],
|
|
812
|
+
'rollback should restore a collection update after removing its placeholder',
|
|
813
|
+
);
|
|
814
|
+
});
|
|
815
|
+
|
|
816
|
+
Deno.test('optimistic placeholder creation requires an existing collection', () => {
|
|
817
|
+
resetCacheState();
|
|
818
|
+
|
|
819
|
+
const fragmentKey = '$sheetFragment:optimistic-missing-collection';
|
|
820
|
+
addFragmentToCache(fragmentKey, {
|
|
821
|
+
id: 'optimistic-missing-collection',
|
|
822
|
+
tabs: null,
|
|
823
|
+
});
|
|
824
|
+
const transaction = beginOptimisticUITransaction(
|
|
825
|
+
{
|
|
826
|
+
action: 'create-placeholder',
|
|
827
|
+
parentFragmentKey: fragmentKey,
|
|
828
|
+
field: 'tabs',
|
|
829
|
+
data: { id: 'temporary-tab', name: 'Saving' },
|
|
830
|
+
},
|
|
831
|
+
() => undefined,
|
|
832
|
+
);
|
|
833
|
+
|
|
834
|
+
assertDeepEqual(
|
|
835
|
+
{
|
|
836
|
+
fragment: loadFragment(fragmentKey),
|
|
837
|
+
status: transaction.status,
|
|
838
|
+
},
|
|
839
|
+
{
|
|
840
|
+
fragment: {
|
|
841
|
+
id: 'optimistic-missing-collection',
|
|
842
|
+
tabs: null,
|
|
843
|
+
},
|
|
844
|
+
status: 'noop',
|
|
845
|
+
},
|
|
846
|
+
'placeholder creation should be a no-op when the collection is not cached',
|
|
847
|
+
);
|
|
848
|
+
});
|
|
849
|
+
|
|
517
850
|
Deno.test('fetchCachedData rejects cached query data missing newly selected nested fields', () => {
|
|
518
851
|
resetCacheState();
|
|
519
852
|
|
|
@@ -543,11 +876,7 @@ Deno.test('fetchCachedData rejects cached query data missing newly selected nest
|
|
|
543
876
|
|
|
544
877
|
setDataToCache(requestData, oldQuery);
|
|
545
878
|
|
|
546
|
-
const cachedData = fetchCachedData(
|
|
547
|
-
newQuery,
|
|
548
|
-
makeVariablesKey(undefined),
|
|
549
|
-
() => {},
|
|
550
|
-
);
|
|
879
|
+
const cachedData = fetchCachedData(newQuery, makeGraphQLVariablesKey(undefined), () => {});
|
|
551
880
|
|
|
552
881
|
assertDeepEqual(
|
|
553
882
|
cachedData,
|
|
@@ -600,11 +929,7 @@ Deno.test('fetchCachedData ignores nonmatching inline fragments for union data',
|
|
|
600
929
|
|
|
601
930
|
setDataToCache(requestData, gqlQuery);
|
|
602
931
|
|
|
603
|
-
const cachedData = fetchCachedData(
|
|
604
|
-
gqlQuery,
|
|
605
|
-
makeVariablesKey(undefined),
|
|
606
|
-
() => {},
|
|
607
|
-
);
|
|
932
|
+
const cachedData = fetchCachedData(gqlQuery, makeGraphQLVariablesKey(undefined), () => {});
|
|
608
933
|
|
|
609
934
|
assertDeepEqual(
|
|
610
935
|
cachedData,
|
|
@@ -616,11 +941,8 @@ Deno.test('fetchCachedData ignores nonmatching inline fragments for union data',
|
|
|
616
941
|
Deno.test('resetQuery reset-only clears matching query cache and notifies observers without force refetch', () => {
|
|
617
942
|
resetCacheState();
|
|
618
943
|
|
|
619
|
-
const gqlQuery = makeQuery('logEntries', [
|
|
620
|
-
|
|
621
|
-
makeField('status'),
|
|
622
|
-
]);
|
|
623
|
-
const variablesKey = makeVariablesKey({
|
|
944
|
+
const gqlQuery = makeQuery('logEntries', [makeField('id'), makeField('status')]);
|
|
945
|
+
const variablesKey = makeGraphQLVariablesKey({
|
|
624
946
|
organizationId: 'org-1',
|
|
625
947
|
});
|
|
626
948
|
const requestData = {
|
|
@@ -713,8 +1035,8 @@ Deno.test('structured reset force-refetch marks only matching scoped query varia
|
|
|
713
1035
|
sheetId: 'sheet-1',
|
|
714
1036
|
sheetTabId: 'tab-2',
|
|
715
1037
|
};
|
|
716
|
-
const matchingVariablesKey =
|
|
717
|
-
const otherTabVariablesKey =
|
|
1038
|
+
const matchingVariablesKey = makeGraphQLVariablesKey(matchingVariables);
|
|
1039
|
+
const otherTabVariablesKey = makeGraphQLVariablesKey(otherTabVariables);
|
|
718
1040
|
const observerArgs: any[] = [];
|
|
719
1041
|
|
|
720
1042
|
setDataToCache(
|
|
@@ -752,7 +1074,13 @@ Deno.test('structured reset force-refetch marks only matching scoped query varia
|
|
|
752
1074
|
observerArgs,
|
|
753
1075
|
[
|
|
754
1076
|
{
|
|
755
|
-
queryId:
|
|
1077
|
+
queryId: getQueryResetTargetId(
|
|
1078
|
+
makeQueryResetTarget('tabScopedSnapshot', matchingVariables),
|
|
1079
|
+
),
|
|
1080
|
+
queryTarget: makeQueryResetTarget(
|
|
1081
|
+
'tabScopedSnapshot',
|
|
1082
|
+
matchingVariables,
|
|
1083
|
+
),
|
|
756
1084
|
forceRefetch: true,
|
|
757
1085
|
},
|
|
758
1086
|
],
|
|
@@ -792,7 +1120,7 @@ Deno.test('root field aliases share the operation response cache key', () => {
|
|
|
792
1120
|
);
|
|
793
1121
|
|
|
794
1122
|
assertDeepEqual(
|
|
795
|
-
fetchCachedData(gqlQuery,
|
|
1123
|
+
fetchCachedData(gqlQuery, makeGraphQLVariablesKey(variables)),
|
|
796
1124
|
{
|
|
797
1125
|
rowsSnapshotAlias: {
|
|
798
1126
|
dataTableId: 'table-1',
|
|
@@ -856,7 +1184,7 @@ Deno.test('appended query list survives a stale flat fragment spread copy', () =
|
|
|
856
1184
|
// mutation and the realtime QUERY_APPEND event
|
|
857
1185
|
addFragmentToCache('$aiChatMessageFragment:msg-3', appendedMessage);
|
|
858
1186
|
updateQuery(
|
|
859
|
-
`#aiChat:${
|
|
1187
|
+
`#aiChat:${makeGraphQLVariablesKey(chatVariables)}`,
|
|
860
1188
|
(currentData: any) => ({
|
|
861
1189
|
...currentData,
|
|
862
1190
|
messages: {
|
|
@@ -868,7 +1196,7 @@ Deno.test('appended query list survives a stale flat fragment spread copy', () =
|
|
|
868
1196
|
);
|
|
869
1197
|
|
|
870
1198
|
assertDeepEqual(
|
|
871
|
-
loadDataFromCache({}, aiChatQuery,
|
|
1199
|
+
loadDataFromCache({}, aiChatQuery, makeGraphQLVariablesKey(chatVariables)),
|
|
872
1200
|
{
|
|
873
1201
|
aiChat: {
|
|
874
1202
|
id: 'chat-1',
|