@dxos/react-client 0.8.4-main.f5c0578 → 0.8.4-main.fcfe5033a5
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 +9 -0
- package/.storybook/preview.mts +8 -0
- package/.swc/plugins/linux_x86_64_19.0.0/727453fb3a62f7f1d952a41e051ca8a6f88cadc45cee43c6a4d1aa45f9b75665.wasmer-v7 +0 -0
- package/dist/lib/browser/chunk-BVDNYEYI.mjs +179 -0
- package/dist/lib/browser/chunk-BVDNYEYI.mjs.map +7 -0
- package/dist/lib/browser/{chunk-BXOLJYAY.mjs → chunk-LO3TU5CK.mjs} +4 -4
- package/dist/lib/browser/chunk-LO3TU5CK.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 +58 -121
- package/dist/lib/browser/echo/index.mjs.map +4 -4
- package/dist/lib/browser/halo/index.mjs +4 -4
- package/dist/lib/browser/halo/index.mjs.map +2 -2
- package/dist/lib/browser/index.mjs +114 -12
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/invitations/index.mjs +1 -1
- 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 +121 -149
- 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-256IHY6F.mjs → chunk-AQJH2UNZ.mjs} +4 -4
- package/dist/lib/node-esm/chunk-AQJH2UNZ.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 +58 -121
- package/dist/lib/node-esm/echo/index.mjs.map +4 -4
- package/dist/lib/node-esm/halo/index.mjs +4 -4
- package/dist/lib/node-esm/halo/index.mjs.map +2 -2
- package/dist/lib/node-esm/index.mjs +114 -12
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/invitations/index.mjs +1 -1
- 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 +121 -149
- 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/useSubscription.d.ts +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 +5 -5
- package/dist/types/src/halo/Passkey.stories.d.ts.map +1 -1
- package/dist/types/src/invitations/useInvitationStatus.d.ts +1 -1
- package/dist/types/src/invitations/useInvitationStatus.d.ts.map +1 -1
- package/dist/types/src/testing/ClientRepeater.d.ts +6 -5
- package/dist/types/src/testing/ClientRepeater.d.ts.map +1 -1
- package/dist/types/src/testing/ClientRepeater.stories.d.ts +6 -10
- 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 +5 -9
- package/dist/types/src/testing/withClientProvider.d.ts.map +1 -1
- package/dist/types/src/testing/withClientProvider.stories.d.ts +8 -9
- 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 +3 -2
- package/package.json +35 -33
- package/src/client/ClientProvider.test.tsx +0 -1
- package/src/client/ClientProvider.tsx +29 -48
- 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 -4
- 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 +31 -30
- package/src/echo/useSubscription.ts +1 -1
- package/src/echo/useSyncState.ts +4 -3
- package/src/halo/Passkey.stories.tsx +15 -14
- package/src/halo/useDevices.test.tsx +0 -1
- package/src/invitations/useInvitationStatus.ts +9 -8
- package/src/testing/ClientRepeater.stories.tsx +19 -12
- package/src/testing/ClientRepeater.tsx +31 -40
- package/src/testing/context.tsx +4 -3
- package/src/testing/util.tsx +0 -1
- package/src/testing/withClientProvider.stories.tsx +30 -17
- package/src/testing/withClientProvider.tsx +74 -92
- package/tsconfig.json +3 -6
- package/typedoc.json +1 -1
- package/vitest.config.ts +10 -16
- package/.swc/plugins/v7_linux_x86_64_13.0.0/c614d7475354583212fbd7669acbae95b9832c305bf51bdaabe2e6de05abb6bf +0 -0
- package/dist/lib/browser/chunk-BXOLJYAY.mjs.map +0 -7
- package/dist/lib/browser/chunk-FQAPI3I4.mjs +0 -312
- package/dist/lib/browser/chunk-FQAPI3I4.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-256IHY6F.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-MNTJNI2M.mjs +0 -314
- package/dist/lib/node-esm/chunk-MNTJNI2M.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 -56
- package/src/echo/useSchema.ts +0 -54
- package/src/playwright/playwright.config.ts +0 -17
- package/src/playwright/smoke.spec.ts +0 -24
|
@@ -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
|
|
@@ -0,0 +1,7 @@
|
|
|
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';\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;;;;ADuCO,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,QAAAA,IAAYC,S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,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 +1,8 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
useClient
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-NETTSER2.mjs";
|
|
5
|
+
import "../chunk-373DPHEQ.mjs";
|
|
5
6
|
|
|
6
7
|
// src/devtools/index.ts
|
|
7
8
|
export * from "@dxos/client/devtools";
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/devtools/index.ts", "../../../../src/devtools/useDevtools.ts", "../../../../src/devtools/useStream.ts"],
|
|
4
4
|
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nexport * from '@dxos/client/devtools';\n\nexport * from './useDevtools';\nexport * from './useStream';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type DevtoolsHost } from '@dxos/client/devtools';\nimport { raise } from '@dxos/debug';\n\nimport { useClient } from '../client';\n\nexport const useDevtools = (): DevtoolsHost => {\n const client = useClient();\n return client.services.services.DevtoolsHost ?? raise(new Error('DevtoolsHost not available.'));\n};\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { type DependencyList, useEffect, useState } from 'react';\n\nimport { type Stream } from '@dxos/codec-protobuf/stream';\nimport { log } from '@dxos/log';\n\n/**\n * Subscribe to service API streams.\n */\nexport const useStream = <T>(streamFactory: () => Stream<T>, defaultValue: T, deps: DependencyList = []): T => {\n const [value, setValue] = useState<T | undefined>(defaultValue);\n useEffect(() => {\n const stream = streamFactory();\n stream.subscribe(\n (response: T) => setValue(response),\n (err) => {\n if (err) {\n log.catch(err);\n }\n },\n );\n\n return () => {\n void stream.close();\n };\n }, deps);\n\n return value ?? defaultValue;\n};\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;AAIA,cAAc;;;ACCd,SAASA,aAAa;AAIf,IAAMC,cAAc,MAAA;AACzB,QAAMC,SAASC,UAAAA;AACf,SAAOD,OAAOE,SAASA,SAASC,gBAAgBC,MAAM,IAAIC,MAAM,6BAAA,CAAA;AAClE;;;ACRA,SAA8BC,WAAWC,gBAAgB;AAGzD,SAASC,WAAW;;AAKb,IAAMC,YAAY,CAAIC,eAAgCC,cAAiBC,OAAuB,CAAA,MAAE;AACrG,QAAM,CAACC,OAAOC,QAAAA,IAAYP,SAAwBI,YAAAA;AAClDL,YAAU,MAAA;AACR,UAAMS,SAASL,cAAAA;AACfK,WAAOC,UACL,CAACC,aAAgBH,SAASG,QAAAA,GAC1B,CAACC,QAAAA;AACC,UAAIA,KAAK;AACPV,YAAIW,MAAMD,KAAAA,QAAAA;;;;;;MACZ;IACF,CAAA;AAGF,WAAO,MAAA;AACL,WAAKH,OAAOK,MAAK;IACnB;EACF,GAAGR,IAAAA;AAEH,SAAOC,SAASF;AAClB;",
|
|
6
6
|
"names": ["raise", "useDevtools", "client", "useClient", "services", "DevtoolsHost", "raise", "Error", "useEffect", "useState", "log", "useStream", "streamFactory", "defaultValue", "deps", "value", "setValue", "stream", "subscribe", "response", "err", "catch", "close"]
|
|
7
7
|
}
|
|
@@ -1,46 +1,42 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
useInvitationStatus
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-AQJH2UNZ.mjs";
|
|
5
5
|
import {
|
|
6
6
|
useClient
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-NETTSER2.mjs";
|
|
8
|
+
import "../chunk-373DPHEQ.mjs";
|
|
8
9
|
|
|
9
10
|
// src/echo/index.ts
|
|
10
11
|
export * from "@dxos/client/echo";
|
|
12
|
+
export * from "@dxos/echo-react";
|
|
11
13
|
|
|
12
14
|
// src/echo/useMembers.ts
|
|
13
15
|
import { MulticastObservable } from "@dxos/async";
|
|
16
|
+
import { PublicKey as PublicKey2 } from "@dxos/client";
|
|
14
17
|
import { HaloSpaceMember } from "@dxos/client/echo";
|
|
15
18
|
import { useMulticastObservable as useMulticastObservable2 } from "@dxos/react-hooks";
|
|
16
19
|
|
|
17
20
|
// src/echo/useSpaces.ts
|
|
18
|
-
import {
|
|
21
|
+
import { PublicKey } from "@dxos/client";
|
|
19
22
|
import { SpaceState } from "@dxos/client/echo";
|
|
20
23
|
import { useMulticastObservable } from "@dxos/react-hooks";
|
|
21
|
-
var useSpace = (
|
|
24
|
+
var useSpace = (spaceId) => {
|
|
22
25
|
const client = useClient();
|
|
23
26
|
const spaces = useMulticastObservable(client.spaces);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (spaceKeyLike) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const timeout = setTimeout(async () => {
|
|
30
|
-
await client.spaces.waitUntilReady();
|
|
31
|
-
setReady(true);
|
|
32
|
-
});
|
|
33
|
-
return () => clearTimeout(timeout);
|
|
34
|
-
}, [
|
|
35
|
-
client,
|
|
36
|
-
spaceKeyLike
|
|
37
|
-
]);
|
|
38
|
-
if (spaceKeyLike) {
|
|
39
|
-
return spaces.find((space) => space.key.equals(spaceKeyLike) || space.id === spaceKeyLike);
|
|
40
|
-
}
|
|
41
|
-
if (ready && client.halo.identity.get()) {
|
|
42
|
-
return client.spaces.default;
|
|
27
|
+
if (!spaceId) {
|
|
28
|
+
return void 0;
|
|
43
29
|
}
|
|
30
|
+
return spaces.find((space) => {
|
|
31
|
+
if (spaceId instanceof PublicKey) {
|
|
32
|
+
return space.key.equals(spaceId);
|
|
33
|
+
}
|
|
34
|
+
return space.id === spaceId;
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
var useDatabase = (spaceId) => {
|
|
38
|
+
const space = useSpace(spaceId);
|
|
39
|
+
return space?.db;
|
|
44
40
|
};
|
|
45
41
|
var useSpaces = ({ all = false } = {}) => {
|
|
46
42
|
const client = useClient();
|
|
@@ -53,50 +49,19 @@ var useMembers = (spaceKey) => {
|
|
|
53
49
|
const spaces = useSpaces({
|
|
54
50
|
all: true
|
|
55
51
|
});
|
|
56
|
-
const space = spaceKey ? spaces.find((space2) => space2.key.equals(spaceKey)) : void 0;
|
|
52
|
+
const space = spaceKey ? spaces.find((space2) => spaceKey instanceof PublicKey2 ? space2.key.equals(spaceKey) : space2.id === spaceKey) : void 0;
|
|
57
53
|
const members = useMulticastObservable2(space?.members ?? MulticastObservable.empty()) ?? [];
|
|
58
54
|
return members.filter((member) => member.role !== HaloSpaceMember.Role.REMOVED);
|
|
59
55
|
};
|
|
60
56
|
|
|
61
|
-
// src/echo/useQuery.ts
|
|
62
|
-
import { useMemo, useSyncExternalStore } from "react";
|
|
63
|
-
import { Filter, Query, isSpace } from "@dxos/client/echo";
|
|
64
|
-
var EMPTY_ARRAY = [];
|
|
65
|
-
var noop = () => {
|
|
66
|
-
};
|
|
67
|
-
var useQuery = (spaceOrEcho, queryOrFilter, deps) => {
|
|
68
|
-
const query = Filter.is(queryOrFilter) ? Query.select(queryOrFilter) : queryOrFilter;
|
|
69
|
-
const { getObjects, subscribe } = useMemo(() => {
|
|
70
|
-
let subscribed = false;
|
|
71
|
-
const queryResult = spaceOrEcho === void 0 ? void 0 : isSpace(spaceOrEcho) ? spaceOrEcho.db.query(query) : spaceOrEcho.query(query);
|
|
72
|
-
return {
|
|
73
|
-
getObjects: () => subscribed && queryResult ? queryResult.objects : EMPTY_ARRAY,
|
|
74
|
-
subscribe: (cb) => {
|
|
75
|
-
subscribed = true;
|
|
76
|
-
const unsubscribe = queryResult?.subscribe(cb) ?? noop;
|
|
77
|
-
return () => {
|
|
78
|
-
unsubscribe?.();
|
|
79
|
-
subscribed = false;
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}, [
|
|
84
|
-
spaceOrEcho,
|
|
85
|
-
JSON.stringify(query.ast),
|
|
86
|
-
...deps ?? []
|
|
87
|
-
]);
|
|
88
|
-
const objects = useSyncExternalStore(subscribe, getObjects);
|
|
89
|
-
return objects ?? [];
|
|
90
|
-
};
|
|
91
|
-
|
|
92
57
|
// src/echo/useQueue.ts
|
|
93
|
-
import { useEffect
|
|
58
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
94
59
|
import { raise } from "@dxos/debug";
|
|
95
60
|
var MIN_POLL_INTERVAL = 1e3;
|
|
96
61
|
var useQueue = (queueDxn, options = {}) => {
|
|
97
62
|
const client = useClient();
|
|
98
63
|
const mountedRef = useRef(true);
|
|
99
|
-
const queue =
|
|
64
|
+
const queue = useMemo(() => {
|
|
100
65
|
if (!queueDxn) {
|
|
101
66
|
return void 0;
|
|
102
67
|
}
|
|
@@ -106,12 +71,12 @@ var useQueue = (queueDxn, options = {}) => {
|
|
|
106
71
|
client,
|
|
107
72
|
queueDxn?.toString()
|
|
108
73
|
]);
|
|
109
|
-
|
|
74
|
+
useEffect(() => {
|
|
110
75
|
void queue?.refresh();
|
|
111
76
|
}, [
|
|
112
77
|
queue
|
|
113
78
|
]);
|
|
114
|
-
|
|
79
|
+
useEffect(() => {
|
|
115
80
|
let timeout;
|
|
116
81
|
mountedRef.current = true;
|
|
117
82
|
const poll = () => {
|
|
@@ -138,71 +103,42 @@ var useQueue = (queueDxn, options = {}) => {
|
|
|
138
103
|
return queue;
|
|
139
104
|
};
|
|
140
105
|
|
|
141
|
-
// src/echo/useSchema.ts
|
|
142
|
-
import { useMemo as useMemo3, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
143
|
-
var useSchema = (client, space, typename) => {
|
|
144
|
-
const { subscribe, getSchema } = useMemo3(() => {
|
|
145
|
-
if (!typename || !space) {
|
|
146
|
-
return {
|
|
147
|
-
subscribe: () => () => {
|
|
148
|
-
},
|
|
149
|
-
getSchema: () => void 0
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
const staticSchema = client.graph.schemaRegistry.getSchema(typename);
|
|
153
|
-
if (staticSchema) {
|
|
154
|
-
return {
|
|
155
|
-
subscribe: () => () => {
|
|
156
|
-
},
|
|
157
|
-
getSchema: () => staticSchema
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
const query = space.db.schemaRegistry.query({
|
|
161
|
-
typename
|
|
162
|
-
});
|
|
163
|
-
const initialResult = query.runSync()[0];
|
|
164
|
-
let currentSchema = initialResult;
|
|
165
|
-
return {
|
|
166
|
-
subscribe: (onStoreChange) => {
|
|
167
|
-
const unsubscribe = query.subscribe(() => {
|
|
168
|
-
currentSchema = query.results[0];
|
|
169
|
-
onStoreChange();
|
|
170
|
-
});
|
|
171
|
-
return unsubscribe;
|
|
172
|
-
},
|
|
173
|
-
getSchema: () => currentSchema
|
|
174
|
-
};
|
|
175
|
-
}, [
|
|
176
|
-
typename,
|
|
177
|
-
space
|
|
178
|
-
]);
|
|
179
|
-
return useSyncExternalStore2(subscribe, getSchema);
|
|
180
|
-
};
|
|
181
|
-
|
|
182
106
|
// src/echo/useSpaceInvitations.ts
|
|
183
|
-
import { useMemo as
|
|
107
|
+
import { useMemo as useMemo2 } from "react";
|
|
184
108
|
import { MulticastObservable as MulticastObservable2 } from "@dxos/async";
|
|
185
109
|
import { useMulticastObservable as useMulticastObservable3 } from "@dxos/react-hooks";
|
|
186
|
-
var useSpaceInvitations = (
|
|
187
|
-
const space = useSpace(
|
|
110
|
+
var useSpaceInvitations = (spaceId) => {
|
|
111
|
+
const space = useSpace(spaceId);
|
|
188
112
|
return useMulticastObservable3(space?.invitations ?? MulticastObservable2.empty()) ?? [];
|
|
189
113
|
};
|
|
190
|
-
var useSpaceInvitation = (
|
|
191
|
-
const invitations = useSpaceInvitations(
|
|
192
|
-
const invitation =
|
|
114
|
+
var useSpaceInvitation = (spaceId, invitationId) => {
|
|
115
|
+
const invitations = useSpaceInvitations(spaceId);
|
|
116
|
+
const invitation = useMemo2(() => invitations.find((invitation2) => invitation2.get().invitationId === invitationId), [
|
|
193
117
|
invitations
|
|
194
118
|
]);
|
|
195
119
|
return useInvitationStatus(invitation);
|
|
196
120
|
};
|
|
197
121
|
|
|
122
|
+
// src/echo/useSpaceProperties.ts
|
|
123
|
+
import { MulticastObservable as MulticastObservable3 } from "@dxos/async";
|
|
124
|
+
import { SpaceState as SpaceState2 } from "@dxos/client/echo";
|
|
125
|
+
import { useObject } from "@dxos/echo-react";
|
|
126
|
+
import { useMulticastObservable as useMulticastObservable4 } from "@dxos/react-hooks";
|
|
127
|
+
var useSpaceProperties = (spaceId) => {
|
|
128
|
+
const space = useSpace(spaceId);
|
|
129
|
+
const spaceState = useMulticastObservable4(space?.state ?? MulticastObservable3.empty());
|
|
130
|
+
const properties = spaceState === SpaceState2.SPACE_READY ? space?.properties : void 0;
|
|
131
|
+
return useObject(properties);
|
|
132
|
+
};
|
|
133
|
+
|
|
198
134
|
// src/echo/useSubscription.ts
|
|
199
|
-
import { useEffect as
|
|
135
|
+
import { useEffect as useEffect2, useRef as useRef2 } from "react";
|
|
200
136
|
import { createSubscription } from "@dxos/client/echo";
|
|
201
137
|
var useSubscription = (cb, selection) => {
|
|
202
138
|
const callbackRef = useRef2(cb);
|
|
203
139
|
callbackRef.current = cb;
|
|
204
|
-
const subscriptionRef = useRef2();
|
|
205
|
-
|
|
140
|
+
const subscriptionRef = useRef2(null);
|
|
141
|
+
useEffect2(() => {
|
|
206
142
|
subscriptionRef.current = createSubscription(() => {
|
|
207
143
|
callbackRef.current();
|
|
208
144
|
});
|
|
@@ -213,25 +149,26 @@ var useSubscription = (cb, selection) => {
|
|
|
213
149
|
};
|
|
214
150
|
|
|
215
151
|
// src/echo/useSyncState.ts
|
|
216
|
-
import { useEffect as
|
|
152
|
+
import { useEffect as useEffect3, useState } from "react";
|
|
217
153
|
import { Context } from "@dxos/context";
|
|
218
154
|
import { EdgeService } from "@dxos/protocols";
|
|
155
|
+
import { compositeKey } from "@dxos/util";
|
|
219
156
|
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/react-client/src/echo/useSyncState.ts";
|
|
220
|
-
var isEdgePeerId = (peerId, spaceId) => peerId.startsWith(
|
|
157
|
+
var isEdgePeerId = (peerId, spaceId) => peerId.startsWith(compositeKey(EdgeService.AUTOMERGE_REPLICATOR, spaceId));
|
|
221
158
|
var useSyncState = () => {
|
|
222
159
|
const client = useClient();
|
|
223
|
-
const [spaceState, setSpaceState] =
|
|
224
|
-
|
|
160
|
+
const [spaceState, setSpaceState] = useState({});
|
|
161
|
+
useEffect3(() => {
|
|
225
162
|
const ctx = new Context(void 0, {
|
|
226
163
|
F: __dxlog_file,
|
|
227
|
-
L:
|
|
164
|
+
L: 26
|
|
228
165
|
});
|
|
229
166
|
const createSubscriptions = (spaces) => {
|
|
230
167
|
for (const space of spaces) {
|
|
231
168
|
if (spaceState[space.id]) {
|
|
232
169
|
continue;
|
|
233
170
|
}
|
|
234
|
-
ctx.onDispose(space.db.subscribeToSyncState(ctx, ({ peers = [] }) => {
|
|
171
|
+
ctx.onDispose(space.internal.db.subscribeToSyncState(ctx, ({ peers = [] }) => {
|
|
235
172
|
const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));
|
|
236
173
|
if (syncState) {
|
|
237
174
|
setSpaceState((spaceState2) => ({
|
|
@@ -255,13 +192,13 @@ var useSyncState = () => {
|
|
|
255
192
|
return spaceState;
|
|
256
193
|
};
|
|
257
194
|
var useSpaceSyncState = (space) => {
|
|
258
|
-
const [spaceState, setSpaceState] =
|
|
259
|
-
|
|
195
|
+
const [spaceState, setSpaceState] = useState();
|
|
196
|
+
useEffect3(() => {
|
|
260
197
|
const ctx = new Context(void 0, {
|
|
261
198
|
F: __dxlog_file,
|
|
262
|
-
L:
|
|
199
|
+
L: 65
|
|
263
200
|
});
|
|
264
|
-
space.db.subscribeToSyncState(ctx, ({ peers = [] }) => {
|
|
201
|
+
space.internal.db.subscribeToSyncState(ctx, ({ peers = [] }) => {
|
|
265
202
|
const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));
|
|
266
203
|
if (syncState) {
|
|
267
204
|
setSpaceState(syncState);
|
|
@@ -276,13 +213,13 @@ var useSpaceSyncState = (space) => {
|
|
|
276
213
|
return spaceState;
|
|
277
214
|
};
|
|
278
215
|
export {
|
|
216
|
+
useDatabase,
|
|
279
217
|
useMembers,
|
|
280
|
-
useQuery,
|
|
281
218
|
useQueue,
|
|
282
|
-
useSchema,
|
|
283
219
|
useSpace,
|
|
284
220
|
useSpaceInvitation,
|
|
285
221
|
useSpaceInvitations,
|
|
222
|
+
useSpaceProperties,
|
|
286
223
|
useSpaceSyncState,
|
|
287
224
|
useSpaces,
|
|
288
225
|
useSubscription,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/echo/index.ts", "../../../../src/echo/useMembers.ts", "../../../../src/echo/useSpaces.ts", "../../../../src/echo/
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nexport * from '@dxos/client/echo';\n\nexport * from './useMembers';\nexport * from './useQuery';\nexport * from './useQueue';\nexport * from './useSchema';\nexport * from './useSpaces';\nexport * from './useSpaceInvitations';\nexport * from './useSubscription';\nexport * from './useSyncState';\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { MulticastObservable } from '@dxos/async';\nimport { type PublicKey } from '@dxos/client';\nimport { HaloSpaceMember, type SpaceMember } from '@dxos/client/echo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useSpaces } from './useSpaces';\n\nexport const useMembers = (spaceKey: PublicKey | undefined): SpaceMember[] => {\n // TODO(dmaretskyi): useSpace hook for spaces that are not ready.\n const spaces = useSpaces({ all: true });\n const space = spaceKey ? spaces.find((space) => space.key.equals(spaceKey)) : undefined;\n\n // EMPTY_OBSERVABLE needs to be a stable reference to avoid re-subscribing on every render.\n const members = useMulticastObservable(space?.members ?? MulticastObservable.empty()) ?? [];\n return members.filter((member) => member.role !== HaloSpaceMember.Role.REMOVED);\n};\n", "//\n// Copyright 2020 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type PublicKeyLike } from '@dxos/client';\nimport { type Space, SpaceState } from '@dxos/client/echo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client';\n\n/**\n * Get a specific Space using its key.\n * The space is not guaranteed to be in the ready state.\n * Returns the default space if no key is provided.\n * Requires a ClientProvider somewhere in the parent tree.\n *\n * @param spaceKeyLike the key of the space to look for\n */\nexport const useSpace = (spaceKeyLike?: PublicKeyLike): Space | undefined => {\n const client = useClient();\n const spaces = useMulticastObservable<Space[]>(client.spaces);\n const [ready, setReady] = useState(false);\n\n useEffect(() => {\n // Only wait for ready if looking for the default space.\n if (spaceKeyLike) {\n return;\n }\n\n const timeout = setTimeout(async () => {\n await client.spaces.waitUntilReady();\n setReady(true);\n });\n\n return () => clearTimeout(timeout);\n }, [client, spaceKeyLike]);\n\n if (spaceKeyLike) {\n return spaces.find((space) => space.key.equals(spaceKeyLike) || space.id === spaceKeyLike);\n }\n\n if (ready && client.halo.identity.get()) {\n return client.spaces.default;\n }\n};\n\nexport type UseSpacesParams = {\n /**\n * Return uninitialized spaces as well.\n */\n all?: boolean;\n};\n\n/**\n * Get all Spaces available to current user.\n * Requires a ClientProvider somewhere in the parent tree.\n * By default, only ready spaces are returned.\n * @returns an array of Spaces\n */\nexport const useSpaces = ({ all = false }: UseSpacesParams = {}): Space[] => {\n const client = useClient();\n const spaces = useMulticastObservable<Space[]>(client.spaces);\n\n // TODO(dmaretskyi): Array reference equality.\n return spaces.filter((space) => all || space.state.get() === SpaceState.SPACE_READY);\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { useMemo, useSyncExternalStore } from 'react';\n\nimport { type Echo, Filter, type Live, Query, type Space, isSpace } from '@dxos/client/echo';\n\nconst EMPTY_ARRAY: never[] = [];\n\nconst noop = () => {};\n\n// TODO(dmaretskyi): Queries are fully serializable, so we can remove `deps` argument.\ninterface UseQueryFn {\n <Q extends Query.Any>(spaceOrEcho: Space | Echo | undefined, query: Q, deps?: any[]): Live<Query.Type<Q>>[];\n\n <F extends Filter.Any>(spaceOrEcho: Space | Echo | undefined, filter: F, deps?: any[]): Live<Filter.Type<F>>[];\n}\n\n/**\n * Create subscription.\n */\nexport const useQuery: UseQueryFn = (\n spaceOrEcho: Space | Echo | undefined,\n queryOrFilter: Query.Any | Filter.Any,\n deps?: any[],\n): Live<unknown>[] => {\n const query = Filter.is(queryOrFilter) ? Query.select(queryOrFilter) : queryOrFilter;\n\n const { getObjects, subscribe } = useMemo(() => {\n let subscribed = false;\n const queryResult =\n spaceOrEcho === undefined\n ? undefined\n : isSpace(spaceOrEcho)\n ? spaceOrEcho.db.query(query)\n : spaceOrEcho.query(query);\n\n return {\n getObjects: () => (subscribed && queryResult ? queryResult.objects : EMPTY_ARRAY),\n subscribe: (cb: () => void) => {\n subscribed = true;\n const unsubscribe = queryResult?.subscribe(cb) ?? noop;\n return () => {\n unsubscribe?.();\n subscribed = false;\n };\n },\n };\n }, [spaceOrEcho, JSON.stringify(query.ast), ...(deps ?? [])]);\n\n // https://beta.reactjs.org/reference/react/useSyncExternalStore\n // NOTE: This hook will resubscribe whenever the callback passed to the first argument changes; make sure it is stable.\n const objects = useSyncExternalStore<Live<unknown>[] | undefined>(subscribe, getObjects);\n return objects ?? [];\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect, useMemo, useRef } from 'react';\n\nimport { type Queue } from '@dxos/client/echo';\nimport { raise } from '@dxos/debug';\nimport { type Obj, type Relation } from '@dxos/echo';\nimport { type DXN } from '@dxos/keys';\n\nimport { useClient } from '../client';\n\nconst MIN_POLL_INTERVAL = 1_000;\n\nexport type UseQueueOptions = {\n pollInterval?: number;\n};\n\n/**\n * Polls the given Edge queue.\n */\n// TODO(burdon): Replace polling with socket?\n// TODO(dmaretskyi): Move into client package.\n// TODO(dmaretskyi): Consider passing the space into the hook to support queue DXNs without space id.\n// TODO(ZaymonFC): If queue is unchanged returned object should be refferentially stable on poll.\nexport const useQueue = <T extends Obj.Any | Relation.Any>(\n queueDxn?: DXN,\n options: UseQueueOptions = {},\n): Queue<T> | undefined => {\n const client = useClient();\n const mountedRef = useRef(true);\n\n const queue = useMemo<Queue<T> | undefined>(() => {\n if (!queueDxn) {\n return undefined;\n }\n\n const { spaceId } = queueDxn.asQueueDXN() ?? raise(new TypeError('Invalid queue DXN'));\n return client.spaces.get(spaceId)?.queues.get<T>(queueDxn);\n }, [client, queueDxn?.toString()]);\n\n useEffect(() => {\n void queue?.refresh();\n }, [queue]);\n\n useEffect(() => {\n let timeout: NodeJS.Timeout;\n mountedRef.current = true;\n\n const poll = () => {\n if (!mountedRef.current) {\n return;\n }\n\n void queue?.refresh().finally(() => {\n if (mountedRef.current && options.pollInterval) {\n timeout = setTimeout(poll, Math.max(options.pollInterval ?? 0, MIN_POLL_INTERVAL));\n }\n });\n };\n\n if (options.pollInterval) {\n poll();\n }\n\n return () => {\n mountedRef.current = false;\n clearTimeout(timeout);\n };\n }, [queue, options.pollInterval]);\n\n return queue;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Schema } from 'effect';\nimport { useMemo, useSyncExternalStore } from 'react';\n\nimport { type Client } from '@dxos/client';\nimport { type Space } from '@dxos/client/echo';\nimport { type BaseSchema } from '@dxos/echo-schema';\n\n/**\n * Subscribe to and retrieve schema changes from a space's schema registry.\n */\nexport const useSchema = (\n client: Client,\n space: Space | undefined,\n typename: string | undefined,\n): Schema.Schema.AnyNoContext | undefined => {\n const { subscribe, getSchema } = useMemo(() => {\n if (!typename || !space) {\n return {\n subscribe: () => () => {},\n getSchema: () => undefined,\n };\n }\n\n const staticSchema = client.graph.schemaRegistry.getSchema(typename);\n if (staticSchema) {\n return {\n subscribe: () => () => {},\n getSchema: () => staticSchema,\n };\n }\n\n const query = space.db.schemaRegistry.query({ typename });\n const initialResult: BaseSchema = query.runSync()[0];\n let currentSchema = initialResult;\n\n return {\n subscribe: (onStoreChange: () => void) => {\n const unsubscribe = query.subscribe(() => {\n currentSchema = query.results[0];\n onStoreChange();\n });\n\n return unsubscribe;\n },\n getSchema: () => currentSchema,\n };\n }, [typename, space]);\n\n return useSyncExternalStore(subscribe, getSchema);\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { useMemo } from 'react';\n\nimport { MulticastObservable } from '@dxos/async';\nimport { type PublicKey } from '@dxos/client';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { type CancellableInvitationObservable, useInvitationStatus } from '../invitations';\n\nimport { useSpace } from './useSpaces';\n\nexport const useSpaceInvitations = (spaceKey?: PublicKey): CancellableInvitationObservable[] => {\n const space = useSpace(spaceKey);\n return useMulticastObservable(space?.invitations ?? MulticastObservable.empty()) ?? [];\n};\n\nexport const useSpaceInvitation = (spaceKey?: PublicKey, invitationId?: string) => {\n const invitations = useSpaceInvitations(spaceKey);\n const invitation = useMemo(\n () => invitations.find((invitation) => invitation.get().invitationId === invitationId),\n [invitations],\n );\n return useInvitationStatus(invitation);\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { useEffect, useRef } from 'react';\n\nimport { type Selection, type SubscriptionHandle, createSubscription } from '@dxos/client/echo';\n\n/**\n * Create reactive selection.\n * Calls the callback when the selection changes and during the first render.\n */\n// TODO(wittjosiah): Is this still needed with signals reactivity? If not, remove or update jsdoc with usage info.\nexport const useSubscription = (cb: () => void, selection: Selection) => {\n // Make sure that the callback is always the one from the latest render.\n // Without this, we would always call the callback from the initial render,\n // which might contain stale data.\n const callbackRef = useRef(cb);\n callbackRef.current = cb;\n\n const subscriptionRef = useRef<SubscriptionHandle>();\n\n useEffect(() => {\n subscriptionRef.current = createSubscription(() => {\n callbackRef.current();\n });\n\n return () => subscriptionRef.current?.unsubscribe();\n }, []);\n\n subscriptionRef.current?.update(selection);\n return subscriptionRef.current;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type PeerSyncState, type Space, type SpaceSyncStateMap } from '@dxos/client/echo';\nimport { Context } from '@dxos/context';\nimport { type SpaceId } from '@dxos/keys';\nimport { EdgeService } from '@dxos/protocols';\n\nimport { useClient } from '../client';\n\nconst isEdgePeerId = (peerId: string, spaceId: SpaceId) =>\n peerId.startsWith(`${EdgeService.AUTOMERGE_REPLICATOR}:${spaceId}`);\n\n/**\n * Hook Subscribes to sync state for each space.\n */\nexport const useSyncState = (): SpaceSyncStateMap => {\n const client = useClient();\n const [spaceState, setSpaceState] = useState<SpaceSyncStateMap>({});\n\n useEffect(() => {\n const ctx = new Context();\n const createSubscriptions = (spaces: Space[]) => {\n for (const space of spaces) {\n if (spaceState[space.id]) {\n continue;\n }\n\n ctx.onDispose(\n space.db.subscribeToSyncState(ctx, ({ peers = [] }) => {\n const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));\n if (syncState) {\n setSpaceState((spaceState) => ({ ...spaceState, [space.id]: syncState }));\n }\n }),\n );\n }\n };\n\n createSubscriptions(client.spaces.get());\n client.spaces.subscribe((spaces) => {\n createSubscriptions(spaces);\n });\n\n return () => {\n void ctx.dispose();\n };\n }, [client]);\n\n return spaceState;\n};\n\n/**\n * Hook Subscribes to sync state for a single space.\n */\n// TODO(wittjosiah): Reconcile w/ useSyncState.\nexport const useSpaceSyncState = (space: Space): PeerSyncState | undefined => {\n const [spaceState, setSpaceState] = useState<PeerSyncState>();\n\n useEffect(() => {\n const ctx = new Context();\n space.db.subscribeToSyncState(ctx, ({ peers = [] }) => {\n const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));\n if (syncState) {\n setSpaceState(syncState);\n }\n });\n\n return () => {\n void ctx.dispose();\n };\n }, [space]);\n\n return spaceState;\n};\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["MulticastObservable", "
|
|
3
|
+
"sources": ["../../../../src/echo/index.ts", "../../../../src/echo/useMembers.ts", "../../../../src/echo/useSpaces.ts", "../../../../src/echo/useQueue.ts", "../../../../src/echo/useSpaceInvitations.ts", "../../../../src/echo/useSpaceProperties.ts", "../../../../src/echo/useSubscription.ts", "../../../../src/echo/useSyncState.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nexport * from '@dxos/client/echo';\nexport * from '@dxos/echo-react';\n\nexport * from './useMembers';\nexport * from './useQueue';\nexport * from './useSpaces';\nexport * from './useSpaceInvitations';\nexport * from './useSpaceProperties';\nexport * from './useSubscription';\nexport * from './useSyncState';\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { MulticastObservable } from '@dxos/async';\nimport { PublicKey, type PublicKeyLike } from '@dxos/client';\nimport { HaloSpaceMember, type SpaceMember } from '@dxos/client/echo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useSpaces } from './useSpaces';\n\nexport const useMembers = (spaceKey: PublicKeyLike | undefined): SpaceMember[] => {\n // TODO(dmaretskyi): useSpace hook for spaces that are not ready.\n const spaces = useSpaces({ all: true });\n const space = spaceKey\n ? spaces.find((space) => (spaceKey instanceof PublicKey ? space.key.equals(spaceKey) : space.id === spaceKey))\n : undefined;\n\n // EMPTY_OBSERVABLE needs to be a stable reference to avoid re-subscribing on every render.\n const members = useMulticastObservable(space?.members ?? MulticastObservable.empty()) ?? [];\n return members.filter((member) => member.role !== HaloSpaceMember.Role.REMOVED);\n};\n", "//\n// Copyright 2020 DXOS.org\n//\n\nimport { PublicKey } from '@dxos/client';\nimport { type Space, type SpaceId, SpaceState } from '@dxos/client/echo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client';\n\n/**\n * Get a specific Space using its id.\n * The space is not guaranteed to be in the ready state.\n * Returns undefined if no id is provided.\n * Requires a ClientProvider somewhere in the parent tree.\n *\n * @param spaceId the id of the space to look for.\n */\n// TODO(wittjosiah): Currently unable to remove `PublicKey` from this api.\n// When initially joining a space that is all that is returned.\nexport const useSpace = (spaceId?: SpaceId | PublicKey): Space | undefined => {\n const client = useClient();\n const spaces = useMulticastObservable<Space[]>(client.spaces);\n if (!spaceId) {\n return undefined;\n }\n\n return spaces.find((space) => {\n if (spaceId instanceof PublicKey) {\n return space.key.equals(spaceId);\n }\n\n return space.id === spaceId;\n });\n};\n\n/**\n * Get a Space database by the id of the space.\n * The space is not guaranteed to be in the ready state.\n * Returns undefined if no id is provided.\n * Requires a ClientProvider somewhere in the parent tree.\n *\n * @param spaceId the id of the space to look for.\n */\nexport const useDatabase = (spaceId?: SpaceId): Space['db'] | undefined => {\n const space = useSpace(spaceId);\n return space?.db;\n};\n\nexport type UseSpacesProps = {\n /**\n * Return uninitialized spaces as well.\n */\n all?: boolean;\n};\n\n/**\n * Get all Spaces available to current user.\n * Requires a ClientProvider somewhere in the parent tree.\n * By default, only ready spaces are returned.\n * @returns an array of Spaces.\n */\nexport const useSpaces = ({ all = false }: UseSpacesProps = {}): Space[] => {\n const client = useClient();\n const spaces = useMulticastObservable<Space[]>(client.spaces);\n\n // TODO(dmaretskyi): Array reference equality.\n return spaces.filter((space) => all || space.state.get() === SpaceState.SPACE_READY);\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect, useMemo, useRef } from 'react';\n\nimport { type Queue } from '@dxos/client/echo';\nimport { raise } from '@dxos/debug';\nimport { type Entity } from '@dxos/echo';\nimport { type DXN } from '@dxos/keys';\n\nimport { useClient } from '../client';\n\nconst MIN_POLL_INTERVAL = 1_000;\n\nexport type UseQueueOptions = {\n pollInterval?: number;\n};\n\n/**\n * Polls the given Edge queue.\n * @deprecated Use `useQuery` instead.\n */\n// TODO(dmaretskyi): Move into client package.\n// TODO(dmaretskyi): Consider passing the space into the hook to support queue DXNs without space id.\nexport const useQueue = <T extends Entity.Unknown>(\n queueDxn?: DXN,\n options: UseQueueOptions = {},\n): Queue<T> | undefined => {\n const client = useClient();\n const mountedRef = useRef(true);\n\n const queue = useMemo<Queue<T> | undefined>(() => {\n if (!queueDxn) {\n return undefined;\n }\n\n const { spaceId } = queueDxn.asQueueDXN() ?? raise(new TypeError('Invalid queue DXN'));\n return client.spaces.get(spaceId)?.queues.get<T>(queueDxn);\n }, [client, queueDxn?.toString()]);\n\n useEffect(() => {\n void queue?.refresh();\n }, [queue]);\n\n useEffect(() => {\n let timeout: NodeJS.Timeout;\n mountedRef.current = true;\n\n const poll = () => {\n if (!mountedRef.current) {\n return;\n }\n\n void queue?.refresh().finally(() => {\n if (mountedRef.current && options.pollInterval) {\n timeout = setTimeout(poll, Math.max(options.pollInterval ?? 0, MIN_POLL_INTERVAL));\n }\n });\n };\n\n if (options.pollInterval) {\n poll();\n }\n\n return () => {\n mountedRef.current = false;\n clearTimeout(timeout);\n };\n }, [queue, options.pollInterval]);\n\n return queue;\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { useMemo } from 'react';\n\nimport { MulticastObservable } from '@dxos/async';\nimport { type PublicKey } from '@dxos/client';\nimport { type SpaceId } from '@dxos/client/echo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { type CancellableInvitationObservable, useInvitationStatus } from '../invitations';\nimport { useSpace } from './useSpaces';\n\n// TODO(wittjosiah): Currently unable to remove `PublicKey` from this api.\n// When initially joining a space that is all that is returned.\nexport const useSpaceInvitations = (spaceId?: SpaceId | PublicKey): CancellableInvitationObservable[] => {\n const space = useSpace(spaceId);\n return useMulticastObservable(space?.invitations ?? MulticastObservable.empty()) ?? [];\n};\n\n// TODO(wittjosiah): Currently unable to remove `PublicKey` from this api.\n// When initially joining a space that is all that is returned.\nexport const useSpaceInvitation = (spaceId?: SpaceId | PublicKey, invitationId?: string) => {\n const invitations = useSpaceInvitations(spaceId);\n const invitation = useMemo(\n () => invitations.find((invitation) => invitation.get().invitationId === invitationId),\n [invitations],\n );\n return useInvitationStatus(invitation);\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { MulticastObservable } from '@dxos/async';\nimport { type SpaceProperties, SpaceState } from '@dxos/client/echo';\nimport { type Key, type Obj } from '@dxos/echo';\nimport { type ObjectUpdateCallback, useObject } from '@dxos/echo-react';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useSpace } from './useSpaces';\n\n/**\n * Subscribe to a space's properties with reactive updates.\n * Returns undefined if the space is undefined or not ready yet.\n * Automatically waits for the space to be ready before returning properties.\n *\n * @param spaceId - The space ID to get properties from (can be undefined).\n * @returns A tuple of [snapshot, updateCallback] or [undefined, no-op] if not ready.\n */\nexport const useSpaceProperties = (\n spaceId: Key.SpaceId | undefined,\n): [Obj.Snapshot<SpaceProperties> | undefined, ObjectUpdateCallback<SpaceProperties>] => {\n const space = useSpace(spaceId);\n const spaceState = useMulticastObservable(space?.state ?? MulticastObservable.empty());\n const properties = spaceState === SpaceState.SPACE_READY ? space?.properties : undefined;\n return useObject(properties);\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { useEffect, useRef } from 'react';\n\nimport { type Selection, type SubscriptionHandle, createSubscription } from '@dxos/client/echo';\n\n/**\n * Create reactive selection.\n * Calls the callback when the selection changes and during the first render.\n */\n// TODO(wittjosiah): Is this still needed with signals reactivity? If not, remove or update jsdoc with usage info.\nexport const useSubscription = (cb: () => void, selection: Selection) => {\n // Make sure that the callback is always the one from the latest render.\n // Without this, we would always call the callback from the initial render,\n // which might contain stale data.\n const callbackRef = useRef(cb);\n callbackRef.current = cb;\n\n const subscriptionRef = useRef<SubscriptionHandle>(null);\n\n useEffect(() => {\n subscriptionRef.current = createSubscription(() => {\n callbackRef.current();\n });\n\n return () => subscriptionRef.current?.unsubscribe();\n }, []);\n\n subscriptionRef.current?.update(selection);\n return subscriptionRef.current;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type PeerSyncState, type Space, type SpaceSyncStateMap } from '@dxos/client/echo';\nimport { Context } from '@dxos/context';\nimport { type SpaceId } from '@dxos/keys';\nimport { EdgeService } from '@dxos/protocols';\nimport { compositeKey } from '@dxos/util';\n\nimport { useClient } from '../client';\n\nconst isEdgePeerId = (peerId: string, spaceId: SpaceId) =>\n peerId.startsWith(compositeKey(EdgeService.AUTOMERGE_REPLICATOR, spaceId));\n\n/**\n * Hook Subscribes to sync state for each space.\n */\nexport const useSyncState = (): SpaceSyncStateMap => {\n const client = useClient();\n const [spaceState, setSpaceState] = useState<SpaceSyncStateMap>({});\n\n useEffect(() => {\n const ctx = new Context();\n const createSubscriptions = (spaces: Space[]) => {\n for (const space of spaces) {\n if (spaceState[space.id]) {\n continue;\n }\n\n ctx.onDispose(\n space.internal.db.subscribeToSyncState(ctx, ({ peers = [] }) => {\n const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));\n if (syncState) {\n setSpaceState((spaceState) => ({ ...spaceState, [space.id]: syncState }));\n }\n }),\n );\n }\n };\n\n createSubscriptions(client.spaces.get());\n client.spaces.subscribe((spaces) => {\n createSubscriptions(spaces);\n });\n\n return () => {\n void ctx.dispose();\n };\n }, [client]);\n\n return spaceState;\n};\n\n/**\n * Hook Subscribes to sync state for a single space.\n */\n// TODO(wittjosiah): Reconcile w/ useSyncState.\nexport const useSpaceSyncState = (space: Space): PeerSyncState | undefined => {\n const [spaceState, setSpaceState] = useState<PeerSyncState>();\n\n useEffect(() => {\n const ctx = new Context();\n space.internal.db.subscribeToSyncState(ctx, ({ peers = [] }) => {\n const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));\n if (syncState) {\n setSpaceState(syncState);\n }\n });\n\n return () => {\n void ctx.dispose();\n };\n }, [space]);\n\n return spaceState;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;AAIA,cAAc;AACd,cAAc;;;ACDd,SAASA,2BAA2B;AACpC,SAASC,aAAAA,kBAAqC;AAC9C,SAASC,uBAAyC;AAClD,SAASC,0BAAAA,+BAA8B;;;ACHvC,SAASC,iBAAiB;AAC1B,SAAmCC,kBAAkB;AACrD,SAASC,8BAA8B;AAchC,IAAMC,WAAW,CAACC,YAAAA;AACvB,QAAMC,SAASC,UAAAA;AACf,QAAMC,SAASC,uBAAgCH,OAAOE,MAAM;AAC5D,MAAI,CAACH,SAAS;AACZ,WAAOK;EACT;AAEA,SAAOF,OAAOG,KAAK,CAACC,UAAAA;AAClB,QAAIP,mBAAmBQ,WAAW;AAChC,aAAOD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AMC,YAAYD,MAAME,KAAK,CAACC,UAAU3B,aAAa2B,MAAM1B,QAAQiB,MAAMC,EAAE,CAAA;AAC3E,cAAIM,WAAW;AACbd,0BAAc,CAACD,iBAAgB;cAAE,GAAGA;cAAY,CAACQ,MAAMC,EAAE,GAAGM;YAAU,EAAA;UACxE;QACF,CAAA,CAAA;MAEJ;IACF;AAEAT,wBAAoBR,OAAOS,OAAOW,IAAG,CAAA;AACrCpB,WAAOS,OAAOY,UAAU,CAACZ,WAAAA;AACvBD,0BAAoBC,MAAAA;IACtB,CAAA;AAEA,WAAO,MAAA;AACL,WAAKH,IAAIgB,QAAO;IAClB;EACF,GAAG;IAACtB;GAAO;AAEX,SAAOE;AACT;AAMO,IAAMqB,oBAAoB,CAACb,UAAAA;AAChC,QAAM,CAACR,YAAYC,aAAAA,IAAiBC,SAAAA;AAEpCC,EAAAA,WAAU,MAAA;AACR,UAAMC,MAAM,IAAIC,QAAAA,QAAAA;;;;AAChBG,UAAMG,SAASC,GAAGC,qBAAqBT,KAAK,CAAC,EAAEU,QAAQ,CAAA,EAAE,MAAE;AACzD,YAAMC,YAAYD,MAAME,KAAK,CAACC,UAAU3B,aAAa2B,MAAM1B,QAAQiB,MAAMC,EAAE,CAAA;AAC3E,UAAIM,WAAW;AACbd,sBAAcc,SAAAA;MAChB;IACF,CAAA;AAEA,WAAO,MAAA;AACL,WAAKX,IAAIgB,QAAO;IAClB;EACF,GAAG;IAACZ;GAAM;AAEV,SAAOR;AACT;",
|
|
6
|
+
"names": ["MulticastObservable", "PublicKey", "HaloSpaceMember", "useMulticastObservable", "PublicKey", "SpaceState", "useMulticastObservable", "useSpace", "spaceId", "client", "useClient", "spaces", "useMulticastObservable", "undefined", "find", "space", "PublicKey", "key", "equals", "id", "useDatabase", "db", "useSpaces", "all", "filter", "state", "get", "SpaceState", "SPACE_READY", "useMembers", "spaceKey", "spaces", "useSpaces", "all", "space", "find", "PublicKey", "key", "equals", "id", "undefined", "members", "useMulticastObservable", "MulticastObservable", "empty", "filter", "member", "role", "HaloSpaceMember", "Role", "REMOVED", "useEffect", "useMemo", "useRef", "raise", "MIN_POLL_INTERVAL", "useQueue", "queueDxn", "options", "client", "useClient", "mountedRef", "useRef", "queue", "useMemo", "undefined", "spaceId", "asQueueDXN", "raise", "TypeError", "spaces", "get", "queues", "toString", "useEffect", "refresh", "timeout", "current", "poll", "finally", "pollInterval", "setTimeout", "Math", "max", "clearTimeout", "useMemo", "MulticastObservable", "useMulticastObservable", "useSpaceInvitations", "spaceId", "space", "useSpace", "useMulticastObservable", "invitations", "MulticastObservable", "empty", "useSpaceInvitation", "invitationId", "invitation", "useMemo", "find", "get", "useInvitationStatus", "MulticastObservable", "SpaceState", "useObject", "useMulticastObservable", "useSpaceProperties", "spaceId", "space", "useSpace", "spaceState", "useMulticastObservable", "state", "MulticastObservable", "empty", "properties", "SpaceState", "SPACE_READY", "undefined", "useObject", "useEffect", "useRef", "createSubscription", "useSubscription", "cb", "selection", "callbackRef", "useRef", "current", "subscriptionRef", "useEffect", "createSubscription", "unsubscribe", "update", "useEffect", "useState", "Context", "EdgeService", "compositeKey", "isEdgePeerId", "peerId", "spaceId", "startsWith", "compositeKey", "EdgeService", "AUTOMERGE_REPLICATOR", "useSyncState", "client", "useClient", "spaceState", "setSpaceState", "useState", "useEffect", "ctx", "Context", "createSubscriptions", "spaces", "space", "id", "onDispose", "internal", "db", "subscribeToSyncState", "peers", "syncState", "find", "state", "get", "subscribe", "dispose", "useSpaceSyncState"]
|
|
7
7
|
}
|