@filen/sync 0.1.1 → 0.1.3

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.
Files changed (43) hide show
  1. package/LICENSE +661 -661
  2. package/README.md +1 -1
  3. package/SECURITY.md +17 -17
  4. package/dist/constants.d.ts +7 -0
  5. package/dist/constants.js +51 -1
  6. package/dist/constants.js.map +1 -1
  7. package/dist/ignorer.d.ts +14 -0
  8. package/dist/ignorer.js +69 -0
  9. package/dist/ignorer.js.map +1 -0
  10. package/dist/index.d.ts +27 -6
  11. package/dist/index.js +113 -13
  12. package/dist/index.js.map +1 -1
  13. package/dist/lib/deltas.d.ts +9 -31
  14. package/dist/lib/deltas.js +59 -65
  15. package/dist/lib/deltas.js.map +1 -1
  16. package/dist/lib/filesystems/local.d.ts +25 -20
  17. package/dist/lib/filesystems/local.js +203 -55
  18. package/dist/lib/filesystems/local.js.map +1 -1
  19. package/dist/lib/filesystems/remote.d.ts +18 -7
  20. package/dist/lib/filesystems/remote.js +435 -61
  21. package/dist/lib/filesystems/remote.js.map +1 -1
  22. package/dist/lib/ipc.d.ts +9 -0
  23. package/dist/lib/ipc.js +56 -0
  24. package/dist/lib/ipc.js.map +1 -0
  25. package/dist/lib/logger.d.ts +14 -0
  26. package/dist/lib/logger.js +93 -0
  27. package/dist/lib/logger.js.map +1 -0
  28. package/dist/lib/state.d.ts +4 -15
  29. package/dist/lib/state.js +16 -29
  30. package/dist/lib/state.js.map +1 -1
  31. package/dist/lib/sync.d.ts +23 -9
  32. package/dist/lib/sync.js +242 -28
  33. package/dist/lib/sync.js.map +1 -1
  34. package/dist/lib/tasks.d.ts +18 -33
  35. package/dist/lib/tasks.js +52 -29
  36. package/dist/lib/tasks.js.map +1 -1
  37. package/dist/types.d.ts +175 -0
  38. package/dist/utils.d.ts +24 -0
  39. package/dist/utils.js +132 -1
  40. package/dist/utils.js.map +1 -1
  41. package/package.json +60 -58
  42. package/tsconfig.json +24 -24
  43. package/index.d.ts +0 -298
