@neuralinnovations/dataisland-sdk 0.0.1-dev73 → 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.
Files changed (145) hide show
  1. package/README.md +5 -0
  2. package/dist/package.json +1 -1
  3. package/dist/src/commands/startCommandHandler.d.ts.map +1 -1
  4. package/dist/src/commands/startCommandHandler.js +3 -0
  5. package/dist/src/commands/startCommandHandler.js.map +1 -1
  6. package/dist/src/dataIslandApp.d.ts +5 -0
  7. package/dist/src/dataIslandApp.d.ts.map +1 -1
  8. package/dist/src/dataIslandApp.js.map +1 -1
  9. package/dist/src/dto/chatResponse.d.ts +18 -3
  10. package/dist/src/dto/chatResponse.d.ts.map +1 -1
  11. package/dist/src/dto/chatResponse.js +12 -1
  12. package/dist/src/dto/chatResponse.js.map +1 -1
  13. package/dist/src/dto/libraryResponse.d.ts +41 -0
  14. package/dist/src/dto/libraryResponse.d.ts.map +1 -0
  15. package/dist/src/dto/libraryResponse.js +3 -0
  16. package/dist/src/dto/libraryResponse.js.map +1 -0
  17. package/dist/src/dto/queryFlowResponse.d.ts +19 -0
  18. package/dist/src/dto/queryFlowResponse.d.ts.map +1 -0
  19. package/dist/src/dto/queryFlowResponse.js +10 -0
  20. package/dist/src/dto/queryFlowResponse.js.map +1 -0
  21. package/dist/src/dto/workspacesResponse.d.ts +1 -0
  22. package/dist/src/dto/workspacesResponse.d.ts.map +1 -1
  23. package/dist/src/dto/workspacesResponse.js.map +1 -1
  24. package/dist/src/index.d.ts +7 -0
  25. package/dist/src/index.d.ts.map +1 -1
  26. package/dist/src/index.js +7 -0
  27. package/dist/src/index.js.map +1 -1
  28. package/dist/src/internal/app.impl.d.ts +2 -0
  29. package/dist/src/internal/app.impl.d.ts.map +1 -1
  30. package/dist/src/internal/app.impl.js +7 -0
  31. package/dist/src/internal/app.impl.js.map +1 -1
  32. package/dist/src/services/acquiringService.d.ts.map +1 -1
  33. package/dist/src/services/acquiringService.js +2 -2
  34. package/dist/src/services/acquiringService.js.map +1 -1
  35. package/dist/src/services/librariesService.d.ts +9 -0
  36. package/dist/src/services/librariesService.d.ts.map +1 -0
  37. package/dist/src/services/librariesService.js +19 -0
  38. package/dist/src/services/librariesService.js.map +1 -0
  39. package/dist/src/storages/chats/chat.d.ts +3 -6
  40. package/dist/src/storages/chats/chat.d.ts.map +1 -1
  41. package/dist/src/storages/chats/chat.impl.d.ts +2 -3
  42. package/dist/src/storages/chats/chat.impl.d.ts.map +1 -1
  43. package/dist/src/storages/chats/chat.impl.js +2 -6
  44. package/dist/src/storages/chats/chat.impl.js.map +1 -1
  45. package/dist/src/storages/chats/chat.js.map +1 -1
  46. package/dist/src/storages/chats/chats.d.ts +12 -0
  47. package/dist/src/storages/chats/chats.d.ts.map +1 -1
  48. package/dist/src/storages/chats/chats.impl.d.ts +2 -0
  49. package/dist/src/storages/chats/chats.impl.d.ts.map +1 -1
  50. package/dist/src/storages/chats/chats.impl.js +68 -0
  51. package/dist/src/storages/chats/chats.impl.js.map +1 -1
  52. package/dist/src/storages/chats/chats.js.map +1 -1
  53. package/dist/src/storages/library/libraries.d.ts +12 -0
  54. package/dist/src/storages/library/libraries.d.ts.map +1 -0
  55. package/dist/src/storages/library/libraries.impl.d.ts +18 -0
  56. package/dist/src/storages/library/libraries.impl.d.ts.map +1 -0
  57. package/dist/src/storages/library/libraries.impl.js +134 -0
  58. package/dist/src/storages/library/libraries.impl.js.map +1 -0
  59. package/dist/src/storages/library/libraries.js +7 -0
  60. package/dist/src/storages/library/libraries.js.map +1 -0
  61. package/dist/src/storages/library/library.d.ts +10 -0
  62. package/dist/src/storages/library/library.d.ts.map +1 -0
  63. package/dist/src/storages/library/library.impl.d.ts +17 -0
  64. package/dist/src/storages/library/library.impl.d.ts.map +1 -0
  65. package/dist/src/storages/library/library.impl.js +98 -0
  66. package/dist/src/storages/library/library.impl.js.map +1 -0
  67. package/dist/src/storages/library/library.js +7 -0
  68. package/dist/src/storages/library/library.js.map +1 -0
  69. package/dist/src/storages/library/libraryFolder.d.ts +16 -0
  70. package/dist/src/storages/library/libraryFolder.d.ts.map +1 -0
  71. package/dist/src/storages/library/libraryFolder.impl.d.ts +22 -0
  72. package/dist/src/storages/library/libraryFolder.impl.d.ts.map +1 -0
  73. package/dist/src/storages/library/libraryFolder.impl.js +97 -0
  74. package/dist/src/storages/library/libraryFolder.impl.js.map +1 -0
  75. package/dist/src/storages/library/libraryFolder.js +7 -0
  76. package/dist/src/storages/library/libraryFolder.js.map +1 -0
  77. package/dist/src/storages/library/libraryPage.d.ts +29 -0
  78. package/dist/src/storages/library/libraryPage.d.ts.map +1 -0
  79. package/dist/src/storages/library/libraryPage.impl.d.ts +13 -0
  80. package/dist/src/storages/library/libraryPage.impl.d.ts.map +1 -0
  81. package/dist/src/storages/library/libraryPage.impl.js +20 -0
  82. package/dist/src/storages/library/libraryPage.impl.js.map +1 -0
  83. package/dist/src/storages/library/libraryPage.js +7 -0
  84. package/dist/src/storages/library/libraryPage.js.map +1 -0
  85. package/dist/src/storages/organizations/organization.d.ts +5 -0
  86. package/dist/src/storages/organizations/organization.d.ts.map +1 -1
  87. package/dist/src/storages/organizations/organization.impl.d.ts +3 -0
  88. package/dist/src/storages/organizations/organization.impl.d.ts.map +1 -1
  89. package/dist/src/storages/organizations/organization.impl.js +7 -1
  90. package/dist/src/storages/organizations/organization.impl.js.map +1 -1
  91. package/dist/src/storages/organizations/organization.js.map +1 -1
  92. package/dist/src/storages/queryFlows/queryFlow.d.ts +12 -0
  93. package/dist/src/storages/queryFlows/queryFlow.d.ts.map +1 -0
  94. package/dist/src/storages/queryFlows/queryFlow.impl.d.ts +16 -0
  95. package/dist/src/storages/queryFlows/queryFlow.impl.d.ts.map +1 -0
  96. package/dist/src/storages/queryFlows/queryFlow.impl.js +59 -0
  97. package/dist/src/storages/queryFlows/queryFlow.impl.js.map +1 -0
  98. package/dist/src/storages/queryFlows/queryFlow.js +12 -0
  99. package/dist/src/storages/queryFlows/queryFlow.js.map +1 -0
  100. package/dist/src/storages/queryFlows/queryFlows.d.ts +22 -0
  101. package/dist/src/storages/queryFlows/queryFlows.d.ts.map +1 -0
  102. package/dist/src/storages/queryFlows/queryFlows.impl.d.ts +18 -0
  103. package/dist/src/storages/queryFlows/queryFlows.impl.d.ts.map +1 -0
  104. package/dist/src/storages/queryFlows/queryFlows.impl.js +108 -0
  105. package/dist/src/storages/queryFlows/queryFlows.impl.js.map +1 -0
  106. package/dist/src/storages/queryFlows/queryFlows.js +16 -0
  107. package/dist/src/storages/queryFlows/queryFlows.js.map +1 -0
  108. package/dist/src/storages/workspaces/workspace.d.ts +6 -0
  109. package/dist/src/storages/workspaces/workspace.d.ts.map +1 -1
  110. package/dist/src/storages/workspaces/workspace.impl.d.ts +2 -0
  111. package/dist/src/storages/workspaces/workspace.impl.d.ts.map +1 -1
  112. package/dist/src/storages/workspaces/workspace.impl.js +36 -0
  113. package/dist/src/storages/workspaces/workspace.impl.js.map +1 -1
  114. package/dist/src/storages/workspaces/workspace.js.map +1 -1
  115. package/package.json +1 -1
  116. package/src/commands/startCommandHandler.ts +3 -0
  117. package/src/dataIslandApp.ts +6 -0
  118. package/src/dto/chatResponse.ts +21 -3
  119. package/src/dto/libraryResponse.ts +49 -0
  120. package/src/dto/queryFlowResponse.ts +27 -0
  121. package/src/dto/workspacesResponse.ts +1 -0
  122. package/src/index.ts +7 -0
  123. package/src/internal/app.impl.ts +9 -0
  124. package/src/services/acquiringService.ts +2 -2
  125. package/src/services/librariesService.ts +22 -0
  126. package/src/storages/chats/chat.impl.ts +3 -7
  127. package/src/storages/chats/chat.ts +3 -7
  128. package/src/storages/chats/chats.impl.ts +92 -0
  129. package/src/storages/chats/chats.ts +14 -0
  130. package/src/storages/library/libraries.impl.ts +192 -0
  131. package/src/storages/library/libraries.ts +20 -0
  132. package/src/storages/library/library.impl.ts +150 -0
  133. package/src/storages/library/library.ts +16 -0
  134. package/src/storages/library/libraryFolder.impl.ts +136 -0
  135. package/src/storages/library/libraryFolder.ts +25 -0
  136. package/src/storages/library/libraryPage.impl.ts +23 -0
  137. package/src/storages/library/libraryPage.ts +37 -0
  138. package/src/storages/organizations/organization.impl.ts +10 -1
  139. package/src/storages/organizations/organization.ts +6 -0
  140. package/src/storages/queryFlows/queryFlow.impl.ts +74 -0
  141. package/src/storages/queryFlows/queryFlow.ts +20 -0
  142. package/src/storages/queryFlows/queryFlows.impl.ts +151 -0
  143. package/src/storages/queryFlows/queryFlows.ts +32 -0
  144. package/src/storages/workspaces/workspace.impl.ts +43 -0
  145. package/src/storages/workspaces/workspace.ts +8 -0
