@dxos/react-client 2.18.1 → 2.19.1

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 (112) hide show
  1. package/.rush/temp/package-deps_build.json +53 -0
  2. package/.rush/temp/package-deps_build:test.json +23 -25
  3. package/.rush/temp/shrinkwrap-deps.json +59 -4
  4. package/README.md +6 -6
  5. package/dist/src/containers/ClientProvider.d.ts +29 -5
  6. package/dist/src/containers/ClientProvider.d.ts.map +1 -1
  7. package/dist/src/containers/ClientProvider.js +45 -4
  8. package/dist/src/containers/ClientProvider.js.map +1 -1
  9. package/dist/src/containers/ClientProvider.test.js +0 -2
  10. package/dist/src/containers/ClientProvider.test.js.map +1 -1
  11. package/dist/src/containers/index.d.ts +0 -2
  12. package/dist/src/containers/index.d.ts.map +1 -1
  13. package/dist/src/containers/index.js +0 -2
  14. package/dist/src/containers/index.js.map +1 -1
  15. package/dist/src/hooks/client/context.d.ts +5 -1
  16. package/dist/src/hooks/client/context.d.ts.map +1 -1
  17. package/dist/src/hooks/client/context.js.map +1 -1
  18. package/dist/src/hooks/client/useClient.d.ts +1 -1
  19. package/dist/src/hooks/client/useClient.d.ts.map +1 -1
  20. package/dist/src/hooks/client/useClient.js +3 -2
  21. package/dist/src/hooks/client/useClient.js.map +1 -1
  22. package/dist/src/hooks/client/useConfig.d.ts +2 -2
  23. package/dist/src/hooks/client/useConfig.d.ts.map +1 -1
  24. package/dist/src/hooks/client/useConfig.js +3 -3
  25. package/dist/src/hooks/client/useConfig.js.map +1 -1
  26. package/dist/src/hooks/client/useProfile.d.ts +2 -2
  27. package/dist/src/hooks/client/useProfile.d.ts.map +1 -1
  28. package/dist/src/hooks/client/useProfile.js +1 -1
  29. package/dist/src/hooks/echo-queries/useContacts.d.ts +1 -1
  30. package/dist/src/hooks/echo-queries/useContacts.js +2 -2
  31. package/dist/src/hooks/echo-queries/useContacts.js.map +1 -1
  32. package/dist/src/hooks/echo-queries/useMembers.d.ts +3 -2
  33. package/dist/src/hooks/echo-queries/useMembers.d.ts.map +1 -1
  34. package/dist/src/hooks/echo-queries/useMembers.js.map +1 -1
  35. package/dist/src/hooks/echo-queries/useParties.d.ts +6 -6
  36. package/dist/src/hooks/echo-queries/useParties.d.ts.map +1 -1
  37. package/dist/src/hooks/echo-queries/useParties.js +2 -2
  38. package/dist/src/hooks/echo-queries/useParties.js.map +1 -1
  39. package/dist/src/hooks/echo-queries/useRemoteParties.d.ts +3 -4
  40. package/dist/src/hooks/echo-queries/useRemoteParties.d.ts.map +1 -1
  41. package/dist/src/hooks/echo-queries/useRemoteParties.js +1 -1
  42. package/dist/src/hooks/echo-queries/useRemoteParties.js.map +1 -1
  43. package/dist/src/index.d.ts +1 -2
  44. package/dist/src/index.d.ts.map +1 -1
  45. package/dist/src/index.js +1 -2
  46. package/dist/src/index.js.map +1 -1
  47. package/dist/src/{containers → testing}/ProfileInitializer.d.ts +0 -0
  48. package/dist/src/testing/ProfileInitializer.d.ts.map +1 -0
  49. package/dist/src/{containers → testing}/ProfileInitializer.js +4 -2
  50. package/dist/src/testing/ProfileInitializer.js.map +1 -0
  51. package/dist/src/testing/index.d.ts +2 -0
  52. package/dist/src/testing/index.d.ts.map +1 -0
  53. package/dist/src/{components → testing}/index.js +1 -1
  54. package/dist/src/testing/index.js.map +1 -0
  55. package/dist/stories/client.stories.d.ts +1 -0
  56. package/dist/stories/client.stories.d.ts.map +1 -1
  57. package/dist/stories/client.stories.js +9 -6
  58. package/dist/stories/client.stories.js.map +1 -1
  59. package/dist/stories/halo-invitations.stories.js +3 -3
  60. package/dist/stories/halo-invitations.stories.js.map +1 -1
  61. package/dist/stories/helpers/ClientPanel.d.ts +2 -3
  62. package/dist/stories/helpers/ClientPanel.d.ts.map +1 -1
  63. package/dist/stories/helpers/ClientPanel.js +1 -5
  64. package/dist/stories/helpers/ClientPanel.js.map +1 -1
  65. package/dist/stories/party-invitations.stories.js +3 -3
  66. package/dist/stories/party-invitations.stories.js.map +1 -1
  67. package/dist/tests/config.test.js +1 -1
  68. package/dist/tests/config.test.js.map +1 -1
  69. package/dist/tsconfig.tsbuildinfo +1 -1
  70. package/esbuild-server.config.js +21 -0
  71. package/package.json +16 -12
  72. package/react-client.build.log +5 -5
  73. package/src/containers/ClientProvider.test.tsx +0 -2
  74. package/src/containers/ClientProvider.tsx +86 -7
  75. package/src/containers/index.ts +0 -2
  76. package/src/hooks/client/context.ts +5 -1
  77. package/src/hooks/client/useClient.ts +3 -2
  78. package/src/hooks/client/useConfig.ts +3 -3
  79. package/src/hooks/client/useProfile.ts +1 -1
  80. package/src/hooks/echo-queries/useContacts.ts +2 -2
  81. package/src/hooks/echo-queries/useMembers.tsx +3 -2
  82. package/src/hooks/echo-queries/useParties.ts +6 -6
  83. package/src/hooks/echo-queries/useRemoteParties.ts +4 -2
  84. package/src/index.ts +1 -2
  85. package/src/{containers → testing}/ProfileInitializer.tsx +4 -2
  86. package/src/testing/index.ts +5 -0
  87. package/stories/client.stories.tsx +14 -10
  88. package/stories/halo-invitations.stories.tsx +6 -6
  89. package/stories/helpers/ClientPanel.tsx +3 -8
  90. package/stories/party-invitations.stories.tsx +5 -5
  91. package/tests/config.test.ts +1 -1
  92. package/dist/src/components/ErrorBoundary.d.ts +0 -52
  93. package/dist/src/components/ErrorBoundary.d.ts.map +0 -1
  94. package/dist/src/components/ErrorBoundary.js +0 -78
  95. package/dist/src/components/ErrorBoundary.js.map +0 -1
  96. package/dist/src/components/index.d.ts +0 -2
  97. package/dist/src/components/index.d.ts.map +0 -1
  98. package/dist/src/components/index.js.map +0 -1
  99. package/dist/src/config.d.ts +0 -8
  100. package/dist/src/config.d.ts.map +0 -1
  101. package/dist/src/config.js +0 -11
  102. package/dist/src/config.js.map +0 -1
  103. package/dist/src/containers/ClientInitializer.d.ts +0 -30
  104. package/dist/src/containers/ClientInitializer.d.ts.map +0 -1
  105. package/dist/src/containers/ClientInitializer.js +0 -82
  106. package/dist/src/containers/ClientInitializer.js.map +0 -1
  107. package/dist/src/containers/ProfileInitializer.d.ts.map +0 -1
  108. package/dist/src/containers/ProfileInitializer.js.map +0 -1
  109. package/src/components/ErrorBoundary.tsx +0 -96
  110. package/src/components/index.ts +0 -5
  111. package/src/config.ts +0 -15
  112. package/src/containers/ClientInitializer.tsx +0 -121
