@jsb188/graphql 1.1.10 → 1.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/cache/config.ts +64 -50
  2. package/cache/index.test.ts +671 -109
  3. package/cache/index.ts +1700 -1240
  4. package/cache/persist.ts +721 -0
  5. package/cache/store.ts +437 -0
  6. package/client/data-table-realtime-subscriptions.test.ts +740 -0
  7. package/client/data-table-realtime-subscriptions.ts +955 -0
  8. package/client/data-table-realtime.test.ts +792 -0
  9. package/client/data-table-realtime.ts +1218 -0
  10. package/client/fragment-realtime-sequence.ts +52 -0
  11. package/client/index.ts +2 -0
  12. package/client/open-sheet.ts +137 -0
  13. package/client/request-managed-session.test.ts +574 -0
  14. package/client/request-no-store.test.ts +157 -0
  15. package/client/request.ts +954 -163
  16. package/client/sse-ticket.test.ts +26 -0
  17. package/deno.lock +170 -0
  18. package/deno.test.json +8 -4
  19. package/drafts/index.ts +149 -0
  20. package/drafts/store.ts +397 -0
  21. package/gql/eagerQueryMap.ts +12 -0
  22. package/gql/fragments/accountAuthFragments.ts +5 -0
  23. package/gql/fragments/accountFragments.ts +0 -3
  24. package/gql/fragments/accountSessionFragments.ts +16 -0
  25. package/gql/fragments/agentDocFragments.ts +46 -0
  26. package/gql/fragments/agentMemoryFragments.ts +19 -0
  27. package/gql/fragments/aiChatFragments.ts +16 -0
  28. package/gql/fragments/billingFragments.ts +0 -11
  29. package/gql/fragments/campaignFragments.ts +277 -0
  30. package/gql/fragments/dataTableFragments.ts +18 -128
  31. package/gql/fragments/emailFragments.ts +19 -9
  32. package/gql/fragments/fieldDocFragments.ts +82 -0
  33. package/gql/fragments/logFragments.ts +20 -79
  34. package/gql/fragments/organizationFragments.ts +43 -5
  35. package/gql/fragments/scheduleFragments.ts +155 -0
  36. package/gql/fragments/sheetFragments.ts +552 -22
  37. package/gql/fragments/storageFragments.ts +21 -0
  38. package/gql/fragments/workflowFragments.ts +28 -4
  39. package/gql/mutations/accountMutations.ts +0 -2
  40. package/gql/mutations/agentDocMutations.ts +177 -0
  41. package/gql/mutations/agentMemoryMutations.ts +36 -0
  42. package/gql/mutations/aiChatMutations.ts +17 -4
  43. package/gql/mutations/authMutations.ts +158 -17
  44. package/gql/mutations/campaignMutations.ts +215 -0
  45. package/gql/mutations/dataTableMutations.ts +48 -26
  46. package/gql/mutations/fieldDocMutations.ts +24 -0
  47. package/gql/mutations/index.ts +6 -1
  48. package/gql/mutations/logMutations.ts +6 -29
  49. package/gql/mutations/organizationMutations.ts +13 -4
  50. package/gql/mutations/scheduleMutations.ts +423 -0
  51. package/gql/mutations/sheetMutations.ts +273 -56
  52. package/gql/mutations/storageMutations.ts +20 -0
  53. package/gql/mutations/workflowMutations.ts +42 -0
  54. package/gql/queries/agentDocQueries.ts +120 -0
  55. package/gql/queries/agentMemoryQueries.ts +22 -0
  56. package/gql/queries/aiChatQueries.ts +18 -2
  57. package/gql/queries/authQueries.ts +41 -0
  58. package/gql/queries/billingQueries.ts +23 -0
  59. package/gql/queries/campaignQueries.ts +127 -0
  60. package/gql/queries/dataTableQueries.ts +100 -11
  61. package/gql/queries/emailQueries.ts +55 -3
  62. package/gql/queries/fieldDocQueries.ts +158 -0
  63. package/gql/queries/index.ts +8 -2
  64. package/gql/queries/logQueries.ts +11 -28
  65. package/gql/queries/organizationQueries.ts +52 -1
  66. package/gql/queries/scheduleQueries.ts +315 -0
  67. package/gql/queries/sheetQueries.ts +336 -25
  68. package/gql/queries/storageQueries.ts +38 -0
  69. package/gql/queries/workflowQueries.ts +72 -3
  70. package/hooks/index.ts +2065 -971
  71. package/hooks/use-account-mtn.ts +76 -81
  72. package/hooks/use-agentDoc-mtn.ts +285 -0
  73. package/hooks/use-agentDoc-qry.ts +208 -0
  74. package/hooks/use-agentMemory-mtn.ts +73 -0
  75. package/hooks/use-agentMemory-qry.ts +44 -0
  76. package/hooks/use-aiChat-mtn.ts +232 -137
  77. package/hooks/use-aiChat-qry.ts +480 -222
  78. package/hooks/use-app-qry.ts +12 -9
  79. package/hooks/use-auth-mtn.ts +406 -252
  80. package/hooks/use-auth-qry.ts +51 -0
  81. package/hooks/use-campaign-mtn.ts +377 -0
  82. package/hooks/use-campaign-qry.ts +257 -0
  83. package/hooks/use-dataTable-mtn.ts +116 -33
  84. package/hooks/use-dataTable-qry.ts +859 -35
  85. package/hooks/use-email-qry.ts +194 -79
  86. package/hooks/use-fieldDoc-mtn.ts +50 -0
  87. package/hooks/use-fieldDoc-qry.ts +180 -0
  88. package/hooks/use-inboundContact-mtn.ts +19 -16
  89. package/hooks/use-inboundContact-qry.ts +63 -55
  90. package/hooks/use-integration-mtn.ts +56 -38
  91. package/hooks/use-integration-qry.ts +24 -9
  92. package/hooks/use-log-mtn.ts +72 -56
  93. package/hooks/use-log-qry.ts +93 -69
  94. package/hooks/use-organization-mtn.ts +334 -277
  95. package/hooks/use-organization-qry.ts +199 -129
  96. package/hooks/use-schedule-mtn.ts +416 -0
  97. package/hooks/use-schedule-qry.ts +157 -0
  98. package/hooks/use-sheet-mtn.ts +233 -47
  99. package/hooks/use-sheet-qry.ts +353 -70
  100. package/hooks/use-storage-mtn.ts +81 -41
  101. package/hooks/use-storage-qry.ts +104 -13
  102. package/hooks/use-workflow-mtn.ts +55 -0
  103. package/hooks/use-workflow-qry.ts +206 -48
  104. package/loaders/campaign.ts +137 -0
  105. package/package.json +94 -71
  106. package/sse.ts +157 -104
  107. package/tsconfig.json +11 -10
  108. package/types.d.ts +60 -30
  109. package/utils.ts +78 -49
  110. package/gql/fragments/productFragments.ts +0 -39
  111. package/gql/fragments/reportFragments.ts +0 -90
  112. package/gql/mutations/billingMutations.ts +0 -34
  113. package/gql/queries/productQueries.ts +0 -31
  114. package/gql/queries/reportQueries.ts +0 -134
  115. package/hooks/use-product-qry.ts +0 -67
  116. package/hooks/use-report-qry.ts +0 -153
