@dxos/react-client 0.8.4-main.937b3ca → 0.8.4-main.9be5663bfe
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/.storybook/main.mts +1 -3
- package/dist/lib/browser/{chunk-5UKA2BMA.mjs → chunk-BVDNYEYI.mjs} +10 -10
- package/dist/lib/browser/chunk-BVDNYEYI.mjs.map +7 -0
- package/dist/lib/browser/echo/index.mjs +16 -29
- package/dist/lib/browser/echo/index.mjs.map +3 -3
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +14 -48
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/{chunk-T3QTQHBD.mjs → chunk-VSA674XR.mjs} +10 -10
- package/dist/lib/node-esm/chunk-VSA674XR.mjs.map +7 -0
- package/dist/lib/node-esm/echo/index.mjs +16 -29
- package/dist/lib/node-esm/echo/index.mjs.map +3 -3
- package/dist/lib/node-esm/index.mjs +1 -1
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +14 -48
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/client/ClientProvider.d.ts.map +1 -1
- package/dist/types/src/echo/useQueue.d.ts +1 -0
- package/dist/types/src/echo/useQueue.d.ts.map +1 -1
- package/dist/types/src/echo/useSpaceInvitations.d.ts.map +1 -1
- package/dist/types/src/echo/useSpaces.d.ts +5 -5
- package/dist/types/src/echo/useSpaces.d.ts.map +1 -1
- package/dist/types/src/echo/useSyncState.d.ts.map +1 -1
- package/dist/types/src/halo/Passkey.stories.d.ts.map +1 -1
- package/dist/types/src/testing/ClientRepeater.d.ts +1 -1
- package/dist/types/src/testing/ClientRepeater.d.ts.map +1 -1
- package/dist/types/src/testing/ClientRepeater.stories.d.ts.map +1 -1
- package/dist/types/src/testing/util.d.ts.map +1 -1
- package/dist/types/src/testing/withClientProvider.d.ts.map +1 -1
- package/dist/types/src/testing/withClientProvider.stories.d.ts +2 -1
- package/dist/types/src/testing/withClientProvider.stories.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/docs/README.md +38 -38
- package/moon.yml +2 -5
- package/package.json +24 -25
- package/src/client/ClientProvider.test.tsx +0 -1
- package/src/client/ClientProvider.tsx +0 -1
- package/src/client/useConfig.test.tsx +0 -1
- package/src/echo/useQueue.ts +1 -2
- package/src/echo/useSpaceInvitations.ts +0 -1
- package/src/echo/useSpaces.test.tsx +6 -13
- package/src/echo/useSpaces.ts +14 -30
- package/src/echo/useSyncState.ts +2 -1
- package/src/halo/Passkey.stories.tsx +4 -5
- package/src/halo/useDevices.test.tsx +0 -1
- package/src/testing/ClientRepeater.stories.tsx +4 -5
- package/src/testing/ClientRepeater.tsx +3 -4
- package/src/testing/util.tsx +0 -1
- package/src/testing/withClientProvider.stories.tsx +12 -7
- package/src/testing/withClientProvider.tsx +4 -38
- package/typedoc.json +1 -1
- package/vitest.config.ts +0 -2
- package/dist/lib/browser/chunk-5UKA2BMA.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-T3QTQHBD.mjs.map +0 -7
- package/dist/types/src/playwright/playwright.config.d.ts +0 -3
- package/dist/types/src/playwright/playwright.config.d.ts.map +0 -1
- package/dist/types/src/playwright/smoke.spec.d.ts +0 -2
- package/dist/types/src/playwright/smoke.spec.d.ts.map +0 -1
- package/src/playwright/playwright.config.ts +0 -17
- package/src/playwright/smoke.spec.ts +0 -24
package/docs/README.md
CHANGED
|
@@ -168,41 +168,41 @@ dxos/react-client --> dxos/react-async
|
|
|
168
168
|
|
|
169
169
|
## Dependencies
|
|
170
170
|
|
|
171
|
-
| Module
|
|
172
|
-
|
|
173
|
-
| [`@dxos/async`](../../../common/async/docs/README.md)
|
|
174
|
-
| [`@dxos/broadcast`](../../../core/mesh/broadcast/docs/README.md)
|
|
175
|
-
| [`@dxos/client`](../../client/docs/README.md)
|
|
176
|
-
| [`@dxos/client-services`](../../client-services/docs/README.md)
|
|
177
|
-
| [`@dxos/codec-protobuf`](../../../common/codec-protobuf/docs/README.md)
|
|
178
|
-
| [`@dxos/config`](../../config/docs/README.md)
|
|
179
|
-
| [`@dxos/context`](../../../common/context/docs/README.md)
|
|
180
|
-
| [`@dxos/credentials`](../../../core/halo/credentials/docs/README.md)
|
|
181
|
-
| [`@dxos/crypto`](../../../common/crypto/docs/README.md)
|
|
182
|
-
| [`@dxos/debug`](../../../common/debug/docs/README.md)
|
|
183
|
-
| [`@dxos/echo-db`](../../../core/echo/echo-db/docs/README.md)
|
|
184
|
-
| [`@dxos/errors`](../../errors/docs/README.md)
|
|
185
|
-
| [`@dxos/feed-store`](../../../common/feed-store/docs/README.md)
|
|
186
|
-
| [`@dxos/hypercore`](../../../common/hypercore/docs/README.md)
|
|
187
|
-
| [`@dxos/keyring`](../../../core/halo/keyring/docs/README.md)
|
|
188
|
-
| [`@dxos/keys`](../../../common/keys/docs/README.md)
|
|
189
|
-
| [`@dxos/log`](../../../common/log/docs/README.md)
|
|
190
|
-
| [`@dxos/mesh-protocol`](../../../core/mesh/mesh-protocol/docs/README.md)
|
|
191
|
-
| [`@dxos/messaging`](../../../core/mesh/messaging/docs/README.md)
|
|
192
|
-
| [`@dxos/model-factory`](../../../core/echo/model-factory/docs/README.md)
|
|
193
|
-
| [`@dxos/network-generator`](../../../core/mesh/network-generator/docs/README.md)
|
|
194
|
-
| [`@dxos/network-manager`](../../../core/mesh/network-manager/docs/README.md)
|
|
195
|
-
| [`@dxos/document-model`](../../../core/echo/document-model/docs/README.md)
|
|
196
|
-
| [`@dxos/protocol-plugin-presence`](../../../core/mesh/protocol-plugin-presence/docs/README.md)
|
|
197
|
-
| [`@dxos/protocol-plugin-replicator`](../../../core/mesh/protocol-plugin-replicator/docs/README.md) |
|
|
198
|
-
| [`@dxos/protocol-plugin-rpc`](../../../core/mesh/protocol-plugin-rpc/docs/README.md)
|
|
199
|
-
| [`@dxos/protocols`](../../../core/protocols/docs/README.md)
|
|
200
|
-
| [`@dxos/random-access-storage`](../../../common/random-access-storage/docs/README.md)
|
|
201
|
-
| [`@dxos/react-async`](../../../common/react-async/docs/README.md)
|
|
202
|
-
| [`@dxos/rpc`](../../../core/mesh/rpc/docs/README.md)
|
|
203
|
-
| [`@dxos/rpc-tunnel`](../../../core/mesh/rpc-tunnel/docs/README.md)
|
|
204
|
-
| [`@dxos/teleport`](../../../core/mesh/teleport/docs/README.md)
|
|
205
|
-
| [`@dxos/teleport-plugin-replicator`](../../../core/mesh/teleport-plugin-replicator/docs/README.md) |
|
|
206
|
-
| [`@dxos/text-model`](../../../core/echo/text-model/docs/README.md)
|
|
207
|
-
| [`@dxos/timeframe`](../../../common/timeframe/docs/README.md)
|
|
208
|
-
| [`@dxos/util`](../../../common/util/docs/README.md)
|
|
171
|
+
| Module | Direct |
|
|
172
|
+
| -------------------------------------------------------------------------------------------------- | ------- |
|
|
173
|
+
| [`@dxos/async`](../../../common/async/docs/README.md) | ✓ |
|
|
174
|
+
| [`@dxos/broadcast`](../../../core/mesh/broadcast/docs/README.md) | |
|
|
175
|
+
| [`@dxos/client`](../../client/docs/README.md) | ✓ |
|
|
176
|
+
| [`@dxos/client-services`](../../client-services/docs/README.md) | ✓ |
|
|
177
|
+
| [`@dxos/codec-protobuf`](../../../common/codec-protobuf/docs/README.md) | ✓ |
|
|
178
|
+
| [`@dxos/config`](../../config/docs/README.md) | ✓ |
|
|
179
|
+
| [`@dxos/context`](../../../common/context/docs/README.md) | |
|
|
180
|
+
| [`@dxos/credentials`](../../../core/halo/credentials/docs/README.md) | |
|
|
181
|
+
| [`@dxos/crypto`](../../../common/crypto/docs/README.md) | |
|
|
182
|
+
| [`@dxos/debug`](../../../common/debug/docs/README.md) | ✓ |
|
|
183
|
+
| [`@dxos/echo-db`](../../../core/echo/echo-db/docs/README.md) | |
|
|
184
|
+
| [`@dxos/errors`](../../errors/docs/README.md) | |
|
|
185
|
+
| [`@dxos/feed-store`](../../../common/feed-store/docs/README.md) | |
|
|
186
|
+
| [`@dxos/hypercore`](../../../common/hypercore/docs/README.md) | |
|
|
187
|
+
| [`@dxos/keyring`](../../../core/halo/keyring/docs/README.md) | |
|
|
188
|
+
| [`@dxos/keys`](../../../common/keys/docs/README.md) | ✓ |
|
|
189
|
+
| [`@dxos/log`](../../../common/log/docs/README.md) | ✓ |
|
|
190
|
+
| [`@dxos/mesh-protocol`](../../../core/mesh/mesh-protocol/docs/README.md) | |
|
|
191
|
+
| [`@dxos/messaging`](../../../core/mesh/messaging/docs/README.md) | ✓ |
|
|
192
|
+
| [`@dxos/model-factory`](../../../core/echo/model-factory/docs/README.md) | |
|
|
193
|
+
| [`@dxos/network-generator`](../../../core/mesh/network-generator/docs/README.md) | |
|
|
194
|
+
| [`@dxos/network-manager`](../../../core/mesh/network-manager/docs/README.md) | |
|
|
195
|
+
| [`@dxos/document-model`](../../../core/echo/document-model/docs/README.md) | |
|
|
196
|
+
| [`@dxos/protocol-plugin-presence`](../../../core/mesh/protocol-plugin-presence/docs/README.md) | |
|
|
197
|
+
| [`@dxos/protocol-plugin-replicator`](../../../core/mesh/protocol-plugin-replicator/docs/README.md) | |
|
|
198
|
+
| [`@dxos/protocol-plugin-rpc`](../../../core/mesh/protocol-plugin-rpc/docs/README.md) | |
|
|
199
|
+
| [`@dxos/protocols`](../../../core/protocols/docs/README.md) | ✓ |
|
|
200
|
+
| [`@dxos/random-access-storage`](../../../common/random-access-storage/docs/README.md) | |
|
|
201
|
+
| [`@dxos/react-async`](../../../common/react-async/docs/README.md) | ✓ |
|
|
202
|
+
| [`@dxos/rpc`](../../../core/mesh/rpc/docs/README.md) | ✓ |
|
|
203
|
+
| [`@dxos/rpc-tunnel`](../../../core/mesh/rpc-tunnel/docs/README.md) | ✓ |
|
|
204
|
+
| [`@dxos/teleport`](../../../core/mesh/teleport/docs/README.md) | |
|
|
205
|
+
| [`@dxos/teleport-plugin-replicator`](../../../core/mesh/teleport-plugin-replicator/docs/README.md) | |
|
|
206
|
+
| [`@dxos/text-model`](../../../core/echo/text-model/docs/README.md) | |
|
|
207
|
+
| [`@dxos/timeframe`](../../../common/timeframe/docs/README.md) | |
|
|
208
|
+
| [`@dxos/util`](../../../common/util/docs/README.md) | ✓ |
|
package/moon.yml
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
layer: library
|
|
2
2
|
language: typescript
|
|
3
3
|
tags:
|
|
4
|
-
- e2e
|
|
5
4
|
- ts-build
|
|
6
5
|
- ts-test
|
|
6
|
+
- ts-test-storybook
|
|
7
7
|
- typedoc
|
|
8
8
|
- pack
|
|
9
9
|
- storybook
|
|
@@ -18,6 +18,3 @@ tasks:
|
|
|
18
18
|
- '--entryPoint=src/mesh/index.ts'
|
|
19
19
|
- '--entryPoint=src/testing/index.ts'
|
|
20
20
|
- '--entryPoint=src/worker.ts'
|
|
21
|
-
test:
|
|
22
|
-
inputs:
|
|
23
|
-
- .storybook/*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-client",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.9be5663bfe",
|
|
4
4
|
"description": "React client API",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -89,21 +89,20 @@
|
|
|
89
89
|
}
|
|
90
90
|
},
|
|
91
91
|
"dependencies": {
|
|
92
|
-
"
|
|
93
|
-
"@dxos/
|
|
94
|
-
"@dxos/
|
|
95
|
-
"@dxos/
|
|
96
|
-
"@dxos/
|
|
97
|
-
"@dxos/
|
|
98
|
-
"@dxos/
|
|
99
|
-
"@dxos/
|
|
100
|
-
"@dxos/
|
|
101
|
-
"@dxos/
|
|
102
|
-
"@dxos/
|
|
103
|
-
"@dxos/
|
|
104
|
-
"@dxos/
|
|
105
|
-
"@dxos/react
|
|
106
|
-
"@dxos/util": "0.8.4-main.937b3ca"
|
|
92
|
+
"@dxos/async": "0.8.4-main.9be5663bfe",
|
|
93
|
+
"@dxos/context": "0.8.4-main.9be5663bfe",
|
|
94
|
+
"@dxos/debug": "0.8.4-main.9be5663bfe",
|
|
95
|
+
"@dxos/codec-protobuf": "0.8.4-main.9be5663bfe",
|
|
96
|
+
"@dxos/echo": "0.8.4-main.9be5663bfe",
|
|
97
|
+
"@dxos/client": "0.8.4-main.9be5663bfe",
|
|
98
|
+
"@dxos/log": "0.8.4-main.9be5663bfe",
|
|
99
|
+
"@dxos/node-std": "0.8.4-main.9be5663bfe",
|
|
100
|
+
"@dxos/protocols": "0.8.4-main.9be5663bfe",
|
|
101
|
+
"@dxos/react-hooks": "0.8.4-main.9be5663bfe",
|
|
102
|
+
"@dxos/util": "0.8.4-main.9be5663bfe",
|
|
103
|
+
"@dxos/config": "0.8.4-main.9be5663bfe",
|
|
104
|
+
"@dxos/invariant": "0.8.4-main.9be5663bfe",
|
|
105
|
+
"@dxos/echo-react": "0.8.4-main.9be5663bfe"
|
|
107
106
|
},
|
|
108
107
|
"devDependencies": {
|
|
109
108
|
"@types/react": "~19.2.7",
|
|
@@ -111,21 +110,21 @@
|
|
|
111
110
|
"react": "~19.2.3",
|
|
112
111
|
"react-dom": "~19.2.3",
|
|
113
112
|
"typedoc": "0.28.1",
|
|
114
|
-
"@dxos/random": "0.8.4-main.
|
|
115
|
-
"@dxos/react-ui
|
|
116
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
117
|
-
"@dxos/
|
|
118
|
-
"@dxos/
|
|
119
|
-
"@dxos/ui-theme": "0.8.4-main.
|
|
113
|
+
"@dxos/random": "0.8.4-main.9be5663bfe",
|
|
114
|
+
"@dxos/react-ui": "0.8.4-main.9be5663bfe",
|
|
115
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.9be5663bfe",
|
|
116
|
+
"@dxos/test-utils": "0.8.4-main.9be5663bfe",
|
|
117
|
+
"@dxos/storybook-utils": "0.8.4-main.9be5663bfe",
|
|
118
|
+
"@dxos/ui-theme": "0.8.4-main.9be5663bfe"
|
|
120
119
|
},
|
|
121
120
|
"peerDependencies": {
|
|
122
121
|
"react": "~19.2.3",
|
|
123
122
|
"react-dom": "~19.2.3"
|
|
124
123
|
},
|
|
125
124
|
"optionalDependencies": {
|
|
126
|
-
"@dxos/random": "0.8.4-main.
|
|
127
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
128
|
-
"@dxos/ui-theme": "0.8.4-main.
|
|
125
|
+
"@dxos/random": "0.8.4-main.9be5663bfe",
|
|
126
|
+
"@dxos/react-ui": "0.8.4-main.9be5663bfe",
|
|
127
|
+
"@dxos/ui-theme": "0.8.4-main.9be5663bfe"
|
|
129
128
|
},
|
|
130
129
|
"publishConfig": {
|
|
131
130
|
"access": "public"
|
|
@@ -18,7 +18,6 @@ import { useAsyncEffect, useControlledState } from '@dxos/react-hooks';
|
|
|
18
18
|
import { type MaybePromise, type Provider, getAsyncProviderValue } from '@dxos/util';
|
|
19
19
|
|
|
20
20
|
import { printBanner } from '../banner';
|
|
21
|
-
|
|
22
21
|
import { ClientContext, type ClientContextProps } from './context';
|
|
23
22
|
|
|
24
23
|
/**
|
|
@@ -9,7 +9,6 @@ import { waitForCondition } from '@dxos/async';
|
|
|
9
9
|
import { Config, SystemStatus } from '@dxos/client';
|
|
10
10
|
|
|
11
11
|
import { createClient, createClientContextProvider } from '../testing/util';
|
|
12
|
-
|
|
13
12
|
import { useConfig } from './useConfig';
|
|
14
13
|
|
|
15
14
|
// TODO(burdon): Disabled in CI since flaky.
|
package/src/echo/useQueue.ts
CHANGED
|
@@ -19,11 +19,10 @@ export type UseQueueOptions = {
|
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Polls the given Edge queue.
|
|
22
|
+
* @deprecated Use `useQuery` instead.
|
|
22
23
|
*/
|
|
23
|
-
// TODO(burdon): Replace polling with socket?
|
|
24
24
|
// TODO(dmaretskyi): Move into client package.
|
|
25
25
|
// TODO(dmaretskyi): Consider passing the space into the hook to support queue DXNs without space id.
|
|
26
|
-
// TODO(ZaymonFC): If queue is unchanged returned object should be refferentially stable on poll.
|
|
27
26
|
export const useQueue = <T extends Entity.Unknown>(
|
|
28
27
|
queueDxn?: DXN,
|
|
29
28
|
options: UseQueueOptions = {},
|
|
@@ -10,7 +10,6 @@ import { type SpaceId } from '@dxos/client/echo';
|
|
|
10
10
|
import { useMulticastObservable } from '@dxos/react-hooks';
|
|
11
11
|
|
|
12
12
|
import { type CancellableInvitationObservable, useInvitationStatus } from '../invitations';
|
|
13
|
-
|
|
14
13
|
import { useSpace } from './useSpaces';
|
|
15
14
|
|
|
16
15
|
// TODO(wittjosiah): Currently unable to remove `PublicKey` from this api.
|
|
@@ -6,19 +6,18 @@ import { act, renderHook } from '@testing-library/react';
|
|
|
6
6
|
import { describe, expect, test } from 'vitest';
|
|
7
7
|
|
|
8
8
|
import { createClient, createClientContextProvider } from '../testing/util';
|
|
9
|
-
|
|
10
9
|
import { useSpace, useSpaces } from './useSpaces';
|
|
11
10
|
|
|
12
11
|
describe('useSpaces', () => {
|
|
13
12
|
test('lists existing spaces', async () => {
|
|
14
|
-
const { client } = await createClient({ createIdentity: true });
|
|
13
|
+
const { client } = await createClient({ createIdentity: true, createSpace: true });
|
|
15
14
|
const wrapper = await createClientContextProvider(client);
|
|
16
15
|
const { result } = renderHook(() => useSpaces(), { wrapper });
|
|
17
16
|
expect(result.current.length).to.eq(1);
|
|
18
17
|
});
|
|
19
18
|
|
|
20
19
|
test('updates when new spaces are created', async () => {
|
|
21
|
-
const { client } = await createClient({ createIdentity: true });
|
|
20
|
+
const { client } = await createClient({ createIdentity: true, createSpace: true });
|
|
22
21
|
const wrapper = await createClientContextProvider(client);
|
|
23
22
|
const { result, rerender } = renderHook(() => useSpaces(), { wrapper });
|
|
24
23
|
expect(result.current.length).to.eq(1);
|
|
@@ -31,20 +30,14 @@ describe('useSpaces', () => {
|
|
|
31
30
|
});
|
|
32
31
|
|
|
33
32
|
describe('useSpace', () => {
|
|
34
|
-
test('
|
|
35
|
-
const { client } = await createClient();
|
|
33
|
+
test('returns undefined when no id provided', async () => {
|
|
34
|
+
const { client } = await createClient({ createIdentity: true });
|
|
36
35
|
const wrapper = await createClientContextProvider(client);
|
|
37
|
-
const { result
|
|
36
|
+
const { result } = renderHook(() => useSpace(undefined), { wrapper });
|
|
38
37
|
expect(result.current).to.be.undefined;
|
|
39
|
-
await act(async () => {
|
|
40
|
-
await client.halo.createIdentity();
|
|
41
|
-
await client.spaces.waitUntilReady();
|
|
42
|
-
});
|
|
43
|
-
rerender();
|
|
44
|
-
expect(result.current).to.not.be.undefined;
|
|
45
38
|
});
|
|
46
39
|
|
|
47
|
-
test('gets space by
|
|
40
|
+
test('gets space by id', async () => {
|
|
48
41
|
const { client, space } = await createClient({ createIdentity: true, createSpace: true });
|
|
49
42
|
const wrapper = await createClientContextProvider(client);
|
|
50
43
|
const { result } = renderHook(() => useSpace(space!.id), { wrapper });
|
package/src/echo/useSpaces.ts
CHANGED
|
@@ -2,61 +2,45 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { useState } from 'react';
|
|
6
|
-
|
|
7
5
|
import { PublicKey } from '@dxos/client';
|
|
8
6
|
import { type Space, type SpaceId, SpaceState } from '@dxos/client/echo';
|
|
9
|
-
import {
|
|
7
|
+
import { useMulticastObservable } from '@dxos/react-hooks';
|
|
10
8
|
|
|
11
9
|
import { useClient } from '../client';
|
|
12
10
|
|
|
13
11
|
/**
|
|
14
12
|
* Get a specific Space using its id.
|
|
15
13
|
* The space is not guaranteed to be in the ready state.
|
|
16
|
-
* Returns
|
|
14
|
+
* Returns undefined if no id is provided.
|
|
17
15
|
* Requires a ClientProvider somewhere in the parent tree.
|
|
18
16
|
*
|
|
19
|
-
* @param spaceId the id of the space to look for
|
|
17
|
+
* @param spaceId the id of the space to look for.
|
|
20
18
|
*/
|
|
21
19
|
// TODO(wittjosiah): Currently unable to remove `PublicKey` from this api.
|
|
22
20
|
// When initially joining a space that is all that is returned.
|
|
23
21
|
export const useSpace = (spaceId?: SpaceId | PublicKey): Space | undefined => {
|
|
24
22
|
const client = useClient();
|
|
25
23
|
const spaces = useMulticastObservable<Space[]>(client.spaces);
|
|
26
|
-
|
|
24
|
+
if (!spaceId) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return;
|
|
28
|
+
return spaces.find((space) => {
|
|
29
|
+
if (spaceId instanceof PublicKey) {
|
|
30
|
+
return space.key.equals(spaceId);
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}, [client, spaceId]);
|
|
37
|
-
|
|
38
|
-
if (spaceId) {
|
|
39
|
-
return spaces.find((space) => {
|
|
40
|
-
if (spaceId instanceof PublicKey) {
|
|
41
|
-
return space.key.equals(spaceId);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return space.id === spaceId;
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (ready && client.halo.identity.get()) {
|
|
49
|
-
return client.spaces.default;
|
|
50
|
-
}
|
|
33
|
+
return space.id === spaceId;
|
|
34
|
+
});
|
|
51
35
|
};
|
|
52
36
|
|
|
53
37
|
/**
|
|
54
38
|
* Get a Space database by the id of the space.
|
|
55
39
|
* The space is not guaranteed to be in the ready state.
|
|
56
|
-
* Returns
|
|
40
|
+
* Returns undefined if no id is provided.
|
|
57
41
|
* Requires a ClientProvider somewhere in the parent tree.
|
|
58
42
|
*
|
|
59
|
-
* @param spaceId the id of the space to look for
|
|
43
|
+
* @param spaceId the id of the space to look for.
|
|
60
44
|
*/
|
|
61
45
|
export const useDatabase = (spaceId?: SpaceId): Space['db'] | undefined => {
|
|
62
46
|
const space = useSpace(spaceId);
|
|
@@ -74,7 +58,7 @@ export type UseSpacesProps = {
|
|
|
74
58
|
* Get all Spaces available to current user.
|
|
75
59
|
* Requires a ClientProvider somewhere in the parent tree.
|
|
76
60
|
* By default, only ready spaces are returned.
|
|
77
|
-
* @returns an array of Spaces
|
|
61
|
+
* @returns an array of Spaces.
|
|
78
62
|
*/
|
|
79
63
|
export const useSpaces = ({ all = false }: UseSpacesProps = {}): Space[] => {
|
|
80
64
|
const client = useClient();
|
package/src/echo/useSyncState.ts
CHANGED
|
@@ -8,11 +8,12 @@ import { type PeerSyncState, type Space, type SpaceSyncStateMap } from '@dxos/cl
|
|
|
8
8
|
import { Context } from '@dxos/context';
|
|
9
9
|
import { type SpaceId } from '@dxos/keys';
|
|
10
10
|
import { EdgeService } from '@dxos/protocols';
|
|
11
|
+
import { compositeKey } from '@dxos/util';
|
|
11
12
|
|
|
12
13
|
import { useClient } from '../client';
|
|
13
14
|
|
|
14
15
|
const isEdgePeerId = (peerId: string, spaceId: SpaceId) =>
|
|
15
|
-
peerId.startsWith(
|
|
16
|
+
peerId.startsWith(compositeKey(EdgeService.AUTOMERGE_REPLICATOR, spaceId));
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Hook Subscribes to sync state for each space.
|
|
@@ -9,12 +9,11 @@ import { Config, PublicKey } from '@dxos/client';
|
|
|
9
9
|
import { invariant } from '@dxos/invariant';
|
|
10
10
|
import { log } from '@dxos/log';
|
|
11
11
|
import { Button } from '@dxos/react-ui';
|
|
12
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
13
12
|
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
13
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
14
14
|
|
|
15
15
|
import { useClient } from '../client';
|
|
16
16
|
import { withClientProvider } from '../testing';
|
|
17
|
-
|
|
18
17
|
import { useCredentials } from './useCredentials';
|
|
19
18
|
import { useIdentity } from './useIdentity';
|
|
20
19
|
|
|
@@ -105,7 +104,7 @@ const Test = () => {
|
|
|
105
104
|
|
|
106
105
|
return (
|
|
107
106
|
<>
|
|
108
|
-
<div className='
|
|
107
|
+
<div className='mb-4 flex gap-2'>
|
|
109
108
|
<Button disabled={!!identity} onClick={handleCreateIdentity}>
|
|
110
109
|
Create Identity
|
|
111
110
|
</Button>
|
|
@@ -116,7 +115,7 @@ const Test = () => {
|
|
|
116
115
|
Authenticate with Passkey
|
|
117
116
|
</Button>
|
|
118
117
|
</div>
|
|
119
|
-
<div className='flex flex-col min-w-[28rem] divide-y divide-separator border border-separator rounded'>
|
|
118
|
+
<div className='flex flex-col min-w-[28rem] divide-y divide-separator border border-separator rounded-sm'>
|
|
120
119
|
<SyntaxHighlighter language='json'>
|
|
121
120
|
{JSON.stringify({ identity, credentials: credentials.length }, null, 2)}
|
|
122
121
|
</SyntaxHighlighter>
|
|
@@ -148,7 +147,7 @@ const config = new Config({
|
|
|
148
147
|
const meta = {
|
|
149
148
|
title: 'sdk/react-client/Passkeys',
|
|
150
149
|
render: Test,
|
|
151
|
-
decorators: [withClientProvider({ config }), withTheme],
|
|
150
|
+
decorators: [withClientProvider({ config }), withTheme()],
|
|
152
151
|
} satisfies Meta;
|
|
153
152
|
|
|
154
153
|
export default meta;
|
|
@@ -6,7 +6,6 @@ import { renderHook } from '@testing-library/react';
|
|
|
6
6
|
import { describe, expect, test } from 'vitest';
|
|
7
7
|
|
|
8
8
|
import { createClient, createClientContextProvider } from '../testing/util';
|
|
9
|
-
|
|
10
9
|
import { useDevices } from './useDevices';
|
|
11
10
|
|
|
12
11
|
describe('useDevices', () => {
|
|
@@ -7,17 +7,16 @@ import React from 'react';
|
|
|
7
7
|
|
|
8
8
|
import { Obj } from '@dxos/echo';
|
|
9
9
|
import { Input } from '@dxos/react-ui';
|
|
10
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
11
10
|
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
11
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
12
12
|
|
|
13
13
|
import { useClient } from '../client';
|
|
14
14
|
import { useSpace } from '../echo';
|
|
15
|
-
|
|
16
15
|
import { type ClientRepeatedComponentProps, ClientRepeater } from './ClientRepeater';
|
|
17
16
|
|
|
18
17
|
const meta = {
|
|
19
18
|
title: 'sdk/react-client/ClientRepeater',
|
|
20
|
-
decorators: [withTheme],
|
|
19
|
+
decorators: [withTheme()],
|
|
21
20
|
} satisfies Meta<typeof Input>;
|
|
22
21
|
|
|
23
22
|
export default meta;
|
|
@@ -47,8 +46,8 @@ const ClientSpace = ({ spaceId }: ClientRepeatedComponentProps) => {
|
|
|
47
46
|
placeholder='Name'
|
|
48
47
|
value={space.properties.name}
|
|
49
48
|
onChange={(event) =>
|
|
50
|
-
Obj.change(space.properties, (
|
|
51
|
-
|
|
49
|
+
Obj.change(space.properties, (obj) => {
|
|
50
|
+
obj.name = event.target.value;
|
|
52
51
|
})
|
|
53
52
|
}
|
|
54
53
|
/>
|
|
@@ -7,12 +7,11 @@ import React, { type FC, useRef, useState } from 'react';
|
|
|
7
7
|
import { Client } from '@dxos/client';
|
|
8
8
|
import { TestBuilder, performInvitation } from '@dxos/client/testing';
|
|
9
9
|
import { type Type } from '@dxos/echo';
|
|
10
|
-
import {
|
|
10
|
+
import { random } from '@dxos/random';
|
|
11
11
|
import { useAsyncEffect } from '@dxos/react-hooks';
|
|
12
12
|
|
|
13
13
|
import { ClientProvider } from '../client';
|
|
14
14
|
import { type SpaceId } from '../echo';
|
|
15
|
-
|
|
16
15
|
import { type WithClientProviderProps } from './withClientProvider';
|
|
17
16
|
|
|
18
17
|
export type ClientRepeatedComponentProps = { id: number; count: number; spaceId?: SpaceId };
|
|
@@ -26,7 +25,7 @@ export type ClientRepeaterProps<P extends ClientRepeatedComponentProps> = {
|
|
|
26
25
|
controls?: FC<ClientRepeaterControlsProps>;
|
|
27
26
|
count?: number;
|
|
28
27
|
clients?: Client[];
|
|
29
|
-
types?: Type.
|
|
28
|
+
types?: Type.AnyObj[];
|
|
30
29
|
args?: Omit<P, 'id' | 'count'>;
|
|
31
30
|
} & Pick<WithClientProviderProps, 'createIdentity' | 'createSpace' | 'onCreateSpace'>;
|
|
32
31
|
|
|
@@ -67,7 +66,7 @@ export const ClientRepeater = <P extends ClientRepeatedComponentProps>(props: Cl
|
|
|
67
66
|
|
|
68
67
|
if (createSpace) {
|
|
69
68
|
const client = clients[0];
|
|
70
|
-
const space = await client.spaces.create({ name:
|
|
69
|
+
const space = await client.spaces.create({ name: random.commerce.productName() });
|
|
71
70
|
setSpaceId(space.id);
|
|
72
71
|
await onCreateSpace?.({ client, space }, {});
|
|
73
72
|
await Promise.all(clients.slice(1).flatMap((client) => performInvitation({ host: space, guest: client.spaces })));
|
package/src/testing/util.tsx
CHANGED
|
@@ -4,15 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
6
|
import React from 'react';
|
|
7
|
+
import { expect, within } from 'storybook/test';
|
|
7
8
|
|
|
8
9
|
import { log } from '@dxos/log';
|
|
9
|
-
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
10
10
|
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
11
|
-
import {
|
|
11
|
+
import { withLayout, withTheme, Loading } from '@dxos/react-ui/testing';
|
|
12
12
|
|
|
13
13
|
import { useClient } from '../client';
|
|
14
14
|
import { type Space, useSpaces } from '../echo';
|
|
15
|
-
|
|
16
15
|
import { type WithClientProviderProps, withClientProvider, withMultiClientProvider } from './withClientProvider';
|
|
17
16
|
|
|
18
17
|
const SpaceInfo = ({ space }: { space: Space }) => {
|
|
@@ -24,7 +23,7 @@ const DefaultStory = () => {
|
|
|
24
23
|
const client = useClient();
|
|
25
24
|
const spaces = useSpaces();
|
|
26
25
|
if (!client) {
|
|
27
|
-
return
|
|
26
|
+
return <Loading data={{ client: !!client }} />;
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
return (
|
|
@@ -39,8 +38,9 @@ const DefaultStory = () => {
|
|
|
39
38
|
|
|
40
39
|
const meta = {
|
|
41
40
|
title: 'sdk/react-client/withClientProvider',
|
|
42
|
-
render:
|
|
43
|
-
decorators: [withTheme],
|
|
41
|
+
render: DefaultStory,
|
|
42
|
+
decorators: [withTheme()],
|
|
43
|
+
tags: ['test'],
|
|
44
44
|
} satisfies Meta<typeof DefaultStory>;
|
|
45
45
|
|
|
46
46
|
export default meta;
|
|
@@ -63,11 +63,16 @@ export const Default: Story = {
|
|
|
63
63
|
parameters: {
|
|
64
64
|
layout: 'centered',
|
|
65
65
|
},
|
|
66
|
+
play: async ({ canvasElement }) => {
|
|
67
|
+
const canvas = within(canvasElement);
|
|
68
|
+
const initializedText = await canvas.findByText(/"initialized": true/i, {}, { timeout: 30_000 });
|
|
69
|
+
await expect(initializedText).toBeVisible();
|
|
70
|
+
},
|
|
66
71
|
};
|
|
67
72
|
|
|
68
73
|
export const Multiple: Story = {
|
|
69
74
|
decorators: [
|
|
70
|
-
withTheme,
|
|
75
|
+
withTheme(),
|
|
71
76
|
withLayout({ classNames: 'grid grid-cols-3' }),
|
|
72
77
|
withMultiClientProvider({ ...clientProps, numClients: 3 }),
|
|
73
78
|
],
|
|
@@ -3,18 +3,17 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Decorator, type StoryContext } from '@storybook/react';
|
|
6
|
-
import React, {
|
|
7
|
-
import { type FallbackProps, ErrorBoundary as NaturalErrorBoundary } from 'react-error-boundary';
|
|
6
|
+
import React, { useCallback, useMemo, useRef, useState } from 'react';
|
|
8
7
|
|
|
9
8
|
import { Trigger } from '@dxos/async';
|
|
10
9
|
import { type Client } from '@dxos/client';
|
|
11
10
|
import { type Space, type SpaceId } from '@dxos/client/echo';
|
|
12
11
|
import { TestBuilder, performInvitation } from '@dxos/client/testing';
|
|
13
12
|
import { log } from '@dxos/log';
|
|
13
|
+
import { ErrorBoundary } from '@dxos/react-ui';
|
|
14
14
|
import { type MaybePromise } from '@dxos/util';
|
|
15
15
|
|
|
16
16
|
import { ClientProvider, type ClientProviderProps } from '../client';
|
|
17
|
-
|
|
18
17
|
import { ClientStory } from './context';
|
|
19
18
|
|
|
20
19
|
type InitializeProps = {
|
|
@@ -39,8 +38,6 @@ const initializeClient = async (
|
|
|
39
38
|
if (createIdentity || createSpace) {
|
|
40
39
|
if (!client.halo.identity.get()) {
|
|
41
40
|
await client.halo.createIdentity();
|
|
42
|
-
await client.spaces.waitUntilReady();
|
|
43
|
-
await client.spaces.default.waitUntilReady();
|
|
44
41
|
await onCreateIdentity?.({ client }, context);
|
|
45
42
|
}
|
|
46
43
|
}
|
|
@@ -87,7 +84,7 @@ export const withClientProvider = ({
|
|
|
87
84
|
};
|
|
88
85
|
|
|
89
86
|
return (
|
|
90
|
-
<ErrorBoundary>
|
|
87
|
+
<ErrorBoundary name='client-provider'>
|
|
91
88
|
<ClientProvider onInitialized={handleInitialized} {...props}>
|
|
92
89
|
<ClientStory.Provider value={data}>
|
|
93
90
|
<Story />
|
|
@@ -178,7 +175,7 @@ export const withMultiClientProvider = ({
|
|
|
178
175
|
{...props}
|
|
179
176
|
>
|
|
180
177
|
<ClientStory.Provider value={{ index, spaceId }}>
|
|
181
|
-
<ErrorBoundary>
|
|
178
|
+
<ErrorBoundary name='client-provider'>
|
|
182
179
|
<Story />
|
|
183
180
|
</ErrorBoundary>
|
|
184
181
|
</ClientStory.Provider>
|
|
@@ -188,34 +185,3 @@ export const withMultiClientProvider = ({
|
|
|
188
185
|
);
|
|
189
186
|
};
|
|
190
187
|
};
|
|
191
|
-
|
|
192
|
-
const ErrorBoundary = ({ children }: PropsWithChildren) => {
|
|
193
|
-
const [error, setError] = useState<Error>();
|
|
194
|
-
useEffect(() => {
|
|
195
|
-
const handleError = (event: PromiseRejectionEvent) => {
|
|
196
|
-
setError(event.reason);
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
window.addEventListener('unhandledrejection', handleError);
|
|
200
|
-
return () => window.removeEventListener('unhandledrejection', handleError);
|
|
201
|
-
}, []);
|
|
202
|
-
|
|
203
|
-
if (error) {
|
|
204
|
-
return <ErrorFallback error={error} resetErrorBoundary={() => setError(undefined)} />;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return <NaturalErrorBoundary FallbackComponent={ErrorFallback}>{children}</NaturalErrorBoundary>;
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
const ErrorFallback = ({ error }: FallbackProps) => {
|
|
211
|
-
const { name, message, stack } =
|
|
212
|
-
error instanceof Error ? error : { name: 'Error', message: String(error), stack: undefined };
|
|
213
|
-
|
|
214
|
-
return (
|
|
215
|
-
<div role='alert' className='flex flex-col p-4 gap-4 overflow-auto'>
|
|
216
|
-
<h1 className='text-xl text-red-500'>{name}</h1>
|
|
217
|
-
<div className='text-lg'>{message}</div>
|
|
218
|
-
{stack && <pre className='whitespace-pre-wrap text-sm text-subdued'>{stack}</pre>}
|
|
219
|
-
</div>
|
|
220
|
-
);
|
|
221
|
-
};
|
package/typedoc.json
CHANGED