@jsb188/graphql 1.1.12 → 1.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/LICENSE +21 -0
  2. package/audience.d.ts +14 -152
  3. package/cache/config.ts +35 -32
  4. package/cache/index.helpers.ts +1 -1
  5. package/cache/index.ts +73 -44
  6. package/cache/mounted-queries.ts +33 -0
  7. package/cache/persist.ts +10 -4
  8. package/cache/realtime-fence.ts +47 -0
  9. package/cache/realtime-live.ts +17 -0
  10. package/client/draft-persistence.ts +10 -39
  11. package/client/index.ts +2 -1
  12. package/client/request.ts +9 -34
  13. package/client/storage-asset.ts +58 -0
  14. package/gql/fragments/accountAuthFragments.ts +0 -4
  15. package/gql/fragments/agentNoteFragments.ts +8 -2
  16. package/gql/fragments/aiChatFragments.ts +0 -2
  17. package/gql/fragments/aiChatLinkFragments.ts +8 -0
  18. package/gql/fragments/audienceFragments.ts +1 -66
  19. package/gql/fragments/emailFragments.ts +27 -4
  20. package/gql/fragments/emailOutreachFragments.ts +281 -0
  21. package/gql/fragments/inboundContactFragments.ts +1 -1
  22. package/gql/fragments/libraryFragments.ts +120 -0
  23. package/gql/fragments/organizationFragments.ts +4 -2
  24. package/gql/fragments/scheduleFragments.ts +241 -324
  25. package/gql/fragments/sheetFragments.ts +4 -53
  26. package/gql/fragments/workWaitFragments.ts +13 -0
  27. package/gql/fragments/workflowFragments.ts +20 -4
  28. package/gql/mutations/agentNoteMutations.ts +2 -0
  29. package/gql/mutations/aiChatLinkMutations.ts +13 -0
  30. package/gql/mutations/aiChatMutations.ts +4 -6
  31. package/gql/mutations/audienceMutations.ts +0 -13
  32. package/gql/mutations/authMutations.ts +12 -60
  33. package/gql/mutations/emailMutations.ts +22 -0
  34. package/gql/mutations/emailOutreachMutations.ts +139 -0
  35. package/gql/mutations/index.ts +3 -1
  36. package/gql/mutations/organizationMutations.ts +2 -2
  37. package/gql/mutations/scheduleMutations.ts +61 -787
  38. package/gql/mutations/storageMutations.ts +1 -0
  39. package/gql/mutations/workflowMutations.ts +76 -0
  40. package/gql/queries/agentMemoryQueries.ts +6 -2
  41. package/gql/queries/agentNoteQueries.ts +26 -29
  42. package/gql/queries/aiChatQueries.ts +39 -40
  43. package/gql/queries/audienceQueries.ts +31 -55
  44. package/gql/queries/authQueries.ts +16 -6
  45. package/gql/queries/billingQueries.ts +26 -10
  46. package/gql/queries/dataTableQueries.ts +24 -15
  47. package/gql/queries/emailOutreachQueries.ts +282 -0
  48. package/gql/queries/emailQueries.ts +39 -12
  49. package/gql/queries/emailReplyReportQueries.ts +60 -9
  50. package/gql/queries/fieldDocQueries.ts +36 -14
  51. package/gql/queries/inboundContactQueries.ts +11 -4
  52. package/gql/queries/index.ts +2 -2
  53. package/gql/queries/libraryQueries.ts +112 -0
  54. package/gql/queries/logQueries.ts +31 -12
  55. package/gql/queries/organizationQueries.ts +31 -12
  56. package/gql/queries/qrCodeQueries.ts +11 -4
  57. package/gql/queries/scheduleQueries.ts +252 -505
  58. package/gql/queries/sheetQueries.ts +36 -14
  59. package/gql/queries/storageQueries.ts +11 -4
  60. package/gql/queries/workflowQueries.ts +53 -10
  61. package/gql/reactivity.ts +98 -0
  62. package/gql/recordReads.ts +171 -0
  63. package/hooks/index.ts +79 -52
  64. package/hooks/use-agentNote-mtn.ts +7 -0
  65. package/hooks/use-agentNote-qry.ts +30 -58
  66. package/hooks/use-agentNote-recovery.ts +6 -21
  67. package/hooks/use-aiChat-mtn.ts +9 -4
  68. package/hooks/use-aiChat-qry.ts +28 -7
  69. package/hooks/use-audience-mtn.ts +0 -24
  70. package/hooks/use-audience-qry.helpers.ts +0 -24
  71. package/hooks/use-audience-qry.ts +1 -86
  72. package/hooks/use-dataTable-mtn.ts +3 -3
  73. package/hooks/use-dataTable-qry.ts +7 -2
  74. package/hooks/use-email-mtn.ts +26 -0
  75. package/hooks/use-email-qry.helpers.ts +1 -1
  76. package/hooks/use-email-qry.ts +18 -3
  77. package/hooks/use-emailOutreach-mtn.ts +211 -0
  78. package/hooks/use-emailOutreach-qry.helpers.ts +25 -0
  79. package/hooks/use-emailOutreach-qry.ts +367 -0
  80. package/hooks/use-emailOutreachReplyReport-qry.ts +46 -0
  81. package/hooks/use-fieldDoc-qry.ts +1 -1
  82. package/hooks/use-library-qry.ts +233 -0
  83. package/hooks/use-qrCode-qry.ts +1 -1
  84. package/hooks/use-schedule-mtn.ts +10 -300
  85. package/hooks/use-schedule-qry.ts +168 -680
  86. package/hooks/use-schedule-reactive.ts +71 -339
  87. package/hooks/use-sheet-qry.ts +6 -1
  88. package/hooks/use-workflow-mtn.ts +45 -1
  89. package/hooks/use-workflow-qry.ts +22 -2
  90. package/libs/ai-chat-link-events.ts +78 -0
  91. package/libs/data-changes.helpers.ts +161 -0
  92. package/libs/data-changes.ts +382 -0
  93. package/libs/fragment-realtime-sequence.ts +3 -3
  94. package/libs/record-read.ts +327 -0
  95. package/libs/sheet-command-batch.ts +3 -2
  96. package/libs/sheet-realtime-packet.ts +53 -0
  97. package/loaders/emailPreference.ts +18 -24
  98. package/package.json +44 -17
  99. package/schedule.d.ts +267 -874
  100. package/types.d.ts +3 -1
  101. package/cache/index.chat-activity.test.ts +0 -119
  102. package/cache/index.chat.test.ts +0 -92
  103. package/cache/index.regression.test.ts +0 -149
  104. package/cache/index.test.ts +0 -1209
  105. package/deno.lock +0 -187
  106. package/deno.test.json +0 -12
  107. package/gql/fragments/campaignFragments.ts +0 -566
  108. package/gql/mutations/campaignMutations.ts +0 -258
  109. package/gql/queries/appQueries.ts +0 -14
  110. package/gql/queries/campaignQueries.ts +0 -236
  111. package/hooks/index.helpers.test.ts +0 -50
  112. package/hooks/use-agentNote-recovery.helpers.test.ts +0 -68
  113. package/hooks/use-aiChat-qry.helpers.test.ts +0 -63
  114. package/hooks/use-app-qry.ts +0 -22
  115. package/hooks/use-audience-qry.helpers.test.ts +0 -80
  116. package/hooks/use-campaign-generation-recovery.ts +0 -53
  117. package/hooks/use-campaign-mtn.ts +0 -436
  118. package/hooks/use-campaign-qry.helpers.ts +0 -40
  119. package/hooks/use-campaign-qry.ts +0 -834
  120. package/hooks/use-emailCampaignReplyReport-qry.ts +0 -27
  121. package/hooks/use-fieldDoc-qry.helpers.test.ts +0 -65
  122. package/hooks/use-publicFormEmail-mtn.ts +0 -27
  123. package/libs/fragment-recovery.test.ts +0 -326
  124. package/libs/fragment-recovery.ts +0 -325
  125. package/libs/orchestrator-realtime.helpers.test.ts +0 -229
  126. package/libs/orchestrator-realtime.helpers.ts +0 -317
  127. package/libs/orchestrator-realtime.ts +0 -433
  128. package/libs/request-cache-regression.test.ts +0 -122
  129. package/libs/request-managed-session.test.ts +0 -574
  130. package/libs/request-no-store.test.ts +0 -419
  131. package/libs/sheet-view-realtime-router.test.ts +0 -214
  132. package/libs/sse-ticket.test.ts +0 -26
  133. package/loaders/campaign.test.ts +0 -186
  134. package/loaders/campaign.ts +0 -110
  135. package/tests/agent-note-detail-cache.test.ts +0 -120
  136. package/tests/agent-note-search.test.ts +0 -444
  137. package/tsconfig.json +0 -13