@@ -1,44 +1,91 @@
1
- import { makeVariablesKey } from '@jsb188/app/utils/logic.ts';
2
- import { useQuery, useReactiveFragment, useReactiveFragmentMap } from '@jsb188/graphql/client';
3
- import { sheetGridQry, sheetQry, sheetsQry } from '../gql/queries/sheetQueries.ts';
4
- import type { UseQueryParams } from '../types.d.ts';
5
-
6
- export type SheetGridViewportVariables = {
7
- startRowIndex: number;
8
- startColumnIndex: number;
9
- rowCount: number;
10
- columnCount: number;
1
+ import {
2
+ graphqlRequestNoStore,
3
+ useQuery,
4
+ useReactiveFragment,
5
+ useReactiveFragmentMap,
6
+ } from '@jsb188/graphql/client';
7
+ import { GRID_ITEM_LIST_LIMIT } from '@jsb188/mday/constants/sheet.ts';
8
+ import type { DataTableRowGQL } from '@jsb188/mday/types/dataTable.d.ts';
9
+ import type {
10
+ GridItemSortEnum,
11
+ SheetGridViewportObj,
12
+ SheetJournalSeqInput,
13
+ SheetOperationalHistoryGQL,
14
+ } from '@jsb188/mday/types/sheet.d.ts';
15
+ import { normalizeSheetJournalSeq } from '@jsb188/mday/utils/sheetSequence.ts';
16
+ import {
17
+ FRAGMENT_NAMES,
18
+ getFragmentBaseName,
19
+ makeFragmentKey,
20
+ } from '@jsb188/mday/constants/graphqlReactivity.ts';
21
+ import { useEffect, useMemo, useRef, useState } from 'react';
22
+ import { fetchOpenSheetOnce } from '../client/open-sheet.ts';
23
+ import {
24
+ sheetAccessGrantsQry,
25
+ sheetAccessQry,
26
+ sheetOperationalHistoryQry,
27
+ sheetRegionSourcePreviewRowsQry,
28
+ sheetsQry,
29
+ sheetTabChangesQry,
30
+ } from '../gql/queries/sheetQueries.ts';
31
+ import type { PaginationArgs, UseQueryParams } from '../types.d.ts';
32
+
33
+ export {
34
+ fetchOpenSheetOnce,
35
+ getOpenSheetQueryVariables,
36
+ } from '../client/open-sheet.ts';
37
+
38
+ export type SheetsVariables = PaginationArgs & {
39
+ organizationId?: string | null;
40
+ sort?: GridItemSortEnum | null;
11
41
  };
12
42
 
13
43
  /*
14
- * Return the query key that belongs to one sheet grid variables key.
44
+ * Add front-end deleted status to trashed Sheet records.
15
45
  */
16
46
 
17
- function getSheetGridQueryKey(variablesKey: string) {
18
- return `#sheetGrid:${variablesKey}`;
47
+ function mapSheetDeletedStatus(sheet: any) {
48
+ if (!sheet || sheet.__deleted || !sheet.deletedAt) {
49
+ return sheet;
50
+ }
51
+
52
+ return {
53
+ ...sheet,
54
+ __deleted: true,
55
+ };
19
56
  }
20
57
 
21
58
  /*
22
- * Merge reactive SheetCell fragments back into a sheetGrid viewport.
59
+ * Return whether one useSheets input is the paginated variables object.
23
60
  */
61
+ function isSheetsVariables(
62
+ value: string | null | undefined | SheetsVariables,
63
+ ): value is SheetsVariables {
64
+ return !!value && typeof value === 'object';
65
+ }
24
66
 
25
- function mergeReactiveCellsIntoSheetGrid(sheetGrid?: any | null, sheetGridCells?: any[] | null) {
26
- if (!sheetGrid || !sheetGridCells) {
27
- return sheetGrid;
28
- }
29
-
30
- if (sheetGridCells === sheetGrid.cells && !sheetGridCells.some((cell) => cell?.__deleted)) {
31
- return sheetGrid;
32
- }
33
-
34
- const nextCells = sheetGridCells.filter((cell) => !cell?.__deleted);
35
- if (nextCells.length === sheetGrid.cells?.length && nextCells.every((cell, index) => cell === sheetGrid.cells[index])) {
36
- return sheetGrid;
67
+ /*
68
+ * Return GraphQL variables for the paginated sheets query.
69
+ */
70
+ function getSheetsQueryVariables(
71
+ organizationIdOrVariables?: string | null | SheetsVariables,
72
+ ): SheetsVariables {
73
+ if (isSheetsVariables(organizationIdOrVariables)) {
74
+ return {
75
+ ...organizationIdOrVariables,
76
+ after: organizationIdOrVariables.after ?? true,
77
+ cursor: organizationIdOrVariables.cursor ?? null,
78
+ limit: organizationIdOrVariables.limit ?? GRID_ITEM_LIST_LIMIT,
79
+ sort: organizationIdOrVariables.sort || 'UPDATED_AT_DESC',
80
+ };
37
81
  }
38
82
 
39
83
  return {
40
- ...sheetGrid,
41
- cells: nextCells,
84
+ organizationId: organizationIdOrVariables,
85
+ after: true,
86
+ cursor: null,
87
+ limit: GRID_ITEM_LIST_LIMIT,
88
+ sort: 'UPDATED_AT_DESC',
42
89
  };
43
90
  }
44
91
 
@@ -47,111 +94,347 @@ function mergeReactiveCellsIntoSheetGrid(sheetGrid?: any | null, sheetGridCells?
47
94
  */
48
95
 
49
96
  export function useSheets(
50
- organizationId?: string | null,
51
- active?: boolean | null,
97
+ organizationId?: string | null | SheetsVariables,
52
98
  params: UseQueryParams = {},
53
99
  ) {
100
+ const variables = getSheetsQueryVariables(organizationId);
54
101
  const { data, ...rest } = useQuery(sheetsQry, {
102
+ variables,
103
+ skip: !variables.organizationId,
104
+ ...params,
105
+ });
106
+ const sheets = useReactiveFragmentMap(
107
+ data?.sheets || null,
108
+ getFragmentBaseName(FRAGMENT_NAMES.sheet),
109
+ );
110
+ const sheetsWithDeletedStatus = useMemo(
111
+ () => sheets?.map(mapSheetDeletedStatus) || sheets,
112
+ [sheets],
113
+ );
114
+
115
+ return {
116
+ sheets: sheetsWithDeletedStatus,
117
+ ...rest,
118
+ };
119
+ }
120
+
121
+ /*
122
+ * Fetch source rows for an unsaved generated Sheet region preview.
123
+ */
124
+ export function useSheetRegionSourcePreviewRows(
125
+ organizationId?: string | null,
126
+ region?: Record<string, any> | null,
127
+ limit?: number | null,
128
+ params: UseQueryParams = {},
129
+ ) {
130
+ const variables = {
131
+ organizationId,
132
+ region,
133
+ limit,
134
+ };
135
+ const { data, ...rest } = useQuery(sheetRegionSourcePreviewRowsQry, {
136
+ variables,
137
+ ...params,
138
+ skip: !organizationId || !region || !limit || Boolean(params.skip),
139
+ });
140
+
141
+ return {
142
+ sheetRegionSourcePreviewRows:
143
+ (data?.sheetRegionSourcePreviewRows as DataTableRowGQL[] | null) || null,
144
+ ...rest,
145
+ };
146
+ }
147
+
148
+ /*
149
+ * Fetch one sheet's viewer-specific access facts (works signed out).
150
+ */
151
+
152
+ export function useSheetAccess(
153
+ sheetId?: string | null,
154
+ params: UseQueryParams = {},
155
+ authorizationScopeId?: string | null,
156
+ ) {
157
+ const { data, ...rest } = useQuery(sheetAccessQry, {
55
158
  variables: {
56
- organizationId,
57
- active,
159
+ // Not consumed by GraphQL; it isolates viewer-specific client cache and
160
+ // in-flight keys while preserving sheetId for targeted cache resets.
161
+ authorizationScopeId: authorizationScopeId || null,
162
+ sheetId,
58
163
  },
59
- skip: !organizationId,
60
164
  ...params,
165
+ skip: !sheetId || !!params.skip,
61
166
  });
62
167
 
63
168
  return {
64
- sheets: data?.sheets,
169
+ sheetAccess: data?.sheetAccess || null,
65
170
  ...rest,
66
171
  };
67
172
  }
68
173
 
69
174
  /*
70
- * Fetch one sheet by id.
175
+ * Keep viewer-specific Sheet access live after an openSheet bootstrap. The
176
+ * initial refetch is intentionally effect-driven so it never blocks bootstrap
177
+ * paint; subsequent server RESET_ONLY events are handled by useQuery.
71
178
  */
72
-
73
- export function useSheet(
179
+ export function useSheetAccessMonitor(
74
180
  sheetId?: string | null,
181
+ enabled: boolean = true,
182
+ monitorScopeId: string = '',
183
+ ) {
184
+ const activeSheetId = enabled ? String(sheetId || '') : '';
185
+ const refreshKey = activeSheetId
186
+ ? JSON.stringify([activeSheetId, monitorScopeId])
187
+ : '';
188
+ const [monitorState, setMonitorState] = useState<{
189
+ key: string;
190
+ status: 'READY' | 'ERROR';
191
+ }>({ key: '', status: 'ERROR' });
192
+ const query = useSheetAccess(
193
+ sheetId,
194
+ {
195
+ skip: !enabled,
196
+ onCompleted: () => {
197
+ setMonitorState({ key: refreshKey, status: 'READY' });
198
+ },
199
+ onError: () => {
200
+ setMonitorState({ key: refreshKey, status: 'ERROR' });
201
+ },
202
+ },
203
+ monitorScopeId,
204
+ );
205
+ const refetchRef = useRef<(() => Promise<any>) | null>(null);
206
+ const refreshedSheetIdRef = useRef('');
207
+ refetchRef.current = query.refetch as unknown as () => Promise<any>;
208
+
209
+ useEffect(() => {
210
+ if (!refreshKey || refreshedSheetIdRef.current === refreshKey) {
211
+ return;
212
+ }
213
+ let cancelled = false;
214
+
215
+ queueMicrotask(async () => {
216
+ if (cancelled) {
217
+ return;
218
+ }
219
+ refreshedSheetIdRef.current = refreshKey;
220
+ const response = await refetchRef.current?.();
221
+ if (!cancelled) {
222
+ setMonitorState({
223
+ key: refreshKey,
224
+ status: response?.error ? 'ERROR' : 'READY',
225
+ });
226
+ }
227
+ });
228
+
229
+ return () => {
230
+ cancelled = true;
231
+ };
232
+ }, [refreshKey]);
233
+
234
+ const monitorSettled = monitorState.key === refreshKey;
235
+ return {
236
+ ...query,
237
+ loading: enabled && !monitorSettled ? true : query.loading,
238
+ sheetAccess:
239
+ monitorSettled && monitorState.status === 'READY'
240
+ ? query.sheetAccess
241
+ : null,
242
+ };
243
+ }
244
+
245
+ /*
246
+ * Fetch one sheet's access grants list (owner-org members only), used by
247
+ * the access settings screen alongside the Sheet fragment's base policy.
248
+ */
249
+
250
+ export function useSheetAccessGrants(
75
251
  organizationId?: string | null,
252
+ sheetId?: string | null,
76
253
  params: UseQueryParams = {},
77
254
  ) {
78
- const { data, ...rest } = useQuery(sheetQry, {
255
+ const { data, ...rest } = useQuery(sheetAccessGrantsQry, {
79
256
  variables: {
80
257
  organizationId,
81
258
  sheetId,
82
259
  },
83
- skip: !organizationId || !sheetId,
84
260
  ...params,
261
+ skip: !organizationId || !sheetId || !!params.skip,
85
262
  });
86
263
 
87
264
  return {
88
- sheet: data?.sheet,
265
+ sheetAccessGrants: data?.sheetAccessGrants || null,
89
266
  ...rest,
90
267
  };
91
268
  }
92
269
 
270
+ /*
271
+ * Prefetch one authoritative openSheet payload without storing the raw
272
+ * transport response in the normalized query cache.
273
+ */
274
+ export function prefetchOpenSheet(
275
+ sheetId: string,
276
+ params: {
277
+ authToken?: string | null;
278
+ selectedTabId: string;
279
+ sinceSeq?: string | null;
280
+ baseSnapshotSeq?: string | null;
281
+ baseSnapshotEncodingVersion?: number | null;
282
+ baseSnapshotChecksum?: string | null;
283
+ viewport?: SheetGridViewportObj | null;
284
+ },
285
+ ) {
286
+ return fetchOpenSheetOnce(sheetId, {
287
+ selectedTabId: params.selectedTabId,
288
+ sinceSeq: params.sinceSeq,
289
+ baseSnapshotSeq: params.baseSnapshotSeq,
290
+ baseSnapshotEncodingVersion: params.baseSnapshotEncodingVersion,
291
+ baseSnapshotChecksum: params.baseSnapshotChecksum,
292
+ viewport: params.viewport,
293
+ authToken: params.authToken,
294
+ });
295
+ }
296
+
93
297
  /*
94
298
  * Get reactive Sheet fragment.
95
299
  */
96
300
 
97
- export function useReactiveSheetFragment(sheetId: string, currentData?: any, queryCount?: number) {
98
- return useReactiveFragment(
301
+ export function useReactiveSheetFragment(
302
+ sheetId: string,
303
+ currentData?: any,
304
+ queryCount?: number,
305
+ ) {
306
+ const sheet = useReactiveFragment(
99
307
  currentData,
100
- [`$sheetFragment:${sheetId}`],
308
+ sheetId ? [makeFragmentKey(FRAGMENT_NAMES.sheet, sheetId)] : [],
309
+ queryCount,
310
+ );
311
+ const reactiveTabs = useReactiveFragmentMap(
312
+ Array.isArray(sheet?.tabs) ? sheet.tabs : null,
313
+ getFragmentBaseName(FRAGMENT_NAMES.sheetTab),
101
314
  queryCount,
102
315
  );
316
+ const sheetWithDeletedStatus = useMemo(
317
+ () =>
318
+ mapSheetDeletedStatus(
319
+ sheet && reactiveTabs
320
+ ? {
321
+ ...sheet,
322
+ tabs: reactiveTabs.filter((tab: any) => !tab?.__deleted),
323
+ }
324
+ : sheet,
325
+ ),
326
+ [reactiveTabs, sheet],
327
+ );
328
+
329
+ return sheetWithDeletedStatus;
103
330
  }
104
331
 
105
332
  /*
106
- * Get reactive SheetGrid fragment.
333
+ * Get reactive SheetCell fragments.
107
334
  */
335
+ export function useReactiveSheetCells(cells?: any[] | null) {
336
+ return useReactiveFragmentMap(
337
+ cells || null,
338
+ getFragmentBaseName(FRAGMENT_NAMES.sheetCell),
339
+ );
340
+ }
108
341
 
109
- export function useReactiveSheetGridFragment(sheetGridId: string, currentData?: any, queryCount?: number) {
342
+ /*
343
+ * Get one background sheet import job's reactive status fragment. The server
344
+ * emits $sheetImportJobFragment updates to the requesting account as the
345
+ * import job progresses and finishes.
346
+ */
347
+ export function useReactiveSheetImportJobFragment(
348
+ importJobId: string,
349
+ currentData?: any,
350
+ ) {
110
351
  return useReactiveFragment(
111
352
  currentData,
112
- sheetGridId ? [`$sheetGridFragment:${sheetGridId}`] : [],
113
- queryCount,
353
+ importJobId
354
+ ? [makeFragmentKey(FRAGMENT_NAMES.sheetImportJob, importJobId)]
355
+ : [],
114
356
  );
115
357
  }
116
358
 
117
359
  /*
118
- * Get reactive SheetGrid cell fragments.
360
+ * Return the reactive fragment key carrying realtime sheetView cell deltas
361
+ * for one sheet view ({ id, cellsDelta, deletedCellCoords } patches).
119
362
  */
120
-
121
- export function useReactiveSheetGridCells(sheetGrid?: any | null) {
122
- const reactiveCells = useReactiveFragmentMap(sheetGrid?.cells || null, 'sheetCellFragment');
123
-
124
- return mergeReactiveCellsIntoSheetGrid(sheetGrid, reactiveCells);
363
+ export function getSheetViewFragmentKey(sheetViewId: string) {
364
+ return makeFragmentKey(FRAGMENT_NAMES.sheetView, sheetViewId);
125
365
  }
126
366
 
127
367
  /*
128
- * Fetch one sheet viewport by id.
368
+ * Imperatively fetch one Sheet tab's journal tail (every change after the
369
+ * client's last-seen seq) to close a detected realtime seq gap without a full
370
+ * authoritative tab snapshot. Returns the raw sheetTabChanges result or null;
371
+ * tailAvailable: false means the caller must request a new snapshot.
372
+ *
373
+ * This path deliberately bypasses query/fragment caches and the shared
374
+ * in-flight request map. Recovery cursors are one-shot values, and requests
375
+ * carrying distinct auth tokens must never share a promise.
129
376
  */
130
377
 
131
- export function useSheetGrid(
132
- sheetId?: string | null,
133
- organizationId?: string | null,
134
- viewport?: SheetGridViewportVariables | null,
135
- params: UseQueryParams = {},
136
- ) {
378
+ export async function fetchSheetTabChangesTail(
379
+ organizationId: string,
380
+ sheetId: string,
381
+ sheetTabId: string,
382
+ afterSeq: SheetJournalSeqInput,
383
+ params: {
384
+ authToken?: string | null;
385
+ } = {},
386
+ ): Promise<any> {
137
387
  const variables = {
138
388
  organizationId,
139
389
  sheetId,
140
- viewport,
390
+ sheetTabId,
391
+ afterSeq: normalizeSheetJournalSeq(afterSeq),
392
+ };
393
+
394
+ const result = (await graphqlRequestNoStore(sheetTabChangesQry, variables, {
395
+ authToken: params.authToken,
396
+ })) as { sheetTabChanges?: any; error?: unknown } | null;
397
+ if (result?.error) {
398
+ return null;
399
+ }
400
+
401
+ return result?.sheetTabChanges || null;
402
+ }
403
+
404
+ /*
405
+ * Read one browser-tab session's payload-free durable undo/redo stacks.
406
+ */
407
+ export function useSheetOperationalHistoryQuery(
408
+ params: {
409
+ organizationId?: string | null;
410
+ sessionId?: string | null;
411
+ sheetId?: string | null;
412
+ sheetTabId?: string | null;
413
+ },
414
+ queryParams: UseQueryParams = {},
415
+ ) {
416
+ const variables = {
417
+ organizationId: params.organizationId,
418
+ sessionId: params.sessionId,
419
+ sheetId: params.sheetId,
420
+ sheetTabId: params.sheetTabId,
141
421
  };
142
- const { data, ...rest } = useQuery(sheetGridQry, {
422
+ const skip =
423
+ !variables.organizationId ||
424
+ !variables.sessionId ||
425
+ !variables.sheetId ||
426
+ !variables.sheetTabId ||
427
+ Boolean(queryParams.skip);
428
+ const { data, ...rest } = useQuery(sheetOperationalHistoryQry, {
429
+ ...queryParams,
143
430
  variables,
144
- skip: !organizationId || !sheetId || !viewport,
145
- ...params,
431
+ skip,
146
432
  });
147
- const variablesKey = makeVariablesKey(variables);
148
- const queryMatchesVariables = rest.queryKey === getSheetGridQueryKey(variablesKey) ||
149
- rest.variablesKey === variablesKey;
150
- const reactiveSheetGrid = useReactiveSheetGridFragment(sheetId || '', queryMatchesVariables ? data?.sheetGrid : undefined);
151
- const sheetGrid = useReactiveSheetGridCells(reactiveSheetGrid);
152
433
 
153
434
  return {
154
- sheetGrid,
435
+ sheetOperationalHistory:
436
+ (data?.sheetOperationalHistory as SheetOperationalHistoryGQL | null) ||
437
+ null,
155
438
  ...rest,
156
439
  };
157
440
  }
@@ -1,57 +1,97 @@
1
1
  import type { UseMutationParams } from '@jsb188/graphql/types.d';
2
2
  import { OpenModalPopUpFn } from '@jsb188/react/states';
3
+ import {
4
+ FRAGMENT_NAMES,
5
+ makeFragmentKey,
6
+ } from '@jsb188/mday/constants/graphqlReactivity.ts';
3
7
  import { updateFragment } from '../cache/index.ts';
4
- import { createSignedUploadUrlMtn, deleteStorageFileMtn } from '../gql/mutations/storageMutations.ts';
8
+ import {
9
+ createGeneratedFileDownloadLinkMtn,
10
+ createSignedUploadUrlMtn,
11
+ deleteStorageFileMtn,
12
+ } from '../gql/mutations/storageMutations.ts';
5
13
  import { useMutation } from './index.ts';
6
14
 
7
15
  /**
8
16
  * Get signed URL for file uploads
9
17
  */
10
18
 
11
- export function useCreateSignedUploadUrl(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
12
-
13
- const [createSignedUploadUrl, mtnValues, mtnHandlers, updateObservers] = useMutation(
14
- createSignedUploadUrlMtn,
15
- {
16
- openModalPopUp,
17
- ...params,
18
- },
19
- );
20
-
21
- return {
22
- createSignedUploadUrl,
23
- updateObservers,
24
- ...mtnValues,
25
- ...mtnHandlers,
26
- };
19
+ export function useCreateSignedUploadUrl(
20
+ params: UseMutationParams = {},
21
+ openModalPopUp?: OpenModalPopUpFn,
22
+ ) {
23
+ const [createSignedUploadUrl, mtnValues, mtnHandlers, updateObservers] =
24
+ useMutation(createSignedUploadUrlMtn, {
25
+ openModalPopUp,
26
+ ...params,
27
+ });
28
+
29
+ return {
30
+ createSignedUploadUrl,
31
+ updateObservers,
32
+ ...mtnValues,
33
+ ...mtnHandlers,
34
+ };
35
+ }
36
+
37
+ /**
38
+ * Mint (or rotate) the download link for one generated file (AI CSV export)
39
+ */
40
+
41
+ export function useCreateGeneratedFileDownloadLink(
42
+ params: UseMutationParams = {},
43
+ openModalPopUp?: OpenModalPopUpFn,
44
+ ) {
45
+ const [
46
+ createGeneratedFileDownloadLink,
47
+ mtnValues,
48
+ mtnHandlers,
49
+ updateObservers,
50
+ ] = useMutation(createGeneratedFileDownloadLinkMtn, {
51
+ openModalPopUp,
52
+ ...params,
53
+ });
54
+
55
+ return {
56
+ createGeneratedFileDownloadLink,
57
+ updateObservers,
58
+ ...mtnValues,
59
+ ...mtnHandlers,
60
+ };
27
61
  }
28
62
 
29
63
  /**
30
64
  * Delete a storage file
31
65
  */
32
66
 
33
- export function useDeleteStorageFile(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
34
-
35
- const { onCompleted, ...rest } = params;
36
- const [deleteStorageFile, mtnValues, mtnHandlers, updateObservers] = useMutation(
37
- deleteStorageFileMtn,
38
- {
39
- openModalPopUp,
40
- onCompleted: (data, dataMtnValues, variables) => {
41
- const deletedStorageId = data?.deleteStorageFile;
42
- if (deletedStorageId) {
43
- updateFragment(`$storageFileFragment:${deletedStorageId}`, { __deleted: true }, null, false, updateObservers);
44
- }
45
- onCompleted?.(data, dataMtnValues, variables);
46
- },
47
- ...rest,
48
- },
49
- );
50
-
51
- return {
52
- deleteStorageFile,
53
- updateObservers,
54
- ...mtnValues,
55
- ...mtnHandlers,
56
- };
67
+ export function useDeleteStorageFile(
68
+ params: UseMutationParams = {},
69
+ openModalPopUp?: OpenModalPopUpFn,
70
+ ) {
71
+ const { onCompleted, ...rest } = params;
72
+ const [deleteStorageFile, mtnValues, mtnHandlers, updateObservers] =
73
+ useMutation(deleteStorageFileMtn, {
74
+ openModalPopUp,
75
+ onCompleted: (data, dataMtnValues, variables) => {
76
+ const deletedStorageId = data?.deleteStorageFile;
77
+ if (deletedStorageId) {
78
+ updateFragment(
79
+ makeFragmentKey(FRAGMENT_NAMES.storageFile, deletedStorageId),
80
+ { __deleted: true },
81
+ null,
82
+ false,
83
+ updateObservers,
84
+ );
85
+ }
86
+ onCompleted?.(data, dataMtnValues, variables);
87
+ },
88
+ ...rest,
89
+ });
90
+
91
+ return {
92
+ deleteStorageFile,
93
+ updateObservers,
94
+ ...mtnValues,
95
+ ...mtnHandlers,
96
+ };
57
97
  }