@dxos/react-client 0.6.11-staging.e6894a4 → 0.6.12-main.15a606f
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 +9 -7
- package/dist/lib/browser/echo/index.mjs.map +3 -3
- 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 +115 -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 +14 -12
- package/dist/lib/node/echo/index.cjs.map +3 -3
- 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 +113 -10
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/lib/node-esm/chunk-ACLHQASD.mjs +302 -0
- package/dist/lib/node-esm/chunk-ACLHQASD.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-UYJUBYMU.mjs +165 -0
- package/dist/lib/node-esm/chunk-UYJUBYMU.mjs.map +7 -0
- package/dist/lib/node-esm/devtools/index.mjs +44 -0
- package/dist/lib/node-esm/devtools/index.mjs.map +7 -0
- package/dist/lib/node-esm/echo/index.mjs +134 -0
- package/dist/lib/node-esm/echo/index.mjs.map +7 -0
- package/dist/lib/node-esm/halo/index.mjs +100 -0
- package/dist/lib/node-esm/halo/index.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +33 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/invitations/index.mjs +18 -0
- package/dist/lib/node-esm/invitations/index.mjs.map +7 -0
- package/dist/lib/node-esm/mesh/index.mjs +18 -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 +173 -0
- package/dist/lib/node-esm/testing/index.mjs.map +7 -0
- package/dist/lib/node-esm/worker.mjs +5 -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/echo/useQuery.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 +29 -0
- package/dist/types/src/testing/withClientProvider.d.ts.map +1 -0
- package/dist/types/src/testing/withClientProvider.stories.d.ts +14 -0
- package/dist/types/src/testing/withClientProvider.stories.d.ts.map +1 -0
- package/package.json +48 -36
- 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/useQuery.ts +3 -6
- 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 +65 -0
- package/src/testing/withClientProvider.tsx +146 -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
package/package.json
CHANGED
|
@@ -1,65 +1,73 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-client",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.12-main.15a606f",
|
|
4
4
|
"description": "React client API",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"author": "DXOS.org",
|
|
9
9
|
"exports": {
|
|
10
|
-
".": {
|
|
11
|
-
"browser": "./dist/lib/browser/index.mjs",
|
|
12
|
-
"node": {
|
|
13
|
-
"default": "./dist/lib/node/index.cjs"
|
|
14
|
-
},
|
|
15
|
-
"types": "./dist/types/src/index.d.ts"
|
|
16
|
-
},
|
|
17
10
|
"./devtools": {
|
|
18
11
|
"browser": "./dist/lib/browser/devtools/index.mjs",
|
|
19
12
|
"node": {
|
|
20
|
-
"
|
|
13
|
+
"require": "./dist/lib/node/devtools/index.cjs",
|
|
14
|
+
"default": "./dist/lib/node-esm/devtools/index.mjs"
|
|
21
15
|
},
|
|
22
16
|
"types": "./dist/types/src/devtools/index.d.ts"
|
|
23
17
|
},
|
|
24
18
|
"./echo": {
|
|
25
19
|
"browser": "./dist/lib/browser/echo/index.mjs",
|
|
26
20
|
"node": {
|
|
27
|
-
"
|
|
21
|
+
"require": "./dist/lib/node/echo/index.cjs",
|
|
22
|
+
"default": "./dist/lib/node-esm/echo/index.mjs"
|
|
28
23
|
},
|
|
29
24
|
"types": "./dist/types/src/echo/index.d.ts"
|
|
30
25
|
},
|
|
31
26
|
"./halo": {
|
|
32
27
|
"browser": "./dist/lib/browser/halo/index.mjs",
|
|
33
28
|
"node": {
|
|
34
|
-
"
|
|
29
|
+
"require": "./dist/lib/node/halo/index.cjs",
|
|
30
|
+
"default": "./dist/lib/node-esm/halo/index.mjs"
|
|
35
31
|
},
|
|
36
32
|
"types": "./dist/types/src/halo/index.d.ts"
|
|
37
33
|
},
|
|
34
|
+
".": {
|
|
35
|
+
"browser": "./dist/lib/browser/index.mjs",
|
|
36
|
+
"node": {
|
|
37
|
+
"require": "./dist/lib/node/index.cjs",
|
|
38
|
+
"default": "./dist/lib/node-esm/index.mjs"
|
|
39
|
+
},
|
|
40
|
+
"types": "./dist/types/src/index.d.ts"
|
|
41
|
+
},
|
|
38
42
|
"./invitations": {
|
|
39
43
|
"browser": "./dist/lib/browser/invitations/index.mjs",
|
|
40
44
|
"node": {
|
|
41
|
-
"
|
|
45
|
+
"require": "./dist/lib/node/invitations/index.cjs",
|
|
46
|
+
"default": "./dist/lib/node-esm/invitations/index.mjs"
|
|
42
47
|
},
|
|
43
48
|
"types": "./dist/types/src/invitations/index.d.ts"
|
|
44
49
|
},
|
|
45
50
|
"./mesh": {
|
|
46
51
|
"browser": "./dist/lib/browser/mesh/index.mjs",
|
|
47
52
|
"node": {
|
|
48
|
-
"
|
|
53
|
+
"require": "./dist/lib/node/mesh/index.cjs",
|
|
54
|
+
"default": "./dist/lib/node-esm/mesh/index.mjs"
|
|
49
55
|
},
|
|
50
56
|
"types": "./dist/types/src/mesh/index.d.ts"
|
|
51
57
|
},
|
|
52
58
|
"./testing": {
|
|
53
59
|
"browser": "./dist/lib/browser/testing/index.mjs",
|
|
54
60
|
"node": {
|
|
55
|
-
"
|
|
61
|
+
"require": "./dist/lib/node/testing/index.cjs",
|
|
62
|
+
"default": "./dist/lib/node-esm/testing/index.mjs"
|
|
56
63
|
},
|
|
57
64
|
"types": "./dist/types/src/testing/index.d.ts"
|
|
58
65
|
},
|
|
59
66
|
"./worker": {
|
|
60
67
|
"browser": "./dist/lib/browser/worker.mjs",
|
|
61
68
|
"node": {
|
|
62
|
-
"
|
|
69
|
+
"require": "./dist/lib/node/worker.cjs",
|
|
70
|
+
"default": "./dist/lib/node-esm/worker.mjs"
|
|
63
71
|
},
|
|
64
72
|
"types": "./dist/types/src/worker.d.ts"
|
|
65
73
|
}
|
|
@@ -91,18 +99,20 @@
|
|
|
91
99
|
}
|
|
92
100
|
},
|
|
93
101
|
"dependencies": {
|
|
94
|
-
"
|
|
95
|
-
"@dxos/
|
|
96
|
-
"@dxos/
|
|
97
|
-
"@dxos/config": "0.6.
|
|
98
|
-
"@dxos/
|
|
99
|
-
"@dxos/
|
|
100
|
-
"@dxos/
|
|
101
|
-
"@dxos/
|
|
102
|
-
"@dxos/
|
|
103
|
-
"@dxos/
|
|
104
|
-
"@dxos/
|
|
105
|
-
"@dxos/
|
|
102
|
+
"react-error-boundary": "^4.0.13",
|
|
103
|
+
"@dxos/client": "0.6.12-main.15a606f",
|
|
104
|
+
"@dxos/async": "0.6.12-main.15a606f",
|
|
105
|
+
"@dxos/config": "0.6.12-main.15a606f",
|
|
106
|
+
"@dxos/echo-signals": "0.6.12-main.15a606f",
|
|
107
|
+
"@dxos/debug": "0.6.12-main.15a606f",
|
|
108
|
+
"@dxos/echo-schema": "0.6.12-main.15a606f",
|
|
109
|
+
"@dxos/codec-protobuf": "0.6.12-main.15a606f",
|
|
110
|
+
"@dxos/log": "0.6.12-main.15a606f",
|
|
111
|
+
"@dxos/invariant": "0.6.12-main.15a606f",
|
|
112
|
+
"@dxos/protocols": "0.6.12-main.15a606f",
|
|
113
|
+
"@dxos/node-std": "0.6.12-main.15a606f",
|
|
114
|
+
"@dxos/react-hooks": "0.6.12-main.15a606f",
|
|
115
|
+
"@dxos/util": "0.6.12-main.15a606f"
|
|
106
116
|
},
|
|
107
117
|
"devDependencies": {
|
|
108
118
|
"@testing-library/dom": "^8.17.1",
|
|
@@ -112,19 +122,21 @@
|
|
|
112
122
|
"@types/react-dom": "~18.2.0",
|
|
113
123
|
"react": "~18.2.0",
|
|
114
124
|
"react-dom": "~18.2.0",
|
|
115
|
-
"@dxos/
|
|
116
|
-
"@dxos/
|
|
117
|
-
"@dxos/react-ui-
|
|
118
|
-
"@dxos/
|
|
125
|
+
"@dxos/react-ui": "0.6.12-main.15a606f",
|
|
126
|
+
"@dxos/random": "0.6.12-main.15a606f",
|
|
127
|
+
"@dxos/react-ui-syntax-highlighter": "0.6.12-main.15a606f",
|
|
128
|
+
"@dxos/react-ui-theme": "0.6.12-main.15a606f",
|
|
129
|
+
"@dxos/storybook-utils": "0.6.12-main.15a606f",
|
|
130
|
+
"@dxos/test-utils": "0.6.12-main.15a606f"
|
|
119
131
|
},
|
|
120
132
|
"peerDependencies": {
|
|
121
|
-
"react": "
|
|
122
|
-
"react-dom": "
|
|
123
|
-
"@dxos/react-ui": "0.6.
|
|
124
|
-
"@dxos/react-ui-theme": "0.6.
|
|
133
|
+
"react": "~18.2.0",
|
|
134
|
+
"react-dom": "~18.2.0",
|
|
135
|
+
"@dxos/react-ui": "0.6.12-main.15a606f",
|
|
136
|
+
"@dxos/react-ui-theme": "0.6.12-main.15a606f"
|
|
125
137
|
},
|
|
126
138
|
"optionalDependencies": {
|
|
127
|
-
"@dxos/random": "0.6.
|
|
139
|
+
"@dxos/random": "0.6.12-main.15a606f"
|
|
128
140
|
},
|
|
129
141
|
"publishConfig": {
|
|
130
142
|
"access": "public"
|
package/project.json
CHANGED
|
@@ -26,32 +26,12 @@
|
|
|
26
26
|
"dependsOn": [
|
|
27
27
|
"^compile",
|
|
28
28
|
"stories:mkdist"
|
|
29
|
-
]
|
|
30
|
-
"options": {
|
|
31
|
-
"playwrightConfigPath": "{projectRoot}/src/playwright/playwright.config.ts",
|
|
32
|
-
"serve": "stories:storybook-e2e",
|
|
33
|
-
"testPatterns": [
|
|
34
|
-
"{projectRoot}/src/playwright/**/*.spec.{ts,js}"
|
|
35
|
-
],
|
|
36
|
-
"timeout": 60000,
|
|
37
|
-
"watchPatterns": [
|
|
38
|
-
"{projectRoot}/src/**/*"
|
|
39
|
-
]
|
|
40
|
-
}
|
|
29
|
+
]
|
|
41
30
|
},
|
|
42
31
|
"lint": {},
|
|
43
|
-
"test": {
|
|
44
|
-
"options": {
|
|
45
|
-
"ciEnvironments": [
|
|
46
|
-
"nodejs"
|
|
47
|
-
],
|
|
48
|
-
"domRequired": true,
|
|
49
|
-
"forceExit": true
|
|
50
|
-
}
|
|
51
|
-
}
|
|
32
|
+
"test": {}
|
|
52
33
|
},
|
|
53
34
|
"implicitDependencies": [
|
|
54
|
-
"esbuild"
|
|
55
|
-
"test"
|
|
35
|
+
"esbuild"
|
|
56
36
|
]
|
|
57
37
|
}
|
|
@@ -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
|
|
package/src/echo/useQuery.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { useMemo, useSyncExternalStore } from 'react';
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
|
+
Filter,
|
|
8
9
|
isSpace,
|
|
9
10
|
type Echo,
|
|
10
11
|
type EchoReactiveObject,
|
|
@@ -41,18 +42,14 @@ export const useQuery = <T extends EchoReactiveObject<any>>(
|
|
|
41
42
|
},
|
|
42
43
|
getObjects: () => (subscribed && query ? query.objects : EMPTY_ARRAY),
|
|
43
44
|
};
|
|
44
|
-
}, [spaceOrEcho, ...
|
|
45
|
+
}, [spaceOrEcho, ...filterToDepsArray(filter), ...(deps ?? [])]);
|
|
45
46
|
|
|
46
47
|
// https://beta.reactjs.org/reference/react/useSyncExternalStore
|
|
47
48
|
// NOTE: This hook will resubscribe whenever the callback passed to the first argument changes -- make sure it is stable.
|
|
48
49
|
return useSyncExternalStore<T[] | undefined>(subscribe, getObjects) ?? [];
|
|
49
50
|
};
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
const filterToDepsArray = (filter?: FilterSource<any>) =>
|
|
53
|
-
Object.entries(filter ?? {})
|
|
54
|
-
.flat(10)
|
|
55
|
-
.map((x) => (typeof x === 'function' || typeof x === 'object' ? null : x));
|
|
52
|
+
const filterToDepsArray = (filter?: FilterSource<any>) => [JSON.stringify(Filter.from(filter).toProto())];
|
|
56
53
|
|
|
57
54
|
const noop = () => {};
|
|
58
55
|
|