@neuralinnovations/dataisland-sdk 0.0.1-dev74 → 0.0.1-dev75
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/README.md +5 -0
- package/dist/package.json +1 -1
- package/dist/src/commands/startCommandHandler.d.ts.map +1 -1
- package/dist/src/commands/startCommandHandler.js +3 -0
- package/dist/src/commands/startCommandHandler.js.map +1 -1
- package/dist/src/dataIslandApp.d.ts +5 -0
- package/dist/src/dataIslandApp.d.ts.map +1 -1
- package/dist/src/dataIslandApp.js.map +1 -1
- package/dist/src/dto/chatResponse.d.ts +18 -3
- package/dist/src/dto/chatResponse.d.ts.map +1 -1
- package/dist/src/dto/chatResponse.js +12 -1
- package/dist/src/dto/chatResponse.js.map +1 -1
- package/dist/src/dto/libraryResponse.d.ts +41 -0
- package/dist/src/dto/libraryResponse.d.ts.map +1 -0
- package/dist/src/dto/libraryResponse.js +3 -0
- package/dist/src/dto/libraryResponse.js.map +1 -0
- package/dist/src/dto/workspacesResponse.d.ts +1 -0
- package/dist/src/dto/workspacesResponse.d.ts.map +1 -1
- package/dist/src/dto/workspacesResponse.js.map +1 -1
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/internal/app.impl.d.ts +2 -0
- package/dist/src/internal/app.impl.d.ts.map +1 -1
- package/dist/src/internal/app.impl.js +7 -0
- package/dist/src/internal/app.impl.js.map +1 -1
- package/dist/src/services/acquiringService.d.ts.map +1 -1
- package/dist/src/services/acquiringService.js +2 -2
- package/dist/src/services/acquiringService.js.map +1 -1
- package/dist/src/services/librariesService.d.ts +9 -0
- package/dist/src/services/librariesService.d.ts.map +1 -0
- package/dist/src/services/librariesService.js +19 -0
- package/dist/src/services/librariesService.js.map +1 -0
- package/dist/src/storages/chats/chat.d.ts +3 -6
- package/dist/src/storages/chats/chat.d.ts.map +1 -1
- package/dist/src/storages/chats/chat.impl.d.ts +2 -3
- package/dist/src/storages/chats/chat.impl.d.ts.map +1 -1
- package/dist/src/storages/chats/chat.impl.js +2 -6
- package/dist/src/storages/chats/chat.impl.js.map +1 -1
- package/dist/src/storages/chats/chat.js.map +1 -1
- package/dist/src/storages/chats/chats.d.ts +12 -0
- package/dist/src/storages/chats/chats.d.ts.map +1 -1
- package/dist/src/storages/chats/chats.impl.d.ts +2 -0
- package/dist/src/storages/chats/chats.impl.d.ts.map +1 -1
- package/dist/src/storages/chats/chats.impl.js +68 -0
- package/dist/src/storages/chats/chats.impl.js.map +1 -1
- package/dist/src/storages/chats/chats.js.map +1 -1
- package/dist/src/storages/library/libraries.d.ts +12 -0
- package/dist/src/storages/library/libraries.d.ts.map +1 -0
- package/dist/src/storages/library/libraries.impl.d.ts +18 -0
- package/dist/src/storages/library/libraries.impl.d.ts.map +1 -0
- package/dist/src/storages/library/libraries.impl.js +134 -0
- package/dist/src/storages/library/libraries.impl.js.map +1 -0
- package/dist/src/storages/library/libraries.js +7 -0
- package/dist/src/storages/library/libraries.js.map +1 -0
- package/dist/src/storages/library/library.d.ts +10 -0
- package/dist/src/storages/library/library.d.ts.map +1 -0
- package/dist/src/storages/library/library.impl.d.ts +17 -0
- package/dist/src/storages/library/library.impl.d.ts.map +1 -0
- package/dist/src/storages/library/library.impl.js +98 -0
- package/dist/src/storages/library/library.impl.js.map +1 -0
- package/dist/src/storages/library/library.js +7 -0
- package/dist/src/storages/library/library.js.map +1 -0
- package/dist/src/storages/library/libraryFolder.d.ts +16 -0
- package/dist/src/storages/library/libraryFolder.d.ts.map +1 -0
- package/dist/src/storages/library/libraryFolder.impl.d.ts +22 -0
- package/dist/src/storages/library/libraryFolder.impl.d.ts.map +1 -0
- package/dist/src/storages/library/libraryFolder.impl.js +97 -0
- package/dist/src/storages/library/libraryFolder.impl.js.map +1 -0
- package/dist/src/storages/library/libraryFolder.js +7 -0
- package/dist/src/storages/library/libraryFolder.js.map +1 -0
- package/dist/src/storages/library/libraryPage.d.ts +29 -0
- package/dist/src/storages/library/libraryPage.d.ts.map +1 -0
- package/dist/src/storages/library/libraryPage.impl.d.ts +13 -0
- package/dist/src/storages/library/libraryPage.impl.d.ts.map +1 -0
- package/dist/src/storages/library/libraryPage.impl.js +20 -0
- package/dist/src/storages/library/libraryPage.impl.js.map +1 -0
- package/dist/src/storages/library/libraryPage.js +7 -0
- package/dist/src/storages/library/libraryPage.js.map +1 -0
- package/dist/src/storages/workspaces/workspace.d.ts +6 -0
- package/dist/src/storages/workspaces/workspace.d.ts.map +1 -1
- package/dist/src/storages/workspaces/workspace.impl.d.ts +2 -0
- package/dist/src/storages/workspaces/workspace.impl.d.ts.map +1 -1
- package/dist/src/storages/workspaces/workspace.impl.js +36 -0
- package/dist/src/storages/workspaces/workspace.impl.js.map +1 -1
- package/dist/src/storages/workspaces/workspace.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/startCommandHandler.ts +3 -0
- package/src/dataIslandApp.ts +6 -0
- package/src/dto/chatResponse.ts +21 -3
- package/src/dto/libraryResponse.ts +49 -0
- package/src/dto/workspacesResponse.ts +1 -0
- package/src/index.ts +4 -0
- package/src/internal/app.impl.ts +9 -0
- package/src/services/acquiringService.ts +2 -2
- package/src/services/librariesService.ts +22 -0
- package/src/storages/chats/chat.impl.ts +3 -7
- package/src/storages/chats/chat.ts +3 -7
- package/src/storages/chats/chats.impl.ts +92 -0
- package/src/storages/chats/chats.ts +14 -0
- package/src/storages/library/libraries.impl.ts +192 -0
- package/src/storages/library/libraries.ts +20 -0
- package/src/storages/library/library.impl.ts +150 -0
- package/src/storages/library/library.ts +16 -0
- package/src/storages/library/libraryFolder.impl.ts +136 -0
- package/src/storages/library/libraryFolder.ts +25 -0
- package/src/storages/library/libraryPage.impl.ts +23 -0
- package/src/storages/library/libraryPage.ts +37 -0
- package/src/storages/workspaces/workspace.impl.ts +43 -0
- package/src/storages/workspaces/workspace.ts +8 -0
@@ -0,0 +1,192 @@
|
|
1
|
+
import {Libraries} from "./libraries"
|
2
|
+
import {Library, LibraryId} from "./library"
|
3
|
+
import {LibraryImpl} from "./library.impl"
|
4
|
+
import {Context} from "../../context"
|
5
|
+
import {
|
6
|
+
CreateLibraryResponse,
|
7
|
+
LibrariesResponse, LibraryDto, LibraryResponse
|
8
|
+
} from "../../dto/libraryResponse"
|
9
|
+
import {RpcService} from "../../services/rpcService"
|
10
|
+
import {ResponseUtils} from "../../services/responseUtils"
|
11
|
+
import {OrganizationId} from "../organizations/organizations"
|
12
|
+
|
13
|
+
|
14
|
+
export class LibrariesImpl extends Libraries {
|
15
|
+
private readonly _libraries: LibraryImpl[] = []
|
16
|
+
|
17
|
+
constructor(
|
18
|
+
private readonly context: Context
|
19
|
+
) {
|
20
|
+
super()
|
21
|
+
}
|
22
|
+
|
23
|
+
async initialize(){
|
24
|
+
// fetch limits
|
25
|
+
const response = await this.context.resolve(RpcService)
|
26
|
+
?.requestBuilder("api/v1/libraries")
|
27
|
+
.sendGet()
|
28
|
+
|
29
|
+
// check response status
|
30
|
+
if (ResponseUtils.isFail(response)) {
|
31
|
+
await ResponseUtils.throwError("Failed to get libraries", response)
|
32
|
+
}
|
33
|
+
|
34
|
+
const json = await response!.json()
|
35
|
+
|
36
|
+
// parse limits from the server's response
|
37
|
+
const libraries = (json as LibrariesResponse).libraries
|
38
|
+
|
39
|
+
for (const library of libraries){
|
40
|
+
const impl = new LibraryImpl(this.context)
|
41
|
+
await impl.initFrom(library)
|
42
|
+
this._libraries.push(impl)
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
|
47
|
+
get collection(): readonly Library[] {
|
48
|
+
return this._libraries
|
49
|
+
}
|
50
|
+
|
51
|
+
async createLibrary(name: string, region: number, isPublic: boolean): Promise<LibraryId>{
|
52
|
+
if (
|
53
|
+
name === undefined ||
|
54
|
+
name === null ||
|
55
|
+
name.trim() === ""
|
56
|
+
) {
|
57
|
+
throw new Error("Name for library is required, must be not empty")
|
58
|
+
}
|
59
|
+
|
60
|
+
if (
|
61
|
+
isPublic === undefined ||
|
62
|
+
isPublic === null
|
63
|
+
) {
|
64
|
+
throw new Error("IsPublic is required, must be not empty")
|
65
|
+
}
|
66
|
+
|
67
|
+
// send create request to the server
|
68
|
+
const response = await this.context
|
69
|
+
.resolve(RpcService)
|
70
|
+
?.requestBuilder("api/v1/libraries/management")
|
71
|
+
.sendPostJson({
|
72
|
+
name: name,
|
73
|
+
region: region,
|
74
|
+
isPublic: isPublic
|
75
|
+
})
|
76
|
+
|
77
|
+
// check response status
|
78
|
+
if (ResponseUtils.isFail(response)) {
|
79
|
+
await ResponseUtils.throwError(`Failed to create library ${name}`, response)
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
const library = (await response!.json()) as CreateLibraryResponse
|
84
|
+
|
85
|
+
return library.libraryId
|
86
|
+
}
|
87
|
+
|
88
|
+
async addOrgToLibrary(libraryId: LibraryId, organizationId: OrganizationId): Promise<void>{
|
89
|
+
if (libraryId === undefined || libraryId === null) {
|
90
|
+
throw new Error("Organization add to library, libraryId is undefined or null")
|
91
|
+
}
|
92
|
+
if (libraryId.length === 0 || libraryId.trim().length === 0) {
|
93
|
+
throw new Error("Organization add to from library, libraryId is empty")
|
94
|
+
}
|
95
|
+
if (organizationId === undefined || organizationId === null) {
|
96
|
+
throw new Error("Organization add to from library, organizationId is undefined or null")
|
97
|
+
}
|
98
|
+
if (organizationId.length === 0 || organizationId.trim().length === 0) {
|
99
|
+
throw new Error("Organization add to from library, organizationId is empty")
|
100
|
+
}
|
101
|
+
|
102
|
+
const response = await this.context
|
103
|
+
.resolve(RpcService)
|
104
|
+
?.requestBuilder("api/v1/libraries/management/allowed/organization")
|
105
|
+
.sendPutJson({
|
106
|
+
libraryId: libraryId,
|
107
|
+
organizationId: organizationId
|
108
|
+
})
|
109
|
+
if (ResponseUtils.isFail(response)) {
|
110
|
+
await ResponseUtils.throwError(
|
111
|
+
`Organization ${organizationId} add to library ${libraryId} failed`,
|
112
|
+
response
|
113
|
+
)
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
async getLibraries(): Promise<LibraryDto[]>{
|
118
|
+
const response = await this.context
|
119
|
+
.resolve(RpcService)
|
120
|
+
?.requestBuilder("api/v1/libraries/management/allowed/organizations")
|
121
|
+
.sendGet()
|
122
|
+
|
123
|
+
// check response status
|
124
|
+
if (ResponseUtils.isFail(response)) {
|
125
|
+
await ResponseUtils.throwError(
|
126
|
+
"Can not get libraries",
|
127
|
+
response
|
128
|
+
)
|
129
|
+
}
|
130
|
+
|
131
|
+
// parse libraries from the server's response
|
132
|
+
const libraries = (await response!.json()) as LibraryResponse
|
133
|
+
|
134
|
+
return libraries.libraries
|
135
|
+
}
|
136
|
+
|
137
|
+
async deleteOrgFromLibrary(libraryId: LibraryId, organizationId: OrganizationId): Promise<void>{
|
138
|
+
if (libraryId === undefined || libraryId === null) {
|
139
|
+
throw new Error("Organization delete from library, libraryId is undefined or null")
|
140
|
+
}
|
141
|
+
if (libraryId.length === 0 || libraryId.trim().length === 0) {
|
142
|
+
throw new Error("Organization delete from library, libraryId is empty")
|
143
|
+
}
|
144
|
+
if (organizationId === undefined || organizationId === null) {
|
145
|
+
throw new Error("Organization delete from library, organizationId is undefined or null")
|
146
|
+
}
|
147
|
+
if (organizationId.length === 0 || organizationId.trim().length === 0) {
|
148
|
+
throw new Error("Organization delete from library, organizationId is empty")
|
149
|
+
}
|
150
|
+
|
151
|
+
// send request to the server
|
152
|
+
const response = await this.context
|
153
|
+
.resolve(RpcService)
|
154
|
+
?.requestBuilder("api/v1/libraries/management/allowed/organization")
|
155
|
+
.searchParam("libraryId", libraryId)
|
156
|
+
.searchParam("organizationId", organizationId)
|
157
|
+
.sendDelete()
|
158
|
+
|
159
|
+
// check response status
|
160
|
+
if (ResponseUtils.isFail(response)) {
|
161
|
+
await ResponseUtils.throwError(
|
162
|
+
`Organization ${organizationId} delete from library ${libraryId}, failed`,
|
163
|
+
response
|
164
|
+
)
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
async deleteLibrary(libraryId: LibraryId): Promise<void>{
|
169
|
+
if (libraryId === undefined || libraryId === null) {
|
170
|
+
throw new Error("Library delete, libraryId is undefined or null")
|
171
|
+
}
|
172
|
+
if (libraryId.length === 0 || libraryId.trim().length === 0) {
|
173
|
+
throw new Error("Library delete, libraryId is empty")
|
174
|
+
}
|
175
|
+
|
176
|
+
// send request to the server
|
177
|
+
const response = await this.context
|
178
|
+
.resolve(RpcService)
|
179
|
+
?.requestBuilder("api/v1/libraries/management")
|
180
|
+
.searchParam("libraryId", libraryId)
|
181
|
+
.sendDelete()
|
182
|
+
|
183
|
+
// check response status
|
184
|
+
if (ResponseUtils.isFail(response)) {
|
185
|
+
await ResponseUtils.throwError(
|
186
|
+
`Library ${libraryId} delete, failed`,
|
187
|
+
response
|
188
|
+
)
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
import {Library, LibraryId} from "./library"
|
3
|
+
import {OrganizationId} from "../organizations/organizations"
|
4
|
+
import {LibraryDto} from "../../dto/libraryResponse"
|
5
|
+
|
6
|
+
|
7
|
+
export abstract class Libraries {
|
8
|
+
|
9
|
+
abstract get collection(): ReadonlyArray<Library>
|
10
|
+
|
11
|
+
abstract createLibrary(name: string, region: number, isPublic: boolean): Promise<LibraryId>
|
12
|
+
|
13
|
+
abstract addOrgToLibrary(libraryId: LibraryId, organizationId: OrganizationId): Promise<void>
|
14
|
+
|
15
|
+
abstract getLibraries(): Promise<LibraryDto[]>
|
16
|
+
|
17
|
+
abstract deleteOrgFromLibrary(libraryId: LibraryId, organizationId: OrganizationId): Promise<void>
|
18
|
+
|
19
|
+
abstract deleteLibrary(libraryId: LibraryId): Promise<void>
|
20
|
+
}
|
@@ -0,0 +1,150 @@
|
|
1
|
+
import {Library, LibraryId} from "./library"
|
2
|
+
import {
|
3
|
+
LibraryFolderDto,
|
4
|
+
LibraryFolderResponse,
|
5
|
+
LibraryPageResponse
|
6
|
+
} from "../../dto/libraryResponse"
|
7
|
+
import {LibraryPage} from "./libraryPage"
|
8
|
+
import {RpcService} from "../../services/rpcService"
|
9
|
+
import {ResponseUtils} from "../../services/responseUtils"
|
10
|
+
import {FileImpl} from "../files/file.impl"
|
11
|
+
import {Context} from "../../context"
|
12
|
+
import {LibraryPageImpl} from "./libraryPage.impl"
|
13
|
+
import {LibraryFolderImpl} from "./libraryFolder.impl"
|
14
|
+
import {FolderId, LibraryFolder} from "./libraryFolder"
|
15
|
+
|
16
|
+
|
17
|
+
export class LibraryImpl extends Library {
|
18
|
+
|
19
|
+
private _library?: LibraryFolderDto
|
20
|
+
|
21
|
+
public root?: LibraryPage
|
22
|
+
|
23
|
+
constructor(
|
24
|
+
private readonly context: Context
|
25
|
+
) {
|
26
|
+
super()
|
27
|
+
}
|
28
|
+
|
29
|
+
async initFrom(library: LibraryFolderDto){
|
30
|
+
this._library = library
|
31
|
+
}
|
32
|
+
|
33
|
+
get id(): LibraryId {
|
34
|
+
if (this._library) {
|
35
|
+
return this._library.id
|
36
|
+
}
|
37
|
+
throw new Error("Library is not loaded.")
|
38
|
+
}
|
39
|
+
|
40
|
+
get name(): string {
|
41
|
+
if (this._library) {
|
42
|
+
return this._library.id
|
43
|
+
}
|
44
|
+
throw new Error("Library is not loaded.")
|
45
|
+
}
|
46
|
+
|
47
|
+
async getFolder(folderId: FolderId): Promise<LibraryFolder> {
|
48
|
+
if (folderId === undefined || folderId === null || folderId.trim() === "") {
|
49
|
+
throw new Error("Query library folder, folderId is undefined or null")
|
50
|
+
}
|
51
|
+
|
52
|
+
// send request to the server
|
53
|
+
const response = await this.context
|
54
|
+
.resolve(RpcService)
|
55
|
+
?.requestBuilder("api/v1/libraries/folder")
|
56
|
+
.searchParam("libraryId", this.id)
|
57
|
+
.searchParam("folderId", folderId)
|
58
|
+
.sendGet()
|
59
|
+
|
60
|
+
// check response status
|
61
|
+
if (ResponseUtils.isFail(response)) {
|
62
|
+
await ResponseUtils.throwError(
|
63
|
+
`Query library folder for ${folderId} failed`,
|
64
|
+
response
|
65
|
+
)
|
66
|
+
}
|
67
|
+
|
68
|
+
// parse files from the server's response
|
69
|
+
const folder = (await response!.json()) as LibraryFolderResponse
|
70
|
+
|
71
|
+
const libFolder = new LibraryFolderImpl(this, this.context)
|
72
|
+
|
73
|
+
await libFolder.initFrom(folder.folder)
|
74
|
+
|
75
|
+
return libFolder
|
76
|
+
}
|
77
|
+
|
78
|
+
async query(query: string, page: number, limit: number): Promise<LibraryPage> {
|
79
|
+
// check page
|
80
|
+
if (page === undefined || page === null) {
|
81
|
+
throw new Error("Query library root, page is undefined or null")
|
82
|
+
}
|
83
|
+
if (page < 0) {
|
84
|
+
throw new Error("Query library root, page is negative")
|
85
|
+
}
|
86
|
+
|
87
|
+
// check limit
|
88
|
+
if (limit === undefined || limit === null) {
|
89
|
+
throw new Error("Query library root, limit is undefined or null")
|
90
|
+
}
|
91
|
+
if (limit === 0) {
|
92
|
+
throw new Error("Query library root, limit is 0")
|
93
|
+
}
|
94
|
+
|
95
|
+
// send request to the server
|
96
|
+
const response = await this.context
|
97
|
+
.resolve(RpcService)
|
98
|
+
?.requestBuilder("api/v1/libraries/content/list")
|
99
|
+
.searchParam("libraryId", this.id)
|
100
|
+
.searchParam("nodeId", "")
|
101
|
+
.searchParam("query", query)
|
102
|
+
.searchParam("page", page.toString())
|
103
|
+
.searchParam("limit", limit.toString())
|
104
|
+
.sendGet()
|
105
|
+
|
106
|
+
// check response status
|
107
|
+
if (ResponseUtils.isFail(response)) {
|
108
|
+
await ResponseUtils.throwError(
|
109
|
+
`Query library root :${query}, page:${page}, limit:${limit}, failed`,
|
110
|
+
response
|
111
|
+
)
|
112
|
+
}
|
113
|
+
|
114
|
+
// parse files from the server's response
|
115
|
+
const pageResponse = (await response!.json()) as LibraryPageResponse
|
116
|
+
|
117
|
+
// create files list
|
118
|
+
const root = new LibraryPageImpl()
|
119
|
+
root.total = pageResponse.totalItemsCount
|
120
|
+
root.filesPerPage = pageResponse.itemsPerPage
|
121
|
+
root.page = page
|
122
|
+
|
123
|
+
// init files from the server's response
|
124
|
+
for (const fl of pageResponse.files) {
|
125
|
+
|
126
|
+
// create file implementation
|
127
|
+
const file = await new FileImpl(this.context).initFrom(fl)
|
128
|
+
|
129
|
+
// add file to the collection
|
130
|
+
root.files.push(file)
|
131
|
+
}
|
132
|
+
|
133
|
+
for (const flr of pageResponse.folders) {
|
134
|
+
|
135
|
+
// create folder implementation
|
136
|
+
const folder = new LibraryFolderImpl(this, this.context)
|
137
|
+
|
138
|
+
await folder.initFrom(flr)
|
139
|
+
|
140
|
+
// add folder to the collection
|
141
|
+
root.folders.push(folder)
|
142
|
+
}
|
143
|
+
|
144
|
+
// set files list
|
145
|
+
this.root = root
|
146
|
+
|
147
|
+
return root
|
148
|
+
}
|
149
|
+
|
150
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import {LibraryPage} from "./libraryPage"
|
2
|
+
import {LibraryFolder, FolderId} from "./libraryFolder"
|
3
|
+
|
4
|
+
export type LibraryId = string
|
5
|
+
|
6
|
+
|
7
|
+
export abstract class Library {
|
8
|
+
|
9
|
+
abstract get id(): LibraryId
|
10
|
+
|
11
|
+
abstract get name(): string
|
12
|
+
|
13
|
+
abstract getFolder(folderId: FolderId): Promise<LibraryFolder>
|
14
|
+
|
15
|
+
abstract query(query: string, page: number, limit: number): Promise<LibraryPage>
|
16
|
+
}
|
@@ -0,0 +1,136 @@
|
|
1
|
+
import {LibraryFolder, FolderId} from "./libraryFolder"
|
2
|
+
import {LibraryId} from "./library"
|
3
|
+
import {LibraryPage} from "./libraryPage"
|
4
|
+
import {Context} from "../../context"
|
5
|
+
import {LibraryFolderDto, LibraryPageResponse} from "../../dto/libraryResponse"
|
6
|
+
import {LibraryImpl} from "./library.impl"
|
7
|
+
import {RpcService} from "../../services/rpcService"
|
8
|
+
import {ResponseUtils} from "../../services/responseUtils"
|
9
|
+
import {LibraryPageImpl} from "./libraryPage.impl"
|
10
|
+
import {FileImpl} from "../files/file.impl"
|
11
|
+
|
12
|
+
|
13
|
+
export class LibraryFolderImpl extends LibraryFolder {
|
14
|
+
private _libFolder?: LibraryFolderDto
|
15
|
+
|
16
|
+
public libraryPage?: LibraryPage
|
17
|
+
|
18
|
+
constructor(
|
19
|
+
private readonly libraryImpl: LibraryImpl,
|
20
|
+
private readonly context: Context
|
21
|
+
) {
|
22
|
+
super()
|
23
|
+
}
|
24
|
+
|
25
|
+
async initFrom(libFolder: LibraryFolderDto) {
|
26
|
+
this._libFolder = libFolder
|
27
|
+
}
|
28
|
+
|
29
|
+
get iconId(): string {
|
30
|
+
if (this._libFolder) {
|
31
|
+
return this._libFolder.iconId
|
32
|
+
}
|
33
|
+
throw new Error("LibraryFolder is not loaded.")
|
34
|
+
}
|
35
|
+
|
36
|
+
itemsCount(): Promise<number> {
|
37
|
+
return Promise.resolve(0)
|
38
|
+
}
|
39
|
+
|
40
|
+
get libraryId(): LibraryId {
|
41
|
+
return this.libraryImpl.id
|
42
|
+
}
|
43
|
+
|
44
|
+
get name(): string {
|
45
|
+
if (this._libFolder) {
|
46
|
+
return this._libFolder.name
|
47
|
+
}
|
48
|
+
throw new Error("LibraryFolder is not loaded.")
|
49
|
+
}
|
50
|
+
|
51
|
+
get parents(): string[] {
|
52
|
+
if (this.libraryPage) {
|
53
|
+
return this.libraryPage.parents
|
54
|
+
}
|
55
|
+
throw new Error("Library page is not loaded, try query first")
|
56
|
+
}
|
57
|
+
|
58
|
+
get folderId(): FolderId {
|
59
|
+
if (this._libFolder) {
|
60
|
+
return this._libFolder.id
|
61
|
+
}
|
62
|
+
throw new Error("LibraryFolder is not loaded.")
|
63
|
+
}
|
64
|
+
|
65
|
+
async query(query: string, page: number, limit: number): Promise<LibraryPage> {
|
66
|
+
if (page === undefined || page === null) {
|
67
|
+
throw new Error("Query library folder, page is undefined or null")
|
68
|
+
}
|
69
|
+
if (page < 0) {
|
70
|
+
throw new Error("Query library folder, page is negative")
|
71
|
+
}
|
72
|
+
|
73
|
+
// check limit
|
74
|
+
if (limit === undefined || limit === null) {
|
75
|
+
throw new Error("Query library folder, limit is undefined or null")
|
76
|
+
}
|
77
|
+
if (limit === 0) {
|
78
|
+
throw new Error("Query library folder, limit is 0")
|
79
|
+
}
|
80
|
+
|
81
|
+
// send request to the server
|
82
|
+
const response = await this.context
|
83
|
+
.resolve(RpcService)
|
84
|
+
?.requestBuilder("api/v1/libraries/content/list")
|
85
|
+
.searchParam("libraryId", this.libraryId)
|
86
|
+
.searchParam("folderId", this.folderId)
|
87
|
+
.searchParam("query", query)
|
88
|
+
.searchParam("page", page.toString())
|
89
|
+
.searchParam("limit", limit.toString())
|
90
|
+
.sendGet()
|
91
|
+
|
92
|
+
// check response status
|
93
|
+
if (ResponseUtils.isFail(response)) {
|
94
|
+
await ResponseUtils.throwError(
|
95
|
+
`Query library folder :${query}, page:${page}, limit:${limit}, failed`,
|
96
|
+
response
|
97
|
+
)
|
98
|
+
}
|
99
|
+
|
100
|
+
// parse files from the server's response
|
101
|
+
const libPageResponse = (await response!.json()) as LibraryPageResponse
|
102
|
+
|
103
|
+
// create files list
|
104
|
+
const libraryPage = new LibraryPageImpl()
|
105
|
+
libraryPage.total = libPageResponse.totalItemsCount
|
106
|
+
libraryPage.filesPerPage = libPageResponse.itemsPerPage
|
107
|
+
libraryPage.page = page
|
108
|
+
|
109
|
+
// init files from the server's response
|
110
|
+
for (const fl of libPageResponse.files) {
|
111
|
+
|
112
|
+
// create file implementation
|
113
|
+
const file = await new FileImpl(this.context).initFrom(fl)
|
114
|
+
|
115
|
+
// add file to the collection
|
116
|
+
libraryPage.files.push(file)
|
117
|
+
}
|
118
|
+
|
119
|
+
for (const flr of libPageResponse.folders) {
|
120
|
+
|
121
|
+
// create folder implementation
|
122
|
+
const folder = new LibraryFolderImpl(this.libraryImpl, this.context)
|
123
|
+
|
124
|
+
await folder.initFrom(flr)
|
125
|
+
|
126
|
+
// add folder to the collection
|
127
|
+
libraryPage.folders.push(folder)
|
128
|
+
}
|
129
|
+
|
130
|
+
// set files list
|
131
|
+
this.libraryPage = libraryPage
|
132
|
+
|
133
|
+
return libraryPage
|
134
|
+
}
|
135
|
+
|
136
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import {LibraryId} from "./library"
|
2
|
+
import {LibraryPage} from "./libraryPage"
|
3
|
+
|
4
|
+
|
5
|
+
export type FolderId = string
|
6
|
+
|
7
|
+
export abstract class LibraryFolder {
|
8
|
+
|
9
|
+
abstract get libraryId(): LibraryId
|
10
|
+
|
11
|
+
abstract get parents(): FolderId[]
|
12
|
+
|
13
|
+
abstract get folderId(): FolderId
|
14
|
+
|
15
|
+
abstract get name(): string
|
16
|
+
|
17
|
+
abstract get iconId(): string
|
18
|
+
|
19
|
+
abstract itemsCount(): Promise<number>
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Query files.
|
23
|
+
*/
|
24
|
+
abstract query(query: string, page: number, limit: number): Promise<LibraryPage>
|
25
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import {LibraryPage} from "./libraryPage"
|
2
|
+
import {LibraryFolder} from "./libraryFolder"
|
3
|
+
import {File} from "../files/file"
|
4
|
+
|
5
|
+
|
6
|
+
export class LibraryPageImpl extends LibraryPage {
|
7
|
+
|
8
|
+
public parents: string[] = []
|
9
|
+
|
10
|
+
public files: File[] = []
|
11
|
+
public folders: LibraryFolder[] = []
|
12
|
+
|
13
|
+
public total: number = 0
|
14
|
+
public filesPerPage: number = 0
|
15
|
+
public page: number = 0
|
16
|
+
|
17
|
+
|
18
|
+
get pages(): number {
|
19
|
+
return Math.ceil(Math.max(this.total / this.filesPerPage, 1.0))
|
20
|
+
}
|
21
|
+
|
22
|
+
|
23
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import {LibraryFolder} from "./libraryFolder"
|
2
|
+
import {File} from "../files/file"
|
3
|
+
|
4
|
+
|
5
|
+
export abstract class LibraryPage {
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Get current page.
|
9
|
+
*/
|
10
|
+
abstract get parents(): string[]
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Get page files.
|
14
|
+
*/
|
15
|
+
abstract get files(): File[]
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Get page folders
|
19
|
+
*/
|
20
|
+
abstract get folders(): LibraryFolder[]
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Get pages count.
|
24
|
+
*/
|
25
|
+
abstract get pages(): number
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Get total count.
|
29
|
+
*/
|
30
|
+
abstract get total(): number
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Get current page.
|
34
|
+
*/
|
35
|
+
abstract get page(): number
|
36
|
+
|
37
|
+
}
|
@@ -42,6 +42,13 @@ export class WorkspaceImpl extends Workspace {
|
|
42
42
|
throw new Error("Workspace is not loaded.")
|
43
43
|
}
|
44
44
|
|
45
|
+
get isShared(): boolean {
|
46
|
+
if (this._workspace) {
|
47
|
+
return this._workspace.isShared
|
48
|
+
}
|
49
|
+
throw new Error("Workspace is not loaded.")
|
50
|
+
}
|
51
|
+
|
45
52
|
get files(): Files {
|
46
53
|
return this._files
|
47
54
|
}
|
@@ -115,6 +122,42 @@ export class WorkspaceImpl extends Workspace {
|
|
115
122
|
})
|
116
123
|
}
|
117
124
|
|
125
|
+
async share(isShared: boolean): Promise<void> {
|
126
|
+
if (!this._workspace) {
|
127
|
+
throw new Error("Workspace is not loaded.")
|
128
|
+
}
|
129
|
+
if (this._isMarkAsDeleted) {
|
130
|
+
throw new Error("Workspace is marked as deleted.")
|
131
|
+
}
|
132
|
+
if (isShared === this.isShared) {
|
133
|
+
return Promise.resolve()
|
134
|
+
}
|
135
|
+
if (isShared === undefined || isShared === null) {
|
136
|
+
throw new Error("Is shared parameter is required.")
|
137
|
+
}
|
138
|
+
|
139
|
+
const response = await this.context
|
140
|
+
.resolve(RpcService)
|
141
|
+
?.requestBuilder("api/v1/workspaces/library")
|
142
|
+
.sendPutJson({
|
143
|
+
workspaceId: this.id,
|
144
|
+
isShared: isShared
|
145
|
+
})
|
146
|
+
|
147
|
+
if (ResponseUtils.isFail(response)) {
|
148
|
+
await ResponseUtils.throwError("Failed to change workspace shared state", response)
|
149
|
+
}
|
150
|
+
|
151
|
+
if (this._workspace) {
|
152
|
+
this._workspace.isShared = isShared
|
153
|
+
}
|
154
|
+
|
155
|
+
this.dispatch({
|
156
|
+
type: WorkspaceEvent.CHANGED,
|
157
|
+
data: this
|
158
|
+
})
|
159
|
+
}
|
160
|
+
|
118
161
|
async initFrom(workspace: WorkspaceDto) {
|
119
162
|
this._workspace = workspace
|
120
163
|
}
|
@@ -37,6 +37,8 @@ export abstract class Workspace extends EventDispatcher<
|
|
37
37
|
*/
|
38
38
|
abstract get description(): string
|
39
39
|
|
40
|
+
abstract get isShared(): boolean
|
41
|
+
|
40
42
|
/**
|
41
43
|
* Workspace files.
|
42
44
|
*/
|
@@ -51,4 +53,10 @@ export abstract class Workspace extends EventDispatcher<
|
|
51
53
|
* Change workspace name and description.
|
52
54
|
*/
|
53
55
|
abstract change(name: string, description: string): Promise<void>
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Make workspace available for the library implementation
|
59
|
+
* @param isShared
|
60
|
+
*/
|
61
|
+
abstract share(isShared: boolean): Promise<void>
|
54
62
|
}
|