document-drive 0.0.15 → 0.0.17
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/package.json +2 -2
- package/src/storage/filesystem.ts +4 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "document-drive",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./src/index.ts",
|
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
"localforage": "^1.10.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"proper-lockfile": "^4.1.2",
|
|
34
33
|
"sanitize-filename": "^1.6.3"
|
|
35
34
|
},
|
|
36
35
|
"devDependencies": {
|
|
@@ -46,6 +45,7 @@
|
|
|
46
45
|
"localforage": "^1.10.0",
|
|
47
46
|
"prettier": "^3.1.0",
|
|
48
47
|
"prettier-plugin-organize-imports": "^3.2.4",
|
|
48
|
+
"tsx": "^4.6.2",
|
|
49
49
|
"typescript": "^5.3.2",
|
|
50
50
|
"vitest": "^0.34.6"
|
|
51
51
|
}
|
|
@@ -4,7 +4,6 @@ import type { Dirent } from 'fs';
|
|
|
4
4
|
import { existsSync, mkdirSync } from 'fs';
|
|
5
5
|
import fs from 'fs/promises';
|
|
6
6
|
import path from 'path';
|
|
7
|
-
import { lock } from 'proper-lockfile';
|
|
8
7
|
import sanitize from 'sanitize-filename';
|
|
9
8
|
import { isDocumentDrive } from '../utils';
|
|
10
9
|
import { IDriveStorage } from './types';
|
|
@@ -22,15 +21,6 @@ function ensureDir(dir: string) {
|
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
function lockFile(path: string) {
|
|
26
|
-
return lock(path, {
|
|
27
|
-
fs,
|
|
28
|
-
retries: 3,
|
|
29
|
-
realpath: false,
|
|
30
|
-
onCompromised: () => {}
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
24
|
export class FilesystemStorage implements IDriveStorage {
|
|
35
25
|
private basePath: string;
|
|
36
26
|
private drivesPath: string;
|
|
@@ -95,16 +85,15 @@ export class FilesystemStorage implements IDriveStorage {
|
|
|
95
85
|
|
|
96
86
|
async saveDocument(drive: string, id: string, document: Document) {
|
|
97
87
|
const documentPath = this._buildDocumentPath(drive, id);
|
|
98
|
-
|
|
99
|
-
? await lockFile(documentPath)
|
|
100
|
-
: undefined;
|
|
88
|
+
let handle: fs.FileHandle | undefined = undefined;
|
|
101
89
|
try {
|
|
102
90
|
await ensureDir(path.dirname(documentPath));
|
|
103
|
-
|
|
91
|
+
handle = await fs.open(documentPath, 'w');
|
|
92
|
+
await fs.writeFile(handle, JSON.stringify(document), {
|
|
104
93
|
encoding: 'utf-8'
|
|
105
94
|
});
|
|
106
95
|
} finally {
|
|
107
|
-
|
|
96
|
+
await handle?.close();
|
|
108
97
|
}
|
|
109
98
|
}
|
|
110
99
|
|