@tblabs/storage 5.14.0 → 5.15.0
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/Datasets/DatasetBase.d.ts +2 -2
- package/Datasets/DatasetBase.js +11 -2
- package/Datasets/File/FileDataset.d.ts +16 -0
- package/Datasets/File/FileDataset.js +80 -0
- package/Datasets/File/FilePack.d.ts +7 -0
- package/Datasets/File/FilePack.js +1 -0
- package/Datasets/Object/ObjectDataset.d.ts +0 -1
- package/Datasets/Object/ObjectDataset.js +17 -26
- package/Datasets/Picture/PicturePack.d.ts +1 -1
- package/Datasets/Picture/PicturesDataset.d.ts +1 -3
- package/Datasets/Picture/PicturesDataset.js +9 -14
- package/Datasets/Text/ITextRepo.d.ts +2 -0
- package/Datasets/Text/RawTextDataset.d.ts +0 -1
- package/Datasets/Text/RawTextDataset.js +6 -15
- package/Datasets/UploadResult.d.ts +8 -0
- package/Datasets/UploadResult.js +16 -0
- package/Messages/AddObjectCommand.d.ts +5 -0
- package/Messages/AddObjectCommand.js +6 -0
- package/Messages/{AppendCommand.d.ts → AppendTextCommand.d.ts} +1 -1
- package/Messages/{UpdateFileCommand.js → AppendTextCommand.js} +2 -2
- package/Messages/DeleteObjectCommand.d.ts +5 -0
- package/Messages/DeleteObjectCommand.js +6 -0
- package/Messages/GetFileQuery.d.ts +1 -1
- package/Messages/GetFileQuery.js +2 -2
- package/Messages/GetObjectQuery.d.ts +5 -0
- package/Messages/GetObjectQuery.js +6 -0
- package/Messages/ListFilesQuery.d.ts +1 -1
- package/Messages/ListFilesQuery.js +2 -2
- package/Messages/ListObjectsIdsQuery.d.ts +5 -0
- package/Messages/ListObjectsIdsQuery.js +6 -0
- package/Messages/ListObjectsQuery.d.ts +5 -0
- package/Messages/ListObjectsQuery.js +6 -0
- package/Messages/ListPicturesQuery.d.ts +1 -1
- package/Messages/ListPicturesQuery.js +2 -2
- package/Messages/MoveObjectCommand.d.ts +5 -0
- package/Messages/MoveObjectCommand.js +6 -0
- package/Messages/{ReadFileQuery.d.ts → ReadTextQuery.d.ts} +1 -1
- package/Messages/{ReadFileQuery.js → ReadTextQuery.js} +2 -2
- package/Messages/UpdateObjectCommand.d.ts +5 -0
- package/Messages/UpdateObjectCommand.js +6 -0
- package/Models/DatasetMetadata.d.ts +4 -0
- package/Services/DatasetType.d.ts +2 -1
- package/Services/DatasetType.js +1 -0
- package/Services/OnlineStorage.d.ts +3 -1
- package/Services/OnlineStorage.js +8 -4
- package/index.d.ts +2 -1
- package/index.js +2 -1
- package/package.json +1 -1
- package/tblabs-storage-5.15.0.tgz +0 -0
- package/Datasets/Picture/PicturesUploadResult.d.ts +0 -9
- package/Datasets/Picture/PicturesUploadResult.js +0 -16
- package/Messages/AddFileCommand.d.ts +0 -5
- package/Messages/AddFileCommand.js +0 -6
- package/Messages/AppendCommand.js +0 -6
- package/Messages/MoveFileCommand.d.ts +0 -5
- package/Messages/MoveFileCommand.js +0 -6
- package/Messages/UpdateFileCommand.d.ts +0 -5
- package/tblabs-storage-5.14.0.tgz +0 -0
|
@@ -8,13 +8,13 @@ export declare abstract class DatasetBase {
|
|
|
8
8
|
protected dataset: dir;
|
|
9
9
|
abstract Type: DatasetType;
|
|
10
10
|
abstract GetAllIds(): Promise<string[]>;
|
|
11
|
-
abstract Drop(): Promise<void>;
|
|
12
11
|
abstract Delete(id: string): Promise<void>;
|
|
13
12
|
constructor(_db: OnlineStorage, dataset: dir);
|
|
14
13
|
get Name(): string;
|
|
15
14
|
get Database(): OnlineStorage;
|
|
16
|
-
|
|
15
|
+
get DatasetPath(): string;
|
|
17
16
|
GetMetadata(): Promise<DatasetMetadata>;
|
|
18
17
|
CanUserDo(action: keyof IStorageUserPrivileges): boolean;
|
|
19
18
|
protected Log(message: string): void;
|
|
19
|
+
Drop(): Promise<void>;
|
|
20
20
|
}
|
package/Datasets/DatasetBase.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GetMetadataQuery } from "../Messages/GetMetadataQuery";
|
|
2
|
+
import { DropDatasetCommand } from "../Messages/DropDatasetCommand";
|
|
2
3
|
export class DatasetBase {
|
|
3
4
|
_db;
|
|
4
5
|
dataset;
|
|
@@ -26,10 +27,10 @@ export class DatasetBase {
|
|
|
26
27
|
if (!this._db.User.Privileges) {
|
|
27
28
|
return false;
|
|
28
29
|
}
|
|
29
|
-
if (
|
|
30
|
+
if (this._db.User.Privileges?.[action] && typeof this._db.User.Privileges[action] === "object") {
|
|
30
31
|
return (this._db.User.Privileges[action].Datasets == "all" || this._db.User.Privileges[action].Datasets?.includes(this.dataset)) ?? false;
|
|
31
32
|
}
|
|
32
|
-
if (
|
|
33
|
+
if (this._db.User.Privileges?.[action] && typeof this._db.User.Privileges[action] === "boolean") {
|
|
33
34
|
return this._db.User.Privileges[action];
|
|
34
35
|
}
|
|
35
36
|
return false;
|
|
@@ -37,4 +38,12 @@ export class DatasetBase {
|
|
|
37
38
|
Log(message) {
|
|
38
39
|
this._db.Log(message);
|
|
39
40
|
}
|
|
41
|
+
async Drop() {
|
|
42
|
+
this.Log(`Dropping "${this.DatasetPath}"...`);
|
|
43
|
+
const result = await this._db.Send(new DropDatasetCommand(this._db.DatabaseDir, this.dataset));
|
|
44
|
+
if (!result.IsSuccess) {
|
|
45
|
+
throw new Error("Failed to drop dataset: " + result.ErrorMessage);
|
|
46
|
+
}
|
|
47
|
+
this.Log(`"${this.DatasetPath}" dropped successfully.`);
|
|
48
|
+
}
|
|
40
49
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { OnlineStorage } from "../../Services/OnlineStorage";
|
|
2
|
+
import { dir } from "../../Types/dir";
|
|
3
|
+
import { DatasetBase } from "../DatasetBase";
|
|
4
|
+
import { DatasetType } from "../../Services/DatasetType";
|
|
5
|
+
import { FilePack } from "./FilePack";
|
|
6
|
+
export declare class FileDataset extends DatasetBase {
|
|
7
|
+
protected _db: OnlineStorage;
|
|
8
|
+
protected dataset: dir;
|
|
9
|
+
Type: DatasetType;
|
|
10
|
+
constructor(_db: OnlineStorage, dataset: dir);
|
|
11
|
+
GetAllIds(): Promise<string[]>;
|
|
12
|
+
GetOne(fileId: string): Promise<FilePack>;
|
|
13
|
+
GetAll(): Promise<FilePack[]>;
|
|
14
|
+
Add(files: File[]): Promise<FilePack[]>;
|
|
15
|
+
Delete(fileId: string): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { DatasetBase } from "../DatasetBase";
|
|
2
|
+
import { DatasetType } from "../../Services/DatasetType";
|
|
3
|
+
import { ListFilesQuery } from "../../Messages/ListFilesQuery";
|
|
4
|
+
import { ListFilesIdsQuery } from "../../Messages/ListFilesIdsQuery";
|
|
5
|
+
import { GetFileQuery } from "../../Messages/GetFileQuery";
|
|
6
|
+
import { DeleteFileCommand } from "../../Messages/DeleteFileCommand";
|
|
7
|
+
export class FileDataset extends DatasetBase {
|
|
8
|
+
_db;
|
|
9
|
+
dataset;
|
|
10
|
+
Type = DatasetType.File;
|
|
11
|
+
constructor(_db, dataset) {
|
|
12
|
+
super(_db, dataset);
|
|
13
|
+
this._db = _db;
|
|
14
|
+
this.dataset = dataset;
|
|
15
|
+
}
|
|
16
|
+
async GetAllIds() {
|
|
17
|
+
const result = await this._db.Send(new ListFilesIdsQuery(this._db.DatabaseDir, this.dataset));
|
|
18
|
+
if (!result.IsSuccess) {
|
|
19
|
+
throw new Error("Failed to list files ids: " + result.ErrorMessage);
|
|
20
|
+
}
|
|
21
|
+
return result.Result;
|
|
22
|
+
}
|
|
23
|
+
async GetOne(fileId) {
|
|
24
|
+
const result = await this._db.Send(new GetFileQuery(this._db.Server, this._db.DatabaseDir, this.dataset, fileId));
|
|
25
|
+
if (!result.IsSuccess) {
|
|
26
|
+
throw new Error("Failed to get picture: " + result.ErrorMessage);
|
|
27
|
+
}
|
|
28
|
+
return result.Result;
|
|
29
|
+
}
|
|
30
|
+
async GetAll() {
|
|
31
|
+
const result = await this._db.Send(new ListFilesQuery(this._db.Server, this._db.DatabaseDir, this.dataset));
|
|
32
|
+
if (!result.IsSuccess) {
|
|
33
|
+
throw new Error("Failed to list file packs: " + result.ErrorMessage);
|
|
34
|
+
}
|
|
35
|
+
return result.Result;
|
|
36
|
+
}
|
|
37
|
+
async Add(files) {
|
|
38
|
+
try {
|
|
39
|
+
if (!files) {
|
|
40
|
+
throw new Error("No files provided");
|
|
41
|
+
}
|
|
42
|
+
const formData = new FormData();
|
|
43
|
+
for (let i = 0; i < files.length; i++) {
|
|
44
|
+
formData.append('files[]', files[i]); // Tak, te [] w nazwie zmiennej są konieczne! bez tego php (mimo że odbiera przez $_FILES["files"]) nie jest w stanie odebrać wielu plików xd
|
|
45
|
+
}
|
|
46
|
+
formData.append('server', this._db.Server);
|
|
47
|
+
formData.append('database', this._db.DatabaseDir);
|
|
48
|
+
formData.append('dataset', this.dataset);
|
|
49
|
+
formData.append('userId', this._db.User.Id);
|
|
50
|
+
let serverUrl = this._db.Server;
|
|
51
|
+
if (serverUrl.endsWith("/")) // Because for local env we use ".../src/" but for prod ".../v5"
|
|
52
|
+
{
|
|
53
|
+
serverUrl = serverUrl.slice(0, -1);
|
|
54
|
+
}
|
|
55
|
+
const response = await fetch(serverUrl + "/files-upload", {
|
|
56
|
+
method: 'POST',
|
|
57
|
+
body: formData,
|
|
58
|
+
});
|
|
59
|
+
if (!response.ok) {
|
|
60
|
+
throw new Error(`Request failed with status ${response.status}`);
|
|
61
|
+
}
|
|
62
|
+
// const t = await response.text();
|
|
63
|
+
// console.log(t);
|
|
64
|
+
const result = await response.json();
|
|
65
|
+
if (!result.IsSuccess) {
|
|
66
|
+
throw new Error("Failed to upload files: " + result.ErrorMessage);
|
|
67
|
+
}
|
|
68
|
+
return result.Result ?? [];
|
|
69
|
+
}
|
|
70
|
+
catch (ex) {
|
|
71
|
+
throw new Error(`Can not upload file: ${ex.message}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async Delete(fileId) {
|
|
75
|
+
const result = await this._db.Send(new DeleteFileCommand(this._db.DatabaseDir, this.dataset, fileId));
|
|
76
|
+
if (!result.IsSuccess) {
|
|
77
|
+
throw new Error("Failed to delete file: " + result.ErrorMessage);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { GetFileQuery } from "../../Messages/GetFileQuery";
|
|
6
|
-
import { UpdateFileCommand } from "../../Messages/UpdateFileCommand";
|
|
7
|
-
import { ListFilesIdsQuery } from "../../Messages/ListFilesIdsQuery";
|
|
1
|
+
import { AddObjectCommand } from "../../Messages/AddObjectCommand";
|
|
2
|
+
import { ListObjectsQuery } from "../../Messages/ListObjectsQuery";
|
|
3
|
+
import { UpdateObjectCommand } from "../../Messages/UpdateObjectCommand";
|
|
4
|
+
import { ListObjectsIdsQuery } from '../../Messages/ListObjectsIdsQuery';
|
|
8
5
|
import { DatasetBase } from "../DatasetBase";
|
|
9
6
|
import { DatasetType } from "../../Services/DatasetType";
|
|
10
7
|
import { DummyConverter } from "../../Converters/DummyConverter";
|
|
8
|
+
import { GetObjectQuery } from "../../Messages/GetObjectQuery";
|
|
9
|
+
import { DeleteObjectCommand } from "../../Messages/DeleteObjectCommand";
|
|
11
10
|
export class ObjectDataset extends DatasetBase {
|
|
12
11
|
_db;
|
|
13
12
|
dataset;
|
|
@@ -21,9 +20,9 @@ export class ObjectDataset extends DatasetBase {
|
|
|
21
20
|
}
|
|
22
21
|
async GetOne(id) {
|
|
23
22
|
this.Log(`Fetching "${id}"...`);
|
|
24
|
-
const queryResult = await this._db.Send(new
|
|
23
|
+
const queryResult = await this._db.Send(new GetObjectQuery(this._db.DatabaseDir, this.dataset, id));
|
|
25
24
|
if (!queryResult.IsSuccess) {
|
|
26
|
-
throw new Error("Failed to get one
|
|
25
|
+
throw new Error("Failed to get one object: " + queryResult.ErrorMessage);
|
|
27
26
|
}
|
|
28
27
|
const rawItem = queryResult.Result;
|
|
29
28
|
const item = this._converter.FromRaw(rawItem);
|
|
@@ -32,7 +31,7 @@ export class ObjectDataset extends DatasetBase {
|
|
|
32
31
|
}
|
|
33
32
|
async GetAll() {
|
|
34
33
|
this.Log(`Fetching all from "${this.DatasetPath}"...`);
|
|
35
|
-
const queryResult = await this._db.Send(new
|
|
34
|
+
const queryResult = await this._db.Send(new ListObjectsQuery(this._db.DatabaseDir, this.dataset));
|
|
36
35
|
if (!queryResult.IsSuccess) {
|
|
37
36
|
throw new Error("Failed to fetch all items: " + queryResult.ErrorMessage);
|
|
38
37
|
}
|
|
@@ -42,19 +41,19 @@ export class ObjectDataset extends DatasetBase {
|
|
|
42
41
|
return items;
|
|
43
42
|
}
|
|
44
43
|
async GetAllIds() {
|
|
45
|
-
this.Log(`Fetching all
|
|
46
|
-
const queryResult = await this._db.Send(new
|
|
44
|
+
this.Log(`Fetching all objects IDs from "${this.DatasetPath}"...`);
|
|
45
|
+
const queryResult = await this._db.Send(new ListObjectsIdsQuery(this._db.DatabaseDir, this.dataset));
|
|
47
46
|
if (!queryResult.IsSuccess) {
|
|
48
|
-
throw new Error("Failed to fetch all
|
|
47
|
+
throw new Error("Failed to fetch all objects ids: " + queryResult.ErrorMessage);
|
|
49
48
|
}
|
|
50
49
|
const ids = queryResult.Result;
|
|
51
|
-
this.Log(`Found ${ids.length}
|
|
50
|
+
this.Log(`Found ${ids.length} objects in "${this.DatasetPath}".`);
|
|
52
51
|
return ids;
|
|
53
52
|
}
|
|
54
53
|
async Add(id, item) {
|
|
55
54
|
this.Log(`Adding "${id}" to "${this.DatasetPath}"...`);
|
|
56
55
|
const rawItem = this._converter.ToRaw(item);
|
|
57
|
-
const result = await this._db.Send(new
|
|
56
|
+
const result = await this._db.Send(new AddObjectCommand(this._db.DatabaseDir, this.dataset, id, rawItem));
|
|
58
57
|
if (!result.IsSuccess) {
|
|
59
58
|
throw new Error("Failed to add item: " + result.ErrorMessage);
|
|
60
59
|
}
|
|
@@ -64,7 +63,7 @@ export class ObjectDataset extends DatasetBase {
|
|
|
64
63
|
async Update(id, item) {
|
|
65
64
|
this.Log(`Updating "${id}"...`);
|
|
66
65
|
const rawItem = this._converter.ToRaw(item);
|
|
67
|
-
const result = await this._db.Send(new
|
|
66
|
+
const result = await this._db.Send(new UpdateObjectCommand(this._db.DatabaseDir, this.dataset, id, rawItem));
|
|
68
67
|
if (!result.IsSuccess) {
|
|
69
68
|
throw new Error("Failed to update item: " + result.ErrorMessage);
|
|
70
69
|
}
|
|
@@ -73,18 +72,10 @@ export class ObjectDataset extends DatasetBase {
|
|
|
73
72
|
;
|
|
74
73
|
async Delete(id) {
|
|
75
74
|
this.Log(`Deleting "${id}" from "${this.DatasetPath}"...`);
|
|
76
|
-
const result = await this._db.Send(new
|
|
75
|
+
const result = await this._db.Send(new DeleteObjectCommand(this._db.DatabaseDir, this.dataset, id));
|
|
77
76
|
if (!result.IsSuccess) {
|
|
78
|
-
throw new Error("Failed to delete
|
|
77
|
+
throw new Error("Failed to delete object: " + result.ErrorMessage);
|
|
79
78
|
}
|
|
80
79
|
this.Log(`Deleted "${id}" from "${this.DatasetPath}".`);
|
|
81
80
|
}
|
|
82
|
-
async Drop() {
|
|
83
|
-
this.Log(`Dropping "${this.DatasetPath}"...`);
|
|
84
|
-
const result = await this._db.Send(new DropDatasetCommand(this._db.DatabaseDir, this.dataset));
|
|
85
|
-
if (!result.IsSuccess) {
|
|
86
|
-
throw new Error("Failed to drop dataset: " + result.ErrorMessage);
|
|
87
|
-
}
|
|
88
|
-
this.Log(`"${this.DatasetPath}" dropped.`);
|
|
89
|
-
}
|
|
90
81
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { OnlineStorage } from "../../Services/OnlineStorage";
|
|
2
2
|
import { dir } from "../../Types/dir";
|
|
3
3
|
import { DatasetBase } from "../DatasetBase";
|
|
4
|
-
import { PicturesUploadResult } from "./PicturesUploadResult";
|
|
5
4
|
import { PicsConfig } from "./PicsConfig";
|
|
6
5
|
import { PicturePack } from "./PicturePack";
|
|
7
6
|
import { DatasetType } from "../../Services/DatasetType";
|
|
@@ -16,7 +15,6 @@ export declare class PicturesDataset extends DatasetBase {
|
|
|
16
15
|
GetAllIds(): Promise<string[]>;
|
|
17
16
|
GetOne(pictureDir: string): Promise<PicturePack>;
|
|
18
17
|
GetAll(): Promise<PicturePack[]>;
|
|
19
|
-
Add(files: File[]): Promise<
|
|
18
|
+
Add(files: File[]): Promise<PicturePack[]>;
|
|
20
19
|
Delete(pictureDir: string): Promise<void>;
|
|
21
|
-
Drop(): Promise<void>;
|
|
22
20
|
}
|
|
@@ -2,11 +2,9 @@ import { DeletePictureCommand } from "../../Messages/DeletePictureCommand";
|
|
|
2
2
|
import { ListPicturesQuery } from "../../Messages/ListPicturesQuery";
|
|
3
3
|
import { DatasetBase } from "../DatasetBase";
|
|
4
4
|
import { DefaultPicsConfig } from "./DefaultPicsConfig";
|
|
5
|
-
import { PicturesUploadResult } from "./PicturesUploadResult";
|
|
6
5
|
import { DatasetType } from "../../Services/DatasetType";
|
|
7
6
|
import { ListPicturesIdsQuery } from "../../Messages/ListPicturesIdsQuery";
|
|
8
7
|
import { GetPictureQuery } from "../../Messages/GetPictureQuery";
|
|
9
|
-
import { DropPicturesCommand } from "../../Messages/DropPicturesCommand";
|
|
10
8
|
export class PicturesDataset extends DatasetBase {
|
|
11
9
|
_db;
|
|
12
10
|
dataset;
|
|
@@ -39,7 +37,7 @@ export class PicturesDataset extends DatasetBase {
|
|
|
39
37
|
return result.Result;
|
|
40
38
|
}
|
|
41
39
|
async GetAll() {
|
|
42
|
-
const result = await this._db.Send(new ListPicturesQuery(this._db.DatabaseDir, this.dataset));
|
|
40
|
+
const result = await this._db.Send(new ListPicturesQuery(this._db.Server, this._db.DatabaseDir, this.dataset));
|
|
43
41
|
if (!result.IsSuccess) {
|
|
44
42
|
throw new Error("Failed to list picture packs: " + result.ErrorMessage);
|
|
45
43
|
}
|
|
@@ -48,7 +46,7 @@ export class PicturesDataset extends DatasetBase {
|
|
|
48
46
|
async Add(files) {
|
|
49
47
|
try {
|
|
50
48
|
if (!files) {
|
|
51
|
-
|
|
49
|
+
throw new Error("No files provided");
|
|
52
50
|
}
|
|
53
51
|
const formData = new FormData();
|
|
54
52
|
for (let i = 0; i < files.length; i++) {
|
|
@@ -69,13 +67,16 @@ export class PicturesDataset extends DatasetBase {
|
|
|
69
67
|
body: formData,
|
|
70
68
|
});
|
|
71
69
|
if (!response.ok) {
|
|
72
|
-
|
|
70
|
+
throw new Error(`Request failed with status ${response.status}`);
|
|
73
71
|
}
|
|
74
|
-
const
|
|
75
|
-
|
|
72
|
+
const result = await response.json();
|
|
73
|
+
if (!result.IsSuccess) {
|
|
74
|
+
throw new Error("Failed to upload pictures: " + result.ErrorMessage);
|
|
75
|
+
}
|
|
76
|
+
return result.Result ?? [];
|
|
76
77
|
}
|
|
77
78
|
catch (ex) {
|
|
78
|
-
|
|
79
|
+
throw new Error(`Can not upload: ${ex.message}`);
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
async Delete(pictureDir) {
|
|
@@ -84,10 +85,4 @@ export class PicturesDataset extends DatasetBase {
|
|
|
84
85
|
throw new Error("Failed to delete picture: " + result.ErrorMessage);
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
|
-
async Drop() {
|
|
88
|
-
const result = await this._db.Send(new DropPicturesCommand(this._db.DatabaseDir, this.dataset));
|
|
89
|
-
if (!result.IsSuccess) {
|
|
90
|
-
throw new Error("Failed to drop pictures: " + result.ErrorMessage);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
88
|
}
|
|
@@ -5,6 +5,8 @@ export interface ITextRepo extends IRepoBase {
|
|
|
5
5
|
GetAllIds(): Promise<string[]>;
|
|
6
6
|
AppendText(id: string, text: string): Promise<void>;
|
|
7
7
|
AppendLine(id: string, line: string): Promise<void>;
|
|
8
|
+
Clear(id: string): Promise<void>;
|
|
9
|
+
ReplaceText(id: string, text: string): Promise<void>;
|
|
8
10
|
Delete(id: string): Promise<void>;
|
|
9
11
|
Drop(): Promise<void>;
|
|
10
12
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { DatasetBase } from "../DatasetBase";
|
|
2
|
-
import {
|
|
2
|
+
import { AppendTextCommand } from "../../Messages/AppendTextCommand";
|
|
3
3
|
import { ClearCommand } from "../../Messages/ClearCommand";
|
|
4
4
|
import { CreateFileCommand } from "../../Messages/CreateFileCommand";
|
|
5
5
|
import { DeleteFileCommand } from "../../Messages/DeleteFileCommand";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { ReadFileQuery } from "../../Messages/ReadFileQuery";
|
|
6
|
+
import { ListObjectsIdsQuery } from '../../Messages/ListObjectsIdsQuery';
|
|
7
|
+
import { ReadTextQuery } from "../../Messages/ReadTextQuery";
|
|
9
8
|
import { DatasetType } from "../../Services/DatasetType";
|
|
10
9
|
export class RawTextDataset extends DatasetBase {
|
|
11
10
|
_db;
|
|
@@ -21,7 +20,7 @@ export class RawTextDataset extends DatasetBase {
|
|
|
21
20
|
if (limit < 0) {
|
|
22
21
|
throw new Error("Limit cannot be negative number. 0 = no limit.");
|
|
23
22
|
}
|
|
24
|
-
const queryResult = await this._db.Send(new
|
|
23
|
+
const queryResult = await this._db.Send(new ReadTextQuery(this._db.DatabaseDir, this.dataset, id, offset, limit));
|
|
25
24
|
if (!queryResult.IsSuccess) {
|
|
26
25
|
throw new Error("Failed to read: " + queryResult.ErrorMessage);
|
|
27
26
|
}
|
|
@@ -31,7 +30,7 @@ export class RawTextDataset extends DatasetBase {
|
|
|
31
30
|
}
|
|
32
31
|
async GetAllIds() {
|
|
33
32
|
this.Log(`Fetching all files IDs from "${this.DatasetPath}"...`);
|
|
34
|
-
const queryResult = await this._db.Send(new
|
|
33
|
+
const queryResult = await this._db.Send(new ListObjectsIdsQuery(this._db.DatabaseDir, this.dataset));
|
|
35
34
|
if (!queryResult.IsSuccess) {
|
|
36
35
|
throw new Error("Failed to fetch all items ids: " + queryResult.ErrorMessage);
|
|
37
36
|
}
|
|
@@ -50,7 +49,7 @@ export class RawTextDataset extends DatasetBase {
|
|
|
50
49
|
;
|
|
51
50
|
async AppendText(id, text) {
|
|
52
51
|
this.Log(`Appending ${text.length} characters to "${id}" in "${this.DatasetPath}"...`);
|
|
53
|
-
const result = await this._db.Send(new
|
|
52
|
+
const result = await this._db.Send(new AppendTextCommand(this._db.DatabaseDir, this.dataset, id, text));
|
|
54
53
|
if (!result.IsSuccess) {
|
|
55
54
|
throw new Error("Failed to append: " + result.ErrorMessage);
|
|
56
55
|
}
|
|
@@ -84,12 +83,4 @@ export class RawTextDataset extends DatasetBase {
|
|
|
84
83
|
}
|
|
85
84
|
this.Log(`Deleted "${id}" from "${this.DatasetPath}".`);
|
|
86
85
|
}
|
|
87
|
-
async Drop() {
|
|
88
|
-
this.Log(`Dropping "${this.DatasetPath}"...`);
|
|
89
|
-
const result = await this._db.Send(new DropDatasetCommand(this._db.DatabaseDir, this.dataset));
|
|
90
|
-
if (!result.IsSuccess) {
|
|
91
|
-
throw new Error("Failed to drop dataset: " + result.ErrorMessage);
|
|
92
|
-
}
|
|
93
|
-
this.Log(`"${this.DatasetPath}" dropped.`);
|
|
94
|
-
}
|
|
95
86
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class UploadResult<T extends object> {
|
|
2
|
+
IsSuccess: boolean;
|
|
3
|
+
Result: T | null;
|
|
4
|
+
ErrorMessage: string;
|
|
5
|
+
constructor(IsSuccess?: boolean, Result?: T | null, ErrorMessage?: string);
|
|
6
|
+
static Success<T extends object>(result: T): UploadResult<T>;
|
|
7
|
+
static Failure<T extends object>(reason: string): UploadResult<T>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export class UploadResult {
|
|
2
|
+
IsSuccess;
|
|
3
|
+
Result;
|
|
4
|
+
ErrorMessage;
|
|
5
|
+
constructor(IsSuccess = false, Result = null, ErrorMessage = "") {
|
|
6
|
+
this.IsSuccess = IsSuccess;
|
|
7
|
+
this.Result = Result;
|
|
8
|
+
this.ErrorMessage = ErrorMessage;
|
|
9
|
+
}
|
|
10
|
+
static Success(result) {
|
|
11
|
+
return new UploadResult(true, result, "");
|
|
12
|
+
}
|
|
13
|
+
static Failure(reason) {
|
|
14
|
+
return new UploadResult(false, null, reason);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Message } from '../MessageBus/Message';
|
|
2
2
|
import { dir } from '../Types/dir';
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class AppendTextCommand extends Message {
|
|
4
4
|
constructor(Database: dir, Dataset: dir, FileId: string, Content: string);
|
|
5
5
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Message } from '../MessageBus/Message';
|
|
2
|
-
export class
|
|
2
|
+
export class AppendTextCommand extends Message {
|
|
3
3
|
constructor(Database, Dataset, FileId, Content) {
|
|
4
|
-
super("
|
|
4
|
+
super("AppendText", { Database, Dataset, FileId, Content });
|
|
5
5
|
}
|
|
6
6
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Message } from '../MessageBus/Message';
|
|
2
2
|
import { dir } from '../Types/dir';
|
|
3
3
|
export declare class GetFileQuery extends Message {
|
|
4
|
-
constructor(Database: dir, Dataset: dir, FileId: string);
|
|
4
|
+
constructor(Server: string, Database: dir, Dataset: dir, FileId: string);
|
|
5
5
|
}
|
package/Messages/GetFileQuery.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Message } from '../MessageBus/Message';
|
|
2
2
|
export class GetFileQuery extends Message {
|
|
3
|
-
constructor(Database, Dataset, FileId) {
|
|
4
|
-
super("GetFile", { Database, Dataset, FileId });
|
|
3
|
+
constructor(Server, Database, Dataset, FileId) {
|
|
4
|
+
super("GetFile", { Server, Database, Dataset, FileId });
|
|
5
5
|
}
|
|
6
6
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Message } from '../MessageBus/Message';
|
|
2
2
|
export class ListFilesQuery extends Message {
|
|
3
|
-
constructor(Database, Dataset) {
|
|
4
|
-
super("ListFiles", { Database, Dataset });
|
|
3
|
+
constructor(Server, Database, Dataset) {
|
|
4
|
+
super("ListFiles", { Server, Database, Dataset });
|
|
5
5
|
}
|
|
6
6
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Message } from '../MessageBus/Message';
|
|
2
2
|
export class ListPicturesQuery extends Message {
|
|
3
|
-
constructor(Database, Dataset) {
|
|
4
|
-
super("ListPictures", { Database, Dataset });
|
|
3
|
+
constructor(Server, Database, Dataset) {
|
|
4
|
+
super("ListPictures", { Server, Database, Dataset });
|
|
5
5
|
}
|
|
6
6
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Message } from '../MessageBus/Message';
|
|
2
2
|
import { dir } from '../Types/dir';
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class ReadTextQuery extends Message {
|
|
4
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
|
-
export class
|
|
2
|
+
export class ReadTextQuery extends Message {
|
|
3
3
|
constructor(Database, Dataset, FileId, Offset = 0, Limit = 0) {
|
|
4
|
-
super("
|
|
4
|
+
super("ReadText", { Database, Dataset, FileId, Offset, Limit });
|
|
5
5
|
}
|
|
6
6
|
}
|
package/Services/DatasetType.js
CHANGED
|
@@ -15,6 +15,7 @@ import { ITextConverter } from "../Converters/ITextConverter";
|
|
|
15
15
|
import { DatasetType } from "./DatasetType";
|
|
16
16
|
import { PicturesDataset } from "../Datasets/Picture/PicturesDataset";
|
|
17
17
|
import { PicsConfig } from "../Datasets/Picture/PicsConfig";
|
|
18
|
+
import { FileDataset } from "../Datasets/File/FileDataset";
|
|
18
19
|
export declare class OnlineStorage {
|
|
19
20
|
private server;
|
|
20
21
|
private database;
|
|
@@ -40,7 +41,8 @@ export declare class OnlineStorage {
|
|
|
40
41
|
DeleteUser(user: IStorageUser): Promise<void>;
|
|
41
42
|
GetObjectDataset<T extends object>(datasetName: string, converter?: IConverter<any, T>): ObjectDataset<T>;
|
|
42
43
|
GetTextDataset(datasetName: string, converter?: ITextConverter<any>): TextDataset<any> | RawTextDataset;
|
|
43
|
-
|
|
44
|
+
GetPictureDataset(datasetName: string, picsConfig?: PicsConfig): PicturesDataset;
|
|
45
|
+
GetFileDataset(datasetName: string): FileDataset;
|
|
44
46
|
private IsBrowserEnvironment;
|
|
45
47
|
private LoadUserFromLocalStorage;
|
|
46
48
|
Login(password: string, login?: string): Promise<IStorageUser>;
|
|
@@ -3,7 +3,7 @@ import { CreateDatasetCommand } from '../Messages/CreateDatasetCommand';
|
|
|
3
3
|
import { DatasetExistsCommand } from '../Messages/DatasetExistsCommand';
|
|
4
4
|
import { RemoveDatasetCommand } from '../Messages/RemoveDatasetCommand';
|
|
5
5
|
import { ObjectDataset } from "../Datasets/Object/ObjectDataset";
|
|
6
|
-
import {
|
|
6
|
+
import { MoveObjectCommand } from "../Messages/MoveObjectCommand";
|
|
7
7
|
import { LoginUserQuery } from "../Messages/LoginUserQuery";
|
|
8
8
|
import { ListUsersQuery } from "../Messages/ListUsersQuery";
|
|
9
9
|
import { UpdateUserCommand } from "../Messages/UpdateUserCommand";
|
|
@@ -19,6 +19,7 @@ import { DeleteDatabaseCommand } from "../Messages/DeleteDatabaseCommand";
|
|
|
19
19
|
import { RawTextDataset } from "../Datasets/Text/RawTextDataset";
|
|
20
20
|
import { TextDataset } from "../Datasets/Text/TextDataset";
|
|
21
21
|
import { PicturesDataset } from "../Datasets/Picture/PicturesDataset";
|
|
22
|
+
import { FileDataset } from "../Datasets/File/FileDataset";
|
|
22
23
|
export class OnlineStorage {
|
|
23
24
|
server;
|
|
24
25
|
database;
|
|
@@ -115,9 +116,12 @@ export class OnlineStorage {
|
|
|
115
116
|
? new TextDataset(this, datasetName, converter)
|
|
116
117
|
: new RawTextDataset(this, datasetName);
|
|
117
118
|
}
|
|
118
|
-
|
|
119
|
+
GetPictureDataset(datasetName, picsConfig) {
|
|
119
120
|
return new PicturesDataset(this, datasetName, picsConfig);
|
|
120
121
|
}
|
|
122
|
+
GetFileDataset(datasetName) {
|
|
123
|
+
return new FileDataset(this, datasetName);
|
|
124
|
+
}
|
|
121
125
|
IsBrowserEnvironment() {
|
|
122
126
|
return typeof window !== "undefined" && typeof window.localStorage !== "undefined";
|
|
123
127
|
}
|
|
@@ -135,7 +139,7 @@ export class OnlineStorage {
|
|
|
135
139
|
async Login(password, login) {
|
|
136
140
|
const result = await this._bus.SendMessage(new LoginUserQuery(this.DatabaseDir, password, login));
|
|
137
141
|
if (!result.IsSuccess) {
|
|
138
|
-
throw new Error(result.ErrorMessage);
|
|
142
|
+
throw new Error("Failed to login: " + result.ErrorMessage);
|
|
139
143
|
}
|
|
140
144
|
this.user = result.Result || this.ANONYMOUS_USER;
|
|
141
145
|
this.SetUser(this.user);
|
|
@@ -242,7 +246,7 @@ export class OnlineStorage {
|
|
|
242
246
|
}
|
|
243
247
|
async Move(fileId, sourceDataset, targetDataset) {
|
|
244
248
|
this.Log(`Moving "${fileId}" from "${sourceDataset.Name}" to "${targetDataset.Name}"...`);
|
|
245
|
-
const result = await this._bus.SendMessage(new
|
|
249
|
+
const result = await this._bus.SendMessage(new MoveObjectCommand(this.DatabaseDir, fileId, sourceDataset.Name, targetDataset.Name));
|
|
246
250
|
if (!result.IsSuccess) {
|
|
247
251
|
throw new Error(`Failed to move "${fileId}" from "${sourceDataset.Name}" to "${targetDataset.Name}": ${result.ErrorMessage}`);
|
|
248
252
|
}
|
package/index.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export * from "./Datasets/IRepoBase";
|
|
|
13
13
|
export * from "./Datasets/Object/IRepo";
|
|
14
14
|
export * from "./Datasets/Text/ITextRepo";
|
|
15
15
|
export * from "./Datasets/Object/IRepos";
|
|
16
|
+
export * from "./Datasets/File/FileDataset";
|
|
17
|
+
export * from "./Datasets/File/FilePack";
|
|
16
18
|
export * from "./Datasets/DatasetBase";
|
|
17
19
|
export * from "./Datasets/Object/ObjectDataset";
|
|
18
20
|
export * from "./Datasets/Text/RawTextDataset";
|
|
@@ -21,6 +23,5 @@ export * from "./Datasets/Picture/PicturesDataset";
|
|
|
21
23
|
export * from "./Datasets/Picture/PicConfig";
|
|
22
24
|
export * from "./Datasets/Picture/PicsConfig";
|
|
23
25
|
export * from "./Datasets/Picture/PicturePack";
|
|
24
|
-
export * from "./Datasets/Picture/PicturesUploadResult";
|
|
25
26
|
export * from "./Services/DatasetType";
|
|
26
27
|
export * from "./Services/OnlineStorage";
|
package/index.js
CHANGED
|
@@ -13,6 +13,8 @@ export * from "./Datasets/IRepoBase";
|
|
|
13
13
|
export * from "./Datasets/Object/IRepo";
|
|
14
14
|
export * from "./Datasets/Text/ITextRepo";
|
|
15
15
|
export * from "./Datasets/Object/IRepos";
|
|
16
|
+
export * from "./Datasets/File/FileDataset";
|
|
17
|
+
export * from "./Datasets/File/FilePack";
|
|
16
18
|
export * from "./Datasets/DatasetBase";
|
|
17
19
|
export * from "./Datasets/Object/ObjectDataset";
|
|
18
20
|
export * from "./Datasets/Text/RawTextDataset";
|
|
@@ -21,6 +23,5 @@ export * from "./Datasets/Picture/PicturesDataset";
|
|
|
21
23
|
export * from "./Datasets/Picture/PicConfig";
|
|
22
24
|
export * from "./Datasets/Picture/PicsConfig";
|
|
23
25
|
export * from "./Datasets/Picture/PicturePack";
|
|
24
|
-
export * from "./Datasets/Picture/PicturesUploadResult";
|
|
25
26
|
export * from "./Services/DatasetType";
|
|
26
27
|
export * from "./Services/OnlineStorage";
|
package/package.json
CHANGED
|
Binary file
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { PicturePack } from "./PicturePack";
|
|
2
|
-
export declare class PicturesUploadResult {
|
|
3
|
-
IsSuccess: boolean;
|
|
4
|
-
PicturePacks: PicturePack[] | null;
|
|
5
|
-
ErrorMessage: string;
|
|
6
|
-
constructor(IsSuccess?: boolean, PicturePacks?: PicturePack[] | null, ErrorMessage?: string);
|
|
7
|
-
static Success(packs: PicturePack[]): PicturesUploadResult;
|
|
8
|
-
static Failure(reason: string): PicturesUploadResult;
|
|
9
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export class PicturesUploadResult {
|
|
2
|
-
IsSuccess;
|
|
3
|
-
PicturePacks;
|
|
4
|
-
ErrorMessage;
|
|
5
|
-
constructor(IsSuccess = false, PicturePacks = null, ErrorMessage = "") {
|
|
6
|
-
this.IsSuccess = IsSuccess;
|
|
7
|
-
this.PicturePacks = PicturePacks;
|
|
8
|
-
this.ErrorMessage = ErrorMessage;
|
|
9
|
-
}
|
|
10
|
-
static Success(packs) {
|
|
11
|
-
return new PicturesUploadResult(true, packs, "");
|
|
12
|
-
}
|
|
13
|
-
static Failure(reason) {
|
|
14
|
-
return new PicturesUploadResult(false, null, reason);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
Binary file
|