document-drive 0.0.18 → 0.0.20
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 +1 -3
- package/src/server/index.ts +1 -1
- package/src/server/types.ts +7 -2
- package/src/storage/filesystem.ts +12 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "document-drive",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./src/index.ts",
|
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
"sanitize-filename": "^1.6.3"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/proper-lockfile": "^4.1.4",
|
|
37
36
|
"@typescript-eslint/eslint-plugin": "^6.12.0",
|
|
38
37
|
"@typescript-eslint/parser": "^6.12.0",
|
|
39
38
|
"@vitest/coverage-v8": "^0.34.6",
|
|
@@ -45,7 +44,6 @@
|
|
|
45
44
|
"localforage": "^1.10.0",
|
|
46
45
|
"prettier": "^3.1.0",
|
|
47
46
|
"prettier-plugin-organize-imports": "^3.2.4",
|
|
48
|
-
"tsx": "^4.6.2",
|
|
49
47
|
"typescript": "^5.3.2",
|
|
50
48
|
"vitest": "^0.34.6"
|
|
51
49
|
}
|
package/src/server/index.ts
CHANGED
package/src/server/types.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
DocumentDriveAction,
|
|
3
3
|
DocumentDriveDocument,
|
|
4
|
+
DocumentDriveLocalState,
|
|
4
5
|
DocumentDriveState
|
|
5
6
|
} from 'document-model-libs/document-drive';
|
|
6
7
|
import type {
|
|
7
8
|
BaseAction,
|
|
8
9
|
Document,
|
|
9
10
|
Operation,
|
|
10
|
-
Signal
|
|
11
|
+
Signal,
|
|
12
|
+
State
|
|
11
13
|
} from 'document-model/document';
|
|
12
14
|
|
|
13
|
-
export type DriveInput =
|
|
15
|
+
export type DriveInput = State<
|
|
16
|
+
Omit<DocumentDriveState, '__typename' | 'nodes'>,
|
|
17
|
+
DocumentDriveLocalState
|
|
18
|
+
>;
|
|
14
19
|
|
|
15
20
|
export type CreateDocumentInput = {
|
|
16
21
|
id: string;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { DocumentDriveDocument } from 'document-model-libs/document-drive';
|
|
2
2
|
import { Document } from 'document-model/document';
|
|
3
3
|
import type { Dirent } from 'fs';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
existsSync,
|
|
6
|
+
mkdirSync,
|
|
7
|
+
readFileSync,
|
|
8
|
+
readdirSync,
|
|
9
|
+
writeFileSync
|
|
10
|
+
} from 'fs';
|
|
5
11
|
import fs from 'fs/promises';
|
|
6
12
|
import path from 'path';
|
|
7
13
|
import sanitize from 'sanitize-filename';
|
|
@@ -46,7 +52,7 @@ export class FilesystemStorage implements IDriveStorage {
|
|
|
46
52
|
async getDocuments(drive: string) {
|
|
47
53
|
let files: Dirent[] = [];
|
|
48
54
|
try {
|
|
49
|
-
files =
|
|
55
|
+
files = readdirSync(path.join(this.basePath, drive), {
|
|
50
56
|
withFileTypes: true
|
|
51
57
|
});
|
|
52
58
|
} catch (error) {
|
|
@@ -72,10 +78,9 @@ export class FilesystemStorage implements IDriveStorage {
|
|
|
72
78
|
|
|
73
79
|
async getDocument(drive: string, id: string) {
|
|
74
80
|
try {
|
|
75
|
-
const content =
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
);
|
|
81
|
+
const content = readFileSync(this._buildDocumentPath(drive, id), {
|
|
82
|
+
encoding: 'utf-8'
|
|
83
|
+
});
|
|
79
84
|
return JSON.parse(content);
|
|
80
85
|
} catch (error) {
|
|
81
86
|
console.error(error);
|
|
@@ -96,7 +101,7 @@ export class FilesystemStorage implements IDriveStorage {
|
|
|
96
101
|
}
|
|
97
102
|
|
|
98
103
|
async getDrives() {
|
|
99
|
-
const files = await
|
|
104
|
+
const files = await readdirSync(this.drivesPath, {
|
|
100
105
|
withFileTypes: true
|
|
101
106
|
});
|
|
102
107
|
const drives: string[] = [];
|