@@ -1,7 +1,9 @@
1
1
  import { gql } from 'graphql-tag';
2
2
  import { sheetFragment, sheetMetadataFragment, sheetTabFragment, sheetTabSummaryFragment } from '../fragments/sheetFragments.ts';
3
+ import { live } from '../reactivity.ts';
3
4
 
4
- export const sheetsQry = gql`
5
+ export const sheetsQry = live(
6
+ gql`
5
7
  query sheets (
6
8
  $organizationId: GenericID!
7
9
  $sort: GridItemSort
@@ -21,9 +23,12 @@ query sheets (
21
23
  }
22
24
 
23
25
  ${sheetFragment}
24
- `;
26
+ `,
27
+ { refresh: 'notice', lists: ['sheet'] },
28
+ );
25
29
 
26
- export const publicSheetMetadataQry = gql`
30
+ export const publicSheetMetadataQry = live(
31
+ gql`
27
32
  query publicSheetMetadata (
28
33
  $sheetId: GenericID!
29
34
  ) {
@@ -35,14 +40,17 @@ query publicSheetMetadata (
35
40
  }
36
41
 
37
42
  ${sheetMetadataFragment}
38
- `;
43
+ `,
44
+ { refresh: 'auto' },
45
+ );
39
46
 
40
47
  // NOTE: sheetAccess is viewer-specific and works signed out: the public
