document-drive 1.0.0-alpha.4 → 1.0.0-alpha.41
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 +28 -21
- package/src/cache/index.ts +2 -0
- package/src/cache/memory.ts +24 -0
- package/src/cache/redis.ts +29 -0
- package/src/cache/types.ts +9 -0
- package/src/server/error.ts +17 -0
- package/src/server/index.ts +620 -380
- package/src/server/listener/manager.ts +161 -179
- package/src/server/listener/transmitter/index.ts +1 -0
- package/src/server/listener/transmitter/internal.ts +91 -0
- package/src/server/listener/transmitter/pull-responder.ts +44 -11
- package/src/server/listener/transmitter/switchboard-push.ts +3 -1
- package/src/server/types.ts +61 -16
- package/src/server/utils.ts +34 -0
- package/src/storage/browser.ts +12 -7
- package/src/storage/filesystem.ts +38 -0
- package/src/storage/memory.ts +5 -0
- package/src/storage/prisma.ts +178 -89
- package/src/storage/sequelize.ts +65 -44
- package/src/storage/types.ts +18 -0
- package/src/utils/document-helpers.ts +494 -0
- package/src/utils/graphql.ts +2 -1
- package/src/utils/index.ts +24 -1
- package/src/utils/logger.ts +44 -0
- package/src/server/listener/decorator.ts +0 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "document-drive",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.41",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./src/index.ts",
|
|
@@ -13,8 +13,11 @@
|
|
|
13
13
|
"./storage/filesystem": "./src/storage/filesystem.ts",
|
|
14
14
|
"./storage/memory": "./src/storage/memory.ts",
|
|
15
15
|
"./storage/prisma": "./src/storage/prisma.ts",
|
|
16
|
+
"./cache/redis": "./src/cache/redis.ts",
|
|
17
|
+
"./cache/memory": "./src/cache/memory.ts",
|
|
16
18
|
"./utils": "./src/utils/index.ts",
|
|
17
|
-
"./utils/graphql": "./src/utils/graphql.ts"
|
|
19
|
+
"./utils/graphql": "./src/utils/graphql.ts",
|
|
20
|
+
"./logger": "./src/utils/logger.ts"
|
|
18
21
|
},
|
|
19
22
|
"files": [
|
|
20
23
|
"./src"
|
|
@@ -29,10 +32,13 @@
|
|
|
29
32
|
"test:watch": "vitest watch"
|
|
30
33
|
},
|
|
31
34
|
"peerDependencies": {
|
|
32
|
-
"
|
|
33
|
-
"document-model": "^1.0
|
|
34
|
-
|
|
35
|
+
"document-model": "^1.0.45",
|
|
36
|
+
"document-model-libs": "^1.34.0"
|
|
37
|
+
},
|
|
38
|
+
"optionalDependencies": {
|
|
39
|
+
"@prisma/client": "5.11.0",
|
|
35
40
|
"localforage": "^1.10.0",
|
|
41
|
+
"redis": "^4.6.13",
|
|
36
42
|
"sequelize": "^6.35.2",
|
|
37
43
|
"sqlite3": "^5.1.7"
|
|
38
44
|
},
|
|
@@ -45,28 +51,29 @@
|
|
|
45
51
|
},
|
|
46
52
|
"devDependencies": {
|
|
47
53
|
"@commitlint/cli": "^18.6.1",
|
|
48
|
-
"@commitlint/config-conventional": "^18.6.
|
|
49
|
-
"@prisma/client": "5.
|
|
54
|
+
"@commitlint/config-conventional": "^18.6.3",
|
|
55
|
+
"@prisma/client": "5.11.0",
|
|
50
56
|
"@semantic-release/changelog": "^6.0.3",
|
|
51
57
|
"@semantic-release/git": "^10.0.1",
|
|
52
58
|
"@total-typescript/ts-reset": "^0.5.1",
|
|
53
|
-
"@types/node": "^20.
|
|
54
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
55
|
-
"@typescript-eslint/parser": "^6.
|
|
56
|
-
"@vitest/coverage-v8": "^
|
|
57
|
-
"document-model": "^1.0.
|
|
58
|
-
"document-model-libs": "^1.
|
|
59
|
-
"eslint": "^8.
|
|
59
|
+
"@types/node": "^20.12.7",
|
|
60
|
+
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
61
|
+
"@typescript-eslint/parser": "^6.21.0",
|
|
62
|
+
"@vitest/coverage-v8": "^1.4.0",
|
|
63
|
+
"document-model": "^1.0.45",
|
|
64
|
+
"document-model-libs": "^1.34.0",
|
|
65
|
+
"eslint": "^8.57.0",
|
|
60
66
|
"eslint-config-prettier": "^9.1.0",
|
|
61
|
-
"fake-indexeddb": "^5.0.
|
|
67
|
+
"fake-indexeddb": "^5.0.2",
|
|
62
68
|
"localforage": "^1.10.0",
|
|
63
|
-
"msw": "^2.
|
|
64
|
-
"prettier": "^3.
|
|
69
|
+
"msw": "^2.2.13",
|
|
70
|
+
"prettier": "^3.2.5",
|
|
65
71
|
"prettier-plugin-organize-imports": "^3.2.4",
|
|
66
|
-
"
|
|
67
|
-
"
|
|
72
|
+
"prisma": "^5.12.1",
|
|
73
|
+
"semantic-release": "^23.0.8",
|
|
74
|
+
"sequelize": "^6.37.2",
|
|
68
75
|
"sqlite3": "^5.1.7",
|
|
69
|
-
"typescript": "^5.
|
|
70
|
-
"vitest": "^1.
|
|
76
|
+
"typescript": "^5.4.4",
|
|
77
|
+
"vitest": "^1.5.0"
|
|
71
78
|
}
|
|
72
79
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Document } from "document-model/document";
|
|
2
|
+
import { ICache } from "./types";
|
|
3
|
+
|
|
4
|
+
class InMemoryCache implements ICache {
|
|
5
|
+
private cache = new Map<string, Map<string, Document>>();
|
|
6
|
+
|
|
7
|
+
async setDocument(drive: string, id: string, document: Document) {
|
|
8
|
+
if (!this.cache.has(drive)) {
|
|
9
|
+
this.cache.set(drive, new Map());
|
|
10
|
+
}
|
|
11
|
+
this.cache.get(drive)?.set(id, document);
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async deleteDocument(drive: string, id: string) {
|
|
16
|
+
return this.cache.get(drive)?.delete(id) ?? false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async getDocument(drive: string, id: string) {
|
|
20
|
+
return this.cache.get(drive)?.get(id);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default InMemoryCache;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Document } from "document-model/document";
|
|
2
|
+
import { ICache } from "./types";
|
|
3
|
+
import type { RedisClientType } from "redis";
|
|
4
|
+
import { logger } from "../utils/logger";
|
|
5
|
+
|
|
6
|
+
class RedisCache implements ICache {
|
|
7
|
+
private redis: RedisClientType;
|
|
8
|
+
|
|
9
|
+
constructor(redis: RedisClientType) {
|
|
10
|
+
this.redis = redis;
|
|
11
|
+
this.redis.flushAll().catch(logger.error);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async setDocument(drive: string, id: string, document: Document) {
|
|
15
|
+
return (await this.redis.hSet(drive, id, JSON.stringify(document))) > 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async getDocument(drive: string, id: string) {
|
|
19
|
+
const doc = await this.redis.hGet(drive, id);
|
|
20
|
+
|
|
21
|
+
return doc ? JSON.parse(doc) as Document : undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async deleteDocument(drive: string, id: string) {
|
|
25
|
+
return (await this.redis.hDel(drive, id)) > 0;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default RedisCache;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Document } from "document-model/document";
|
|
2
|
+
|
|
3
|
+
export interface ICache {
|
|
4
|
+
setDocument(drive: string, id: string, document: Document): Promise<boolean>
|
|
5
|
+
getDocument(drive: string, id: string): Promise<Document | undefined>
|
|
6
|
+
|
|
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
|
+
}
|
package/src/server/error.ts
CHANGED
|
@@ -16,3 +16,20 @@ export class OperationError extends Error {
|
|
|
16
16
|
this.operation = operation;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
+
|
|
20
|
+
export class ConflictOperationError extends OperationError {
|
|
21
|
+
constructor(existingOperation: Operation, newOperation: Operation) {
|
|
22
|
+
super(
|
|
23
|
+
'CONFLICT',
|
|
24
|
+
newOperation,
|
|
25
|
+
`Conflicting operation on index ${newOperation.index}`,
|
|
26
|
+
{ existingOperation, newOperation }
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class MissingOperationError extends OperationError {
|
|
32
|
+
constructor(index: number, operation: Operation) {
|
|
33
|
+
super('MISSING', operation, `Missing operation on index ${index}`);
|
|
34
|
+
}
|
|
35
|
+
}
|