document-drive 1.0.0-alpha.3 → 1.0.0-alpha.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-drive",
3
- "version": "1.0.0-alpha.3",
3
+ "version": "1.0.0-alpha.5",
4
4
  "license": "AGPL-3.0-only",
5
5
  "type": "module",
6
6
  "module": "./src/index.ts",
@@ -305,10 +305,10 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
305
305
  const filteredOperations = operations.filter(
306
306
  operation =>
307
307
  Object.keys(filter).length === 0 ||
308
- (filter.since !== undefined &&
309
- filter.since <= operation.timestamp) ||
310
- (filter.fromRevision !== undefined &&
311
- operation.index > filter.fromRevision)
308
+ ((filter.since === undefined ||
309
+ filter.since <= operation.timestamp) &&
310
+ (filter.fromRevision === undefined ||
311
+ operation.index > filter.fromRevision))
312
312
  );
313
313
 
314
314
  return filteredOperations.map(operation => ({
@@ -68,17 +68,8 @@ export class PrismaStorage implements IDriveStorage {
68
68
  try {
69
69
  await Promise.all(
70
70
  operations.map(async op => {
71
- return this.db.operation.upsert({
72
- where: {
73
- driveId_documentId_scope_branch_index: {
74
- driveId: drive,
75
- documentId: id,
76
- scope: op.scope,
77
- branch: 'main',
78
- index: op.index
79
- }
80
- },
81
- create: {
71
+ return this.db.operation.createMany({
72
+ data: {
82
73
  driveId: drive,
83
74
  documentId: id,
84
75
  hash: op.hash,
@@ -90,18 +81,6 @@ export class PrismaStorage implements IDriveStorage {
90
81
  branch: 'main',
91
82
  skip: op.skip
92
83
  },
93
- update: {
94
- driveId: drive,
95
- documentId: id,
96
- hash: op.hash,
97
- index: op.index,
98
- input: op.input as Prisma.InputJsonObject,
99
- timestamp: op.timestamp,
100
- type: op.type,
101
- scope: op.scope,
102
- branch: 'main',
103
- skip: op.skip
104
- }
105
84
  });
106
85
  })
107
86
  );
@@ -213,48 +192,22 @@ export class PrismaStorage implements IDriveStorage {
213
192
  }
214
193
 
215
194
  async deleteDocument(drive: string, id: string) {
216
- await this.db.attachment.deleteMany({
217
- where: {
218
- driveId: drive,
219
- documentId: id
220
- }
221
- });
222
-
223
- await this.db.operation.deleteMany({
224
- where: {
225
- driveId: drive,
226
- documentId: id
227
- }
228
- });
229
-
230
195
  await this.db.document.delete({
231
196
  where: {
232
197
  id_driveId: {
233
198
  driveId: drive,
234
199
  id: id
235
200
  }
201
+ },
202
+ include: {
203
+ operations: {
204
+ include: {
205
+ attachments: true
206
+ }
207
+ }
236
208
  }
237
209
  });
238
210
 
239
- if (drive === 'drives') {
240
- await this.db.attachment.deleteMany({
241
- where: {
242
- driveId: id
243
- }
244
- });
245
-
246
- await this.db.operation.deleteMany({
247
- where: {
248
- driveId: id
249
- }
250
- });
251
-
252
- await this.db.document.deleteMany({
253
- where: {
254
- driveId: id
255
- }
256
- });
257
- }
258
211
  }
259
212
 
260
213
  async getDrives() {
@@ -271,6 +224,10 @@ export class PrismaStorage implements IDriveStorage {
271
224
  }
272
225
 
273
226
  async deleteDrive(id: string) {
227
+ const docs = await this.getDocuments(id);
228
+ await Promise.all(docs.map(async doc => {
229
+ return this.deleteDocument(id, doc)
230
+ }));
274
231
  await this.deleteDocument('drives', id);
275
232
  }
276
233
  }