@powerhousedao/reactor-api 6.0.0-dev.226 → 6.0.0-dev.227
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/dist/index.mjs +54 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -11
package/dist/index.mjs
CHANGED
|
@@ -32,7 +32,7 @@ import { typeDefs } from "@powerhousedao/document-engineering/graphql";
|
|
|
32
32
|
import { camelCase, kebabCase, pascalCase } from "change-case";
|
|
33
33
|
import { GraphQLJSONObject } from "graphql-type-json";
|
|
34
34
|
import { setName } from "@powerhousedao/shared/document-model";
|
|
35
|
-
import { PropagationMode as PropagationMode$1, consolidateSyncOperations, driveIdFromUrl, envelopesToSyncOperations, parseDriveUrl,
|
|
35
|
+
import { PropagationMode as PropagationMode$1, consolidateSyncOperations, driveIdFromUrl, envelopesToSyncOperations, parseDriveUrl, trimMailboxFromAckOrdinal } from "@powerhousedao/reactor";
|
|
36
36
|
import * as z$1 from "zod";
|
|
37
37
|
import { z } from "zod";
|
|
38
38
|
import { createHandler } from "graphql-sse/lib/use/fetch";
|
|
@@ -2731,9 +2731,6 @@ function matchesJobFilter(payload, args) {
|
|
|
2731
2731
|
* the drive-ownership cache tracks on each switchboard instance.
|
|
2732
2732
|
*/
|
|
2733
2733
|
const DRIVE_DOCUMENT_TYPE = "powerhouse/document-drive";
|
|
2734
|
-
//#endregion
|
|
2735
|
-
//#region src/graphql/reactor/resolvers.ts
|
|
2736
|
-
const POLL_SYNC_ENVELOPES_MAX_LIMIT = 100;
|
|
2737
2734
|
async function documentModels(reactorClient, args) {
|
|
2738
2735
|
const namespace = fromInputMaybe(args.namespace);
|
|
2739
2736
|
let paging;
|
|
@@ -3201,29 +3198,61 @@ function pollSyncEnvelopes(syncManager, args) {
|
|
|
3201
3198
|
const sorted = [...operations].sort((a, b) => {
|
|
3202
3199
|
return (a.operations[0]?.context.ordinal ?? 0) - (b.operations[0]?.context.ordinal ?? 0);
|
|
3203
3200
|
});
|
|
3204
|
-
const
|
|
3205
|
-
|
|
3201
|
+
const envelopes = [];
|
|
3202
|
+
let pageOps = 0;
|
|
3203
|
+
let hasMore = false;
|
|
3206
3204
|
let maxOrdinal = args.outboxLatest;
|
|
3207
|
-
for (const syncOp of
|
|
3208
|
-
|
|
3209
|
-
|
|
3205
|
+
outer: for (const syncOp of sorted) {
|
|
3206
|
+
if (pageOps >= 100) {
|
|
3207
|
+
hasMore = true;
|
|
3208
|
+
break;
|
|
3209
|
+
}
|
|
3210
|
+
const unseen = syncOp.operations.filter((op) => op.context.ordinal > args.outboxLatest);
|
|
3211
|
+
if (unseen.length === 0) continue;
|
|
3212
|
+
let prevPartKey;
|
|
3213
|
+
let partIdx = 0;
|
|
3214
|
+
let i = 0;
|
|
3215
|
+
while (i < unseen.length) {
|
|
3216
|
+
if (pageOps >= 100) {
|
|
3217
|
+
hasMore = true;
|
|
3218
|
+
break outer;
|
|
3219
|
+
}
|
|
3220
|
+
const remainingPage = 100 - pageOps;
|
|
3221
|
+
const chunkSize = Math.max(1, Math.min(25, remainingPage, unseen.length - i));
|
|
3222
|
+
const slice = unseen.slice(i, i + chunkSize);
|
|
3223
|
+
const isOnly = unseen.length <= 25 && unseen.length <= remainingPage;
|
|
3224
|
+
const baseKey = syncOp.jobId || void 0;
|
|
3225
|
+
const partKey = isOnly ? baseKey : baseKey ? `${baseKey}__p${partIdx}` : void 0;
|
|
3226
|
+
const partDeps = partIdx === 0 ? syncOp.jobDependencies.filter(Boolean) : prevPartKey ? [prevPartKey] : [];
|
|
3227
|
+
for (const op of slice) if (op.context.ordinal > maxOrdinal) maxOrdinal = op.context.ordinal;
|
|
3228
|
+
envelopes.push({
|
|
3229
|
+
type: "OPERATIONS",
|
|
3230
|
+
channelMeta: { id: args.channelId },
|
|
3231
|
+
operations: slice.map((op) => ({
|
|
3232
|
+
operation: serializeOperationForGraphQL(op.operation),
|
|
3233
|
+
context: op.context
|
|
3234
|
+
})),
|
|
3235
|
+
cursor: {
|
|
3236
|
+
remoteName: remote.name,
|
|
3237
|
+
cursorOrdinal: 0,
|
|
3238
|
+
lastSyncedAtUtcMs: Date.now().toString()
|
|
3239
|
+
},
|
|
3240
|
+
key: partKey,
|
|
3241
|
+
dependsOn: partDeps.length > 0 ? partDeps : void 0
|
|
3242
|
+
});
|
|
3243
|
+
pageOps += slice.length;
|
|
3244
|
+
i += slice.length;
|
|
3245
|
+
prevPartKey = partKey;
|
|
3246
|
+
partIdx++;
|
|
3247
|
+
if (i < unseen.length && pageOps >= 100) {
|
|
3248
|
+
hasMore = true;
|
|
3249
|
+
break outer;
|
|
3250
|
+
}
|
|
3251
|
+
}
|
|
3210
3252
|
}
|
|
3253
|
+
for (const envelope of envelopes) if (envelope.cursor) envelope.cursor.cursorOrdinal = maxOrdinal;
|
|
3211
3254
|
return {
|
|
3212
|
-
envelopes
|
|
3213
|
-
type: "OPERATIONS",
|
|
3214
|
-
channelMeta: { id: args.channelId },
|
|
3215
|
-
operations: syncOp.operations.map((op) => ({
|
|
3216
|
-
operation: serializeOperationForGraphQL(op.operation),
|
|
3217
|
-
context: op.context
|
|
3218
|
-
})),
|
|
3219
|
-
cursor: {
|
|
3220
|
-
remoteName: remote.name,
|
|
3221
|
-
cursorOrdinal: maxOrdinal,
|
|
3222
|
-
lastSyncedAtUtcMs: Date.now().toString()
|
|
3223
|
-
},
|
|
3224
|
-
key: syncOp.jobId || void 0,
|
|
3225
|
-
dependsOn: syncOp.jobDependencies.filter(Boolean).length > 0 ? syncOp.jobDependencies.filter(Boolean) : void 0
|
|
3226
|
-
}))),
|
|
3255
|
+
envelopes,
|
|
3227
3256
|
ackOrdinal: remote.channel.inbox.ackOrdinal,
|
|
3228
3257
|
deadLetters,
|
|
3229
3258
|
hasMore
|
|
@@ -3238,9 +3267,8 @@ function pollSyncEnvelopes(syncManager, args) {
|
|
|
3238
3267
|
* and returns the highest one as `ackOrdinal` in pollSyncEnvelopes.
|
|
3239
3268
|
*/
|
|
3240
3269
|
function pushSyncEnvelopes(syncManager, args) {
|
|
3241
|
-
const sortedEnvelopes = sortEnvelopesByFirstOperationTimestamp(args.envelopes);
|
|
3242
3270
|
const remoteSyncOps = /* @__PURE__ */ new Map();
|
|
3243
|
-
for (const envelope of
|
|
3271
|
+
for (const envelope of args.envelopes) {
|
|
3244
3272
|
let remote;
|
|
3245
3273
|
try {
|
|
3246
3274
|
remote = syncManager.getById(envelope.channelMeta.id);
|