@filen/sync 0.1.1 → 0.1.4
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 -661
- package/README.md +1 -1
- package/SECURITY.md +17 -17
- package/dist/constants.d.ts +7 -0
- package/dist/constants.js +51 -1
- package/dist/constants.js.map +1 -1
- package/dist/ignorer.d.ts +14 -0
- package/dist/ignorer.js +69 -0
- package/dist/ignorer.js.map +1 -0
- package/dist/index.d.ts +31 -17
- package/dist/index.js +125 -24
- package/dist/index.js.map +1 -1
- package/dist/lib/deltas.d.ts +9 -31
- package/dist/lib/deltas.js +194 -99
- package/dist/lib/deltas.js.map +1 -1
- package/dist/lib/filesystems/local.d.ts +32 -43
- package/dist/lib/filesystems/local.js +383 -106
- package/dist/lib/filesystems/local.js.map +1 -1
- package/dist/lib/filesystems/remote.d.ts +21 -7
- package/dist/lib/filesystems/remote.js +531 -67
- package/dist/lib/filesystems/remote.js.map +1 -1
- package/dist/lib/ipc.d.ts +9 -0
- package/dist/lib/ipc.js +60 -0
- package/dist/lib/ipc.js.map +1 -0
- package/dist/lib/lock.d.ts +13 -0
- package/dist/lib/lock.js +73 -0
- package/dist/lib/lock.js.map +1 -0
- package/dist/lib/logger.d.ts +14 -0
- package/dist/lib/logger.js +93 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/state.d.ts +4 -15
- package/dist/lib/state.js +106 -87
- package/dist/lib/state.js.map +1 -1
- package/dist/lib/sync.d.ts +30 -10
- package/dist/lib/sync.js +363 -36
- package/dist/lib/sync.js.map +1 -1
- package/dist/lib/tasks.d.ts +27 -40
- package/dist/lib/tasks.js +397 -48
- package/dist/lib/tasks.js.map +1 -1
- package/dist/types.d.ts +340 -0
- package/dist/utils.d.ts +42 -0
- package/dist/utils.js +164 -1
- package/dist/utils.js.map +1 -1
- package/index.d.ts +6 -295
- package/jest.config.js +5 -0
- package/package.json +62 -58
- package/tests/utils.test.ts +33 -0
- package/tsconfig.json +24 -24
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-
|
|
6
|
-
|
|
7
|
-
## Reporting a Vulnerability
|
|
8
|
-
|
|
9
|
-
Security is very important to us. If you have discovered a security issue with filen-
|
|
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.
|
package/dist/constants.d.ts
CHANGED
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
|
package/dist/constants.js.map
CHANGED
|
@@ -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;
|
package/dist/ignorer.js
ADDED
|
@@ -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,GAAG,aAAa,CAAA;QACxB,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I,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
|
|
2
|
-
import
|
|
1
|
+
import { type SyncPair, type SyncMessage } 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,25 +11,36 @@ import { type FilenSDKConfig } from "@filen/sdk";
|
|
|
9
11
|
* @typedef {SyncWorker}
|
|
10
12
|
*/
|
|
11
13
|
export declare class SyncWorker {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* @public
|
|
21
|
-
* @param {{ syncPairs: SyncPair[]; dbPath: string; sdkConfig: FilenSDKConfig }} param0
|
|
22
|
-
* @param {{}} param0.syncPairs
|
|
23
|
-
* @param {string} param0.dbPath
|
|
24
|
-
* @param {FilenSDKConfig} param0.sdkConfig
|
|
25
|
-
*/
|
|
26
|
-
constructor({ syncPairs, dbPath, 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;
|
|
20
|
+
readonly runOnce: boolean;
|
|
21
|
+
constructor({ syncPairs, dbPath, sdkConfig, onMessage, runOnce }: {
|
|
27
22
|
syncPairs: SyncPair[];
|
|
28
23
|
dbPath: string;
|
|
29
24
|
sdkConfig: FilenSDKConfig;
|
|
25
|
+
onMessage?: (message: SyncMessage) => void;
|
|
26
|
+
runOnce?: boolean;
|
|
30
27
|
});
|
|
28
|
+
/**
|
|
29
|
+
* Sets up receiving message from the main thread.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
private setupMainThreadListeners;
|
|
34
|
+
private resetSyncPairsCache;
|
|
35
|
+
/**
|
|
36
|
+
* Initialize sync pairs.
|
|
37
|
+
*
|
|
38
|
+
* @private
|
|
39
|
+
* @async
|
|
40
|
+
* @param {SyncPair[]} pairs
|
|
41
|
+
* @returns {Promise<void>}
|
|
42
|
+
*/
|
|
43
|
+
private initSyncPairs;
|
|
31
44
|
/**
|
|
32
45
|
* Initialize the Sync worker.
|
|
33
46
|
* @date 2/23/2024 - 5:51:12 AM
|
|
@@ -38,4 +51,5 @@ export declare class SyncWorker {
|
|
|
38
51
|
*/
|
|
39
52
|
initialize(): Promise<void>;
|
|
40
53
|
}
|
|
54
|
+
export * from "./utils";
|
|
41
55
|
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
|
|
@@ -14,21 +35,111 @@ const sync_1 = __importDefault(require("./lib/sync"));
|
|
|
14
35
|
* @typedef {SyncWorker}
|
|
15
36
|
*/
|
|
16
37
|
class SyncWorker {
|
|
17
|
-
|
|
18
|
-
* Creates an instance of SyncWorker.
|
|
19
|
-
*
|
|
20
|
-
* @constructor
|
|
21
|
-
* @public
|
|
22
|
-
* @param {{ syncPairs: SyncPair[]; dbPath: string; sdkConfig: FilenSDKConfig }} param0
|
|
23
|
-
* @param {{}} param0.syncPairs
|
|
24
|
-
* @param {string} param0.dbPath
|
|
25
|
-
* @param {FilenSDKConfig} param0.sdkConfig
|
|
26
|
-
*/
|
|
27
|
-
constructor({ syncPairs, dbPath, sdkConfig }) {
|
|
38
|
+
constructor({ syncPairs, dbPath, sdkConfig, onMessage, runOnce = false }) {
|
|
28
39
|
this.syncs = {};
|
|
40
|
+
this.initSyncPairsMutex = new semaphore_1.Semaphore(1);
|
|
41
|
+
if (onMessage) {
|
|
42
|
+
process.onMessage = onMessage;
|
|
43
|
+
}
|
|
44
|
+
this.runOnce = runOnce;
|
|
29
45
|
this.syncPairs = syncPairs;
|
|
30
46
|
this.dbPath = dbPath;
|
|
31
|
-
this.
|
|
47
|
+
this.logger = new logger_1.default(dbPath);
|
|
48
|
+
this.sdk = new sdk_1.default(Object.assign(Object.assign({}, sdkConfig), { connectToSocket: true, metadataCache: true }));
|
|
49
|
+
this.setupMainThreadListeners();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Sets up receiving message from the main thread.
|
|
53
|
+
*
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
56
|
+
setupMainThreadListeners() {
|
|
57
|
+
const receiver = !worker_threads_1.isMainThread && worker_threads_1.parentPort ? worker_threads_1.parentPort : process;
|
|
58
|
+
receiver.on("message", async (message) => {
|
|
59
|
+
if (message.type === "updateSyncPairs") {
|
|
60
|
+
try {
|
|
61
|
+
await this.initSyncPairs(message.data.pairs);
|
|
62
|
+
if (message.data.resetCache) {
|
|
63
|
+
this.resetSyncPairsCache();
|
|
64
|
+
}
|
|
65
|
+
(0, ipc_1.postMessageToMain)({
|
|
66
|
+
type: "syncPairsUpdated"
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
this.logger.log("error", e, "index.setupMainThreadListeners");
|
|
71
|
+
if (e instanceof Error) {
|
|
72
|
+
(0, ipc_1.postMessageToMain)({
|
|
73
|
+
type: "error",
|
|
74
|
+
data: {
|
|
75
|
+
error: (0, utils_1.serializeError)(e)
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else if (message.type === "resetSyncPairCache") {
|
|
82
|
+
this.resetSyncPairsCache();
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
resetSyncPairsCache() {
|
|
87
|
+
for (const pair of this.syncPairs) {
|
|
88
|
+
const sync = this.syncs[pair.uuid];
|
|
89
|
+
if (!sync) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
sync.localFileSystem.lastDirectoryChangeTimestamp = Date.now() - constants_1.SYNC_INTERVAL * 2;
|
|
93
|
+
sync.localFileSystem.getDirectoryTreeCache = {
|
|
94
|
+
timestamp: 0,
|
|
95
|
+
tree: {},
|
|
96
|
+
inodes: {}
|
|
97
|
+
};
|
|
98
|
+
sync.remoteFileSystem.previousTreeRawResponse = "";
|
|
99
|
+
sync.remoteFileSystem.getDirectoryTreeCache = {
|
|
100
|
+
timestamp: 0,
|
|
101
|
+
tree: {},
|
|
102
|
+
uuids: {}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Initialize sync pairs.
|
|
108
|
+
*
|
|
109
|
+
* @private
|
|
110
|
+
* @async
|
|
111
|
+
* @param {SyncPair[]} pairs
|
|
112
|
+
* @returns {Promise<void>}
|
|
113
|
+
*/
|
|
114
|
+
async initSyncPairs(pairs) {
|
|
115
|
+
await this.initSyncPairsMutex.acquire();
|
|
116
|
+
const currentSyncPairsUUIDs = this.syncPairs.map(pair => pair.uuid);
|
|
117
|
+
const newSyncPairsUUIDs = pairs.map(pair => pair.uuid);
|
|
118
|
+
try {
|
|
119
|
+
const promises = [];
|
|
120
|
+
for (const pair of pairs) {
|
|
121
|
+
if (!this.syncs[pair.uuid]) {
|
|
122
|
+
this.syncs[pair.uuid] = new sync_1.default({
|
|
123
|
+
syncPair: pair,
|
|
124
|
+
worker: this
|
|
125
|
+
});
|
|
126
|
+
promises.push(this.syncs[pair.uuid].initialize());
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
await Promise.all(promises);
|
|
130
|
+
for (const uuid of currentSyncPairsUUIDs) {
|
|
131
|
+
if (!newSyncPairsUUIDs.includes(uuid) && this.syncs[uuid]) {
|
|
132
|
+
this.syncs[uuid].removed = true;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
this.logger.log("error", e, "index.initSyncPairs");
|
|
138
|
+
throw e;
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
this.initSyncPairsMutex.release();
|
|
142
|
+
}
|
|
32
143
|
}
|
|
33
144
|
/**
|
|
34
145
|
* Initialize the Sync worker.
|
|
@@ -39,20 +150,10 @@ class SyncWorker {
|
|
|
39
150
|
* @returns {Promise<void>}
|
|
40
151
|
*/
|
|
41
152
|
async initialize() {
|
|
42
|
-
|
|
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);
|
|
153
|
+
await this.initSyncPairs(this.syncPairs);
|
|
54
154
|
}
|
|
55
155
|
}
|
|
56
156
|
exports.SyncWorker = SyncWorker;
|
|
157
|
+
__exportStar(require("./utils"), exports);
|
|
57
158
|
exports.default = SyncWorker;
|
|
58
159
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AACA,sDAA6B;AAC7B,qDAA0D;AAC1D,mDAAyD;AACzD,mCAA6C;AAC7C,2CAAuC;AACvC,2CAA2C;AAC3C,mCAAw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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;AA5JD,gCA4JC;AAED,0CAAuB;AACvB,kBAAe,UAAU,CAAA"}
|
package/dist/lib/deltas.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type Sync from "./sync";
|
|
2
|
-
import type
|
|
3
|
-
import type
|
|
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 {
|
|
76
|
-
* @param {Sync} param0.sync
|
|
54
|
+
* @param {Sync} sync
|
|
77
55
|
*/
|
|
78
|
-
constructor(
|
|
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;
|