document-drive 1.0.0-websockets.1 → 1.0.1
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/README.md +1 -0
- package/package.json +74 -88
- package/src/cache/index.ts +2 -2
- package/src/cache/memory.ts +22 -13
- package/src/cache/redis.ts +43 -16
- package/src/cache/types.ts +4 -4
- package/src/index.ts +6 -3
- package/src/queue/base.ts +276 -214
- package/src/queue/index.ts +2 -2
- package/src/queue/redis.ts +138 -127
- package/src/queue/types.ts +44 -38
- package/src/read-mode/errors.ts +19 -0
- package/src/read-mode/index.ts +125 -0
- package/src/read-mode/service.ts +207 -0
- package/src/read-mode/types.ts +108 -0
- package/src/server/error.ts +61 -26
- package/src/server/index.ts +2160 -1785
- package/src/server/listener/index.ts +2 -2
- package/src/server/listener/manager.ts +475 -437
- package/src/server/listener/transmitter/index.ts +4 -5
- package/src/server/listener/transmitter/internal.ts +77 -79
- package/src/server/listener/transmitter/pull-responder.ts +363 -329
- package/src/server/listener/transmitter/switchboard-push.ts +72 -55
- package/src/server/listener/transmitter/types.ts +19 -25
- package/src/server/types.ts +536 -349
- package/src/server/utils.ts +26 -27
- package/src/storage/base.ts +81 -0
- package/src/storage/browser.ts +233 -216
- package/src/storage/filesystem.ts +257 -256
- package/src/storage/index.ts +2 -1
- package/src/storage/memory.ts +206 -214
- package/src/storage/prisma.ts +575 -568
- package/src/storage/sequelize.ts +460 -471
- package/src/storage/types.ts +83 -67
- package/src/utils/default-drives-manager.ts +341 -0
- package/src/utils/document-helpers.ts +19 -18
- package/src/utils/graphql.ts +288 -34
- package/src/utils/index.ts +61 -59
- package/src/utils/logger.ts +39 -37
- package/src/utils/migrations.ts +58 -0
- package/src/utils/run-asap.ts +156 -0
- package/CHANGELOG.md +0 -818
- package/src/server/listener/transmitter/subscription.ts +0 -364
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Document Drive
|
package/package.json
CHANGED
|
@@ -1,89 +1,75 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"fake-indexeddb": "^5.0.2",
|
|
77
|
-
"localforage": "^1.10.0",
|
|
78
|
-
"msw": "^2.2.13",
|
|
79
|
-
"prettier": "^3.2.5",
|
|
80
|
-
"prettier-plugin-organize-imports": "^3.2.4",
|
|
81
|
-
"prisma": "^5.14.0",
|
|
82
|
-
"semantic-release": "^23.0.8",
|
|
83
|
-
"sequelize": "^6.37.2",
|
|
84
|
-
"sqlite3": "^5.1.7",
|
|
85
|
-
"typescript": "^5.4.4",
|
|
86
|
-
"vitest": "^1.6.0"
|
|
87
|
-
},
|
|
88
|
-
"packageManager": "pnpm@9.1.4+sha256.30a1801ac4e723779efed13a21f4c39f9eb6c9fbb4ced101bce06b422593d7c9"
|
|
89
|
-
}
|
|
2
|
+
"name": "document-drive",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"license": "AGPL-3.0-only",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"module": "./src/index.ts",
|
|
7
|
+
"types": "./src/index.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./src/index.ts",
|
|
10
|
+
"./server": "./src/server/index.ts",
|
|
11
|
+
"./storage": "./src/storage/index.ts",
|
|
12
|
+
"./storage/browser": "./src/storage/browser.ts",
|
|
13
|
+
"./storage/filesystem": "./src/storage/filesystem.ts",
|
|
14
|
+
"./storage/memory": "./src/storage/memory.ts",
|
|
15
|
+
"./storage/prisma": "./src/storage/prisma.ts",
|
|
16
|
+
"./cache/redis": "./src/cache/redis.ts",
|
|
17
|
+
"./cache/memory": "./src/cache/memory.ts",
|
|
18
|
+
"./queue/redis": "./src/queue/redis.ts",
|
|
19
|
+
"./queue/base": "./src/queue/base.ts",
|
|
20
|
+
"./utils": "./src/utils/index.ts",
|
|
21
|
+
"./utils/graphql": "./src/utils/graphql.ts",
|
|
22
|
+
"./utils/migrations": "./src/utils/migrations.ts",
|
|
23
|
+
"./logger": "./src/utils/logger.ts"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"./src"
|
|
27
|
+
],
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"document-model": "^2.1.0",
|
|
30
|
+
"document-model-libs": "^1.92.0"
|
|
31
|
+
},
|
|
32
|
+
"optionalDependencies": {
|
|
33
|
+
"@prisma/client": "^5.18.0",
|
|
34
|
+
"localforage": "^1.10.0",
|
|
35
|
+
"redis": "^4.6.15",
|
|
36
|
+
"sequelize": "^6.37.3",
|
|
37
|
+
"sqlite3": "^5.1.7"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"change-case": "^5.4.4",
|
|
41
|
+
"exponential-backoff": "^3.1.1",
|
|
42
|
+
"graphql": "^16.9.0",
|
|
43
|
+
"graphql-request": "^6.1.0",
|
|
44
|
+
"json-stringify-deterministic": "^1.0.12",
|
|
45
|
+
"nanoevents": "^9.0.0",
|
|
46
|
+
"sanitize-filename": "^1.6.3",
|
|
47
|
+
"uuid": "^9.0.1"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@prisma/client": "5.17.0",
|
|
51
|
+
"@types/node": "^20.14.11",
|
|
52
|
+
"@types/uuid": "^9.0.8",
|
|
53
|
+
"document-model": "2.2.0",
|
|
54
|
+
"document-model-libs": "1.93.2",
|
|
55
|
+
"fake-indexeddb": "^5.0.2",
|
|
56
|
+
"localforage": "^1.10.0",
|
|
57
|
+
"msw": "^2.3.1",
|
|
58
|
+
"prisma": "^5.18.0",
|
|
59
|
+
"sequelize": "^6.37.2",
|
|
60
|
+
"sqlite3": "^5.1.7",
|
|
61
|
+
"webdriverio": "^9.0.9",
|
|
62
|
+
"vitest-fetch-mock": "^0.3.0"
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"check-types": "tsc --noEmit",
|
|
66
|
+
"postlint": "npm run check-types",
|
|
67
|
+
"lint": "eslint",
|
|
68
|
+
"release": "semantic-release",
|
|
69
|
+
"test": "vitest run --coverage --exclude \"test/flaky/**\"",
|
|
70
|
+
"test:watch": "vitest watch",
|
|
71
|
+
"clean": "rimraf dist",
|
|
72
|
+
"clean:node_modules": "rimraf node_modules",
|
|
73
|
+
"build": "prisma generate"
|
|
74
|
+
}
|
|
75
|
+
}
|
package/src/cache/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./memory";
|
|
2
|
+
export * from "./types";
|
package/src/cache/memory.ts
CHANGED
|
@@ -2,23 +2,32 @@ import { Document } from "document-model/document";
|
|
|
2
2
|
import { ICache } from "./types";
|
|
3
3
|
|
|
4
4
|
class InMemoryCache implements ICache {
|
|
5
|
-
|
|
5
|
+
private cache = new Map<string, Map<string, Document>>();
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
async setDocument(drive: string, id: string, document: Document) {
|
|
8
|
+
const global = document.operations.global.map((e) => {
|
|
9
|
+
delete e.resultingState;
|
|
10
|
+
return e;
|
|
11
|
+
});
|
|
12
|
+
const local = document.operations.local.map((e) => {
|
|
13
|
+
delete e.resultingState;
|
|
14
|
+
return e;
|
|
15
|
+
});
|
|
16
|
+
const doc = { ...document, operations: { global, local } };
|
|
17
|
+
if (!this.cache.has(drive)) {
|
|
18
|
+
this.cache.set(drive, new Map());
|
|
13
19
|
}
|
|
20
|
+
this.cache.get(drive)?.set(id, doc);
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
14
23
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
24
|
+
async deleteDocument(drive: string, id: string) {
|
|
25
|
+
return this.cache.get(drive)?.delete(id) ?? false;
|
|
26
|
+
}
|
|
18
27
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
async getDocument(drive: string, id: string) {
|
|
29
|
+
return this.cache.get(drive)?.get(id);
|
|
30
|
+
}
|
|
22
31
|
}
|
|
23
32
|
|
|
24
33
|
export default InMemoryCache;
|
package/src/cache/redis.ts
CHANGED
|
@@ -1,29 +1,56 @@
|
|
|
1
1
|
import { Document } from "document-model/document";
|
|
2
|
-
import { ICache } from "./types";
|
|
3
2
|
import type { RedisClientType } from "redis";
|
|
4
|
-
import {
|
|
3
|
+
import { ICache } from "./types";
|
|
5
4
|
|
|
6
5
|
class RedisCache implements ICache {
|
|
7
|
-
|
|
6
|
+
private redis: RedisClientType;
|
|
7
|
+
private timeoutInSeconds: number;
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
constructor(
|
|
10
|
+
redis: RedisClientType,
|
|
11
|
+
timeoutInSeconds: number | undefined = 5 * 60,
|
|
12
|
+
) {
|
|
13
|
+
this.redis = redis;
|
|
14
|
+
this.timeoutInSeconds = timeoutInSeconds;
|
|
15
|
+
}
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
private static _getId(drive: string, id: string) {
|
|
18
|
+
return `cache:${drive}:${id}`;
|
|
19
|
+
}
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
async setDocument(drive: string, id: string, document: Document) {
|
|
22
|
+
const global = document.operations.global.map((e) => {
|
|
23
|
+
delete e.resultingState;
|
|
24
|
+
return e;
|
|
25
|
+
});
|
|
26
|
+
const local = document.operations.local.map((e) => {
|
|
27
|
+
delete e.resultingState;
|
|
28
|
+
return e;
|
|
29
|
+
});
|
|
30
|
+
const doc = { ...document, operations: { global, local } };
|
|
31
|
+
const redisId = RedisCache._getId(drive, id);
|
|
32
|
+
const result = await this.redis.set(redisId, JSON.stringify(doc), {
|
|
33
|
+
EX: this.timeoutInSeconds ? this.timeoutInSeconds : undefined,
|
|
34
|
+
});
|
|
20
35
|
|
|
21
|
-
|
|
36
|
+
if (result === "OK") {
|
|
37
|
+
return true;
|
|
22
38
|
}
|
|
23
39
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async getDocument(drive: string, id: string) {
|
|
44
|
+
const redisId = RedisCache._getId(drive, id);
|
|
45
|
+
const doc = await this.redis.get(redisId);
|
|
46
|
+
|
|
47
|
+
return doc ? (JSON.parse(doc) as Document) : undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async deleteDocument(drive: string, id: string) {
|
|
51
|
+
const redisId = RedisCache._getId(drive, id);
|
|
52
|
+
return (await this.redis.del(redisId)) > 0;
|
|
53
|
+
}
|
|
27
54
|
}
|
|
28
55
|
|
|
29
56
|
export default RedisCache;
|
package/src/cache/types.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Document } from "document-model/document";
|
|
2
2
|
|
|
3
3
|
export interface ICache {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
setDocument(drive: string, id: string, document: Document): Promise<boolean>;
|
|
5
|
+
getDocument(drive: string, id: string): Promise<Document | undefined>;
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
// @returns — true if a document existed and has been removed, or false if the document is not cached.
|
|
8
|
+
deleteDocument(drive: string, id: string): Promise<boolean>;
|
|
9
9
|
}
|
package/src/index.ts
CHANGED