@dxos/react-client 0.8.4-main.c85a9c8dae → 0.8.4-main.d05539e30a
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/LICENSE +102 -5
- package/README.md +1 -1
- 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 +26 -97
- package/dist/lib/browser/echo/index.mjs.map +4 -4
- 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 +26 -97
- package/dist/lib/node-esm/echo/index.mjs.map +4 -4
- 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/index.d.ts +0 -1
- package/dist/types/src/echo/index.d.ts.map +1 -1
- package/dist/types/src/echo/useMembers.d.ts.map +1 -1
- package/dist/types/src/echo/useSpaceInvitations.d.ts +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 +9 -7
- 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 +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/context.d.ts +2 -1
- package/dist/types/src/testing/context.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 +27 -50
- 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/index.ts +0 -1
- package/src/echo/useSpaceInvitations.ts +1 -2
- package/src/echo/useSpaces.test.tsx +6 -13
- package/src/echo/useSpaces.ts +17 -31
- package/src/echo/useSyncState.ts +1 -5
- 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 +3 -4
- package/src/testing/context.tsx +2 -1
- package/src/testing/util.tsx +0 -1
- package/src/testing/withClientProvider.stories.tsx +6 -8
- package/src/testing/withClientProvider.tsx +2 -4
- package/tsconfig.json +6 -0
- 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/types/src/echo/useQueue.d.ts +0 -11
- package/dist/types/src/echo/useQueue.d.ts.map +0 -1
- package/src/echo/useQueue.ts +0 -74
- /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.d05539e30a",
|
|
4
4
|
"description": "React client API",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://github.com/dxos/dxos"
|
|
10
10
|
},
|
|
11
|
-
"license": "
|
|
11
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
12
12
|
"author": "DXOS.org",
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"type": "module",
|
|
@@ -63,46 +63,23 @@
|
|
|
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/async": "0.8.4-main.
|
|
93
|
-
"@dxos/
|
|
94
|
-
"@dxos/
|
|
95
|
-
"@dxos/context": "0.8.4-main.
|
|
96
|
-
"@dxos/
|
|
97
|
-
"@dxos/echo
|
|
98
|
-
"@dxos/
|
|
99
|
-
"@dxos/
|
|
100
|
-
"@dxos/echo": "0.8.4-main.
|
|
101
|
-
"@dxos/
|
|
102
|
-
"@dxos/
|
|
103
|
-
"@dxos/
|
|
104
|
-
"@dxos/
|
|
105
|
-
"@dxos/
|
|
67
|
+
"@dxos/async": "0.8.4-main.d05539e30a",
|
|
68
|
+
"@dxos/client": "0.8.4-main.d05539e30a",
|
|
69
|
+
"@dxos/config": "0.8.4-main.d05539e30a",
|
|
70
|
+
"@dxos/context": "0.8.4-main.d05539e30a",
|
|
71
|
+
"@dxos/codec-protobuf": "0.8.4-main.d05539e30a",
|
|
72
|
+
"@dxos/echo": "0.8.4-main.d05539e30a",
|
|
73
|
+
"@dxos/debug": "0.8.4-main.d05539e30a",
|
|
74
|
+
"@dxos/echo-protocol": "0.8.4-main.d05539e30a",
|
|
75
|
+
"@dxos/echo-react": "0.8.4-main.d05539e30a",
|
|
76
|
+
"@dxos/invariant": "0.8.4-main.d05539e30a",
|
|
77
|
+
"@dxos/keys": "0.8.4-main.d05539e30a",
|
|
78
|
+
"@dxos/log": "0.8.4-main.d05539e30a",
|
|
79
|
+
"@dxos/node-std": "0.8.4-main.d05539e30a",
|
|
80
|
+
"@dxos/protocols": "0.8.4-main.d05539e30a",
|
|
81
|
+
"@dxos/react-hooks": "0.8.4-main.d05539e30a",
|
|
82
|
+
"@dxos/util": "0.8.4-main.d05539e30a"
|
|
106
83
|
},
|
|
107
84
|
"devDependencies": {
|
|
108
85
|
"@types/react": "~19.2.7",
|
|
@@ -110,21 +87,21 @@
|
|
|
110
87
|
"react": "~19.2.3",
|
|
111
88
|
"react-dom": "~19.2.3",
|
|
112
89
|
"typedoc": "0.28.1",
|
|
113
|
-
"@dxos/react-ui
|
|
114
|
-
"@dxos/
|
|
115
|
-
"@dxos/storybook-utils": "0.8.4-main.
|
|
116
|
-
"@dxos/test-utils": "0.8.4-main.
|
|
117
|
-
"@dxos/ui-theme": "0.8.4-main.
|
|
118
|
-
"@dxos/
|
|
90
|
+
"@dxos/react-ui": "0.8.4-main.d05539e30a",
|
|
91
|
+
"@dxos/random": "0.8.4-main.d05539e30a",
|
|
92
|
+
"@dxos/storybook-utils": "0.8.4-main.d05539e30a",
|
|
93
|
+
"@dxos/test-utils": "0.8.4-main.d05539e30a",
|
|
94
|
+
"@dxos/ui-theme": "0.8.4-main.d05539e30a",
|
|
95
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.d05539e30a"
|
|
119
96
|
},
|
|
120
97
|
"peerDependencies": {
|
|
121
98
|
"react": "~19.2.3",
|
|
122
99
|
"react-dom": "~19.2.3"
|
|
123
100
|
},
|
|
124
101
|
"optionalDependencies": {
|
|
125
|
-
"@dxos/
|
|
126
|
-
"@dxos/
|
|
127
|
-
"@dxos/
|
|
102
|
+
"@dxos/react-ui": "0.8.4-main.d05539e30a",
|
|
103
|
+
"@dxos/random": "0.8.4-main.d05539e30a",
|
|
104
|
+
"@dxos/ui-theme": "0.8.4-main.d05539e30a"
|
|
128
105
|
},
|
|
129
106
|
"publishConfig": {
|
|
130
107
|
"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/index.ts
CHANGED
|
@@ -6,11 +6,10 @@ import { useMemo } from 'react';
|
|
|
6
6
|
|
|
7
7
|
import { MulticastObservable } from '@dxos/async';
|
|
8
8
|
import { type PublicKey } from '@dxos/client';
|
|
9
|
-
import { type SpaceId } from '@dxos/
|
|
9
|
+
import { type SpaceId } from '@dxos/keys';
|
|
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,47 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { useState } from 'react';
|
|
6
|
-
|
|
7
5
|
import { PublicKey } from '@dxos/client';
|
|
8
|
-
import { type Space,
|
|
9
|
-
import {
|
|
6
|
+
import { type Space, SpaceState } from '@dxos/client/echo';
|
|
7
|
+
import { type SpaceId } from '@dxos/keys';
|
|
8
|
+
import { useMulticastObservable } from '@dxos/react-hooks';
|
|
10
9
|
|
|
11
10
|
import { useClient } from '../client';
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* Get a specific Space using its id.
|
|
15
14
|
* The space is not guaranteed to be in the ready state.
|
|
16
|
-
* Returns
|
|
15
|
+
* Returns undefined if no id is provided.
|
|
17
16
|
* Requires a ClientProvider somewhere in the parent tree.
|
|
18
17
|
*
|
|
19
|
-
* @param spaceId the id of the space to look for
|
|
18
|
+
* @param spaceId the id of the space to look for.
|
|
20
19
|
*/
|
|
21
20
|
// TODO(wittjosiah): Currently unable to remove `PublicKey` from this api.
|
|
22
21
|
// When initially joining a space that is all that is returned.
|
|
23
22
|
export const useSpace = (spaceId?: SpaceId | PublicKey): Space | undefined => {
|
|
24
23
|
const client = useClient();
|
|
25
24
|
const spaces = useMulticastObservable<Space[]>(client.spaces);
|
|
26
|
-
|
|
25
|
+
if (!spaceId) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return;
|
|
29
|
+
return spaces.find((space) => {
|
|
30
|
+
if (spaceId instanceof PublicKey) {
|
|
31
|
+
return space.key.equals(spaceId);
|
|
32
32
|
}
|
|
33
33
|
|
|
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
|
-
}
|
|
34
|
+
return space.id === spaceId;
|
|
35
|
+
});
|
|
51
36
|
};
|
|
52
37
|
|
|
53
38
|
/**
|
|
54
39
|
* Get a Space database by the id of the space.
|
|
55
40
|
* The space is not guaranteed to be in the ready state.
|
|
56
|
-
* Returns
|
|
41
|
+
* Returns undefined if no id is provided.
|
|
57
42
|
* Requires a ClientProvider somewhere in the parent tree.
|
|
58
43
|
*
|
|
59
|
-
* @param spaceId the id of the space to look for
|
|
44
|
+
* @param spaceId the id of the space to look for.
|
|
45
|
+
* @deprecated Use useSpace.
|
|
60
46
|
*/
|
|
61
47
|
export const useDatabase = (spaceId?: SpaceId): Space['db'] | undefined => {
|
|
62
48
|
const space = useSpace(spaceId);
|
|
@@ -74,7 +60,7 @@ export type UseSpacesProps = {
|
|
|
74
60
|
* Get all Spaces available to current user.
|
|
75
61
|
* Requires a ClientProvider somewhere in the parent tree.
|
|
76
62
|
* By default, only ready spaces are returned.
|
|
77
|
-
* @returns an array of Spaces
|
|
63
|
+
* @returns an array of Spaces.
|
|
78
64
|
*/
|
|
79
65
|
export const useSpaces = ({ all = false }: UseSpacesProps = {}): Space[] => {
|
|
80
66
|
const client = useClient();
|
package/src/echo/useSyncState.ts
CHANGED
|
@@ -6,14 +6,10 @@ import { useEffect, useState } from 'react';
|
|
|
6
6
|
|
|
7
7
|
import { type PeerSyncState, type Space, type SpaceSyncStateMap } from '@dxos/client/echo';
|
|
8
8
|
import { Context } from '@dxos/context';
|
|
9
|
-
import {
|
|
10
|
-
import { EdgeService } from '@dxos/protocols';
|
|
9
|
+
import { isEdgePeerId } from '@dxos/echo-protocol';
|
|
11
10
|
|
|
12
11
|
import { useClient } from '../client';
|
|
13
12
|
|
|
14
|
-
const isEdgePeerId = (peerId: string, spaceId: SpaceId) =>
|
|
15
|
-
peerId.startsWith(`${EdgeService.AUTOMERGE_REPLICATOR}:${spaceId}`);
|
|
16
|
-
|
|
17
13
|
/**
|
|
18
14
|
* Hook Subscribes to sync state for each space.
|
|
19
15
|
*/
|
|
@@ -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 { type SpaceId } from '@dxos/keys';
|
|
11
|
+
import { random } from '@dxos/random';
|
|
11
12
|
import { useAsyncEffect } from '@dxos/react-hooks';
|
|
12
13
|
|
|
13
14
|
import { ClientProvider } from '../client';
|
|
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/context.tsx
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
import { createContext, useContext } from 'react';
|
|
6
6
|
|
|
7
|
-
import { type Space
|
|
7
|
+
import { type Space } from '@dxos/client/echo';
|
|
8
8
|
import { raise } from '@dxos/debug';
|
|
9
|
+
import { type SpaceId } from '@dxos/keys';
|
|
9
10
|
|
|
10
11
|
export type ClientStory = {
|
|
11
12
|
index?: number;
|
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>;
|
|
@@ -7,14 +7,14 @@ import React, { useCallback, useMemo, useRef, useState } from 'react';
|
|
|
7
7
|
|
|
8
8
|
import { Trigger } from '@dxos/async';
|
|
9
9
|
import { type Client } from '@dxos/client';
|
|
10
|
-
import { type Space
|
|
10
|
+
import { type Space } from '@dxos/client/echo';
|
|
11
11
|
import { TestBuilder, performInvitation } from '@dxos/client/testing';
|
|
12
|
+
import { type SpaceId } from '@dxos/keys';
|
|
12
13
|
import { log } from '@dxos/log';
|
|
13
14
|
import { ErrorBoundary } from '@dxos/react-ui';
|
|
14
15
|
import { type MaybePromise } from '@dxos/util';
|
|
15
16
|
|
|
16
17
|
import { ClientProvider, type ClientProviderProps } from '../client';
|
|
17
|
-
|
|
18
18
|
import { ClientStory } from './context';
|
|
19
19
|
|
|
20
20
|
type InitializeProps = {
|
|
@@ -39,8 +39,6 @@ const initializeClient = async (
|
|
|
39
39
|
if (createIdentity || createSpace) {
|
|
40
40
|
if (!client.halo.identity.get()) {
|
|
41
41
|
await client.halo.createIdentity();
|
|
42
|
-
await client.spaces.waitUntilReady();
|
|
43
|
-
await client.spaces.default.waitUntilReady();
|
|
44
42
|
await onCreateIdentity?.({ client }, context);
|
|
45
43
|
}
|
|
46
44
|
}
|
package/tsconfig.json
CHANGED
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
{
|
|
24
24
|
"path": "../../common/invariant"
|
|
25
25
|
},
|
|
26
|
+
{
|
|
27
|
+
"path": "../../common/keys"
|
|
28
|
+
},
|
|
26
29
|
{
|
|
27
30
|
"path": "../../common/log"
|
|
28
31
|
},
|
|
@@ -44,6 +47,9 @@
|
|
|
44
47
|
{
|
|
45
48
|
"path": "../../core/echo/echo"
|
|
46
49
|
},
|
|
50
|
+
{
|
|
51
|
+
"path": "../../core/echo/echo-protocol"
|
|
52
|
+
},
|
|
47
53
|
{
|
|
48
54
|
"path": "../../core/echo/echo-react"
|
|
49
55
|
},
|
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": ";;;;;AAIA,OAAOA,SAGLC,YACAC,WACAC,qBACAC,gBACK;AAEP,SAASC,QAAyDC,oBAAoB;AAEtF,SAASC,WAAW;AACpB,SAASC,gBAAgBC,0BAA0B;AACnD,SAA2CC,6BAA6B;;;ACVxE,IAAMC,SAAS,CAACC,WAAAA;AACd,QAAMC,aAAaD,OAAOE,OAAOC,IAAI,8BAAA;AACrC,QAAMC,OAAOH,aAAa,eAAeA,UAAAA;IAAkB;AAE3D,SACE;;;;;;;eAMkBD,OAAOK,OAAO;EAAMD,IAAAA;AAE1C;AAEA,IAAIE,gBAAgB;AAEb,IAAMC,cAAc,CAACP,WAAAA;AAC1B,MAAIM,iBAAiBE,OAAOC,SAASC,aAAa,aAAa;AAC7D;EACF;AAEAJ,kBAAgB;AAEhBK,UAAQC,IAAI,KAAKb,OAAOC,MAAAA,CAAAA,IAAW,yBAAA;AACrC;;;;ADwCO,IAAMa,iBAAiBC,2BAC5B,CACE,EACEC,UACAC,QAAQC,YACRC,QAAQC,YACRC,UAAUC,cACVC,QAAQC,YACRC,UAAUC,WAAW,MAAM,MAC3BC,UACAC,eACA,GAAGC,QAAAA,GAELC,iBAAAA;AAOA,QAAM,CAACC,OAAOC,QA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GAAGQ;QAAQ,CAAA;AACnDqB,YAAI,kBAAA,QAAA;;;;;;AACJ,cAAMJ,WAAW3B,OAAAA;MACnB;IACF,SAAS8B,KAAK;AACZ,UAAI,CAACJ,UAAU;AACbK,YAAIF,MAAMC,KAAAA,QAAAA;;;;;;MACZ;IACF;AAEA,WAAO,MAAA;AACLC,UAAI,YAAA,QAAA;;;;;;AACJL,iBAAW;AAEX,UAAI,CAACzB,YAAY;AACf,aAAKD,SACDkC,QAAAA,EACDC,KAAK,MAAA;AACJJ,cAAI,aAAA,QAAA;;;;;;QACN,CAAA,EACCF,MAAM,CAACC,QAAQC,IAAIF,MAAMC,KAAAA,QAAAA;;;;;;MAC9B;IACF;EACF,GAAG;IAAC/B;IAAYE;IAAYE;IAAcK;GAAS;AAEnD,MAAI,CAACR,QAAQ4B,eAAexB,WAAWgC,aAAaC,QAAQ;AAC1D,WAAO,sBAAA,cAAC9B,UAAAA;MAASP;MAAgBI;;EACnC;AAEA,SAAO,sBAAA,cAACkC,cAAcC,UAAQ;IAACC,OAAO;MAAExC;MAAQI;IAAO;KAAIP,QAAAA;AAC7D,CAAA;",
|
|
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": ";;;;;;AAIA,OAAOA,SAGLC,YACAC,WACAC,qBACAC,gBACK;AAEP,SAASC,QAAyDC,oBAAoB;AAEtF,SAASC,WAAW;AACpB,SAASC,gBAAgBC,0BAA0B;AACnD,SAA2CC,6BAA6B;;;ACVxE,IAAMC,SAAS,CAACC,WAAAA;AACd,QAAMC,aAAaD,OAAOE,OAAOC,IAA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
-
"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,11 +0,0 @@
|
|
|
1
|
-
import { type Queue } from '@dxos/client/echo';
|
|
2
|
-
import { type Entity } from '@dxos/echo';
|
|
3
|
-
import { type DXN } from '@dxos/keys';
|
|
4
|
-
export type UseQueueOptions = {
|
|
5
|
-
pollInterval?: number;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Polls the given Edge queue.
|
|
9
|
-
*/
|
|
10
|
-
export declare const useQueue: <T extends Entity.Unknown>(queueDxn?: DXN, options?: UseQueueOptions) => Queue<T> | undefined;
|
|
11
|
-
//# sourceMappingURL=useQueue.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useQueue.d.ts","sourceRoot":"","sources":["../../../../src/echo/useQueue.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,YAAY,CAAC;AAMtC,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;GAEG;AAKH,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,MAAM,CAAC,OAAO,EAC/C,WAAW,GAAG,EACd,UAAS,eAAoB,KAC5B,KAAK,CAAC,CAAC,CAAC,GAAG,SA4Cb,CAAC"}
|