@dxos/react-client 0.8.4-main.c1de068 → 0.8.4-main.c4373fc
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 +11 -0
- package/.storybook/preview.mts +8 -0
- package/.swc/plugins/linux_x86_64_19.0.0/727453fb3a62f7f1d952a41e051ca8a6f88cadc45cee43c6a4d1aa45f9b75665.wasmer-v7 +0 -0
- package/dist/lib/browser/{chunk-O5SEVDJG.mjs → chunk-LO3TU5CK.mjs} +5 -5
- package/dist/lib/browser/chunk-LO3TU5CK.mjs.map +7 -0
- package/dist/lib/browser/{chunk-AAR7V3KL.mjs → chunk-TA2HGRAF.mjs} +64 -67
- package/dist/lib/browser/chunk-TA2HGRAF.mjs.map +7 -0
- package/dist/lib/browser/devtools/index.mjs +2 -2
- package/dist/lib/browser/devtools/index.mjs.map +3 -3
- package/dist/lib/browser/echo/index.mjs +22 -22
- package/dist/lib/browser/echo/index.mjs.map +3 -3
- package/dist/lib/browser/halo/index.mjs +21 -6
- package/dist/lib/browser/halo/index.mjs.map +3 -3
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/invitations/index.mjs +1 -1
- package/dist/lib/browser/mesh/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +51 -50
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/{chunk-TU2JJLZK.mjs → chunk-AQJH2UNZ.mjs} +5 -5
- package/dist/lib/node-esm/chunk-AQJH2UNZ.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-ZTD6HPV2.mjs → chunk-ZJMNF7GC.mjs} +64 -67
- package/dist/lib/node-esm/chunk-ZJMNF7GC.mjs.map +7 -0
- package/dist/lib/node-esm/devtools/index.mjs +2 -2
- package/dist/lib/node-esm/devtools/index.mjs.map +3 -3
- package/dist/lib/node-esm/echo/index.mjs +22 -22
- package/dist/lib/node-esm/echo/index.mjs.map +3 -3
- package/dist/lib/node-esm/halo/index.mjs +21 -6
- package/dist/lib/node-esm/halo/index.mjs.map +3 -3
- package/dist/lib/node-esm/index.mjs +1 -1
- package/dist/lib/node-esm/invitations/index.mjs +1 -1
- package/dist/lib/node-esm/mesh/index.mjs +1 -1
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +51 -50
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/client/AgentHostingProvider.d.ts.map +1 -1
- package/dist/types/src/client/ClientProvider.d.ts.map +1 -1
- package/dist/types/src/echo/useQuery.d.ts +3 -3
- package/dist/types/src/echo/useQuery.d.ts.map +1 -1
- package/dist/types/src/echo/useSchema.d.ts +1 -1
- package/dist/types/src/echo/useSchema.d.ts.map +1 -1
- package/dist/types/src/echo/useSpaceInvitations.d.ts.map +1 -1
- 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 +1 -1
- package/dist/types/src/echo/useSyncState.d.ts.map +1 -1
- package/dist/types/src/halo/Passkey.stories.d.ts +5 -5
- package/dist/types/src/halo/Passkey.stories.d.ts.map +1 -1
- package/dist/types/src/halo/useHaloInvitations.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 +2 -2
- package/dist/types/src/testing/ClientRepeater.d.ts.map +1 -1
- package/dist/types/src/testing/ClientRepeater.stories.d.ts +6 -10
- package/dist/types/src/testing/ClientRepeater.stories.d.ts.map +1 -1
- package/dist/types/src/testing/withClientProvider.d.ts +6 -7
- package/dist/types/src/testing/withClientProvider.d.ts.map +1 -1
- package/dist/types/src/testing/withClientProvider.stories.d.ts +7 -9
- package/dist/types/src/testing/withClientProvider.stories.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/moon.yml +4 -0
- package/package.json +38 -31
- package/src/client/AgentHostingProvider.tsx +1 -1
- package/src/client/ClientProvider.test.tsx +3 -2
- package/src/client/ClientProvider.tsx +33 -36
- package/src/client/useConfig.test.tsx +2 -1
- package/src/devtools/useStream.ts +1 -1
- package/src/echo/useQuery.test.tsx +9 -8
- package/src/echo/useQuery.ts +28 -12
- package/src/echo/useSchema.ts +2 -2
- package/src/echo/useSpaceInvitations.ts +2 -1
- package/src/echo/useSpaces.test.tsx +2 -1
- package/src/echo/useSpaces.ts +5 -9
- package/src/echo/useSubscription.ts +1 -1
- package/src/echo/useSyncState.ts +1 -1
- package/src/halo/Passkey.stories.tsx +16 -13
- package/src/halo/useDevices.test.tsx +2 -1
- package/src/halo/useHaloInvitations.ts +1 -1
- package/src/invitations/useInvitationStatus.ts +9 -8
- package/src/testing/ClientRepeater.stories.tsx +12 -8
- package/src/testing/ClientRepeater.tsx +23 -27
- package/src/testing/withClientProvider.stories.tsx +30 -19
- package/src/testing/withClientProvider.tsx +24 -21
- package/tsconfig.json +0 -3
- package/vitest.config.ts +12 -16
- package/.swc/plugins/v7_linux_x86_64_13.0.0/f45bdff002284d9e8f9ef3f0be909de12da36c049cbcf261ac78fc00abb09a2d +0 -0
- package/dist/lib/browser/chunk-AAR7V3KL.mjs.map +0 -7
- package/dist/lib/browser/chunk-O5SEVDJG.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-TU2JJLZK.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ZTD6HPV2.mjs.map +0 -7
|
Binary file
|
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
import { AuthenticatingInvitationObservable, CancellableInvitationObservable, InvitationEncoder as InvitationEncoder2, Invitation as Invitation2, InvitationsProxy } from "@dxos/client/invitations";
|
|
3
3
|
|
|
4
4
|
// src/invitations/useInvitationStatus.ts
|
|
5
|
-
import {
|
|
5
|
+
import { useCallback, useEffect, useMemo, useReducer } from "react";
|
|
6
6
|
import { Invitation, InvitationEncoder } from "@dxos/client/invitations";
|
|
7
7
|
import { log } from "@dxos/log";
|
|
8
8
|
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/react-client/src/invitations/useInvitationStatus.ts";
|
|
9
|
-
var isShareableInvitation = (invitation) => invitation.authMethod !== Invitation.AuthMethod.KNOWN_PUBLIC_KEY || invitation.guestKeypair?.privateKey;
|
|
9
|
+
var isShareableInvitation = (invitation) => invitation.authMethod !== Invitation.AuthMethod.KNOWN_PUBLIC_KEY || !!invitation.guestKeypair?.privateKey;
|
|
10
10
|
var useInvitationStatus = (observable) => {
|
|
11
11
|
const [state, dispatch] = useReducer((prev, action) => {
|
|
12
12
|
log("useInvitationStatus", {
|
|
13
13
|
action
|
|
14
14
|
}, {
|
|
15
15
|
F: __dxlog_file,
|
|
16
|
-
L:
|
|
16
|
+
L: 91,
|
|
17
17
|
S: void 0,
|
|
18
18
|
C: (f, a) => f(...a)
|
|
19
19
|
});
|
|
@@ -126,7 +126,7 @@ var useInvitationStatus = (observable) => {
|
|
|
126
126
|
authCode
|
|
127
127
|
}, {
|
|
128
128
|
F: __dxlog_file,
|
|
129
|
-
L:
|
|
129
|
+
L: 196,
|
|
130
130
|
S: void 0,
|
|
131
131
|
C: (f, a) => f(...a)
|
|
132
132
|
});
|
|
@@ -160,4 +160,4 @@ export {
|
|
|
160
160
|
Invitation2 as Invitation,
|
|
161
161
|
InvitationsProxy
|
|
162
162
|
};
|
|
163
|
-
//# sourceMappingURL=chunk-
|
|
163
|
+
//# sourceMappingURL=chunk-LO3TU5CK.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/invitations/index.ts", "../../../src/invitations/useInvitationStatus.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\n// NOTE: Export * fails here.\nexport {\n AuthenticatingInvitationObservable,\n CancellableInvitationObservable,\n InvitationEncoder,\n Invitation,\n type Invitations,\n InvitationsProxy,\n} from '@dxos/client/invitations';\n\nexport * from './useInvitationStatus';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { useCallback, useEffect, useMemo, useReducer } from 'react';\n\nimport { type PublicKey } from '@dxos/client';\nimport {\n type AuthenticatingInvitationObservable,\n type CancellableInvitationObservable,\n Invitation,\n InvitationEncoder,\n} from '@dxos/client/invitations';\nimport { log } from '@dxos/log';\n\nexport type InvitationResult = {\n spaceKey: PublicKey | null;\n identityKey: PublicKey | null;\n swarmKey: PublicKey | null;\n target: string | null;\n};\n\ninterface InvitationReducerState {\n status: Invitation.State; // TODO(burdon): Rename state.\n haltedAt?: Invitation.State;\n result: InvitationResult;\n error?: Error;\n id?: string;\n multiUse?: boolean;\n shareable?: boolean;\n invitationCode?: string;\n authCode?: string;\n authMethod?: Invitation.AuthMethod;\n type?: Invitation.Type;\n}\n\ntype InvitationPayload = { invitation: Invitation };\n\nexport type InvitationAction =\n | ({\n status:\n | Invitation.State.INIT\n | Invitation.State.CONNECTED\n | Invitation.State.READY_FOR_AUTHENTICATION\n | Invitation.State.AUTHENTICATING;\n } & InvitationPayload)\n | ({\n status: Invitation.State.CONNECTING;\n observable: CancellableInvitationObservable;\n } & InvitationPayload)\n | ({\n status: Invitation.State.SUCCESS;\n result: InvitationResult;\n } & InvitationPayload)\n | ({\n status: Invitation.State.CANCELLED | Invitation.State.TIMEOUT;\n haltedAt: Invitation.State;\n } & InvitationPayload)\n | {\n status: Invitation.State.ERROR;\n error?: Error;\n haltedAt: Invitation.State;\n };\n\nexport type InvitationStatus = {\n id?: string;\n invitationCode?: string;\n authCode?: string;\n authMethod?: Invitation.AuthMethod;\n type?: Invitation.Type;\n status: Invitation.State;\n haltedAt?: Invitation.State;\n multiUse?: boolean;\n shareable?: boolean;\n result: InvitationResult;\n error?: Error;\n cancel(): void;\n // TODO(wittjosiah): Remove?\n connect(observable: CancellableInvitationObservable): void;\n authenticate(authCode: string): Promise<void>;\n};\n\n// Without private key, the invitation code cannot be created.\n// These invitations are only available to be accepted but not shared.\nconst isShareableInvitation = (invitation: Invitation) =>\n invitation.authMethod !== Invitation.AuthMethod.KNOWN_PUBLIC_KEY || !!invitation.guestKeypair?.privateKey;\n\nexport const useInvitationStatus = (observable?: CancellableInvitationObservable): InvitationStatus => {\n const [state, dispatch] = useReducer(\n (prev: InvitationReducerState, action: InvitationAction): InvitationReducerState => {\n log('useInvitationStatus', { action });\n const invitationProps =\n 'invitation' in action\n ? {\n id: action.invitation.invitationId,\n multiUse: action.invitation.multiUse,\n invitationCode: InvitationEncoder.encode(action.invitation),\n authCode: action.invitation.authCode,\n authMethod: action.invitation.authMethod,\n shareable: isShareableInvitation(action.invitation),\n type: action.invitation.type,\n }\n : {};\n return {\n ...prev,\n ...invitationProps,\n // TODO(burdon): State.\n status: action.status,\n // `invitationObservable`, `secret`, and `result` is persisted between the status-actions that set them.\n result: action.status === Invitation.State.SUCCESS ? action.result : prev.result,\n // `error` gets set each time we enter the error state\n ...(action.status === Invitation.State.ERROR && { error: action.error }),\n // `haltedAt` gets set on only the first error/cancelled/timeout action and reset on any others.\n ...((action.status === Invitation.State.ERROR ||\n action.status === Invitation.State.CANCELLED ||\n action.status === Invitation.State.TIMEOUT) && {\n haltedAt: typeof prev.haltedAt === 'undefined' ? action.haltedAt : prev.haltedAt,\n }),\n };\n },\n null,\n (_arg: null): InvitationReducerState => {\n const invitation = observable?.get();\n return {\n status: Invitation.State.INIT,\n result: { spaceKey: null, identityKey: null, swarmKey: null, target: null },\n id: invitation?.invitationId,\n multiUse: invitation?.multiUse,\n invitationCode: invitation ? InvitationEncoder.encode(invitation) : undefined,\n authCode: invitation?.authCode,\n authMethod: invitation?.authMethod,\n shareable: invitation ? isShareableInvitation(invitation) : false,\n type: invitation?.type,\n };\n },\n );\n\n // Handle unmount.\n\n useEffect(() => {\n const update = (invitation: Invitation) => {\n switch (invitation.state) {\n case Invitation.State.INIT:\n case Invitation.State.CONNECTED:\n case Invitation.State.READY_FOR_AUTHENTICATION:\n case Invitation.State.AUTHENTICATING: {\n dispatch({\n invitation,\n status: invitation.state,\n });\n break;\n }\n\n case Invitation.State.SUCCESS: {\n dispatch({\n invitation,\n status: invitation.state,\n result: {\n spaceKey: invitation.spaceKey || null,\n identityKey: invitation.identityKey || null,\n swarmKey: invitation.swarmKey || null,\n target: invitation.target || null,\n },\n });\n break;\n }\n\n case Invitation.State.CANCELLED:\n case Invitation.State.TIMEOUT: {\n dispatch({ invitation, status: invitation.state, haltedAt: state.status });\n break;\n }\n }\n };\n\n const subscription = observable?.subscribe(update, (err: Error) => {\n dispatch({ status: Invitation.State.ERROR, error: err, haltedAt: state.status });\n });\n\n const currentState = observable?.get();\n if (currentState) {\n update(currentState);\n }\n\n return () => subscription?.unsubscribe();\n }, [observable, state.status]);\n\n // Return memoized callbacks & values.\n\n const connect = useCallback((observable: CancellableInvitationObservable) => {\n dispatch({ invitation: observable.get(), status: Invitation.State.CONNECTING, observable });\n }, []);\n\n const authenticate = useCallback(\n (authCode: string) => {\n log('authenticating...', { authCode });\n return (observable as AuthenticatingInvitationObservable).authenticate(authCode);\n },\n [observable],\n );\n\n const cancel = useCallback(async () => observable?.cancel(), [observable]);\n\n return useMemo(() => {\n return {\n ...state,\n cancel,\n connect,\n authenticate,\n };\n }, [state, cancel, connect, authenticate]);\n};\n"],
|
|
5
|
+
"mappings": ";AAKA,SACEA,oCACAC,iCACAC,qBAAAA,oBACAC,cAAAA,aAEAC,wBACK;;;ACRP,SAASC,aAAaC,WAAWC,SAASC,kBAAkB;AAG5D,SAGEC,YACAC,yBACK;AACP,SAASC,WAAW;;AAuEpB,IAAMC,wBAAwB,CAACC,eAC7BA,WAAWC,eAAeL,WAAWM,WAAWC,oBAAoB,CAAC,CAACH,WAAWI,cAAcC;AAE1F,IAAMC,sBAAsB,CAACC,eAAAA;AAClC,QAAM,CAACC,OAAOC,QAAAA,IAAYd,WACxB,CAACe,MAA8BC,WAA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S,GAAA;;;;;;AACpC,WAAQX,WAAkD0C,aAAa/B,QAAAA;EACzE,GACA;IAACX;GAAW;AAGd,QAAM2C,SAAS1D,YAAY,YAAYe,YAAY2C,OAAAA,GAAU;IAAC3C;GAAW;AAEzE,SAAOb,QAAQ,MAAA;AACb,WAAO;MACL,GAAGc;MACH0C;MACAH;MACAE;IACF;EACF,GAAG;IAACzC;IAAO0C;IAAQH;IAASE;GAAa;AAC3C;",
|
|
6
|
+
"names": ["AuthenticatingInvitationObservable", "CancellableInvitationObservable", "InvitationEncoder", "Invitation", "InvitationsProxy", "useCallback", "useEffect", "useMemo", "useReducer", "Invitation", "InvitationEncoder", "log", "isShareableInvitation", "invitation", "authMethod", "AuthMethod", "KNOWN_PUBLIC_KEY", "guestKeypair", "privateKey", "useInvitationStatus", "observable", "state", "dispatch", "prev", "action", "invitationProps", "id", "invitationId", "multiUse", "invitationCode", "encode", "authCode", "shareable", "type", "status", "result", "State", "SUCCESS", "ERROR", "error", "CANCELLED", "TIMEOUT", "haltedAt", "_arg", "get", "INIT", "spaceKey", "identityKey", "swarmKey", "target", "undefined", "update", "CONNECTED", "READY_FOR_AUTHENTICATION", "AUTHENTICATING", "subscription", "subscribe", "err", "currentState", "unsubscribe", "connect", "CONNECTING", "authenticate", "cancel"]
|
|
7
|
+
}
|
|
@@ -8,13 +8,9 @@ import React, { forwardRef, useEffect, useImperativeHandle, useState } from "rea
|
|
|
8
8
|
import { Client, SystemStatus } from "@dxos/client";
|
|
9
9
|
import { registerSignalsRuntime } from "@dxos/echo-signals/react";
|
|
10
10
|
import { log } from "@dxos/log";
|
|
11
|
-
import { useControlledState } from "@dxos/react-hooks";
|
|
11
|
+
import { useAsyncEffect, useControlledState } from "@dxos/react-hooks";
|
|
12
12
|
import { getAsyncProviderValue } from "@dxos/util";
|
|
13
13
|
|
|
14
|
-
// src/client/context.ts
|
|
15
|
-
import { createContext } from "react";
|
|
16
|
-
var ClientContext = createContext(void 0);
|
|
17
|
-
|
|
18
14
|
// src/banner.ts
|
|
19
15
|
var BANNER = (client) => {
|
|
20
16
|
const commitHash = client.config.get("runtime.app.build.commitHash");
|
|
@@ -39,9 +35,13 @@ var printBanner = (client) => {
|
|
|
39
35
|
console.log(`%c${BANNER(client)}`, "font-family: monospace;");
|
|
40
36
|
};
|
|
41
37
|
|
|
38
|
+
// src/client/context.ts
|
|
39
|
+
import { createContext } from "react";
|
|
40
|
+
var ClientContext = createContext(void 0);
|
|
41
|
+
|
|
42
42
|
// src/client/ClientProvider.tsx
|
|
43
43
|
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/react-client/src/client/ClientProvider.tsx";
|
|
44
|
-
var ClientProvider = /* @__PURE__ */ forwardRef(({ children, config:
|
|
44
|
+
var ClientProvider = /* @__PURE__ */ forwardRef(({ children, config: configParam, client: clientParam, services: servicesParam, status: statusParam, fallback: Fallback = () => null, signalsRuntime = true, noBanner, onInitialized, ...options }, forwardedRef) => {
|
|
45
45
|
useEffect(() => {
|
|
46
46
|
signalsRuntime && registerSignalsRuntime();
|
|
47
47
|
}, []);
|
|
@@ -49,11 +49,11 @@ var ClientProvider = /* @__PURE__ */ forwardRef(({ children, config: configProvi
|
|
|
49
49
|
if (error) {
|
|
50
50
|
throw error;
|
|
51
51
|
}
|
|
52
|
-
const [client, setClient] = useState(
|
|
52
|
+
const [client, setClient] = useState(clientParam instanceof Client ? clientParam : void 0);
|
|
53
53
|
useImperativeHandle(forwardedRef, () => client, [
|
|
54
54
|
client
|
|
55
55
|
]);
|
|
56
|
-
const [status, setStatus] = useControlledState(
|
|
56
|
+
const [status, setStatus] = useControlledState(statusParam);
|
|
57
57
|
useEffect(() => {
|
|
58
58
|
if (!client) {
|
|
59
59
|
return;
|
|
@@ -63,7 +63,7 @@ var ClientProvider = /* @__PURE__ */ forwardRef(({ children, config: configProvi
|
|
|
63
63
|
}, [
|
|
64
64
|
client
|
|
65
65
|
]);
|
|
66
|
-
|
|
66
|
+
useAsyncEffect(async () => {
|
|
67
67
|
let disposed = false;
|
|
68
68
|
const initialize = async (client3) => {
|
|
69
69
|
if (!client3.initialized) {
|
|
@@ -74,14 +74,14 @@ var ClientProvider = /* @__PURE__ */ forwardRef(({ children, config: configProvi
|
|
|
74
74
|
});
|
|
75
75
|
log("client ready", void 0, {
|
|
76
76
|
F: __dxlog_file,
|
|
77
|
-
L:
|
|
77
|
+
L: 138,
|
|
78
78
|
S: void 0,
|
|
79
79
|
C: (f, a) => f(...a)
|
|
80
80
|
});
|
|
81
81
|
await onInitialized?.(client3);
|
|
82
82
|
log("initialization complete", void 0, {
|
|
83
83
|
F: __dxlog_file,
|
|
84
|
-
L:
|
|
84
|
+
L: 140,
|
|
85
85
|
S: void 0,
|
|
86
86
|
C: (f, a) => f(...a)
|
|
87
87
|
});
|
|
@@ -92,83 +92,80 @@ var ClientProvider = /* @__PURE__ */ forwardRef(({ children, config: configProvi
|
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
let client2;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
await initialize(client2);
|
|
131
|
-
}
|
|
132
|
-
} catch (err) {
|
|
133
|
-
if (!disposed) {
|
|
134
|
-
log.catch(err, void 0, {
|
|
135
|
-
F: __dxlog_file,
|
|
136
|
-
L: 168,
|
|
137
|
-
S: void 0,
|
|
138
|
-
C: (f, a) => f(...a)
|
|
139
|
-
});
|
|
140
|
-
}
|
|
95
|
+
try {
|
|
96
|
+
if (clientParam) {
|
|
97
|
+
client2 = await getAsyncProviderValue(clientParam);
|
|
98
|
+
await initialize(client2);
|
|
99
|
+
} else {
|
|
100
|
+
const config = await getAsyncProviderValue(configParam);
|
|
101
|
+
log("resolved config", {
|
|
102
|
+
config
|
|
103
|
+
}, {
|
|
104
|
+
F: __dxlog_file,
|
|
105
|
+
L: 158,
|
|
106
|
+
S: void 0,
|
|
107
|
+
C: (f, a) => f(...a)
|
|
108
|
+
});
|
|
109
|
+
const services = await getAsyncProviderValue(servicesParam, config);
|
|
110
|
+
log("created services", {
|
|
111
|
+
services
|
|
112
|
+
}, {
|
|
113
|
+
F: __dxlog_file,
|
|
114
|
+
L: 160,
|
|
115
|
+
S: void 0,
|
|
116
|
+
C: (f, a) => f(...a)
|
|
117
|
+
});
|
|
118
|
+
client2 = new Client({
|
|
119
|
+
config,
|
|
120
|
+
services,
|
|
121
|
+
...options
|
|
122
|
+
});
|
|
123
|
+
log("created client", void 0, {
|
|
124
|
+
F: __dxlog_file,
|
|
125
|
+
L: 162,
|
|
126
|
+
S: void 0,
|
|
127
|
+
C: (f, a) => f(...a)
|
|
128
|
+
});
|
|
129
|
+
await initialize(client2);
|
|
141
130
|
}
|
|
142
|
-
})
|
|
131
|
+
} catch (err) {
|
|
132
|
+
if (!disposed) {
|
|
133
|
+
log.catch(err, void 0, {
|
|
134
|
+
F: __dxlog_file,
|
|
135
|
+
L: 167,
|
|
136
|
+
S: void 0,
|
|
137
|
+
C: (f, a) => f(...a)
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
143
141
|
return () => {
|
|
144
142
|
log("clean up", void 0, {
|
|
145
143
|
F: __dxlog_file,
|
|
146
|
-
L:
|
|
144
|
+
L: 172,
|
|
147
145
|
S: void 0,
|
|
148
146
|
C: (f, a) => f(...a)
|
|
149
147
|
});
|
|
150
148
|
disposed = true;
|
|
151
|
-
|
|
152
|
-
if (!clientProvider) {
|
|
149
|
+
if (!clientParam) {
|
|
153
150
|
void client2?.destroy().then(() => {
|
|
154
151
|
log("destroyed", void 0, {
|
|
155
152
|
F: __dxlog_file,
|
|
156
|
-
L:
|
|
153
|
+
L: 179,
|
|
157
154
|
S: void 0,
|
|
158
155
|
C: (f, a) => f(...a)
|
|
159
156
|
});
|
|
160
157
|
}).catch((err) => log.catch(err, void 0, {
|
|
161
158
|
F: __dxlog_file,
|
|
162
|
-
L:
|
|
159
|
+
L: 181,
|
|
163
160
|
S: void 0,
|
|
164
161
|
C: (f, a) => f(...a)
|
|
165
162
|
}));
|
|
166
163
|
}
|
|
167
164
|
};
|
|
168
165
|
}, [
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
166
|
+
configParam,
|
|
167
|
+
clientParam,
|
|
168
|
+
servicesParam,
|
|
172
169
|
noBanner
|
|
173
170
|
]);
|
|
174
171
|
if (!client?.initialized || status !== SystemStatus.ACTIVE) {
|
|
@@ -309,4 +306,4 @@ export {
|
|
|
309
306
|
useShellDisplay,
|
|
310
307
|
useStatus
|
|
311
308
|
};
|
|
312
|
-
//# sourceMappingURL=chunk-
|
|
309
|
+
//# sourceMappingURL=chunk-TA2HGRAF.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/client/AgentHostingProvider.tsx", "../../../src/client/ClientProvider.tsx", "../../../src/banner.ts", "../../../src/client/context.ts", "../../../src/client/useClient.ts", "../../../src/client/useClientStatus.ts", "../../../src/client/useConfig.ts", "../../../src/client/useShell.ts", "../../../src/client/useStatus.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { type PropsWithChildren, createContext, useContext, 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\nimport { useClient } from '../client';\n\nexport type AgentHostingProviderProps = { config: Config; halo: Halo };\n\nexport const AgentHostingContext = createContext<AgentHostingProviderClient | null>(null);\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\nexport const useAgentHostingClient = () => {\n return useContext(AgentHostingContext);\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 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 { registerSignalsRuntime } from '@dxos/echo-signals/react';\nimport { log } from '@dxos/log';\nimport { useAsyncEffect, useControlledState } from '@dxos/react-hooks';\nimport { type MaybePromise, type Provider, getAsyncProviderValue } from '@dxos/util';\n\nimport { printBanner } from '../banner';\n\nimport { ClientContext, type ClientContextProps } from './context';\n\n/**\n * Properties for the ClientProvider.\n */\nexport type ClientProviderProps = Omit<ClientOptions, 'config' | 'services'> &\n Pick<ClientContextProps, 'status'> &\n PropsWithChildren<{\n /**\n * Client object or async provider to enable to caller to do custom initialization.\n *\n * NOTE: For advanced use cases only.\n */\n client?: Client | Provider<Promise<Client>>;\n\n /**\n * Config object or async provider.\n *\n * NOTE: If a `client` is provided then `config` is ignored.\n */\n // TODO(burdon): Reconcile with ClientOptions.\n config?: Config | Provider<Promise<Config>>;\n\n /**\n * Callback to enable the caller to create a custom ClientServicesProvider.\n *\n * NOTE: If a `client` is provided then `services` is ignored.\n */\n // TODO(burdon): Reconcile with ClientOptions.\n services?: ClientServicesProvider | ((config?: Config) => MaybePromise<ClientServicesProvider>);\n\n /**\n * ReactNode to display until the client is available.\n */\n fallback?: FunctionComponent<Partial<ClientContextProps>>;\n\n /**\n * Enable (by default) registration of Preact signals runtime for reactive ECHO objects.\n * @see https://www.npmjs.com/package/@preact/signals-react\n */\n signalsRuntime?: 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: configParam,\n client: clientParam,\n services: servicesParam,\n status: statusParam,\n fallback: Fallback = () => null,\n signalsRuntime = true,\n noBanner,\n onInitialized,\n ...options\n },\n forwardedRef,\n ) => {\n useEffect(() => {\n // TODO(wittjosiah): Ideally this should be imported asynchronously because it is optional.\n // Unfortunately, async import seemed to break signals React instrumentation.\n signalsRuntime && registerSignalsRuntime();\n }, []);\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(clientParam instanceof Client ? clientParam : undefined);\n\n // Provide external access.\n useImperativeHandle(forwardedRef, () => client, [client]);\n\n // Client status subscription.\n const [status, setStatus] = useControlledState(statusParam);\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 (clientParam) {\n // Asynchronously request client.\n client = await getAsyncProviderValue(clientParam);\n await initialize(client);\n } else {\n // Asynchronously construct client (config may be undefined).\n const config = await getAsyncProviderValue(configParam);\n log('resolved config', { config });\n const services = await getAsyncProviderValue(servicesParam, 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 (!clientParam) {\n void client\n ?.destroy()\n .then(() => {\n log('destroyed');\n })\n .catch((err) => log.catch(err));\n }\n };\n }, [configParam, clientParam, servicesParam, noBanner]);\n\n if (!client?.initialized || status !== SystemStatus.ACTIVE) {\n return <Fallback client={client} status={status} />;\n }\n\n return <ClientContext.Provider value={{ client, status }}>{children}</ClientContext.Provider>;\n },\n);\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { type Client } from '@dxos/client';\n\n// http://patorjk.com/software/taag/#p=testall&f=Patorjk-HeX&t=DXOS\nconst BANNER = (client: Client) => {\n const commitHash = client.config.get('runtime.app.build.commitHash');\n const hash = commitHash ? ` App Commit ${commitHash} \\n` : '';\n\n return (\n '\\n' +\n '_/\\\\/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\______/\\\\/\\\\/\\\\/\\\\/\\\\_\\n' +\n '_/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\__/\\\\/\\\\_________\\n' +\n '_/\\\\/\\\\____/\\\\/\\\\______/\\\\/\\\\______/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\___\\n' +\n '_/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\__________/\\\\/\\\\_\\n' +\n '_/\\\\/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\/\\\\___\\n' +\n `\\n DXOS Client ${client.version} \\n${hash}`\n );\n};\n\nlet bannerPrinted = false;\n\nexport const printBanner = (client: Client) => {\n if (bannerPrinted || window.location.hostname === 'localhost') {\n return;\n }\n\n bannerPrinted = true;\n // eslint-disable-next-line no-console\n console.log(`%c${BANNER(client)}`, 'font-family: monospace;');\n};\n", "//\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", "//\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", "//\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"],
|
|
5
|
+
"mappings": ";AAIA,OAAOA,UAAiCC,iBAAAA,gBAAeC,cAAAA,aAAYC,YAAAA,iBAAgB;AAEnF,SAA0CC,oBAAoBC,gCAAgC;AAG9F,SAASC,OAAAA,YAAW;;;ACLpB,OAAOC,SAGLC,YACAC,WACAC,qBACAC,gBACK;AAEP,SAASC,QAAyDC,oBAAoB;AAEtF,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;EACF;AACF;",
|
|
6
|
+
"names": ["React", "createContext", "useContext", "useState", "AgentManagerClient", "FakeAgentHostingProvider", "log", "React", "forwardRef", "useEffect", "useImperativeHandle", "useState", "Client", "SystemStatus", "registerSignalsRuntime", "log", "useAsyncEffect", "useControlledState", "getAsyncProviderValue", "BANNER", "client", "commitHash", "config", "get", "hash", "version", "bannerPrinted", "printBanner", "window", "location", "hostname", "console", "log", "createContext", "ClientContext", "createContext", "undefined", "ClientProvider", "forwardRef", "children", "config", "configParam", "client", "clientParam", "services", "servicesParam", "status", "statusParam", "fallback", "Fallback", "signalsRuntime", "noBanner", "onInitialized", "options", "forwardedRef", "useEffect", "registerSignalsRuntime", "error", "setError", "useState", "setClient", "Client", "undefined", "useImperativeHandle", "setStatus", "useControlledState", "subscription", "subscribe", "unsubscribe", "useAsyncEffect", "disposed", "initialize", "initialized", "catch", "err", "log", "printBanner", "getAsyncProviderValue", "destroy", "then", "SystemStatus", "ACTIVE", "ClientContext", "Provider", "value", "useContext", "raise", "useClient", "client", "useContext", "ClientContext", "raise", "Error", "useEffect", "useState", "useClientStatus", "client", "status", "setStatus", "useState", "useEffect", "subscription", "subscribe", "unsubscribe", "useContext", "raise", "useConfig", "client", "useContext", "ClientContext", "raise", "Error", "config", "useEffect", "useState", "useShell", "client", "useClient", "shell", "useShellDisplay", "display", "setDisplay", "useState", "useEffect", "onDisplayChange", "useContext", "raise", "useStatus", "status", "useContext", "ClientContext", "raise", "Error", "AgentHostingContext", "createContext", "AgentHostingProvider", "props", "client", "useClient", "agentHostingProviderClient", "useState", "makeClient", "React", "Provider", "value", "children", "useAgentHostingClient", "useContext", "config", "halo", "agentHostingConfig", "get", "log", "type", "FakeAgentHostingProvider", "AgentManagerClient", "init", "error"]
|
|
7
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useClient
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-TA2HGRAF.mjs";
|
|
4
4
|
|
|
5
5
|
// src/devtools/index.ts
|
|
6
6
|
export * from "@dxos/client/devtools";
|
|
@@ -13,7 +13,7 @@ var useDevtools = () => {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
// src/devtools/useStream.ts
|
|
16
|
-
import {
|
|
16
|
+
import { useEffect, useState } from "react";
|
|
17
17
|
import { log } from "@dxos/log";
|
|
18
18
|
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/react-client/src/devtools/useStream.ts";
|
|
19
19
|
var useStream = (streamFactory, defaultValue, deps = []) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/devtools/index.ts", "../../../../src/devtools/useDevtools.ts", "../../../../src/devtools/useStream.ts"],
|
|
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,
|
|
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,
|
|
6
|
-
"names": ["raise", "useDevtools", "client", "useClient", "services", "DevtoolsHost", "raise", "Error", "
|
|
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": ";;;;;AAIA,cAAc;;;ACCd,SAASA,aAAa;AAIf,IAAMC,cAAc,MAAA;AACzB,QAAMC,SAASC,UAAAA;AACf,SAAOD,OAAOE,SAASA,SAASC,gBAAgBC,MAAM,IAAIC,MAAM,6BAAA,CAAA;AAClE;;;ACRA,SAA8BC,WAAWC,gBAAgB;AAGzD,SAASC,WAAW;;AAKb,IAAMC,YAAY,CAAIC,eAAgCC,cAAiBC,OAAuB,CAAA,MAAE;AACrG,QAAM,CAACC,OAAOC,QAAAA,IAAYP,SAAwBI,YAAAA;AAClDL,YAAU,MAAA;AACR,UAAMS,SAASL,cAAAA;AACfK,WAAOC,UACL,CAACC,aAAgBH,SAASG,QAAAA,GAC1B,CAACC,QAAAA;AACC,UAAIA,KAAK;AACPV,YAAIW,MAAMD,KAAAA,QAAAA;;;;;;MACZ;IACF,CAAA;AAGF,WAAO,MAAA;AACL,WAAKH,OAAOK,MAAK;IACnB;EACF,GAAGR,IAAAA;AAEH,SAAOC,SAASF;AAClB;",
|
|
6
|
+
"names": ["raise", "useDevtools", "client", "useClient", "services", "DevtoolsHost", "raise", "Error", "useEffect", "useState", "log", "useStream", "streamFactory", "defaultValue", "deps", "value", "setValue", "stream", "subscribe", "response", "err", "catch", "close"]
|
|
7
7
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useInvitationStatus
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-LO3TU5CK.mjs";
|
|
4
4
|
import {
|
|
5
5
|
useClient
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-TA2HGRAF.mjs";
|
|
7
7
|
|
|
8
8
|
// src/echo/index.ts
|
|
9
9
|
export * from "@dxos/client/echo";
|
|
@@ -14,22 +14,19 @@ import { HaloSpaceMember } from "@dxos/client/echo";
|
|
|
14
14
|
import { useMulticastObservable as useMulticastObservable2 } from "@dxos/react-hooks";
|
|
15
15
|
|
|
16
16
|
// src/echo/useSpaces.ts
|
|
17
|
-
import {
|
|
17
|
+
import { useState } from "react";
|
|
18
18
|
import { SpaceState } from "@dxos/client/echo";
|
|
19
|
-
import { useMulticastObservable } from "@dxos/react-hooks";
|
|
19
|
+
import { useAsyncEffect, useMulticastObservable } from "@dxos/react-hooks";
|
|
20
20
|
var useSpace = (spaceKeyLike) => {
|
|
21
21
|
const client = useClient();
|
|
22
22
|
const spaces = useMulticastObservable(client.spaces);
|
|
23
23
|
const [ready, setReady] = useState(false);
|
|
24
|
-
|
|
24
|
+
useAsyncEffect(async () => {
|
|
25
25
|
if (spaceKeyLike) {
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
setReady(true);
|
|
31
|
-
});
|
|
32
|
-
return () => clearTimeout(timeout);
|
|
28
|
+
await client.spaces.waitUntilReady();
|
|
29
|
+
setReady(true);
|
|
33
30
|
}, [
|
|
34
31
|
client,
|
|
35
32
|
spaceKeyLike
|
|
@@ -63,11 +60,14 @@ import { Filter, Query, isSpace } from "@dxos/client/echo";
|
|
|
63
60
|
var EMPTY_ARRAY = [];
|
|
64
61
|
var noop = () => {
|
|
65
62
|
};
|
|
66
|
-
var useQuery = (
|
|
63
|
+
var useQuery = (resource, queryOrFilter, deps) => {
|
|
67
64
|
const query = Filter.is(queryOrFilter) ? Query.select(queryOrFilter) : queryOrFilter;
|
|
68
65
|
const { getObjects, subscribe } = useMemo(() => {
|
|
66
|
+
let queryResult = void 0;
|
|
67
|
+
if (resource) {
|
|
68
|
+
queryResult = isSpace(resource) ? resource.db.query(query) : resource.query(query);
|
|
69
|
+
}
|
|
69
70
|
let subscribed = false;
|
|
70
|
-
const queryResult = spaceOrEcho === void 0 ? void 0 : isSpace(spaceOrEcho) ? spaceOrEcho.db.query(query) : spaceOrEcho.query(query);
|
|
71
71
|
return {
|
|
72
72
|
getObjects: () => subscribed && queryResult ? queryResult.objects : EMPTY_ARRAY,
|
|
73
73
|
subscribe: (cb) => {
|
|
@@ -80,7 +80,7 @@ var useQuery = (spaceOrEcho, queryOrFilter, deps) => {
|
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
82
|
}, [
|
|
83
|
-
|
|
83
|
+
resource,
|
|
84
84
|
JSON.stringify(query.ast),
|
|
85
85
|
...deps ?? []
|
|
86
86
|
]);
|
|
@@ -89,7 +89,7 @@ var useQuery = (spaceOrEcho, queryOrFilter, deps) => {
|
|
|
89
89
|
};
|
|
90
90
|
|
|
91
91
|
// src/echo/useQueue.ts
|
|
92
|
-
import { useEffect
|
|
92
|
+
import { useEffect, useMemo as useMemo2, useRef } from "react";
|
|
93
93
|
import { raise } from "@dxos/debug";
|
|
94
94
|
var MIN_POLL_INTERVAL = 1e3;
|
|
95
95
|
var useQueue = (queueDxn, options = {}) => {
|
|
@@ -105,12 +105,12 @@ var useQueue = (queueDxn, options = {}) => {
|
|
|
105
105
|
client,
|
|
106
106
|
queueDxn?.toString()
|
|
107
107
|
]);
|
|
108
|
-
|
|
108
|
+
useEffect(() => {
|
|
109
109
|
void queue?.refresh();
|
|
110
110
|
}, [
|
|
111
111
|
queue
|
|
112
112
|
]);
|
|
113
|
-
|
|
113
|
+
useEffect(() => {
|
|
114
114
|
let timeout;
|
|
115
115
|
mountedRef.current = true;
|
|
116
116
|
const poll = () => {
|
|
@@ -195,13 +195,13 @@ var useSpaceInvitation = (spaceKey, invitationId) => {
|
|
|
195
195
|
};
|
|
196
196
|
|
|
197
197
|
// src/echo/useSubscription.ts
|
|
198
|
-
import { useEffect as
|
|
198
|
+
import { useEffect as useEffect2, useRef as useRef2 } from "react";
|
|
199
199
|
import { createSubscription } from "@dxos/client/echo";
|
|
200
200
|
var useSubscription = (cb, selection) => {
|
|
201
201
|
const callbackRef = useRef2(cb);
|
|
202
202
|
callbackRef.current = cb;
|
|
203
|
-
const subscriptionRef = useRef2();
|
|
204
|
-
|
|
203
|
+
const subscriptionRef = useRef2(null);
|
|
204
|
+
useEffect2(() => {
|
|
205
205
|
subscriptionRef.current = createSubscription(() => {
|
|
206
206
|
callbackRef.current();
|
|
207
207
|
});
|
|
@@ -212,7 +212,7 @@ var useSubscription = (cb, selection) => {
|
|
|
212
212
|
};
|
|
213
213
|
|
|
214
214
|
// src/echo/useSyncState.ts
|
|
215
|
-
import { useEffect as
|
|
215
|
+
import { useEffect as useEffect3, useState as useState2 } from "react";
|
|
216
216
|
import { Context } from "@dxos/context";
|
|
217
217
|
import { EdgeService } from "@dxos/protocols";
|
|
218
218
|
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/react-client/src/echo/useSyncState.ts";
|
|
@@ -220,7 +220,7 @@ var isEdgePeerId = (peerId, spaceId) => peerId.startsWith(`${EdgeService.AUTOMER
|
|
|
220
220
|
var useSyncState = () => {
|
|
221
221
|
const client = useClient();
|
|
222
222
|
const [spaceState, setSpaceState] = useState2({});
|
|
223
|
-
|
|
223
|
+
useEffect3(() => {
|
|
224
224
|
const ctx = new Context(void 0, {
|
|
225
225
|
F: __dxlog_file,
|
|
226
226
|
L: 25
|
|
@@ -255,7 +255,7 @@ var useSyncState = () => {
|
|
|
255
255
|
};
|
|
256
256
|
var useSpaceSyncState = (space) => {
|
|
257
257
|
const [spaceState, setSpaceState] = useState2();
|
|
258
|
-
|
|
258
|
+
useEffect3(() => {
|
|
259
259
|
const ctx = new Context(void 0, {
|
|
260
260
|
F: __dxlog_file,
|
|
261
261
|
L: 64
|