@jsb188/graphql 1.1.11 → 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 (174) hide show
  1. package/LICENSE +21 -0
  2. package/audience.d.ts +205 -0
  3. package/cache/config.ts +65 -28
  4. package/cache/index.helpers.ts +96 -0
  5. package/cache/index.ts +364 -808
  6. package/cache/mounted-queries.ts +33 -0
  7. package/cache/optimistic-ui-runtime.ts +46 -0
  8. package/cache/optimistic-ui.ts +401 -0
  9. package/cache/persist.ts +107 -22
  10. package/cache/realtime-fence.ts +47 -0
  11. package/cache/realtime-live.ts +17 -0
  12. package/cache/store.ts +22 -64
  13. package/cache/value.helpers.ts +17 -0
  14. package/{drafts/store.ts → client/draft-persistence-indexed-db.ts} +19 -3
  15. package/{drafts/index.ts → client/draft-persistence.ts} +13 -39
  16. package/client/index.ts +4 -2
  17. package/client/request.helpers.ts +14 -0
  18. package/client/request.ts +122 -232
  19. package/client/storage-asset.ts +58 -0
  20. package/gql/fragments/accountAuthFragments.ts +0 -4
  21. package/gql/fragments/agentMemoryFragments.ts +5 -1
  22. package/gql/fragments/agentNoteFragments.ts +156 -0
  23. package/gql/fragments/aiChatFragments.ts +35 -11
  24. package/gql/fragments/aiChatLinkFragments.ts +8 -0
  25. package/gql/fragments/audienceFragments.ts +76 -0
  26. package/gql/fragments/dataTableFragments.ts +48 -80
  27. package/gql/fragments/emailFragments.ts +49 -21
  28. package/gql/fragments/emailOutreachFragments.ts +281 -0
  29. package/gql/fragments/fieldDocFragments.ts +222 -40
  30. package/gql/fragments/inboundContactFragments.ts +2 -0
  31. package/gql/fragments/libraryFragments.ts +120 -0
  32. package/gql/fragments/logFragments.ts +93 -2
  33. package/gql/fragments/organizationFragments.ts +12 -0
  34. package/gql/fragments/qrCodeFragments.ts +29 -0
  35. package/gql/fragments/scheduleFragments.ts +574 -145
  36. package/gql/fragments/sheetFragments.ts +86 -424
  37. package/gql/fragments/storageFragments.ts +25 -1
  38. package/gql/fragments/workWaitFragments.ts +13 -0
  39. package/gql/fragments/workflowFragments.ts +32 -4
  40. package/gql/mutations/agentMemoryMutations.ts +32 -0
  41. package/gql/mutations/agentNoteMutations.ts +64 -0
  42. package/gql/mutations/aiChatLinkMutations.ts +13 -0
  43. package/gql/mutations/aiChatMutations.ts +34 -4
  44. package/gql/mutations/audienceMutations.ts +58 -0
  45. package/gql/mutations/authMutations.ts +24 -28
  46. package/gql/mutations/billingMutations.ts +24 -0
  47. package/gql/mutations/contactMutations.ts +23 -0
  48. package/gql/mutations/dataTableMutations.ts +18 -75
  49. package/gql/mutations/emailMutations.ts +22 -0
  50. package/gql/mutations/emailOutreachMutations.ts +139 -0
  51. package/gql/mutations/fieldDocMutations.ts +162 -13
  52. package/gql/mutations/index.ts +10 -5
  53. package/gql/mutations/organizationMutations.ts +6 -0
  54. package/gql/mutations/qrCodeMutations.ts +20 -0
  55. package/gql/mutations/scheduleMutations.ts +389 -417
  56. package/gql/mutations/sheetMutations.ts +62 -118
  57. package/gql/mutations/storageMutations.ts +1 -1
  58. package/gql/mutations/workflowMutations.ts +94 -0
  59. package/gql/queries/agentMemoryQueries.ts +12 -2
  60. package/gql/queries/agentNoteQueries.ts +86 -0
  61. package/gql/queries/aiChatQueries.ts +63 -12
  62. package/gql/queries/audienceQueries.ts +104 -0
  63. package/gql/queries/authQueries.ts +20 -4
  64. package/gql/queries/billingQueries.ts +114 -9
  65. package/gql/queries/dataTableQueries.ts +43 -75
  66. package/gql/queries/emailOutreachQueries.ts +282 -0
  67. package/gql/queries/emailQueries.ts +48 -64
  68. package/gql/queries/emailReplyReportQueries.ts +127 -0
  69. package/gql/queries/fieldDocQueries.ts +128 -98
  70. package/gql/queries/inboundContactQueries.ts +15 -4
  71. package/gql/queries/index.ts +5 -3
  72. package/gql/queries/libraryQueries.ts +112 -0
  73. package/gql/queries/logQueries.ts +86 -12
  74. package/gql/queries/organizationQueries.ts +44 -12
  75. package/gql/queries/qrCodeQueries.ts +27 -0
  76. package/gql/queries/scheduleQueries.ts +401 -278
  77. package/gql/queries/sheetQueries.ts +94 -165
  78. package/gql/queries/storageQueries.ts +11 -4
  79. package/gql/queries/workflowQueries.ts +61 -12
  80. package/gql/reactivity.ts +98 -0
  81. package/gql/recordReads.ts +171 -0
  82. package/hooks/index.helpers.ts +52 -0
  83. package/hooks/index.ts +920 -715
  84. package/hooks/use-agentMemory-mtn.ts +29 -31
  85. package/hooks/use-agentMemory-qry.ts +15 -3
  86. package/hooks/use-agentNote-mtn.ts +89 -0
  87. package/hooks/use-agentNote-qry.ts +162 -0
  88. package/hooks/use-agentNote-recovery.helpers.ts +58 -0
  89. package/hooks/use-agentNote-recovery.ts +57 -0
  90. package/hooks/use-aiChat-mtn.ts +104 -115
  91. package/hooks/use-aiChat-qry.helpers.ts +124 -0
  92. package/hooks/use-aiChat-qry.ts +254 -387
  93. package/hooks/use-aiChat-stream-mtn.ts +14 -0
  94. package/hooks/use-audience-mtn.ts +170 -0
  95. package/hooks/use-audience-qry.helpers.ts +39 -0
  96. package/hooks/use-audience-qry.ts +245 -0
  97. package/hooks/use-auth-mtn.ts +30 -1
  98. package/hooks/use-billing-mtn.ts +31 -0
  99. package/hooks/use-billing-qry.ts +76 -0
  100. package/hooks/use-dataTable-mtn.ts +23 -115
  101. package/hooks/use-dataTable-qry.ts +69 -914
  102. package/hooks/use-email-mtn.ts +26 -0
  103. package/hooks/use-email-qry.helpers.ts +37 -0
  104. package/hooks/use-email-qry.ts +44 -174
  105. package/hooks/use-emailOutreach-mtn.ts +211 -0
  106. package/hooks/use-emailOutreach-qry.helpers.ts +25 -0
  107. package/hooks/use-emailOutreach-qry.ts +367 -0
  108. package/hooks/use-emailOutreachReplyReport-qry.ts +46 -0
  109. package/hooks/use-fieldDoc-mtn.ts +244 -32
  110. package/hooks/use-fieldDoc-qry.helpers.ts +49 -0
  111. package/hooks/use-fieldDoc-qry.ts +134 -102
  112. package/hooks/use-inboundContact-qry.ts +7 -9
  113. package/hooks/use-library-qry.ts +233 -0
  114. package/hooks/use-log-mtn.ts +25 -12
  115. package/hooks/use-log-qry.ts +99 -46
  116. package/hooks/use-organization-qry.ts +16 -60
  117. package/hooks/use-qrCode-mtn.ts +40 -0
  118. package/hooks/use-qrCode-qry.ts +78 -0
  119. package/hooks/use-schedule-mtn.ts +231 -348
  120. package/hooks/use-schedule-qry.ts +208 -139
  121. package/hooks/use-schedule-reactive.ts +218 -0
  122. package/hooks/use-sheet-mtn.ts +91 -199
  123. package/hooks/use-sheet-qry.ts +88 -237
  124. package/hooks/use-storage-qry.ts +84 -61
  125. package/hooks/use-workflow-mtn.ts +84 -23
  126. package/hooks/use-workflow-qry.ts +60 -61
  127. package/libs/ai-chat-link-events.ts +78 -0
  128. package/libs/ai-chat-outgoing.helpers.ts +153 -0
  129. package/libs/ai-chat-outgoing.ts +11 -0
  130. package/libs/ai-chat-outgoing.types.ts +25 -0
  131. package/libs/ai-chat-run-realtime.ts +20 -0
  132. package/libs/ai-chat-submission-realtime.ts +150 -0
  133. package/libs/data-changes.helpers.ts +161 -0
  134. package/libs/data-changes.ts +382 -0
  135. package/libs/fragment-realtime-sequence.ts +55 -0
  136. package/libs/open-sheet.ts +138 -0
  137. package/libs/record-read.ts +327 -0
  138. package/libs/sheet-command-batch.ts +45 -0
  139. package/libs/sheet-realtime-packet.ts +53 -0
  140. package/libs/sheet-view-realtime-router.ts +99 -0
  141. package/loaders/emailPreference.ts +69 -0
  142. package/loaders/rest.ts +12 -0
  143. package/package.json +77 -25
  144. package/schedule.d.ts +1183 -0
  145. package/sse.helpers.ts +19 -0
  146. package/sse.ts +26 -115
  147. package/types.d.ts +48 -25
  148. package/cache/index.test.ts +0 -881
  149. package/client/data-table-realtime-subscriptions.test.ts +0 -740
  150. package/client/data-table-realtime-subscriptions.ts +0 -955
  151. package/client/data-table-realtime.test.ts +0 -792
  152. package/client/data-table-realtime.ts +0 -1218
  153. package/client/fragment-realtime-sequence.ts +0 -52
  154. package/client/open-sheet.ts +0 -137
  155. package/client/request-managed-session.test.ts +0 -574
  156. package/client/request-no-store.test.ts +0 -157
  157. package/client/sse-ticket.test.ts +0 -26
  158. package/deno.lock +0 -170
  159. package/deno.test.json +0 -10
  160. package/gql/fragments/agentDocFragments.ts +0 -46
  161. package/gql/fragments/billingFragments.ts +0 -14
  162. package/gql/fragments/campaignFragments.ts +0 -277
  163. package/gql/mutations/agentDocMutations.ts +0 -177
  164. package/gql/mutations/campaignMutations.ts +0 -215
  165. package/gql/queries/agentDocQueries.ts +0 -120
  166. package/gql/queries/appQueries.ts +0 -14
  167. package/gql/queries/campaignQueries.ts +0 -127
  168. package/hooks/use-agentDoc-mtn.ts +0 -285
  169. package/hooks/use-agentDoc-qry.ts +0 -208
  170. package/hooks/use-app-qry.ts +0 -22
  171. package/hooks/use-campaign-mtn.ts +0 -377
  172. package/hooks/use-campaign-qry.ts +0 -257
  173. package/loaders/campaign.ts +0 -137
  174. package/tsconfig.json +0 -13