@@ -0,0 +1,21 @@
1
+ //
2
+ // Copyright 2020 DXOS.org
3
+ //
4
+
5
+ const {
6
+ FixMemdownPlugin,
7
+ NodeGlobalsPolyfillPlugin,
8
+ NodeModulesPlugin
9
+ } = require('@dxos/esbuild-plugins');
10
+
11
+ /** @type {import('@dxos/esbuild-server').Config} */
12
+ module.exports = {
13
+ plugins: [
14
+ NodeGlobalsPolyfillPlugin(),
15
+ FixMemdownPlugin(),
16
+ NodeModulesPlugin()
17
+ ],
18
+ overrides: {
19
+ sourcemap: 'inline',
20
+ }
21
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-client",
3
- "version": "2.18.1",
3
+ "version": "2.19.1",
4
4
  "description": "React client API",
5
5
  "keywords": [],
6
6
  "license": "AGPL-3.0",
@@ -8,31 +8,35 @@
8
8
  "main": "dist/src/index.js",
9
9
  "types": "dist/src/index.d.ts",
10
10
  "scripts": {
11
+ "book": "esbuild-server book",
11
12
  "build": "toolchain build",
12
13
  "build:test": "toolchain build:test",
13
14
  "lint": "toolchain lint",
14
15
  "test": "toolchain test"
15
16
  },
16
17
  "dependencies": {
17
- "@dxos/async": "2.18.1",
18
- "@dxos/client": "2.18.1",
19
- "@dxos/config": "2.18.1",
20
- "@dxos/credentials": "2.18.1",
21
- "@dxos/crypto": "2.18.1",
22
- "@dxos/debug": "2.18.1",
23
- "@dxos/echo-db": "2.18.1",
24
- "@dxos/util": "2.18.1",
25
- "@types/debug": "^4.1.1",
18
+ "@dxos/async": "2.19.1",
19
+ "@dxos/client": "2.19.1",
20
+ "@dxos/config": "2.19.1",
21
+ "@dxos/credentials": "2.19.1",
22
+ "@dxos/crypto": "2.19.1",
23
+ "@dxos/debug": "2.19.1",
24
+ "@dxos/echo-db": "2.19.1",
25
+ "@dxos/esbuild-plugins": "2.19.1",
26
+ "@dxos/esbuild-server": "~1.4.1",
27
+ "@dxos/util": "2.19.1",
28
+ "@types/debug": "^4.1.7",
26
29
  "assert": "^2.0.0",
27
- "debug": "^4.1.1",
30
+ "debug": "^4.3.3",
28
31
  "react-display-name": "^0.2.5",
29
32
  "use-subscription": "^1.4.1"
30
33
  },
31
34
  "devDependencies": {
32
- "@dxos/toolchain-node-library": "2.18.1",
35
+ "@dxos/toolchain-node-library": "2.19.1",
33
36
  "@mui/material": "^5.0.1",
34
37
  "@testing-library/react": "^11.0.4",
35
38
  "@testing-library/react-hooks": "5.1.2",
39
+ "@types/debug": "^4.1.7",
36
40
  "@types/level-js": "~4.0.1",
37
41
  "@types/mocha": "~8.2.2",
38
42
  "@types/node": "^14.0.9",
@@ -2,10 +2,10 @@ Invoking: toolchain build:test
2
2
 
3
3
 
4
4
  typescript
5
- OK in 9465 ms
5
+ OK in 3964 ms
6
6
 
7
7
  eslint
8
- OK in 9863 ms
8
+ OK in 8771 ms
9
9
 
10
10
  mocha
11
11
  This browser doesn't support requestAnimationFrame. Make sure that you load a polyfill in older browsers. https://reactjs.org/link/react-polyfills
@@ -26,8 +26,8 @@ This browser doesn't support cancelAnimationFrame. Make sure that you load a pol
26
26
  ✓ should return custom client config when used properly in a context
27
27
 
28
28
 
29
- 7 passing (526ms)
29
+ 7 passing (271ms)
30
30
 
31
- OK in 11932 ms
31
+ OK in 11463 ms
32
32
 
33
- CHECK COMPLETE in 31268 ms
33
+ CHECK COMPLETE in 24205 ms
@@ -4,7 +4,6 @@
4
4
 
5
5
  import { screen, render } from '@testing-library/react';
6
6
  import expect from 'expect';
7
- // code import '@testing-library/jest-dom/extend-expect';
8
7
  import React from 'react';
9
8
 
10
9
  import { Client } from '@dxos/client';
@@ -29,7 +28,6 @@ describe('ClientProvider', () => {
29
28
  client = new Client();
30
29
  await client.initialize();
31
30
  await client.halo.createProfile({ username: 'test-user' });
32
- await client.echo.open();
33
31
  });
34
32
 
35
33
  after(async () => {
@@ -2,28 +2,107 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import React, { ReactNode, useEffect } from 'react';
5
+ import debug from 'debug';
6
+ import React, { MutableRefObject, ReactNode, useEffect, useState } from 'react';
6
7
 
7
- import { Client } from '@dxos/client';
8
+ import { Client, ClientOptions } from '@dxos/client';
9
+ import { Config, ConfigObject } from '@dxos/config';
10
+ import { MaybeFunction, MaybePromise, getAsyncValue } from '@dxos/util';
8
11
 
9
12
  import { ClientContext } from '../hooks';
10
13
 
14
+ const log = debug('dxos:react-client');
15
+
16
+ export type ClientProvider = MaybeFunction<MaybePromise<Client>>
17
+
18
+ // TODO(burdon): Why defs?
19
+ export type ConfigProvider = MaybeFunction<MaybePromise<Config | ConfigObject>>
20
+
11
21
  export interface ClientProviderProps {
12
- client: Client
13
22
  children?: ReactNode
23
+
24
+ /**
25
+ * Forward reference to provide client object to outercontainer since it won't have access to the context.
26
+ */
27
+ clientRef?: MutableRefObject<Client | undefined>
28
+
29
+ /**
30
+ * Client object or async provider to enable to caller to do custom initialization.
31
+ */
32
+ client?: ClientProvider
33
+
34
+ /**
35
+ * Config object or async provider.
36
+ */
37
+ config?: ConfigProvider
38
+
39
+ /**
40
+ * Runtime objects.
41
+ */
42
+ options?: ClientOptions
43
+
44
+ /**
45
+ * Post initialization hook.
46
+ * @param Client
47
+ */
48
+ onInitialize?: (client: Client) => Promise<void>
14
49
  }
15
50
 
16
51
  /**
17
52
  * Root component that provides the DXOS client instance to child components.
18
- * To be used with `useClient` hook.
53
+ * To be used with the `useClient` hook.
19
54
  */
20
- export const ClientProvider = ({ client, children }: ClientProviderProps) => {
55
+ export const ClientProvider = ({
56
+ children,
57
+ clientRef,
58
+ client: clientProvider,
59
+ config: configProvider,
60
+ options,
61
+ onInitialize
62
+ }: ClientProviderProps) => {
63
+ const [client, setClient] = useState<Client | undefined>(clientProvider instanceof Client ? clientProvider : undefined);
64
+
65
+ // Async helpers.
21
66
  useEffect(() => {
22
- (window as any).__DXOS__ = client.getDevtoolsContext();
67
+ if (!client) {
68
+ const done = async (client: Client) => {
69
+ log(`Created client: ${client}`);
70
+ if (clientRef) {
71
+ clientRef.current = client;
72
+ }
73
+ await onInitialize?.(client);
74
+ setClient(client);
75
+ };
76
+
77
+ // TODO(burdon): Error handling.
78
+ setImmediate(async () => {
79
+ if (clientProvider) {
80
+ // Asynchornously request client.
81
+ const client = await getAsyncValue(clientProvider);
82
+ await done(client);
83
+ } else {
84
+ // Asynchronously construct client (config may be undefined).
85
+ const config = await getAsyncValue(configProvider);
86
+ const client = new Client(config, options);
87
+ await client.initialize();
88
+ await done(client);
89
+ }
90
+ });
91
+ }
23
92
  }, []);
24
93
 
94
+ useEffect(() => {
95
+ if (client) {
96
+ (window as any).__DXOS__ = client.getDevtoolsContext();
97
+ }
98
+ }, [client]);
99
+
100
+ if (!client) {
101
+ return null;
102
+ }
103
+
25
104
  return (
26
- <ClientContext.Provider value={client}>
105
+ <ClientContext.Provider value={{ client }}>
27
106
  {children}
28
107
  </ClientContext.Provider>
29
108
  );
@@ -2,6 +2,4 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- export * from './ClientInitializer';
6
5
  export * from './ClientProvider';
7
- export * from './ProfileInitializer';
@@ -6,7 +6,11 @@ import { createContext } from 'react';
6
6
 
7
7
  import { Client } from '@dxos/client';
8
8
 
9
+ interface ClientContextProps {
10
+ client: Client
11
+ }
12
+
9
13
  /**
10
14
  * https://reactjs.org/docs/context.html#reactcreatecontext
11
15
  */
12
- export const ClientContext = createContext<Client | undefined>(undefined);
16
+ export const ClientContext = createContext<ClientContextProps | undefined>(undefined);
@@ -10,8 +10,9 @@ import { ClientContext } from './context';
10
10
 
11
11
  /**
12
12
  * Hook returning instance of DXOS client.
13
- * To be used with `ClientProvider` or `ClientInitializer` component wrapper.
13
+ * Requires ClientContext to be set via ClientProvider.
14
14
  */
15
15
  export const useClient = () => {
16
- return useContext(ClientContext) ?? raise(new Error('ClientContext no set.'));
16
+ const { client } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));
17
+ return client;
17
18
  };
@@ -10,9 +10,9 @@ import { ClientContext } from './context';
10
10
 
11
11
  /**
12
12
  * Hook returning config object used to initialize the DXOS client instance.
13
- * To be used with `ClientProvider` or `ClientInitializer` component wrapper.
13
+ * Requires ClientConext to be set via ClientProvider.
14
14
  */
15
15
  export const useConfig = () => {
16
- const { config } = useContext(ClientContext) ?? raise(new Error('ClientContext no set.'));
17
- return config;
16
+ const { client } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));
17
+ return client.config;
18
18
  };
@@ -8,7 +8,7 @@ import { useClient } from './useClient';
8
8
 
9
9
  /**
10
10
  * Hook returning DXOS user profile object.
11
- * To be used with `ClientProvider` or `ClientInitializer` component wrapper.
11
+ * Requires ClientConext to be set via ClientProvider.
12
12
  */
13
13
  export const useProfile = () => {
14
14
  const client = useClient();
@@ -11,14 +11,14 @@ import { useClient } from '../client';
11
11
  /**
12
12
  * Returns all known Contacts across all Parties.
13
13
  * Contacts are known members of a common Party.
14
- * To be used with `ClientProvider` or `ClientInitializer` component wrapper.
14
+ * Requires ClientConext to be set via ClientProvider.
15
15
  */
16
16
  export const useContacts = () => {
17
17
  const client = useClient();
18
18
  const [contacts, setContacts] = useState<PartyMember[]>([]);
19
19
 
20
20
  useEffect(() => {
21
- const result = client.echo.halo.queryContacts();
21
+ const result = client.halo.queryContacts();
22
22
  setContacts(result.value);
23
23
 
24
24
  const unsubscribe = result.subscribe(() => {
@@ -4,9 +4,10 @@
4
4
 
5
5
  import { useEffect, useState } from 'react';
6
6
 
7
- import { Party, PartyMember } from '@dxos/echo-db';
7
+ import { PartyProxy } from '@dxos/client';
8
+ import { PartyMember } from '@dxos/echo-db';
8
9
 
9
- export const useMembers = (party: Party | undefined) => {
10
+ export const useMembers = (party: PartyProxy | undefined) => {
10
11
  const [members, setMembers] = useState<PartyMember[]>([]);
11
12
 
12
13
  useEffect(() => {
@@ -4,28 +4,28 @@
4
4
 
5
5
  import { useEffect, useMemo, useState } from 'react';
6
6
 
7
+ import { PartyProxy } from '@dxos/client';
7
8
  import { PublicKey, PublicKeyLike } from '@dxos/crypto';
8
- import { Party } from '@dxos/echo-db';
9
9
 
10
10
  import { useClient } from '../client';
11
11
  import { useResultSet } from '../util';
12
12
 
13
13
  /**
14
14
  * Get a specific Party.
15
- * To be used with `ClientProvider` or `ClientInitializer` component wrapper.
15
+ * Requires ClientConext to be set via ClientProvider.
16
16
  */
17
- export const useParty = (partyKey?: PublicKeyLike) => {
17
+ export const useParty = (partyKey?: PublicKeyLike): PartyProxy | undefined => {
18
18
  const client = useClient();
19
19
  return partyKey ? client.echo.getParty(PublicKey.from(partyKey)) : undefined;
20
20
  };
21
21
 
22
22
  /**
23
23
  * Get all Parties available to current user.
24
- * To be used with `ClientProvider` or `ClientInitializer` component wrapper.
24
+ * Requires ClientConext to be set via ClientProvider.
25
25
  */
26
26
  export const useParties = () => {
27
27
  const client = useClient();
28
- const [parties, setParties] = useState<Party[]>([]);
28
+ const [parties, setParties] = useState<PartyProxy[]>([]);
29
29
 
30
30
  useEffect(() => {
31
31
  const result = client.echo.queryParties();
@@ -48,6 +48,6 @@ export const useParties = () => {
48
48
  /**
49
49
  * Get all known members of a Party.
50
50
  */
51
- export const usePartyMembers = (party: Party) => {
51
+ export const usePartyMembers = (party: PartyProxy) => {
52
52
  return useResultSet(useMemo(() => party.queryMembers(), [party.key.toHex()]));
53
53
  };
@@ -4,15 +4,17 @@
4
4
 
5
5
  import { useEffect, useState } from 'react';
6
6
 
7
+ import { Party } from '@dxos/client/src/proto/gen/dxos/client';
8
+
7
9
  import { useClient } from '../client';
8
10
 
9
11
  /**
10
12
  * Get all Parties available to current user.
11
- * To be used with `ClientProvider` or `ClientInitializer` component wrapper.
13
+ * Requires ClientConext to be set via ClientProvider.
12
14
  */
13
15
  export const useRemoteParties = () => {
14
16
  const client = useClient();
15
- const [parties, setParties] = useState<{key?: Uint8Array}[]>([]);
17
+ const [parties, setParties] = useState<Party[]>([]);
16
18
 
17
19
  useEffect(() => {
18
20
  const stream = client.services.PartyService.SubscribeParties();
package/src/index.ts CHANGED
@@ -2,7 +2,6 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- export * from './components';
6
5
  export * from './containers';
7
6
  export * from './hooks';
8
- export * from './config';
7
+ export * from './testing';
@@ -10,14 +10,16 @@ import { useClient, useProfile } from '../hooks';
10
10
  * Automatically creates a random DXOS profile.
11
11
  * @deprecated
12
12
  */
13
- // TODO(burdon): Testing-only.
13
+ // TODO(burdon): Testing-only; replace with useTestProfile();
14
14
  export const ProfileInitializer = ({ children }: { children: React.ReactNode }) => {
15
15
  const client = useClient();
16
16
  const profile = useProfile();
17
17
 
18
18
  useEffect(() => {
19
19
  if (!profile) {
20
- void client.halo.createProfile();
20
+ setImmediate(async () => {
21
+ await client.halo.createProfile();
22
+ });
21
23
  }
22
24
  }, []);
23
25
 
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2020 DXOS.org
3
+ //
4
+
5
+ export * from './ProfileInitializer';
@@ -4,11 +4,11 @@
4
4
 
5
5
  import React, { useEffect } from 'react';
6
6
 
7
- import { ClientInitializer, ErrorBoundary, useClient } from '../src';
8
- import { ClientPanel, ThemeProvider } from './helpers';
7
+ import { ClientProvider, useClient } from '../src';
8
+ import { ClientPanel } from './helpers';
9
9
 
10
10
  export default {
11
- title: 'react-client/ClientInitializer'
11
+ title: 'react-client/ClientProvider'
12
12
  };
13
13
 
14
14
  const TestApp = () => {
@@ -27,12 +27,16 @@ const TestApp = () => {
27
27
 
28
28
  export const Primary = () => {
29
29
  return (
30
- <ThemeProvider>
31
- <ErrorBoundary>
32
- <ClientInitializer config={{}}>
33
- <TestApp />
34
- </ClientInitializer>
35
- </ErrorBoundary>
36
- </ThemeProvider>
30
+ <ClientProvider>
31
+ <TestApp />
32
+ </ClientProvider>
33
+ );
34
+ };
35
+
36
+ export const Secondary = () => {
37
+ return (
38
+ <ClientProvider config={() => ({})}>
39
+ <TestApp />
40
+ </ClientProvider>
37
41
  );
38
42
  };
@@ -12,7 +12,7 @@ import { Awaited } from '@dxos/async';
12
12
  import { Client, decodeInvitation, PendingInvitation } from '@dxos/client';
13
13
 
14
14
  import {
15
- ClientInitializer,
15
+ ClientProvider,
16
16
  ProfileInitializer,
17
17
  useClient,
18
18
  useParties,
@@ -146,7 +146,7 @@ const TestApp = () => {
146
146
  <ClientPanel client={client} profile={profile} parties={parties} />
147
147
  <Divider />
148
148
  <HaloInvitationContainer />
149
- {!client.echo.halo.isInitialized && (
149
+ {!client.halo.isInitialized && (
150
150
  <>
151
151
  <Divider />
152
152
  <HaloAuthenticationContainer />
@@ -164,17 +164,17 @@ export const Primary = () => {
164
164
  <Container>
165
165
  <Box sx={{ display: 'flex', flex: 1, padding: 1, justifyContent: 'space-around' }}>
166
166
  {/* Instantiated Client. */}
167
- <ClientInitializer config={{}}>
167
+ <ClientProvider>
168
168
  <ProfileInitializer>
169
169
  <TestApp />
170
170
  </ProfileInitializer>
171
- </ClientInitializer>
171
+ </ClientProvider>
172
172
 
173
173
  {/* Joiners. */}
174
174
  {[...new Array(peers)].map((_, i) => (
175
- <ClientInitializer key={i} config={{}}>
175
+ <ClientProvider key={i}>
176
176
  <TestApp />
177
- </ClientInitializer>
177
+ </ClientProvider>
178
178
  ))}
179
179
  </Box>
180
180
  </Container>
@@ -6,8 +6,7 @@ import React from 'react';
6
6
 
7
7
  import { Box } from '@mui/material';
8
8
 
9
- import { Client } from '@dxos/client';
10
- import { Party } from '@dxos/echo-db';
9
+ import { Client, PartyProxy } from '@dxos/client';
11
10
 
12
11
  import { useProfile } from '../../src';
13
12
  import { JsonPanel } from './JsonPanel';
@@ -19,13 +18,9 @@ export const ClientPanel = ({
19
18
  }: {
20
19
  client: Client,
21
20
  profile?: Partial<ReturnType<typeof useProfile>>,
22
- parties?: Party[]
21
+ parties?: PartyProxy[]
23
22
  }) => {
24
- const data = (parties.length !== 0)
25
- ? {
26
- parties: parties.map(({ key }) => key.toHex())
27
- }
28
- : undefined;
23
+ const data = (parties.length !== 0) ? { parties: parties.map(({ key }) => key.toHex()) } : undefined;
29
24
 
30
25
  return (
31
26
  <Box>
@@ -13,7 +13,7 @@ import { PublicKey } from '@dxos/crypto';
13
13
  import { InvitationDescriptorType } from '@dxos/echo-db';
14
14
 
15
15
  import {
16
- ClientInitializer,
16
+ ClientProvider,
17
17
  ProfileInitializer,
18
18
  useClient,
19
19
  useContacts,
@@ -58,8 +58,8 @@ const PartyInvitationContainer = () => {
58
58
  const handleCreateInvitation = () => {
59
59
  setImmediate(async () => {
60
60
  const invitation = (contact)
61
- ? await client.createOfflineInvitation(partyKey!, PublicKey.fromHex(contact!))
62
- : await client.createInvitation(partyKey!, secretProvider, {
61
+ ? await client.echo.createOfflineInvitation(partyKey!, PublicKey.fromHex(contact!))
62
+ : await client.echo.createInvitation(partyKey!, { secretProvider }, {
63
63
  onFinish: () => { // TODO(burdon): Normalize callbacks (error, etc.)
64
64
  setInvitationCode(undefined);
65
65
  resetPin();
@@ -192,11 +192,11 @@ export const Primary = () => {
192
192
  <Container>
193
193
  <Box sx={{ display: 'flex', flex: 1, padding: 1, justifyContent: 'space-around' }}>
194
194
  {[...new Array(peers)].map((_, i) => (
195
- <ClientInitializer key={i} config={{}}>
195
+ <ClientProvider key={i}>
196
196
  <ProfileInitializer>
197
197
  <TestApp />
198
198
  </ProfileInitializer>
199
- </ClientInitializer>
199
+ </ClientProvider>
200
200
  ))}
201
201
  </Box>
202
202
  </Container>
@@ -14,7 +14,7 @@ describe('Config hook', () => {
14
14
  const { result } = renderHook(render);
15
15
  // TODO(burdon): Do NOT test functionality by matching literal error messages.
16
16
  expect(result.error?.message)
17
- .toEqual('`useConfig` hook is called outside of ClientContext. Wrap the component with `ClientProvider` or `ClientInitializer`');
17
+ .toEqual('`useConfig` hook is called outside of ClientContext. Use `ClientProvider`');
18
18
  });
19
19
 
20
20
  // TODO(burdon): Add test for context.
@@ -1,52 +0,0 @@
1
- import React, { Component, ErrorInfo } from 'react';
2
- /**
3
- * Root-level error boundary.
4
- * https://reactjs.org/docs/error-boundaries.html
5
- *
6
- * NOTE: Must currently be a Component.
7
- * https://reactjs.org/docs/hooks-faq.html#do-hooks-cover-all-use-cases-for-classes
8
- */
9
- export declare type ErrorCallbackType = (error: Error, errorInfo?: ErrorInfo) => void;
10
- export interface ErrorComponentProps {
11
- error: Error | null;
12
- onRestart?: () => void;
13
- onReset?: () => void;
14
- }
15
- interface ErrorBoundaryProps {
16
- onError: ErrorCallbackType;
17
- onRestart?: () => void;
18
- onReset?: () => void;
19
- errorComponent?: React.ComponentType<ErrorComponentProps>;
20
- }
21
- interface State {
22
- error: Error | null;
23
- }
24
- /**
25
- * Top-level error boundary.
26
- * NOTE: Doesn't catch exceptions in event handlers, or asynchronous callbacks.
27
- * A global error handler should be configured for such errors.
28
- * https://reactjs.org/docs/error-boundaries.html#how-about-event-handlers
29
- * https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror
30
- * It DOES catch exceptions in hooks and any components that return malformed React compoennts.
31
- */
32
- export declare class ErrorBoundary extends Component<ErrorBoundaryProps, State> {
33
- state: {
34
- error: null;
35
- };
36
- static defaultProps: {
37
- onError: {
38
- (...data: any[]): void;
39
- (message?: any, ...optionalParams: any[]): void;
40
- };
41
- onRestart: () => void;
42
- onReset: undefined;
43
- errorComponent: undefined;
44
- };
45
- static getDerivedStateFromError(error: any): {
46
- error: any;
47
- };
48
- componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
49
- render(): React.ReactNode;
50
- }
51
- export {};
52
- //# sourceMappingURL=ErrorBoundary.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ErrorBoundary.d.ts","sourceRoot":"","sources":["../../../src/components/ErrorBoundary.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIpD;;;;;;GAMG;AAEH,oBAAY,iBAAiB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;AAE9E,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,UAAU,kBAAkB;IAC1B,OAAO,EAAE,iBAAiB,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,cAAc,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,mBAAmB,CAAC,CAAA;CAC1D;AAED,UAAU,KAAK;IACb,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;CACpB;AAED;;;;;;;GAOG;AACH,qBAAa,aAAc,SAAQ,SAAS,CAAC,kBAAkB,EAAE,KAAK,CAAC;IAC5D,KAAK;;MAEZ;IAEF,MAAM,CAAC,YAAY;;;;;;;;MAOjB;IAEF,MAAM,CAAC,wBAAwB,CAAE,KAAK,EAAE,GAAG;;;IAIlC,iBAAiB,CAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS;IAKrD,MAAM;CA4BhB"}