@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.
- package/LICENSE +21 -0
- package/audience.d.ts +205 -0
- package/cache/config.ts +65 -28
- package/cache/index.helpers.ts +96 -0
- package/cache/index.ts +364 -808
- package/cache/mounted-queries.ts +33 -0
- package/cache/optimistic-ui-runtime.ts +46 -0
- package/cache/optimistic-ui.ts +401 -0
- package/cache/persist.ts +107 -22
- package/cache/realtime-fence.ts +47 -0
- package/cache/realtime-live.ts +17 -0
- 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} +13 -39
- package/client/index.ts +4 -2
- package/client/request.helpers.ts +14 -0
- package/client/request.ts +122 -232
- package/client/storage-asset.ts +58 -0
- package/gql/fragments/accountAuthFragments.ts +0 -4
- package/gql/fragments/agentMemoryFragments.ts +5 -1
- package/gql/fragments/agentNoteFragments.ts +156 -0
- package/gql/fragments/aiChatFragments.ts +35 -11
- package/gql/fragments/aiChatLinkFragments.ts +8 -0
- package/gql/fragments/audienceFragments.ts +76 -0
- package/gql/fragments/dataTableFragments.ts +48 -80
- package/gql/fragments/emailFragments.ts +49 -21
- package/gql/fragments/emailOutreachFragments.ts +281 -0
- package/gql/fragments/fieldDocFragments.ts +222 -40
- package/gql/fragments/inboundContactFragments.ts +2 -0
- package/gql/fragments/libraryFragments.ts +120 -0
- package/gql/fragments/logFragments.ts +93 -2
- package/gql/fragments/organizationFragments.ts +12 -0
- package/gql/fragments/qrCodeFragments.ts +29 -0
- package/gql/fragments/scheduleFragments.ts +574 -145
- package/gql/fragments/sheetFragments.ts +86 -424
- package/gql/fragments/storageFragments.ts +25 -1
- package/gql/fragments/workWaitFragments.ts +13 -0
- package/gql/fragments/workflowFragments.ts +32 -4
- package/gql/mutations/agentMemoryMutations.ts +32 -0
- package/gql/mutations/agentNoteMutations.ts +64 -0
- package/gql/mutations/aiChatLinkMutations.ts +13 -0
- package/gql/mutations/aiChatMutations.ts +34 -4
- package/gql/mutations/audienceMutations.ts +58 -0
- package/gql/mutations/authMutations.ts +24 -28
- package/gql/mutations/billingMutations.ts +24 -0
- package/gql/mutations/contactMutations.ts +23 -0
- package/gql/mutations/dataTableMutations.ts +18 -75
- package/gql/mutations/emailMutations.ts +22 -0
- package/gql/mutations/emailOutreachMutations.ts +139 -0
- package/gql/mutations/fieldDocMutations.ts +162 -13
- package/gql/mutations/index.ts +10 -5
- package/gql/mutations/organizationMutations.ts +6 -0
- package/gql/mutations/qrCodeMutations.ts +20 -0
- package/gql/mutations/scheduleMutations.ts +389 -417
- package/gql/mutations/sheetMutations.ts +62 -118
- package/gql/mutations/storageMutations.ts +1 -1
- package/gql/mutations/workflowMutations.ts +94 -0
- package/gql/queries/agentMemoryQueries.ts +12 -2
- package/gql/queries/agentNoteQueries.ts +86 -0
- package/gql/queries/aiChatQueries.ts +63 -12
- package/gql/queries/audienceQueries.ts +104 -0
- package/gql/queries/authQueries.ts +20 -4
- package/gql/queries/billingQueries.ts +114 -9
- package/gql/queries/dataTableQueries.ts +43 -75
- package/gql/queries/emailOutreachQueries.ts +282 -0
- package/gql/queries/emailQueries.ts +48 -64
- package/gql/queries/emailReplyReportQueries.ts +127 -0
- package/gql/queries/fieldDocQueries.ts +128 -98
- package/gql/queries/inboundContactQueries.ts +15 -4
- package/gql/queries/index.ts +5 -3
- package/gql/queries/libraryQueries.ts +112 -0
- package/gql/queries/logQueries.ts +86 -12
- package/gql/queries/organizationQueries.ts +44 -12
- package/gql/queries/qrCodeQueries.ts +27 -0
- package/gql/queries/scheduleQueries.ts +401 -278
- package/gql/queries/sheetQueries.ts +94 -165
- package/gql/queries/storageQueries.ts +11 -4
- package/gql/queries/workflowQueries.ts +61 -12
- package/gql/reactivity.ts +98 -0
- package/gql/recordReads.ts +171 -0
- package/hooks/index.helpers.ts +52 -0
- package/hooks/index.ts +920 -715
- package/hooks/use-agentMemory-mtn.ts +29 -31
- package/hooks/use-agentMemory-qry.ts +15 -3
- package/hooks/use-agentNote-mtn.ts +89 -0
- package/hooks/use-agentNote-qry.ts +162 -0
- package/hooks/use-agentNote-recovery.helpers.ts +58 -0
- package/hooks/use-agentNote-recovery.ts +57 -0
- package/hooks/use-aiChat-mtn.ts +104 -115
- package/hooks/use-aiChat-qry.helpers.ts +124 -0
- package/hooks/use-aiChat-qry.ts +254 -387
- package/hooks/use-aiChat-stream-mtn.ts +14 -0
- package/hooks/use-audience-mtn.ts +170 -0
- package/hooks/use-audience-qry.helpers.ts +39 -0
- package/hooks/use-audience-qry.ts +245 -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-dataTable-mtn.ts +23 -115
- package/hooks/use-dataTable-qry.ts +69 -914
- package/hooks/use-email-mtn.ts +26 -0
- package/hooks/use-email-qry.helpers.ts +37 -0
- package/hooks/use-email-qry.ts +44 -174
- package/hooks/use-emailOutreach-mtn.ts +211 -0
- package/hooks/use-emailOutreach-qry.helpers.ts +25 -0
- package/hooks/use-emailOutreach-qry.ts +367 -0
- package/hooks/use-emailOutreachReplyReport-qry.ts +46 -0
- package/hooks/use-fieldDoc-mtn.ts +244 -32
- 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-library-qry.ts +233 -0
- 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-qrCode-mtn.ts +40 -0
- package/hooks/use-qrCode-qry.ts +78 -0
- package/hooks/use-schedule-mtn.ts +231 -348
- package/hooks/use-schedule-qry.ts +208 -139
- package/hooks/use-schedule-reactive.ts +218 -0
- package/hooks/use-sheet-mtn.ts +91 -199
- package/hooks/use-sheet-qry.ts +88 -237
- package/hooks/use-storage-qry.ts +84 -61
- package/hooks/use-workflow-mtn.ts +84 -23
- package/hooks/use-workflow-qry.ts +60 -61
- package/libs/ai-chat-link-events.ts +78 -0
- 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/data-changes.helpers.ts +161 -0
- package/libs/data-changes.ts +382 -0
- package/libs/fragment-realtime-sequence.ts +55 -0
- package/libs/open-sheet.ts +138 -0
- package/libs/record-read.ts +327 -0
- package/libs/sheet-command-batch.ts +45 -0
- package/libs/sheet-realtime-packet.ts +53 -0
- package/libs/sheet-view-realtime-router.ts +99 -0
- package/loaders/emailPreference.ts +69 -0
- package/loaders/rest.ts +12 -0
- package/package.json +77 -25
- package/schedule.d.ts +1183 -0
- package/sse.helpers.ts +19 -0
- package/sse.ts +26 -115
- package/types.d.ts +48 -25
- package/cache/index.test.ts +0 -881
- 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-managed-session.test.ts +0 -574
- package/client/request-no-store.test.ts +0 -157
- package/client/sse-ticket.test.ts +0 -26
- package/deno.lock +0 -170
- package/deno.test.json +0 -10
- package/gql/fragments/agentDocFragments.ts +0 -46
- package/gql/fragments/billingFragments.ts +0 -14
- package/gql/fragments/campaignFragments.ts +0 -277
- package/gql/mutations/agentDocMutations.ts +0 -177
- package/gql/mutations/campaignMutations.ts +0 -215
- package/gql/queries/agentDocQueries.ts +0 -120
- package/gql/queries/appQueries.ts +0 -14
- package/gql/queries/campaignQueries.ts +0 -127
- package/hooks/use-agentDoc-mtn.ts +0 -285
- package/hooks/use-agentDoc-qry.ts +0 -208
- package/hooks/use-app-qry.ts +0 -22
- package/hooks/use-campaign-mtn.ts +0 -377
- package/hooks/use-campaign-qry.ts +0 -257
- package/loaders/campaign.ts +0 -137
- 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
|
+
}
|