@neuralinnovations/dataisland-sdk 0.0.1-dev22 → 0.0.1-dev23
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/dist/package.json +1 -1
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/storages/groups/group.d.ts +63 -0
- package/dist/src/storages/groups/group.d.ts.map +1 -0
- package/dist/src/storages/groups/group.impl.d.ts +37 -0
- package/dist/src/storages/groups/group.impl.d.ts.map +1 -0
- package/dist/src/storages/groups/group.impl.js +205 -0
- package/dist/src/storages/groups/group.impl.js.map +1 -0
- package/dist/src/storages/groups/group.js +15 -0
- package/dist/src/storages/groups/group.js.map +1 -0
- package/dist/src/storages/groups/groups.d.ts +3 -60
- package/dist/src/storages/groups/groups.d.ts.map +1 -1
- package/dist/src/storages/groups/groups.impl.d.ts +2 -35
- package/dist/src/storages/groups/groups.impl.d.ts.map +1 -1
- package/dist/src/storages/groups/groups.impl.js +14 -193
- package/dist/src/storages/groups/groups.impl.js.map +1 -1
- package/dist/src/storages/groups/groups.js +7 -13
- package/dist/src/storages/groups/groups.js.map +1 -1
- package/dist/src/storages/organizations/organization.d.ts +2 -1
- package/dist/src/storages/organizations/organization.d.ts.map +1 -1
- package/dist/src/storages/organizations/organization.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +3 -0
- package/src/storages/groups/group.impl.ts +267 -0
- package/src/storages/groups/group.ts +73 -0
- package/src/storages/groups/groups.impl.ts +17 -252
- package/src/storages/groups/groups.ts +3 -70
- package/src/storages/organizations/organization.ts +2 -1
@@ -0,0 +1,73 @@
|
|
1
|
+
import { EventDispatcher } from "../../events"
|
2
|
+
import { AccessGroupDto } from "../../dto/accessGroupResponse"
|
3
|
+
import { UserDto } from "../../dto/userInfoResponse"
|
4
|
+
import { Workspace } from "../workspaces/workspace"
|
5
|
+
import { WorkspaceId } from "../workspaces/workspaces"
|
6
|
+
import { UserId } from "../user/userProfile"
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Group id.
|
10
|
+
*/
|
11
|
+
export type GroupId = string
|
12
|
+
|
13
|
+
export enum GroupEvent {
|
14
|
+
UPDATED = "updated"
|
15
|
+
}
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Group.
|
19
|
+
*/
|
20
|
+
export abstract class Group extends EventDispatcher<GroupEvent, Group> {
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Group id.
|
24
|
+
*/
|
25
|
+
abstract get id(): GroupId
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Group information.
|
29
|
+
*/
|
30
|
+
abstract get group(): AccessGroupDto
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Group members.
|
34
|
+
*/
|
35
|
+
abstract get members(): UserDto[]
|
36
|
+
|
37
|
+
/**
|
38
|
+
* Group workspaces.
|
39
|
+
*/
|
40
|
+
abstract get workspaces(): readonly Workspace[]
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Set workspaces.
|
44
|
+
*/
|
45
|
+
abstract setWorkspaces(workspaces: WorkspaceId[]): Promise<void>
|
46
|
+
|
47
|
+
/**
|
48
|
+
* Set name.
|
49
|
+
*/
|
50
|
+
abstract setName(name: string): Promise<void>
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Set permits.
|
54
|
+
*/
|
55
|
+
abstract setPermits(permits: { isAdmin: boolean }): Promise<void>
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Set members.
|
59
|
+
*/
|
60
|
+
abstract setMembersIds(members: UserId[]): Promise<void>
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Remove members.
|
64
|
+
* @param members
|
65
|
+
*/
|
66
|
+
abstract removeMembers(members: UserId[]): Promise<void>
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Remove workspaces.
|
70
|
+
* @param workspaces
|
71
|
+
*/
|
72
|
+
abstract removeWorkspaces(workspaces: WorkspaceId[]): Promise<void>
|
73
|
+
}
|
@@ -1,254 +1,14 @@
|
|
1
1
|
import { Context } from "../../context"
|
2
|
-
import { Disposable } from "../../disposable"
|
3
2
|
import {
|
4
|
-
AccessGroupDto,
|
5
3
|
AccessGroupResponse,
|
6
4
|
AccessGroupsResponse
|
7
5
|
} from "../../dto/accessGroupResponse"
|
8
|
-
import { UserDto } from "../../dto/userInfoResponse"
|
9
|
-
import { WorkspacesResponse } from "../../dto/workspacesResponse"
|
10
6
|
import { RpcService } from "../../services/rpcService"
|
11
|
-
import {
|
7
|
+
import { Groups, GroupsEvent } from "./groups"
|
12
8
|
import { OrganizationImpl } from "../organizations/organization.impl"
|
13
9
|
import { ResponseUtils } from "../../services/responseUtils"
|
14
|
-
import {
|
15
|
-
import {
|
16
|
-
import { Workspace } from "../workspaces/workspace"
|
17
|
-
import { WorkspaceId } from "../workspaces/workspaces"
|
18
|
-
|
19
|
-
export class GroupImpl extends Group implements Disposable {
|
20
|
-
private _isDisposed: boolean = false
|
21
|
-
private _content?: AccessGroupDto
|
22
|
-
private _members?: UserDto[]
|
23
|
-
private _workspaces: Workspace[] = []
|
24
|
-
|
25
|
-
constructor(
|
26
|
-
private readonly context: Context,
|
27
|
-
public readonly organization: Organization
|
28
|
-
) {
|
29
|
-
super()
|
30
|
-
}
|
31
|
-
|
32
|
-
async initFrom(id: GroupId): Promise<Group> {
|
33
|
-
await this.reloadGroup(id)
|
34
|
-
await this.reloadWorkspaces()
|
35
|
-
return this
|
36
|
-
}
|
37
|
-
|
38
|
-
async reloadGroup(id: GroupId): Promise<void> {
|
39
|
-
// fetch group
|
40
|
-
const response = await this.context.resolve(RpcService)
|
41
|
-
?.requestBuilder("api/v1/AccessGroups")
|
42
|
-
.searchParam("groupId", id)
|
43
|
-
.sendGet()
|
44
|
-
|
45
|
-
// check response status
|
46
|
-
if (ResponseUtils.isFail(response)) {
|
47
|
-
await ResponseUtils.throwError(`Failed to get group: ${id}, organization: ${this.organization.id}`, response)
|
48
|
-
}
|
49
|
-
|
50
|
-
// parse group from the server's response
|
51
|
-
const group = (await response!.json()) as AccessGroupResponse
|
52
|
-
// init group
|
53
|
-
this._content = group.group
|
54
|
-
this._members = group.members
|
55
|
-
}
|
56
|
-
|
57
|
-
async reloadWorkspaces(): Promise<void> {
|
58
|
-
const groupWorkspaces = await this.loadWorkspaces(this.id)
|
59
|
-
this._workspaces.length = 0
|
60
|
-
this._workspaces.push(...groupWorkspaces)
|
61
|
-
}
|
62
|
-
|
63
|
-
async loadWorkspaces(groupId: GroupId): Promise<Workspace[]> {
|
64
|
-
// fetch workspaces
|
65
|
-
const response = await this.context.resolve(RpcService)
|
66
|
-
?.requestBuilder("api/v1/AccessGroups/workspaces")
|
67
|
-
.searchParam("groupId", groupId)
|
68
|
-
.sendGet()
|
69
|
-
|
70
|
-
if (ResponseUtils.isFail(response)) {
|
71
|
-
await ResponseUtils.throwError(`Failed to get workspaces for group: ${this.id}, organization: ${this.organization.id}`, response)
|
72
|
-
}
|
73
|
-
|
74
|
-
// parse workspaces from the server's response
|
75
|
-
const workspaces = (await response!.json()) as WorkspacesResponse
|
76
|
-
|
77
|
-
// get workspaces
|
78
|
-
const result: Workspace[] = []
|
79
|
-
for (const workspaceDto of workspaces.workspaces) {
|
80
|
-
result.push(this.organization.workspaces.get(workspaceDto.id))
|
81
|
-
}
|
82
|
-
|
83
|
-
return result
|
84
|
-
}
|
85
|
-
|
86
|
-
get id(): GroupId {
|
87
|
-
if (this._content) {
|
88
|
-
return this._content.id
|
89
|
-
}
|
90
|
-
throw new Error("Access group is not loaded.")
|
91
|
-
}
|
92
|
-
|
93
|
-
get group(): AccessGroupDto {
|
94
|
-
if (this._content) {
|
95
|
-
return this._content
|
96
|
-
}
|
97
|
-
throw new Error("Access group is not loaded.")
|
98
|
-
}
|
99
|
-
|
100
|
-
get workspaces(): readonly Workspace[] {
|
101
|
-
return this._workspaces
|
102
|
-
}
|
103
|
-
|
104
|
-
get members(): UserDto[] {
|
105
|
-
if (this._members) {
|
106
|
-
return this._members
|
107
|
-
}
|
108
|
-
throw new Error("Access group is not loaded.")
|
109
|
-
}
|
110
|
-
|
111
|
-
async setName(name: string): Promise<void> {
|
112
|
-
if (name === undefined || name === null) {
|
113
|
-
throw new Error("Groups change, name is undefined or null")
|
114
|
-
}
|
115
|
-
if (name.length === 0 || name.trim().length === 0) {
|
116
|
-
throw new Error("Groups change, name is empty")
|
117
|
-
}
|
118
|
-
// send request to the server
|
119
|
-
const response = await this.context
|
120
|
-
.resolve(RpcService)
|
121
|
-
?.requestBuilder("api/v1/AccessGroups/name")
|
122
|
-
.sendPutJson({
|
123
|
-
groupId: this.id,
|
124
|
-
name: name
|
125
|
-
})
|
126
|
-
|
127
|
-
// check response status
|
128
|
-
if (ResponseUtils.isFail(response)) {
|
129
|
-
await ResponseUtils.throwError(`Failed to change group name, group: ${this.id}, organization: ${this.organization.id}`, response)
|
130
|
-
}
|
131
|
-
|
132
|
-
// change name
|
133
|
-
if (this._content) {
|
134
|
-
this._content.name = name
|
135
|
-
}
|
136
|
-
}
|
137
|
-
|
138
|
-
async setPermits(permits: { isAdmin: boolean }): Promise<void> {
|
139
|
-
// send request to the server
|
140
|
-
const response = await this.context
|
141
|
-
.resolve(RpcService)
|
142
|
-
?.requestBuilder("api/v1/AccessGroups/permits")
|
143
|
-
.sendPutJson({
|
144
|
-
groupId: this.id,
|
145
|
-
permits: permits
|
146
|
-
})
|
147
|
-
|
148
|
-
if (ResponseUtils.isFail(response)) {
|
149
|
-
await ResponseUtils.throwError(`Failed to change group permits, group: ${this.id}, organization: ${this.organization.id}`, response)
|
150
|
-
}
|
151
|
-
}
|
152
|
-
|
153
|
-
async setWorkspaces(workspaces: string[]): Promise<void> {
|
154
|
-
if (workspaces === null || workspaces === undefined) {
|
155
|
-
throw new Error("Group add workspaces, workspaces is undefined or null")
|
156
|
-
}
|
157
|
-
|
158
|
-
// send request to the server
|
159
|
-
const response = await this.context
|
160
|
-
.resolve(RpcService)
|
161
|
-
?.requestBuilder("api/v1/AccessGroups/workspaces")
|
162
|
-
.sendPutJson({
|
163
|
-
groupId: this.id,
|
164
|
-
actualWorkspaceIds: workspaces
|
165
|
-
})
|
166
|
-
|
167
|
-
if (ResponseUtils.isFail(response)) {
|
168
|
-
await ResponseUtils.throwError(`Failed to set workspaces for group: ${this.id}, organization: ${this.organization.id}`, response)
|
169
|
-
}
|
170
|
-
|
171
|
-
// reload workspaces
|
172
|
-
await this.reloadWorkspaces()
|
173
|
-
}
|
174
|
-
|
175
|
-
async removeWorkspaces(workspaces: WorkspaceId[]): Promise<void> {
|
176
|
-
if (workspaces === null || workspaces === undefined) {
|
177
|
-
throw new Error("Group removeWorkspaces, workspaces is undefined or null")
|
178
|
-
}
|
179
|
-
|
180
|
-
// make set of workspaces
|
181
|
-
const groupWorkspaces = new Set(this.workspaces.map(w => w.id))
|
182
|
-
|
183
|
-
// check argument
|
184
|
-
if (!workspaces.every(w => groupWorkspaces.has(w))) {
|
185
|
-
const notExistingWorkspaces = workspaces.filter(workspaceId => !groupWorkspaces.has(workspaceId))
|
186
|
-
throw new Error(`Group removeWorkspaces, workspaces contains not existing workspaces: ${notExistingWorkspaces}`)
|
187
|
-
}
|
188
|
-
|
189
|
-
// remove workspaces
|
190
|
-
for (const id of workspaces) {
|
191
|
-
groupWorkspaces.delete(id)
|
192
|
-
}
|
193
|
-
|
194
|
-
// send request to the server
|
195
|
-
await this.setWorkspaces(Array.from(groupWorkspaces))
|
196
|
-
}
|
197
|
-
|
198
|
-
async setMembersIds(members: UserId[]) {
|
199
|
-
if (members === null || members === undefined) {
|
200
|
-
throw new Error("Group setMembersIds, members is undefined or null")
|
201
|
-
}
|
202
|
-
|
203
|
-
// send request to the server
|
204
|
-
const response = await this.context
|
205
|
-
.resolve(RpcService)
|
206
|
-
?.requestBuilder("api/v1/AccessGroups/members")
|
207
|
-
.sendPutJson({
|
208
|
-
groupId: this.id,
|
209
|
-
memberIds: members
|
210
|
-
})
|
211
|
-
|
212
|
-
if (ResponseUtils.isFail(response)) {
|
213
|
-
await ResponseUtils.throwError(`Failed to set members for group: ${this.id}, organization: ${this.organization.id}`, response)
|
214
|
-
}
|
215
|
-
|
216
|
-
// reload group
|
217
|
-
await this.reloadGroup(this.id)
|
218
|
-
}
|
219
|
-
|
220
|
-
async removeMembers(members: UserId[]): Promise<void> {
|
221
|
-
// check members
|
222
|
-
if (members === null || members === undefined) {
|
223
|
-
throw new Error("Group removeMembers, members is undefined or null")
|
224
|
-
}
|
225
|
-
|
226
|
-
// make set of members
|
227
|
-
const groupMembers = new Set(this.members.map(m => m.id))
|
228
|
-
|
229
|
-
// check argument
|
230
|
-
if (!members.every(m => groupMembers.has(m))) {
|
231
|
-
const notExistingMembers = members.filter(memberId => !groupMembers.has(memberId))
|
232
|
-
throw new Error(`Group removeMembers, members contains not existing members: ${notExistingMembers}`)
|
233
|
-
}
|
234
|
-
|
235
|
-
// remove members
|
236
|
-
for (const id of members) {
|
237
|
-
groupMembers.delete(id)
|
238
|
-
}
|
239
|
-
|
240
|
-
// send request to the server
|
241
|
-
await this.setMembersIds(Array.from(groupMembers))
|
242
|
-
}
|
243
|
-
|
244
|
-
get isDisposed(): boolean {
|
245
|
-
return this._isDisposed
|
246
|
-
}
|
247
|
-
|
248
|
-
dispose(): void {
|
249
|
-
this._isDisposed = true
|
250
|
-
}
|
251
|
-
}
|
10
|
+
import { Group, GroupId } from "./group"
|
11
|
+
import { GroupImpl } from "./group.impl"
|
252
12
|
|
253
13
|
export class GroupsImpl extends Groups {
|
254
14
|
|
@@ -305,19 +65,24 @@ export class GroupsImpl extends Groups {
|
|
305
65
|
// parse groups from the server's response
|
306
66
|
const groups = (await response!.json()) as AccessGroupsResponse
|
307
67
|
|
68
|
+
const wait: Promise<Group>[] = []
|
69
|
+
|
308
70
|
// init groups
|
309
71
|
for (const gr of groups.groups) {
|
310
72
|
// create group implementation
|
311
|
-
const group =
|
73
|
+
const group = new GroupImpl(this.context, this.organization).initFrom(gr.id)
|
74
|
+
|
75
|
+
// add to the wait list
|
76
|
+
wait.push(group)
|
77
|
+
}
|
312
78
|
|
79
|
+
// wait for all groups
|
80
|
+
const groupsResult = await Promise.all(wait)
|
81
|
+
|
82
|
+
// add groups to the collection
|
83
|
+
for (const group of groupsResult) {
|
313
84
|
// add group to the collection
|
314
85
|
this._groups.push(group)
|
315
|
-
|
316
|
-
// dispatch event
|
317
|
-
this.dispatch({
|
318
|
-
type: GroupEvent.ADDED,
|
319
|
-
data: group
|
320
|
-
})
|
321
86
|
}
|
322
87
|
}
|
323
88
|
|
@@ -357,7 +122,7 @@ export class GroupsImpl extends Groups {
|
|
357
122
|
|
358
123
|
// dispatch event
|
359
124
|
this.dispatch({
|
360
|
-
type:
|
125
|
+
type: GroupsEvent.ADDED,
|
361
126
|
data: group
|
362
127
|
})
|
363
128
|
|
@@ -400,7 +165,7 @@ export class GroupsImpl extends Groups {
|
|
400
165
|
|
401
166
|
// dispatch event, group removed
|
402
167
|
this.dispatch({
|
403
|
-
type:
|
168
|
+
type: GroupsEvent.REMOVED,
|
404
169
|
data: group
|
405
170
|
})
|
406
171
|
|
@@ -1,86 +1,19 @@
|
|
1
|
-
import { AccessGroupDto } from "../../dto/accessGroupResponse"
|
2
|
-
import { UserDto } from "../../dto/userInfoResponse"
|
3
1
|
import { EventDispatcher } from "../../events"
|
4
|
-
import {
|
5
|
-
import { WorkspaceId } from "../workspaces/workspaces"
|
6
|
-
import { Workspace } from "../workspaces/workspace"
|
7
|
-
|
8
|
-
/**
|
9
|
-
* Group id.
|
10
|
-
*/
|
11
|
-
export type GroupId = string
|
2
|
+
import { Group, GroupId } from "./group"
|
12
3
|
|
13
4
|
/**
|
14
5
|
* Group event.
|
15
6
|
*/
|
16
|
-
export enum
|
7
|
+
export enum GroupsEvent {
|
17
8
|
ADDED = "added",
|
18
9
|
REMOVED = "removed",
|
19
10
|
UPDATED = "updated"
|
20
11
|
}
|
21
12
|
|
22
|
-
/**
|
23
|
-
* Group.
|
24
|
-
*/
|
25
|
-
export abstract class Group extends EventDispatcher<GroupEvent, Group> {
|
26
|
-
|
27
|
-
/**
|
28
|
-
* Group id.
|
29
|
-
*/
|
30
|
-
abstract get id(): GroupId
|
31
|
-
|
32
|
-
/**
|
33
|
-
* Group information.
|
34
|
-
*/
|
35
|
-
abstract get group(): AccessGroupDto
|
36
|
-
|
37
|
-
/**
|
38
|
-
* Group members.
|
39
|
-
*/
|
40
|
-
abstract get members(): UserDto[]
|
41
|
-
|
42
|
-
/**
|
43
|
-
* Group workspaces.
|
44
|
-
*/
|
45
|
-
abstract get workspaces(): readonly Workspace[]
|
46
|
-
|
47
|
-
/**
|
48
|
-
* Set workspaces.
|
49
|
-
*/
|
50
|
-
abstract setWorkspaces(workspaces: WorkspaceId[]): Promise<void>
|
51
|
-
|
52
|
-
/**
|
53
|
-
* Set name.
|
54
|
-
*/
|
55
|
-
abstract setName(name: string): Promise<void>
|
56
|
-
|
57
|
-
/**
|
58
|
-
* Set permits.
|
59
|
-
*/
|
60
|
-
abstract setPermits(permits: { isAdmin: boolean }): Promise<void>
|
61
|
-
|
62
|
-
/**
|
63
|
-
* Set members.
|
64
|
-
*/
|
65
|
-
abstract setMembersIds(members: UserId[]): Promise<void>
|
66
|
-
|
67
|
-
/**
|
68
|
-
* Remove members.
|
69
|
-
* @param members
|
70
|
-
*/
|
71
|
-
abstract removeMembers(members: UserId[]): Promise<void>
|
72
|
-
|
73
|
-
/**
|
74
|
-
* Remove workspaces.
|
75
|
-
* @param workspaces
|
76
|
-
*/
|
77
|
-
abstract removeWorkspaces(workspaces: WorkspaceId[]): Promise<void>
|
78
|
-
}
|
79
|
-
|
80
13
|
/**
|
81
14
|
* Groups storage.
|
82
15
|
*/
|
83
|
-
export abstract class Groups extends EventDispatcher<
|
16
|
+
export abstract class Groups extends EventDispatcher<GroupsEvent, Group> {
|
84
17
|
|
85
18
|
/**
|
86
19
|
* Collection.
|
@@ -1,9 +1,10 @@
|
|
1
1
|
import { Workspaces } from "../workspaces/workspaces"
|
2
2
|
import { OrganizationId } from "./organizations"
|
3
|
-
import {
|
3
|
+
import { Groups } from "../groups/groups"
|
4
4
|
import { Chats } from "../chats/chats"
|
5
5
|
import { EventDispatcher } from "../../events"
|
6
6
|
import { UserDto } from "../../dto/userInfoResponse"
|
7
|
+
import { GroupId } from "../groups/group"
|
7
8
|
|
8
9
|
|
9
10
|
/**
|