@powerhousedao/reactor-api 6.0.0-dev.235 → 6.0.0-dev.236

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 CHANGED
@@ -31,7 +31,7 @@ import { typeDefs } from "@powerhousedao/document-engineering/graphql";
31
31
  import { camelCase, kebabCase, pascalCase } from "change-case";
32
32
  import { GraphQLJSONObject } from "graphql-type-json";
33
33
  import { setName } from "@powerhousedao/shared/document-model";
34
- import { PropagationMode as PropagationMode$1, consolidateSyncOperations, driveIdFromUrl, envelopesToSyncOperations, parseDriveUrl, trimMailboxFromAckOrdinal } from "@powerhousedao/reactor";
34
+ import { PropagationMode as PropagationMode$1, consolidateSyncOperations, driveIdFromUrl, envelopesToSyncOperations, parseDriveUrl } from "@powerhousedao/reactor";
35
35
  import * as z$1 from "zod";
36
36
  import { z } from "zod";
37
37
  import { createHandler } from "graphql-sse/lib/use/fetch";
@@ -3184,14 +3184,22 @@ function pollSyncEnvelopes(syncManager, args) {
3184
3184
  scopes: syncOp.scopes,
3185
3185
  operationCount: syncOp.operations.length
3186
3186
  }));
3187
- if (args.outboxAck > 0) trimMailboxFromAckOrdinal(remote.channel.outbox, args.outboxAck);
3188
- let operations = remote.channel.outbox.items;
3189
- operations = operations.filter((syncOp) => {
3190
- let maxOrdinal = 0;
3191
- for (const op of syncOp.operations) maxOrdinal = Math.max(maxOrdinal, op.context.ordinal);
3192
- if (maxOrdinal > args.outboxLatest) return true;
3193
- return false;
3194
- });
3187
+ if (args.outboxAck > 0) {
3188
+ const ackOrdinal = args.outboxAck;
3189
+ const outbox = remote.channel.outbox;
3190
+ const toRemove = [];
3191
+ for (const syncOp of outbox.items) {
3192
+ if (!((syncOp.emittedCount ?? 0) >= syncOp.operations.length)) continue;
3193
+ let maxOrdinal = 0;
3194
+ for (const op of syncOp.operations) if (op.context.ordinal > maxOrdinal) maxOrdinal = op.context.ordinal;
3195
+ if (maxOrdinal <= ackOrdinal) toRemove.push(syncOp);
3196
+ }
3197
+ if (toRemove.length > 0) {
3198
+ for (const syncOp of toRemove) syncOp.executed();
3199
+ outbox.remove(...toRemove);
3200
+ }
3201
+ }
3202
+ const operations = remote.channel.outbox.items;
3195
3203
  if (operations.length === 0) return {
3196
3204
  envelopes: [],
3197
3205
  ackOrdinal: remote.channel.inbox.ackOrdinal,
@@ -3210,20 +3218,23 @@ function pollSyncEnvelopes(syncManager, args) {
3210
3218
  hasMore = true;
3211
3219
  break;
3212
3220
  }
3213
- const unseen = syncOp.operations.filter((op) => op.context.ordinal > args.outboxLatest);
3214
- if (unseen.length === 0) continue;
3221
+ syncOp.deliveredCount ??= 0;
3222
+ syncOp.emittedCount ??= 0;
3223
+ while (syncOp.deliveredCount < syncOp.emittedCount && syncOp.operations[syncOp.deliveredCount].context.ordinal <= args.outboxLatest) syncOp.deliveredCount += 1;
3224
+ const remaining = syncOp.operations.slice(syncOp.deliveredCount);
3225
+ if (remaining.length === 0) continue;
3215
3226
  let prevPartKey;
3216
3227
  let partIdx = 0;
3217
3228
  let i = 0;
3218
- while (i < unseen.length) {
3229
+ while (i < remaining.length) {
3219
3230
  if (pageOps >= 100) {
3220
3231
  hasMore = true;
3221
3232
  break outer;
3222
3233
  }
3223
3234
  const remainingPage = 100 - pageOps;
3224
- const chunkSize = Math.max(1, Math.min(25, remainingPage, unseen.length - i));
3225
- const slice = unseen.slice(i, i + chunkSize);
3226
- const isOnly = unseen.length <= 25 && unseen.length <= remainingPage;
3235
+ const chunkSize = Math.max(1, Math.min(25, remainingPage, remaining.length - i));
3236
+ const slice = remaining.slice(i, i + chunkSize);
3237
+ const isOnly = remaining.length <= 25 && remaining.length <= remainingPage;
3227
3238
  const baseKey = syncOp.jobId || void 0;
3228
3239
  const partKey = isOnly ? baseKey : baseKey ? `${baseKey}__p${partIdx}` : void 0;
3229
3240
  const partDeps = partIdx === 0 ? syncOp.jobDependencies.filter(Boolean) : prevPartKey ? [prevPartKey] : [];
@@ -3247,7 +3258,9 @@ function pollSyncEnvelopes(syncManager, args) {
3247
3258
  i += slice.length;
3248
3259
  prevPartKey = partKey;
3249
3260
  partIdx++;
3250
- if (i < unseen.length && pageOps >= 100) {
3261
+ const emittedThrough = syncOp.deliveredCount + i;
3262
+ if (emittedThrough > syncOp.emittedCount) syncOp.emittedCount = emittedThrough;
3263
+ if (i < remaining.length && pageOps >= 100) {
3251
3264
  hasMore = true;
3252
3265
  break outer;
3253
3266
  }
@@ -4900,10 +4913,10 @@ const ADMIN_USERS = getAdminUsers();
4900
4913
  //#endregion
4901
4914
  //#region src/graphql/system/version.ts
4902
4915
  function getVersion() {
4903
- return "6.0.0-dev.235";
4916
+ return "6.0.0-dev.236";
4904
4917
  }
4905
4918
  function getGitHash() {
4906
- return "19586d46c40853beb2c2c88e7991f7734804b94b";
4919
+ return "839d5949da4a0211c001b057c9cc1012ea149d7b";
4907
4920
  }
4908
4921
  function getGitUrl() {
4909
4922
  return buildTreeUrl(getGitHash());