document-drive 0.0.8 → 0.0.10

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": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "license": "AGPL-3.0-only",
5
5
  "type": "module",
6
6
  "module": "./src/index.ts",
@@ -36,8 +36,8 @@
36
36
  "@typescript-eslint/eslint-plugin": "^6.12.0",
37
37
  "@typescript-eslint/parser": "^6.12.0",
38
38
  "@vitest/coverage-v8": "^0.34.6",
39
- "document-model": "^1.0.15",
40
- "document-model-libs": "^1.1.23",
39
+ "document-model": "^1.0.16",
40
+ "document-model-libs": "^1.1.24",
41
41
  "eslint": "^8.54.0",
42
42
  "eslint-config-prettier": "^9.0.0",
43
43
  "fake-indexeddb": "^5.0.1",
@@ -40,7 +40,9 @@ export class DocumentDriveServer implements IDocumentDriveServer {
40
40
  }
41
41
 
42
42
  addDrive(drive: DriveInput) {
43
- const document = utils.createDocument({ state: drive });
43
+ const document = utils.createDocument({
44
+ state: { global: drive, local: {} }
45
+ });
44
46
  return this.storage.saveDrive(document);
45
47
  }
46
48
 
@@ -10,10 +10,7 @@ import type {
10
10
  Signal
11
11
  } from 'document-model/document';
12
12
 
13
- export type DriveInput = Omit<
14
- DocumentDriveState,
15
- '__typename' | 'remoteUrl' | 'nodes'
16
- >;
13
+ export type DriveInput = Omit<DocumentDriveState, '__typename' | 'nodes'>;
17
14
 
18
15
  export type CreateDocumentInput = {
19
16
  id: string;
@@ -53,7 +53,7 @@ export class BrowserStorage implements IDriveStorage {
53
53
  await this.db
54
54
  ).getItem<DocumentDriveDocument[]>(BrowserStorage.DRIVES_KEY)) ??
55
55
  [];
56
- return drives.map(drive => drive.state.id);
56
+ return drives.map(drive => drive.state.global.id);
57
57
  }
58
58
 
59
59
  async getDrive(id: string) {
@@ -62,7 +62,7 @@ export class BrowserStorage implements IDriveStorage {
62
62
  await this.db
63
63
  ).getItem<DocumentDriveDocument[]>(BrowserStorage.DRIVES_KEY)) ??
64
64
  [];
65
- const drive = drives.find(drive => drive.state.id === id);
65
+ const drive = drives.find(drive => drive.state.global.id === id);
66
66
  if (!drive) {
67
67
  throw new Error(`Drive with id ${id} not found`);
68
68
  }
@@ -75,7 +75,9 @@ export class BrowserStorage implements IDriveStorage {
75
75
  (await db.getItem<DocumentDriveDocument[]>(
76
76
  BrowserStorage.DRIVES_KEY
77
77
  )) ?? [];
78
- const index = drives.findIndex(d => d.state.id === drive.state.id);
78
+ const index = drives.findIndex(
79
+ d => d.state.global.id === drive.state.global.id
80
+ );
79
81
  if (index > -1) {
80
82
  drives[index] = drive;
81
83
  } else {
@@ -94,7 +96,7 @@ export class BrowserStorage implements IDriveStorage {
94
96
  )) ?? [];
95
97
  await db.setItem(
96
98
  BrowserStorage.DRIVES_KEY,
97
- drives.filter(drive => drive.state.id !== id)
99
+ drives.filter(drive => drive.state.global.id !== id)
98
100
  );
99
101
  }
100
102
  }
@@ -120,8 +120,8 @@ export class FilesystemStorage implements IDriveStorage {
120
120
  let document: Document;
121
121
  try {
122
122
  document = await this.getDocument(FilesystemStorage.DRIVES_DIR, id);
123
- } catch {
124
- throw new Error(`Drive with id ${id} not found`);
123
+ } catch (error) {
124
+ throw new Error(`Drive with id ${id} not found: ${error}`);
125
125
  }
126
126
  if (isDocumentDrive(document)) {
127
127
  return document;
@@ -133,7 +133,7 @@ export class FilesystemStorage implements IDriveStorage {
133
133
  saveDrive(drive: DocumentDriveDocument) {
134
134
  return this.saveDocument(
135
135
  FilesystemStorage.DRIVES_DIR,
136
- drive.state.id,
136
+ drive.state.global.id,
137
137
  drive
138
138
  );
139
139
  }
@@ -52,7 +52,7 @@ export class MemoryStorage implements IDriveStorage {
52
52
  }
53
53
 
54
54
  async saveDrive(drive: DocumentDriveDocument) {
55
- this.drives[drive.state.id] = drive;
55
+ this.drives[drive.state.global.id] = drive;
56
56
  }
57
57
 
58
58
  async deleteDrive(id: string) {
package/src/utils.ts CHANGED
@@ -10,6 +10,6 @@ export function isDocumentDrive(
10
10
  ): document is DocumentDriveDocument {
11
11
  return (
12
12
  document.documentType === DocumentDriveModel.id &&
13
- z.DocumentDriveStateSchema().safeParse(document.state).success
13
+ z.DocumentDriveStateSchema().safeParse(document.state.global).success
14
14
  );
15
15
  }