document-drive 1.0.0-alpha.102 → 1.0.0-alpha.103

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.
Files changed (40) hide show
  1. package/package.json +6 -13
  2. package/src/cache/index.ts +2 -2
  3. package/src/cache/memory.ts +24 -24
  4. package/src/cache/redis.ts +46 -46
  5. package/src/cache/types.ts +5 -9
  6. package/src/index.ts +5 -5
  7. package/src/queue/base.ts +273 -281
  8. package/src/queue/index.ts +2 -2
  9. package/src/queue/redis.ts +128 -128
  10. package/src/queue/types.ts +44 -44
  11. package/src/read-mode/errors.ts +9 -9
  12. package/src/read-mode/index.ts +119 -122
  13. package/src/read-mode/service.ts +187 -186
  14. package/src/read-mode/types.ts +70 -70
  15. package/src/server/error.ts +46 -46
  16. package/src/server/index.ts +2221 -2331
  17. package/src/server/listener/index.ts +2 -2
  18. package/src/server/listener/manager.ts +470 -499
  19. package/src/server/listener/transmitter/index.ts +4 -4
  20. package/src/server/listener/transmitter/internal.ts +77 -79
  21. package/src/server/listener/transmitter/pull-responder.ts +362 -370
  22. package/src/server/listener/transmitter/switchboard-push.ts +72 -72
  23. package/src/server/listener/transmitter/types.ts +17 -17
  24. package/src/server/types.ts +467 -473
  25. package/src/server/utils.ts +26 -26
  26. package/src/storage/base.ts +64 -67
  27. package/src/storage/browser.ts +233 -240
  28. package/src/storage/filesystem.ts +256 -267
  29. package/src/storage/index.ts +2 -2
  30. package/src/storage/memory.ts +206 -211
  31. package/src/storage/prisma.ts +563 -587
  32. package/src/storage/sequelize.ts +460 -468
  33. package/src/storage/types.ts +82 -82
  34. package/src/utils/default-drives-manager.ts +304 -329
  35. package/src/utils/document-helpers.ts +18 -18
  36. package/src/utils/graphql.ts +208 -212
  37. package/src/utils/index.ts +57 -60
  38. package/src/utils/logger.ts +37 -38
  39. package/src/utils/migrations.ts +49 -49
  40. package/src/utils/run-asap.ts +137 -140
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-drive",
3
- "version": "1.0.0-alpha.102",
3
+ "version": "1.0.0-alpha.103",
4
4
  "license": "AGPL-3.0-only",
5
5
  "type": "module",
6
6
  "module": "./src/index.ts",
@@ -48,35 +48,28 @@
48
48
  },
49
49
  "devDependencies": {
50
50
  "@prisma/client": "5.17.0",
51
- "@total-typescript/ts-reset": "^0.5.1",
52
51
  "@types/node": "^20.14.11",
53
52
  "@types/uuid": "^9.0.8",
54
- "@vitest/browser": "^2.0.5",
55
- "@vitest/coverage-v8": "^2.0.5",
53
+ "document-model-libs": "1.93.1",
56
54
  "fake-indexeddb": "^5.0.2",
57
55
  "localforage": "^1.10.0",
58
56
  "msw": "^2.3.1",
59
57
  "prisma": "^5.18.0",
60
58
  "sequelize": "^6.37.2",
61
59
  "sqlite3": "^5.1.7",
62
- "typescript": "^5.5.3",
63
- "vitest": "^2.0.5",
64
60
  "webdriverio": "^9.0.9",
65
61
  "vitest-fetch-mock": "^0.3.0",
66
- "document-model-libs": "1.92.0",
67
62
  "document-model": "2.1.0"
68
63
  },
69
- "packageManager": "pnpm@9.1.4+sha256.30a1801ac4e723779efed13a21f4c39f9eb6c9fbb4ced101bce06b422593d7c9",
70
64
  "scripts": {
71
- "check-types": "tsc --noemit --emitDeclarationOnly false --project tsconfig.json",
72
- "lint": "eslint src --ext .js,.jsx,.ts,.tsx && pnpm run check-types",
73
- "lint:fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
74
- "format": "prettier . --write",
65
+ "check-types": "tsc --noEmit",
66
+ "postlint": "npm run check-types",
67
+ "lint": "eslint",
75
68
  "release": "semantic-release",
76
69
  "test": "vitest run --coverage --exclude \"test/flaky/**\"",
77
70
  "test:watch": "vitest watch",
78
71
  "clean": "rimraf dist",
79
72
  "clean:node_modules": "rimraf node_modules",
80
- "build": " "
73
+ "build": "prisma generate"
81
74
  }
82
75
  }
