@jsb188/graphql 1.1.11 → 1.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/audience.d.ts +343 -0
- package/cache/config.ts +58 -24
- package/cache/index.chat-activity.test.ts +119 -0
- package/cache/index.chat.test.ts +92 -0
- package/cache/index.helpers.ts +96 -0
- package/cache/index.regression.test.ts +149 -0
- package/cache/index.test.ts +370 -42
- package/cache/index.ts +326 -799
- package/cache/optimistic-ui-runtime.ts +46 -0
- package/cache/optimistic-ui.ts +401 -0
- package/cache/persist.ts +98 -19
- package/cache/store.ts +22 -64
- package/cache/value.helpers.ts +17 -0
- package/{drafts/store.ts → client/draft-persistence-indexed-db.ts} +19 -3
- package/{drafts/index.ts → client/draft-persistence.ts} +5 -2
- package/client/index.ts +3 -2
- package/client/request.helpers.ts +14 -0
- package/client/request.ts +130 -215
- package/deno.lock +17 -0
- package/deno.test.json +2 -0
- package/gql/fragments/agentMemoryFragments.ts +5 -1
- package/gql/fragments/agentNoteFragments.ts +150 -0
- package/gql/fragments/aiChatFragments.ts +36 -10
- package/gql/fragments/audienceFragments.ts +141 -0
- package/gql/fragments/campaignFragments.ts +415 -126
- package/gql/fragments/dataTableFragments.ts +48 -80
- package/gql/fragments/emailFragments.ts +28 -23
- package/gql/fragments/fieldDocFragments.ts +222 -40
- package/gql/fragments/inboundContactFragments.ts +2 -0
- package/gql/fragments/logFragments.ts +93 -2
- package/gql/fragments/organizationFragments.ts +10 -0
- package/gql/fragments/qrCodeFragments.ts +29 -0
- package/gql/fragments/scheduleFragments.ts +652 -140
- package/gql/fragments/sheetFragments.ts +84 -373
- package/gql/fragments/storageFragments.ts +25 -1
- package/gql/fragments/workflowFragments.ts +13 -1
- package/gql/mutations/agentMemoryMutations.ts +32 -0
- package/gql/mutations/agentNoteMutations.ts +62 -0
- package/gql/mutations/aiChatMutations.ts +36 -4
- package/gql/mutations/audienceMutations.ts +71 -0
- package/gql/mutations/authMutations.ts +45 -1
- package/gql/mutations/billingMutations.ts +24 -0
- package/gql/mutations/campaignMutations.ts +170 -127
- package/gql/mutations/contactMutations.ts +23 -0
- package/gql/mutations/dataTableMutations.ts +18 -75
- package/gql/mutations/fieldDocMutations.ts +162 -13
- package/gql/mutations/index.ts +8 -5
- package/gql/mutations/organizationMutations.ts +6 -0
- package/gql/mutations/qrCodeMutations.ts +20 -0
- package/gql/mutations/scheduleMutations.ts +1052 -354
- package/gql/mutations/sheetMutations.ts +62 -118
- package/gql/mutations/storageMutations.ts +0 -1
- package/gql/mutations/workflowMutations.ts +18 -0
- package/gql/queries/agentMemoryQueries.ts +6 -0
- package/gql/queries/agentNoteQueries.ts +89 -0
- package/gql/queries/aiChatQueries.ts +56 -4
- package/gql/queries/audienceQueries.ts +128 -0
- package/gql/queries/authQueries.ts +6 -0
- package/gql/queries/billingQueries.ts +95 -6
- package/gql/queries/campaignQueries.ts +132 -23
- package/gql/queries/dataTableQueries.ts +24 -65
- package/gql/queries/emailQueries.ts +18 -61
- package/gql/queries/emailReplyReportQueries.ts +76 -0
- package/gql/queries/fieldDocQueries.ts +100 -92
- package/gql/queries/inboundContactQueries.ts +4 -0
- package/gql/queries/index.ts +3 -1
- package/gql/queries/logQueries.ts +62 -7
- package/gql/queries/organizationQueries.ts +13 -0
- package/gql/queries/qrCodeQueries.ts +20 -0
- package/gql/queries/scheduleQueries.ts +633 -257
- package/gql/queries/sheetQueries.ts +59 -152
- package/gql/queries/workflowQueries.ts +10 -4
- package/hooks/index.helpers.test.ts +50 -0
- package/hooks/index.helpers.ts +52 -0
- package/hooks/index.ts +863 -685
- package/hooks/use-agentMemory-mtn.ts +29 -31
- package/hooks/use-agentMemory-qry.ts +15 -3
- package/hooks/use-agentNote-mtn.ts +82 -0
- package/hooks/use-agentNote-qry.ts +190 -0
- package/hooks/use-agentNote-recovery.helpers.test.ts +68 -0
- package/hooks/use-agentNote-recovery.helpers.ts +58 -0
- package/hooks/use-agentNote-recovery.ts +72 -0
- package/hooks/use-aiChat-mtn.ts +96 -112
- package/hooks/use-aiChat-qry.helpers.test.ts +63 -0
- package/hooks/use-aiChat-qry.helpers.ts +124 -0
- package/hooks/use-aiChat-qry.ts +229 -383
- package/hooks/use-aiChat-stream-mtn.ts +14 -0
- package/hooks/use-audience-mtn.ts +194 -0
- package/hooks/use-audience-qry.helpers.test.ts +80 -0
- package/hooks/use-audience-qry.helpers.ts +63 -0
- package/hooks/use-audience-qry.ts +330 -0
- package/hooks/use-auth-mtn.ts +30 -1
- package/hooks/use-billing-mtn.ts +31 -0
- package/hooks/use-billing-qry.ts +76 -0
- package/hooks/use-campaign-generation-recovery.ts +53 -0
- package/hooks/use-campaign-mtn.ts +224 -165
- package/hooks/use-campaign-qry.helpers.ts +40 -0
- package/hooks/use-campaign-qry.ts +631 -54
- package/hooks/use-dataTable-mtn.ts +23 -115
- package/hooks/use-dataTable-qry.ts +66 -916
- package/hooks/use-email-qry.helpers.ts +37 -0
- package/hooks/use-email-qry.ts +33 -178
- package/hooks/use-emailCampaignReplyReport-qry.ts +27 -0
- package/hooks/use-fieldDoc-mtn.ts +244 -32
- package/hooks/use-fieldDoc-qry.helpers.test.ts +65 -0
- package/hooks/use-fieldDoc-qry.helpers.ts +49 -0
- package/hooks/use-fieldDoc-qry.ts +134 -102
- package/hooks/use-inboundContact-qry.ts +7 -9
- package/hooks/use-log-mtn.ts +25 -12
- package/hooks/use-log-qry.ts +99 -46
- package/hooks/use-organization-qry.ts +16 -60
- package/hooks/use-publicFormEmail-mtn.ts +27 -0
- package/hooks/use-qrCode-mtn.ts +40 -0
- package/hooks/use-qrCode-qry.ts +78 -0
- package/hooks/use-schedule-mtn.ts +506 -333
- package/hooks/use-schedule-qry.ts +682 -101
- package/hooks/use-schedule-reactive.ts +486 -0
- package/hooks/use-sheet-mtn.ts +91 -199
- package/hooks/use-sheet-qry.ts +84 -238
- package/hooks/use-storage-qry.ts +84 -61
- package/hooks/use-workflow-mtn.ts +39 -22
- package/hooks/use-workflow-qry.ts +40 -61
- package/libs/ai-chat-outgoing.helpers.ts +153 -0
- package/libs/ai-chat-outgoing.ts +11 -0
- package/libs/ai-chat-outgoing.types.ts +25 -0
- package/libs/ai-chat-run-realtime.ts +20 -0
- package/libs/ai-chat-submission-realtime.ts +150 -0
- package/libs/fragment-realtime-sequence.ts +55 -0
- package/libs/fragment-recovery.test.ts +326 -0
- package/libs/fragment-recovery.ts +325 -0
- package/libs/open-sheet.ts +138 -0
- package/libs/orchestrator-realtime.helpers.test.ts +229 -0
- package/libs/orchestrator-realtime.helpers.ts +317 -0
- package/libs/orchestrator-realtime.ts +433 -0
- package/libs/request-cache-regression.test.ts +122 -0
- package/{client → libs}/request-managed-session.test.ts +1 -1
- package/libs/request-no-store.test.ts +419 -0
- package/libs/sheet-command-batch.ts +44 -0
- package/libs/sheet-view-realtime-router.test.ts +214 -0
- package/libs/sheet-view-realtime-router.ts +99 -0
- package/loaders/campaign.test.ts +186 -0
- package/loaders/campaign.ts +56 -83
- package/loaders/emailPreference.ts +75 -0
- package/loaders/rest.ts +12 -0
- package/package.json +42 -17
- package/schedule.d.ts +1790 -0
- package/sse.helpers.ts +19 -0
- package/sse.ts +26 -115
- package/tests/agent-note-detail-cache.test.ts +120 -0
- package/tests/agent-note-search.test.ts +444 -0
- package/types.d.ts +46 -25
- package/client/data-table-realtime-subscriptions.test.ts +0 -740
- package/client/data-table-realtime-subscriptions.ts +0 -955
- package/client/data-table-realtime.test.ts +0 -792
- package/client/data-table-realtime.ts +0 -1218
- package/client/fragment-realtime-sequence.ts +0 -52
- package/client/open-sheet.ts +0 -137
- package/client/request-no-store.test.ts +0 -157
- package/gql/fragments/agentDocFragments.ts +0 -46
- package/gql/fragments/billingFragments.ts +0 -14
- package/gql/mutations/agentDocMutations.ts +0 -177
- package/gql/queries/agentDocQueries.ts +0 -120
- package/hooks/use-agentDoc-mtn.ts +0 -285
- package/hooks/use-agentDoc-qry.ts +0 -208
- /package/{client → libs}/sse-ticket.test.ts +0 -0
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
import { gql } from 'graphql-tag';
|
|
2
|
-
import {
|
|
3
|
-
dataTableCellFragment,
|
|
4
|
-
dataTableRowFragment,
|
|
5
|
-
} from '../fragments/dataTableFragments.ts';
|
|
6
|
-
import {
|
|
7
|
-
sheetFragment,
|
|
8
|
-
sheetMetadataFragment,
|
|
9
|
-
sheetReferencedDataTableSchemaFragment,
|
|
10
|
-
sheetTabFragment,
|
|
11
|
-
sheetTabSummaryFragment,
|
|
12
|
-
} from '../fragments/sheetFragments.ts';
|
|
2
|
+
import { sheetFragment, sheetMetadataFragment, sheetTabFragment, sheetTabSummaryFragment } from '../fragments/sheetFragments.ts';
|
|
13
3
|
|
|
14
4
|
export const sheetsQry = gql`
|
|
15
5
|
query sheets (
|
|
@@ -68,29 +58,6 @@ query sheetAccess (
|
|
|
68
58
|
}
|
|
69
59
|
`;
|
|
70
60
|
|
|
71
|
-
export const sheetRegionSourcePreviewRowsQry = gql`
|
|
72
|
-
query sheetRegionSourcePreviewRows (
|
|
73
|
-
$organizationId: GenericID!
|
|
74
|
-
$region: SheetRegionInput!
|
|
75
|
-
$limit: Int!
|
|
76
|
-
) {
|
|
77
|
-
sheetRegionSourcePreviewRows (
|
|
78
|
-
organizationId: $organizationId
|
|
79
|
-
region: $region
|
|
80
|
-
limit: $limit
|
|
81
|
-
) {
|
|
82
|
-
...dataTableRowFragment
|
|
83
|
-
|
|
84
|
-
cells {
|
|
85
|
-
...dataTableCellFragment
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
${dataTableRowFragment}
|
|
91
|
-
${dataTableCellFragment}
|
|
92
|
-
`;
|
|
93
|
-
|
|
94
61
|
// NOTE: sheetAccessGrants is owner-org only: the access settings screen
|
|
95
62
|
// loads the grants list with it, on top of the base policy carried by the
|
|
96
63
|
// Sheet fragment's "access" selection.
|
|
@@ -111,28 +78,24 @@ query sheetAccessGrants (
|
|
|
111
78
|
}
|
|
112
79
|
`;
|
|
113
80
|
|
|
114
|
-
// NOTE: openSheet is the page-bootstrap contract. It derives the
|
|
115
|
-
// from sheetId, folds viewer access into the response, and
|
|
116
|
-
//
|
|
81
|
+
// NOTE: openSheet is the page-bootstrap contract (contract 4). It derives the
|
|
82
|
+
// owner org from sheetId, folds viewer access into the response, and serves a
|
|
83
|
+
// DELTA after the client's applied sinceSeq or a SNAPSHOT plus its tail (with
|
|
84
|
+
// the topology rows the image absorbed after sinceSeq, so pending work
|
|
85
|
+
// re-maps through them).
|
|
117
86
|
|
|
118
87
|
export const openSheetQry = gql`
|
|
119
88
|
query openSheet (
|
|
120
89
|
$sheetId: GenericID!
|
|
121
90
|
$selectedTabId: GenericID
|
|
122
91
|
$sinceSeq: BigInt
|
|
123
|
-
$
|
|
124
|
-
$baseSnapshotEncodingVersion: Int
|
|
125
|
-
$baseSnapshotChecksum: String
|
|
126
|
-
$viewport: SheetGridViewportInput
|
|
92
|
+
$requireSnapshot: Boolean
|
|
127
93
|
) {
|
|
128
94
|
openSheet (
|
|
129
95
|
sheetId: $sheetId
|
|
130
96
|
selectedTabId: $selectedTabId
|
|
131
97
|
sinceSeq: $sinceSeq
|
|
132
|
-
|
|
133
|
-
baseSnapshotEncodingVersion: $baseSnapshotEncodingVersion
|
|
134
|
-
baseSnapshotChecksum: $baseSnapshotChecksum
|
|
135
|
-
viewport: $viewport
|
|
98
|
+
requireSnapshot: $requireSnapshot
|
|
136
99
|
) {
|
|
137
100
|
access {
|
|
138
101
|
sheetId
|
|
@@ -143,7 +106,7 @@ query openSheet (
|
|
|
143
106
|
}
|
|
144
107
|
|
|
145
108
|
contractVersion
|
|
146
|
-
|
|
109
|
+
realtimeToken
|
|
147
110
|
status
|
|
148
111
|
unavailableReason
|
|
149
112
|
sheet {
|
|
@@ -195,39 +158,69 @@ query openSheet (
|
|
|
195
158
|
createdAt
|
|
196
159
|
}
|
|
197
160
|
|
|
198
|
-
|
|
199
|
-
|
|
161
|
+
topologyChanges {
|
|
162
|
+
sheetTabId
|
|
163
|
+
seq
|
|
164
|
+
kind
|
|
165
|
+
payload
|
|
166
|
+
commandId
|
|
200
167
|
}
|
|
168
|
+
|
|
169
|
+
topologyComplete
|
|
201
170
|
}
|
|
202
171
|
}
|
|
203
172
|
|
|
204
173
|
${sheetFragment}
|
|
205
174
|
${sheetTabFragment}
|
|
206
175
|
${sheetTabSummaryFragment}
|
|
207
|
-
${sheetReferencedDataTableSchemaFragment}
|
|
208
176
|
`;
|
|
209
177
|
|
|
210
|
-
// NOTE:
|
|
211
|
-
//
|
|
178
|
+
// NOTE: renewSheetRealtimeCapability re-runs openSheet's authorization over a
|
|
179
|
+
// fence-only read and returns fresh signed capabilities, never workbook data.
|
|
180
|
+
// It is fetched no-store only: bearer tokens must stay out of the cache.
|
|
181
|
+
|
|
182
|
+
export const renewSheetRealtimeCapabilityQry = gql`
|
|
183
|
+
query renewSheetRealtimeCapability (
|
|
184
|
+
$sheetId: GenericID!
|
|
185
|
+
) {
|
|
186
|
+
renewSheetRealtimeCapability (
|
|
187
|
+
sheetId: $sheetId
|
|
188
|
+
) {
|
|
189
|
+
access {
|
|
190
|
+
sheetId
|
|
191
|
+
organizationId
|
|
192
|
+
canView
|
|
193
|
+
canEdit
|
|
194
|
+
signInRequired
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
status
|
|
198
|
+
unavailableReason
|
|
199
|
+
realtimeToken
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
`;
|
|
203
|
+
|
|
204
|
+
// NOTE: syncSheetTab is the tab-only snapshot/delta negotiation (contract 3)
|
|
205
|
+
// used once the workbook manifest is known: a gap, a selection or a
|
|
206
|
+
// watermark catch-up asks for the rows after the tab's applied sinceSeq.
|
|
212
207
|
|
|
213
|
-
export const
|
|
214
|
-
query
|
|
208
|
+
export const syncSheetTabQry = gql`
|
|
209
|
+
query syncSheetTab (
|
|
215
210
|
$sheetId: GenericID!
|
|
216
211
|
$sheetTabId: GenericID!
|
|
217
212
|
$sinceSeq: BigInt
|
|
218
|
-
$
|
|
219
|
-
$
|
|
220
|
-
$
|
|
221
|
-
$viewport: SheetGridViewportInput
|
|
213
|
+
$requireSnapshot: Boolean
|
|
214
|
+
$minimumCellsRevision: BigInt
|
|
215
|
+
$minimumDesignRevision: BigInt
|
|
222
216
|
) {
|
|
223
|
-
|
|
217
|
+
syncSheetTab (
|
|
224
218
|
sheetId: $sheetId
|
|
225
219
|
sheetTabId: $sheetTabId
|
|
226
220
|
sinceSeq: $sinceSeq
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
viewport: $viewport
|
|
221
|
+
requireSnapshot: $requireSnapshot
|
|
222
|
+
minimumCellsRevision: $minimumCellsRevision
|
|
223
|
+
minimumDesignRevision: $minimumDesignRevision
|
|
231
224
|
) {
|
|
232
225
|
access {
|
|
233
226
|
sheetId
|
|
@@ -238,7 +231,6 @@ query openSheetTab (
|
|
|
238
231
|
}
|
|
239
232
|
|
|
240
233
|
contractVersion
|
|
241
|
-
realtimeToken
|
|
242
234
|
status
|
|
243
235
|
unavailableReason
|
|
244
236
|
selectedTab {
|
|
@@ -282,102 +274,17 @@ query openSheetTab (
|
|
|
282
274
|
createdAt
|
|
283
275
|
}
|
|
284
276
|
|
|
285
|
-
|
|
286
|
-
...sheetReferencedDataTableSchemaFragment
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
${sheetTabFragment}
|
|
292
|
-
${sheetReferencedDataTableSchemaFragment}
|
|
293
|
-
`;
|
|
294
|
-
|
|
295
|
-
// NOTE: sheetTabChanges is the realtime gap-recovery tail read: a client that
|
|
296
|
-
// detects a seq gap in its SheetView fragment deltas fetches every journaled change
|
|
297
|
-
// after its last-seen seq and replays the JSON payloads locally instead of
|
|
298
|
-
// refetching the whole viewport. tailAvailable: false means the tail cannot
|
|
299
|
-
// be served (too long/heavy, truncated, or pre-deployment history) and the
|
|
300
|
-
// client must request a fresh authoritative tab snapshot.
|
|
301
|
-
|
|
302
|
-
export const sheetTabChangesQry = gql`
|
|
303
|
-
query sheetTabChanges (
|
|
304
|
-
$organizationId: GenericID!
|
|
305
|
-
$sheetId: GenericID!
|
|
306
|
-
$sheetTabId: GenericID!
|
|
307
|
-
$afterSeq: BigInt!
|
|
308
|
-
) {
|
|
309
|
-
sheetTabChanges (
|
|
310
|
-
organizationId: $organizationId
|
|
311
|
-
sheetId: $sheetId
|
|
312
|
-
sheetTabId: $sheetTabId
|
|
313
|
-
afterSeq: $afterSeq
|
|
314
|
-
) {
|
|
315
|
-
sheetTabId
|
|
316
|
-
currentSeq
|
|
317
|
-
tailAvailable
|
|
318
|
-
changes {
|
|
277
|
+
topologyChanges {
|
|
319
278
|
sheetTabId
|
|
320
279
|
seq
|
|
321
280
|
kind
|
|
322
281
|
payload
|
|
323
282
|
commandId
|
|
324
|
-
causationId
|
|
325
|
-
sessionId
|
|
326
|
-
commandType
|
|
327
|
-
createdAt
|
|
328
283
|
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
`;
|
|
332
284
|
|
|
333
|
-
|
|
334
|
-
// for instant replay and is scoped by the server to the authenticated actor
|
|
335
|
-
// plus this exact browser-tab session.
|
|
336
|
-
|
|
337
|
-
export const sheetOperationalHistoryQry = gql`
|
|
338
|
-
query sheetOperationalHistory (
|
|
339
|
-
$organizationId: GenericID!
|
|
340
|
-
$sheetId: GenericID!
|
|
341
|
-
$sheetTabId: GenericID!
|
|
342
|
-
$sessionId: String!
|
|
343
|
-
) {
|
|
344
|
-
sheetOperationalHistory (
|
|
345
|
-
organizationId: $organizationId
|
|
346
|
-
sheetId: $sheetId
|
|
347
|
-
sheetTabId: $sheetTabId
|
|
348
|
-
sessionId: $sessionId
|
|
349
|
-
) {
|
|
350
|
-
sheetId
|
|
351
|
-
sheetTabId
|
|
352
|
-
sessionId
|
|
353
|
-
truncated
|
|
354
|
-
incompleteBeforeBoundary
|
|
355
|
-
undo {
|
|
356
|
-
commandId
|
|
357
|
-
commandType
|
|
358
|
-
committedAt
|
|
359
|
-
resultRevision
|
|
360
|
-
resultDesignRevision
|
|
361
|
-
axisMove {
|
|
362
|
-
axis
|
|
363
|
-
sourceStartIndex
|
|
364
|
-
sourceEndIndex
|
|
365
|
-
targetStartIndex
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
redo {
|
|
369
|
-
commandId
|
|
370
|
-
commandType
|
|
371
|
-
committedAt
|
|
372
|
-
resultRevision
|
|
373
|
-
resultDesignRevision
|
|
374
|
-
axisMove {
|
|
375
|
-
axis
|
|
376
|
-
sourceStartIndex
|
|
377
|
-
sourceEndIndex
|
|
378
|
-
targetStartIndex
|
|
379
|
-
}
|
|
380
|
-
}
|
|
285
|
+
topologyComplete
|
|
381
286
|
}
|
|
382
287
|
}
|
|
288
|
+
|
|
289
|
+
${sheetTabFragment}
|
|
383
290
|
`;
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { gql } from 'graphql-tag';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { workflowFragment, workflowRunFragment } from '../fragments/workflowFragments.ts';
|
|
3
|
+
|
|
4
|
+
export const workflowQry = gql`
|
|
5
|
+
query workflow ($workflowId: GenericID!) {
|
|
6
|
+
workflow (workflowId: $workflowId) {
|
|
7
|
+
...workflowFragment
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
${workflowFragment}
|
|
11
|
+
`;
|
|
6
12
|
|
|
7
13
|
export const workflowMetadataQry = gql`
|
|
8
14
|
query workflowMetadata (
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { claimQueryActivation, getQueryActivation, type QueryActivation } from './index.helpers.ts';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Fail a lifecycle regression with its expected behavior rather than an opaque boolean mismatch.
|
|
5
|
+
*/
|
|
6
|
+
function assert(value: boolean, message: string) {
|
|
7
|
+
if (!value) throw new Error(message);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
Deno.test('a fresh cached query is checked once per mount, including Strict Mode effect replay', () => {
|
|
11
|
+
let activation: QueryActivation = { queryKey: null, checked: false };
|
|
12
|
+
activation = getQueryActivation(activation, 'logs:org1', false);
|
|
13
|
+
assert(claimQueryActivation(activation, 'logs:org1'), 'A mounted cached list must get an entry check');
|
|
14
|
+
activation = getQueryActivation(activation, 'logs:org1', false);
|
|
15
|
+
assert(!claimQueryActivation(activation, 'logs:org1'), 'Renders and effect replay must not start another request');
|
|
16
|
+
const remounted = getQueryActivation({ queryKey: null, checked: false }, 'logs:org1', false);
|
|
17
|
+
assert(claimQueryActivation(remounted, 'logs:org1'), 'Reopening the page must check even a fresh cached result');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
Deno.test('a cold load satisfies the entry check when its response populates the cache', () => {
|
|
21
|
+
const activation = getQueryActivation({ queryKey: null, checked: false }, 'emails:org1', false);
|
|
22
|
+
claimQueryActivation(activation, 'emails:org1');
|
|
23
|
+
assert(!claimQueryActivation(activation, 'emails:org1'), 'A successful cold load must not cause a second warm load');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
Deno.test('changing variables and returning to a previous scope each start a new activation', () => {
|
|
27
|
+
let activation = getQueryActivation({ queryKey: null, checked: false }, 'logs:org1', false);
|
|
28
|
+
claimQueryActivation(activation, 'logs:org1');
|
|
29
|
+
activation = getQueryActivation(activation, 'logs:org2', false);
|
|
30
|
+
assert(!claimQueryActivation(activation, 'logs:org1'), 'An old scope request must not consume the new scope check');
|
|
31
|
+
assert(claimQueryActivation(activation, 'logs:org2'), 'Changed filters or organization must check cached data');
|
|
32
|
+
activation = getQueryActivation(activation, 'logs:org1', false);
|
|
33
|
+
assert(claimQueryActivation(activation, 'logs:org1'), 'Returning to a previously visited scope must check again');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
Deno.test('skipped queries wait and reactivation checks the same variables again', () => {
|
|
37
|
+
let activation = getQueryActivation({ queryKey: null, checked: false }, 'shifts:org1', false);
|
|
38
|
+
claimQueryActivation(activation, 'shifts:org1');
|
|
39
|
+
activation = getQueryActivation(activation, 'shifts:org1', true);
|
|
40
|
+
assert(!claimQueryActivation(activation, 'shifts:org1'), 'Skipped queries must not claim a request');
|
|
41
|
+
activation = getQueryActivation(activation, 'shifts:org1', false);
|
|
42
|
+
assert(claimQueryActivation(activation, 'shifts:org1'), 'Opening a previously hidden query must check again');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
Deno.test('waiting for hydration or connection preserves an unclaimed activation', () => {
|
|
46
|
+
let activation = getQueryActivation({ queryKey: null, checked: false }, 'runs:org1', false);
|
|
47
|
+
activation = getQueryActivation(activation, 'runs:org1', false);
|
|
48
|
+
assert(!activation.checked, 'Readiness changes must not consume the pending check');
|
|
49
|
+
assert(claimQueryActivation(activation, 'runs:org1'), 'The query must still check when ready');
|
|
50
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { QUERY_EXPIRE_TIMES } from '../cache/config.ts';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Apply the same freshness boundary on mount, prefetch, focus and reconnect.
|
|
5
|
+
* Zero always refreshes; Infinity never expires a known timestamp. Missing,
|
|
6
|
+
* invalid or future timestamps require validation against the server.
|
|
7
|
+
*/
|
|
8
|
+
export function isQueryDataStale(queryName: string, fetchedAt: number | undefined, persistTime?: number, now = Date.now()): boolean {
|
|
9
|
+
if (fetchedAt === undefined || !Number.isFinite(fetchedAt) || fetchedAt > now) return true;
|
|
10
|
+
const configured = persistTime ?? QUERY_EXPIRE_TIMES[queryName] ?? QUERY_EXPIRE_TIMES.__default;
|
|
11
|
+
const freshnessWindow = Number.isNaN(configured) ? QUERY_EXPIRE_TIMES.__default : Math.max(0, configured);
|
|
12
|
+
return now - fetchedAt >= freshnessWindow;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface QueryActivation {
|
|
16
|
+
queryKey: string | null;
|
|
17
|
+
checked: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
* Start a new activation when a hook changes query scope or resumes after being skipped.
|
|
22
|
+
*/
|
|
23
|
+
export function getQueryActivation(current: QueryActivation, queryKey: string, skipped: boolean): QueryActivation {
|
|
24
|
+
const activeKey = skipped ? null : queryKey;
|
|
25
|
+
return current.queryKey === activeKey ? current : { queryKey: activeKey, checked: false };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/*
|
|
29
|
+
* Claim one entry-time cache check before starting or joining a request. Cache writes,
|
|
30
|
+
* rerenders and Strict Mode effect replay must not repeatedly refresh the same activation.
|
|
31
|
+
*/
|
|
32
|
+
export function claimQueryActivation(activation: QueryActivation, queryKey: string): boolean {
|
|
33
|
+
if (activation.queryKey !== queryKey || activation.checked) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
activation.checked = true;
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/*
|
|
41
|
+
* Bound an opted-in query's network lifetime so a hung request cannot occupy
|
|
42
|
+
* its shared in-flight slot forever. Owners clear the timer after settlement.
|
|
43
|
+
*/
|
|
44
|
+
export function startQueryRequestTimeout(controller: AbortController, timeoutMs?: number): () => void {
|
|
45
|
+
if (!timeoutMs || !Number.isFinite(timeoutMs) || timeoutMs <= 0) return () => {};
|
|
46
|
+
const timeout = globalThis.setTimeout(() => {
|
|
47
|
+
controller.abort(new DOMException('The GraphQL query exceeded its request deadline.', 'AbortError'));
|
|
48
|
+
}, timeoutMs);
|
|
49
|
+
return () => {
|
|
50
|
+
globalThis.clearTimeout(timeout);
|
|
51
|
+
};
|
|
52
|
+
}
|