@dxos/react-client 0.11.0 → 0.12.0-next-2be9f24c465d98f4bd186aa03ece788902e6c17a
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/CHANGELOG.md +94 -0
- package/dist/lib/chunk-ClientProvider.mjs +18 -13
- package/dist/lib/chunk-ClientProvider.mjs.map +1 -1
- package/dist/lib/chunk-useClient.mjs +11 -0
- package/dist/lib/chunk-useClient.mjs.map +1 -1
- package/dist/lib/devtools.mjs.map +1 -1
- package/dist/lib/echo.mjs +12 -6
- package/dist/lib/echo.mjs.map +1 -1
- package/dist/lib/halo.mjs +12 -6
- package/dist/lib/halo.mjs.map +1 -1
- package/dist/lib/index.mjs +2 -1
- package/dist/lib/index.mjs.map +1 -1
- package/dist/lib/invitations.mjs +5 -7
- package/dist/lib/invitations.mjs.map +1 -1
- package/dist/lib/mesh.mjs +2 -1
- package/dist/lib/mesh.mjs.map +1 -1
- package/dist/lib/testing.mjs.map +1 -1
- package/dist/types/src/client/ClientProvider.d.ts +16 -0
- package/dist/types/src/client/ClientProvider.d.ts.map +1 -1
- package/dist/types/src/client/useClient.d.ts +10 -0
- package/dist/types/src/client/useClient.d.ts.map +1 -1
- package/dist/types/src/devtools/useStream.d.ts +1 -1
- package/dist/types/src/devtools/useStream.d.ts.map +1 -1
- package/dist/types/src/halo/Passkey.stories.d.ts +2 -1
- package/dist/types/src/halo/Passkey.stories.d.ts.map +1 -1
- package/dist/types/src/testing/util.d.ts.map +1 -1
- package/dist/types/src/testing/withClientProvider.d.ts +1 -1
- package/dist/types/src/testing/withClientProvider.d.ts.map +1 -1
- package/dist/types/src/testing/withClientProvider.stories.d.ts +2 -1
- package/dist/types/src/testing/withClientProvider.stories.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +23 -25
- package/src/client/ClientProvider.test.tsx +2 -1
- package/src/client/ClientProvider.tsx +23 -3
- package/src/client/useClient.ts +13 -0
- package/src/devtools/useStream.ts +1 -1
- package/src/halo/Passkey.stories.tsx +2 -2
- package/src/testing/util.tsx +2 -1
- package/src/testing/withClientProvider.tsx +1 -1
- package/tsconfig.json +0 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,99 @@
|
|
|
1
1
|
# @dxos/react-client
|
|
2
2
|
|
|
3
|
+
## 0.12.0-next-2be9f24c465d98f4bd186aa03ece788902e6c17a
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [86d1482]
|
|
8
|
+
- Updated dependencies [e2eecf2]
|
|
9
|
+
- Updated dependencies [22bea85]
|
|
10
|
+
- Updated dependencies [069e8ed]
|
|
11
|
+
- Updated dependencies [75971ad]
|
|
12
|
+
- Updated dependencies [3958355]
|
|
13
|
+
- Updated dependencies [ea11703]
|
|
14
|
+
- Updated dependencies [881f900]
|
|
15
|
+
- Updated dependencies [da37a13]
|
|
16
|
+
- Updated dependencies [0a01ff7]
|
|
17
|
+
- Updated dependencies [1c995c4]
|
|
18
|
+
- Updated dependencies [a69d861]
|
|
19
|
+
- Updated dependencies [ba08e65]
|
|
20
|
+
- Updated dependencies [5fcd238]
|
|
21
|
+
- Updated dependencies [5e8878c]
|
|
22
|
+
- Updated dependencies [e094f74]
|
|
23
|
+
- Updated dependencies [6c6987e]
|
|
24
|
+
- Updated dependencies [3e02201]
|
|
25
|
+
- Updated dependencies [a3b6ef0]
|
|
26
|
+
- Updated dependencies [b02fe16]
|
|
27
|
+
- Updated dependencies [c439ba0]
|
|
28
|
+
- Updated dependencies [6af130f]
|
|
29
|
+
- Updated dependencies [d62a947]
|
|
30
|
+
- Updated dependencies [7d000b9]
|
|
31
|
+
- Updated dependencies [4c107a2]
|
|
32
|
+
- Updated dependencies [b9d72bb]
|
|
33
|
+
- Updated dependencies [3e9a10f]
|
|
34
|
+
- Updated dependencies [8ea2bf9]
|
|
35
|
+
- Updated dependencies [48ea128]
|
|
36
|
+
- Updated dependencies [8ca2ac7]
|
|
37
|
+
- Updated dependencies [b600f72]
|
|
38
|
+
- Updated dependencies [99e323d]
|
|
39
|
+
- Updated dependencies [ea11703]
|
|
40
|
+
- Updated dependencies [bcfe4c5]
|
|
41
|
+
- Updated dependencies [ca34a80]
|
|
42
|
+
- Updated dependencies [24fcadc]
|
|
43
|
+
- Updated dependencies [4804da0]
|
|
44
|
+
- Updated dependencies [63e500b]
|
|
45
|
+
- Updated dependencies [256f286]
|
|
46
|
+
- Updated dependencies [5b504b4]
|
|
47
|
+
- Updated dependencies [d7b0a3b]
|
|
48
|
+
- Updated dependencies [f4c2702]
|
|
49
|
+
- Updated dependencies [318bbad]
|
|
50
|
+
- Updated dependencies [f8bfba0]
|
|
51
|
+
- Updated dependencies [ea11703]
|
|
52
|
+
- Updated dependencies [0280a6a]
|
|
53
|
+
- Updated dependencies [18597fc]
|
|
54
|
+
- Updated dependencies [881f900]
|
|
55
|
+
- Updated dependencies [32353e6]
|
|
56
|
+
- Updated dependencies [559acfa]
|
|
57
|
+
- Updated dependencies [e8088ea]
|
|
58
|
+
- Updated dependencies [5d816a6]
|
|
59
|
+
- Updated dependencies [40b50c2]
|
|
60
|
+
- Updated dependencies [85bdad2]
|
|
61
|
+
- Updated dependencies [77d0026]
|
|
62
|
+
- Updated dependencies [cc11297]
|
|
63
|
+
- @dxos/client@0.12.0-next-2be9f24c465d98f4bd186aa03ece788902e6c17a
|
|
64
|
+
- @dxos/echo@0.12.0-next-2be9f24c465d98f4bd186aa03ece788902e6c17a
|
|
65
|
+
- @dxos/config@0.12.0-next-2be9f24c465d98f4bd186aa03ece788902e6c17a
|
|
66
|
+
- @dxos/echo-protocol@0.12.0-next-2be9f24c465d98f4bd186aa03ece788902e6c17a
|
|
67
|
+
- @dxos/util@0.12.0-next-2be9f24c465d98f4bd186aa03ece788902e6c17a
|
|
68
|
+
- @dxos/react-hooks@0.12.0-next-2be9f24c465d98f4bd186aa03ece788902e6c17a
|
|
69
|
+
- @dxos/echo-react@0.12.0-next-2be9f24c465d98f4bd186aa03ece788902e6c17a
|
|
70
|
+
- @dxos/async@0.12.0-next-2be9f24c465d98f4bd186aa03ece788902e6c17a
|
|
71
|
+
- @dxos/context@0.12.0-next-2be9f24c465d98f4bd186aa03ece788902e6c17a
|
|
72
|
+
- @dxos/log@0.12.0-next-2be9f24c465d98f4bd186aa03ece788902e6c17a
|
|
73
|
+
- @dxos/debug@0.12.0-next-2be9f24c465d98f4bd186aa03ece788902e6c17a
|
|
74
|
+
- @dxos/keys@0.12.0-next-2be9f24c465d98f4bd186aa03ece788902e6c17a
|
|
75
|
+
- @dxos/node-std@0.12.0-next-2be9f24c465d98f4bd186aa03ece788902e6c17a
|
|
76
|
+
|
|
77
|
+
## 0.11.1
|
|
78
|
+
|
|
79
|
+
### Patch Changes
|
|
80
|
+
|
|
81
|
+
- @dxos/async@0.11.1
|
|
82
|
+
- @dxos/client@0.11.1
|
|
83
|
+
- @dxos/codec-protobuf@0.11.1
|
|
84
|
+
- @dxos/config@0.11.1
|
|
85
|
+
- @dxos/context@0.11.1
|
|
86
|
+
- @dxos/debug@0.11.1
|
|
87
|
+
- @dxos/echo@0.11.1
|
|
88
|
+
- @dxos/echo-protocol@0.11.1
|
|
89
|
+
- @dxos/echo-react@0.11.1
|
|
90
|
+
- @dxos/invariant@0.11.1
|
|
91
|
+
- @dxos/keys@0.11.1
|
|
92
|
+
- @dxos/log@0.11.1
|
|
93
|
+
- @dxos/node-std@0.11.1
|
|
94
|
+
- @dxos/react-hooks@0.11.1
|
|
95
|
+
- @dxos/util@0.11.1
|
|
96
|
+
|
|
3
97
|
## 0.11.0
|
|
4
98
|
|
|
5
99
|
### Patch Changes
|
|
@@ -30,7 +30,7 @@ var __dxlog_file = "/__w/dxos/dxos/packages/sdk/react-client/src/client/ClientPr
|
|
|
30
30
|
* Root component that provides the DXOS client instance to child components.
|
|
31
31
|
* To be used with the `useClient` hook.
|
|
32
32
|
*/
|
|
33
|
-
var ClientProvider = forwardRef(({ children, config: configProp, client: clientProp, services: servicesProp, status: statusProp, fallback: Fallback = () => null, noBanner, onInitialized, ...options }, forwardedRef) => {
|
|
33
|
+
var ClientProvider = forwardRef(({ children, config: configProp, client: clientProp, services: servicesProp, status: statusProp, fallback: Fallback = () => null, suspend, noBanner, onInitialized, ...options }, forwardedRef) => {
|
|
34
34
|
const [error, setError] = useState();
|
|
35
35
|
if (error) throw error;
|
|
36
36
|
const [client, setClient] = useState(clientProp instanceof Client ? clientProp : void 0);
|
|
@@ -44,21 +44,21 @@ var ClientProvider = forwardRef(({ children, config: configProp, client: clientP
|
|
|
44
44
|
useAsyncEffect(async () => {
|
|
45
45
|
let disposed = false;
|
|
46
46
|
const initialize = async (client) => {
|
|
47
|
-
if (!client.initialized) {
|
|
47
|
+
if (!client.initialized && !(suspend && clientProp)) {
|
|
48
48
|
await client.initialize().catch((err) => {
|
|
49
49
|
if (!disposed) setError(err);
|
|
50
50
|
});
|
|
51
51
|
log("client ready", void 0, {
|
|
52
52
|
"~LogMeta": "~LogMeta",
|
|
53
53
|
F: __dxlog_file,
|
|
54
|
-
L:
|
|
54
|
+
L: 137,
|
|
55
55
|
S: void 0
|
|
56
56
|
});
|
|
57
57
|
await onInitialized?.(client);
|
|
58
58
|
log("initialization complete", void 0, {
|
|
59
59
|
"~LogMeta": "~LogMeta",
|
|
60
60
|
F: __dxlog_file,
|
|
61
|
-
L:
|
|
61
|
+
L: 139,
|
|
62
62
|
S: void 0
|
|
63
63
|
});
|
|
64
64
|
}
|
|
@@ -75,14 +75,14 @@ var ClientProvider = forwardRef(({ children, config: configProp, client: clientP
|
|
|
75
75
|
log("resolved config", { config }, {
|
|
76
76
|
"~LogMeta": "~LogMeta",
|
|
77
77
|
F: __dxlog_file,
|
|
78
|
-
L:
|
|
78
|
+
L: 157,
|
|
79
79
|
S: void 0
|
|
80
80
|
});
|
|
81
81
|
const services = await getAsyncProviderValue(servicesProp, config);
|
|
82
82
|
log("created services", { services }, {
|
|
83
83
|
"~LogMeta": "~LogMeta",
|
|
84
84
|
F: __dxlog_file,
|
|
85
|
-
L:
|
|
85
|
+
L: 159,
|
|
86
86
|
S: void 0
|
|
87
87
|
});
|
|
88
88
|
client = new Client({
|
|
@@ -93,7 +93,7 @@ var ClientProvider = forwardRef(({ children, config: configProp, client: clientP
|
|
|
93
93
|
log("created client", void 0, {
|
|
94
94
|
"~LogMeta": "~LogMeta",
|
|
95
95
|
F: __dxlog_file,
|
|
96
|
-
L:
|
|
96
|
+
L: 161,
|
|
97
97
|
S: void 0
|
|
98
98
|
});
|
|
99
99
|
await initialize(client);
|
|
@@ -102,7 +102,7 @@ var ClientProvider = forwardRef(({ children, config: configProp, client: clientP
|
|
|
102
102
|
if (!disposed) log.catch(err, void 0, {
|
|
103
103
|
"~LogMeta": "~LogMeta",
|
|
104
104
|
F: __dxlog_file,
|
|
105
|
-
L:
|
|
105
|
+
L: 166,
|
|
106
106
|
S: void 0
|
|
107
107
|
});
|
|
108
108
|
}
|
|
@@ -110,7 +110,7 @@ var ClientProvider = forwardRef(({ children, config: configProp, client: clientP
|
|
|
110
110
|
log("clean up", void 0, {
|
|
111
111
|
"~LogMeta": "~LogMeta",
|
|
112
112
|
F: __dxlog_file,
|
|
113
|
-
L:
|
|
113
|
+
L: 171,
|
|
114
114
|
S: void 0
|
|
115
115
|
});
|
|
116
116
|
disposed = true;
|
|
@@ -118,13 +118,13 @@ var ClientProvider = forwardRef(({ children, config: configProp, client: clientP
|
|
|
118
118
|
log("destroyed", void 0, {
|
|
119
119
|
"~LogMeta": "~LogMeta",
|
|
120
120
|
F: __dxlog_file,
|
|
121
|
-
L:
|
|
121
|
+
L: 178,
|
|
122
122
|
S: void 0
|
|
123
123
|
});
|
|
124
124
|
}).catch((err) => log.catch(err, void 0, {
|
|
125
125
|
"~LogMeta": "~LogMeta",
|
|
126
126
|
F: __dxlog_file,
|
|
127
|
-
L:
|
|
127
|
+
L: 180,
|
|
128
128
|
S: void 0
|
|
129
129
|
}));
|
|
130
130
|
};
|
|
@@ -132,9 +132,14 @@ var ClientProvider = forwardRef(({ children, config: configProp, client: clientP
|
|
|
132
132
|
configProp,
|
|
133
133
|
clientProp,
|
|
134
134
|
servicesProp,
|
|
135
|
-
noBanner
|
|
135
|
+
noBanner,
|
|
136
|
+
suspend
|
|
136
137
|
]);
|
|
137
|
-
if (!client?.initialized || status !== SystemStatus.ACTIVE) return /* @__PURE__ */ jsx(Fallback, {
|
|
138
|
+
if (!suspend && (!client?.initialized || status !== SystemStatus.ACTIVE)) return /* @__PURE__ */ jsx(Fallback, {
|
|
139
|
+
client,
|
|
140
|
+
status
|
|
141
|
+
});
|
|
142
|
+
if (!client) return /* @__PURE__ */ jsx(Fallback, {
|
|
138
143
|
client,
|
|
139
144
|
status
|
|
140
145
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-ClientProvider.mjs","names":[],"sources":["../../src/banner.ts","../../src/client/ClientProvider.tsx"],"sourcesContent":["//\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","//\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"],"mappings":";;;;;;;;AAOA,IAAM,UAAU,WAAmB;CACjC,MAAM,aAAa,OAAO,OAAO,IAAI,8BAA8B;CACnE,MAAM,OAAO,aAAa,eAAe,WAAW,OAAO;CAE3D,OACE;;;;;;iBAMkB,OAAO,QAAQ,KAAK;AAE1C;AAEA,IAAI,gBAAgB;AAEpB,IAAa,eAAe,WAAmB;CAC7C,IAAI,iBAAiB,OAAO,SAAS,aAAa,aAChD;CAGF,gBAAgB;CAEhB,QAAQ,IAAI,KAAK,OAAO,MAAM,KAAK,yBAAyB;AAC9D;;;;;;;;ACuCA,IAAa,iBAAiB,YAE1B,EACE,UACA,QAAQ,YACR,QAAQ,YACR,UAAU,cACV,QAAQ,YACR,UAAU,iBAAiB,MAC3B,UACA,eACA,GAAG,WAEL,iBACG;CAMH,MAAM,CAAC,OAAO,YAAY,SAAS;CACnC,IAAI,OACF,MAAM;CAGR,MAAM,CAAC,QAAQ,aAAa,SAAS,sBAAsB,SAAS,aAAa,KAAA,CAAS;CAG1F,oBAAoB,oBAAoB,QAAQ,CAAC,MAAM,CAAC;CAGxD,MAAM,CAAC,QAAQ,aAAa,mBAAmB,UAAU;CACzD,gBAAgB;EACd,IAAI,CAAC,QACH;EAGF,MAAM,eAAe,OAAO,OAAO,WAAW,WAAW,UAAU,MAAM,CAAC;EAC1E,aAAa,aAAa,YAAY;CACxC,GAAG,CAAC,MAAM,CAAC;CAGX,eAAe,YAAY;EACzB,IAAI,WAAW;EACf,MAAM,aAAa,OAAO,WAAmB;GAC3C,IAAI,CAAC,OAAO,aAAa;IACvB,MAAM,OAAO,WAAW,CAAC,CAAC,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,QAAQ,CAAA,CACT,WAAW;IACV,IAAI,aAAU,KAAA,GAAA;KAAA,YAAA;KAAA,GAAA;KAAA,GAAA;KAAA,GAAA,KAAA;IAAA,CAAC;GACjB,CAAC,CAAA,CACA,OAAO,QAAQ,IAAI,MAAM,KAAE,KAAA,GAAA;IAAA,YAAA;IAAA,GAAA;IAAA,GAAA;IAAA,GAAA,KAAA;GAAA,CAAC,CAAC;EAEpC;CACF,GAAG;EAAC;EAAY;EAAY;EAAc;CAAQ,CAAC;CAEnD,IAAI,CAAC,QAAQ,eAAe,WAAW,aAAa,QAClD,OAAO,oBAAC,UAAD;EAAkB;EAAgB;CAAS,CAAA;CAGpD,OAAO,oBAAC,cAAc,UAAf;EAAwB,OAAO;GAAE;GAAQ;EAAO;EAAI;CAAiC,CAAA;AAC9F,CACF"}
|
|
1
|
+
{"version":3,"file":"chunk-ClientProvider.mjs","names":[],"sources":["../../src/banner.ts","../../src/client/ClientProvider.tsx"],"sourcesContent":["//\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","//\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 * Provide the context immediately instead of rendering `fallback` until the client is\n * initialized and active. Client-dependent hooks then suspend at their own Suspense\n * boundaries, so the surrounding shell renders while initialization runs. Only valid with\n * a caller-supplied `client` whose initialization the caller owns (e.g. a forked\n * `initialize()`); the config/services paths keep the blocking behavior.\n */\n suspend?: boolean;\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 suspend,\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 // In suspend mode the caller owns initialization (typically a forked `initialize()` whose\n // failure raises the app's fatal error). A competing call here can succeed after that\n // failure and wake suspended consumers into an app whose initialization events never\n // fired — onboarding, app-graph, and migrations all gate on those.\n if (!client.initialized && !(suspend && clientProp)) {\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, suspend]);\n\n // In suspend mode the (possibly uninitialized) client is provided immediately and hooks\n // suspend individually; the status gate is skipped because status only becomes ACTIVE\n // after the caller's forked initialization completes.\n if (!suspend && (!client?.initialized || status !== SystemStatus.ACTIVE)) {\n return <Fallback client={client} status={status} />;\n }\n if (!client) {\n return <Fallback client={client} status={status} />;\n }\n\n return <ClientContext.Provider value={{ client, status }}>{children}</ClientContext.Provider>;\n },\n);\n"],"mappings":";;;;;;;;AAOA,IAAM,UAAU,WAAmB;CACjC,MAAM,aAAa,OAAO,OAAO,IAAI,8BAA8B;CACnE,MAAM,OAAO,aAAa,eAAe,WAAW,OAAO;CAE3D,OACE;;;;;;iBAMkB,OAAO,QAAQ,KAAK;AAE1C;AAEA,IAAI,gBAAgB;AAEpB,IAAa,eAAe,WAAmB;CAC7C,IAAI,iBAAiB,OAAO,SAAS,aAAa,aAChD;CAGF,gBAAgB;CAEhB,QAAQ,IAAI,KAAK,OAAO,MAAM,KAAK,yBAAyB;AAC9D;;;;;;;;ACgDA,IAAa,iBAAiB,YAE1B,EACE,UACA,QAAQ,YACR,QAAQ,YACR,UAAU,cACV,QAAQ,YACR,UAAU,iBAAiB,MAC3B,SACA,UACA,eACA,GAAG,WAEL,iBACG;CAMH,MA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ClientProvider.
|
|
8
|
+
*
|
|
9
|
+
* Under a `suspend` ClientProvider the context is available before `client.initialize()`
|
|
10
|
+
* completes; this hook then suspends (throws the initialization promise) so any component
|
|
11
|
+
* depending on the client parks at its nearest Suspense boundary instead of reading an
|
|
12
|
+
* uninitialized client.
|
|
13
|
+
*
|
|
14
|
+
* Deliberately no timeout here: React retries a rejected thrown promise and the retry suspends
|
|
15
|
+
* again, so a rejection loops rather than reaching an error boundary (measured: ~90 renders in
|
|
16
|
+
* 500ms). A stalled initialization is bounded once, at the app entry point, which raises it as a
|
|
17
|
+
* fatal error instead.
|
|
8
18
|
*/
|
|
9
19
|
var useClient = () => {
|
|
10
20
|
const { client } = useContext(ClientContext) ?? raise(/* @__PURE__ */ new Error("Missing ClientContext."));
|
|
21
|
+
if (!client.initialized) throw client.waitUntilInitialized();
|
|
11
22
|
return client;
|
|
12
23
|
};
|
|
13
24
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-useClient.mjs","names":[],"sources":["../../src/client/useClient.ts"],"sourcesContent":["//\n// Copyright 2024 DXOS.org\n//\n\nimport { useContext } from 'react';\n\nimport { raise } from '@dxos/debug';\n\nimport { ClientContext } from '../client/context';\n\n/**\n * Hook returning instance of DXOS client.\n * Requires ClientContext to be set via ClientProvider.\n */\nexport const useClient = () => {\n const { client } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));\n return client;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"chunk-useClient.mjs","names":[],"sources":["../../src/client/useClient.ts"],"sourcesContent":["//\n// Copyright 2024 DXOS.org\n//\n\nimport { useContext } from 'react';\n\nimport { raise } from '@dxos/debug';\n\nimport { ClientContext } from '../client/context';\n\n/**\n * Hook returning instance of DXOS client.\n * Requires ClientContext to be set via ClientProvider.\n *\n * Under a `suspend` ClientProvider the context is available before `client.initialize()`\n * completes; this hook then suspends (throws the initialization promise) so any component\n * depending on the client parks at its nearest Suspense boundary instead of reading an\n * uninitialized client.\n *\n * Deliberately no timeout here: React retries a rejected thrown promise and the retry suspends\n * again, so a rejection loops rather than reaching an error boundary (measured: ~90 renders in\n * 500ms). A stalled initialization is bounded once, at the app entry point, which raises it as a\n * fatal error instead.\n */\nexport const useClient = () => {\n const { client } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));\n if (!client.initialized) {\n throw client.waitUntilInitialized();\n }\n return client;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwBA,IAAa,kBAAkB;CAC7B,MAAM,EAAE,WAAW,WAAW,aAAa,KAAK,sBAAM,IAAI,MAAM,wBAAwB,CAAC;CACzF,IAAI,CAAC,OAAO,aACV,MAAM,OAAO,qBAAqB;CAEpC,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devtools.mjs","names":[],"sources":["../../src/devtools/useDevtools.ts","../../src/devtools/useStream.ts"],"sourcesContent":["//\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/
|
|
1
|
+
{"version":3,"file":"devtools.mjs","names":[],"sources":["../../src/devtools/useDevtools.ts","../../src/devtools/useStream.ts"],"sourcesContent":["//\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/async';\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"],"mappings":";;;;;;AASA,IAAa,oBAAkC;CAE7C,OADe,UACR,CAAA,CAAO,SAAS,SAAS,gBAAgB,sBAAM,IAAI,MAAM,6BAA6B,CAAC;AAChG;;;;;;;ACAA,IAAa,aAAgB,eAAgC,cAAiB,OAAuB,CAAC,MAAS;CAC7G,MAAM,CAAC,OAAO,YAAY,SAAwB,YAAY;CAC9D,gBAAgB;EACd,MAAM,SAAS,cAAc;EAC7B,OAAO,WACJ,aAAgB,SAAS,QAAQ,IACjC,QAAQ;GACP,IAAI,KACF,IAAI,MAAM,KAAE,KAAA,GAAA;IAAA,YAAA;IAAA,GAAA;IAAA,GAAA;IAAA,GAAA,KAAA;GAAA,CAAC;EAEjB,CACF;EAEA,aAAa;GACX,OAAY,MAAM;EACpB;CACF,GAAG,IAAI;CAEP,OAAO,SAAS;AAClB"}
|
package/dist/lib/echo.mjs
CHANGED
|
@@ -20,7 +20,8 @@ export * from "@dxos/echo-react";
|
|
|
20
20
|
* @param spaceId the id of the space to look for.
|
|
21
21
|
*/
|
|
22
22
|
var useSpace = (spaceId) => {
|
|
23
|
-
const
|
|
23
|
+
const client = useClient();
|
|
24
|
+
const spaces = useMulticastObservable(client.spaces);
|
|
24
25
|
if (!spaceId) return;
|
|
25
26
|
return spaces.find((space) => {
|
|
26
27
|
if (spaceId instanceof PublicKey) return space.key.equals(spaceId);
|
|
@@ -34,22 +35,26 @@ var useSpace = (spaceId) => {
|
|
|
34
35
|
* @returns an array of Spaces.
|
|
35
36
|
*/
|
|
36
37
|
var useSpaces = ({ all = false } = {}) => {
|
|
37
|
-
|
|
38
|
+
const client = useClient();
|
|
39
|
+
return useMulticastObservable(client.spaces).filter((space) => all || space.state.get() === SpaceState.SPACE_READY);
|
|
38
40
|
};
|
|
39
41
|
//#endregion
|
|
40
42
|
//#region src/echo/useMembers.ts
|
|
41
43
|
var useMembers = (spaceKey) => {
|
|
42
44
|
const spaces = useSpaces({ all: true });
|
|
43
|
-
|
|
45
|
+
const space = spaceKey ? spaces.find((space) => spaceKey instanceof PublicKey ? space.key.equals(spaceKey) : space.id === spaceKey) : void 0;
|
|
46
|
+
return (useMulticastObservable(space?.members ?? MulticastObservable.empty()) ?? []).filter((member) => member.role !== HaloSpaceMember.Role.REMOVED);
|
|
44
47
|
};
|
|
45
48
|
//#endregion
|
|
46
49
|
//#region src/echo/useSpaceInvitations.ts
|
|
47
50
|
var useSpaceInvitations = (spaceId) => {
|
|
48
|
-
|
|
51
|
+
const space = useSpace(spaceId);
|
|
52
|
+
return useMulticastObservable(space?.invitations ?? MulticastObservable.empty()) ?? [];
|
|
49
53
|
};
|
|
50
54
|
var useSpaceInvitation = (spaceId, invitationId) => {
|
|
51
55
|
const invitations = useSpaceInvitations(spaceId);
|
|
52
|
-
|
|
56
|
+
const invitation = useMemo(() => invitations.find((invitation) => invitation.get().invitationId === invitationId), [invitations]);
|
|
57
|
+
return useInvitationStatus(invitation);
|
|
53
58
|
};
|
|
54
59
|
//#endregion
|
|
55
60
|
//#region src/echo/useSpaceProperties.ts
|
|
@@ -63,7 +68,8 @@ var useSpaceInvitation = (spaceId, invitationId) => {
|
|
|
63
68
|
*/
|
|
64
69
|
var useSpaceProperties = (spaceId) => {
|
|
65
70
|
const space = useSpace(spaceId);
|
|
66
|
-
|
|
71
|
+
const properties = useMulticastObservable(space?.state ?? MulticastObservable.empty()) === SpaceState.SPACE_READY ? space?.properties : void 0;
|
|
72
|
+
return useObject(properties);
|
|
67
73
|
};
|
|
68
74
|
//#endregion
|
|
69
75
|
//#region src/echo/useFlush.ts
|
package/dist/lib/echo.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"echo.mjs","names":[],"sources":["../../src/echo/useSpaces.ts","../../src/echo/useMembers.ts","../../src/echo/useSpaceInvitations.ts","../../src/echo/useSpaceProperties.ts","../../src/echo/useFlush.ts","../../src/echo/useSubscription.ts","../../src/echo/useSyncState.ts","../../src/echo/useFeedSyncState.ts","../../src/echo/useRegistry.ts"],"sourcesContent":["//\n// Copyright 2020 DXOS.org\n//\n\nimport { PublicKey } from '@dxos/client';\nimport { type Space, SpaceState } from '@dxos/client/echo';\nimport { type SpaceId } from '@dxos/keys';\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\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 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 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/keys';\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 2025 DXOS.org\n//\n\nimport { useCallback, useRef, useState } from 'react';\n\nimport { type Space } from '@dxos/client/echo';\n\n/**\n * Flushes a space's database to storage, exposing a transient `idle → flushing → flushed → idle`\n * state suitable for driving a toolbar affordance.\n */\nexport const useFlush = (space?: Space) => {\n const [state, setState] = useState<'idle' | 'flushing' | 'flushed'>('idle');\n const resetTimer = useRef<NodeJS.Timeout | null>(null);\n\n const handleFlush = useCallback(() => {\n if (!space) {\n return;\n }\n\n queueMicrotask(async () => {\n if (resetTimer.current) {\n clearTimeout(resetTimer.current);\n }\n\n setState('flushing');\n await space.db.flush();\n setState('flushed');\n\n resetTimer.current = setTimeout(() => {\n setState('idle');\n resetTimer.current = null;\n }, 1_000);\n });\n }, [space]);\n\n return { state, handleFlush };\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 { isEdgePeerId } from '@dxos/echo-protocol';\n\nimport { useClient } from '../client';\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.subscribeToAutomergeSyncState(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.subscribeToAutomergeSyncState(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","//\n// Copyright 2026 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type SpaceId } from '@dxos/keys';\n\nimport { useClient } from '../client';\n\nconst DEFAULT_POLL_INTERVAL_MS = 5_000;\n\nexport type FeedSyncState = {\n /** Combined blocks to pull + push across namespaces. */\n pending: number;\n /** Total blocks stored locally across namespaces. */\n total: number;\n};\n\nexport type FeedSyncStateMap = Record<SpaceId, FeedSyncState>;\n\n/**\n * Polls feed replication state per space.\n */\nexport const useFeedSyncState = (pollIntervalMs = DEFAULT_POLL_INTERVAL_MS): FeedSyncStateMap => {\n const client = useClient();\n const [feedSyncState, setFeedSyncState] = useState<FeedSyncStateMap>({});\n\n useEffect(() => {\n const feedService = client.services.services.FeedService;\n if (!feedService) {\n return;\n }\n\n let cancelled = false;\n\n const poll = async () => {\n const spaces = client.spaces.get();\n const entries = await Promise.all(\n spaces.map(async (space) => {\n try {\n const response = await feedService.getSyncState({ spaceId: space.id });\n const state = (response.namespaces ?? []).reduce<FeedSyncState>(\n (acc, entry) => {\n acc.pending += Number(entry.blocksToPull ?? 0) + Number(entry.blocksToPush ?? 0);\n acc.total += Number(entry.totalBlocks ?? 0);\n return acc;\n },\n { pending: 0, total: 0 },\n );\n return [space.id, state] as const;\n } catch {\n return [space.id, { pending: 0, total: 0 }] as const;\n }\n }),\n );\n\n if (!cancelled) {\n setFeedSyncState(Object.fromEntries(entries));\n }\n };\n\n void poll();\n const interval = setInterval(() => void poll(), pollIntervalMs);\n\n const spacesSubscription = client.spaces.subscribe(() => {\n void poll();\n });\n\n return () => {\n cancelled = true;\n clearInterval(interval);\n spacesSubscription.unsubscribe();\n };\n }, [client, pollIntervalMs]);\n\n return feedSyncState;\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { type Registry } from '@dxos/echo';\n\nimport { useClient } from '../client';\n\n/**\n * Returns the hypergraph registry attached to the current client.\n */\nexport const useRegistry = (): Registry.Registry => {\n const client = useClient();\n return client.graph.registry;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,IAAa,YAAY,YAAqD;CAE5E,MAAM,SAAS,uBADA,UACgC,CAAA,CAAO,MAAM;CAC5D,IAAI,CAAC,SACH;CAGF,OAAO,OAAO,MAAM,UAAU;EAC5B,IAAI,mBAAmB,WACrB,OAAO,MAAM,IAAI,OAAO,OAAO;EAGjC,OAAO,MAAM,OAAO;CACtB,CAAC;AACH;;;;;;;AAeA,IAAa,aAAa,EAAE,MAAM,UAA0B,CAAC,MAAe;CAK1E,OAHe,uBADA,UACgC,CAAA,CAAO,MAG/C,CAAA,CAAO,QAAQ,UAAU,OAAO,MAAM,MAAM,IAAI,MAAM,WAAW,WAAW;AACrF;;;AC7CA,IAAa,cAAc,aAAuD;CAEhF,MAAM,SAAS,UAAU,EAAE,KAAK,KAAK,CAAC;CAOtC,QADgB,wBALF,WACV,OAAO,MAAM,UAAW,oBAAoB,YAAY,MAAM,IAAI,OAAO,QAAQ,IAAI,MAAM,OAAO,QAAS,IAC3G,KAAA,EAAA,EAG0C,WAAW,oBAAoB,MAAM,CAAC,KAAK,CAAC,EAAA,CAC3E,QAAQ,WAAW,OAAO,SAAS,gBAAgB,KAAK,OAAO;AAChF;;;ACLA,IAAa,uBAAuB,YAAqE;CAEvG,OAAO,uBADO,SAAS,OACO,CAAA,EAAO,eAAe,oBAAoB,MAAM,CAAC,KAAK,CAAC;AACvF;AAIA,IAAa,sBAAsB,SAA+B,iBAA0B;CAC1F,MAAM,cAAc,oBAAoB,OAAO;CAK/C,OAAO,oBAJY,cACX,YAAY,MAAM,eAAe,WAAW,IAAI,CAAC,CAAC,iBAAiB,YAAY,GACrF,CAAC,WAAW,CAEa,CAAU;AACvC;;;;;;;;;;;ACVA,IAAa,sBACX,YACuF;CACvF,MAAM,QAAQ,SAAS,OAAO;CAG9B,OAAO,UAFY,uBAAuB,OAAO,SA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,CAAG,QACvC,KAAK,UAAU;MACd,IAAI,WAAW,OAAO,MAAM,gBAAgB,CAAC,IAAI,OAAO,MAAM,gBAAgB,CAAC;MAC/E,IAAI,SAAS,OAAO,MAAM,eAAe,CAAC;MAC1C,OAAO;KACT,GACA;MAAE,SAAS;MAAG,OAAO;KAAE,CACzB;KACA,OAAO,CAAC,MAAM,IAAI,KAAK;IACzB,QAAQ;KACN,OAAO,CAAC,MAAM,IAAI;MAAE,SAAS;MAAG,OAAO;KAAE,CAAC;IAC5C;GACF,CAAC,CACH;GAEA,IAAI,CAAC,WACH,iBAAiB,OAAO,YAAY,OAAO,CAAC;EAEhD;EAEA,KAAU;EACV,MAAM,WAAW,kBAAkB,KAAK,KAAK,GAAG,cAAc;EAE9D,MAAM,qBAAqB,OAAO,OAAO,gBAAgB;GACvD,KAAU;EACZ,CAAC;EAED,aAAa;GACX,YAAY;GACZ,cAAc,QAAQ;GACtB,mBAAmB,YAAY;EACjC;CACF,GAAG,CAAC,QAAQ,cAAc,CAAC;CAE3B,OAAO;AACT;;;;;;AClEA,IAAa,oBAAuC;CAElD,OADe,UACR,CAAA,CAAO,MAAM;AACtB"}
|
|
1
|
+
{"version":3,"file":"echo.mjs","names":[],"sources":["../../src/echo/useSpaces.ts","../../src/echo/useMembers.ts","../../src/echo/useSpaceInvitations.ts","../../src/echo/useSpaceProperties.ts","../../src/echo/useFlush.ts","../../src/echo/useSubscription.ts","../../src/echo/useSyncState.ts","../../src/echo/useFeedSyncState.ts","../../src/echo/useRegistry.ts"],"sourcesContent":["//\n// Copyright 2020 DXOS.org\n//\n\nimport { PublicKey } from '@dxos/client';\nimport { type Space, SpaceState } from '@dxos/client/echo';\nimport { type SpaceId } from '@dxos/keys';\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\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 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 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/keys';\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 2025 DXOS.org\n//\n\nimport { useCallback, useRef, useState } from 'react';\n\nimport { type Space } from '@dxos/client/echo';\n\n/**\n * Flushes a space's database to storage, exposing a transient `idle → flushing → flushed → idle`\n * state suitable for driving a toolbar affordance.\n */\nexport const useFlush = (space?: Space) => {\n const [state, setState] = useState<'idle' | 'flushing' | 'flushed'>('idle');\n const resetTimer = useRef<NodeJS.Timeout | null>(null);\n\n const handleFlush = useCallback(() => {\n if (!space) {\n return;\n }\n\n queueMicrotask(async () => {\n if (resetTimer.current) {\n clearTimeout(resetTimer.current);\n }\n\n setState('flushing');\n await space.db.flush();\n setState('flushed');\n\n resetTimer.current = setTimeout(() => {\n setState('idle');\n resetTimer.current = null;\n }, 1_000);\n });\n }, [space]);\n\n return { state, handleFlush };\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 { isEdgePeerId } from '@dxos/echo-protocol';\n\nimport { useClient } from '../client';\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.subscribeToAutomergeSyncState(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.subscribeToAutomergeSyncState(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","//\n// Copyright 2026 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type SpaceId } from '@dxos/keys';\n\nimport { useClient } from '../client';\n\nconst DEFAULT_POLL_INTERVAL_MS = 5_000;\n\nexport type FeedSyncState = {\n /** Combined blocks to pull + push across namespaces. */\n pending: number;\n /** Total blocks stored locally across namespaces. */\n total: number;\n};\n\nexport type FeedSyncStateMap = Record<SpaceId, FeedSyncState>;\n\n/**\n * Polls feed replication state per space.\n */\nexport const useFeedSyncState = (pollIntervalMs = DEFAULT_POLL_INTERVAL_MS): FeedSyncStateMap => {\n const client = useClient();\n const [feedSyncState, setFeedSyncState] = useState<FeedSyncStateMap>({});\n\n useEffect(() => {\n const feedService = client.services.services.FeedService;\n if (!feedService) {\n return;\n }\n\n let cancelled = false;\n\n const poll = async () => {\n const spaces = client.spaces.get();\n const entries = await Promise.all(\n spaces.map(async (space) => {\n try {\n const response = await feedService.getSyncState({ spaceId: space.id });\n const state = (response.namespaces ?? []).reduce<FeedSyncState>(\n (acc, entry) => {\n acc.pending += Number(entry.blocksToPull ?? 0) + Number(entry.blocksToPush ?? 0);\n acc.total += Number(entry.totalBlocks ?? 0);\n return acc;\n },\n { pending: 0, total: 0 },\n );\n return [space.id, state] as const;\n } catch {\n return [space.id, { pending: 0, total: 0 }] as const;\n }\n }),\n );\n\n if (!cancelled) {\n setFeedSyncState(Object.fromEntries(entries));\n }\n };\n\n void poll();\n const interval = setInterval(() => void poll(), pollIntervalMs);\n\n const spacesSubscription = client.spaces.subscribe(() => {\n void poll();\n });\n\n return () => {\n cancelled = true;\n clearInterval(interval);\n spacesSubscription.unsubscribe();\n };\n }, [client, pollIntervalMs]);\n\n return feedSyncState;\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { type Registry } from '@dxos/echo';\n\nimport { useClient } from '../client';\n\n/**\n * Returns the hypergraph registry attached to the current client.\n */\nexport const useRegistry = (): Registry.Registry => {\n const client = useClient();\n return client.graph.registry;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,IAAa,YAAY,YAAqD;CAC5E,MAAM,SAAS,UAAU;CACzB,MAAM,SAAS,uBAAgC,OAAO,MAAM;CAC5D,IAAI,CAAC,SACH;CAGF,OAAO,OAAO,MAAM,UAAU;EAC5B,IAAI,mBAAmB,WACrB,OAAO,MAAM,IAAI,OAAO,OAAO;EAGjC,OAAO,MAAM,OAAO;CACtB,CAAC;AACH;;;;;;;AAeA,IAAa,aAAa,EAAE,MAAM,UAA0B,CAAC,MAAe;CAC1E,MAAM,SAAS,UAAU;CAIzB,OAHe,uBAAgC,OAAO,MAG/C,CAAA,CAAO,QAAQ,UAAU,OAAO,MAAM,MAAM,IAAI,MAAM,WAAW,WAAW;AACrF;;;AC7CA,IAAa,cAAc,aAAuD;CAEhF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AAqB,OAAO,OAAO,gBAAgB;GACvD,KAAU;EACZ,CAAC;EAED,aAAa;GACX,YAAY;GACZ,cAAc,QAAQ;GACtB,mBAAmB,YAAY;EACjC;CACF,GAAG,CAAC,QAAQ,cAAc,CAAC;CAE3B,OAAO;AACT;;;;;;AClEA,IAAa,oBAAuC;CAElD,OADe,UACR,CAAA,CAAO,MAAM;AACtB"}
|
package/dist/lib/halo.mjs
CHANGED
|
@@ -10,26 +10,31 @@ import { Device, DeviceKind, DeviceType } from "@dxos/client/halo";
|
|
|
10
10
|
* Requires ClientContext to be set via ClientProvider.
|
|
11
11
|
*/
|
|
12
12
|
var useContacts = () => {
|
|
13
|
-
|
|
13
|
+
const client = useClient();
|
|
14
|
+
return useMulticastObservable(client.halo.contacts);
|
|
14
15
|
};
|
|
15
16
|
//#endregion
|
|
16
17
|
//#region src/halo/useCredentials.ts
|
|
17
18
|
var useCredentials = () => {
|
|
18
|
-
|
|
19
|
+
const client = useClient();
|
|
20
|
+
return useMulticastObservable(client.halo.credentials);
|
|
19
21
|
};
|
|
20
22
|
//#endregion
|
|
21
23
|
//#region src/halo/useDevices.ts
|
|
22
24
|
var useDevices = () => {
|
|
23
|
-
|
|
25
|
+
const client = useClient();
|
|
26
|
+
return useMulticastObservable(client.halo.devices);
|
|
24
27
|
};
|
|
25
28
|
//#endregion
|
|
26
29
|
//#region src/halo/useHaloInvitations.ts
|
|
27
30
|
var useHaloInvitations = () => {
|
|
28
|
-
|
|
31
|
+
const client = useClient();
|
|
32
|
+
return useMulticastObservable(client.halo.invitations);
|
|
29
33
|
};
|
|
30
34
|
var useHaloInvitation = (invitationId) => {
|
|
31
35
|
const invitations = useHaloInvitations();
|
|
32
|
-
|
|
36
|
+
const invitation = useMemo(() => invitations.find((invitation) => invitation.get().invitationId === invitationId), [invitations]);
|
|
37
|
+
return useInvitationStatus(invitation);
|
|
33
38
|
};
|
|
34
39
|
//#endregion
|
|
35
40
|
//#region src/halo/useIdentity.ts
|
|
@@ -38,7 +43,8 @@ var useHaloInvitation = (invitationId) => {
|
|
|
38
43
|
* Requires ClientContext to be set via ClientProvider.
|
|
39
44
|
*/
|
|
40
45
|
var useIdentity = () => {
|
|
41
|
-
|
|
46
|
+
const client = useClient();
|
|
47
|
+
return useMulticastObservable(client.halo.identity);
|
|
42
48
|
};
|
|
43
49
|
//#endregion
|
|
44
50
|
//#region src/halo/useKeyStore.ts
|
package/dist/lib/halo.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"halo.mjs","names":[],"sources":["../../src/halo/useContacts.ts","../../src/halo/useCredentials.ts","../../src/halo/useDevices.ts","../../src/halo/useHaloInvitations.ts","../../src/halo/useIdentity.ts","../../src/halo/useKeyStore.ts"],"sourcesContent":["//\n// Copyright 2020 DXOS.org\n//\n\nimport type { Contact } from '@dxos/client/halo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client';\n\n/**\n * Returns all known Contacts across all Spaces.\n * Contacts are known members of a common Space.\n * Requires ClientContext to be set via ClientProvider.\n */\nexport const useContacts = (): Contact[] => {\n const client = useClient();\n return useMulticastObservable(client.halo.contacts);\n};\n","//\n// Copyright 2020 DXOS.org\n//\n\nimport type { Credential } from '@dxos/client/halo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client';\n\nexport const useCredentials = (): Credential[] => {\n const client = useClient();\n return useMulticastObservable(client.halo.credentials);\n};\n","//\n// Copyright 2020 DXOS.org\n//\n\nimport type { Device } from '@dxos/client/halo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client';\n\nexport const useDevices = (): Device[] => {\n const client = useClient();\n return useMulticastObservable(client.halo.devices);\n};\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport { useMemo } from 'react';\n\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client';\nimport { type CancellableInvitationObservable, useInvitationStatus } from '../invitations';\n\nexport const useHaloInvitations = (): CancellableInvitationObservable[] => {\n const client = useClient();\n return useMulticastObservable(client.halo.invitations);\n};\n\nexport const useHaloInvitation = (invitationId?: string) => {\n const invitations = useHaloInvitations();\n const invitation = useMemo(\n () => invitations.find((invitation) => invitation.get().invitationId === invitationId),\n [invitations],\n );\n return useInvitationStatus(invitation);\n};\n","//\n// Copyright 2020 DXOS.org\n//\n\nimport { type Identity } from '@dxos/client/halo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client';\n\n/**\n * Hook returning DXOS identity object.\n * Requires ClientContext to be set via ClientProvider.\n */\nexport const useIdentity = (): Identity | null => {\n const client = useClient();\n return useMulticastObservable(client.halo.identity);\n};\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport { useMemo, useReducer } from 'react';\n\n// TODO(burdon): Move to settings plugin.\nexport class KeyStore {\n private _keyMap = new Map<string, string>();\n\n constructor(private readonly _defaultKeys: string[] = []) {}\n\n get map() {\n return this._keyMap;\n }\n\n // TODO(burdon): Create subkeys.\n initialize(): this {\n this._defaultKeys.forEach((key) => {\n const value = localStorage.getItem(key);\n this.setKey(key, value ?? '');\n });\n\n return this;\n }\n\n getKey(key: string): void {\n localStorage.getItem(key);\n }\n\n setKey(key: string, value: string): void {\n localStorage.setItem(key, '');\n this._keyMap.set(key, value);\n }\n}\n\n/**\n * Settings store.\n * @deprecated Replace with HALO key store when available.\n */\nexport const useKeyStore = (\n defaultKeys: string[] = [],\n): [Map<string, string>, (key: string, value: string) => void] => {\n const [, forceUpdate] = useReducer((x) => x + 1, 0);\n const store = useMemo(() => new KeyStore(defaultKeys).initialize(), [defaultKeys]);\n const setKey = (key: string, value: string) => {\n store.setKey(key, value);\n forceUpdate();\n };\n\n return [store.map, setKey];\n};\n"],"mappings":";;;;;;;;;;;AAcA,IAAa,oBAA+B;
|
|
1
|
+
{"version":3,"file":"halo.mjs","names":[],"sources":["../../src/halo/useContacts.ts","../../src/halo/useCredentials.ts","../../src/halo/useDevices.ts","../../src/halo/useHaloInvitations.ts","../../src/halo/useIdentity.ts","../../src/halo/useKeyStore.ts"],"sourcesContent":["//\n// Copyright 2020 DXOS.org\n//\n\nimport type { Contact } from '@dxos/client/halo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client';\n\n/**\n * Returns all known Contacts across all Spaces.\n * Contacts are known members of a common Space.\n * Requires ClientContext to be set via ClientProvider.\n */\nexport const useContacts = (): Contact[] => {\n const client = useClient();\n return useMulticastObservable(client.halo.contacts);\n};\n","//\n// Copyright 2020 DXOS.org\n//\n\nimport type { Credential } from '@dxos/client/halo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client';\n\nexport const useCredentials = (): Credential[] => {\n const client = useClient();\n return useMulticastObservable(client.halo.credentials);\n};\n","//\n// Copyright 2020 DXOS.org\n//\n\nimport type { Device } from '@dxos/client/halo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client';\n\nexport const useDevices = (): Device[] => {\n const client = useClient();\n return useMulticastObservable(client.halo.devices);\n};\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport { useMemo } from 'react';\n\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client';\nimport { type CancellableInvitationObservable, useInvitationStatus } from '../invitations';\n\nexport const useHaloInvitations = (): CancellableInvitationObservable[] => {\n const client = useClient();\n return useMulticastObservable(client.halo.invitations);\n};\n\nexport const useHaloInvitation = (invitationId?: string) => {\n const invitations = useHaloInvitations();\n const invitation = useMemo(\n () => invitations.find((invitation) => invitation.get().invitationId === invitationId),\n [invitations],\n );\n return useInvitationStatus(invitation);\n};\n","//\n// Copyright 2020 DXOS.org\n//\n\nimport { type Identity } from '@dxos/client/halo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client';\n\n/**\n * Hook returning DXOS identity object.\n * Requires ClientContext to be set via ClientProvider.\n */\nexport const useIdentity = (): Identity | null => {\n const client = useClient();\n return useMulticastObservable(client.halo.identity);\n};\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport { useMemo, useReducer } from 'react';\n\n// TODO(burdon): Move to settings plugin.\nexport class KeyStore {\n private _keyMap = new Map<string, string>();\n\n constructor(private readonly _defaultKeys: string[] = []) {}\n\n get map() {\n return this._keyMap;\n }\n\n // TODO(burdon): Create subkeys.\n initialize(): this {\n this._defaultKeys.forEach((key) => {\n const value = localStorage.getItem(key);\n this.setKey(key, value ?? '');\n });\n\n return this;\n }\n\n getKey(key: string): void {\n localStorage.getItem(key);\n }\n\n setKey(key: string, value: string): void {\n localStorage.setItem(key, '');\n this._keyMap.set(key, value);\n }\n}\n\n/**\n * Settings store.\n * @deprecated Replace with HALO key store when available.\n */\nexport const useKeyStore = (\n defaultKeys: string[] = [],\n): [Map<string, string>, (key: string, value: string) => void] => {\n const [, forceUpdate] = useReducer((x) => x + 1, 0);\n const store = useMemo(() => new KeyStore(defaultKeys).initialize(), [defaultKeys]);\n const setKey = (key: string, value: string) => {\n store.setKey(key, value);\n forceUpdate();\n };\n\n return [store.map, setKey];\n};\n"],"mappings":";;;;;;;;;;;AAcA,IAAa,oBAA+B;CAC1C,MAAM,SAAS,UAAU;CACzB,OAAO,uBAAuB,OAAO,KAAK,QAAQ;AACpD;;;ACRA,IAAa,uBAAqC;CAChD,MAAM,SAAS,UAAU;CACzB,OAAO,uBAAuB,OAAO,KAAK,WAAW;AACvD;;;ACHA,IAAa,mBAA6B;CACxC,MAAM,SAAS,UAAU;CACzB,OAAO,uBAAuB,OAAO,KAAK,OAAO;AACnD;;;ACDA,IAAa,2BAA8D;CACzE,MAAM,SAAS,UAAU;CACzB,OAAO,uBAAuB,OAAO,KAAK,WAAW;AACvD;AAEA,IAAa,qBAAqB,iBAA0B;CAC1D,MAAM,cAAc,mBAAmB;CACvC,MAAM,aAAa,cACX,YAAY,MAAM,eAAe,WAAW,IAAI,CAAC,CAAC,iBAAiB,YAAY,GACrF,CAAC,WAAW,CACd;CACA,OAAO,oBAAoB,UAAU;AACvC;;;;;;;ACVA,IAAa,oBAAqC;CAChD,MAAM,SAAS,UAAU;CACzB,OAAO,uBAAuB,OAAO,KAAK,QAAQ;AACpD;;;ACTA,IAAa,WAAb,MAAsB;CAGS;CAF7B,0BAAkB,IAAI,IAAoB;CAE1C,YAAY,eAA0C,CAAC,GAAG;EAA7B,KAAA,eAAA;CAA8B;CAE3D,IAAI,MAAM;EACR,OAAO,KAAK;CACd;CAGA,aAAmB;EACjB,KAAK,aAAa,SAAS,QAAQ;GACjC,MAAM,QAAQ,aAAa,QAAQ,GAAG;GACtC,KAAK,OAAO,KAAK,SAAS,EAAE;EAC9B,CAAC;EAED,OAAO;CACT;CAEA,OAAO,KAAmB;EACxB,aAAa,QAAQ,GAAG;CAC1B;CAEA,OAAO,KAAa,OAAqB;EACvC,aAAa,QAAQ,KAAK,EAAE;EAC5B,KAAK,QAAQ,IAAI,KAAK,KAAK;CAC7B;AACF;;;;;AAMA,IAAa,eACX,cAAwB,CAAC,MACuC;CAChE,MAAM,GAAG,eAAe,YAAY,MAAM,IAAI,GAAG,CAAC;CAClD,MAAM,QAAQ,cAAc,IAAI,SAAS,WAAW,CAAC,CAAC,WAAW,GAAG,CAAC,WAAW,CAAC;CACjF,MAAM,UAAU,KAAa,UAAkB;EAC7C,MAAM,OAAO,KAAK,KAAK;EACvB,YAAY;CACd;CAEA,OAAO,CAAC,MAAM,KAAK,MAAM;AAC3B"}
|
package/dist/lib/index.mjs
CHANGED
|
@@ -17,7 +17,8 @@ var __dxlog_file = "/__w/dxos/dxos/packages/sdk/react-client/src/client/AgentHos
|
|
|
17
17
|
* @deprecated
|
|
18
18
|
*/
|
|
19
19
|
var AgentHostingProvider = (props) => {
|
|
20
|
-
const
|
|
20
|
+
const client = useClient();
|
|
21
|
+
const [agentHostingProviderClient] = useState(makeClient(client));
|
|
21
22
|
return /* @__PURE__ */ jsxs(AgentHostingContext.Provider, {
|
|
22
23
|
value: agentHostingProviderClient,
|
|
23
24
|
children: [" ", props.children]
|
package/dist/lib/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/client/AgentHostingProvider.tsx","../../src/client/useClientStatus.ts","../../src/client/useConfig.ts","../../src/client/useShell.ts","../../src/client/useStatus.ts"],"sourcesContent":["//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { type PropsWithChildren, useState } from 'react';\n\nimport { type AgentHostingProviderClient, AgentManagerClient, FakeAgentHostingProvider } from '@dxos/client';\nimport { type Halo } from '@dxos/client/halo';\nimport { type Config } from '@dxos/config';\nimport { log } from '@dxos/log';\n\n// Imported from the defining module, not the directory barrel: `'../client'` is this file's own\n// barrel, and that cycle made every downstream edit a full page reload.\nimport { AgentHostingContext } from './context';\nimport { useClient } from './useClient';\n\nexport type AgentHostingProviderProps = { config: Config; halo: Halo };\n\n/**\n * Experimental agent hosting provider.\n * @param props\n * @constructor\n * @deprecated\n */\nexport const AgentHostingProvider = (props: PropsWithChildren) => {\n const client = useClient();\n const [agentHostingProviderClient] = useState(makeClient(client));\n return (\n <AgentHostingContext.Provider value={agentHostingProviderClient}> {props.children}</AgentHostingContext.Provider>\n );\n};\n\nconst makeClient = ({ config, halo }: AgentHostingProviderProps) => {\n const agentHostingConfig = config.get('runtime.services.agentHosting');\n if (!agentHostingConfig) {\n log('no agent hosting configured');\n return null;\n }\n\n // TODO(nf): Dynamically discover based on runtime config.\n let agentHostingProviderClient: AgentHostingProviderClient | null = null;\n switch (agentHostingConfig.type) {\n case 'LOCAL_TESTING': {\n log('using FakeAgentHostingProvider');\n return new FakeAgentHostingProvider();\n }\n\n case 'AGENTHOSTING_API': {\n agentHostingProviderClient = new AgentManagerClient(config, halo);\n if (agentHostingProviderClient.init()) {\n return agentHostingProviderClient;\n } else {\n // Not authorized or error initializing.\n return null;\n }\n }\n\n default: {\n log.error('Unknown agent hosting provider type: ' + agentHostingConfig.type);\n return null;\n }\n }\n};\n","//\n// Copyright 2024 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type Client, type SystemStatus } from '@dxos/client';\n\nexport const useClientStatus = (client: Client) => {\n const [status, setStatus] = useState<SystemStatus | null>();\n useEffect(() => {\n if (!client) {\n return;\n }\n\n const subscription = client.status.subscribe((status) => setStatus(status));\n return () => subscription.unsubscribe();\n }, [client, setStatus]);\n\n return status;\n};\n","//\n// Copyright 2020 DXOS.org\n//\n\nimport { useContext } from 'react';\n\nimport { raise } from '@dxos/debug';\n\nimport { ClientContext } from './context';\n\n/**\n * Hook returning config object used to initialize the DXOS client instance.\n * Requires ClientContext to be set via ClientProvider.\n */\nexport const useConfig = () => {\n const { client } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));\n return client.config;\n};\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type Shell, type ShellDisplay } from '@dxos/client';\n\nimport { useClient } from './useClient';\n\n/**\n * Helper hook to access the shell.\n */\nexport const useShell = (): Shell => {\n const client = useClient();\n return client.shell;\n};\n\n/**\n * Hook to access the shell’s display state.\n */\nexport const useShellDisplay = (): ShellDisplay => {\n const client = useClient();\n const [display, setDisplay] = useState(client.shell.display);\n useEffect(() => client.shell.onDisplayChange(setDisplay), [client]);\n return display;\n};\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport { useContext } from 'react';\n\nimport { type SystemStatus } from '@dxos/client';\nimport { raise } from '@dxos/debug';\n\nimport { ClientContext } from './context';\n\nexport const useStatus = (): SystemStatus | null | undefined => {\n const { status } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));\n return status;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwBA,IAAa,wBAAwB,UAA6B;
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/client/AgentHostingProvider.tsx","../../src/client/useClientStatus.ts","../../src/client/useConfig.ts","../../src/client/useShell.ts","../../src/client/useStatus.ts"],"sourcesContent":["//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { type PropsWithChildren, useState } from 'react';\n\nimport { type AgentHostingProviderClient, AgentManagerClient, FakeAgentHostingProvider } from '@dxos/client';\nimport { type Halo } from '@dxos/client/halo';\nimport { type Config } from '@dxos/config';\nimport { log } from '@dxos/log';\n\n// Imported from the defining module, not the directory barrel: `'../client'` is this file's own\n// barrel, and that cycle made every downstream edit a full page reload.\nimport { AgentHostingContext } from './context';\nimport { useClient } from './useClient';\n\nexport type AgentHostingProviderProps = { config: Config; halo: Halo };\n\n/**\n * Experimental agent hosting provider.\n * @param props\n * @constructor\n * @deprecated\n */\nexport const AgentHostingProvider = (props: PropsWithChildren) => {\n const client = useClient();\n const [agentHostingProviderClient] = useState(makeClient(client));\n return (\n <AgentHostingContext.Provider value={agentHostingProviderClient}> {props.children}</AgentHostingContext.Provider>\n );\n};\n\nconst makeClient = ({ config, halo }: AgentHostingProviderProps) => {\n const agentHostingConfig = config.get('runtime.services.agentHosting');\n if (!agentHostingConfig) {\n log('no agent hosting configured');\n return null;\n }\n\n // TODO(nf): Dynamically discover based on runtime config.\n let agentHostingProviderClient: AgentHostingProviderClient | null = null;\n switch (agentHostingConfig.type) {\n case 'LOCAL_TESTING': {\n log('using FakeAgentHostingProvider');\n return new FakeAgentHostingProvider();\n }\n\n case 'AGENTHOSTING_API': {\n agentHostingProviderClient = new AgentManagerClient(config, halo);\n if (agentHostingProviderClient.init()) {\n return agentHostingProviderClient;\n } else {\n // Not authorized or error initializing.\n return null;\n }\n }\n\n default: {\n log.error('Unknown agent hosting provider type: ' + agentHostingConfig.type);\n return null;\n }\n }\n};\n","//\n// Copyright 2024 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type Client, type SystemStatus } from '@dxos/client';\n\nexport const useClientStatus = (client: Client) => {\n const [status, setStatus] = useState<SystemStatus | null>();\n useEffect(() => {\n if (!client) {\n return;\n }\n\n const subscription = client.status.subscribe((status) => setStatus(status));\n return () => subscription.unsubscribe();\n }, [client, setStatus]);\n\n return status;\n};\n","//\n// Copyright 2020 DXOS.org\n//\n\nimport { useContext } from 'react';\n\nimport { raise } from '@dxos/debug';\n\nimport { ClientContext } from './context';\n\n/**\n * Hook returning config object used to initialize the DXOS client instance.\n * Requires ClientContext to be set via ClientProvider.\n */\nexport const useConfig = () => {\n const { client } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));\n return client.config;\n};\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type Shell, type ShellDisplay } from '@dxos/client';\n\nimport { useClient } from './useClient';\n\n/**\n * Helper hook to access the shell.\n */\nexport const useShell = (): Shell => {\n const client = useClient();\n return client.shell;\n};\n\n/**\n * Hook to access the shell’s display state.\n */\nexport const useShellDisplay = (): ShellDisplay => {\n const client = useClient();\n const [display, setDisplay] = useState(client.shell.display);\n useEffect(() => client.shell.onDisplayChange(setDisplay), [client]);\n return display;\n};\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport { useContext } from 'react';\n\nimport { type SystemStatus } from '@dxos/client';\nimport { raise } from '@dxos/debug';\n\nimport { ClientContext } from './context';\n\nexport const useStatus = (): SystemStatus | null | undefined => {\n const { status } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));\n return status;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwBA,IAAa,wBAAwB,UAA6B;CAChE,MAAM,SAAS,UAAU;CACzB,MAAM,CAAC,8BAA8B,SAAS,WAAW,MAAM,CAAC;CAChE,OACE,qBAAC,oBAAoB,UAArB;EAA8B,OAAO;EAArC,UAAA,CAAiE,KAAE,MAAM,QAAuC;;AAEpH;AAEA,IAAM,cAAc,EAAE,QAAQ,WAAsC;CAClE,MAAM,qBAAqB,OAAO,IAAI,+BAA+B;CACrE,IAAI,CAAC,oBAAoB;EACvB,IAAI,+BAA4B,KAAA,GAAA;GAAA,YAAA;GAAA,GAAA;GAAA,GAAA;GAAA,GAAA,KAAA;EAAA,CAAC;EACjC,OAAO;CACT;CAGA,IAA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(observable) => {
|
|
|
73
73
|
});
|
|
74
74
|
break;
|
|
75
75
|
case Invitation$1.State.CANCELLED:
|
|
76
|
-
case Invitation$1.State.TIMEOUT:
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
});
|
|
82
|
-
break;
|
|
76
|
+
case Invitation$1.State.TIMEOUT: dispatch({
|
|
77
|
+
invitation,
|
|
78
|
+
status: invitation.state,
|
|
79
|
+
haltedAt: state.status
|
|
80
|
+
});
|
|
83
81
|
}
|
|
84
82
|
};
|
|
85
83
|
const subscription = observable?.subscribe(update, (err) => {
|