document-drive 1.0.0-alpha.100 → 1.0.0-alpha.102

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.100",
3
+ "version": "1.0.0-alpha.102",
4
4
  "license": "AGPL-3.0-only",
5
5
  "type": "module",
6
6
  "module": "./src/index.ts",
@@ -26,8 +26,8 @@
26
26
  "./src"
27
27
  ],
28
28
  "peerDependencies": {
29
- "document-model": "^1.8.0",
30
- "document-model-libs": "^1.90.1"
29
+ "document-model": "^2.1.0",
30
+ "document-model-libs": "^1.92.0"
31
31
  },
32
32
  "optionalDependencies": {
33
33
  "@prisma/client": "^5.18.0",
@@ -53,7 +53,6 @@
53
53
  "@types/uuid": "^9.0.8",
54
54
  "@vitest/browser": "^2.0.5",
55
55
  "@vitest/coverage-v8": "^2.0.5",
56
- "document-model-libs": "^1.90.1",
57
56
  "fake-indexeddb": "^5.0.2",
58
57
  "localforage": "^1.10.0",
59
58
  "msw": "^2.3.1",
@@ -64,18 +63,20 @@
64
63
  "vitest": "^2.0.5",
65
64
  "webdriverio": "^9.0.9",
66
65
  "vitest-fetch-mock": "^0.3.0",
66
+ "document-model-libs": "1.92.0",
67
67
  "document-model": "2.1.0"
68
68
  },
69
69
  "packageManager": "pnpm@9.1.4+sha256.30a1801ac4e723779efed13a21f4c39f9eb6c9fbb4ced101bce06b422593d7c9",
70
70
  "scripts": {
71
71
  "check-types": "tsc --noemit --emitDeclarationOnly false --project tsconfig.json",
72
- "lint": "eslint src --ext .js,.jsx,.ts,.tsx && yarn check-types",
72
+ "lint": "eslint src --ext .js,.jsx,.ts,.tsx && pnpm run check-types",
73
73
  "lint:fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
74
74
  "format": "prettier . --write",
75
75
  "release": "semantic-release",
76
76
  "test": "vitest run --coverage --exclude \"test/flaky/**\"",
77
77
  "test:watch": "vitest watch",
78
78
  "clean": "rimraf dist",
79
- "clean:node_modules": "rimraf node_modules"
79
+ "clean:node_modules": "rimraf node_modules",
80
+ "build": " "
80
81
  }
81
82
  }
package/src/index.ts CHANGED
@@ -2,3 +2,5 @@ export * from './server';
2
2
  export * from './server/error';
3
3
  export * from './storage';
4
4
  export * from './utils';
5
+
6
+ export const test = 'test';
@@ -184,6 +184,15 @@ export class BaseDocumentDriveServer
184
184
  this.initializePromise = this._initialize();
185
185
  }
186
186
 
187
+ setDocumentModels(models: DocumentModel[]): void {
188
+ this.documentModels = [...models];
189
+ this.emit('documentModels', [...models]);
190
+ }
191
+
192
+ initializeDefaultRemoteDrives() {
193
+ return this.defaultDrivesManager.initializeDefaultRemoteDrives();
194
+ }
195
+
187
196
  getDefaultRemoteDrives() {
188
197
  return this.defaultDrivesManager.getDefaultRemoteDrives();
189
198
  }
@@ -191,6 +200,7 @@ export class BaseDocumentDriveServer
191
200
  setDefaultDriveAccessLevel(url: string, level: RemoteDriveAccessLevel) {
192
201
  return this.defaultDrivesManager.setDefaultDriveAccessLevel(url, level);
193
202
  }
203
+
194
204
  setAllDefaultDrivesAccessLevel(level: RemoteDriveAccessLevel) {
195
205
  return this.defaultDrivesManager.setAllDefaultDrivesAccessLevel(level);
196
206
  }
@@ -626,7 +636,9 @@ export class BaseDocumentDriveServer
626
636
  });
627
637
  }
628
638
 
629
- await this.defaultDrivesManager.initializeDefaultRemoteDrives();
639
+ if (this.options.defaultDrives.loadOnInit !== false) {
640
+ await this.defaultDrivesManager.initializeDefaultRemoteDrives();
641
+ }
630
642
 
631
643
  // if network connect comes back online
632
644
  // then triggers the listeners update
