document-drive 1.29.0 → 1.29.1-dev.0
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/dist/prisma/schema.prisma +6 -10
- package/dist/src/cache/memory.d.ts +14 -4
- package/dist/src/cache/memory.d.ts.map +1 -1
- package/dist/src/cache/memory.js +57 -19
- package/dist/src/cache/redis.d.ts +14 -4
- package/dist/src/cache/redis.d.ts.map +1 -1
- package/dist/src/cache/redis.js +71 -19
- package/dist/src/cache/types.d.ts +10 -3
- package/dist/src/cache/types.d.ts.map +1 -1
- package/dist/src/cache/util.d.ts +3 -0
- package/dist/src/cache/util.d.ts.map +1 -0
- package/dist/src/cache/util.js +13 -0
- package/dist/src/server/base-server.d.ts +1 -1
- package/dist/src/server/base-server.d.ts.map +1 -1
- package/dist/src/server/base-server.js +35 -28
- package/dist/src/server/listener/listener-manager.js +2 -2
- package/dist/src/server/listener/transmitter/pull-responder.d.ts +1 -1
- package/dist/src/server/listener/transmitter/pull-responder.d.ts.map +1 -1
- package/dist/src/server/listener/transmitter/pull-responder.js +2 -3
- package/dist/src/server/sync-manager.d.ts.map +1 -1
- package/dist/src/server/sync-manager.js +7 -18
- package/dist/src/server/types.d.ts +0 -1
- package/dist/src/server/types.d.ts.map +1 -1
- package/dist/src/storage/browser.d.ts +6 -4
- package/dist/src/storage/browser.d.ts.map +1 -1
- package/dist/src/storage/browser.js +83 -22
- package/dist/src/storage/filesystem.d.ts +5 -3
- package/dist/src/storage/filesystem.d.ts.map +1 -1
- package/dist/src/storage/filesystem.js +83 -29
- package/dist/src/storage/ipfs.d.ts +5 -1
- package/dist/src/storage/ipfs.d.ts.map +1 -1
- package/dist/src/storage/ipfs.js +74 -21
- package/dist/src/storage/memory.d.ts +5 -5
- package/dist/src/storage/memory.d.ts.map +1 -1
- package/dist/src/storage/memory.js +78 -51
- package/dist/src/storage/prisma/factory.d.ts +4 -3
- package/dist/src/storage/prisma/factory.d.ts.map +1 -1
- package/dist/src/storage/prisma/factory.js +5 -5
- package/dist/src/storage/prisma/index.d.ts +11 -6
- package/dist/src/storage/prisma/index.d.ts.map +1 -1
- package/dist/src/storage/prisma/index.js +233 -190
- package/dist/src/storage/types.d.ts +6 -6
- package/dist/src/storage/types.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
|
@@ -27,7 +27,7 @@ model Document {
|
|
|
27
27
|
initialState String // json object with the scope as keys of the root object
|
|
28
28
|
documentType String
|
|
29
29
|
meta String?
|
|
30
|
-
|
|
30
|
+
synchronizationUnits SynchronizationUnit[]
|
|
31
31
|
driveDocuments DriveDocument[]
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -46,7 +46,6 @@ model DriveDocument {
|
|
|
46
46
|
model Operation {
|
|
47
47
|
id String @id @default(uuid())
|
|
48
48
|
opId String?
|
|
49
|
-
driveId String
|
|
50
49
|
Document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade)
|
|
51
50
|
documentId String
|
|
52
51
|
scope String
|
|
@@ -63,22 +62,19 @@ model Operation {
|
|
|
63
62
|
context Json?
|
|
64
63
|
resultingState Bytes?
|
|
65
64
|
|
|
66
|
-
|
|
65
|
+
SynchronizationUnit SynchronizationUnit? @relation(fields: [syncId], references: [id], onDelete: Cascade)
|
|
67
66
|
|
|
68
|
-
@@unique([
|
|
67
|
+
@@unique([documentId, scope, branch, index(sort: Asc)], name: "unique_operation")
|
|
69
68
|
}
|
|
70
69
|
|
|
71
|
-
model
|
|
72
|
-
id String
|
|
73
|
-
driveId String
|
|
70
|
+
model SynchronizationUnit {
|
|
71
|
+
id String @id
|
|
74
72
|
documentId String
|
|
75
73
|
|
|
76
|
-
Document Document
|
|
74
|
+
Document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
|
|
77
75
|
scope String
|
|
78
76
|
branch String
|
|
79
77
|
operations Operation[]
|
|
80
|
-
|
|
81
|
-
@@id([id, driveId])
|
|
82
78
|
}
|
|
83
79
|
|
|
84
80
|
model Attachment {
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
+
import { type DocumentDriveDocument } from "#drive-document-model/gen/types";
|
|
1
2
|
import { type PHDocument } from "document-model";
|
|
2
3
|
import { type ICache } from "./types.js";
|
|
3
4
|
declare class InMemoryCache implements ICache {
|
|
4
|
-
private
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
private idTodocument;
|
|
6
|
+
private idToDrive;
|
|
7
|
+
private slugToDriveId;
|
|
8
|
+
clear(): void;
|
|
9
|
+
setDocument(documentId: string, document: PHDocument): Promise<void>;
|
|
10
|
+
getDocument<TDocument extends PHDocument>(documentId: string): Promise<TDocument | undefined>;
|
|
11
|
+
deleteDocument(documentId: string): Promise<boolean>;
|
|
12
|
+
setDrive(driveId: string, drive: DocumentDriveDocument): Promise<void>;
|
|
13
|
+
getDrive(driveId: string): Promise<DocumentDriveDocument | undefined>;
|
|
14
|
+
deleteDrive(driveId: string): Promise<boolean>;
|
|
15
|
+
setDriveBySlug(slug: string, drive: DocumentDriveDocument): Promise<void>;
|
|
16
|
+
getDriveBySlug(slug: string): Promise<DocumentDriveDocument | undefined>;
|
|
17
|
+
deleteDriveBySlug(slug: string): Promise<boolean>;
|
|
8
18
|
}
|
|
9
19
|
export default InMemoryCache;
|
|
10
20
|
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/cache/memory.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/cache/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAGzC,cAAM,aAAc,YAAW,MAAM;IACnC,OAAO,CAAC,YAAY,CAAiC;IACrD,OAAO,CAAC,SAAS,CAA4C;IAC7D,OAAO,CAAC,aAAa,CAA6B;IAElD,KAAK;IAUC,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU;IAKpD,WAAW,CAAC,SAAS,SAAS,UAAU,EAC5C,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAI3B,cAAc,CAAC,UAAU,EAAE,MAAM;IAIjC,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,qBAAqB;IAKtD,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;IAIrE,WAAW,CAAC,OAAO,EAAE,MAAM;IAe3B,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,qBAAqB;IAMzD,cAAc,CAClB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;IAQvC,iBAAiB,CAAC,IAAI,EAAE,MAAM;CASrC;AAED,eAAe,aAAa,CAAC"}
|
package/dist/src/cache/memory.js
CHANGED
|
@@ -1,26 +1,64 @@
|
|
|
1
|
+
import { trimResultingState } from "./util.js";
|
|
1
2
|
class InMemoryCache {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
idTodocument = new Map();
|
|
4
|
+
idToDrive = new Map();
|
|
5
|
+
slugToDriveId = new Map();
|
|
6
|
+
clear() {
|
|
7
|
+
this.idTodocument.clear();
|
|
8
|
+
this.idToDrive.clear();
|
|
9
|
+
this.slugToDriveId.clear();
|
|
10
|
+
}
|
|
11
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
12
|
+
// ICache
|
|
13
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
14
|
+
async setDocument(documentId, document) {
|
|
15
|
+
const doc = trimResultingState(document);
|
|
16
|
+
this.idTodocument.set(documentId, doc);
|
|
17
|
+
}
|
|
18
|
+
async getDocument(documentId) {
|
|
19
|
+
return this.idTodocument.get(documentId);
|
|
20
|
+
}
|
|
21
|
+
async deleteDocument(documentId) {
|
|
22
|
+
return this.idTodocument.delete(documentId);
|
|
23
|
+
}
|
|
24
|
+
async setDrive(driveId, drive) {
|
|
25
|
+
const doc = trimResultingState(drive);
|
|
26
|
+
this.idToDrive.set(driveId, doc);
|
|
27
|
+
}
|
|
28
|
+
async getDrive(driveId) {
|
|
29
|
+
return this.idToDrive.get(driveId);
|
|
30
|
+
}
|
|
31
|
+
async deleteDrive(driveId) {
|
|
32
|
+
// look up the slug
|
|
33
|
+
const drive = this.idToDrive.get(driveId);
|
|
34
|
+
if (!drive) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const slug = drive.state.global.slug;
|
|
38
|
+
if (slug) {
|
|
39
|
+
this.slugToDriveId.delete(slug);
|
|
15
40
|
}
|
|
16
|
-
this.
|
|
17
|
-
return true;
|
|
41
|
+
return this.idToDrive.delete(driveId);
|
|
18
42
|
}
|
|
19
|
-
async
|
|
20
|
-
|
|
43
|
+
async setDriveBySlug(slug, drive) {
|
|
44
|
+
const driveId = drive.state.global.id;
|
|
45
|
+
this.slugToDriveId.set(slug, driveId);
|
|
46
|
+
this.setDrive(driveId, drive);
|
|
21
47
|
}
|
|
22
|
-
async
|
|
23
|
-
|
|
48
|
+
async getDriveBySlug(slug) {
|
|
49
|
+
const driveId = this.slugToDriveId.get(slug);
|
|
50
|
+
if (!driveId) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
return this.getDrive(driveId);
|
|
54
|
+
}
|
|
55
|
+
async deleteDriveBySlug(slug) {
|
|
56
|
+
const driveId = this.slugToDriveId.get(slug);
|
|
57
|
+
if (!driveId) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
this.slugToDriveId.delete(slug);
|
|
61
|
+
return this.deleteDrive(driveId);
|
|
24
62
|
}
|
|
25
63
|
}
|
|
26
64
|
export default InMemoryCache;
|
|
@@ -1,14 +1,24 @@
|
|
|
1
|
+
import { type DocumentDriveDocument } from "#drive-document-model/gen/types";
|
|
1
2
|
import { type PHDocument } from "document-model";
|
|
2
3
|
import type { RedisClientType } from "redis";
|
|
3
4
|
import { type ICache } from "./types.js";
|
|
4
5
|
declare class RedisCache implements ICache {
|
|
6
|
+
private logger;
|
|
5
7
|
private redis;
|
|
6
8
|
private timeoutInSeconds;
|
|
7
9
|
constructor(redis: RedisClientType, timeoutInSeconds?: number | undefined);
|
|
8
|
-
private static
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
private static _getDocumentKey;
|
|
11
|
+
private static _getDriveKey;
|
|
12
|
+
private static _getDriveBySlugKey;
|
|
13
|
+
setDocument(documentId: string, document: PHDocument): Promise<void>;
|
|
14
|
+
getDocument<TDocument extends PHDocument>(documentId: string): Promise<TDocument | undefined>;
|
|
15
|
+
deleteDocument(documentId: string): Promise<boolean>;
|
|
16
|
+
setDrive(driveId: string, drive: DocumentDriveDocument): Promise<void>;
|
|
17
|
+
getDrive(driveId: string): Promise<DocumentDriveDocument | undefined>;
|
|
18
|
+
deleteDrive(driveId: string): Promise<boolean>;
|
|
19
|
+
setDriveBySlug(slug: string, drive: DocumentDriveDocument): Promise<void>;
|
|
20
|
+
getDriveBySlug(slug: string): Promise<DocumentDriveDocument | undefined>;
|
|
21
|
+
deleteDriveBySlug(slug: string): Promise<boolean>;
|
|
12
22
|
}
|
|
13
23
|
export default RedisCache;
|
|
14
24
|
//# sourceMappingURL=redis.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../../src/cache/redis.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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/redis.js
CHANGED
|
@@ -1,39 +1,91 @@
|
|
|
1
|
+
import { childLogger } from "#utils/logger";
|
|
2
|
+
import { trimResultingState } from "./util.js";
|
|
1
3
|
class RedisCache {
|
|
4
|
+
logger = childLogger(["RedisCache"]);
|
|
2
5
|
redis;
|
|
3
6
|
timeoutInSeconds;
|
|
4
7
|
constructor(redis, timeoutInSeconds = 5 * 60) {
|
|
5
8
|
this.redis = redis;
|
|
6
9
|
this.timeoutInSeconds = timeoutInSeconds;
|
|
7
10
|
}
|
|
8
|
-
static
|
|
9
|
-
return `cache:${
|
|
11
|
+
static _getDocumentKey(documentId) {
|
|
12
|
+
return `cache:document:${documentId}`;
|
|
10
13
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
static _getDriveKey(driveId) {
|
|
15
|
+
return `cache:drive:${driveId}`;
|
|
16
|
+
}
|
|
17
|
+
static _getDriveBySlugKey(slug) {
|
|
18
|
+
return `cache:drive:slug:${slug}`;
|
|
19
|
+
}
|
|
20
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
21
|
+
// ICache
|
|
22
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
async setDocument(documentId, document) {
|
|
24
|
+
const doc = trimResultingState(document);
|
|
25
|
+
const redisId = RedisCache._getDocumentKey(documentId);
|
|
26
|
+
const result = await this.redis.set(redisId, JSON.stringify(doc), {
|
|
27
|
+
EX: this.timeoutInSeconds ? this.timeoutInSeconds : undefined,
|
|
19
28
|
});
|
|
20
|
-
|
|
21
|
-
|
|
29
|
+
if (result !== "OK") {
|
|
30
|
+
throw new Error(`Failed to set document ${documentId} in redis. Got '${result}'`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async getDocument(documentId) {
|
|
34
|
+
const redisId = RedisCache._getDocumentKey(documentId);
|
|
35
|
+
const doc = await this.redis.get(redisId);
|
|
36
|
+
return doc ? JSON.parse(doc) : undefined;
|
|
37
|
+
}
|
|
38
|
+
async deleteDocument(documentId) {
|
|
39
|
+
const redisId = RedisCache._getDocumentKey(documentId);
|
|
40
|
+
return (await this.redis.del(redisId)) > 0;
|
|
41
|
+
}
|
|
42
|
+
async setDrive(driveId, drive) {
|
|
43
|
+
const doc = trimResultingState(drive);
|
|
44
|
+
const redisId = RedisCache._getDriveKey(driveId);
|
|
22
45
|
const result = await this.redis.set(redisId, JSON.stringify(doc), {
|
|
23
46
|
EX: this.timeoutInSeconds ? this.timeoutInSeconds : undefined,
|
|
24
47
|
});
|
|
25
|
-
if (result
|
|
26
|
-
|
|
48
|
+
if (result !== "OK") {
|
|
49
|
+
throw new Error(`Failed to set drive ${driveId} in redis. Got '${result}'`);
|
|
27
50
|
}
|
|
28
|
-
return false;
|
|
29
51
|
}
|
|
30
|
-
async
|
|
31
|
-
const redisId = RedisCache.
|
|
52
|
+
async getDrive(driveId) {
|
|
53
|
+
const redisId = RedisCache._getDriveKey(driveId);
|
|
32
54
|
const doc = await this.redis.get(redisId);
|
|
33
55
|
return doc ? JSON.parse(doc) : undefined;
|
|
34
56
|
}
|
|
35
|
-
async
|
|
36
|
-
const redisId = RedisCache.
|
|
57
|
+
async deleteDrive(driveId) {
|
|
58
|
+
const redisId = RedisCache._getDriveKey(driveId);
|
|
59
|
+
const drive = await this.getDrive(driveId);
|
|
60
|
+
if (!drive) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const slug = drive.state.global.slug;
|
|
64
|
+
if (slug) {
|
|
65
|
+
const slugRedisId = RedisCache._getDriveBySlugKey(slug);
|
|
66
|
+
await this.redis.del(slugRedisId);
|
|
67
|
+
}
|
|
68
|
+
return (await this.redis.del(redisId)) > 0;
|
|
69
|
+
}
|
|
70
|
+
// We store two pices: slug -> driveId, and driveId -> drive
|
|
71
|
+
async setDriveBySlug(slug, drive) {
|
|
72
|
+
const driveId = drive.state.global.id;
|
|
73
|
+
const redisId = RedisCache._getDriveBySlugKey(slug);
|
|
74
|
+
const result = await this.redis.set(redisId, driveId, {
|
|
75
|
+
EX: this.timeoutInSeconds ? this.timeoutInSeconds : undefined,
|
|
76
|
+
});
|
|
77
|
+
if (result !== "OK") {
|
|
78
|
+
throw new Error(`Failed to set drive slug mapping for ${slug} -> ${driveId} in redis. Got '${result}'`);
|
|
79
|
+
}
|
|
80
|
+
await this.setDrive(driveId, drive);
|
|
81
|
+
}
|
|
82
|
+
async getDriveBySlug(slug) {
|
|
83
|
+
const redisId = RedisCache._getDriveBySlugKey(slug);
|
|
84
|
+
const driveId = await this.redis.get(redisId);
|
|
85
|
+
return driveId ? await this.getDrive(driveId) : undefined;
|
|
86
|
+
}
|
|
87
|
+
async deleteDriveBySlug(slug) {
|
|
88
|
+
const redisId = RedisCache._getDriveBySlugKey(slug);
|
|
37
89
|
return (await this.redis.del(redisId)) > 0;
|
|
38
90
|
}
|
|
39
91
|
}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
import { type DocumentDriveDocument } from "#drive-document-model/gen/types";
|
|
1
2
|
import { type PHDocument } from "document-model";
|
|
2
3
|
export interface ICache {
|
|
3
|
-
setDocument(
|
|
4
|
-
getDocument<TDocument extends PHDocument>(
|
|
5
|
-
deleteDocument(
|
|
4
|
+
setDocument(documentId: string, document: PHDocument): Promise<void>;
|
|
5
|
+
getDocument<TDocument extends PHDocument>(documentId: string): Promise<TDocument | undefined>;
|
|
6
|
+
deleteDocument(documentId: string): Promise<boolean>;
|
|
7
|
+
setDrive(driveId: string, drive: DocumentDriveDocument): Promise<void>;
|
|
8
|
+
setDriveBySlug(slug: string, drive: DocumentDriveDocument): Promise<void>;
|
|
9
|
+
getDrive(driveId: string): Promise<DocumentDriveDocument | undefined>;
|
|
10
|
+
getDriveBySlug(slug: string): Promise<DocumentDriveDocument | undefined>;
|
|
11
|
+
deleteDrive(driveId: string): Promise<boolean>;
|
|
12
|
+
deleteDriveBySlug(slug: string): Promise<boolean>;
|
|
6
13
|
}
|
|
7
14
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/cache/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,MAAM,WAAW,MAAM;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/cache/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,MAAM,WAAW,MAAM;IAGrB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAGrE,WAAW,CAAC,SAAS,SAAS,UAAU,EACtC,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;IAElC,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAIrD,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAIvE,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAG1E,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAAC;IAGtE,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAAC;IAEzE,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/C,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACnD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/cache/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAIjD,eAAO,MAAM,kBAAkB,GAAI,SAAS,SAAS,UAAU,EAC7D,UAAU,SAAS,KAClB,SAYF,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Deletes the resulting state on all operations in a document.
|
|
2
|
+
// NOTE: THE RESULT IS THE CACHES MUTATE DOCUMENTS
|
|
3
|
+
export const trimResultingState = (document) => {
|
|
4
|
+
const global = document.operations.global.map((e) => {
|
|
5
|
+
delete e.resultingState;
|
|
6
|
+
return e;
|
|
7
|
+
});
|
|
8
|
+
const local = document.operations.local.map((e) => {
|
|
9
|
+
delete e.resultingState;
|
|
10
|
+
return e;
|
|
11
|
+
});
|
|
12
|
+
return { ...document, operations: { global, local } };
|
|
13
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { type ICache } from "#cache/types";
|
|
2
1
|
import { type IQueueManager } from "#queue/types";
|
|
3
2
|
import { type IDocumentStorage, type IDriveStorage } from "#storage/types";
|
|
4
3
|
import { type IDefaultDrivesManager } from "#utils/default-drives-manager";
|
|
5
4
|
import { type DocumentDriveAction, type DocumentDriveDocument } from "document-drive";
|
|
6
5
|
import { type Action, type DocumentModelModule, type Operation, type PHDocument } from "document-model";
|
|
7
6
|
import { type Unsubscribe } from "nanoevents";
|
|
7
|
+
import { type ICache } from "../cache/types.js";
|
|
8
8
|
import { OperationError, type SynchronizationUnitNotFoundError } from "./error.js";
|
|
9
9
|
import { type AddOperationOptions, type Constructor, type CreateDocumentInput, type DocumentDriveServerOptions, type DriveEvents, type DriveInput, type DriveOperationResult, type GetDocumentOptions, type GetStrandsOptions, type IBaseDocumentDriveServer, type IEventEmitter, type IListenerManager, type IOperationResult, type ISynchronizationManager, type Mixin, type OperationUpdate, type RemoteDriveAccessLevel, type RemoteDriveOptions, type SignalResult, type SyncStatus, type SyncUnitStatusObject, type SynchronizationUnit, type SynchronizationUnitQuery } from "./types.js";
|
|
10
10
|
export declare class BaseDocumentDriveServer implements IBaseDocumentDriveServer, IDefaultDrivesManager {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-server.d.ts","sourceRoot":"","sources":["../../../src/server/base-server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base-server.d.ts","sourceRoot":"","sources":["../../../src/server/base-server.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,KAAK,aAAa,EAKnB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,+BAA+B,CAAC;AAKvC,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAG3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,MAAM,EAEX,KAAK,mBAAmB,EACxB,KAAK,SAAS,EAEd,KAAK,UAAU,EAYhB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAGL,cAAc,EACd,KAAK,gCAAgC,EACtC,MAAM,YAAY,CAAC;AAOpB,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,mBAAmB,EAExB,KAAK,0BAA0B,EAC/B,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KA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AAO,EAAE,MAAM,EACf,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,IAAI,CAAC;IAOhB,yBAAyB,CAAC,cAAc,EAAE,oBAAoB,GAAG,UAAU;YAO7D,UAAU;CA6CzB;AAED,MAAM,MAAM,8BAA8B,GACxC,WAAW,CAAC,uBAAuB,CAAC,CAAC;AAEvC,MAAM,MAAM,wBAAwB,CAAC,CAAC,IAAI,KAAK,CAC7C,OAAO,uBAAuB,EAC9B,CAAC,CACF,CAAC;AAEF,eAAO,MAAM,mBAAmB,sKAA0C,CAAC"}
|
|
@@ -11,6 +11,7 @@ import { attachBranch, garbageCollect, garbageCollectDocumentOperations, groupOp
|
|
|
11
11
|
import { ClientError } from "graphql-request";
|
|
12
12
|
import { ConflictOperationError, DriveAlreadyExistsError, OperationError, } from "./error.js";
|
|
13
13
|
import { PullResponderTransmitter, } from "./listener/transmitter/pull-responder.js";
|
|
14
|
+
import { SwitchboardPushTransmitter } from "./listener/transmitter/switchboard-push.js";
|
|
14
15
|
import { DefaultListenerManagerOptions, } from "./types.js";
|
|
15
16
|
import { filterOperationsByRevision, isAtRevision } from "./utils.js";
|
|
16
17
|
export class BaseDocumentDriveServer {
|
|
@@ -81,18 +82,6 @@ export class BaseDocumentDriveServer {
|
|
|
81
82
|
};
|
|
82
83
|
// todo: move to external dependencies
|
|
83
84
|
this.defaultDrivesManager = new DefaultDrivesManager(this, this.defaultDrivesManagerDelegate, options);
|
|
84
|
-
this.storage.setStorageDelegate?.({
|
|
85
|
-
getCachedOperations: async (drive, id) => {
|
|
86
|
-
try {
|
|
87
|
-
const document = await this.cache.getDocument(drive, id);
|
|
88
|
-
return document?.operations;
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
logger.error(error);
|
|
92
|
-
return undefined;
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
});
|
|
96
85
|
this.initializePromise = this._initialize();
|
|
97
86
|
}
|
|
98
87
|
// workaround for testing the ephemeral listeners -- we don't have DI in place yet
|
|
@@ -251,6 +240,27 @@ export class BaseDocumentDriveServer {
|
|
|
251
240
|
if (this.shouldSyncRemoteDrive(drive)) {
|
|
252
241
|
await this.startSyncRemoteDrive(driveId);
|
|
253
242
|
}
|
|
243
|
+
// add switchboard push listeners
|
|
244
|
+
for (const zodListener of drive.state.local.listeners) {
|
|
245
|
+
if (zodListener.callInfo?.transmitterType === "SwitchboardPush") {
|
|
246
|
+
const transmitter = new SwitchboardPushTransmitter(zodListener.callInfo?.data ?? "");
|
|
247
|
+
this.listenerManager.setListener(driveId, {
|
|
248
|
+
block: zodListener.block,
|
|
249
|
+
driveId: drive.state.global.id,
|
|
250
|
+
filter: {
|
|
251
|
+
branch: zodListener.filter?.branch ?? [],
|
|
252
|
+
documentId: zodListener.filter?.documentId ?? [],
|
|
253
|
+
documentType: zodListener.filter?.documentType ?? [],
|
|
254
|
+
scope: zodListener.filter?.scope ?? [],
|
|
255
|
+
},
|
|
256
|
+
listenerId: zodListener.listenerId,
|
|
257
|
+
callInfo: zodListener.callInfo,
|
|
258
|
+
system: zodListener.system,
|
|
259
|
+
label: zodListener.label ?? "",
|
|
260
|
+
transmitter,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
254
264
|
}
|
|
255
265
|
// Delegate synchronization methods to synchronizationManager
|
|
256
266
|
getSynchronizationUnits(driveId, documentId, scope, branch, documentType) {
|
|
@@ -292,7 +302,7 @@ export class BaseDocumentDriveServer {
|
|
|
292
302
|
};
|
|
293
303
|
await this.storage.createDrive(id, document);
|
|
294
304
|
if (input.global.slug) {
|
|
295
|
-
await this.cache.
|
|
305
|
+
await this.cache.deleteDriveBySlug(input.global.slug);
|
|
296
306
|
}
|
|
297
307
|
await this._initializeDrive(id);
|
|
298
308
|
this.eventEmitter.emit("driveAdded", document);
|
|
@@ -324,7 +334,7 @@ export class BaseDocumentDriveServer {
|
|
|
324
334
|
const result = await Promise.allSettled([
|
|
325
335
|
this.stopSyncRemoteDrive(driveId),
|
|
326
336
|
this.listenerManager.removeDrive(driveId),
|
|
327
|
-
this.cache.
|
|
337
|
+
this.cache.deleteDrive(driveId),
|
|
328
338
|
this.storage.deleteDrive(driveId),
|
|
329
339
|
]);
|
|
330
340
|
result.forEach((r) => {
|
|
@@ -339,7 +349,7 @@ export class BaseDocumentDriveServer {
|
|
|
339
349
|
async getDrive(driveId, options) {
|
|
340
350
|
let document;
|
|
341
351
|
try {
|
|
342
|
-
const cachedDocument = await this.cache.
|
|
352
|
+
const cachedDocument = await this.cache.getDrive(driveId); // TODO support GetDocumentOptions
|
|
343
353
|
if (cachedDocument && isDocumentDrive(cachedDocument)) {
|
|
344
354
|
document = cachedDocument;
|
|
345
355
|
if (isAtRevision(document, options?.revisions)) {
|
|
@@ -357,16 +367,16 @@ export class BaseDocumentDriveServer {
|
|
|
357
367
|
}
|
|
358
368
|
else {
|
|
359
369
|
if (!options?.revisions) {
|
|
360
|
-
this.cache.
|
|
370
|
+
this.cache.setDrive(driveId, result).catch(logger.error);
|
|
361
371
|
}
|
|
362
372
|
return result;
|
|
363
373
|
}
|
|
364
374
|
}
|
|
365
375
|
async getDriveBySlug(slug, options) {
|
|
366
376
|
try {
|
|
367
|
-
const
|
|
368
|
-
if (
|
|
369
|
-
return
|
|
377
|
+
const drive = await this.cache.getDriveBySlug(slug);
|
|
378
|
+
if (drive) {
|
|
379
|
+
return drive;
|
|
370
380
|
}
|
|
371
381
|
}
|
|
372
382
|
catch (e) {
|
|
@@ -378,14 +388,14 @@ export class BaseDocumentDriveServer {
|
|
|
378
388
|
throw new Error(`Document with slug ${slug} is not a Document Drive`);
|
|
379
389
|
}
|
|
380
390
|
else {
|
|
381
|
-
this.cache.
|
|
391
|
+
this.cache.setDriveBySlug(slug, document).catch(logger.error);
|
|
382
392
|
return document;
|
|
383
393
|
}
|
|
384
394
|
}
|
|
385
395
|
async getDocument(driveId, documentId, options) {
|
|
386
396
|
let cachedDocument;
|
|
387
397
|
try {
|
|
388
|
-
cachedDocument = await this.cache.getDocument(
|
|
398
|
+
cachedDocument = await this.cache.getDocument(documentId); // TODO support GetDocumentOptions
|
|
389
399
|
if (cachedDocument && isAtRevision(cachedDocument, options?.revisions)) {
|
|
390
400
|
return cachedDocument;
|
|
391
401
|
}
|
|
@@ -397,7 +407,7 @@ export class BaseDocumentDriveServer {
|
|
|
397
407
|
(await this.storage.getDocument(driveId, documentId));
|
|
398
408
|
const document = this._buildDocument(documentStorage, options);
|
|
399
409
|
if (!options?.revisions) {
|
|
400
|
-
this.cache.setDocument(
|
|
410
|
+
this.cache.setDocument(documentId, document).catch(logger.error);
|
|
401
411
|
}
|
|
402
412
|
return document;
|
|
403
413
|
}
|
|
@@ -466,7 +476,7 @@ export class BaseDocumentDriveServer {
|
|
|
466
476
|
catch (error) {
|
|
467
477
|
logger.warn("Error deleting document", error);
|
|
468
478
|
}
|
|
469
|
-
await this.cache.deleteDocument(
|
|
479
|
+
await this.cache.deleteDocument(documentId);
|
|
470
480
|
return this.storage.deleteDocument(driveId, documentId);
|
|
471
481
|
}
|
|
472
482
|
async _processOperations(driveId, documentId, documentStorage, operations) {
|
|
@@ -802,9 +812,7 @@ export class BaseDocumentDriveServer {
|
|
|
802
812
|
};
|
|
803
813
|
});
|
|
804
814
|
if (document) {
|
|
805
|
-
this.cache
|
|
806
|
-
.setDocument(driveId, documentId, document)
|
|
807
|
-
.catch(logger.error);
|
|
815
|
+
this.cache.setDocument(documentId, document).catch(logger.error);
|
|
808
816
|
}
|
|
809
817
|
// gets all the different scopes and branches combinations from the operations
|
|
810
818
|
const { scopes, branches } = operationsApplied.reduce((acc, operation) => {
|
|
@@ -996,7 +1004,7 @@ export class BaseDocumentDriveServer {
|
|
|
996
1004
|
if (!document || !isDocumentDrive(document)) {
|
|
997
1005
|
throw error ?? new Error("Invalid Document Drive document");
|
|
998
1006
|
}
|
|
999
|
-
this.cache.
|
|
1007
|
+
this.cache.setDrive(driveId, document).catch(logger.error);
|
|
1000
1008
|
// update listener cache
|
|
1001
1009
|
const lastOperation = operationsApplied
|
|
1002
1010
|
.filter((op) => op.scope === "global")
|
|
@@ -1019,7 +1027,6 @@ export class BaseDocumentDriveServer {
|
|
|
1019
1027
|
.updateSynchronizationRevisions(driveId, [
|
|
1020
1028
|
{
|
|
1021
1029
|
syncId: "0",
|
|
1022
|
-
driveId: driveId,
|
|
1023
1030
|
documentId: "",
|
|
1024
1031
|
scope: "global",
|
|
1025
1032
|
branch: "main",
|
|
@@ -154,7 +154,7 @@ export class ListenerManager {
|
|
|
154
154
|
return;
|
|
155
155
|
}
|
|
156
156
|
else {
|
|
157
|
-
this.logger.verbose(`Listener out-of-date for sync unit (${syncUnit.
|
|
157
|
+
this.logger.verbose(`Listener out-of-date for sync unit (${syncUnit.scope}, ${syncUnit.documentId}): ${unitState?.listenerRev} < ${syncUnit.revision}`);
|
|
158
158
|
}
|
|
159
159
|
const opData = [];
|
|
160
160
|
try {
|
|
@@ -342,7 +342,7 @@ export class ListenerManager {
|
|
|
342
342
|
if (entry && entry.listenerRev >= syncUnit.revision) {
|
|
343
343
|
return;
|
|
344
344
|
}
|
|
345
|
-
const { documentId,
|
|
345
|
+
const { documentId, scope, branch } = syncUnit;
|
|
346
346
|
try {
|
|
347
347
|
const operations = await this.syncManager.getOperationData(
|
|
348
348
|
// DEAL WITH INVALID SYNC ID ERROR
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type GetStrandsOptions, type IListenerManager, type IOperationResult, type Listener, type ListenerRevision, type ListenerRevisionWithError, type OperationUpdate, type RemoteDriveOptions, type StrandUpdate } from "#server/types";
|
|
2
|
-
import { type ITransmitter, type PullResponderTrigger, type StrandUpdateSource } from "./types.js";
|
|
3
2
|
import { type ListenerFilter, type Trigger } from "#drive-document-model/gen/types";
|
|
3
|
+
import { type ITransmitter, type PullResponderTrigger, type StrandUpdateSource } from "./types.js";
|
|
4
4
|
export type OperationUpdateGraphQL = Omit<OperationUpdate, "input"> & {
|
|
5
5
|
input: string;
|
|
6
6
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pull-responder.d.ts","sourceRoot":"","sources":["../../../../../src/server/listener/transmitter/pull-responder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,yBAAyB,EAC9B,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"pull-responder.d.ts","sourceRoot":"","sources":["../../../../../src/server/listener/transmitter/pull-responder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,yBAAyB,EAC9B,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,OAAO,EACb,MAAM,iCAAiC,CAAC;AAOzC,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACxB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,GAAG;IACpE,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE;QACN,IAAI,EAAE;YACJ,OAAO,EAAE,mBAAmB,EAAE,CAAC;SAChC,CAAC;KACH,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC;AAExC,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,GAAG;IACnE,UAAU,EAAE,sBAAsB,EAAE,C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AC,EAC9B,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,EAC/B,WAAW,CAAC,EAAE,CAAC,SAAS,EAAE,yBAAyB,EAAE,KAAK,IAAI,EAC9D,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,GACzC,cAAc;WAoDJ,0BAA0B,CACrC,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,IAAI,CAAC,kBAAkB,EAAE,cAAc,GAAG,YAAY,CAAC,GAC/D,OAAO,CAAC,oBAAoB,CAAC;IA6BhC,MAAM,CAAC,sBAAsB,CAC3B,OAAO,EAAE,OAAO,GACf,OAAO,IAAI,oBAAoB;CAGnC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { childLogger } from "#utils/logger";
|
|
2
|
-
import { generateUUID } from "#utils/misc";
|
|
3
1
|
import { PULL_DRIVE_INTERVAL } from "#server/constants";
|
|
4
2
|
import { OperationError } from "#server/error";
|
|
5
3
|
import { requestGraphql } from "#utils/graphql";
|
|
4
|
+
import { childLogger } from "#utils/logger";
|
|
5
|
+
import { generateUUID } from "#utils/misc";
|
|
6
6
|
import { gql } from "graphql-request";
|
|
7
7
|
const MAX_REVISIONS_PER_ACK = 100;
|
|
8
8
|
export class PullResponderTransmitter {
|
|
@@ -36,7 +36,6 @@ export class PullResponderTransmitter {
|
|
|
36
36
|
for (const revision of revisions) {
|
|
37
37
|
const syncUnit = syncUnits.find((s) => s.scope === revision.scope &&
|
|
38
38
|
s.branch === revision.branch &&
|
|
39
|
-
s.driveId === revision.driveId &&
|
|
40
39
|
s.documentId == revision.documentId);
|
|
41
40
|
if (!syncUnit) {
|
|
42
41
|
this.logger.warn("Unknown sync unit was acknowledged", revision);
|