@neuralinnovations/dataisland-sdk 0.0.1-dev8 → 0.0.1-dev9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/.github/workflows/publish-npm.yml +11 -0
  2. package/.github/workflows/tests.yml +4 -0
  3. package/.github/workflows/version.yml +5 -1
  4. package/README.md +36 -3
  5. package/docs/classes/BasicCredential.md +1 -1
  6. package/docs/classes/BearerCredential.md +1 -1
  7. package/docs/classes/Chat.md +34 -6
  8. package/docs/classes/Chats.md +87 -1
  9. package/docs/classes/CredentialBase.md +1 -1
  10. package/docs/classes/DataIslandApp.md +1 -1
  11. package/docs/classes/DebugCredential.md +1 -1
  12. package/docs/classes/DefaultCredential.md +1 -1
  13. package/docs/classes/DisposableContainer.md +1 -1
  14. package/docs/classes/EventDispatcher.md +1 -1
  15. package/docs/classes/File.md +1 -1
  16. package/docs/classes/Files.md +2 -2
  17. package/docs/classes/FilesPage.md +1 -1
  18. package/docs/classes/Group.md +19 -1
  19. package/docs/classes/Groups.md +27 -3
  20. package/docs/classes/Lifetime.md +1 -1
  21. package/docs/classes/Organization.md +37 -1
  22. package/docs/classes/Organizations.md +1 -1
  23. package/docs/classes/UserProfile.md +1 -1
  24. package/docs/classes/Workspace.md +1 -1
  25. package/docs/classes/Workspaces.md +6 -2
  26. package/docs/enums/ChatAnswerType.md +22 -0
  27. package/docs/enums/ChatsEvent.md +1 -1
  28. package/docs/enums/FilesEvent.md +1 -1
  29. package/docs/enums/GroupEvent.md +3 -1
  30. package/docs/enums/OrganizationsEvent.md +1 -1
  31. package/docs/enums/UserEvent.md +1 -1
  32. package/docs/enums/WorkspaceEvent.md +1 -1
  33. package/docs/enums/WorkspacesEvent.md +1 -1
  34. package/docs/interfaces/Disposable.md +1 -1
  35. package/docs/interfaces/Event.md +1 -1
  36. package/docs/interfaces/EventSubscriber.md +1 -1
  37. package/docs/interfaces/Input.md +1 -1
  38. package/docs/modules.md +5 -3
  39. package/package.json +6 -2
  40. package/src/dataIslandApp.ts +2 -2
  41. package/src/dto/chatResponse.ts +54 -55
  42. package/src/dto/workspacesResponse.ts +2 -2
  43. package/src/index.ts +13 -13
  44. package/src/internal/app.impl.ts +2 -2
  45. package/src/services/organizationService.ts +2 -2
  46. package/src/services/userProfileService.ts +2 -2
  47. package/src/storages/chats/answer.impl.ts +163 -0
  48. package/src/storages/chats/answer.ts +42 -0
  49. package/src/storages/chats/chat.impl.ts +87 -0
  50. package/src/storages/chats/chat.ts +38 -0
  51. package/src/storages/chats/chats.impl.ts +142 -0
  52. package/src/storages/chats/chats.ts +47 -0
  53. package/src/storages/{file.impl.ts → files/file.impl.ts} +5 -5
  54. package/src/storages/{file.ts → files/file.ts} +1 -1
  55. package/src/storages/{files.impl.ts → files/files.impl.ts} +6 -6
  56. package/src/storages/{files.ts → files/files.ts} +2 -2
  57. package/src/storages/{groups.impl.ts → groups/groups.impl.ts} +86 -97
  58. package/src/storages/groups/groups.ts +101 -0
  59. package/src/storages/{organization.impl.ts → organizations/organization.impl.ts} +34 -7
  60. package/src/storages/{organization.ts → organizations/organization.ts} +13 -2
  61. package/src/storages/{organizations.impl.ts → organizations/organizations.impl.ts} +10 -4
  62. package/src/storages/{organizations.ts → organizations/organizations.ts} +1 -1
  63. package/src/storages/{userProfile.impl.ts → user/userProfile.impl.ts} +1 -1
  64. package/src/storages/{userProfile.ts → user/userProfile.ts} +1 -1
  65. package/src/storages/{workspace.impl.ts → workspaces/workspace.impl.ts} +7 -7
  66. package/src/storages/{workspace.ts → workspaces/workspace.ts} +3 -3
  67. package/src/storages/{workspaces.impl.ts → workspaces/workspaces.impl.ts} +11 -11
  68. package/src/storages/{workspaces.ts → workspaces/workspaces.ts} +2 -2
  69. package/test/chats.test.ts +48 -0
  70. package/test/organization.test.ts +13 -1
  71. package/test/setup.ts +7 -0
  72. package/docs/enums/ChatAnswer.md +0 -22
  73. package/src/storages/chat.ts +0 -21
  74. package/src/storages/chats.ts +0 -17
  75. package/src/storages/groups.ts +0 -43
  76. /package/src/storages/{filesPage.ts → files/filesPage.ts} +0 -0