41
48
  // sheet route uses it to learn the owner org and view/edit facts, and the
42
49
  // in-app Sheet page uses it for the viewer's effective edit fact (grants
43
50
  // are per-viewer overrides, so the base policy alone cannot decide it).
44
51
 
45
- export const sheetAccessQry = gql`
52
+ export const sheetAccessQry = live(
53
+ gql`
46
54
  query sheetAccess (
47
55
  $sheetId: GenericID!
48
56
  ) {
@@ -56,13 +64,16 @@ query sheetAccess (
56
64
  signInRequired
57
65
  }
58
66
  }
59
- `;
67
+ `,
68
+ { refresh: 'auto', derived: ['sheetAccess'] },
69
+ );
60
70
 
61
71
  // NOTE: sheetAccessGrants is owner-org only: the access settings screen
62
72
  // loads the grants list with it, on top of the base policy carried by the
63
73
  // Sheet fragment's "access" selection.
64
74
 
65
- export const sheetAccessGrantsQry = gql`
75
+ export const sheetAccessGrantsQry = live(
76
+ gql`
66
77
  query sheetAccessGrants (
67
78
  $organizationId: GenericID!
68
79
  $sheetId: GenericID!
@@ -76,7 +87,9 @@ query sheetAccessGrants (
76
87
  permission
77
88
  }
78
89
  }
79
- `;
90
+ `,
91
+ { refresh: 'auto' },
92
+ );
80
93
 
81
94
  // NOTE: openSheet is the page-bootstrap contract (contract 4). It derives the
82
95
  // owner org from sheetId, folds viewer access into the response, and serves a
