@tblabs/storage 5.0.0 → 5.0.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.
- package/Dataset.d.ts +1 -1
- package/Dataset.js +9 -12
- package/IStorageUser.d.ts +50 -0
- package/IStorageUser.js +2 -0
- package/Messages/LoginQuery.d.ts +5 -0
- package/Messages/LoginQuery.js +6 -0
- package/Messages/RegisterCommand.d.ts +6 -0
- package/Messages/RegisterCommand.js +6 -0
- package/OnlineStorage.d.ts +5 -53
- package/OnlineStorage.js +19 -12
- package/package.json +1 -1
- package/tblabs-storage-5.0.2.tgz +0 -0
- package/tblabs-storage-5.0.0.tgz +0 -0
package/Dataset.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare class Dataset<T extends object> implements IRepo<T> {
|
|
|
9
9
|
get Name(): string;
|
|
10
10
|
constructor(_db: OnlineStorage, _converter: IConverter<any, T>, dataset: dir);
|
|
11
11
|
private get DatasetPath();
|
|
12
|
-
GetOne(id: string): Promise<T
|
|
12
|
+
GetOne(id: string): Promise<T>;
|
|
13
13
|
FindOne(id: string): Promise<T | null>;
|
|
14
14
|
GetAll(): Promise<T[]>;
|
|
15
15
|
Add(id: string, item: T): Promise<void>;
|
package/Dataset.js
CHANGED
|
@@ -24,32 +24,29 @@ export class Dataset {
|
|
|
24
24
|
this._db.Log(`Fetching "${id}"...`);
|
|
25
25
|
const queryResult = await this._db.Send(new GetQuery(this._db.DatabaseDir, this.dataset, id));
|
|
26
26
|
if (!queryResult.IsSuccess) {
|
|
27
|
-
|
|
28
|
-
return null;
|
|
27
|
+
throw new Error(`Could not fetch file: ${queryResult.ErrorMessage}`);
|
|
29
28
|
}
|
|
30
|
-
this._db.Log(`Found "${id}" in "${this.DatasetPath}".`);
|
|
31
29
|
const rawItem = queryResult.Result;
|
|
32
30
|
const item = this._converter.FromRaw(rawItem);
|
|
31
|
+
this._db.Log(`Fetched "${id}" from "${this.DatasetPath}".`);
|
|
33
32
|
return item;
|
|
34
33
|
}
|
|
35
34
|
async FindOne(id) {
|
|
36
35
|
this._db.Log(`Searching for "${id}"...`);
|
|
37
36
|
const queryResult = await this._db.Send(new FindQuery(id, this._db.DatabaseDir));
|
|
38
37
|
if (!queryResult.IsSuccess) {
|
|
39
|
-
|
|
40
|
-
return null;
|
|
38
|
+
throw new Error(`Could not find file: ${queryResult.ErrorMessage}`);
|
|
41
39
|
}
|
|
42
|
-
this._db.Log(`Found "${id}".`);
|
|
43
40
|
const rawItem = queryResult.Result;
|
|
44
41
|
const item = this._converter.FromRaw(rawItem);
|
|
42
|
+
this._db.Log(`Found "${id}" in "${this.DatasetPath}".`);
|
|
45
43
|
return item;
|
|
46
44
|
}
|
|
47
45
|
async GetAll() {
|
|
48
46
|
this._db.Log(`Fetching all from "${this.DatasetPath}"...`);
|
|
49
47
|
const queryResult = await this._db.Send(new ListQuery(this._db.DatabaseDir, this.dataset));
|
|
50
48
|
if (!queryResult.IsSuccess) {
|
|
51
|
-
|
|
52
|
-
return [];
|
|
49
|
+
throw new Error(`Could not fetch items: ${queryResult.ErrorMessage}`);
|
|
53
50
|
}
|
|
54
51
|
const rawItems = queryResult.Result;
|
|
55
52
|
const items = rawItems.map((raw) => this._converter.FromRaw(raw));
|
|
@@ -73,7 +70,7 @@ export class Dataset {
|
|
|
73
70
|
this._db.Log(`Adding "${id}" to "${this.DatasetPath}"...`);
|
|
74
71
|
const result = await this._db.Send(new AddCommand(this._db.DatabaseDir, this.dataset, id, item));
|
|
75
72
|
if (!result.IsSuccess) {
|
|
76
|
-
throw new Error(`Could not add
|
|
73
|
+
throw new Error(`Could not add file: ${result.ErrorMessage}`);
|
|
77
74
|
}
|
|
78
75
|
this._db.Log(`"${id}" added to "${this.DatasetPath}".`);
|
|
79
76
|
}
|
|
@@ -82,7 +79,7 @@ export class Dataset {
|
|
|
82
79
|
this._db.Log(`Updating "${id}"...`);
|
|
83
80
|
const result = await this._db.Send(new UpdateCommand(this._db.DatabaseDir, this.dataset, id, item));
|
|
84
81
|
if (!result.IsSuccess) {
|
|
85
|
-
throw new Error(`Could not update
|
|
82
|
+
throw new Error(`Could not update file: ${result.ErrorMessage}`);
|
|
86
83
|
}
|
|
87
84
|
this._db.Log(`"${id}" updated in "${this.DatasetPath}".`);
|
|
88
85
|
}
|
|
@@ -91,7 +88,7 @@ export class Dataset {
|
|
|
91
88
|
this._db.Log(`Deleting "${id}" from "${this.DatasetPath}"...`);
|
|
92
89
|
const result = await this._db.Send(new DeleteCommand(this._db.DatabaseDir, this.dataset, id));
|
|
93
90
|
if (!result.IsSuccess) {
|
|
94
|
-
throw new Error(`Could not delete
|
|
91
|
+
throw new Error(`Could not delete file: ${result.ErrorMessage}`);
|
|
95
92
|
}
|
|
96
93
|
this._db.Log(`Deleted "${id}" from "${this.DatasetPath}".`);
|
|
97
94
|
}
|
|
@@ -99,7 +96,7 @@ export class Dataset {
|
|
|
99
96
|
this._db.Log(`Dropping "${this.DatasetPath}"...`);
|
|
100
97
|
const result = await this._db.Send(new DropCommand(this._db.DatabaseDir, this.dataset));
|
|
101
98
|
if (!result.IsSuccess) {
|
|
102
|
-
throw new Error(`Could not drop
|
|
99
|
+
throw new Error(`Could not drop dataset: ${result.ErrorMessage}`);
|
|
103
100
|
}
|
|
104
101
|
this._db.Log(`"${this.DatasetPath}" dropped.`);
|
|
105
102
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ISender } from "./MessageBus/ISender";
|
|
2
|
+
export type IEntitiesSet = string[] | "all" | "none";
|
|
3
|
+
export type ICommandPrivilege = {
|
|
4
|
+
Datasets?: IEntitiesSet;
|
|
5
|
+
Files?: IEntitiesSet;
|
|
6
|
+
};
|
|
7
|
+
export interface IStorageUserPrivileges {
|
|
8
|
+
Add: {
|
|
9
|
+
Datasets: IEntitiesSet;
|
|
10
|
+
};
|
|
11
|
+
Update: {
|
|
12
|
+
Files: IEntitiesSet;
|
|
13
|
+
};
|
|
14
|
+
Delete: {
|
|
15
|
+
Files: IEntitiesSet;
|
|
16
|
+
};
|
|
17
|
+
List: {
|
|
18
|
+
Datasets: IEntitiesSet;
|
|
19
|
+
};
|
|
20
|
+
Get: {
|
|
21
|
+
Files: IEntitiesSet;
|
|
22
|
+
};
|
|
23
|
+
Drop: {
|
|
24
|
+
Datasets: IEntitiesSet;
|
|
25
|
+
};
|
|
26
|
+
Move: {
|
|
27
|
+
Datasets: IEntitiesSet;
|
|
28
|
+
Files: IEntitiesSet;
|
|
29
|
+
};
|
|
30
|
+
Create: {
|
|
31
|
+
Datasets: IEntitiesSet;
|
|
32
|
+
};
|
|
33
|
+
Exists: {
|
|
34
|
+
Datasets: IEntitiesSet;
|
|
35
|
+
};
|
|
36
|
+
Remove: {
|
|
37
|
+
Datasets: IEntitiesSet;
|
|
38
|
+
};
|
|
39
|
+
Register: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface IStorageUser extends ISender {
|
|
42
|
+
Id: string;
|
|
43
|
+
Database: string;
|
|
44
|
+
Name: string;
|
|
45
|
+
Role: string;
|
|
46
|
+
Icon: string;
|
|
47
|
+
Password: string;
|
|
48
|
+
Privileges: IStorageUserPrivileges;
|
|
49
|
+
Tags: string[];
|
|
50
|
+
}
|
package/IStorageUser.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IStorageUserPrivileges } from "../IStorageUser";
|
|
2
|
+
import { Message } from "../MessageBus/Message";
|
|
3
|
+
import { dir } from "../Types/dir";
|
|
4
|
+
export declare class RegisterCommand extends Message {
|
|
5
|
+
constructor(Database: dir, Id: string, Role: string, Name: string, Password: string, Privileges: IStorageUserPrivileges, Icon?: string, Tags?: string[]);
|
|
6
|
+
}
|
package/OnlineStorage.d.ts
CHANGED
|
@@ -3,68 +3,20 @@ import { IMessage } from "./MessageBus/IMessage";
|
|
|
3
3
|
import { ISender } from "./MessageBus/ISender";
|
|
4
4
|
import { MessageBus } from "./MessageBus/MessageBus";
|
|
5
5
|
import { MessageBusResponse } from "./MessageBus/MessageBusResponse";
|
|
6
|
-
import { Message } from "./MessageBus/Message";
|
|
7
6
|
import { Dataset } from "./Dataset";
|
|
8
|
-
|
|
9
|
-
export interface IUser {
|
|
10
|
-
Id: string;
|
|
11
|
-
Name: string;
|
|
12
|
-
Database: string;
|
|
13
|
-
Privileges: {
|
|
14
|
-
Add: {
|
|
15
|
-
Datasets: IEntitiesSet;
|
|
16
|
-
};
|
|
17
|
-
Update: {
|
|
18
|
-
Datasets: IEntitiesSet;
|
|
19
|
-
Files: IEntitiesSet;
|
|
20
|
-
};
|
|
21
|
-
Delete: {
|
|
22
|
-
Datasets: IEntitiesSet;
|
|
23
|
-
Files: IEntitiesSet;
|
|
24
|
-
};
|
|
25
|
-
List: {
|
|
26
|
-
Datasets: IEntitiesSet;
|
|
27
|
-
};
|
|
28
|
-
Get: {
|
|
29
|
-
Files: IEntitiesSet;
|
|
30
|
-
};
|
|
31
|
-
Drop: {
|
|
32
|
-
Datasets: IEntitiesSet;
|
|
33
|
-
};
|
|
34
|
-
Move: {
|
|
35
|
-
Datasets: IEntitiesSet;
|
|
36
|
-
Files: IEntitiesSet;
|
|
37
|
-
};
|
|
38
|
-
Backup: {
|
|
39
|
-
Datasets: IEntitiesSet;
|
|
40
|
-
};
|
|
41
|
-
Find: {
|
|
42
|
-
Files: IEntitiesSet;
|
|
43
|
-
};
|
|
44
|
-
Create: {
|
|
45
|
-
Datasets: IEntitiesSet;
|
|
46
|
-
};
|
|
47
|
-
Exists: {
|
|
48
|
-
Datasets: IEntitiesSet;
|
|
49
|
-
};
|
|
50
|
-
Remove: {
|
|
51
|
-
Datasets: IEntitiesSet;
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
export declare class AuthQuery extends Message {
|
|
56
|
-
constructor(Database: dir, Password: string);
|
|
57
|
-
}
|
|
7
|
+
import { IStorageUser, IStorageUserPrivileges } from "./IStorageUser";
|
|
58
8
|
export declare class OnlineStorage {
|
|
59
9
|
private database;
|
|
60
10
|
private logEnabled;
|
|
61
11
|
private readonly _bus;
|
|
62
12
|
get DatabaseDir(): dir;
|
|
63
13
|
constructor(server: url, database: dir, sender?: ISender, bus?: MessageBus);
|
|
64
|
-
Login(password: string): Promise<
|
|
14
|
+
Login(password: string): Promise<IStorageUser>;
|
|
15
|
+
Register(id: string, role: string, name: string, password: string, privileges: IStorageUserPrivileges, icon?: string, tags?: string[]): Promise<IStorageUser>;
|
|
65
16
|
Logout(): this;
|
|
17
|
+
Init(): Promise<void>;
|
|
66
18
|
IsAuthorized(): boolean;
|
|
67
|
-
User(
|
|
19
|
+
User(sender: ISender): this;
|
|
68
20
|
EnableLog(): this;
|
|
69
21
|
DisableLog(): this;
|
|
70
22
|
Log(...message: any[]): void;
|
package/OnlineStorage.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { MessageBus } from "./MessageBus/MessageBus";
|
|
2
2
|
import { CreateCommand, ExistsCommand, RemoveCommand } from "./Messages/AddDirCommand";
|
|
3
|
-
import { Message } from "./MessageBus/Message";
|
|
4
3
|
import { MoveCommand } from "./Messages/MoveCommand";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
super("LoginUser", { Database, Password });
|
|
8
|
-
}
|
|
9
|
-
}
|
|
4
|
+
import { LoginQuery } from "./Messages/LoginQuery";
|
|
5
|
+
import { RegisterCommand } from "./Messages/RegisterCommand";
|
|
10
6
|
export class OnlineStorage {
|
|
11
7
|
database;
|
|
12
8
|
logEnabled = false;
|
|
@@ -19,7 +15,7 @@ export class OnlineStorage {
|
|
|
19
15
|
this._bus = bus || new MessageBus(server, sender);
|
|
20
16
|
}
|
|
21
17
|
async Login(password) {
|
|
22
|
-
const result = await this._bus.SendMessage(new
|
|
18
|
+
const result = await this._bus.SendMessage(new LoginQuery(this.DatabaseDir, password));
|
|
23
19
|
if (!result.IsSuccess) {
|
|
24
20
|
throw new Error(`Could not login: ${result.ErrorMessage}`);
|
|
25
21
|
}
|
|
@@ -27,15 +23,26 @@ export class OnlineStorage {
|
|
|
27
23
|
this.User({ Id: user?.Id ?? "Anonymous" });
|
|
28
24
|
return user;
|
|
29
25
|
}
|
|
26
|
+
async Register(id, role, name, password, privileges, icon, tags) {
|
|
27
|
+
const result = await this._bus.SendMessage(new RegisterCommand(this.DatabaseDir, id, role, name, password, privileges, icon, tags));
|
|
28
|
+
if (!result.IsSuccess) {
|
|
29
|
+
throw new Error(`Could not register: ${result.ErrorMessage}`);
|
|
30
|
+
}
|
|
31
|
+
const user = result.Result;
|
|
32
|
+
return user;
|
|
33
|
+
}
|
|
30
34
|
Logout() {
|
|
31
35
|
this.User({ Id: "Anonymous" });
|
|
32
36
|
return this;
|
|
33
37
|
}
|
|
38
|
+
async Init() {
|
|
39
|
+
// TODO: Setup Anonymous user and Admin
|
|
40
|
+
}
|
|
34
41
|
IsAuthorized() {
|
|
35
42
|
return this._bus.Sender?.Id !== "Anonymous";
|
|
36
43
|
}
|
|
37
|
-
User(
|
|
38
|
-
this._bus.SetSender(
|
|
44
|
+
User(sender) {
|
|
45
|
+
this._bus.SetSender(sender);
|
|
39
46
|
return this;
|
|
40
47
|
}
|
|
41
48
|
EnableLog() {
|
|
@@ -61,7 +68,7 @@ export class OnlineStorage {
|
|
|
61
68
|
this.Log(`Creating dataset "${datasetName}"...`);
|
|
62
69
|
const result = await this._bus.SendMessage(new CreateCommand(this.DatabaseDir, datasetName));
|
|
63
70
|
if (!result.IsSuccess) {
|
|
64
|
-
throw new Error(`Could not add dataset
|
|
71
|
+
throw new Error(`Could not add dataset: ${result.ErrorMessage}`);
|
|
65
72
|
}
|
|
66
73
|
this.Log(`Dataset "${datasetName}" created.`);
|
|
67
74
|
}
|
|
@@ -69,7 +76,7 @@ export class OnlineStorage {
|
|
|
69
76
|
this.Log(`Checking if dataset "${datasetName}" exists...`);
|
|
70
77
|
const result = await this._bus.SendMessage(new ExistsCommand(this.DatabaseDir, datasetName));
|
|
71
78
|
if (!result.IsSuccess) {
|
|
72
|
-
throw new Error(`Could not check if dataset
|
|
79
|
+
throw new Error(`Could not check if dataset exists: ${result.ErrorMessage}`);
|
|
73
80
|
}
|
|
74
81
|
this.Log(`Dataset "${datasetName}" ${result.Result ? "exists" : "does not exist"}.`);
|
|
75
82
|
return result.Result;
|
|
@@ -78,7 +85,7 @@ export class OnlineStorage {
|
|
|
78
85
|
this.Log(`Removing dataset "${datasetName}"...`);
|
|
79
86
|
const result = await this._bus.SendMessage(new RemoveCommand(this.DatabaseDir, datasetName));
|
|
80
87
|
if (!result.IsSuccess) {
|
|
81
|
-
throw new Error(`Could not remove dataset
|
|
88
|
+
throw new Error(`Could not remove dataset: ${result.ErrorMessage}`);
|
|
82
89
|
}
|
|
83
90
|
this.Log(`Dataset "${datasetName}" removed.`);
|
|
84
91
|
}
|
package/package.json
CHANGED
|
Binary file
|
package/tblabs-storage-5.0.0.tgz
DELETED
|
Binary file
|