@jsb188/graphql 1.1.12 → 1.1.13
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/LICENSE +21 -0
- package/audience.d.ts +14 -152
- package/cache/config.ts +35 -32
- package/cache/index.helpers.ts +1 -1
- package/cache/index.ts +73 -44
- package/cache/mounted-queries.ts +33 -0
- package/cache/persist.ts +10 -4
- package/cache/realtime-fence.ts +47 -0
- package/cache/realtime-live.ts +17 -0
- package/client/draft-persistence.ts +10 -39
- package/client/index.ts +2 -1
- package/client/request.ts +9 -34
- package/client/storage-asset.ts +58 -0
- package/gql/fragments/accountAuthFragments.ts +0 -4
- package/gql/fragments/agentNoteFragments.ts +8 -2
- package/gql/fragments/aiChatFragments.ts +0 -2
- package/gql/fragments/aiChatLinkFragments.ts +8 -0
- package/gql/fragments/audienceFragments.ts +1 -66
- package/gql/fragments/emailFragments.ts +27 -4
- package/gql/fragments/emailOutreachFragments.ts +281 -0
- package/gql/fragments/inboundContactFragments.ts +1 -1
- package/gql/fragments/libraryFragments.ts +120 -0
- package/gql/fragments/organizationFragments.ts +4 -2
- package/gql/fragments/scheduleFragments.ts +241 -324
- package/gql/fragments/sheetFragments.ts +4 -53
- package/gql/fragments/workWaitFragments.ts +13 -0
- package/gql/fragments/workflowFragments.ts +20 -4
- package/gql/mutations/agentNoteMutations.ts +2 -0
- package/gql/mutations/aiChatLinkMutations.ts +13 -0
- package/gql/mutations/aiChatMutations.ts +4 -6
- package/gql/mutations/audienceMutations.ts +0 -13
- package/gql/mutations/authMutations.ts +12 -60
- package/gql/mutations/emailMutations.ts +22 -0
- package/gql/mutations/emailOutreachMutations.ts +139 -0
- package/gql/mutations/index.ts +3 -1
- package/gql/mutations/organizationMutations.ts +2 -2
- package/gql/mutations/scheduleMutations.ts +61 -787
- package/gql/mutations/storageMutations.ts +1 -0
- package/gql/mutations/workflowMutations.ts +76 -0
- package/gql/queries/agentMemoryQueries.ts +6 -2
- package/gql/queries/agentNoteQueries.ts +26 -29
- package/gql/queries/aiChatQueries.ts +39 -40
- package/gql/queries/audienceQueries.ts +31 -55
- package/gql/queries/authQueries.ts +16 -6
- package/gql/queries/billingQueries.ts +26 -10
- package/gql/queries/dataTableQueries.ts +24 -15
- package/gql/queries/emailOutreachQueries.ts +282 -0
- package/gql/queries/emailQueries.ts +39 -12
- package/gql/queries/emailReplyReportQueries.ts +60 -9
- package/gql/queries/fieldDocQueries.ts +36 -14
- package/gql/queries/inboundContactQueries.ts +11 -4
- package/gql/queries/index.ts +2 -2
- package/gql/queries/libraryQueries.ts +112 -0
- package/gql/queries/logQueries.ts +31 -12
- package/gql/queries/organizationQueries.ts +31 -12
- package/gql/queries/qrCodeQueries.ts +11 -4
- package/gql/queries/scheduleQueries.ts +252 -505
- package/gql/queries/sheetQueries.ts +36 -14
- package/gql/queries/storageQueries.ts +11 -4
- package/gql/queries/workflowQueries.ts +53 -10
- package/gql/reactivity.ts +98 -0
- package/gql/recordReads.ts +171 -0
- package/hooks/index.ts +79 -52
- package/hooks/use-agentNote-mtn.ts +7 -0
- package/hooks/use-agentNote-qry.ts +30 -58
- package/hooks/use-agentNote-recovery.ts +6 -21
- package/hooks/use-aiChat-mtn.ts +9 -4
- package/hooks/use-aiChat-qry.ts +28 -7
- package/hooks/use-audience-mtn.ts +0 -24
- package/hooks/use-audience-qry.helpers.ts +0 -24
- package/hooks/use-audience-qry.ts +1 -86
- package/hooks/use-dataTable-mtn.ts +3 -3
- package/hooks/use-dataTable-qry.ts +7 -2
- package/hooks/use-email-mtn.ts +26 -0
- package/hooks/use-email-qry.helpers.ts +1 -1
- package/hooks/use-email-qry.ts +18 -3
- package/hooks/use-emailOutreach-mtn.ts +211 -0
- package/hooks/use-emailOutreach-qry.helpers.ts +25 -0
- package/hooks/use-emailOutreach-qry.ts +367 -0
- package/hooks/use-emailOutreachReplyReport-qry.ts +46 -0
- package/hooks/use-fieldDoc-qry.ts +1 -1
- package/hooks/use-library-qry.ts +233 -0
- package/hooks/use-qrCode-qry.ts +1 -1
- package/hooks/use-schedule-mtn.ts +10 -300
- package/hooks/use-schedule-qry.ts +168 -680
- package/hooks/use-schedule-reactive.ts +71 -339
- package/hooks/use-sheet-qry.ts +6 -1
- package/hooks/use-workflow-mtn.ts +45 -1
- package/hooks/use-workflow-qry.ts +22 -2
- package/libs/ai-chat-link-events.ts +78 -0
- package/libs/data-changes.helpers.ts +161 -0
- package/libs/data-changes.ts +382 -0
- package/libs/fragment-realtime-sequence.ts +3 -3
- package/libs/record-read.ts +327 -0
- package/libs/sheet-command-batch.ts +3 -2
- package/libs/sheet-realtime-packet.ts +53 -0
- package/loaders/emailPreference.ts +18 -24
- package/package.json +44 -17
- package/schedule.d.ts +267 -874
- package/types.d.ts +3 -1
- package/cache/index.chat-activity.test.ts +0 -119
- package/cache/index.chat.test.ts +0 -92
- package/cache/index.regression.test.ts +0 -149
- package/cache/index.test.ts +0 -1209
- package/deno.lock +0 -187
- package/deno.test.json +0 -12
- package/gql/fragments/campaignFragments.ts +0 -566
- package/gql/mutations/campaignMutations.ts +0 -258
- package/gql/queries/appQueries.ts +0 -14
- package/gql/queries/campaignQueries.ts +0 -236
- package/hooks/index.helpers.test.ts +0 -50
- package/hooks/use-agentNote-recovery.helpers.test.ts +0 -68
- package/hooks/use-aiChat-qry.helpers.test.ts +0 -63
- package/hooks/use-app-qry.ts +0 -22
- package/hooks/use-audience-qry.helpers.test.ts +0 -80
- package/hooks/use-campaign-generation-recovery.ts +0 -53
- package/hooks/use-campaign-mtn.ts +0 -436
- package/hooks/use-campaign-qry.helpers.ts +0 -40
- package/hooks/use-campaign-qry.ts +0 -834
- package/hooks/use-emailCampaignReplyReport-qry.ts +0 -27
- package/hooks/use-fieldDoc-qry.helpers.test.ts +0 -65
- package/hooks/use-publicFormEmail-mtn.ts +0 -27
- package/libs/fragment-recovery.test.ts +0 -326
- package/libs/fragment-recovery.ts +0 -325
- package/libs/orchestrator-realtime.helpers.test.ts +0 -229
- package/libs/orchestrator-realtime.helpers.ts +0 -317
- package/libs/orchestrator-realtime.ts +0 -433
- package/libs/request-cache-regression.test.ts +0 -122
- package/libs/request-managed-session.test.ts +0 -574
- package/libs/request-no-store.test.ts +0 -419
- package/libs/sheet-view-realtime-router.test.ts +0 -214
- package/libs/sse-ticket.test.ts +0 -26
- package/loaders/campaign.test.ts +0 -186
- package/loaders/campaign.ts +0 -110
- package/tests/agent-note-detail-cache.test.ts +0 -120
- package/tests/agent-note-search.test.ts +0 -444
- package/tsconfig.json +0 -13
package/cache/index.test.ts
DELETED
|
@@ -1,1209 +0,0 @@
|
|
|
1
|
-
import { makeGraphQLVariablesKey } from '@jsb188/app/utils/logic.ts';
|
|
2
|
-
import { getQueryResetTargetId, makeQueryResetTarget } from '@jsb188/app/utils/queryReset.ts';
|
|
3
|
-
import {
|
|
4
|
-
addFragmentToCache,
|
|
5
|
-
clearGraphQLClientCache,
|
|
6
|
-
fetchCachedData,
|
|
7
|
-
getNextQueryLastUpdatedCount,
|
|
8
|
-
getQueryRefreshTime,
|
|
9
|
-
loadDataFromCache,
|
|
10
|
-
loadFragment,
|
|
11
|
-
resetQuery,
|
|
12
|
-
resetQueryByTarget,
|
|
13
|
-
setDataToCache,
|
|
14
|
-
updateFragment,
|
|
15
|
-
updateQuery,
|
|
16
|
-
} from './index.ts';
|
|
17
|
-
import { beginOptimisticUITransaction } from './optimistic-ui.ts';
|
|
18
|
-
|
|
19
|
-
if (typeof (console as any).dev !== 'function') {
|
|
20
|
-
(console as any).dev = () => {};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Create a GraphQL field selection node for cache tests.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
function makeField(name: string, selections?: any[]) {
|
|
28
|
-
return {
|
|
29
|
-
kind: 'Field',
|
|
30
|
-
name: { value: name },
|
|
31
|
-
...(selections
|
|
32
|
-
? {
|
|
33
|
-
selectionSet: { selections },
|
|
34
|
-
}
|
|
35
|
-
: {}),
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Create a GraphQL fragment spread node for cache tests.
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
function makeFragmentSpread(name: string) {
|
|
44
|
-
return {
|
|
45
|
-
kind: 'FragmentSpread',
|
|
46
|
-
name: { value: name },
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Create a GraphQL inline fragment node for cache tests.
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
function makeInlineFragment(typeName: string, selections: any[]) {
|
|
55
|
-
return {
|
|
56
|
-
kind: 'InlineFragment',
|
|
57
|
-
typeCondition: {
|
|
58
|
-
name: { value: typeName },
|
|
59
|
-
},
|
|
60
|
-
selectionSet: { selections },
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Create a GraphQL fragment definition node for cache tests.
|
|
66
|
-
*/
|
|
67
|
-
|
|
68
|
-
function makeFragmentDefinition(name: string, selections: any[]) {
|
|
69
|
-
return {
|
|
70
|
-
kind: 'FragmentDefinition',
|
|
71
|
-
name: { value: name },
|
|
72
|
-
selectionSet: { selections },
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Create a minimal GraphQL operation document for cache tests.
|
|
78
|
-
*/
|
|
79
|
-
|
|
80
|
-
function makeQuery(
|
|
81
|
-
queryName: string,
|
|
82
|
-
selections: any[],
|
|
83
|
-
extraDefinitions: any[] = [],
|
|
84
|
-
) {
|
|
85
|
-
return {
|
|
86
|
-
definitions: [
|
|
87
|
-
{
|
|
88
|
-
kind: 'OperationDefinition',
|
|
89
|
-
selectionSet: {
|
|
90
|
-
selections: [
|
|
91
|
-
{
|
|
92
|
-
kind: 'Field',
|
|
93
|
-
name: { value: queryName },
|
|
94
|
-
selectionSet: { selections },
|
|
95
|
-
},
|
|
96
|
-
],
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
...extraDefinitions,
|
|
100
|
-
],
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Normalize nested values into a stable structure for comparisons.
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
|
-
function normalizeValue(value: unknown): unknown {
|
|
109
|
-
if (Array.isArray(value)) {
|
|
110
|
-
return value.map(normalizeValue);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (value && typeof value === 'object') {
|
|
114
|
-
return Object.keys(value as Record<string, unknown>)
|
|
115
|
-
.sort()
|
|
116
|
-
.reduce(
|
|
117
|
-
(acc, key) => {
|
|
118
|
-
acc[key] = normalizeValue((value as Record<string, unknown>)[key]);
|
|
119
|
-
return acc;
|
|
120
|
-
},
|
|
121
|
-
{} as Record<string, unknown>,
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return value;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Assert that two values are deeply equal.
|
|
130
|
-
*/
|
|
131
|
-
|
|
132
|
-
function assertDeepEqual(actual: unknown, expected: unknown, label: string) {
|
|
133
|
-
const actualJson = JSON.stringify(normalizeValue(actual));
|
|
134
|
-
const expectedJson = JSON.stringify(normalizeValue(expected));
|
|
135
|
-
|
|
136
|
-
if (actualJson !== expectedJson) {
|
|
137
|
-
throw new Error(
|
|
138
|
-
`${label}\nExpected: ${expectedJson}\nActual: ${actualJson}`,
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Reset the shared cache state before each test run.
|
|
145
|
-
*/
|
|
146
|
-
|
|
147
|
-
function resetCacheState() {
|
|
148
|
-
clearGraphQLClientCache();
|
|
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
|
-
|
|
203
|
-
Deno.test('loadFragment rebuilds nested list items without inner fragments', () => {
|
|
204
|
-
resetCacheState();
|
|
205
|
-
|
|
206
|
-
const gqlQuery = makeQuery('fieldDoc', [
|
|
207
|
-
makeFragmentSpread('fieldDocFragment'),
|
|
208
|
-
makeField('sections', [makeField('id'), makeField('title')]),
|
|
209
|
-
]);
|
|
210
|
-
|
|
211
|
-
const requestData = {
|
|
212
|
-
fieldDoc: {
|
|
213
|
-
id: 'fieldDoc-1',
|
|
214
|
-
title: 'Daily FieldDoc',
|
|
215
|
-
sections: [
|
|
216
|
-
{
|
|
217
|
-
id: 'section-1',
|
|
218
|
-
title: 'Overview',
|
|
219
|
-
},
|
|
220
|
-
{
|
|
221
|
-
id: 'section-2',
|
|
222
|
-
title: 'Tasks',
|
|
223
|
-
},
|
|
224
|
-
],
|
|
225
|
-
},
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
setDataToCache(requestData, gqlQuery);
|
|
229
|
-
|
|
230
|
-
const cachedFragment = loadFragment('$fieldDocFragment:fieldDoc-1');
|
|
231
|
-
|
|
232
|
-
assertDeepEqual(
|
|
233
|
-
cachedFragment,
|
|
234
|
-
requestData.fieldDoc,
|
|
235
|
-
'fragment cache should rebuild plain nested list items',
|
|
236
|
-
);
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
Deno.test('loadDataFromCache preserves mixed list items with fragment refs and inline fields', () => {
|
|
240
|
-
resetCacheState();
|
|
241
|
-
|
|
242
|
-
const gqlQuery = makeQuery('fieldDoc', [
|
|
243
|
-
makeFragmentSpread('fieldDocFragment'),
|
|
244
|
-
makeField('sections', [
|
|
245
|
-
makeFragmentSpread('fieldDocSectionFragment'),
|
|
246
|
-
makeField('files', [makeField('uri')]),
|
|
247
|
-
]),
|
|
248
|
-
]);
|
|
249
|
-
|
|
250
|
-
const requestData = {
|
|
251
|
-
fieldDoc: {
|
|
252
|
-
id: 'fieldDoc-2',
|
|
253
|
-
title: 'Inspection',
|
|
254
|
-
sections: [
|
|
255
|
-
{
|
|
256
|
-
id: 'section-a',
|
|
257
|
-
title: 'Photos',
|
|
258
|
-
files: [
|
|
259
|
-
{
|
|
260
|
-
uri: '/files/a.jpg',
|
|
261
|
-
},
|
|
262
|
-
],
|
|
263
|
-
},
|
|
264
|
-
],
|
|
265
|
-
},
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
setDataToCache(requestData, gqlQuery);
|
|
269
|
-
|
|
270
|
-
const cachedData = loadDataFromCache({}, gqlQuery, makeGraphQLVariablesKey(undefined));
|
|
271
|
-
|
|
272
|
-
assertDeepEqual(
|
|
273
|
-
cachedData,
|
|
274
|
-
requestData,
|
|
275
|
-
'query cache should rebuild mixed list items from fragment and inline cache data',
|
|
276
|
-
);
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
Deno.test('loadFragment uses newest spread list after same fragment id mutation', () => {
|
|
280
|
-
resetCacheState();
|
|
281
|
-
|
|
282
|
-
const sheetQuery = makeQuery('workbookSnapshot', [
|
|
283
|
-
makeFragmentSpread('sheetFragment'),
|
|
284
|
-
makeField('tabs', [makeFragmentSpread('sheetTabFragment')]),
|
|
285
|
-
]);
|
|
286
|
-
const createSheetTabMutation = makeQuery('createSheetTab', [
|
|
287
|
-
makeFragmentSpread('sheetFragment'),
|
|
288
|
-
makeField('tabs', [makeFragmentSpread('sheetTabFragment')]),
|
|
289
|
-
]);
|
|
290
|
-
const initialSheet = {
|
|
291
|
-
id: 'sheet-1',
|
|
292
|
-
title: 'Sheet',
|
|
293
|
-
tabs: [
|
|
294
|
-
{
|
|
295
|
-
id: 'tab-1',
|
|
296
|
-
sheetId: 'sheet-1',
|
|
297
|
-
name: 'tab_1',
|
|
298
|
-
},
|
|
299
|
-
],
|
|
300
|
-
};
|
|
301
|
-
const updatedSheet = {
|
|
302
|
-
...initialSheet,
|
|
303
|
-
tabs: [
|
|
304
|
-
{
|
|
305
|
-
id: 'tab-1',
|
|
306
|
-
sheetId: 'sheet-1',
|
|
307
|
-
name: 'tab_1',
|
|
308
|
-
},
|
|
309
|
-
{
|
|
310
|
-
id: 'tab-2',
|
|
311
|
-
sheetId: 'sheet-1',
|
|
312
|
-
name: 'tab_2',
|
|
313
|
-
},
|
|
314
|
-
],
|
|
315
|
-
};
|
|
316
|
-
const sheetVariables = { sheetId: 'sheet-1' };
|
|
317
|
-
|
|
318
|
-
setDataToCache(
|
|
319
|
-
{ workbookSnapshot: initialSheet },
|
|
320
|
-
sheetQuery,
|
|
321
|
-
sheetVariables,
|
|
322
|
-
);
|
|
323
|
-
setDataToCache({ createSheetTab: updatedSheet }, createSheetTabMutation);
|
|
324
|
-
|
|
325
|
-
assertDeepEqual(
|
|
326
|
-
loadFragment('$sheetFragment:sheet-1'),
|
|
327
|
-
updatedSheet,
|
|
328
|
-
'fragment cache should rebuild same-id Sheet with newest nested tabs spread list',
|
|
329
|
-
);
|
|
330
|
-
assertDeepEqual(
|
|
331
|
-
loadDataFromCache({}, sheetQuery, makeGraphQLVariablesKey(sheetVariables)),
|
|
332
|
-
{ workbookSnapshot: updatedSheet },
|
|
333
|
-
'query cache should rebuild same-id Sheet with newest nested tabs spread list',
|
|
334
|
-
);
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
Deno.test('SheetView fragment patches preserve null state fields and clear volatile fields', () => {
|
|
338
|
-
resetCacheState();
|
|
339
|
-
|
|
340
|
-
setDataToCache(
|
|
341
|
-
{
|
|
342
|
-
authoritativeTabSnapshot: {
|
|
343
|
-
axisMoveOps: [{ commandId: 'move-1' }],
|
|
344
|
-
id: 'sheet-view-1',
|
|
345
|
-
originClientId: 'old-client',
|
|
346
|
-
sheetTab: { id: 'tab-1', title: 'Tab 1' },
|
|
347
|
-
structureOps: [{ index: 2, operation: 'INSERT_ROW' }],
|
|
348
|
-
},
|
|
349
|
-
},
|
|
350
|
-
makeQuery('authoritativeTabSnapshot', [
|
|
351
|
-
makeFragmentSpread('sheetViewFragment'),
|
|
352
|
-
]),
|
|
353
|
-
);
|
|
354
|
-
setDataToCache(
|
|
355
|
-
{
|
|
356
|
-
editSheetCommandBatch: {
|
|
357
|
-
axisMoveOps: null,
|
|
358
|
-
id: 'sheet-view-1',
|
|
359
|
-
originClientId: null,
|
|
360
|
-
sheetTab: null,
|
|
361
|
-
structureOps: null,
|
|
362
|
-
},
|
|
363
|
-
},
|
|
364
|
-
makeQuery('editSheetCommandBatch', [
|
|
365
|
-
makeFragmentSpread('sheetViewPatchFragment'),
|
|
366
|
-
]),
|
|
367
|
-
);
|
|
368
|
-
|
|
369
|
-
assertDeepEqual(
|
|
370
|
-
loadFragment('$sheetViewFragment:sheet-view-1'),
|
|
371
|
-
{
|
|
372
|
-
axisMoveOps: null,
|
|
373
|
-
id: 'sheet-view-1',
|
|
374
|
-
originClientId: null,
|
|
375
|
-
sheetTab: { id: 'tab-1', title: 'Tab 1' },
|
|
376
|
-
structureOps: null,
|
|
377
|
-
},
|
|
378
|
-
'partial SheetView patches should preserve stateful null fields only',
|
|
379
|
-
);
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
Deno.test('updateFragment callback receives cleaned optimistic array fields', () => {
|
|
383
|
-
resetCacheState();
|
|
384
|
-
|
|
385
|
-
const sheetQuery = makeQuery('workbookSnapshot', [
|
|
386
|
-
makeFragmentSpread('sheetFragment'),
|
|
387
|
-
makeField('tabs', [makeFragmentSpread('sheetTabFragment')]),
|
|
388
|
-
]);
|
|
389
|
-
const sheet = {
|
|
390
|
-
id: 'sheet-optimistic-callback',
|
|
391
|
-
title: 'Sheet',
|
|
392
|
-
tabs: [
|
|
393
|
-
{
|
|
394
|
-
id: 'tab-1',
|
|
395
|
-
sheetId: 'sheet-optimistic-callback',
|
|
396
|
-
name: 'tab_1',
|
|
397
|
-
},
|
|
398
|
-
],
|
|
399
|
-
};
|
|
400
|
-
const optimisticTab = {
|
|
401
|
-
id: 'temp-tab-1',
|
|
402
|
-
sheetId: 'sheet-optimistic-callback',
|
|
403
|
-
name: 'saving',
|
|
404
|
-
__optimisticPlaceholder: true,
|
|
405
|
-
};
|
|
406
|
-
const nextOptimisticTab = {
|
|
407
|
-
id: 'temp-tab-2',
|
|
408
|
-
sheetId: 'sheet-optimistic-callback',
|
|
409
|
-
name: 'still_saving',
|
|
410
|
-
__optimisticPlaceholder: true,
|
|
411
|
-
};
|
|
412
|
-
let callbackTabs: any[] = [];
|
|
413
|
-
|
|
414
|
-
setDataToCache({ workbookSnapshot: sheet }, sheetQuery);
|
|
415
|
-
updateFragment(
|
|
416
|
-
'$sheetFragment:sheet-optimistic-callback',
|
|
417
|
-
(currentSheet: any) => ({
|
|
418
|
-
tabs: [...currentSheet.tabs, optimisticTab],
|
|
419
|
-
}),
|
|
420
|
-
);
|
|
421
|
-
updateFragment(
|
|
422
|
-
'$sheetFragment:sheet-optimistic-callback',
|
|
423
|
-
(currentSheet: any) => {
|
|
424
|
-
callbackTabs = currentSheet.tabs;
|
|
425
|
-
|
|
426
|
-
return {
|
|
427
|
-
tabs: [...currentSheet.tabs, nextOptimisticTab],
|
|
428
|
-
};
|
|
429
|
-
},
|
|
430
|
-
);
|
|
431
|
-
|
|
432
|
-
assertDeepEqual(
|
|
433
|
-
callbackTabs,
|
|
434
|
-
sheet.tabs,
|
|
435
|
-
'updateFragment callback should receive tabs without previous optimistic objects',
|
|
436
|
-
);
|
|
437
|
-
assertDeepEqual(
|
|
438
|
-
loadFragment('$sheetFragment:sheet-optimistic-callback')?.tabs,
|
|
439
|
-
[...sheet.tabs, nextOptimisticTab],
|
|
440
|
-
'loadFragment should return newly added optimistic tab after callback update',
|
|
441
|
-
);
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
Deno.test('updateFragment direct object preserves current optimistic placeholders', () => {
|
|
445
|
-
resetCacheState();
|
|
446
|
-
|
|
447
|
-
const sheetQuery = makeQuery('workbookSnapshot', [
|
|
448
|
-
makeFragmentSpread('sheetFragment'),
|
|
449
|
-
makeField('tabs', [makeFragmentSpread('sheetTabFragment')]),
|
|
450
|
-
]);
|
|
451
|
-
const sheet = {
|
|
452
|
-
id: 'sheet-optimistic-direct',
|
|
453
|
-
title: 'Sheet',
|
|
454
|
-
tabs: [
|
|
455
|
-
{
|
|
456
|
-
id: 'tab-1',
|
|
457
|
-
sheetId: 'sheet-optimistic-direct',
|
|
458
|
-
name: 'tab_1',
|
|
459
|
-
},
|
|
460
|
-
],
|
|
461
|
-
};
|
|
462
|
-
const optimisticTab = {
|
|
463
|
-
id: 'temp-tab',
|
|
464
|
-
sheetId: 'sheet-optimistic-direct',
|
|
465
|
-
name: 'saving',
|
|
466
|
-
__optimisticPlaceholder: true,
|
|
467
|
-
};
|
|
468
|
-
|
|
469
|
-
setDataToCache({ workbookSnapshot: sheet }, sheetQuery);
|
|
470
|
-
updateFragment('$sheetFragment:sheet-optimistic-direct', {
|
|
471
|
-
tabs: [...sheet.tabs, optimisticTab],
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
assertDeepEqual(
|
|
475
|
-
loadFragment('$sheetFragment:sheet-optimistic-direct')?.tabs,
|
|
476
|
-
[...sheet.tabs, optimisticTab],
|
|
477
|
-
'direct update object should preserve optimistic objects included in the current update',
|
|
478
|
-
);
|
|
479
|
-
|
|
480
|
-
updateFragment('$sheetFragment:sheet-optimistic-direct', {
|
|
481
|
-
title: 'Updated Sheet',
|
|
482
|
-
});
|
|
483
|
-
|
|
484
|
-
assertDeepEqual(
|
|
485
|
-
loadFragment('$sheetFragment:sheet-optimistic-direct')?.tabs,
|
|
486
|
-
sheet.tabs,
|
|
487
|
-
'next normal updateFragment call should clean previous optimistic objects',
|
|
488
|
-
);
|
|
489
|
-
});
|
|
490
|
-
|
|
491
|
-
Deno.test('authoritative fragment writes remove or replace optimistic placeholders by id', () => {
|
|
492
|
-
resetCacheState();
|
|
493
|
-
|
|
494
|
-
const sheetQuery = makeQuery('workbookSnapshot', [
|
|
495
|
-
makeFragmentSpread('sheetFragment'),
|
|
496
|
-
makeField('tabs', [makeFragmentSpread('sheetTabFragment')]),
|
|
497
|
-
]);
|
|
498
|
-
const sheetVariables = { sheetId: 'sheet-optimistic-authoritative' };
|
|
499
|
-
const sheet = {
|
|
500
|
-
id: 'sheet-optimistic-authoritative',
|
|
501
|
-
title: 'Sheet',
|
|
502
|
-
tabs: [
|
|
503
|
-
{
|
|
504
|
-
id: 'tab-1',
|
|
505
|
-
sheetId: 'sheet-optimistic-authoritative',
|
|
506
|
-
name: 'tab_1',
|
|
507
|
-
},
|
|
508
|
-
],
|
|
509
|
-
};
|
|
510
|
-
const optimisticMatchedTab = {
|
|
511
|
-
id: 'tab-2',
|
|
512
|
-
sheetId: 'sheet-optimistic-authoritative',
|
|
513
|
-
name: 'saving_tab_2',
|
|
514
|
-
__optimisticPlaceholder: true,
|
|
515
|
-
};
|
|
516
|
-
const optimisticUnmatchedTab = {
|
|
517
|
-
id: 'temp-tab',
|
|
518
|
-
sheetId: 'sheet-optimistic-authoritative',
|
|
519
|
-
name: 'saving_temp',
|
|
520
|
-
__optimisticPlaceholder: true,
|
|
521
|
-
};
|
|
522
|
-
const realSheet = {
|
|
523
|
-
...sheet,
|
|
524
|
-
tabs: [
|
|
525
|
-
{
|
|
526
|
-
id: 'tab-1',
|
|
527
|
-
sheetId: 'sheet-optimistic-authoritative',
|
|
528
|
-
name: 'tab_1',
|
|
529
|
-
},
|
|
530
|
-
{
|
|
531
|
-
id: 'tab-2',
|
|
532
|
-
sheetId: 'sheet-optimistic-authoritative',
|
|
533
|
-
name: 'real_tab_2',
|
|
534
|
-
},
|
|
535
|
-
],
|
|
536
|
-
};
|
|
537
|
-
|
|
538
|
-
setDataToCache({ workbookSnapshot: sheet }, sheetQuery, sheetVariables);
|
|
539
|
-
updateFragment(
|
|
540
|
-
'$sheetFragment:sheet-optimistic-authoritative',
|
|
541
|
-
(currentSheet: any) => ({
|
|
542
|
-
tabs: [
|
|
543
|
-
...currentSheet.tabs,
|
|
544
|
-
optimisticMatchedTab,
|
|
545
|
-
optimisticUnmatchedTab,
|
|
546
|
-
],
|
|
547
|
-
}),
|
|
548
|
-
);
|
|
549
|
-
setDataToCache({ workbookSnapshot: realSheet }, sheetQuery, sheetVariables);
|
|
550
|
-
|
|
551
|
-
assertDeepEqual(
|
|
552
|
-
loadFragment('$sheetFragment:sheet-optimistic-authoritative')?.tabs,
|
|
553
|
-
realSheet.tabs,
|
|
554
|
-
'real spread-backed tabs should replace matching optimistic tabs and remove unmatched optimistic tabs',
|
|
555
|
-
);
|
|
556
|
-
assertDeepEqual(
|
|
557
|
-
loadDataFromCache({}, sheetQuery, makeGraphQLVariablesKey(sheetVariables)),
|
|
558
|
-
{ workbookSnapshot: realSheet },
|
|
559
|
-
'query cache should also return authoritative tabs without optimistic duplicates',
|
|
560
|
-
);
|
|
561
|
-
});
|
|
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
|
-
|
|
850
|
-
Deno.test('fetchCachedData rejects cached query data missing newly selected nested fields', () => {
|
|
851
|
-
resetCacheState();
|
|
852
|
-
|
|
853
|
-
const oldQuery = makeQuery('myOrganizations', [
|
|
854
|
-
makeField('id'),
|
|
855
|
-
makeField('organization', [makeField('id'), makeField('name')]),
|
|
856
|
-
]);
|
|
857
|
-
const newQuery = makeQuery('myOrganizations', [
|
|
858
|
-
makeField('id'),
|
|
859
|
-
makeField('organization', [
|
|
860
|
-
makeField('id'),
|
|
861
|
-
makeField('name'),
|
|
862
|
-
makeField('integrations', [makeField('id'), makeField('provider')]),
|
|
863
|
-
]),
|
|
864
|
-
]);
|
|
865
|
-
const requestData = {
|
|
866
|
-
myOrganizations: [
|
|
867
|
-
{
|
|
868
|
-
id: 'rel-1',
|
|
869
|
-
organization: {
|
|
870
|
-
id: 'org-1',
|
|
871
|
-
name: 'Marketday',
|
|
872
|
-
},
|
|
873
|
-
},
|
|
874
|
-
],
|
|
875
|
-
};
|
|
876
|
-
|
|
877
|
-
setDataToCache(requestData, oldQuery);
|
|
878
|
-
|
|
879
|
-
const cachedData = fetchCachedData(newQuery, makeGraphQLVariablesKey(undefined), () => {});
|
|
880
|
-
|
|
881
|
-
assertDeepEqual(
|
|
882
|
-
cachedData,
|
|
883
|
-
null,
|
|
884
|
-
'cached query data should be invalidated when the current query asks for missing fields',
|
|
885
|
-
);
|
|
886
|
-
});
|
|
887
|
-
|
|
888
|
-
Deno.test('fetchCachedData ignores nonmatching inline fragments for union data', () => {
|
|
889
|
-
resetCacheState();
|
|
890
|
-
|
|
891
|
-
const gqlQuery = makeQuery(
|
|
892
|
-
'activityEntries',
|
|
893
|
-
[
|
|
894
|
-
makeField('id'),
|
|
895
|
-
makeField('details', [
|
|
896
|
-
makeInlineFragment('ActivityDetail', [
|
|
897
|
-
makeFragmentSpread('activityDetailFragment'),
|
|
898
|
-
]),
|
|
899
|
-
makeInlineFragment('InvoiceDetail', [
|
|
900
|
-
makeFragmentSpread('invoiceDetailFragment'),
|
|
901
|
-
]),
|
|
902
|
-
]),
|
|
903
|
-
],
|
|
904
|
-
[
|
|
905
|
-
makeFragmentDefinition('activityDetailFragment', [
|
|
906
|
-
makeField('__typename'),
|
|
907
|
-
makeField('id'),
|
|
908
|
-
makeField('activity'),
|
|
909
|
-
]),
|
|
910
|
-
makeFragmentDefinition('invoiceDetailFragment', [
|
|
911
|
-
makeField('__typename'),
|
|
912
|
-
makeField('id'),
|
|
913
|
-
makeField('invoiceNumber'),
|
|
914
|
-
]),
|
|
915
|
-
],
|
|
916
|
-
);
|
|
917
|
-
const requestData = {
|
|
918
|
-
activityEntries: [
|
|
919
|
-
{
|
|
920
|
-
id: 'log-1',
|
|
921
|
-
details: {
|
|
922
|
-
__typename: 'ActivityDetail',
|
|
923
|
-
id: 'log-1',
|
|
924
|
-
activity: 'SEEDING',
|
|
925
|
-
},
|
|
926
|
-
},
|
|
927
|
-
],
|
|
928
|
-
};
|
|
929
|
-
|
|
930
|
-
setDataToCache(requestData, gqlQuery);
|
|
931
|
-
|
|
932
|
-
const cachedData = fetchCachedData(gqlQuery, makeGraphQLVariablesKey(undefined), () => {});
|
|
933
|
-
|
|
934
|
-
assertDeepEqual(
|
|
935
|
-
cachedData,
|
|
936
|
-
requestData,
|
|
937
|
-
'cached union data should only require fields for the matching inline fragment type',
|
|
938
|
-
);
|
|
939
|
-
});
|
|
940
|
-
|
|
941
|
-
Deno.test('resetQuery reset-only clears matching query cache and notifies observers without force refetch', () => {
|
|
942
|
-
resetCacheState();
|
|
943
|
-
|
|
944
|
-
const gqlQuery = makeQuery('logEntries', [makeField('id'), makeField('status')]);
|
|
945
|
-
const variablesKey = makeGraphQLVariablesKey({
|
|
946
|
-
organizationId: 'org-1',
|
|
947
|
-
});
|
|
948
|
-
const requestData = {
|
|
949
|
-
logEntries: [
|
|
950
|
-
{
|
|
951
|
-
id: 'log-1',
|
|
952
|
-
status: 'COMPLETED',
|
|
953
|
-
},
|
|
954
|
-
],
|
|
955
|
-
};
|
|
956
|
-
const observerArgs: any[] = [];
|
|
957
|
-
|
|
958
|
-
setDataToCache(requestData, gqlQuery, variablesKey);
|
|
959
|
-
resetQuery(
|
|
960
|
-
'#logEntries:',
|
|
961
|
-
false,
|
|
962
|
-
(args) => {
|
|
963
|
-
observerArgs.push(args);
|
|
964
|
-
},
|
|
965
|
-
true,
|
|
966
|
-
);
|
|
967
|
-
|
|
968
|
-
const cachedData = fetchCachedData(gqlQuery, variablesKey, () => {});
|
|
969
|
-
|
|
970
|
-
assertDeepEqual(
|
|
971
|
-
observerArgs,
|
|
972
|
-
[
|
|
973
|
-
{
|
|
974
|
-
queryId: '#logEntries:',
|
|
975
|
-
forceRefetch: false,
|
|
976
|
-
resetOnly: true,
|
|
977
|
-
},
|
|
978
|
-
],
|
|
979
|
-
'reset-only should notify mounted query observers without force refetch',
|
|
980
|
-
);
|
|
981
|
-
assertDeepEqual(
|
|
982
|
-
cachedData,
|
|
983
|
-
null,
|
|
984
|
-
'reset-only should remove matching cached query data',
|
|
985
|
-
);
|
|
986
|
-
});
|
|
987
|
-
|
|
988
|
-
Deno.test('getNextQueryLastUpdatedCount acknowledges one external force refetch after a missing cache', () => {
|
|
989
|
-
resetCacheState();
|
|
990
|
-
|
|
991
|
-
const acknowledgedCount = getNextQueryLastUpdatedCount(0, 7, 0);
|
|
992
|
-
const repeatedAcknowledgement = getNextQueryLastUpdatedCount(
|
|
993
|
-
acknowledgedCount,
|
|
994
|
-
7,
|
|
995
|
-
0,
|
|
996
|
-
);
|
|
997
|
-
const ownObserverAcknowledgement = getNextQueryLastUpdatedCount(
|
|
998
|
-
acknowledgedCount,
|
|
999
|
-
7,
|
|
1000
|
-
1,
|
|
1001
|
-
);
|
|
1002
|
-
|
|
1003
|
-
assertDeepEqual(
|
|
1004
|
-
acknowledgedCount,
|
|
1005
|
-
7,
|
|
1006
|
-
'external force-refetch observers should be acknowledged even without a cached query result',
|
|
1007
|
-
);
|
|
1008
|
-
assertDeepEqual(
|
|
1009
|
-
repeatedAcknowledgement,
|
|
1010
|
-
7,
|
|
1011
|
-
'the same external force-refetch observer should not advance after it has been acknowledged',
|
|
1012
|
-
);
|
|
1013
|
-
assertDeepEqual(
|
|
1014
|
-
ownObserverAcknowledgement,
|
|
1015
|
-
8,
|
|
1016
|
-
'query writes observed during the request should still advance the acknowledged count once',
|
|
1017
|
-
);
|
|
1018
|
-
});
|
|
1019
|
-
|
|
1020
|
-
Deno.test('structured reset force-refetch marks only matching scoped query variables', () => {
|
|
1021
|
-
resetCacheState();
|
|
1022
|
-
|
|
1023
|
-
const gqlQuery = makeQuery('tabScopedSnapshot', [
|
|
1024
|
-
makeField('id'),
|
|
1025
|
-
makeField('sheetId'),
|
|
1026
|
-
makeField('sheetTabId'),
|
|
1027
|
-
]);
|
|
1028
|
-
const matchingVariables = {
|
|
1029
|
-
organizationId: 'org-1',
|
|
1030
|
-
sheetId: 'sheet-1',
|
|
1031
|
-
sheetTabId: 'tab-1',
|
|
1032
|
-
};
|
|
1033
|
-
const otherTabVariables = {
|
|
1034
|
-
organizationId: 'org-1',
|
|
1035
|
-
sheetId: 'sheet-1',
|
|
1036
|
-
sheetTabId: 'tab-2',
|
|
1037
|
-
};
|
|
1038
|
-
const matchingVariablesKey = makeGraphQLVariablesKey(matchingVariables);
|
|
1039
|
-
const otherTabVariablesKey = makeGraphQLVariablesKey(otherTabVariables);
|
|
1040
|
-
const observerArgs: any[] = [];
|
|
1041
|
-
|
|
1042
|
-
setDataToCache(
|
|
1043
|
-
{
|
|
1044
|
-
tabScopedSnapshot: {
|
|
1045
|
-
id: 'tab-1',
|
|
1046
|
-
sheetId: 'sheet-1',
|
|
1047
|
-
sheetTabId: 'tab-1',
|
|
1048
|
-
},
|
|
1049
|
-
},
|
|
1050
|
-
gqlQuery,
|
|
1051
|
-
matchingVariables,
|
|
1052
|
-
);
|
|
1053
|
-
setDataToCache(
|
|
1054
|
-
{
|
|
1055
|
-
tabScopedSnapshot: {
|
|
1056
|
-
id: 'tab-2',
|
|
1057
|
-
sheetId: 'sheet-1',
|
|
1058
|
-
sheetTabId: 'tab-2',
|
|
1059
|
-
},
|
|
1060
|
-
},
|
|
1061
|
-
gqlQuery,
|
|
1062
|
-
otherTabVariables,
|
|
1063
|
-
);
|
|
1064
|
-
|
|
1065
|
-
resetQueryByTarget(
|
|
1066
|
-
makeQueryResetTarget('tabScopedSnapshot', matchingVariables),
|
|
1067
|
-
true,
|
|
1068
|
-
(args) => {
|
|
1069
|
-
observerArgs.push(args);
|
|
1070
|
-
},
|
|
1071
|
-
);
|
|
1072
|
-
|
|
1073
|
-
assertDeepEqual(
|
|
1074
|
-
observerArgs,
|
|
1075
|
-
[
|
|
1076
|
-
{
|
|
1077
|
-
queryId: getQueryResetTargetId(
|
|
1078
|
-
makeQueryResetTarget('tabScopedSnapshot', matchingVariables),
|
|
1079
|
-
),
|
|
1080
|
-
queryTarget: makeQueryResetTarget(
|
|
1081
|
-
'tabScopedSnapshot',
|
|
1082
|
-
matchingVariables,
|
|
1083
|
-
),
|
|
1084
|
-
forceRefetch: true,
|
|
1085
|
-
},
|
|
1086
|
-
],
|
|
1087
|
-
'structured reset should notify only queries matching organizationId, sheetId, and sheetTabId',
|
|
1088
|
-
);
|
|
1089
|
-
assertDeepEqual(
|
|
1090
|
-
Boolean(getQueryRefreshTime('tabScopedSnapshot', matchingVariablesKey)),
|
|
1091
|
-
true,
|
|
1092
|
-
'matching scoped query should be marked for one force refetch',
|
|
1093
|
-
);
|
|
1094
|
-
assertDeepEqual(
|
|
1095
|
-
getQueryRefreshTime('tabScopedSnapshot', otherTabVariablesKey),
|
|
1096
|
-
undefined,
|
|
1097
|
-
'nonmatching scoped query should not be marked for refetch',
|
|
1098
|
-
);
|
|
1099
|
-
});
|
|
1100
|
-
|
|
1101
|
-
Deno.test('root field aliases share the operation response cache key', () => {
|
|
1102
|
-
resetCacheState();
|
|
1103
|
-
const gqlQuery = makeQuery('dataTableRowsSnapshot', [
|
|
1104
|
-
makeField('dataTableId'),
|
|
1105
|
-
makeField('currentSeq'),
|
|
1106
|
-
]);
|
|
1107
|
-
const rootSelection = gqlQuery.definitions[0].selectionSet.selections[0];
|
|
1108
|
-
rootSelection.alias = { value: 'rowsSnapshotAlias' };
|
|
1109
|
-
const variables = { dataTableId: 'table-1' };
|
|
1110
|
-
|
|
1111
|
-
setDataToCache(
|
|
1112
|
-
{
|
|
1113
|
-
rowsSnapshotAlias: {
|
|
1114
|
-
dataTableId: 'table-1',
|
|
1115
|
-
currentSeq: '4',
|
|
1116
|
-
},
|
|
1117
|
-
},
|
|
1118
|
-
gqlQuery,
|
|
1119
|
-
variables,
|
|
1120
|
-
);
|
|
1121
|
-
|
|
1122
|
-
assertDeepEqual(
|
|
1123
|
-
fetchCachedData(gqlQuery, makeGraphQLVariablesKey(variables)),
|
|
1124
|
-
{
|
|
1125
|
-
rowsSnapshotAlias: {
|
|
1126
|
-
dataTableId: 'table-1',
|
|
1127
|
-
currentSeq: '4',
|
|
1128
|
-
},
|
|
1129
|
-
},
|
|
1130
|
-
'aliased root fields should read and write under their response key',
|
|
1131
|
-
);
|
|
1132
|
-
});
|
|
1133
|
-
|
|
1134
|
-
Deno.test('persisted private cache is bound to a live authorization epoch', async () => {
|
|
1135
|
-
const persistenceRuntime = await Deno.readTextFile(
|
|
1136
|
-
new URL('./persist.ts', import.meta.url),
|
|
1137
|
-
);
|
|
1138
|
-
const authFragmentRuntime = await Deno.readTextFile(
|
|
1139
|
-
new URL('../gql/fragments/accountAuthFragments.ts', import.meta.url),
|
|
1140
|
-
);
|
|
1141
|
-
|
|
1142
|
-
assertDeepEqual(
|
|
1143
|
-
[
|
|
1144
|
-
persistenceRuntime.includes('cacheAuthorizationEpoch: string | null;'),
|
|
1145
|
-
persistenceRuntime.includes('contextAllowsPersistence(context)'),
|
|
1146
|
-
persistenceRuntime.includes('(meta.cacheAuthorizationEpoch ?? null) ==='),
|
|
1147
|
-
persistenceRuntime.includes(
|
|
1148
|
-
'(ACTIVE_CONTEXT.cacheAuthorizationEpoch ?? null) ===',
|
|
1149
|
-
),
|
|
1150
|
-
authFragmentRuntime.includes('cacheAuthorizationEpoch'),
|
|
1151
|
-
],
|
|
1152
|
-
[true, true, true, true, true],
|
|
1153
|
-
'private persistence must fail closed and match the server authorization epoch',
|
|
1154
|
-
);
|
|
1155
|
-
});
|
|
1156
|
-
|
|
1157
|
-
Deno.test('appended query list survives a stale flat fragment spread copy', () => {
|
|
1158
|
-
resetCacheState();
|
|
1159
|
-
|
|
1160
|
-
const aiChatQuery = makeQuery('aiChat', [
|
|
1161
|
-
makeFragmentSpread('aiChatFragment'),
|
|
1162
|
-
makeField('messages', [makeFragmentSpread('aiChatMessageFragment')]),
|
|
1163
|
-
]);
|
|
1164
|
-
const chatVariables = { aiChatId: 'chat-1' };
|
|
1165
|
-
const firstMessage = { id: 'msg-1', text: 'first' };
|
|
1166
|
-
const secondMessage = { id: 'msg-2', text: 'second' };
|
|
1167
|
-
const appendedMessage = { id: 'msg-3', text: 'appended' };
|
|
1168
|
-
|
|
1169
|
-
// The response normalizes messages into the query cache AND leaves a
|
|
1170
|
-
// point-in-time copy on the chat fragment's spreads
|
|
1171
|
-
setDataToCache(
|
|
1172
|
-
{
|
|
1173
|
-
aiChat: {
|
|
1174
|
-
id: 'chat-1',
|
|
1175
|
-
summary: 'Chat',
|
|
1176
|
-
messages: [firstMessage, secondMessage],
|
|
1177
|
-
},
|
|
1178
|
-
},
|
|
1179
|
-
aiChatQuery,
|
|
1180
|
-
chatVariables,
|
|
1181
|
-
);
|
|
1182
|
-
|
|
1183
|
-
// A sent message reaches the query cache only, exactly like the send
|
|
1184
|
-
// mutation and the realtime QUERY_APPEND event
|
|
1185
|
-
addFragmentToCache('$aiChatMessageFragment:msg-3', appendedMessage);
|
|
1186
|
-
updateQuery(
|
|
1187
|
-
`#aiChat:${makeGraphQLVariablesKey(chatVariables)}`,
|
|
1188
|
-
(currentData: any) => ({
|
|
1189
|
-
...currentData,
|
|
1190
|
-
messages: {
|
|
1191
|
-
...currentData.messages,
|
|
1192
|
-
data: [...currentData.messages.data, ['$aiChatMessageFragment:msg-3']],
|
|
1193
|
-
},
|
|
1194
|
-
}),
|
|
1195
|
-
true,
|
|
1196
|
-
);
|
|
1197
|
-
|
|
1198
|
-
assertDeepEqual(
|
|
1199
|
-
loadDataFromCache({}, aiChatQuery, makeGraphQLVariablesKey(chatVariables)),
|
|
1200
|
-
{
|
|
1201
|
-
aiChat: {
|
|
1202
|
-
id: 'chat-1',
|
|
1203
|
-
summary: 'Chat',
|
|
1204
|
-
messages: [firstMessage, secondMessage, appendedMessage],
|
|
1205
|
-
},
|
|
1206
|
-
},
|
|
1207
|
-
'query cache list must keep appended items instead of reverting to the flat fragment copy',
|
|
1208
|
-
);
|
|
1209
|
-
});
|