document-drive 1.0.0-alpha.38 → 1.0.0-alpha.39
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 +8 -6
- package/src/server/index.ts +26 -10
- package/src/storage/prisma.ts +0 -4
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.39",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./src/index.ts",
|
|
@@ -13,6 +13,8 @@
|
|
|
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
19
|
"./utils/graphql": "./src/utils/graphql.ts",
|
|
18
20
|
"./logger": "./src/utils/logger.ts"
|
|
@@ -30,8 +32,8 @@
|
|
|
30
32
|
"test:watch": "vitest watch"
|
|
31
33
|
},
|
|
32
34
|
"peerDependencies": {
|
|
33
|
-
"document-model": "^1.0.
|
|
34
|
-
"document-model-libs": "^1.
|
|
35
|
+
"document-model": "^1.0.42",
|
|
36
|
+
"document-model-libs": "^1.32.0"
|
|
35
37
|
},
|
|
36
38
|
"optionalDependencies": {
|
|
37
39
|
"@prisma/client": "5.11.0",
|
|
@@ -58,8 +60,8 @@
|
|
|
58
60
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
59
61
|
"@typescript-eslint/parser": "^6.21.0",
|
|
60
62
|
"@vitest/coverage-v8": "^1.4.0",
|
|
61
|
-
"document-model": "^1.0.
|
|
62
|
-
"document-model-libs": "^1.
|
|
63
|
+
"document-model": "^1.0.42",
|
|
64
|
+
"document-model-libs": "^1.32.0",
|
|
63
65
|
"eslint": "^8.57.0",
|
|
64
66
|
"eslint-config-prettier": "^9.1.0",
|
|
65
67
|
"fake-indexeddb": "^5.0.2",
|
|
@@ -72,6 +74,6 @@
|
|
|
72
74
|
"sequelize": "^6.37.2",
|
|
73
75
|
"sqlite3": "^5.1.7",
|
|
74
76
|
"typescript": "^5.4.4",
|
|
75
|
-
"vitest": "^1.
|
|
77
|
+
"vitest": "^1.5.0"
|
|
76
78
|
}
|
|
77
79
|
}
|
package/src/server/index.ts
CHANGED
|
@@ -223,6 +223,21 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
|
|
|
223
223
|
for (const drive of drives) {
|
|
224
224
|
await this._initializeDrive(drive);
|
|
225
225
|
}
|
|
226
|
+
|
|
227
|
+
// if network connect comes online then
|
|
228
|
+
// triggers the listeners update
|
|
229
|
+
if (typeof window !== "undefined") {
|
|
230
|
+
window.addEventListener('online', () => {
|
|
231
|
+
this.listenerStateManager.triggerUpdate(false,
|
|
232
|
+
this.handleListenerError.bind(this)).catch(error => {
|
|
233
|
+
logger.error(
|
|
234
|
+
'Non handled error updating listeners',
|
|
235
|
+
error
|
|
236
|
+
);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
});
|
|
240
|
+
}
|
|
226
241
|
}
|
|
227
242
|
|
|
228
243
|
private async _initializeDrive(driveId: string) {
|
|
@@ -470,7 +485,7 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
|
|
|
470
485
|
async getDrive(drive: string, options?: GetDocumentOptions) {
|
|
471
486
|
try {
|
|
472
487
|
const document = await this.cache.getDocument("drives", drive);
|
|
473
|
-
if (document) {
|
|
488
|
+
if (document && isDocumentDrive(document)) {
|
|
474
489
|
return document;
|
|
475
490
|
}
|
|
476
491
|
} catch (e) {
|
|
@@ -493,6 +508,7 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
|
|
|
493
508
|
`Document with id ${drive} is not a Document Drive`
|
|
494
509
|
);
|
|
495
510
|
} else {
|
|
511
|
+
this.cache.setDocument("drives", drive, document).catch(logger.error);
|
|
496
512
|
return document;
|
|
497
513
|
}
|
|
498
514
|
}
|
|
@@ -511,13 +527,15 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
|
|
|
511
527
|
|
|
512
528
|
const documentModel = this._getDocumentModel(header.documentType);
|
|
513
529
|
|
|
514
|
-
|
|
530
|
+
const document = baseUtils.replayDocument(
|
|
515
531
|
initialState,
|
|
516
532
|
filterOperationsByRevision(operations, options?.revisions),
|
|
517
533
|
documentModel.reducer,
|
|
518
534
|
undefined,
|
|
519
535
|
header
|
|
520
536
|
);
|
|
537
|
+
this.cache.setDocument(drive, id, document).catch(logger.error);
|
|
538
|
+
return document;
|
|
521
539
|
}
|
|
522
540
|
|
|
523
541
|
getDocuments(drive: string) {
|
|
@@ -556,8 +574,8 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
|
|
|
556
574
|
const operationsApplied: Operation<A | BaseAction>[] = [];
|
|
557
575
|
const operationsUpdated: Operation<A | BaseAction>[] = [];
|
|
558
576
|
const signals: SignalResult[] = [];
|
|
559
|
-
|
|
560
577
|
let document: T = this._buildDocument(storageDocument);
|
|
578
|
+
|
|
561
579
|
let error: OperationError | undefined; // TODO: replace with an array of errors/consistency issues
|
|
562
580
|
const operationsByScope = groupOperationsByScope(operations);
|
|
563
581
|
|
|
@@ -601,7 +619,6 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
|
|
|
601
619
|
updatedOperationIndex = firstNewOperation.index;
|
|
602
620
|
}
|
|
603
621
|
}
|
|
604
|
-
|
|
605
622
|
for (const nextOperation of newOperations) {
|
|
606
623
|
let skipHashValidation = false;
|
|
607
624
|
|
|
@@ -615,7 +632,7 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
|
|
|
615
632
|
}
|
|
616
633
|
|
|
617
634
|
try {
|
|
618
|
-
const appliedResult = await this._performOperation
|
|
635
|
+
const appliedResult = await this._performOperation(
|
|
619
636
|
drive,
|
|
620
637
|
document,
|
|
621
638
|
nextOperation,
|
|
@@ -670,16 +687,15 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
|
|
|
670
687
|
) as T;
|
|
671
688
|
}
|
|
672
689
|
|
|
673
|
-
private async _performOperation<T extends Document
|
|
690
|
+
private async _performOperation<T extends Document>(
|
|
674
691
|
drive: string,
|
|
675
|
-
|
|
676
|
-
operation: Operation
|
|
692
|
+
document: T,
|
|
693
|
+
operation: Operation,
|
|
677
694
|
skipHashValidation = false
|
|
678
695
|
) {
|
|
679
696
|
const documentModel = this._getDocumentModel(
|
|
680
|
-
|
|
697
|
+
document.documentType
|
|
681
698
|
);
|
|
682
|
-
const document = this._buildDocument(documentStorage);
|
|
683
699
|
|
|
684
700
|
const signalResults: SignalResult[] = [];
|
|
685
701
|
let newDocument = document;
|
package/src/storage/prisma.ts
CHANGED
|
@@ -215,18 +215,14 @@ export class PrismaStorage implements IDriveStorage {
|
|
|
215
215
|
header: DocumentHeader;
|
|
216
216
|
updatedOperations?: Operation[] | undefined;
|
|
217
217
|
} | null = null;
|
|
218
|
-
|
|
219
218
|
await this.db.$transaction(async tx => {
|
|
220
219
|
const document = await this.getDocument(drive, id, tx);
|
|
221
|
-
|
|
222
220
|
if (!document) {
|
|
223
221
|
throw new Error(`Document with id ${id} not found`);
|
|
224
222
|
}
|
|
225
|
-
|
|
226
223
|
result = await callback(document);
|
|
227
224
|
|
|
228
225
|
const { operations, header, updatedOperations } = result;
|
|
229
|
-
|
|
230
226
|
return this._addDocumentOperations(
|
|
231
227
|
tx,
|
|
232
228
|
drive,
|