@neuralinnovations/dataisland-sdk 0.0.1-dev21 → 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 -55
- package/dist/src/storages/groups/groups.d.ts.map +1 -1
- package/dist/src/storages/groups/groups.impl.d.ts +2 -33
- package/dist/src/storages/groups/groups.impl.d.ts.map +1 -1
- package/dist/src/storages/groups/groups.impl.js +14 -175
- 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 -228
- package/src/storages/groups/groups.ts +3 -64
- package/src/storages/organizations/organization.ts +2 -1
@@ -1,230 +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
|
-
|
18
|
-
export class GroupImpl extends Group implements Disposable {
|
19
|
-
private _isDisposed: boolean = false
|
20
|
-
private _content?: AccessGroupDto
|
21
|
-
private _members?: UserDto[]
|
22
|
-
private _workspaces: Workspace[] = []
|
23
|
-
|
24
|
-
constructor(
|
25
|
-
private readonly context: Context,
|
26
|
-
public readonly organization: Organization
|
27
|
-
) {
|
28
|
-
super()
|
29
|
-
}
|
30
|
-
|
31
|
-
async initFrom(id: GroupId): Promise<Group> {
|
32
|
-
await this.reloadGroup(id)
|
33
|
-
await this.reloadWorkspaces()
|
34
|
-
return this
|
35
|
-
}
|
36
|
-
|
37
|
-
async reloadGroup(id: GroupId): Promise<void> {
|
38
|
-
// fetch group
|
39
|
-
const response = await this.context.resolve(RpcService)
|
40
|
-
?.requestBuilder("api/v1/AccessGroups")
|
41
|
-
.searchParam("groupId", id)
|
42
|
-
.sendGet()
|
43
|
-
|
44
|
-
// check response status
|
45
|
-
if (ResponseUtils.isFail(response)) {
|
46
|
-
await ResponseUtils.throwError(`Failed to get group: ${id}, organization: ${this.organization.id}`, response)
|
47
|
-
}
|
48
|
-
|
49
|
-
// parse group from the server's response
|
50
|
-
const group = (await response!.json()) as AccessGroupResponse
|
51
|
-
// init group
|
52
|
-
this._content = group.group
|
53
|
-
this._members = group.members
|
54
|
-
}
|
55
|
-
|
56
|
-
async reloadWorkspaces(): Promise<void> {
|
57
|
-
const groupWorkspaces = await this.loadWorkspaces(this.id)
|
58
|
-
this._workspaces.length = 0
|
59
|
-
this._workspaces.push(...groupWorkspaces)
|
60
|
-
}
|
61
|
-
|
62
|
-
async loadWorkspaces(groupId: GroupId): Promise<Workspace[]> {
|
63
|
-
// fetch workspaces
|
64
|
-
const response = await this.context.resolve(RpcService)
|
65
|
-
?.requestBuilder("api/v1/AccessGroups/workspaces")
|
66
|
-
.searchParam("groupId", groupId)
|
67
|
-
.sendGet()
|
68
|
-
|
69
|
-
if (ResponseUtils.isFail(response)) {
|
70
|
-
await ResponseUtils.throwError(`Failed to get workspaces for group: ${this.id}, organization: ${this.organization.id}`, response)
|
71
|
-
}
|
72
|
-
|
73
|
-
// parse workspaces from the server's response
|
74
|
-
const workspaces = (await response!.json()) as WorkspacesResponse
|
75
|
-
|
76
|
-
// get workspaces
|
77
|
-
const result: Workspace[] = []
|
78
|
-
for (const workspaceDto of workspaces.workspaces) {
|
79
|
-
result.push(this.organization.workspaces.get(workspaceDto.id))
|
80
|
-
}
|
81
|
-
|
82
|
-
return result
|
83
|
-
}
|
84
|
-
|
85
|
-
get id(): GroupId {
|
86
|
-
if (this._content) {
|
87
|
-
return this._content.id
|
88
|
-
}
|
89
|
-
throw new Error("Access group is not loaded.")
|
90
|
-
}
|
91
|
-
|
92
|
-
get group(): AccessGroupDto {
|
93
|
-
if (this._content) {
|
94
|
-
return this._content
|
95
|
-
}
|
96
|
-
throw new Error("Access group is not loaded.")
|
97
|
-
}
|
98
|
-
|
99
|
-
get workspaces(): readonly Workspace[] {
|
100
|
-
return this._workspaces
|
101
|
-
}
|
102
|
-
|
103
|
-
get members(): UserDto[] {
|
104
|
-
if (this._members) {
|
105
|
-
return this._members
|
106
|
-
}
|
107
|
-
throw new Error("Access group is not loaded.")
|
108
|
-
}
|
109
|
-
|
110
|
-
async setName(name: string): Promise<void> {
|
111
|
-
if (name === undefined || name === null) {
|
112
|
-
throw new Error("Groups change, name is undefined or null")
|
113
|
-
}
|
114
|
-
if (name.length === 0 || name.trim().length === 0) {
|
115
|
-
throw new Error("Groups change, name is empty")
|
116
|
-
}
|
117
|
-
// send request to the server
|
118
|
-
const response = await this.context
|
119
|
-
.resolve(RpcService)
|
120
|
-
?.requestBuilder("api/v1/AccessGroups/name")
|
121
|
-
.sendPutJson({
|
122
|
-
groupId: this.id,
|
123
|
-
name: name
|
124
|
-
})
|
125
|
-
|
126
|
-
// check response status
|
127
|
-
if (ResponseUtils.isFail(response)) {
|
128
|
-
await ResponseUtils.throwError(`Failed to change group name, group: ${this.id}, organization: ${this.organization.id}`, response)
|
129
|
-
}
|
130
|
-
|
131
|
-
// change name
|
132
|
-
if (this._content) {
|
133
|
-
this._content.name = name
|
134
|
-
}
|
135
|
-
}
|
136
|
-
|
137
|
-
async setPermits(permits: { isAdmin: boolean }): Promise<void> {
|
138
|
-
// send request to the server
|
139
|
-
const response = await this.context
|
140
|
-
.resolve(RpcService)
|
141
|
-
?.requestBuilder("api/v1/AccessGroups/permits")
|
142
|
-
.sendPutJson({
|
143
|
-
groupId: this.id,
|
144
|
-
permits: permits
|
145
|
-
})
|
146
|
-
|
147
|
-
if (ResponseUtils.isFail(response)) {
|
148
|
-
await ResponseUtils.throwError(`Failed to change group permits, group: ${this.id}, organization: ${this.organization.id}`, response)
|
149
|
-
}
|
150
|
-
}
|
151
|
-
|
152
|
-
async setWorkspaces(workspaces: string[]): Promise<void> {
|
153
|
-
if (workspaces === null || workspaces === undefined) {
|
154
|
-
throw new Error("Group add workspaces, workspaces is undefined or null")
|
155
|
-
}
|
156
|
-
|
157
|
-
// send request to the server
|
158
|
-
const response = await this.context
|
159
|
-
.resolve(RpcService)
|
160
|
-
?.requestBuilder("api/v1/AccessGroups/workspaces")
|
161
|
-
.sendPutJson({
|
162
|
-
groupId: this.id,
|
163
|
-
actualWorkspaceIds: workspaces
|
164
|
-
})
|
165
|
-
|
166
|
-
if (ResponseUtils.isFail(response)) {
|
167
|
-
await ResponseUtils.throwError(`Failed to set workspaces for group: ${this.id}, organization: ${this.organization.id}`, response)
|
168
|
-
}
|
169
|
-
|
170
|
-
// reload workspaces
|
171
|
-
await this.reloadWorkspaces()
|
172
|
-
}
|
173
|
-
|
174
|
-
async setMembersIds(members: UserId[]) {
|
175
|
-
if (members === null || members === undefined) {
|
176
|
-
throw new Error("Group setMembersIds, members is undefined or null")
|
177
|
-
}
|
178
|
-
|
179
|
-
// send request to the server
|
180
|
-
const response = await this.context
|
181
|
-
.resolve(RpcService)
|
182
|
-
?.requestBuilder("api/v1/AccessGroups/members")
|
183
|
-
.sendPutJson({
|
184
|
-
groupId: this.id,
|
185
|
-
memberIds: members
|
186
|
-
})
|
187
|
-
|
188
|
-
if (ResponseUtils.isFail(response)) {
|
189
|
-
await ResponseUtils.throwError(`Failed to set members for group: ${this.id}, organization: ${this.organization.id}`, response)
|
190
|
-
}
|
191
|
-
|
192
|
-
// reload group
|
193
|
-
await this.reloadGroup(this.id)
|
194
|
-
}
|
195
|
-
|
196
|
-
async removeMembers(members: UserId[]): Promise<void> {
|
197
|
-
// check members
|
198
|
-
if (members === null || members === undefined) {
|
199
|
-
throw new Error("Group removeMembers, members is undefined or null")
|
200
|
-
}
|
201
|
-
|
202
|
-
// make set of members
|
203
|
-
const groupMembers = new Set(this.members.map(m => m.id))
|
204
|
-
|
205
|
-
// check argument
|
206
|
-
if (!members.every(m => groupMembers.has(m))) {
|
207
|
-
const notExistingMembers = members.filter(memberId => !groupMembers.has(memberId))
|
208
|
-
throw new Error(`Group removeMembers, members contains not existing members: ${notExistingMembers}`)
|
209
|
-
}
|
210
|
-
|
211
|
-
// remove members
|
212
|
-
for (const id of members) {
|
213
|
-
groupMembers.delete(id)
|
214
|
-
}
|
215
|
-
|
216
|
-
// send request to the server
|
217
|
-
await this.setMembersIds(Array.from(groupMembers))
|
218
|
-
}
|
219
|
-
|
220
|
-
get isDisposed(): boolean {
|
221
|
-
return this._isDisposed
|
222
|
-
}
|
223
|
-
|
224
|
-
dispose(): void {
|
225
|
-
this._isDisposed = true
|
226
|
-
}
|
227
|
-
}
|
10
|
+
import { Group, GroupId } from "./group"
|
11
|
+
import { GroupImpl } from "./group.impl"
|
228
12
|
|
229
13
|
export class GroupsImpl extends Groups {
|
230
14
|
|
@@ -281,19 +65,24 @@ export class GroupsImpl extends Groups {
|
|
281
65
|
// parse groups from the server's response
|
282
66
|
const groups = (await response!.json()) as AccessGroupsResponse
|
283
67
|
|
68
|
+
const wait: Promise<Group>[] = []
|
69
|
+
|
284
70
|
// init groups
|
285
71
|
for (const gr of groups.groups) {
|
286
72
|
// create group implementation
|
287
|
-
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
|
+
}
|
288
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) {
|
289
84
|
// add group to the collection
|
290
85
|
this._groups.push(group)
|
291
|
-
|
292
|
-
// dispatch event
|
293
|
-
this.dispatch({
|
294
|
-
type: GroupEvent.ADDED,
|
295
|
-
data: group
|
296
|
-
})
|
297
86
|
}
|
298
87
|
}
|
299
88
|
|
@@ -333,7 +122,7 @@ export class GroupsImpl extends Groups {
|
|
333
122
|
|
334
123
|
// dispatch event
|
335
124
|
this.dispatch({
|
336
|
-
type:
|
125
|
+
type: GroupsEvent.ADDED,
|
337
126
|
data: group
|
338
127
|
})
|
339
128
|
|
@@ -376,7 +165,7 @@ export class GroupsImpl extends Groups {
|
|
376
165
|
|
377
166
|
// dispatch event, group removed
|
378
167
|
this.dispatch({
|
379
|
-
type:
|
168
|
+
type: GroupsEvent.REMOVED,
|
380
169
|
data: group
|
381
170
|
})
|
382
171
|
|
@@ -1,80 +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
13
|
/**
|
75
14
|
* Groups storage.
|
76
15
|
*/
|
77
|
-
export abstract class Groups extends EventDispatcher<
|
16
|
+
export abstract class Groups extends EventDispatcher<GroupsEvent, Group> {
|
78
17
|
|
79
18
|
/**
|
80
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
|
/**
|