@@ -84,7 +97,8 @@ query sheetAccessGrants (
84
97
  // the topology rows the image absorbed after sinceSeq, so pending work
85
98
  // re-maps through them).
86
99
 
87
- export const openSheetQry = gql`
100
+ export const openSheetQry = live(
101
+ gql`
88
102
  query openSheet (
89
103
  $sheetId: GenericID!
90
104
  $selectedTabId: GenericID
@@ -173,13 +187,16 @@ query openSheet (
173
187
  ${sheetFragment}
174
188
  ${sheetTabFragment}
175
189
  ${sheetTabSummaryFragment}
176
- `;
190
+ `,
191
+ { refresh: 'auto' },
192
+ );
177
193
 
178
194
  // NOTE: renewSheetRealtimeCapability re-runs openSheet's authorization over a
179
195
  // fence-only read and returns fresh signed capabilities, never workbook data.
180
196
  // It is fetched no-store only: bearer tokens must stay out of the cache.
181
197
 
182
- export const renewSheetRealtimeCapabilityQry = gql`
198
+ export const renewSheetRealtimeCapabilityQry = live(
199
+ gql`
183
200
  query renewSheetRealtimeCapability (
184
201
  $sheetId: GenericID!
185
202
  ) {
@@ -199,13 +216,16 @@ query renewSheetRealtimeCapability (
199
216
  realtimeToken
200
217
  }
201
218
  }
202
- `;
219
+ `,
220
+ { refresh: 'auto' },
221
+ );
203
222
 
204
223
  // NOTE: syncSheetTab is the tab-only snapshot/delta negotiation (contract 3)
205
224
  // used once the workbook manifest is known: a gap, a selection or a
206
225
  // watermark catch-up asks for the rows after the tab's applied sinceSeq.
207
226
 
208
- export const syncSheetTabQry = gql`
227
+ export const syncSheetTabQry = live(
228
+ gql`
209
229
  query syncSheetTab (
210
230
  $sheetId: GenericID!
211
231
  $sheetTabId: GenericID!
@@ -287,4 +307,6 @@ query syncSheetTab (
287
307
  }
288
308
 
289
309
  ${sheetTabFragment}
290
- `;
310
+ `,
311
+ { refresh: 'auto' },
312
+ );
@@ -1,7 +1,9 @@
1
1
  import { gql } from 'graphql-tag';
2
2
  import { generatedFileFragment } from '../fragments/storageFragments.ts';
3
+ import { live } from '../reactivity.ts';
3
4
 
4
- export const generatedFilesQry = gql`
5
+ export const generatedFilesQry = live(
6
+ gql`
5
7
  query generatedFiles (
6
8
  $organizationId: GenericID!
7
9
  $cursor: Cursor
@@ -19,9 +21,12 @@ query generatedFiles (
19
21
  }
20
22
 
21
23
  ${generatedFileFragment}
22
- `;
24
+ `,
25
+ { refresh: 'auto', lists: ['generatedFile'] },
26
+ );
23
27
 
24
- export const generatedFileQry = gql`
28
+ export const generatedFileQry = live(
29
+ gql`
25
30
  query generatedFile (
26
31
  $organizationId: GenericID!
27
32
  $code: String!
@@ -35,4 +40,6 @@ query generatedFile (
35
40
  }
36
41
 
37
42
  ${generatedFileFragment}
38
- `;
43
+ `,
44
+ { refresh: 'auto' },
45
+ );
@@ -1,16 +1,23 @@
1
1
  import { gql } from 'graphql-tag';
2
2
  import { workflowFragment, workflowRunFragment } from '../fragments/workflowFragments.ts';
3
+ import { workWaitItemFragment } from '../fragments/workWaitFragments.ts';
4
+ import { live } from '../reactivity.ts';
3
5
 
4
- export const workflowQry = gql`
6
+ export const workflowQry = live(
7
+ gql`
5
8
  query workflow ($workflowId: GenericID!) {
6
9
  workflow (workflowId: $workflowId) {
7
10
  ...workflowFragment
8
11
  }
9
12
  }
10
13
  ${workflowFragment}
11
- `;
14
+ ${workWaitItemFragment}
15
+ `,
16
+ { refresh: 'auto' },
17
+ );
12
18
 
13
- export const workflowMetadataQry = gql`
19
+ export const workflowMetadataQry = live(
20
+ gql`
14
21
  query workflowMetadata (
15
22
  $workflowId: GenericID!
16
23
  ) {
@@ -21,9 +28,12 @@ query workflowMetadata (
21
28
  title
22
29
  }
23
30
  }
24
- `;
31
+ `,
32
+ { refresh: 'auto' },
33
+ );
25
34
 
