document-drive 1.0.0-alpha.71 → 1.0.0-alpha.72

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/server/index.ts +109 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-drive",
3
- "version": "1.0.0-alpha.71",
3
+ "version": "1.0.0-alpha.72",
4
4
  "license": "AGPL-3.0-only",
5
5
  "type": "module",
6
6
  "module": "./src/index.ts",
@@ -87,7 +87,7 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
87
87
  DocumentDriveState['id'],
88
88
  Map<Trigger['id'], CancelPullLoop>
89
89
  >();
90
- private syncStatus = new Map<DocumentDriveState['id'], SyncStatus>();
90
+ private syncStatus = new Map<string, SyncStatus>();
91
91
 
92
92
  private queueManager: IQueueManager;
93
93
 
@@ -186,6 +186,8 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
186
186
  const drive = await this.getDrive(driveId);
187
187
  let driveTriggers = this.triggerMap.get(driveId);
188
188
 
189
+ const syncUnits = await this.getSynchronizationUnits(driveId);
190
+
189
191
  for (const trigger of drive.state.local.triggers) {
190
192
  if (driveTriggers?.get(trigger.id)) {
191
193
  continue;
@@ -196,6 +198,11 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
196
198
  }
197
199
 
198
200
  this.updateSyncStatus(driveId, 'SYNCING');
201
+
202
+ for (const syncUnit of syncUnits) {
203
+ this.updateSyncStatus(syncUnit.syncId, 'SYNCING');
204
+ }
205
+
199
206
  if (PullResponderTransmitter.isPullResponderTrigger(trigger)) {
200
207
  const cancelPullLoop = PullResponderTransmitter.setupPull(
201
208
  driveId,
@@ -211,12 +218,31 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
211
218
  );
212
219
  },
213
220
  revisions => {
214
- const errorRevision = revisions.find(
221
+ const errorRevision = revisions.filter(
215
222
  r => r.status !== 'SUCCESS'
216
223
  );
217
- if (!errorRevision) {
224
+ if (errorRevision.length < 1) {
218
225
  this.updateSyncStatus(driveId, 'SUCCESS');
219
226
  }
227
+
228
+ for (const syncUnit of syncUnits) {
229
+ const fileErrorRevision = errorRevision.find(
230
+ r => r.documentId === syncUnit.documentId
231
+ );
232
+
233
+ if (fileErrorRevision) {
234
+ this.updateSyncStatus(
235
+ syncUnit.syncId,
236
+ fileErrorRevision.status,
237
+ fileErrorRevision.error
238
+ );
239
+ } else {
240
+ this.updateSyncStatus(
241
+ syncUnit.syncId,
242
+ 'SUCCESS'
243
+ );
244
+ }
245
+ }
220
246
  }
221
247
  );
222
248
  driveTriggers.set(trigger.id, cancelPullLoop);
@@ -226,9 +252,18 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
226
252
  }
227
253
 
228
254
  private async stopSyncRemoteDrive(driveId: string) {
255
+ const syncUnits = await this.getSynchronizationUnits(driveId);
256
+ const fileNodes = syncUnits
257
+ .filter(syncUnit => syncUnit.documentId !== '')
258
+ .map(syncUnit => syncUnit.documentId);
259
+
229
260
  const triggers = this.triggerMap.get(driveId);
230
261
  triggers?.forEach(cancel => cancel());
231
262
  this.updateSyncStatus(driveId, null);
263
+
264
+ for (const fileNode of fileNodes) {
265
+ this.updateSyncStatus(fileNode, null);
266
+ }
232
267
  return this.triggerMap.delete(driveId);
233
268
  }
234
269
 
@@ -1075,21 +1110,37 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
1075
1110
  .updateSynchronizationRevisions(
1076
1111
  drive,
1077
1112
  syncUnits,
1078
- () => this.updateSyncStatus(drive, 'SYNCING'),
1113
+ () => {
1114
+ this.updateSyncStatus(drive, 'SYNCING');
1115
+
1116
+ for (const syncUnit of syncUnits) {
1117
+ this.updateSyncStatus(syncUnit.syncId, 'SYNCING');
1118
+ }
1119
+ },
1079
1120
  this.handleListenerError.bind(this),
1080
1121
  forceSync
1081
1122
  )
1082
- .then(
1083
- updates =>
1084
- updates.length &&
1085
- this.updateSyncStatus(drive, 'SUCCESS')
1086
- )
1123
+ .then(updates => {
1124
+ updates.length && this.updateSyncStatus(drive, 'SUCCESS');
1125
+
1126
+ for (const syncUnit of syncUnits) {
1127
+ this.updateSyncStatus(syncUnit.syncId, 'SUCCESS');
1128
+ }
1129
+ })
1087
1130
  .catch(error => {
1088
1131
  logger.error(
1089
1132
  'Non handled error updating sync revision',
1090
1133
  error
1091
1134
  );
1092
1135
  this.updateSyncStatus(drive, 'ERROR', error as Error);
1136
+
1137
+ for (const syncUnit of syncUnits) {
1138
+ this.updateSyncStatus(
1139
+ syncUnit.syncId,
1140
+ 'ERROR',
1141
+ error as Error
1142
+ );
1143
+ }
1093
1144
  });
1094
1145
 
1095
1146
  // after applying all the valid operations,throws
@@ -1208,6 +1259,8 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
1208
1259
  const signals: SignalResult[] = [];
1209
1260
  let error: Error | undefined;
1210
1261
 
1262
+ const prevSyncUnits = await this.getSynchronizationUnits(drive);
1263
+
1211
1264
  try {
1212
1265
  await this._addDriveOperations(drive, async documentStorage => {
1213
1266
  const result = await this._processOperations<
@@ -1247,6 +1300,19 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
1247
1300
  }
1248
1301
  }
1249
1302
 
1303
+ const syncUnits = await this.getSynchronizationUnits(drive);
1304
+
1305
+ const prevSyncUnitsIds = prevSyncUnits.map(unit => unit.syncId);
1306
+ const syncUnitsIds = syncUnits.map(unit => unit.syncId);
1307
+
1308
+ const newSyncUnits = syncUnitsIds.filter(
1309
+ syncUnitId => !prevSyncUnitsIds.includes(syncUnitId)
1310
+ );
1311
+
1312
+ const removedSyncUnits = prevSyncUnitsIds.filter(
1313
+ syncUnitId => !syncUnitsIds.includes(syncUnitId)
1314
+ );
1315
+
1250
1316
  // update listener cache
1251
1317
  const lastOperation = operationsApplied
1252
1318
  .filter(op => op.scope === 'global')
@@ -1268,21 +1334,49 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
1268
1334
  revision: lastOperation.index
1269
1335
  }
1270
1336
  ],
