@tblabs/storage 5.7.0 → 5.7.2

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.
@@ -0,0 +1,5 @@
1
+ export interface DatabaseInfo {
2
+ Dir: string;
3
+ DatasetsCount: number;
4
+ UsersCount: number;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
package/Dataset.js CHANGED
@@ -35,6 +35,9 @@ export class Dataset {
35
35
  async GetOne(id) {
36
36
  this._db.Log(`Fetching "${id}"...`);
37
37
  const queryResult = await this._db.Send(new GetFileQuery(this._db.DatabaseDir, this.dataset, id));
38
+ if (!queryResult.IsSuccess) {
39
+ throw new Error("Failed to get one item: " + queryResult.ErrorMessage);
40
+ }
38
41
  const rawItem = queryResult.Result;
39
42
  const item = this._converter.FromRaw(rawItem);
40
43
  this._db.Log(`Fetched "${id}" from "${this.DatasetPath}".`);
@@ -64,25 +67,37 @@ export class Dataset {
64
67
  async Add(id, item) {
65
68
  this._db.Log(`Adding "${id}" to "${this.DatasetPath}"...`);
66
69
  const rawItem = this._converter.ToRaw(item);
67
- await this._db.Send(new AddFileCommand(this._db.DatabaseDir, this.dataset, id, rawItem));
70
+ const result = await this._db.Send(new AddFileCommand(this._db.DatabaseDir, this.dataset, id, rawItem));
71
+ if (!result.IsSuccess) {
72
+ throw new Error("Failed to add item: " + result.ErrorMessage);
73
+ }
68
74
  this._db.Log(`"${id}" added to "${this.DatasetPath}".`);
69
75
  }
70
76
  ;
71
77
  async Update(id, item) {
72
78
  this._db.Log(`Updating "${id}"...`);
73
79
  const rawItem = this._converter.ToRaw(item);
74
- await this._db.Send(new UpdateFileCommand(this._db.DatabaseDir, this.dataset, id, rawItem));
80
+ const result = await this._db.Send(new UpdateFileCommand(this._db.DatabaseDir, this.dataset, id, rawItem));
81
+ if (!result.IsSuccess) {
82
+ throw new Error("Failed to update item: " + result.ErrorMessage);
83
+ }
75
84
  this._db.Log(`"${id}" updated in "${this.DatasetPath}".`);
76
85
  }
77
86
  ;
78
87
  async Delete(id) {
79
88
  this._db.Log(`Deleting "${id}" from "${this.DatasetPath}"...`);
80
- await this._db.Send(new DeleteFileCommand(this._db.DatabaseDir, this.dataset, id));
89
+ const result = await this._db.Send(new DeleteFileCommand(this._db.DatabaseDir, this.dataset, id));
90
+ if (!result.IsSuccess) {
91
+ throw new Error("Failed to delete item: " + result.ErrorMessage);
92
+ }
81
93
  this._db.Log(`Deleted "${id}" from "${this.DatasetPath}".`);
82
94
  }
83
95
  async Drop() {
84
96
  this._db.Log(`Dropping "${this.DatasetPath}"...`);
85
- await this._db.Send(new DropDatasetCommand(this._db.DatabaseDir, this.dataset));
97
+ const result = await this._db.Send(new DropDatasetCommand(this._db.DatabaseDir, this.dataset));
98
+ if (!result.IsSuccess) {
99
+ throw new Error("Failed to drop dataset: " + result.ErrorMessage);
100
+ }
86
101
  this._db.Log(`"${this.DatasetPath}" dropped.`);
87
102
  }
88
103
  }
@@ -7,6 +7,7 @@ import { Dataset } from "./Dataset";
7
7
  import { IStorageUser } from "./IStorageUser";
8
8
  import { IConverter } from "./IConverter";
9
9
  import { IStorageUserPrivileges } from "./IStorageUserPrivileges";
10
+ import { DatabaseInfo } from "./DatabaseInfo";
10
11
  export declare class OnlineStorage {
11
12
  private server;
12
13
  private database;
@@ -57,9 +58,5 @@ export declare class OnlineStorage {
57
58
  ListDatabases(): Promise<DatabaseInfo[]>;
58
59
  CreateDatabase(databaseDir: string): Promise<void>;
59
60
  DeleteDatabase(databaseDir: string): Promise<void>;
60
- }
61
- export interface DatabaseInfo {
62
- Dir: string;
63
- DatasetsCount: number;
64
- UsersCount: number;
61
+ CanUser(action: keyof IStorageUserPrivileges): boolean;
65
62
  }
package/OnlineStorage.js CHANGED
@@ -290,4 +290,13 @@ export class OnlineStorage {
290
290
  throw new Error(`Could not delete database: ${result.ErrorMessage}`);
291
291
  }
292
292
  }
293
+ CanUser(action) {
294
+ if (!this.User.Privileges) {
295
+ return false;
296
+ }
297
+ if (typeof this.User.Privileges[action] === "boolean" && this.User.Privileges[action]) {
298
+ return !!this.User.Privileges[action];
299
+ }
300
+ return false;
301
+ }
293
302
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tblabs/storage",
3
- "version": "5.7.0",
3
+ "version": "5.7.2",
4
4
  "description": "online storage module with auth",
5
5
  "license": "beerware",
6
6
  "main": "index.js",
Binary file
Binary file