@dxos/react-client 0.8.4-main.c85a9c8dae → 0.8.4-main.cb12b3f963
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-PFF63FPR.mjs → chunk-3LVU7RNK.mjs} +2 -2
- package/dist/lib/browser/{chunk-TSF6Y5VB.mjs → chunk-CZMIVAGI.mjs} +1 -1
- package/dist/lib/browser/{chunk-TSF6Y5VB.mjs.map → chunk-CZMIVAGI.mjs.map} +2 -2
- package/dist/lib/browser/{chunk-5UKA2BMA.mjs → chunk-XT352YI6.mjs} +11 -56
- package/dist/lib/browser/chunk-XT352YI6.mjs.map +7 -0
- package/dist/lib/browser/{chunk-LO3TU5CK.mjs → chunk-YHE6WD44.mjs} +3 -13
- package/dist/lib/browser/{chunk-LO3TU5CK.mjs.map → chunk-YHE6WD44.mjs.map} +2 -2
- package/dist/lib/browser/devtools/index.mjs +3 -8
- package/dist/lib/browser/devtools/index.mjs.map +2 -2
- package/dist/lib/browser/echo/index.mjs +19 -38
- package/dist/lib/browser/echo/index.mjs.map +3 -3
- package/dist/lib/browser/halo/index.mjs +3 -3
- package/dist/lib/browser/halo/index.mjs.map +2 -2
- package/dist/lib/browser/index.mjs +6 -21
- package/dist/lib/browser/index.mjs.map +2 -2
- package/dist/lib/browser/invitations/index.mjs +1 -1
- package/dist/lib/browser/mesh/index.mjs +2 -2
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +7 -24
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/{chunk-NETTSER2.mjs → chunk-CUDKNAMV.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-AQJH2UNZ.mjs → chunk-RQJPEHDY.mjs} +3 -13
- package/dist/lib/node-esm/{chunk-AQJH2UNZ.mjs.map → chunk-RQJPEHDY.mjs.map} +2 -2
- package/dist/lib/node-esm/{chunk-T3QTQHBD.mjs → chunk-WL3Z5HOH.mjs} +11 -56
- package/dist/lib/node-esm/chunk-WL3Z5HOH.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-373DPHEQ.mjs → chunk-WUTK2IJF.mjs} +1 -1
- package/dist/lib/node-esm/{chunk-373DPHEQ.mjs.map → chunk-WUTK2IJF.mjs.map} +2 -2
- package/dist/lib/node-esm/devtools/index.mjs +3 -8
- package/dist/lib/node-esm/devtools/index.mjs.map +2 -2
- package/dist/lib/node-esm/echo/index.mjs +19 -38
- package/dist/lib/node-esm/echo/index.mjs.map +3 -3
- package/dist/lib/node-esm/halo/index.mjs +3 -3
- package/dist/lib/node-esm/halo/index.mjs.map +2 -2
- package/dist/lib/node-esm/index.mjs +6 -21
- package/dist/lib/node-esm/index.mjs.map +2 -2
- package/dist/lib/node-esm/invitations/index.mjs +1 -1
- package/dist/lib/node-esm/mesh/index.mjs +2 -2
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +7 -24
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/banner.d.ts.map +1 -1
- package/dist/types/src/client/AgentHostingProvider.d.ts.map +1 -1
- package/dist/types/src/client/ClientProvider.d.ts +1 -1
- package/dist/types/src/client/ClientProvider.d.ts.map +1 -1
- package/dist/types/src/client/useClientStatus.d.ts.map +1 -1
- package/dist/types/src/devtools/useStream.d.ts.map +1 -1
- package/dist/types/src/echo/useMembers.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/useSpaceProperties.d.ts.map +1 -1
- package/dist/types/src/echo/useSpaces.d.ts +7 -6
- package/dist/types/src/echo/useSpaces.d.ts.map +1 -1
- package/dist/types/src/echo/useSubscription.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/halo/useHaloInvitations.d.ts.map +1 -1
- package/dist/types/src/halo/useKeyStore.d.ts.map +1 -1
- package/dist/types/src/invitations/useInvitationStatus.d.ts.map +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 +1 -1
- package/dist/types/src/testing/withClientProvider.stories.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -49
- 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 +15 -30
- package/src/echo/useSyncState.ts +2 -1
- package/src/halo/Passkey.stories.tsx +2 -5
- package/src/halo/useDevices.test.tsx +0 -1
- package/src/testing/ClientRepeater.stories.tsx +4 -7
- package/src/testing/ClientRepeater.tsx +2 -3
- package/src/testing/util.tsx +0 -1
- package/src/testing/withClientProvider.stories.tsx +6 -8
- package/src/testing/withClientProvider.tsx +0 -3
- package/vitest.config.ts +0 -2
- package/.swc/plugins/linux_x86_64_19.0.0/727453fb3a62f7f1d952a41e051ca8a6f88cadc45cee43c6a4d1aa45f9b75665.wasmer-v7 +0 -0
- package/dist/lib/browser/chunk-5UKA2BMA.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-T3QTQHBD.mjs.map +0 -7
- /package/dist/lib/browser/{chunk-PFF63FPR.mjs.map → chunk-3LVU7RNK.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-NETTSER2.mjs.map → chunk-CUDKNAMV.mjs.map} +0 -0
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.cb12b3f963",
|
|
4
4
|
"description": "React client API",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -63,46 +63,21 @@
|
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
65
|
"types": "dist/types/src/index.d.ts",
|
|
66
|
-
"typesVersions": {
|
|
67
|
-
"*": {
|
|
68
|
-
"devtools": [
|
|
69
|
-
"dist/types/src/devtools/index.d.ts"
|
|
70
|
-
],
|
|
71
|
-
"echo": [
|
|
72
|
-
"dist/types/src/echo/index.d.ts"
|
|
73
|
-
],
|
|
74
|
-
"halo": [
|
|
75
|
-
"dist/types/src/halo/index.d.ts"
|
|
76
|
-
],
|
|
77
|
-
"invitations": [
|
|
78
|
-
"dist/types/src/invitations/index.d.ts"
|
|
79
|
-
],
|
|
80
|
-
"mesh": [
|
|
81
|
-
"dist/types/src/mesh/index.d.ts"
|
|
82
|
-
],
|
|
83
|
-
"testing": [
|
|
84
|
-
"dist/types/src/testing/index.d.ts"
|
|
85
|
-
],
|
|
86
|
-
"worker": [
|
|
87
|
-
"dist/types/src/worker.d.ts"
|
|
88
|
-
]
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
66
|
"dependencies": {
|
|
92
|
-
"@dxos/
|
|
93
|
-
"@dxos/config": "0.8.4-main.
|
|
94
|
-
"@dxos/
|
|
95
|
-
"@dxos/
|
|
96
|
-
"@dxos/
|
|
97
|
-
"@dxos/echo-react": "0.8.4-main.
|
|
98
|
-
"@dxos/
|
|
99
|
-
"@dxos/
|
|
100
|
-
"@dxos/
|
|
101
|
-
"@dxos/
|
|
102
|
-
"@dxos/
|
|
103
|
-
"@dxos/
|
|
104
|
-
"@dxos/util": "0.8.4-main.
|
|
105
|
-
"@dxos/
|
|
67
|
+
"@dxos/client": "0.8.4-main.cb12b3f963",
|
|
68
|
+
"@dxos/config": "0.8.4-main.cb12b3f963",
|
|
69
|
+
"@dxos/debug": "0.8.4-main.cb12b3f963",
|
|
70
|
+
"@dxos/async": "0.8.4-main.cb12b3f963",
|
|
71
|
+
"@dxos/context": "0.8.4-main.cb12b3f963",
|
|
72
|
+
"@dxos/echo-react": "0.8.4-main.cb12b3f963",
|
|
73
|
+
"@dxos/invariant": "0.8.4-main.cb12b3f963",
|
|
74
|
+
"@dxos/log": "0.8.4-main.cb12b3f963",
|
|
75
|
+
"@dxos/node-std": "0.8.4-main.cb12b3f963",
|
|
76
|
+
"@dxos/codec-protobuf": "0.8.4-main.cb12b3f963",
|
|
77
|
+
"@dxos/echo": "0.8.4-main.cb12b3f963",
|
|
78
|
+
"@dxos/protocols": "0.8.4-main.cb12b3f963",
|
|
79
|
+
"@dxos/util": "0.8.4-main.cb12b3f963",
|
|
80
|
+
"@dxos/react-hooks": "0.8.4-main.cb12b3f963"
|
|
106
81
|
},
|
|
107
82
|
"devDependencies": {
|
|
108
83
|
"@types/react": "~19.2.7",
|
|
@@ -110,21 +85,21 @@
|
|
|
110
85
|
"react": "~19.2.3",
|
|
111
86
|
"react-dom": "~19.2.3",
|
|
112
87
|
"typedoc": "0.28.1",
|
|
113
|
-
"@dxos/react-ui
|
|
114
|
-
"@dxos/
|
|
115
|
-
"@dxos/
|
|
116
|
-
"@dxos/
|
|
117
|
-
"@dxos/
|
|
118
|
-
"@dxos/
|
|
88
|
+
"@dxos/react-ui": "0.8.4-main.cb12b3f963",
|
|
89
|
+
"@dxos/random": "0.8.4-main.cb12b3f963",
|
|
90
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.cb12b3f963",
|
|
91
|
+
"@dxos/storybook-utils": "0.8.4-main.cb12b3f963",
|
|
92
|
+
"@dxos/test-utils": "0.8.4-main.cb12b3f963",
|
|
93
|
+
"@dxos/ui-theme": "0.8.4-main.cb12b3f963"
|
|
119
94
|
},
|
|
120
95
|
"peerDependencies": {
|
|
121
96
|
"react": "~19.2.3",
|
|
122
97
|
"react-dom": "~19.2.3"
|
|
123
98
|
},
|
|
124
99
|
"optionalDependencies": {
|
|
125
|
-
"@dxos/random": "0.8.4-main.
|
|
126
|
-
"@dxos/ui
|
|
127
|
-
"@dxos/
|
|
100
|
+
"@dxos/random": "0.8.4-main.cb12b3f963",
|
|
101
|
+
"@dxos/react-ui": "0.8.4-main.cb12b3f963",
|
|
102
|
+
"@dxos/ui-theme": "0.8.4-main.cb12b3f963"
|
|
128
103
|
},
|
|
129
104
|
"publishConfig": {
|
|
130
105
|
"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,46 @@
|
|
|
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.
|
|
44
|
+
* @deprecated Use useSpace.
|
|
60
45
|
*/
|
|
61
46
|
export const useDatabase = (spaceId?: SpaceId): Space['db'] | undefined => {
|
|
62
47
|
const space = useSpace(spaceId);
|
|
@@ -74,7 +59,7 @@ export type UseSpacesProps = {
|
|
|
74
59
|
* Get all Spaces available to current user.
|
|
75
60
|
* Requires a ClientProvider somewhere in the parent tree.
|
|
76
61
|
* By default, only ready spaces are returned.
|
|
77
|
-
* @returns an array of Spaces
|
|
62
|
+
* @returns an array of Spaces.
|
|
78
63
|
*/
|
|
79
64
|
export const useSpaces = ({ all = false }: UseSpacesProps = {}): Space[] => {
|
|
80
65
|
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 { JsonHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
12
13
|
import { withTheme } from '@dxos/react-ui/testing';
|
|
13
|
-
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
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
|
|
|
@@ -117,9 +116,7 @@ const Test = () => {
|
|
|
117
116
|
</Button>
|
|
118
117
|
</div>
|
|
119
118
|
<div className='flex flex-col min-w-[28rem] divide-y divide-separator border border-separator rounded-sm'>
|
|
120
|
-
<
|
|
121
|
-
{JSON.stringify({ identity, credentials: credentials.length }, null, 2)}
|
|
122
|
-
</SyntaxHighlighter>
|
|
119
|
+
<JsonHighlighter data={{ identity, credentials: credentials.length }} />
|
|
123
120
|
</div>
|
|
124
121
|
</>
|
|
125
122
|
);
|
|
@@ -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,12 +7,11 @@ import React from 'react';
|
|
|
7
7
|
|
|
8
8
|
import { Obj } from '@dxos/echo';
|
|
9
9
|
import { Input } from '@dxos/react-ui';
|
|
10
|
+
import { JsonHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
10
11
|
import { withTheme } from '@dxos/react-ui/testing';
|
|
11
|
-
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
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 = {
|
|
@@ -24,9 +23,7 @@ export default meta;
|
|
|
24
23
|
|
|
25
24
|
type Story = StoryObj<typeof meta>;
|
|
26
25
|
|
|
27
|
-
const JsonPanel = ({ value }: { value: any }) =>
|
|
28
|
-
<SyntaxHighlighter language='json'>{JSON.stringify(value, undefined, 2)}</SyntaxHighlighter>
|
|
29
|
-
);
|
|
26
|
+
const JsonPanel = ({ value }: { value: any }) => <JsonHighlighter data={value} />;
|
|
30
27
|
|
|
31
28
|
const ClientStory = () => {
|
|
32
29
|
const client = useClient();
|
|
@@ -47,8 +44,8 @@ const ClientSpace = ({ spaceId }: ClientRepeatedComponentProps) => {
|
|
|
47
44
|
placeholder='Name'
|
|
48
45
|
value={space.properties.name}
|
|
49
46
|
onChange={(event) =>
|
|
50
|
-
Obj.
|
|
51
|
-
|
|
47
|
+
Obj.update(space.properties, (obj) => {
|
|
48
|
+
obj.name = event.target.value;
|
|
52
49
|
})
|
|
53
50
|
}
|
|
54
51
|
/>
|
|
@@ -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 };
|
|
@@ -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
|
@@ -7,30 +7,28 @@ import React from 'react';
|
|
|
7
7
|
import { expect, within } from 'storybook/test';
|
|
8
8
|
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { render } from '@dxos/storybook-utils';
|
|
10
|
+
import { JsonHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
11
|
+
import { withLayout, withTheme, Loading } from '@dxos/react-ui/testing';
|
|
13
12
|
|
|
14
13
|
import { useClient } from '../client';
|
|
15
14
|
import { type Space, useSpaces } from '../echo';
|
|
16
|
-
|
|
17
15
|
import { type WithClientProviderProps, withClientProvider, withMultiClientProvider } from './withClientProvider';
|
|
18
16
|
|
|
19
17
|
const SpaceInfo = ({ space }: { space: Space }) => {
|
|
20
18
|
const name = space.isOpen ? space.properties.name : '';
|
|
21
|
-
return <
|
|
19
|
+
return <JsonHighlighter data={{ id: space.id, name }} />;
|
|
22
20
|
};
|
|
23
21
|
|
|
24
22
|
const DefaultStory = () => {
|
|
25
23
|
const client = useClient();
|
|
26
24
|
const spaces = useSpaces();
|
|
27
25
|
if (!client) {
|
|
28
|
-
return
|
|
26
|
+
return <Loading data={{ client: !!client }} />;
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
return (
|
|
32
30
|
<div className='flex flex-col divide-y divide-separator border border-separator'>
|
|
33
|
-
<
|
|
31
|
+
<JsonHighlighter data={client.toJSON()} />
|
|
34
32
|
{spaces.map((space) => (
|
|
35
33
|
<SpaceInfo key={space.id} space={space} />
|
|
36
34
|
))}
|
|
@@ -40,7 +38,7 @@ const DefaultStory = () => {
|
|
|
40
38
|
|
|
41
39
|
const meta = {
|
|
42
40
|
title: 'sdk/react-client/withClientProvider',
|
|
43
|
-
render:
|
|
41
|
+
render: DefaultStory,
|
|
44
42
|
decorators: [withTheme()],
|
|
45
43
|
tags: ['test'],
|
|
46
44
|
} satisfies Meta<typeof DefaultStory>;
|
|
@@ -14,7 +14,6 @@ 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
|
}
|
package/vitest.config.ts
CHANGED
|
@@ -11,8 +11,6 @@ export default createConfig({
|
|
|
11
11
|
dirname: typeof __dirname !== 'undefined' ? __dirname : path.dirname(fileURLToPath(import.meta.url)),
|
|
12
12
|
node: {
|
|
13
13
|
environment: 'happy-dom',
|
|
14
|
-
// TODO(dmaretskyi): Enabled because client tests were flaky. Remove when that's not the case.
|
|
15
|
-
retry: 2,
|
|
16
14
|
},
|
|
17
15
|
storybook: true,
|
|
18
16
|
});
|
|
Binary file
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/client/ClientProvider.tsx", "../../../src/banner.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport React, {\n type FunctionComponent,\n type PropsWithChildren,\n forwardRef,\n useEffect,\n useImperativeHandle,\n useState,\n} from 'react';\n\nimport { Client, type ClientOptions, type ClientServicesProvider, SystemStatus } from '@dxos/client';\nimport { type Config } from '@dxos/config';\nimport { log } from '@dxos/log';\nimport { useAsyncEffect, useControlledState } from '@dxos/react-hooks';\nimport { type MaybePromise, type Provider, getAsyncProviderValue } from '@dxos/util';\n\nimport { printBanner } from '../banner';\n\nimport { ClientContext, type ClientContextProps } from './context';\n\n/**\n * Properties for the ClientProvider.\n */\nexport type ClientProviderProps = Omit<ClientOptions, 'config' | 'services'> &\n Pick<ClientContextProps, 'status'> &\n PropsWithChildren<{\n /**\n * Client object or async provider to enable to caller to do custom initialization.\n *\n * NOTE: For advanced use cases only.\n */\n client?: Client | Provider<Promise<Client>>;\n\n /**\n * Config object or async provider.\n *\n * NOTE: If a `client` is provided then `config` is ignored.\n */\n // TODO(burdon): Reconcile with ClientOptions.\n config?: Config | Provider<Promise<Config>>;\n\n /**\n * Callback to enable the caller to create a custom ClientServicesProvider.\n *\n * NOTE: If a `client` is provided then `services` is ignored.\n */\n // TODO(burdon): Reconcile with ClientOptions.\n services?: ClientServicesProvider | ((config?: Config) => MaybePromise<ClientServicesProvider>);\n\n /**\n * ReactNode to display until the client is available.\n */\n fallback?: FunctionComponent<Partial<ClientContextProps>>;\n\n /**\n * Skip the DXOS banner.\n */\n noBanner?: boolean;\n\n /**\n * Post initialization hook to enable to caller to do custom initialization.\n */\n onInitialized?: (client: Client) => MaybePromise<void>;\n }>;\n\n/**\n * Root component that provides the DXOS client instance to child components.\n * To be used with the `useClient` hook.\n */\nexport const ClientProvider = forwardRef<Client | undefined, ClientProviderProps>(\n (\n {\n children,\n config: configProp,\n client: clientProp,\n services: servicesProp,\n status: statusProp,\n fallback: Fallback = () => null,\n noBanner,\n onInitialized,\n ...options\n },\n forwardedRef,\n ) => {\n // The client is initialized asynchronously.\n // If an error occurs during initialization, it is caught and the state is set.\n // This allows the error to be thrown in the render method.\n // The assumption is that a client initialization error is fatal to the app.\n // This error will be caught by the nearest error boundary.\n const [error, setError] = useState();\n if (error) {\n throw error;\n }\n\n const [client, setClient] = useState(clientProp instanceof Client ? clientProp : undefined);\n\n // Provide external access.\n useImperativeHandle(forwardedRef, () => client, [client]);\n\n // Client status subscription.\n const [status, setStatus] = useControlledState(statusProp);\n useEffect(() => {\n if (!client) {\n return;\n }\n\n const subscription = client.status.subscribe((status) => setStatus(status));\n return () => subscription.unsubscribe();\n }, [client]);\n\n // Create and/or initialize client.\n useAsyncEffect(async () => {\n let disposed = false;\n const initialize = async (client: Client) => {\n if (!client.initialized) {\n await client.initialize().catch((err) => {\n if (!disposed) {\n setError(err);\n }\n });\n log('client ready');\n await onInitialized?.(client);\n log('initialization complete');\n }\n\n setClient(client);\n if (!noBanner) {\n printBanner(client);\n }\n };\n\n let client: Client;\n try {\n if (clientProp) {\n // Asynchronously request client.\n client = await getAsyncProviderValue(clientProp);\n await initialize(client);\n } else {\n // Asynchronously construct client (config may be undefined).\n const config = await getAsyncProviderValue(configProp);\n log('resolved config', { config });\n const services = await getAsyncProviderValue(servicesProp, config);\n log('created services', { services });\n client = new Client({ config, services, ...options });\n log('created client');\n await initialize(client);\n }\n } catch (err) {\n if (!disposed) {\n log.catch(err);\n }\n }\n\n return () => {\n log('clean up');\n disposed = true;\n // Only destroy if the client is not provided by the parent.\n if (!clientProp) {\n void client\n ?.destroy()\n .then(() => {\n log('destroyed');\n })\n .catch((err) => log.catch(err));\n }\n };\n }, [configProp, clientProp, servicesProp, noBanner]);\n\n if (!client?.initialized || status !== SystemStatus.ACTIVE) {\n return <Fallback client={client} status={status} />;\n }\n\n return <ClientContext.Provider value={{ client, status }}>{children}</ClientContext.Provider>;\n },\n);\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { type Client } from '@dxos/client';\n\n// http://patorjk.com/software/taag/#p=testall&f=Patorjk-HeX&t=DXOS\nconst BANNER = (client: Client) => {\n const commitHash = client.config.get('runtime.app.build.commitHash');\n const hash = commitHash ? ` App Commit ${commitHash} \\n` : '';\n\n return (\n '\\n' +\n '_/\\\\/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\______/\\\\/\\\\/\\\\/\\\\/\\\\_\\n' +\n '_/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\__/\\\\/\\\\_________\\n' +\n '_/\\\\/\\\\____/\\\\/\\\\______/\\\\/\\\\______/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\___\\n' +\n '_/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\__________/\\\\/\\\\_\\n' +\n '_/\\\\/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\/\\\\___\\n' +\n `\\n DXOS Client ${client.version} \\n${hash}`\n );\n};\n\nlet bannerPrinted = false;\n\nexport const printBanner = (client: Client) => {\n if (bannerPrinted || window.location.hostname === 'localhost') {\n return;\n }\n\n bannerPrinted = true;\n // eslint-disable-next-line no-console\n console.log(`%c${BANNER(client)}`, 'font-family: monospace;');\n};\n"],
|
|
5
|
-
"mappings": "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",
|
|
6
|
-
"names": ["React", "forwardRef", "useEffect", "useImperativeHandle", "useState", "Client", "SystemStatus", "log", "useAsyncEffect", "useControlledState", "getAsyncProviderValue", "BANNER", "client", "commitHash", "config", "get", "hash", "version", "bannerPrinted", "printBanner", "window", "location", "hostname", "console", "log", "ClientProvider", "forwardRef", "children", "config", "configProp", "client", "clientProp", "services", "servicesProp", "status", "statusProp", "fallback", "Fallback", "noBanner", "onInitialized", "options", "forwardedRef", "error", "setError", "useState", "setClient", "Client", "undefined", "useImperativeHandle", "setStatus", "useControlledState", "useEffect", "subscription", "subscribe", "unsubscribe", "useAsyncEffect", "disposed", "initialize", "initialized", "catch", "err", "log", "printBanner", "getAsyncProviderValue", "destroy", "then", "SystemStatus", "ACTIVE", "ClientContext", "Provider", "value"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/client/ClientProvider.tsx", "../../../src/banner.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport React, {\n type FunctionComponent,\n type PropsWithChildren,\n forwardRef,\n useEffect,\n useImperativeHandle,\n useState,\n} from 'react';\n\nimport { Client, type ClientOptions, type ClientServicesProvider, SystemStatus } from '@dxos/client';\nimport { type Config } from '@dxos/config';\nimport { log } from '@dxos/log';\nimport { useAsyncEffect, useControlledState } from '@dxos/react-hooks';\nimport { type MaybePromise, type Provider, getAsyncProviderValue } from '@dxos/util';\n\nimport { printBanner } from '../banner';\n\nimport { ClientContext, type ClientContextProps } from './context';\n\n/**\n * Properties for the ClientProvider.\n */\nexport type ClientProviderProps = Omit<ClientOptions, 'config' | 'services'> &\n Pick<ClientContextProps, 'status'> &\n PropsWithChildren<{\n /**\n * Client object or async provider to enable to caller to do custom initialization.\n *\n * NOTE: For advanced use cases only.\n */\n client?: Client | Provider<Promise<Client>>;\n\n /**\n * Config object or async provider.\n *\n * NOTE: If a `client` is provided then `config` is ignored.\n */\n // TODO(burdon): Reconcile with ClientOptions.\n config?: Config | Provider<Promise<Config>>;\n\n /**\n * Callback to enable the caller to create a custom ClientServicesProvider.\n *\n * NOTE: If a `client` is provided then `services` is ignored.\n */\n // TODO(burdon): Reconcile with ClientOptions.\n services?: ClientServicesProvider | ((config?: Config) => MaybePromise<ClientServicesProvider>);\n\n /**\n * ReactNode to display until the client is available.\n */\n fallback?: FunctionComponent<Partial<ClientContextProps>>;\n\n /**\n * Skip the DXOS banner.\n */\n noBanner?: boolean;\n\n /**\n * Post initialization hook to enable to caller to do custom initialization.\n */\n onInitialized?: (client: Client) => MaybePromise<void>;\n }>;\n\n/**\n * Root component that provides the DXOS client instance to child components.\n * To be used with the `useClient` hook.\n */\nexport const ClientProvider = forwardRef<Client | undefined, ClientProviderProps>(\n (\n {\n children,\n config: configProp,\n client: clientProp,\n services: servicesProp,\n status: statusProp,\n fallback: Fallback = () => null,\n noBanner,\n onInitialized,\n ...options\n },\n forwardedRef,\n ) => {\n // The client is initialized asynchronously.\n // If an error occurs during initialization, it is caught and the state is set.\n // This allows the error to be thrown in the render method.\n // The assumption is that a client initialization error is fatal to the app.\n // This error will be caught by the nearest error boundary.\n const [error, setError] = useState();\n if (error) {\n throw error;\n }\n\n const [client, setClient] = useState(clientProp instanceof Client ? clientProp : undefined);\n\n // Provide external access.\n useImperativeHandle(forwardedRef, () => client, [client]);\n\n // Client status subscription.\n const [status, setStatus] = useControlledState(statusProp);\n useEffect(() => {\n if (!client) {\n return;\n }\n\n const subscription = client.status.subscribe((status) => setStatus(status));\n return () => subscription.unsubscribe();\n }, [client]);\n\n // Create and/or initialize client.\n useAsyncEffect(async () => {\n let disposed = false;\n const initialize = async (client: Client) => {\n if (!client.initialized) {\n await client.initialize().catch((err) => {\n if (!disposed) {\n setError(err);\n }\n });\n log('client ready');\n await onInitialized?.(client);\n log('initialization complete');\n }\n\n setClient(client);\n if (!noBanner) {\n printBanner(client);\n }\n };\n\n let client: Client;\n try {\n if (clientProp) {\n // Asynchronously request client.\n client = await getAsyncProviderValue(clientProp);\n await initialize(client);\n } else {\n // Asynchronously construct client (config may be undefined).\n const config = await getAsyncProviderValue(configProp);\n log('resolved config', { config });\n const services = await getAsyncProviderValue(servicesProp, config);\n log('created services', { services });\n client = new Client({ config, services, ...options });\n log('created client');\n await initialize(client);\n }\n } catch (err) {\n if (!disposed) {\n log.catch(err);\n }\n }\n\n return () => {\n log('clean up');\n disposed = true;\n // Only destroy if the client is not provided by the parent.\n if (!clientProp) {\n void client\n ?.destroy()\n .then(() => {\n log('destroyed');\n })\n .catch((err) => log.catch(err));\n }\n };\n }, [configProp, clientProp, servicesProp, noBanner]);\n\n if (!client?.initialized || status !== SystemStatus.ACTIVE) {\n return <Fallback client={client} status={status} />;\n }\n\n return <ClientContext.Provider value={{ client, status }}>{children}</ClientContext.Provider>;\n },\n);\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { type Client } from '@dxos/client';\n\n// http://patorjk.com/software/taag/#p=testall&f=Patorjk-HeX&t=DXOS\nconst BANNER = (client: Client) => {\n const commitHash = client.config.get('runtime.app.build.commitHash');\n const hash = commitHash ? ` App Commit ${commitHash} \\n` : '';\n\n return (\n '\\n' +\n '_/\\\\/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\______/\\\\/\\\\/\\\\/\\\\/\\\\_\\n' +\n '_/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\__/\\\\/\\\\_________\\n' +\n '_/\\\\/\\\\____/\\\\/\\\\______/\\\\/\\\\______/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\___\\n' +\n '_/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\__________/\\\\/\\\\_\\n' +\n '_/\\\\/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\/\\\\___\\n' +\n `\\n DXOS Client ${client.version} \\n${hash}`\n );\n};\n\nlet bannerPrinted = false;\n\nexport const printBanner = (client: Client) => {\n if (bannerPrinted || window.location.hostname === 'localhost') {\n return;\n }\n\n bannerPrinted = true;\n // eslint-disable-next-line no-console\n console.log(`%c${BANNER(client)}`, 'font-family: monospace;');\n};\n"],
|
|
5
|
-
"mappings": "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",
|
|
6
|
-
"names": ["React", "forwardRef", "useEffect", "useImperativeHandle", "useState", "Client", "SystemStatus", "log", "useAsyncEffect", "useControlledState", "getAsyncProviderValue", "BANNER", "client", "commitHash", "config", "get", "hash", "version", "bannerPrinted", "printBanner", "window", "location", "hostname", "console", "log", "ClientProvider", "forwardRef", "children", "config", "configProp", "client", "clientProp", "services", "servicesProp", "status", "statusProp", "fallback", "Fallback", "noBanner", "onInitialized", "options", "forwardedRef", "error", "setError", "useState", "setClient", "Client", "undefined", "useImperativeHandle", "setStatus", "useControlledState", "useEffect", "subscription", "subscribe", "unsubscribe", "useAsyncEffect", "disposed", "initialize", "initialized", "catch", "err", "log", "printBanner", "getAsyncProviderValue", "destroy", "then", "SystemStatus", "ACTIVE", "ClientContext", "Provider", "value"]
|
|
7
|
-
}
|
|
File without changes
|
|
File without changes
|