@@ -202,6 +202,7 @@ export interface DriveEvents {
202
202
  status: number,
203
203
  errorMessage: string
204
204
  ) => void;
205
+ documentModels: (documentModels: DocumentModel[]) => void;
205
206
  }
206
207
 
207
208
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -294,6 +295,7 @@ export type RemoveOldRemoteDrivesOption =
294
295
 
295
296
  export type DocumentDriveServerOptions = {
296
297
  defaultDrives: {
298
+ loadOnInit?: boolean; // defaults to true
297
299
  remoteDrives?: Array<DefaultRemoteDriveInput>;
298
300
  removeOldRemoteDrives?: RemoveOldRemoteDrivesOption;
299
301
  };
@@ -313,6 +315,8 @@ export type GetStrandsOptions = {
313
315
 
314
316
  export abstract class AbstractDocumentDriveServer {
315
317
  /** Public methods **/
318
+ abstract initialize(): Promise<Error[] | null>;
319
+ abstract setDocumentModels(models: DocumentModel[]): void;
316
320
  abstract getDrives(): Promise<string[]>;
317
321
  abstract addDrive(drive: DriveInput): Promise<DocumentDriveDocument>;
318
322
  abstract addRemoteDrive(
@@ -485,6 +485,7 @@ export class PrismaStorage implements IDriveStorage {
485
485
  DocumentDriveState,
486
486
  DocumentDriveLocalState
487
487
  >,
488
+ // @ts-expect-error TODO: fix as this should not be undefined
488
489
  state: undefined,
489
490
  lastModified: new Date(dbDoc.lastModified).toISOString(),
490
491
  operations: operationsByScope,
@@ -73,6 +73,10 @@ export class SequelizeStorage implements IDriveStorage {
73
73
  type: DataTypes.STRING,
74
74
  primaryKey: true,
75
75
  unique: 'unique_operation'
76
+ },
77
+ skip: {
78
+ type: DataTypes.INTEGER,
79
+ defaultValue: 0
76
80
  }
77
81
  });
78
82
 
@@ -292,6 +296,7 @@ export class SequelizeStorage implements IDriveStorage {
292
296
  return count > 0;
293
297
  }
294
298
 
299
+ // @ts-expect-error TODO: fix as this should not be undefined
295
300
  async getDocument(driveId: string, id: string) {
296
301
  const Document = this.db.models.document;
297
302
  if (!Document) {
@@ -326,6 +331,7 @@ export class SequelizeStorage implements IDriveStorage {
326
331
  type: string;
327
332
  scope: string;
328
333
  opId?: string;
334
+ skip: number;
329
335
  }
330
336
  ];
331
337
  revision: Required<Record<OperationScope, number>>;
@@ -343,26 +349,17 @@ export class SequelizeStorage implements IDriveStorage {
343
349
  throw new Error('Operation model not found');
344
350
  }
345
351
 
346
- const operations = document.operations.map(
347
- (op: {
348
- hash: string;
349
- index: number;
350
- timestamp: Date;
351
- input: JSON;
352
- type: string;
353
- scope: string;
354
- opId?: string;
355
- }) => ({
356
- hash: op.hash,
357
- index: op.index,
358
- timestamp: new Date(op.timestamp).toISOString(),
359
- input: op.input,
360
- type: op.type,
361
- scope: op.scope as OperationScope,
362
- id: op.opId
363
- // attachments: fileRegistry
364
- })
365
- );
352
+ const operations: Operation[] = document.operations.map(op => ({
353
+ hash: op.hash,
354
+ index: op.index,
355
+ timestamp: new Date(op.timestamp).toISOString(),
356
+ input: op.input,
357
+ type: op.type,
358
+ scope: op.scope as OperationScope,
359
+ id: op.opId,
360
+ skip: op.skip
361
+ // attachments: fileRegistry
362
+ }));
366
363
 
367
364
  const doc = {
368
365
  created: document.createdAt.toISOString(),
@@ -22,6 +22,7 @@ function isReadModeDriveServer(obj: unknown): obj is IReadModeDriveServer {
22
22
  }
23
23
 
24
24
  export interface IDefaultDrivesManager {
25
+ initializeDefaultRemoteDrives(): Promise<void>;
25
26
  getDefaultRemoteDrives(): Map<string, DefaultRemoteDriveInfo>;
26
27
  setDefaultDriveAccessLevel(
27
28
  url: string,