@tblabs/storage 5.9.0 → 5.9.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 +3 -2
- package/Dataset.js +14 -4
- package/Messages/CreateFileCommand.d.ts +5 -0
- package/Messages/CreateFileCommand.js +6 -0
- package/Messages/ReadFileQuery.d.ts +1 -1
- package/Messages/ReadFileQuery.js +2 -2
- package/package.json +1 -1
- package/tblabs-storage-5.9.2.tgz +0 -0
- package/tblabs-storage-5.9.0.tgz +0 -0
package/Dataset.d.ts
CHANGED
|
@@ -13,11 +13,12 @@ export declare class Dataset<T extends object> implements IRepo<T> {
|
|
|
13
13
|
private get DatasetPath();
|
|
14
14
|
CanUserDo(action: keyof IStorageUserPrivileges): boolean;
|
|
15
15
|
GetOne(id: string): Promise<T>;
|
|
16
|
-
Read(id: string,
|
|
16
|
+
Read(id: string, offset?: number, limit?: number): Promise<string[]>;
|
|
17
17
|
GetAll(): Promise<T[]>;
|
|
18
18
|
GetAllIds(): Promise<string[]>;
|
|
19
|
+
Create(id: string): Promise<void>;
|
|
19
20
|
Add(id: string, item: T): Promise<void>;
|
|
20
|
-
|
|
21
|
+
AppendText(id: string, text: string): Promise<void>;
|
|
21
22
|
AppendLine(id: string, line: string): Promise<void>;
|
|
22
23
|
Update(id: string, item: T): Promise<void>;
|
|
23
24
|
Delete(id: string): Promise<void>;
|
package/Dataset.js
CHANGED
|
@@ -7,6 +7,7 @@ import { UpdateFileCommand } from "./Messages/UpdateFileCommand";
|
|
|
7
7
|
import { ListFilesIdsQuery } from "./Messages/ListFilesIdsQuery";
|
|
8
8
|
import { AppendCommand } from "./Messages/AppendCommand";
|
|
9
9
|
import { ReadFileQuery } from "./Messages/ReadFileQuery";
|
|
10
|
+
import { CreateFileCommand } from "./Messages/CreateFileCommand";
|
|
10
11
|
export class Dataset {
|
|
11
12
|
_db;
|
|
12
13
|
_converter;
|
|
@@ -48,9 +49,9 @@ export class Dataset {
|
|
|
48
49
|
this._db.Log(`Fetched "${id}" from "${this.DatasetPath}".`);
|
|
49
50
|
return item;
|
|
50
51
|
}
|
|
51
|
-
async Read(id,
|
|
52
|
+
async Read(id, offset = 0, limit = 0) {
|
|
52
53
|
this._db.Log(`Reading "${id}" from "${this.DatasetPath}"...`);
|
|
53
|
-
const queryResult = await this._db.Send(new ReadFileQuery(this._db.DatabaseDir, this.dataset, id,
|
|
54
|
+
const queryResult = await this._db.Send(new ReadFileQuery(this._db.DatabaseDir, this.dataset, id, offset, limit));
|
|
54
55
|
if (!queryResult.IsSuccess) {
|
|
55
56
|
throw new Error("Failed to read: " + queryResult.ErrorMessage);
|
|
56
57
|
}
|
|
@@ -79,6 +80,15 @@ export class Dataset {
|
|
|
79
80
|
this._db.Log(`Found ${ids.length} files in "${this.DatasetPath}".`);
|
|
80
81
|
return ids;
|
|
81
82
|
}
|
|
83
|
+
async Create(id) {
|
|
84
|
+
this._db.Log(`Creating "${id}" in "${this.DatasetPath}"...`);
|
|
85
|
+
const result = await this._db.Send(new CreateFileCommand(this._db.DatabaseDir, this.dataset, id));
|
|
86
|
+
if (!result.IsSuccess) {
|
|
87
|
+
throw new Error("Failed to create item: " + result.ErrorMessage);
|
|
88
|
+
}
|
|
89
|
+
this._db.Log(`"${id}" created in "${this.DatasetPath}".`);
|
|
90
|
+
}
|
|
91
|
+
;
|
|
82
92
|
async Add(id, item) {
|
|
83
93
|
this._db.Log(`Adding "${id}" to "${this.DatasetPath}"...`);
|
|
84
94
|
const rawItem = this._converter.ToRaw(item);
|
|
@@ -89,7 +99,7 @@ export class Dataset {
|
|
|
89
99
|
this._db.Log(`"${id}" added to "${this.DatasetPath}".`);
|
|
90
100
|
}
|
|
91
101
|
;
|
|
92
|
-
async
|
|
102
|
+
async AppendText(id, text) {
|
|
93
103
|
this._db.Log(`Appending ${text.length} characters to "${id}" in "${this.DatasetPath}"...`);
|
|
94
104
|
const result = await this._db.Send(new AppendCommand(this._db.DatabaseDir, this.dataset, id, text));
|
|
95
105
|
if (!result.IsSuccess) {
|
|
@@ -99,7 +109,7 @@ export class Dataset {
|
|
|
99
109
|
}
|
|
100
110
|
;
|
|
101
111
|
async AppendLine(id, line) {
|
|
102
|
-
await this.
|
|
112
|
+
await this.AppendText(id, line + "\n");
|
|
103
113
|
}
|
|
104
114
|
async Update(id, item) {
|
|
105
115
|
this._db.Log(`Updating "${id}"...`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Message } from '../MessageBus/Message';
|
|
2
2
|
import { dir } from '../Types/dir';
|
|
3
3
|
export declare class ReadFileQuery extends Message {
|
|
4
|
-
constructor(Database: dir, Dataset: dir, FileId: string,
|
|
4
|
+
constructor(Database: dir, Dataset: dir, FileId: string, Offset?: number, Limit?: number);
|
|
5
5
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Message } from '../MessageBus/Message';
|
|
2
2
|
export class ReadFileQuery extends Message {
|
|
3
|
-
constructor(Database, Dataset, FileId,
|
|
4
|
-
super("ReadFile", { Database, Dataset, FileId,
|
|
3
|
+
constructor(Database, Dataset, FileId, Offset = 0, Limit = 0) {
|
|
4
|
+
super("ReadFile", { Database, Dataset, FileId, Offset, Limit });
|
|
5
5
|
}
|
|
6
6
|
}
|
package/package.json
CHANGED
|
Binary file
|
package/tblabs-storage-5.9.0.tgz
DELETED
|
Binary file
|