@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.
- package/dist/lib/browser/{chunk-NLQLAARM.mjs → chunk-ESSNDYBJ.mjs} +116 -79
- package/dist/lib/browser/chunk-ESSNDYBJ.mjs.map +7 -0
- package/dist/lib/browser/devtools/index.mjs +6 -18
- package/dist/lib/browser/devtools/index.mjs.map +3 -3
- package/dist/lib/browser/echo/index.mjs +4 -4
- package/dist/lib/browser/echo/index.mjs.map +1 -1
- package/dist/lib/browser/halo/index.mjs +5 -5
- package/dist/lib/browser/halo/index.mjs.map +1 -1
- package/dist/lib/browser/index.mjs +4 -4
- package/dist/lib/browser/index.mjs.map +1 -1
- package/dist/lib/browser/mesh/index.mjs +2 -2
- package/dist/lib/browser/mesh/index.mjs.map +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +108 -12
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/{chunk-E3S6YHNJ.cjs → chunk-N474KOAU.cjs} +102 -69
- package/dist/lib/node/chunk-N474KOAU.cjs.map +7 -0
- package/dist/lib/node/devtools/index.cjs +8 -20
- package/dist/lib/node/devtools/index.cjs.map +3 -3
- package/dist/lib/node/echo/index.cjs +10 -10
- package/dist/lib/node/echo/index.cjs.map +2 -2
- package/dist/lib/node/halo/index.cjs +13 -13
- package/dist/lib/node/halo/index.cjs.map +2 -2
- package/dist/lib/node/index.cjs +15 -15
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/mesh/index.cjs +4 -4
- package/dist/lib/node/mesh/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +106 -10
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/lib/node-esm/chunk-AL2CUQ46.mjs +163 -0
- package/dist/lib/node-esm/chunk-AL2CUQ46.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-ESSNDYBJ.mjs +300 -0
- package/dist/lib/node-esm/chunk-ESSNDYBJ.mjs.map +7 -0
- package/dist/lib/node-esm/devtools/index.mjs +43 -0
- package/dist/lib/node-esm/devtools/index.mjs.map +7 -0
- package/dist/lib/node-esm/echo/index.mjs +131 -0
- package/dist/lib/node-esm/echo/index.mjs.map +7 -0
- package/dist/lib/node-esm/halo/index.mjs +99 -0
- package/dist/lib/node-esm/halo/index.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +32 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/invitations/index.mjs +17 -0
- package/dist/lib/node-esm/invitations/index.mjs.map +7 -0
- package/dist/lib/node-esm/mesh/index.mjs +17 -0
- package/dist/lib/node-esm/mesh/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/testing/index.mjs +165 -0
- package/dist/lib/node-esm/testing/index.mjs.map +7 -0
- package/dist/lib/node-esm/worker.mjs +3 -0
- package/dist/lib/node-esm/worker.mjs.map +7 -0
- package/dist/types/src/client/AgentHostingProvider.d.ts +6 -0
- package/dist/types/src/client/AgentHostingProvider.d.ts.map +1 -1
- package/dist/types/src/client/ClientProvider.d.ts +108 -0
- package/dist/types/src/client/ClientProvider.d.ts.map +1 -0
- package/dist/types/src/client/ClientProvider.test.d.ts +2 -0
- package/dist/types/src/client/ClientProvider.test.d.ts.map +1 -0
- package/dist/types/src/client/context.d.ts +6 -0
- package/dist/types/src/client/context.d.ts.map +1 -0
- package/dist/types/src/client/index.d.ts +4 -2
- package/dist/types/src/client/index.d.ts.map +1 -1
- package/dist/types/src/client/useClient.d.ts +6 -0
- package/dist/types/src/client/useClient.d.ts.map +1 -0
- package/dist/types/src/client/useClientStatus.d.ts +3 -0
- package/dist/types/src/client/useClientStatus.d.ts.map +1 -0
- package/dist/types/src/devtools/useDevtools.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/playwright/playwright.config.d.ts +2 -2
- package/dist/types/src/playwright/playwright.config.d.ts.map +1 -1
- package/dist/types/src/testing/ClientRepeater.d.ts +6 -5
- package/dist/types/src/testing/ClientRepeater.d.ts.map +1 -1
- package/dist/types/src/testing/{decorators.stories.d.ts → ClientRepeater.stories.d.ts} +3 -3
- package/dist/types/src/testing/ClientRepeater.stories.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +1 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/util.d.ts +14 -0
- package/dist/types/src/testing/util.d.ts.map +1 -0
- package/dist/types/src/testing/withClientProvider.d.ts +26 -0
- package/dist/types/src/testing/withClientProvider.d.ts.map +1 -0
- package/dist/types/src/testing/withClientProvider.stories.d.ts +13 -0
- package/dist/types/src/testing/withClientProvider.stories.d.ts.map +1 -0
- package/package.json +46 -34
- package/project.json +3 -23
- package/src/client/AgentHostingProvider.tsx +7 -6
- package/src/client/{ClientContext.test.tsx → ClientProvider.test.tsx} +9 -5
- package/src/client/ClientProvider.tsx +196 -0
- package/src/client/context.ts +20 -0
- package/src/client/index.ts +5 -2
- package/src/client/useClient.ts +18 -0
- package/src/client/useClientStatus.ts +21 -0
- package/src/client/useConfig.test.tsx +7 -11
- package/src/client/useConfig.ts +1 -1
- package/src/client/useShell.ts +1 -1
- package/src/client/useStatus.ts +1 -1
- package/src/devtools/useDevtools.ts +3 -7
- package/src/echo/useMembers.ts +1 -1
- package/src/echo/useSpaceInvitations.ts +1 -1
- package/src/echo/useSpaces.test.tsx +11 -37
- package/src/echo/useSpaces.ts +1 -1
- package/src/halo/useContacts.ts +1 -1
- package/src/halo/useDevices.test.tsx +4 -13
- package/src/halo/useDevices.ts +1 -1
- package/src/halo/useHaloInvitations.ts +1 -1
- package/src/halo/useIdentity.ts +1 -1
- package/src/index.ts +1 -1
- package/src/mesh/useNetworkStatus.ts +1 -1
- package/src/playwright/playwright.config.ts +13 -2
- package/src/playwright/smoke.spec.ts +5 -10
- package/src/testing/ClientRepeater.stories.tsx +58 -0
- package/src/testing/ClientRepeater.tsx +14 -13
- package/src/testing/index.ts +1 -0
- package/src/testing/util.tsx +39 -0
- package/src/testing/withClientProvider.stories.tsx +56 -0
- package/src/testing/withClientProvider.tsx +143 -0
- package/tsconfig.json +11 -3
- package/vitest.config.ts +22 -0
- package/dist/lib/browser/chunk-NLQLAARM.mjs.map +0 -7
- package/dist/lib/node/chunk-E3S6YHNJ.cjs.map +0 -7
- package/dist/types/src/client/ClientContext.d.ts +0 -57
- package/dist/types/src/client/ClientContext.d.ts.map +0 -1
- package/dist/types/src/client/ClientContext.stories.d.ts +0 -15
- package/dist/types/src/client/ClientContext.stories.d.ts.map +0 -1
- package/dist/types/src/client/ClientContext.test.d.ts +0 -2
- package/dist/types/src/client/ClientContext.test.d.ts.map +0 -1
- package/dist/types/src/client/useClientServices.d.ts +0 -3
- package/dist/types/src/client/useClientServices.d.ts.map +0 -1
- package/dist/types/src/testing/decorators.stories.d.ts.map +0 -1
- package/src/client/ClientContext.stories.tsx +0 -94
- package/src/client/ClientContext.tsx +0 -182
- package/src/client/useClientServices.ts +0 -15
- 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
|
|
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
|
|
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
|
+
);
|
package/src/client/index.ts
CHANGED
|
@@ -3,8 +3,11 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
export * from './AgentHostingProvider';
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
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 '
|
|
7
|
-
import React from 'react';
|
|
6
|
+
import { describe, expect, test } from 'vitest';
|
|
8
7
|
|
|
9
8
|
import { waitForCondition } from '@dxos/async';
|
|
10
|
-
import {
|
|
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 =
|
|
26
|
-
await client
|
|
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 =
|
|
47
|
-
await client
|
|
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 });
|
package/src/client/useConfig.ts
CHANGED
package/src/client/useShell.ts
CHANGED
package/src/client/useStatus.ts
CHANGED
|
@@ -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 './
|
|
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 {
|
|
8
|
+
import { useClient } from '../client';
|
|
12
9
|
|
|
13
10
|
export const useDevtools = (): DevtoolsHost => {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
return services.DevtoolsHost;
|
|
11
|
+
const client = useClient();
|
|
12
|
+
return client.services.services.DevtoolsHost ?? raise(new Error('DevtoolsHost not available.'));
|
|
17
13
|
};
|
package/src/echo/useMembers.ts
CHANGED
|
@@ -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-
|
|
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-
|
|
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 '
|
|
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 {
|
|
9
|
+
import { createClient, createClientContextProvider } from '../testing/util';
|
|
14
10
|
|
|
15
11
|
describe('useSpaces', () => {
|
|
16
12
|
test('lists existing spaces', async () => {
|
|
17
|
-
const client =
|
|
18
|
-
await client
|
|
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 =
|
|
31
|
-
await client
|
|
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 =
|
|
51
|
-
await client
|
|
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 =
|
|
68
|
-
await client
|
|
69
|
-
|
|
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
|
});
|
package/src/echo/useSpaces.ts
CHANGED
|
@@ -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-
|
|
9
|
+
import { useMulticastObservable } from '@dxos/react-hooks';
|
|
10
10
|
|
|
11
11
|
import { useClient } from '../client';
|
|
12
12
|
|
package/src/halo/useContacts.ts
CHANGED
|
@@ -3,24 +3,15 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { renderHook } from '@testing-library/react';
|
|
6
|
-
import { expect } from '
|
|
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 {
|
|
9
|
+
import { createClient, createClientContextProvider } from '../testing/util';
|
|
14
10
|
|
|
15
11
|
describe('useDevices', () => {
|
|
16
12
|
test('lists existing devices', async () => {
|
|
17
|
-
const client =
|
|
18
|
-
await client
|
|
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
|
});
|
package/src/halo/useDevices.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { useMemo } from 'react';
|
|
6
6
|
|
|
7
|
-
import { useMulticastObservable } from '@dxos/react-
|
|
7
|
+
import { useMulticastObservable } from '@dxos/react-hooks';
|
|
8
8
|
|
|
9
9
|
import { useClient } from '../client';
|
|
10
10
|
import { useInvitationStatus, type CancellableInvitationObservable } from '../invitations';
|
package/src/halo/useIdentity.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { nxE2EPreset } from '@nx/playwright/preset';
|
|
6
|
+
import { defineConfig } from '@playwright/test';
|
|
6
7
|
|
|
7
|
-
|
|
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
|
+
});
|