@dxos/react-client 2.28.6-dev.ca9d0e33 → 2.28.6

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 (43) hide show
  1. package/.rush/temp/package-deps_build.json +9 -8
  2. package/.rush/temp/package-deps_build:test.json +9 -8
  3. package/.rush/temp/package-deps_prerelease.json +9 -8
  4. package/dist/src/banner.d.ts.map +1 -1
  5. package/dist/src/banner.js +0 -1
  6. package/dist/src/banner.js.map +1 -1
  7. package/dist/src/containers/BotFactoryClientProvider.d.ts +9 -0
  8. package/dist/src/containers/BotFactoryClientProvider.d.ts.map +1 -0
  9. package/dist/src/containers/BotFactoryClientProvider.js +55 -0
  10. package/dist/src/containers/BotFactoryClientProvider.js.map +1 -0
  11. package/dist/src/containers/ClientProvider.d.ts +1 -2
  12. package/dist/src/containers/ClientProvider.d.ts.map +1 -1
  13. package/dist/src/containers/ClientProvider.js +2 -1
  14. package/dist/src/containers/ClientProvider.js.map +1 -1
  15. package/dist/src/containers/index.d.ts +1 -0
  16. package/dist/src/containers/index.d.ts.map +1 -1
  17. package/dist/src/containers/index.js +1 -0
  18. package/dist/src/containers/index.js.map +1 -1
  19. package/dist/src/hooks/bot-factory/useBotFactoryClient.d.ts +4 -1
  20. package/dist/src/hooks/bot-factory/useBotFactoryClient.d.ts.map +1 -1
  21. package/dist/src/hooks/bot-factory/useBotFactoryClient.js +18 -23
  22. package/dist/src/hooks/bot-factory/useBotFactoryClient.js.map +1 -1
  23. package/dist/src/hooks/client/context.d.ts +0 -3
  24. package/dist/src/hooks/client/context.d.ts.map +1 -1
  25. package/dist/src/hooks/client/context.js +0 -3
  26. package/dist/src/hooks/client/context.js.map +1 -1
  27. package/dist/src/hooks/index.d.ts +2 -2
  28. package/dist/src/hooks/index.d.ts.map +1 -1
  29. package/dist/src/hooks/index.js +2 -2
  30. package/dist/src/hooks/index.js.map +1 -1
  31. package/dist/stories/halo-invitations.stories.d.ts.map +1 -1
  32. package/dist/stories/halo-invitations.stories.js.map +1 -1
  33. package/dist/tsconfig.tsbuildinfo +1 -1
  34. package/out/book/index.js +14 -7
  35. package/package.json +12 -12
  36. package/src/banner.ts +0 -2
  37. package/src/containers/BotFactoryClientProvider.tsx +50 -0
  38. package/src/containers/ClientProvider.tsx +3 -5
  39. package/src/containers/index.ts +1 -0
  40. package/src/hooks/bot-factory/useBotFactoryClient.ts +19 -23
  41. package/src/hooks/client/context.ts +0 -3
  42. package/src/hooks/index.ts +2 -2
  43. package/stories/halo-invitations.stories.tsx +1 -3