@@ -1,2 +1,2 @@
1
- export * from './memory';
2
- export * from './types';
1
+ export * from "./memory";
2
+ export * from "./types";
@@ -1,33 +1,33 @@
1
- import { Document } from 'document-model/document';
2
- import { ICache } from './types';
1
+ import { Document } from "document-model/document";
2
+ import { ICache } from "./types";
3
3
 
4
4
  class InMemoryCache implements ICache {
5
- private cache = new Map<string, Map<string, Document>>();
5
+ private cache = new Map<string, Map<string, Document>>();
6
6
 
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());
19
- }
20
- this.cache.get(drive)?.set(id, doc);
21
- return true;
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());
22
19
  }
20
+ this.cache.get(drive)?.set(id, doc);
21
+ return true;
22
+ }
23
23
 
24
- async deleteDocument(drive: string, id: string) {
25
- return this.cache.get(drive)?.delete(id) ?? false;
26
- }
24
+ async deleteDocument(drive: string, id: string) {
25
+ return this.cache.get(drive)?.delete(id) ?? false;
26
+ }
27
27
 
28
- async getDocument(drive: string, id: string) {
29
- return this.cache.get(drive)?.get(id);
30
- }
28
+ async getDocument(drive: string, id: string) {
29
+ return this.cache.get(drive)?.get(id);
30
+ }
31
31
  }
32
32
 
33
33
  export default InMemoryCache;
@@ -1,56 +1,56 @@
1
- import { Document } from 'document-model/document';
2
- import type { RedisClientType } from 'redis';
3
- import { ICache } from './types';
1
+ import { Document } from "document-model/document";
2
+ import type { RedisClientType } from "redis";
3
+ import { ICache } from "./types";
4
4
 
5
5
  class RedisCache implements ICache {
6
- private redis: RedisClientType;
7
- private timeoutInSeconds: number;
8
-
9
- constructor(
10
- redis: RedisClientType,
11
- timeoutInSeconds: number | undefined = 5 * 60
12
- ) {
13
- this.redis = redis;
14
- this.timeoutInSeconds = timeoutInSeconds;
6
+ private redis: RedisClientType;
7
+ private timeoutInSeconds: number;
8
+
9
+ constructor(
10
+ redis: RedisClientType,
11
+ timeoutInSeconds: number | undefined = 5 * 60,
12
+ ) {
13
+ this.redis = redis;
14
+ this.timeoutInSeconds = timeoutInSeconds;
15
+ }
16
+
17
+ private static _getId(drive: string, id: string) {
18
+ return `cache:${drive}:${id}`;
19
+ }
20
+
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
+ });
35
+
36
+ if (result === "OK") {
37
+ return true;
15
38
  }
16
39
 
17
- private static _getId(drive: string, id: string) {
18
- return `cache:${drive}:${id}`;
19
- }
40
+ return false;
41
+ }
20
42
 
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
- });
35
-
36
- if (result === 'OK') {
37
- return true;
38
- }
39
-
40
- return false;
41
- }
43
+ async getDocument(drive: string, id: string) {
44
+ const redisId = RedisCache._getId(drive, id);
45
+ const doc = await this.redis.get(redisId);
42
46
 
43
- async getDocument(drive: string, id: string) {
44
- const redisId = RedisCache._getId(drive, id);
45
- const doc = await this.redis.get(redisId);
47
+ return doc ? (JSON.parse(doc) as Document) : undefined;
48
+ }
46
49
 
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
- }
50
+ async deleteDocument(drive: string, id: string) {
51
+ const redisId = RedisCache._getId(drive, id);
52
+ return (await this.redis.del(redisId)) > 0;
53
+ }
54
54
  }
55
55
 
56
56
  export default RedisCache;
@@ -1,13 +1,9 @@
1
- import type { Document } from 'document-model/document';
1
+ import type { Document } from "document-model/document";
2
2
 
3
3
  export interface ICache {
4
- setDocument(
5
- drive: string,
6
- id: string,
7
- document: Document
8
- ): Promise<boolean>;
9
- getDocument(drive: string, id: string): Promise<Document | undefined>;
4
+ setDocument(drive: string, id: string, document: Document): Promise<boolean>;
5
+ getDocument(drive: string, id: string): Promise<Document | undefined>;
10
6
 
11
- // @returns — true if a document existed and has been removed, or false if the document is not cached.
12
- deleteDocument(drive: string, id: string): Promise<boolean>;
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>;
13
9
  }
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
- export * from './server';
2
- export * from './server/error';
3
- export * from './storage';
4
- export * from './utils';
1
+ export * from "./server";
2
+ export * from "./server/error";
3
+ export * from "./storage";
4
+ export * from "./utils";
5
5
 
6
- export const test = 'test';
6
+ export const test = "test";