@@ -1,13 +1,13 @@
1
1
  import { WorkspaceId, Workspaces, WorkspacesEvent } from "./workspaces"
2
- import { OrganizationImpl } from "./organization.impl"
3
- import { Context } from "../context"
2
+ import { OrganizationImpl } from "../organizations/organization.impl"
3
+ import { Context } from "../../context"
4
4
  import { Workspace } from "./workspace"
5
5
  import { WorkspaceImpl } from "./workspace.impl"
6
- import { OrganizationId } from "./organizations"
7
- import { RpcService } from "../services/rpcService"
8
- import { OrganizationWorkspaces } from "../dto/userInfoResponse"
9
- import { WorkspaceDto } from "../dto/workspacesResponse"
10
- import { ResponseUtils } from "../services/responseUtils"
6
+ import { OrganizationId } from "../organizations/organizations"
7
+ import { RpcService } from "../../services/rpcService"
8
+ import { OrganizationWorkspaces } from "../../dto/userInfoResponse"
9
+ import { WorkspaceDto } from "../../dto/workspacesResponse"
10
+ import { ResponseUtils } from "../../services/responseUtils"
11
11
 
12
12
  export class WorkspacesImpl extends Workspaces {
13
13
  private readonly _workspaces: WorkspaceImpl[] = []
@@ -102,7 +102,7 @@ export class WorkspacesImpl extends Workspaces {
102
102
 
103
103
  // check response status
104
104
  if (ResponseUtils.isFail(response)) {
105
- await ResponseUtils.throwError("Failed to create workspace", response)
105
+ await ResponseUtils.throwError(`Failed to create workspace, in organization: ${this.organization.id}`, response)
106
106
  }
107
107
 
108
108
  // parse workspace from the server's response
@@ -139,7 +139,7 @@ export class WorkspacesImpl extends Workspaces {
139
139
 
140
140
  // check if workspace is already marked as deleted
141
141
  if (workspace.isMarkAsDeleted) {
142
- throw new Error(`Workspace ${id} is already marked as deleted`)
142
+ throw new Error(`Workspace ${id} is already marked as deleted, in organization: ${this.organization.id}`)
143
143
  }
144
144
 
145
145
  // mark workspace as deleted
@@ -155,7 +155,7 @@ export class WorkspacesImpl extends Workspaces {
155
155
  // check response status
156
156
  if (ResponseUtils.isFail(response)) {
157
157
  await ResponseUtils.throwError(
158
- `Failed to delete workspace: ${workspace.organization.name}/${workspace.name}:${id}`,
158
+ `Failed to delete workspace: ${workspace.organization.name}/${workspace.name}:${id}, in organization: ${this.organization.id}`,
159
159
  response
160
160
  )
161
161
  }
@@ -184,7 +184,7 @@ export class WorkspacesImpl extends Workspaces {
184
184
 
185
185
  // check response status
186
186
  if (ResponseUtils.isFail(response)) {
187
- await ResponseUtils.throwError("Failed to fetch workspaces.", response)
187
+ await ResponseUtils.throwError(`Failed to fetch workspaces in organization: ${organizationId}`, response)
188
188
  }
189
189
 
190
190
  // parse workspaces from the server's response
@@ -1,4 +1,4 @@
1
- import { EventDispatcher } from "../events"
1
+ import { EventDispatcher } from "../../events"
2
2
  import { Workspace } from "./workspace"
3
3
 
4
4
  export type WorkspaceId = string
@@ -44,7 +44,7 @@ export abstract class Workspaces extends EventDispatcher<
44
44
  /**
45
45
  * Create workspace.
46
46
  */
47
- abstract create(name: string, description: string): Promise<Workspace>
47
+ abstract create(name: string, description: string, regulation?: { isCreateNewGroup: boolean, newGroupName: string, groupIds: string[]}): Promise<Workspace>
48
48
 
49
49
  /**
50
50
  * Delete workspace.
@@ -0,0 +1,48 @@
1
+ import { ChatAnswerType } from "../src"
2
+ import { AnswerStatus, StepType } from "../src/dto/chatResponse"
3
+ import { testInOrganization } from "./setup"
4
+
5
+ test("Chat create, ask question, delete", async () => {
6
+ await testInOrganization(async (app, org) => {
7
+
8
+ const chatPromise = org.chats.create()
9
+
10
+ // check not throw
11
+ await expect(chatPromise).resolves.not.toThrow()
12
+
13
+ // get chat
14
+ const chat = await chatPromise
15
+
16
+ // check exists
17
+ expect(chat).not.toBeUndefined()
18
+
19
+ // check exists
20
+ expect(chat).not.toBeNull()
21
+
22
+ // check get
23
+ expect(org.chats.get(chat.id)).toBe(chat)
24
+
25
+ // Create answer
26
+
27
+ const askPromise = chat.ask("Hello!", ChatAnswerType.SHORT)
28
+
29
+ // check not throw
30
+ await expect(chatPromise).resolves.not.toThrow()
31
+
32
+ const answer = await askPromise
33
+
34
+ expect(answer.status).toBe(AnswerStatus.RUNNING)
35
+
36
+ while (answer.status !== AnswerStatus.SUCCESS) {
37
+ await new Promise(r => setTimeout(r, 300))
38
+ await answer.fetch()
39
+ }
40
+
41
+ const tokens = await answer.fetchTokens(StepType.DONE, 0)
42
+
43
+ expect(tokens.step_tokens.length).toBeGreaterThan(0)
44
+
45
+ // check delete
46
+ await expect(org.chats.delete(chat.id)).resolves.not.toThrow()
47
+ })
48
+ })
@@ -1,6 +1,18 @@
1
1
  import { dataIslandApp, DebugCredential } from "../src"
2
2
  import { HOST, randomHash, TOKEN } from "./setup"
3
- import { OrganizationImpl } from "../src/storages/organization.impl"
3
+ import {
4
+ OrganizationImpl
5
+ } from "../src/storages/organizations/organization.impl"
6
+
7
+ test.skip("Delete all organizations", async () => {
8
+ const app = await dataIslandApp("delete-all", async builder => {
9
+ builder.useHost(HOST)
10
+ builder.useCredential(new DebugCredential(TOKEN))
11
+ })
12
+ for (const organization of app.organizations.collection) {
13
+ await app.organizations.delete(organization.id)
14
+ }
15
+ })
4
16
 
5
17
  test("Organization", async () => {
6
18
  // make random name
package/test/setup.ts CHANGED
@@ -19,6 +19,13 @@ export const testInOrganization = async (func: (app: DataIslandApp, org: Organiz
19
19
  const app = await dataIslandApp(randomName, async builder => {
20
20
  builder.useHost(config?.host ?? HOST)
21
21
  builder.useCredential(new DebugCredential(config?.token ?? TOKEN))
22
+ builder.registerMiddleware(async (req, next) => {
23
+ const url = req.url
24
+ console.log("REQUEST", url, req.method)
25
+ const response = await next(req)
26
+ console.log("RESPONSE", url, response.status)
27
+ return response
28
+ })
22
29
  })
23
30
  const org = await app.organizations.create(
24
31
  randomName,
@@ -1,22 +0,0 @@
1
- [@neuralinnovations/dataisland-sdk - v0.0.1-dev8](../../README.md) / [Exports](../modules.md) / ChatAnswer
2
-
3
- # Enumeration: ChatAnswer
4
-
5
- ## Table of contents
6
-
7
- ### Enumeration Members
8
-
9
- - [LONG](ChatAnswer.md#long)
10
- - [SHORT](ChatAnswer.md#short)
11
-
12
- ## Enumeration Members
13
-
14
- ### LONG
15
-
16
- • **LONG** = ``"long"``
17
-
18
- ___
19
-
20
- ### SHORT
21
-
22
- • **SHORT** = ``"short"``
@@ -1,21 +0,0 @@
1
- export type ChatId = string
2
-
3
- export enum ChatAnswer {
4
- SHORT = "short",
5
- LONG = "long"
6
- }
7
-
8
- export abstract class Chat {
9
- /**
10
- * Chat id.
11
- */
12
- abstract get id(): ChatId
13
-
14
- /**
15
- * Chat name.
16
- */
17
- abstract get name(): string
18
-
19
- abstract question(message: string, answer?: ChatAnswer): Promise<void>
20
- }
21
-
@@ -1,17 +0,0 @@
1
- import { EventDispatcher } from "../events"
2
- import { Chat } from "./chat"
3
-
4
- export enum ChatsEvent {
5
- ADDED = "added",
6
- REMOVED = "removed"
7
- }
8
-
9
- /**
10
- * Chats storage.
11
- */
12
- export abstract class Chats extends EventDispatcher<ChatsEvent, Chat> {
13
- /**
14
- * Create new chat.
15
- */
16
- abstract create(): Promise<Chat>
17
- }
@@ -1,43 +0,0 @@
1
- import { AccessGroupDto } from "../dto/accessGroupResponse"
2
- import { UserDto } from "../dto/userInfoResponse"
3
- import { WorkspaceDto } from "../dto/workspacesResponse"
4
- import { EventDispatcher } from "../events"
5
- import { OrganizationId } from "./organizations"
6
-
7
- export type GroupId = string
8
-
9
- export enum GroupEvent {
10
- ADDED = "added",
11
- REMOVED = "removed",
12
- UPDATED = "updated"
13
- }
14
-
15
- export abstract class Group extends EventDispatcher<GroupEvent, Group> {
16
-
17
- abstract get id(): GroupId
18
-
19
- abstract get group(): AccessGroupDto
20
-
21
- abstract get members(): UserDto[]
22
-
23
- abstract getWorkspaces() : Promise<WorkspaceDto[]>
24
-
25
- abstract setWorkspaces(workspaces: string[]): Promise<void>
26
-
27
- abstract setName(name: string): Promise<void>
28
-
29
- abstract setPermits(permits: {isAdmin: boolean}): Promise<void>
30
-
31
- abstract setMembersIds(members: string[]): Promise<void>
32
- }
33
-
34
-
35
- export abstract class Groups extends EventDispatcher<GroupEvent, Group>{
36
-
37
- abstract create(name: string, organizationId: OrganizationId, permits: { isAdmin: boolean }, memberIds: string[]): Promise<Group>
38
-
39
- abstract get(id: GroupId): Promise<Group | undefined>
40
-
41
- abstract delete(id: GroupId): Promise<void>
42
-
43
- }