@jsb188/graphql 1.1.11 → 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 +205 -0
- package/cache/config.ts +65 -28
- package/cache/index.helpers.ts +96 -0
- package/cache/index.ts +364 -808
- package/cache/mounted-queries.ts +33 -0
- package/cache/optimistic-ui-runtime.ts +46 -0
- package/cache/optimistic-ui.ts +401 -0
- package/cache/persist.ts +107 -22
- package/cache/realtime-fence.ts +47 -0
- package/cache/realtime-live.ts +17 -0
- 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} +13 -39
- package/client/index.ts +4 -2
- package/client/request.helpers.ts +14 -0
- package/client/request.ts +122 -232
- package/client/storage-asset.ts +58 -0
- package/gql/fragments/accountAuthFragments.ts +0 -4
- package/gql/fragments/agentMemoryFragments.ts +5 -1
- package/gql/fragments/agentNoteFragments.ts +156 -0
- package/gql/fragments/aiChatFragments.ts +35 -11
- package/gql/fragments/aiChatLinkFragments.ts +8 -0
- package/gql/fragments/audienceFragments.ts +76 -0
- package/gql/fragments/dataTableFragments.ts +48 -80
- package/gql/fragments/emailFragments.ts +49 -21
- package/gql/fragments/emailOutreachFragments.ts +281 -0
- package/gql/fragments/fieldDocFragments.ts +222 -40
- package/gql/fragments/inboundContactFragments.ts +2 -0
- package/gql/fragments/libraryFragments.ts +120 -0
- package/gql/fragments/logFragments.ts +93 -2
- package/gql/fragments/organizationFragments.ts +12 -0
- package/gql/fragments/qrCodeFragments.ts +29 -0
- package/gql/fragments/scheduleFragments.ts +574 -145
- package/gql/fragments/sheetFragments.ts +86 -424
- package/gql/fragments/storageFragments.ts +25 -1
- package/gql/fragments/workWaitFragments.ts +13 -0
- package/gql/fragments/workflowFragments.ts +32 -4
- package/gql/mutations/agentMemoryMutations.ts +32 -0
- package/gql/mutations/agentNoteMutations.ts +64 -0
- package/gql/mutations/aiChatLinkMutations.ts +13 -0
- package/gql/mutations/aiChatMutations.ts +34 -4
- package/gql/mutations/audienceMutations.ts +58 -0
- package/gql/mutations/authMutations.ts +24 -28
- package/gql/mutations/billingMutations.ts +24 -0
- package/gql/mutations/contactMutations.ts +23 -0
- package/gql/mutations/dataTableMutations.ts +18 -75
- package/gql/mutations/emailMutations.ts +22 -0
- package/gql/mutations/emailOutreachMutations.ts +139 -0
- package/gql/mutations/fieldDocMutations.ts +162 -13
- package/gql/mutations/index.ts +10 -5
- package/gql/mutations/organizationMutations.ts +6 -0
- package/gql/mutations/qrCodeMutations.ts +20 -0
- package/gql/mutations/scheduleMutations.ts +389 -417
- package/gql/mutations/sheetMutations.ts +62 -118
- package/gql/mutations/storageMutations.ts +1 -1
- package/gql/mutations/workflowMutations.ts +94 -0
- package/gql/queries/agentMemoryQueries.ts +12 -2
- package/gql/queries/agentNoteQueries.ts +86 -0
- package/gql/queries/aiChatQueries.ts +63 -12
- package/gql/queries/audienceQueries.ts +104 -0
- package/gql/queries/authQueries.ts +20 -4
- package/gql/queries/billingQueries.ts +114 -9
- package/gql/queries/dataTableQueries.ts +43 -75
- package/gql/queries/emailOutreachQueries.ts +282 -0
- package/gql/queries/emailQueries.ts +48 -64
- package/gql/queries/emailReplyReportQueries.ts +127 -0
- package/gql/queries/fieldDocQueries.ts +128 -98
- package/gql/queries/inboundContactQueries.ts +15 -4
- package/gql/queries/index.ts +5 -3
- package/gql/queries/libraryQueries.ts +112 -0
- package/gql/queries/logQueries.ts +86 -12
- package/gql/queries/organizationQueries.ts +44 -12
- package/gql/queries/qrCodeQueries.ts +27 -0
- package/gql/queries/scheduleQueries.ts +401 -278
- package/gql/queries/sheetQueries.ts +94 -165
- package/gql/queries/storageQueries.ts +11 -4
- package/gql/queries/workflowQueries.ts +61 -12
- package/gql/reactivity.ts +98 -0
- package/gql/recordReads.ts +171 -0
- package/hooks/index.helpers.ts +52 -0
- package/hooks/index.ts +920 -715
- package/hooks/use-agentMemory-mtn.ts +29 -31
- package/hooks/use-agentMemory-qry.ts +15 -3
- package/hooks/use-agentNote-mtn.ts +89 -0
- package/hooks/use-agentNote-qry.ts +162 -0
- package/hooks/use-agentNote-recovery.helpers.ts +58 -0
- package/hooks/use-agentNote-recovery.ts +57 -0
- package/hooks/use-aiChat-mtn.ts +104 -115
- package/hooks/use-aiChat-qry.helpers.ts +124 -0
- package/hooks/use-aiChat-qry.ts +254 -387
- package/hooks/use-aiChat-stream-mtn.ts +14 -0
- package/hooks/use-audience-mtn.ts +170 -0
- package/hooks/use-audience-qry.helpers.ts +39 -0
- package/hooks/use-audience-qry.ts +245 -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-dataTable-mtn.ts +23 -115
- package/hooks/use-dataTable-qry.ts +69 -914
- package/hooks/use-email-mtn.ts +26 -0
- package/hooks/use-email-qry.helpers.ts +37 -0
- package/hooks/use-email-qry.ts +44 -174
- 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-mtn.ts +244 -32
- 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-library-qry.ts +233 -0
- 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-qrCode-mtn.ts +40 -0
- package/hooks/use-qrCode-qry.ts +78 -0
- package/hooks/use-schedule-mtn.ts +231 -348
- package/hooks/use-schedule-qry.ts +208 -139
- package/hooks/use-schedule-reactive.ts +218 -0
- package/hooks/use-sheet-mtn.ts +91 -199
- package/hooks/use-sheet-qry.ts +88 -237
- package/hooks/use-storage-qry.ts +84 -61
- package/hooks/use-workflow-mtn.ts +84 -23
- package/hooks/use-workflow-qry.ts +60 -61
- package/libs/ai-chat-link-events.ts +78 -0
- 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/data-changes.helpers.ts +161 -0
- package/libs/data-changes.ts +382 -0
- package/libs/fragment-realtime-sequence.ts +55 -0
- package/libs/open-sheet.ts +138 -0
- package/libs/record-read.ts +327 -0
- package/libs/sheet-command-batch.ts +45 -0
- package/libs/sheet-realtime-packet.ts +53 -0
- package/libs/sheet-view-realtime-router.ts +99 -0
- package/loaders/emailPreference.ts +69 -0
- package/loaders/rest.ts +12 -0
- package/package.json +77 -25
- package/schedule.d.ts +1183 -0
- package/sse.helpers.ts +19 -0
- package/sse.ts +26 -115
- package/types.d.ts +48 -25
- package/cache/index.test.ts +0 -881
- 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-managed-session.test.ts +0 -574
- package/client/request-no-store.test.ts +0 -157
- package/client/sse-ticket.test.ts +0 -26
- package/deno.lock +0 -170
- package/deno.test.json +0 -10
- package/gql/fragments/agentDocFragments.ts +0 -46
- package/gql/fragments/billingFragments.ts +0 -14
- package/gql/fragments/campaignFragments.ts +0 -277
- package/gql/mutations/agentDocMutations.ts +0 -177
- package/gql/mutations/campaignMutations.ts +0 -215
- package/gql/queries/agentDocQueries.ts +0 -120
- package/gql/queries/appQueries.ts +0 -14
- package/gql/queries/campaignQueries.ts +0 -127
- package/hooks/use-agentDoc-mtn.ts +0 -285
- package/hooks/use-agentDoc-qry.ts +0 -208
- package/hooks/use-app-qry.ts +0 -22
- package/hooks/use-campaign-mtn.ts +0 -377
- package/hooks/use-campaign-qry.ts +0 -257
- package/loaders/campaign.ts +0 -137
- package/tsconfig.json +0 -13
package/cache/index.test.ts
DELETED
|
@@ -1,881 +0,0 @@
|
|
|
1
|
-
import { makeVariablesKey } from '@jsb188/app/utils/logic.ts';
|
|
2
|
-
import { makeQueryResetTarget } from '@jsb188/app/utils/queryReset.ts';
|
|
3
|
-
import {
|
|
4
|
-
addFragmentToCache,
|
|
5
|
-
clearGraphQLClientCache,
|
|
6
|
-
fetchCachedData,
|
|
7
|
-
loadDataFromCache,
|
|
8
|
-
loadFragment,
|
|
9
|
-
getNextQueryLastUpdatedCount,
|
|
10
|
-
getQueryRefreshTime,
|
|
11
|
-
resetQuery,
|
|
12
|
-
resetQueryByTarget,
|
|
13
|
-
setDataToCache,
|
|
14
|
-
updateFragment,
|
|
15
|
-
updateQuery,
|
|
16
|
-
} from './index.ts';
|
|
17
|
-
|
|
18
|
-
if (typeof (console as any).dev !== 'function') {
|
|
19
|
-
(console as any).dev = () => {};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Create a GraphQL field selection node for cache tests.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
function makeField(name: string, selections?: any[]) {
|
|
27
|
-
return {
|
|
28
|
-
kind: 'Field',
|
|
29
|
-
name: { value: name },
|
|
30
|
-
...(selections
|
|
31
|
-
? {
|
|
32
|
-
selectionSet: { selections },
|
|
33
|
-
}
|
|
34
|
-
: {}),
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Create a GraphQL fragment spread node for cache tests.
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
function makeFragmentSpread(name: string) {
|
|
43
|
-
return {
|
|
44
|
-
kind: 'FragmentSpread',
|
|
45
|
-
name: { value: name },
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Create a GraphQL inline fragment node for cache tests.
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
function makeInlineFragment(typeName: string, selections: any[]) {
|
|
54
|
-
return {
|
|
55
|
-
kind: 'InlineFragment',
|
|
56
|
-
typeCondition: {
|
|
57
|
-
name: { value: typeName },
|
|
58
|
-
},
|
|
59
|
-
selectionSet: { selections },
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Create a GraphQL fragment definition node for cache tests.
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
|
-
function makeFragmentDefinition(name: string, selections: any[]) {
|
|
68
|
-
return {
|
|
69
|
-
kind: 'FragmentDefinition',
|
|
70
|
-
name: { value: name },
|
|
71
|
-
selectionSet: { selections },
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Create a minimal GraphQL operation document for cache tests.
|
|
77
|
-
*/
|
|
78
|
-
|
|
79
|
-
function makeQuery(
|
|
80
|
-
queryName: string,
|
|
81
|
-
selections: any[],
|
|
82
|
-
extraDefinitions: any[] = [],
|
|
83
|
-
) {
|
|
84
|
-
return {
|
|
85
|
-
definitions: [
|
|
86
|
-
{
|
|
87
|
-
kind: 'OperationDefinition',
|
|
88
|
-
selectionSet: {
|
|
89
|
-
selections: [
|
|
90
|
-
{
|
|
91
|
-
kind: 'Field',
|
|
92
|
-
name: { value: queryName },
|
|
93
|
-
selectionSet: { selections },
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
...extraDefinitions,
|
|
99
|
-
],
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Normalize nested values into a stable structure for comparisons.
|
|
105
|
-
*/
|
|
106
|
-
|
|
107
|
-
function normalizeValue(value: unknown): unknown {
|
|
108
|
-
if (Array.isArray(value)) {
|
|
109
|
-
return value.map(normalizeValue);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (value && typeof value === 'object') {
|
|
113
|
-
return Object.keys(value as Record<string, unknown>)
|
|
114
|
-
.sort()
|
|
115
|
-
.reduce(
|
|
116
|
-
(acc, key) => {
|
|
117
|
-
acc[key] = normalizeValue((value as Record<string, unknown>)[key]);
|
|
118
|
-
return acc;
|
|
119
|
-
},
|
|
120
|
-
{} as Record<string, unknown>,
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return value;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Assert that two values are deeply equal.
|
|
129
|
-
*/
|
|
130
|
-
|
|
131
|
-
function assertDeepEqual(actual: unknown, expected: unknown, label: string) {
|
|
132
|
-
const actualJson = JSON.stringify(normalizeValue(actual));
|
|
133
|
-
const expectedJson = JSON.stringify(normalizeValue(expected));
|
|
134
|
-
|
|
135
|
-
if (actualJson !== expectedJson) {
|
|
136
|
-
throw new Error(
|
|
137
|
-
`${label}\nExpected: ${expectedJson}\nActual: ${actualJson}`,
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Reset the shared cache state before each test run.
|
|
144
|
-
*/
|
|
145
|
-
|
|
146
|
-
function resetCacheState() {
|
|
147
|
-
clearGraphQLClientCache();
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
Deno.test('loadFragment rebuilds nested list items without inner fragments', () => {
|
|
151
|
-
resetCacheState();
|
|
152
|
-
|
|
153
|
-
const gqlQuery = makeQuery('fieldDoc', [
|
|
154
|
-
makeFragmentSpread('fieldDocFragment'),
|
|
155
|
-
makeField('sections', [makeField('id'), makeField('title')]),
|
|
156
|
-
]);
|
|
157
|
-
|
|
158
|
-
const requestData = {
|
|
159
|
-
fieldDoc: {
|
|
160
|
-
id: 'fieldDoc-1',
|
|
161
|
-
title: 'Daily FieldDoc',
|
|
162
|
-
sections: [
|
|
163
|
-
{
|
|
164
|
-
id: 'section-1',
|
|
165
|
-
title: 'Overview',
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
id: 'section-2',
|
|
169
|
-
title: 'Tasks',
|
|
170
|
-
},
|
|
171
|
-
],
|
|
172
|
-
},
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
setDataToCache(requestData, gqlQuery);
|
|
176
|
-
|
|
177
|
-
const cachedFragment = loadFragment('$fieldDocFragment:fieldDoc-1');
|
|
178
|
-
|
|
179
|
-
assertDeepEqual(
|
|
180
|
-
cachedFragment,
|
|
181
|
-
requestData.fieldDoc,
|
|
182
|
-
'fragment cache should rebuild plain nested list items',
|
|
183
|
-
);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
Deno.test('loadDataFromCache preserves mixed list items with fragment refs and inline fields', () => {
|
|
187
|
-
resetCacheState();
|
|
188
|
-
|
|
189
|
-
const gqlQuery = makeQuery('fieldDoc', [
|
|
190
|
-
makeFragmentSpread('fieldDocFragment'),
|
|
191
|
-
makeField('sections', [
|
|
192
|
-
makeFragmentSpread('fieldDocSectionFragment'),
|
|
193
|
-
makeField('files', [makeField('uri')]),
|
|
194
|
-
]),
|
|
195
|
-
]);
|
|
196
|
-
|
|
197
|
-
const requestData = {
|
|
198
|
-
fieldDoc: {
|
|
199
|
-
id: 'fieldDoc-2',
|
|
200
|
-
title: 'Inspection',
|
|
201
|
-
sections: [
|
|
202
|
-
{
|
|
203
|
-
id: 'section-a',
|
|
204
|
-
title: 'Photos',
|
|
205
|
-
files: [
|
|
206
|
-
{
|
|
207
|
-
uri: '/files/a.jpg',
|
|
208
|
-
},
|
|
209
|
-
],
|
|
210
|
-
},
|
|
211
|
-
],
|
|
212
|
-
},
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
setDataToCache(requestData, gqlQuery);
|
|
216
|
-
|
|
217
|
-
const cachedData = loadDataFromCache(
|
|
218
|
-
{},
|
|
219
|
-
gqlQuery,
|
|
220
|
-
makeVariablesKey(undefined),
|
|
221
|
-
);
|
|
222
|
-
|
|
223
|
-
assertDeepEqual(
|
|
224
|
-
cachedData,
|
|
225
|
-
requestData,
|
|
226
|
-
'query cache should rebuild mixed list items from fragment and inline cache data',
|
|
227
|
-
);
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
Deno.test('loadFragment uses newest spread list after same fragment id mutation', () => {
|
|
231
|
-
resetCacheState();
|
|
232
|
-
|
|
233
|
-
const sheetQuery = makeQuery('workbookSnapshot', [
|
|
234
|
-
makeFragmentSpread('sheetFragment'),
|
|
235
|
-
makeField('tabs', [makeFragmentSpread('sheetTabFragment')]),
|
|
236
|
-
]);
|
|
237
|
-
const createSheetTabMutation = makeQuery('createSheetTab', [
|
|
238
|
-
makeFragmentSpread('sheetFragment'),
|
|
239
|
-
makeField('tabs', [makeFragmentSpread('sheetTabFragment')]),
|
|
240
|
-
]);
|
|
241
|
-
const initialSheet = {
|
|
242
|
-
id: 'sheet-1',
|
|
243
|
-
title: 'Sheet',
|
|
244
|
-
tabs: [
|
|
245
|
-
{
|
|
246
|
-
id: 'tab-1',
|
|
247
|
-
sheetId: 'sheet-1',
|
|
248
|
-
name: 'tab_1',
|
|
249
|
-
},
|
|
250
|
-
],
|
|
251
|
-
};
|
|
252
|
-
const updatedSheet = {
|
|
253
|
-
...initialSheet,
|
|
254
|
-
tabs: [
|
|
255
|
-
{
|
|
256
|
-
id: 'tab-1',
|
|
257
|
-
sheetId: 'sheet-1',
|
|
258
|
-
name: 'tab_1',
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
id: 'tab-2',
|
|
262
|
-
sheetId: 'sheet-1',
|
|
263
|
-
name: 'tab_2',
|
|
264
|
-
},
|
|
265
|
-
],
|
|
266
|
-
};
|
|
267
|
-
const sheetVariables = { sheetId: 'sheet-1' };
|
|
268
|
-
|
|
269
|
-
setDataToCache(
|
|
270
|
-
{ workbookSnapshot: initialSheet },
|
|
271
|
-
sheetQuery,
|
|
272
|
-
sheetVariables,
|
|
273
|
-
);
|
|
274
|
-
setDataToCache({ createSheetTab: updatedSheet }, createSheetTabMutation);
|
|
275
|
-
|
|
276
|
-
assertDeepEqual(
|
|
277
|
-
loadFragment('$sheetFragment:sheet-1'),
|
|
278
|
-
updatedSheet,
|
|
279
|
-
'fragment cache should rebuild same-id Sheet with newest nested tabs spread list',
|
|
280
|
-
);
|
|
281
|
-
assertDeepEqual(
|
|
282
|
-
loadDataFromCache({}, sheetQuery, makeVariablesKey(sheetVariables)),
|
|
283
|
-
{ workbookSnapshot: updatedSheet },
|
|
284
|
-
'query cache should rebuild same-id Sheet with newest nested tabs spread list',
|
|
285
|
-
);
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
Deno.test('SheetView fragment patches preserve null state fields and clear volatile fields', () => {
|
|
289
|
-
resetCacheState();
|
|
290
|
-
|
|
291
|
-
setDataToCache(
|
|
292
|
-
{
|
|
293
|
-
authoritativeTabSnapshot: {
|
|
294
|
-
axisMoveOps: [{ commandId: 'move-1' }],
|
|
295
|
-
id: 'sheet-view-1',
|
|
296
|
-
originClientId: 'old-client',
|
|
297
|
-
ranges: [{ id: 'range-1' }],
|
|
298
|
-
sheetTab: { id: 'tab-1', title: 'Tab 1' },
|
|
299
|
-
structureOps: [{ index: 2, operation: 'INSERT_ROW' }],
|
|
300
|
-
},
|
|
301
|
-
},
|
|
302
|
-
makeQuery('authoritativeTabSnapshot', [
|
|
303
|
-
makeFragmentSpread('sheetViewFragment'),
|
|
304
|
-
]),
|
|
305
|
-
);
|
|
306
|
-
setDataToCache(
|
|
307
|
-
{
|
|
308
|
-
editSheetCommandBatch: {
|
|
309
|
-
axisMoveOps: null,
|
|
310
|
-
id: 'sheet-view-1',
|
|
311
|
-
originClientId: null,
|
|
312
|
-
ranges: null,
|
|
313
|
-
sheetTab: null,
|
|
314
|
-
structureOps: null,
|
|
315
|
-
},
|
|
316
|
-
},
|
|
317
|
-
makeQuery('editSheetCommandBatch', [
|
|
318
|
-
makeFragmentSpread('sheetViewPatchFragment'),
|
|
319
|
-
]),
|
|
320
|
-
);
|
|
321
|
-
|
|
322
|
-
assertDeepEqual(
|
|
323
|
-
loadFragment('$sheetViewFragment:sheet-view-1'),
|
|
324
|
-
{
|
|
325
|
-
axisMoveOps: null,
|
|
326
|
-
id: 'sheet-view-1',
|
|
327
|
-
originClientId: null,
|
|
328
|
-
ranges: [{ id: 'range-1' }],
|
|
329
|
-
sheetTab: { id: 'tab-1', title: 'Tab 1' },
|
|
330
|
-
structureOps: null,
|
|
331
|
-
},
|
|
332
|
-
'partial SheetView patches should preserve stateful null fields only',
|
|
333
|
-
);
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
Deno.test('updateFragment callback receives cleaned optimistic array fields', () => {
|
|
337
|
-
resetCacheState();
|
|
338
|
-
|
|
339
|
-
const sheetQuery = makeQuery('workbookSnapshot', [
|
|
340
|
-
makeFragmentSpread('sheetFragment'),
|
|
341
|
-
makeField('tabs', [makeFragmentSpread('sheetTabFragment')]),
|
|
342
|
-
]);
|
|
343
|
-
const sheet = {
|
|
344
|
-
id: 'sheet-optimistic-callback',
|
|
345
|
-
title: 'Sheet',
|
|
346
|
-
tabs: [
|
|
347
|
-
{
|
|
348
|
-
id: 'tab-1',
|
|
349
|
-
sheetId: 'sheet-optimistic-callback',
|
|
350
|
-
name: 'tab_1',
|
|
351
|
-
},
|
|
352
|
-
],
|
|
353
|
-
};
|
|
354
|
-
const optimisticTab = {
|
|
355
|
-
id: 'temp-tab-1',
|
|
356
|
-
sheetId: 'sheet-optimistic-callback',
|
|
357
|
-
name: 'saving',
|
|
358
|
-
__optimisticUI: true,
|
|
359
|
-
};
|
|
360
|
-
const nextOptimisticTab = {
|
|
361
|
-
id: 'temp-tab-2',
|
|
362
|
-
sheetId: 'sheet-optimistic-callback',
|
|
363
|
-
name: 'still_saving',
|
|
364
|
-
__optimisticUI: true,
|
|
365
|
-
};
|
|
366
|
-
let callbackTabs: any[] = [];
|
|
367
|
-
|
|
368
|
-
setDataToCache({ workbookSnapshot: sheet }, sheetQuery);
|
|
369
|
-
updateFragment(
|
|
370
|
-
'$sheetFragment:sheet-optimistic-callback',
|
|
371
|
-
(currentSheet: any) => ({
|
|
372
|
-
tabs: [...currentSheet.tabs, optimisticTab],
|
|
373
|
-
}),
|
|
374
|
-
);
|
|
375
|
-
updateFragment(
|
|
376
|
-
'$sheetFragment:sheet-optimistic-callback',
|
|
377
|
-
(currentSheet: any) => {
|
|
378
|
-
callbackTabs = currentSheet.tabs;
|
|
379
|
-
|
|
380
|
-
return {
|
|
381
|
-
tabs: [...currentSheet.tabs, nextOptimisticTab],
|
|
382
|
-
};
|
|
383
|
-
},
|
|
384
|
-
);
|
|
385
|
-
|
|
386
|
-
assertDeepEqual(
|
|
387
|
-
callbackTabs,
|
|
388
|
-
sheet.tabs,
|
|
389
|
-
'updateFragment callback should receive tabs without previous optimistic objects',
|
|
390
|
-
);
|
|
391
|
-
assertDeepEqual(
|
|
392
|
-
loadFragment('$sheetFragment:sheet-optimistic-callback')?.tabs,
|
|
393
|
-
[...sheet.tabs, nextOptimisticTab],
|
|
394
|
-
'loadFragment should return newly added optimistic tab after callback update',
|
|
395
|
-
);
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
Deno.test('updateFragment direct object preserves current optimistic array objects', () => {
|
|
399
|
-
resetCacheState();
|
|
400
|
-
|
|
401
|
-
const sheetQuery = makeQuery('workbookSnapshot', [
|
|
402
|
-
makeFragmentSpread('sheetFragment'),
|
|
403
|
-
makeField('tabs', [makeFragmentSpread('sheetTabFragment')]),
|
|
404
|
-
]);
|
|
405
|
-
const sheet = {
|
|
406
|
-
id: 'sheet-optimistic-direct',
|
|
407
|
-
title: 'Sheet',
|
|
408
|
-
tabs: [
|
|
409
|
-
{
|
|
410
|
-
id: 'tab-1',
|
|
411
|
-
sheetId: 'sheet-optimistic-direct',
|
|
412
|
-
name: 'tab_1',
|
|
413
|
-
},
|
|
414
|
-
],
|
|
415
|
-
};
|
|
416
|
-
const optimisticTab = {
|
|
417
|
-
id: 'temp-tab',
|
|
418
|
-
sheetId: 'sheet-optimistic-direct',
|
|
419
|
-
name: 'saving',
|
|
420
|
-
__optimisticUI: true,
|
|
421
|
-
};
|
|
422
|
-
|
|
423
|
-
setDataToCache({ workbookSnapshot: sheet }, sheetQuery);
|
|
424
|
-
updateFragment('$sheetFragment:sheet-optimistic-direct', {
|
|
425
|
-
tabs: [...sheet.tabs, optimisticTab],
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
assertDeepEqual(
|
|
429
|
-
loadFragment('$sheetFragment:sheet-optimistic-direct')?.tabs,
|
|
430
|
-
[...sheet.tabs, optimisticTab],
|
|
431
|
-
'direct update object should preserve optimistic objects included in the current update',
|
|
432
|
-
);
|
|
433
|
-
|
|
434
|
-
updateFragment('$sheetFragment:sheet-optimistic-direct', {
|
|
435
|
-
title: 'Updated Sheet',
|
|
436
|
-
});
|
|
437
|
-
|
|
438
|
-
assertDeepEqual(
|
|
439
|
-
loadFragment('$sheetFragment:sheet-optimistic-direct')?.tabs,
|
|
440
|
-
sheet.tabs,
|
|
441
|
-
'next normal updateFragment call should clean previous optimistic objects',
|
|
442
|
-
);
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
Deno.test('authoritative fragment writes remove or replace optimistic array objects by id', () => {
|
|
446
|
-
resetCacheState();
|
|
447
|
-
|
|
448
|
-
const sheetQuery = makeQuery('workbookSnapshot', [
|
|
449
|
-
makeFragmentSpread('sheetFragment'),
|
|
450
|
-
makeField('tabs', [makeFragmentSpread('sheetTabFragment')]),
|
|
451
|
-
]);
|
|
452
|
-
const sheetVariables = { sheetId: 'sheet-optimistic-authoritative' };
|
|
453
|
-
const sheet = {
|
|
454
|
-
id: 'sheet-optimistic-authoritative',
|
|
455
|
-
title: 'Sheet',
|
|
456
|
-
tabs: [
|
|
457
|
-
{
|
|
458
|
-
id: 'tab-1',
|
|
459
|
-
sheetId: 'sheet-optimistic-authoritative',
|
|
460
|
-
name: 'tab_1',
|
|
461
|
-
},
|
|
462
|
-
],
|
|
463
|
-
};
|
|
464
|
-
const optimisticMatchedTab = {
|
|
465
|
-
id: 'tab-2',
|
|
466
|
-
sheetId: 'sheet-optimistic-authoritative',
|
|
467
|
-
name: 'saving_tab_2',
|
|
468
|
-
__optimisticUI: true,
|
|
469
|
-
};
|
|
470
|
-
const optimisticUnmatchedTab = {
|
|
471
|
-
id: 'temp-tab',
|
|
472
|
-
sheetId: 'sheet-optimistic-authoritative',
|
|
473
|
-
name: 'saving_temp',
|
|
474
|
-
__optimisticUI: true,
|
|
475
|
-
};
|
|
476
|
-
const realSheet = {
|
|
477
|
-
...sheet,
|
|
478
|
-
tabs: [
|
|
479
|
-
{
|
|
480
|
-
id: 'tab-1',
|
|
481
|
-
sheetId: 'sheet-optimistic-authoritative',
|
|
482
|
-
name: 'tab_1',
|
|
483
|
-
},
|
|
484
|
-
{
|
|
485
|
-
id: 'tab-2',
|
|
486
|
-
sheetId: 'sheet-optimistic-authoritative',
|
|
487
|
-
name: 'real_tab_2',
|
|
488
|
-
},
|
|
489
|
-
],
|
|
490
|
-
};
|
|
491
|
-
|
|
492
|
-
setDataToCache({ workbookSnapshot: sheet }, sheetQuery, sheetVariables);
|
|
493
|
-
updateFragment(
|
|
494
|
-
'$sheetFragment:sheet-optimistic-authoritative',
|
|
495
|
-
(currentSheet: any) => ({
|
|
496
|
-
tabs: [
|
|
497
|
-
...currentSheet.tabs,
|
|
498
|
-
optimisticMatchedTab,
|
|
499
|
-
optimisticUnmatchedTab,
|
|
500
|
-
],
|
|
501
|
-
}),
|
|
502
|
-
);
|
|
503
|
-
setDataToCache({ workbookSnapshot: realSheet }, sheetQuery, sheetVariables);
|
|
504
|
-
|
|
505
|
-
assertDeepEqual(
|
|
506
|
-
loadFragment('$sheetFragment:sheet-optimistic-authoritative')?.tabs,
|
|
507
|
-
realSheet.tabs,
|
|
508
|
-
'real spread-backed tabs should replace matching optimistic tabs and remove unmatched optimistic tabs',
|
|
509
|
-
);
|
|
510
|
-
assertDeepEqual(
|
|
511
|
-
loadDataFromCache({}, sheetQuery, makeVariablesKey(sheetVariables)),
|
|
512
|
-
{ workbookSnapshot: realSheet },
|
|
513
|
-
'query cache should also return authoritative tabs without optimistic duplicates',
|
|
514
|
-
);
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
Deno.test('fetchCachedData rejects cached query data missing newly selected nested fields', () => {
|
|
518
|
-
resetCacheState();
|
|
519
|
-
|
|
520
|
-
const oldQuery = makeQuery('myOrganizations', [
|
|
521
|
-
makeField('id'),
|
|
522
|
-
makeField('organization', [makeField('id'), makeField('name')]),
|
|
523
|
-
]);
|
|
524
|
-
const newQuery = makeQuery('myOrganizations', [
|
|
525
|
-
makeField('id'),
|
|
526
|
-
makeField('organization', [
|
|
527
|
-
makeField('id'),
|
|
528
|
-
makeField('name'),
|
|
529
|
-
makeField('integrations', [makeField('id'), makeField('provider')]),
|
|
530
|
-
]),
|
|
531
|
-
]);
|
|
532
|
-
const requestData = {
|
|
533
|
-
myOrganizations: [
|
|
534
|
-
{
|
|
535
|
-
id: 'rel-1',
|
|
536
|
-
organization: {
|
|
537
|
-
id: 'org-1',
|
|
538
|
-
name: 'Marketday',
|
|
539
|
-
},
|
|
540
|
-
},
|
|
541
|
-
],
|
|
542
|
-
};
|
|
543
|
-
|
|
544
|
-
setDataToCache(requestData, oldQuery);
|
|
545
|
-
|
|
546
|
-
const cachedData = fetchCachedData(
|
|
547
|
-
newQuery,
|
|
548
|
-
makeVariablesKey(undefined),
|
|
549
|
-
() => {},
|
|
550
|
-
);
|
|
551
|
-
|
|
552
|
-
assertDeepEqual(
|
|
553
|
-
cachedData,
|
|
554
|
-
null,
|
|
555
|
-
'cached query data should be invalidated when the current query asks for missing fields',
|
|
556
|
-
);
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
Deno.test('fetchCachedData ignores nonmatching inline fragments for union data', () => {
|
|
560
|
-
resetCacheState();
|
|
561
|
-
|
|
562
|
-
const gqlQuery = makeQuery(
|
|
563
|
-
'activityEntries',
|
|
564
|
-
[
|
|
565
|
-
makeField('id'),
|
|
566
|
-
makeField('details', [
|
|
567
|
-
makeInlineFragment('ActivityDetail', [
|
|
568
|
-
makeFragmentSpread('activityDetailFragment'),
|
|
569
|
-
]),
|
|
570
|
-
makeInlineFragment('InvoiceDetail', [
|
|
571
|
-
makeFragmentSpread('invoiceDetailFragment'),
|
|
572
|
-
]),
|
|
573
|
-
]),
|
|
574
|
-
],
|
|
575
|
-
[
|
|
576
|
-
makeFragmentDefinition('activityDetailFragment', [
|
|
577
|
-
makeField('__typename'),
|
|
578
|
-
makeField('id'),
|
|
579
|
-
makeField('activity'),
|
|
580
|
-
]),
|
|
581
|
-
makeFragmentDefinition('invoiceDetailFragment', [
|
|
582
|
-
makeField('__typename'),
|
|
583
|
-
makeField('id'),
|
|
584
|
-
makeField('invoiceNumber'),
|
|
585
|
-
]),
|
|
586
|
-
],
|
|
587
|
-
);
|
|
588
|
-
const requestData = {
|
|
589
|
-
activityEntries: [
|
|
590
|
-
{
|
|
591
|
-
id: 'log-1',
|
|
592
|
-
details: {
|
|
593
|
-
__typename: 'ActivityDetail',
|
|
594
|
-
id: 'log-1',
|
|
595
|
-
activity: 'SEEDING',
|
|
596
|
-
},
|
|
597
|
-
},
|
|
598
|
-
],
|
|
599
|
-
};
|
|
600
|
-
|
|
601
|
-
setDataToCache(requestData, gqlQuery);
|
|
602
|
-
|
|
603
|
-
const cachedData = fetchCachedData(
|
|
604
|
-
gqlQuery,
|
|
605
|
-
makeVariablesKey(undefined),
|
|
606
|
-
() => {},
|
|
607
|
-
);
|
|
608
|
-
|
|
609
|
-
assertDeepEqual(
|
|
610
|
-
cachedData,
|
|
611
|
-
requestData,
|
|
612
|
-
'cached union data should only require fields for the matching inline fragment type',
|
|
613
|
-
);
|
|
614
|
-
});
|
|
615
|
-
|
|
616
|
-
Deno.test('resetQuery reset-only clears matching query cache and notifies observers without force refetch', () => {
|
|
617
|
-
resetCacheState();
|
|
618
|
-
|
|
619
|
-
const gqlQuery = makeQuery('logEntries', [
|
|
620
|
-
makeField('id'),
|
|
621
|
-
makeField('status'),
|
|
622
|
-
]);
|
|
623
|
-
const variablesKey = makeVariablesKey({
|
|
624
|
-
organizationId: 'org-1',
|
|
625
|
-
});
|
|
626
|
-
const requestData = {
|
|
627
|
-
logEntries: [
|
|
628
|
-
{
|
|
629
|
-
id: 'log-1',
|
|
630
|
-
status: 'COMPLETED',
|
|
631
|
-
},
|
|
632
|
-
],
|
|
633
|
-
};
|
|
634
|
-
const observerArgs: any[] = [];
|
|
635
|
-
|
|
636
|
-
setDataToCache(requestData, gqlQuery, variablesKey);
|
|
637
|
-
resetQuery(
|
|
638
|
-
'#logEntries:',
|
|
639
|
-
false,
|
|
640
|
-
(args) => {
|
|
641
|
-
observerArgs.push(args);
|
|
642
|
-
},
|
|
643
|
-
true,
|
|
644
|
-
);
|
|
645
|
-
|
|
646
|
-
const cachedData = fetchCachedData(gqlQuery, variablesKey, () => {});
|
|
647
|
-
|
|
648
|
-
assertDeepEqual(
|
|
649
|
-
observerArgs,
|
|
650
|
-
[
|
|
651
|
-
{
|
|
652
|
-
queryId: '#logEntries:',
|
|
653
|
-
forceRefetch: false,
|
|
654
|
-
resetOnly: true,
|
|
655
|
-
},
|
|
656
|
-
],
|
|
657
|
-
'reset-only should notify mounted query observers without force refetch',
|
|
658
|
-
);
|
|
659
|
-
assertDeepEqual(
|
|
660
|
-
cachedData,
|
|
661
|
-
null,
|
|
662
|
-
'reset-only should remove matching cached query data',
|
|
663
|
-
);
|
|
664
|
-
});
|
|
665
|
-
|
|
666
|
-
Deno.test('getNextQueryLastUpdatedCount acknowledges one external force refetch after a missing cache', () => {
|
|
667
|
-
resetCacheState();
|
|
668
|
-
|
|
669
|
-
const acknowledgedCount = getNextQueryLastUpdatedCount(0, 7, 0);
|
|
670
|
-
const repeatedAcknowledgement = getNextQueryLastUpdatedCount(
|
|
671
|
-
acknowledgedCount,
|
|
672
|
-
7,
|
|
673
|
-
0,
|
|
674
|
-
);
|
|
675
|
-
const ownObserverAcknowledgement = getNextQueryLastUpdatedCount(
|
|
676
|
-
acknowledgedCount,
|
|
677
|
-
7,
|
|
678
|
-
1,
|
|
679
|
-
);
|
|
680
|
-
|
|
681
|
-
assertDeepEqual(
|
|
682
|
-
acknowledgedCount,
|
|
683
|
-
7,
|
|
684
|
-
'external force-refetch observers should be acknowledged even without a cached query result',
|
|
685
|
-
);
|
|
686
|
-
assertDeepEqual(
|
|
687
|
-
repeatedAcknowledgement,
|
|
688
|
-
7,
|
|
689
|
-
'the same external force-refetch observer should not advance after it has been acknowledged',
|
|
690
|
-
);
|
|
691
|
-
assertDeepEqual(
|
|
692
|
-
ownObserverAcknowledgement,
|
|
693
|
-
8,
|
|
694
|
-
'query writes observed during the request should still advance the acknowledged count once',
|
|
695
|
-
);
|
|
696
|
-
});
|
|
697
|
-
|
|
698
|
-
Deno.test('structured reset force-refetch marks only matching scoped query variables', () => {
|
|
699
|
-
resetCacheState();
|
|
700
|
-
|
|
701
|
-
const gqlQuery = makeQuery('tabScopedSnapshot', [
|
|
702
|
-
makeField('id'),
|
|
703
|
-
makeField('sheetId'),
|
|
704
|
-
makeField('sheetTabId'),
|
|
705
|
-
]);
|
|
706
|
-
const matchingVariables = {
|
|
707
|
-
organizationId: 'org-1',
|
|
708
|
-
sheetId: 'sheet-1',
|
|
709
|
-
sheetTabId: 'tab-1',
|
|
710
|
-
};
|
|
711
|
-
const otherTabVariables = {
|
|
712
|
-
organizationId: 'org-1',
|
|
713
|
-
sheetId: 'sheet-1',
|
|
714
|
-
sheetTabId: 'tab-2',
|
|
715
|
-
};
|
|
716
|
-
const matchingVariablesKey = makeVariablesKey(matchingVariables);
|
|
717
|
-
const otherTabVariablesKey = makeVariablesKey(otherTabVariables);
|
|
718
|
-
const observerArgs: any[] = [];
|
|
719
|
-
|
|
720
|
-
setDataToCache(
|
|
721
|
-
{
|
|
722
|
-
tabScopedSnapshot: {
|
|
723
|
-
id: 'tab-1',
|
|
724
|
-
sheetId: 'sheet-1',
|
|
725
|
-
sheetTabId: 'tab-1',
|
|
726
|
-
},
|
|
727
|
-
},
|
|
728
|
-
gqlQuery,
|
|
729
|
-
matchingVariables,
|
|
730
|
-
);
|
|
731
|
-
setDataToCache(
|
|
732
|
-
{
|
|
733
|
-
tabScopedSnapshot: {
|
|
734
|
-
id: 'tab-2',
|
|
735
|
-
sheetId: 'sheet-1',
|
|
736
|
-
sheetTabId: 'tab-2',
|
|
737
|
-
},
|
|
738
|
-
},
|
|
739
|
-
gqlQuery,
|
|
740
|
-
otherTabVariables,
|
|
741
|
-
);
|
|
742
|
-
|
|
743
|
-
resetQueryByTarget(
|
|
744
|
-
makeQueryResetTarget('tabScopedSnapshot', matchingVariables),
|
|
745
|
-
true,
|
|
746
|
-
(args) => {
|
|
747
|
-
observerArgs.push(args);
|
|
748
|
-
},
|
|
749
|
-
);
|
|
750
|
-
|
|
751
|
-
assertDeepEqual(
|
|
752
|
-
observerArgs,
|
|
753
|
-
[
|
|
754
|
-
{
|
|
755
|
-
queryId: `#tabScopedSnapshot:${matchingVariablesKey}`,
|
|
756
|
-
forceRefetch: true,
|
|
757
|
-
},
|
|
758
|
-
],
|
|
759
|
-
'structured reset should notify only queries matching organizationId, sheetId, and sheetTabId',
|
|
760
|
-
);
|
|
761
|
-
assertDeepEqual(
|
|
762
|
-
Boolean(getQueryRefreshTime('tabScopedSnapshot', matchingVariablesKey)),
|
|
763
|
-
true,
|
|
764
|
-
'matching scoped query should be marked for one force refetch',
|
|
765
|
-
);
|
|
766
|
-
assertDeepEqual(
|
|
767
|
-
getQueryRefreshTime('tabScopedSnapshot', otherTabVariablesKey),
|
|
768
|
-
undefined,
|
|
769
|
-
'nonmatching scoped query should not be marked for refetch',
|
|
770
|
-
);
|
|
771
|
-
});
|
|
772
|
-
|
|
773
|
-
Deno.test('root field aliases share the operation response cache key', () => {
|
|
774
|
-
resetCacheState();
|
|
775
|
-
const gqlQuery = makeQuery('dataTableRowsSnapshot', [
|
|
776
|
-
makeField('dataTableId'),
|
|
777
|
-
makeField('currentSeq'),
|
|
778
|
-
]);
|
|
779
|
-
const rootSelection = gqlQuery.definitions[0].selectionSet.selections[0];
|
|
780
|
-
rootSelection.alias = { value: 'rowsSnapshotAlias' };
|
|
781
|
-
const variables = { dataTableId: 'table-1' };
|
|
782
|
-
|
|
783
|
-
setDataToCache(
|
|
784
|
-
{
|
|
785
|
-
rowsSnapshotAlias: {
|
|
786
|
-
dataTableId: 'table-1',
|
|
787
|
-
currentSeq: '4',
|
|
788
|
-
},
|
|
789
|
-
},
|
|
790
|
-
gqlQuery,
|
|
791
|
-
variables,
|
|
792
|
-
);
|
|
793
|
-
|
|
794
|
-
assertDeepEqual(
|
|
795
|
-
fetchCachedData(gqlQuery, makeVariablesKey(variables)),
|
|
796
|
-
{
|
|
797
|
-
rowsSnapshotAlias: {
|
|
798
|
-
dataTableId: 'table-1',
|
|
799
|
-
currentSeq: '4',
|
|
800
|
-
},
|
|
801
|
-
},
|
|
802
|
-
'aliased root fields should read and write under their response key',
|
|
803
|
-
);
|
|
804
|
-
});
|
|
805
|
-
|
|
806
|
-
Deno.test('persisted private cache is bound to a live authorization epoch', async () => {
|
|
807
|
-
const persistenceRuntime = await Deno.readTextFile(
|
|
808
|
-
new URL('./persist.ts', import.meta.url),
|
|
809
|
-
);
|
|
810
|
-
const authFragmentRuntime = await Deno.readTextFile(
|
|
811
|
-
new URL('../gql/fragments/accountAuthFragments.ts', import.meta.url),
|
|
812
|
-
);
|
|
813
|
-
|
|
814
|
-
assertDeepEqual(
|
|
815
|
-
[
|
|
816
|
-
persistenceRuntime.includes('cacheAuthorizationEpoch: string | null;'),
|
|
817
|
-
persistenceRuntime.includes('contextAllowsPersistence(context)'),
|
|
818
|
-
persistenceRuntime.includes('(meta.cacheAuthorizationEpoch ?? null) ==='),
|
|
819
|
-
persistenceRuntime.includes(
|
|
820
|
-
'(ACTIVE_CONTEXT.cacheAuthorizationEpoch ?? null) ===',
|
|
821
|
-
),
|
|
822
|
-
authFragmentRuntime.includes('cacheAuthorizationEpoch'),
|
|
823
|
-
],
|
|
824
|
-
[true, true, true, true, true],
|
|
825
|
-
'private persistence must fail closed and match the server authorization epoch',
|
|
826
|
-
);
|
|
827
|
-
});
|
|
828
|
-
|
|
829
|
-
Deno.test('appended query list survives a stale flat fragment spread copy', () => {
|
|
830
|
-
resetCacheState();
|
|
831
|
-
|
|
832
|
-
const aiChatQuery = makeQuery('aiChat', [
|
|
833
|
-
makeFragmentSpread('aiChatFragment'),
|
|
834
|
-
makeField('messages', [makeFragmentSpread('aiChatMessageFragment')]),
|
|
835
|
-
]);
|
|
836
|
-
const chatVariables = { aiChatId: 'chat-1' };
|
|
837
|
-
const firstMessage = { id: 'msg-1', text: 'first' };
|
|
838
|
-
const secondMessage = { id: 'msg-2', text: 'second' };
|
|
839
|
-
const appendedMessage = { id: 'msg-3', text: 'appended' };
|
|
840
|
-
|
|
841
|
-
// The response normalizes messages into the query cache AND leaves a
|
|
842
|
-
// point-in-time copy on the chat fragment's spreads
|
|
843
|
-
setDataToCache(
|
|
844
|
-
{
|
|
845
|
-
aiChat: {
|
|
846
|
-
id: 'chat-1',
|
|
847
|
-
summary: 'Chat',
|
|
848
|
-
messages: [firstMessage, secondMessage],
|
|
849
|
-
},
|
|
850
|
-
},
|
|
851
|
-
aiChatQuery,
|
|
852
|
-
chatVariables,
|
|
853
|
-
);
|
|
854
|
-
|
|
855
|
-
// A sent message reaches the query cache only, exactly like the send
|
|
856
|
-
// mutation and the realtime QUERY_APPEND event
|
|
857
|
-
addFragmentToCache('$aiChatMessageFragment:msg-3', appendedMessage);
|
|
858
|
-
updateQuery(
|
|
859
|
-
`#aiChat:${makeVariablesKey(chatVariables)}`,
|
|
860
|
-
(currentData: any) => ({
|
|
861
|
-
...currentData,
|
|
862
|
-
messages: {
|
|
863
|
-
...currentData.messages,
|
|
864
|
-
data: [...currentData.messages.data, ['$aiChatMessageFragment:msg-3']],
|
|
865
|
-
},
|
|
866
|
-
}),
|
|
867
|
-
true,
|
|
868
|
-
);
|
|
869
|
-
|
|
870
|
-
assertDeepEqual(
|
|
871
|
-
loadDataFromCache({}, aiChatQuery, makeVariablesKey(chatVariables)),
|
|
872
|
-
{
|
|
873
|
-
aiChat: {
|
|
874
|
-
id: 'chat-1',
|
|
875
|
-
summary: 'Chat',
|
|
876
|
-
messages: [firstMessage, secondMessage, appendedMessage],
|
|
877
|
-
},
|
|
878
|
-
},
|
|
879
|
-
'query cache list must keep appended items instead of reverting to the flat fragment copy',
|
|
880
|
-
);
|
|
881
|
-
});
|