@neuralinnovations/dataisland-sdk 0.0.1-dev4 → 0.0.1-dev5

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/README.md CHANGED
@@ -24,7 +24,7 @@ For connecting this library to your website project simply install it using npm
24
24
  You can initialize default app sdk instance using this code example.
25
25
 
26
26
  ```
27
- const app = await appSdk("your-app-name", async (builder: AppBuilder) => {
27
+ const app = await dataIslandApp("your-app-name", async (builder: AppBuilder) => {
28
28
  builder.useHost(HOST)
29
29
  builder.useCredential(new BearerCredential(TOKEN))
30
30
  })
@@ -39,7 +39,7 @@ Second required parameter for builder is Credentials. It is recomended to use Be
39
39
  You can also add requests middlewares with builder options.
40
40
 
41
41
  ```
42
- const app = await appSdk("your-app-name", async (builder: AppBuilder) => {
42
+ const app = await dataIslandApp("your-app-name", async (builder: AppBuilder) => {
43
43
  builder.useHost(YOUR_HOST)
44
44
  builder.useAutomaticDataCollectionEnabled(false)
45
45
  builder.useCredential(new BasicCredential("email", "password"))
@@ -76,7 +76,7 @@ Workspaces are folder-like objects used to store files and controll access to it
76
76
  Default workspace creation example:
77
77
 
78
78
  ```
79
- const wsPromise = org.workspaces.create(
79
+ const workspace = await org.workspaces.create(
80
80
  "your-workspace-name",
81
81
  "your-workspace-description",
82
82
  regulation: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neuralinnovations/dataisland-sdk",
3
- "version": "0.0.1-dev4",
3
+ "version": "0.0.1-dev5",
4
4
  "description": "SDK for DataIsland project",
5
5
  "licenses": [
6
6
  {
@@ -8,7 +8,7 @@ import { UserProfile } from "./storages/userProfile"
8
8
  /**
9
9
  * DataIsland App instance.
10
10
  */
11
- export abstract class AppSdk {
11
+ export abstract class DataIslandApp {
12
12
  /**
13
13
  * The name of this app.
14
14
  */
package/src/index.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { version } from "../package.json"
2
2
  import { _createApp } from "./internal/createApp.impl"
3
3
  import { type AppBuilder } from "./appBuilder"
4
- import { type AppSdk } from "./appSdk"
4
+ import { type DataIslandApp } from "./dataIslandApp"
5
5
 
6
6
  export * from "./events"
7
7
  export * from "./disposable"
8
8
  export * from "./credentials"
9
- export * from "./appSdk"
9
+ export * from "./dataIslandApp"
10
10
  export * from "./storages/organizations"
11
11
  export * from "./storages/organization"
12
12
  export * from "./storages/workspaces"
@@ -19,8 +19,8 @@ export * from "./storages/filesPage"
19
19
  export * from "./storages/chats"
20
20
  export * from "./storages/chat"
21
21
 
22
- const _appsNotReady = new Map<string, Promise<AppSdk>>()
23
- const _appsReady = new Map<string, AppSdk>()
22
+ const _appsNotReady = new Map<string, Promise<DataIslandApp>>()
23
+ const _appsReady = new Map<string, DataIslandApp>()
24
24
 
25
25
  /**
26
26
  * Current SDK version.
@@ -37,7 +37,10 @@ export const DEFAULT_NAME = "[DEFAULT]"
37
37
  */
38
38
  export const DEFAULT_HOST = "https://api.dataisland.com.ua"
39
39
 
40
- export function sdks(): AppSdk[] {
40
+ /**
41
+ * Returns a list of DataIsland App instances.
42
+ */
43
+ export function dataIslandInstances(): DataIslandApp[] {
41
44
  return Array.from(_appsReady.values())
42
45
  }
43
46
 
@@ -48,19 +51,19 @@ export function sdks(): AppSdk[] {
48
51
  * @returns A DataIsland App instance.
49
52
  * @example
50
53
  * ```js
51
- * import { appSdk } from 'data-island'
54
+ * import { dataIslandApp, DEFAULT_NAME } from '@neuralinnovations/dataisland-sdk'
52
55
  *
53
- * const app = await appSdk("my-app", builder => {
56
+ * const app = await dataIslandApp(DEFAULT_NAME, builder => {
54
57
  * builder.useHost("https://dataisland.com.ua")
55
58
  * builder.useAutomaticDataCollectionEnabled(true)
56
59
  * builder.useCredential(new BasicCredential("email", "password"))
57
60
  * })
58
61
  * ```
59
62
  */
60
- export async function appSdk(
63
+ export async function dataIslandApp(
61
64
  name?: string,
62
65
  setup?: (builder: AppBuilder) => Promise<void>
63
- ): Promise<AppSdk> {
66
+ ): Promise<DataIslandApp> {
64
67
  name = name ?? DEFAULT_NAME
65
68
 
66
69
  let appPromise = _appsNotReady.get(name)
@@ -78,7 +81,7 @@ export async function appSdk(
78
81
  } else {
79
82
  if (setup !== undefined) {
80
83
  throw new Error(
81
- `App ${name} is initializing. You can't setup the same again.`
84
+ `DataIsland ${name} is initializing. You can't setup the same again.`
82
85
  )
83
86
  }
84
87
  }
@@ -8,7 +8,7 @@ import { type Service, ServiceContext } from "../services/service"
8
8
  import { CredentialService } from "../services/credentialService"
9
9
  import { MiddlewareService } from "../services/middlewareService"
10
10
  import { type CredentialBase } from "../credentials"
11
- import { AppSdk } from "../appSdk"
11
+ import { DataIslandApp } from "../dataIslandApp"
12
12
  import { RpcService } from "../services/rpcService"
13
13
  import { CommandService } from "../services/commandService"
14
14
  import {
@@ -21,7 +21,7 @@ import { Organizations } from "../storages/organizations"
21
21
  import { UserProfile } from "../storages/userProfile"
22
22
  import { isUnitTest, UnitTest } from "../unitTest"
23
23
 
24
- export class AppImplementation extends AppSdk {
24
+ export class DataIslandAppImpl extends DataIslandApp {
25
25
  readonly name: string
26
26
  private _host: string = DEFAULT_HOST
27
27
  private _automaticDataCollectionEnabled: boolean = true
@@ -178,7 +178,7 @@ export class AppImplementation extends AppSdk {
178
178
 
179
179
  // log app initialized
180
180
  if (!isUnitTest(UnitTest.DO_NOT_PRINT_INITIALIZED_LOG)) {
181
- console.log(`AppSDK ${this.name} initialized`)
181
+ console.log(`DataIsland ${this.name} initialized`)
182
182
  }
183
183
  }
184
184
  }
@@ -1,12 +1,12 @@
1
- import { AppImplementation } from "./app.impl"
1
+ import { DataIslandAppImpl } from "./app.impl"
2
2
  import { type AppBuilder } from "../appBuilder"
3
- import { AppSdk } from "../appSdk"
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<AppSdk> {
9
- const app = new AppImplementation(name)
8
+ ): Promise<DataIslandApp> {
9
+ const app = new DataIslandAppImpl(name)
10
10
  await app.initialize(setup)
11
11
  return app
12
12
  }
package/src/unitTest.ts CHANGED
@@ -9,7 +9,7 @@ export enum UnitTest {
9
9
  export type UnitTestProfileSyncAction = () => void
10
10
  export type UnitTestProfileAsyncAction = () => Promise<void>
11
11
 
12
- export class AppSdkUnitTest {
12
+ class AppSdkUnitTest {
13
13
  private static _stack: UnitTest[] = [UnitTest.DO_NOTHING]
14
14
 
15
15
  public static get current(): UnitTest {
@@ -37,6 +37,17 @@ export class AppSdkUnitTest {
37
37
  }
38
38
  }
39
39
 
40
+ export const appTest = async (
41
+ unitTest: UnitTest = UnitTest.DEFAULT,
42
+ func: UnitTestProfileSyncAction | UnitTestProfileAsyncAction
43
+ ): Promise<void> => {
44
+ await AppSdkUnitTest.test(unitTest, func)
45
+ }
46
+
47
+ export const appTestCurrent = (): UnitTest => {
48
+ return AppSdkUnitTest.current
49
+ }
50
+
40
51
  export const isUnitTest = (mask: UnitTest): boolean => {
41
52
  return (AppSdkUnitTest.current & mask) == mask
42
53
  }
@@ -1,6 +1,6 @@
1
1
  import { Command, CommandHandler } from "../src/services/commandService"
2
- import { appSdk } from "../src"
3
- import { UnitTest, AppSdkUnitTest } from "../src/unitTest"
2
+ import { dataIslandApp } from "../src"
3
+ import { appTest, UnitTest } from "../src/unitTest"
4
4
 
5
5
  class Cmd extends Command {
6
6
  constructor(public readonly name: string = "test") {
@@ -15,8 +15,8 @@ class CmdHandler extends CommandHandler<Cmd> {
15
15
  }
16
16
 
17
17
  test("Commands test", async () => {
18
- await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
19
- const app = await appSdk("test-commands", async builder => {
18
+ await appTest(UnitTest.DEFAULT, async () => {
19
+ const app = await dataIslandApp("test-commands", async builder => {
20
20
  builder.registerCommand(Cmd, context => new CmdHandler(context))
21
21
  })
22
22
  expect(app.context.execute(new Cmd("test-command"))).toBeDefined()
@@ -1,8 +1,8 @@
1
1
  import { version } from "../package.json"
2
2
  import {
3
- AppSdk,
3
+ DataIslandApp,
4
4
  BasicCredential,
5
- appSdk,
5
+ dataIslandApp,
6
6
  SDK_VERSION,
7
7
  DEFAULT_NAME,
8
8
  DebugCredential
@@ -11,7 +11,7 @@ import { MiddlewareService } from "../src/services/middlewareService"
11
11
  import { CredentialService } from "../src/services/credentialService"
12
12
  import { RpcService } from "../src/services/rpcService"
13
13
  import { AppBuilder } from "../src/appBuilder"
14
- import { UnitTest, AppSdkUnitTest } from "../src/unitTest"
14
+ import { UnitTest, appTest } from "../src/unitTest"
15
15
  import { HOST, randomHash, TOKEN } from "./setup"
16
16
 
17
17
  test("SDK_VERSION", () => {
@@ -20,7 +20,7 @@ test("SDK_VERSION", () => {
20
20
 
21
21
  test("Default SDK", async () => {
22
22
  // default
23
- const app = await appSdk(DEFAULT_NAME, async (builder: AppBuilder) => {
23
+ const app = await dataIslandApp(DEFAULT_NAME, async (builder: AppBuilder) => {
24
24
  builder.useHost(HOST)
25
25
  builder.useCredential(new DebugCredential(TOKEN))
26
26
  })
@@ -28,8 +28,8 @@ test("Default SDK", async () => {
28
28
  })
29
29
 
30
30
  test("SDK, middleware", async () => {
31
- await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
32
- const app = await appSdk("test-settings", async (builder: AppBuilder) => {
31
+ await appTest(UnitTest.DEFAULT, async () => {
32
+ const app = await dataIslandApp("test-settings", async (builder: AppBuilder) => {
33
33
  builder.useHost("https://test.com")
34
34
  builder.useAutomaticDataCollectionEnabled(false)
35
35
  builder.useCredential(new BasicCredential("email", "password"))
@@ -45,8 +45,8 @@ test("SDK, middleware", async () => {
45
45
  })
46
46
 
47
47
  test("SDK, services", async () => {
48
- await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
49
- const app = await appSdk("test-sdk")
48
+ await appTest(UnitTest.DEFAULT, async () => {
49
+ const app = await dataIslandApp("test-sdk")
50
50
  const middlewareService = app.resolve(MiddlewareService)
51
51
  expect(middlewareService).not.toBeUndefined()
52
52
  expect(app.resolve(MiddlewareService)).toBe(middlewareService)
@@ -57,8 +57,8 @@ test("SDK, services", async () => {
57
57
  })
58
58
 
59
59
  test("SDK, middleware", async () => {
60
- await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
61
- const app = await appSdk("test-middleware")
60
+ await appTest(UnitTest.DEFAULT, async () => {
61
+ const app = await dataIslandApp("test-middleware")
62
62
  const middlewareService = app.resolve(MiddlewareService)
63
63
  expect(middlewareService).not.toBeUndefined()
64
64
  expect(app.resolve(MiddlewareService)).toBe(middlewareService)
@@ -93,15 +93,15 @@ test("SDK, middleware", async () => {
93
93
  })
94
94
 
95
95
  test("SDK, it is impossible to setup the same application", async () => {
96
- await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
96
+ await appTest(UnitTest.DEFAULT, async () => {
97
97
  // this test is not stable if you run all tests at once
98
98
  // because the app is cached all app instances
99
99
  // we use a random identifier every time
100
100
  const testId = `test-setup-${randomHash()}`
101
- const promise = appSdk(testId).then(() => {
101
+ const promise = dataIslandApp(testId).then(() => {
102
102
  })
103
103
  await expect(
104
- appSdk(testId, async () => {
104
+ dataIslandApp(testId, async () => {
105
105
  })
106
106
  ).rejects.toThrow()
107
107
  await promise
@@ -109,14 +109,14 @@ test("SDK, it is impossible to setup the same application", async () => {
109
109
  })
110
110
 
111
111
  test("SDK, setup and get this app", async () => {
112
- await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
112
+ await appTest(UnitTest.DEFAULT, async () => {
113
113
  // this test is not stable if you run all tests at once
114
114
  // because the app is cached all app instances
115
115
  // we use a random identifier every time
116
116
  const testId = `test-get-${randomHash()}`
117
- const promise = appSdk(testId).then(() => {
117
+ const promise = dataIslandApp(testId).then(() => {
118
118
  })
119
- await expect(appSdk(testId)).resolves.toBeInstanceOf(AppSdk)
119
+ await expect(dataIslandApp(testId)).resolves.toBeInstanceOf(DataIslandApp)
120
120
  await promise
121
121
  })
122
122
  })
@@ -1,4 +1,4 @@
1
- import { appSdk, DebugCredential } from "../src"
1
+ import { dataIslandApp, DebugCredential } from "../src"
2
2
  import { HOST, randomHash, TOKEN } from "./setup"
3
3
  import { OrganizationImpl } from "../src/storages/organization.impl"
4
4
 
@@ -7,7 +7,7 @@ test("Organization", async () => {
7
7
  const randomName = `org-test-${randomHash()}`
8
8
 
9
9
  // create app
10
- const app = await appSdk(randomName, async builder => {
10
+ const app = await dataIslandApp(randomName, async builder => {
11
11
  builder.useHost(HOST)
12
12
  builder.useCredential(new DebugCredential(TOKEN))
13
13
  })
@@ -1,11 +1,11 @@
1
- import { appSdk, BasicCredential, DefaultCredential } from "../src"
1
+ import { dataIslandApp, BasicCredential, DefaultCredential } from "../src"
2
2
  import { CredentialService } from "../src/services/credentialService"
3
3
  import { MiddlewareService } from "../src/services/middlewareService"
4
- import { UnitTest, AppSdkUnitTest } from "../src/unitTest"
4
+ import { UnitTest, appTest } from "../src/unitTest"
5
5
 
6
6
  test("CredentialService", async () => {
7
- await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
8
- const app = await appSdk("test-services", async builder => {
7
+ await appTest(UnitTest.DEFAULT, async () => {
8
+ const app = await dataIslandApp("test-services", async builder => {
9
9
  builder.env.unitTest = UnitTest.DO_NOT_START
10
10
  })
11
11
  const credentialService = app.resolve(CredentialService)
package/test/setup.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { appSdk, AppSdk, DebugCredential } from "../src"
2
- import { Organization } from "../src/storages/organization"
3
- import { Workspace } from "../src/storages/workspace"
1
+ import { dataIslandApp, DataIslandApp, DebugCredential } from "../src"
2
+ import { Organization } from "../src"
3
+ import { Workspace } from "../src"
4
4
 
5
5
  export const HOST = <string>process.env.HOST
6
6
  export const TOKEN = <string>process.env.TOKEN
@@ -10,13 +10,13 @@ export const randomHash = (length: number = 5) => {
10
10
  return `name-${((Math.random() * Math.pow(10, length)) | 0).toString(16)}`
11
11
  }
12
12
 
13
- export const testInOrganization = async (func: (app: AppSdk, org: Organization) => Promise<void>, config ?: {
13
+ export const testInOrganization = async (func: (app: DataIslandApp, org: Organization) => Promise<void>, config ?: {
14
14
  host: string,
15
15
  token: string
16
16
  }
17
17
  ): Promise<void> => {
18
18
  const randomName = `org-name-${randomHash()}`
19
- const app = await appSdk(randomName, async builder => {
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
22
  })
@@ -35,7 +35,7 @@ export const testInOrganization = async (func: (app: AppSdk, org: Organization)
35
35
  }
36
36
  }
37
37
 
38
- export const testInWorkspace = async (func: (app: AppSdk, org: Organization, workspace: Workspace)
38
+ export const testInWorkspace = async (func: (app: DataIslandApp, org: Organization, workspace: Workspace)
39
39
  => Promise<void>, config?: {
40
40
  host: string,
41
41
  token: string,
@@ -1,21 +1,21 @@
1
- import { AppSdkUnitTest, UnitTest } from "../src/unitTest"
1
+ import { appTest, appTestCurrent, UnitTest } from "../src/unitTest"
2
2
 
3
3
  test("SDK, unitTest", async () => {
4
- expect(AppSdkUnitTest.current).toBe(UnitTest.DO_NOTHING)
4
+ expect(appTestCurrent()).toBe(UnitTest.DO_NOTHING)
5
5
  expect(
6
- await AppSdkUnitTest.test(UnitTest.DO_NOT_PRINT_INITIALIZED_LOG, () => {
7
- expect(AppSdkUnitTest.current).toBe(UnitTest.DO_NOT_PRINT_INITIALIZED_LOG)
6
+ await appTest(UnitTest.DO_NOT_PRINT_INITIALIZED_LOG, () => {
7
+ expect(appTestCurrent()).toBe(UnitTest.DO_NOT_PRINT_INITIALIZED_LOG)
8
8
  })
9
9
  )
10
10
  expect(
11
- await AppSdkUnitTest.test(
11
+ await appTest(
12
12
  UnitTest.DO_NOT_PRINT_INITIALIZED_LOG,
13
13
  async () => {
14
- expect(AppSdkUnitTest.current).toBe(
14
+ expect(appTestCurrent()).toBe(
15
15
  UnitTest.DO_NOT_PRINT_INITIALIZED_LOG
16
16
  )
17
17
  }
18
18
  )
19
19
  )
20
- expect(AppSdkUnitTest.current).toBe(UnitTest.DO_NOTHING)
20
+ expect(appTestCurrent()).toBe(UnitTest.DO_NOTHING)
21
21
  })