document-drive 1.29.0-dev.0 → 1.29.0-dev.1
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 +5 -2
- package/dist/src/cache/memory.d.ts.map +1 -1
- package/dist/src/cache/memory.js +14 -0
- package/dist/src/cache/redis.d.ts +5 -2
- package/dist/src/cache/redis.d.ts.map +1 -1
- package/dist/src/cache/redis.js +12 -0
- package/dist/src/drive-document-model/gen/schema/zod.d.ts +8 -8
- package/dist/src/drive-document-model/gen/schema/zod.d.ts.map +1 -1
- 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 +0 -13
- 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 +5 -16
- 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 +0 -3
- package/dist/src/storage/browser.d.ts.map +1 -1
- package/dist/src/storage/browser.js +27 -18
- package/dist/src/storage/filesystem.d.ts +0 -2
- package/dist/src/storage/filesystem.d.ts.map +1 -1
- package/dist/src/storage/filesystem.js +24 -23
- package/dist/src/storage/ipfs.d.ts +1 -1
- package/dist/src/storage/ipfs.d.ts.map +1 -1
- package/dist/src/storage/ipfs.js +17 -17
- package/dist/src/storage/memory.d.ts +0 -4
- package/dist/src/storage/memory.d.ts.map +1 -1
- package/dist/src/storage/memory.js +31 -36
- 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 +4 -5
- package/dist/src/storage/prisma/index.d.ts.map +1 -1
- package/dist/src/storage/prisma/index.js +33 -71
- package/dist/src/storage/types.d.ts +2 -3
- package/dist/src/storage/types.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
|
@@ -6,7 +6,6 @@ export class BrowserStorage {
|
|
|
6
6
|
db;
|
|
7
7
|
static DBName = "DOCUMENT_DRIVES";
|
|
8
8
|
static SEP = ":";
|
|
9
|
-
static DRIVES_KEY = "DRIVES";
|
|
10
9
|
static DOCUMENT_KEY = "DOCUMENT";
|
|
11
10
|
static MANIFEST_KEY = "MANIFEST";
|
|
12
11
|
constructor(namespace) {
|
|
@@ -97,13 +96,16 @@ export class BrowserStorage {
|
|
|
97
96
|
const db = await this.db;
|
|
98
97
|
const keys = await db.keys();
|
|
99
98
|
return keys
|
|
100
|
-
.filter((key) => key.startsWith(BrowserStorage.
|
|
101
|
-
.map((key) => key.slice(BrowserStorage.
|
|
99
|
+
.filter((key) => key.startsWith(BrowserStorage.MANIFEST_KEY))
|
|
100
|
+
.map((key) => key.slice(BrowserStorage.MANIFEST_KEY.length + BrowserStorage.SEP.length));
|
|
102
101
|
}
|
|
103
102
|
async getDrive(id) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
let drive;
|
|
104
|
+
try {
|
|
105
|
+
drive = await this.get(id);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// preserve throwing a specialized error for drives
|
|
107
109
|
throw new DriveNotFoundError(id);
|
|
108
110
|
}
|
|
109
111
|
return drive;
|
|
@@ -120,8 +122,21 @@ export class BrowserStorage {
|
|
|
120
122
|
throw new Error(`Drive with slug ${slug} not found`);
|
|
121
123
|
}
|
|
122
124
|
async createDrive(id, drive) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
+
// check if a drive with the same slug already exists
|
|
126
|
+
const slug = drive.initialState.state.global.slug;
|
|
127
|
+
if (slug) {
|
|
128
|
+
let existingDrive;
|
|
129
|
+
try {
|
|
130
|
+
existingDrive = await this.getDriveBySlug(slug);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
// do nothing
|
|
134
|
+
}
|
|
135
|
+
if (existingDrive) {
|
|
136
|
+
throw new Error(`Drive with slug ${slug} already exists`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
await this.create(id, drive);
|
|
125
140
|
// Initialize an empty manifest for the new drive
|
|
126
141
|
await this.updateDriveManifest(id, { documentIds: [] });
|
|
127
142
|
}
|
|
@@ -133,13 +148,13 @@ export class BrowserStorage {
|
|
|
133
148
|
// Delete the drive and its manifest
|
|
134
149
|
const db = await this.db;
|
|
135
150
|
await db.removeItem(this.buildManifestKey(id));
|
|
136
|
-
return db.removeItem(this.
|
|
151
|
+
return db.removeItem(this.buildDocumentKey(id));
|
|
137
152
|
}
|
|
138
153
|
async addDriveOperations(id, operations, header) {
|
|
139
154
|
const drive = await this.getDrive(id);
|
|
140
155
|
const mergedOperations = mergeOperations(drive.operations, operations);
|
|
141
156
|
const db = await this.db;
|
|
142
|
-
await db.setItem(this.
|
|
157
|
+
await db.setItem(this.buildDocumentKey(id), {
|
|
143
158
|
...drive,
|
|
144
159
|
...header,
|
|
145
160
|
operations: mergedOperations,
|
|
@@ -148,16 +163,13 @@ export class BrowserStorage {
|
|
|
148
163
|
async getSynchronizationUnitsRevision(units) {
|
|
149
164
|
const results = await Promise.allSettled(units.map(async (unit) => {
|
|
150
165
|
try {
|
|
151
|
-
const document = await (unit.documentId
|
|
152
|
-
? this.getDocument(unit.driveId, unit.documentId)
|
|
153
|
-
: this.getDrive(unit.driveId));
|
|
166
|
+
const document = await this.get(unit.documentId);
|
|
154
167
|
if (!document) {
|
|
155
168
|
return undefined;
|
|
156
169
|
}
|
|
157
170
|
const operation = document.operations[unit.scope].at(-1);
|
|
158
171
|
if (operation) {
|
|
159
172
|
return {
|
|
160
|
-
driveId: unit.driveId,
|
|
161
173
|
documentId: unit.documentId,
|
|
162
174
|
scope: unit.scope,
|
|
163
175
|
branch: unit.branch,
|
|
@@ -190,7 +202,7 @@ export class BrowserStorage {
|
|
|
190
202
|
const drive = await this.getDrive(driveId);
|
|
191
203
|
const migratedDrive = migrateDocumentOperationSignatures(drive);
|
|
192
204
|
if (migratedDrive !== drive) {
|
|
193
|
-
return (await this.db).setItem(this.
|
|
205
|
+
return (await this.db).setItem(this.buildDocumentKey(driveId), migratedDrive);
|
|
194
206
|
}
|
|
195
207
|
}
|
|
196
208
|
async migrateDocument(drive, id) {
|
|
@@ -203,9 +215,6 @@ export class BrowserStorage {
|
|
|
203
215
|
////////////////////////////////
|
|
204
216
|
// Private methods
|
|
205
217
|
////////////////////////////////
|
|
206
|
-
buildDriveKey(driveId) {
|
|
207
|
-
return `${BrowserStorage.DRIVES_KEY}${BrowserStorage.SEP}${driveId}`;
|
|
208
|
-
}
|
|
209
218
|
buildDocumentKey(documentId) {
|
|
210
219
|
return `${BrowserStorage.DOCUMENT_KEY}${BrowserStorage.SEP}${documentId}`;
|
|
211
220
|
}
|
|
@@ -22,7 +22,6 @@ export declare class FilesystemStorage implements IDriveStorage, IDocumentStorag
|
|
|
22
22
|
deleteDrive(id: string): Promise<void>;
|
|
23
23
|
addDriveOperations(id: string, operations: Operation<DocumentDriveAction>[], header: DocumentHeader): Promise<void>;
|
|
24
24
|
getSynchronizationUnitsRevision(units: SynchronizationUnitQuery[]): Promise<{
|
|
25
|
-
driveId: string;
|
|
26
25
|
documentId: string;
|
|
27
26
|
scope: string;
|
|
28
27
|
branch: string;
|
|
@@ -30,7 +29,6 @@ export declare class FilesystemStorage implements IDriveStorage, IDocumentStorag
|
|
|
30
29
|
revision: number;
|
|
31
30
|
}[]>;
|
|
32
31
|
private _buildDocumentPath;
|
|
33
|
-
private _buildDrivePath;
|
|
34
32
|
private _buildManifestPath;
|
|
35
33
|
private getDriveManifest;
|
|
36
34
|
private updateDriveManifest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version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AK,EAAE,MAAM,EACb,EAAE,EAAE,MAAM,EACV,UAAU,EAAE,SAAS,EAAE,EACvB,MAAM,EAAE,cAAc;IAuBlB,SAAS;IAWT,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;IASpD,cAAc,CAAC,IAAI,EAAE,MAAM;IAmB3B,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,qBAAqB;IAqBpD,WAAW,CAAC,EAAE,EAAE,MAAM;IAYtB,kBAAkB,CACtB,EAAE,EAAE,MAAM,EACV,UAAU,EAAE,SAAS,CAAC,mBAAmB,CAAC,EAAE,EAC5C,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,IAAI,CAAC;IAqBV,+BAA+B,CACnC,KAAK,EAAE,wBAAwB,EAAE,GAChC,OAAO,CACR;QACE,UAAU,EAAE,MAAM,CAAC;QACnB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;KAClB,EAAE,CACJ;IA4CD,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,kBAAkB;YAIZ,gBAAgB;YAWhB,mBAAmB;CAOlC"}
|
|
@@ -117,18 +117,16 @@ export class FilesystemStorage {
|
|
|
117
117
|
// get anything that starts with drive-
|
|
118
118
|
const files = await fs.readdir(this.basePath, { withFileTypes: true });
|
|
119
119
|
return (files
|
|
120
|
-
.filter((file) => file.name.startsWith("
|
|
121
|
-
// remove
|
|
122
|
-
.map((file) => file.name.replace("
|
|
120
|
+
.filter((file) => file.name.startsWith("manifest-"))
|
|
121
|
+
// remove manifest- prefix and extension
|
|
122
|
+
.map((file) => file.name.replace("manifest-", "").replace(".json", "")));
|
|
123
123
|
}
|
|
124
124
|
async getDrive(id) {
|
|
125
125
|
try {
|
|
126
|
-
|
|
127
|
-
encoding: "utf-8",
|
|
128
|
-
});
|
|
129
|
-
return JSON.parse(content);
|
|
126
|
+
return await this.get(id);
|
|
130
127
|
}
|
|
131
128
|
catch (error) {
|
|
129
|
+
// preserve throwing a specialized error for drives
|
|
132
130
|
throw new DriveNotFoundError(id);
|
|
133
131
|
}
|
|
134
132
|
}
|
|
@@ -144,10 +142,21 @@ export class FilesystemStorage {
|
|
|
144
142
|
throw new Error(`Drive with slug ${slug} not found`);
|
|
145
143
|
}
|
|
146
144
|
async createDrive(id, drive) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
145
|
+
// check if a drive with the same slug already exists
|
|
146
|
+
const slug = drive.initialState.state.global.slug;
|
|
147
|
+
if (slug) {
|
|
148
|
+
let existingDrive;
|
|
149
|
+
try {
|
|
150
|
+
existingDrive = await this.getDriveBySlug(slug);
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
// do nothing
|
|
154
|
+
}
|
|
155
|
+
if (existingDrive) {
|
|
156
|
+
throw new Error(`Drive with slug ${slug} already exists`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
await this.create(id, drive);
|
|
151
160
|
// Initialize an empty manifest for the new drive
|
|
152
161
|
await this.updateDriveManifest(id, { documentIds: [] });
|
|
153
162
|
}
|
|
@@ -157,15 +166,13 @@ export class FilesystemStorage {
|
|
|
157
166
|
// Delete each document from this drive (may not actually delete the file if shared with other drives)
|
|
158
167
|
await Promise.all(documents.map((doc) => this.deleteDocument(id, doc)));
|
|
159
168
|
// Delete the drive manifest and the drive itself
|
|
160
|
-
await fs.rm(this._buildManifestPath(id))
|
|
161
|
-
|
|
162
|
-
});
|
|
163
|
-
await fs.rm(this._buildDrivePath(id));
|
|
169
|
+
await fs.rm(this._buildManifestPath(id));
|
|
170
|
+
await fs.rm(this._buildDocumentPath(id));
|
|
164
171
|
}
|
|
165
172
|
async addDriveOperations(id, operations, header) {
|
|
166
173
|
const drive = await this.getDrive(id);
|
|
167
174
|
const mergedOperations = mergeOperations(drive.operations, operations);
|
|
168
|
-
const drivePath = this.
|
|
175
|
+
const drivePath = this._buildDocumentPath(id);
|
|
169
176
|
writeFileSync(drivePath, stringify({
|
|
170
177
|
...drive,
|
|
171
178
|
...header,
|
|
@@ -177,16 +184,13 @@ export class FilesystemStorage {
|
|
|
177
184
|
async getSynchronizationUnitsRevision(units) {
|
|
178
185
|
const results = await Promise.allSettled(units.map(async (unit) => {
|
|
179
186
|
try {
|
|
180
|
-
const document = await (unit.documentId
|
|
181
|
-
? this.getDocument(unit.driveId, unit.documentId)
|
|
182
|
-
: this.getDrive(unit.driveId));
|
|
187
|
+
const document = await this.get(unit.documentId);
|
|
183
188
|
if (!document) {
|
|
184
189
|
return undefined;
|
|
185
190
|
}
|
|
186
191
|
const operation = document.operations[unit.scope].at(-1);
|
|
187
192
|
if (operation) {
|
|
188
193
|
return {
|
|
189
|
-
driveId: unit.driveId,
|
|
190
194
|
documentId: unit.documentId,
|
|
191
195
|
scope: unit.scope,
|
|
192
196
|
branch: unit.branch,
|
|
@@ -212,9 +216,6 @@ export class FilesystemStorage {
|
|
|
212
216
|
_buildDocumentPath(documentId) {
|
|
213
217
|
return `${this.basePath}/document-${documentId}.json`;
|
|
214
218
|
}
|
|
215
|
-
_buildDrivePath(driveId) {
|
|
216
|
-
return `${this.basePath}/drive-${driveId}.json`;
|
|
217
|
-
}
|
|
218
219
|
_buildManifestPath(driveId) {
|
|
219
220
|
return `${this.basePath}/manifest-${driveId}.json`;
|
|
220
221
|
}
|
|
@@ -8,6 +8,7 @@ export declare class IPFSStorage implements IStorage, IDocumentStorage {
|
|
|
8
8
|
constructor(helia: Helia);
|
|
9
9
|
exists(documentId: string): Promise<boolean>;
|
|
10
10
|
create(documentId: string, document: PHDocument): Promise<void>;
|
|
11
|
+
get<TDocument extends PHDocument>(documentId: string): Promise<TDocument>;
|
|
11
12
|
checkDocumentExists(drive: string, id: string): Promise<boolean>;
|
|
12
13
|
getDocuments(drive: string): Promise<string[]>;
|
|
13
14
|
getDocument<TDocument extends PHDocument>(drive: string, id: string): Promise<TDocument>;
|
|
@@ -22,7 +23,6 @@ export declare class IPFSStorage implements IStorage, IDocumentStorage {
|
|
|
22
23
|
addDriveOperations(id: string, operations: Operation<DocumentDriveAction>[], header: DocumentHeader): Promise<void>;
|
|
23
24
|
clearStorage(): Promise<void>;
|
|
24
25
|
getSynchronizationUnitsRevision(units: SynchronizationUnitQuery[]): Promise<{
|
|
25
|
-
driveId: string;
|
|
26
26
|
documentId: string;
|
|
27
27
|
scope: string;
|
|
28
28
|
branch: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipfs.d.ts","sourceRoot":"","sources":["../../../src/storage/ipfs.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC3B,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAG9D,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,SAAS,EAEd,KAAK,UAAU,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAO7D,qBAAa,WAAY,YAAW,QAAQ,EAAE,gBAAgB;IAC5D,OAAO,CAAC,EAAE,CAAM;gBAEJ,KAAK,EAAE,KAAK;IAQlB,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAmB5C,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"ipfs.d.ts","sourceRoot":"","sources":["../../../src/storage/ipfs.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC3B,MAAM,iCAAiC,CAAC;AAEzC,OA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MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,IAAI,CAAC;IAeV,SAAS,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAoB9B,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAepD,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAkB5D,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAcpE,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA2BtC,kBAAkB,CACtB,EAAE,EAAE,MAAM,EACV,UAAU,EAAE,SAAS,CAAC,mBAAmB,CAAC,EAAE,EAC5C,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,IAAI,CAAC;IAcV,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAa7B,+BAA+B,CACnC,KAAK,EAAE,wBAAwB,EAAE,GAChC,OAAO,CACR;QACE,UAAU,EAAE,MAAM,CAAC;QACnB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;KAClB,EAAE,CACJ;IA4CD,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,uBAAuB;YAIjB,gBAAgB;YAgBhB,mBAAmB;CASlC"}
|
package/dist/src/storage/ipfs.js
CHANGED
|
@@ -30,19 +30,9 @@ export class IPFSStorage {
|
|
|
30
30
|
async create(documentId, document) {
|
|
31
31
|
await this.fs.writeBytes(new TextEncoder().encode(stringify(document)), this._buildDocumentPath(documentId));
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
// IDriveStorage
|
|
35
|
-
////////////////////////////////
|
|
36
|
-
async checkDocumentExists(drive, id) {
|
|
37
|
-
return this.exists(id);
|
|
38
|
-
}
|
|
39
|
-
async getDocuments(drive) {
|
|
40
|
-
const manifest = await this.getDriveManifest(drive);
|
|
41
|
-
return manifest.documentIds;
|
|
42
|
-
}
|
|
43
|
-
async getDocument(drive, id) {
|
|
33
|
+
async get(documentId) {
|
|
44
34
|
try {
|
|
45
|
-
const documentPath = this._buildDocumentPath(
|
|
35
|
+
const documentPath = this._buildDocumentPath(documentId);
|
|
46
36
|
const chunks = [];
|
|
47
37
|
for await (const chunk of this.fs.cat(documentPath)) {
|
|
48
38
|
chunks.push(chunk);
|
|
@@ -52,9 +42,22 @@ export class IPFSStorage {
|
|
|
52
42
|
return JSON.parse(content);
|
|
53
43
|
}
|
|
54
44
|
catch (error) {
|
|
55
|
-
throw new Error(`Document with id ${
|
|
45
|
+
throw new Error(`Document with id ${documentId} not found`);
|
|
56
46
|
}
|
|
57
47
|
}
|
|
48
|
+
////////////////////////////////s
|
|
49
|
+
// IDriveStorage
|
|
50
|
+
////////////////////////////////
|
|
51
|
+
async checkDocumentExists(drive, id) {
|
|
52
|
+
return this.exists(id);
|
|
53
|
+
}
|
|
54
|
+
async getDocuments(drive) {
|
|
55
|
+
const manifest = await this.getDriveManifest(drive);
|
|
56
|
+
return manifest.documentIds;
|
|
57
|
+
}
|
|
58
|
+
async getDocument(drive, id) {
|
|
59
|
+
return this.get(id);
|
|
60
|
+
}
|
|
58
61
|
async createDocument(drive, id, document) {
|
|
59
62
|
await this.create(id, document);
|
|
60
63
|
// Update the drive manifest to include this document
|
|
@@ -208,16 +211,13 @@ export class IPFSStorage {
|
|
|
208
211
|
async getSynchronizationUnitsRevision(units) {
|
|
209
212
|
const results = await Promise.allSettled(units.map(async (unit) => {
|
|
210
213
|
try {
|
|
211
|
-
const document = await (unit.documentId
|
|
212
|
-
? this.getDocument(unit.driveId, unit.documentId)
|
|
213
|
-
: this.getDrive(unit.driveId));
|
|
214
|
+
const document = await this.get(unit.documentId);
|
|
214
215
|
if (!document) {
|
|
215
216
|
return undefined;
|
|
216
217
|
}
|
|
217
218
|
const operation = document.operations[unit.scope].at(-1);
|
|
218
219
|
if (operation) {
|
|
219
220
|
return {
|
|
220
|
-
driveId: unit.driveId,
|
|
221
221
|
documentId: unit.documentId,
|
|
222
222
|
scope: unit.scope,
|
|
223
223
|
branch: unit.branch,
|
|
@@ -4,9 +4,7 @@ import { type DocumentHeader, type Operation, type OperationFromDocument, type P
|
|
|
4
4
|
import { type IDocumentStorage, type IDriveStorage } from "./types.js";
|
|
5
5
|
export declare class MemoryStorage implements IDriveStorage, IDocumentStorage {
|
|
6
6
|
private documents;
|
|
7
|
-
private drives;
|
|
8
7
|
private driveManifests;
|
|
9
|
-
private slugToDriveId;
|
|
10
8
|
constructor();
|
|
11
9
|
exists(documentId: string): Promise<boolean>;
|
|
12
10
|
create(documentId: string, document: PHDocument): Promise<void>;
|
|
@@ -14,7 +12,6 @@ export declare class MemoryStorage implements IDriveStorage, IDocumentStorage {
|
|
|
14
12
|
checkDocumentExists(drive: string, id: string): Promise<boolean>;
|
|
15
13
|
getDocuments(drive: string): Promise<string[]>;
|
|
16
14
|
getDocument<TDocument extends PHDocument>(driveId: string, id: string): Promise<TDocument>;
|
|
17
|
-
saveDocument(drive: string, id: string, document: PHDocument): Promise<void>;
|
|
18
15
|
clearStorage(): Promise<void>;
|
|
19
16
|
createDocument(drive: string, id: string, document: PHDocument): Promise<void>;
|
|
20
17
|
addDocumentOperations(drive: string, id: string, operations: Operation[], header: DocumentHeader): Promise<void>;
|
|
@@ -26,7 +23,6 @@ export declare class MemoryStorage implements IDriveStorage, IDocumentStorage {
|
|
|
26
23
|
addDriveOperations(id: string, operations: OperationFromDocument<DocumentDriveDocument>[], header: DocumentHeader): Promise<void>;
|
|
27
24
|
deleteDrive(id: string): Promise<void>;
|
|
28
25
|
getSynchronizationUnitsRevision(units: SynchronizationUnitQuery[]): Promise<{
|
|
29
|
-
driveId: string;
|
|
30
26
|
documentId: string;
|
|
31
27
|
scope: string;
|
|
32
28
|
branch: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/storage/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAE7E,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAE9D,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,qBAAqB,EAE1B,KAAK,UAAU,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAMvE,qBAAa,aAAc,YAAW,aAAa,EAAE,gBAAgB;IACnE,OAAO,CAAC,SAAS,CAA6B;IAC9C,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/storage/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAE7E,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAE9D,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,qBAAqB,EAE1B,KAAK,UAAU,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAMvE,qBAAa,aAAc,YAAW,aAAa,EAAE,gBAAgB;IACnE,OAAO,CAAC,SAAS,CAA6B;IAC9C,OAAO,CAAC,cAAc,CAAgC;;IAWtD,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAM5C,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU;IAM/C,GAAG,CAAC,SAAS,SAAS,UAAU,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAkBzE,mBAA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FoundError } from "#server/error";
|
|
|
2
2
|
import { mergeOperations } from "#utils/misc";
|
|
3
3
|
export class MemoryStorage {
|
|
4
4
|
documents;
|
|
5
|
-
drives;
|
|
6
5
|
driveManifests;
|
|
7
|
-
slugToDriveId = {};
|
|
8
6
|
constructor() {
|
|
9
7
|
this.documents = {};
|
|
10
|
-
this.drives = {};
|
|
11
8
|
this.driveManifests = {};
|
|
12
9
|
}
|
|
13
10
|
////////////////////////////////
|
|
14
11
|
// IDocumentStorage
|
|
15
12
|
////////////////////////////////
|
|
16
13
|
exists(documentId) {
|
|
17
|
-
return Promise.resolve(!!this.documents[documentId]);
|
|
14
|
+
return Promise.resolve(!!this.documents[documentId] || !!this.documents[`drive/${documentId}`]);
|
|
18
15
|
}
|
|
19
16
|
create(documentId, document) {
|
|
20
17
|
this.documents[documentId] = document;
|
|
@@ -23,6 +20,10 @@ export class MemoryStorage {
|
|
|
23
20
|
get(documentId) {
|
|
24
21
|
const document = this.documents[documentId];
|
|
25
22
|
if (!document) {
|
|
23
|
+
const drive = this.documents[`drive/${documentId}`];
|
|
24
|
+
if (drive) {
|
|
25
|
+
return Promise.resolve(drive);
|
|
26
|
+
}
|
|
26
27
|
throw new Error(`Document with id ${documentId} not found`);
|
|
27
28
|
}
|
|
28
29
|
return Promise.resolve(document);
|
|
@@ -40,18 +41,9 @@ export class MemoryStorage {
|
|
|
40
41
|
getDocument(driveId, id) {
|
|
41
42
|
return this.get(id);
|
|
42
43
|
}
|
|
43
|
-
async saveDocument(drive, id, document) {
|
|
44
|
-
this.documents[id] = document;
|
|
45
|
-
// Update the drive manifest
|
|
46
|
-
const manifest = this.getDriveManifest(drive);
|
|
47
|
-
manifest.documentIds.add(id);
|
|
48
|
-
this.updateDriveManifest(drive, manifest);
|
|
49
|
-
}
|
|
50
44
|
async clearStorage() {
|
|
51
45
|
this.documents = {};
|
|
52
|
-
this.drives = {};
|
|
53
46
|
this.driveManifests = {};
|
|
54
|
-
this.slugToDriveId = {};
|
|
55
47
|
}
|
|
56
48
|
async createDocument(drive, id, document) {
|
|
57
49
|
await this.create(id, document);
|
|
@@ -85,35 +77,47 @@ export class MemoryStorage {
|
|
|
85
77
|
delete this.documents[id];
|
|
86
78
|
}
|
|
87
79
|
async getDrives() {
|
|
88
|
-
return Object.keys(this.
|
|
80
|
+
return Object.keys(this.driveManifests);
|
|
89
81
|
}
|
|
90
82
|
async getDrive(id) {
|
|
91
|
-
const drive = this.
|
|
83
|
+
const drive = this.documents[`drive/${id}`];
|
|
92
84
|
if (!drive) {
|
|
93
85
|
throw new DriveNotFoundError(id);
|
|
94
86
|
}
|
|
95
87
|
return drive;
|
|
96
88
|
}
|
|
97
89
|
async getDriveBySlug(slug) {
|
|
98
|
-
const driveId
|
|
99
|
-
|
|
100
|
-
|
|
90
|
+
for (const driveId of Object.keys(this.driveManifests)) {
|
|
91
|
+
const drive = this.documents[`drive/${driveId}`];
|
|
92
|
+
if (drive.initialState.state.global.slug === slug) {
|
|
93
|
+
return drive;
|
|
94
|
+
}
|
|
101
95
|
}
|
|
102
|
-
|
|
96
|
+
throw new Error(`Drive with slug ${slug} not found`);
|
|
103
97
|
}
|
|
104
98
|
async createDrive(id, drive) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
this.updateDriveManifest(id, { documentIds: new Set() });
|
|
108
|
-
const { slug } = drive.initialState.state.global;
|
|
99
|
+
// check if a drive with the same slug already exists
|
|
100
|
+
const slug = drive.initialState.state.global.slug;
|
|
109
101
|
if (slug) {
|
|
110
|
-
|
|
102
|
+
let existingDrive;
|
|
103
|
+
try {
|
|
104
|
+
existingDrive = await this.getDriveBySlug(slug);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// do nothing
|
|
108
|
+
}
|
|
109
|
+
if (existingDrive) {
|
|
110
|
+
throw new Error(`Drive with slug ${slug} already exists`);
|
|
111
|
+
}
|
|
111
112
|
}
|
|
113
|
+
await this.create(`drive/${id}`, drive);
|
|
114
|
+
// Initialize an empty manifest for the new drive
|
|
115
|
+
this.updateDriveManifest(id, { documentIds: new Set() });
|
|
112
116
|
}
|
|
113
117
|
async addDriveOperations(id, operations, header) {
|
|
114
118
|
const drive = await this.getDrive(id);
|
|
115
119
|
const mergedOperations = mergeOperations(drive.operations, operations);
|
|
116
|
-
this.
|
|
120
|
+
this.documents[`drive/${id}`] = {
|
|
117
121
|
...drive,
|
|
118
122
|
...header,
|
|
119
123
|
operations: mergedOperations,
|
|
@@ -138,27 +142,18 @@ export class MemoryStorage {
|
|
|
138
142
|
}));
|
|
139
143
|
// Delete the drive manifest and the drive itself
|
|
140
144
|
delete this.driveManifests[id];
|
|
141
|
-
delete this.
|
|
142
|
-
// Clean up slug mapping if needed
|
|
143
|
-
for (const [slug, driveId] of Object.entries(this.slugToDriveId)) {
|
|
144
|
-
if (driveId === id) {
|
|
145
|
-
delete this.slugToDriveId[slug];
|
|
146
|
-
}
|
|
147
|
-
}
|
|
145
|
+
delete this.documents[id];
|
|
148
146
|
}
|
|
149
147
|
async getSynchronizationUnitsRevision(units) {
|
|
150
148
|
const results = await Promise.allSettled(units.map(async (unit) => {
|
|
151
149
|
try {
|
|
152
|
-
const document = await (unit.documentId
|
|
153
|
-
? this.getDocument(unit.driveId, unit.documentId)
|
|
154
|
-
: this.getDrive(unit.driveId));
|
|
150
|
+
const document = await this.get(unit.documentId);
|
|
155
151
|
if (!document) {
|
|
156
152
|
return undefined;
|
|
157
153
|
}
|
|
158
154
|
const operation = document.operations[unit.scope].at(-1);
|
|
159
155
|
if (operation) {
|
|
160
156
|
return {
|
|
161
|
-
driveId: unit.driveId,
|
|
162
157
|
documentId: unit.documentId,
|
|
163
158
|
scope: unit.scope,
|
|
164
159
|
branch: unit.branch,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { PrismaStorage } from "#storage/prisma/index";
|
|
2
|
+
import { IOperationsCache } from "#storage/types";
|
|
2
3
|
export declare class PrismaStorageFactory {
|
|
3
|
-
private readonly
|
|
4
|
-
private
|
|
5
|
-
constructor(dbUrl: string);
|
|
4
|
+
private readonly prisma;
|
|
5
|
+
private readonly cache;
|
|
6
|
+
constructor(dbUrl: string, cache: IOperationsCache);
|
|
6
7
|
build(): PrismaStorage;
|
|
7
8
|
}
|
|
8
9
|
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../src/storage/prisma/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../src/storage/prisma/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIlD,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoC;IAC3D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAmB;gBAE7B,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB;IAWlD,KAAK;CAGN"}
|
|
@@ -2,19 +2,19 @@ import { PrismaStorage } from "#storage/prisma/index";
|
|
|
2
2
|
import Prisma from "@prisma/client";
|
|
3
3
|
const PrismaClient = Prisma.PrismaClient;
|
|
4
4
|
export class PrismaStorageFactory {
|
|
5
|
-
dbUrl;
|
|
6
5
|
prisma;
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
cache;
|
|
7
|
+
constructor(dbUrl, cache) {
|
|
8
|
+
this.cache = cache;
|
|
9
9
|
this.prisma = new PrismaClient({
|
|
10
10
|
datasources: {
|
|
11
11
|
db: {
|
|
12
|
-
url:
|
|
12
|
+
url: dbUrl,
|
|
13
13
|
},
|
|
14
14
|
},
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
build() {
|
|
18
|
-
return new PrismaStorage(this.prisma);
|
|
18
|
+
return new PrismaStorage(this.prisma, this.cache);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -3,7 +3,7 @@ import type { BaseStateFromDocument, DocumentHeader, Operation, OperationFromDoc
|
|
|
3
3
|
import { type IBackOffOptions } from "exponential-backoff";
|
|
4
4
|
import { type DocumentDriveAction, type DocumentDriveDocument } from "../../drive-document-model/gen/types.js";
|
|
5
5
|
import { type SynchronizationUnitQuery } from "../../server/types.js";
|
|
6
|
-
import type { IDocumentStorage, IDriveStorage,
|
|
6
|
+
import type { IDocumentStorage, IDriveStorage, IOperationsCache } from "../types.js";
|
|
7
7
|
export * from "./factory.js";
|
|
8
8
|
type Transaction = Omit<PrismaClient<Prisma.PrismaClientOptions, never>, "$connect" | "$disconnect" | "$on" | "$transaction" | "$use" | "$extends"> | ExtendedPrismaClient;
|
|
9
9
|
export type PrismaStorageOptions = {
|
|
@@ -27,11 +27,11 @@ declare function getRetryTransactionsClient<T extends PrismaClient>(prisma: T, b
|
|
|
27
27
|
type ExtendedPrismaClient = ReturnType<typeof getRetryTransactionsClient<PrismaClient>>;
|
|
28
28
|
export declare class PrismaStorage implements IDriveStorage, IDocumentStorage {
|
|
29
29
|
private db;
|
|
30
|
-
private
|
|
31
|
-
constructor(db: PrismaClient, options?: PrismaStorageOptions);
|
|
30
|
+
private cache;
|
|
31
|
+
constructor(db: PrismaClient, cache: IOperationsCache, options?: PrismaStorageOptions);
|
|
32
32
|
exists(documentId: string): Promise<boolean>;
|
|
33
33
|
create(documentId: string, document: PHDocument): Promise<void>;
|
|
34
|
-
|
|
34
|
+
get<TDocument extends PHDocument>(documentId: string): Promise<TDocument>;
|
|
35
35
|
createDrive(id: string, drive: DocumentDriveDocument): Promise<void>;
|
|
36
36
|
addDriveOperations(id: string, operations: Operation<DocumentDriveAction>[], header: DocumentHeader): Promise<void>;
|
|
37
37
|
addDriveOperationsWithTransaction(drive: string, callback: (document: DocumentDriveDocument) => Promise<{
|
|
@@ -57,7 +57,6 @@ export declare class PrismaStorage implements IDriveStorage, IDocumentStorage {
|
|
|
57
57
|
getOperationResultingState(driveId: string, documentId: string, index: number, scope: string, branch: string): Promise<string | undefined>;
|
|
58
58
|
getDriveOperationResultingState(drive: string, index: number, scope: string, branch: string): Promise<string | undefined>;
|
|
59
59
|
getSynchronizationUnitsRevision(units: SynchronizationUnitQuery[]): Promise<{
|
|
60
|
-
driveId: string;
|
|
61
60
|
documentId: string;
|
|
62
61
|
scope: string;
|
|
63
62
|
branch: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/prisma/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEhE,OAAO,KAAK,EAEV,qBAAqB,EACrB,cAAc,EAGd,SAAS,EACT,qBAAqB,EAGrB,UAAU,EACX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,eAAe,EAAW,MAAM,qBAAqB,CAAC;AACpE,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC3B,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAErB,cAAc,cAAc,CAAC;AAE7B,KAAK,WAAW,GACZ,IAAI,CACF,YAAY,CAAC,MAAM,CAAC,mBAAmB,EAAE,KAAK,CAAC,EAC/C,UAAU,GAAG,aAAa,GAAG,KAAK,GAAG,cAAc,GAAG,MAAM,GAAG,UAAU,CAC1E,GACD,oBAAoB,CAAC;AA2BzB,MAAM,MAAM,oBAAoB,GAAG;IACjC,uBAAuB,CAAC,EAAE,eAAe,CAAC;CAC3C,CAAC;AAEF,iBAAS,0BAA0B,CAAC,CAAC,SAAS,YAAY,EACxD,MAAM,EAAE,CAAC,EAC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