@@ -212,6 +212,98 @@ export class ChatsImpl extends Chats {
212
212
  return chat
213
213
  }
214
214
 
215
+ async createWithLibraryFolder(libraryId: string, folderIds: string[] | null = null): Promise<Chat | undefined>{
216
+ if (libraryId === undefined || libraryId === null || libraryId.trim() === "") {
217
+ throw new Error("Create chat with library folder, library id is undefined, null or empty")
218
+ }
219
+
220
+ // send create request to the server
221
+ const response = await this.context
222
+ .resolve(RpcService)
223
+ ?.requestBuilder("api/v1/chats/library/folders")
224
+ .sendPostJson({
225
+ libraryId: libraryId,
226
+ folderIds: folderIds,
227
+ model: "search",
228
+ clientContext: "",
229
+ })
230
+
231
+ // check response status
232
+ if (ResponseUtils.isFail(response)) {
233
+ if (await ResponseUtils.isLimitReached()){
234
+ return undefined
235
+ }
236
+
237
+ await ResponseUtils.throwError(`Failed to create chat in library with folder, library: ${libraryId}`, response)
238
+ }
239
+
240
+ // parse workspace from the server's response
241
+ const content = (await response!.json() as {
242
+ chat: ChatDto
243
+ }).chat as ChatDto
244
+
245
+ // create workspace implementation
246
+ const chat = new ChatImpl(this.context, this.organization)
247
+ await chat.initFrom(content)
248
+
249
+ // add chat to the collection
250
+ this._chats.push(chat)
251
+
252
+ // dispatch event
253
+ this.dispatch({
254
+ type: ChatsEvent.ADDED,
255
+ data: chat
256
+ })
257
+
258
+ return chat
259
+ }
260
+
261
+ async createWithLibraryFile(libraryId: string, fileId: string): Promise<Chat | undefined>{
262
+ if (libraryId === undefined || libraryId === null || libraryId.trim() === "") {
263
+ throw new Error("Create chat with library file, library id is undefined, null or empty")
264
+ }
265
+
266
+ // send create request to the server
267
+ const response = await this.context
268
+ .resolve(RpcService)
269
+ ?.requestBuilder("api/v1/chats/library/file")
270
+ .sendPostJson({
271
+ libraryId: libraryId,
272
+ fileId: fileId,
273
+ model: "search",
274
+ clientContext: "",
275
+ })
276
+
277
+ // check response status
278
+ if (ResponseUtils.isFail(response)) {
279
+ if (await ResponseUtils.isLimitReached()){
280
+ return undefined
281
+ }
282
+
283
+ await ResponseUtils.throwError(`Failed to create chat in library with file, library: ${libraryId}`, response)
284
+ }
285
+
286
+ // parse workspace from the server's response
287
+ const content = (await response!.json() as {
288
+ chat: ChatDto
289
+ }).chat as ChatDto
290
+
291
+ // create workspace implementation
292
+ const chat = new ChatImpl(this.context, this.organization)
293
+ await chat.initFrom(content)
294
+
295
+ // add chat to the collection
296
+ this._chats.push(chat)
297
+
298
+ // dispatch event
299
+ this.dispatch({
300
+ type: ChatsEvent.ADDED,
301
+ data: chat
302
+ })
303
+
304
+ return chat
305
+ }
306
+
215
307
 
216
308
 
217
309
 
@@ -40,6 +40,20 @@ export abstract class Chats extends EventDispatcher<ChatsEvent, Chat> {
40
40
  */
41
41
  abstract createWithWorkspace(workspaceIds: string[], clientContext: string): Promise<Chat | undefined>
42
42
 
43
+ /**
44
+ * Create chat with library folders
45
+ * @param libraryId
46
+ * @param folderIds
47
+ */
48
+ abstract createWithLibraryFolder(libraryId: string, folderIds: string[]): Promise<Chat | undefined>
49
+
50
+ /**
51
+ * Create chat with library file
52
+ * @param libraryId
53
+ * @param fileId
54
+ */
55
+ abstract createWithLibraryFile(libraryId: string, fileId: string): Promise<Chat | undefined>
56
+
43
57
  /**
44
58
  * Get chat by id.
45
59
  * @param id
@@ -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
+ }