document-drive 1.0.0-alpha.39 → 1.0.0-alpha.40
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 +5 -5
- package/src/server/index.ts +19 -36
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.40",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./src/index.ts",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"test:watch": "vitest watch"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"document-model": "^1.0.
|
|
36
|
-
"document-model-libs": "^1.
|
|
35
|
+
"document-model": "^1.0.44",
|
|
36
|
+
"document-model-libs": "^1.34.0"
|
|
37
37
|
},
|
|
38
38
|
"optionalDependencies": {
|
|
39
39
|
"@prisma/client": "5.11.0",
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
61
61
|
"@typescript-eslint/parser": "^6.21.0",
|
|
62
62
|
"@vitest/coverage-v8": "^1.4.0",
|
|
63
|
-
"document-model": "^1.0.
|
|
64
|
-
"document-model-libs": "^1.
|
|
63
|
+
"document-model": "^1.0.44",
|
|
64
|
+
"document-model-libs": "^1.34.0",
|
|
65
65
|
"eslint": "^8.57.0",
|
|
66
66
|
"eslint-config-prettier": "^9.1.0",
|
|
67
67
|
"fake-indexeddb": "^5.0.2",
|
package/src/server/index.ts
CHANGED
|
@@ -316,9 +316,8 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
|
|
|
316
316
|
: this.getDrive(driveId));
|
|
317
317
|
|
|
318
318
|
for (const { syncId, scope, branch } of nodeUnits) {
|
|
319
|
-
const operations =
|
|
320
|
-
|
|
321
|
-
const lastOperation = operations.pop();
|
|
319
|
+
const operations = document.operations[scope as OperationScope] ?? [];
|
|
320
|
+
const lastOperation = operations[operations.length - 1];
|
|
322
321
|
synchronizationUnits.push({
|
|
323
322
|
syncId,
|
|
324
323
|
scope,
|
|
@@ -501,7 +500,9 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
|
|
|
501
500
|
),
|
|
502
501
|
documentModel.reducer,
|
|
503
502
|
undefined,
|
|
504
|
-
driveStorage
|
|
503
|
+
driveStorage,
|
|
504
|
+
undefined,
|
|
505
|
+
{ checkHashes: false }
|
|
505
506
|
);
|
|
506
507
|
if (!isDocumentDrive(document)) {
|
|
507
508
|
throw new Error(
|
|
@@ -532,7 +533,9 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
|
|
|
532
533
|
filterOperationsByRevision(operations, options?.revisions),
|
|
533
534
|
documentModel.reducer,
|
|
534
535
|
undefined,
|
|
535
|
-
header
|
|
536
|
+
header,
|
|
537
|
+
undefined,
|
|
538
|
+
{ checkHashes: false }
|
|
536
539
|
);
|
|
537
540
|
this.cache.setDocument(drive, id, document).catch(logger.error);
|
|
538
541
|
return document;
|
|
@@ -683,7 +686,9 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
|
|
|
683
686
|
documentStorage.operations,
|
|
684
687
|
documentModel.reducer,
|
|
685
688
|
undefined,
|
|
686
|
-
documentStorage
|
|
689
|
+
documentStorage,
|
|
690
|
+
undefined,
|
|
691
|
+
{ checkHashes: false }
|
|
687
692
|
) as T;
|
|
688
693
|
}
|
|
689
694
|
|
|
@@ -1105,31 +1110,13 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
|
|
|
1105
1110
|
}
|
|
1106
1111
|
}
|
|
1107
1112
|
|
|
1108
|
-
private _buildOperation<T extends Action>(
|
|
1109
|
-
documentStorage: DocumentStorage,
|
|
1110
|
-
action: T | BaseAction
|
|
1111
|
-
): Operation<T | BaseAction> {
|
|
1112
|
-
const [operation] = this._buildOperations(documentStorage, [action]);
|
|
1113
|
-
if (!operation) {
|
|
1114
|
-
throw new Error('Error creating operation');
|
|
1115
|
-
}
|
|
1116
|
-
return operation;
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
1113
|
private _buildOperations<T extends Action>(
|
|
1120
|
-
|
|
1114
|
+
document: Document,
|
|
1121
1115
|
actions: (T | BaseAction)[]
|
|
1122
1116
|
): Operation<T | BaseAction>[] {
|
|
1123
1117
|
const operations: Operation<T | BaseAction>[] = [];
|
|
1124
1118
|
const { reducer } = this._getDocumentModel(
|
|
1125
|
-
|
|
1126
|
-
);
|
|
1127
|
-
let document = baseUtils.replayDocument(
|
|
1128
|
-
documentStorage.initialState,
|
|
1129
|
-
documentStorage.operations,
|
|
1130
|
-
reducer,
|
|
1131
|
-
undefined,
|
|
1132
|
-
documentStorage
|
|
1119
|
+
document.documentType
|
|
1133
1120
|
);
|
|
1134
1121
|
for (const action of actions) {
|
|
1135
1122
|
document = reducer(document, action);
|
|
@@ -1147,9 +1134,7 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
|
|
|
1147
1134
|
id: string,
|
|
1148
1135
|
action: Action
|
|
1149
1136
|
): Promise<IOperationResult> {
|
|
1150
|
-
|
|
1151
|
-
const operation = this._buildOperation(documentStorage, action);
|
|
1152
|
-
return this.addOperation(drive, id, operation);
|
|
1137
|
+
return this.addActions(drive, id, [action]);
|
|
1153
1138
|
}
|
|
1154
1139
|
|
|
1155
1140
|
async addActions(
|
|
@@ -1157,8 +1142,8 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
|
|
|
1157
1142
|
id: string,
|
|
1158
1143
|
actions: Action[]
|
|
1159
1144
|
): Promise<IOperationResult> {
|
|
1160
|
-
const
|
|
1161
|
-
const operations = this._buildOperations(
|
|
1145
|
+
const document = await this.getDocument(drive, id);
|
|
1146
|
+
const operations = this._buildOperations(document, actions);
|
|
1162
1147
|
return this.addOperations(drive, id, operations);
|
|
1163
1148
|
}
|
|
1164
1149
|
|
|
@@ -1166,17 +1151,15 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
|
|
|
1166
1151
|
drive: string,
|
|
1167
1152
|
action: DocumentDriveAction | BaseAction
|
|
1168
1153
|
): Promise<IOperationResult<DocumentDriveDocument>> {
|
|
1169
|
-
|
|
1170
|
-
const operation = this._buildOperation(documentStorage, action);
|
|
1171
|
-
return this.addDriveOperation(drive, operation);
|
|
1154
|
+
return this.addDriveActions(drive, [action]);
|
|
1172
1155
|
}
|
|
1173
1156
|
|
|
1174
1157
|
async addDriveActions(
|
|
1175
1158
|
drive: string,
|
|
1176
1159
|
actions: (DocumentDriveAction | BaseAction)[]
|
|
1177
1160
|
): Promise<IOperationResult<DocumentDriveDocument>> {
|
|
1178
|
-
const
|
|
1179
|
-
const operations = this._buildOperations(
|
|
1161
|
+
const document = await this.getDrive(drive);
|
|
1162
|
+
const operations = this._buildOperations(document, actions);
|
|
1180
1163
|
return this.addDriveOperations(drive, operations);
|
|
1181
1164
|
}
|
|
1182
1165
|
|