1271
- () => this.updateSyncStatus(drive, 'SYNCING'),
1337
+ () => {
1338
+ this.updateSyncStatus(drive, 'SYNCING');
1339
+
1340
+ for (const syncUnitId of [
1341
+ ...newSyncUnits,
1342
+ ...removedSyncUnits
1343
+ ]) {
1344
+ this.updateSyncStatus(syncUnitId, 'SYNCING');
1345
+ }
1346
+ },
1272
1347
  this.handleListenerError.bind(this),
1273
1348
  forceSync
1274
1349
  )
1275
- .then(
1276
- updates =>
1277
- updates.length &&
1278
- this.updateSyncStatus(drive, 'SUCCESS')
1279
- )
1350
+ .then(updates => {
1351
+ if (updates.length) {
1352
+ this.updateSyncStatus(drive, 'SUCCESS');
1353
+
1354
+ for (const syncUnitId of newSyncUnits) {
1355
+ this.updateSyncStatus(syncUnitId, 'SUCCESS');
1356
+ }
1357
+
1358
+ for (const syncUnitId of removedSyncUnits) {
1359
+ this.updateSyncStatus(syncUnitId, null);
1360
+ }
1361
+ }
1362
+ })
1280
1363
  .catch(error => {
1281
1364
  logger.error(
1282
1365
  'Non handled error updating sync revision',
1283
1366
  error
1284
1367
  );
1285
1368
  this.updateSyncStatus(drive, 'ERROR', error as Error);
1369
+
1370
+ for (const syncUnitId of [
1371
+ ...newSyncUnits,
1372
+ ...removedSyncUnits
1373
+ ]) {
1374
+ this.updateSyncStatus(
1375
+ syncUnitId,
1376
+ 'ERROR',
1377
+ error as Error
1378
+ );
1379
+ }
1286
1380
  });
1287
1381
  }
1288
1382