mirror of
https://github.com/wekan/wekan.git
synced 2026-11-07 02:52:33 -05:00
Await private intent persistence before the activity insert, preserve scoped Sync deferral, and retain pending evidence until all recipient subscribers acknowledge local writes. Compact successful intents while preserving dispatch identity; keep webhook delivery independent. Validated with six MongoDB cases, three Node suites, three full-app Meteor cases and ten Chromium email delivery and private-storage scenarios. Automatic pending-intent recovery remains unfinished. Thanks to xet7.
18 lines
804 B
JavaScript
18 lines
804 B
JavaScript
'use strict';
|
|
const { AsyncLocalStorage } = require('node:async_hooks');
|
|
const { canonical } = require('../../models/lib/changeHistoryIntegrity');
|
|
const storage = new AsyncLocalStorage();
|
|
async function withSyncActivityDeferred(activity, work) {
|
|
const scope = { expected: canonical(activity), slots: new Set(['timestamps', 'notificationIntent', 'rules', 'notifications']), active: true };
|
|
return storage.run(scope, async () => {
|
|
try { return await work(); } finally { scope.active = false; }
|
|
});
|
|
}
|
|
function deferSyncActivity(kind, activity) {
|
|
const scope = storage.getStore();
|
|
if (!scope?.active || !scope.slots.has(kind) || canonical(activity) !== scope.expected) return false;
|
|
scope.slots.delete(kind);
|
|
return true;
|
|
}
|
|
module.exports = { withSyncActivityDeferred, deferSyncActivity };
|