@dxos/react-client 0.6.11-staging.e6894a4 → 0.6.12-main.5cc132e

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 (131) hide show
  1. package/dist/lib/browser/{chunk-NLQLAARM.mjs → chunk-ESSNDYBJ.mjs} +116 -79
  2. package/dist/lib/browser/chunk-ESSNDYBJ.mjs.map +7 -0
  3. package/dist/lib/browser/devtools/index.mjs +6 -18
  4. package/dist/lib/browser/devtools/index.mjs.map +3 -3
  5. package/dist/lib/browser/echo/index.mjs +4 -4
  6. package/dist/lib/browser/echo/index.mjs.map +1 -1
  7. package/dist/lib/browser/halo/index.mjs +5 -5
  8. package/dist/lib/browser/halo/index.mjs.map +1 -1
  9. package/dist/lib/browser/index.mjs +4 -4
  10. package/dist/lib/browser/index.mjs.map +1 -1
  11. package/dist/lib/browser/mesh/index.mjs +2 -2
  12. package/dist/lib/browser/mesh/index.mjs.map +1 -1
  13. package/dist/lib/browser/meta.json +1 -1
  14. package/dist/lib/browser/testing/index.mjs +108 -12
  15. package/dist/lib/browser/testing/index.mjs.map +4 -4
  16. package/dist/lib/node/{chunk-E3S6YHNJ.cjs → chunk-N474KOAU.cjs} +102 -69
  17. package/dist/lib/node/chunk-N474KOAU.cjs.map +7 -0
  18. package/dist/lib/node/devtools/index.cjs +8 -20
  19. package/dist/lib/node/devtools/index.cjs.map +3 -3
  20. package/dist/lib/node/echo/index.cjs +10 -10
  21. package/dist/lib/node/echo/index.cjs.map +2 -2
  22. package/dist/lib/node/halo/index.cjs +13 -13
  23. package/dist/lib/node/halo/index.cjs.map +2 -2
  24. package/dist/lib/node/index.cjs +15 -15
  25. package/dist/lib/node/index.cjs.map +1 -1
  26. package/dist/lib/node/mesh/index.cjs +4 -4
  27. package/dist/lib/node/mesh/index.cjs.map +1 -1
  28. package/dist/lib/node/meta.json +1 -1
  29. package/dist/lib/node/testing/index.cjs +106 -10
  30. package/dist/lib/node/testing/index.cjs.map +4 -4
  31. package/dist/lib/node-esm/chunk-AL2CUQ46.mjs +163 -0
  32. package/dist/lib/node-esm/chunk-AL2CUQ46.mjs.map +7 -0
  33. package/dist/lib/node-esm/chunk-ESSNDYBJ.mjs +300 -0
  34. package/dist/lib/node-esm/chunk-ESSNDYBJ.mjs.map +7 -0
  35. package/dist/lib/node-esm/devtools/index.mjs +43 -0
  36. package/dist/lib/node-esm/devtools/index.mjs.map +7 -0
  37. package/dist/lib/node-esm/echo/index.mjs +131 -0
  38. package/dist/lib/node-esm/echo/index.mjs.map +7 -0
  39. package/dist/lib/node-esm/halo/index.mjs +99 -0
  40. package/dist/lib/node-esm/halo/index.mjs.map +7 -0
  41. package/dist/lib/node-esm/index.mjs +32 -0
  42. package/dist/lib/node-esm/index.mjs.map +7 -0
  43. package/dist/lib/node-esm/invitations/index.mjs +17 -0
  44. package/dist/lib/node-esm/invitations/index.mjs.map +7 -0
  45. package/dist/lib/node-esm/mesh/index.mjs +17 -0
  46. package/dist/lib/node-esm/mesh/index.mjs.map +7 -0
  47. package/dist/lib/node-esm/meta.json +1 -0
  48. package/dist/lib/node-esm/testing/index.mjs +165 -0
  49. package/dist/lib/node-esm/testing/index.mjs.map +7 -0
  50. package/dist/lib/node-esm/worker.mjs +3 -0
  51. package/dist/lib/node-esm/worker.mjs.map +7 -0
  52. package/dist/types/src/client/AgentHostingProvider.d.ts +6 -0
  53. package/dist/types/src/client/AgentHostingProvider.d.ts.map +1 -1
  54. package/dist/types/src/client/ClientProvider.d.ts +108 -0
  55. package/dist/types/src/client/ClientProvider.d.ts.map +1 -0
  56. package/dist/types/src/client/ClientProvider.test.d.ts +2 -0
  57. package/dist/types/src/client/ClientProvider.test.d.ts.map +1 -0
  58. package/dist/types/src/client/context.d.ts +6 -0
  59. package/dist/types/src/client/context.d.ts.map +1 -0
  60. package/dist/types/src/client/index.d.ts +4 -2
  61. package/dist/types/src/client/index.d.ts.map +1 -1
  62. package/dist/types/src/client/useClient.d.ts +6 -0
  63. package/dist/types/src/client/useClient.d.ts.map +1 -0
  64. package/dist/types/src/client/useClientStatus.d.ts +3 -0
  65. package/dist/types/src/client/useClientStatus.d.ts.map +1 -0
  66. package/dist/types/src/devtools/useDevtools.d.ts.map +1 -1
  67. package/dist/types/src/index.d.ts +1 -1
  68. package/dist/types/src/playwright/playwright.config.d.ts +2 -2
  69. package/dist/types/src/playwright/playwright.config.d.ts.map +1 -1
  70. package/dist/types/src/testing/ClientRepeater.d.ts +6 -5
  71. package/dist/types/src/testing/ClientRepeater.d.ts.map +1 -1
  72. package/dist/types/src/testing/{decorators.stories.d.ts → ClientRepeater.stories.d.ts} +3 -3
  73. package/dist/types/src/testing/ClientRepeater.stories.d.ts.map +1 -0
  74. package/dist/types/src/testing/index.d.ts +1 -0
  75. package/dist/types/src/testing/index.d.ts.map +1 -1
  76. package/dist/types/src/testing/util.d.ts +14 -0
  77. package/dist/types/src/testing/util.d.ts.map +1 -0
  78. package/dist/types/src/testing/withClientProvider.d.ts +26 -0
  79. package/dist/types/src/testing/withClientProvider.d.ts.map +1 -0
  80. package/dist/types/src/testing/withClientProvider.stories.d.ts +13 -0
  81. package/dist/types/src/testing/withClientProvider.stories.d.ts.map +1 -0
  82. package/package.json +46 -34
  83. package/project.json +3 -23
  84. package/src/client/AgentHostingProvider.tsx +7 -6
  85. package/src/client/{ClientContext.test.tsx → ClientProvider.test.tsx} +9 -5
  86. package/src/client/ClientProvider.tsx +196 -0
  87. package/src/client/context.ts +20 -0
  88. package/src/client/index.ts +5 -2
  89. package/src/client/useClient.ts +18 -0
  90. package/src/client/useClientStatus.ts +21 -0
  91. package/src/client/useConfig.test.tsx +7 -11
  92. package/src/client/useConfig.ts +1 -1
  93. package/src/client/useShell.ts +1 -1
  94. package/src/client/useStatus.ts +1 -1
  95. package/src/devtools/useDevtools.ts +3 -7
  96. package/src/echo/useMembers.ts +1 -1
  97. package/src/echo/useSpaceInvitations.ts +1 -1
  98. package/src/echo/useSpaces.test.tsx +11 -37
  99. package/src/echo/useSpaces.ts +1 -1
  100. package/src/halo/useContacts.ts +1 -1
  101. package/src/halo/useDevices.test.tsx +4 -13
  102. package/src/halo/useDevices.ts +1 -1
  103. package/src/halo/useHaloInvitations.ts +1 -1
  104. package/src/halo/useIdentity.ts +1 -1
  105. package/src/index.ts +1 -1
  106. package/src/mesh/useNetworkStatus.ts +1 -1
  107. package/src/playwright/playwright.config.ts +13 -2
  108. package/src/playwright/smoke.spec.ts +5 -10
  109. package/src/testing/ClientRepeater.stories.tsx +58 -0
  110. package/src/testing/ClientRepeater.tsx +14 -13
  111. package/src/testing/index.ts +1 -0
  112. package/src/testing/util.tsx +39 -0
  113. package/src/testing/withClientProvider.stories.tsx +56 -0
  114. package/src/testing/withClientProvider.tsx +143 -0
  115. package/tsconfig.json +11 -3
  116. package/vitest.config.ts +22 -0
  117. package/dist/lib/browser/chunk-NLQLAARM.mjs.map +0 -7
  118. package/dist/lib/node/chunk-E3S6YHNJ.cjs.map +0 -7
  119. package/dist/types/src/client/ClientContext.d.ts +0 -57
  120. package/dist/types/src/client/ClientContext.d.ts.map +0 -1
  121. package/dist/types/src/client/ClientContext.stories.d.ts +0 -15
  122. package/dist/types/src/client/ClientContext.stories.d.ts.map +0 -1
  123. package/dist/types/src/client/ClientContext.test.d.ts +0 -2
  124. package/dist/types/src/client/ClientContext.test.d.ts.map +0 -1
  125. package/dist/types/src/client/useClientServices.d.ts +0 -3
  126. package/dist/types/src/client/useClientServices.d.ts.map +0 -1
  127. package/dist/types/src/testing/decorators.stories.d.ts.map +0 -1
  128. package/src/client/ClientContext.stories.tsx +0 -94
  129. package/src/client/ClientContext.tsx +0 -182
  130. package/src/client/useClientServices.ts +0 -15
  131. package/src/testing/decorators.stories.tsx +0 -63
