@jsb188/graphql 1.1.10 → 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 +98 -50
- 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 +1017 -127
- package/cache/index.ts +1256 -1269
- package/cache/optimistic-ui-runtime.ts +46 -0
- package/cache/optimistic-ui.ts +401 -0
- package/cache/persist.ts +800 -0
- package/cache/store.ts +395 -0
- package/cache/value.helpers.ts +17 -0
- package/client/draft-persistence-indexed-db.ts +413 -0
- package/client/draft-persistence.ts +152 -0
- package/client/index.ts +3 -0
- package/client/request.helpers.ts +14 -0
- package/client/request.ts +870 -164
- package/deno.lock +187 -0
- package/deno.test.json +10 -4
- package/gql/eagerQueryMap.ts +12 -0
- package/gql/fragments/accountAuthFragments.ts +5 -0
- package/gql/fragments/accountFragments.ts +0 -3
- package/gql/fragments/accountSessionFragments.ts +16 -0
- package/gql/fragments/agentMemoryFragments.ts +23 -0
- package/gql/fragments/agentNoteFragments.ts +150 -0
- package/gql/fragments/aiChatFragments.ts +42 -0
- package/gql/fragments/audienceFragments.ts +141 -0
- package/gql/fragments/campaignFragments.ts +566 -0
- package/gql/fragments/dataTableFragments.ts +50 -192
- package/gql/fragments/emailFragments.ts +32 -17
- package/gql/fragments/fieldDocFragments.ts +264 -0
- package/gql/fragments/inboundContactFragments.ts +2 -0
- package/gql/fragments/logFragments.ts +101 -69
- package/gql/fragments/organizationFragments.ts +53 -5
- package/gql/fragments/qrCodeFragments.ts +29 -0
- package/gql/fragments/scheduleFragments.ts +667 -0
- package/gql/fragments/sheetFragments.ts +304 -63
- package/gql/fragments/storageFragments.ts +45 -0
- package/gql/fragments/workflowFragments.ts +41 -5
- package/gql/mutations/accountMutations.ts +0 -2
- package/gql/mutations/agentMemoryMutations.ts +68 -0
- package/gql/mutations/agentNoteMutations.ts +62 -0
- package/gql/mutations/aiChatMutations.ts +49 -4
- package/gql/mutations/audienceMutations.ts +71 -0
- package/gql/mutations/authMutations.ts +203 -18
- package/gql/mutations/billingMutations.ts +17 -27
- package/gql/mutations/campaignMutations.ts +258 -0
- package/gql/mutations/contactMutations.ts +23 -0
- package/gql/mutations/dataTableMutations.ts +19 -54
- package/gql/mutations/fieldDocMutations.ts +173 -0
- package/gql/mutations/index.ts +10 -2
- package/gql/mutations/logMutations.ts +6 -29
- package/gql/mutations/organizationMutations.ts +19 -4
- package/gql/mutations/qrCodeMutations.ts +20 -0
- package/gql/mutations/scheduleMutations.ts +1121 -0
- package/gql/mutations/sheetMutations.ts +221 -60
- package/gql/mutations/storageMutations.ts +19 -0
- package/gql/mutations/workflowMutations.ts +60 -0
- package/gql/queries/agentMemoryQueries.ts +28 -0
- package/gql/queries/agentNoteQueries.ts +89 -0
- package/gql/queries/aiChatQueries.ts +70 -2
- package/gql/queries/audienceQueries.ts +128 -0
- package/gql/queries/authQueries.ts +47 -0
- package/gql/queries/billingQueries.ts +118 -6
- package/gql/queries/campaignQueries.ts +236 -0
- package/gql/queries/dataTableQueries.ts +61 -13
- package/gql/queries/emailQueries.ts +26 -17
- package/gql/queries/emailReplyReportQueries.ts +76 -0
- package/gql/queries/fieldDocQueries.ts +166 -0
- package/gql/queries/inboundContactQueries.ts +4 -0
- package/gql/queries/index.ts +10 -2
- package/gql/queries/logQueries.ts +68 -30
- package/gql/queries/organizationQueries.ts +65 -1
- package/gql/queries/qrCodeQueries.ts +20 -0
- package/gql/queries/scheduleQueries.ts +691 -0
- package/gql/queries/sheetQueries.ts +244 -26
- package/gql/queries/storageQueries.ts +38 -0
- package/gql/queries/workflowQueries.ts +77 -2
- package/hooks/index.helpers.test.ts +50 -0
- package/hooks/index.helpers.ts +52 -0
- package/hooks/index.ts +2254 -982
- package/hooks/use-account-mtn.ts +76 -81
- package/hooks/use-agentMemory-mtn.ts +71 -0
- package/hooks/use-agentMemory-qry.ts +56 -0
- 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 +220 -141
- 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 +341 -237
- package/hooks/use-aiChat-stream-mtn.ts +14 -0
- package/hooks/use-app-qry.ts +12 -9
- 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 +435 -252
- package/hooks/use-auth-qry.ts +51 -0
- 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 +436 -0
- package/hooks/use-campaign-qry.helpers.ts +40 -0
- package/hooks/use-campaign-qry.ts +834 -0
- package/hooks/use-dataTable-mtn.ts +37 -46
- package/hooks/use-dataTable-qry.ts +102 -128
- package/hooks/use-email-qry.helpers.ts +37 -0
- package/hooks/use-email-qry.ts +56 -86
- package/hooks/use-emailCampaignReplyReport-qry.ts +27 -0
- package/hooks/use-fieldDoc-mtn.ts +262 -0
- 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 +212 -0
- package/hooks/use-inboundContact-mtn.ts +19 -16
- package/hooks/use-inboundContact-qry.ts +62 -56
- package/hooks/use-integration-mtn.ts +56 -38
- package/hooks/use-integration-qry.ts +24 -9
- package/hooks/use-log-mtn.ts +88 -59
- package/hooks/use-log-qry.ts +150 -73
- package/hooks/use-organization-mtn.ts +334 -277
- package/hooks/use-organization-qry.ts +155 -129
- 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 +589 -0
- package/hooks/use-schedule-qry.ts +738 -0
- package/hooks/use-schedule-reactive.ts +486 -0
- package/hooks/use-sheet-mtn.ts +157 -79
- package/hooks/use-sheet-qry.ts +221 -92
- package/hooks/use-storage-mtn.ts +81 -41
- package/hooks/use-storage-qry.ts +128 -14
- package/hooks/use-workflow-mtn.ts +72 -0
- package/hooks/use-workflow-qry.ts +184 -47
- 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/libs/request-managed-session.test.ts +574 -0
- 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/libs/sse-ticket.test.ts +26 -0
- package/loaders/campaign.test.ts +186 -0
- package/loaders/campaign.ts +110 -0
- package/loaders/emailPreference.ts +75 -0
- package/loaders/rest.ts +12 -0
- package/package.json +119 -71
- package/schedule.d.ts +1790 -0
- package/sse.helpers.ts +19 -0
- package/sse.ts +70 -106
- package/tests/agent-note-detail-cache.test.ts +120 -0
- package/tests/agent-note-search.test.ts +444 -0
- package/tsconfig.json +11 -10
- package/types.d.ts +77 -26
- package/utils.ts +78 -49
- package/gql/fragments/billingFragments.ts +0 -25
- package/gql/fragments/productFragments.ts +0 -39
- package/gql/fragments/reportFragments.ts +0 -90
- package/gql/queries/productQueries.ts +0 -31
- package/gql/queries/reportQueries.ts +0 -134
- package/hooks/use-product-qry.ts +0 -67
- package/hooks/use-report-qry.ts +0 -153
package/sse.helpers.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Compare decimal database revisions without losing bigint precision. Legacy
|
|
3
|
+
* unversioned events remain supported during the fleet transition.
|
|
4
|
+
*/
|
|
5
|
+
export function isOlderChatCheckpoint(current: any, incoming: any) {
|
|
6
|
+
const before = String(current?.revision ?? '');
|
|
7
|
+
const after = String(incoming?.revision ?? '');
|
|
8
|
+
if (!/^\d+$/.test(before) || !/^\d+$/.test(after)) return false;
|
|
9
|
+
if (BigInt(after) !== BigInt(before)) return BigInt(after) < BigInt(before);
|
|
10
|
+
|
|
11
|
+
// A terminal run can settle its final checkpoint before cleanup increments
|
|
12
|
+
// the stored row revision. That settled state wins an equal-revision tie.
|
|
13
|
+
const settled =
|
|
14
|
+
current?.finished === true ||
|
|
15
|
+
['COMPLETED', 'INCOMPLETE'].includes(current?.generationStatus);
|
|
16
|
+
const streaming =
|
|
17
|
+
incoming?.finished === false || incoming?.generationStatus === 'STREAMING';
|
|
18
|
+
return settled && streaming;
|
|
19
|
+
}
|
package/sse.ts
CHANGED
|
@@ -1,110 +1,71 @@
|
|
|
1
|
-
import { addFragmentToCache, updateFragment, updateQuery } from './cache/index.ts';
|
|
1
|
+
import { addFragmentToCache, loadFragment, updateFragment, updateQuery } from './cache/index.ts';
|
|
2
2
|
import type { UpdateObserversFn } from './types.d.ts';
|
|
3
|
+
import { FRAGMENT_NAMES } from '@jsb188/mday/constants/graphqlReactivity.ts';
|
|
4
|
+
import { isOlderChatCheckpoint } from './sse.helpers.ts';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Types
|
|
6
8
|
*/
|
|
7
9
|
|
|
8
|
-
type ValidSSEType =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
type ValidSSEType =
|
|
11
|
+
// Default SSE events
|
|
12
|
+
| 'CONNECTED'
|
|
13
|
+
| 'CHAT_RUN_STATUS'
|
|
14
|
+
| 'CHAT_RUN_UPDATE'
|
|
15
|
+
// Durable chat checkpoints append a new message or replace an existing one
|
|
16
|
+
| 'QUERY_APPEND'
|
|
17
|
+
| 'DATA_UPDATE';
|
|
16
18
|
|
|
17
19
|
export interface PublishPayload {
|
|
18
20
|
__type: ValidSSEType;
|
|
19
21
|
fragmentKey: string;
|
|
20
22
|
fragmentNamespace?: string;
|
|
21
|
-
|
|
23
|
+
dataFragmentKey?: string;
|
|
22
24
|
data: Record<string, any>;
|
|
23
|
-
otherData?: Record<string, any>;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
*
|
|
27
|
+
/*
|
|
28
|
+
* Ignore an older full checkpoint from an overlapping reconnect before it
|
|
29
|
+
* changes either the normalized cache or the chat's local streaming state.
|
|
28
30
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const { __type, fragmentKey, fragmentNamespace, dataFragmentKey, data, otherData } = payload;
|
|
33
|
-
|
|
34
|
-
if (fragmentKey && fragmentNamespace && dataFragmentKey && data) {
|
|
35
|
-
const isAppend = __type === 'QUERY_APPEND';
|
|
36
|
-
const updateData = (currentData: any) => {
|
|
37
|
-
const currentList = currentData?.[fragmentNamespace]?.data;
|
|
38
|
-
if (
|
|
39
|
-
currentData?.[fragmentNamespace]?.__list &&
|
|
40
|
-
Array.isArray(currentList) &&
|
|
41
|
-
!currentList.find(a => a[0] === dataFragmentKey)
|
|
42
|
-
) {
|
|
43
|
-
addFragmentToCache(dataFragmentKey, data);
|
|
44
|
-
const updatedList = isAppend ? [...currentList, [dataFragmentKey]] : [[dataFragmentKey], ...currentList];
|
|
45
|
-
|
|
46
|
-
// console.log('UPDATED !!!!')
|
|
47
|
-
// console.log('UPDATED !!!!')
|
|
48
|
-
// console.log('UPDATED !!!!')
|
|
49
|
-
// console.log('UPDATED !!!!')
|
|
50
|
-
// console.log(fragmentNamespace, {
|
|
51
|
-
// ...currentData?.[fragmentNamespace],
|
|
52
|
-
// data: updatedList
|
|
53
|
-
// });
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
...currentData,
|
|
57
|
-
...otherData,
|
|
58
|
-
[fragmentNamespace]: {
|
|
59
|
-
...currentData?.[fragmentNamespace],
|
|
60
|
-
data: updatedList
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
return currentData;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
updateQuery(
|
|
68
|
-
fragmentKey,
|
|
69
|
-
updateData,
|
|
70
|
-
false,
|
|
71
|
-
updateObservers
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return null;
|
|
31
|
+
export function isStaleSSECheckpoint(payload: PublishPayload) {
|
|
32
|
+
const key = payload.dataFragmentKey || payload.fragmentKey;
|
|
33
|
+
return !!key?.startsWith(FRAGMENT_NAMES.aiChatMessage + ':') && isOlderChatCheckpoint(loadFragment(key), payload.data);
|
|
76
34
|
}
|
|
77
35
|
|
|
78
36
|
/**
|
|
79
|
-
* Append
|
|
37
|
+
* Append data to a query
|
|
80
38
|
*/
|
|
81
39
|
|
|
82
|
-
function
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
40
|
+
function handleQueryAppend(payload: PublishPayload, updateObservers?: UpdateObserversFn) {
|
|
41
|
+
const { fragmentKey, fragmentNamespace, dataFragmentKey, data } = payload;
|
|
42
|
+
|
|
43
|
+
if (fragmentKey && fragmentNamespace && dataFragmentKey && data) {
|
|
44
|
+
addFragmentToCache(dataFragmentKey, data);
|
|
45
|
+
|
|
46
|
+
const updateData = (currentData: any) => {
|
|
47
|
+
const currentList = currentData?.[fragmentNamespace]?.data;
|
|
48
|
+
if (
|
|
49
|
+
currentData?.[fragmentNamespace]?.__list &&
|
|
50
|
+
Array.isArray(currentList) &&
|
|
51
|
+
!currentList.find((a) => a[0] === dataFragmentKey)
|
|
52
|
+
) {
|
|
53
|
+
return {
|
|
54
|
+
...currentData,
|
|
55
|
+
[fragmentNamespace]: {
|
|
56
|
+
...currentData?.[fragmentNamespace],
|
|
57
|
+
data: [...currentList, [dataFragmentKey]],
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return currentData;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
updateQuery(fragmentKey, updateData, true);
|
|
65
|
+
updateObservers?.({ queryId: fragmentKey, fragmentIds: [dataFragmentKey] });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return null;
|
|
108
69
|
}
|
|
109
70
|
|
|
110
71
|
/**
|
|
@@ -112,8 +73,15 @@ function handleFragmentConcat(payload: PublishPayload, updateObservers?: UpdateO
|
|
|
112
73
|
*/
|
|
113
74
|
|
|
114
75
|
function handleFragmentUpdate(payload: PublishPayload, updateObservers?: UpdateObserversFn) {
|
|
115
|
-
|
|
116
|
-
|
|
76
|
+
const { fragmentKey, dataFragmentKey, data } = payload;
|
|
77
|
+
const updateFragmentKey = dataFragmentKey || fragmentKey;
|
|
78
|
+
const updatedFragmentKey = updateFragment(updateFragmentKey, data, null, false, updateObservers);
|
|
79
|
+
if (!updatedFragmentKey) {
|
|
80
|
+
addFragmentToCache(updateFragmentKey, data);
|
|
81
|
+
updateObservers?.({
|
|
82
|
+
fragmentIds: [updateFragmentKey],
|
|
83
|
+
});
|
|
84
|
+
}
|
|
117
85
|
}
|
|
118
86
|
|
|
119
87
|
/**
|
|
@@ -121,23 +89,19 @@ function handleFragmentUpdate(payload: PublishPayload, updateObservers?: UpdateO
|
|
|
121
89
|
*/
|
|
122
90
|
|
|
123
91
|
function handleSSEData(payload: PublishPayload, updateObservers?: UpdateObserversFn) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
default:
|
|
138
|
-
console.log('Unknown {__type} in handleSSEData():', payload.__type);
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
92
|
+
if (isStaleSSECheckpoint(payload)) return;
|
|
93
|
+
switch (payload.__type) {
|
|
94
|
+
case 'CONNECTED':
|
|
95
|
+
// Do nothing
|
|
96
|
+
break;
|
|
97
|
+
case 'QUERY_APPEND':
|
|
98
|
+
return handleQueryAppend(payload, updateObservers);
|
|
99
|
+
case 'DATA_UPDATE':
|
|
100
|
+
return handleFragmentUpdate(payload, updateObservers);
|
|
101
|
+
default:
|
|
102
|
+
console.log('Unknown {__type} in handleSSEData():', payload.__type);
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
141
105
|
}
|
|
142
106
|
|
|
143
107
|
export default handleSSEData;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act, createElement } from 'react';
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client';
|
|
4
|
+
import { afterEach, beforeEach, expect, it, vi } from 'vitest';
|
|
5
|
+
import { clearGraphQLClientCache, setDataToCache, updateFragment } from '../cache/index.ts';
|
|
6
|
+
import { agentNoteQry, agentNotesQry } from '../gql/queries/agentNoteQueries.ts';
|
|
7
|
+
import { updateDataObservers } from '../hooks/index.ts';
|
|
8
|
+
import { useAgentNote } from '../hooks/use-agentNote-qry.ts';
|
|
9
|
+
|
|
10
|
+
const STATE = vi.hoisted(() => ({
|
|
11
|
+
requests: [] as { variables: any; complete: (note: any) => void }[],
|
|
12
|
+
value: null as any,
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
vi.mock('@jsb188/app/utils/api.ts', async (original) => ({
|
|
16
|
+
...(await original<Record<string, unknown>>()),
|
|
17
|
+
getAuthToken: () => 'token-1',
|
|
18
|
+
}));
|
|
19
|
+
vi.mock('@jsb188/react/states', () => ({
|
|
20
|
+
useConnectedToServerValue: () => true,
|
|
21
|
+
useOptimisticConnectedToServerValue: () => true,
|
|
22
|
+
useScreenIsFocusedValue: () => true,
|
|
23
|
+
useCurrentAccount: () => ({ account: { id: 'account-1' } }),
|
|
24
|
+
useRealtimeConnectionGenerationValue: () => 0,
|
|
25
|
+
}));
|
|
26
|
+
vi.mock('../hooks/use-agentNote-mtn.ts', () => ({ useMarkAgentNoteRead: () => undefined }));
|
|
27
|
+
vi.mock('../client/request.ts', () => ({
|
|
28
|
+
/* Complete the same guarded and normalized request path used by the real client. */
|
|
29
|
+
graphqlRequest: (query: any, variables: any, options: any, _signal: any, observers: any) =>
|
|
30
|
+
new Promise((resolve) => {
|
|
31
|
+
STATE.requests.push({
|
|
32
|
+
variables,
|
|
33
|
+
complete: (note) => {
|
|
34
|
+
const data = { agentNote: note };
|
|
35
|
+
if (options.shouldAcceptResult?.(data, variables) === false) {
|
|
36
|
+
resolve({ __clientResultRejected: true });
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
setDataToCache(data, query, variables, undefined, observers);
|
|
40
|
+
options.onCompleted?.({ data }, null);
|
|
41
|
+
resolve(data);
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}),
|
|
45
|
+
}));
|
|
46
|
+
|
|
47
|
+
let root: Root;
|
|
48
|
+
|
|
49
|
+
/* Render the real cache-first detail hook that both the menu and drawer use. */
|
|
50
|
+
const Reader = (p: { organizationId?: string; agentNoteId?: string } = {}) => {
|
|
51
|
+
STATE.value = useAgentNote(
|
|
52
|
+
{ organizationId: p.organizationId || 'org-1', agentNoteId: p.agentNoteId || 'note-1' },
|
|
53
|
+
{ cacheFirst: true, markRead: false },
|
|
54
|
+
);
|
|
55
|
+
return createElement('span', null, STATE.value.agentNote?.body);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/* Supply the detail fields whose absence distinguishes a homepage summary from a full note. */
|
|
59
|
+
function note(extra: Record<string, unknown> = {}) {
|
|
60
|
+
return { id: 'note-1', organizationId: 'org-1', headline: 'Tracker', body: 'Cached body', links: [], ...extra };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
beforeEach(() => {
|
|
64
|
+
(console as any).dev ||= () => undefined;
|
|
65
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true);
|
|
66
|
+
clearGraphQLClientCache();
|
|
67
|
+
STATE.requests = [];
|
|
68
|
+
document.body.innerHTML = '<div id="root"></div>';
|
|
69
|
+
root = createRoot(document.getElementById('root')!);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
afterEach(async () => {
|
|
73
|
+
act(() => root.unmount());
|
|
74
|
+
await act(async () => {
|
|
75
|
+
for (const request of STATE.requests) request.complete(null);
|
|
76
|
+
});
|
|
77
|
+
clearGraphQLClientCache();
|
|
78
|
+
vi.unstubAllGlobals();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('renders full normalized details without a detail request and observes live changes', async () => {
|
|
82
|
+
setDataToCache({ agentNote: note() }, agentNoteQry, { organizationId: 'org-1', agentNoteId: 'note-1' });
|
|
83
|
+
await act(async () => root.render(createElement(Reader)));
|
|
84
|
+
expect(STATE.requests).toHaveLength(0);
|
|
85
|
+
expect(STATE.value.agentNote.body).toBe('Cached body');
|
|
86
|
+
expect(STATE.value.loading).toBe(false);
|
|
87
|
+
await act(async () => {
|
|
88
|
+
updateFragment('$agentNoteFragment:note-1', { body: 'Live body' }, null, false, updateDataObservers);
|
|
89
|
+
});
|
|
90
|
+
expect(STATE.value.agentNote.body).toBe('Live body');
|
|
91
|
+
expect(STATE.requests).toHaveLength(0);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('loads details once when only a summary is cached, then reuses them after remount', async () => {
|
|
95
|
+
setDataToCache({ agentNotes: [{ id: 'note-1', organizationId: 'org-1', headline: 'Tracker' }] }, agentNotesQry, {
|
|
96
|
+
organizationId: 'org-1',
|
|
97
|
+
});
|
|
98
|
+
await act(async () => root.render(createElement(Reader)));
|
|
99
|
+
expect(STATE.requests).toHaveLength(1);
|
|
100
|
+
await act(async () => STATE.requests[0].complete(note()));
|
|
101
|
+
expect(STATE.value.agentNote.body).toBe('Cached body');
|
|
102
|
+
await act(async () => root.render(null));
|
|
103
|
+
await act(async () => root.render(createElement(Reader)));
|
|
104
|
+
expect(STATE.requests).toHaveLength(1);
|
|
105
|
+
expect(STATE.value.agentNote.body).toBe('Cached body');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('does not reuse a cached note from another organization', async () => {
|
|
109
|
+
setDataToCache({ agentNote: note() }, agentNoteQry, { organizationId: 'org-1', agentNoteId: 'note-1' });
|
|
110
|
+
await act(async () => root.render(createElement(Reader, { organizationId: 'org-2' })));
|
|
111
|
+
expect(STATE.requests).toHaveLength(1);
|
|
112
|
+
expect(STATE.value.agentNote).toBeNull();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('keeps deleted cached notes unavailable without a request', async () => {
|
|
116
|
+
setDataToCache({ agentNote: note({ __deleted: true }) }, agentNoteQry, { organizationId: 'org-1', agentNoteId: 'note-1' });
|
|
117
|
+
await act(async () => root.render(createElement(Reader)));
|
|
118
|
+
expect(STATE.requests).toHaveLength(0);
|
|
119
|
+
expect(STATE.value.agentNote).toBeNull();
|
|
120
|
+
});
|