@@ -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
+ );
@@ -0,0 +1,52 @@
1
+ import { QUERY_EXPIRE_TIMES } from '../cache/config.ts';
2
+
3
+ /*
4
+ * Apply the same freshness boundary on mount, prefetch, focus and reconnect.
5
+ * Zero always refreshes; Infinity never expires a known timestamp. Missing,
6
+ * invalid or future timestamps require validation against the server.
7
+ */
8
+ export function isQueryDataStale(queryName: string, fetchedAt: number | undefined, persistTime?: number, now = Date.now()): boolean {
9
+ if (fetchedAt === undefined || !Number.isFinite(fetchedAt) || fetchedAt > now) return true;
10
+ const configured = persistTime ?? QUERY_EXPIRE_TIMES[queryName] ?? QUERY_EXPIRE_TIMES.__default;
11
+ const freshnessWindow = Number.isNaN(configured) ? QUERY_EXPIRE_TIMES.__default : Math.max(0, configured);
12
+ return now - fetchedAt >= freshnessWindow;
13
+ }
14
+
15
+ export interface QueryActivation {
16
+ queryKey: string | null;
17
+ checked: boolean;
18
+ }
19
+
20
+ /*
21
+ * Start a new activation when a hook changes query scope or resumes after being skipped.
22
+ */
23
+ export function getQueryActivation(current: QueryActivation, queryKey: string, skipped: boolean): QueryActivation {
24
+ const activeKey = skipped ? null : queryKey;
25
+ return current.queryKey === activeKey ? current : { queryKey: activeKey, checked: false };
26
+ }
27
+
28
+ /*
29
+ * Claim one entry-time cache check before starting or joining a request. Cache writes,
30
+ * rerenders and Strict Mode effect replay must not repeatedly refresh the same activation.
31
+ */
32
+ export function claimQueryActivation(activation: QueryActivation, queryKey: string): boolean {
33
+ if (activation.queryKey !== queryKey || activation.checked) {
34
+ return false;
35
+ }
36
+ activation.checked = true;
37
+ return true;
38
+ }
39
+
40
+ /*
41
+ * Bound an opted-in query's network lifetime so a hung request cannot occupy
42
+ * its shared in-flight slot forever. Owners clear the timer after settlement.
43
+ */
44
+ export function startQueryRequestTimeout(controller: AbortController, timeoutMs?: number): () => void {
45
+ if (!timeoutMs || !Number.isFinite(timeoutMs) || timeoutMs <= 0) return () => {};
46
+ const timeout = globalThis.setTimeout(() => {
47
+ controller.abort(new DOMException('The GraphQL query exceeded its request deadline.', 'AbortError'));
48
+ }, timeoutMs);
49
+ return () => {
50
+ globalThis.clearTimeout(timeout);
51
+ };
52
+ }