@dxos/react-client 0.8.4-main.dedc0f3 → 0.8.4-main.dfabb4ec29
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/dist/lib/browser/chunk-3LVU7RNK.mjs +16 -0
- package/dist/lib/browser/chunk-3LVU7RNK.mjs.map +7 -0
- package/dist/lib/browser/chunk-CZMIVAGI.mjs +8 -0
- package/dist/lib/browser/chunk-CZMIVAGI.mjs.map +7 -0
- package/dist/lib/browser/chunk-XT352YI6.mjs +134 -0
- package/dist/lib/browser/chunk-XT352YI6.mjs.map +7 -0
- package/dist/lib/browser/{chunk-BXOLJYAY.mjs → chunk-YHE6WD44.mjs} +4 -14
- package/dist/lib/browser/chunk-YHE6WD44.mjs.map +7 -0
- package/dist/lib/browser/devtools/index.mjs +3 -7
- package/dist/lib/browser/devtools/index.mjs.map +2 -2
- package/dist/lib/browser/echo/index.mjs +53 -119
- package/dist/lib/browser/echo/index.mjs.map +4 -4
- package/dist/lib/browser/halo/index.mjs +8 -21
- package/dist/lib/browser/halo/index.mjs.map +2 -2
- package/dist/lib/browser/index.mjs +99 -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 +86 -127
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/chunk-CUDKNAMV.mjs +17 -0
- package/dist/lib/node-esm/chunk-CUDKNAMV.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-256IHY6F.mjs → chunk-RQJPEHDY.mjs} +4 -14
- package/dist/lib/node-esm/chunk-RQJPEHDY.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-WL3Z5HOH.mjs +135 -0
- package/dist/lib/node-esm/chunk-WL3Z5HOH.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-WUTK2IJF.mjs +10 -0
- package/dist/lib/node-esm/chunk-WUTK2IJF.mjs.map +7 -0
- package/dist/lib/node-esm/devtools/index.mjs +3 -7
- package/dist/lib/node-esm/devtools/index.mjs.map +2 -2
- package/dist/lib/node-esm/echo/index.mjs +53 -119
- package/dist/lib/node-esm/echo/index.mjs.map +4 -4
- package/dist/lib/node-esm/halo/index.mjs +8 -21
- package/dist/lib/node-esm/halo/index.mjs.map +2 -2
- package/dist/lib/node-esm/index.mjs +99 -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 +86 -127
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/banner.d.ts.map +1 -1
- package/dist/types/src/client/AgentHostingProvider.d.ts.map +1 -1
- package/dist/types/src/client/ClientProvider.d.ts +1 -11
- package/dist/types/src/client/ClientProvider.d.ts.map +1 -1
- package/dist/types/src/client/useClientStatus.d.ts.map +1 -1
- package/dist/types/src/devtools/useStream.d.ts.map +1 -1
- package/dist/types/src/echo/index.d.ts +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 +19 -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 +1 -1
- package/dist/types/src/halo/Passkey.stories.d.ts.map +1 -1
- package/dist/types/src/halo/useHaloInvitations.d.ts.map +1 -1
- package/dist/types/src/halo/useKeyStore.d.ts.map +1 -1
- package/dist/types/src/invitations/useInvitationStatus.d.ts +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 +0 -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 +5 -9
- package/dist/types/src/testing/withClientProvider.d.ts.map +1 -1
- package/dist/types/src/testing/withClientProvider.stories.d.ts +3 -2
- 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 -58
- 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 -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 +33 -27
- package/src/echo/useSubscription.ts +1 -1
- package/src/echo/useSyncState.ts +4 -3
- package/src/halo/Passkey.stories.tsx +16 -22
- package/src/halo/useDevices.test.tsx +0 -1
- package/src/invitations/useInvitationStatus.ts +9 -8
- package/src/testing/ClientRepeater.stories.tsx +12 -12
- package/src/testing/ClientRepeater.tsx +14 -18
- package/src/testing/context.tsx +4 -3
- package/src/testing/util.tsx +0 -1
- package/src/testing/withClientProvider.stories.tsx +23 -15
- 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/linux_x86_64_19.0.0/727453fb3a62f7f1d952a41e051ca8a6f88cadc45cee43c6a4d1aa45f9b75665.wasmer-v7 +0 -0
- package/dist/lib/browser/chunk-BXOLJYAY.mjs.map +0 -7
- 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-256IHY6F.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 -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,135 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
ClientContext
|
|
4
|
+
} from "./chunk-WUTK2IJF.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, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 50, S: void 0 });
|
|
68
|
+
await onInitialized?.(client3);
|
|
69
|
+
log("initialization complete", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 52, S: void 0 });
|
|
70
|
+
}
|
|
71
|
+
setClient(client3);
|
|
72
|
+
if (!noBanner) {
|
|
73
|
+
printBanner(client3);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
let client2;
|
|
77
|
+
try {
|
|
78
|
+
if (clientProp) {
|
|
79
|
+
client2 = await getAsyncProviderValue(clientProp);
|
|
80
|
+
await initialize(client2);
|
|
81
|
+
} else {
|
|
82
|
+
const config = await getAsyncProviderValue(configProp);
|
|
83
|
+
log("resolved config", {
|
|
84
|
+
config
|
|
85
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 68, S: void 0 });
|
|
86
|
+
const services = await getAsyncProviderValue(servicesProp, config);
|
|
87
|
+
log("created services", {
|
|
88
|
+
services
|
|
89
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 72, S: void 0 });
|
|
90
|
+
client2 = new Client({
|
|
91
|
+
config,
|
|
92
|
+
services,
|
|
93
|
+
...options
|
|
94
|
+
});
|
|
95
|
+
log("created client", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 80, S: void 0 });
|
|
96
|
+
await initialize(client2);
|
|
97
|
+
}
|
|
98
|
+
} catch (err) {
|
|
99
|
+
if (!disposed) {
|
|
100
|
+
log.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 85, S: void 0 });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return () => {
|
|
104
|
+
log("clean up", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 89, S: void 0 });
|
|
105
|
+
disposed = true;
|
|
106
|
+
if (!clientProp) {
|
|
107
|
+
void client2?.destroy().then(() => {
|
|
108
|
+
log("destroyed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 94, S: void 0 });
|
|
109
|
+
}).catch((err) => log.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 95, S: void 0 }));
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}, [
|
|
113
|
+
configProp,
|
|
114
|
+
clientProp,
|
|
115
|
+
servicesProp,
|
|
116
|
+
noBanner
|
|
117
|
+
]);
|
|
118
|
+
if (!client?.initialized || status !== SystemStatus.ACTIVE) {
|
|
119
|
+
return /* @__PURE__ */ React.createElement(Fallback, {
|
|
120
|
+
client,
|
|
121
|
+
status
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return /* @__PURE__ */ React.createElement(ClientContext.Provider, {
|
|
125
|
+
value: {
|
|
126
|
+
client,
|
|
127
|
+
status
|
|
128
|
+
}
|
|
129
|
+
}, children);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
export {
|
|
133
|
+
ClientProvider
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=chunk-WL3Z5HOH.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${B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AAAA,KAAME,MAAAA;AAC9B,cAAA,aAAA,QAAA,EAAA,YAAA,YAAA,GAAA,cAAA,GAAA,IAAA,GAAA,OAAA,CAAA;QACF,CAAA,EAAA,MAAA,CAAA,QAAA,IAAA,MAAA,KAAA,QAAA,EAAA,YAAA,YAAA,GAAA,cAAA,GAAA,IAAA,GAAA,OAAA,CAAA,CAAA;MACC;IAACQ;;IAAwBC;IAAcC;IAAS;IAE/C;;eACelB,eAAQA,WAAAA,aAAAA,QAAAA;WAAgBG,sBAAAA,cAAAA,UAAAA;;MAC3C;IAEA,CAAA;;SAAwCH,sBAAAA,cAAAA,cAAAA,UAAAA;WAAQG;MAAO;MAAIgB;IAE7D;;;",
|
|
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", "error", "client", "useImperativeHandle", "forwardedRef", "status", "useAsyncEffect", "initialize", "catch", "setError", "err", "log", "setClient", "printBanner", "config", "services", "disposed", "clientProp", "configProp", "servicesProp", "noBanner", "children"]
|
|
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-WUTK2IJF.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,gBAAyDD,cACpEE,MAAAA;",
|
|
6
|
+
"names": ["createContext", "ClientContext", "undefined"]
|
|
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-CUDKNAMV.mjs";
|
|
5
|
+
import "../chunk-WUTK2IJF.mjs";
|
|
5
6
|
|
|
6
7
|
// src/devtools/index.ts
|
|
7
8
|
export * from "@dxos/client/devtools";
|
|
@@ -23,12 +24,7 @@ var useStream = (streamFactory, defaultValue, deps = []) => {
|
|
|
23
24
|
const stream = streamFactory();
|
|
24
25
|
stream.subscribe((response) => setValue(response), (err) => {
|
|
25
26
|
if (err) {
|
|
26
|
-
log.catch(err, void 0, {
|
|
27
|
-
F: __dxlog_file,
|
|
28
|
-
L: 21,
|
|
29
|
-
S: void 0,
|
|
30
|
-
C: (f, a) => f(...a)
|
|
31
|
-
});
|
|
27
|
+
log.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 14, S: void 0 });
|
|
32
28
|
}
|
|
33
29
|
});
|
|
34
30
|
return () => {
|
|
@@ -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": "
|
|
6
|
-
"names": ["raise", "useDevtools", "client", "useClient", "services", "DevtoolsHost", "raise", "Error", "useEffect", "useState", "log", "
|
|
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;AAEpB,IAAA,eAAA;AAKEF,IAAU,YAAA,CAAA,eAAA,cAAA,OAAA,CAAA,MAAA;QACR,CAAA,OAAMG,QAASC,IAAAA,SAAAA,YAAAA;YACfD,MAAOE;UAGH,SAAS,cAAA;qBACE,CAACC,aAAAA,SAAAA,QAAAA,GAAAA,CAAAA,QAAAA;AACZ,UAAA,KAAA;AACF,YAAA,MAAA,KAAA,QAAA,EAAA,YAAA,YAAA,GAAA,cAAA,GAAA,IAAA,GAAA,OAAA,CAAA;MAGF;;AAEA,WAAA,MAAA;AACCC,WAAAA,OAAAA,MAAAA;IAEH;EACA,GAAA,IAAA;;;",
|
|
6
|
+
"names": ["raise", "useDevtools", "client", "useClient", "services", "DevtoolsHost", "raise", "Error", "useEffect", "useState", "log", "stream", "streamFactory", "subscribe", "err", "deps"]
|
|
7
7
|
}
|
|
@@ -1,43 +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-RQJPEHDY.mjs";
|
|
5
5
|
import {
|
|
6
6
|
useClient
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-CUDKNAMV.mjs";
|
|
8
|
+
import "../chunk-WUTK2IJF.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
|
-
import {
|
|
21
|
-
var useSpace = (
|
|
23
|
+
import { useMulticastObservable } from "@dxos/react-hooks";
|
|
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
|
-
await client.spaces.waitUntilReady();
|
|
30
|
-
setReady(true);
|
|
31
|
-
}, [
|
|
32
|
-
client,
|
|
33
|
-
spaceKeyLike
|
|
34
|
-
]);
|
|
35
|
-
if (spaceKeyLike) {
|
|
36
|
-
return spaces.find((space) => space.key.equals(spaceKeyLike) || space.id === spaceKeyLike);
|
|
37
|
-
}
|
|
38
|
-
if (ready && client.halo.identity.get()) {
|
|
39
|
-
return client.spaces.default;
|
|
27
|
+
if (!spaceId) {
|
|
28
|
+
return void 0;
|
|
40
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;
|
|
41
40
|
};
|
|
42
41
|
var useSpaces = ({ all = false } = {}) => {
|
|
43
42
|
const client = useClient();
|
|
@@ -50,50 +49,19 @@ var useMembers = (spaceKey) => {
|
|
|
50
49
|
const spaces = useSpaces({
|
|
51
50
|
all: true
|
|
52
51
|
});
|
|
53
|
-
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;
|
|
54
53
|
const members = useMulticastObservable2(space?.members ?? MulticastObservable.empty()) ?? [];
|
|
55
54
|
return members.filter((member) => member.role !== HaloSpaceMember.Role.REMOVED);
|
|
56
55
|
};
|
|
57
56
|
|
|
58
|
-
// src/echo/useQuery.ts
|
|
59
|
-
import { useMemo, useSyncExternalStore } from "react";
|
|
60
|
-
import { Filter, Query, isSpace } from "@dxos/client/echo";
|
|
61
|
-
var EMPTY_ARRAY = [];
|
|
62
|
-
var noop = () => {
|
|
63
|
-
};
|
|
64
|
-
var useQuery = (spaceOrEcho, queryOrFilter, deps) => {
|
|
65
|
-
const query = Filter.is(queryOrFilter) ? Query.select(queryOrFilter) : queryOrFilter;
|
|
66
|
-
const { getObjects, subscribe } = useMemo(() => {
|
|
67
|
-
let subscribed = false;
|
|
68
|
-
const queryResult = spaceOrEcho === void 0 ? void 0 : isSpace(spaceOrEcho) ? spaceOrEcho.db.query(query) : spaceOrEcho.query(query);
|
|
69
|
-
return {
|
|
70
|
-
getObjects: () => subscribed && queryResult ? queryResult.objects : EMPTY_ARRAY,
|
|
71
|
-
subscribe: (cb) => {
|
|
72
|
-
subscribed = true;
|
|
73
|
-
const unsubscribe = queryResult?.subscribe(cb) ?? noop;
|
|
74
|
-
return () => {
|
|
75
|
-
unsubscribe?.();
|
|
76
|
-
subscribed = false;
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
}, [
|
|
81
|
-
spaceOrEcho,
|
|
82
|
-
JSON.stringify(query.ast),
|
|
83
|
-
...deps ?? []
|
|
84
|
-
]);
|
|
85
|
-
const objects = useSyncExternalStore(subscribe, getObjects);
|
|
86
|
-
return objects ?? [];
|
|
87
|
-
};
|
|
88
|
-
|
|
89
57
|
// src/echo/useQueue.ts
|
|
90
|
-
import { useEffect, useMemo
|
|
58
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
91
59
|
import { raise } from "@dxos/debug";
|
|
92
60
|
var MIN_POLL_INTERVAL = 1e3;
|
|
93
61
|
var useQueue = (queueDxn, options = {}) => {
|
|
94
62
|
const client = useClient();
|
|
95
63
|
const mountedRef = useRef(true);
|
|
96
|
-
const queue =
|
|
64
|
+
const queue = useMemo(() => {
|
|
97
65
|
if (!queueDxn) {
|
|
98
66
|
return void 0;
|
|
99
67
|
}
|
|
@@ -135,70 +103,41 @@ var useQueue = (queueDxn, options = {}) => {
|
|
|
135
103
|
return queue;
|
|
136
104
|
};
|
|
137
105
|
|
|
138
|
-
// src/echo/useSchema.ts
|
|
139
|
-
import { useMemo as useMemo3, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
140
|
-
var useSchema = (client, space, typename) => {
|
|
141
|
-
const { subscribe, getSchema } = useMemo3(() => {
|
|
142
|
-
if (!typename || !space) {
|
|
143
|
-
return {
|
|
144
|
-
subscribe: () => () => {
|
|
145
|
-
},
|
|
146
|
-
getSchema: () => void 0
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
const staticSchema = client.graph.schemaRegistry.getSchema(typename);
|
|
150
|
-
if (staticSchema) {
|
|
151
|
-
return {
|
|
152
|
-
subscribe: () => () => {
|
|
153
|
-
},
|
|
154
|
-
getSchema: () => staticSchema
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
const query = space.db.schemaRegistry.query({
|
|
158
|
-
typename
|
|
159
|
-
});
|
|
160
|
-
const initialResult = query.runSync()[0];
|
|
161
|
-
let currentSchema = initialResult;
|
|
162
|
-
return {
|
|
163
|
-
subscribe: (onStoreChange) => {
|
|
164
|
-
const unsubscribe = query.subscribe(() => {
|
|
165
|
-
currentSchema = query.results[0];
|
|
166
|
-
onStoreChange();
|
|
167
|
-
});
|
|
168
|
-
return unsubscribe;
|
|
169
|
-
},
|
|
170
|
-
getSchema: () => currentSchema
|
|
171
|
-
};
|
|
172
|
-
}, [
|
|
173
|
-
typename,
|
|
174
|
-
space
|
|
175
|
-
]);
|
|
176
|
-
return useSyncExternalStore2(subscribe, getSchema);
|
|
177
|
-
};
|
|
178
|
-
|
|
179
106
|
// src/echo/useSpaceInvitations.ts
|
|
180
|
-
import { useMemo as
|
|
107
|
+
import { useMemo as useMemo2 } from "react";
|
|
181
108
|
import { MulticastObservable as MulticastObservable2 } from "@dxos/async";
|
|
182
109
|
import { useMulticastObservable as useMulticastObservable3 } from "@dxos/react-hooks";
|
|
183
|
-
var useSpaceInvitations = (
|
|
184
|
-
const space = useSpace(
|
|
110
|
+
var useSpaceInvitations = (spaceId) => {
|
|
111
|
+
const space = useSpace(spaceId);
|
|
185
112
|
return useMulticastObservable3(space?.invitations ?? MulticastObservable2.empty()) ?? [];
|
|
186
113
|
};
|
|
187
|
-
var useSpaceInvitation = (
|
|
188
|
-
const invitations = useSpaceInvitations(
|
|
189
|
-
const invitation =
|
|
114
|
+
var useSpaceInvitation = (spaceId, invitationId) => {
|
|
115
|
+
const invitations = useSpaceInvitations(spaceId);
|
|
116
|
+
const invitation = useMemo2(() => invitations.find((invitation2) => invitation2.get().invitationId === invitationId), [
|
|
190
117
|
invitations
|
|
191
118
|
]);
|
|
192
119
|
return useInvitationStatus(invitation);
|
|
193
120
|
};
|
|
194
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
|
+
|
|
195
134
|
// src/echo/useSubscription.ts
|
|
196
135
|
import { useEffect as useEffect2, useRef as useRef2 } from "react";
|
|
197
136
|
import { createSubscription } from "@dxos/client/echo";
|
|
198
137
|
var useSubscription = (cb, selection) => {
|
|
199
138
|
const callbackRef = useRef2(cb);
|
|
200
139
|
callbackRef.current = cb;
|
|
201
|
-
const subscriptionRef = useRef2();
|
|
140
|
+
const subscriptionRef = useRef2(null);
|
|
202
141
|
useEffect2(() => {
|
|
203
142
|
subscriptionRef.current = createSubscription(() => {
|
|
204
143
|
callbackRef.current();
|
|
@@ -210,25 +149,23 @@ var useSubscription = (cb, selection) => {
|
|
|
210
149
|
};
|
|
211
150
|
|
|
212
151
|
// src/echo/useSyncState.ts
|
|
213
|
-
import { useEffect as useEffect3, useState
|
|
152
|
+
import { useEffect as useEffect3, useState } from "react";
|
|
214
153
|
import { Context } from "@dxos/context";
|
|
215
154
|
import { EdgeService } from "@dxos/protocols";
|
|
155
|
+
import { compositeKey } from "@dxos/util";
|
|
216
156
|
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/react-client/src/echo/useSyncState.ts";
|
|
217
|
-
var isEdgePeerId = (peerId, spaceId) => peerId.startsWith(
|
|
157
|
+
var isEdgePeerId = (peerId, spaceId) => peerId.startsWith(compositeKey(EdgeService.AUTOMERGE_REPLICATOR, spaceId));
|
|
218
158
|
var useSyncState = () => {
|
|
219
159
|
const client = useClient();
|
|
220
|
-
const [spaceState, setSpaceState] =
|
|
160
|
+
const [spaceState, setSpaceState] = useState({});
|
|
221
161
|
useEffect3(() => {
|
|
222
|
-
const ctx = new Context(void 0, {
|
|
223
|
-
F: __dxlog_file,
|
|
224
|
-
L: 25
|
|
225
|
-
});
|
|
162
|
+
const ctx = new Context(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 16 });
|
|
226
163
|
const createSubscriptions = (spaces) => {
|
|
227
164
|
for (const space of spaces) {
|
|
228
165
|
if (spaceState[space.id]) {
|
|
229
166
|
continue;
|
|
230
167
|
}
|
|
231
|
-
ctx.onDispose(space.db.subscribeToSyncState(ctx, ({ peers = [] }) => {
|
|
168
|
+
ctx.onDispose(space.internal.db.subscribeToSyncState(ctx, ({ peers = [] }) => {
|
|
232
169
|
const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));
|
|
233
170
|
if (syncState) {
|
|
234
171
|
setSpaceState((spaceState2) => ({
|
|
@@ -252,13 +189,10 @@ var useSyncState = () => {
|
|
|
252
189
|
return spaceState;
|
|
253
190
|
};
|
|
254
191
|
var useSpaceSyncState = (space) => {
|
|
255
|
-
const [spaceState, setSpaceState] =
|
|
192
|
+
const [spaceState, setSpaceState] = useState();
|
|
256
193
|
useEffect3(() => {
|
|
257
|
-
const ctx = new Context(void 0, {
|
|
258
|
-
|
|
259
|
-
L: 64
|
|
260
|
-
});
|
|
261
|
-
space.db.subscribeToSyncState(ctx, ({ peers = [] }) => {
|
|
194
|
+
const ctx = new Context(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 51 });
|
|
195
|
+
space.internal.db.subscribeToSyncState(ctx, ({ peers = [] }) => {
|
|
262
196
|
const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));
|
|
263
197
|
if (syncState) {
|
|
264
198
|
setSpaceState(syncState);
|
|
@@ -273,13 +207,13 @@ var useSpaceSyncState = (space) => {
|
|
|
273
207
|
return spaceState;
|
|
274
208
|
};
|
|
275
209
|
export {
|
|
210
|
+
useDatabase,
|
|
276
211
|
useMembers,
|
|
277
|
-
useQuery,
|
|
278
212
|
useQueue,
|
|
279
|
-
useSchema,
|
|
280
213
|
useSpace,
|
|
281
214
|
useSpaceInvitation,
|
|
282
215
|
useSpaceInvitations,
|
|
216
|
+
useSpaceProperties,
|
|
283
217
|
useSpaceSyncState,
|
|
284
218
|
useSpaces,
|
|
285
219
|
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 { useState } from 'react';\n\nimport { type PublicKeyLike } from '@dxos/client';\nimport { type Space, SpaceState } from '@dxos/client/echo';\nimport { useAsyncEffect, 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 useAsyncEffect(async () => {\n // Only wait for ready if looking for the default space.\n if (spaceKeyLike) {\n return;\n }\n\n await client.spaces.waitUntilReady();\n setReady(true);\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 * @deprecated Use useSpace.\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
|
+
"mapp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able", "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", "current", "subscriptionRef", "unsubscribe", "update", "useEffect", "useState", "Context", "EdgeService", "compositeKey", "isEdgePeerId", "spaceState", "setSpaceState", "useEffect", "Context", "createSubscriptions", "space", "spaces", "id", "onDispose", "syncState", "client", "internal", "peers", "find", "state"]
|
|
7
7
|
}
|