@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
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const FRAGMENT_REALTIME_SEQUENCES = new Map<string, string>();
|
|
2
|
+
let fragmentRealtimeEpoch = 0;
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Compare two unsigned decimal sequence strings without narrowing them to
|
|
6
|
+
* JavaScript's unsafe integer range.
|
|
7
|
+
*/
|
|
8
|
+
function compareFragmentRealtimeSequences(left: string, right: string) {
|
|
9
|
+
const normalizedLeft = left.replace(/^0+(?=\d)/, '');
|
|
10
|
+
const normalizedRight = right.replace(/^0+(?=\d)/, '');
|
|
11
|
+
|
|
12
|
+
if (normalizedLeft.length !== normalizedRight.length) {
|
|
13
|
+
return normalizedLeft.length > normalizedRight.length ? 1 : -1;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return normalizedLeft === normalizedRight ? 0 : normalizedLeft > normalizedRight ? 1 : -1;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/*
|
|
20
|
+
* Check ordering without advancing the fence while an oversized fragment is
|
|
21
|
+
* still being recovered through an authorized single-record read.
|
|
22
|
+
*/
|
|
23
|
+
export function isFragmentRealtimeSequenceCurrent(fragmentKey: string, sequence?: string) {
|
|
24
|
+
if (!sequence || !/^\d+$/.test(sequence)) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const currentSequence = FRAGMENT_REALTIME_SEQUENCES.get(fragmentKey);
|
|
29
|
+
if (currentSequence && compareFragmentRealtimeSequences(sequence, currentSequence) < 0) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/* Accept an update and advance its sequence only when its data can be applied. */
|
|
37
|
+
export function shouldApplyFragmentRealtimeSequence(fragmentKey: string, sequence?: string) {
|
|
38
|
+
if (!isFragmentRealtimeSequenceCurrent(fragmentKey, sequence)) return false;
|
|
39
|
+
if (sequence && /^\d+$/.test(sequence)) FRAGMENT_REALTIME_SEQUENCES.set(fragmentKey, sequence);
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* Bind asynchronous fragment recovery to the current authorization/cache lifetime. */
|
|
44
|
+
export function getFragmentRealtimeEpoch() {
|
|
45
|
+
return fragmentRealtimeEpoch;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/*
|
|
49
|
+
* Clear fragment sequence fences when authorization-bound cache state is
|
|
50
|
+
* discarded.
|
|
51
|
+
*/
|
|
52
|
+
export function clearFragmentRealtimeSequences() {
|
|
53
|
+
fragmentRealtimeEpoch += 1;
|
|
54
|
+
FRAGMENT_REALTIME_SEQUENCES.clear();
|
|
55
|
+
}
|
|
@@ -0,0 +1,326 @@
|
|
|
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
|
+
}));
|