@jsb188/graphql 1.1.8 → 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.
- package/cache/config.ts +66 -42
- package/cache/index.test.ts +881 -0
- package/cache/index.ts +1815 -979
- package/cache/persist.ts +721 -0
- package/cache/store.ts +437 -0
- package/client/data-table-realtime-subscriptions.test.ts +740 -0
- package/client/data-table-realtime-subscriptions.ts +955 -0
- package/client/data-table-realtime.test.ts +792 -0
- package/client/data-table-realtime.ts +1218 -0
- package/client/fragment-realtime-sequence.ts +52 -0
- package/client/index.ts +4 -2
- package/client/open-sheet.ts +137 -0
- package/client/request-managed-session.test.ts +574 -0
- package/client/request-no-store.test.ts +157 -0
- package/client/request.ts +973 -143
- package/client/sse-ticket.test.ts +26 -0
- package/deno.lock +170 -0
- package/deno.test.json +10 -0
- package/drafts/index.ts +149 -0
- package/drafts/store.ts +397 -0
- package/gql/eagerQueryMap.ts +12 -0
- package/gql/fragments/accountAuthFragments.ts +5 -0
- package/gql/fragments/accountFragments.ts +1 -3
- package/gql/fragments/accountSessionFragments.ts +16 -0
- package/gql/fragments/agentDocFragments.ts +46 -0
- package/gql/fragments/agentMemoryFragments.ts +19 -0
- package/gql/fragments/aiChatFragments.ts +17 -0
- package/gql/fragments/billingFragments.ts +0 -11
- package/gql/fragments/campaignFragments.ts +277 -0
- package/gql/fragments/dataTableFragments.ts +102 -0
- package/gql/fragments/emailFragments.ts +36 -0
- package/gql/fragments/fieldDocFragments.ts +82 -0
- package/gql/fragments/inboundContactFragments.ts +15 -0
- package/gql/fragments/integrationFragments.ts +22 -0
- package/gql/fragments/logFragments.ts +33 -64
- package/gql/fragments/organizationFragments.ts +94 -21
- package/gql/fragments/scheduleFragments.ts +155 -0
- package/gql/fragments/sheetFragments.ts +675 -0
- package/gql/fragments/storageFragments.ts +21 -1
- package/gql/fragments/workflowFragments.ts +67 -0
- package/gql/mutations/accountMutations.ts +24 -4
- package/gql/mutations/agentDocMutations.ts +177 -0
- package/gql/mutations/agentMemoryMutations.ts +36 -0
- package/gql/mutations/aiChatMutations.ts +43 -3
- package/gql/mutations/authMutations.ts +160 -19
- package/gql/mutations/campaignMutations.ts +215 -0
- package/gql/mutations/dataTableMutations.ts +106 -0
- package/gql/mutations/fieldDocMutations.ts +24 -0
- package/gql/mutations/inboundContactMutations.ts +24 -0
- package/gql/mutations/index.ts +17 -8
- package/gql/mutations/integrationMutations.ts +25 -0
- package/gql/mutations/logMutations.ts +10 -19
- package/gql/mutations/organizationMutations.ts +160 -2
- package/gql/mutations/scheduleMutations.ts +423 -0
- package/gql/mutations/sheetMutations.ts +385 -0
- package/gql/mutations/storageMutations.ts +21 -2
- package/gql/mutations/workflowMutations.ts +42 -0
- package/gql/queries/agentDocQueries.ts +120 -0
- package/gql/queries/agentMemoryQueries.ts +22 -0
- package/gql/queries/aiChatQueries.ts +18 -2
- package/gql/queries/authQueries.ts +41 -0
- package/gql/queries/billingQueries.ts +24 -1
- package/gql/queries/campaignQueries.ts +127 -0
- package/gql/queries/dataTableQueries.ts +134 -0
- package/gql/queries/emailQueries.ts +96 -0
- package/gql/queries/fieldDocQueries.ts +158 -0
- package/gql/queries/inboundContactQueries.ts +40 -0
- package/gql/queries/index.ts +17 -6
- package/gql/queries/logQueries.ts +42 -32
- package/gql/queries/organizationQueries.ts +113 -8
- package/gql/queries/scheduleQueries.ts +315 -0
- package/gql/queries/sheetQueries.ts +383 -0
- package/gql/queries/storageQueries.ts +38 -0
- package/gql/queries/workflowQueries.ts +99 -0
- package/hooks/index.ts +2104 -860
- package/hooks/use-account-mtn.ts +91 -48
- package/hooks/use-agentDoc-mtn.ts +285 -0
- package/hooks/use-agentDoc-qry.ts +208 -0
- package/hooks/use-agentMemory-mtn.ts +73 -0
- package/hooks/use-agentMemory-qry.ts +44 -0
- package/hooks/use-aiChat-mtn.ts +248 -97
- package/hooks/use-aiChat-qry.ts +501 -191
- package/hooks/use-app-qry.ts +14 -11
- package/hooks/use-auth-mtn.ts +410 -256
- package/hooks/use-auth-qry.ts +51 -0
- package/hooks/use-campaign-mtn.ts +377 -0
- package/hooks/use-campaign-qry.ts +257 -0
- package/hooks/use-dataTable-mtn.ts +170 -0
- package/hooks/use-dataTable-qry.ts +996 -0
- package/hooks/use-email-qry.ts +227 -0
- package/hooks/use-fieldDoc-mtn.ts +50 -0
- package/hooks/use-fieldDoc-qry.ts +180 -0
- package/hooks/use-inboundContact-mtn.ts +34 -0
- package/hooks/use-inboundContact-qry.ts +96 -0
- package/hooks/use-integration-mtn.ts +77 -0
- package/hooks/use-integration-qry.ts +30 -0
- package/hooks/use-log-mtn.ts +77 -61
- package/hooks/use-log-qry.ts +99 -72
- package/hooks/use-organization-mtn.ts +409 -80
- package/hooks/use-organization-qry.ts +211 -92
- package/hooks/use-schedule-mtn.ts +416 -0
- package/hooks/use-schedule-qry.ts +157 -0
- package/hooks/use-sheet-mtn.ts +367 -0
- package/hooks/use-sheet-qry.ts +440 -0
- package/hooks/use-storage-mtn.ts +83 -42
- package/hooks/use-storage-qry.ts +104 -13
- package/hooks/use-workflow-mtn.ts +55 -0
- package/hooks/use-workflow-qry.ts +230 -0
- package/loaders/campaign.ts +137 -0
- package/package.json +94 -52
- package/sse.ts +158 -105
- package/tsconfig.json +13 -0
- package/types.d.ts +60 -29
- package/utils.ts +77 -50
- package/gql/fragments/actionFragments.ts +0 -16
- package/gql/fragments/productFragments.ts +0 -63
- package/gql/fragments/reportFragments.ts +0 -48
- package/gql/mutations/billingMutations.ts +0 -34
- package/gql/queries/productQueries.ts +0 -70
- package/gql/queries/reportQueries.ts +0 -66
- package/hooks/use-product-qry.ts +0 -109
- package/hooks/use-report-qry.ts +0 -69
|
@@ -0,0 +1,440 @@
|
|
|
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;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/*
|
|
44
|
+
* Add front-end deleted status to trashed Sheet records.
|
|
45
|
+
*/
|
|
46
|
+
|
|
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
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/*
|
|
59
|
+
* Return whether one useSheets input is the paginated variables object.
|
|
60
|
+
*/
|
|
61
|
+
function isSheetsVariables(
|
|
62
|
+
value: string | null | undefined | SheetsVariables,
|
|
63
|
+
): value is SheetsVariables {
|
|
64
|
+
return !!value && typeof value === 'object';
|
|
65
|
+
}
|
|
66
|
+
|
|
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
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
organizationId: organizationIdOrVariables,
|
|
85
|
+
after: true,
|
|
86
|
+
cursor: null,
|
|
87
|
+
limit: GRID_ITEM_LIST_LIMIT,
|
|
88
|
+
sort: 'UPDATED_AT_DESC',
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/*
|
|
93
|
+
* Fetch sheets for an organization.
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
export function useSheets(
|
|
97
|
+
organizationId?: string | null | SheetsVariables,
|
|
98
|
+
params: UseQueryParams = {},
|
|
99
|
+
) {
|
|
100
|
+
const variables = getSheetsQueryVariables(organizationId);
|
|
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, {
|
|
158
|
+
variables: {
|
|
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,
|
|
163
|
+
},
|
|
164
|
+
...params,
|
|
165
|
+
skip: !sheetId || !!params.skip,
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
sheetAccess: data?.sheetAccess || null,
|
|
170
|
+
...rest,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/*
|
|
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.
|
|
178
|
+
*/
|
|
179
|
+
export function useSheetAccessMonitor(
|
|
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(
|
|
251
|
+
organizationId?: string | null,
|
|
252
|
+
sheetId?: string | null,
|
|
253
|
+
params: UseQueryParams = {},
|
|
254
|
+
) {
|
|
255
|
+
const { data, ...rest } = useQuery(sheetAccessGrantsQry, {
|
|
256
|
+
variables: {
|
|
257
|
+
organizationId,
|
|
258
|
+
sheetId,
|
|
259
|
+
},
|
|
260
|
+
...params,
|
|
261
|
+
skip: !organizationId || !sheetId || !!params.skip,
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
return {
|
|
265
|
+
sheetAccessGrants: data?.sheetAccessGrants || null,
|
|
266
|
+
...rest,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
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
|
+
|
|
297
|
+
/*
|
|
298
|
+
* Get reactive Sheet fragment.
|
|
299
|
+
*/
|
|
300
|
+
|
|
301
|
+
export function useReactiveSheetFragment(
|
|
302
|
+
sheetId: string,
|
|
303
|
+
currentData?: any,
|
|
304
|
+
queryCount?: number,
|
|
305
|
+
) {
|
|
306
|
+
const sheet = useReactiveFragment(
|
|
307
|
+
currentData,
|
|
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),
|
|
314
|
+
queryCount,
|
|
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;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/*
|
|
333
|
+
* Get reactive SheetCell fragments.
|
|
334
|
+
*/
|
|
335
|
+
export function useReactiveSheetCells(cells?: any[] | null) {
|
|
336
|
+
return useReactiveFragmentMap(
|
|
337
|
+
cells || null,
|
|
338
|
+
getFragmentBaseName(FRAGMENT_NAMES.sheetCell),
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
|
|
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
|
+
) {
|
|
351
|
+
return useReactiveFragment(
|
|
352
|
+
currentData,
|
|
353
|
+
importJobId
|
|
354
|
+
? [makeFragmentKey(FRAGMENT_NAMES.sheetImportJob, importJobId)]
|
|
355
|
+
: [],
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/*
|
|
360
|
+
* Return the reactive fragment key carrying realtime sheetView cell deltas
|
|
361
|
+
* for one sheet view ({ id, cellsDelta, deletedCellCoords } patches).
|
|
362
|
+
*/
|
|
363
|
+
export function getSheetViewFragmentKey(sheetViewId: string) {
|
|
364
|
+
return makeFragmentKey(FRAGMENT_NAMES.sheetView, sheetViewId);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/*
|
|
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.
|
|
376
|
+
*/
|
|
377
|
+
|
|
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> {
|
|
387
|
+
const variables = {
|
|
388
|
+
organizationId,
|
|
389
|
+
sheetId,
|
|
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,
|
|
421
|
+
};
|
|
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,
|
|
430
|
+
variables,
|
|
431
|
+
skip,
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
return {
|
|
435
|
+
sheetOperationalHistory:
|
|
436
|
+
(data?.sheetOperationalHistory as SheetOperationalHistoryGQL | null) ||
|
|
437
|
+
null,
|
|
438
|
+
...rest,
|
|
439
|
+
};
|
|
440
|
+
}
|
package/hooks/use-storage-mtn.ts
CHANGED
|
@@ -1,56 +1,97 @@
|
|
|
1
1
|
import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
2
2
|
import { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import {
|
|
4
|
+
FRAGMENT_NAMES,
|
|
5
|
+
makeFragmentKey,
|
|
6
|
+
} from '@jsb188/mday/constants/graphqlReactivity.ts';
|
|
7
|
+
import { updateFragment } from '../cache/index.ts';
|
|
8
|
+
import {
|
|
9
|
+
createGeneratedFileDownloadLinkMtn,
|
|
10
|
+
createSignedUploadUrlMtn,
|
|
11
|
+
deleteStorageFileMtn,
|
|
12
|
+
} from '../gql/mutations/storageMutations.ts';
|
|
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(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
+
};
|
|
56
97
|
}
|
package/hooks/use-storage-qry.ts
CHANGED
|
@@ -1,21 +1,112 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { GeneratedFileGQL } from '@jsb188/mday/types/storage.d.ts';
|
|
2
|
+
import {
|
|
3
|
+
FRAGMENT_NAMES,
|
|
4
|
+
makeFragmentKey,
|
|
5
|
+
} from '@jsb188/mday/constants/graphqlReactivity.ts';
|
|
6
|
+
import {
|
|
7
|
+
generatedFileQry,
|
|
8
|
+
generatedFilesQry,
|
|
9
|
+
} from '../gql/queries/storageQueries.ts';
|
|
10
|
+
import { useQuery, useReactiveFragment } from '../client/index.ts';
|
|
11
|
+
import type { PaginationArgs, UseQueryParams } from '../types.d.ts';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Constants
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const GENERATED_FILES_LIST_LIMIT = 100;
|
|
2
18
|
|
|
3
19
|
/**
|
|
4
20
|
* Get reactive log fragment
|
|
5
21
|
*/
|
|
6
22
|
|
|
7
|
-
export function useReactiveStorageFragment(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
23
|
+
export function useReactiveStorageFragment(
|
|
24
|
+
storageId: string,
|
|
25
|
+
currentData?: any,
|
|
26
|
+
queryCount?: number,
|
|
27
|
+
) {
|
|
28
|
+
return useReactiveFragment(
|
|
29
|
+
currentData,
|
|
30
|
+
[makeFragmentKey(FRAGMENT_NAMES.storageFile, storageId)],
|
|
31
|
+
queryCount,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Get reactive generated file fragment (AI CSV exports).
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
export function useReactiveGeneratedFileFragment(
|
|
40
|
+
code: string,
|
|
41
|
+
currentData?: any,
|
|
42
|
+
queryCount?: number,
|
|
43
|
+
) {
|
|
44
|
+
return useReactiveFragment(
|
|
45
|
+
currentData,
|
|
46
|
+
[makeFragmentKey(FRAGMENT_NAMES.generatedFile, code)],
|
|
47
|
+
queryCount,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Fetch generated files (AI CSV exports) for one organization.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
export function useGeneratedFiles(
|
|
56
|
+
variables: PaginationArgs & {
|
|
57
|
+
organizationId?: string | null;
|
|
58
|
+
},
|
|
59
|
+
params: UseQueryParams = {},
|
|
60
|
+
) {
|
|
61
|
+
const { data, ...rest } = useQuery(generatedFilesQry, {
|
|
62
|
+
...params,
|
|
63
|
+
variables: {
|
|
64
|
+
...variables,
|
|
65
|
+
cursor: null,
|
|
66
|
+
after: true,
|
|
67
|
+
limit: GENERATED_FILES_LIST_LIMIT,
|
|
68
|
+
},
|
|
69
|
+
skip: !variables.organizationId || params.skip,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
generatedFiles: data?.generatedFiles as GeneratedFileGQL[] | undefined,
|
|
74
|
+
...rest,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Fetch one generated file; serves reactive cache data first so a deep link
|
|
80
|
+
* that arrives after the list loaded does not refetch.
|
|
81
|
+
*/
|
|
12
82
|
|
|
13
|
-
|
|
14
|
-
|
|
83
|
+
export function useGeneratedFile(
|
|
84
|
+
variables: {
|
|
85
|
+
organizationId?: string | null;
|
|
86
|
+
code?: string | null;
|
|
87
|
+
},
|
|
88
|
+
params: UseQueryParams = {},
|
|
89
|
+
) {
|
|
90
|
+
const cachedGeneratedFile = useReactiveGeneratedFileFragment(
|
|
91
|
+
variables.code || '',
|
|
92
|
+
null,
|
|
93
|
+
);
|
|
94
|
+
const shouldFetchGeneratedFile =
|
|
95
|
+
!!variables.organizationId &&
|
|
96
|
+
!!variables.code &&
|
|
97
|
+
!cachedGeneratedFile &&
|
|
98
|
+
!params.skip;
|
|
99
|
+
const { data, ...rest } = useQuery(generatedFileQry, {
|
|
100
|
+
...params,
|
|
101
|
+
variables,
|
|
102
|
+
skip: !shouldFetchGeneratedFile,
|
|
103
|
+
});
|
|
15
104
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
105
|
+
return {
|
|
106
|
+
generatedFile: (cachedGeneratedFile || data?.generatedFile) as
|
|
107
|
+
| GeneratedFileGQL
|
|
108
|
+
| undefined,
|
|
109
|
+
initialLoading: shouldFetchGeneratedFile && !data,
|
|
110
|
+
...rest,
|
|
111
|
+
};
|
|
21
112
|
}
|