@powerhousedao/connect 1.0.9-dev.0 → 1.0.11-dev.0
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/LICENSE +661 -0
- package/dist/assets/{app-D9QJBr8i.css → app-BIIVKAZr.css} +223 -60
- package/dist/assets/{app-Uu65do7x.js → app-CSB8ljfZ.js} +2107 -1027
- package/dist/assets/{app-loader-BnxLpX27.js → app-loader-k9YqeUtT.js} +416 -268
- package/dist/assets/{app-loader-Bnp0H-wa.css → app-loader-pcztQTL4.css} +173 -26
- package/dist/assets/{ccip-CpD5P3bc.js → ccip-CE4X4bM8.js} +3 -3
- package/dist/assets/{content-DV_bRXbH.js → content-DPhkZXQC.js} +37 -7
- package/dist/assets/{index-B4m3ucR9.js → index-COuqxA6R.js} +3 -3
- package/dist/assets/{index-Ch_NXi_f.js → index-CTQ6qYUS.js} +670 -519
- package/dist/assets/{index-yrCJMRn6.js → index-Dr18XVHc.js} +4 -4
- package/dist/assets/{main.CpORyZoE.js → main.Biy01WIR.js} +1 -1
- package/dist/assets/{style-D4JhTt_m.css → style-Ce3V83BE.css} +31 -36
- package/dist/hmr.js +1 -1
- package/dist/index.html +1 -1
- package/dist/modules/@powerhousedao/reactor-browser/{chunk-G6LMXRY5.js → chunk-2ONJ2PX4.js} +1 -1
- package/dist/modules/@powerhousedao/reactor-browser/{chunk-IC6B3767.js → chunk-6GRZOLU5.js} +1 -1
- package/dist/modules/@powerhousedao/reactor-browser/{chunk-FW7N6EJH.js → chunk-C7QRY43M.js} +3 -3
- package/dist/modules/@powerhousedao/reactor-browser/{chunk-45DCPCA7.js → chunk-CO2RVWYY.js} +1 -1
- package/dist/modules/@powerhousedao/reactor-browser/{chunk-UDKYG6I4.js → chunk-HNBKSZYU.js} +1 -1
- package/dist/modules/@powerhousedao/reactor-browser/{chunk-6MBHOHAA.js → chunk-HNTH6HAH.js} +7 -20
- package/dist/modules/@powerhousedao/reactor-browser/{chunk-N5UNGAA6.js → chunk-HYN4HC4N.js} +391 -232
- package/dist/modules/@powerhousedao/reactor-browser/{chunk-F3RCGUF6.js → chunk-NHD6VUCD.js} +2 -2
- package/dist/modules/@powerhousedao/reactor-browser/{chunk-OYYVE7RP.js → chunk-ODF4NZBP.js} +1 -1
- package/dist/modules/@powerhousedao/reactor-browser/{chunk-M2UUQ5LH.js → chunk-U34SEKEB.js} +2 -2
- package/dist/modules/@powerhousedao/reactor-browser/context/index.js +2 -2
- package/dist/modules/@powerhousedao/reactor-browser/context/read-mode.js +2 -2
- package/dist/modules/@powerhousedao/reactor-browser/hooks/index.js +8 -8
- package/dist/modules/@powerhousedao/reactor-browser/hooks/useAddDebouncedOperations.js +3 -3
- package/dist/modules/@powerhousedao/reactor-browser/hooks/useConnectCrypto.js +2 -2
- package/dist/modules/@powerhousedao/reactor-browser/hooks/useDocumentDrives.js +2 -2
- package/dist/modules/@powerhousedao/reactor-browser/hooks/useDocumentEditor.js +5 -5
- package/dist/modules/@powerhousedao/reactor-browser/hooks/useDriveActions.js +2 -2
- package/dist/modules/@powerhousedao/reactor-browser/hooks/useDriveActionsWithUiNodes.js +3 -3
- package/dist/modules/@powerhousedao/reactor-browser/index.js +10 -10
- package/dist/modules/@powerhousedao/reactor-browser/reactor.js +2 -2
- package/dist/vite-envs.sh +1 -1
- package/package.json +9 -9
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/app-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/app-CSB8ljfZ.js","assets/main.Biy01WIR.js","assets/app-BIIVKAZr.css"])))=>i.map(i=>d[i]);
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __typeError = (msg) => {
|
|
4
4
|
throw TypeError(msg);
|
|
@@ -11,7 +11,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
|
|
|
11
11
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
12
12
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
13
13
|
var _tags, _levelString, _errorHandler, _ConsoleLogger_instances, levelValue_get, _getDocumentModelModule, _drives, _ReadModeService_instances, parseGraphQLErrors_fn, fetchDrive_fn, _a, _ServiceWorkerManager_instances, handleServiceWorkerMessage_fn, handleServiceWorker_fn;
|
|
14
|
-
import { _ as __vitePreload } from "./main.
|
|
14
|
+
import { _ as __vitePreload } from "./main.Biy01WIR.js";
|
|
15
15
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
16
16
|
import { useState, useEffect, Suspense, lazy } from "react";
|
|
17
17
|
function _mergeNamespaces(n, m) {
|
|
@@ -11554,13 +11554,6 @@ class DriveAlreadyExistsError extends Error {
|
|
|
11554
11554
|
this.driveId = driveId;
|
|
11555
11555
|
}
|
|
11556
11556
|
}
|
|
11557
|
-
class DriveNotFoundError extends Error {
|
|
11558
|
-
constructor(driveId) {
|
|
11559
|
-
super(`Drive with id ${driveId} not found`);
|
|
11560
|
-
__publicField(this, "driveId");
|
|
11561
|
-
this.driveId = driveId;
|
|
11562
|
-
}
|
|
11563
|
-
}
|
|
11564
11557
|
class SynchronizationUnitNotFoundError extends Error {
|
|
11565
11558
|
constructor(message, syncUnitId) {
|
|
11566
11559
|
super(message);
|
|
@@ -22368,9 +22361,7 @@ class DefaultDrivesManager {
|
|
|
22368
22361
|
try {
|
|
22369
22362
|
await this.server.deleteDrive(driveId);
|
|
22370
22363
|
} catch (error) {
|
|
22371
|
-
|
|
22372
|
-
logger$1.error(error);
|
|
22373
|
-
}
|
|
22364
|
+
logger$1.error(error);
|
|
22374
22365
|
}
|
|
22375
22366
|
}
|
|
22376
22367
|
async preserveDrivesById(driveIdsToPreserve, drives, removeStrategy = "detach") {
|
|
@@ -22517,7 +22508,14 @@ class DefaultDrivesManager {
|
|
|
22517
22508
|
}
|
|
22518
22509
|
const PULL_DRIVE_INTERVAL = 1500;
|
|
22519
22510
|
const MAX_REVISIONS_PER_ACK = 100;
|
|
22520
|
-
|
|
22511
|
+
let _staticLogger;
|
|
22512
|
+
const staticLogger = () => {
|
|
22513
|
+
if (!_staticLogger) {
|
|
22514
|
+
_staticLogger = childLogger(["PullResponderTransmitter", "static"]);
|
|
22515
|
+
}
|
|
22516
|
+
return _staticLogger;
|
|
22517
|
+
};
|
|
22518
|
+
class PullResponderTransmitter {
|
|
22521
22519
|
constructor(listener, manager) {
|
|
22522
22520
|
__publicField(this, "logger", childLogger([
|
|
22523
22521
|
"PullResponderTransmitter",
|
|
@@ -22530,8 +22528,18 @@ const _PullResponderTransmitter = class _PullResponderTransmitter {
|
|
|
22530
22528
|
this.logger.verbose(`constructor(listener: ${listener.listenerId})`);
|
|
22531
22529
|
}
|
|
22532
22530
|
getStrands(options) {
|
|
22533
|
-
this.logger.verbose(`getStrands
|
|
22534
|
-
return this.manager.getStrands(this.listener.driveId, this.listener.listenerId, options)
|
|
22531
|
+
this.logger.verbose(`[SYNC DEBUG] PullResponderTransmitter.getStrands called for drive: ${this.listener.driveId}, listener: ${this.listener.listenerId}, options: ${JSON.stringify(options || {})}`);
|
|
22532
|
+
return this.manager.getStrands(this.listener.driveId, this.listener.listenerId, options).then((strands) => {
|
|
22533
|
+
this.logger.verbose(`[SYNC DEBUG] PullResponderTransmitter.getStrands returning ${strands.length} strands for drive: ${this.listener.driveId}, listener: ${this.listener.listenerId}`);
|
|
22534
|
+
if (strands.length === 0) {
|
|
22535
|
+
this.logger.verbose(`[SYNC DEBUG] No strands returned for drive: ${this.listener.driveId}, listener: ${this.listener.listenerId}`);
|
|
22536
|
+
} else {
|
|
22537
|
+
for (const strand of strands) {
|
|
22538
|
+
this.logger.verbose(`[SYNC DEBUG] Strand for drive: ${strand.driveId}, document: ${strand.documentId}, scope: ${strand.scope}, operations: ${strand.operations.length}`);
|
|
22539
|
+
}
|
|
22540
|
+
}
|
|
22541
|
+
return strands;
|
|
22542
|
+
});
|
|
22535
22543
|
}
|
|
22536
22544
|
disconnect() {
|
|
22537
22545
|
return Promise.resolve();
|
|
@@ -22551,16 +22559,22 @@ const _PullResponderTransmitter = class _PullResponderTransmitter {
|
|
|
22551
22559
|
}
|
|
22552
22560
|
return success;
|
|
22553
22561
|
}
|
|
22554
|
-
static async registerPullResponder(driveId, url, filter) {
|
|
22562
|
+
static async registerPullResponder(driveId, url, filter, listenerId) {
|
|
22555
22563
|
var _a2;
|
|
22556
|
-
|
|
22564
|
+
staticLogger().verbose(`registerPullResponder(url: ${url})`, filter);
|
|
22557
22565
|
const result = await requestGraphql(url, gql`
|
|
22558
|
-
mutation registerPullResponderListener(
|
|
22559
|
-
|
|
22566
|
+
mutation registerPullResponderListener(
|
|
22567
|
+
$filter: InputListenerFilter!
|
|
22568
|
+
$listenerId: String
|
|
22569
|
+
) {
|
|
22570
|
+
registerPullResponderListener(
|
|
22571
|
+
filter: $filter
|
|
22572
|
+
listenerId: $listenerId
|
|
22573
|
+
) {
|
|
22560
22574
|
listenerId
|
|
22561
22575
|
}
|
|
22562
22576
|
}
|
|
22563
|
-
`, { filter });
|
|
22577
|
+
`, { filter, listenerId });
|
|
22564
22578
|
const error = (_a2 = result.errors) == null ? void 0 : _a2.at(0);
|
|
22565
22579
|
if (error) {
|
|
22566
22580
|
throw error;
|
|
@@ -22572,7 +22586,7 @@ const _PullResponderTransmitter = class _PullResponderTransmitter {
|
|
|
22572
22586
|
}
|
|
22573
22587
|
static async pullStrands(driveId, url, listenerId, options) {
|
|
22574
22588
|
var _a2;
|
|
22575
|
-
|
|
22589
|
+
staticLogger().verbose(`[SYNC DEBUG] PullResponderTransmitter.pullStrands called for drive: ${driveId}, url: ${url}, listener: ${listenerId}, options: ${JSON.stringify(options || {})}`);
|
|
22576
22590
|
const result = await requestGraphql(url, gql`
|
|
22577
22591
|
query strands($listenerId: ID!) {
|
|
22578
22592
|
system {
|
|
@@ -22612,27 +22626,34 @@ const _PullResponderTransmitter = class _PullResponderTransmitter {
|
|
|
22612
22626
|
`, { listenerId });
|
|
22613
22627
|
const error = (_a2 = result.errors) == null ? void 0 : _a2.at(0);
|
|
22614
22628
|
if (error) {
|
|
22629
|
+
staticLogger().verbose(`[SYNC DEBUG] Error pulling strands for drive: ${driveId}, listener: ${listenerId}, error: ${JSON.stringify(error)}`);
|
|
22615
22630
|
throw error;
|
|
22616
22631
|
}
|
|
22617
22632
|
if (!result.system) {
|
|
22633
|
+
staticLogger().verbose(`[SYNC DEBUG] No system data returned when pulling strands for drive: ${driveId}, listener: ${listenerId}`);
|
|
22618
22634
|
return [];
|
|
22619
22635
|
}
|
|
22620
|
-
|
|
22636
|
+
const strands = result.system.sync.strands.map((s) => ({
|
|
22621
22637
|
...s,
|
|
22622
22638
|
operations: s.operations.map((o) => ({
|
|
22623
22639
|
...o,
|
|
22624
22640
|
input: JSON.parse(o.input)
|
|
22625
22641
|
}))
|
|
22626
22642
|
}));
|
|
22643
|
+
staticLogger().verbose(`[SYNC DEBUG] PullResponderTransmitter.pullStrands returning ${strands.length} strands for drive: ${driveId}, listener: ${listenerId}`);
|
|
22644
|
+
if (strands.length > 0) {
|
|
22645
|
+
staticLogger().verbose(`[SYNC DEBUG] Strands being returned: ${strands.map((s) => `${s.documentId}:${s.scope}`).join(", ")}`);
|
|
22646
|
+
}
|
|
22647
|
+
return strands;
|
|
22627
22648
|
}
|
|
22628
22649
|
static async acknowledgeStrands(url, listenerId, revisions) {
|
|
22629
|
-
|
|
22650
|
+
staticLogger().verbose(`acknowledgeStrands(url: ${url}, listener: ${listenerId})`, revisions);
|
|
22630
22651
|
const chunks = [];
|
|
22631
22652
|
for (let i = 0; i < revisions.length; i += MAX_REVISIONS_PER_ACK) {
|
|
22632
22653
|
chunks.push(revisions.slice(i, i + MAX_REVISIONS_PER_ACK));
|
|
22633
22654
|
}
|
|
22634
22655
|
if (chunks.length > 1) {
|
|
22635
|
-
|
|
22656
|
+
staticLogger().verbose(`Breaking strand acknowledgement into ${chunks.length} chunks...`);
|
|
22636
22657
|
}
|
|
22637
22658
|
const results = await Promise.allSettled(chunks.map(async (chunk) => {
|
|
22638
22659
|
var _a2;
|
|
@@ -22657,75 +22678,125 @@ const _PullResponderTransmitter = class _PullResponderTransmitter {
|
|
|
22657
22678
|
throw new Error("Error acknowledging strands");
|
|
22658
22679
|
}
|
|
22659
22680
|
}
|
|
22681
|
+
/**
|
|
22682
|
+
* This function will only throw if `onError` throws an error (or there is
|
|
22683
|
+
* an unintentionally unhandled error in the pull loop).
|
|
22684
|
+
*
|
|
22685
|
+
* All other errors are caught, logged, and passed to `onError`.
|
|
22686
|
+
*
|
|
22687
|
+
* Because of this, `onError` _may be called multiple times_.
|
|
22688
|
+
*/
|
|
22660
22689
|
static async executePull(driveId, trigger, onStrandUpdate, onError, onRevisions, onAcknowledge) {
|
|
22661
|
-
var _a2;
|
|
22662
|
-
|
|
22690
|
+
var _a2, _b;
|
|
22691
|
+
staticLogger().verbose(`executePull(driveId: ${driveId}), trigger:`, trigger);
|
|
22692
|
+
staticLogger().info(`[SYNC DEBUG] PullResponderTransmitter.executePull starting for drive: ${driveId}, listenerId: ${trigger.data.listenerId}`);
|
|
22693
|
+
const { url } = trigger.data;
|
|
22694
|
+
let strands;
|
|
22695
|
+
let error;
|
|
22696
|
+
const listenerId = trigger.data.listenerId;
|
|
22663
22697
|
try {
|
|
22664
|
-
|
|
22665
|
-
|
|
22666
|
-
|
|
22667
|
-
|
|
22668
|
-
|
|
22669
|
-
|
|
22670
|
-
|
|
22671
|
-
|
|
22672
|
-
|
|
22673
|
-
|
|
22674
|
-
|
|
22675
|
-
|
|
22676
|
-
|
|
22677
|
-
|
|
22678
|
-
|
|
22679
|
-
|
|
22680
|
-
let error = void 0;
|
|
22681
|
-
try {
|
|
22682
|
-
const result = await onStrandUpdate(strand, {
|
|
22683
|
-
type: "trigger",
|
|
22684
|
-
trigger
|
|
22685
|
-
});
|
|
22686
|
-
if (result.error) {
|
|
22687
|
-
throw result.error;
|
|
22698
|
+
strands = await PullResponderTransmitter.pullStrands(driveId, url, listenerId);
|
|
22699
|
+
} catch (e) {
|
|
22700
|
+
error = e;
|
|
22701
|
+
const graphqlError = error;
|
|
22702
|
+
const errors = ((_a2 = graphqlError.response) == null ? void 0 : _a2.errors) ?? [];
|
|
22703
|
+
for (const err of errors) {
|
|
22704
|
+
if (err.message === "Listener not found") {
|
|
22705
|
+
staticLogger().verbose(`[SYNC DEBUG] Auto-registering pull responder for drive: ${driveId}`);
|
|
22706
|
+
await PullResponderTransmitter.registerPullResponder(trigger.driveId, url, trigger.filter, listenerId);
|
|
22707
|
+
try {
|
|
22708
|
+
strands = await PullResponderTransmitter.pullStrands(driveId, url, listenerId);
|
|
22709
|
+
staticLogger().verbose(`Successfully auto-registered and pulled strands for drive: ${driveId}, listenerId: ${listenerId}`);
|
|
22710
|
+
} catch (error2) {
|
|
22711
|
+
staticLogger().error(`Could not resolve 'Listener not found' error by registering a new pull responder for drive: ${driveId}, listenerId: ${listenerId}: ${error2}`);
|
|
22712
|
+
onError(error2);
|
|
22713
|
+
return;
|
|
22688
22714
|
}
|
|
22689
|
-
|
|
22690
|
-
error = e;
|
|
22691
|
-
onError(error);
|
|
22715
|
+
break;
|
|
22692
22716
|
}
|
|
22693
|
-
listenerRevisions.push({
|
|
22694
|
-
branch: strand.branch,
|
|
22695
|
-
documentId: strand.documentId || "",
|
|
22696
|
-
driveId: strand.driveId,
|
|
22697
|
-
revision: ((_a2 = operations.pop()) == null ? void 0 : _a2.index) ?? -1,
|
|
22698
|
-
scope: strand.scope,
|
|
22699
|
-
status: error ? error instanceof OperationError ? error.status : "ERROR" : "SUCCESS",
|
|
22700
|
-
error
|
|
22701
|
-
});
|
|
22702
22717
|
}
|
|
22703
|
-
|
|
22704
|
-
|
|
22705
|
-
|
|
22706
|
-
|
|
22718
|
+
}
|
|
22719
|
+
if (!strands) {
|
|
22720
|
+
staticLogger().error(`Error pulling strands for drive, and could not auto-register: ${driveId}, listenerId: ${trigger.data.listenerId}: ${error}`);
|
|
22721
|
+
onError(error);
|
|
22722
|
+
return;
|
|
22723
|
+
}
|
|
22724
|
+
if (!strands.length) {
|
|
22725
|
+
staticLogger().verbose(`[SYNC DEBUG] No strands returned in pull cycle for drive: ${driveId}, listenerId: ${trigger.data.listenerId}`);
|
|
22707
22726
|
try {
|
|
22708
|
-
|
|
22709
|
-
|
|
22710
|
-
|
|
22711
|
-
|
|
22712
|
-
success = true;
|
|
22713
|
-
} catch (error) {
|
|
22714
|
-
this.staticLogger.error("ACK error", error);
|
|
22715
|
-
}
|
|
22716
|
-
if (success) {
|
|
22717
|
-
this.staticLogger.verbose("Acknowledged strands successfully.");
|
|
22718
|
-
} else {
|
|
22719
|
-
this.staticLogger.error("Failed to acknowledge strands");
|
|
22727
|
+
onRevisions == null ? void 0 : onRevisions([]);
|
|
22728
|
+
} catch (error2) {
|
|
22729
|
+
staticLogger().error(`Error calling onRevisions for drive: ${driveId}, listenerId: ${trigger.data.listenerId}: ${error2}`);
|
|
22730
|
+
onError(error2);
|
|
22720
22731
|
}
|
|
22732
|
+
return;
|
|
22733
|
+
}
|
|
22734
|
+
staticLogger().verbose(`[SYNC DEBUG] Processing ${strands.length} strands in pull cycle for drive: ${driveId}, listenerId: ${trigger.data.listenerId}`);
|
|
22735
|
+
const listenerRevisions = [];
|
|
22736
|
+
for (const strand of strands) {
|
|
22737
|
+
const operations = strand.operations.map((op) => ({
|
|
22738
|
+
...op,
|
|
22739
|
+
scope: strand.scope,
|
|
22740
|
+
branch: strand.branch
|
|
22741
|
+
}));
|
|
22742
|
+
staticLogger().verbose(`[SYNC DEBUG] Processing strand for drive: ${strand.driveId}, document: ${strand.documentId}, scope: ${strand.scope}, with ${operations.length} operations`);
|
|
22743
|
+
let error2 = void 0;
|
|
22744
|
+
try {
|
|
22745
|
+
const result = await onStrandUpdate(strand, {
|
|
22746
|
+
type: "trigger",
|
|
22747
|
+
trigger
|
|
22748
|
+
});
|
|
22749
|
+
if (result.error) {
|
|
22750
|
+
throw result.error;
|
|
22751
|
+
}
|
|
22752
|
+
} catch (e) {
|
|
22753
|
+
staticLogger().error(`Error processing strand for drive: ${strand.driveId}, document: ${strand.documentId}, scope: ${strand.scope}, with ${operations.length} operations: ${e}`);
|
|
22754
|
+
error2 = e;
|
|
22755
|
+
onError(error2);
|
|
22756
|
+
}
|
|
22757
|
+
listenerRevisions.push({
|
|
22758
|
+
branch: strand.branch,
|
|
22759
|
+
documentId: strand.documentId || "",
|
|
22760
|
+
driveId: strand.driveId,
|
|
22761
|
+
revision: ((_b = operations.pop()) == null ? void 0 : _b.index) ?? -1,
|
|
22762
|
+
scope: strand.scope,
|
|
22763
|
+
status: error2 ? error2 instanceof OperationError ? error2.status : "ERROR" : "SUCCESS",
|
|
22764
|
+
error: error2
|
|
22765
|
+
});
|
|
22766
|
+
}
|
|
22767
|
+
staticLogger().verbose("Processed strands...");
|
|
22768
|
+
try {
|
|
22769
|
+
onRevisions == null ? void 0 : onRevisions(listenerRevisions);
|
|
22770
|
+
} catch (error2) {
|
|
22771
|
+
staticLogger().error(`Error calling onRevisions for drive: ${driveId}, listenerId: ${trigger.data.listenerId}: ${error2}`);
|
|
22772
|
+
onError(error2);
|
|
22773
|
+
}
|
|
22774
|
+
staticLogger().verbose(`[SYNC DEBUG] Acknowledging ${listenerRevisions.length} strands for drive: ${driveId}, listenerId: ${trigger.data.listenerId}`);
|
|
22775
|
+
let success = false;
|
|
22776
|
+
try {
|
|
22777
|
+
await PullResponderTransmitter.acknowledgeStrands(url, trigger.data.listenerId, listenerRevisions.map((revision) => {
|
|
22778
|
+
const { error: error2, ...rest } = revision;
|
|
22779
|
+
return rest;
|
|
22780
|
+
}));
|
|
22781
|
+
success = true;
|
|
22782
|
+
} catch (error2) {
|
|
22783
|
+
staticLogger().error(`Error acknowledging strands for drive: ${driveId}, listenerId: ${trigger.data.listenerId}: ${error2}`);
|
|
22784
|
+
onError(error2);
|
|
22785
|
+
}
|
|
22786
|
+
if (success) {
|
|
22787
|
+
staticLogger().verbose(`[SYNC DEBUG] Successfully acknowledged strands for drive: ${driveId}, listenerId: ${trigger.data.listenerId}`);
|
|
22788
|
+
} else {
|
|
22789
|
+
staticLogger().error("Failed to acknowledge strands");
|
|
22790
|
+
}
|
|
22791
|
+
try {
|
|
22721
22792
|
onAcknowledge == null ? void 0 : onAcknowledge(success);
|
|
22722
|
-
} catch (
|
|
22723
|
-
|
|
22724
|
-
onError(
|
|
22793
|
+
} catch (error2) {
|
|
22794
|
+
staticLogger().error(`Error calling onAcknowledge for drive: ${driveId}, listenerId: ${trigger.data.listenerId}: ${error2}`);
|
|
22795
|
+
onError(error2);
|
|
22725
22796
|
}
|
|
22726
22797
|
}
|
|
22727
22798
|
static setupPull(driveId, trigger, onStrandUpdate, onError, onRevisions, onAcknowledge) {
|
|
22728
|
-
|
|
22799
|
+
staticLogger().verbose(`[SYNC DEBUG] PullResponderTransmitter.setupPull initiated for drive: ${driveId}, listenerId: ${trigger.data.listenerId}`);
|
|
22729
22800
|
const { interval } = trigger.data;
|
|
22730
22801
|
let loopInterval = PULL_DRIVE_INTERVAL;
|
|
22731
22802
|
if (interval) {
|
|
@@ -22737,20 +22808,25 @@ const _PullResponderTransmitter = class _PullResponderTransmitter {
|
|
|
22737
22808
|
} catch {
|
|
22738
22809
|
}
|
|
22739
22810
|
}
|
|
22811
|
+
staticLogger().verbose(`[SYNC DEBUG] Pull interval set to ${loopInterval}ms for drive: ${driveId}, listenerId: ${trigger.data.listenerId}`);
|
|
22740
22812
|
let isCancelled = false;
|
|
22741
22813
|
let timeout;
|
|
22742
22814
|
const executeLoop = async () => {
|
|
22743
22815
|
while (!isCancelled) {
|
|
22744
|
-
|
|
22816
|
+
staticLogger().verbose(`[SYNC DEBUG] Starting pull cycle for drive: ${driveId}, listenerId: ${trigger.data.listenerId}`);
|
|
22745
22817
|
await this.executePull(driveId, trigger, onStrandUpdate, onError, onRevisions, onAcknowledge);
|
|
22818
|
+
staticLogger().verbose(`[SYNC DEBUG] Completed pull cycle for drive: ${driveId}, listenerId: ${trigger.data.listenerId}, waiting ${loopInterval}ms for next cycle`);
|
|
22746
22819
|
await new Promise((resolve) => {
|
|
22747
|
-
|
|
22820
|
+
staticLogger().verbose(`Scheduling next pull in ${loopInterval} ms`);
|
|
22748
22821
|
timeout = setTimeout(resolve, loopInterval);
|
|
22749
22822
|
});
|
|
22750
22823
|
}
|
|
22751
22824
|
};
|
|
22752
|
-
executeLoop().catch(
|
|
22825
|
+
executeLoop().catch((error) => {
|
|
22826
|
+
staticLogger().error(`Error in executeLoop for drive: ${driveId}, listenerId: ${trigger.data.listenerId}: ${error}`);
|
|
22827
|
+
});
|
|
22753
22828
|
return () => {
|
|
22829
|
+
staticLogger().verbose(`[SYNC DEBUG] Cancelling pull loop for drive: ${driveId}, listenerId: ${trigger.data.listenerId}`);
|
|
22754
22830
|
isCancelled = true;
|
|
22755
22831
|
if (timeout !== void 0) {
|
|
22756
22832
|
clearTimeout(timeout);
|
|
@@ -22758,17 +22834,20 @@ const _PullResponderTransmitter = class _PullResponderTransmitter {
|
|
|
22758
22834
|
};
|
|
22759
22835
|
}
|
|
22760
22836
|
static async createPullResponderTrigger(driveId, url, options) {
|
|
22761
|
-
|
|
22837
|
+
staticLogger().verbose(`createPullResponderTrigger(drive: ${driveId}, url: ${url})`);
|
|
22762
22838
|
const { pullFilter, pullInterval } = options;
|
|
22763
|
-
const
|
|
22839
|
+
const filter = pullFilter ?? {
|
|
22764
22840
|
documentId: ["*"],
|
|
22765
22841
|
documentType: ["*"],
|
|
22766
22842
|
branch: ["*"],
|
|
22767
22843
|
scope: ["*"]
|
|
22768
|
-
}
|
|
22844
|
+
};
|
|
22845
|
+
const listenerId = await PullResponderTransmitter.registerPullResponder(driveId, url, filter);
|
|
22769
22846
|
const pullTrigger = {
|
|
22770
22847
|
id: generateUUID(),
|
|
22771
22848
|
type: "PullResponder",
|
|
22849
|
+
driveId,
|
|
22850
|
+
filter,
|
|
22772
22851
|
data: {
|
|
22773
22852
|
url,
|
|
22774
22853
|
listenerId,
|
|
@@ -22780,12 +22859,7 @@ const _PullResponderTransmitter = class _PullResponderTransmitter {
|
|
|
22780
22859
|
static isPullResponderTrigger(trigger) {
|
|
22781
22860
|
return trigger.type === "PullResponder";
|
|
22782
22861
|
}
|
|
22783
|
-
}
|
|
22784
|
-
__publicField(_PullResponderTransmitter, "staticLogger", childLogger([
|
|
22785
|
-
"PullResponderTransmitter",
|
|
22786
|
-
"static"
|
|
22787
|
-
]));
|
|
22788
|
-
let PullResponderTransmitter = _PullResponderTransmitter;
|
|
22862
|
+
}
|
|
22789
22863
|
var defaults;
|
|
22790
22864
|
var hasRequiredDefaults;
|
|
22791
22865
|
function requireDefaults() {
|
|
@@ -23002,9 +23076,10 @@ function isAtRevision(document, revisions) {
|
|
|
23002
23076
|
}
|
|
23003
23077
|
class BaseDocumentDriveServer {
|
|
23004
23078
|
constructor(documentModelModules, storage, documentStorage, cache, queueManager, eventEmitter, synchronizationManager, listenerManager, options) {
|
|
23079
|
+
__publicField(this, "logger", childLogger(["BaseDocumentDriveServer"]));
|
|
23005
23080
|
// external dependencies
|
|
23006
23081
|
__publicField(this, "documentModelModules");
|
|
23007
|
-
__publicField(this, "
|
|
23082
|
+
__publicField(this, "legacyStorage");
|
|
23008
23083
|
__publicField(this, "documentStorage");
|
|
23009
23084
|
__publicField(this, "cache");
|
|
23010
23085
|
__publicField(this, "queueManager");
|
|
@@ -23040,7 +23115,7 @@ class BaseDocumentDriveServer {
|
|
|
23040
23115
|
__publicField(this, "triggerMap", /* @__PURE__ */ new Map());
|
|
23041
23116
|
__publicField(this, "initializePromise");
|
|
23042
23117
|
this.documentModelModules = documentModelModules;
|
|
23043
|
-
this.
|
|
23118
|
+
this.legacyStorage = storage;
|
|
23044
23119
|
this.documentStorage = documentStorage;
|
|
23045
23120
|
this.cache = cache;
|
|
23046
23121
|
this.queueManager = queueManager;
|
|
@@ -23072,19 +23147,19 @@ class BaseDocumentDriveServer {
|
|
|
23072
23147
|
async _initialize() {
|
|
23073
23148
|
await this.listenerManager.initialize(this.handleListenerError);
|
|
23074
23149
|
await this.queueManager.init(this.queueDelegate, (error) => {
|
|
23075
|
-
logger
|
|
23150
|
+
this.logger.error(`Error initializing queue manager`, error);
|
|
23076
23151
|
errors.push(error);
|
|
23077
23152
|
});
|
|
23078
23153
|
try {
|
|
23079
23154
|
await this.defaultDrivesManager.removeOldremoteDrives();
|
|
23080
23155
|
} catch (error) {
|
|
23081
|
-
logger
|
|
23156
|
+
this.logger.error(error);
|
|
23082
23157
|
}
|
|
23083
23158
|
const errors = [];
|
|
23084
23159
|
const drives = await this.getDrives();
|
|
23085
23160
|
for (const drive of drives) {
|
|
23086
23161
|
await this._initializeDrive(drive).catch((error) => {
|
|
23087
|
-
logger
|
|
23162
|
+
this.logger.error(`Error initializing drive ${drive}`, error);
|
|
23088
23163
|
errors.push(error);
|
|
23089
23164
|
});
|
|
23090
23165
|
}
|
|
@@ -23114,7 +23189,7 @@ class BaseDocumentDriveServer {
|
|
|
23114
23189
|
return source.type === "local" ? "push" : "pull";
|
|
23115
23190
|
}
|
|
23116
23191
|
handleListenerError(error, driveId, listener) {
|
|
23117
|
-
logger
|
|
23192
|
+
this.logger.error(`Listener ${listener.listener.label ?? listener.listener.listenerId} error:`, error);
|
|
23118
23193
|
const status = error instanceof OperationError ? error.status : "ERROR";
|
|
23119
23194
|
this.synchronizationManager.updateSyncStatus(driveId, { push: status }, error);
|
|
23120
23195
|
}
|
|
@@ -23177,9 +23252,9 @@ class BaseDocumentDriveServer {
|
|
|
23177
23252
|
if (pushListener) {
|
|
23178
23253
|
this.getSynchronizationUnitsRevision(driveId, syncUnits).then((syncUnitRevisions) => {
|
|
23179
23254
|
for (const revision of syncUnitRevisions) {
|
|
23180
|
-
this.listenerManager.updateListenerRevision(pushListener.listenerId, driveId, revision.syncId, revision.revision).catch(logger
|
|
23255
|
+
this.listenerManager.updateListenerRevision(pushListener.listenerId, driveId, revision.syncId, revision.revision).catch(this.logger.error);
|
|
23181
23256
|
}
|
|
23182
|
-
}).catch(logger
|
|
23257
|
+
}).catch(this.logger.error);
|
|
23183
23258
|
}
|
|
23184
23259
|
}
|
|
23185
23260
|
});
|
|
@@ -23200,30 +23275,57 @@ class BaseDocumentDriveServer {
|
|
|
23200
23275
|
return this.triggerMap.delete(driveId);
|
|
23201
23276
|
}
|
|
23202
23277
|
async _initializeDrive(driveId) {
|
|
23203
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
23278
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
23204
23279
|
const drive = await this.getDrive(driveId);
|
|
23280
|
+
this.logger.verbose(`[SYNC DEBUG] Initializing drive ${driveId} with slug "${drive.state.global.slug}"`);
|
|
23205
23281
|
await this.synchronizationManager.initializeDriveSyncStatus(driveId, drive);
|
|
23206
23282
|
if (this.shouldSyncRemoteDrive(drive)) {
|
|
23283
|
+
this.logger.verbose(`[SYNC DEBUG] Starting sync for remote drive ${driveId}`);
|
|
23207
23284
|
await this.startSyncRemoteDrive(driveId);
|
|
23208
23285
|
}
|
|
23286
|
+
this.logger.verbose(`[SYNC DEBUG] Processing ${drive.state.local.listeners.length} listeners for drive ${driveId}`);
|
|
23209
23287
|
for (const zodListener of drive.state.local.listeners) {
|
|
23210
23288
|
if (((_a2 = zodListener.callInfo) == null ? void 0 : _a2.transmitterType) === "SwitchboardPush") {
|
|
23289
|
+
this.logger.verbose(`[SYNC DEBUG] Setting up SwitchboardPush listener ${zodListener.listenerId} for drive ${driveId}`);
|
|
23211
23290
|
const transmitter = new SwitchboardPushTransmitter(((_b = zodListener.callInfo) == null ? void 0 : _b.data) ?? "");
|
|
23212
|
-
this.
|
|
23291
|
+
this.logger.verbose(`[SYNC DEBUG] Created SwitchboardPush transmitter with URL: ${((_c = zodListener.callInfo) == null ? void 0 : _c.data) || "none"}`);
|
|
23292
|
+
await this.listenerManager.setListener(driveId, {
|
|
23213
23293
|
block: zodListener.block,
|
|
23214
23294
|
driveId: drive.state.global.id,
|
|
23215
23295
|
filter: {
|
|
23216
|
-
branch: ((
|
|
23217
|
-
documentId: ((
|
|
23218
|
-
documentType: ((
|
|
23219
|
-
scope: ((
|
|
23296
|
+
branch: ((_d = zodListener.filter) == null ? void 0 : _d.branch) ?? [],
|
|
23297
|
+
documentId: ((_e = zodListener.filter) == null ? void 0 : _e.documentId) ?? [],
|
|
23298
|
+
documentType: ((_f = zodListener.filter) == null ? void 0 : _f.documentType) ?? [],
|
|
23299
|
+
scope: ((_g = zodListener.filter) == null ? void 0 : _g.scope) ?? []
|
|
23220
23300
|
},
|
|
23221
23301
|
listenerId: zodListener.listenerId,
|
|
23222
23302
|
callInfo: zodListener.callInfo,
|
|
23223
23303
|
system: zodListener.system,
|
|
23224
23304
|
label: zodListener.label ?? "",
|
|
23225
23305
|
transmitter
|
|
23306
|
+
}).then(() => {
|
|
23307
|
+
this.logger.verbose(`[SYNC DEBUG] Successfully set up listener ${zodListener.listenerId} for drive ${driveId}`);
|
|
23226
23308
|
});
|
|
23309
|
+
} else if (((_h = zodListener.callInfo) == null ? void 0 : _h.transmitterType) === "PullResponder") {
|
|
23310
|
+
this.logger.verbose(`[SYNC DEBUG] Setting up PullResponder listener ${zodListener.listenerId} for drive ${driveId}`);
|
|
23311
|
+
const pullResponderListener = {
|
|
23312
|
+
driveId,
|
|
23313
|
+
listenerId: zodListener.listenerId,
|
|
23314
|
+
block: false,
|
|
23315
|
+
filter: zodListener.filter,
|
|
23316
|
+
system: false,
|
|
23317
|
+
label: `PullResponder #${zodListener.listenerId}`,
|
|
23318
|
+
callInfo: {
|
|
23319
|
+
data: "",
|
|
23320
|
+
name: "PullResponder",
|
|
23321
|
+
transmitterType: "PullResponder"
|
|
23322
|
+
}
|
|
23323
|
+
};
|
|
23324
|
+
const pullResponder = new PullResponderTransmitter(pullResponderListener, this.listenerManager);
|
|
23325
|
+
pullResponderListener.transmitter = pullResponder;
|
|
23326
|
+
await this.listenerManager.setListener(driveId, pullResponderListener);
|
|
23327
|
+
} else {
|
|
23328
|
+
this.logger.error(`Skipping listener ${zodListener.listenerId} with unsupported type ${((_i = zodListener.callInfo) == null ? void 0 : _i.transmitterType) || "unknown"}`);
|
|
23227
23329
|
}
|
|
23228
23330
|
}
|
|
23229
23331
|
}
|
|
@@ -23255,7 +23357,7 @@ class BaseDocumentDriveServer {
|
|
|
23255
23357
|
if (!id) {
|
|
23256
23358
|
throw new Error("Invalid Drive Id");
|
|
23257
23359
|
}
|
|
23258
|
-
const drives = await this.
|
|
23360
|
+
const drives = await this.legacyStorage.getDrives();
|
|
23259
23361
|
if (drives.includes(id)) {
|
|
23260
23362
|
throw new DriveAlreadyExistsError(id);
|
|
23261
23363
|
}
|
|
@@ -23265,7 +23367,7 @@ class BaseDocumentDriveServer {
|
|
|
23265
23367
|
document.meta = {
|
|
23266
23368
|
preferredEditor
|
|
23267
23369
|
};
|
|
23268
|
-
await this.
|
|
23370
|
+
await this.legacyStorage.createDrive(id, document);
|
|
23269
23371
|
if (input.global.slug) {
|
|
23270
23372
|
await this.cache.deleteDriveBySlug(input.global.slug);
|
|
23271
23373
|
}
|
|
@@ -23300,7 +23402,7 @@ class BaseDocumentDriveServer {
|
|
|
23300
23402
|
this.stopSyncRemoteDrive(driveId),
|
|
23301
23403
|
this.listenerManager.removeDrive(driveId),
|
|
23302
23404
|
this.cache.deleteDrive(driveId),
|
|
23303
|
-
this.
|
|
23405
|
+
this.legacyStorage.deleteDrive(driveId)
|
|
23304
23406
|
]);
|
|
23305
23407
|
result.forEach((r) => {
|
|
23306
23408
|
if (r.status === "rejected") {
|
|
@@ -23309,7 +23411,7 @@ class BaseDocumentDriveServer {
|
|
|
23309
23411
|
});
|
|
23310
23412
|
}
|
|
23311
23413
|
getDrives() {
|
|
23312
|
-
return this.
|
|
23414
|
+
return this.legacyStorage.getDrives();
|
|
23313
23415
|
}
|
|
23314
23416
|
async getDrive(driveId, options) {
|
|
23315
23417
|
let document;
|
|
@@ -23322,15 +23424,15 @@ class BaseDocumentDriveServer {
|
|
|
23322
23424
|
}
|
|
23323
23425
|
}
|
|
23324
23426
|
} catch (e) {
|
|
23325
|
-
logger
|
|
23427
|
+
this.logger.error("Error getting drive from cache", e);
|
|
23326
23428
|
}
|
|
23327
|
-
const driveStorage = document ?? await this.
|
|
23429
|
+
const driveStorage = document ?? await this.documentStorage.get(driveId);
|
|
23328
23430
|
const result = this._buildDocument(driveStorage, options);
|
|
23329
23431
|
if (!isDocumentDrive(result)) {
|
|
23330
23432
|
throw new Error(`Document with id ${driveId} is not a Document Drive`);
|
|
23331
23433
|
} else {
|
|
23332
23434
|
if (!(options == null ? void 0 : options.revisions)) {
|
|
23333
|
-
this.cache.setDrive(driveId, result).catch(logger
|
|
23435
|
+
this.cache.setDrive(driveId, result).catch(this.logger.error);
|
|
23334
23436
|
}
|
|
23335
23437
|
return result;
|
|
23336
23438
|
}
|
|
@@ -23342,14 +23444,14 @@ class BaseDocumentDriveServer {
|
|
|
23342
23444
|
return drive;
|
|
23343
23445
|
}
|
|
23344
23446
|
} catch (e) {
|
|
23345
|
-
logger
|
|
23447
|
+
this.logger.error("Error getting drive from cache", e);
|
|
23346
23448
|
}
|
|
23347
|
-
const driveStorage = await this.
|
|
23449
|
+
const driveStorage = await this.legacyStorage.getDriveBySlug(slug);
|
|
23348
23450
|
const document = this._buildDocument(driveStorage, options);
|
|
23349
23451
|
if (!isDocumentDrive(document)) {
|
|
23350
23452
|
throw new Error(`Document with slug ${slug} is not a Document Drive`);
|
|
23351
23453
|
} else {
|
|
23352
|
-
this.cache.setDriveBySlug(slug, document).catch(logger
|
|
23454
|
+
this.cache.setDriveBySlug(slug, document).catch(this.logger.error);
|
|
23353
23455
|
return document;
|
|
23354
23456
|
}
|
|
23355
23457
|
}
|
|
@@ -23361,17 +23463,17 @@ class BaseDocumentDriveServer {
|
|
|
23361
23463
|
return cachedDocument;
|
|
23362
23464
|
}
|
|
23363
23465
|
} catch (e) {
|
|
23364
|
-
logger
|
|
23466
|
+
this.logger.error("Error getting document from cache", e);
|
|
23365
23467
|
}
|
|
23366
|
-
const documentStorage = cachedDocument ?? await this.
|
|
23468
|
+
const documentStorage = cachedDocument ?? await this.documentStorage.get(documentId);
|
|
23367
23469
|
const document = this._buildDocument(documentStorage, options);
|
|
23368
23470
|
if (!(options == null ? void 0 : options.revisions)) {
|
|
23369
|
-
this.cache.setDocument(documentId, document).catch(logger
|
|
23471
|
+
this.cache.setDocument(documentId, document).catch(this.logger.error);
|
|
23370
23472
|
}
|
|
23371
23473
|
return document;
|
|
23372
23474
|
}
|
|
23373
23475
|
getDocuments(driveId) {
|
|
23374
|
-
return this.
|
|
23476
|
+
return this.legacyStorage.getDocuments(driveId);
|
|
23375
23477
|
}
|
|
23376
23478
|
async createDocument(driveId, input) {
|
|
23377
23479
|
let state = void 0;
|
|
@@ -23394,7 +23496,7 @@ class BaseDocumentDriveServer {
|
|
|
23394
23496
|
clipboard: [],
|
|
23395
23497
|
state: state ?? document.state
|
|
23396
23498
|
};
|
|
23397
|
-
await this.
|
|
23499
|
+
await this.legacyStorage.createDocument(driveId, input.id, documentStorage);
|
|
23398
23500
|
for (const syncUnit of input.synchronizationUnits) {
|
|
23399
23501
|
this.synchronizationManager.updateSyncStatus(syncUnit.syncId, {
|
|
23400
23502
|
pull: this.triggerMap.get(driveId) ? "INITIAL_SYNC" : void 0,
|
|
@@ -23404,9 +23506,9 @@ class BaseDocumentDriveServer {
|
|
|
23404
23506
|
const operations = Object.values(document.operations).flat();
|
|
23405
23507
|
if (operations.length) {
|
|
23406
23508
|
if (isDocumentDrive(document)) {
|
|
23407
|
-
await this.
|
|
23509
|
+
await this.legacyStorage.addDriveOperations(driveId, operations, document);
|
|
23408
23510
|
} else {
|
|
23409
|
-
await this.
|
|
23511
|
+
await this.legacyStorage.addDocumentOperations(driveId, input.id, operations, document);
|
|
23410
23512
|
}
|
|
23411
23513
|
}
|
|
23412
23514
|
return document;
|
|
@@ -23421,10 +23523,10 @@ class BaseDocumentDriveServer {
|
|
|
23421
23523
|
}
|
|
23422
23524
|
await this.listenerManager.removeSyncUnits(driveId, syncUnits);
|
|
23423
23525
|
} catch (error) {
|
|
23424
|
-
logger
|
|
23526
|
+
this.logger.warn("Error deleting document", error);
|
|
23425
23527
|
}
|
|
23426
23528
|
await this.cache.deleteDocument(documentId);
|
|
23427
|
-
return this.
|
|
23529
|
+
return this.legacyStorage.deleteDocument(driveId, documentId);
|
|
23428
23530
|
}
|
|
23429
23531
|
async _processOperations(driveId, documentId, documentStorage, operations) {
|
|
23430
23532
|
const operationsApplied = [];
|
|
@@ -23476,7 +23578,7 @@ class BaseDocumentDriveServer {
|
|
|
23476
23578
|
for (const scope of Object.keys(documentOperations)) {
|
|
23477
23579
|
const lastRemainingOperation = documentOperations[scope].at(-1);
|
|
23478
23580
|
if (lastRemainingOperation && !lastRemainingOperation.resultingState) {
|
|
23479
|
-
lastRemainingOperation.resultingState = await (documentId ? (_b = (_a2 = this.
|
|
23581
|
+
lastRemainingOperation.resultingState = await (documentId ? (_b = (_a2 = this.legacyStorage).getOperationResultingState) == null ? void 0 : _b.call(_a2, driveId, documentId, lastRemainingOperation.index, lastRemainingOperation.scope, "main") : (_d = (_c = this.legacyStorage).getDriveOperationResultingState) == null ? void 0 : _d.call(_c, driveId, lastRemainingOperation.index, lastRemainingOperation.scope, "main"));
|
|
23480
23582
|
}
|
|
23481
23583
|
}
|
|
23482
23584
|
return {
|
|
@@ -23509,7 +23611,7 @@ class BaseDocumentDriveServer {
|
|
|
23509
23611
|
});
|
|
23510
23612
|
const lastRemainingOperation = documentOperations[scope].at(-1);
|
|
23511
23613
|
if (lastRemainingOperation && !lastRemainingOperation.resultingState) {
|
|
23512
|
-
lastRemainingOperation.resultingState = await (documentId ? (_b = (_a2 = this.
|
|
23614
|
+
lastRemainingOperation.resultingState = await (documentId ? (_b = (_a2 = this.legacyStorage).getOperationResultingState) == null ? void 0 : _b.call(_a2, driveId, documentId, lastRemainingOperation.index, lastRemainingOperation.scope, "main") : (_d = (_c = this.legacyStorage).getDriveOperationResultingState) == null ? void 0 : _d.call(_c, driveId, lastRemainingOperation.index, lastRemainingOperation.scope, "main"));
|
|
23513
23615
|
}
|
|
23514
23616
|
const operationSignals = [];
|
|
23515
23617
|
newDocument = documentModelModule.reducer(newDocument, operation, (signal) => {
|
|
@@ -23556,14 +23658,14 @@ class BaseDocumentDriveServer {
|
|
|
23556
23658
|
return this.addOperations(driveId, documentId, [operation], options);
|
|
23557
23659
|
}
|
|
23558
23660
|
async _addOperations(driveId, documentId, callback) {
|
|
23559
|
-
if (!this.
|
|
23560
|
-
const documentStorage = await this.
|
|
23661
|
+
if (!this.legacyStorage.addDocumentOperationsWithTransaction) {
|
|
23662
|
+
const documentStorage = await this.documentStorage.get(documentId);
|
|
23561
23663
|
const result = await callback(documentStorage);
|
|
23562
23664
|
if (result.operations.length > 0) {
|
|
23563
|
-
await this.
|
|
23665
|
+
await this.legacyStorage.addDocumentOperations(driveId, documentId, result.operations, result.header);
|
|
23564
23666
|
}
|
|
23565
23667
|
} else {
|
|
23566
|
-
await this.
|
|
23668
|
+
await this.legacyStorage.addDocumentOperationsWithTransaction(driveId, documentId, callback);
|
|
23567
23669
|
}
|
|
23568
23670
|
}
|
|
23569
23671
|
queueOperation(driveId, documentId, operation, options) {
|
|
@@ -23595,33 +23697,35 @@ class BaseDocumentDriveServer {
|
|
|
23595
23697
|
if (result) {
|
|
23596
23698
|
return result;
|
|
23597
23699
|
}
|
|
23700
|
+
let jobId;
|
|
23701
|
+
const promise = new Promise((resolve, reject) => {
|
|
23702
|
+
const unsubscribe = this.queueManager.on("jobCompleted", (job, result2) => {
|
|
23703
|
+
if (job.jobId === jobId) {
|
|
23704
|
+
unsubscribe();
|
|
23705
|
+
unsubscribeError();
|
|
23706
|
+
resolve(result2);
|
|
23707
|
+
}
|
|
23708
|
+
});
|
|
23709
|
+
const unsubscribeError = this.queueManager.on("jobFailed", (job, error) => {
|
|
23710
|
+
if (job.jobId === jobId) {
|
|
23711
|
+
unsubscribe();
|
|
23712
|
+
unsubscribeError();
|
|
23713
|
+
reject(error);
|
|
23714
|
+
}
|
|
23715
|
+
});
|
|
23716
|
+
});
|
|
23598
23717
|
try {
|
|
23599
|
-
|
|
23718
|
+
jobId = await this.queueManager.addJob({
|
|
23600
23719
|
driveId,
|
|
23601
23720
|
documentId,
|
|
23602
23721
|
operations,
|
|
23603
23722
|
options
|
|
23604
23723
|
});
|
|
23605
|
-
return new Promise((resolve, reject) => {
|
|
23606
|
-
const unsubscribe = this.queueManager.on("jobCompleted", (job, result2) => {
|
|
23607
|
-
if (job.jobId === jobId) {
|
|
23608
|
-
unsubscribe();
|
|
23609
|
-
unsubscribeError();
|
|
23610
|
-
resolve(result2);
|
|
23611
|
-
}
|
|
23612
|
-
});
|
|
23613
|
-
const unsubscribeError = this.queueManager.on("jobFailed", (job, error) => {
|
|
23614
|
-
if (job.jobId === jobId) {
|
|
23615
|
-
unsubscribe();
|
|
23616
|
-
unsubscribeError();
|
|
23617
|
-
reject(error);
|
|
23618
|
-
}
|
|
23619
|
-
});
|
|
23620
|
-
});
|
|
23621
23724
|
} catch (error) {
|
|
23622
|
-
logger
|
|
23725
|
+
this.logger.error("Error adding job", error);
|
|
23623
23726
|
throw error;
|
|
23624
23727
|
}
|
|
23728
|
+
return promise;
|
|
23625
23729
|
}
|
|
23626
23730
|
async queueAction(driveId, documentId, action, options) {
|
|
23627
23731
|
return this.queueActions(driveId, documentId, [action], options);
|
|
@@ -23651,7 +23755,7 @@ class BaseDocumentDriveServer {
|
|
|
23651
23755
|
});
|
|
23652
23756
|
});
|
|
23653
23757
|
} catch (error) {
|
|
23654
|
-
logger
|
|
23758
|
+
this.logger.error("Error adding job", error);
|
|
23655
23759
|
throw error;
|
|
23656
23760
|
}
|
|
23657
23761
|
}
|
|
@@ -23682,7 +23786,7 @@ class BaseDocumentDriveServer {
|
|
|
23682
23786
|
});
|
|
23683
23787
|
});
|
|
23684
23788
|
} catch (error) {
|
|
23685
|
-
logger
|
|
23789
|
+
this.logger.error("Error adding drive job", error);
|
|
23686
23790
|
throw error;
|
|
23687
23791
|
}
|
|
23688
23792
|
}
|
|
@@ -23699,7 +23803,7 @@ class BaseDocumentDriveServer {
|
|
|
23699
23803
|
await this._addOperations(driveId, documentId, async (documentStorage) => {
|
|
23700
23804
|
const result2 = await this._processOperations(driveId, documentId, documentStorage, operations);
|
|
23701
23805
|
if (!result2.document) {
|
|
23702
|
-
logger
|
|
23806
|
+
this.logger.error("Invalid document");
|
|
23703
23807
|
throw result2.error ?? new Error("Invalid document");
|
|
23704
23808
|
}
|
|
23705
23809
|
document = result2.document;
|
|
@@ -23713,7 +23817,7 @@ class BaseDocumentDriveServer {
|
|
|
23713
23817
|
};
|
|
23714
23818
|
});
|
|
23715
23819
|
if (document) {
|
|
23716
|
-
this.cache.setDocument(documentId, document).catch(logger
|
|
23820
|
+
this.cache.setDocument(documentId, document).catch(this.logger.error);
|
|
23717
23821
|
}
|
|
23718
23822
|
const { scopes, branches } = operationsApplied.reduce((acc, operation) => {
|
|
23719
23823
|
if (!acc.scopes.includes(operation.scope)) {
|
|
@@ -23746,7 +23850,7 @@ class BaseDocumentDriveServer {
|
|
|
23746
23850
|
});
|
|
23747
23851
|
}
|
|
23748
23852
|
}).catch((error2) => {
|
|
23749
|
-
logger
|
|
23853
|
+
this.logger.error("Non handled error updating sync revision", error2);
|
|
23750
23854
|
this.synchronizationManager.updateSyncStatus(driveId, {
|
|
23751
23855
|
[operationSource]: "ERROR"
|
|
23752
23856
|
}, error2);
|
|
@@ -23784,18 +23888,18 @@ class BaseDocumentDriveServer {
|
|
|
23784
23888
|
for (const drive of await this.getDrives()) {
|
|
23785
23889
|
await this.deleteDrive(drive);
|
|
23786
23890
|
}
|
|
23787
|
-
await ((_b = (_a2 = this.
|
|
23891
|
+
await ((_b = (_a2 = this.legacyStorage).clearStorage) == null ? void 0 : _b.call(_a2));
|
|
23788
23892
|
}
|
|
23789
23893
|
async _addDriveOperations(driveId, callback) {
|
|
23790
|
-
if (!this.
|
|
23791
|
-
const documentStorage = await this.
|
|
23894
|
+
if (!this.legacyStorage.addDriveOperationsWithTransaction) {
|
|
23895
|
+
const documentStorage = await this.documentStorage.get(driveId);
|
|
23792
23896
|
const result = await callback(documentStorage);
|
|
23793
23897
|
if (result.operations.length > 0) {
|
|
23794
|
-
await this.
|
|
23898
|
+
await this.legacyStorage.addDriveOperations(driveId, result.operations, result.header);
|
|
23795
23899
|
}
|
|
23796
23900
|
return result;
|
|
23797
23901
|
} else {
|
|
23798
|
-
return this.
|
|
23902
|
+
return this.legacyStorage.addDriveOperationsWithTransaction(driveId, callback);
|
|
23799
23903
|
}
|
|
23800
23904
|
}
|
|
23801
23905
|
queueDriveOperation(driveId, operation, options) {
|
|
@@ -23848,7 +23952,7 @@ class BaseDocumentDriveServer {
|
|
|
23848
23952
|
});
|
|
23849
23953
|
});
|
|
23850
23954
|
} catch (error) {
|
|
23851
|
-
logger
|
|
23955
|
+
this.logger.error("Error adding drive job", error);
|
|
23852
23956
|
throw error;
|
|
23853
23957
|
}
|
|
23854
23958
|
}
|
|
@@ -23876,7 +23980,7 @@ class BaseDocumentDriveServer {
|
|
|
23876
23980
|
if (!document || !isDocumentDrive(document)) {
|
|
23877
23981
|
throw error ?? new Error("Invalid Document Drive document");
|
|
23878
23982
|
}
|
|
23879
|
-
this.cache.setDrive(driveId, document).catch(logger
|
|
23983
|
+
this.cache.setDrive(driveId, document).catch(this.logger.error);
|
|
23880
23984
|
const lastOperation = operationsApplied.filter((op) => op.scope === "global").slice().pop();
|
|
23881
23985
|
if (lastOperation) {
|
|
23882
23986
|
const newOp = operationsApplied.find((appliedOp) => !operations.find((o) => o.id === appliedOp.id && o.index === appliedOp.index && o.skip === appliedOp.skip && o.hash === appliedOp.hash));
|
|
@@ -23903,7 +24007,7 @@ class BaseDocumentDriveServer {
|
|
|
23903
24007
|
});
|
|
23904
24008
|
}
|
|
23905
24009
|
}).catch((error2) => {
|
|
23906
|
-
logger
|
|
24010
|
+
this.logger.error("Non handled error updating sync revision", error2);
|
|
23907
24011
|
this.synchronizationManager.updateSyncStatus(driveId, {
|
|
23908
24012
|
[operationSource]: "ERROR"
|
|
23909
24013
|
}, error2);
|
|
@@ -24005,9 +24109,26 @@ class BaseDocumentDriveServer {
|
|
|
24005
24109
|
scope: strand.scope,
|
|
24006
24110
|
branch: strand.branch
|
|
24007
24111
|
}));
|
|
24008
|
-
|
|
24009
|
-
|
|
24010
|
-
|
|
24112
|
+
let result;
|
|
24113
|
+
if (strand.documentId) {
|
|
24114
|
+
try {
|
|
24115
|
+
result = await this.queueOperations(strand.driveId, strand.documentId, operations, {
|
|
24116
|
+
source
|
|
24117
|
+
});
|
|
24118
|
+
} catch (error) {
|
|
24119
|
+
this.logger.error("Error queueing operations", error);
|
|
24120
|
+
throw error;
|
|
24121
|
+
}
|
|
24122
|
+
} else {
|
|
24123
|
+
try {
|
|
24124
|
+
result = await this.queueDriveOperations(strand.driveId, operations, {
|
|
24125
|
+
source
|
|
24126
|
+
});
|
|
24127
|
+
} catch (error) {
|
|
24128
|
+
this.logger.error("Error queueing operations", error);
|
|
24129
|
+
throw error;
|
|
24130
|
+
}
|
|
24131
|
+
}
|
|
24011
24132
|
if (result.status === "ERROR") {
|
|
24012
24133
|
const syncUnits = strand.documentId !== "" ? (await this.getSynchronizationUnitsIds(strand.driveId, [strand.documentId], [strand.scope], [strand.branch])).map((s) => s.syncId) : [strand.driveId];
|
|
24013
24134
|
const operationSource = this.getOperationSource(source);
|
|
@@ -24031,7 +24152,7 @@ class MemoryStorage {
|
|
|
24031
24152
|
// IDocumentStorage
|
|
24032
24153
|
////////////////////////////////
|
|
24033
24154
|
exists(documentId) {
|
|
24034
|
-
return Promise.resolve(!!this.documents[documentId]
|
|
24155
|
+
return Promise.resolve(!!this.documents[documentId]);
|
|
24035
24156
|
}
|
|
24036
24157
|
create(documentId, document) {
|
|
24037
24158
|
this.documents[documentId] = document;
|
|
@@ -24040,10 +24161,6 @@ class MemoryStorage {
|
|
|
24040
24161
|
get(documentId) {
|
|
24041
24162
|
const document = this.documents[documentId];
|
|
24042
24163
|
if (!document) {
|
|
24043
|
-
const drive = this.documents[`drive/${documentId}`];
|
|
24044
|
-
if (drive) {
|
|
24045
|
-
return Promise.resolve(drive);
|
|
24046
|
-
}
|
|
24047
24164
|
throw new Error(`Document with id ${documentId} not found`);
|
|
24048
24165
|
}
|
|
24049
24166
|
return Promise.resolve(document);
|
|
@@ -24096,9 +24213,6 @@ class MemoryStorage {
|
|
|
24096
24213
|
const manifest = this.getManifest(drive);
|
|
24097
24214
|
return Promise.resolve([...manifest.documentIds]);
|
|
24098
24215
|
}
|
|
24099
|
-
getDocument(driveId, id) {
|
|
24100
|
-
return this.get(id);
|
|
24101
|
-
}
|
|
24102
24216
|
async clearStorage() {
|
|
24103
24217
|
this.documents = {};
|
|
24104
24218
|
this.driveManifests = {};
|
|
@@ -24110,7 +24224,7 @@ class MemoryStorage {
|
|
|
24110
24224
|
this.updateDriveManifest(drive, manifest);
|
|
24111
24225
|
}
|
|
24112
24226
|
async addDocumentOperations(drive, id, operations, header) {
|
|
24113
|
-
const document = await this.
|
|
24227
|
+
const document = await this.get(id);
|
|
24114
24228
|
if (!document) {
|
|
24115
24229
|
throw new Error(`Document with id ${id} not found`);
|
|
24116
24230
|
}
|
|
@@ -24127,16 +24241,9 @@ class MemoryStorage {
|
|
|
24127
24241
|
async getDrives() {
|
|
24128
24242
|
return Object.keys(this.driveManifests);
|
|
24129
24243
|
}
|
|
24130
|
-
async getDrive(id) {
|
|
24131
|
-
const drive = this.documents[`drive/${id}`];
|
|
24132
|
-
if (!drive) {
|
|
24133
|
-
throw new DriveNotFoundError(id);
|
|
24134
|
-
}
|
|
24135
|
-
return drive;
|
|
24136
|
-
}
|
|
24137
24244
|
async getDriveBySlug(slug) {
|
|
24138
24245
|
for (const driveId of Object.keys(this.driveManifests)) {
|
|
24139
|
-
const drive = this.documents[
|
|
24246
|
+
const drive = this.documents[driveId];
|
|
24140
24247
|
if (drive.initialState.state.global.slug === slug) {
|
|
24141
24248
|
return drive;
|
|
24142
24249
|
}
|
|
@@ -24155,13 +24262,13 @@ class MemoryStorage {
|
|
|
24155
24262
|
throw new Error(`Drive with slug ${slug} already exists`);
|
|
24156
24263
|
}
|
|
24157
24264
|
}
|
|
24158
|
-
await this.create(
|
|
24265
|
+
await this.create(id, drive);
|
|
24159
24266
|
this.updateDriveManifest(id, { documentIds: /* @__PURE__ */ new Set() });
|
|
24160
24267
|
}
|
|
24161
24268
|
async addDriveOperations(id, operations, header) {
|
|
24162
|
-
const drive = await this.
|
|
24269
|
+
const drive = await this.get(id);
|
|
24163
24270
|
const mergedOperations = mergeOperations(drive.operations, operations);
|
|
24164
|
-
this.documents[
|
|
24271
|
+
this.documents[id] = {
|
|
24165
24272
|
...drive,
|
|
24166
24273
|
...header,
|
|
24167
24274
|
operations: mergedOperations
|
|
@@ -24381,11 +24488,10 @@ const _ListenerManager = class _ListenerManager {
|
|
|
24381
24488
|
throw new Error("Maximum retries exhausted.");
|
|
24382
24489
|
}
|
|
24383
24490
|
const listenerUpdates = [];
|
|
24384
|
-
for (const [driveId,
|
|
24385
|
-
for (const [listenerId, listenerState] of
|
|
24491
|
+
for (const [driveId, listenerStateById] of this.listenerStateByDriveId) {
|
|
24492
|
+
for (const [listenerId, listenerState] of listenerStateById) {
|
|
24386
24493
|
const transmitter = listenerState.listener.transmitter;
|
|
24387
24494
|
if (!(transmitter == null ? void 0 : transmitter.transmit)) {
|
|
24388
|
-
this.logger.verbose(`Transmitter not set on listener: ${listenerId}`);
|
|
24389
24495
|
continue;
|
|
24390
24496
|
}
|
|
24391
24497
|
const syncUnits = await this.getListenerSyncUnits(driveId, listenerId);
|
|
@@ -24539,57 +24645,78 @@ const _ListenerManager = class _ListenerManager {
|
|
|
24539
24645
|
}
|
|
24540
24646
|
}
|
|
24541
24647
|
async getStrands(driveId, listenerId, options) {
|
|
24542
|
-
|
|
24648
|
+
this.logger.verbose(`[SYNC DEBUG] ListenerManager.getStrands called for drive: ${driveId}, listener: ${listenerId}, options: ${JSON.stringify(options || {})}`);
|
|
24649
|
+
let listenerState;
|
|
24650
|
+
try {
|
|
24651
|
+
listenerState = this.getListenerState(driveId, listenerId);
|
|
24652
|
+
this.logger.verbose(`[SYNC DEBUG] Found listener state for drive: ${driveId}, listener: ${listenerId}, status: ${listenerState.listenerStatus}`);
|
|
24653
|
+
} catch (error) {
|
|
24654
|
+
this.logger.error(`[SYNC DEBUG] Failed to find listener state for drive: ${driveId}, listener: ${listenerId}. Error: ${error}`);
|
|
24655
|
+
throw error;
|
|
24656
|
+
}
|
|
24543
24657
|
const strands = [];
|
|
24544
|
-
|
|
24545
|
-
|
|
24546
|
-
|
|
24547
|
-
|
|
24548
|
-
|
|
24549
|
-
|
|
24550
|
-
|
|
24551
|
-
|
|
24552
|
-
|
|
24553
|
-
|
|
24554
|
-
|
|
24555
|
-
|
|
24556
|
-
|
|
24557
|
-
|
|
24558
|
-
|
|
24559
|
-
|
|
24560
|
-
|
|
24561
|
-
|
|
24562
|
-
|
|
24563
|
-
|
|
24564
|
-
{
|
|
24565
|
-
|
|
24566
|
-
|
|
24567
|
-
|
|
24658
|
+
try {
|
|
24659
|
+
const syncUnits = await this.getListenerSyncUnits(driveId, listenerId);
|
|
24660
|
+
this.logger.verbose(`[SYNC DEBUG] Retrieved ${syncUnits.length} sync units for drive: ${driveId}, listener: ${listenerId}`);
|
|
24661
|
+
const limit = options == null ? void 0 : options.limit;
|
|
24662
|
+
let operationsCount = 0;
|
|
24663
|
+
const tasks = syncUnits.map((syncUnit) => async () => {
|
|
24664
|
+
if (limit && operationsCount >= limit) {
|
|
24665
|
+
return;
|
|
24666
|
+
}
|
|
24667
|
+
if (syncUnit.revision < 0) {
|
|
24668
|
+
this.logger.verbose(`[SYNC DEBUG] Skipping sync unit with negative revision: ${syncUnit.syncId}, revision: ${syncUnit.revision}`);
|
|
24669
|
+
return;
|
|
24670
|
+
}
|
|
24671
|
+
const entry = listenerState.syncUnits.get(syncUnit.syncId);
|
|
24672
|
+
if (entry && entry.listenerRev >= syncUnit.revision) {
|
|
24673
|
+
this.logger.verbose(`[SYNC DEBUG] Skipping sync unit - listener already up to date: ${syncUnit.syncId}, listenerRev: ${entry.listenerRev}, revision: ${syncUnit.revision}`);
|
|
24674
|
+
return;
|
|
24675
|
+
}
|
|
24676
|
+
const { documentId, scope, branch } = syncUnit;
|
|
24677
|
+
try {
|
|
24678
|
+
this.logger.verbose(`[SYNC DEBUG] Getting operations for syncUnit: ${syncUnit.syncId}, documentId: ${documentId}, scope: ${scope}, branch: ${branch}`);
|
|
24679
|
+
const operations = await this.syncManager.getOperationData(
|
|
24680
|
+
// DEAL WITH INVALID SYNC ID ERROR
|
|
24681
|
+
driveId,
|
|
24682
|
+
syncUnit.syncId,
|
|
24683
|
+
{
|
|
24684
|
+
since: options == null ? void 0 : options.since,
|
|
24685
|
+
fromRevision: (options == null ? void 0 : options.fromRevision) ?? (entry == null ? void 0 : entry.listenerRev),
|
|
24686
|
+
limit: limit ? limit - operationsCount : void 0
|
|
24687
|
+
}
|
|
24688
|
+
);
|
|
24689
|
+
this.logger.verbose(`[SYNC DEBUG] Retrieved ${operations.length} operations for syncUnit: ${syncUnit.syncId}`);
|
|
24690
|
+
if (!operations.length) {
|
|
24691
|
+
return;
|
|
24568
24692
|
}
|
|
24569
|
-
|
|
24570
|
-
|
|
24693
|
+
operationsCount += operations.length;
|
|
24694
|
+
strands.push({
|
|
24695
|
+
driveId,
|
|
24696
|
+
documentId,
|
|
24697
|
+
scope,
|
|
24698
|
+
branch,
|
|
24699
|
+
operations
|
|
24700
|
+
});
|
|
24701
|
+
this.logger.verbose(`[SYNC DEBUG] Added strand with ${operations.length} operations for syncUnit: ${syncUnit.syncId}`);
|
|
24702
|
+
} catch (error) {
|
|
24703
|
+
this.logger.error(`Error getting operations for syncUnit: ${syncUnit.syncId}, error: ${error}`);
|
|
24571
24704
|
return;
|
|
24572
24705
|
}
|
|
24573
|
-
|
|
24574
|
-
|
|
24575
|
-
|
|
24576
|
-
|
|
24577
|
-
|
|
24578
|
-
|
|
24579
|
-
|
|
24580
|
-
});
|
|
24581
|
-
|
|
24582
|
-
this.logger.error(error);
|
|
24583
|
-
return;
|
|
24584
|
-
}
|
|
24585
|
-
});
|
|
24586
|
-
if (this.options.sequentialUpdates) {
|
|
24587
|
-
for (const task of tasks) {
|
|
24588
|
-
await task();
|
|
24706
|
+
});
|
|
24707
|
+
if (this.options.sequentialUpdates) {
|
|
24708
|
+
this.logger.verbose(`[SYNC DEBUG] Processing ${tasks.length} sync units sequentially`);
|
|
24709
|
+
for (const task of tasks) {
|
|
24710
|
+
await task();
|
|
24711
|
+
}
|
|
24712
|
+
} else {
|
|
24713
|
+
this.logger.verbose(`[SYNC DEBUG] Processing ${tasks.length} sync units in parallel`);
|
|
24714
|
+
await Promise.all(tasks.map((task) => task()));
|
|
24589
24715
|
}
|
|
24590
|
-
}
|
|
24591
|
-
|
|
24716
|
+
} catch (error) {
|
|
24717
|
+
this.logger.error(`Error in getStrands: ${error}`);
|
|
24592
24718
|
}
|
|
24719
|
+
this.logger.verbose(`ListenerManager.getStrands returning ${strands.length} strands for drive: ${driveId}, listener: ${listenerId}`);
|
|
24593
24720
|
return strands;
|
|
24594
24721
|
}
|
|
24595
24722
|
getListenerState(driveId, listenerId) {
|
|
@@ -24639,40 +24766,49 @@ class TransmitterFactory {
|
|
|
24639
24766
|
}
|
|
24640
24767
|
}
|
|
24641
24768
|
class SynchronizationManager {
|
|
24642
|
-
constructor(storage, cache, documentModelModules, eventEmitter) {
|
|
24769
|
+
constructor(storage, documentStorage, cache, documentModelModules, eventEmitter) {
|
|
24643
24770
|
__publicField(this, "storage");
|
|
24771
|
+
__publicField(this, "documentStorage");
|
|
24644
24772
|
__publicField(this, "cache");
|
|
24645
24773
|
__publicField(this, "documentModelModules");
|
|
24646
24774
|
__publicField(this, "eventEmitter");
|
|
24647
24775
|
__publicField(this, "syncStatus", /* @__PURE__ */ new Map());
|
|
24648
24776
|
__publicField(this, "logger", childLogger(["SynchronizationManager"]));
|
|
24649
24777
|
this.storage = storage;
|
|
24778
|
+
this.documentStorage = documentStorage;
|
|
24650
24779
|
this.cache = cache;
|
|
24651
24780
|
this.documentModelModules = documentModelModules;
|
|
24652
24781
|
this.eventEmitter = eventEmitter;
|
|
24653
24782
|
}
|
|
24654
24783
|
async getSynchronizationUnits(driveId, documentId, scope, branch, documentType2) {
|
|
24655
24784
|
const synchronizationUnitsQuery = await this.getSynchronizationUnitsIds(driveId, documentId, scope, branch, documentType2);
|
|
24785
|
+
this.logger.verbose(`getSynchronizationUnits query: ${JSON.stringify(synchronizationUnitsQuery)}`);
|
|
24656
24786
|
return this.getSynchronizationUnitsRevision(driveId, synchronizationUnitsQuery);
|
|
24657
24787
|
}
|
|
24658
24788
|
async getSynchronizationUnitsRevision(driveId, syncUnitsQuery) {
|
|
24659
24789
|
const drive = await this.getDrive(driveId);
|
|
24660
24790
|
const revisions = await this.storage.getSynchronizationUnitsRevision(syncUnitsQuery);
|
|
24661
|
-
|
|
24662
|
-
|
|
24663
|
-
|
|
24664
|
-
|
|
24665
|
-
|
|
24666
|
-
|
|
24667
|
-
|
|
24668
|
-
|
|
24791
|
+
this.logger.verbose(`getSynchronizationUnitsRevision: ${JSON.stringify(revisions)}`);
|
|
24792
|
+
const synchronizationUnits = syncUnitsQuery.map((s) => ({
|
|
24793
|
+
...s,
|
|
24794
|
+
lastUpdated: drive.created,
|
|
24795
|
+
revision: -1
|
|
24796
|
+
}));
|
|
24797
|
+
for (const revision of revisions) {
|
|
24798
|
+
const syncUnit = synchronizationUnits.find((s) => revision.documentId === s.documentId && revision.scope === s.scope && revision.branch === s.branch);
|
|
24799
|
+
if (syncUnit) {
|
|
24800
|
+
syncUnit.revision = revision.revision;
|
|
24801
|
+
syncUnit.lastUpdated = revision.lastUpdated;
|
|
24802
|
+
}
|
|
24803
|
+
}
|
|
24804
|
+
return synchronizationUnits;
|
|
24669
24805
|
}
|
|
24670
24806
|
async getSynchronizationUnitsIds(driveId, documentId, scope, branch, documentType2) {
|
|
24671
24807
|
const drive = await this.getDrive(driveId);
|
|
24672
24808
|
const nodes = drive.state.global.nodes.filter((node) => isFileNode(node) && (!(documentId == null ? void 0 : documentId.length) || documentId.includes(node.id) || documentId.includes("*")) && (!(documentType2 == null ? void 0 : documentType2.length) || documentType2.includes(node.documentType) || documentType2.includes("*")));
|
|
24673
24809
|
if ((!documentId || documentId.includes("*") || documentId.includes("")) && (!(documentType2 == null ? void 0 : documentType2.length) || documentType2.includes("powerhouse/document-drive") || documentType2.includes("*"))) {
|
|
24674
24810
|
nodes.unshift({
|
|
24675
|
-
id:
|
|
24811
|
+
id: driveId,
|
|
24676
24812
|
documentType: "powerhouse/document-drive",
|
|
24677
24813
|
synchronizationUnits: [
|
|
24678
24814
|
{
|
|
@@ -24738,14 +24874,27 @@ class SynchronizationManager {
|
|
|
24738
24874
|
};
|
|
24739
24875
|
}
|
|
24740
24876
|
async getOperationData(driveId, syncId, filter) {
|
|
24877
|
+
this.logger.verbose(`[SYNC DEBUG] SynchronizationManager.getOperationData called for drive: ${driveId}, syncId: ${syncId}, filter: ${JSON.stringify(filter)}`);
|
|
24741
24878
|
const syncUnit = syncId === "0" ? { documentId: "", scope: "global" } : await this.getSynchronizationUnitIdInfo(driveId, syncId);
|
|
24742
24879
|
if (!syncUnit) {
|
|
24880
|
+
this.logger.error(`SYNC DEBUG] Invalid Sync Id ${syncId} in drive ${driveId}`);
|
|
24743
24881
|
throw new Error(`Invalid Sync Id ${syncId} in drive ${driveId}`);
|
|
24744
24882
|
}
|
|
24883
|
+
this.logger.verbose(`[SYNC DEBUG] Found sync unit: documentId: ${syncUnit.documentId}, scope: ${syncUnit.scope}`);
|
|
24745
24884
|
const document = syncId === "0" ? await this.getDrive(driveId) : await this.getDocument(driveId, syncUnit.documentId);
|
|
24885
|
+
this.logger.verbose(`[SYNC DEBUG] Retrieved document ${syncUnit.documentId} with type: ${document.documentType}`);
|
|
24746
24886
|
const operations = document.operations[syncUnit.scope] ?? [];
|
|
24887
|
+
this.logger.verbose(`[SYNC DEBUG] Found ${operations.length} total operations in scope ${syncUnit.scope}`);
|
|
24747
24888
|
const filteredOperations = operations.filter((operation) => Object.keys(filter).length === 0 || (filter.since === void 0 || isBefore(filter.since, operation.timestamp)) && (filter.fromRevision === void 0 || operation.index > filter.fromRevision));
|
|
24889
|
+
this.logger.verbose(`[SYNC DEBUG] Filtered to ${filteredOperations.length} operations based on filter criteria` + (filter.fromRevision !== void 0 ? ` (fromRevision: ${filter.fromRevision})` : ""));
|
|
24748
24890
|
const limitedOperations = filter.limit ? filteredOperations.slice(0, filter.limit) : filteredOperations;
|
|
24891
|
+
this.logger.verbose(`[SYNC DEBUG] Returning ${limitedOperations.length} operations after applying limit`);
|
|
24892
|
+
if (limitedOperations.length > 0) {
|
|
24893
|
+
const firstOp = limitedOperations[0];
|
|
24894
|
+
const lastOp = limitedOperations[limitedOperations.length - 1];
|
|
24895
|
+
this.logger.verbose(`[SYNC DEBUG] First operation: index=${firstOp.index}, type=${firstOp.type}`);
|
|
24896
|
+
this.logger.verbose(`[SYNC DEBUG] Last operation: index=${lastOp.index}, type=${lastOp.type}`);
|
|
24897
|
+
}
|
|
24749
24898
|
return limitedOperations.map((operation) => ({
|
|
24750
24899
|
hash: operation.hash,
|
|
24751
24900
|
index: operation.index,
|
|
@@ -24766,7 +24915,7 @@ class SynchronizationManager {
|
|
|
24766
24915
|
} catch (e) {
|
|
24767
24916
|
this.logger.error("Error getting drive from cache", e);
|
|
24768
24917
|
}
|
|
24769
|
-
const driveStorage = await this.
|
|
24918
|
+
const driveStorage = await this.documentStorage.get(driveId);
|
|
24770
24919
|
const result = this._buildDocument(driveStorage);
|
|
24771
24920
|
if (!isDocumentDrive(result)) {
|
|
24772
24921
|
throw new Error(`Document with id ${driveId} is not a Document Drive`);
|
|
@@ -24782,7 +24931,7 @@ class SynchronizationManager {
|
|
|
24782
24931
|
} catch (e) {
|
|
24783
24932
|
this.logger.error("Error getting document from cache", e);
|
|
24784
24933
|
}
|
|
24785
|
-
const documentStorage = await this.
|
|
24934
|
+
const documentStorage = await this.documentStorage.get(documentId);
|
|
24786
24935
|
return this._buildDocument(documentStorage);
|
|
24787
24936
|
}
|
|
24788
24937
|
_buildDocument(documentStorage) {
|
|
@@ -24943,7 +25092,14 @@ class ReactorBuilder {
|
|
|
24943
25092
|
this.eventEmitter = new DefaultEventEmitter();
|
|
24944
25093
|
}
|
|
24945
25094
|
if (!this.synchronizationManager) {
|
|
24946
|
-
this.synchronizationManager = new SynchronizationManager(
|
|
25095
|
+
this.synchronizationManager = new SynchronizationManager(
|
|
25096
|
+
this.storage,
|
|
25097
|
+
// as we refactor, we're secretly making all the IStorage implementations also implement IDocumentStorage
|
|
25098
|
+
this.storage,
|
|
25099
|
+
this.cache,
|
|
25100
|
+
this.documentModelModules,
|
|
25101
|
+
this.eventEmitter
|
|
25102
|
+
);
|
|
24947
25103
|
}
|
|
24948
25104
|
if (!this.listenerManager) {
|
|
24949
25105
|
const config = {
|
|
@@ -25251,6 +25407,9 @@ function Modified(props) {
|
|
|
25251
25407
|
function Moved(props) {
|
|
25252
25408
|
return jsxs("svg", { ...props, width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [jsx("path", { d: "M7.07143 1.96429C7.07143 2.2207 6.86356 2.42857 6.60714 2.42857H5.21429C3.67578 2.42857 2.42857 3.67578 2.42857 5.21429V10.7857C2.42857 12.3242 3.67578 13.5714 5.21429 13.5714H10.7857C12.3242 13.5714 13.5714 12.3242 13.5714 10.7857V9.39286C13.5714 9.13644 13.7793 8.92857 14.0357 8.92857C14.2921 8.92857 14.5 9.13644 14.5 9.39286V10.7857C14.5 12.8371 12.8371 14.5 10.7857 14.5H5.21429C3.16294 14.5 1.5 12.8371 1.5 10.7857V5.21429C1.5 3.16294 3.16294 1.5 5.21429 1.5H6.60714C6.86356 1.5 7.07143 1.70787 7.07143 1.96429Z", fill: "currentcolor" }), jsx("path", { d: "M14 6.5V2.5C14 2.22386 13.7761 2 13.5 2H9.5", stroke: "currentcolor", strokeLinecap: "round" }), jsx("path", { d: "M7 10L7.28346 9.29136C8.39378 6.51556 10.4269 4.20728 13.0403 2.75539L13.5 2.5", stroke: "currentcolor", strokeLinecap: "round" })] });
|
|
25253
25409
|
}
|
|
25410
|
+
function Npm(props) {
|
|
25411
|
+
return jsx("svg", { ...props, xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 128 128", children: jsx("path", { fill: "#cb3837", d: "M2 38.5h124v43.71H64v7.29H36.44v-7.29H2zm6.89 36.43h13.78V53.07h6.89v21.86h6.89V45.79H8.89zm34.44-29.14v36.42h13.78v-7.28h13.78V45.79zm13.78 7.29H64v14.56h-6.89zm20.67-7.29v29.14h13.78V53.07h6.89v21.86h6.89V53.07h6.89v21.86h6.89V45.79z" }) });
|
|
25412
|
+
}
|
|
25254
25413
|
function PackageManager(props) {
|
|
25255
25414
|
return jsx("svg", { ...props, width: "12", height: "12", viewBox: "0 0 12 12", fill: "currentcolor", children: jsx("path", { d: "M1.22323 -0.00109863C0.549226 -0.00109863 -0.00610352 0.533576 -0.00610352 1.20691V2.79089C-0.00610352 3.46423 0.549226 3.9989 1.22323 3.9989H4.0979C4.7719 3.9989 5.32723 3.46423 5.32723 2.79089V1.20691C5.32723 0.533576 4.7719 -0.00109863 4.0979 -0.00109863H1.22323ZM7.9939 -0.00109863C7.25723 -0.00109863 6.66056 0.595568 6.66056 1.33223V5.33223C6.66056 6.0689 7.25723 6.66557 7.9939 6.66557H10.6606C11.3972 6.66557 11.9939 6.0689 11.9939 5.33223V1.33223C11.9939 0.595568 11.3972 -0.00109863 10.6606 -0.00109863H7.9939ZM1.32723 5.33223C0.590563 5.33223 -0.00610352 5.9289 -0.00610352 6.66557V10.6656C-0.00610352 11.4022 0.590563 11.9989 1.32723 11.9989H3.9939C4.73056 11.9989 5.32723 11.4022 5.32723 10.6656V6.66557C5.32723 5.9289 4.73056 5.33223 3.9939 5.33223H1.32723ZM7.88989 7.9989C7.21589 7.9989 6.66056 8.53358 6.66056 9.20691V10.7909C6.66056 11.4642 7.21589 11.9989 7.88989 11.9989H10.7646C11.4386 11.9989 11.9939 11.4642 11.9939 10.7909V9.20691C11.9939 8.53358 11.4386 7.9989 10.7646 7.9989H7.88989Z" }) });
|
|
25256
25415
|
}
|
|
@@ -25439,6 +25598,7 @@ const iconComponents = {
|
|
|
25439
25598
|
M,
|
|
25440
25599
|
Modified,
|
|
25441
25600
|
Moved,
|
|
25601
|
+
Npm,
|
|
25442
25602
|
PackageManager,
|
|
25443
25603
|
Pencil,
|
|
25444
25604
|
PeopleFill,
|
|
@@ -25616,7 +25776,7 @@ const nodeOptionsMap = {
|
|
|
25616
25776
|
};
|
|
25617
25777
|
const name = "@powerhousedao/connect";
|
|
25618
25778
|
const productName = "Powerhouse-Connect";
|
|
25619
|
-
const version$1 = "1.0.
|
|
25779
|
+
const version$1 = "1.0.11-dev.0";
|
|
25620
25780
|
const description = "Powerhouse Connect";
|
|
25621
25781
|
const main = "./dist/index.html";
|
|
25622
25782
|
const type = "module";
|
|
@@ -28496,9 +28656,6 @@ const _BrowserStorage = class _BrowserStorage {
|
|
|
28496
28656
|
const manifest = await this.getManifest(drive);
|
|
28497
28657
|
return manifest.documentIds;
|
|
28498
28658
|
}
|
|
28499
|
-
async getDocument(driveId, id) {
|
|
28500
|
-
return this.get(id);
|
|
28501
|
-
}
|
|
28502
28659
|
async createDocument(drive, id, document) {
|
|
28503
28660
|
await this.create(id, document);
|
|
28504
28661
|
const manifest = await this.getManifest(drive);
|
|
@@ -28520,7 +28677,7 @@ const _BrowserStorage = class _BrowserStorage {
|
|
|
28520
28677
|
return (await this.db).clear();
|
|
28521
28678
|
}
|
|
28522
28679
|
async addDocumentOperations(drive, id, operations, header) {
|
|
28523
|
-
const document = await this.
|
|
28680
|
+
const document = await this.get(id);
|
|
28524
28681
|
if (!document) {
|
|
28525
28682
|
throw new Error(`Document with id ${id} not found`);
|
|
28526
28683
|
}
|
|
@@ -28537,21 +28694,12 @@ const _BrowserStorage = class _BrowserStorage {
|
|
|
28537
28694
|
const keys = await db.keys();
|
|
28538
28695
|
return keys.filter((key) => key.startsWith(_BrowserStorage.MANIFEST_KEY)).map((key) => key.slice(_BrowserStorage.MANIFEST_KEY.length + _BrowserStorage.SEP.length));
|
|
28539
28696
|
}
|
|
28540
|
-
async getDrive(id) {
|
|
28541
|
-
let drive;
|
|
28542
|
-
try {
|
|
28543
|
-
drive = await this.get(id);
|
|
28544
|
-
} catch {
|
|
28545
|
-
throw new DriveNotFoundError(id);
|
|
28546
|
-
}
|
|
28547
|
-
return drive;
|
|
28548
|
-
}
|
|
28549
28697
|
async getDriveBySlug(slug) {
|
|
28550
28698
|
const drives = (await this.getDrives()).reverse();
|
|
28551
28699
|
for (const drive of drives) {
|
|
28552
|
-
const driveData = await this.
|
|
28700
|
+
const driveData = await this.get(drive);
|
|
28553
28701
|
if (driveData.initialState.state.global.slug === slug) {
|
|
28554
|
-
return
|
|
28702
|
+
return driveData;
|
|
28555
28703
|
}
|
|
28556
28704
|
}
|
|
28557
28705
|
throw new Error(`Drive with slug ${slug} not found`);
|
|
@@ -28579,7 +28727,7 @@ const _BrowserStorage = class _BrowserStorage {
|
|
|
28579
28727
|
return db.removeItem(this.buildDocumentKey(id));
|
|
28580
28728
|
}
|
|
28581
28729
|
async addDriveOperations(id, operations, header) {
|
|
28582
|
-
const drive = await this.
|
|
28730
|
+
const drive = await this.get(id);
|
|
28583
28731
|
const mergedOperations = mergeOperations(drive.operations, operations);
|
|
28584
28732
|
const db = await this.db;
|
|
28585
28733
|
await db.setItem(this.buildDocumentKey(id), {
|
|
@@ -28626,14 +28774,14 @@ const _BrowserStorage = class _BrowserStorage {
|
|
|
28626
28774
|
}
|
|
28627
28775
|
}
|
|
28628
28776
|
async migrateDrive(driveId) {
|
|
28629
|
-
const drive = await this.
|
|
28777
|
+
const drive = await this.get(driveId);
|
|
28630
28778
|
const migratedDrive = migrateDocumentOperationSignatures(drive);
|
|
28631
28779
|
if (migratedDrive !== drive) {
|
|
28632
28780
|
return (await this.db).setItem(this.buildDocumentKey(driveId), migratedDrive);
|
|
28633
28781
|
}
|
|
28634
28782
|
}
|
|
28635
28783
|
async migrateDocument(drive, id) {
|
|
28636
|
-
const document = await this.
|
|
28784
|
+
const document = await this.get(id);
|
|
28637
28785
|
const migratedDocument = migrateDocumentOperationSignatures(document);
|
|
28638
28786
|
if (migratedDocument !== document) {
|
|
28639
28787
|
return (await this.db).setItem(this.buildDocumentKey(id), migratedDocument);
|
|
@@ -31256,7 +31404,7 @@ if (window.__VITE_ENVS.MODE === "development") {
|
|
|
31256
31404
|
} else {
|
|
31257
31405
|
serviceWorkerManager.registerServiceWorker(false);
|
|
31258
31406
|
}
|
|
31259
|
-
const App = lazy(() => __vitePreload(() => import("./app-
|
|
31407
|
+
const App = lazy(() => __vitePreload(() => import("./app-CSB8ljfZ.js").then((n) => n.aN), true ? __vite__mapDeps([0,1,2]) : void 0));
|
|
31260
31408
|
const AppLoader = /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(App, {}) });
|
|
31261
31409
|
const appLoader = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
31262
31410
|
__proto__: null,
|