@tblabs/storage 5.9.1 → 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 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, offset?: number, limit?: number): Promise<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
- Append(id: string, text: string): Promise<void>;
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;
@@ -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 Append(id, text) {
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.Append(id, line + "\n");
112
+ await this.AppendText(id, line + "\n");
103
113
  }
104
114
  async Update(id, item) {
105
115
  this._db.Log(`Updating "${id}"...`);
@@ -0,0 +1,5 @@
1
+ import { Message } from '../MessageBus/Message';
2
+ import { dir } from '../Types/dir';
3
+ export declare class CreateFileCommand extends Message {
4
+ constructor(Database: dir, Dataset: dir, FileId: string);
5
+ }
@@ -0,0 +1,6 @@
1
+ import { Message } from '../MessageBus/Message';
2
+ export class CreateFileCommand extends Message {
3
+ constructor(Database, Dataset, FileId) {
4
+ super("CreateFile", { Database, Dataset, FileId });
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tblabs/storage",
3
- "version": "5.9.1",
3
+ "version": "5.9.2",
4
4
  "description": "online storage module with auth",
5
5
  "license": "beerware",
6
6
  "main": "index.js",
Binary file
Binary file