@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
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { EmailCampaignReplyReportGQL } from '@jsb188/mday/types/emailReplyReport.d.ts';
|
|
2
|
-
import { useQuery } from '../client/index.ts';
|
|
3
|
-
import { emailCampaignReplyReportQry } from '../gql/queries/emailReplyReportQueries.ts';
|
|
4
|
-
import type { UseQueryParams } from '../types.d.ts';
|
|
5
|
-
import { getCampaignQueryData } from './use-campaign-qry.helpers.ts';
|
|
6
|
-
|
|
7
|
-
/*
|
|
8
|
-
* Read one complete campaign report into mounted query state, hiding retained
|
|
9
|
-
* output after scope changes or read errors. RESET_ONLY preserves the displayed
|
|
10
|
-
* snapshot until the ordinary query refresh action is acknowledged.
|
|
11
|
-
*/
|
|
12
|
-
export function useEmailCampaignReplyReport(
|
|
13
|
-
variables: { organizationId?: string | null; campaignId?: string | null },
|
|
14
|
-
params: UseQueryParams = {},
|
|
15
|
-
) {
|
|
16
|
-
const skipped = !variables.organizationId || !variables.campaignId || !!params.skip;
|
|
17
|
-
const { data, ...rest } = useQuery(emailCampaignReplyReportQry, {
|
|
18
|
-
...params,
|
|
19
|
-
variables,
|
|
20
|
-
skip: skipped,
|
|
21
|
-
});
|
|
22
|
-
const currentData = getCampaignQueryData({ data, ...rest }, skipped || !!rest.error);
|
|
23
|
-
return {
|
|
24
|
-
...rest,
|
|
25
|
-
report: (currentData?.emailCampaignReplyReport ?? null) as EmailCampaignReplyReportGQL | null,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { getFieldDocSubmissionsVariables, normalizeFieldDocSubmissionsFilter } from './use-fieldDoc-qry.helpers.ts';
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* Throw one readable test failure when a condition is false.
|
|
5
|
-
*/
|
|
6
|
-
function expect(value: unknown, message: string) {
|
|
7
|
-
if (!value) {
|
|
8
|
-
throw new Error(message);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
Deno.test('the submissions filter keeps only FieldDocSubmissionsFilter fields', () => {
|
|
13
|
-
const filter = normalizeFieldDocSubmissionsFilter({
|
|
14
|
-
fieldDocProgramId: 'P1',
|
|
15
|
-
fieldDocIds: ['D1', 'D2'],
|
|
16
|
-
statuses: ['OPEN'],
|
|
17
|
-
startPeriod: '2026-10-01',
|
|
18
|
-
siteId: '',
|
|
19
|
-
sort: 'PERIOD_DESC',
|
|
20
|
-
startDate: '2026-10-01',
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
expect(
|
|
24
|
-
JSON.stringify(filter) ===
|
|
25
|
-
JSON.stringify({
|
|
26
|
-
fieldDocProgramId: 'P1',
|
|
27
|
-
fieldDocIds: ['D1', 'D2'],
|
|
28
|
-
siteId: null,
|
|
29
|
-
statuses: ['OPEN'],
|
|
30
|
-
startPeriod: '2026-10-01',
|
|
31
|
-
endPeriod: null,
|
|
32
|
-
}),
|
|
33
|
-
'URL-only keys are dropped and every input field is present in one fixed order.',
|
|
34
|
-
);
|
|
35
|
-
expect(
|
|
36
|
-
JSON.stringify(normalizeFieldDocSubmissionsFilter({ fieldDocProgramId: 'P1' })) ===
|
|
37
|
-
JSON.stringify(normalizeFieldDocSubmissionsFilter({ fieldDocProgramId: 'P1', preset: 'x' })),
|
|
38
|
-
'Equal filters build equal variables, so every consumer shares one cache entry.',
|
|
39
|
-
);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
Deno.test('the first page and fetchMore follow the logEntries cursor contract', () => {
|
|
43
|
-
const first = getFieldDocSubmissionsVariables({ organizationId: 'O1', filter: { fieldDocProgramId: 'P1' } });
|
|
44
|
-
expect(
|
|
45
|
-
first.cursor === null && first.after === true && first.limit === 100 && first.organizationId === 'O1',
|
|
46
|
-
'The first page has no cursor, after true and the fixed limit.',
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
const next = getFieldDocSubmissionsVariables({
|
|
50
|
-
organizationId: 'O1',
|
|
51
|
-
filter: { fieldDocProgramId: 'P1' },
|
|
52
|
-
cursor: 'C1',
|
|
53
|
-
after: false,
|
|
54
|
-
limit: 40,
|
|
55
|
-
sort: 'PERIOD_DESC',
|
|
56
|
-
} as any);
|
|
57
|
-
expect(
|
|
58
|
-
next.cursor === 'C1' && next.after === false && next.limit === 40,
|
|
59
|
-
'fetchMore keeps the row cursor, the direction and the requested page size.',
|
|
60
|
-
);
|
|
61
|
-
expect(
|
|
62
|
-
JSON.stringify(Object.keys(next)) === JSON.stringify(['organizationId', 'filter', 'cursor', 'after', 'limit']),
|
|
63
|
-
'Only the declared query variables are sent; the route table sort is dropped.',
|
|
64
|
-
);
|
|
65
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
2
|
-
import { confirmPublicFormEmailCodeMtn, sendPublicFormEmailCodeMtn } from '../gql/mutations/authMutations.ts';
|
|
3
|
-
import { useMutation } from './index.ts';
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
* Request a numeric email code for temporary public-form respondent access.
|
|
7
|
-
*/
|
|
8
|
-
export function useSendPublicFormEmailCode(params: UseMutationParams = {}) {
|
|
9
|
-
const [sendPublicFormEmailCode, mutation, handlers] = useMutation(sendPublicFormEmailCodeMtn, {
|
|
10
|
-
...params,
|
|
11
|
-
checkMountedBeforeCallback: true,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
return { sendPublicFormEmailCode, ...mutation, ...handlers };
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/*
|
|
18
|
-
* Verify a public-form email code without adopting an account session.
|
|
19
|
-
*/
|
|
20
|
-
export function useConfirmPublicFormEmailCode(params: UseMutationParams = {}) {
|
|
21
|
-
const [confirmPublicFormEmailCode, mutation, handlers] = useMutation(confirmPublicFormEmailCodeMtn, {
|
|
22
|
-
...params,
|
|
23
|
-
checkMountedBeforeCallback: true,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
return { confirmPublicFormEmailCode, ...mutation, ...handlers };
|
|
27
|
-
}
|
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { registerENV } from '@jsb188/app';
|
|
3
|
-
import type { WSDataUpdateObj } from '@jsb188/app/types/app.d.ts';
|
|
4
|
-
import { setAuthToken } from '@jsb188/app/utils/api.ts';
|
|
5
|
-
import { FRAGMENT_NAMES } from '@jsb188/mday/constants/graphqlReactivity.ts';
|
|
6
|
-
import { addFragmentToCache, clearGraphQLClientCache, loadFragment, loadQuery } from '../cache/index.ts';
|
|
7
|
-
import { clearFragmentRealtimeSequences, shouldApplyFragmentRealtimeSequence } from './fragment-realtime-sequence.ts';
|
|
8
|
-
import {
|
|
9
|
-
resolveFragmentRecoveryUpdate as applyFragmentRecoveryUpdate,
|
|
10
|
-
clearFragmentRecoveryRequests,
|
|
11
|
-
noteFragmentRealtimeUpdate,
|
|
12
|
-
} from './fragment-recovery.ts';
|
|
13
|
-
|
|
14
|
-
/* Capture the synchronously guarded apply callback for assertions without mutating cache. */
|
|
15
|
-
async function resolveFragmentRecoveryUpdate(update: WSDataUpdateObj) {
|
|
16
|
-
let result: { update: WSDataUpdateObj } | null = null;
|
|
17
|
-
await applyFragmentRecoveryUpdate(update, (resolved) => {
|
|
18
|
-
result = { update: resolved };
|
|
19
|
-
});
|
|
20
|
-
return result as { update: WSDataUpdateObj } | null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/* Build a real supported marker without depending on server mapper implementations. */
|
|
24
|
-
function marker(name = FRAGMENT_NAMES.agentNote as string, dataId = 'n1', sequence = '10'): WSDataUpdateObj {
|
|
25
|
-
return {
|
|
26
|
-
id: `${dataId}:${sequence}`,
|
|
27
|
-
fragments: [
|
|
28
|
-
{
|
|
29
|
-
name,
|
|
30
|
-
dataId,
|
|
31
|
-
data: { id: dataId },
|
|
32
|
-
sequence,
|
|
33
|
-
recovery: { kind: name === FRAGMENT_NAMES.agentNote ? 'AGENT_NOTE' : 'LOG_ENTRY', organizationId: 'org1' },
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/* Isolate global transport/cache state while exercising the real no-store GraphQL request path. */
|
|
40
|
-
async function withRecoveryTest(run: () => Promise<void>) {
|
|
41
|
-
const originalFetch = globalThis.fetch;
|
|
42
|
-
registerENV({ GQL_SERVER: 'https://graphql.test/recovery', IS_BROWSER: '' });
|
|
43
|
-
clearFragmentRecoveryRequests();
|
|
44
|
-
clearGraphQLClientCache();
|
|
45
|
-
clearFragmentRealtimeSequences();
|
|
46
|
-
try {
|
|
47
|
-
await run();
|
|
48
|
-
} finally {
|
|
49
|
-
globalThis.fetch = originalFetch;
|
|
50
|
-
clearFragmentRecoveryRequests();
|
|
51
|
-
clearGraphQLClientCache();
|
|
52
|
-
clearFragmentRealtimeSequences();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/* Provide a manually settled fetch for deterministic interleaving of websocket and HTTP activity. */
|
|
57
|
-
function deferredResponse() {
|
|
58
|
-
let resolve!: (value: Response) => void;
|
|
59
|
-
const promise = new Promise<Response>((settle) => {
|
|
60
|
-
resolve = settle;
|
|
61
|
-
});
|
|
62
|
-
return { promise, resolve: (data: any) => resolve(Response.json({ data })) };
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/* Let the request pipeline dispatch without introducing wall-clock sleeps. */
|
|
66
|
-
async function flushRequests() {
|
|
67
|
-
for (let index = 0; index < 10; index += 1) await Promise.resolve();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
Deno.test('oversized note recovery uses its detail contract without normalizing unrelated data', () =>
|
|
71
|
-
withRecoveryTest(async () => {
|
|
72
|
-
let variables: any;
|
|
73
|
-
globalThis.fetch = (_input, init) => {
|
|
74
|
-
variables = JSON.parse(String(init?.body)).variables;
|
|
75
|
-
return Promise.resolve(
|
|
76
|
-
Response.json({
|
|
77
|
-
data: {
|
|
78
|
-
agentNote: {
|
|
79
|
-
id: 'n1',
|
|
80
|
-
organizationId: 'org1',
|
|
81
|
-
headline: 'Recovered',
|
|
82
|
-
body: 'Body',
|
|
83
|
-
links: [{ entityType: 'LOG', entityId: 'l1', unselected: 'private' }],
|
|
84
|
-
unselected: 'private',
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
}),
|
|
88
|
-
);
|
|
89
|
-
};
|
|
90
|
-
const result = await resolveFragmentRecoveryUpdate(marker());
|
|
91
|
-
assert.deepEqual(variables, { organizationId: 'org1', agentNoteId: 'n1' });
|
|
92
|
-
assert.equal(result?.update.fragments?.[0]?.recovery, undefined);
|
|
93
|
-
assert.equal(result?.update.fragments?.[0]?.data.body, 'Body');
|
|
94
|
-
assert.equal(result?.update.fragments?.[0]?.data.unselected, undefined);
|
|
95
|
-
assert.equal(result?.update.fragments?.[0]?.data.links[0].unselected, undefined);
|
|
96
|
-
assert.equal(loadFragment(`${FRAGMENT_NAMES.agentNote}:n1`), null);
|
|
97
|
-
assert.equal(loadQuery('#agentNote:'), null);
|
|
98
|
-
}));
|
|
99
|
-
|
|
100
|
-
Deno.test('log core and details share one read and retain only their selected projections', () =>
|
|
101
|
-
withRecoveryTest(async () => {
|
|
102
|
-
let reads = 0;
|
|
103
|
-
globalThis.fetch = () => {
|
|
104
|
-
reads += 1;
|
|
105
|
-
return Promise.resolve(
|
|
106
|
-
Response.json({
|
|
107
|
-
data: {
|
|
108
|
-
logEntry: {
|
|
109
|
-
id: 'l1',
|
|
110
|
-
summary: 'Recovered',
|
|
111
|
-
details: { id: 'l1', notes: 'Details', secret: 'omit' },
|
|
112
|
-
account: { id: 'a1' },
|
|
113
|
-
files: [],
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
}),
|
|
117
|
-
);
|
|
118
|
-
};
|
|
119
|
-
const update = marker(FRAGMENT_NAMES.logEntry, 'l1');
|
|
120
|
-
update.fragments!.push(marker(FRAGMENT_NAMES.logEntryDetails, 'l1').fragments![0]);
|
|
121
|
-
const result = await resolveFragmentRecoveryUpdate(update);
|
|
122
|
-
assert.equal(reads, 1);
|
|
123
|
-
assert.deepEqual(result?.update.fragments?.[0]?.data, { id: 'l1', summary: 'Recovered' });
|
|
124
|
-
assert.deepEqual(result?.update.fragments?.[1]?.data, { id: 'l1', notes: 'Details' });
|
|
125
|
-
}));
|
|
126
|
-
|
|
127
|
-
Deno.test('stale markers make no HTTP read and retain reset controls', () =>
|
|
128
|
-
withRecoveryTest(async () => {
|
|
129
|
-
let reads = 0;
|
|
130
|
-
globalThis.fetch = () => {
|
|
131
|
-
reads += 1;
|
|
132
|
-
throw new Error('Unexpected read');
|
|
133
|
-
};
|
|
134
|
-
shouldApplyFragmentRealtimeSequence(`${FRAGMENT_NAMES.agentNote}:n1`, '20');
|
|
135
|
-
const update = {
|
|
136
|
-
...marker(),
|
|
137
|
-
resetQueryRule: 'ALWAYS' as const,
|
|
138
|
-
resetQueries: [{ name: 'agentNotes', match: { organizationId: 'org1' } }],
|
|
139
|
-
};
|
|
140
|
-
const result = await resolveFragmentRecoveryUpdate(update);
|
|
141
|
-
assert.equal(reads, 0);
|
|
142
|
-
assert.deepEqual(result?.update, update);
|
|
143
|
-
}));
|
|
144
|
-
|
|
145
|
-
Deno.test('ordinary partial writes during a read retry the authoritative target', () =>
|
|
146
|
-
withRecoveryTest(async () => {
|
|
147
|
-
const first = deferredResponse();
|
|
148
|
-
let reads = 0;
|
|
149
|
-
globalThis.fetch = () =>
|
|
150
|
-
++reads === 1
|
|
151
|
-
? first.promise
|
|
152
|
-
: Promise.resolve(Response.json({ data: { agentNote: { id: 'n1', headline: 'Latest', body: 'Fresh body' } } }));
|
|
153
|
-
const pending = resolveFragmentRecoveryUpdate(marker());
|
|
154
|
-
await flushRequests();
|
|
155
|
-
addFragmentToCache(`${FRAGMENT_NAMES.agentNote}:n1`, { id: 'n1', headline: 'Latest' });
|
|
156
|
-
noteFragmentRealtimeUpdate({ name: FRAGMENT_NAMES.agentNote, dataId: 'n1', data: { headline: 'Latest' } });
|
|
157
|
-
first.resolve({ agentNote: { id: 'n1', headline: 'Old', body: 'Old body' } });
|
|
158
|
-
const result = await pending;
|
|
159
|
-
assert.equal(reads, 2);
|
|
160
|
-
assert.equal(result?.update.fragments?.[0]?.data.body, 'Fresh body');
|
|
161
|
-
}));
|
|
162
|
-
|
|
163
|
-
Deno.test('a deleted log parent prevents its pending details recovery from resurrecting content', () =>
|
|
164
|
-
withRecoveryTest(async () => {
|
|
165
|
-
const response = deferredResponse();
|
|
166
|
-
let reads = 0;
|
|
167
|
-
globalThis.fetch = () => {
|
|
168
|
-
reads += 1;
|
|
169
|
-
return response.promise;
|
|
170
|
-
};
|
|
171
|
-
const pending = resolveFragmentRecoveryUpdate(marker(FRAGMENT_NAMES.logEntryDetails, 'l1'));
|
|
172
|
-
await flushRequests();
|
|
173
|
-
addFragmentToCache(`${FRAGMENT_NAMES.logEntry}:l1`, { id: 'l1', __deleted: true });
|
|
174
|
-
noteFragmentRealtimeUpdate({ name: FRAGMENT_NAMES.logEntry, dataId: 'l1', data: { __deleted: true } });
|
|
175
|
-
response.resolve({ logEntry: { id: 'l1', details: { id: 'l1', notes: 'Deleted content' } } });
|
|
176
|
-
const result = await pending;
|
|
177
|
-
assert.equal(reads, 1);
|
|
178
|
-
assert.ok(result?.update.fragments?.[0]?.recovery);
|
|
179
|
-
}));
|
|
180
|
-
|
|
181
|
-
Deno.test('cache clearing without a sequence reset rejects an old private HTTP response', () =>
|
|
182
|
-
withRecoveryTest(async () => {
|
|
183
|
-
const response = deferredResponse();
|
|
184
|
-
globalThis.fetch = () => response.promise;
|
|
185
|
-
const pending = resolveFragmentRecoveryUpdate(marker());
|
|
186
|
-
await flushRequests();
|
|
187
|
-
clearGraphQLClientCache();
|
|
188
|
-
response.resolve({ agentNote: { id: 'n1', body: 'Old scope' } });
|
|
189
|
-
assert.equal(await pending, null);
|
|
190
|
-
}));
|
|
191
|
-
|
|
192
|
-
Deno.test('a delayed older marker cannot take ownership from a higher in-flight revision', () =>
|
|
193
|
-
withRecoveryTest(async () => {
|
|
194
|
-
const response = deferredResponse();
|
|
195
|
-
let reads = 0;
|
|
196
|
-
globalThis.fetch = () => {
|
|
197
|
-
reads += 1;
|
|
198
|
-
return response.promise;
|
|
199
|
-
};
|
|
200
|
-
const newer = resolveFragmentRecoveryUpdate(marker(FRAGMENT_NAMES.agentNote, 'n1', '20'));
|
|
201
|
-
await flushRequests();
|
|
202
|
-
const older = resolveFragmentRecoveryUpdate(marker(FRAGMENT_NAMES.agentNote, 'n1', '10'));
|
|
203
|
-
response.resolve({ agentNote: { id: 'n1', body: 'Latest' } });
|
|
204
|
-
const [latest, obsolete] = await Promise.all([newer, older]);
|
|
205
|
-
assert.equal(reads, 1);
|
|
206
|
-
assert.equal(latest?.update.fragments?.[0]?.recovery, undefined);
|
|
207
|
-
assert.equal(latest?.update.fragments?.[0]?.sequence, '20');
|
|
208
|
-
assert.ok(obsolete?.update.fragments?.[0]?.recovery);
|
|
209
|
-
}));
|
|
210
|
-
|
|
211
|
-
Deno.test('a reused outbox id with a newer revision forces a fresh read', () =>
|
|
212
|
-
withRecoveryTest(async () => {
|
|
213
|
-
const response = deferredResponse();
|
|
214
|
-
let reads = 0;
|
|
215
|
-
globalThis.fetch = () =>
|
|
216
|
-
++reads === 1 ? response.promise : Promise.resolve(Response.json({ data: { agentNote: { id: 'n1', body: 'Revision 20' } } }));
|
|
217
|
-
const first = { ...marker(FRAGMENT_NAMES.agentNote, 'n1', '10'), id: 'outbox1' };
|
|
218
|
-
const pendingFirst = resolveFragmentRecoveryUpdate(first);
|
|
219
|
-
await flushRequests();
|
|
220
|
-
const second = { ...marker(FRAGMENT_NAMES.agentNote, 'n1', '20'), id: 'outbox1' };
|
|
221
|
-
const pendingSecond = resolveFragmentRecoveryUpdate(second);
|
|
222
|
-
response.resolve({ agentNote: { id: 'n1', body: 'Revision 10' } });
|
|
223
|
-
const [old, latest] = await Promise.all([pendingFirst, pendingSecond]);
|
|
224
|
-
assert.equal(reads, 2);
|
|
225
|
-
assert.ok(old?.update.fragments?.[0]?.recovery);
|
|
226
|
-
assert.equal(latest?.update.fragments?.[0]?.data.body, 'Revision 20');
|
|
227
|
-
}));
|
|
228
|
-
|
|
229
|
-
Deno.test('fast recovered data is revalidated after a slower sibling completes', () =>
|
|
230
|
-
withRecoveryTest(async () => {
|
|
231
|
-
const slow = deferredResponse();
|
|
232
|
-
let firstReads = 0;
|
|
233
|
-
globalThis.fetch = (_input, init) => {
|
|
234
|
-
const id = JSON.parse(String(init?.body)).variables.logEntryId;
|
|
235
|
-
if (id === 'l2') return slow.promise;
|
|
236
|
-
firstReads += 1;
|
|
237
|
-
return Promise.resolve(Response.json({ data: { logEntry: { id: 'l1', summary: firstReads === 1 ? 'Old' : 'Latest' } } }));
|
|
238
|
-
};
|
|
239
|
-
const update = marker(FRAGMENT_NAMES.logEntry, 'l1');
|
|
240
|
-
update.fragments!.push(marker(FRAGMENT_NAMES.logEntry, 'l2').fragments![0]);
|
|
241
|
-
const pending = resolveFragmentRecoveryUpdate(update);
|
|
242
|
-
await flushRequests();
|
|
243
|
-
addFragmentToCache(`${FRAGMENT_NAMES.logEntry}:l1`, { id: 'l1', summary: 'Latest' });
|
|
244
|
-
noteFragmentRealtimeUpdate({ name: FRAGMENT_NAMES.logEntry, dataId: 'l1', data: { summary: 'Latest' } });
|
|
245
|
-
slow.resolve({ logEntry: { id: 'l2', summary: 'Second' } });
|
|
246
|
-
const result = await pending;
|
|
247
|
-
assert.equal(firstReads, 2);
|
|
248
|
-
assert.equal(result?.update.fragments?.[0]?.data.summary, 'Latest');
|
|
249
|
-
}));
|
|
250
|
-
|
|
251
|
-
Deno.test('denied or missing reads retain the marker and cached value without inventing deletion', () =>
|
|
252
|
-
withRecoveryTest(async () => {
|
|
253
|
-
addFragmentToCache(`${FRAGMENT_NAMES.agentNote}:n1`, { id: 'n1', body: 'Retained' });
|
|
254
|
-
let reads = 0;
|
|
255
|
-
globalThis.fetch = () => {
|
|
256
|
-
reads += 1;
|
|
257
|
-
return Promise.resolve(
|
|
258
|
-
Response.json({
|
|
259
|
-
data: { agentNote: null },
|
|
260
|
-
errors: [{ errorCode: 20232, statusCode: 404, message: '20232', path: ['agentNote'] }],
|
|
261
|
-
}),
|
|
262
|
-
);
|
|
263
|
-
};
|
|
264
|
-
const result = await resolveFragmentRecoveryUpdate(marker());
|
|
265
|
-
assert.equal(reads, 1);
|
|
266
|
-
assert.ok(result?.update.fragments?.[0]?.recovery);
|
|
267
|
-
assert.equal(loadFragment(`${FRAGMENT_NAMES.agentNote}:n1`)?.body, 'Retained');
|
|
268
|
-
}));
|
|
269
|
-
|
|
270
|
-
Deno.test('a no-op websocket write after a fast read still invalidates it while a sibling is pending', () =>
|
|
271
|
-
withRecoveryTest(async () => {
|
|
272
|
-
const slow = deferredResponse();
|
|
273
|
-
addFragmentToCache(`${FRAGMENT_NAMES.logEntry}:l1`, { id: 'l1', summary: 'Same' });
|
|
274
|
-
let reads = 0;
|
|
275
|
-
globalThis.fetch = (_input, init) => {
|
|
276
|
-
if (JSON.parse(String(init?.body)).variables.logEntryId === 'l2') return slow.promise;
|
|
277
|
-
reads += 1;
|
|
278
|
-
return Promise.resolve(Response.json({ data: { logEntry: { id: 'l1', summary: reads === 1 ? 'Old snapshot' : 'Same' } } }));
|
|
279
|
-
};
|
|
280
|
-
const update = marker(FRAGMENT_NAMES.logEntry, 'l1');
|
|
281
|
-
update.fragments!.push(marker(FRAGMENT_NAMES.logEntry, 'l2').fragments![0]);
|
|
282
|
-
const pending = resolveFragmentRecoveryUpdate(update);
|
|
283
|
-
for (let index = 0; index < 5; index += 1) await flushRequests();
|
|
284
|
-
noteFragmentRealtimeUpdate({ name: FRAGMENT_NAMES.logEntry, dataId: 'l1', data: { summary: 'Same' } });
|
|
285
|
-
slow.resolve({ logEntry: { id: 'l2', summary: 'Second' } });
|
|
286
|
-
const result = await pending;
|
|
287
|
-
assert.equal(reads, 2);
|
|
288
|
-
assert.equal(result?.update.fragments?.[0]?.data.summary, 'Same');
|
|
289
|
-
}));
|
|
290
|
-
|
|
291
|
-
Deno.test('switching authenticated sessions rejects a pending recovery before application', () =>
|
|
292
|
-
withRecoveryTest(async () => {
|
|
293
|
-
registerENV({ IS_BROWSER: 'true' });
|
|
294
|
-
setAuthToken('first-session');
|
|
295
|
-
try {
|
|
296
|
-
const response = deferredResponse();
|
|
297
|
-
globalThis.fetch = () => response.promise;
|
|
298
|
-
const pending = resolveFragmentRecoveryUpdate(marker());
|
|
299
|
-
await flushRequests();
|
|
300
|
-
setAuthToken('second-session');
|
|
301
|
-
response.resolve({ agentNote: { id: 'n1', body: 'Prior session' } });
|
|
302
|
-
assert.equal(await pending, null);
|
|
303
|
-
} finally {
|
|
304
|
-
setAuthToken(null);
|
|
305
|
-
registerENV({ IS_BROWSER: '' });
|
|
306
|
-
}
|
|
307
|
-
}));
|
|
308
|
-
|
|
309
|
-
Deno.test('explicit recovery cancellation cannot restart old work after a slower sibling returns', () =>
|
|
310
|
-
withRecoveryTest(async () => {
|
|
311
|
-
const slow = deferredResponse();
|
|
312
|
-
let reads = 0;
|
|
313
|
-
globalThis.fetch = (_input, init) => {
|
|
314
|
-
reads += 1;
|
|
315
|
-
if (JSON.parse(String(init?.body)).variables.logEntryId === 'l2') return slow.promise;
|
|
316
|
-
return Promise.resolve(Response.json({ data: { logEntry: { id: 'l1', summary: 'Old scope' } } }));
|
|
317
|
-
};
|
|
318
|
-
const update = marker(FRAGMENT_NAMES.logEntry, 'l1');
|
|
319
|
-
update.fragments!.push(marker(FRAGMENT_NAMES.logEntry, 'l2').fragments![0]);
|
|
320
|
-
const pending = resolveFragmentRecoveryUpdate(update);
|
|
321
|
-
for (let index = 0; index < 5; index += 1) await flushRequests();
|
|
322
|
-
clearFragmentRecoveryRequests();
|
|
323
|
-
slow.resolve({ logEntry: { id: 'l2', summary: 'Old scope' } });
|
|
324
|
-
assert.equal(await pending, null);
|
|
325
|
-
assert.equal(reads, 2);
|
|
326
|
-
}));
|