@jsb188/graphql 1.1.11 → 1.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/audience.d.ts +343 -0
- package/cache/config.ts +58 -24
- package/cache/index.chat-activity.test.ts +119 -0
- package/cache/index.chat.test.ts +92 -0
- package/cache/index.helpers.ts +96 -0
- package/cache/index.regression.test.ts +149 -0
- package/cache/index.test.ts +370 -42
- package/cache/index.ts +326 -799
- package/cache/optimistic-ui-runtime.ts +46 -0
- package/cache/optimistic-ui.ts +401 -0
- package/cache/persist.ts +98 -19
- package/cache/store.ts +22 -64
- package/cache/value.helpers.ts +17 -0
- package/{drafts/store.ts → client/draft-persistence-indexed-db.ts} +19 -3
- package/{drafts/index.ts → client/draft-persistence.ts} +5 -2
- package/client/index.ts +3 -2
- package/client/request.helpers.ts +14 -0
- package/client/request.ts +130 -215
- package/deno.lock +17 -0
- package/deno.test.json +2 -0
- package/gql/fragments/agentMemoryFragments.ts +5 -1
- package/gql/fragments/agentNoteFragments.ts +150 -0
- package/gql/fragments/aiChatFragments.ts +36 -10
- package/gql/fragments/audienceFragments.ts +141 -0
- package/gql/fragments/campaignFragments.ts +415 -126
- package/gql/fragments/dataTableFragments.ts +48 -80
- package/gql/fragments/emailFragments.ts +28 -23
- package/gql/fragments/fieldDocFragments.ts +222 -40
- package/gql/fragments/inboundContactFragments.ts +2 -0
- package/gql/fragments/logFragments.ts +93 -2
- package/gql/fragments/organizationFragments.ts +10 -0
- package/gql/fragments/qrCodeFragments.ts +29 -0
- package/gql/fragments/scheduleFragments.ts +652 -140
- package/gql/fragments/sheetFragments.ts +84 -373
- package/gql/fragments/storageFragments.ts +25 -1
- package/gql/fragments/workflowFragments.ts +13 -1
- package/gql/mutations/agentMemoryMutations.ts +32 -0
- package/gql/mutations/agentNoteMutations.ts +62 -0
- package/gql/mutations/aiChatMutations.ts +36 -4
- package/gql/mutations/audienceMutations.ts +71 -0
- package/gql/mutations/authMutations.ts +45 -1
- package/gql/mutations/billingMutations.ts +24 -0
- package/gql/mutations/campaignMutations.ts +170 -127
- package/gql/mutations/contactMutations.ts +23 -0
- package/gql/mutations/dataTableMutations.ts +18 -75
- package/gql/mutations/fieldDocMutations.ts +162 -13
- package/gql/mutations/index.ts +8 -5
- package/gql/mutations/organizationMutations.ts +6 -0
- package/gql/mutations/qrCodeMutations.ts +20 -0
- package/gql/mutations/scheduleMutations.ts +1052 -354
- package/gql/mutations/sheetMutations.ts +62 -118
- package/gql/mutations/storageMutations.ts +0 -1
- package/gql/mutations/workflowMutations.ts +18 -0
- package/gql/queries/agentMemoryQueries.ts +6 -0
- package/gql/queries/agentNoteQueries.ts +89 -0
- package/gql/queries/aiChatQueries.ts +56 -4
- package/gql/queries/audienceQueries.ts +128 -0
- package/gql/queries/authQueries.ts +6 -0
- package/gql/queries/billingQueries.ts +95 -6
- package/gql/queries/campaignQueries.ts +132 -23
- package/gql/queries/dataTableQueries.ts +24 -65
- package/gql/queries/emailQueries.ts +18 -61
- package/gql/queries/emailReplyReportQueries.ts +76 -0
- package/gql/queries/fieldDocQueries.ts +100 -92
- package/gql/queries/inboundContactQueries.ts +4 -0
- package/gql/queries/index.ts +3 -1
- package/gql/queries/logQueries.ts +62 -7
- package/gql/queries/organizationQueries.ts +13 -0
- package/gql/queries/qrCodeQueries.ts +20 -0
- package/gql/queries/scheduleQueries.ts +633 -257
- package/gql/queries/sheetQueries.ts +59 -152
- package/gql/queries/workflowQueries.ts +10 -4
- package/hooks/index.helpers.test.ts +50 -0
- package/hooks/index.helpers.ts +52 -0
- package/hooks/index.ts +863 -685
- package/hooks/use-agentMemory-mtn.ts +29 -31
- package/hooks/use-agentMemory-qry.ts +15 -3
- package/hooks/use-agentNote-mtn.ts +82 -0
- package/hooks/use-agentNote-qry.ts +190 -0
- package/hooks/use-agentNote-recovery.helpers.test.ts +68 -0
- package/hooks/use-agentNote-recovery.helpers.ts +58 -0
- package/hooks/use-agentNote-recovery.ts +72 -0
- package/hooks/use-aiChat-mtn.ts +96 -112
- package/hooks/use-aiChat-qry.helpers.test.ts +63 -0
- package/hooks/use-aiChat-qry.helpers.ts +124 -0
- package/hooks/use-aiChat-qry.ts +229 -383
- package/hooks/use-aiChat-stream-mtn.ts +14 -0
- package/hooks/use-audience-mtn.ts +194 -0
- package/hooks/use-audience-qry.helpers.test.ts +80 -0
- package/hooks/use-audience-qry.helpers.ts +63 -0
- package/hooks/use-audience-qry.ts +330 -0
- package/hooks/use-auth-mtn.ts +30 -1
- package/hooks/use-billing-mtn.ts +31 -0
- package/hooks/use-billing-qry.ts +76 -0
- package/hooks/use-campaign-generation-recovery.ts +53 -0
- package/hooks/use-campaign-mtn.ts +224 -165
- package/hooks/use-campaign-qry.helpers.ts +40 -0
- package/hooks/use-campaign-qry.ts +631 -54
- package/hooks/use-dataTable-mtn.ts +23 -115
- package/hooks/use-dataTable-qry.ts +66 -916
- package/hooks/use-email-qry.helpers.ts +37 -0
- package/hooks/use-email-qry.ts +33 -178
- package/hooks/use-emailCampaignReplyReport-qry.ts +27 -0
- package/hooks/use-fieldDoc-mtn.ts +244 -32
- package/hooks/use-fieldDoc-qry.helpers.test.ts +65 -0
- package/hooks/use-fieldDoc-qry.helpers.ts +49 -0
- package/hooks/use-fieldDoc-qry.ts +134 -102
- package/hooks/use-inboundContact-qry.ts +7 -9
- package/hooks/use-log-mtn.ts +25 -12
- package/hooks/use-log-qry.ts +99 -46
- package/hooks/use-organization-qry.ts +16 -60
- package/hooks/use-publicFormEmail-mtn.ts +27 -0
- package/hooks/use-qrCode-mtn.ts +40 -0
- package/hooks/use-qrCode-qry.ts +78 -0
- package/hooks/use-schedule-mtn.ts +506 -333
- package/hooks/use-schedule-qry.ts +682 -101
- package/hooks/use-schedule-reactive.ts +486 -0
- package/hooks/use-sheet-mtn.ts +91 -199
- package/hooks/use-sheet-qry.ts +84 -238
- package/hooks/use-storage-qry.ts +84 -61
- package/hooks/use-workflow-mtn.ts +39 -22
- package/hooks/use-workflow-qry.ts +40 -61
- package/libs/ai-chat-outgoing.helpers.ts +153 -0
- package/libs/ai-chat-outgoing.ts +11 -0
- package/libs/ai-chat-outgoing.types.ts +25 -0
- package/libs/ai-chat-run-realtime.ts +20 -0
- package/libs/ai-chat-submission-realtime.ts +150 -0
- package/libs/fragment-realtime-sequence.ts +55 -0
- package/libs/fragment-recovery.test.ts +326 -0
- package/libs/fragment-recovery.ts +325 -0
- package/libs/open-sheet.ts +138 -0
- package/libs/orchestrator-realtime.helpers.test.ts +229 -0
- package/libs/orchestrator-realtime.helpers.ts +317 -0
- package/libs/orchestrator-realtime.ts +433 -0
- package/libs/request-cache-regression.test.ts +122 -0
- package/{client → libs}/request-managed-session.test.ts +1 -1
- package/libs/request-no-store.test.ts +419 -0
- package/libs/sheet-command-batch.ts +44 -0
- package/libs/sheet-view-realtime-router.test.ts +214 -0
- package/libs/sheet-view-realtime-router.ts +99 -0
- package/loaders/campaign.test.ts +186 -0
- package/loaders/campaign.ts +56 -83
- package/loaders/emailPreference.ts +75 -0
- package/loaders/rest.ts +12 -0
- package/package.json +42 -17
- package/schedule.d.ts +1790 -0
- package/sse.helpers.ts +19 -0
- package/sse.ts +26 -115
- package/tests/agent-note-detail-cache.test.ts +120 -0
- package/tests/agent-note-search.test.ts +444 -0
- package/types.d.ts +46 -25
- package/client/data-table-realtime-subscriptions.test.ts +0 -740
- package/client/data-table-realtime-subscriptions.ts +0 -955
- package/client/data-table-realtime.test.ts +0 -792
- package/client/data-table-realtime.ts +0 -1218
- package/client/fragment-realtime-sequence.ts +0 -52
- package/client/open-sheet.ts +0 -137
- package/client/request-no-store.test.ts +0 -157
- package/gql/fragments/agentDocFragments.ts +0 -46
- package/gql/fragments/billingFragments.ts +0 -14
- package/gql/mutations/agentDocMutations.ts +0 -177
- package/gql/queries/agentDocQueries.ts +0 -120
- package/hooks/use-agentDoc-mtn.ts +0 -285
- package/hooks/use-agentDoc-qry.ts +0 -208
- /package/{client → libs}/sse-ticket.test.ts +0 -0
|
@@ -1,996 +1,146 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
graphqlRequestNoStore,
|
|
4
|
-
useQuery,
|
|
5
|
-
useReactiveFragment,
|
|
6
|
-
useReactiveFragmentMap,
|
|
7
|
-
useUpdateObservers,
|
|
8
|
-
} from '@jsb188/graphql/client';
|
|
1
|
+
import { FRAGMENT_NAMES, getFragmentBaseName, makeFragmentKey } from '@jsb188/mday/constants/graphqlReactivity.ts';
|
|
9
2
|
import { GRID_ITEM_LIST_LIMIT } from '@jsb188/mday/constants/sheet.ts';
|
|
10
|
-
import type {
|
|
3
|
+
import type { DtSortDirectionEnum } from '@jsb188/mday/types/dt.d.ts';
|
|
11
4
|
import type { GridItemSortEnum } from '@jsb188/mday/types/sheet.d.ts';
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
import { dataTableQry, dataTableRowsQry, dataTableRunsQry, dataTablesQry } from '../gql/queries/dataTableQueries.ts';
|
|
6
|
+
import type { PaginationArgs, UseQueryParams } from '../types.d.ts';
|
|
7
|
+
import { useQuery, useReactiveFragment, useReactiveFragmentMap } from './index.ts';
|
|
48
8
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
*/
|
|
52
|
-
|
|
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;
|
|
9
|
+
export type DataTablesFilterVariables = {
|
|
10
|
+
search?: string | null;
|
|
85
11
|
};
|
|
86
12
|
|
|
87
13
|
export type DataTablesVariables = PaginationArgs & {
|
|
88
|
-
filter?:
|
|
14
|
+
filter?: DataTablesFilterVariables | null;
|
|
89
15
|
organizationId?: string | null;
|
|
90
16
|
sort?: GridItemSortEnum | null;
|
|
91
17
|
};
|
|
92
18
|
|
|
93
|
-
type
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
19
|
+
export type DataTableRowsVariables = {
|
|
20
|
+
organizationId?: string | null;
|
|
21
|
+
dataTableId?: string | null;
|
|
22
|
+
sort?: { column: string; direction: DtSortDirectionEnum } | null;
|
|
23
|
+
cursor?: string | null;
|
|
24
|
+
limit?: number | null;
|
|
98
25
|
};
|
|
99
26
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
}
|
|
316
|
-
|
|
317
|
-
/*
|
|
318
|
-
* Return all dataTable cell records nested under the provided dataTable rows.
|
|
319
|
-
*/
|
|
320
|
-
|
|
321
|
-
function getDataTableRowCells(dataTableRows?: any[] | null) {
|
|
322
|
-
return dataTableRows?.flatMap((row) => row.cells || []) || null;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/*
|
|
326
|
-
* Merge reactive dataTable cell fragments back into their parent dataTable rows.
|
|
327
|
-
*/
|
|
328
|
-
|
|
329
|
-
function mergeReactiveCellsIntoRows(
|
|
330
|
-
dataTableRows?: any[] | null,
|
|
331
|
-
dataTableCells?: any[] | null,
|
|
332
|
-
) {
|
|
333
|
-
if (!dataTableRows || !dataTableCells) {
|
|
334
|
-
return dataTableRows;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
const cellMap = new Map(dataTableCells.map((cell) => [cell.id, cell]));
|
|
338
|
-
let changedRows = false;
|
|
339
|
-
|
|
340
|
-
const nextRows = dataTableRows.map((row) => {
|
|
341
|
-
let changedCells = false;
|
|
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
|
-
}
|
|
348
|
-
|
|
349
|
-
return nextCell;
|
|
350
|
-
}) || [];
|
|
351
|
-
|
|
352
|
-
if (!changedCells) {
|
|
353
|
-
return row;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
changedRows = true;
|
|
357
|
-
|
|
358
|
-
return {
|
|
359
|
-
...row,
|
|
360
|
-
cells: nextCells,
|
|
361
|
-
};
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
return changedRows ? nextRows : dataTableRows;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
/*
|
|
368
|
-
* Get reactive dataTable rows and their nested cell fragments.
|
|
369
|
-
*/
|
|
370
|
-
|
|
371
|
-
export function useReactiveDataTableRows(dataTableRows?: any[] | null) {
|
|
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
|
-
);
|
|
380
|
-
|
|
381
|
-
return mergeReactiveCellsIntoRows(
|
|
382
|
-
reactiveRows || dataTableRows,
|
|
383
|
-
reactiveCells,
|
|
384
|
-
);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
/*
|
|
388
|
-
* Return the query key that belongs to one dataTable rows variables payload.
|
|
389
|
-
*/
|
|
390
|
-
|
|
391
|
-
function getDataTableRowsQueryKey(variables: Record<string, unknown>) {
|
|
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
|
-
}
|
|
27
|
+
export type DataTableRunsVariables = {
|
|
28
|
+
organizationId?: string | null;
|
|
29
|
+
dataTableId?: string | null;
|
|
30
|
+
limit?: number | null;
|
|
31
|
+
};
|
|
551
32
|
|
|
552
33
|
/*
|
|
553
34
|
* Return whether one useDataTables input is the paginated variables object.
|
|
554
35
|
*/
|
|
555
|
-
function isDataTablesVariables(
|
|
556
|
-
value: string | null | undefined | DataTablesVariables,
|
|
557
|
-
): value is DataTablesVariables {
|
|
36
|
+
function isDataTablesVariables(value: string | null | undefined | DataTablesVariables): value is DataTablesVariables {
|
|
558
37
|
return !!value && typeof value === 'object';
|
|
559
38
|
}
|
|
560
39
|
|
|
561
40
|
/*
|
|
562
41
|
* Return GraphQL variables for the paginated dataTables query.
|
|
563
42
|
*/
|
|
564
|
-
function getDataTablesQueryVariables(
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
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
|
-
|
|
43
|
+
function getDataTablesQueryVariables(organizationIdOrVariables?: string | null | DataTablesVariables): DataTablesVariables {
|
|
44
|
+
const variables = isDataTablesVariables(organizationIdOrVariables)
|
|
45
|
+
? organizationIdOrVariables
|
|
46
|
+
: { organizationId: organizationIdOrVariables };
|
|
579
47
|
return {
|
|
580
|
-
|
|
581
|
-
after: true,
|
|
582
|
-
cursor: null,
|
|
583
|
-
filter:
|
|
584
|
-
limit: GRID_ITEM_LIST_LIMIT,
|
|
585
|
-
sort: 'UPDATED_AT_DESC',
|
|
48
|
+
...variables,
|
|
49
|
+
after: variables.after ?? true,
|
|
50
|
+
cursor: variables.cursor ?? null,
|
|
51
|
+
filter: variables.filter ?? null,
|
|
52
|
+
limit: variables.limit ?? GRID_ITEM_LIST_LIMIT,
|
|
53
|
+
sort: variables.sort || 'UPDATED_AT_DESC',
|
|
586
54
|
};
|
|
587
55
|
}
|
|
588
56
|
|
|
589
57
|
/**
|
|
590
|
-
* Fetch
|
|
58
|
+
* Fetch the listed data tables of an organization the viewer may read, newest first.
|
|
591
59
|
*/
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
organizationId?: string | null | DataTablesVariables,
|
|
595
|
-
active?: boolean | null,
|
|
596
|
-
params: UseQueryParams = {},
|
|
597
|
-
) {
|
|
598
|
-
const variables = getDataTablesQueryVariables(organizationId, active);
|
|
599
|
-
const updateObservers = useUpdateObservers();
|
|
60
|
+
export function useDataTables(organizationId?: string | null | DataTablesVariables, params: UseQueryParams = {}) {
|
|
61
|
+
const variables = getDataTablesQueryVariables(organizationId);
|
|
600
62
|
const { data, ...rest } = useQuery(dataTablesQry, {
|
|
601
63
|
variables,
|
|
602
|
-
skip: !variables.organizationId,
|
|
603
64
|
...params,
|
|
604
|
-
|
|
605
|
-
healDataTableDeletedFlags(result?.dataTables, updateObservers);
|
|
606
|
-
params.onCompleted?.(result, error, completedVariables);
|
|
607
|
-
},
|
|
65
|
+
skip: !variables.organizationId || !!params.skip,
|
|
608
66
|
});
|
|
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
|
-
);
|
|
67
|
+
const dataTables = useReactiveFragmentMap(data?.dataTables || null, getFragmentBaseName(FRAGMENT_NAMES.dataTable));
|
|
617
68
|
|
|
618
69
|
return {
|
|
619
|
-
dataTables
|
|
70
|
+
dataTables,
|
|
620
71
|
...rest,
|
|
621
72
|
};
|
|
622
73
|
}
|
|
623
74
|
|
|
624
75
|
/*
|
|
625
|
-
* Fetch one
|
|
76
|
+
* Fetch one data table (metadata, columns, sync state and owner note).
|
|
626
77
|
*/
|
|
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();
|
|
78
|
+
export function useDataTable(dataTableId?: string | null, organizationId?: string | null, params: UseQueryParams = {}) {
|
|
635
79
|
const { data, ...rest } = useQuery(dataTableQry, {
|
|
636
80
|
variables: {
|
|
637
81
|
organizationId,
|
|
638
82
|
dataTableId,
|
|
639
83
|
},
|
|
640
84
|
...params,
|
|
641
|
-
skip: !organizationId || !dataTableId ||
|
|
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
|
-
},
|
|
85
|
+
skip: !organizationId || !dataTableId || !!params.skip,
|
|
649
86
|
});
|
|
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
|
-
);
|
|
87
|
+
const dataTable = useReactiveDataTableFragment(dataTableId || '', data?.dataTable || null, rest.updatedCount);
|
|
670
88
|
|
|
671
89
|
return {
|
|
672
|
-
dataTable:
|
|
90
|
+
dataTable: dataTable?.id === dataTableId ? dataTable : null,
|
|
673
91
|
...rest,
|
|
674
92
|
};
|
|
675
93
|
}
|
|
676
94
|
|
|
677
|
-
|
|
678
|
-
* Fetch rows
|
|
95
|
+
/*
|
|
96
|
+
* Fetch one keyset page of a data table's live rows (100 by default), in id
|
|
97
|
+
* order or sorted by one column. The server resets this query (RESET_ONLY)
|
|
98
|
+
* when the table's rows change.
|
|
679
99
|
*/
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
realtimeToken?: string | null,
|
|
688
|
-
) {
|
|
689
|
-
const skipQuery = !organizationId || !dataTableId || Boolean(params.skip);
|
|
690
|
-
const variables = {
|
|
691
|
-
dataTableId,
|
|
692
|
-
organizationId,
|
|
693
|
-
cursor,
|
|
694
|
-
limit,
|
|
100
|
+
export function useDataTableRows(variables: DataTableRowsVariables, params: UseQueryParams = {}) {
|
|
101
|
+
const queryVariables = {
|
|
102
|
+
organizationId: variables.organizationId,
|
|
103
|
+
dataTableId: variables.dataTableId,
|
|
104
|
+
sort: variables.sort ?? null,
|
|
105
|
+
cursor: variables.cursor ?? null,
|
|
106
|
+
limit: variables.limit ?? 100,
|
|
695
107
|
};
|
|
696
|
-
|
|
697
|
-
|
|
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, {
|
|
711
|
-
variables,
|
|
108
|
+
const { data, ...rest } = useQuery(dataTableRowsQry, {
|
|
109
|
+
variables: queryVariables,
|
|
712
110
|
...params,
|
|
713
|
-
skip:
|
|
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
|
-
},
|
|
111
|
+
skip: !queryVariables.organizationId || !queryVariables.dataTableId || !!params.skip,
|
|
739
112
|
});
|
|
740
113
|
|
|
741
|
-
const queryMatchesVariables =
|
|
742
|
-
rest.queryKey === getDataTableRowsQueryKey(variables) ||
|
|
743
|
-
rest.variablesKey === makeVariablesKey(variables);
|
|
744
|
-
const snapshot = queryMatchesVariables ? data?.dataTableRowsSnapshot : null;
|
|
745
|
-
const dataTableRows = useReactiveDataTableRows(snapshot?.rows || null);
|
|
746
114
|
return {
|
|
747
|
-
dataTableRows:
|
|
115
|
+
dataTableRows: data?.dataTableRows || null,
|
|
748
116
|
...rest,
|
|
749
117
|
};
|
|
750
118
|
}
|
|
751
119
|
|
|
752
120
|
/*
|
|
753
|
-
*
|
|
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.
|
|
121
|
+
* Fetch the newest change batches (runs) of a data table.
|
|
884
122
|
*/
|
|
885
|
-
export function
|
|
886
|
-
variables: DataTableChangesVariables,
|
|
887
|
-
params: UseQueryParams = {},
|
|
888
|
-
) {
|
|
123
|
+
export function useDataTableRuns(variables: DataTableRunsVariables, params: UseQueryParams = {}) {
|
|
889
124
|
const queryVariables = {
|
|
890
|
-
dataTableId: variables.dataTableId,
|
|
891
125
|
organizationId: variables.organizationId,
|
|
892
|
-
|
|
893
|
-
limit: variables.limit ??
|
|
126
|
+
dataTableId: variables.dataTableId,
|
|
127
|
+
limit: variables.limit ?? 10,
|
|
894
128
|
};
|
|
895
|
-
const { data, ...rest } = useQuery(
|
|
129
|
+
const { data, ...rest } = useQuery(dataTableRunsQry, {
|
|
896
130
|
variables: queryVariables,
|
|
897
131
|
...params,
|
|
898
|
-
skip:
|
|
899
|
-
!queryVariables.organizationId ||
|
|
900
|
-
!queryVariables.dataTableId ||
|
|
901
|
-
!!params.skip,
|
|
132
|
+
skip: !queryVariables.organizationId || !queryVariables.dataTableId || !!params.skip,
|
|
902
133
|
});
|
|
903
134
|
|
|
904
135
|
return {
|
|
905
|
-
|
|
136
|
+
dataTableRuns: data?.dataTableRuns || null,
|
|
906
137
|
...rest,
|
|
907
138
|
};
|
|
908
139
|
}
|
|
909
140
|
|
|
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
|
-
|
|
944
141
|
/**
|
|
945
|
-
* Get reactive
|
|
142
|
+
* Get the reactive data table fragment.
|
|
946
143
|
*/
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
dataTableId: string,
|
|
950
|
-
currentData?: any,
|
|
951
|
-
queryCount?: number,
|
|
952
|
-
) {
|
|
953
|
-
const dataTable = useReactiveFragment(
|
|
954
|
-
currentData,
|
|
955
|
-
[makeFragmentKey(FRAGMENT_NAMES.dataTable, dataTableId)],
|
|
956
|
-
queryCount,
|
|
957
|
-
);
|
|
958
|
-
const dataTableWithDeletedStatus = useMemo(
|
|
959
|
-
() => mapDataTableDeletedStatus(dataTable),
|
|
960
|
-
[dataTable],
|
|
961
|
-
);
|
|
962
|
-
|
|
963
|
-
return dataTableWithDeletedStatus;
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
/**
|
|
967
|
-
* Get reactive dataTable row fragment.
|
|
968
|
-
*/
|
|
969
|
-
|
|
970
|
-
export function useReactiveDataTableRowFragment(
|
|
971
|
-
dataTableRowId: string,
|
|
972
|
-
currentData?: any,
|
|
973
|
-
queryCount?: number,
|
|
974
|
-
) {
|
|
975
|
-
return useReactiveFragment(
|
|
976
|
-
currentData,
|
|
977
|
-
[makeFragmentKey(FRAGMENT_NAMES.dataTableRow, dataTableRowId)],
|
|
978
|
-
queryCount,
|
|
979
|
-
);
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
/**
|
|
983
|
-
* Get reactive dataTable cell fragment.
|
|
984
|
-
*/
|
|
985
|
-
|
|
986
|
-
export function useReactiveDataTableCellFragment(
|
|
987
|
-
dataTableCellId: string,
|
|
988
|
-
currentData?: any,
|
|
989
|
-
queryCount?: number,
|
|
990
|
-
) {
|
|
991
|
-
return useReactiveFragment(
|
|
992
|
-
currentData,
|
|
993
|
-
[makeFragmentKey(FRAGMENT_NAMES.dataTableCell, dataTableCellId)],
|
|
994
|
-
queryCount,
|
|
995
|
-
);
|
|
144
|
+
export function useReactiveDataTableFragment(dataTableId: string, currentData?: any, queryCount?: number) {
|
|
145
|
+
return useReactiveFragment(currentData, dataTableId ? [makeFragmentKey(FRAGMENT_NAMES.dataTable, dataTableId)] : [], queryCount);
|
|
996
146
|
}
|