@dxos/react-client 0.8.4-main.72ec0f3 → 0.8.4-main.74a063c4e0
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 +2 -4
- package/.storybook/preview.mts +2 -2
- package/dist/lib/browser/chunk-BVDNYEYI.mjs +179 -0
- package/dist/lib/browser/chunk-BVDNYEYI.mjs.map +7 -0
- package/dist/lib/browser/chunk-PFF63FPR.mjs +16 -0
- package/dist/lib/browser/chunk-PFF63FPR.mjs.map +7 -0
- package/dist/lib/browser/chunk-TSF6Y5VB.mjs +8 -0
- package/dist/lib/browser/chunk-TSF6Y5VB.mjs.map +7 -0
- package/dist/lib/browser/devtools/index.mjs +2 -1
- package/dist/lib/browser/devtools/index.mjs.map +1 -1
- package/dist/lib/browser/echo/index.mjs +51 -114
- package/dist/lib/browser/echo/index.mjs.map +4 -4
- package/dist/lib/browser/halo/index.mjs +2 -1
- package/dist/lib/browser/halo/index.mjs.map +1 -1
- package/dist/lib/browser/index.mjs +114 -12
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/mesh/index.mjs +2 -1
- package/dist/lib/browser/mesh/index.mjs.map +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +85 -114
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/chunk-373DPHEQ.mjs +10 -0
- package/dist/lib/node-esm/chunk-373DPHEQ.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-NETTSER2.mjs +17 -0
- package/dist/lib/node-esm/chunk-NETTSER2.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-VSA674XR.mjs +180 -0
- package/dist/lib/node-esm/chunk-VSA674XR.mjs.map +7 -0
- package/dist/lib/node-esm/devtools/index.mjs +2 -1
- package/dist/lib/node-esm/devtools/index.mjs.map +1 -1
- package/dist/lib/node-esm/echo/index.mjs +51 -114
- package/dist/lib/node-esm/echo/index.mjs.map +4 -4
- package/dist/lib/node-esm/halo/index.mjs +2 -1
- package/dist/lib/node-esm/halo/index.mjs.map +1 -1
- package/dist/lib/node-esm/index.mjs +114 -12
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/mesh/index.mjs +2 -1
- package/dist/lib/node-esm/mesh/index.mjs.map +1 -1
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +85 -114
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/client/ClientProvider.d.ts +0 -10
- package/dist/types/src/client/ClientProvider.d.ts.map +1 -1
- package/dist/types/src/echo/index.d.ts +2 -2
- package/dist/types/src/echo/index.d.ts.map +1 -1
- package/dist/types/src/echo/useMembers.d.ts +2 -2
- package/dist/types/src/echo/useMembers.d.ts.map +1 -1
- package/dist/types/src/echo/useQueue.d.ts +3 -2
- package/dist/types/src/echo/useQueue.d.ts.map +1 -1
- package/dist/types/src/echo/useSpaceInvitations.d.ts +3 -2
- package/dist/types/src/echo/useSpaceInvitations.d.ts.map +1 -1
- package/dist/types/src/echo/useSpaceProperties.d.ts +13 -0
- package/dist/types/src/echo/useSpaceProperties.d.ts.map +1 -0
- package/dist/types/src/echo/useSpaces.d.ts +18 -9
- 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 +5 -4
- 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 +4 -2
- 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 +0 -3
- 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 +35 -32
- package/src/client/ClientProvider.test.tsx +0 -1
- package/src/client/ClientProvider.tsx +12 -27
- package/src/client/useConfig.test.tsx +0 -1
- package/src/echo/index.ts +2 -2
- package/src/echo/useMembers.ts +5 -3
- package/src/echo/useQueue.ts +3 -2
- package/src/echo/useSpaceInvitations.ts +9 -5
- package/src/echo/useSpaceProperties.ts +28 -0
- package/src/echo/useSpaces.test.tsx +7 -14
- package/src/echo/useSpaces.ts +33 -27
- package/src/echo/useSyncState.ts +4 -3
- package/src/halo/Passkey.stories.tsx +4 -5
- package/src/halo/useDevices.test.tsx +0 -1
- package/src/testing/ClientRepeater.stories.tsx +10 -6
- package/src/testing/ClientRepeater.tsx +11 -15
- package/src/testing/context.tsx +4 -3
- package/src/testing/util.tsx +0 -1
- package/src/testing/withClientProvider.stories.tsx +12 -7
- package/src/testing/withClientProvider.tsx +62 -82
- package/tsconfig.json +3 -3
- package/typedoc.json +1 -1
- package/vitest.config.ts +1 -3
- package/dist/lib/browser/chunk-TA2HGRAF.mjs +0 -309
- package/dist/lib/browser/chunk-TA2HGRAF.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ZJMNF7GC.mjs +0 -311
- package/dist/lib/node-esm/chunk-ZJMNF7GC.mjs.map +0 -7
- package/dist/types/src/echo/useQuery.d.ts +0 -11
- package/dist/types/src/echo/useQuery.d.ts.map +0 -1
- package/dist/types/src/echo/useQuery.test.d.ts +0 -2
- package/dist/types/src/echo/useQuery.test.d.ts.map +0 -1
- package/dist/types/src/echo/useSchema.d.ts +0 -8
- package/dist/types/src/echo/useSchema.d.ts.map +0 -1
- 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/echo/useQuery.test.tsx +0 -129
- package/src/echo/useQuery.ts +0 -64
- package/src/echo/useSchema.ts +0 -54
- package/src/playwright/playwright.config.ts +0 -17
- package/src/playwright/smoke.spec.ts +0 -24
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ClientProvider
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-BVDNYEYI.mjs";
|
|
4
|
+
import "../chunk-TSF6Y5VB.mjs";
|
|
4
5
|
|
|
5
6
|
// src/testing/index.ts
|
|
6
7
|
export * from "@dxos/client/testing";
|
|
@@ -9,24 +10,20 @@ export * from "@dxos/client/testing";
|
|
|
9
10
|
import { createContext, useContext } from "react";
|
|
10
11
|
import { raise } from "@dxos/debug";
|
|
11
12
|
var ClientStory = /* @__PURE__ */ createContext(void 0);
|
|
12
|
-
var
|
|
13
|
+
var useClientStory = () => {
|
|
13
14
|
return useContext(ClientStory) ?? raise(new Error("Missing ClientStory"));
|
|
14
15
|
};
|
|
15
16
|
|
|
16
17
|
// src/testing/ClientRepeater.tsx
|
|
17
|
-
import React, {
|
|
18
|
+
import React, { useRef, useState } from "react";
|
|
18
19
|
import { Client } from "@dxos/client";
|
|
19
20
|
import { TestBuilder, performInvitation } from "@dxos/client/testing";
|
|
20
|
-
import {
|
|
21
|
-
import { faker } from "@dxos/random";
|
|
21
|
+
import { random } from "@dxos/random";
|
|
22
22
|
import { useAsyncEffect } from "@dxos/react-hooks";
|
|
23
23
|
var ClientRepeater = (props) => {
|
|
24
24
|
const { component: Component, controls: Controls, count = 1, types, createIdentity, createSpace, onCreateSpace } = props;
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
registerSignalsRuntime();
|
|
27
|
-
}, []);
|
|
28
25
|
const [clients, setClients] = useState(props.clients ?? []);
|
|
29
|
-
const [
|
|
26
|
+
const [spaceId, setSpaceId] = useState();
|
|
30
27
|
const testBuilder = useRef(new TestBuilder());
|
|
31
28
|
useAsyncEffect(async () => {
|
|
32
29
|
const clients2 = [
|
|
@@ -42,9 +39,9 @@ var ClientRepeater = (props) => {
|
|
|
42
39
|
if (createSpace) {
|
|
43
40
|
const client = clients2[0];
|
|
44
41
|
const space = await client.spaces.create({
|
|
45
|
-
name:
|
|
42
|
+
name: random.commerce.productName()
|
|
46
43
|
});
|
|
47
|
-
|
|
44
|
+
setSpaceId(space.id);
|
|
48
45
|
await onCreateSpace?.({
|
|
49
46
|
client,
|
|
50
47
|
space
|
|
@@ -67,25 +64,23 @@ var ClientRepeater = (props) => {
|
|
|
67
64
|
}, /* @__PURE__ */ React.createElement(Component, {
|
|
68
65
|
id: index,
|
|
69
66
|
count: clients.length,
|
|
70
|
-
|
|
67
|
+
spaceId,
|
|
71
68
|
...props.args
|
|
72
69
|
}))));
|
|
73
70
|
};
|
|
74
71
|
|
|
75
72
|
// src/testing/withClientProvider.tsx
|
|
76
|
-
import React2, {
|
|
77
|
-
import { ErrorBoundary as NaturalErrorBoundary } from "react-error-boundary";
|
|
73
|
+
import React2, { useCallback, useMemo, useRef as useRef2, useState as useState2 } from "react";
|
|
78
74
|
import { Trigger } from "@dxos/async";
|
|
79
75
|
import { TestBuilder as TestBuilder2, performInvitation as performInvitation2 } from "@dxos/client/testing";
|
|
80
76
|
import { log } from "@dxos/log";
|
|
77
|
+
import { ErrorBoundary } from "@dxos/react-ui";
|
|
81
78
|
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/react-client/src/testing/withClientProvider.tsx";
|
|
82
79
|
var initializeClient = async (client, { createIdentity, createSpace, onCreateIdentity, onCreateSpace, onInitialized }, context) => {
|
|
83
80
|
await onInitialized?.(client);
|
|
84
81
|
if (createIdentity || createSpace) {
|
|
85
82
|
if (!client.halo.identity.get()) {
|
|
86
83
|
await client.halo.createIdentity();
|
|
87
|
-
await client.spaces.waitUntilReady();
|
|
88
|
-
await client.spaces.default.waitUntilReady();
|
|
89
84
|
await onCreateIdentity?.({
|
|
90
85
|
client
|
|
91
86
|
}, context);
|
|
@@ -103,7 +98,8 @@ var initializeClient = async (client, { createIdentity, createSpace, onCreateIde
|
|
|
103
98
|
}, context);
|
|
104
99
|
}
|
|
105
100
|
return {
|
|
106
|
-
space
|
|
101
|
+
space,
|
|
102
|
+
spaceId: space?.id
|
|
107
103
|
};
|
|
108
104
|
};
|
|
109
105
|
var withClientProvider = ({ createIdentity, createSpace, onCreateSpace, onCreateIdentity, onInitialized, ...props } = {}) => {
|
|
@@ -119,7 +115,9 @@ var withClientProvider = ({ createIdentity, createSpace, onCreateSpace, onCreate
|
|
|
119
115
|
}, context);
|
|
120
116
|
setData(data2);
|
|
121
117
|
};
|
|
122
|
-
return /* @__PURE__ */ React2.createElement(ErrorBoundary,
|
|
118
|
+
return /* @__PURE__ */ React2.createElement(ErrorBoundary, {
|
|
119
|
+
name: "client-provider"
|
|
120
|
+
}, /* @__PURE__ */ React2.createElement(ClientProvider, {
|
|
123
121
|
onInitialized: handleInitialized,
|
|
124
122
|
...props
|
|
125
123
|
}, /* @__PURE__ */ React2.createElement(ClientStory.Provider, {
|
|
@@ -127,121 +125,94 @@ var withClientProvider = ({ createIdentity, createSpace, onCreateSpace, onCreate
|
|
|
127
125
|
}, /* @__PURE__ */ React2.createElement(Story, null))));
|
|
128
126
|
};
|
|
129
127
|
};
|
|
130
|
-
var MultiClientContext = /* @__PURE__ */ createContext2({
|
|
131
|
-
id: 0
|
|
132
|
-
});
|
|
133
|
-
var useMultiClient = () => useContext2(MultiClientContext);
|
|
134
128
|
var withMultiClientProvider = ({ numClients = 2, createIdentity, createSpace, onCreateSpace, onCreateIdentity, onInitialized, ...props }) => {
|
|
135
129
|
return (Story, context) => {
|
|
136
|
-
const builder = useRef2(new TestBuilder2());
|
|
137
|
-
const hostRef = useRef2(null);
|
|
138
130
|
const spaceReady = useRef2(new Trigger());
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
131
|
+
const [spaceId, setSpaceId] = useState2();
|
|
132
|
+
const clients = useMemo(() => {
|
|
133
|
+
const buidler = new TestBuilder2();
|
|
134
|
+
return Array.from({
|
|
135
|
+
length: numClients
|
|
136
|
+
}).map(() => {
|
|
137
|
+
return {
|
|
138
|
+
services: buidler.createLocalClientServices()
|
|
139
|
+
};
|
|
147
140
|
});
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
141
|
+
}, [
|
|
142
|
+
numClients
|
|
143
|
+
]);
|
|
144
|
+
const handleInitialized = useCallback(async (client, index) => {
|
|
145
|
+
if (index === 0) {
|
|
146
|
+
const { space } = await initializeClient(client, {
|
|
147
|
+
createIdentity,
|
|
148
|
+
createSpace,
|
|
149
|
+
onCreateSpace,
|
|
150
|
+
onCreateIdentity,
|
|
151
|
+
onInitialized
|
|
152
|
+
}, context);
|
|
153
|
+
log.info("inviting", {
|
|
154
|
+
index,
|
|
155
|
+
spaceId: space?.id
|
|
156
|
+
}, {
|
|
157
|
+
F: __dxlog_file,
|
|
158
|
+
L: 147,
|
|
159
|
+
S: void 0,
|
|
160
|
+
C: (f, a) => f(...a)
|
|
161
|
+
});
|
|
162
|
+
setSpaceId(space?.id);
|
|
163
|
+
spaceReady.current.wake(space);
|
|
164
|
+
} else {
|
|
165
|
+
await initializeClient(client, {
|
|
166
|
+
createIdentity,
|
|
167
|
+
onInitialized
|
|
168
|
+
}, context);
|
|
169
|
+
log.info("waiting", {
|
|
170
|
+
index
|
|
171
|
+
}, {
|
|
172
|
+
F: __dxlog_file,
|
|
173
|
+
L: 154,
|
|
174
|
+
S: void 0,
|
|
175
|
+
C: (f, a) => f(...a)
|
|
176
|
+
});
|
|
177
|
+
const space = await spaceReady.current.wait();
|
|
178
|
+
if (space) {
|
|
179
|
+
log.info("joining", {
|
|
180
|
+
index,
|
|
181
|
+
spaceId: space.id
|
|
161
182
|
}, {
|
|
162
183
|
F: __dxlog_file,
|
|
163
|
-
L:
|
|
184
|
+
L: 157,
|
|
164
185
|
S: void 0,
|
|
165
186
|
C: (f, a) => f(...a)
|
|
166
187
|
});
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}, context);
|
|
172
|
-
const space = await spaceReady.current.wait();
|
|
173
|
-
if (space) {
|
|
174
|
-
log.info("joining", {
|
|
175
|
-
index
|
|
176
|
-
}, {
|
|
177
|
-
F: __dxlog_file,
|
|
178
|
-
L: 154,
|
|
179
|
-
S: void 0,
|
|
180
|
-
C: (f, a) => f(...a)
|
|
181
|
-
});
|
|
182
|
-
await Promise.all(performInvitation2({
|
|
183
|
-
host: space,
|
|
184
|
-
guest: client.spaces
|
|
185
|
-
}));
|
|
186
|
-
}
|
|
188
|
+
await Promise.all(performInvitation2({
|
|
189
|
+
host: space,
|
|
190
|
+
guest: client.spaces
|
|
191
|
+
}));
|
|
187
192
|
}
|
|
188
193
|
}
|
|
189
|
-
};
|
|
190
|
-
return /* @__PURE__ */ React2.createElement(
|
|
191
|
-
|
|
192
|
-
}
|
|
194
|
+
}, []);
|
|
195
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
196
|
+
className: "absolute inset-0 grid grid-flow-col auto-cols-fr gap-4 overflow-hidden"
|
|
197
|
+
}, clients.map((client, index) => /* @__PURE__ */ React2.createElement(ClientProvider, {
|
|
193
198
|
key: index,
|
|
199
|
+
services: client.services,
|
|
200
|
+
onInitialized: (client2) => handleInitialized(client2, index),
|
|
201
|
+
...props
|
|
202
|
+
}, /* @__PURE__ */ React2.createElement(ClientStory.Provider, {
|
|
194
203
|
value: {
|
|
195
|
-
|
|
204
|
+
index,
|
|
205
|
+
spaceId
|
|
196
206
|
}
|
|
197
|
-
}, /* @__PURE__ */ React2.createElement(
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
...props
|
|
201
|
-
}, /* @__PURE__ */ React2.createElement(Story, null)))));
|
|
202
|
-
};
|
|
203
|
-
};
|
|
204
|
-
var ErrorBoundary = ({ children }) => {
|
|
205
|
-
const [error, setError] = useState2();
|
|
206
|
-
useEffect2(() => {
|
|
207
|
-
const handleError = (event) => {
|
|
208
|
-
setError(event.reason);
|
|
209
|
-
};
|
|
210
|
-
window.addEventListener("unhandledrejection", handleError);
|
|
211
|
-
return () => window.removeEventListener("unhandledrejection", handleError);
|
|
212
|
-
}, []);
|
|
213
|
-
if (error) {
|
|
214
|
-
return /* @__PURE__ */ React2.createElement(ErrorFallback, {
|
|
215
|
-
error,
|
|
216
|
-
resetErrorBoundary: () => setError(void 0)
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
return /* @__PURE__ */ React2.createElement(NaturalErrorBoundary, {
|
|
220
|
-
FallbackComponent: ErrorFallback
|
|
221
|
-
}, children);
|
|
222
|
-
};
|
|
223
|
-
var ErrorFallback = ({ error }) => {
|
|
224
|
-
const { name, message, stack } = error instanceof Error ? error : {
|
|
225
|
-
name: "Error",
|
|
226
|
-
message: String(error),
|
|
227
|
-
stack: void 0
|
|
207
|
+
}, /* @__PURE__ */ React2.createElement(ErrorBoundary, {
|
|
208
|
+
name: "client-provider"
|
|
209
|
+
}, /* @__PURE__ */ React2.createElement(Story, null))))));
|
|
228
210
|
};
|
|
229
|
-
return /* @__PURE__ */ React2.createElement("div", {
|
|
230
|
-
role: "alert",
|
|
231
|
-
className: "flex flex-col p-4 gap-4 overflow-auto"
|
|
232
|
-
}, /* @__PURE__ */ React2.createElement("h1", {
|
|
233
|
-
className: "text-xl text-red-500"
|
|
234
|
-
}, name), /* @__PURE__ */ React2.createElement("div", {
|
|
235
|
-
className: "text-lg"
|
|
236
|
-
}, message), stack && /* @__PURE__ */ React2.createElement("pre", {
|
|
237
|
-
className: "whitespace-pre-wrap text-sm text-subdued"
|
|
238
|
-
}, stack));
|
|
239
211
|
};
|
|
240
212
|
export {
|
|
241
213
|
ClientRepeater,
|
|
242
214
|
ClientStory,
|
|
243
|
-
|
|
244
|
-
useMultiClient,
|
|
215
|
+
useClientStory,
|
|
245
216
|
withClientProvider,
|
|
246
217
|
withMultiClientProvider
|
|
247
218
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/testing/index.ts", "../../../../src/testing/context.tsx", "../../../../src/testing/ClientRepeater.tsx", "../../../../src/testing/withClientProvider.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nexport * from '@dxos/client/testing';\n\nexport * from './context';\nexport * from './ClientRepeater';\nexport * from './withClientProvider';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { createContext, useContext } from 'react';\n\nimport { type Space } from '@dxos/client/echo';\nimport { raise } from '@dxos/debug';\n\nexport type ClientStory = {\n space?: Space;\n};\n\n// TODO(wittjosiah): Add to multi-client as well.\nexport const ClientStory = createContext<ClientStory | undefined>(undefined);\n\nexport const useClientProvider = (): ClientStory => {\n return useContext(ClientStory) ?? raise(new Error('Missing ClientStory'));\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport React, { type FC, useEffect, useRef, useState } from 'react';\n\nimport { Client, type PublicKey } from '@dxos/client';\nimport { TestBuilder, performInvitation } from '@dxos/client/testing';\nimport { type TypedObject } from '@dxos/echo/internal';\nimport { registerSignalsRuntime } from '@dxos/echo-signals/react';\nimport { faker } from '@dxos/random';\nimport { useAsyncEffect } from '@dxos/react-hooks';\n\nimport { ClientProvider } from '../client';\n\nimport { type WithClientProviderProps } from './withClientProvider';\n\nexport type ClientRepeatedComponentProps = { id: number; count: number; spaceKey?: PublicKey };\n\nexport type ClientRepeaterControlsProps = { clients: Client[] };\n\n// TODO(burdon): Reconcile with ClientProviderProps.\nexport type ClientRepeaterProps<P extends ClientRepeatedComponentProps> = {\n className?: string;\n component: FC<ClientRepeatedComponentProps>;\n controls?: FC<ClientRepeaterControlsProps>;\n count?: number;\n clients?: Client[];\n types?: TypedObject[];\n args?: Omit<P, 'id' | 'count'>;\n} & Pick<WithClientProviderProps, 'createIdentity' | 'createSpace' | 'onCreateSpace'>;\n\n/**\n * Utility component for Storybook stories which sets up clients for n peers.\n * The `Component` property is rendered n times, once for each peer.\n * @deprecated use `withClientProvider`.\n */\n// TODO(burdon): To discuss: evolve ClientRepeater with optional decorator that uses it.\n// NOTE: This is specifically not a storybook decorator because it broke stories as a decorator.\n// This seems primarily due to the fact that it required top-level await for the clients to initialize.\n// Storybook seemed to handle it alright, but Chromatic had a lot of trouble with it.\n// There was also a question of whether or not calling the story function multiple times was a good idea.\nexport const ClientRepeater = <P extends ClientRepeatedComponentProps>(props: ClientRepeaterProps<P>) => {\n const {\n component: Component,\n controls: Controls,\n count = 1,\n types,\n createIdentity,\n createSpace,\n onCreateSpace,\n } = props;\n useEffect(() => {\n registerSignalsRuntime();\n }, []);\n\n const [clients, setClients] = useState(props.clients ?? []);\n const [spaceKey, setSpaceKey] = useState<PublicKey>();\n\n const testBuilder = useRef(new TestBuilder());\n useAsyncEffect(async () => {\n const clients = [...Array(count)].map(\n (_) => new Client({ services: testBuilder.current.createLocalClientServices(), types }),\n );\n\n await Promise.all(clients.map((client) => client.initialize()));\n if (createIdentity || createSpace) {\n await Promise.all(clients.map((client) => client.halo.createIdentity()));\n }\n\n if (createSpace) {\n const client = clients[0];\n const space = await client.spaces.create({ name: faker.commerce.productName() });\n setSpaceKey(space.key);\n await onCreateSpace?.({ client, space }, {});\n await Promise.all(clients.slice(1).flatMap((client) => performInvitation({ host: space, guest: client.spaces })));\n }\n\n setClients(clients);\n }, []);\n\n if (clients.length === 0) {\n return null;\n }\n\n return (\n <>\n {Controls && <Controls clients={clients} />}\n {clients.map((client, index) => (\n <ClientProvider key={index} client={client}>\n <Component id={index} count={clients.length} spaceKey={spaceKey} {...{ ...props.args }} />\n </ClientProvider>\n ))}\n </>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Decorator, type StoryContext } from '@storybook/react';\nimport React, { type PropsWithChildren, createContext, useContext, useEffect, useRef, useState } from 'react';\nimport { type FallbackProps, ErrorBoundary as NaturalErrorBoundary } from 'react-error-boundary';\n\nimport { Trigger } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { type Space } from '@dxos/client/echo';\nimport { TestBuilder, performInvitation } from '@dxos/client/testing';\nimport { log } from '@dxos/log';\nimport { type MaybePromise } from '@dxos/util';\n\nimport { ClientProvider, type ClientProviderProps } from '../client';\n\nimport { ClientStory } from './context';\n\ntype InitializeProps = {\n createIdentity?: boolean;\n createSpace?: boolean;\n onInitialized?: (client: Client) => MaybePromise<void>;\n onCreateIdentity?: (props: { client: Client }, context: StoryContext | any) => MaybePromise<void>;\n // NOTE: context must be untyped until ClientRepeater is removed.\n onCreateSpace?: (props: { client: Client; space: Space }, context: StoryContext | any) => MaybePromise<void>;\n};\n\n/**\n * Initialize client, identity and first space.\n */\nconst initializeClient = async (\n client: Client,\n { createIdentity, createSpace, onCreateIdentity, onCreateSpace, onInitialized }: InitializeProps,\n context: StoryContext,\n): Promise<ClientStory> => {\n await onInitialized?.(client);\n\n if (createIdentity || createSpace) {\n if (!client.halo.identity.get()) {\n await client.halo.createIdentity();\n await client.spaces.waitUntilReady();\n await client.spaces.default.waitUntilReady();\n await onCreateIdentity?.({ client }, context);\n }\n }\n\n let space: Space | undefined;\n if (createSpace) {\n space = await client.spaces.create({ name: 'Test Space' });\n await space.waitUntilReady(); // Is this required?\n await onCreateSpace?.({ client, space }, context);\n }\n\n return { space };\n};\n\nexport type WithClientProviderProps = InitializeProps & Omit<ClientProviderProps, 'onInitialized'>;\n\n/**\n * Decorator that provides the client context.\n */\nexport const withClientProvider = ({\n createIdentity,\n createSpace,\n onCreateSpace,\n onCreateIdentity,\n onInitialized,\n ...props\n}: WithClientProviderProps = {}): Decorator => {\n return (Story, context) => {\n const [data, setData] = useState<ClientStory>({});\n const handleInitialized = async (client: Client) => {\n const data = await initializeClient(\n client,\n {\n createIdentity,\n createSpace,\n onCreateSpace,\n onCreateIdentity,\n onInitialized,\n },\n context,\n );\n\n setData(data);\n };\n\n return (\n <ErrorBoundary>\n <ClientProvider onInitialized={handleInitialized} {...props}>\n <ClientStory.Provider value={data}>\n <Story />\n </ClientStory.Provider>\n </ClientProvider>\n </ErrorBoundary>\n );\n };\n};\n\n// TODO(burdon): Implement context per client for context.\n// TODO(burdon): Callback once all invitations have completed.\n// TODO(burdon): Delay/jitter for creation of other clients.\nexport type WithMultiClientProviderProps = InitializeProps &\n Omit<ClientProviderProps, 'onInitialized'> & { numClients?: number };\n\nconst MultiClientContext = createContext<{ id: number }>({ id: 0 });\n\nexport const useMultiClient = () => useContext(MultiClientContext);\n\n/**\n * Decorator that creates a scaffold for multiple clients.\n * Orchestrates invitations between a randomly selected host and the remaining clients.\n */\nexport const withMultiClientProvider = ({\n numClients = 2,\n createIdentity,\n createSpace,\n onCreateSpace,\n onCreateIdentity,\n onInitialized,\n ...props\n}: WithMultiClientProviderProps): Decorator => {\n return (Story, context) => {\n const builder = useRef(new TestBuilder());\n const hostRef = useRef<Client>(null);\n const spaceReady = useRef(new Trigger<Space | undefined>());\n\n // Handle invitations.\n // NOTE: The zeroth client isn't necessarily the first to be initialized.\n const handleInitialized = async (client: Client, index: number) => {\n log.info('initialized', { index });\n if (createSpace) {\n if (!hostRef.current) {\n hostRef.current = client;\n const { space } = await initializeClient(\n client,\n {\n createIdentity,\n createSpace,\n onCreateSpace,\n onCreateIdentity,\n onInitialized,\n },\n context,\n );\n\n spaceReady.current.wake(space);\n log.info('inviting', { index });\n } else {\n await initializeClient(client, { createIdentity, onInitialized }, context);\n const space = await spaceReady.current.wait();\n if (space) {\n log.info('joining', { index });\n await Promise.all(performInvitation({ host: space, guest: client.spaces }));\n }\n }\n }\n };\n\n return (\n <ErrorBoundary>\n {Array.from({ length: numClients }).map((_, index) => (\n <MultiClientContext.Provider key={index} value={{ id: index }}>\n <ClientProvider\n services={builder.current.createLocalClientServices()}\n onInitialized={(client) => handleInitialized(client, index)}\n {...props}\n >\n <Story />\n </ClientProvider>\n </MultiClientContext.Provider>\n ))}\n </ErrorBoundary>\n );\n };\n};\n\nconst ErrorBoundary = ({ children }: PropsWithChildren) => {\n const [error, setError] = useState<Error>();\n useEffect(() => {\n const handleError = (event: PromiseRejectionEvent) => {\n setError(event.reason);\n };\n\n window.addEventListener('unhandledrejection', handleError);\n return () => window.removeEventListener('unhandledrejection', handleError);\n }, []);\n\n if (error) {\n return <ErrorFallback error={error} resetErrorBoundary={() => setError(undefined)} />;\n }\n\n return <NaturalErrorBoundary FallbackComponent={ErrorFallback}>{children}</NaturalErrorBoundary>;\n};\n\nconst ErrorFallback = ({ error }: FallbackProps) => {\n const { name, message, stack } =\n error instanceof Error ? error : { name: 'Error', message: String(error), stack: undefined };\n return (\n <div role='alert' className='flex flex-col p-4 gap-4 overflow-auto'>\n <h1 className='text-xl text-red-500'>{name}</h1>\n <div className='text-lg'>{message}</div>\n {stack && <pre className='whitespace-pre-wrap text-sm text-subdued'>{stack}</pre>}\n </div>\n );\n};\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["createContext", "useContext", "raise", "ClientStory", "createContext", "undefined", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nexport * from '@dxos/client/testing';\n\nexport * from './context';\nexport * from './ClientRepeater';\nexport * from './withClientProvider';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { createContext, useContext } from 'react';\n\nimport { type Space, type SpaceId } from '@dxos/client/echo';\nimport { raise } from '@dxos/debug';\n\nexport type ClientStory = {\n index?: number;\n spaceId?: SpaceId;\n space?: Space;\n};\n\nexport const ClientStory = createContext<ClientStory | undefined>(undefined);\n\nexport const useClientStory = (): ClientStory => {\n return useContext(ClientStory) ?? raise(new Error('Missing ClientStory'));\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport React, { type FC, useRef, useState } from 'react';\n\nimport { Client } from '@dxos/client';\nimport { TestBuilder, performInvitation } from '@dxos/client/testing';\nimport { type Type } from '@dxos/echo';\nimport { random } from '@dxos/random';\nimport { useAsyncEffect } from '@dxos/react-hooks';\n\nimport { ClientProvider } from '../client';\nimport { type SpaceId } from '../echo';\nimport { type WithClientProviderProps } from './withClientProvider';\n\nexport type ClientRepeatedComponentProps = { id: number; count: number; spaceId?: SpaceId };\n\nexport type ClientRepeaterControlsProps = { clients: Client[] };\n\n// TODO(burdon): Reconcile with ClientProviderProps.\nexport type ClientRepeaterProps<P extends ClientRepeatedComponentProps> = {\n className?: string;\n component: FC<ClientRepeatedComponentProps>;\n controls?: FC<ClientRepeaterControlsProps>;\n count?: number;\n clients?: Client[];\n types?: Type.AnyObj[];\n args?: Omit<P, 'id' | 'count'>;\n} & Pick<WithClientProviderProps, 'createIdentity' | 'createSpace' | 'onCreateSpace'>;\n\n/**\n * Utility component for Storybook stories which sets up clients for n peers.\n * The `Component` property is rendered n times, once for each peer.\n * @deprecated use `withClientProvider`.\n */\n// TODO(burdon): To discuss: evolve ClientRepeater with optional decorator that uses it.\n// NOTE: This is specifically not a storybook decorator because it broke stories as a decorator.\n// This seems primarily due to the fact that it required top-level await for the clients to initialize.\n// Storybook seemed to handle it alright, but Chromatic had a lot of trouble with it.\n// There was also a question of whether or not calling the story function multiple times was a good idea.\nexport const ClientRepeater = <P extends ClientRepeatedComponentProps>(props: ClientRepeaterProps<P>) => {\n const {\n component: Component,\n controls: Controls,\n count = 1,\n types,\n createIdentity,\n createSpace,\n onCreateSpace,\n } = props;\n\n const [clients, setClients] = useState(props.clients ?? []);\n const [spaceId, setSpaceId] = useState<SpaceId>();\n\n const testBuilder = useRef(new TestBuilder());\n useAsyncEffect(async () => {\n const clients = [...Array(count)].map(\n (_) => new Client({ services: testBuilder.current.createLocalClientServices(), types }),\n );\n\n await Promise.all(clients.map((client) => client.initialize()));\n if (createIdentity || createSpace) {\n await Promise.all(clients.map((client) => client.halo.createIdentity()));\n }\n\n if (createSpace) {\n const client = clients[0];\n const space = await client.spaces.create({ name: random.commerce.productName() });\n setSpaceId(space.id);\n await onCreateSpace?.({ client, space }, {});\n await Promise.all(clients.slice(1).flatMap((client) => performInvitation({ host: space, guest: client.spaces })));\n }\n\n setClients(clients);\n }, []);\n\n if (clients.length === 0) {\n return null;\n }\n\n return (\n <>\n {Controls && <Controls clients={clients} />}\n {clients.map((client, index) => (\n <ClientProvider key={index} client={client}>\n <Component id={index} count={clients.length} spaceId={spaceId} {...{ ...props.args }} />\n </ClientProvider>\n ))}\n </>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Decorator, type StoryContext } from '@storybook/react';\nimport React, { useCallback, useMemo, useRef, useState } from 'react';\n\nimport { Trigger } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { type Space, type SpaceId } from '@dxos/client/echo';\nimport { TestBuilder, performInvitation } from '@dxos/client/testing';\nimport { log } from '@dxos/log';\nimport { ErrorBoundary } from '@dxos/react-ui';\nimport { type MaybePromise } from '@dxos/util';\n\nimport { ClientProvider, type ClientProviderProps } from '../client';\nimport { ClientStory } from './context';\n\ntype InitializeProps = {\n createIdentity?: boolean;\n createSpace?: boolean;\n onInitialized?: (client: Client) => MaybePromise<void>;\n onCreateIdentity?: (props: { client: Client }, context: StoryContext | any) => MaybePromise<void>;\n // NOTE: context must be untyped until ClientRepeater is removed.\n onCreateSpace?: (props: { client: Client; space: Space }, context: StoryContext | any) => MaybePromise<void>;\n};\n\n/**\n * Initialize client, identity and first space.\n */\nconst initializeClient = async (\n client: Client,\n { createIdentity, createSpace, onCreateIdentity, onCreateSpace, onInitialized }: InitializeProps,\n context: StoryContext,\n): Promise<ClientStory> => {\n await onInitialized?.(client);\n\n if (createIdentity || createSpace) {\n if (!client.halo.identity.get()) {\n await client.halo.createIdentity();\n await onCreateIdentity?.({ client }, context);\n }\n }\n\n let space: Space | undefined;\n if (createSpace) {\n space = await client.spaces.create({ name: 'Test Space' });\n await space.waitUntilReady(); // Is this required?\n await onCreateSpace?.({ client, space }, context);\n }\n\n return { space, spaceId: space?.id };\n};\n\nexport type WithClientProviderProps = InitializeProps & Omit<ClientProviderProps, 'onInitialized'>;\n\n/**\n * Decorator that provides the client context.\n */\nexport const withClientProvider = ({\n createIdentity,\n createSpace,\n onCreateSpace,\n onCreateIdentity,\n onInitialized,\n ...props\n}: WithClientProviderProps = {}): Decorator => {\n return (Story, context) => {\n const [data, setData] = useState<ClientStory>({});\n const handleInitialized = async (client: Client) => {\n const data = await initializeClient(\n client,\n {\n createIdentity,\n createSpace,\n onCreateSpace,\n onCreateIdentity,\n onInitialized,\n },\n context,\n );\n\n setData(data);\n };\n\n return (\n <ErrorBoundary name='client-provider'>\n <ClientProvider onInitialized={handleInitialized} {...props}>\n <ClientStory.Provider value={data}>\n <Story />\n </ClientStory.Provider>\n </ClientProvider>\n </ErrorBoundary>\n );\n };\n};\n\n// TODO(burdon): Implement context per client for context.\n// TODO(burdon): Callback once all invitations have completed.\n// TODO(burdon): Delay/jitter for creation of other clients.\nexport type WithMultiClientProviderProps = InitializeProps &\n Omit<ClientProviderProps, 'onInitialized'> & { numClients?: number };\n\n/**\n * Decorator that creates a scaffold for multiple clients.\n * Orchestrates invitations between a randomly selected host and the remaining clients.\n */\nexport const withMultiClientProvider = ({\n numClients = 2,\n createIdentity,\n createSpace,\n onCreateSpace,\n onCreateIdentity,\n onInitialized,\n ...props\n}: WithMultiClientProviderProps): Decorator => {\n return (Story, context) => {\n const spaceReady = useRef(new Trigger<Space | undefined>());\n const [spaceId, setSpaceId] = useState<SpaceId>();\n\n const clients = useMemo(() => {\n const buidler = new TestBuilder();\n return Array.from({ length: numClients }).map(() => {\n return {\n services: buidler.createLocalClientServices(),\n };\n });\n }, [numClients]);\n\n // Handle invitations.\n // NOTE: The zeroth client isn't necessarily the first to be initialized.\n const handleInitialized = useCallback(async (client: Client, index: number) => {\n if (index === 0) {\n // Initialize host.\n const { space } = await initializeClient(\n client,\n {\n createIdentity,\n createSpace,\n onCreateSpace,\n onCreateIdentity,\n onInitialized,\n },\n context,\n );\n\n log.info('inviting', { index, spaceId: space?.id });\n setSpaceId(space?.id);\n spaceReady.current.wake(space);\n } else {\n // Initialize guest.\n await initializeClient(client, { createIdentity, onInitialized }, context);\n\n log.info('waiting', { index });\n const space = await spaceReady.current.wait();\n if (space) {\n log.info('joining', { index, spaceId: space.id });\n await Promise.all(\n performInvitation({\n host: space,\n guest: client.spaces,\n }),\n );\n }\n }\n }, []);\n\n return (\n <div className='absolute inset-0 grid grid-flow-col auto-cols-fr gap-4 overflow-hidden'>\n {clients.map((client, index) => (\n <ClientProvider\n key={index}\n services={client.services}\n onInitialized={(client) => handleInitialized(client, index)}\n {...props}\n >\n <ClientStory.Provider value={{ index, spaceId }}>\n <ErrorBoundary name='client-provider'>\n <Story />\n </ErrorBoundary>\n </ClientStory.Provider>\n </ClientProvider>\n ))}\n </div>\n );\n };\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;AAIA,cAAc;;;ACAd,SAASA,eAAeC,kBAAkB;AAG1C,SAASC,aAAa;AAQf,IAAMC,cAAcC,8BAAuCC,MAAAA;AAE3D,IAAMC,iBAAiB,MAAA;AAC5B,SAAOC,WAAWJ,WAAAA,KAAgBK,MAAM,IAAIC,MAAM,qBAAA,CAAA;AACpD;;;ACfA,OAAOC,SAAkBC,QAAQC,gBAAgB;AAEjD,SAASC,cAAc;AACvB,SAASC,aAAaC,yBAAyB;AAE/C,SAASC,cAAc;AACvB,SAASC,sBAAsB;AA+BxB,IAAMC,iBAAiB,CAAyCC,UAAAA;AACrE,QAAM,EACJC,WAAWC,WACXC,UAAUC,UACVC,QAAQ,GACRC,OACAC,gBACAC,aACAC,cAAa,IACXT;AAEJ,QAAM,CAACU,SAASC,UAAAA,IAAcC,SAASZ,MAAMU,WAAW,CAAA,CAAE;AAC1D,QAAM,CAACG,SAASC,UAAAA,IAAcF,SAAAA;AAE9B,QAAMG,cAAcC,OAA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cAACkC,OAAAA;MAAIC,WAAU;OACZvB,QAAQO,IAAI,CAAC3C,QAAQ+C,UACpB,gBAAAvB,OAAA,cAACE,gBAAAA;MACCkC,KAAKb;MACLH,UAAU5C,OAAO4C;MACjBvC,eAAe,CAACL,YAAWuB,kBAAkBvB,SAAQ+C,KAAAA;MACpD,GAAG7B;OAEJ,gBAAAM,OAAA,cAACG,YAAYC,UAAQ;MAACC,OAAO;QAAEkB;QAAOhC;MAAQ;OAC5C,gBAAAS,OAAA,cAACC,eAAAA;MAAcZ,MAAK;OAClB,gBAAAW,OAAA,cAACL,OAAAA,IAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA;EAOf;AACF;",
|
|
6
|
+
"names": ["createContext", "useContext", "raise", "ClientStory", "createContext", "undefined", "useClientStory", "useContext", "raise", "Error", "React", "useRef", "useState", "Client", "TestBuilder", "performInvitation", "random", "useAsyncEffect", "ClientRepeater", "props", "component", "Component", "controls", "Controls", "count", "types", "createIdentity", "createSpace", "onCreateSpace", "clients", "setClients", "useState", "spaceId", "setSpaceId", "testBuilder", "useRef", "TestBuilder", "useAsyncEffect", "Array", "map", "_", "Client", "services", "current", "createLocalClientServices", "Promise", "all", "client", "initialize", "halo", "space", "spaces", "create", "name", "random", "commerce", "productName", "id", "slice", "flatMap", "performInvitation", "host", "guest", "length", "index", "ClientProvider", "key", "args", "React", "useCallback", "useMemo", "useRef", "useState", "Trigger", "TestBuilder", "performInvitation", "log", "ErrorBoundary", "initializeClient", "client", "createIdentity", "createSpace", "onCreateIdentity", "onCreateSpace", "onInitialized", "context", "halo", "identity", "get", "space", "spaces", "create", "name", "waitUntilReady", "spaceId", "id", "withClientProvider", "props", "Story", "data", "setData", "useState", "handleInitialized", "React", "ErrorBoundary", "ClientProvider", "ClientStory", "Provider", "value", "withMultiClientProvider", "numClients", "spaceReady", "useRef", "Trigger", "setSpaceId", "clients", "useMemo", "buidler", "TestBuilder", "Array", "from", "length", "map", "services", "createLocalClientServices", "useCallback", "index", "log", "info", "current", "wake", "wait", "Promise", "all", "performInvitation", "host", "guest", "div", "className", "key"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/client/context.ts
|
|
4
|
+
import { createContext } from "react";
|
|
5
|
+
var ClientContext = createContext(void 0);
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
ClientContext
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=chunk-373DPHEQ.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/client/context.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport { type Context, createContext } from 'react';\n\nimport { type Client, type SystemStatus } from '@dxos/client';\n\nexport type ClientContextProps = {\n client: Client;\n status?: SystemStatus | null;\n};\n\n/**\n * @internal Use ClientProvider to create or initialize the Client.\n */\nexport const ClientContext: Context<ClientContextProps | undefined> = createContext<ClientContextProps | undefined>(\n undefined,\n);\n"],
|
|
5
|
+
"mappings": ";;;AAIA,SAAuBA,qBAAqB;AAYrC,IAAMC,gBAAyDC,cACpEC,MAAAA;",
|
|
6
|
+
"names": ["createContext", "ClientContext", "createContext", "undefined"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
ClientContext
|
|
4
|
+
} from "./chunk-373DPHEQ.mjs";
|
|
5
|
+
|
|
6
|
+
// src/client/useClient.ts
|
|
7
|
+
import { useContext } from "react";
|
|
8
|
+
import { raise } from "@dxos/debug";
|
|
9
|
+
var useClient = () => {
|
|
10
|
+
const { client } = useContext(ClientContext) ?? raise(new Error("Missing ClientContext."));
|
|
11
|
+
return client;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
useClient
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=chunk-NETTSER2.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/client/useClient.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { useContext } from 'react';\n\nimport { raise } from '@dxos/debug';\n\nimport { ClientContext } from '../client/context';\n\n/**\n * Hook returning instance of DXOS client.\n * Requires ClientContext to be set via ClientProvider.\n */\nexport const useClient = () => {\n const { client } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));\n return client;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;AAIA,SAASA,kBAAkB;AAE3B,SAASC,aAAa;AAQf,IAAMC,YAAY,MAAA;AACvB,QAAM,EAAEC,OAAM,IAAKC,WAAWC,aAAAA,KAAkBC,MAAM,IAAIC,MAAM,wBAAA,CAAA;AAChE,SAAOJ;AACT;",
|
|
6
|
+
"names": ["useContext", "raise", "useClient", "client", "useContext", "ClientContext", "raise", "Error"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
ClientContext
|
|
4
|
+
} from "./chunk-373DPHEQ.mjs";
|
|
5
|
+
|
|
6
|
+
// src/client/ClientProvider.tsx
|
|
7
|
+
import React, { forwardRef, useEffect, useImperativeHandle, useState } from "react";
|
|
8
|
+
import { Client, SystemStatus } from "@dxos/client";
|
|
9
|
+
import { log } from "@dxos/log";
|
|
10
|
+
import { useAsyncEffect, useControlledState } from "@dxos/react-hooks";
|
|
11
|
+
import { getAsyncProviderValue } from "@dxos/util";
|
|
12
|
+
|
|
13
|
+
// src/banner.ts
|
|
14
|
+
var BANNER = (client) => {
|
|
15
|
+
const commitHash = client.config.get("runtime.app.build.commitHash");
|
|
16
|
+
const hash = commitHash ? ` App Commit ${commitHash}
|
|
17
|
+
` : "";
|
|
18
|
+
return `
|
|
19
|
+
_/\\/\\/\\/\\/\\____/\\/\\____/\\/\\____/\\/\\/\\/\\______/\\/\\/\\/\\/\\_
|
|
20
|
+
_/\\/\\____/\\/\\____/\\/\\/\\/\\____/\\/\\____/\\/\\__/\\/\\_________
|
|
21
|
+
_/\\/\\____/\\/\\______/\\/\\______/\\/\\____/\\/\\____/\\/\\/\\/\\___
|
|
22
|
+
_/\\/\\____/\\/\\____/\\/\\/\\/\\____/\\/\\____/\\/\\__________/\\/\\_
|
|
23
|
+
_/\\/\\/\\/\\/\\____/\\/\\____/\\/\\____/\\/\\/\\/\\____/\\/\\/\\/\\/\\___
|
|
24
|
+
|
|
25
|
+
DXOS Client ${client.version}
|
|
26
|
+
${hash}`;
|
|
27
|
+
};
|
|
28
|
+
var bannerPrinted = false;
|
|
29
|
+
var printBanner = (client) => {
|
|
30
|
+
if (bannerPrinted || window.location.hostname === "localhost") {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
bannerPrinted = true;
|
|
34
|
+
console.log(`%c${BANNER(client)}`, "font-family: monospace;");
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// src/client/ClientProvider.tsx
|
|
38
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/react-client/src/client/ClientProvider.tsx";
|
|
39
|
+
var ClientProvider = /* @__PURE__ */ forwardRef(({ children, config: configProp, client: clientProp, services: servicesProp, status: statusProp, fallback: Fallback = () => null, noBanner, onInitialized, ...options }, forwardedRef) => {
|
|
40
|
+
const [error, setError] = useState();
|
|
41
|
+
if (error) {
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
const [client, setClient] = useState(clientProp instanceof Client ? clientProp : void 0);
|
|
45
|
+
useImperativeHandle(forwardedRef, () => client, [
|
|
46
|
+
client
|
|
47
|
+
]);
|
|
48
|
+
const [status, setStatus] = useControlledState(statusProp);
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (!client) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const subscription = client.status.subscribe((status2) => setStatus(status2));
|
|
54
|
+
return () => subscription.unsubscribe();
|
|
55
|
+
}, [
|
|
56
|
+
client
|
|
57
|
+
]);
|
|
58
|
+
useAsyncEffect(async () => {
|
|
59
|
+
let disposed = false;
|
|
60
|
+
const initialize = async (client3) => {
|
|
61
|
+
if (!client3.initialized) {
|
|
62
|
+
await client3.initialize().catch((err) => {
|
|
63
|
+
if (!disposed) {
|
|
64
|
+
setError(err);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
log("client ready", void 0, {
|
|
68
|
+
F: __dxlog_file,
|
|
69
|
+
L: 123,
|
|
70
|
+
S: void 0,
|
|
71
|
+
C: (f, a) => f(...a)
|
|
72
|
+
});
|
|
73
|
+
await onInitialized?.(client3);
|
|
74
|
+
log("initialization complete", void 0, {
|
|
75
|
+
F: __dxlog_file,
|
|
76
|
+
L: 125,
|
|
77
|
+
S: void 0,
|
|
78
|
+
C: (f, a) => f(...a)
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
setClient(client3);
|
|
82
|
+
if (!noBanner) {
|
|
83
|
+
printBanner(client3);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
let client2;
|
|
87
|
+
try {
|
|
88
|
+
if (clientProp) {
|
|
89
|
+
client2 = await getAsyncProviderValue(clientProp);
|
|
90
|
+
await initialize(client2);
|
|
91
|
+
} else {
|
|
92
|
+
const config = await getAsyncProviderValue(configProp);
|
|
93
|
+
log("resolved config", {
|
|
94
|
+
config
|
|
95
|
+
}, {
|
|
96
|
+
F: __dxlog_file,
|
|
97
|
+
L: 143,
|
|
98
|
+
S: void 0,
|
|
99
|
+
C: (f, a) => f(...a)
|
|
100
|
+
});
|
|
101
|
+
const services = await getAsyncProviderValue(servicesProp, config);
|
|
102
|
+
log("created services", {
|
|
103
|
+
services
|
|
104
|
+
}, {
|
|
105
|
+
F: __dxlog_file,
|
|
106
|
+
L: 145,
|
|
107
|
+
S: void 0,
|
|
108
|
+
C: (f, a) => f(...a)
|
|
109
|
+
});
|
|
110
|
+
client2 = new Client({
|
|
111
|
+
config,
|
|
112
|
+
services,
|
|
113
|
+
...options
|
|
114
|
+
});
|
|
115
|
+
log("created client", void 0, {
|
|
116
|
+
F: __dxlog_file,
|
|
117
|
+
L: 147,
|
|
118
|
+
S: void 0,
|
|
119
|
+
C: (f, a) => f(...a)
|
|
120
|
+
});
|
|
121
|
+
await initialize(client2);
|
|
122
|
+
}
|
|
123
|
+
} catch (err) {
|
|
124
|
+
if (!disposed) {
|
|
125
|
+
log.catch(err, void 0, {
|
|
126
|
+
F: __dxlog_file,
|
|
127
|
+
L: 152,
|
|
128
|
+
S: void 0,
|
|
129
|
+
C: (f, a) => f(...a)
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return () => {
|
|
134
|
+
log("clean up", void 0, {
|
|
135
|
+
F: __dxlog_file,
|
|
136
|
+
L: 157,
|
|
137
|
+
S: void 0,
|
|
138
|
+
C: (f, a) => f(...a)
|
|
139
|
+
});
|
|
140
|
+
disposed = true;
|
|
141
|
+
if (!clientProp) {
|
|
142
|
+
void client2?.destroy().then(() => {
|
|
143
|
+
log("destroyed", void 0, {
|
|
144
|
+
F: __dxlog_file,
|
|
145
|
+
L: 164,
|
|
146
|
+
S: void 0,
|
|
147
|
+
C: (f, a) => f(...a)
|
|
148
|
+
});
|
|
149
|
+
}).catch((err) => log.catch(err, void 0, {
|
|
150
|
+
F: __dxlog_file,
|
|
151
|
+
L: 166,
|
|
152
|
+
S: void 0,
|
|
153
|
+
C: (f, a) => f(...a)
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}, [
|
|
158
|
+
configProp,
|
|
159
|
+
clientProp,
|
|
160
|
+
servicesProp,
|
|
161
|
+
noBanner
|
|
162
|
+
]);
|
|
163
|
+
if (!client?.initialized || status !== SystemStatus.ACTIVE) {
|
|
164
|
+
return /* @__PURE__ */ React.createElement(Fallback, {
|
|
165
|
+
client,
|
|
166
|
+
status
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return /* @__PURE__ */ React.createElement(ClientContext.Provider, {
|
|
170
|
+
value: {
|
|
171
|
+
client,
|
|
172
|
+
status
|
|
173
|
+
}
|
|
174
|
+
}, children);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
export {
|
|
178
|
+
ClientProvider
|
|
179
|
+
};
|
|
180
|
+
//# sourceMappingURL=chunk-VSA674XR.mjs.map
|