26
- export const workflowsQry = gql`
35
+ export const workflowsQry = live(
36
+ gql`
27
37
  query workflows (
28
38
  $organizationId: GenericID!
29
39
  $filter: WorkflowsFilter!
@@ -50,9 +60,37 @@ query workflows (
50
60
 
51
61
  ${workflowFragment}
52
62
  ${workflowRunFragment}
53
- `;
63
+ ${workWaitItemFragment}
64
+ `,
65
+ { refresh: 'notice', lists: ['workflow'] },
66
+ );
54
67
 
55
- export const workflowRunsQry = gql`
68
+ // The workflow of one form, for the notice on its page. Not a table, so a workflow added elsewhere refetches it quietly
69
+ // instead of raising the "new data" notice; the alias keeps it apart from workflowsQry's declaration
70
+ export const fieldDocWorkflowQry = live(
71
+ gql`
72
+ query fieldDocWorkflow (
73
+ $organizationId: GenericID!
74
+ $fieldDocId: GenericID!
75
+ ) {
76
+ fieldDocWorkflow: workflows (
77
+ organizationId: $organizationId
78
+ filter: { kind: WORKFLOW, fieldDocId: $fieldDocId }
79
+ after: true
80
+ limit: 1
81
+ ) {
82
+ ...workflowFragment
83
+ }
84
+ }
85
+
86
+ ${workflowFragment}
87
+ ${workWaitItemFragment}
88
+ `,
89
+ { refresh: 'auto', lists: ['workflow'] },
90
+ );
91
+
92
+ export const workflowRunsQry = live(
93
+ gql`
56
94
  query workflowRuns (
57
95
  $organizationId: GenericID!
58
96
  $filter: WorkflowRunsFilter!
@@ -80,9 +118,12 @@ query workflowRuns (
80
118
  }
81
119
 
82
120
  ${workflowRunFragment}
83
- `;
121
+ `,
122
+ { refresh: 'notice', lists: ['workflowRun'], scope: { workflowId: 'filter.workflowId' } },
123
+ );
84
124
 
85
- export const workflowRunQry = gql`
125
+ export const workflowRunQry = live(
126
+ gql`
86
127
  query workflowRun (
87
128
  $organizationId: GenericID!
88
129
  $workflowRunId: GenericID!
@@ -102,4 +143,6 @@ query workflowRun (
102
143
  }
103
144
 
104
145
  ${workflowRunFragment}
105
- `;
146
+ `,
147
+ { refresh: 'auto' },
148
+ );
@@ -0,0 +1,98 @@
1
+ import type { DataTypeKey } from '@jsb188/mday/constants/graphqlReactivity.ts';
2
+ import type { DocumentNode, OperationDefinitionNode } from 'graphql';
3
+
4
+ /*
5
+ * What a query document states about itself: how it refreshes and which data
6
+ * types it depends on (design 3). Attached to the document with live().
7
+ */
8
+ export interface QueryReactivity {
9
+ refresh: 'auto' | 'notice';
10
+ lists?: readonly DataTypeKey[];
11
+ derived?: readonly DataTypeKey[];
12
+ // scope key → variable path, when the names differ; null ignores that scope key
13
+ scope?: Readonly<Record<string, string | null>>;
14
+ // Changes caused by this tab do not refresh the query (editor sessions with unsaved local state)
15
+ skipOwnChanges?: true;
16
+ }
17
+
18
+ /*
19
+ * A declaration as registered: the declaration plus every name its query is cached or mounted under.
20
+ */
21
+ export interface RegisteredQueryReactivity extends QueryReactivity {
22
+ // Operation name first, then every root field name or alias that differs from it
23
+ names: string[];
24
+ }
25
+
26
+ // Filled as query modules load; read by the realtime dispatcher
27
+ const REGISTRY = {
28
+ byName: new Map<string, RegisteredQueryReactivity>(),
29
+ byType: new Map<DataTypeKey, RegisteredQueryReactivity[]>(),
30
+ };
31
+
32
+ /*
33
+ * Return the names one query document is known by: its operation name, then the
34
+ * response name (alias or field name) of every root field, without duplicates.
35
+ * Interpolated fragment definitions may come before or after the operation.
36
+ */
37
+ function getQueryDocumentNames(document: DocumentNode): string[] {
38
+ const operation = document.definitions.find(
39
+ (definition): definition is OperationDefinitionNode => definition.kind === 'OperationDefinition',
40
+ );
41
+ if (!operation?.name) {
42
+ throw new Error('live() needs a document with a named operation');
43
+ }
44
+
45
+ const roots = operation.selectionSet.selections.flatMap((selection) =>
46
+ selection.kind === 'Field' ? [selection.alias?.value || selection.name.value] : [],
47
+ );
48
+ return [...new Set([operation.name.value, ...roots])];
49
+ }
50
+
51
+ /*
52
+ * Attach a reactivity declaration to a query document and return the document unchanged.
53
+ * The declaration is registered under the operation name and every root field name.
54
+ */
55
+ export function live<T extends DocumentNode>(document: T, reactivity: QueryReactivity): T {
56
+ const names = getQueryDocumentNames(document);
57
+ const existing = REGISTRY.byName.get(names[0]);
58
+ if (existing) {
59
+ // Two documents may share one operation name (aiChatMessages, emailOutreach); they declare the same thing
60
+ for (const name of names) {
61
+ if (!existing.names.includes(name)) {
62
+ existing.names.push(name);
63
+ REGISTRY.byName.set(name, existing);
64
+ }
65
+ }
66
+ return document;
67
+ }
68
+
69
+ const registered: RegisteredQueryReactivity = { ...reactivity, names };
70
+ for (const name of names) {
71
+ REGISTRY.byName.set(name, registered);
72
+ }
73
+
74
+ // A type named in both lists and derived is registered once
75
+ for (const type of new Set([...(reactivity.lists || []), ...(reactivity.derived || [])])) {
76
+ const declarations = REGISTRY.byType.get(type);
77
+ if (declarations) {
78
+ declarations.push(registered);
79
+ } else {
80
+ REGISTRY.byType.set(type, [registered]);
81
+ }
82
+ }
83
+ return document;
84
+ }
85
+
86
+ /*
87
+ * Return every declared query that lists or is derived from one data type.
88
+ */
89
+ export function getQueryReactivitiesForType(type: DataTypeKey): readonly RegisteredQueryReactivity[] {
90
+ return REGISTRY.byType.get(type) || [];
91
+ }
92
+
93
+ /*
94
+ * Return the declaration of one query by operation or root field name.
95
+ */
96
+ export function getQueryReactivity(name: string): RegisteredQueryReactivity | undefined {
97
+ return REGISTRY.byName.get(name);
98
+ }
@@ -0,0 +1,171 @@
1
+ import type { DataTypeKey } from '@jsb188/mday/constants/graphqlReactivity.ts';
2
+ import { libraryFileQry } from './queries/libraryQueries.ts';
3
+ import { agentNoteQry } from './queries/agentNoteQueries.ts';
4
+ import { audienceEmailAddressQry, audienceListQry } from './queries/audienceQueries.ts';
5
+ import { dataTableQry } from './queries/dataTableQueries.ts';
6
+ import { emailOutreachQry } from './queries/emailOutreachQueries.ts';
7
+ import { emailMessageQry } from './queries/emailQueries.ts';
8
+ import { fieldDocSubmissionDocumentQry } from './queries/fieldDocQueries.ts';
9
+ import { logEntryQry } from './queries/logQueries.ts';
10
+ import { workflowQry, workflowRunQry } from './queries/workflowQueries.ts';
11
+
12
+ // How the client reads one record of a data type that a realtime change could not carry (design section 6)
13
+ export interface RecordRead {
14
+ query: any; // The single-record query document
15
+ root: string; // Root field of the response
16
+ fragment: string; // Fragment definition in that document whose selection is the record
17
+ nested?: string; // Field under the root that holds the record (logEntryDetails: 'details')
18
+ variables: (id: string, scope: Record<string, string>) => Record<string, any>;
19
+ }
20
+
21
+ // One record read as plain data; RECORD_READS is built from it. The server's document checker imports this module (its document imports rewritten) and checks RECORD_READS.
22
+ export interface RecordReadDefinition {
23
+ type: DataTypeKey;
24
+ queryExportName: string; // Export name of the single-record query document, imported from gql/queries/
25
+ root: string;
26
+ fragment: string;
27
+ nested?: string;
28
+ idVariable: string; // Query variable that receives the record id
29
+ scopeVariables: readonly string[]; // Scope keys passed as the query variables of the same name
30
+ }
31
+
32
+ // One entry for every DATA_TYPES type marked `thin` (strings only)
33
+ export const RECORD_READ_DEFINITIONS: readonly RecordReadDefinition[] = [
34
+ {
35
+ type: 'libraryFile',
36
+ queryExportName: 'libraryFileQry',
37
+ root: 'libraryFile',
38
+ fragment: 'libraryFileFragment',
39
+ idVariable: 'libraryFileId',
40
+ scopeVariables: [],
41
+ },
42
+ {
43
+ type: 'agentNote',
44
+ queryExportName: 'agentNoteQry',
45
+ root: 'agentNote',
46
+ fragment: 'agentNoteDetailFragment',
47
+ idVariable: 'agentNoteId',
48
+ scopeVariables: ['organizationId'],
49
+ },
50
+ {
51
+ type: 'audienceEmailAddress',
52
+ queryExportName: 'audienceEmailAddressQry',
53
+ root: 'audienceEmailAddress',
54
+ fragment: 'audienceEmailAddressFragment',
55
+ idVariable: 'emailAddressId',
56
+ scopeVariables: ['organizationId'],
57
+ },
58
+ {
59
+ type: 'audienceList',
60
+ queryExportName: 'audienceListQry',
61
+ root: 'audienceList',
62
+ fragment: 'audienceListFragment',
63
+ idVariable: 'audienceListId',
64
+ scopeVariables: ['organizationId'],
65
+ },
66
+ {
67
+ type: 'dataTable',
68
+ queryExportName: 'dataTableQry',
69
+ root: 'dataTable',
70
+ fragment: 'dataTableFragment',
71
+ idVariable: 'dataTableId',
72
+ scopeVariables: ['organizationId'],
73
+ },
74
+ {
75
+ type: 'emailMessage',
76
+ queryExportName: 'emailMessageQry',
77
+ root: 'emailMessage',
78
+ fragment: 'emailMessageFragment',
79
+ idVariable: 'emailMessageId',
80
+ scopeVariables: ['organizationId'],
81
+ },
82
+ {
83
+ type: 'emailOutreach',
84
+ queryExportName: 'emailOutreachQry',
85
+ root: 'emailOutreach',
86
+ fragment: 'emailOutreachFragment',
87
+ idVariable: 'emailOutreachId',
88
+ scopeVariables: [],
89
+ },
90
+ {
91
+ type: 'fieldDocSubmission',
92
+ queryExportName: 'fieldDocSubmissionDocumentQry',
93
+ root: 'fieldDocSubmissionDocument',
94
+ fragment: 'fieldDocSubmissionFragment',
95
+ nested: 'submission',
96
+ idVariable: 'fieldDocSubmissionId',
97
+ scopeVariables: [],
98
+ },
99
+ {
100
+ type: 'logEntry',
101
+ queryExportName: 'logEntryQry',
102
+ root: 'logEntry',
103
+ fragment: 'logEntryFragment',
104
+ idVariable: 'logEntryId',
105
+ scopeVariables: ['organizationId'],
106
+ },
107
+ {
108
+ type: 'logEntryDetails',
109
+ queryExportName: 'logEntryQry',
110
+ root: 'logEntry',
111
+ fragment: 'logEntryDetailsFragment',
112
+ nested: 'details',
113
+ idVariable: 'logEntryId',
114
+ scopeVariables: ['organizationId'],
115
+ },
116
+ {
117
+ type: 'workflow',
118
+ queryExportName: 'workflowQry',
119
+ root: 'workflow',
120
+ fragment: 'workflowFragment',
121
+ idVariable: 'workflowId',
122
+ scopeVariables: [],
123
+ },
124
+ {
125
+ type: 'workflowRun',
126
+ queryExportName: 'workflowRunQry',
127
+ root: 'workflowRun',
128
+ fragment: 'workflowRunFragment',
129
+ idVariable: 'workflowRunId',
130
+ scopeVariables: ['organizationId'],
131
+ },
132
+ ];
133
+
134
+ const FILE_CONSTANTS = {
135
+ // Record read documents under the export names RECORD_READ_DEFINITIONS uses
136
+ documents: {
137
+ libraryFileQry,
138
+ agentNoteQry,
139
+ audienceEmailAddressQry,
140
+ audienceListQry,
141
+ dataTableQry,
142
+ emailMessageQry,
143
+ emailOutreachQry,
144
+ fieldDocSubmissionDocumentQry,
145
+ logEntryQry,
146
+ workflowQry,
147
+ workflowRunQry,
148
+ } as Record<string, any>,
149
+ };
150
+
151
+ /*
152
+ * Build the runtime record read of one definition: its document, and
153
+ * variables made of the change's scope values and the record id.
154
+ */
155
+ function makeRecordRead(definition: RecordReadDefinition): RecordRead {
156
+ return {
157
+ query: FILE_CONSTANTS.documents[definition.queryExportName],
158
+ root: definition.root,
159
+ fragment: definition.fragment,
160
+ ...(definition.nested ? { nested: definition.nested } : null),
161
+ variables: (id, scope) => ({
162
+ ...Object.fromEntries(definition.scopeVariables.map((key) => [key, scope[key]])),
163
+ [definition.idVariable]: id,
164
+ }),
165
+ };
166
+ }
167
+
168
+ // The single-record query of every data type that may be sent thin
169
+ export const RECORD_READS: Partial<Record<DataTypeKey, RecordRead>> = Object.fromEntries(
170
+ RECORD_READ_DEFINITIONS.map((definition) => [definition.type, makeRecordRead(definition)]),
171
+ );