@powerhousedao/reactor 6.0.0-dev.216 → 6.0.0-dev.218

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.js CHANGED
@@ -1691,17 +1691,21 @@ var KyselyOperationIndex = class KyselyOperationIndex {
1691
1691
  }
1692
1692
  async find(collectionId, cursor, view, paging, signal) {
1693
1693
  if (signal?.aborted) throw new Error("Operation aborted");
1694
- let query = this.queryExecutor.selectFrom("operation_index_operations as oi").innerJoin("document_collections as dc", "oi.documentId", "dc.documentId").selectAll("oi").select(["dc.documentId", "dc.collectionId"]).where("dc.collectionId", "=", collectionId).where(sql`(dc."leftOrdinal" IS NULL OR oi.ordinal < dc."leftOrdinal")`).orderBy("oi.ordinal", "asc");
1695
- if (cursor !== void 0) query = query.where("oi.ordinal", ">", cursor);
1696
- if (view?.branch) query = query.where("oi.branch", "=", view.branch);
1697
- if (view?.scopes && view.scopes.length > 0) query = query.where("oi.scope", "in", view.scopes);
1698
- if (view?.excludeSourceRemote) query = query.where("oi.sourceRemote", "!=", view.excludeSourceRemote);
1699
- if (paging?.cursor) {
1700
- const cursorOrdinal = Number.parseInt(paging.cursor, 10);
1701
- query = query.where("oi.ordinal", ">", cursorOrdinal);
1702
- }
1703
- if (paging?.limit) query = query.limit(paging.limit + 1);
1704
- const rows = await query.execute();
1694
+ const outerCursor = cursor ?? -1;
1695
+ const pagingCursorOrdinal = paging?.cursor !== void 0 ? Number.parseInt(paging.cursor, 10) : -1;
1696
+ const buildBranch = (kind) => {
1697
+ let qb = this.queryExecutor.selectFrom("operation_index_operations as oi").innerJoin("document_collections as dc", "oi.documentId", "dc.documentId").selectAll("oi").select(["dc.documentId", "dc.collectionId"]).where("dc.collectionId", "=", collectionId).where(sql`(dc."leftOrdinal" IS NULL OR oi.ordinal < dc."leftOrdinal")`);
1698
+ if (kind === "joiner") qb = qb.where("dc.joinedOrdinal", ">", BigInt(outerCursor)).where("oi.ordinal", "<=", outerCursor);
1699
+ else qb = qb.where("oi.ordinal", ">", outerCursor);
1700
+ qb = qb.where("oi.ordinal", ">", pagingCursorOrdinal);
1701
+ if (view?.branch) qb = qb.where("oi.branch", "=", view.branch);
1702
+ if (view?.scopes && view.scopes.length > 0) qb = qb.where("oi.scope", "in", view.scopes);
1703
+ if (view?.excludeSourceRemote) qb = qb.where("oi.sourceRemote", "!=", view.excludeSourceRemote);
1704
+ return qb;
1705
+ };
1706
+ let unionQuery = buildBranch("joiner").unionAll(buildBranch("newOps")).orderBy("ordinal", "asc");
1707
+ if (paging?.limit) unionQuery = unionQuery.limit(paging.limit + 1);
1708
+ const rows = await unionQuery.execute();
1705
1709
  let hasMore = false;
1706
1710
  let items = rows;
1707
1711
  if (paging?.limit && rows.length > paging.limit) {