@neuralinnovations/dataisland-sdk 0.0.1-dev2 → 0.0.1-dev21
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/LICENSE +201 -0
- package/README.md +306 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/package.json +100 -0
- package/dist/src/appBuilder.d.ts +44 -0
- package/dist/src/appBuilder.d.ts.map +1 -0
- package/dist/src/appBuilder.js +10 -0
- package/dist/src/appBuilder.js.map +1 -0
- package/dist/src/commands/startCommandHandler.d.ts +7 -0
- package/dist/src/commands/startCommandHandler.d.ts.map +1 -0
- package/dist/src/commands/startCommandHandler.js +17 -0
- package/dist/src/commands/startCommandHandler.js.map +1 -0
- package/dist/src/context.d.ts +23 -0
- package/dist/src/context.d.ts.map +1 -0
- package/dist/src/context.js +31 -0
- package/dist/src/context.js.map +1 -0
- package/dist/src/credentials.d.ts +28 -0
- package/dist/src/credentials.d.ts.map +1 -0
- package/dist/src/credentials.js +70 -0
- package/dist/src/credentials.js.map +1 -0
- package/dist/src/dataIslandApp.d.ts +50 -0
- package/dist/src/dataIslandApp.d.ts.map +1 -0
- package/dist/src/dataIslandApp.js +10 -0
- package/dist/src/dataIslandApp.js.map +1 -0
- package/dist/src/disposable.d.ts +84 -0
- package/dist/src/disposable.d.ts.map +1 -0
- package/dist/src/disposable.js +147 -0
- package/dist/src/disposable.js.map +1 -0
- package/dist/src/dto/accessGroupResponse.d.ts +27 -0
- package/dist/src/dto/accessGroupResponse.d.ts.map +1 -0
- package/dist/src/dto/accessGroupResponse.js +3 -0
- package/dist/src/dto/accessGroupResponse.js.map +1 -0
- package/dist/src/dto/chatResponse.d.ts +78 -0
- package/dist/src/dto/chatResponse.d.ts.map +1 -0
- package/dist/src/dto/chatResponse.js +45 -0
- package/dist/src/dto/chatResponse.js.map +1 -0
- package/dist/src/dto/userInfoResponse.d.ts +42 -0
- package/dist/src/dto/userInfoResponse.d.ts.map +1 -0
- package/dist/src/dto/userInfoResponse.js +3 -0
- package/dist/src/dto/userInfoResponse.js.map +1 -0
- package/dist/src/dto/workspacesResponse.d.ts +43 -0
- package/dist/src/dto/workspacesResponse.d.ts.map +1 -0
- package/dist/src/dto/workspacesResponse.js +3 -0
- package/dist/src/dto/workspacesResponse.js.map +1 -0
- package/dist/src/events.d.ts +17 -0
- package/dist/src/events.d.ts.map +1 -0
- package/dist/src/events.js +52 -0
- package/dist/src/events.js.map +1 -0
- package/dist/src/index.d.ts +58 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +91 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/internal/app.impl.d.ts +28 -0
- package/dist/src/internal/app.impl.d.ts.map +1 -0
- package/dist/src/internal/app.impl.js +151 -0
- package/dist/src/internal/app.impl.js.map +1 -0
- package/dist/src/internal/appBuilder.impl.d.ts +27 -0
- package/dist/src/internal/appBuilder.impl.d.ts.map +1 -0
- package/dist/src/internal/appBuilder.impl.js +71 -0
- package/dist/src/internal/appBuilder.impl.js.map +1 -0
- package/dist/src/internal/createApp.impl.d.ts +4 -0
- package/dist/src/internal/createApp.impl.d.ts.map +1 -0
- package/dist/src/internal/createApp.impl.js +11 -0
- package/dist/src/internal/createApp.impl.js.map +1 -0
- package/dist/src/internal/registry.d.ts +66 -0
- package/dist/src/internal/registry.d.ts.map +1 -0
- package/dist/src/internal/registry.js +114 -0
- package/dist/src/internal/registry.js.map +1 -0
- package/dist/src/middleware.d.ts +5 -0
- package/dist/src/middleware.d.ts.map +1 -0
- package/dist/src/middleware.js +3 -0
- package/dist/src/middleware.js.map +1 -0
- package/dist/src/services/commandService.d.ts +18 -0
- package/dist/src/services/commandService.d.ts.map +1 -0
- package/dist/src/services/commandService.js +40 -0
- package/dist/src/services/commandService.js.map +1 -0
- package/dist/src/services/credentialService.d.ts +9 -0
- package/dist/src/services/credentialService.d.ts.map +1 -0
- package/dist/src/services/credentialService.js +26 -0
- package/dist/src/services/credentialService.js.map +1 -0
- package/dist/src/services/middlewareService.d.ts +9 -0
- package/dist/src/services/middlewareService.d.ts.map +1 -0
- package/dist/src/services/middlewareService.js +34 -0
- package/dist/src/services/middlewareService.js.map +1 -0
- package/dist/src/services/organizationService.d.ts +10 -0
- package/dist/src/services/organizationService.d.ts.map +1 -0
- package/dist/src/services/organizationService.js +19 -0
- package/dist/src/services/organizationService.js.map +1 -0
- package/dist/src/services/requestBuilder.d.ts +17 -0
- package/dist/src/services/requestBuilder.d.ts.map +1 -0
- package/dist/src/services/requestBuilder.js +104 -0
- package/dist/src/services/requestBuilder.js.map +1 -0
- package/dist/src/services/responseUtils.d.ts +6 -0
- package/dist/src/services/responseUtils.d.ts.map +1 -0
- package/dist/src/services/responseUtils.js +32 -0
- package/dist/src/services/responseUtils.js.map +1 -0
- package/dist/src/services/rpcService.d.ts +77 -0
- package/dist/src/services/rpcService.d.ts.map +1 -0
- package/dist/src/services/rpcService.js +125 -0
- package/dist/src/services/rpcService.js.map +1 -0
- package/dist/src/services/service.d.ts +21 -0
- package/dist/src/services/service.d.ts.map +1 -0
- package/dist/src/services/service.js +41 -0
- package/dist/src/services/service.js.map +1 -0
- package/dist/src/services/userProfileService.d.ts +8 -0
- package/dist/src/services/userProfileService.d.ts.map +1 -0
- package/dist/src/services/userProfileService.js +32 -0
- package/dist/src/services/userProfileService.js.map +1 -0
- package/dist/src/storages/chats/answer.d.ts +40 -0
- package/dist/src/storages/chats/answer.d.ts.map +1 -0
- package/dist/src/storages/chats/answer.impl.d.ts +24 -0
- package/dist/src/storages/chats/answer.impl.d.ts.map +1 -0
- package/dist/src/storages/chats/answer.impl.js +130 -0
- package/dist/src/storages/chats/answer.impl.js.map +1 -0
- package/dist/src/storages/chats/answer.js +14 -0
- package/dist/src/storages/chats/answer.js.map +1 -0
- package/dist/src/storages/chats/chat.d.ts +39 -0
- package/dist/src/storages/chats/chat.d.ts.map +1 -0
- package/dist/src/storages/chats/chat.impl.d.ts +24 -0
- package/dist/src/storages/chats/chat.impl.d.ts.map +1 -0
- package/dist/src/storages/chats/chat.impl.js +98 -0
- package/dist/src/storages/chats/chat.impl.js.map +1 -0
- package/dist/src/storages/chats/chat.js +12 -0
- package/dist/src/storages/chats/chat.js.map +1 -0
- package/dist/src/storages/chats/chats.d.ts +40 -0
- package/dist/src/storages/chats/chats.d.ts.map +1 -0
- package/dist/src/storages/chats/chats.impl.d.ts +18 -0
- package/dist/src/storages/chats/chats.impl.d.ts.map +1 -0
- package/dist/src/storages/chats/chats.impl.js +102 -0
- package/dist/src/storages/chats/chats.impl.js.map +1 -0
- package/dist/src/storages/chats/chats.js +16 -0
- package/dist/src/storages/chats/chats.js.map +1 -0
- package/dist/src/storages/files/file.d.ts +31 -0
- package/dist/src/storages/files/file.d.ts.map +1 -0
- package/dist/src/storages/files/file.impl.d.ts +21 -0
- package/dist/src/storages/files/file.impl.d.ts.map +1 -0
- package/dist/src/storages/files/file.impl.js +64 -0
- package/dist/src/storages/files/file.impl.js.map +1 -0
- package/dist/src/storages/files/file.js +11 -0
- package/dist/src/storages/files/file.js.map +1 -0
- package/dist/src/storages/files/files.d.ts +34 -0
- package/dist/src/storages/files/files.d.ts.map +1 -0
- package/dist/src/storages/files/files.impl.d.ts +22 -0
- package/dist/src/storages/files/files.impl.d.ts.map +1 -0
- package/dist/src/storages/files/files.impl.js +140 -0
- package/dist/src/storages/files/files.impl.js.map +1 -0
- package/dist/src/storages/files/files.js +20 -0
- package/dist/src/storages/files/files.js.map +1 -0
- package/dist/src/storages/files/filesPage.d.ts +28 -0
- package/dist/src/storages/files/filesPage.d.ts.map +1 -0
- package/dist/src/storages/files/filesPage.impl.d.ts +15 -0
- package/dist/src/storages/files/filesPage.impl.d.ts.map +1 -0
- package/dist/src/storages/files/filesPage.impl.js +38 -0
- package/dist/src/storages/files/filesPage.impl.js.map +1 -0
- package/dist/src/storages/files/filesPage.js +10 -0
- package/dist/src/storages/files/filesPage.js.map +1 -0
- package/dist/src/storages/groups/groups.d.ts +91 -0
- package/dist/src/storages/groups/groups.d.ts.map +1 -0
- package/dist/src/storages/groups/groups.impl.d.ts +61 -0
- package/dist/src/storages/groups/groups.impl.d.ts.map +1 -0
- package/dist/src/storages/groups/groups.impl.js +293 -0
- package/dist/src/storages/groups/groups.impl.js.map +1 -0
- package/dist/src/storages/groups/groups.js +26 -0
- package/dist/src/storages/groups/groups.js.map +1 -0
- package/dist/src/storages/organizations/organization.d.ts +54 -0
- package/dist/src/storages/organizations/organization.d.ts.map +1 -0
- package/dist/src/storages/organizations/organization.impl.d.ts +32 -0
- package/dist/src/storages/organizations/organization.impl.d.ts.map +1 -0
- package/dist/src/storages/organizations/organization.impl.js +120 -0
- package/dist/src/storages/organizations/organization.impl.js.map +1 -0
- package/dist/src/storages/organizations/organization.js +18 -0
- package/dist/src/storages/organizations/organization.js.map +1 -0
- package/dist/src/storages/organizations/organizations.d.ts +46 -0
- package/dist/src/storages/organizations/organizations.d.ts.map +1 -0
- package/dist/src/storages/organizations/organizations.impl.d.ts +38 -0
- package/dist/src/storages/organizations/organizations.impl.d.ts.map +1 -0
- package/dist/src/storages/organizations/organizations.impl.js +151 -0
- package/dist/src/storages/organizations/organizations.impl.js.map +1 -0
- package/dist/src/storages/organizations/organizations.js +20 -0
- package/dist/src/storages/organizations/organizations.js.map +1 -0
- package/dist/src/storages/user/userProfile.d.ts +32 -0
- package/dist/src/storages/user/userProfile.d.ts.map +1 -0
- package/dist/src/storages/user/userProfile.impl.d.ts +13 -0
- package/dist/src/storages/user/userProfile.impl.d.ts.map +1 -0
- package/dist/src/storages/user/userProfile.impl.js +51 -0
- package/dist/src/storages/user/userProfile.impl.js.map +1 -0
- package/dist/src/storages/user/userProfile.js +12 -0
- package/dist/src/storages/user/userProfile.js.map +1 -0
- package/dist/src/storages/workspaces/workspace.d.ts +44 -0
- package/dist/src/storages/workspaces/workspace.d.ts.map +1 -0
- package/dist/src/storages/workspaces/workspace.impl.d.ts +23 -0
- package/dist/src/storages/workspaces/workspace.impl.d.ts.map +1 -0
- package/dist/src/storages/workspaces/workspace.impl.js +98 -0
- package/dist/src/storages/workspaces/workspace.impl.js.map +1 -0
- package/dist/src/storages/workspaces/workspace.js +18 -0
- package/dist/src/storages/workspaces/workspace.js.map +1 -0
- package/dist/src/storages/workspaces/workspaces.d.ts +47 -0
- package/dist/src/storages/workspaces/workspaces.d.ts.map +1 -0
- package/dist/src/storages/workspaces/workspaces.impl.d.ts +33 -0
- package/dist/src/storages/workspaces/workspaces.impl.d.ts.map +1 -0
- package/dist/src/storages/workspaces/workspaces.impl.js +157 -0
- package/dist/src/storages/workspaces/workspaces.impl.js.map +1 -0
- package/dist/src/storages/workspaces/workspaces.js +19 -0
- package/dist/src/storages/workspaces/workspaces.js.map +1 -0
- package/dist/src/unitTest.d.ts +12 -0
- package/dist/src/unitTest.d.ts.map +1 -0
- package/dist/src/unitTest.js +44 -0
- package/dist/src/unitTest.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +43 -4
- package/src/appBuilder.ts +6 -6
- package/src/commands/startCommandHandler.ts +2 -2
- package/src/context.ts +5 -4
- package/src/credentials.ts +29 -7
- package/src/{appSdk.ts → dataIslandApp.ts} +7 -7
- package/src/disposable.ts +20 -8
- package/src/dto/accessGroupResponse.ts +35 -0
- package/src/dto/chatResponse.ts +103 -0
- package/src/dto/userInfoResponse.ts +15 -3
- package/src/dto/workspacesResponse.ts +49 -0
- package/src/events.ts +13 -13
- package/src/index.ts +41 -20
- package/src/internal/app.impl.ts +28 -31
- package/src/internal/appBuilder.impl.ts +16 -16
- package/src/internal/createApp.impl.ts +5 -5
- package/src/internal/registry.ts +54 -6
- package/src/services/commandService.ts +3 -3
- package/src/services/credentialService.ts +3 -3
- package/src/services/middlewareService.ts +4 -4
- package/src/services/organizationService.ts +18 -116
- package/src/services/requestBuilder.ts +40 -15
- package/src/services/responseUtils.ts +32 -0
- package/src/services/rpcService.ts +28 -11
- package/src/services/service.ts +10 -8
- package/src/services/userProfileService.ts +18 -66
- package/src/storages/chats/answer.impl.ts +186 -0
- package/src/storages/chats/answer.ts +55 -0
- package/src/storages/chats/chat.impl.ts +126 -0
- package/src/storages/chats/chat.ts +49 -0
- package/src/storages/chats/chats.impl.ts +142 -0
- package/src/storages/chats/chats.ts +47 -0
- package/src/storages/files/file.impl.ts +87 -0
- package/src/storages/files/file.ts +40 -0
- package/src/storages/files/files.impl.ts +191 -0
- package/src/storages/files/files.ts +39 -0
- package/src/storages/files/filesPage.impl.ts +37 -0
- package/src/storages/files/filesPage.ts +33 -0
- package/src/storages/groups/groups.impl.ts +386 -0
- package/src/storages/groups/groups.ts +106 -0
- package/src/storages/organizations/organization.impl.ts +163 -0
- package/src/storages/organizations/organization.ts +67 -0
- package/src/storages/organizations/organizations.impl.ts +197 -0
- package/src/storages/{organizations.ts → organizations/organizations.ts} +8 -28
- package/src/storages/user/userProfile.impl.ts +56 -0
- package/src/storages/{userProfile.ts → user/userProfile.ts} +2 -2
- package/src/storages/workspaces/workspace.impl.ts +129 -0
- package/src/storages/workspaces/workspace.ts +54 -0
- package/src/storages/workspaces/workspaces.impl.ts +212 -0
- package/src/storages/workspaces/workspaces.ts +53 -0
- package/src/unitTest.ts +12 -1
- package/.browserslistrc +0 -5
- package/.editorconfig +0 -22
- package/.eslintrc.json +0 -44
- package/.github/workflows/publish-npm.yml +0 -28
- package/.prettierignore +0 -1
- package/.prettierrc +0 -11
- package/.yarnrc +0 -2
- package/babel.config.js +0 -6
- package/jest.config.ts +0 -199
- package/jest.setup.ts +0 -2
- package/src/services/organizationImpl.ts +0 -51
- package/src/services/organizationsImpl.ts +0 -55
- package/src/types.ts +0 -86
- package/test/commands.test.ts +0 -24
- package/test/disposable.test.ts +0 -39
- package/test/events.test.ts +0 -151
- package/test/index.test.ts +0 -163
- package/test/registry.test.ts +0 -44
- package/test/services.test.ts +0 -56
- package/test/setup.ts +0 -2
- package/test/unitTest.test.ts +0 -21
- package/tsconfig.json +0 -31
@@ -0,0 +1,103 @@
|
|
1
|
+
export interface SourceDto {
|
2
|
+
id: string;
|
3
|
+
name: string;
|
4
|
+
url: string;
|
5
|
+
content: string;
|
6
|
+
page: number;
|
7
|
+
}
|
8
|
+
|
9
|
+
export interface AnswerDto {
|
10
|
+
id: string;
|
11
|
+
chatId: string;
|
12
|
+
question: string;
|
13
|
+
context: string;
|
14
|
+
sources: SourceDto[];
|
15
|
+
timestamp: number;
|
16
|
+
}
|
17
|
+
|
18
|
+
export interface ChatDto {
|
19
|
+
id: string;
|
20
|
+
name: string;
|
21
|
+
createdAt: number;
|
22
|
+
modifiedAt: number;
|
23
|
+
userId: string;
|
24
|
+
organizationId: string;
|
25
|
+
workspaceId: string;
|
26
|
+
answers: AnswerDto[];
|
27
|
+
}
|
28
|
+
|
29
|
+
export interface ChatListResponse {
|
30
|
+
chats: ChatDto[]
|
31
|
+
}
|
32
|
+
|
33
|
+
export enum AnswerStatus {
|
34
|
+
RUNNING = 0,
|
35
|
+
SUCCESS = 1,
|
36
|
+
CANCELED = 2,
|
37
|
+
FAIL = 3,
|
38
|
+
}
|
39
|
+
|
40
|
+
export interface AnswerStepDto {
|
41
|
+
id: string;
|
42
|
+
type: StepType;
|
43
|
+
status: StepStatus;
|
44
|
+
start_at: string;
|
45
|
+
end_at: string;
|
46
|
+
tokens: string[];
|
47
|
+
sources: SourceDto[];
|
48
|
+
}
|
49
|
+
|
50
|
+
export interface FetchAnswerResponse {
|
51
|
+
id: string;
|
52
|
+
status: AnswerStatus;
|
53
|
+
steps: AnswerStepDto[];
|
54
|
+
}
|
55
|
+
|
56
|
+
export interface FetchTokensResponse {
|
57
|
+
id: string;
|
58
|
+
step_id: string;
|
59
|
+
step_status: number;
|
60
|
+
step_tokens: string[];
|
61
|
+
}
|
62
|
+
|
63
|
+
export interface AnswerSourcesResponse {
|
64
|
+
chat_uid: string;
|
65
|
+
uid: string;
|
66
|
+
step_id: string;
|
67
|
+
sources: SourceDto[];
|
68
|
+
}
|
69
|
+
|
70
|
+
export enum StepStatus {
|
71
|
+
RUNNING = 0,
|
72
|
+
SUCCESS = 1,
|
73
|
+
FAIL = 2,
|
74
|
+
CANCELED = 3,
|
75
|
+
}
|
76
|
+
|
77
|
+
export enum StepType {
|
78
|
+
PREPARE = 0,
|
79
|
+
SOURCES = 1,
|
80
|
+
GENERATE_ANSWER = 6,
|
81
|
+
FINALIZE_RESULT = 9,
|
82
|
+
DONE = 10,
|
83
|
+
}
|
84
|
+
|
85
|
+
export class StepTypeInfo {
|
86
|
+
public static hasTokens(type: StepType): boolean {
|
87
|
+
switch (type) {
|
88
|
+
case StepType.GENERATE_ANSWER:
|
89
|
+
case StepType.DONE:
|
90
|
+
case StepType.FINALIZE_RESULT:
|
91
|
+
return true
|
92
|
+
}
|
93
|
+
return false
|
94
|
+
}
|
95
|
+
|
96
|
+
public static hasSources(type: StepType): boolean {
|
97
|
+
switch (type) {
|
98
|
+
case StepType.SOURCES:
|
99
|
+
return true
|
100
|
+
}
|
101
|
+
return false
|
102
|
+
}
|
103
|
+
}
|
@@ -1,3 +1,7 @@
|
|
1
|
+
import { WorkspaceDto } from "./workspacesResponse"
|
2
|
+
import { UserId } from "../storages/user/userProfile"
|
3
|
+
import { OrganizationId } from "../storages/organizations/organizations"
|
4
|
+
|
1
5
|
export interface UserInfoResponse {
|
2
6
|
adminInOrganization: string[]
|
3
7
|
organizations: OrganizationDto[]
|
@@ -5,12 +9,12 @@ export interface UserInfoResponse {
|
|
5
9
|
}
|
6
10
|
|
7
11
|
export interface UserDto {
|
8
|
-
id:
|
12
|
+
id: UserId
|
9
13
|
isDeleted: boolean
|
10
14
|
created_at: number
|
11
15
|
modified_at: number
|
12
16
|
profile: ProfileDto
|
13
|
-
settings
|
17
|
+
settings?: UserSettings | null
|
14
18
|
}
|
15
19
|
|
16
20
|
export interface ProfileDto {
|
@@ -29,9 +33,17 @@ export interface OrganizationProfileDto {
|
|
29
33
|
}
|
30
34
|
|
31
35
|
export interface OrganizationDto {
|
32
|
-
id:
|
36
|
+
id: OrganizationId
|
33
37
|
createdAt: number
|
34
38
|
modifiedAt: number
|
35
39
|
membersCount: number
|
36
40
|
profile: OrganizationProfileDto
|
37
41
|
}
|
42
|
+
|
43
|
+
export interface OrganizationWorkspaces extends OrganizationDto {
|
44
|
+
workspaces: WorkspaceDto[]
|
45
|
+
}
|
46
|
+
|
47
|
+
export interface MembersResponse {
|
48
|
+
members: UserDto
|
49
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import { WorkspaceId } from "../storages/workspaces/workspaces"
|
2
|
+
import { FileId } from "../storages/files/file"
|
3
|
+
|
4
|
+
export interface WorkspaceProfileDto {
|
5
|
+
name: string
|
6
|
+
description: string
|
7
|
+
}
|
8
|
+
|
9
|
+
export interface WorkspaceDto {
|
10
|
+
id: WorkspaceId
|
11
|
+
createdAt: number
|
12
|
+
modifiedAt: number
|
13
|
+
profile: WorkspaceProfileDto
|
14
|
+
}
|
15
|
+
|
16
|
+
export interface WorkspacesResponse {
|
17
|
+
workspaces: WorkspaceDto[]
|
18
|
+
}
|
19
|
+
|
20
|
+
export interface FileUrlDto {
|
21
|
+
url: string
|
22
|
+
}
|
23
|
+
|
24
|
+
export interface FileProgressDto {
|
25
|
+
file_id: FileId
|
26
|
+
file_parts_count: number
|
27
|
+
completed_parts_count: number
|
28
|
+
success: boolean
|
29
|
+
error?: string
|
30
|
+
}
|
31
|
+
|
32
|
+
export interface FileDto {
|
33
|
+
id: string
|
34
|
+
createdAt: number
|
35
|
+
modifiedAt: number
|
36
|
+
name: string
|
37
|
+
description: string
|
38
|
+
url: string
|
39
|
+
hash: string
|
40
|
+
organizationId: string
|
41
|
+
workspaceId: string
|
42
|
+
isProcessedSuccessfully: boolean
|
43
|
+
}
|
44
|
+
|
45
|
+
export interface FileListResponse {
|
46
|
+
files: FileDto[]
|
47
|
+
totalFilesCount: number
|
48
|
+
filesPerPage: number
|
49
|
+
}
|
package/src/events.ts
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
import { type Disposable, DisposableContainer } from
|
1
|
+
import { type Disposable, DisposableContainer } from "./disposable"
|
2
2
|
|
3
|
-
export interface Input<
|
4
|
-
type?:
|
5
|
-
data:
|
3
|
+
export interface Input<EventType, DataType> {
|
4
|
+
type?: EventType
|
5
|
+
data: DataType
|
6
6
|
}
|
7
7
|
|
8
|
-
export interface Event<
|
8
|
+
export interface Event<EventType, DataType> extends Input<EventType, DataType> {
|
9
9
|
unsubscribe: () => void
|
10
10
|
}
|
11
11
|
|
12
|
-
export interface EventSubscriber<
|
13
|
-
subscribe: (callback: (event: Event<
|
12
|
+
export interface EventSubscriber<EventType, DataType> {
|
13
|
+
subscribe: (callback: (event: Event<EventType, DataType>) => void, type?: EventType) => Disposable
|
14
14
|
}
|
15
15
|
|
16
|
-
export class EventDispatcher<
|
16
|
+
export class EventDispatcher<EventType, DataType> implements EventSubscriber<EventType, DataType> {
|
17
17
|
private _listeners: Array<{
|
18
|
-
callback: (value: Event<
|
18
|
+
callback: (value: Event<EventType, DataType>) => void
|
19
19
|
disposable: Disposable
|
20
20
|
}> = []
|
21
21
|
|
22
|
-
dispatch(input: Input<
|
22
|
+
dispatch(input: Input<EventType, DataType>): void {
|
23
23
|
this._listeners.slice().forEach(it => {
|
24
24
|
const value = {
|
25
25
|
type: input.type,
|
@@ -27,16 +27,16 @@ export class EventDispatcher<ET, DT> implements EventSubscriber<ET, DT> {
|
|
27
27
|
unsubscribe: () => {
|
28
28
|
it.disposable.dispose()
|
29
29
|
}
|
30
|
-
} satisfies Event<
|
30
|
+
} satisfies Event<EventType, DataType>
|
31
31
|
it.callback(value)
|
32
32
|
})
|
33
33
|
}
|
34
34
|
|
35
|
-
subscribe(callback: (event: Event<
|
35
|
+
subscribe(callback: (event: Event<EventType, DataType>) => void, type?: EventType): Disposable {
|
36
36
|
const container = new DisposableContainer()
|
37
37
|
if (type !== undefined) {
|
38
38
|
const cb = callback
|
39
|
-
const listener = (evt: Event<
|
39
|
+
const listener = (evt: Event<EventType, DataType>): void => {
|
40
40
|
if (evt.type === type) {
|
41
41
|
cb(evt)
|
42
42
|
}
|
package/src/index.ts
CHANGED
@@ -1,17 +1,35 @@
|
|
1
|
-
import { version } from
|
2
|
-
import { _createApp } from
|
3
|
-
import { type AppBuilder } from
|
4
|
-
import { type
|
1
|
+
import { version } from "../package.json"
|
2
|
+
import { _createApp } from "./internal/createApp.impl"
|
3
|
+
import { type AppBuilder } from "./appBuilder"
|
4
|
+
import { type DataIslandApp } from "./dataIslandApp"
|
5
5
|
|
6
|
-
export * from
|
7
|
-
export * from
|
8
|
-
export * from
|
9
|
-
export * from
|
10
|
-
export * from
|
11
|
-
export * from
|
6
|
+
export * from "./events"
|
7
|
+
export * from "./disposable"
|
8
|
+
export * from "./credentials"
|
9
|
+
export * from "./dataIslandApp"
|
10
|
+
export * from "./appBuilder"
|
11
|
+
export * from "./context"
|
12
|
+
export * from "./middleware"
|
13
|
+
export * from "./dto/chatResponse"
|
14
|
+
export * from "./dto/accessGroupResponse"
|
15
|
+
export * from "./dto/userInfoResponse"
|
16
|
+
export * from "./dto/workspacesResponse"
|
17
|
+
export * from "./storages/organizations/organizations"
|
18
|
+
export * from "./storages/organizations/organization"
|
19
|
+
export * from "./storages/workspaces/workspaces"
|
20
|
+
export * from "./storages/workspaces/workspace"
|
21
|
+
export * from "./storages/groups/groups"
|
22
|
+
export * from "./storages/user/userProfile"
|
23
|
+
export * from "./storages/files/files"
|
24
|
+
export * from "./storages/files/file"
|
25
|
+
export * from "./storages/files/filesPage"
|
26
|
+
export * from "./storages/chats/chats"
|
27
|
+
export * from "./storages/chats/chat"
|
12
28
|
|
13
|
-
|
14
|
-
const
|
29
|
+
// map of apps that are not ready to be used
|
30
|
+
const _appsNotReady = new Map<string, Promise<DataIslandApp>>()
|
31
|
+
// map of apps that are ready to be used
|
32
|
+
const _appsReady = new Map<string, DataIslandApp>()
|
15
33
|
|
16
34
|
/**
|
17
35
|
* Current SDK version.
|
@@ -21,14 +39,17 @@ export const SDK_VERSION = version
|
|
21
39
|
/**
|
22
40
|
* Default DataIsland App name.
|
23
41
|
*/
|
24
|
-
export const DEFAULT_NAME =
|
42
|
+
export const DEFAULT_NAME = "[DEFAULT]"
|
25
43
|
|
26
44
|
/**
|
27
45
|
* Default DataIsland App host.
|
28
46
|
*/
|
29
|
-
export const DEFAULT_HOST =
|
47
|
+
export const DEFAULT_HOST = "https://api.dataisland.com.ua"
|
30
48
|
|
31
|
-
|
49
|
+
/**
|
50
|
+
* Returns a list of DataIsland App instances.
|
51
|
+
*/
|
52
|
+
export function dataIslandInstances(): DataIslandApp[] {
|
32
53
|
return Array.from(_appsReady.values())
|
33
54
|
}
|
34
55
|
|
@@ -39,19 +60,19 @@ export function sdks(): AppSdk[] {
|
|
39
60
|
* @returns A DataIsland App instance.
|
40
61
|
* @example
|
41
62
|
* ```js
|
42
|
-
* import {
|
63
|
+
* import { dataIslandApp, DEFAULT_NAME } from '@neuralinnovations/dataisland-sdk'
|
43
64
|
*
|
44
|
-
* const app = await
|
65
|
+
* const app = await dataIslandApp(DEFAULT_NAME, builder => {
|
45
66
|
* builder.useHost("https://dataisland.com.ua")
|
46
67
|
* builder.useAutomaticDataCollectionEnabled(true)
|
47
68
|
* builder.useCredential(new BasicCredential("email", "password"))
|
48
69
|
* })
|
49
70
|
* ```
|
50
71
|
*/
|
51
|
-
export async function
|
72
|
+
export async function dataIslandApp(
|
52
73
|
name?: string,
|
53
74
|
setup?: (builder: AppBuilder) => Promise<void>
|
54
|
-
): Promise<
|
75
|
+
): Promise<DataIslandApp> {
|
55
76
|
name = name ?? DEFAULT_NAME
|
56
77
|
|
57
78
|
let appPromise = _appsNotReady.get(name)
|
@@ -69,7 +90,7 @@ export async function appSdk(
|
|
69
90
|
} else {
|
70
91
|
if (setup !== undefined) {
|
71
92
|
throw new Error(
|
72
|
-
`
|
93
|
+
`DataIsland ${name} is initializing. You can't setup the same again.`
|
73
94
|
)
|
74
95
|
}
|
75
96
|
}
|
package/src/internal/app.impl.ts
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
import { DEFAULT_HOST } from
|
2
|
-
import { type AppBuilder } from
|
3
|
-
import { AppBuilderImplementation } from
|
4
|
-
import { type Constructor, Registry } from
|
5
|
-
import { Context } from
|
6
|
-
import { DisposableContainer, type Lifetime } from
|
7
|
-
import { type Service, ServiceContext } from
|
8
|
-
import { CredentialService } from
|
9
|
-
import { MiddlewareService } from
|
10
|
-
import { type CredentialBase } from
|
11
|
-
import {
|
12
|
-
import { RpcService } from
|
13
|
-
import { CommandService } from
|
1
|
+
import { DEFAULT_HOST } from "../index"
|
2
|
+
import { type AppBuilder } from "../appBuilder"
|
3
|
+
import { AppBuilderImplementation } from "./appBuilder.impl"
|
4
|
+
import { type Constructor, Registry } from "./registry"
|
5
|
+
import { Context } from "../context"
|
6
|
+
import { DisposableContainer, type Lifetime } from "../disposable"
|
7
|
+
import { type Service, ServiceContext } from "../services/service"
|
8
|
+
import { CredentialService } from "../services/credentialService"
|
9
|
+
import { MiddlewareService } from "../services/middlewareService"
|
10
|
+
import { type CredentialBase } from "../credentials"
|
11
|
+
import { DataIslandApp } from "../dataIslandApp"
|
12
|
+
import { RpcService } from "../services/rpcService"
|
13
|
+
import { CommandService } from "../services/commandService"
|
14
14
|
import {
|
15
15
|
StartCommandHandler,
|
16
16
|
StartCommand
|
17
|
-
} from
|
18
|
-
import { UserProfileService } from
|
19
|
-
import { OrganizationService } from
|
20
|
-
import { Organizations } from
|
21
|
-
import { UserProfile } from
|
22
|
-
import { isUnitTest, UnitTest } from
|
23
|
-
|
24
|
-
export class
|
17
|
+
} from "../commands/startCommandHandler"
|
18
|
+
import { UserProfileService } from "../services/userProfileService"
|
19
|
+
import { OrganizationService } from "../services/organizationService"
|
20
|
+
import { Organizations } from "../storages/organizations/organizations"
|
21
|
+
import { UserProfile } from "../storages/user/userProfile"
|
22
|
+
import { isUnitTest, UnitTest } from "../unitTest"
|
23
|
+
|
24
|
+
export class DataIslandAppImpl extends DataIslandApp {
|
25
25
|
readonly name: string
|
26
26
|
private _host: string = DEFAULT_HOST
|
27
27
|
private _automaticDataCollectionEnabled: boolean = true
|
@@ -104,13 +104,6 @@ export class AppImplementation extends AppSdk {
|
|
104
104
|
return new OrganizationService(context)
|
105
105
|
})
|
106
106
|
|
107
|
-
// register middlewares
|
108
|
-
builder.registerMiddleware(async (req, next) => {
|
109
|
-
req.headers.set('accept', 'text/plain')
|
110
|
-
req.headers.set('content-type', 'application/json')
|
111
|
-
return await next(req)
|
112
|
-
})
|
113
|
-
|
114
107
|
// call customer setup
|
115
108
|
if (setup !== undefined) {
|
116
109
|
await setup(builder)
|
@@ -154,7 +147,9 @@ export class AppImplementation extends AppSdk {
|
|
154
147
|
const waitList: Array<Promise<void>> = []
|
155
148
|
// call onRegister service's callback
|
156
149
|
services.forEach(([serviceContext]) => {
|
157
|
-
|
150
|
+
if (typeof serviceContext.onRegister === "function") {
|
151
|
+
waitList.push(serviceContext.onRegister())
|
152
|
+
}
|
158
153
|
})
|
159
154
|
|
160
155
|
// wait for all services to register
|
@@ -167,7 +162,9 @@ export class AppImplementation extends AppSdk {
|
|
167
162
|
waitList.length = 0
|
168
163
|
// call onStart service's callback
|
169
164
|
services.forEach(([serviceContext]) => {
|
170
|
-
|
165
|
+
if (typeof serviceContext.onStart === "function") {
|
166
|
+
waitList.push(serviceContext.onStart())
|
167
|
+
}
|
171
168
|
})
|
172
169
|
|
173
170
|
// wait for all services to start
|
@@ -181,7 +178,7 @@ export class AppImplementation extends AppSdk {
|
|
181
178
|
|
182
179
|
// log app initialized
|
183
180
|
if (!isUnitTest(UnitTest.DO_NOT_PRINT_INITIALIZED_LOG)) {
|
184
|
-
console.log(`
|
181
|
+
console.log(`DataIsland ${this.name} initialized`)
|
185
182
|
}
|
186
183
|
}
|
187
184
|
}
|
@@ -1,12 +1,12 @@
|
|
1
|
-
import { AppBuilder } from
|
2
|
-
import { DEFAULT_HOST } from
|
3
|
-
import { type CredentialBase, DefaultCredential } from
|
4
|
-
import type { Middleware } from
|
5
|
-
import { type Service, type ServiceContext } from
|
6
|
-
import { type Constructor } from
|
7
|
-
import { Command, CommandHandler } from
|
8
|
-
import { Context } from
|
9
|
-
import { UnitTest } from
|
1
|
+
import { AppBuilder } from "../appBuilder"
|
2
|
+
import { DEFAULT_HOST } from "../index"
|
3
|
+
import { type CredentialBase, DefaultCredential } from "../credentials"
|
4
|
+
import type { Middleware } from "../middleware"
|
5
|
+
import { type Service, type ServiceContext } from "../services/service"
|
6
|
+
import { type Constructor } from "./registry"
|
7
|
+
import { Command, CommandHandler } from "../services/commandService"
|
8
|
+
import { Context } from "../context"
|
9
|
+
import { UnitTest } from "../unitTest"
|
10
10
|
|
11
11
|
export class AppBuilderImplementation extends AppBuilder {
|
12
12
|
envData: Record<string, any> = {
|
@@ -33,7 +33,7 @@ export class AppBuilderImplementation extends AppBuilder {
|
|
33
33
|
useAutomaticDataCollectionEnabled(value: boolean): AppBuilder {
|
34
34
|
if (value === undefined || value === null) {
|
35
35
|
throw new Error(
|
36
|
-
|
36
|
+
"useAutomaticDataCollectionEnabled, value is undefined|null"
|
37
37
|
)
|
38
38
|
}
|
39
39
|
this.automaticDataCollectionEnabled = value
|
@@ -42,7 +42,7 @@ export class AppBuilderImplementation extends AppBuilder {
|
|
42
42
|
|
43
43
|
useCredential(credential: CredentialBase): AppBuilder {
|
44
44
|
if (credential === undefined || credential === null) {
|
45
|
-
throw new Error(
|
45
|
+
throw new Error("useCredential, credential is undefined|null")
|
46
46
|
}
|
47
47
|
this.credential = credential
|
48
48
|
return this
|
@@ -50,7 +50,7 @@ export class AppBuilderImplementation extends AppBuilder {
|
|
50
50
|
|
51
51
|
registerMiddleware(middleware: Middleware): AppBuilder {
|
52
52
|
if (middleware === undefined || middleware === null) {
|
53
|
-
throw new Error(
|
53
|
+
throw new Error("addMiddleware, middleware is undefined|null")
|
54
54
|
}
|
55
55
|
this.middlewares.push(middleware)
|
56
56
|
return this
|
@@ -61,10 +61,10 @@ export class AppBuilderImplementation extends AppBuilder {
|
|
61
61
|
factory: (context: ServiceContext) => T
|
62
62
|
): AppBuilder {
|
63
63
|
if (type === undefined || type === null) {
|
64
|
-
throw new Error(
|
64
|
+
throw new Error("registerService, type is undefined|null")
|
65
65
|
}
|
66
66
|
if (factory === undefined || factory === null) {
|
67
|
-
throw new Error(
|
67
|
+
throw new Error("registerService, factory is undefined|null")
|
68
68
|
}
|
69
69
|
this.services.push([type, factory])
|
70
70
|
return this
|
@@ -75,10 +75,10 @@ export class AppBuilderImplementation extends AppBuilder {
|
|
75
75
|
commandFactory: (context: Context) => CommandHandler<T>
|
76
76
|
): AppBuilder {
|
77
77
|
if (messageType === undefined || messageType === null) {
|
78
|
-
throw new Error(
|
78
|
+
throw new Error("registerCommand, messageType is undefined|null")
|
79
79
|
}
|
80
80
|
if (commandFactory === undefined || commandFactory === null) {
|
81
|
-
throw new Error(
|
81
|
+
throw new Error("registerCommand, commandFactory is undefined|null")
|
82
82
|
}
|
83
83
|
this.commands.push([messageType, commandFactory])
|
84
84
|
return this
|
@@ -1,12 +1,12 @@
|
|
1
|
-
import {
|
2
|
-
import { type AppBuilder } from
|
3
|
-
import {
|
1
|
+
import { DataIslandAppImpl } from "./app.impl"
|
2
|
+
import { type AppBuilder } from "../appBuilder"
|
3
|
+
import { DataIslandApp } from "../dataIslandApp"
|
4
4
|
|
5
5
|
export async function _createApp(
|
6
6
|
name: string,
|
7
7
|
setup?: (builder: AppBuilder) => Promise<void>
|
8
|
-
): Promise<
|
9
|
-
const app = new
|
8
|
+
): Promise<DataIslandApp> {
|
9
|
+
const app = new DataIslandAppImpl(name)
|
10
10
|
await app.initialize(setup)
|
11
11
|
return app
|
12
12
|
}
|
package/src/internal/registry.ts
CHANGED
@@ -1,9 +1,21 @@
|
|
1
|
+
/**
|
2
|
+
* Constructor type.
|
3
|
+
*/
|
1
4
|
export type Constructor<T> = new (...args: any[]) => T
|
2
5
|
|
6
|
+
/**
|
7
|
+
* Provider interface.
|
8
|
+
*/
|
3
9
|
abstract class Provider {
|
10
|
+
/**
|
11
|
+
* Provide method.
|
12
|
+
*/
|
4
13
|
abstract provide(): any | undefined
|
5
14
|
}
|
6
15
|
|
16
|
+
/**
|
17
|
+
* MethodProvider class.
|
18
|
+
*/
|
7
19
|
class MethodProvider<T> extends Provider {
|
8
20
|
private instance?: T
|
9
21
|
private provided: boolean = false
|
@@ -25,6 +37,9 @@ class MethodProvider<T> extends Provider {
|
|
25
37
|
}
|
26
38
|
}
|
27
39
|
|
40
|
+
/**
|
41
|
+
* ValueProvider class.
|
42
|
+
*/
|
28
43
|
class ValueProvider<T> extends Provider {
|
29
44
|
constructor(private readonly value: T | undefined) {
|
30
45
|
super()
|
@@ -35,44 +50,77 @@ class ValueProvider<T> extends Provider {
|
|
35
50
|
}
|
36
51
|
}
|
37
52
|
|
53
|
+
/**
|
54
|
+
* RegistryItem class.
|
55
|
+
*/
|
38
56
|
export class RegistryItem<T> {
|
39
57
|
constructor(
|
40
58
|
private readonly registry: Map<Constructor<any>, Provider>,
|
41
59
|
private readonly type: Constructor<T>
|
42
|
-
) {
|
60
|
+
) {
|
61
|
+
}
|
43
62
|
|
63
|
+
/**
|
64
|
+
* As value method.
|
65
|
+
* @param value
|
66
|
+
*/
|
44
67
|
asValue(value: T): void {
|
45
68
|
this.registry.set(this.type, new ValueProvider<T>(value))
|
46
69
|
}
|
47
70
|
|
71
|
+
/**
|
72
|
+
* As provider method.
|
73
|
+
* @param provider
|
74
|
+
* @param oneTime
|
75
|
+
*/
|
48
76
|
asProvider<T>(provider: () => T, oneTime: boolean = false): void {
|
49
77
|
this.registry.set(this.type, new MethodProvider<T>(provider, oneTime))
|
50
78
|
}
|
51
79
|
|
80
|
+
/**
|
81
|
+
* As factory method.
|
82
|
+
* @param provider
|
83
|
+
*/
|
52
84
|
asFactory<T>(provider: () => T): void {
|
53
85
|
this.registry.set(this.type, new MethodProvider<T>(provider, false))
|
54
86
|
}
|
55
87
|
|
88
|
+
/**
|
89
|
+
* As singleton method.
|
90
|
+
* @param provider
|
91
|
+
*/
|
56
92
|
asSingleton<T>(provider: () => T): void {
|
57
93
|
this.registry.set(this.type, new MethodProvider<T>(provider, true))
|
58
94
|
}
|
59
95
|
}
|
60
96
|
|
97
|
+
/**
|
98
|
+
* Registry class.
|
99
|
+
*/
|
61
100
|
export class Registry {
|
62
|
-
private readonly services: Map<Constructor<any>, Provider>
|
63
|
-
|
64
|
-
constructor() {
|
65
|
-
this.services = new Map()
|
66
|
-
}
|
101
|
+
private readonly services: Map<Constructor<any>, Provider> = new Map()
|
67
102
|
|
103
|
+
/**
|
104
|
+
* Map method.
|
105
|
+
* @param type
|
106
|
+
*/
|
68
107
|
map<T>(type: Constructor<T>): RegistryItem<T> {
|
69
108
|
return new RegistryItem<T>(this.services, type)
|
70
109
|
}
|
71
110
|
|
111
|
+
/**
|
112
|
+
* Set method.
|
113
|
+
* @param type
|
114
|
+
* @param provider
|
115
|
+
*/
|
72
116
|
set<T>(type: Constructor<T>, provider: Provider): void {
|
73
117
|
this.services.set(type, provider)
|
74
118
|
}
|
75
119
|
|
120
|
+
/**
|
121
|
+
* Get method.
|
122
|
+
* @param type
|
123
|
+
*/
|
76
124
|
get<T>(type: Constructor<T>): T | undefined {
|
77
125
|
const provider = this.services.get(type)
|
78
126
|
if (provider === undefined) {
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { Service } from
|
2
|
-
import { Context } from
|
3
|
-
import { Constructor } from
|
1
|
+
import { Service } from "./service"
|
2
|
+
import { Context } from "../context"
|
3
|
+
import { Constructor } from "../internal/registry"
|
4
4
|
|
5
5
|
export abstract class CommandHandler<T> {
|
6
6
|
constructor(protected readonly context: Context) {}
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { type CredentialBase } from
|
2
|
-
import { Service } from
|
3
|
-
import { type DisposableContainer } from
|
1
|
+
import { type CredentialBase } from "../credentials"
|
2
|
+
import { Service } from "./service"
|
3
|
+
import { type DisposableContainer } from "../disposable"
|
4
4
|
|
5
5
|
export class CredentialService extends Service {
|
6
6
|
private _credentialDispose?: DisposableContainer = undefined
|