document-drive 1.0.0-alpha.67 → 1.0.0-alpha.69
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 +1 -1
- package/src/queue/base.ts +1 -1
- package/src/queue/redis.ts +12 -11
- package/src/server/types.ts +4 -0
- package/src/storage/prisma.ts +13 -0
package/package.json
CHANGED
package/src/queue/base.ts
CHANGED
package/src/queue/redis.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RedisClientType } from "redis";
|
|
2
|
-
import { IJob, IQueue, IQueueManager, OperationJob } from "./types";
|
|
2
|
+
import { IJob, IQueue, IQueueManager, IServerDelegate, OperationJob } from "./types";
|
|
3
3
|
import { BaseQueueManager } from "./base";
|
|
4
4
|
|
|
5
5
|
export class RedisQueue<T, R> implements IQueue<T, R> {
|
|
@@ -10,7 +10,7 @@ export class RedisQueue<T, R> implements IQueue<T, R> {
|
|
|
10
10
|
this.client = client;
|
|
11
11
|
this.id = id;
|
|
12
12
|
this.client.hSet("queues", id, "true");
|
|
13
|
-
|
|
13
|
+
this.client.hSet(this.id, "blocked", "false");
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
async addJob(data: any) {
|
|
@@ -33,13 +33,13 @@ export class RedisQueue<T, R> implements IQueue<T, R> {
|
|
|
33
33
|
if (blocked) {
|
|
34
34
|
await this.client.hSet(this.id, "blocked", "true");
|
|
35
35
|
} else {
|
|
36
|
-
await this.client.
|
|
36
|
+
await this.client.hSet(this.id, "blocked", "false");
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
async isBlocked() {
|
|
41
41
|
const blockedResult = await this.client.hGet(this.id, "blocked");
|
|
42
|
-
if (blockedResult) {
|
|
42
|
+
if (blockedResult === "true") {
|
|
43
43
|
return true;
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -69,7 +69,6 @@ export class RedisQueue<T, R> implements IQueue<T, R> {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
async removeDependencies(job: IJob<OperationJob>) {
|
|
72
|
-
const allDeps1 = await this.client.lLen(this.id + "-deps");
|
|
73
72
|
await this.client.lRem(this.id + "-deps", 1, JSON.stringify(job));
|
|
74
73
|
const allDeps = await this.client.lLen(this.id + "-deps");
|
|
75
74
|
if (allDeps > 0) {
|
|
@@ -80,15 +79,15 @@ export class RedisQueue<T, R> implements IQueue<T, R> {
|
|
|
80
79
|
}
|
|
81
80
|
|
|
82
81
|
async isDeleted() {
|
|
83
|
-
const
|
|
84
|
-
return
|
|
82
|
+
const active = await this.client.hGet("queues", this.id);
|
|
83
|
+
return active === "false";
|
|
85
84
|
}
|
|
86
85
|
|
|
87
86
|
async setDeleted(deleted: boolean) {
|
|
88
87
|
if (deleted) {
|
|
89
|
-
await this.client.hSet(this.id, "
|
|
88
|
+
await this.client.hSet("queues", this.id, "false");
|
|
90
89
|
} else {
|
|
91
|
-
await this.client.
|
|
90
|
+
await this.client.hSet("queues", this.id, "true");
|
|
92
91
|
}
|
|
93
92
|
}
|
|
94
93
|
}
|
|
@@ -104,10 +103,12 @@ export class RedisQueueManager extends BaseQueueManager implements IQueueManager
|
|
|
104
103
|
|
|
105
104
|
async init(delegate: IServerDelegate, onError: (error: Error) => void): Promise<void> {
|
|
106
105
|
await super.init(delegate, onError);
|
|
107
|
-
// load all queues
|
|
108
106
|
const queues = await this.client.hGetAll("queues");
|
|
109
107
|
for (const queueId in queues) {
|
|
110
|
-
this.
|
|
108
|
+
const active = await this.client.hGet("queues", queueId);
|
|
109
|
+
if (active === "true") {
|
|
110
|
+
this.queues.push(new RedisQueue(queueId, this.client));
|
|
111
|
+
}
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
114
|
|
package/src/server/types.ts
CHANGED
|
@@ -161,6 +161,10 @@ export abstract class BaseDocumentDriveServer {
|
|
|
161
161
|
options?: GetDocumentOptions
|
|
162
162
|
): Promise<DocumentDriveDocument>;
|
|
163
163
|
|
|
164
|
+
abstract getDriveBySlug(
|
|
165
|
+
slug: string,
|
|
166
|
+
): Promise<DocumentDriveDocument>;
|
|
167
|
+
|
|
164
168
|
abstract getDocuments(drive: string): Promise<string[]>;
|
|
165
169
|
abstract getDocument(
|
|
166
170
|
drive: string,
|
package/src/storage/prisma.ts
CHANGED
|
@@ -329,6 +329,9 @@ export class PrismaStorage implements IDriveStorage {
|
|
|
329
329
|
|
|
330
330
|
async getDocuments(drive: string) {
|
|
331
331
|
const docs = await this.db.document.findMany({
|
|
332
|
+
select: {
|
|
333
|
+
id: true
|
|
334
|
+
},
|
|
332
335
|
where: {
|
|
333
336
|
AND: {
|
|
334
337
|
driveId: drive,
|
|
@@ -513,11 +516,21 @@ export class PrismaStorage implements IDriveStorage {
|
|
|
513
516
|
}
|
|
514
517
|
|
|
515
518
|
async deleteDrive(id: string) {
|
|
519
|
+
// delete drive documents and operations
|
|
516
520
|
await this.db.document.deleteMany({
|
|
517
521
|
where: {
|
|
518
522
|
driveId: id
|
|
519
523
|
}
|
|
520
524
|
});
|
|
525
|
+
|
|
526
|
+
// delete drive and associated slug
|
|
527
|
+
await this.db.drive.deleteMany({
|
|
528
|
+
where: {
|
|
529
|
+
id
|
|
530
|
+
}
|
|
531
|
+
})
|
|
532
|
+
|
|
533
|
+
// delete drive itself
|
|
521
534
|
await this.deleteDocument('drives', id);
|
|
522
535
|
}
|
|
523
536
|
|