@@ -11,15 +11,16 @@ import { log } from '@dxos/log';
11
11
 
12
12
  import { useClient } from '../client';
13
13
 
14
- /*
15
- * Interface for invoking the agent hosting provider client.
16
- * @experimental
17
- */
18
-
19
14
  export type AgentHostingProviderProps = { config: Config; halo: Halo };
20
15
 
21
16
  export const AgentHostingContext = createContext<AgentHostingProviderClient | null>(null);
22
17
 
18
+ /**
19
+ * Experimental agent hosting provider.
20
+ * @param props
21
+ * @constructor
22
+ * @deprecated
23
+ */
23
24
  export const AgentHostingProvider = (props: PropsWithChildren<{}>) => {
24
25
  const client = useClient();
25
26
  const [agentHostingProviderClient] = useState(makeClient(client));
@@ -52,7 +53,7 @@ const makeClient = ({ config, halo }: AgentHostingProviderProps) => {
52
53
  if (agentHostingProviderClient.init()) {
53
54
  return agentHostingProviderClient;
54
55
  } else {
55
- // Not authorized or error initializing
56
+ // Not authorized or error initializing.
56
57
  return null;
57
58
  }
58
59
  }
@@ -2,16 +2,16 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import { renderHook, screen, render, act } from '@testing-library/react';
6
- import expect from 'expect';
5
+ import { renderHook, screen, render, act, cleanup } from '@testing-library/react';
7
6
  import React, { Component, type PropsWithChildren } from 'react';
7
+ import { afterEach, beforeEach, describe, expect, test } from 'vitest';
8
8
 
9
9
  import { waitForCondition } from '@dxos/async';
10
10
  import { Client, Config, SystemStatus, fromHost } from '@dxos/client';
11
11
  import { log } from '@dxos/log';
12
- import { describe, test } from '@dxos/test';
13
12
 
14
- import { ClientProvider, useClient } from './ClientContext';
13
+ import { ClientProvider } from './ClientProvider';
14
+ import { useClient } from './useClient';
15
15
  import { useIdentity } from '../halo';
16
16
 
17
17
  log.config({ filter: 'ClientContext:debug,warn' });
@@ -96,6 +96,10 @@ describe('ClientProvider', () => {
96
96
  await client.halo.createIdentity({ displayName: 'test-user' });
97
97
  });
98
98
 
99
+ afterEach(() => {
100
+ cleanup();
101
+ });
102
+
99
103
  test('Renders with children', async () => {
100
104
  render(
101
105
  <ClientProvider client={client}>
@@ -147,7 +151,7 @@ describe('ClientProvider', () => {
147
151
 
148
152
  await act(async () => {
149
153
  await waitForCondition({
150
- condition: () => newClient.status.get() === SystemStatus.ACTIVE && !client.initialized,
154
+ condition: () => !client.initialized && newClient.status.get() === SystemStatus.ACTIVE,
151
155
  });
152
156
  });
153
157
  expect(client.initialized).toBe(false);
@@ -0,0 +1,196 @@
1
+ //
2
+ // Copyright 2020 DXOS.org
3
+ //
4
+
5
+ import React, {
6
+ forwardRef,
7
+ type FunctionComponent,
8
+ type ReactNode,
9
+ useEffect,
10
+ useImperativeHandle,
11
+ useState,
12
+ } from 'react';
13
+
14
+ import { Client, type ClientOptions, type ClientServicesProvider, SystemStatus } from '@dxos/client';
15
+ import { type Config } from '@dxos/config';
16
+ import { type S } from '@dxos/echo-schema';
17
+ import { registerSignalRuntime } from '@dxos/echo-signals/react';
18
+ import { log } from '@dxos/log';
19
+ import { useControlledValue } from '@dxos/react-hooks';
20
+ import { getAsyncProviderValue, type MaybePromise, type Provider } from '@dxos/util';
21
+
22
+ import { ClientContext, type ClientContextProps } from './context';
23
+ import { printBanner } from '../banner';
24
+
25
+ /**
26
+ * Properties for the ClientProvider.
27
+ */
28
+ export type ClientProviderProps = Pick<ClientContextProps, 'status'> &
29
+ Omit<ClientOptions, 'config' | 'services'> & {
30
+ children?: ReactNode;
31
+
32
+ /**
33
+ * Client object or async provider to enable to caller to do custom initialization.
34
+ *
35
+ * NOTE: For advanced use cases only.
36
+ */
37
+ client?: Client | Provider<Promise<Client>>;
38
+
39
+ /**
40
+ * Config object or async provider.
41
+ *
42
+ * NOTE: If a `client` is provided then `config` is ignored.
43
+ */
44
+ config?: Config | Provider<Promise<Config>>;
45
+
46
+ /**
47
+ * Callback to enable the caller to create a custom ClientServicesProvider.
48
+ *
49
+ * NOTE: If a `client` is provided then `services` is ignored.
50
+ */
51
+ services?: ClientServicesProvider | ((config?: Config) => MaybePromise<ClientServicesProvider>);
52
+
53
+ /**
54
+ * List of schema to register.
55
+ *
56
+ * NOTE: If a `client` is provided then `types` will not be added until after the children are first rendered.
57
+ */
58
+ types?: S.Schema<any>[];
59
+
60
+ /**
61
+ * ReactNode to display until the client is available.
62
+ */
63
+ fallback?: FunctionComponent<Partial<ClientContextProps>>;
64
+
65
+ /**
66
+ * Set to false to stop default signal runtime from being registered.
67
+ *
68
+ * The signals runtime is used to provide reactive updates to ECHO objects.
69
+ */
70
+ registerSignalRuntime?: boolean;
71
+
72
+ /**
73
+ * Skip the DXOS banner print.
74
+ */
75
+ disableBanner?: boolean;
76
+
77
+ /**
78
+ * Post initialization hook to enable to caller to do custom initialization.
79
+ *
80
+ * @param Client
81
+ */
82
+ onInitialized?: (client: Client) => MaybePromise<void>;
83
+ };
84
+
85
+ /**
86
+ * Root component that provides the DXOS client instance to child components.
87
+ * To be used with the `useClient` hook.
88
+ */
89
+ export const ClientProvider = forwardRef<Client | undefined, ClientProviderProps>(
90
+ (
91
+ {
92
+ children,
93
+ config: configProvider,
94
+ client: clientProvider,
95
+ services: servicesProvider,
96
+ types,
97
+ status: controlledStatus,
98
+ fallback: Fallback = () => null,
99
+ registerSignalRuntime: _registerSignalRuntime = true,
100
+ disableBanner,
101
+ onInitialized,
102
+ ...options
103
+ },
104
+ forwardedRef,
105
+ ) => {
106
+ useEffect(() => {
107
+ // TODO(wittjosiah): Ideally this should be imported asynchronously because it is optional.
108
+ // Unfortunately, async import seemed to break signals React instrumentation.
109
+ _registerSignalRuntime && registerSignalRuntime();
110
+ }, [_registerSignalRuntime]);
111
+
112
+ // The client is initialized asynchronously.
113
+ // If an error occurs during initialization, it is caught and the state is set.
114
+ // This allows the error to be thrown in the render method.
115
+ // The assumption is that a client initialization error is fatal to the app.
116
+ // This error will be caught by the nearest error boundary.
117
+ const [error, setError] = useState();
118
+ if (error) {
119
+ throw error;
120
+ }
121
+
122
+ const [client, setClient] = useState(clientProvider instanceof Client ? clientProvider : undefined);
123
+
124
+ // Provide external access.
125
+ useImperativeHandle(forwardedRef, () => client, [client]);
126
+
127
+ // Client status subscription.
128
+ const [status, setStatus] = useControlledValue(controlledStatus);
129
+ useEffect(() => {
130
+ if (!client) {
131
+ return;
132
+ }
133
+
134
+ const subscription = client.status.subscribe((status) => setStatus(status));
135
+ return () => subscription.unsubscribe();
136
+ }, [client]);
137
+
138
+ // Create and/or initialize client.
139
+ useEffect(() => {
140
+ const initialize = async (client: Client) => {
141
+ if (!client.initialized) {
142
+ await client.initialize().catch(setError);
143
+ log('client ready');
144
+ if (types) {
145
+ client.addTypes(types);
146
+ }
147
+ await onInitialized?.(client);
148
+ log('initialization complete');
149
+ } else if (types) {
150
+ client.addTypes(types);
151
+ }
152
+
153
+ setClient(client);
154
+
155
+ if (!disableBanner) {
156
+ printBanner(client);
157
+ }
158
+ };
159
+
160
+ let client: Client;
161
+ const t = setTimeout(async () => {
162
+ if (clientProvider) {
163
+ // Asynchronously request client.
164
+ client = await getAsyncProviderValue(clientProvider);
165
+ await initialize(client);
166
+ } else {
167
+ // Asynchronously construct client (config may be undefined).
168
+ const config = await getAsyncProviderValue(configProvider);
169
+ log('resolved config', { config });
170
+ const services = await getAsyncProviderValue(servicesProvider, config);
171
+ log('created services', { services });
172
+ client = new Client({ config, services, ...options });
173
+ log('created client');
174
+ await initialize(client);
175
+ }
176
+ });
177
+
178
+ return () => {
179
+ log('clean up');
180
+ clearTimeout(t);
181
+ void client
182
+ ?.destroy()
183
+ .then(() => {
184
+ log('destroyed');
185
+ })
186
+ .catch((err) => log.catch(err));
187
+ };
188
+ }, [configProvider, clientProvider, servicesProvider, disableBanner]);
189
+
190
+ if (!client?.initialized || status !== SystemStatus.ACTIVE) {
191
+ return <Fallback client={client} status={status} />;
192
+ }
193
+
194
+ return <ClientContext.Provider value={{ client, status }}>{children}</ClientContext.Provider>;
195
+ },
196
+ );
@@ -0,0 +1,20 @@
1
+ //
2
+ // Copyright 2020 DXOS.org
3
+ //
4
+
5
+ import { type Context, createContext } from 'react';
6
+
7
+ import { type Client, type SystemStatus } from '@dxos/client';
8
+
9
+ export type ClientContextProps = {
10
+ client: Client;
11
+
12
+ status?: SystemStatus | null;
13
+ };
14
+
15
+ /**
16
+ * @internal Use ClientProvider to create or initialize the Client.
17
+ */
18
+ export const ClientContext: Context<ClientContextProps | undefined> = createContext<ClientContextProps | undefined>(
19
+ undefined,
20
+ );
@@ -3,8 +3,11 @@
3
3
  //
4
4
 
5
5
  export * from './AgentHostingProvider';
6
- export * from './ClientContext';
7
- export * from './useClientServices';
6
+ export * from './ClientProvider';
7
+ export * from './context';
8
+
9
+ export * from './useClient';
10
+ export * from './useClientStatus';
8
11
  export * from './useConfig';
9
12
  export * from './useShell';
10
13
  export * from './useStatus';
@@ -0,0 +1,18 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { useContext } from 'react';
6
+
7
+ import { raise } from '@dxos/debug';
8
+
9
+ import { ClientContext } from '../client/context';
10
+
11
+ /**
12
+ * Hook returning instance of DXOS client.
13
+ * Requires ClientContext to be set via ClientProvider.
14
+ */
15
+ export const useClient = () => {
16
+ const { client } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));
17
+ return client;
18
+ };
@@ -0,0 +1,21 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { useEffect, useState } from 'react';
6
+
7
+ import { type Client, type SystemStatus } from '@dxos/client';
8
+
9
+ export const useClientStatus = (client: Client) => {
10
+ const [status, setStatus] = useState<SystemStatus | null>();
11
+ useEffect(() => {
12
+ if (!client) {
13
+ return;
14
+ }
15
+
16
+ const subscription = client.status.subscribe((status) => setStatus(status));
17
+ return () => subscription.unsubscribe();
18
+ }, [client, setStatus]);
19
+
20
+ return status;
21
+ };
@@ -3,15 +3,13 @@
3
3
  //
4
4
 
5
5
  import { act, renderHook } from '@testing-library/react';
6
- import expect from 'expect';
7
- import React from 'react';
6
+ import { describe, expect, test } from 'vitest';
8
7
 
9
8
  import { waitForCondition } from '@dxos/async';
10
- import { Client, Config, SystemStatus, fromHost } from '@dxos/client';
11
- import { describe, test } from '@dxos/test';
9
+ import { Config, SystemStatus } from '@dxos/client';
12
10
 
13
- import { ClientProvider } from './ClientContext';
14
11
  import { useConfig } from './useConfig';
12
+ import { createClient, createClientContextProvider } from '../testing/util';
15
13
 
16
14
  describe('Config hook', () => {
17
15
  const render = () => useConfig();
@@ -22,9 +20,8 @@ describe('Config hook', () => {
22
20
  });
23
21
 
24
22
  test('should return default client config when no config is passed in a context', async () => {
25
- const client = new Client({ services: fromHost() });
26
- await client.initialize();
27
- const wrapper = ({ children }: any) => <ClientProvider client={client}>{children}</ClientProvider>;
23
+ const { client } = await createClient();
24
+ const wrapper = await createClientContextProvider(client);
28
25
  const { result } = renderHook(render, { wrapper });
29
26
  await act(async () => {
30
27
  await waitForCondition({ condition: () => client.status.get() === SystemStatus.ACTIVE });
@@ -43,9 +40,8 @@ describe('Config hook', () => {
43
40
  },
44
41
  },
45
42
  });
46
- const client = new Client({ config, services: fromHost(config) });
47
- await client.initialize();
48
- const wrapper = ({ children }: any) => <ClientProvider client={client}>{children}</ClientProvider>;
43
+ const { client } = await createClient({ config });
44
+ const wrapper = await createClientContextProvider(client);
49
45
  const { result } = renderHook(render, { wrapper });
50
46
  await act(async () => {
51
47
  await waitForCondition({ condition: () => client.status.get() === SystemStatus.ACTIVE });
@@ -6,7 +6,7 @@ import { useContext } from 'react';
6
6
 
7
7
  import { raise } from '@dxos/debug';
8
8
 
9
- import { ClientContext } from './ClientContext';
9
+ import { ClientContext } from './context';
10
10
 
11
11
  /**
12
12
  * Hook returning config object used to initialize the DXOS client instance.
@@ -6,7 +6,7 @@ import { useEffect, useState } from 'react';
6
6
 
7
7
  import { type Shell, type ShellDisplay } from '@dxos/client';
8
8
 
9
- import { useClient } from './ClientContext';
9
+ import { useClient } from './useClient';
10
10
 
11
11
  /**
12
12
  * Helper hook to access the shell.
@@ -7,7 +7,7 @@ import { useContext } from 'react';
7
7
  import { type SystemStatus } from '@dxos/client';
8
8
  import { raise } from '@dxos/debug';
9
9
 
10
- import { ClientContext } from './ClientContext';
10
+ import { ClientContext } from './context';
11
11
 
12
12
  export const useStatus = (): SystemStatus | null | undefined => {
13
13
  const { status } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));
@@ -2,16 +2,12 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import { useContext } from 'react';
6
-
7
5
  import { type DevtoolsHost } from '@dxos/client/devtools';
8
6
  import { raise } from '@dxos/debug';
9
- import { invariant } from '@dxos/invariant';
10
7
 
11
- import { ClientContext } from '../client';
8
+ import { useClient } from '../client';
12
9
 
13
10
  export const useDevtools = (): DevtoolsHost => {
14
- const { services } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));
15
- invariant(services);
16
- return services.DevtoolsHost;
11
+ const client = useClient();
12
+ return client.services.services.DevtoolsHost ?? raise(new Error('DevtoolsHost not available.'));
17
13
  };
@@ -5,7 +5,7 @@
5
5
  import { MulticastObservable } from '@dxos/async';
6
6
  import { type PublicKey } from '@dxos/client';
7
7
  import { HaloSpaceMember, type SpaceMember } from '@dxos/client/echo';
8
- import { useMulticastObservable } from '@dxos/react-async';
8
+ import { useMulticastObservable } from '@dxos/react-hooks';
9
9
 
10
10
  import { useSpaces } from './useSpaces';
11
11
 
@@ -6,7 +6,7 @@ import { useMemo } from 'react';
6
6
 
7
7
  import { MulticastObservable } from '@dxos/async';
8
8
  import { type PublicKey } from '@dxos/client';
9
- import { useMulticastObservable } from '@dxos/react-async';
9
+ import { useMulticastObservable } from '@dxos/react-hooks';
10
10
 
11
11
  import { useSpace } from './useSpaces';
12
12
  import { type CancellableInvitationObservable, useInvitationStatus } from '../invitations';
@@ -3,38 +3,22 @@
3
3
  //
4
4
 
5
5
  import { act, renderHook } from '@testing-library/react';
6
- import { expect } from 'chai';
7
- import React from 'react';
8
-
9
- import { Client, fromHost } from '@dxos/client';
10
- import { describe, test } from '@dxos/test';
6
+ import { describe, expect, test } from 'vitest';
11
7
 
12
8
  import { useSpace, useSpaces } from './useSpaces';
13
- import { ClientContext } from '../client';
9
+ import { createClient, createClientContextProvider } from '../testing/util';
14
10
 
15
11
  describe('useSpaces', () => {
16
12
  test('lists existing spaces', async () => {
17
- const client = new Client({ services: fromHost() });
18
- await client.initialize();
19
- await client.halo.createIdentity();
20
- await client.spaces.isReady.wait();
21
- // TODO(wittjosiah): Factor out.
22
- const wrapper = ({ children }: any) => (
23
- <ClientContext.Provider value={{ client }}>{children}</ClientContext.Provider>
24
- );
13
+ const { client } = await createClient({ createIdentity: true });
14
+ const wrapper = await createClientContextProvider(client);
25
15
  const { result } = renderHook(() => useSpaces(), { wrapper });
26
16
  expect(result.current.length).to.eq(1);
27
17
  });
28
18
 
29
19
  test('updates when new spaces are created', async () => {
30
- const client = new Client({ services: fromHost() });
31
- await client.initialize();
32
- await client.halo.createIdentity();
33
- await client.spaces.isReady.wait();
34
- // TODO(wittjosiah): Factor out.
35
- const wrapper = ({ children }: any) => (
36
- <ClientContext.Provider value={{ client }}>{children}</ClientContext.Provider>
37
- );
20
+ const { client } = await createClient({ createIdentity: true });
21
+ const wrapper = await createClientContextProvider(client);
38
22
  const { result, rerender } = renderHook(() => useSpaces(), { wrapper });
39
23
  expect(result.current.length).to.eq(1);
40
24
  await act(async () => {
@@ -47,12 +31,8 @@ describe('useSpaces', () => {
47
31
 
48
32
  describe('useSpace', () => {
49
33
  test('gets default space', async () => {
50
- const client = new Client({ services: fromHost() });
51
- await client.initialize();
52
- // TODO(wittjosiah): Factor out.
53
- const wrapper = ({ children }: any) => (
54
- <ClientContext.Provider value={{ client }}>{children}</ClientContext.Provider>
55
- );
34
+ const { client } = await createClient();
35
+ const wrapper = await createClientContextProvider(client);
56
36
  const { result, rerender } = renderHook(() => useSpace(), { wrapper });
57
37
  expect(result.current).to.be.undefined;
58
38
  await act(async () => {
@@ -64,15 +44,9 @@ describe('useSpace', () => {
64
44
  });
65
45
 
66
46
  test('gets space by key', async () => {
67
- const client = new Client({ services: fromHost() });
68
- await client.initialize();
69
- await client.halo.createIdentity();
70
- const space = await client.spaces.create();
71
- // TODO(wittjosiah): Factor out.
72
- const wrapper = ({ children }: any) => (
73
- <ClientContext.Provider value={{ client }}>{children}</ClientContext.Provider>
74
- );
75
- const { result } = renderHook(() => useSpace(space.key), { wrapper });
47
+ const { client, space } = await createClient({ createIdentity: true, createSpace: true });
48
+ const wrapper = await createClientContextProvider(client);
49
+ const { result } = renderHook(() => useSpace(space!.key), { wrapper });
76
50
  expect(result.current).to.not.be.undefined;
77
51
  });
78
52
  });
@@ -6,7 +6,7 @@ import { useEffect, useState } from 'react';
6
6
 
7
7
  import { type PublicKeyLike } from '@dxos/client';
8
8
  import { type Space, SpaceState } from '@dxos/client/echo';
9
- import { useMulticastObservable } from '@dxos/react-async';
9
+ import { useMulticastObservable } from '@dxos/react-hooks';
10
10
 
11
11
  import { useClient } from '../client';
12
12
 
@@ -3,7 +3,7 @@
3
3
  //
4
4
 
5
5
  import type { Contact } from '@dxos/client/halo';
6
- import { useMulticastObservable } from '@dxos/react-async';
6
+ import { useMulticastObservable } from '@dxos/react-hooks';
7
7
 
8
8
  import { useClient } from '../client';
9
9
 
@@ -3,24 +3,15 @@
3
3
  //
4
4
 
5
5
  import { renderHook } from '@testing-library/react';
6
- import { expect } from 'chai';
7
- import React from 'react';
8
-
9
- import { Client, fromHost } from '@dxos/client';
10
- import { describe, test } from '@dxos/test';
6
+ import { describe, expect, test } from 'vitest';
11
7
 
12
8
  import { useDevices } from './useDevices';
13
- import { ClientContext } from '../client';
9
+ import { createClient, createClientContextProvider } from '../testing/util';
14
10
 
15
11
  describe('useDevices', () => {
16
12
  test('lists existing devices', async () => {
17
- const client = new Client({ services: fromHost() });
18
- await client.initialize();
19
- await client.halo.createIdentity();
20
- // TODO(wittjosiah): Factor out.
21
- const wrapper = ({ children }: any) => (
22
- <ClientContext.Provider value={{ client }}>{children}</ClientContext.Provider>
23
- );
13
+ const { client } = await createClient({ createIdentity: true });
14
+ const wrapper = await createClientContextProvider(client);
24
15
  const { result } = renderHook(() => useDevices(), { wrapper });
25
16
  expect(result.current?.length).to.eq(1);
26
17
  });
@@ -3,7 +3,7 @@
3
3
  //
4
4
 
5
5
  import type { Device } from '@dxos/client/halo';
6
- import { useMulticastObservable } from '@dxos/react-async';
6
+ import { useMulticastObservable } from '@dxos/react-hooks';
7
7
 
8
8
  import { useClient } from '../client';
9
9
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { useMemo } from 'react';
6
6
 
7
- import { useMulticastObservable } from '@dxos/react-async';
7
+ import { useMulticastObservable } from '@dxos/react-hooks';
8
8
 
9
9
  import { useClient } from '../client';
10
10
  import { useInvitationStatus, type CancellableInvitationObservable } from '../invitations';
@@ -3,7 +3,7 @@
3
3
  //
4
4
 
5
5
  import { type Identity } from '@dxos/client/halo';
6
- import { useMulticastObservable } from '@dxos/react-async';
6
+ import { useMulticastObservable } from '@dxos/react-hooks';
7
7
 
8
8
  import { useClient } from '../client';
9
9
 
package/src/index.ts CHANGED
@@ -3,6 +3,6 @@
3
3
  //
4
4
 
5
5
  export * from '@dxos/client';
6
- export { useMulticastObservable } from '@dxos/react-async';
6
+ export { useMulticastObservable } from '@dxos/react-hooks';
7
7
 
8
8
  export * from './client';
@@ -3,7 +3,7 @@
3
3
  //
4
4
 
5
5
  import { type NetworkStatus } from '@dxos/client/mesh';
6
- import { useMulticastObservable } from '@dxos/react-async';
6
+ import { useMulticastObservable } from '@dxos/react-hooks';
7
7
 
8
8
  import { useClient } from '../client';
9
9
 
@@ -2,6 +2,17 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { defaultPlaywrightConfig } from '@dxos/test/playwright';
5
+ import { nxE2EPreset } from '@nx/playwright/preset';
6
+ import { defineConfig } from '@playwright/test';
6
7
 
7
- export default defaultPlaywrightConfig;
8
+ import { e2ePreset } from '@dxos/test-utils/playwright';
9
+
10
+ export default defineConfig({
11
+ ...nxE2EPreset(__filename, { testDir: __dirname }),
12
+ ...e2ePreset(__dirname),
13
+ webServer: {
14
+ command: 'pnpm -w nx storybook-e2e stories',
15
+ port: 9009,
16
+ reuseExistingServer: !process.env.CI,
17
+ },
18
+ });