package/README.md CHANGED
@@ -1 +1 @@
1
- work in progress, do not use it yet nor report issues/request features
1
+ work in progress, do not use it yet nor report issues/request features
package/SECURITY.md CHANGED
@@ -1,17 +1,17 @@
1
- # Security Policy
2
-
3
- ## Supported Versions
4
-
5
- The latest release version of filen-sdk-ts is currently being supported with security updates
6
-
7
- ## Reporting a Vulnerability
8
-
9
- Security is very important to us. If you have discovered a security issue with filen-sdk-ts,
10
- please read our responsible disclosure guidelines and contact us at [https://support.filen.io](https://support.filen.io).
11
- Your report should include:
12
-
13
- - Product version
14
- - A vulnerability description
15
- - Reproduction steps
16
-
17
- A member of the development team will confirm the vulnerability, determine its impact, and develop a fix.
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ The latest release version of filen-sync is currently being supported with security updates
6
+
7
+ ## Reporting a Vulnerability
8
+
9
+ Security is very important to us. If you have discovered a security issue with filen-sync,
10
+ please read our responsible disclosure guidelines and contact us at [https://support.filen.io](https://support.filen.io).
11
+ Your report should include:
12
+
13
+ - Product version
14
+ - A vulnerability description
15
+ - Reproduction steps
16
+
17
+ A member of the development team will confirm the vulnerability, determine its impact, and develop a fix.
@@ -1 +1,8 @@
1
1
  export declare const SYNC_INTERVAL = 5000;
2
+ export declare const LOCAL_TRASH_NAME: string;
3
+ export declare const DEFAULT_IGNORED: {
4
+ names: string[];
5
+ extensions: string[];
6
+ directories: string[];
7
+ system: string[];
8
+ };
package/dist/constants.js CHANGED
@@ -1,5 +1,55 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SYNC_INTERVAL = void 0;
3
+ exports.DEFAULT_IGNORED = exports.LOCAL_TRASH_NAME = exports.SYNC_INTERVAL = void 0;
4
4
  exports.SYNC_INTERVAL = 5000;
5
+ exports.LOCAL_TRASH_NAME = ".filen.trash.local";
6
+ exports.DEFAULT_IGNORED = {
7
+ names: [".ds_store"],
8
+ extensions: [".tmp", ".temp", ".ffs_tmp", ".temporary", ".crdownload", ".~cr", ".thumbdata"],
9
+ directories: [
10
+ exports.LOCAL_TRASH_NAME,
11
+ "$RECYCLE.BIN",
12
+ ".Trash",
13
+ ".local/share/Trash",
14
+ "/share/Trash",
15
+ "local/share/Trash",
16
+ "/AppData/Local",
17
+ "/AppData/Roaming"
18
+ ],
19
+ system: [
20
+ "C:\\$WINDOWS.~BT",
21
+ "C:\\$Windows.~WS",
22
+ "C:\\$WinREAgent",
23
+ "C:\\Windows",
24
+ "C:\\OneDriveTemp",
25
+ "C:\\PerfLogs",
26
+ "C:\\ProgramData",
27
+ "C:\\Program Files\\Uninstall Information",
28
+ "C:\\Program Files\\WindowsApps",
29
+ "C:\\Program Files\\Windows Defender",
30
+ "C:\\Program Files\\Windows Mail",
31
+ "C:\\Program Files\\Windows Media Player",
32
+ "C:\\Program Files\\Windows Multimedia Platform",
33
+ "C:\\Program Files\\Windows NT",
34
+ "C:\\Program Files\\Windows Photo Viewer",
35
+ "C:\\Program Files\\Windows Portable Devices",
36
+ "C:\\Program Files\\Windows Security",
37
+ "C:\\Program Files\\WindowsPowerShell",
38
+ "C:\\Program Files (x86)\\Uninstall Information",
39
+ "C:\\Program Files (x86)\\WindowsApps",
40
+ "C:\\Program Files (x86)\\Windows Defender",
41
+ "C:\\Program Files (x86)\\Windows Mail",
42
+ "C:\\Program Files (x86)\\Windows Media Player",
43
+ "C:\\Program Files (x86)\\Windows Multimedia Platform",
44
+ "C:\\Program Files (x86)\\Windows NT",
45
+ "C:\\Program Files (x86)\\Windows Photo Viewer",
46
+ "C:\\Program Files (x86)\\Windows Portable Devices",
47
+ "C:\\Program Files (x86)\\Windows Security",
48
+ "C:\\Program Files (x86)\\WindowsPowerShell",
49
+ "C:\\Program Files (x86)\\Internet Explorer",
50
+ "C:\\Program Files (x86)\\Microsoft",
51
+ "C:\\Program Files (x86)\\WindowsPowerShell",
52
+ "C:\\Program Files (x86)\\Reference Assemblies"
53
+ ]
54
+ };
5
55
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG,IAAI,CAAA"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG,IAAI,CAAA;AACpB,QAAA,gBAAgB,GAAW,oBAAoB,CAAA;AAC/C,QAAA,eAAe,GAAG;IAC9B,KAAK,EAAE,CAAC,WAAW,CAAC;IACpB,UAAU,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,CAAC;IAC5F,WAAW,EAAE;QACZ,wBAAgB;QAChB,cAAc;QACd,QAAQ;QACR,oBAAoB;QACpB,cAAc;QACd,mBAAmB;QACnB,gBAAgB;QAChB,kBAAkB;KAClB;IACD,MAAM,EAAE;QACP,kBAAkB;QAClB,kBAAkB;QAClB,iBAAiB;QACjB,aAAa;QACb,kBAAkB;QAClB,cAAc;QACd,iBAAiB;QACjB,0CAA0C;QAC1C,gCAAgC;QAChC,qCAAqC;QACrC,iCAAiC;QACjC,yCAAyC;QACzC,gDAAgD;QAChD,+BAA+B;QAC/B,yCAAyC;QACzC,6CAA6C;QAC7C,qCAAqC;QACrC,sCAAsC;QACtC,gDAAgD;QAChD,sCAAsC;QACtC,2CAA2C;QAC3C,uCAAuC;QACvC,+CAA+C;QAC/C,sDAAsD;QACtD,qCAAqC;QACrC,+CAA+C;QAC/C,mDAAmD;QACnD,2CAA2C;QAC3C,4CAA4C;QAC5C,4CAA4C;QAC5C,oCAAoC;QACpC,4CAA4C;QAC5C,+CAA+C;KAC/C;CACD,CAAA"}
@@ -0,0 +1,14 @@
1
+ import type Sync from "./lib/sync";
2
+ export declare const IGNORER_VERSION = 1;
3
+ export declare class Ignorer {
4
+ private readonly sync;
5
+ private instance;
6
+ private readonly name;
7
+ private readonly cache;
8
+ constructor(sync: Sync, name?: string);
9
+ initialize(passedContent?: string): Promise<void>;
10
+ update(content?: string): Promise<void>;
11
+ clear(): void;
12
+ ignores(path: string): boolean;
13
+ }
14
+ export default Ignorer;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Ignorer = exports.IGNORER_VERSION = void 0;
7
+ const ignore_1 = __importDefault(require("ignore"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const fs_extra_1 = __importDefault(require("fs-extra"));
10
+ exports.IGNORER_VERSION = 1;
11
+ class Ignorer {
12
+ constructor(sync, name = "localIgnorer") {
13
+ this.instance = (0, ignore_1.default)();
14
+ this.name = "localIgnorer";
15
+ this.cache = {};
16
+ this.sync = sync;
17
+ this.name = name;
18
+ }
19
+ async initialize(passedContent) {
20
+ let content = "";
21
+ const filePath = path_1.default.join(this.sync.dbPath, this.name, `v${exports.IGNORER_VERSION}`, this.sync.syncPair.uuid, "filenIgnore");
22
+ await fs_extra_1.default.ensureDir(path_1.default.dirname(filePath));
23
+ if (passedContent) {
24
+ await fs_extra_1.default.writeFile(filePath, passedContent, {
25
+ encoding: "utf-8"
26
+ });
27
+ content = passedContent;
28
+ }
29
+ else {
30
+ const exists = await fs_extra_1.default.exists(filePath);
31
+ if (!exists) {
32
+ return;
33
+ }
34
+ const stats = await fs_extra_1.default.stat(filePath);
35
+ if (stats.size === 0) {
36
+ return;
37
+ }
38
+ const readContent = await fs_extra_1.default.readFile(filePath, {
39
+ encoding: "utf-8"
40
+ });
41
+ if (readContent.length === 0) {
42
+ return;
43
+ }
44
+ content = readContent;
45
+ }
46
+ this.instance = (0, ignore_1.default)().add(content);
47
+ }
48
+ async update(content) {
49
+ await this.initialize(content);
50
+ }
51
+ clear() {
52
+ this.instance = (0, ignore_1.default)();
53
+ }
54
+ ignores(path) {
55
+ if (this.cache[path]) {
56
+ return this.cache[path];
57
+ }
58
+ const normalizedPath = path.startsWith("\\") ? path.slice(1) : path.startsWith("/") ? path.slice(1) : path;
59
+ if (normalizedPath.length === 0) {
60
+ return false;
61
+ }
62
+ const ig = this.instance.ignores(normalizedPath);
63
+ this.cache[path] = ig;
64
+ return ig;
65
+ }
66
+ }
67
+ exports.Ignorer = Ignorer;
68
+ exports.default = Ignorer;
69
+ //# sourceMappingURL=ignorer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ignorer.js","sourceRoot":"","sources":["../src/ignorer.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAE3B,gDAA6B;AAC7B,wDAAyB;AAEZ,QAAA,eAAe,GAAG,CAAC,CAAA;AAEhC,MAAa,OAAO;IAMnB,YAAmB,IAAU,EAAE,OAAe,cAAc;QAJpD,aAAQ,GAAG,IAAA,gBAAM,GAAE,CAAA;QACV,SAAI,GAAW,cAAc,CAAA;QAC7B,UAAK,GAA4B,EAAE,CAAA;QAGnD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IACjB,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,aAAsB;QAC7C,IAAI,OAAO,GAAW,EAAE,CAAA;QACxB,MAAM,QAAQ,GAAG,cAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,uBAAe,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,CAAA;QAE5H,MAAM,kBAAE,CAAC,SAAS,CAAC,cAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;QAEhD,IAAI,aAAa,EAAE,CAAC;YACnB,MAAM,kBAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,aAAa,EAAE;gBAC3C,QAAQ,EAAE,OAAO;aACjB,CAAC,CAAA;YAEF,OAAO,G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IAAI,CAAA;QAE1G,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACjC,OAAO,KAAK,CAAA;QACb,CAAC;QAED,MAAM,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;QAEhD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;QAErB,OAAO,EAAE,CAAA;IACV,CAAC;CACD;AA3ED,0BA2EC;AAED,kBAAe,OAAO,CAAA"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
- import type { SyncPair } from "./types";
2
- import { type FilenSDKConfig } from "@filen/sdk";
1
+ import { type SyncPair } from "./types";
2
+ import Sync from "./lib/sync";
3
+ import FilenSDK, { type FilenSDKConfig } from "@filen/sdk";
4
+ import Logger from "./lib/logger";
3
5
  /**
4
6
  * SyncWorker
5
7
  * @date 2/23/2024 - 5:50:56 AM
@@ -9,10 +11,12 @@ import { type FilenSDKConfig } from "@filen/sdk";
9
11
  * @typedef {SyncWorker}
10
12
  */
11
13
  export declare class SyncWorker {
12
- private readonly syncPairs;
13
- private readonly syncs;
14
- private readonly dbPath;
15
- private readonly sdkConfig;
14
+ readonly syncPairs: SyncPair[];
15
+ readonly syncs: Record<string, Sync>;
16
+ readonly dbPath: string;
17
+ readonly initSyncPairsMutex: import("./semaphore").ISemaphore;
18
+ readonly sdk: FilenSDK;
19
+ readonly logger: Logger;
16
20
  /**
17
21
  * Creates an instance of SyncWorker.
18
22
  *
@@ -28,6 +32,22 @@ export declare class SyncWorker {
28
32
  dbPath: string;
29
33
  sdkConfig: FilenSDKConfig;
30
34
  });
35
+ /**
36
+ * Sets up receiving message from the main thread.
37
+ *
38
+ * @private
39
+ */
40
+ private setupMainThreadListeners;
41
+ private resetSyncPairsCache;
42
+ /**
43
+ * Initialize sync pairs.
44
+ *
45
+ * @private
46
+ * @async
47
+ * @param {SyncPair[]} pairs
48
+ * @returns {Promise<void>}
49
+ */
50
+ private initSyncPairs;
31
51
  /**
32
52
  * Initialize the Sync worker.
33
53
  * @date 2/23/2024 - 5:51:12 AM
@@ -38,4 +58,5 @@ export declare class SyncWorker {
38
58
  */
39
59
  initialize(): Promise<void>;
40
60
  }
61
+ export * from "./utils";
41
62
  export default SyncWorker;
package/dist/index.js CHANGED
@@ -1,10 +1,31 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
18
  };
5
19
  Object.defineProperty(exports, "__esModule", { value: true });
6
20
  exports.SyncWorker = void 0;
7
21
  const sync_1 = __importDefault(require("./lib/sync"));
22
+ const sdk_1 = __importDefault(require("@filen/sdk"));
23
+ const worker_threads_1 = require("worker_threads");
24
+ const ipc_1 = require("./lib/ipc");
25
+ const semaphore_1 = require("./semaphore");
26
+ const constants_1 = require("./constants");
27
+ const utils_1 = require("./utils");
28
+ const logger_1 = __importDefault(require("./lib/logger"));
8
29
  /**
9
30
  * SyncWorker
10
31
  * @date 2/23/2024 - 5:50:56 AM
@@ -26,9 +47,98 @@ class SyncWorker {
26
47
  */
27
48
  constructor({ syncPairs, dbPath, sdkConfig }) {
28
49
  this.syncs = {};
50
+ this.initSyncPairsMutex = new semaphore_1.Semaphore(1);
29
51
  this.syncPairs = syncPairs;
30
52
  this.dbPath = dbPath;
31
- this.sdkConfig = sdkConfig;
53
+ this.logger = new logger_1.default(dbPath);
54
+ this.sdk = new sdk_1.default(Object.assign(Object.assign({}, sdkConfig), { connectToSocket: true, metadataCache: true }));
55
+ this.setupMainThreadListeners();
56
+ }
57
+ /**
58
+ * Sets up receiving message from the main thread.
59
+ *
60
+ * @private
61
+ */
62
+ setupMainThreadListeners() {
63
+ const receiver = !worker_threads_1.isMainThread && worker_threads_1.parentPort ? worker_threads_1.parentPort : process;
64
+ receiver.on("message", async (message) => {
65
+ if (message.type === "updateSyncPairs") {
66
+ try {
67
+ await this.initSyncPairs(message.data.pairs);
68
+ if (message.data.resetCache) {
69
+ this.resetSyncPairsCache();
70
+ }
71
+ (0, ipc_1.postMessageToMain)({
72
+ type: "syncPairsUpdated"
73
+ });
74
+ }
75
+ catch (e) {
76
+ this.logger.log("error", e, "index.setupMainThreadListeners");
77
+ if (e instanceof Error) {
78
+ (0, ipc_1.postMessageToMain)({
79
+ type: "error",
80
+ data: {
81
+ error: (0, utils_1.serializeError)(e)
82
+ }
83
+ });
84
+ }
85
+ }
86
+ }
87
+ else if (message.type === "resetSyncPairCache") {
88
+ this.resetSyncPairsCache();
89
+ }
90
+ });
91
+ }
92
+ resetSyncPairsCache() {
93
+ for (const pair of this.syncPairs) {
94
+ const sync = this.syncs[pair.uuid];
95
+ if (!sync) {
96
+ continue;
97
+ }
98
+ sync.localFileSystem.lastDirectoryChangeTimestamp = Date.now() - constants_1.SYNC_INTERVAL * 2;
99
+ sync.localFileSystem.getDirectoryTreeCache = {
100
+ timestamp: 0,
101
+ tree: {},
102
+ inodes: {}
103
+ };
104
+ sync.remoteFileSystem.previousTreeRawResponse = "";
105
+ sync.remoteFileSystem.getDirectoryTreeCache = {
106
+ timestamp: 0,
107
+ tree: {},
108
+ uuids: {}
109
+ };
110
+ }
111
+ }
112
+ /**
113
+ * Initialize sync pairs.
114
+ *
115
+ * @private
116
+ * @async
117
+ * @param {SyncPair[]} pairs
118
+ * @returns {Promise<void>}
119
+ */
120
+ async initSyncPairs(pairs) {
121
+ await this.initSyncPairsMutex.acquire();
122
+ try {
123
+ const promises = [];
124
+ for (const pair of pairs) {
125
+ if (!this.syncs[pair.uuid]) {
126
+ this.syncs[pair.uuid] = new sync_1.default({
127
+ syncPair: pair,
128
+ worker: this
129
+ });
130
+ promises.push(this.syncs[pair.uuid].initialize());
131
+ }
132
+ }
133
+ await Promise.all(promises);
134
+ }
135
+ catch (e) {
136
+ this.logger.log("error", e, "index.initSyncPairs");
137
+ throw e;
138
+ }
139
+ finally {
140
+ this.initSyncPairsMutex.release();
141
+ }
32
142
  }
33
143
  /**
34
144
  * Initialize the Sync worker.
@@ -39,20 +149,10 @@ class SyncWorker {
39
149
  * @returns {Promise<void>}
40
150
  */
41
151
  async initialize() {
42
- const promises = [];
43
- for (const pair of this.syncPairs) {
44
- if (!this.syncs[pair.uuid]) {
45
- this.syncs[pair.uuid] = new sync_1.default({
46
- syncPair: pair,
47
- dbPath: this.dbPath,
48
- sdkConfig: this.sdkConfig
49
- });
50
- promises.push(this.syncs[pair.uuid].initialize());
51
- }
52
- }
53
- await Promise.all(promises);
152
+ await this.initSyncPairs(this.syncPairs);
54
153
  }
55
154
  }
56
155
  exports.SyncWorker = SyncWorker;
156
+ __exportStar(require("./utils"), exports);
57
157
  exports.default = SyncWorker;
58
158
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AACA,sDAA6B;AAG7B;;;;;;;GAOG;AACH,MAAa,UAAU;IAMtB;;;;;;;;;OASG;IACH,YAAmB,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAwE;QAdxG,UAAK,GAAyB,EAAE,CAAA;QAehD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAA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AAC,UAAU,EAAE,CAAC,CAAA;gBACnD,CAAC;YACF,CAAC;YAED,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAC5B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,EAAE,qBAAqB,CAAC,CAAA;YAElD,MAAM,CAAC,CAAA;QACR,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,CAAA;QAClC,CAAC;IACF,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,UAAU;QACtB,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IACzC,CAAC;CACD;AA3ID,gCA2IC;AAED,0CAAuB;AACvB,kBAAe,UAAU,CAAA"}
@@ -1,6 +1,6 @@
1
1
  import type Sync from "./sync";
2
- import type { LocalTree } from "./filesystems/local";
3
- import type { RemoteTree } from "./filesystems/remote";
2
+ import { type LocalTree, type LocalTreeError } from "./filesystems/local";
3
+ import { type RemoteTree } from "./filesystems/remote";
4
4
  export type Delta = {
5
5
  path: string;
6
6
  } & ({
@@ -19,18 +19,10 @@ export type Delta = {
19
19
  type: "deleteRemoteDirectory";
20
20
  } | {
21
21
  type: "downloadFile";
22
- } | {
23
- type: "moveLocalFile";
24
- from: string;
25
- to: string;
26
22
  } | {
27
23
  type: "renameLocalFile";
28
24
  from: string;
29
25
  to: string;
30
- } | {
31
- type: "moveRemoteFile";
32
- from: string;
33
- to: string;
34
26
  } | {
35
27
  type: "renameRemoteFile";
36
28
  from: string;
@@ -43,18 +35,6 @@ export type Delta = {
43
35
  type: "renameLocalDirectory";
44
36
  from: string;
45
37
  to: string;
46
- } | {
47
- type: "moveRemoteDirectory";
48
- from: string;
49
- to: string;
50
- } | {
51
- type: "moveLocalFile";
52
- from: string;
53
- to: string;
54
- } | {
55
- type: "moveLocalDirectory";
56
- from: string;
57
- to: string;
58
38
  });
59
39
  /**
60
40
  * Deltas
@@ -68,19 +48,14 @@ export declare class Deltas {
68
48
  private readonly sync;
69
49
  /**
70
50
  * Creates an instance of Deltas.
71
- * @date 3/1/2024 - 11:11:36 PM
72
51
  *
73
52
  * @constructor
74
53
  * @public
75
- * @param {{ sync: Sync }} param0
76
- * @param {Sync} param0.sync
54
+ * @param {Sync} sync
77
55
  */
78
- constructor({ sync }: {
79
- sync: Sync;
80
- });
56
+ constructor(sync: Sync);
81
57
  /**
82
58
  * Process the directory trees and return all sync deltas.
83
- * @date 3/2/2024 - 8:42:25 AM
84
59
  *
85
60
  * @public
86
61
  * @async
@@ -88,19 +63,22 @@ export declare class Deltas {
88
63
  * currentLocalTree: LocalTree
89
64
  * currentRemoteTree: RemoteTree
90
65
  * previousLocalTree: LocalTree
91
- * previousRemoteTree: RemoteTree
66
+ * previousRemoteTree: RemoteTree,
67
+ * currentLocalTreeErrors: LocalTreeError[]
92
68
  * }} param0
93
69
  * @param {LocalTree} param0.currentLocalTree
94
70
  * @param {RemoteTree} param0.currentRemoteTree
95
71
  * @param {LocalTree} param0.previousLocalTree
96
72
  * @param {RemoteTree} param0.previousRemoteTree
73
+ * @param {{}} param0.currentLocalTreeErrors
97
74
  * @returns {Promise<Delta[]>}
98
75
  */
99
- process({ currentLocalTree, currentRemoteTree, previousLocalTree, previousRemoteTree }: {
76
+ process({ currentLocalTree, currentRemoteTree, previousLocalTree, previousRemoteTree, currentLocalTreeErrors }: {
100
77
  currentLocalTree: LocalTree;
101
78
  currentRemoteTree: RemoteTree;
102
79
  previousLocalTree: LocalTree;
103
80
  previousRemoteTree: RemoteTree;
81
+ currentLocalTreeErrors: LocalTreeError[];
104
82
  }): Promise<Delta[]>;
105
83
  }
106
84
  export default Deltas;