@neuralinnovations/dataisland-sdk 0.0.1-dev2 → 0.0.1-dev3
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/.editorconfig +4 -1
- package/.eslintrc.json +1 -1
- package/jest.config.ts +3 -3
- package/jest.setup.ts +2 -2
- package/package.json +3 -2
- package/src/appBuilder.ts +6 -6
- package/src/appSdk.ts +6 -6
- package/src/commands/startCommandHandler.ts +2 -2
- package/src/context.ts +3 -3
- package/src/credentials.ts +29 -7
- package/src/disposable.ts +1 -1
- package/src/dto/accessGroupResponse.ts +35 -0
- package/src/dto/chatResponse.ts +104 -0
- package/src/dto/userInfoResponse.ts +11 -1
- package/src/dto/workspacesResponse.ts +49 -0
- package/src/events.ts +1 -1
- package/src/index.ts +10 -12
- package/src/internal/app.impl.ts +21 -21
- package/src/internal/appBuilder.impl.ts +16 -16
- package/src/internal/createApp.impl.ts +3 -3
- package/src/services/commandService.ts +3 -3
- package/src/services/credentialService.ts +3 -3
- package/src/services/middlewareService.ts +3 -3
- package/src/services/organizationService.ts +18 -116
- package/src/services/requestBuilder.ts +6 -6
- package/src/services/responseUtils.ts +32 -0
- package/src/services/rpcService.ts +5 -5
- package/src/services/service.ts +3 -3
- package/src/services/userProfileService.ts +18 -66
- package/src/storages/chat.ts +37 -0
- package/src/storages/file.impl.ts +68 -0
- package/src/storages/files.impl.ts +192 -0
- package/src/storages/files.ts +67 -0
- package/src/storages/groups.impl.ts +337 -0
- package/src/storages/groups.ts +43 -0
- package/src/storages/organization.impl.ts +68 -0
- package/src/storages/organization.ts +33 -0
- package/src/storages/organizations.impl.ts +191 -0
- package/src/storages/organizations.ts +8 -28
- package/src/storages/userProfile.impl.ts +56 -0
- package/src/storages/userProfile.ts +2 -2
- package/src/storages/workspace.impl.ts +109 -0
- package/src/storages/workspace.ts +43 -0
- package/src/storages/workspaces.impl.ts +212 -0
- package/src/storages/workspaces.ts +53 -0
- package/test/commands.test.ts +8 -8
- package/test/disposable.test.ts +3 -3
- package/test/events.test.ts +4 -4
- package/test/index.test.ts +102 -40
- package/test/registry.test.ts +8 -8
- package/test/services.test.ts +15 -15
- package/test/unitTest.test.ts +2 -2
- package/test_file.pdf +0 -0
- package/src/services/organizationImpl.ts +0 -51
- package/src/services/organizationsImpl.ts +0 -55
- package/src/types.ts +0 -86
package/.editorconfig
CHANGED
@@ -18,5 +18,8 @@ indent_style = space
|
|
18
18
|
indent_size = 2
|
19
19
|
ij_javascript_use_semicolon_after_statement = false
|
20
20
|
ij_typescript_use_semicolon_after_statement = false
|
21
|
+
ij_typescript_use_double_quotes = true
|
22
|
+
ij_javascript_use_double_quotes = true
|
23
|
+
|
21
24
|
# Not currently supported by vscode, but is supported others, e.g. vim.
|
22
|
-
max_line_length = 80
|
25
|
+
max_line_length = 80
|
package/.eslintrc.json
CHANGED
package/jest.config.ts
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
* https://jestjs.io/docs/configuration
|
4
4
|
*/
|
5
5
|
|
6
|
-
import type { Config } from
|
6
|
+
import type { Config } from "jest"
|
7
7
|
|
8
8
|
const config: Config = {
|
9
9
|
// All imported modules in your tests should be mocked automatically
|
@@ -25,7 +25,7 @@ const config: Config = {
|
|
25
25
|
// collectCoverageFrom: undefined,
|
26
26
|
|
27
27
|
// The directory where Jest should output its coverage files
|
28
|
-
coverageDirectory:
|
28
|
+
coverageDirectory: "coverage",
|
29
29
|
|
30
30
|
// An array of regexp pattern strings used to skip coverage collection
|
31
31
|
// coveragePathIgnorePatterns: [
|
@@ -134,7 +134,7 @@ const config: Config = {
|
|
134
134
|
// runner: "jest-runner",
|
135
135
|
|
136
136
|
// The paths to modules that run some code to configure or set up the testing environment before each test
|
137
|
-
setupFiles: [
|
137
|
+
setupFiles: ["./jest.setup.ts"]
|
138
138
|
|
139
139
|
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
140
140
|
// setupFilesAfterEnv: [],
|
package/jest.setup.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
import * as dotenv from
|
2
|
-
dotenv.config({ path:
|
1
|
+
import * as dotenv from "dotenv"
|
2
|
+
dotenv.config({ path: ".env.test" })
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@neuralinnovations/dataisland-sdk",
|
3
|
-
"version": "0.0.1-
|
3
|
+
"version": "0.0.1-dev3",
|
4
4
|
"description": "SDK for DataIsland project",
|
5
5
|
"licenses": [
|
6
6
|
{
|
@@ -14,7 +14,8 @@
|
|
14
14
|
"scripts": {
|
15
15
|
"build": "tsc",
|
16
16
|
"test": "jest",
|
17
|
-
"lint": "eslint --ext .ts,.tsx src"
|
17
|
+
"lint": "eslint --ext .ts,.tsx src test",
|
18
|
+
"lint:fix": "eslint --fix --ext .ts,.tsx src test"
|
18
19
|
},
|
19
20
|
"author": "Neural Innovations LTD",
|
20
21
|
"license": "Apache-2.0",
|
package/src/appBuilder.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
import type { Middleware } from
|
2
|
-
import type { CredentialBase } from
|
3
|
-
import type { Service, ServiceContext } from
|
4
|
-
import type { Constructor } from
|
5
|
-
import { CommandHandler, Command } from
|
6
|
-
import { Context } from
|
1
|
+
import type { Middleware } from "./middleware"
|
2
|
+
import type { CredentialBase } from "./credentials"
|
3
|
+
import type { Service, ServiceContext } from "./services/service"
|
4
|
+
import type { Constructor } from "./internal/registry"
|
5
|
+
import { CommandHandler, Command } from "./services/commandService"
|
6
|
+
import { Context } from "./context"
|
7
7
|
|
8
8
|
/**
|
9
9
|
* DataIsland App builder.
|
package/src/appSdk.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
import type { Lifetime } from
|
2
|
-
import type { CredentialBase } from
|
3
|
-
import { Context } from
|
4
|
-
import type { Constructor } from
|
5
|
-
import { Organizations } from
|
6
|
-
import { UserProfile } from
|
1
|
+
import type { Lifetime } from "./disposable"
|
2
|
+
import type { CredentialBase } from "./credentials"
|
3
|
+
import { Context } from "./context"
|
4
|
+
import type { Constructor } from "./internal/registry"
|
5
|
+
import { Organizations } from "./storages/organizations"
|
6
|
+
import { UserProfile } from "./storages/userProfile"
|
7
7
|
|
8
8
|
/**
|
9
9
|
* DataIsland App instance.
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { CommandHandler, Command } from
|
2
|
-
import { UserProfileService } from
|
1
|
+
import { CommandHandler, Command } from "../services/commandService"
|
2
|
+
import { UserProfileService } from "../services/userProfileService"
|
3
3
|
|
4
4
|
export class StartCommand extends Command {}
|
5
5
|
|
package/src/context.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { type Constructor, type Registry } from
|
2
|
-
import { type Lifetime } from
|
3
|
-
import { Command, CommandService } from
|
1
|
+
import { type Constructor, type Registry } from "./internal/registry"
|
2
|
+
import { type Lifetime } from "./disposable"
|
3
|
+
import { Command, CommandService } from "./services/commandService"
|
4
4
|
|
5
5
|
/**
|
6
6
|
* DataIsland App context.
|
package/src/credentials.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { MiddlewareService } from
|
2
|
-
import { type Lifetime } from
|
3
|
-
import { type Context } from
|
1
|
+
import { MiddlewareService } from "./services/middlewareService"
|
2
|
+
import { type Lifetime } from "./disposable"
|
3
|
+
import { type Context } from "./context"
|
4
4
|
|
5
5
|
/**
|
6
6
|
* DataIsland App credential.
|
@@ -29,11 +29,33 @@ export class BasicCredential extends CredentialBase {
|
|
29
29
|
onRegister(lifetime: Lifetime, context: Context): void {
|
30
30
|
const service = context.resolve(MiddlewareService)
|
31
31
|
if (service === undefined) {
|
32
|
-
throw new Error(
|
32
|
+
throw new Error("MiddlewareService is not registered.")
|
33
33
|
}
|
34
34
|
lifetime.add(
|
35
35
|
service.useMiddleware(async (req, next) => {
|
36
|
-
req.headers.set(
|
36
|
+
req.headers.set("Authorization", `Basic ${this.email}:${this.password}`)
|
37
|
+
return await next(req)
|
38
|
+
})
|
39
|
+
)
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
export class DebugCredential extends CredentialBase {
|
44
|
+
readonly token: string
|
45
|
+
|
46
|
+
constructor(token: string) {
|
47
|
+
super()
|
48
|
+
this.token = token
|
49
|
+
}
|
50
|
+
|
51
|
+
onRegister(lifetime: Lifetime, context: Context): void {
|
52
|
+
const service = context.resolve(MiddlewareService)
|
53
|
+
if (service === undefined) {
|
54
|
+
throw new Error("MiddlewareService is not registered.")
|
55
|
+
}
|
56
|
+
lifetime.add(
|
57
|
+
service.useMiddleware(async (req, next) => {
|
58
|
+
req.headers.set("Authorization", `Debug ${this.token}`)
|
37
59
|
return await next(req)
|
38
60
|
})
|
39
61
|
)
|
@@ -51,11 +73,11 @@ export class BearerCredential extends CredentialBase {
|
|
51
73
|
onRegister(lifetime: Lifetime, context: Context): void {
|
52
74
|
const service = context.resolve(MiddlewareService)
|
53
75
|
if (service === undefined) {
|
54
|
-
throw new Error(
|
76
|
+
throw new Error("MiddlewareService is not registered.")
|
55
77
|
}
|
56
78
|
lifetime.add(
|
57
79
|
service.useMiddleware(async (req, next) => {
|
58
|
-
req.headers.set(
|
80
|
+
req.headers.set("Authorization", `Bearer ${this.token}`)
|
59
81
|
return await next(req)
|
60
82
|
})
|
61
83
|
)
|
package/src/disposable.ts
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
import { UserDto } from "./userInfoResponse"
|
2
|
+
|
3
|
+
|
4
|
+
export interface PermitsDto {
|
5
|
+
isAdmin: boolean;
|
6
|
+
}
|
7
|
+
|
8
|
+
export interface RegulationDto {
|
9
|
+
isRegulateOrganization: boolean;
|
10
|
+
regulateWorkspaceIds: string[];
|
11
|
+
}
|
12
|
+
|
13
|
+
export interface AccessGroupDto {
|
14
|
+
id: string;
|
15
|
+
name: string;
|
16
|
+
type: number;
|
17
|
+
createdAt: number;
|
18
|
+
modifiedAt: number;
|
19
|
+
organizationId: string;
|
20
|
+
permits: PermitsDto;
|
21
|
+
regulation: RegulationDto;
|
22
|
+
membersCount: number;
|
23
|
+
}
|
24
|
+
|
25
|
+
export interface AccessGroupResponse {
|
26
|
+
group: AccessGroupDto;
|
27
|
+
members: UserDto[];
|
28
|
+
}
|
29
|
+
|
30
|
+
export interface AccessGroupsResponse {
|
31
|
+
groups: AccessGroupDto[];
|
32
|
+
}
|
33
|
+
|
34
|
+
|
35
|
+
|
@@ -0,0 +1,104 @@
|
|
1
|
+
|
2
|
+
export interface SourceDto {
|
3
|
+
id: string;
|
4
|
+
name: string;
|
5
|
+
url: string;
|
6
|
+
content: string;
|
7
|
+
page: number;
|
8
|
+
}
|
9
|
+
|
10
|
+
export interface AnswerDto {
|
11
|
+
id: string;
|
12
|
+
chatId: string;
|
13
|
+
question: string;
|
14
|
+
context: string;
|
15
|
+
sources: SourceDto[];
|
16
|
+
timestamp: number;
|
17
|
+
}
|
18
|
+
|
19
|
+
export interface ChatDto {
|
20
|
+
id: string;
|
21
|
+
name: string;
|
22
|
+
createdAt: number;
|
23
|
+
modifiedAt: number;
|
24
|
+
userId: string;
|
25
|
+
organizationId: string;
|
26
|
+
workspaceId: string;
|
27
|
+
answers: AnswerDto[];
|
28
|
+
}
|
29
|
+
|
30
|
+
export interface ChatListResponse {
|
31
|
+
chats: ChatDto[]
|
32
|
+
}
|
33
|
+
|
34
|
+
export enum AnswerStatus {
|
35
|
+
RUNNING = 0,
|
36
|
+
SUCCESS = 1,
|
37
|
+
CANCELED = 2,
|
38
|
+
FAIL = 3,
|
39
|
+
}
|
40
|
+
|
41
|
+
export interface AnswerStepDto{
|
42
|
+
id: string;
|
43
|
+
type: StepType;
|
44
|
+
status: StepStatus;
|
45
|
+
start_at: string;
|
46
|
+
end_at: string;
|
47
|
+
tokens: string[];
|
48
|
+
sources: SourceDto[];
|
49
|
+
}
|
50
|
+
|
51
|
+
export interface FetchAnswerResponse {
|
52
|
+
id: string;
|
53
|
+
status: AnswerStatus;
|
54
|
+
steps: AnswerStepDto[];
|
55
|
+
}
|
56
|
+
|
57
|
+
export interface FetchTokensResponse {
|
58
|
+
id: string;
|
59
|
+
step_id: string;
|
60
|
+
step_status: number;
|
61
|
+
step_tokens: string[];
|
62
|
+
}
|
63
|
+
|
64
|
+
export interface AnswerSourcesResponse {
|
65
|
+
chat_uid: string;
|
66
|
+
uid: string;
|
67
|
+
step_id: string;
|
68
|
+
sources: SourceDto[];
|
69
|
+
}
|
70
|
+
|
71
|
+
export enum StepStatus {
|
72
|
+
RUNNING = 0,
|
73
|
+
SUCCESS = 1,
|
74
|
+
FAIL = 2,
|
75
|
+
CANCELED = 3,
|
76
|
+
}
|
77
|
+
|
78
|
+
export enum StepType {
|
79
|
+
PREPARE = 0,
|
80
|
+
SOURCES = 1,
|
81
|
+
GENERATE_ANSWER = 6,
|
82
|
+
FINALIZE_RESULT = 9,
|
83
|
+
DONE = 10,
|
84
|
+
}
|
85
|
+
|
86
|
+
export class StepTypeInfo {
|
87
|
+
public static hasTokens(type: StepType): boolean {
|
88
|
+
switch (type) {
|
89
|
+
case StepType.GENERATE_ANSWER:
|
90
|
+
case StepType.DONE:
|
91
|
+
case StepType.FINALIZE_RESULT:
|
92
|
+
return true
|
93
|
+
}
|
94
|
+
return false
|
95
|
+
}
|
96
|
+
|
97
|
+
public static hasSources(type: StepType): boolean {
|
98
|
+
switch (type) {
|
99
|
+
case StepType.SOURCES:
|
100
|
+
return true
|
101
|
+
}
|
102
|
+
return false
|
103
|
+
}
|
104
|
+
}
|
@@ -1,3 +1,5 @@
|
|
1
|
+
import { WorkspaceDto } from "./workspacesResponse"
|
2
|
+
|
1
3
|
export interface UserInfoResponse {
|
2
4
|
adminInOrganization: string[]
|
3
5
|
organizations: OrganizationDto[]
|
@@ -10,7 +12,7 @@ export interface UserDto {
|
|
10
12
|
created_at: number
|
11
13
|
modified_at: number
|
12
14
|
profile: ProfileDto
|
13
|
-
settings
|
15
|
+
settings?: UserSettings | null
|
14
16
|
}
|
15
17
|
|
16
18
|
export interface ProfileDto {
|
@@ -35,3 +37,11 @@ export interface OrganizationDto {
|
|
35
37
|
membersCount: number
|
36
38
|
profile: OrganizationProfileDto
|
37
39
|
}
|
40
|
+
|
41
|
+
export interface OrganizationWorkspaces extends OrganizationDto {
|
42
|
+
workspaces: WorkspaceDto[]
|
43
|
+
}
|
44
|
+
|
45
|
+
export interface MembersResponse {
|
46
|
+
members: UserDto
|
47
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import { WorkspaceId } from "../storages/workspaces"
|
2
|
+
import { FileId } from "../storages/files"
|
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
package/src/index.ts
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
-
import { version } from
|
2
|
-
import { _createApp } from
|
3
|
-
import { type AppBuilder } from
|
4
|
-
import { type AppSdk } from
|
1
|
+
import { version } from "../package.json"
|
2
|
+
import { _createApp } from "./internal/createApp.impl"
|
3
|
+
import { type AppBuilder } from "./appBuilder"
|
4
|
+
import { type AppSdk } from "./appSdk"
|
5
5
|
|
6
|
-
export * from
|
7
|
-
export * from
|
8
|
-
export * from
|
9
|
-
export * from
|
10
|
-
export * from './credentials'
|
11
|
-
export * from './appSdk'
|
6
|
+
export * from "./events"
|
7
|
+
export * from "./disposable"
|
8
|
+
export * from "./credentials"
|
9
|
+
export * from "./appSdk"
|
12
10
|
|
13
11
|
const _appsNotReady = new Map<string, Promise<AppSdk>>()
|
14
12
|
const _appsReady = new Map<string, AppSdk>()
|
@@ -21,12 +19,12 @@ export const SDK_VERSION = version
|
|
21
19
|
/**
|
22
20
|
* Default DataIsland App name.
|
23
21
|
*/
|
24
|
-
export const DEFAULT_NAME =
|
22
|
+
export const DEFAULT_NAME = "[DEFAULT]"
|
25
23
|
|
26
24
|
/**
|
27
25
|
* Default DataIsland App host.
|
28
26
|
*/
|
29
|
-
export const DEFAULT_HOST =
|
27
|
+
export const DEFAULT_HOST = "https://api.dataisland.com.ua"
|
30
28
|
|
31
29
|
export function sdks(): AppSdk[] {
|
32
30
|
return Array.from(_appsReady.values())
|
package/src/internal/app.impl.ts
CHANGED
@@ -1,25 +1,25 @@
|
|
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 { AppSdk } from
|
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 { AppSdk } from "../appSdk"
|
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
|
17
|
+
} from "../commands/startCommandHandler"
|
18
|
+
import { UserProfileService } from "../services/userProfileService"
|
19
|
+
import { OrganizationService } from "../services/organizationService"
|
20
|
+
import { Organizations } from "../storages/organizations"
|
21
|
+
import { UserProfile } from "../storages/userProfile"
|
22
|
+
import { isUnitTest, UnitTest } from "../unitTest"
|
23
23
|
|
24
24
|
export class AppImplementation extends AppSdk {
|
25
25
|
readonly name: string
|
@@ -106,8 +106,8 @@ export class AppImplementation extends AppSdk {
|
|
106
106
|
|
107
107
|
// register middlewares
|
108
108
|
builder.registerMiddleware(async (req, next) => {
|
109
|
-
req.headers.set(
|
110
|
-
req.headers.set(
|
109
|
+
req.headers.set("accept", "text/plain")
|
110
|
+
req.headers.set("content-type", "application/json")
|
111
111
|
return await next(req)
|
112
112
|
})
|
113
113
|
|
@@ -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,6 +1,6 @@
|
|
1
|
-
import { AppImplementation } from
|
2
|
-
import { type AppBuilder } from
|
3
|
-
import { AppSdk } from
|
1
|
+
import { AppImplementation } from "./app.impl"
|
2
|
+
import { type AppBuilder } from "../appBuilder"
|
3
|
+
import { AppSdk } from "../appSdk"
|
4
4
|
|
5
5
|
export async function _createApp(
|
6
6
|
name: string,
|
@@ -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
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { Service } from
|
2
|
-
import { type Middleware } from
|
3
|
-
import { type Disposable } from
|
1
|
+
import { Service } from "./service"
|
2
|
+
import { type Middleware } from "../middleware"
|
3
|
+
import { type Disposable } from "../disposable"
|
4
4
|
|
5
5
|
export class MiddlewareService extends Service {
|
6
6
|
_middlewares: Middleware[] = []
|