package/package.json CHANGED
@@ -1,22 +1,22 @@
1
1
  {
2
2
  "name": "@dxos/react-client",
3
- "version": "2.28.6-dev.ca9d0e33",
3
+ "version": "2.28.6",
4
4
  "description": "React client API",
5
5
  "license": "MIT",
6
6
  "author": "DXOS.org",
7
7
  "main": "dist/src/index.js",
8
8
  "types": "dist/src/index.d.ts",
9
9
  "dependencies": {
10
- "@dxos/async": "2.28.6-dev.ca9d0e33",
11
- "@dxos/bot-factory-client": "2.28.6-dev.ca9d0e33",
12
- "@dxos/client": "2.28.6-dev.ca9d0e33",
13
- "@dxos/config": "2.28.6-dev.ca9d0e33",
14
- "@dxos/credentials": "2.28.6-dev.ca9d0e33",
15
- "@dxos/crypto": "2.28.6-dev.ca9d0e33",
16
- "@dxos/debug": "2.28.6-dev.ca9d0e33",
17
- "@dxos/echo-db": "2.28.6-dev.ca9d0e33",
18
- "@dxos/network-manager": "2.28.6-dev.ca9d0e33",
19
- "@dxos/util": "2.28.6-dev.ca9d0e33",
10
+ "@dxos/async": "2.28.6",
11
+ "@dxos/bot-factory-client": "2.28.6",
12
+ "@dxos/client": "2.28.6",
13
+ "@dxos/config": "2.28.6",
14
+ "@dxos/credentials": "2.28.6",
15
+ "@dxos/crypto": "2.28.6",
16
+ "@dxos/debug": "2.28.6",
17
+ "@dxos/echo-db": "2.28.6",
18
+ "@dxos/network-manager": "2.28.6",
19
+ "@dxos/util": "2.28.6",
20
20
  "assert": "^2.0.0",
21
21
  "debug": "^4.3.3",
22
22
  "use-subscription": "^1.4.1"
@@ -24,7 +24,7 @@
24
24
  "devDependencies": {
25
25
  "@dxos/esbuild-plugins": "~2.28.4",
26
26
  "@dxos/eslint-plugin": "~1.0.27",
27
- "@dxos/protocols-toolchain": "2.28.5",
27
+ "@dxos/protocols-toolchain": "2.28.6",
28
28
  "@mui/material": "^5.4.2",
29
29
  "@testing-library/react": "^11.0.4",
30
30
  "@testing-library/react-hooks": "5.1.2",
package/src/banner.ts CHANGED
@@ -4,9 +4,7 @@
4
4
 
5
5
  import { Client } from '@dxos/client';
6
6
 
7
- // TODO(burdon): Print version.
8
7
  // http://patorjk.com/software/taag/#p=testall&f=Patorjk-HeX&t=DXOS
9
-
10
8
  const BANNER = (client: Client) => '\n' +
11
9
  '_/\\/\\/\\/\\/\\____/\\/\\____/\\/\\____/\\/\\/\\/\\______/\\/\\/\\/\\/\\_\n' +
12
10
  '_/\\/\\____/\\/\\____/\\/\\/\\/\\____/\\/\\____/\\/\\__/\\/\\_________\n' +
@@ -0,0 +1,50 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ import React, { ReactNode, useEffect, useState } from 'react';
6
+
7
+ import { BotFactoryClient } from '@dxos/bot-factory-client';
8
+ import { PublicKey } from '@dxos/crypto';
9
+ import { raise } from '@dxos/debug';
10
+
11
+ import { BotFactoryClientContext, createBotFactoryClient, useConfig } from '../hooks';
12
+
13
+ export interface BotFactoryClientProviderProps {
14
+ children?: ReactNode
15
+ }
16
+
17
+ /**
18
+ * BotFactoryClientProvider
19
+ */
20
+ export const BotFactoryClientProvider = ({
21
+ children
22
+ }: BotFactoryClientProviderProps) => {
23
+ const config = useConfig();
24
+ const [botFactoryClient, setBotFactoryClient] = useState<BotFactoryClient>();
25
+
26
+ useEffect(() => {
27
+ setImmediate(async () => {
28
+ const botFactoryClient = await createBotFactoryClient(config);
29
+ setBotFactoryClient(botFactoryClient);
30
+
31
+ // TODO(burdon): Rename property: 'runtime.services.bot-factory.topic'
32
+ const topic = config.get('runtime.services.bot.topic') ?? raise(new Error('Missing Bot factory topic.'));
33
+ await botFactoryClient.start(PublicKey.from(topic));
34
+ });
35
+
36
+ return () => {
37
+ void botFactoryClient?.stop();
38
+ };
39
+ }, []);
40
+
41
+ if (!botFactoryClient) {
42
+ return null;
43
+ }
44
+
45
+ return (
46
+ <BotFactoryClientContext.Provider value={botFactoryClient}>
47
+ {children}
48
+ </BotFactoryClientContext.Provider>
49
+ );
50
+ };
@@ -6,7 +6,7 @@ import debug from 'debug';
6
6
  import React, { MutableRefObject, ReactNode, useEffect, useState } from 'react';
7
7
 
8
8
  import { Client, ClientOptions } from '@dxos/client';
9
- import { Config, ConfigObject } from '@dxos/config';
9
+ import { ConfigProvider } from '@dxos/config';
10
10
  import { MaybeFunction, MaybePromise, getAsyncValue } from '@dxos/util';
11
11
 
12
12
  import { printBanner } from '../banner';
@@ -16,9 +16,6 @@ const log = debug('dxos:react-client');
16
16
 
17
17
  export type ClientProvider = MaybeFunction<MaybePromise<Client>>
18
18
 
19
- // TODO(burdon): Why defs?
20
- export type ConfigProvider = MaybeFunction<MaybePromise<Config | ConfigObject>>
21
-
22
19
  export interface ClientProviderProps {
23
20
  children?: ReactNode
24
21
 
@@ -76,7 +73,6 @@ export const ClientProvider = ({
76
73
  printBanner(client);
77
74
  };
78
75
 
79
- // TODO(burdon): Error handling.
80
76
  setImmediate(async () => {
81
77
  if (clientProvider) {
82
78
  // Asynchornously request client.
@@ -93,6 +89,8 @@ export const ClientProvider = ({
93
89
  }
94
90
  }, []);
95
91
 
92
+ // Console debug access.
93
+ // TODO(burdon): Debug only.
96
94
  useEffect(() => {
97
95
  if (client) {
98
96
  (window as any).__DXOS__ = client.getDevtoolsContext();
@@ -2,4 +2,5 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
+ export * from './BotFactoryClientProvider';
5
6
  export * from './ClientProvider';
@@ -2,34 +2,30 @@
2
2
  // Copyright 2021 DXOS.org
3
3
  //
4
4
 
5
- import { useEffect, useState } from 'react';
5
+ import { createContext, useContext } from 'react';
6
6
 
7
7
  import { BotFactoryClient } from '@dxos/bot-factory-client';
8
8
  import { Config } from '@dxos/config';
9
- import { PublicKey } from '@dxos/crypto';
10
- import { raise } from '@dxos/debug';
11
9
  import { NetworkManager } from '@dxos/network-manager';
12
10
 
13
- export const useBotFactoryClient = (config: Config): BotFactoryClient | undefined => {
14
- const [botFactoryClient, setBotFactoryClient] = useState<BotFactoryClient>();
11
+ export const BotFactoryClientContext = createContext<BotFactoryClient | undefined>(undefined);
15
12
 
16
- useEffect(() => {
17
- const networkManager = new NetworkManager({
18
- signal: config.get('runtime.services.signal.server') ? [config.get('runtime.services.signal.server')!] : undefined,
19
- ice: config.get('runtime.services.ice'),
20
- log: true
21
- });
22
- const botFactoryClient = new BotFactoryClient(networkManager);
23
- const topic = config.get('runtime.services.bot.topic') ??
24
- raise(new Error('Bot factory topic is not provided'));
25
- setImmediate(async () => {
26
- await botFactoryClient.start(PublicKey.from(topic));
27
- setBotFactoryClient(botFactoryClient);
28
- });
29
- return () => {
30
- void botFactoryClient.stop();
31
- };
32
- }, []);
13
+ export const useBotFactoryClient = (required = true): BotFactoryClient | undefined => {
14
+ const client = useContext(BotFactoryClientContext);
15
+ if (required && !client) {
16
+ throw new Error('Missing BotFactoryClientContext.');
17
+ }
33
18
 
34
- return botFactoryClient;
19
+ return client;
20
+ };
21
+
22
+ export const createBotFactoryClient = async (config: Config): Promise<BotFactoryClient> => {
23
+ const signal = config.get('runtime.services.signal.server');
24
+ const networkManager = new NetworkManager({
25
+ signal: signal ? [signal] : undefined,
26
+ ice: config.get('runtime.services.ice'),
27
+ log: true
28
+ });
29
+
30
+ return new BotFactoryClient(networkManager);
35
31
  };
@@ -10,7 +10,4 @@ interface ClientContextProps {
10
10
  client: Client
11
11
  }
12
12
 
13
- /**
14
- * https://reactjs.org/docs/context.html#reactcreatecontext
15
- */
16
13
  export const ClientContext = createContext<ClientContextProps | undefined>(undefined);
@@ -2,10 +2,10 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
+ export * from './bot-factory';
5
6
  export * from './client';
6
7
  export * from './echo-queries';
7
8
  export * from './echo-selections';
8
9
  export * from './invitations';
9
- export * from './wns';
10
10
  export * from './util';
11
- export * from './bot-factory';
11
+ export * from './wns';
@@ -4,9 +4,7 @@
4
4
 
5
5
  import React, { useState } from 'react';
6
6
 
7
- import {
8
- Box, Button, Divider, Paper, TextField, Toolbar
9
- } from '@mui/material';
7
+ import { Box, Button, Divider, Paper, TextField, Toolbar } from '@mui/material';
10
8
 
11
9
  import { Invitation, InvitationDescriptor } from '@dxos/client';
12
10