@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.
- package/LICENSE +21 -0
- package/audience.d.ts +14 -152
- package/cache/config.ts +35 -32
- package/cache/index.helpers.ts +1 -1
- package/cache/index.ts +73 -44
- package/cache/mounted-queries.ts +33 -0
- package/cache/persist.ts +10 -4
- package/cache/realtime-fence.ts +47 -0
- package/cache/realtime-live.ts +17 -0
- package/client/draft-persistence.ts +10 -39
- package/client/index.ts +2 -1
- package/client/request.ts +9 -34
- package/client/storage-asset.ts +58 -0
- package/gql/fragments/accountAuthFragments.ts +0 -4
- package/gql/fragments/agentNoteFragments.ts +8 -2
- package/gql/fragments/aiChatFragments.ts +0 -2
- package/gql/fragments/aiChatLinkFragments.ts +8 -0
- package/gql/fragments/audienceFragments.ts +1 -66
- package/gql/fragments/emailFragments.ts +27 -4
- package/gql/fragments/emailOutreachFragments.ts +281 -0
- package/gql/fragments/inboundContactFragments.ts +1 -1
- package/gql/fragments/libraryFragments.ts +120 -0
- package/gql/fragments/organizationFragments.ts +4 -2
- package/gql/fragments/scheduleFragments.ts +241 -324
- package/gql/fragments/sheetFragments.ts +4 -53
- package/gql/fragments/workWaitFragments.ts +13 -0
- package/gql/fragments/workflowFragments.ts +20 -4
- package/gql/mutations/agentNoteMutations.ts +2 -0
- package/gql/mutations/aiChatLinkMutations.ts +13 -0
- package/gql/mutations/aiChatMutations.ts +4 -6
- package/gql/mutations/audienceMutations.ts +0 -13
- package/gql/mutations/authMutations.ts +12 -60
- package/gql/mutations/emailMutations.ts +22 -0
- package/gql/mutations/emailOutreachMutations.ts +139 -0
- package/gql/mutations/index.ts +3 -1
- package/gql/mutations/organizationMutations.ts +2 -2
- package/gql/mutations/scheduleMutations.ts +61 -787
- package/gql/mutations/storageMutations.ts +1 -0
- package/gql/mutations/workflowMutations.ts +76 -0
- package/gql/queries/agentMemoryQueries.ts +6 -2
- package/gql/queries/agentNoteQueries.ts +26 -29
- package/gql/queries/aiChatQueries.ts +39 -40
- package/gql/queries/audienceQueries.ts +31 -55
- package/gql/queries/authQueries.ts +16 -6
- package/gql/queries/billingQueries.ts +26 -10
- package/gql/queries/dataTableQueries.ts +24 -15
- package/gql/queries/emailOutreachQueries.ts +282 -0
- package/gql/queries/emailQueries.ts +39 -12
- package/gql/queries/emailReplyReportQueries.ts +60 -9
- package/gql/queries/fieldDocQueries.ts +36 -14
- package/gql/queries/inboundContactQueries.ts +11 -4
- package/gql/queries/index.ts +2 -2
- package/gql/queries/libraryQueries.ts +112 -0
- package/gql/queries/logQueries.ts +31 -12
- package/gql/queries/organizationQueries.ts +31 -12
- package/gql/queries/qrCodeQueries.ts +11 -4
- package/gql/queries/scheduleQueries.ts +252 -505
- package/gql/queries/sheetQueries.ts +36 -14
- package/gql/queries/storageQueries.ts +11 -4
- package/gql/queries/workflowQueries.ts +53 -10
- package/gql/reactivity.ts +98 -0
- package/gql/recordReads.ts +171 -0
- package/hooks/index.ts +79 -52
- package/hooks/use-agentNote-mtn.ts +7 -0
- package/hooks/use-agentNote-qry.ts +30 -58
- package/hooks/use-agentNote-recovery.ts +6 -21
- package/hooks/use-aiChat-mtn.ts +9 -4
- package/hooks/use-aiChat-qry.ts +28 -7
- package/hooks/use-audience-mtn.ts +0 -24
- package/hooks/use-audience-qry.helpers.ts +0 -24
- package/hooks/use-audience-qry.ts +1 -86
- package/hooks/use-dataTable-mtn.ts +3 -3
- package/hooks/use-dataTable-qry.ts +7 -2
- package/hooks/use-email-mtn.ts +26 -0
- package/hooks/use-email-qry.helpers.ts +1 -1
- package/hooks/use-email-qry.ts +18 -3
- 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-qry.ts +1 -1
- package/hooks/use-library-qry.ts +233 -0
- package/hooks/use-qrCode-qry.ts +1 -1
- package/hooks/use-schedule-mtn.ts +10 -300
- package/hooks/use-schedule-qry.ts +168 -680
- package/hooks/use-schedule-reactive.ts +71 -339
- package/hooks/use-sheet-qry.ts +6 -1
- package/hooks/use-workflow-mtn.ts +45 -1
- package/hooks/use-workflow-qry.ts +22 -2
- package/libs/ai-chat-link-events.ts +78 -0
- package/libs/data-changes.helpers.ts +161 -0
- package/libs/data-changes.ts +382 -0
- package/libs/fragment-realtime-sequence.ts +3 -3
- package/libs/record-read.ts +327 -0
- package/libs/sheet-command-batch.ts +3 -2
- package/libs/sheet-realtime-packet.ts +53 -0
- package/loaders/emailPreference.ts +18 -24
- package/package.json +44 -17
- package/schedule.d.ts +267 -874
- package/types.d.ts +3 -1
- package/cache/index.chat-activity.test.ts +0 -119
- package/cache/index.chat.test.ts +0 -92
- package/cache/index.regression.test.ts +0 -149
- package/cache/index.test.ts +0 -1209
- package/deno.lock +0 -187
- package/deno.test.json +0 -12
- package/gql/fragments/campaignFragments.ts +0 -566
- package/gql/mutations/campaignMutations.ts +0 -258
- package/gql/queries/appQueries.ts +0 -14
- package/gql/queries/campaignQueries.ts +0 -236
- package/hooks/index.helpers.test.ts +0 -50
- package/hooks/use-agentNote-recovery.helpers.test.ts +0 -68
- package/hooks/use-aiChat-qry.helpers.test.ts +0 -63
- package/hooks/use-app-qry.ts +0 -22
- package/hooks/use-audience-qry.helpers.test.ts +0 -80
- package/hooks/use-campaign-generation-recovery.ts +0 -53
- package/hooks/use-campaign-mtn.ts +0 -436
- package/hooks/use-campaign-qry.helpers.ts +0 -40
- package/hooks/use-campaign-qry.ts +0 -834
- package/hooks/use-emailCampaignReplyReport-qry.ts +0 -27
- package/hooks/use-fieldDoc-qry.helpers.test.ts +0 -65
- package/hooks/use-publicFormEmail-mtn.ts +0 -27
- package/libs/fragment-recovery.test.ts +0 -326
- package/libs/fragment-recovery.ts +0 -325
- package/libs/orchestrator-realtime.helpers.test.ts +0 -229
- package/libs/orchestrator-realtime.helpers.ts +0 -317
- package/libs/orchestrator-realtime.ts +0 -433
- package/libs/request-cache-regression.test.ts +0 -122
- package/libs/request-managed-session.test.ts +0 -574
- package/libs/request-no-store.test.ts +0 -419
- package/libs/sheet-view-realtime-router.test.ts +0 -214
- package/libs/sse-ticket.test.ts +0 -26
- package/loaders/campaign.test.ts +0 -186
- package/loaders/campaign.ts +0 -110
- package/tests/agent-note-detail-cache.test.ts +0 -120
- package/tests/agent-note-search.test.ts +0 -444
- package/tsconfig.json +0 -13
package/types.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export interface UpdateDataObserverArgs {
|
|
|
26
26
|
fragmentIds?: (string | null)[];
|
|
27
27
|
forceRefetch?: boolean;
|
|
28
28
|
resetOnly?: boolean;
|
|
29
|
+
// With resetOnly: this tab's own request caused the reset, so a mounted result refetches instead of showing the notice
|
|
30
|
+
selfRefresh?: boolean;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
/**
|
|
@@ -85,7 +87,7 @@ export interface GraphQLQueryOptions {
|
|
|
85
87
|
skip?: boolean;
|
|
86
88
|
// Revalidate cached data once on mount, query-scope change, or skip -> active.
|
|
87
89
|
// Defaults to true. False retains freshness-window checks for this query.
|
|
88
|
-
// Cached data still renders immediately; active
|
|
90
|
+
// Cached data still renders immediately; an active "new data" notice stays deferred.
|
|
89
91
|
revalidateOnMount?: boolean;
|
|
90
92
|
// Freshness window in ms for cache-age checks, including entry when
|
|
91
93
|
// revalidateOnMount is false. Does not control IndexedDB retention.
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { makeGraphQLVariablesKey } from '@jsb188/app/utils/logic.ts';
|
|
2
|
-
import { makeQueryResetTarget } from '@jsb188/app/utils/queryReset.ts';
|
|
3
|
-
import { getActiveAIChatsByActivity, getAIChatActivityOrder } from '@jsb188/mday/utils/aiChat.ts';
|
|
4
|
-
import { aiChatQry, aiChatsQry } from '../gql/queries/aiChatQueries.ts';
|
|
5
|
-
import {
|
|
6
|
-
clearGraphQLClientCache,
|
|
7
|
-
loadFragment,
|
|
8
|
-
loadQuery,
|
|
9
|
-
resetQueryByTargetIfFragmentsMissing,
|
|
10
|
-
setDataToCache,
|
|
11
|
-
updateFragment,
|
|
12
|
-
} from './index.ts';
|
|
13
|
-
|
|
14
|
-
if (typeof (console as any).dev !== 'function') (console as any).dev = () => {};
|
|
15
|
-
|
|
16
|
-
/* Fail with the actual value when cache behavior differs from the expected result. */
|
|
17
|
-
function assertEqual(actual: unknown, expected: unknown) {
|
|
18
|
-
if (JSON.stringify(actual) !== JSON.stringify(expected))
|
|
19
|
-
throw new Error(`Expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/* Build the exact sidebar variables used by the mounted query. */
|
|
23
|
-
function sidebarVariables(organizationId = 'org') {
|
|
24
|
-
return { organizationId, filter: 'CHATS', cursor: null, after: false, limit: 70 };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/* Seed a small authoritative sidebar snapshot with opaque identifiers. */
|
|
28
|
-
function seedSidebar(organizationId = 'org') {
|
|
29
|
-
const chats = [
|
|
30
|
-
{ id: 'opaque-a', updatedAt: '2026-10-04T12:00:00.000Z', activityOrder: getAIChatActivityOrder('2026-10-04T12:00:00.000Z', 9) },
|
|
31
|
-
{ id: 'opaque-z', updatedAt: '2026-10-04T11:00:00.000Z', activityOrder: getAIChatActivityOrder('2026-10-04T11:00:00.000Z', 10) },
|
|
32
|
-
];
|
|
33
|
-
setDataToCache({ aiChats: chats }, aiChatsQry, sidebarVariables(organizationId));
|
|
34
|
-
return chats;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
Deno.test('listed chat activity reorders immediately without requesting any query reset', () => {
|
|
38
|
-
clearGraphQLClientCache();
|
|
39
|
-
seedSidebar();
|
|
40
|
-
const events: unknown[] = [];
|
|
41
|
-
resetQueryByTargetIfFragmentsMissing(
|
|
42
|
-
makeQueryResetTarget('aiChats', { organizationId: 'org', filter: 'CHATS' }),
|
|
43
|
-
['$aiChatFragment:opaque-z'],
|
|
44
|
-
(event) => events.push(event),
|
|
45
|
-
);
|
|
46
|
-
assertEqual(events, []);
|
|
47
|
-
updateFragment('$aiChatFragment:opaque-z', {
|
|
48
|
-
updatedAt: '2026-10-04T13:00:00.000Z',
|
|
49
|
-
activityOrder: getAIChatActivityOrder('2026-10-04T13:00:00.000Z', 10),
|
|
50
|
-
});
|
|
51
|
-
const chats = loadQuery(`#aiChats:${makeGraphQLVariablesKey(sidebarVariables())}`);
|
|
52
|
-
assertEqual(
|
|
53
|
-
getActiveAIChatsByActivity(chats).map((chat: any) => chat.id),
|
|
54
|
-
['opaque-z', 'opaque-a'],
|
|
55
|
-
);
|
|
56
|
-
assertEqual(
|
|
57
|
-
chats.map((chat: any) => chat.id),
|
|
58
|
-
['opaque-a', 'opaque-z'],
|
|
59
|
-
);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
Deno.test('a globally cached chat outside the sidebar resets only that organization list', () => {
|
|
63
|
-
clearGraphQLClientCache();
|
|
64
|
-
seedSidebar();
|
|
65
|
-
seedSidebar('other');
|
|
66
|
-
setDataToCache({ aiChat: { id: 'outside', updatedAt: '2026-10-04T13:00:00.000Z' } }, aiChatQry, { aiChatId: 'outside' });
|
|
67
|
-
const events: any[] = [];
|
|
68
|
-
resetQueryByTargetIfFragmentsMissing(
|
|
69
|
-
makeQueryResetTarget('aiChats', { organizationId: 'org', filter: 'CHATS' }),
|
|
70
|
-
['$aiChatFragment:outside'],
|
|
71
|
-
(event) => events.push(event),
|
|
72
|
-
);
|
|
73
|
-
assertEqual(
|
|
74
|
-
events.map((event) => ({ queryId: event.queryId, forceRefetch: event.forceRefetch })),
|
|
75
|
-
[
|
|
76
|
-
{
|
|
77
|
-
queryId: `#aiChats:${makeGraphQLVariablesKey(sidebarVariables())}`,
|
|
78
|
-
forceRefetch: true,
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
Deno.test('a missing chat and an in-flight initial sidebar snapshot both request recovery', () => {
|
|
85
|
-
clearGraphQLClientCache();
|
|
86
|
-
const target = makeQueryResetTarget('aiChats', { organizationId: 'org', filter: 'CHATS' });
|
|
87
|
-
const events: any[] = [];
|
|
88
|
-
resetQueryByTargetIfFragmentsMissing(target, ['$aiChatFragment:new'], (event) => events.push(event));
|
|
89
|
-
assertEqual(events[0]?.queryTarget, target);
|
|
90
|
-
seedSidebar();
|
|
91
|
-
resetQueryByTargetIfFragmentsMissing(target, ['$aiChatFragment:new'], (event) => events.push(event));
|
|
92
|
-
assertEqual(events.length, 2);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
Deno.test('late queries and realtime metadata cannot move a chat back to older activity', () => {
|
|
96
|
-
clearGraphQLClientCache();
|
|
97
|
-
const stale = seedSidebar();
|
|
98
|
-
const fresh = { updatedAt: '2026-10-04T13:00:00.000Z', activityOrder: getAIChatActivityOrder('2026-10-04T13:00:00.000Z', 10) };
|
|
99
|
-
updateFragment('$aiChatFragment:opaque-z', fresh);
|
|
100
|
-
setDataToCache({ aiChats: stale }, aiChatsQry, sidebarVariables());
|
|
101
|
-
updateFragment('$aiChatFragment:opaque-z', { ...stale[1], summary: 'New title' });
|
|
102
|
-
const chat = loadFragment('$aiChatFragment:opaque-z');
|
|
103
|
-
assertEqual(
|
|
104
|
-
{ updatedAt: chat.updatedAt, activityOrder: chat.activityOrder, summary: chat.summary },
|
|
105
|
-
{ ...fresh, summary: 'New title' },
|
|
106
|
-
);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
Deno.test('timestamp ties use database id order rather than scrambled GenericID order', () => {
|
|
110
|
-
const updatedAt = '2026-10-04T13:00:00.000Z';
|
|
111
|
-
assertEqual(
|
|
112
|
-
getActiveAIChatsByActivity([
|
|
113
|
-
{ id: 'zzz', updatedAt, activityOrder: getAIChatActivityOrder(updatedAt, 9) },
|
|
114
|
-
{ id: 'aaa', updatedAt, activityOrder: getAIChatActivityOrder(updatedAt, 10) },
|
|
115
|
-
{ id: 'archived', updatedAt, archivedAt: updatedAt, activityOrder: getAIChatActivityOrder(updatedAt, 11) },
|
|
116
|
-
]).map((chat) => chat.id),
|
|
117
|
-
['aaa', 'zzz'],
|
|
118
|
-
);
|
|
119
|
-
});
|
package/cache/index.chat.test.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { makeGraphQLVariablesKey } from '@jsb188/app/utils/logic.ts';
|
|
2
|
-
import type { AIChatRunData } from '@jsb188/app/types/ai.d.ts';
|
|
3
|
-
import { aiChatMessagesQry, aiChatQry, aiChatWorkMessagesQry } from '../gql/queries/aiChatQueries.ts';
|
|
4
|
-
import { cacheAIChatRunUpdate } from '../libs/ai-chat-run-realtime.ts';
|
|
5
|
-
import { clearGraphQLClientCache, loadFragment, loadQuery, setDataToCache, updateFragment } from './index.ts';
|
|
6
|
-
|
|
7
|
-
if (typeof (console as any).dev !== 'function') (console as any).dev = () => {};
|
|
8
|
-
|
|
9
|
-
/* Assert the observable cache state without relying on a mounted hook's local state. */
|
|
10
|
-
function assertEqual(actual: unknown, expected: unknown) {
|
|
11
|
-
if (JSON.stringify(actual) !== JSON.stringify(expected))
|
|
12
|
-
throw new Error(`Expected ${JSON.stringify(expected)}, received ${JSON.stringify(actual)}`);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/* Build authoritative run snapshots with a fixed immutable start time. */
|
|
16
|
-
function makeRun(inProgress: boolean): AIChatRunData {
|
|
17
|
-
return {
|
|
18
|
-
id: 'run-1',
|
|
19
|
-
sourceMessageIds: ['source'],
|
|
20
|
-
status: inProgress ? 'RUNNING' : 'COMPLETED',
|
|
21
|
-
inProgress,
|
|
22
|
-
createdAt: '2026-10-02T10:00:00Z',
|
|
23
|
-
claimedAt: '2026-10-02T10:00:01Z',
|
|
24
|
-
updatedAt: inProgress ? '2026-10-02T10:00:01Z' : '2026-10-02T10:01:00Z',
|
|
25
|
-
finishedAt: inProgress ? null : '2026-10-02T10:01:00Z',
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
Deno.test('late chat queries cannot reopen canonical or embedded runs when the transcript is read again', () => {
|
|
30
|
-
clearGraphQLClientCache();
|
|
31
|
-
const variables = { aiChatId: 'chat', includeWork: false };
|
|
32
|
-
const stale = {
|
|
33
|
-
aiChat: {
|
|
34
|
-
id: 'chat',
|
|
35
|
-
inProgress: true,
|
|
36
|
-
latestRun: makeRun(true),
|
|
37
|
-
messages: [{ id: 'source', accountId: 'account', run: makeRun(true) }],
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
setDataToCache(stale, aiChatQry, variables);
|
|
41
|
-
cacheAIChatRunUpdate(makeRun(false), () => {});
|
|
42
|
-
setDataToCache(stale, aiChatQry, variables);
|
|
43
|
-
const reopened = loadQuery(`#aiChat:${makeGraphQLVariablesKey(variables)}`);
|
|
44
|
-
assertEqual(reopened.latestRun, makeRun(false));
|
|
45
|
-
assertEqual(reopened.messages[0].run, makeRun(false));
|
|
46
|
-
assertEqual(loadFragment('$aiChatRunFragment:run-1'), makeRun(false));
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
Deno.test('late run history pages retain streamed message revisions and stay separate from the outer transcript', () => {
|
|
50
|
-
clearGraphQLClientCache();
|
|
51
|
-
const stale = {
|
|
52
|
-
id: 'message',
|
|
53
|
-
runId: 'run-1',
|
|
54
|
-
run: makeRun(true),
|
|
55
|
-
revision: '1',
|
|
56
|
-
text: 'Partial',
|
|
57
|
-
finished: false,
|
|
58
|
-
generationStatus: 'STREAMING',
|
|
59
|
-
};
|
|
60
|
-
const fresh = { ...stale, revision: '2', text: 'Complete', finished: true, generationStatus: 'COMPLETED' };
|
|
61
|
-
setDataToCache({ aiChatMessages: [stale] }, aiChatMessagesQry);
|
|
62
|
-
updateFragment('$aiChatMessageFragment:message', fresh);
|
|
63
|
-
cacheAIChatRunUpdate(makeRun(false), () => {});
|
|
64
|
-
setDataToCache({ aiChatMessages: [stale] }, aiChatMessagesQry);
|
|
65
|
-
const workVariables = { aiChatId: 'chat', runId: 'run-1', cursor: null, after: false, limit: 55 };
|
|
66
|
-
setDataToCache({ aiChatMessages: [stale] }, aiChatWorkMessagesQry, workVariables);
|
|
67
|
-
setDataToCache({ aiChatMessages: [] }, aiChatMessagesQry);
|
|
68
|
-
const reread = loadQuery(`#aiChatMessages:${makeGraphQLVariablesKey(workVariables)}`);
|
|
69
|
-
assertEqual(reread, [{ ...fresh, run: makeRun(false) }]);
|
|
70
|
-
assertEqual(loadQuery(`#aiChatMessages:${makeGraphQLVariablesKey(undefined)}`), []);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
Deno.test('older message text can carry newer run settlement without a canonical run fragment', () => {
|
|
74
|
-
clearGraphQLClientCache();
|
|
75
|
-
const current = { id: 'message', runId: 'run-1', run: makeRun(true), revision: '9', text: 'Latest text' };
|
|
76
|
-
const incoming = { ...current, revision: '8', text: 'Older text', run: makeRun(false) };
|
|
77
|
-
setDataToCache({ aiChatMessages: [current] }, aiChatMessagesQry);
|
|
78
|
-
setDataToCache({ aiChatMessages: [incoming] }, aiChatMessagesQry);
|
|
79
|
-
assertEqual(loadFragment('$aiChatRunFragment:run-1'), null);
|
|
80
|
-
assertEqual(loadFragment('$aiChatMessageFragment:message'), { ...current, run: makeRun(false) });
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
Deno.test('an older canonical run cannot replace a newer source message association', () => {
|
|
84
|
-
clearGraphQLClientCache();
|
|
85
|
-
const newerRun = { ...makeRun(true), id: 'run-2', createdAt: '2026-10-02T10:02:00Z', updatedAt: '2026-10-02T10:02:01Z' };
|
|
86
|
-
const current = { id: 'source', run: newerRun, revision: '9', text: 'Latest text' };
|
|
87
|
-
setDataToCache({ aiChatMessages: [current] }, aiChatMessagesQry);
|
|
88
|
-
// Normalize the prior run without issuing a source-association SSE update.
|
|
89
|
-
setDataToCache({ aiChat: { id: 'chat', latestRun: makeRun(false) } }, aiChatQry);
|
|
90
|
-
setDataToCache({ aiChatMessages: [{ ...current, revision: '8', text: 'Older text', run: makeRun(false) }] }, aiChatMessagesQry);
|
|
91
|
-
assertEqual(loadFragment('$aiChatMessageFragment:source'), current);
|
|
92
|
-
});
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { gql } from 'graphql-tag';
|
|
2
|
-
import { makeGraphQLVariablesKey } from '@jsb188/app/utils/logic.ts';
|
|
3
|
-
import { clearGraphQLClientCache, fetchCachedData, loadDataFromCache, loadFragment, setDataToCache } from './index.ts';
|
|
4
|
-
import { cacheStore } from './store.ts';
|
|
5
|
-
import { graphQLValuesEqual } from './value.helpers.ts';
|
|
6
|
-
import { makeQueryResetTarget, queryCacheKeyMatchesResetTarget } from '@jsb188/app/utils/queryReset.ts';
|
|
7
|
-
|
|
8
|
-
/* Assert response values without collapsing undefined, null or empty objects. */
|
|
9
|
-
function equal(actual: any, expected: any) {
|
|
10
|
-
if (!graphQLValuesEqual(actual, expected))
|
|
11
|
-
throw new Error(`Expected ${JSON.stringify(expected)}, received ${JSON.stringify(actual)}`);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const ORGANIZATIONS = gql`
|
|
15
|
-
fragment relationshipFragment on Relationship { id name }
|
|
16
|
-
query myOrganizations {
|
|
17
|
-
myOrganizations {
|
|
18
|
-
...relationshipFragment
|
|
19
|
-
billingAccess { enforcement planKey }
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
`;
|
|
23
|
-
|
|
24
|
-
Deno.test('nullable billing access remains complete through object/null transitions and legacy cache repair', () => {
|
|
25
|
-
clearGraphQLClientCache();
|
|
26
|
-
const variables = makeGraphQLVariablesKey(undefined);
|
|
27
|
-
for (const billingAccess of [null, { enforcement: 'ACTIVE', planKey: null }, null]) {
|
|
28
|
-
const data = { myOrganizations: [{ id: 'org-1', name: 'Marketday', billingAccess }] };
|
|
29
|
-
setDataToCache(data, ORGANIZATIONS);
|
|
30
|
-
equal(fetchCachedData(ORGANIZATIONS, variables), data);
|
|
31
|
-
equal(loadFragment('$relationshipFragment:org-1'), data.myOrganizations[0]);
|
|
32
|
-
}
|
|
33
|
-
cacheStore.fragments.set('$relationshipFragment:org-1.spreads', {
|
|
34
|
-
billingAccess: [
|
|
35
|
-
['enforcement', undefined],
|
|
36
|
-
['planKey', undefined],
|
|
37
|
-
],
|
|
38
|
-
});
|
|
39
|
-
cacheStore.fragments.set('$relationshipFragment:org-1', { id: 'org-1', name: 'Marketday' });
|
|
40
|
-
equal(fetchCachedData(ORGANIZATIONS, variables), null);
|
|
41
|
-
const healed = { myOrganizations: [{ id: 'org-1', name: 'Marketday', billingAccess: null }] };
|
|
42
|
-
setDataToCache(healed, ORGANIZATIONS);
|
|
43
|
-
equal(fetchCachedData(ORGANIZATIONS, variables), healed);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
Deno.test('a mutation can shrink or clear nested lists without resurrecting removed members', () => {
|
|
47
|
-
clearGraphQLClientCache();
|
|
48
|
-
const query = gql`fragment parentFragment on Parent { id } fragment childFragment on Child { id name }
|
|
49
|
-
query parent { parent { ...parentFragment children { ...childFragment } } }`;
|
|
50
|
-
const mutation = gql`fragment parentFragment on Parent { id } fragment childFragment on Child { id name }
|
|
51
|
-
mutation editParent { editParent { ...parentFragment children { ...childFragment } } }`;
|
|
52
|
-
const children = [
|
|
53
|
-
{ id: 'child-1', name: 'One' },
|
|
54
|
-
{ id: 'child-2', name: 'Two' },
|
|
55
|
-
];
|
|
56
|
-
setDataToCache({ parent: { id: 'parent-1', children } }, query);
|
|
57
|
-
for (const nextChildren of [children.slice(1), [], null, [null, children[0]]]) {
|
|
58
|
-
setDataToCache({ editParent: { id: 'parent-1', children: nextChildren } }, mutation);
|
|
59
|
-
equal(fetchCachedData(query, makeGraphQLVariablesKey(undefined)), { parent: { id: 'parent-1', children: nextChildren } });
|
|
60
|
-
}
|
|
61
|
-
cacheStore.fragments.delete('$childFragment:child-1');
|
|
62
|
-
equal(fetchCachedData(query, makeGraphQLVariablesKey(undefined)), null);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
Deno.test('explicit root null and scalar values replace old cache and are reusable', () => {
|
|
66
|
-
clearGraphQLClientCache();
|
|
67
|
-
const query = gql`query record { record { id } }`;
|
|
68
|
-
setDataToCache({ record: { id: 'record-1' } }, query);
|
|
69
|
-
setDataToCache({ record: null }, query);
|
|
70
|
-
equal(fetchCachedData(query, makeGraphQLVariablesKey(undefined)), { record: null });
|
|
71
|
-
equal(loadDataFromCache({ record: null }, query, makeGraphQLVariablesKey(undefined), undefined, { record: '$recordFragment:old' }), {
|
|
72
|
-
record: null,
|
|
73
|
-
});
|
|
74
|
-
const scalars = gql`query counts { count enabled message labels }`;
|
|
75
|
-
const data = { count: 0, enabled: false, message: '', labels: ['one', null, 'two'] };
|
|
76
|
-
setDataToCache(data, scalars);
|
|
77
|
-
equal(fetchCachedData(scalars, makeGraphQLVariablesKey(undefined)), data);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
Deno.test('nested aliases, nullable list members and direct inline fields round-trip', () => {
|
|
81
|
-
clearGraphQLClientCache();
|
|
82
|
-
const query = gql`query result { result { label: name entries { __typename ... on Entry { label: name } } } }`;
|
|
83
|
-
const data = { result: { label: 'Result', entries: [null, { __typename: 'Entry', label: 'Entry' }] } };
|
|
84
|
-
setDataToCache(data, query);
|
|
85
|
-
equal(fetchCachedData(query, makeGraphQLVariablesKey(undefined)), data);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
Deno.test('cache reads preserve empty JSON objects and equal writes retain memoized references', () => {
|
|
89
|
-
clearGraphQLClientCache();
|
|
90
|
-
const query = gql`fragment jsonFragment on Record { id settings } query record { record { ...jsonFragment } }`;
|
|
91
|
-
const settings = Object.freeze({});
|
|
92
|
-
const data = { record: { id: 'record-1', settings } };
|
|
93
|
-
setDataToCache(data, query);
|
|
94
|
-
const first = fetchCachedData(query, makeGraphQLVariablesKey(undefined));
|
|
95
|
-
equal(first, data);
|
|
96
|
-
setDataToCache({ record: { settings: {}, id: 'record-1' } }, query);
|
|
97
|
-
if (fetchCachedData(query, makeGraphQLVariablesKey(undefined)) !== first)
|
|
98
|
-
throw new Error('Equal writes invalidated the memoized result');
|
|
99
|
-
equal(settings, {});
|
|
100
|
-
equal(graphQLValuesEqual({ field: undefined }, {}), false);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
Deno.test('GraphQL cache identity preserves case, types, nulls and delimiters while resets remain compatible', () => {
|
|
104
|
-
const inputs = [
|
|
105
|
-
{ value: 'ABC' },
|
|
106
|
-
{ value: 'abc' },
|
|
107
|
-
{ value: 1 },
|
|
108
|
-
{ value: '1' },
|
|
109
|
-
{ value: null },
|
|
110
|
-
{ value: '' },
|
|
111
|
-
{},
|
|
112
|
-
{ value: '$other:1' },
|
|
113
|
-
];
|
|
114
|
-
const keys = inputs.map(makeGraphQLVariablesKey);
|
|
115
|
-
equal(new Set(keys).size, inputs.length);
|
|
116
|
-
equal(makeGraphQLVariablesKey({ b: { two: 2, one: 1 }, a: undefined }), makeGraphQLVariablesKey({ b: { one: 1, two: 2 } }));
|
|
117
|
-
const queryKey =
|
|
118
|
-
'#rows:' + makeGraphQLVariablesKey({ organizationId: 'ORG-A', filter: { schemaId: 'SCHEMA-A' }, text: '$organizationid:org-b' });
|
|
119
|
-
equal(
|
|
120
|
-
queryCacheKeyMatchesResetTarget(
|
|
121
|
-
queryKey,
|
|
122
|
-
makeQueryResetTarget('rows', { organizationId: 'ORG-A', 'filter.schemaId': 'SCHEMA-A' }),
|
|
123
|
-
),
|
|
124
|
-
true,
|
|
125
|
-
);
|
|
126
|
-
equal(queryCacheKeyMatchesResetTarget(queryKey, makeQueryResetTarget('rows', { organizationId: 'org-b' })), false);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
Deno.test('mutation responses update shared fragments without storing a reusable mutation root', () => {
|
|
130
|
-
clearGraphQLClientCache();
|
|
131
|
-
const mutation = gql`fragment recordFragment on Record { id name } mutation editRecord { editRecord { ...recordFragment } }`;
|
|
132
|
-
setDataToCache({ editRecord: { id: 'record-1', name: 'Updated' } }, mutation);
|
|
133
|
-
equal(loadFragment('$recordFragment:record-1'), { id: 'record-1', name: 'Updated' });
|
|
134
|
-
equal(fetchCachedData(mutation, makeGraphQLVariablesKey(undefined)), null);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
Deno.test('a server JSON scalar replaces deleted keys in fragment and inline object selections', () => {
|
|
138
|
-
clearGraphQLClientCache();
|
|
139
|
-
const query = gql`fragment settingsFragment on Record { id settings address { city region } } query record { record { ...settingsFragment } }`;
|
|
140
|
-
setDataToCache({ record: { id: 'record-1', settings: { removed: true }, address: { city: 'Old', region: 'Ontario' } } }, query);
|
|
141
|
-
setDataToCache({ record: { id: 'record-1', settings: {}, address: { city: 'New', region: 'Ontario' } } }, query);
|
|
142
|
-
equal(fetchCachedData(query, makeGraphQLVariablesKey(undefined)), {
|
|
143
|
-
record: { id: 'record-1', settings: {}, address: { city: 'New', region: 'Ontario' } },
|
|
144
|
-
});
|
|
145
|
-
const inline = gql`fragment inlineSettingsFragment on Record { id } query inlineRecord { inlineRecord { ...inlineSettingsFragment config { settings } } }`;
|
|
146
|
-
setDataToCache({ inlineRecord: { id: 'inline-1', config: { settings: { removed: true } } } }, inline);
|
|
147
|
-
setDataToCache({ inlineRecord: { id: 'inline-1', config: { settings: {} } } }, inline);
|
|
148
|
-
equal(fetchCachedData(inline, makeGraphQLVariablesKey(undefined)), { inlineRecord: { id: 'inline-1', config: { settings: {} } } });
|
|
149
|
-
});
|