@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.
- package/cache/config.ts +64 -50
- package/cache/index.test.ts +671 -109
- package/cache/index.ts +1700 -1240
- 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 +2 -0
- 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 +954 -163
- package/client/sse-ticket.test.ts +26 -0
- package/deno.lock +170 -0
- package/deno.test.json +8 -4
- 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 +0 -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 +16 -0
- package/gql/fragments/billingFragments.ts +0 -11
- package/gql/fragments/campaignFragments.ts +277 -0
- package/gql/fragments/dataTableFragments.ts +18 -128
- package/gql/fragments/emailFragments.ts +19 -9
- package/gql/fragments/fieldDocFragments.ts +82 -0
- package/gql/fragments/logFragments.ts +20 -79
- package/gql/fragments/organizationFragments.ts +43 -5
- package/gql/fragments/scheduleFragments.ts +155 -0
- package/gql/fragments/sheetFragments.ts +552 -22
- package/gql/fragments/storageFragments.ts +21 -0
- package/gql/fragments/workflowFragments.ts +28 -4
- package/gql/mutations/accountMutations.ts +0 -2
- package/gql/mutations/agentDocMutations.ts +177 -0
- package/gql/mutations/agentMemoryMutations.ts +36 -0
- package/gql/mutations/aiChatMutations.ts +17 -4
- package/gql/mutations/authMutations.ts +158 -17
- package/gql/mutations/campaignMutations.ts +215 -0
- package/gql/mutations/dataTableMutations.ts +48 -26
- package/gql/mutations/fieldDocMutations.ts +24 -0
- package/gql/mutations/index.ts +6 -1
- package/gql/mutations/logMutations.ts +6 -29
- package/gql/mutations/organizationMutations.ts +13 -4
- package/gql/mutations/scheduleMutations.ts +423 -0
- package/gql/mutations/sheetMutations.ts +273 -56
- package/gql/mutations/storageMutations.ts +20 -0
- 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 +23 -0
- package/gql/queries/campaignQueries.ts +127 -0
- package/gql/queries/dataTableQueries.ts +100 -11
- package/gql/queries/emailQueries.ts +55 -3
- package/gql/queries/fieldDocQueries.ts +158 -0
- package/gql/queries/index.ts +8 -2
- package/gql/queries/logQueries.ts +11 -28
- package/gql/queries/organizationQueries.ts +52 -1
- package/gql/queries/scheduleQueries.ts +315 -0
- package/gql/queries/sheetQueries.ts +336 -25
- package/gql/queries/storageQueries.ts +38 -0
- package/gql/queries/workflowQueries.ts +72 -3
- package/hooks/index.ts +2065 -971
- package/hooks/use-account-mtn.ts +76 -81
- 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 +232 -137
- package/hooks/use-aiChat-qry.ts +480 -222
- package/hooks/use-app-qry.ts +12 -9
- package/hooks/use-auth-mtn.ts +406 -252
- 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 +116 -33
- package/hooks/use-dataTable-qry.ts +859 -35
- package/hooks/use-email-qry.ts +194 -79
- package/hooks/use-fieldDoc-mtn.ts +50 -0
- package/hooks/use-fieldDoc-qry.ts +180 -0
- package/hooks/use-inboundContact-mtn.ts +19 -16
- package/hooks/use-inboundContact-qry.ts +63 -55
- package/hooks/use-integration-mtn.ts +56 -38
- package/hooks/use-integration-qry.ts +24 -9
- package/hooks/use-log-mtn.ts +72 -56
- package/hooks/use-log-qry.ts +93 -69
- package/hooks/use-organization-mtn.ts +334 -277
- package/hooks/use-organization-qry.ts +199 -129
- package/hooks/use-schedule-mtn.ts +416 -0
- package/hooks/use-schedule-qry.ts +157 -0
- package/hooks/use-sheet-mtn.ts +233 -47
- package/hooks/use-sheet-qry.ts +353 -70
- package/hooks/use-storage-mtn.ts +81 -41
- package/hooks/use-storage-qry.ts +104 -13
- package/hooks/use-workflow-mtn.ts +55 -0
- package/hooks/use-workflow-qry.ts +206 -48
- package/loaders/campaign.ts +137 -0
- package/package.json +94 -71
- package/sse.ts +157 -104
- package/tsconfig.json +11 -10
- package/types.d.ts +60 -30
- package/utils.ts +78 -49
- package/gql/fragments/productFragments.ts +0 -39
- package/gql/fragments/reportFragments.ts +0 -90
- package/gql/mutations/billingMutations.ts +0 -34
- package/gql/queries/productQueries.ts +0 -31
- package/gql/queries/reportQueries.ts +0 -134
- package/hooks/use-product-qry.ts +0 -67
- package/hooks/use-report-qry.ts +0 -153
|
@@ -1,13 +1,318 @@
|
|
|
1
|
-
import { useQuery, useReactiveFragment, useReactiveFragmentMap } from '@jsb188/graphql/client';
|
|
2
1
|
import { makeVariablesKey } from '@jsb188/app/utils/logic.ts';
|
|
3
|
-
import {
|
|
4
|
-
|
|
2
|
+
import {
|
|
3
|
+
graphqlRequestNoStore,
|
|
4
|
+
useQuery,
|
|
5
|
+
useReactiveFragment,
|
|
6
|
+
useReactiveFragmentMap,
|
|
7
|
+
useUpdateObservers,
|
|
8
|
+
} from '@jsb188/graphql/client';
|
|
9
|
+
import { GRID_ITEM_LIST_LIMIT } from '@jsb188/mday/constants/sheet.ts';
|
|
10
|
+
import type { DataTablesFilterArgs } from '@jsb188/mday/types/dataTable.d.ts';
|
|
11
|
+
import type { GridItemSortEnum } from '@jsb188/mday/types/sheet.d.ts';
|
|
12
|
+
import {
|
|
13
|
+
FRAGMENT_NAMES,
|
|
14
|
+
getFragmentBaseName,
|
|
15
|
+
makeFragmentKey,
|
|
16
|
+
} from '@jsb188/mday/constants/graphqlReactivity.ts';
|
|
17
|
+
import { useLayoutEffect, useMemo } from 'react';
|
|
18
|
+
import {
|
|
19
|
+
addFragmentToCache,
|
|
20
|
+
loadFragment,
|
|
21
|
+
resetQuery,
|
|
22
|
+
setDataToCache,
|
|
23
|
+
updateFragment,
|
|
24
|
+
} from '../cache/index.ts';
|
|
25
|
+
import {
|
|
26
|
+
type DataTableRealtimeSnapshot,
|
|
27
|
+
dataTableRealtimeSequenceGate,
|
|
28
|
+
} from '../client/data-table-realtime.ts';
|
|
29
|
+
import {
|
|
30
|
+
type DataTableRealtimeSubscription,
|
|
31
|
+
dataTableRealtimeSubscriptions,
|
|
32
|
+
getDataTableRealtimeFragmentValue,
|
|
33
|
+
getDataTableRealtimeQuerySubscriptions,
|
|
34
|
+
normalizeDataTableRealtimeSubscriptions,
|
|
35
|
+
resolveDataTableRealtimeQueryResult,
|
|
36
|
+
} from '../client/data-table-realtime-subscriptions.ts';
|
|
37
|
+
import {
|
|
38
|
+
dataTableChangesQry,
|
|
39
|
+
dataTableQry,
|
|
40
|
+
dataTableRowsSnapshotQry,
|
|
41
|
+
dataTablesQry,
|
|
42
|
+
} from '../gql/queries/dataTableQueries.ts';
|
|
43
|
+
import type {
|
|
44
|
+
PaginationArgs,
|
|
45
|
+
UpdateObserversFn,
|
|
46
|
+
UseQueryParams,
|
|
47
|
+
} from '../types.d.ts';
|
|
5
48
|
|
|
6
49
|
/**
|
|
7
50
|
* Constants
|
|
8
51
|
*/
|
|
9
52
|
|
|
10
53
|
const SHEET_ROWS_LIMIT = 200;
|
|
54
|
+
const DATA_TABLE_CHANGES_LIMIT = 100;
|
|
55
|
+
const ACTIVE_DATA_TABLE_SNAPSHOT_PAGES = new Map<
|
|
56
|
+
string,
|
|
57
|
+
Map<
|
|
58
|
+
string,
|
|
59
|
+
{
|
|
60
|
+
count: number;
|
|
61
|
+
variables: ActiveDataTableRowsVariables;
|
|
62
|
+
}
|
|
63
|
+
>
|
|
64
|
+
>();
|
|
65
|
+
|
|
66
|
+
type ActiveDataTableRowsVariables = {
|
|
67
|
+
cursor?: string | null;
|
|
68
|
+
dataTableId: string;
|
|
69
|
+
limit: number;
|
|
70
|
+
organizationId: string;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export type DataTableRealtimeRecoveryStatus =
|
|
74
|
+
| 'CANCELLED'
|
|
75
|
+
| 'RECOVERED'
|
|
76
|
+
| 'RETRY';
|
|
77
|
+
|
|
78
|
+
export type DataTableChangeSeqInput = string | bigint;
|
|
79
|
+
|
|
80
|
+
export type DataTableChangesVariables = {
|
|
81
|
+
afterSeq: DataTableChangeSeqInput;
|
|
82
|
+
dataTableId?: string | null;
|
|
83
|
+
limit?: number;
|
|
84
|
+
organizationId?: string | null;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export type DataTablesVariables = PaginationArgs & {
|
|
88
|
+
filter?: DataTablesFilterArgs | null;
|
|
89
|
+
organizationId?: string | null;
|
|
90
|
+
sort?: GridItemSortEnum | null;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
type DataTableRowsSnapshotResult = DataTableRealtimeSnapshot & {
|
|
94
|
+
currentSeq: string;
|
|
95
|
+
dataTable: any;
|
|
96
|
+
dataTableId: string;
|
|
97
|
+
rows: any[];
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/*
|
|
101
|
+
* Normalize one DataTable journal cursor without losing BIGINT precision.
|
|
102
|
+
*/
|
|
103
|
+
function normalizeDataTableChangeSeq(value: DataTableChangeSeqInput) {
|
|
104
|
+
if (typeof value === 'string' && !/^\d+$/.test(value.trim())) {
|
|
105
|
+
throw new TypeError(
|
|
106
|
+
'DataTable change seq must be a non-negative base-10 integer.',
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
const seq = BigInt(typeof value === 'string' ? value.trim() : value);
|
|
112
|
+
if (seq < 0n || seq > 9223372036854775807n) {
|
|
113
|
+
throw new TypeError(
|
|
114
|
+
'DataTable change seq must fit in a PostgreSQL BIGINT.',
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
return seq.toString();
|
|
118
|
+
} catch (error) {
|
|
119
|
+
if (error instanceof TypeError) {
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
throw new TypeError(
|
|
123
|
+
'DataTable change seq must be a non-negative base-10 integer.',
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/*
|
|
129
|
+
* Return one stable registry key for active snapshot page consumers.
|
|
130
|
+
*/
|
|
131
|
+
function getActiveDataTableSnapshotKey(
|
|
132
|
+
organizationId: string,
|
|
133
|
+
dataTableId: string,
|
|
134
|
+
) {
|
|
135
|
+
return `${organizationId}:${dataTableId}`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/*
|
|
139
|
+
* Register complete row-query variables for safe recovery. Duplicate mounts
|
|
140
|
+
* share reference counts and one table sequence gate.
|
|
141
|
+
*/
|
|
142
|
+
function registerActiveDataTableSnapshot(
|
|
143
|
+
organizationId: string,
|
|
144
|
+
dataTableId: string,
|
|
145
|
+
realtimeToken: string | null | undefined,
|
|
146
|
+
cursor: string | null | undefined,
|
|
147
|
+
limit: number,
|
|
148
|
+
) {
|
|
149
|
+
const key = getActiveDataTableSnapshotKey(organizationId, dataTableId);
|
|
150
|
+
const variables = { cursor, dataTableId, limit, organizationId };
|
|
151
|
+
const variablesKey = makeVariablesKey(variables);
|
|
152
|
+
const pages =
|
|
153
|
+
ACTIVE_DATA_TABLE_SNAPSHOT_PAGES.get(key) ||
|
|
154
|
+
new Map<
|
|
155
|
+
string,
|
|
156
|
+
{
|
|
157
|
+
count: number;
|
|
158
|
+
variables: ActiveDataTableRowsVariables;
|
|
159
|
+
}
|
|
160
|
+
>();
|
|
161
|
+
const currentPage = pages.get(variablesKey);
|
|
162
|
+
pages.set(variablesKey, {
|
|
163
|
+
count: (currentPage?.count || 0) + 1,
|
|
164
|
+
variables,
|
|
165
|
+
});
|
|
166
|
+
ACTIVE_DATA_TABLE_SNAPSHOT_PAGES.set(key, pages);
|
|
167
|
+
const unregisterGate = dataTableRealtimeSequenceGate.registerTable(
|
|
168
|
+
organizationId,
|
|
169
|
+
dataTableId,
|
|
170
|
+
);
|
|
171
|
+
const unregisterRoom = dataTableRealtimeSubscriptions.register(
|
|
172
|
+
getDataTableRealtimeQuerySubscriptions(
|
|
173
|
+
organizationId,
|
|
174
|
+
dataTableId,
|
|
175
|
+
realtimeToken,
|
|
176
|
+
),
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
let active = true;
|
|
180
|
+
return () => {
|
|
181
|
+
if (!active) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
active = false;
|
|
185
|
+
const nextCount = (pages.get(variablesKey)?.count || 1) - 1;
|
|
186
|
+
if (nextCount > 0) {
|
|
187
|
+
pages.set(variablesKey, {
|
|
188
|
+
count: nextCount,
|
|
189
|
+
variables,
|
|
190
|
+
});
|
|
191
|
+
} else {
|
|
192
|
+
pages.delete(variablesKey);
|
|
193
|
+
}
|
|
194
|
+
if (!pages.size) {
|
|
195
|
+
ACTIVE_DATA_TABLE_SNAPSHOT_PAGES.delete(key);
|
|
196
|
+
}
|
|
197
|
+
unregisterGate();
|
|
198
|
+
unregisterRoom();
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/*
|
|
203
|
+
* Subscribe one mounted feature to a deduped set of DataTable rooms while a
|
|
204
|
+
* token-independent gate registration preserves its cursor through rotation.
|
|
205
|
+
*/
|
|
206
|
+
export function useDataTableRealtimeSubscriptions(
|
|
207
|
+
subscriptions: DataTableRealtimeSubscription[],
|
|
208
|
+
) {
|
|
209
|
+
const normalizedSubscriptions =
|
|
210
|
+
normalizeDataTableRealtimeSubscriptions(subscriptions);
|
|
211
|
+
const subscriptionsKey = JSON.stringify(normalizedSubscriptions);
|
|
212
|
+
const scopesKey = JSON.stringify(
|
|
213
|
+
normalizedSubscriptions.map(({ organizationId, dataTableId }) => ({
|
|
214
|
+
organizationId,
|
|
215
|
+
dataTableId,
|
|
216
|
+
})),
|
|
217
|
+
);
|
|
218
|
+
useLayoutEffect(() => {
|
|
219
|
+
return dataTableRealtimeSubscriptions.register(
|
|
220
|
+
JSON.parse(subscriptionsKey) as DataTableRealtimeSubscription[],
|
|
221
|
+
);
|
|
222
|
+
}, [subscriptionsKey]);
|
|
223
|
+
useLayoutEffect(() => {
|
|
224
|
+
const normalizedScopes = JSON.parse(scopesKey) as Array<{
|
|
225
|
+
dataTableId: string;
|
|
226
|
+
organizationId: string;
|
|
227
|
+
}>;
|
|
228
|
+
const unregisterSequenceGates = normalizedScopes.map(
|
|
229
|
+
({ organizationId, dataTableId }) =>
|
|
230
|
+
dataTableRealtimeSequenceGate.registerTable(
|
|
231
|
+
organizationId,
|
|
232
|
+
dataTableId,
|
|
233
|
+
),
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
return () => {
|
|
237
|
+
unregisterSequenceGates.forEach((unregister) => {
|
|
238
|
+
unregister();
|
|
239
|
+
});
|
|
240
|
+
};
|
|
241
|
+
}, [scopesKey]);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/*
|
|
245
|
+
* Return every mounted rows-query page for one table in stable key order.
|
|
246
|
+
*/
|
|
247
|
+
function getActiveDataTableSnapshotPages(
|
|
248
|
+
organizationId: string,
|
|
249
|
+
dataTableId: string,
|
|
250
|
+
) {
|
|
251
|
+
return [
|
|
252
|
+
...(ACTIVE_DATA_TABLE_SNAPSHOT_PAGES.get(
|
|
253
|
+
getActiveDataTableSnapshotKey(organizationId, dataTableId),
|
|
254
|
+
)?.values() || []),
|
|
255
|
+
]
|
|
256
|
+
.map((entry) => entry.variables)
|
|
257
|
+
.sort((left, right) =>
|
|
258
|
+
makeVariablesKey(left).localeCompare(makeVariablesKey(right)),
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/*
|
|
263
|
+
* Validate a watermark-bearing snapshot before it can mutate normalized cache.
|
|
264
|
+
*/
|
|
265
|
+
function isApplicableDataTableRowsSnapshot(
|
|
266
|
+
snapshot: unknown,
|
|
267
|
+
organizationId: string,
|
|
268
|
+
dataTableId: string,
|
|
269
|
+
): snapshot is DataTableRowsSnapshotResult {
|
|
270
|
+
if (!snapshot || typeof snapshot !== 'object' || Array.isArray(snapshot)) {
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
const value = snapshot as Partial<DataTableRowsSnapshotResult>;
|
|
274
|
+
if (
|
|
275
|
+
value.dataTableId !== dataTableId ||
|
|
276
|
+
value.dataTable?.id !== dataTableId ||
|
|
277
|
+
!Array.isArray(value.rows)
|
|
278
|
+
) {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
if (typeof value.currentSeq !== 'string' || !/^\d+$/.test(value.currentSeq)) {
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return dataTableRealtimeSequenceGate.canApplySnapshot(
|
|
286
|
+
organizationId,
|
|
287
|
+
dataTableId,
|
|
288
|
+
value.currentSeq,
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/*
|
|
293
|
+
* Record an accepted snapshot after the GraphQL client has synchronously
|
|
294
|
+
* normalized it. Only an initial page is complete enough to move the table
|
|
295
|
+
* baseline; cursor pages contribute per-fragment version fences only.
|
|
296
|
+
*/
|
|
297
|
+
function acknowledgeAppliedDataTableRowsSnapshot(
|
|
298
|
+
snapshot: DataTableRowsSnapshotResult,
|
|
299
|
+
organizationId: string,
|
|
300
|
+
dataTableId: string,
|
|
301
|
+
cursor?: PaginationArgs['cursor'] | null,
|
|
302
|
+
) {
|
|
303
|
+
dataTableRealtimeSequenceGate.recordSnapshotFragments(
|
|
304
|
+
organizationId,
|
|
305
|
+
dataTableId,
|
|
306
|
+
snapshot,
|
|
307
|
+
);
|
|
308
|
+
if (!cursor) {
|
|
309
|
+
dataTableRealtimeSequenceGate.acknowledgeSnapshot(
|
|
310
|
+
organizationId,
|
|
311
|
+
dataTableId,
|
|
312
|
+
snapshot.currentSeq,
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
11
316
|
|
|
12
317
|
/*
|
|
13
318
|
* Return all dataTable cell records nested under the provided dataTable rows.
|
|
@@ -21,7 +326,10 @@ function getDataTableRowCells(dataTableRows?: any[] | null) {
|
|
|
21
326
|
* Merge reactive dataTable cell fragments back into their parent dataTable rows.
|
|
22
327
|
*/
|
|
23
328
|
|
|
24
|
-
function mergeReactiveCellsIntoRows(
|
|
329
|
+
function mergeReactiveCellsIntoRows(
|
|
330
|
+
dataTableRows?: any[] | null,
|
|
331
|
+
dataTableCells?: any[] | null,
|
|
332
|
+
) {
|
|
25
333
|
if (!dataTableRows || !dataTableCells) {
|
|
26
334
|
return dataTableRows;
|
|
27
335
|
}
|
|
@@ -31,14 +339,15 @@ function mergeReactiveCellsIntoRows(dataTableRows?: any[] | null, dataTableCells
|
|
|
31
339
|
|
|
32
340
|
const nextRows = dataTableRows.map((row) => {
|
|
33
341
|
let changedCells = false;
|
|
34
|
-
const nextCells =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
342
|
+
const nextCells =
|
|
343
|
+
row.cells?.map((cell: any) => {
|
|
344
|
+
const nextCell = cellMap.get(cell.id) || cell;
|
|
345
|
+
if (nextCell !== cell) {
|
|
346
|
+
changedCells = true;
|
|
347
|
+
}
|
|
39
348
|
|
|
40
|
-
|
|
41
|
-
|
|
349
|
+
return nextCell;
|
|
350
|
+
}) || [];
|
|
42
351
|
|
|
43
352
|
if (!changedCells) {
|
|
44
353
|
return row;
|
|
@@ -60,10 +369,19 @@ function mergeReactiveCellsIntoRows(dataTableRows?: any[] | null, dataTableCells
|
|
|
60
369
|
*/
|
|
61
370
|
|
|
62
371
|
export function useReactiveDataTableRows(dataTableRows?: any[] | null) {
|
|
63
|
-
const reactiveRows = useReactiveFragmentMap(
|
|
64
|
-
|
|
372
|
+
const reactiveRows = useReactiveFragmentMap(
|
|
373
|
+
dataTableRows || null,
|
|
374
|
+
getFragmentBaseName(FRAGMENT_NAMES.dataTableRow),
|
|
375
|
+
);
|
|
376
|
+
const reactiveCells = useReactiveFragmentMap(
|
|
377
|
+
getDataTableRowCells(reactiveRows || dataTableRows),
|
|
378
|
+
getFragmentBaseName(FRAGMENT_NAMES.dataTableCell),
|
|
379
|
+
);
|
|
65
380
|
|
|
66
|
-
return mergeReactiveCellsIntoRows(
|
|
381
|
+
return mergeReactiveCellsIntoRows(
|
|
382
|
+
reactiveRows || dataTableRows,
|
|
383
|
+
reactiveCells,
|
|
384
|
+
);
|
|
67
385
|
}
|
|
68
386
|
|
|
69
387
|
/*
|
|
@@ -71,7 +389,201 @@ export function useReactiveDataTableRows(dataTableRows?: any[] | null) {
|
|
|
71
389
|
*/
|
|
72
390
|
|
|
73
391
|
function getDataTableRowsQueryKey(variables: Record<string, unknown>) {
|
|
74
|
-
return `#
|
|
392
|
+
return `#dataTableRowsSnapshot:${makeVariablesKey(variables)}`;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/*
|
|
396
|
+
* Return the exact singular DataTable query key for one owned table.
|
|
397
|
+
*/
|
|
398
|
+
function getDataTableQueryKey(organizationId: string, dataTableId: string) {
|
|
399
|
+
return `#dataTable:${makeVariablesKey({ organizationId, dataTableId })}`;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/*
|
|
403
|
+
* Invalidate every mounted row page for one table so cursor pages are never
|
|
404
|
+
* treated as covered by a smaller first-page recovery snapshot.
|
|
405
|
+
*/
|
|
406
|
+
function invalidateActiveDataTableRowsQueries(
|
|
407
|
+
organizationId: string,
|
|
408
|
+
dataTableId: string,
|
|
409
|
+
updateObservers: UpdateObserversFn,
|
|
410
|
+
) {
|
|
411
|
+
getActiveDataTableSnapshotPages(organizationId, dataTableId).forEach(
|
|
412
|
+
(variables) => {
|
|
413
|
+
resetQuery(
|
|
414
|
+
getDataTableRowsQueryKey(variables),
|
|
415
|
+
true,
|
|
416
|
+
updateObservers,
|
|
417
|
+
true,
|
|
418
|
+
);
|
|
419
|
+
},
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/*
|
|
424
|
+
* Hide a table whose latest authorized room set no longer includes it, clear
|
|
425
|
+
* its sequencing baseline, and force every mounted query to re-evaluate.
|
|
426
|
+
*/
|
|
427
|
+
export function invalidateDataTableRealtimeSubscription(
|
|
428
|
+
organizationId: string,
|
|
429
|
+
dataTableId: string,
|
|
430
|
+
updateObservers: UpdateObserversFn,
|
|
431
|
+
) {
|
|
432
|
+
const fragmentKey = makeFragmentKey(FRAGMENT_NAMES.dataTable, dataTableId);
|
|
433
|
+
const updated = updateFragment(
|
|
434
|
+
fragmentKey,
|
|
435
|
+
{ __deleted: true, active: false },
|
|
436
|
+
null,
|
|
437
|
+
false,
|
|
438
|
+
updateObservers,
|
|
439
|
+
);
|
|
440
|
+
if (!updated) {
|
|
441
|
+
addFragmentToCache(fragmentKey, {
|
|
442
|
+
__deleted: true,
|
|
443
|
+
active: false,
|
|
444
|
+
id: dataTableId,
|
|
445
|
+
});
|
|
446
|
+
updateObservers({ fragmentIds: [fragmentKey] });
|
|
447
|
+
}
|
|
448
|
+
resetQuery(
|
|
449
|
+
getDataTableQueryKey(organizationId, dataTableId),
|
|
450
|
+
true,
|
|
451
|
+
updateObservers,
|
|
452
|
+
true,
|
|
453
|
+
);
|
|
454
|
+
invalidateActiveDataTableRowsQueries(
|
|
455
|
+
organizationId,
|
|
456
|
+
dataTableId,
|
|
457
|
+
updateObservers,
|
|
458
|
+
);
|
|
459
|
+
dataTableRealtimeSequenceGate.clearTable(organizationId, dataTableId);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/*
|
|
463
|
+
* Force mounted metadata and row queries to refetch after bounded snapshot
|
|
464
|
+
* recovery is exhausted without incorrectly marking the table as revoked.
|
|
465
|
+
*/
|
|
466
|
+
export function refreshDataTableRealtimeSubscription(
|
|
467
|
+
organizationId: string,
|
|
468
|
+
dataTableId: string,
|
|
469
|
+
updateObservers: UpdateObserversFn,
|
|
470
|
+
) {
|
|
471
|
+
const fragmentKey = makeFragmentKey(FRAGMENT_NAMES.dataTable, dataTableId);
|
|
472
|
+
addFragmentToCache(fragmentKey, null);
|
|
473
|
+
updateObservers({ fragmentIds: [fragmentKey] });
|
|
474
|
+
resetQuery(
|
|
475
|
+
getDataTableQueryKey(organizationId, dataTableId),
|
|
476
|
+
true,
|
|
477
|
+
updateObservers,
|
|
478
|
+
true,
|
|
479
|
+
);
|
|
480
|
+
invalidateActiveDataTableRowsQueries(
|
|
481
|
+
organizationId,
|
|
482
|
+
dataTableId,
|
|
483
|
+
updateObservers,
|
|
484
|
+
);
|
|
485
|
+
dataTableRealtimeSequenceGate.clearTable(organizationId, dataTableId);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/*
|
|
489
|
+
* Refetch only one mounted DataTable metadata query so it can publish a fresh
|
|
490
|
+
* signed realtime capability without disturbing rows or sequence baselines.
|
|
491
|
+
*/
|
|
492
|
+
export function renewDataTableRealtimeCapability(
|
|
493
|
+
organizationId: string,
|
|
494
|
+
dataTableId: string,
|
|
495
|
+
updateObservers: UpdateObserversFn,
|
|
496
|
+
) {
|
|
497
|
+
resetQuery(
|
|
498
|
+
getDataTableQueryKey(organizationId, dataTableId),
|
|
499
|
+
true,
|
|
500
|
+
updateObservers,
|
|
501
|
+
true,
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/*
|
|
506
|
+
* Add front-end deleted status to deleted or inactive DataTable records.
|
|
507
|
+
*/
|
|
508
|
+
|
|
509
|
+
function mapDataTableDeletedStatus(dataTable: any) {
|
|
510
|
+
if (
|
|
511
|
+
!dataTable ||
|
|
512
|
+
dataTable.__deleted ||
|
|
513
|
+
(!dataTable.deletedAt && dataTable.active !== false)
|
|
514
|
+
) {
|
|
515
|
+
return dataTable;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
return {
|
|
519
|
+
...dataTable,
|
|
520
|
+
__deleted: true,
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/*
|
|
525
|
+
* Clear a stale client-only deleted flag from cached DataTable fragments when
|
|
526
|
+
* a fresh authoritative result reports the table alive. Server payloads never
|
|
527
|
+
* carry __deleted, so fragment merges would otherwise preserve a wrongly
|
|
528
|
+
* poisoned flag through every refetch (and its persisted snapshot).
|
|
529
|
+
*/
|
|
530
|
+
function healDataTableDeletedFlags(
|
|
531
|
+
dataTables: any[] | null | undefined,
|
|
532
|
+
updateObservers: UpdateObserversFn,
|
|
533
|
+
) {
|
|
534
|
+
dataTables?.forEach((dataTable) => {
|
|
535
|
+
if (!dataTable?.id || dataTable.active === false || dataTable.deletedAt) {
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
const fragmentKey = makeFragmentKey(FRAGMENT_NAMES.dataTable, dataTable.id);
|
|
540
|
+
if (loadFragment(fragmentKey)?.__deleted) {
|
|
541
|
+
updateFragment(
|
|
542
|
+
fragmentKey,
|
|
543
|
+
{ __deleted: false },
|
|
544
|
+
null,
|
|
545
|
+
false,
|
|
546
|
+
updateObservers,
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/*
|
|
553
|
+
* Return whether one useDataTables input is the paginated variables object.
|
|
554
|
+
*/
|
|
555
|
+
function isDataTablesVariables(
|
|
556
|
+
value: string | null | undefined | DataTablesVariables,
|
|
557
|
+
): value is DataTablesVariables {
|
|
558
|
+
return !!value && typeof value === 'object';
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/*
|
|
562
|
+
* Return GraphQL variables for the paginated dataTables query.
|
|
563
|
+
*/
|
|
564
|
+
function getDataTablesQueryVariables(
|
|
565
|
+
organizationIdOrVariables?: string | null | DataTablesVariables,
|
|
566
|
+
active?: boolean | null,
|
|
567
|
+
): DataTablesVariables {
|
|
568
|
+
if (isDataTablesVariables(organizationIdOrVariables)) {
|
|
569
|
+
return {
|
|
570
|
+
...organizationIdOrVariables,
|
|
571
|
+
after: organizationIdOrVariables.after ?? true,
|
|
572
|
+
cursor: organizationIdOrVariables.cursor ?? null,
|
|
573
|
+
filter: organizationIdOrVariables.filter ?? null,
|
|
574
|
+
limit: organizationIdOrVariables.limit ?? GRID_ITEM_LIST_LIMIT,
|
|
575
|
+
sort: organizationIdOrVariables.sort || 'UPDATED_AT_DESC',
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
return {
|
|
580
|
+
organizationId: organizationIdOrVariables,
|
|
581
|
+
after: true,
|
|
582
|
+
cursor: null,
|
|
583
|
+
filter: { active },
|
|
584
|
+
limit: GRID_ITEM_LIST_LIMIT,
|
|
585
|
+
sort: 'UPDATED_AT_DESC',
|
|
586
|
+
};
|
|
75
587
|
}
|
|
76
588
|
|
|
77
589
|
/**
|
|
@@ -79,21 +591,85 @@ function getDataTableRowsQueryKey(variables: Record<string, unknown>) {
|
|
|
79
591
|
*/
|
|
80
592
|
|
|
81
593
|
export function useDataTables(
|
|
82
|
-
organizationId?: string | null,
|
|
594
|
+
organizationId?: string | null | DataTablesVariables,
|
|
83
595
|
active?: boolean | null,
|
|
84
596
|
params: UseQueryParams = {},
|
|
85
597
|
) {
|
|
598
|
+
const variables = getDataTablesQueryVariables(organizationId, active);
|
|
599
|
+
const updateObservers = useUpdateObservers();
|
|
86
600
|
const { data, ...rest } = useQuery(dataTablesQry, {
|
|
601
|
+
variables,
|
|
602
|
+
skip: !variables.organizationId,
|
|
603
|
+
...params,
|
|
604
|
+
onCompleted: (result: any, error: any, completedVariables?: any) => {
|
|
605
|
+
healDataTableDeletedFlags(result?.dataTables, updateObservers);
|
|
606
|
+
params.onCompleted?.(result, error, completedVariables);
|
|
607
|
+
},
|
|
608
|
+
});
|
|
609
|
+
const dataTables = useReactiveFragmentMap(
|
|
610
|
+
data?.dataTables || null,
|
|
611
|
+
getFragmentBaseName(FRAGMENT_NAMES.dataTable),
|
|
612
|
+
);
|
|
613
|
+
const dataTablesWithDeletedStatus = useMemo(
|
|
614
|
+
() => dataTables?.map(mapDataTableDeletedStatus) || dataTables,
|
|
615
|
+
[dataTables],
|
|
616
|
+
);
|
|
617
|
+
|
|
618
|
+
return {
|
|
619
|
+
dataTables: dataTablesWithDeletedStatus,
|
|
620
|
+
...rest,
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/*
|
|
625
|
+
* Fetch one dataTable by id.
|
|
626
|
+
*/
|
|
627
|
+
|
|
628
|
+
export function useDataTable(
|
|
629
|
+
dataTableId?: string | null,
|
|
630
|
+
organizationId?: string | null,
|
|
631
|
+
params: UseQueryParams = {},
|
|
632
|
+
) {
|
|
633
|
+
const cachedDataTable = useReactiveDataTableFragment(dataTableId || '', null);
|
|
634
|
+
const updateObservers = useUpdateObservers();
|
|
635
|
+
const { data, ...rest } = useQuery(dataTableQry, {
|
|
87
636
|
variables: {
|
|
88
637
|
organizationId,
|
|
89
|
-
|
|
638
|
+
dataTableId,
|
|
90
639
|
},
|
|
91
|
-
skip: !organizationId,
|
|
92
640
|
...params,
|
|
641
|
+
skip: !organizationId || !dataTableId || Boolean(params.skip),
|
|
642
|
+
onCompleted: (result: any, error: any, completedVariables?: any) => {
|
|
643
|
+
healDataTableDeletedFlags(
|
|
644
|
+
result?.dataTable ? [result.dataTable] : null,
|
|
645
|
+
updateObservers,
|
|
646
|
+
);
|
|
647
|
+
params.onCompleted?.(result, error, completedVariables);
|
|
648
|
+
},
|
|
93
649
|
});
|
|
94
650
|
|
|
651
|
+
// IMPORTANT: Keep `|| data?.dataTable` here -- this prevents an incorrect !dataTable state and `loading` state mismatch
|
|
652
|
+
// It's either that or we have to NOT use useMemo() here, both are valid options.
|
|
653
|
+
const dataTable =
|
|
654
|
+
useMemo(
|
|
655
|
+
() => mapDataTableDeletedStatus(data?.dataTable),
|
|
656
|
+
[data?.dataTable],
|
|
657
|
+
) || data?.dataTable;
|
|
658
|
+
const resolvedDataTable = useMemo(
|
|
659
|
+
() => resolveDataTableRealtimeQueryResult(dataTable, cachedDataTable),
|
|
660
|
+
[dataTable, cachedDataTable],
|
|
661
|
+
);
|
|
662
|
+
useDataTableRealtimeSubscriptions(
|
|
663
|
+
getDataTableRealtimeQuerySubscriptions(
|
|
664
|
+
organizationId,
|
|
665
|
+
dataTableId,
|
|
666
|
+
resolvedDataTable?.realtimeToken,
|
|
667
|
+
Boolean(params.skip),
|
|
668
|
+
),
|
|
669
|
+
);
|
|
670
|
+
|
|
95
671
|
return {
|
|
96
|
-
|
|
672
|
+
dataTable: resolvedDataTable,
|
|
97
673
|
...rest,
|
|
98
674
|
};
|
|
99
675
|
}
|
|
@@ -107,54 +683,298 @@ export function useDataTableRows(
|
|
|
107
683
|
organizationId?: string | null,
|
|
108
684
|
cursor?: string | null,
|
|
109
685
|
limit: number = SHEET_ROWS_LIMIT,
|
|
110
|
-
filter?: {
|
|
111
|
-
viewId?: string | null;
|
|
112
|
-
} | null,
|
|
113
686
|
params: UseQueryParams = {},
|
|
687
|
+
realtimeToken?: string | null,
|
|
114
688
|
) {
|
|
689
|
+
const skipQuery = !organizationId || !dataTableId || Boolean(params.skip);
|
|
115
690
|
const variables = {
|
|
116
691
|
dataTableId,
|
|
117
692
|
organizationId,
|
|
118
693
|
cursor,
|
|
119
694
|
limit,
|
|
120
|
-
filter,
|
|
121
695
|
};
|
|
122
|
-
|
|
696
|
+
useLayoutEffect(() => {
|
|
697
|
+
if (skipQuery || !organizationId || !dataTableId) {
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
return registerActiveDataTableSnapshot(
|
|
702
|
+
organizationId,
|
|
703
|
+
dataTableId,
|
|
704
|
+
realtimeToken,
|
|
705
|
+
cursor,
|
|
706
|
+
limit,
|
|
707
|
+
);
|
|
708
|
+
}, [organizationId, dataTableId, realtimeToken, cursor, limit, skipQuery]);
|
|
709
|
+
|
|
710
|
+
const { data, ...rest } = useQuery(dataTableRowsSnapshotQry, {
|
|
123
711
|
variables,
|
|
124
|
-
skip: !organizationId || !dataTableId,
|
|
125
712
|
...params,
|
|
713
|
+
skip: skipQuery,
|
|
714
|
+
rejectedResultRetryCount: 1,
|
|
715
|
+
shouldAcceptResult: (result: any) => {
|
|
716
|
+
const snapshot = result?.dataTableRowsSnapshot;
|
|
717
|
+
return (
|
|
718
|
+
!organizationId ||
|
|
719
|
+
!dataTableId ||
|
|
720
|
+
isApplicableDataTableRowsSnapshot(snapshot, organizationId, dataTableId)
|
|
721
|
+
);
|
|
722
|
+
},
|
|
723
|
+
onCompleted: (result: any, error: any, completedVariables?: any) => {
|
|
724
|
+
const snapshot = result?.dataTableRowsSnapshot;
|
|
725
|
+
if (
|
|
726
|
+
organizationId &&
|
|
727
|
+
dataTableId &&
|
|
728
|
+
isApplicableDataTableRowsSnapshot(snapshot, organizationId, dataTableId)
|
|
729
|
+
) {
|
|
730
|
+
acknowledgeAppliedDataTableRowsSnapshot(
|
|
731
|
+
snapshot,
|
|
732
|
+
organizationId,
|
|
733
|
+
dataTableId,
|
|
734
|
+
completedVariables?.cursor,
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
params.onCompleted?.(result, error, completedVariables);
|
|
738
|
+
},
|
|
126
739
|
});
|
|
127
740
|
|
|
128
|
-
const queryMatchesVariables =
|
|
741
|
+
const queryMatchesVariables =
|
|
742
|
+
rest.queryKey === getDataTableRowsQueryKey(variables) ||
|
|
129
743
|
rest.variablesKey === makeVariablesKey(variables);
|
|
130
|
-
const
|
|
131
|
-
|
|
744
|
+
const snapshot = queryMatchesVariables ? data?.dataTableRowsSnapshot : null;
|
|
745
|
+
const dataTableRows = useReactiveDataTableRows(snapshot?.rows || null);
|
|
132
746
|
return {
|
|
133
747
|
dataTableRows: queryMatchesVariables ? dataTableRows : undefined,
|
|
134
748
|
...rest,
|
|
135
749
|
};
|
|
136
750
|
}
|
|
137
751
|
|
|
752
|
+
/*
|
|
753
|
+
* Replace the singular metadata query and fragment from one authoritative
|
|
754
|
+
* watermark-bearing rows snapshot.
|
|
755
|
+
*/
|
|
756
|
+
function applyDataTableRecoveryMetadata(
|
|
757
|
+
snapshot: DataTableRowsSnapshotResult,
|
|
758
|
+
organizationId: string,
|
|
759
|
+
dataTableId: string,
|
|
760
|
+
updateObservers: UpdateObserversFn,
|
|
761
|
+
) {
|
|
762
|
+
const dataTable = {
|
|
763
|
+
...snapshot.dataTable,
|
|
764
|
+
__deleted:
|
|
765
|
+
snapshot.dataTable?.active === false ||
|
|
766
|
+
Boolean(snapshot.dataTable?.deletedAt),
|
|
767
|
+
};
|
|
768
|
+
const variables = { organizationId, dataTableId };
|
|
769
|
+
setDataToCache(
|
|
770
|
+
{ dataTable },
|
|
771
|
+
dataTableQry,
|
|
772
|
+
variables,
|
|
773
|
+
undefined,
|
|
774
|
+
updateObservers,
|
|
775
|
+
);
|
|
776
|
+
addFragmentToCache(
|
|
777
|
+
makeFragmentKey(FRAGMENT_NAMES.dataTable, dataTableId),
|
|
778
|
+
getDataTableRealtimeFragmentValue(dataTable),
|
|
779
|
+
);
|
|
780
|
+
updateObservers({
|
|
781
|
+
fragmentIds: [makeFragmentKey(FRAGMENT_NAMES.dataTable, dataTableId)],
|
|
782
|
+
queryId: getDataTableQueryKey(organizationId, dataTableId),
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
/*
|
|
787
|
+
* Fetch and apply one authoritative snapshot after the server confirms room
|
|
788
|
+
* membership. First pages are replaced atomically, cursor pages are invalidated
|
|
789
|
+
* for refetch, and metadata-only subscriptions still receive a fenced snapshot.
|
|
790
|
+
*/
|
|
791
|
+
export async function recoverDataTableRealtimeSubscription(
|
|
792
|
+
organizationId: string,
|
|
793
|
+
dataTableId: string,
|
|
794
|
+
observedToSeq: string,
|
|
795
|
+
updateObservers: UpdateObserversFn,
|
|
796
|
+
params: {
|
|
797
|
+
authToken?: string | null;
|
|
798
|
+
shouldApply?: () => boolean;
|
|
799
|
+
} = {},
|
|
800
|
+
): Promise<DataTableRealtimeRecoveryStatus> {
|
|
801
|
+
const pages = getActiveDataTableSnapshotPages(organizationId, dataTableId);
|
|
802
|
+
const initialPages = pages.filter((variables) => !variables.cursor);
|
|
803
|
+
const cursorPages = pages.filter((variables) => Boolean(variables.cursor));
|
|
804
|
+
const maxLimit = Math.max(
|
|
805
|
+
1,
|
|
806
|
+
...initialPages.map((variables) => variables.limit),
|
|
807
|
+
);
|
|
808
|
+
const requestVariables = {
|
|
809
|
+
dataTableId,
|
|
810
|
+
organizationId,
|
|
811
|
+
cursor: null,
|
|
812
|
+
limit: maxLimit,
|
|
813
|
+
};
|
|
814
|
+
const result = await graphqlRequestNoStore(
|
|
815
|
+
dataTableRowsSnapshotQry,
|
|
816
|
+
requestVariables,
|
|
817
|
+
{
|
|
818
|
+
authToken: params.authToken,
|
|
819
|
+
},
|
|
820
|
+
);
|
|
821
|
+
const snapshot = result?.dataTableRowsSnapshot;
|
|
822
|
+
if (params.shouldApply && !params.shouldApply()) {
|
|
823
|
+
return 'CANCELLED';
|
|
824
|
+
}
|
|
825
|
+
if (
|
|
826
|
+
result?.error ||
|
|
827
|
+
!isApplicableDataTableRowsSnapshot(snapshot, organizationId, dataTableId)
|
|
828
|
+
) {
|
|
829
|
+
return 'RETRY';
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
if (BigInt(snapshot.currentSeq) < BigInt(observedToSeq)) {
|
|
833
|
+
return 'RETRY';
|
|
834
|
+
}
|
|
835
|
+
applyDataTableRecoveryMetadata(
|
|
836
|
+
snapshot,
|
|
837
|
+
organizationId,
|
|
838
|
+
dataTableId,
|
|
839
|
+
updateObservers,
|
|
840
|
+
);
|
|
841
|
+
cursorPages.forEach((variables) => {
|
|
842
|
+
resetQuery(
|
|
843
|
+
getDataTableRowsQueryKey(variables),
|
|
844
|
+
true,
|
|
845
|
+
updateObservers,
|
|
846
|
+
true,
|
|
847
|
+
);
|
|
848
|
+
});
|
|
849
|
+
initialPages.forEach((variables) => {
|
|
850
|
+
setDataToCache(
|
|
851
|
+
{
|
|
852
|
+
dataTableRowsSnapshot: {
|
|
853
|
+
...snapshot,
|
|
854
|
+
rows: snapshot.rows.slice(0, variables.limit),
|
|
855
|
+
},
|
|
856
|
+
},
|
|
857
|
+
dataTableRowsSnapshotQry,
|
|
858
|
+
variables,
|
|
859
|
+
undefined,
|
|
860
|
+
updateObservers,
|
|
861
|
+
);
|
|
862
|
+
updateObservers({
|
|
863
|
+
queryId: getDataTableRowsQueryKey(variables),
|
|
864
|
+
});
|
|
865
|
+
});
|
|
866
|
+
dataTableRealtimeSequenceGate.recordSnapshotFragments(
|
|
867
|
+
organizationId,
|
|
868
|
+
dataTableId,
|
|
869
|
+
snapshot,
|
|
870
|
+
);
|
|
871
|
+
if (dataTableRealtimeSequenceGate.isRegistered(organizationId, dataTableId)) {
|
|
872
|
+
dataTableRealtimeSequenceGate.acknowledgeSnapshot(
|
|
873
|
+
organizationId,
|
|
874
|
+
dataTableId,
|
|
875
|
+
snapshot.currentSeq,
|
|
876
|
+
);
|
|
877
|
+
}
|
|
878
|
+
return 'RECOVERED';
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
/*
|
|
882
|
+
* Read one bounded DataTable journal tail for diagnostics or recovery target
|
|
883
|
+
* selection. Only an applied watermark-bearing snapshot may acknowledge state.
|
|
884
|
+
*/
|
|
885
|
+
export function useDataTableChanges(
|
|
886
|
+
variables: DataTableChangesVariables,
|
|
887
|
+
params: UseQueryParams = {},
|
|
888
|
+
) {
|
|
889
|
+
const queryVariables = {
|
|
890
|
+
dataTableId: variables.dataTableId,
|
|
891
|
+
organizationId: variables.organizationId,
|
|
892
|
+
afterSeq: normalizeDataTableChangeSeq(variables.afterSeq),
|
|
893
|
+
limit: variables.limit ?? DATA_TABLE_CHANGES_LIMIT,
|
|
894
|
+
};
|
|
895
|
+
const { data, ...rest } = useQuery(dataTableChangesQry, {
|
|
896
|
+
variables: queryVariables,
|
|
897
|
+
...params,
|
|
898
|
+
skip:
|
|
899
|
+
!queryVariables.organizationId ||
|
|
900
|
+
!queryVariables.dataTableId ||
|
|
901
|
+
!!params.skip,
|
|
902
|
+
});
|
|
903
|
+
|
|
904
|
+
return {
|
|
905
|
+
dataTableChanges: data?.dataTableChanges,
|
|
906
|
+
...rest,
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
/*
|
|
911
|
+
* Fetch a one-shot uncached DataTable journal tail for future realtime gap
|
|
912
|
+
* recovery. The tail alone cannot acknowledge local state; an awaited
|
|
913
|
+
* watermark-bearing snapshot must do that. Auth-scoped requests never share
|
|
914
|
+
* cached or in-flight results.
|
|
915
|
+
*/
|
|
916
|
+
export async function fetchDataTableChangesTail(
|
|
917
|
+
organizationId: string,
|
|
918
|
+
dataTableId: string,
|
|
919
|
+
afterSeq: DataTableChangeSeqInput,
|
|
920
|
+
params: {
|
|
921
|
+
authToken?: string | null;
|
|
922
|
+
limit?: number;
|
|
923
|
+
} = {},
|
|
924
|
+
) {
|
|
925
|
+
const result = (await graphqlRequestNoStore(
|
|
926
|
+
dataTableChangesQry,
|
|
927
|
+
{
|
|
928
|
+
organizationId,
|
|
929
|
+
dataTableId,
|
|
930
|
+
afterSeq: normalizeDataTableChangeSeq(afterSeq),
|
|
931
|
+
limit: params.limit ?? DATA_TABLE_CHANGES_LIMIT,
|
|
932
|
+
},
|
|
933
|
+
{
|
|
934
|
+
authToken: params.authToken,
|
|
935
|
+
},
|
|
936
|
+
)) as { dataTableChanges?: any; error?: unknown } | null;
|
|
937
|
+
if (result?.error) {
|
|
938
|
+
return null;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
return result?.dataTableChanges || null;
|
|
942
|
+
}
|
|
943
|
+
|
|
138
944
|
/**
|
|
139
945
|
* Get reactive dataTable fragment.
|
|
140
946
|
*/
|
|
141
947
|
|
|
142
|
-
export function useReactiveDataTableFragment(
|
|
143
|
-
|
|
948
|
+
export function useReactiveDataTableFragment(
|
|
949
|
+
dataTableId: string,
|
|
950
|
+
currentData?: any,
|
|
951
|
+
queryCount?: number,
|
|
952
|
+
) {
|
|
953
|
+
const dataTable = useReactiveFragment(
|
|
144
954
|
currentData,
|
|
145
|
-
[
|
|
955
|
+
[makeFragmentKey(FRAGMENT_NAMES.dataTable, dataTableId)],
|
|
146
956
|
queryCount,
|
|
147
957
|
);
|
|
958
|
+
const dataTableWithDeletedStatus = useMemo(
|
|
959
|
+
() => mapDataTableDeletedStatus(dataTable),
|
|
960
|
+
[dataTable],
|
|
961
|
+
);
|
|
962
|
+
|
|
963
|
+
return dataTableWithDeletedStatus;
|
|
148
964
|
}
|
|
149
965
|
|
|
150
966
|
/**
|
|
151
967
|
* Get reactive dataTable row fragment.
|
|
152
968
|
*/
|
|
153
969
|
|
|
154
|
-
export function useReactiveDataTableRowFragment(
|
|
970
|
+
export function useReactiveDataTableRowFragment(
|
|
971
|
+
dataTableRowId: string,
|
|
972
|
+
currentData?: any,
|
|
973
|
+
queryCount?: number,
|
|
974
|
+
) {
|
|
155
975
|
return useReactiveFragment(
|
|
156
976
|
currentData,
|
|
157
|
-
[
|
|
977
|
+
[makeFragmentKey(FRAGMENT_NAMES.dataTableRow, dataTableRowId)],
|
|
158
978
|
queryCount,
|
|
159
979
|
);
|
|
160
980
|
}
|
|
@@ -163,10 +983,14 @@ export function useReactiveDataTableRowFragment(dataTableRowId: string, currentD
|
|
|
163
983
|
* Get reactive dataTable cell fragment.
|
|
164
984
|
*/
|
|
165
985
|
|
|
166
|
-
export function useReactiveDataTableCellFragment(
|
|
986
|
+
export function useReactiveDataTableCellFragment(
|
|
987
|
+
dataTableCellId: string,
|
|
988
|
+
currentData?: any,
|
|
989
|
+
queryCount?: number,
|
|
990
|
+
) {
|
|
167
991
|
return useReactiveFragment(
|
|
168
992
|
currentData,
|
|
169
|
-
[
|
|
993
|
+
[makeFragmentKey(FRAGMENT_NAMES.dataTableCell, dataTableCellId)],
|
|
170
994
|
queryCount,
|
|
171
995
|
);
|
|
172
996
|
}
|