@dxos/react-client 0.8.1 → 0.8.2-main.10c050d
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/dist/lib/browser/echo/index.mjs +124 -62
- package/dist/lib/browser/echo/index.mjs.map +4 -4
- package/dist/lib/browser/halo/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/echo/index.cjs +121 -59
- package/dist/lib/node/echo/index.cjs.map +4 -4
- package/dist/lib/node/halo/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/echo/index.mjs +124 -62
- package/dist/lib/node-esm/echo/index.mjs.map +4 -4
- package/dist/lib/node-esm/halo/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/banner.d.ts.map +1 -1
- package/dist/types/src/client/AgentHostingProvider.d.ts.map +1 -1
- package/dist/types/src/client/useClientStatus.d.ts.map +1 -1
- package/dist/types/src/devtools/useStream.d.ts.map +1 -1
- package/dist/types/src/echo/index.d.ts +2 -1
- package/dist/types/src/echo/index.d.ts.map +1 -1
- package/dist/types/src/echo/useMembers.d.ts.map +1 -1
- package/dist/types/src/echo/useQuery.d.ts +7 -2
- package/dist/types/src/echo/useQuery.d.ts.map +1 -1
- package/dist/types/src/echo/useQueue.d.ts +2 -2
- package/dist/types/src/echo/useQueue.d.ts.map +1 -1
- package/dist/types/src/echo/useSchema.d.ts +2 -2
- 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.map +1 -1
- package/dist/types/src/echo/useSyncState.d.ts +10 -0
- package/dist/types/src/echo/useSyncState.d.ts.map +1 -0
- package/dist/types/src/halo/useHaloInvitations.d.ts.map +1 -1
- package/dist/types/src/halo/useKeyStore.d.ts.map +1 -1
- package/dist/types/src/invitations/useInvitationStatus.d.ts.map +1 -1
- package/dist/types/src/testing/ClientRepeater.d.ts.map +1 -1
- package/dist/types/src/testing/util.d.ts.map +1 -1
- package/dist/types/src/testing/withClientProvider.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +28 -23
- package/project.json +2 -1
- package/src/client/useConfig.test.tsx +4 -4
- package/src/echo/index.ts +2 -1
- package/src/echo/useQuery.ts +28 -29
- package/src/echo/useQueue.ts +3 -2
- package/src/echo/useSchema.ts +4 -5
- package/src/echo/useSyncState.ts +78 -0
- package/src/halo/useKeyStore.ts +3 -3
- package/tsconfig.json +1 -59
- package/typedoc/.nojekyll +1 -0
- package/typedoc/assets/hierarchy.js +1 -0
- package/typedoc/assets/highlight.css +99 -0
- package/typedoc/assets/icons.js +18 -0
- package/typedoc/assets/icons.svg +1 -0
- package/typedoc/assets/main.js +60 -0
- package/typedoc/assets/navigation.js +1 -0
- package/typedoc/assets/search.js +1 -0
- package/typedoc/assets/style.css +1640 -0
- package/typedoc/classes/echo.Hypergraph.html +21 -0
- package/typedoc/classes/echo.PropertiesType.html +19 -0
- package/typedoc/classes/echo.QueryResult.html +18 -0
- package/typedoc/classes/halo.KeyStore.html +6 -0
- package/typedoc/classes/index.AgentClientServiceProvider.html +10 -0
- package/typedoc/classes/index.AgentManagerClient.html +22 -0
- package/typedoc/classes/index.AlreadyJoinedError.html +15 -0
- package/typedoc/classes/index.ApiError.html +16 -0
- package/typedoc/classes/index.CancelledError.html +16 -0
- package/typedoc/classes/index.Client.html +51 -0
- package/typedoc/classes/index.ClientServicesProxy.html +12 -0
- package/typedoc/classes/index.Config.html +17 -0
- package/typedoc/classes/index.DataCorruptionError.html +16 -0
- package/typedoc/classes/index.DatabaseError.html +15 -0
- package/typedoc/classes/index.EntityNotFoundError.html +15 -0
- package/typedoc/classes/index.FakeAgentHostingProvider.html +7 -0
- package/typedoc/classes/index.IFrameManager.html +6 -0
- package/typedoc/classes/index.IdentityNotInitializedError.html +15 -0
- package/typedoc/classes/index.InvalidConfigError.html +16 -0
- package/typedoc/classes/index.InvalidInvitationError.html +15 -0
- package/typedoc/classes/index.InvalidInvitationExtensionRoleError.html +16 -0
- package/typedoc/classes/index.InvalidStorageVersionError.html +15 -0
- package/typedoc/classes/index.LocalClientServices.html +12 -0
- package/typedoc/classes/index.PublicKey.html +55 -0
- package/typedoc/classes/index.RemoteServiceConnectionError.html +15 -0
- package/typedoc/classes/index.RemoteServiceConnectionTimeout.html +15 -0
- package/typedoc/classes/index.RpcClosedError.html +15 -0
- package/typedoc/classes/index.RpcNotOpenError.html +15 -0
- package/typedoc/classes/index.SharedWorkerConnection.html +5 -0
- package/typedoc/classes/index.Shell.html +35 -0
- package/typedoc/classes/index.ShellManager.html +9 -0
- package/typedoc/classes/index.SystemError.html +16 -0
- package/typedoc/classes/index.UnknownModelError.html +15 -0
- package/typedoc/classes/index.WorkerClientServices.html +12 -0
- package/typedoc/classes/invitations.AuthenticatingInvitationObservable.html +30 -0
- package/typedoc/classes/invitations.CancellableInvitationObservable.html +29 -0
- package/typedoc/classes/invitations.InvitationEncoder.html +5 -0
- package/typedoc/classes/invitations.InvitationsProxy.html +12 -0
- package/typedoc/enums/devtools.KeyType.html +9 -0
- package/typedoc/enums/echo.HaloSpaceMember.Role.html +9 -0
- package/typedoc/enums/echo.IndexKind.Kind.html +8 -0
- package/typedoc/enums/echo.QueryOptions.DataLocation.html +6 -0
- package/typedoc/enums/echo.QueryOptions.ShowDeletedOption.html +6 -0
- package/typedoc/enums/echo.ResultFormat.html +10 -0
- package/typedoc/enums/echo.SpaceMember.PresenceState.html +5 -0
- package/typedoc/enums/echo.SpaceState.html +13 -0
- package/typedoc/enums/echo.TextKind.html +5 -0
- package/typedoc/enums/halo.Device.PresenceState.html +6 -0
- package/typedoc/enums/halo.DeviceKind.html +5 -0
- package/typedoc/enums/halo.DeviceType.html +9 -0
- package/typedoc/enums/index.ShellDisplay.html +5 -0
- package/typedoc/enums/index.ShellLayout.html +13 -0
- package/typedoc/enums/index.SystemStatus.html +5 -0
- package/typedoc/enums/invitations.Invitation.AuthMethod.html +6 -0
- package/typedoc/enums/invitations.Invitation.Kind.html +5 -0
- package/typedoc/enums/invitations.Invitation.State.html +13 -0
- package/typedoc/enums/invitations.Invitation.Type.html +6 -0
- package/typedoc/enums/mesh.ConnectionState.html +5 -0
- package/typedoc/functions/devtools.useDevtools.html +1 -0
- package/typedoc/functions/devtools.useStream.html +2 -0
- package/typedoc/functions/echo.useMembers.html +1 -0
- package/typedoc/functions/echo.useQueue.html +2 -0
- package/typedoc/functions/echo.useSchema.html +2 -0
- package/typedoc/functions/echo.useSpace.html +6 -0
- package/typedoc/functions/echo.useSpaceInvitation.html +1 -0
- package/typedoc/functions/echo.useSpaceInvitations.html +1 -0
- package/typedoc/functions/echo.useSpaceSyncState.html +2 -0
- package/typedoc/functions/echo.useSpaces.html +5 -0
- package/typedoc/functions/echo.useSubscription.html +3 -0
- package/typedoc/functions/echo.useSyncState.html +2 -0
- package/typedoc/functions/halo.useContacts.html +4 -0
- package/typedoc/functions/halo.useCredentials.html +1 -0
- package/typedoc/functions/halo.useDevices.html +1 -0
- package/typedoc/functions/halo.useHaloInvitation.html +1 -0
- package/typedoc/functions/halo.useHaloInvitations.html +1 -0
- package/typedoc/functions/halo.useIdentity.html +3 -0
- package/typedoc/functions/halo.useKeyStore.html +3 -0
- package/typedoc/functions/index.AgentHostingProvider.html +2 -0
- package/typedoc/functions/index.useAgentHostingClient.html +1 -0
- package/typedoc/functions/index.useClient.html +3 -0
- package/typedoc/functions/index.useClientStatus.html +1 -0
- package/typedoc/functions/index.useConfig.html +3 -0
- package/typedoc/functions/index.useShell.html +2 -0
- package/typedoc/functions/index.useShellDisplay.html +2 -0
- package/typedoc/functions/index.useStatus.html +1 -0
- package/typedoc/functions/invitations.useInvitationStatus.html +1 -0
- package/typedoc/functions/mesh.useNetworkStatus.html +2 -0
- package/typedoc/hierarchy.html +1 -0
- package/typedoc/index.html +23 -0
- package/typedoc/interfaces/devtools.DevtoolsHook.html +22 -0
- package/typedoc/interfaces/devtools.DevtoolsHost.html +26 -0
- package/typedoc/interfaces/echo.DocAccessor.html +3 -0
- package/typedoc/interfaces/echo.Echo.html +39 -0
- package/typedoc/interfaces/echo.EchoDatabase.html +25 -0
- package/typedoc/interfaces/echo.Expando.html +3 -0
- package/typedoc/interfaces/echo.Filter.html +3 -0
- package/typedoc/interfaces/echo.HaloSpaceMember.html +18 -0
- package/typedoc/interfaces/echo.IDocHandle.html +6 -0
- package/typedoc/interfaces/echo.IndexKind.html +9 -0
- package/typedoc/interfaces/echo.Query.html +34 -0
- package/typedoc/interfaces/echo.QueryOptions.html +39 -0
- package/typedoc/interfaces/echo.Queue.html +13 -0
- package/typedoc/interfaces/echo.Ref.html +32 -0
- package/typedoc/interfaces/echo.Space.html +39 -0
- package/typedoc/interfaces/echo.SpaceMember.html +7 -0
- package/typedoc/interfaces/echo.SpaceSyncState.PeerState.html +14 -0
- package/typedoc/interfaces/echo.SpaceSyncState.html +4 -0
- package/typedoc/interfaces/echo.SubscriptionHandle.html +5 -0
- package/typedoc/interfaces/echo.TypedObject.html +16 -0
- package/typedoc/interfaces/halo.Contact.html +10 -0
- package/typedoc/interfaces/halo.Credential.html +27 -0
- package/typedoc/interfaces/halo.Device.html +11 -0
- package/typedoc/interfaces/halo.Halo.html +16 -0
- package/typedoc/interfaces/halo.Identity.html +15 -0
- package/typedoc/interfaces/index.AgentHostingProviderClient.html +6 -0
- package/typedoc/interfaces/index.AppContextRequest.html +33 -0
- package/typedoc/interfaces/index.ClientServicesProvider.html +9 -0
- package/typedoc/interfaces/index.InvitationUrlRequest.html +9 -0
- package/typedoc/interfaces/index.LayoutRequest.html +29 -0
- package/typedoc/interfaces/index.ShellRuntime.html +15 -0
- package/typedoc/interfaces/invitations.Invitation.html +92 -0
- package/typedoc/interfaces/invitations.Invitations.html +5 -0
- package/typedoc/interfaces/mesh.GossipMessage.html +10 -0
- package/typedoc/interfaces/mesh.NetworkStatus.Signal.html +5 -0
- package/typedoc/interfaces/mesh.NetworkStatus.html +6 -0
- package/typedoc/media/LICENSE +8 -0
- package/typedoc/modules/devtools.html +1 -0
- package/typedoc/modules/echo.Filter.html +1 -0
- package/typedoc/modules/echo.HaloSpaceMember.html +1 -0
- package/typedoc/modules/echo.IndexKind.html +1 -0
- package/typedoc/modules/echo.Query.html +1 -0
- package/typedoc/modules/echo.QueryOptions.html +1 -0
- package/typedoc/modules/echo.Ref.html +2 -0
- package/typedoc/modules/echo.SpaceMember.html +1 -0
- package/typedoc/modules/echo.SpaceSyncState.html +1 -0
- package/typedoc/modules/echo.html +1 -0
- package/typedoc/modules/halo.Device.html +1 -0
- package/typedoc/modules/halo.html +1 -0
- package/typedoc/modules/index.html +1 -0
- package/typedoc/modules/invitations.Invitation.html +1 -0
- package/typedoc/modules/invitations.html +1 -0
- package/typedoc/modules/mesh.NetworkStatus.html +1 -0
- package/typedoc/modules/mesh.html +1 -0
- package/typedoc/modules/worker.html +1 -0
- package/typedoc/modules.html +1 -0
- package/typedoc/types/devtools.MountOptions.html +3 -0
- package/typedoc/types/echo.AnyLiveObject.html +2 -0
- package/typedoc/types/echo.Filter.And.html +1 -0
- package/typedoc/types/echo.Filter.Any.html +1 -0
- package/typedoc/types/echo.Filter.Or.html +1 -0
- package/typedoc/types/echo.Filter.Props.html +1 -0
- package/typedoc/types/echo.Filter.Type.html +1 -0
- package/typedoc/types/echo.Live.html +5 -0
- package/typedoc/types/echo.ObjectMeta.html +1 -0
- package/typedoc/types/echo.ObjectMigration.html +7 -0
- package/typedoc/types/echo.ObjectVersion.html +2 -0
- package/typedoc/types/echo.PeerSyncState.html +1 -0
- package/typedoc/types/echo.Progress.html +3 -0
- package/typedoc/types/echo.PropertiesTypeProps.html +1 -0
- package/typedoc/types/echo.Query.Any.html +1 -0
- package/typedoc/types/echo.Query.TextSearchOptions.html +2 -0
- package/typedoc/types/echo.Query.Type.html +1 -0
- package/typedoc/types/echo.Ref.Target.html +2 -0
- package/typedoc/types/echo.Selection.html +1 -0
- package/typedoc/types/echo.SpaceId.html +6 -0
- package/typedoc/types/echo.SpaceSyncStateMap.html +1 -0
- package/typedoc/types/echo.UseQueueOptions.html +2 -0
- package/typedoc/types/echo.UseSpacesParams.html +3 -0
- package/typedoc/types/index.AgentHostingProviderProps.html +3 -0
- package/typedoc/types/index.ClientContextProps.html +3 -0
- package/typedoc/types/index.ClientOptions.html +12 -0
- package/typedoc/types/index.ClientProviderProps.html +2 -0
- package/typedoc/types/index.ClientServices.html +15 -0
- package/typedoc/types/index.FromAgentOptions.html +2 -0
- package/typedoc/types/index.PublicKeyLike.html +2 -0
- package/typedoc/types/invitations.InvitationAction.html +1 -0
- package/typedoc/types/invitations.InvitationResult.html +5 -0
- package/typedoc/types/invitations.InvitationStatus.html +15 -0
- package/typedoc/variables/devtools.mountDevtoolsHooks.html +1 -0
- package/typedoc/variables/devtools.unmountDevtoolsHooks.html +1 -0
- package/typedoc/variables/echo.DocAccessor.html +1 -0
- package/typedoc/variables/echo.EchoObjectSchema.html +1 -0
- package/typedoc/variables/echo.Expando.html +1 -0
- package/typedoc/variables/echo.FQ_ID_LENGTH.html +1 -0
- package/typedoc/variables/echo.Filter.html +1 -0
- package/typedoc/variables/echo.OBJECT_ID_LENGTH.html +1 -0
- package/typedoc/variables/echo.ObjectVersion.html +1 -0
- package/typedoc/variables/echo.Query.html +1 -0
- package/typedoc/variables/echo.Queue.html +1 -0
- package/typedoc/variables/echo.ReactiveObjectSchema.html +1 -0
- package/typedoc/variables/echo.Ref.html +2 -0
- package/typedoc/variables/echo.RefArray.html +2 -0
- package/typedoc/variables/echo.SPACE_ID_LENGTH.html +1 -0
- package/typedoc/variables/echo.SpaceId.html +1 -0
- package/typedoc/variables/echo.SpaceSchema.html +1 -0
- package/typedoc/variables/echo.TypedObject.html +3 -0
- package/typedoc/variables/echo.compareForeignKeys.html +1 -0
- package/typedoc/variables/echo.createDocAccessor.html +1 -0
- package/typedoc/variables/echo.createEmptyEdgeSyncState.html +1 -0
- package/typedoc/variables/echo.createObject.html +1 -0
- package/typedoc/variables/echo.createQueueDxn.html +1 -0
- package/typedoc/variables/echo.createSubscription.html +5 -0
- package/typedoc/variables/echo.defineObjectMigration.html +1 -0
- package/typedoc/variables/echo.fromCursor.html +1 -0
- package/typedoc/variables/echo.fullyQualifiedId.html +4 -0
- package/typedoc/variables/echo.getMeta.html +1 -0
- package/typedoc/variables/echo.getObjectCore.html +1 -0
- package/typedoc/variables/echo.getRangeFromCursor.html +1 -0
- package/typedoc/variables/echo.getSchema.html +2 -0
- package/typedoc/variables/echo.getSource.html +4 -0
- package/typedoc/variables/echo.getSpace.html +1 -0
- package/typedoc/variables/echo.getSyncSummary.html +1 -0
- package/typedoc/variables/echo.getTarget.html +4 -0
- package/typedoc/variables/echo.getTextInRange.html +2 -0
- package/typedoc/variables/echo.getType.html +5 -0
- package/typedoc/variables/echo.getTypename.html +2 -0
- package/typedoc/variables/echo.getVersion.html +3 -0
- package/typedoc/variables/echo.importSpace.html +1 -0
- package/typedoc/variables/echo.internalDecodeReference.html +1 -0
- package/typedoc/variables/echo.isEchoObject.html +2 -0
- package/typedoc/variables/echo.isLiveObject.html +2 -0
- package/typedoc/variables/echo.isRelation.html +2 -0
- package/typedoc/variables/echo.isSpace.html +1 -0
- package/typedoc/variables/echo.live.html +3 -0
- package/typedoc/variables/echo.loadObjectReferences.html +7 -0
- package/typedoc/variables/echo.makeRef.html +2 -0
- package/typedoc/variables/echo.parseFullyQualifiedId.html +2 -0
- package/typedoc/variables/echo.parseId.html +1 -0
- package/typedoc/variables/echo.refFromDXN.html +2 -0
- package/typedoc/variables/echo.toCursor.html +1 -0
- package/typedoc/variables/echo.toCursorRange.html +1 -0
- package/typedoc/variables/echo.updateText.html +6 -0
- package/typedoc/variables/echo.useQuery.html +2 -0
- package/typedoc/variables/index.AgentHostingContext.html +1 -0
- package/typedoc/variables/index.ClientProvider.html +3 -0
- package/typedoc/variables/index.DXOS_VERSION.html +1 -0
- package/typedoc/variables/index.Defaults.html +2 -0
- package/typedoc/variables/index.Dynamics.html +2 -0
- package/typedoc/variables/index.Envs.html +2 -0
- package/typedoc/variables/index.Local.html +2 -0
- package/typedoc/variables/index.Remote.html +1 -0
- package/typedoc/variables/index.Storage.html +2 -0
- package/typedoc/variables/index.createClientServices.html +4 -0
- package/typedoc/variables/index.fromAgent.html +2 -0
- package/typedoc/variables/index.fromHost.html +2 -0
- package/typedoc/variables/index.fromSocket.html +2 -0
- package/typedoc/variables/index.fromWorker.html +2 -0
- package/typedoc/variables/index.getUnixSocket.html +1 -0
- package/typedoc/variables/index.resolveRef.html +1 -0
- package/typedoc/variables/index.useMulticastObservable.html +3 -0
- package/typedoc/variables/worker.getWorkerServiceHost.html +1 -0
- package/typedoc/variables/worker.onconnect.html +1 -0
|
@@ -59,16 +59,20 @@ var useMembers = (spaceKey) => {
|
|
|
59
59
|
|
|
60
60
|
// packages/sdk/react-client/src/echo/useQuery.ts
|
|
61
61
|
import { useMemo, useSyncExternalStore } from "react";
|
|
62
|
-
import {
|
|
63
|
-
var
|
|
62
|
+
import { Filter, Query, isSpace } from "@dxos/client/echo";
|
|
63
|
+
var EMPTY_ARRAY = [];
|
|
64
|
+
var noop = () => {
|
|
65
|
+
};
|
|
66
|
+
var useQuery = (spaceOrEcho, queryOrFilter, deps) => {
|
|
67
|
+
const query = Filter.is(queryOrFilter) ? Query.select(queryOrFilter) : queryOrFilter;
|
|
64
68
|
const { getObjects, subscribe } = useMemo(() => {
|
|
65
69
|
let subscribed = false;
|
|
66
|
-
const
|
|
70
|
+
const queryResult = spaceOrEcho === void 0 ? void 0 : isSpace(spaceOrEcho) ? spaceOrEcho.db.query(query) : spaceOrEcho.query(query);
|
|
67
71
|
return {
|
|
68
|
-
getObjects: () => subscribed &&
|
|
72
|
+
getObjects: () => subscribed && queryResult ? queryResult.objects : EMPTY_ARRAY,
|
|
69
73
|
subscribe: (cb) => {
|
|
70
74
|
subscribed = true;
|
|
71
|
-
const unsubscribe =
|
|
75
|
+
const unsubscribe = queryResult?.subscribe(cb) ?? noop;
|
|
72
76
|
return () => {
|
|
73
77
|
unsubscribe?.();
|
|
74
78
|
subscribed = false;
|
|
@@ -77,24 +81,66 @@ var useQuery = (spaceOrEcho, filter, options, deps) => {
|
|
|
77
81
|
};
|
|
78
82
|
}, [
|
|
79
83
|
spaceOrEcho,
|
|
80
|
-
|
|
84
|
+
JSON.stringify(query.ast),
|
|
81
85
|
...deps ?? []
|
|
82
86
|
]);
|
|
83
87
|
const objects = useSyncExternalStore(subscribe, getObjects);
|
|
84
88
|
return objects ?? [];
|
|
85
89
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
|
|
91
|
+
// packages/sdk/react-client/src/echo/useQueue.ts
|
|
92
|
+
import { useEffect as useEffect2, useMemo as useMemo2, useRef } from "react";
|
|
93
|
+
import { raise } from "@dxos/debug";
|
|
94
|
+
var MIN_POLL_INTERVAL = 1e3;
|
|
95
|
+
var useQueue = (queueDxn, options = {}) => {
|
|
96
|
+
const client = useClient();
|
|
97
|
+
const mountedRef = useRef(true);
|
|
98
|
+
const queue = useMemo2(() => {
|
|
99
|
+
if (!queueDxn) {
|
|
100
|
+
return void 0;
|
|
101
|
+
}
|
|
102
|
+
const { spaceId } = queueDxn.asQueueDXN() ?? raise(new TypeError("Invalid queue DXN"));
|
|
103
|
+
return client.spaces.get(spaceId)?.queues.get(queueDxn);
|
|
104
|
+
}, [
|
|
105
|
+
client,
|
|
106
|
+
queueDxn?.toString()
|
|
107
|
+
]);
|
|
108
|
+
useEffect2(() => {
|
|
109
|
+
void queue?.refresh();
|
|
110
|
+
}, [
|
|
111
|
+
queue
|
|
112
|
+
]);
|
|
113
|
+
useEffect2(() => {
|
|
114
|
+
let timeout;
|
|
115
|
+
mountedRef.current = true;
|
|
116
|
+
const poll = () => {
|
|
117
|
+
if (!mountedRef.current) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
void queue?.refresh().finally(() => {
|
|
121
|
+
if (mountedRef.current && options.pollInterval) {
|
|
122
|
+
timeout = setTimeout(poll, Math.max(options.pollInterval ?? 0, MIN_POLL_INTERVAL));
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
if (options.pollInterval) {
|
|
127
|
+
poll();
|
|
128
|
+
}
|
|
129
|
+
return () => {
|
|
130
|
+
mountedRef.current = false;
|
|
131
|
+
clearTimeout(timeout);
|
|
132
|
+
};
|
|
133
|
+
}, [
|
|
134
|
+
queue,
|
|
135
|
+
options.pollInterval
|
|
136
|
+
]);
|
|
137
|
+
return queue;
|
|
90
138
|
};
|
|
91
|
-
var EMPTY_ARRAY = [];
|
|
92
139
|
|
|
93
140
|
// packages/sdk/react-client/src/echo/useSchema.ts
|
|
94
|
-
import { useMemo as
|
|
95
|
-
import { ImmutableSchema } from "@dxos/echo-schema";
|
|
141
|
+
import { useMemo as useMemo3, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
96
142
|
var useSchema = (client, space, typename) => {
|
|
97
|
-
const { subscribe, getSchema } =
|
|
143
|
+
const { subscribe, getSchema } = useMemo3(() => {
|
|
98
144
|
if (!typename || !space) {
|
|
99
145
|
return {
|
|
100
146
|
subscribe: () => () => {
|
|
@@ -104,11 +150,10 @@ var useSchema = (client, space, typename) => {
|
|
|
104
150
|
}
|
|
105
151
|
const staticSchema = client.graph.schemaRegistry.getSchema(typename);
|
|
106
152
|
if (staticSchema) {
|
|
107
|
-
const immutableSchema = new ImmutableSchema(staticSchema);
|
|
108
153
|
return {
|
|
109
154
|
subscribe: () => () => {
|
|
110
155
|
},
|
|
111
|
-
getSchema: () =>
|
|
156
|
+
getSchema: () => staticSchema
|
|
112
157
|
};
|
|
113
158
|
}
|
|
114
159
|
const query = space.db.schemaRegistry.query({
|
|
@@ -134,7 +179,7 @@ var useSchema = (client, space, typename) => {
|
|
|
134
179
|
};
|
|
135
180
|
|
|
136
181
|
// packages/sdk/react-client/src/echo/useSpaceInvitations.ts
|
|
137
|
-
import { useMemo as
|
|
182
|
+
import { useMemo as useMemo4 } from "react";
|
|
138
183
|
import { MulticastObservable as MulticastObservable2 } from "@dxos/async";
|
|
139
184
|
import { useMulticastObservable as useMulticastObservable3 } from "@dxos/react-hooks";
|
|
140
185
|
var useSpaceInvitations = (spaceKey) => {
|
|
@@ -143,20 +188,20 @@ var useSpaceInvitations = (spaceKey) => {
|
|
|
143
188
|
};
|
|
144
189
|
var useSpaceInvitation = (spaceKey, invitationId) => {
|
|
145
190
|
const invitations = useSpaceInvitations(spaceKey);
|
|
146
|
-
const invitation =
|
|
191
|
+
const invitation = useMemo4(() => invitations.find((invitation2) => invitation2.get().invitationId === invitationId), [
|
|
147
192
|
invitations
|
|
148
193
|
]);
|
|
149
194
|
return useInvitationStatus(invitation);
|
|
150
195
|
};
|
|
151
196
|
|
|
152
197
|
// packages/sdk/react-client/src/echo/useSubscription.ts
|
|
153
|
-
import { useEffect as
|
|
198
|
+
import { useEffect as useEffect3, useRef as useRef2 } from "react";
|
|
154
199
|
import { createSubscription } from "@dxos/client/echo";
|
|
155
200
|
var useSubscription = (cb, selection) => {
|
|
156
|
-
const callbackRef =
|
|
201
|
+
const callbackRef = useRef2(cb);
|
|
157
202
|
callbackRef.current = cb;
|
|
158
|
-
const subscriptionRef =
|
|
159
|
-
|
|
203
|
+
const subscriptionRef = useRef2();
|
|
204
|
+
useEffect3(() => {
|
|
160
205
|
subscriptionRef.current = createSubscription(() => {
|
|
161
206
|
callbackRef.current();
|
|
162
207
|
});
|
|
@@ -166,53 +211,68 @@ var useSubscription = (cb, selection) => {
|
|
|
166
211
|
return subscriptionRef.current;
|
|
167
212
|
};
|
|
168
213
|
|
|
169
|
-
// packages/sdk/react-client/src/echo/
|
|
170
|
-
import { useEffect as
|
|
171
|
-
import {
|
|
172
|
-
|
|
173
|
-
var
|
|
214
|
+
// packages/sdk/react-client/src/echo/useSyncState.ts
|
|
215
|
+
import { useEffect as useEffect4, useState as useState2 } from "react";
|
|
216
|
+
import { Context } from "@dxos/context";
|
|
217
|
+
import { EdgeService } from "@dxos/protocols";
|
|
218
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/react-client/src/echo/useSyncState.ts";
|
|
219
|
+
var isEdgePeerId = (peerId, spaceId) => peerId.startsWith(`${EdgeService.AUTOMERGE_REPLICATOR}:${spaceId}`);
|
|
220
|
+
var useSyncState = () => {
|
|
174
221
|
const client = useClient();
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
222
|
+
const [spaceState, setSpaceState] = useState2({});
|
|
223
|
+
useEffect4(() => {
|
|
224
|
+
const ctx = new Context(void 0, {
|
|
225
|
+
F: __dxlog_file,
|
|
226
|
+
L: 25
|
|
227
|
+
});
|
|
228
|
+
const createSubscriptions = (spaces) => {
|
|
229
|
+
for (const space of spaces) {
|
|
230
|
+
if (spaceState[space.id]) {
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
ctx.onDispose(space.crud.subscribeToSyncState(ctx, ({ peers = [] }) => {
|
|
234
|
+
const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));
|
|
235
|
+
if (syncState) {
|
|
236
|
+
setSpaceState((spaceState2) => ({
|
|
237
|
+
...spaceState2,
|
|
238
|
+
[space.id]: syncState
|
|
239
|
+
}));
|
|
240
|
+
}
|
|
241
|
+
}));
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
createSubscriptions(client.spaces.get());
|
|
245
|
+
client.spaces.subscribe((spaces) => {
|
|
246
|
+
createSubscriptions(spaces);
|
|
247
|
+
});
|
|
248
|
+
return () => {
|
|
249
|
+
void ctx.dispose();
|
|
250
|
+
};
|
|
188
251
|
}, [
|
|
189
|
-
|
|
252
|
+
client
|
|
190
253
|
]);
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
254
|
+
return spaceState;
|
|
255
|
+
};
|
|
256
|
+
var useSpaceSyncState = (space) => {
|
|
257
|
+
const [spaceState, setSpaceState] = useState2();
|
|
258
|
+
useEffect4(() => {
|
|
259
|
+
const ctx = new Context(void 0, {
|
|
260
|
+
F: __dxlog_file,
|
|
261
|
+
L: 64
|
|
262
|
+
});
|
|
263
|
+
space.crud.subscribeToSyncState(ctx, ({ peers = [] }) => {
|
|
264
|
+
const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));
|
|
265
|
+
if (syncState) {
|
|
266
|
+
setSpaceState(syncState);
|
|
197
267
|
}
|
|
198
|
-
|
|
199
|
-
if (mountedRef.current && options.pollInterval) {
|
|
200
|
-
timeout = setTimeout(poll, Math.max(options.pollInterval ?? 0, MIN_POLL_INTERVAL));
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
};
|
|
204
|
-
if (options.pollInterval) {
|
|
205
|
-
poll();
|
|
206
|
-
}
|
|
268
|
+
});
|
|
207
269
|
return () => {
|
|
208
|
-
|
|
209
|
-
clearTimeout(timeout);
|
|
270
|
+
void ctx.dispose();
|
|
210
271
|
};
|
|
211
272
|
}, [
|
|
212
|
-
|
|
213
|
-
options.pollInterval
|
|
273
|
+
space
|
|
214
274
|
]);
|
|
215
|
-
return
|
|
275
|
+
return spaceState;
|
|
216
276
|
};
|
|
217
277
|
export {
|
|
218
278
|
useMembers,
|
|
@@ -222,7 +282,9 @@ export {
|
|
|
222
282
|
useSpace,
|
|
223
283
|
useSpaceInvitation,
|
|
224
284
|
useSpaceInvitations,
|
|
285
|
+
useSpaceSyncState,
|
|
225
286
|
useSpaces,
|
|
226
|
-
useSubscription
|
|
287
|
+
useSubscription,
|
|
288
|
+
useSyncState
|
|
227
289
|
};
|
|
228
290
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/echo/index.ts", "../../../../src/echo/useMembers.ts", "../../../../src/echo/useSpaces.ts", "../../../../src/echo/useQuery.ts", "../../../../src/echo/useSchema.ts", "../../../../src/echo/useSpaceInvitations.ts", "../../../../src/echo/useSubscription.ts", "../../../../src/echo/
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nexport * from '@dxos/client/echo';\n\nexport * from './useMembers';\nexport * from './useQuery';\nexport * from './useSchema';\nexport * from './useSpaces';\nexport * from './useSpaceInvitations';\nexport * from './useSubscription';\nexport * from './useQueue';\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { MulticastObservable } from '@dxos/async';\nimport { type PublicKey } from '@dxos/client';\nimport { HaloSpaceMember, type SpaceMember } from '@dxos/client/echo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useSpaces } from './useSpaces';\n\nexport const useMembers = (spaceKey: PublicKey | undefined): SpaceMember[] => {\n // TODO(dmaretskyi): useSpace hook for spaces that are not ready.\n const spaces = useSpaces({ all: true });\n const space = spaceKey ? spaces.find((space) => space.key.equals(spaceKey)) : undefined;\n\n // EMPTY_OBSERVABLE needs to be a stable reference to avoid re-subscribing on every render.\n const members = useMulticastObservable(space?.members ?? MulticastObservable.empty()) ?? [];\n return members.filter((member) => member.role !== HaloSpaceMember.Role.REMOVED);\n};\n", "//\n// Copyright 2020 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type PublicKeyLike } from '@dxos/client';\nimport { type Space, SpaceState } from '@dxos/client/echo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client';\n\n/**\n * Get a specific Space using its key.\n * The space is not guaranteed to be in the ready state.\n * Returns the default space if no key is provided.\n * Requires a ClientProvider somewhere in the parent tree.\n *\n * @param spaceKeyLike the key of the space to look for\n */\nexport const useSpace = (spaceKeyLike?: PublicKeyLike): Space | undefined => {\n const client = useClient();\n const spaces = useMulticastObservable<Space[]>(client.spaces);\n const [ready, setReady] = useState(false);\n\n useEffect(() => {\n // Only wait for ready if looking for the default space.\n if (spaceKeyLike) {\n return;\n }\n\n const timeout = setTimeout(async () => {\n await client.spaces.waitUntilReady();\n setReady(true);\n });\n\n return () => clearTimeout(timeout);\n }, [client, spaceKeyLike]);\n\n if (spaceKeyLike) {\n return spaces.find((space) => space.key.equals(spaceKeyLike) || space.id === spaceKeyLike);\n }\n\n if (ready && client.halo.identity.get()) {\n return client.spaces.default;\n }\n};\n\nexport type UseSpacesParams = {\n /**\n * Return uninitialized spaces as well.\n */\n all?: boolean;\n};\n\n/**\n * Get all Spaces available to current user.\n * Requires a ClientProvider somewhere in the parent tree.\n * By default, only ready spaces are returned.\n * @returns an array of Spaces\n */\nexport const useSpaces = ({ all = false }: UseSpacesParams = {}): Space[] => {\n const client = useClient();\n const spaces = useMulticastObservable<Space[]>(client.spaces);\n\n // TODO(dmaretskyi): Array reference equality.\n return spaces.filter((space) => all || space.state.get() === SpaceState.SPACE_READY);\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { useMemo, useSyncExternalStore } from 'react';\n\nimport {\n isSpace,\n type Echo,\n type FilterSource,\n Filter,\n type Query,\n type QueryOptions,\n type ReactiveEchoObject,\n type Space,\n} from '@dxos/client/echo';\n\n/**\n * Create subscription.\n */\n// TODO(burdon): Support typed operator filters (e.g., Note.filter(note => ...)).\nexport const useQuery = <T extends ReactiveEchoObject<any>>(\n spaceOrEcho?: Space | Echo,\n filter?: FilterSource<T>,\n options?: QueryOptions,\n deps?: any[],\n): T[] => {\n const { getObjects, subscribe } = useMemo(() => {\n let subscribed = false;\n const query = isSpace(spaceOrEcho)\n ? spaceOrEcho.db.query(filter, options)\n : (spaceOrEcho?.query(filter, options) as Query<T> | undefined);\n\n return {\n getObjects: () => (subscribed && query ? query.objects : EMPTY_ARRAY),\n subscribe: (cb: () => void) => {\n subscribed = true;\n const unsubscribe = query?.subscribe(cb) ?? noop;\n return () => {\n unsubscribe?.();\n subscribed = false;\n };\n },\n };\n }, [spaceOrEcho, ...filterToDepsArray(filter), ...(deps ?? [])]);\n\n // https://beta.reactjs.org/reference/react/useSyncExternalStore\n // NOTE: This hook will resubscribe whenever the callback passed to the first argument changes; make sure it is stable.\n const objects = useSyncExternalStore<T[] | undefined>(subscribe, getObjects);\n return objects ?? [];\n};\n\nconst filterToDepsArray = (filter?: FilterSource<any>) => [JSON.stringify(Filter.from(filter).toProto())];\n\nconst noop = () => {};\n\nconst EMPTY_ARRAY: never[] = [];\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useMemo, useSyncExternalStore } from 'react';\n\nimport { type Client } from '@dxos/client';\nimport { type Space } from '@dxos/client/echo';\nimport { ImmutableSchema, type BaseSchema } from '@dxos/echo-schema';\n\n/**\n * Subscribe to and retrieve schema changes from a space's schema registry.\n */\nexport const useSchema = (\n client: Client,\n space: Space | undefined,\n typename: string | undefined,\n): BaseSchema | undefined => {\n const { subscribe, getSchema } = useMemo(() => {\n if (!typename || !space) {\n return {\n subscribe: () => () => {},\n getSchema: () => undefined,\n };\n }\n\n const staticSchema = client.graph.schemaRegistry.getSchema(typename);\n if (staticSchema) {\n // Don't inline into getSchema, need a stable reference.\n const immutableSchema = new ImmutableSchema(staticSchema);\n return {\n subscribe: () => () => {},\n getSchema: () => immutableSchema,\n };\n }\n\n const query = space.db.schemaRegistry.query({ typename });\n const initialResult: BaseSchema = query.runSync()[0];\n let currentSchema = initialResult;\n\n return {\n subscribe: (onStoreChange: () => void) => {\n const unsubscribe = query.subscribe(() => {\n currentSchema = query.results[0];\n onStoreChange();\n });\n\n return unsubscribe;\n },\n getSchema: () => currentSchema,\n };\n }, [typename, space]);\n\n return useSyncExternalStore(subscribe, getSchema);\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { useMemo } from 'react';\n\nimport { MulticastObservable } from '@dxos/async';\nimport { type PublicKey } from '@dxos/client';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useSpace } from './useSpaces';\nimport { type CancellableInvitationObservable, useInvitationStatus } from '../invitations';\n\nexport const useSpaceInvitations = (spaceKey?: PublicKey): CancellableInvitationObservable[] => {\n const space = useSpace(spaceKey);\n return useMulticastObservable(space?.invitations ?? MulticastObservable.empty()) ?? [];\n};\n\nexport const useSpaceInvitation = (spaceKey?: PublicKey, invitationId?: string) => {\n const invitations = useSpaceInvitations(spaceKey);\n const invitation = useMemo(\n () => invitations.find((invitation) => invitation.get().invitationId === invitationId),\n [invitations],\n );\n return useInvitationStatus(invitation);\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { useEffect, useRef } from 'react';\n\nimport { type Selection, type SubscriptionHandle, createSubscription } from '@dxos/client/echo';\n\n/**\n * Create reactive selection.\n * Calls the callback when the selection changes and during the first render.\n */\n// TODO(wittjosiah): Is this still needed with signals reactivity? If not, remove or update jsdoc with usage info.\nexport const useSubscription = (cb: () => void, selection: Selection) => {\n // Make sure that the callback is always the one from the latest render.\n // Without this, we would always call the callback from the initial render,\n // which might contain stale data.\n const callbackRef = useRef(cb);\n callbackRef.current = cb;\n\n const subscriptionRef = useRef<SubscriptionHandle>();\n\n useEffect(() => {\n subscriptionRef.current = createSubscription(() => {\n callbackRef.current();\n });\n\n return () => subscriptionRef.current?.unsubscribe();\n }, []);\n\n subscriptionRef.current?.update(selection);\n return subscriptionRef.current;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect, useMemo, useRef } from 'react';\n\nimport type { Queue } from '@dxos/client/echo';\nimport { raise } from '@dxos/debug';\nimport type { BaseEchoObject } from '@dxos/echo-schema';\nimport { type DXN } from '@dxos/keys';\n\nimport { useClient } from '../client';\n\nconst MIN_POLL_INTERVAL = 1_000;\n\nexport type UseQueueOptions = {\n pollInterval?: number;\n};\n\n/**\n * Polls the given Edge queue.\n */\n// TODO(burdon): Replace polling with socket?\n// TODO(dmaretskyi): Move into client package.\n// TODO(dmaretskyi): Consider passing the space into the hook to support queue DXNs without space id.\n// TODO(ZaymonFC): If queue is unchanged returned object should be refferentially stable on poll.\nexport const useQueue = <T extends BaseEchoObject>(\n queueDxn?: DXN,\n options: UseQueueOptions = {},\n): Queue<T> | undefined => {\n const client = useClient();\n const mountedRef = useRef(true);\n\n const queue = useMemo<Queue<T> | undefined>(() => {\n if (!queueDxn) {\n return undefined;\n }\n const { spaceId } = queueDxn.asQueueDXN() ?? raise(new TypeError('Invalid queue DXN'));\n return client.spaces.get(spaceId)?.queues.get<T>(queueDxn);\n }, [client, queueDxn?.toString()]);\n\n useEffect(() => {\n void queue?.refresh();\n }, [queue]);\n\n useEffect(() => {\n let timeout: NodeJS.Timeout;\n mountedRef.current = true;\n\n const poll = () => {\n if (!mountedRef.current) {\n return;\n }\n\n void queue?.refresh().finally(() => {\n if (mountedRef.current && options.pollInterval) {\n timeout = setTimeout(poll, Math.max(options.pollInterval ?? 0, MIN_POLL_INTERVAL));\n }\n });\n };\n\n if (options.pollInterval) {\n poll();\n }\n\n return () => {\n mountedRef.current = false;\n clearTimeout(timeout);\n };\n }, [queue, options.pollInterval]);\n\n return queue;\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;AAIA,cAAc;;;ACAd,SAASA,2BAA2B;AAEpC,SAASC,uBAAyC;AAClD,SAASC,0BAAAA,+BAA8B;;;ACHvC,SAASC,WAAWC,gBAAgB;AAGpC,SAAqBC,kBAAkB;AACvC,SAASC,8BAA8B;AAYhC,IAAMC,WAAW,CAACC,iBAAAA;AACvB,QAAMC,SAASC,UAAAA;AACf,QAAMC,SAASC,uBAAgCH,OAAOE,MAAM;AAC5D,QAAM,CAACE,OAAOC,QAAAA,IAAYC,SAAS,KAAA;AAEnCC,YAAU,MAAA;AAER,QAAIR,cAAc;AAChB;IACF;AAEA,UAAMS,UAAUC,WAAW,YAAA;AACzB,YAAMT,OAAOE,OAAOQ,eAAc;AAClCL,eAAS,IAAA;IACX,CAAA;AAEA,WAAO,MAAMM,aAAaH,OAAAA;EAC5B,GAAG;IAACR;IAAQD;GAAa;AAEzB,MAAIA,cAAc;AAChB,WAAOG,OAAOU,KAAK,CAACC,UAAUA,MAAMC,IAAIC,OAAOhB,YAAAA,KAAiBc,MAAMG,OAAOjB,YAAAA;EAC/E;AAEA,MAAIK,SAASJ,OAAOiB,KAAKC,SAASC,IAAG,GAAI;AACvC,WAAOnB,OAAOE,OAAOkB;EACvB;AACF;AAeO,IAAMC,YAAY,CAAC,EAAEC,MAAM,MAAK,IAAsB,CAAC,MAAC;AAC7D,QAAMtB,SAASC,UAAAA;AACf,QAAMC,SAASC,uBAAgCH,OAAOE,MAAM;AAG5D,SAAOA,OAAOqB,OAAO,CAACV,UAAUS,OAAOT,MAAMW,MAAML,IAAG,MAAOM,WAAWC,WAAW;AACrF;;;ADxDO,IAAMC,aAAa,CAACC,aAAAA;AAEzB,QAAMC,SAASC,UAAU;IAAEC,KAAK;EAAK,CAAA;AACrC,QAAMC,QAAQJ,WAAWC,OAAOI,KAAK,CAACD,WAAUA,OAAME,IAAIC,OAAOP,QAAAA,CAAAA,IAAaQ;AAG9E,QAAMC,UAAUC,wBAAuBN,OAAOK,WAAWE,oBAAoBC,MAAK,CAAA,KAAO,CAAA;AACzF,SAAOH,QAAQI,OAAO,CAACC,WAAWA,OAAOC,SAASC,gBAAgBC,KAAKC,OAAO;AAChF;;;AEfA,SAASC,SAASC,4BAA4B;AAE9C,
|
|
6
|
-
"names": ["MulticastObservable", "HaloSpaceMember", "useMulticastObservable", "useEffect", "useState", "SpaceState", "useMulticastObservable", "useSpace", "spaceKeyLike", "client", "useClient", "spaces", "useMulticastObservable", "ready", "setReady", "useState", "useEffect", "timeout", "setTimeout", "waitUntilReady", "clearTimeout", "find", "space", "key", "equals", "id", "halo", "identity", "get", "default", "useSpaces", "all", "filter", "state", "SpaceState", "SPACE_READY", "useMembers", "spaceKey", "spaces", "useSpaces", "all", "space", "find", "key", "equals", "undefined", "members", "useMulticastObservable", "MulticastObservable", "empty", "filter", "member", "role", "HaloSpaceMember", "Role", "REMOVED", "useMemo", "useSyncExternalStore", "isSpace", "
|
|
3
|
+
"sources": ["../../../../src/echo/index.ts", "../../../../src/echo/useMembers.ts", "../../../../src/echo/useSpaces.ts", "../../../../src/echo/useQuery.ts", "../../../../src/echo/useQueue.ts", "../../../../src/echo/useSchema.ts", "../../../../src/echo/useSpaceInvitations.ts", "../../../../src/echo/useSubscription.ts", "../../../../src/echo/useSyncState.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nexport * from '@dxos/client/echo';\n\nexport * from './useMembers';\nexport * from './useQuery';\nexport * from './useQueue';\nexport * from './useSchema';\nexport * from './useSpaces';\nexport * from './useSpaceInvitations';\nexport * from './useSubscription';\nexport * from './useSyncState';\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { MulticastObservable } from '@dxos/async';\nimport { type PublicKey } from '@dxos/client';\nimport { HaloSpaceMember, type SpaceMember } from '@dxos/client/echo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useSpaces } from './useSpaces';\n\nexport const useMembers = (spaceKey: PublicKey | undefined): SpaceMember[] => {\n // TODO(dmaretskyi): useSpace hook for spaces that are not ready.\n const spaces = useSpaces({ all: true });\n const space = spaceKey ? spaces.find((space) => space.key.equals(spaceKey)) : undefined;\n\n // EMPTY_OBSERVABLE needs to be a stable reference to avoid re-subscribing on every render.\n const members = useMulticastObservable(space?.members ?? MulticastObservable.empty()) ?? [];\n return members.filter((member) => member.role !== HaloSpaceMember.Role.REMOVED);\n};\n", "//\n// Copyright 2020 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type PublicKeyLike } from '@dxos/client';\nimport { type Space, SpaceState } from '@dxos/client/echo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client';\n\n/**\n * Get a specific Space using its key.\n * The space is not guaranteed to be in the ready state.\n * Returns the default space if no key is provided.\n * Requires a ClientProvider somewhere in the parent tree.\n *\n * @param spaceKeyLike the key of the space to look for\n */\nexport const useSpace = (spaceKeyLike?: PublicKeyLike): Space | undefined => {\n const client = useClient();\n const spaces = useMulticastObservable<Space[]>(client.spaces);\n const [ready, setReady] = useState(false);\n\n useEffect(() => {\n // Only wait for ready if looking for the default space.\n if (spaceKeyLike) {\n return;\n }\n\n const timeout = setTimeout(async () => {\n await client.spaces.waitUntilReady();\n setReady(true);\n });\n\n return () => clearTimeout(timeout);\n }, [client, spaceKeyLike]);\n\n if (spaceKeyLike) {\n return spaces.find((space) => space.key.equals(spaceKeyLike) || space.id === spaceKeyLike);\n }\n\n if (ready && client.halo.identity.get()) {\n return client.spaces.default;\n }\n};\n\nexport type UseSpacesParams = {\n /**\n * Return uninitialized spaces as well.\n */\n all?: boolean;\n};\n\n/**\n * Get all Spaces available to current user.\n * Requires a ClientProvider somewhere in the parent tree.\n * By default, only ready spaces are returned.\n * @returns an array of Spaces\n */\nexport const useSpaces = ({ all = false }: UseSpacesParams = {}): Space[] => {\n const client = useClient();\n const spaces = useMulticastObservable<Space[]>(client.spaces);\n\n // TODO(dmaretskyi): Array reference equality.\n return spaces.filter((space) => all || space.state.get() === SpaceState.SPACE_READY);\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { useMemo, useSyncExternalStore } from 'react';\n\nimport { type Echo, Filter, type Live, Query, type Space, isSpace } from '@dxos/client/echo';\n\nconst EMPTY_ARRAY: never[] = [];\n\nconst noop = () => {};\n\n// TODO(dmaretskyi): Queries are fully serializable, so we can remove `deps` argument.\ninterface UseQueryFn {\n <Q extends Query.Any>(spaceOrEcho: Space | Echo | undefined, query: Q, deps?: any[]): Live<Query.Type<Q>>[];\n\n <F extends Filter.Any>(spaceOrEcho: Space | Echo | undefined, filter: F, deps?: any[]): Live<Filter.Type<F>>[];\n}\n\n/**\n * Create subscription.\n */\nexport const useQuery: UseQueryFn = (\n spaceOrEcho: Space | Echo | undefined,\n queryOrFilter: Query.Any | Filter.Any,\n deps?: any[],\n): Live<unknown>[] => {\n const query = Filter.is(queryOrFilter) ? Query.select(queryOrFilter) : queryOrFilter;\n\n const { getObjects, subscribe } = useMemo(() => {\n let subscribed = false;\n const queryResult =\n spaceOrEcho === undefined\n ? undefined\n : isSpace(spaceOrEcho)\n ? spaceOrEcho.db.query(query)\n : spaceOrEcho.query(query);\n\n return {\n getObjects: () => (subscribed && queryResult ? queryResult.objects : EMPTY_ARRAY),\n subscribe: (cb: () => void) => {\n subscribed = true;\n const unsubscribe = queryResult?.subscribe(cb) ?? noop;\n return () => {\n unsubscribe?.();\n subscribed = false;\n };\n },\n };\n }, [spaceOrEcho, JSON.stringify(query.ast), ...(deps ?? [])]);\n\n // https://beta.reactjs.org/reference/react/useSyncExternalStore\n // NOTE: This hook will resubscribe whenever the callback passed to the first argument changes; make sure it is stable.\n const objects = useSyncExternalStore<Live<unknown>[] | undefined>(subscribe, getObjects);\n return objects ?? [];\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect, useMemo, useRef } from 'react';\n\nimport { type Queue } from '@dxos/client/echo';\nimport { raise } from '@dxos/debug';\nimport { type BaseEchoObject } from '@dxos/echo-schema';\nimport { type DXN } from '@dxos/keys';\n\nimport { useClient } from '../client';\n\nconst MIN_POLL_INTERVAL = 1_000;\n\nexport type UseQueueOptions = {\n pollInterval?: number;\n};\n\n/**\n * Polls the given Edge queue.\n */\n// TODO(burdon): Replace polling with socket?\n// TODO(dmaretskyi): Move into client package.\n// TODO(dmaretskyi): Consider passing the space into the hook to support queue DXNs without space id.\n// TODO(ZaymonFC): If queue is unchanged returned object should be refferentially stable on poll.\nexport const useQueue = <T extends BaseEchoObject>(\n queueDxn?: DXN,\n options: UseQueueOptions = {},\n): Queue<T> | undefined => {\n const client = useClient();\n const mountedRef = useRef(true);\n\n const queue = useMemo<Queue<T> | undefined>(() => {\n if (!queueDxn) {\n return undefined;\n }\n\n const { spaceId } = queueDxn.asQueueDXN() ?? raise(new TypeError('Invalid queue DXN'));\n return client.spaces.get(spaceId)?.queues.get<T>(queueDxn);\n }, [client, queueDxn?.toString()]);\n\n useEffect(() => {\n void queue?.refresh();\n }, [queue]);\n\n useEffect(() => {\n let timeout: NodeJS.Timeout;\n mountedRef.current = true;\n\n const poll = () => {\n if (!mountedRef.current) {\n return;\n }\n\n void queue?.refresh().finally(() => {\n if (mountedRef.current && options.pollInterval) {\n timeout = setTimeout(poll, Math.max(options.pollInterval ?? 0, MIN_POLL_INTERVAL));\n }\n });\n };\n\n if (options.pollInterval) {\n poll();\n }\n\n return () => {\n mountedRef.current = false;\n clearTimeout(timeout);\n };\n }, [queue, options.pollInterval]);\n\n return queue;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Schema } from 'effect';\nimport { useMemo, useSyncExternalStore } from 'react';\n\nimport { type Client } from '@dxos/client';\nimport { type Space } from '@dxos/client/echo';\nimport { type BaseSchema } from '@dxos/echo-schema';\n\n/**\n * Subscribe to and retrieve schema changes from a space's schema registry.\n */\nexport const useSchema = (\n client: Client,\n space: Space | undefined,\n typename: string | undefined,\n): Schema.Schema.AnyNoContext | undefined => {\n const { subscribe, getSchema } = useMemo(() => {\n if (!typename || !space) {\n return {\n subscribe: () => () => {},\n getSchema: () => undefined,\n };\n }\n\n const staticSchema = client.graph.schemaRegistry.getSchema(typename);\n if (staticSchema) {\n return {\n subscribe: () => () => {},\n getSchema: () => staticSchema,\n };\n }\n\n const query = space.db.schemaRegistry.query({ typename });\n const initialResult: BaseSchema = query.runSync()[0];\n let currentSchema = initialResult;\n\n return {\n subscribe: (onStoreChange: () => void) => {\n const unsubscribe = query.subscribe(() => {\n currentSchema = query.results[0];\n onStoreChange();\n });\n\n return unsubscribe;\n },\n getSchema: () => currentSchema,\n };\n }, [typename, space]);\n\n return useSyncExternalStore(subscribe, getSchema);\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { useMemo } from 'react';\n\nimport { MulticastObservable } from '@dxos/async';\nimport { type PublicKey } from '@dxos/client';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useSpace } from './useSpaces';\nimport { type CancellableInvitationObservable, useInvitationStatus } from '../invitations';\n\nexport const useSpaceInvitations = (spaceKey?: PublicKey): CancellableInvitationObservable[] => {\n const space = useSpace(spaceKey);\n return useMulticastObservable(space?.invitations ?? MulticastObservable.empty()) ?? [];\n};\n\nexport const useSpaceInvitation = (spaceKey?: PublicKey, invitationId?: string) => {\n const invitations = useSpaceInvitations(spaceKey);\n const invitation = useMemo(\n () => invitations.find((invitation) => invitation.get().invitationId === invitationId),\n [invitations],\n );\n return useInvitationStatus(invitation);\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { useEffect, useRef } from 'react';\n\nimport { type Selection, type SubscriptionHandle, createSubscription } from '@dxos/client/echo';\n\n/**\n * Create reactive selection.\n * Calls the callback when the selection changes and during the first render.\n */\n// TODO(wittjosiah): Is this still needed with signals reactivity? If not, remove or update jsdoc with usage info.\nexport const useSubscription = (cb: () => void, selection: Selection) => {\n // Make sure that the callback is always the one from the latest render.\n // Without this, we would always call the callback from the initial render,\n // which might contain stale data.\n const callbackRef = useRef(cb);\n callbackRef.current = cb;\n\n const subscriptionRef = useRef<SubscriptionHandle>();\n\n useEffect(() => {\n subscriptionRef.current = createSubscription(() => {\n callbackRef.current();\n });\n\n return () => subscriptionRef.current?.unsubscribe();\n }, []);\n\n subscriptionRef.current?.update(selection);\n return subscriptionRef.current;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type PeerSyncState, type SpaceSyncStateMap, type Space } from '@dxos/client/echo';\nimport { Context } from '@dxos/context';\nimport { type SpaceId } from '@dxos/keys';\nimport { EdgeService } from '@dxos/protocols';\n\nimport { useClient } from '../client';\n\nconst isEdgePeerId = (peerId: string, spaceId: SpaceId) =>\n peerId.startsWith(`${EdgeService.AUTOMERGE_REPLICATOR}:${spaceId}`);\n\n/**\n * Hook Subscribes to sync state for each space.\n */\nexport const useSyncState = (): SpaceSyncStateMap => {\n const client = useClient();\n const [spaceState, setSpaceState] = useState<SpaceSyncStateMap>({});\n\n useEffect(() => {\n const ctx = new Context();\n const createSubscriptions = (spaces: Space[]) => {\n for (const space of spaces) {\n if (spaceState[space.id]) {\n continue;\n }\n\n ctx.onDispose(\n space.crud.subscribeToSyncState(ctx, ({ peers = [] }) => {\n const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));\n if (syncState) {\n setSpaceState((spaceState) => ({ ...spaceState, [space.id]: syncState }));\n }\n }),\n );\n }\n };\n\n createSubscriptions(client.spaces.get());\n client.spaces.subscribe((spaces) => {\n createSubscriptions(spaces);\n });\n\n return () => {\n void ctx.dispose();\n };\n }, [client]);\n\n return spaceState;\n};\n\n/**\n * Hook Subscribes to sync state for a single space.\n */\n// TODO(wittjosiah): Reconcile w/ useSyncState.\nexport const useSpaceSyncState = (space: Space): PeerSyncState | undefined => {\n const [spaceState, setSpaceState] = useState<PeerSyncState>();\n\n useEffect(() => {\n const ctx = new Context();\n space.crud.subscribeToSyncState(ctx, ({ peers = [] }) => {\n const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));\n if (syncState) {\n setSpaceState(syncState);\n }\n });\n\n return () => {\n void ctx.dispose();\n };\n }, [space]);\n\n return spaceState;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAIA,cAAc;;;ACAd,SAASA,2BAA2B;AAEpC,SAASC,uBAAyC;AAClD,SAASC,0BAAAA,+BAA8B;;;ACHvC,SAASC,WAAWC,gBAAgB;AAGpC,SAAqBC,kBAAkB;AACvC,SAASC,8BAA8B;AAYhC,IAAMC,WAAW,CAACC,iBAAAA;AACvB,QAAMC,SAASC,UAAAA;AACf,QAAMC,SAASC,uBAAgCH,OAAOE,MAAM;AAC5D,QAAM,CAACE,OAAOC,QAAAA,IAAYC,SAAS,KAAA;AAEnCC,YAAU,MAAA;AAER,QAAIR,cAAc;AAChB;IACF;AAEA,UAAMS,UAAUC,WAAW,YAAA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,sBAAsB,CAACC,WAAAA;AAC3B,iBAAWC,SAASD,QAAQ;AAC1B,YAAIP,WAAWQ,MAAMC,EAAE,GAAG;AACxB;QACF;AAEAL,YAAIM,UACFF,MAAMG,KAAKC,qBAAqBR,KAAK,CAAC,EAAES,QAAQ,CAAA,EAAE,MAAE;AAClD,gBAAMC,YAAYD,MAAME,KAAK,CAACC,UAAUzB,aAAayB,MAAMxB,QAAQgB,MAAMC,EAAE,CAAA;AAC3E,cAAIK,WAAW;AACbb,0BAAc,CAACD,iBAAgB;cAAE,GAAGA;cAAY,CAACQ,MAAMC,EAAE,GAAGK;YAAU,EAAA;UACxE;QACF,CAAA,CAAA;MAEJ;IACF;AAEAR,wBAAoBR,OAAOS,OAAOU,IAAG,CAAA;AACrCnB,WAAOS,OAAOW,UAAU,CAACX,WAAAA;AACvBD,0BAAoBC,MAAAA;IACtB,CAAA;AAEA,WAAO,MAAA;AACL,WAAKH,IAAIe,QAAO;IAClB;EACF,GAAG;IAACrB;GAAO;AAEX,SAAOE;AACT;AAMO,IAAMoB,oBAAoB,CAACZ,UAAAA;AAChC,QAAM,CAACR,YAAYC,aAAAA,IAAiBC,UAAAA;AAEpCC,EAAAA,WAAU,MAAA;AACR,UAAMC,MAAM,IAAIC,QAAAA,QAAAA;;;;AAChBG,UAAMG,KAAKC,qBAAqBR,KAAK,CAAC,EAAES,QAAQ,CAAA,EAAE,MAAE;AAClD,YAAMC,YAAYD,MAAME,KAAK,CAACC,UAAUzB,aAAayB,MAAMxB,QAAQgB,MAAMC,EAAE,CAAA;AAC3E,UAAIK,WAAW;AACbb,sBAAca,SAAAA;MAChB;IACF,CAAA;AAEA,WAAO,MAAA;AACL,WAAKV,IAAIe,QAAO;IAClB;EACF,GAAG;IAACX;GAAM;AAEV,SAAOR;AACT;",
|
|
6
|
+
"names": ["MulticastObservable", "HaloSpaceMember", "useMulticastObservable", "useEffect", "useState", "SpaceState", "useMulticastObservable", "useSpace", "spaceKeyLike", "client", "useClient", "spaces", "useMulticastObservable", "ready", "setReady", "useState", "useEffect", "timeout", "setTimeout", "waitUntilReady", "clearTimeout", "find", "space", "key", "equals", "id", "halo", "identity", "get", "default", "useSpaces", "all", "filter", "state", "SpaceState", "SPACE_READY", "useMembers", "spaceKey", "spaces", "useSpaces", "all", "space", "find", "key", "equals", "undefined", "members", "useMulticastObservable", "MulticastObservable", "empty", "filter", "member", "role", "HaloSpaceMember", "Role", "REMOVED", "useMemo", "useSyncExternalStore", "Filter", "Query", "isSpace", "EMPTY_ARRAY", "noop", "useQuery", "spaceOrEcho", "queryOrFilter", "deps", "query", "Filter", "is", "Query", "select", "getObjects", "subscribe", "useMemo", "subscribed", "queryResult", "undefined", "isSpace", "db", "objects", "cb", "unsubscribe", "JSON", "stringify", "ast", "useSyncExternalStore", "useEffect", "useMemo", "useRef", "raise", "MIN_POLL_INTERVAL", "useQueue", "queueDxn", "options", "client", "useClient", "mountedRef", "useRef", "queue", "useMemo", "undefined", "spaceId", "asQueueDXN", "raise", "TypeError", "spaces", "get", "queues", "toString", "useEffect", "refresh", "timeout", "current", "poll", "finally", "pollInterval", "setTimeout", "Math", "max", "clearTimeout", "useMemo", "useSyncExternalStore", "useSchema", "client", "space", "typename", "subscribe", "getSchema", "useMemo", "undefined", "staticSchema", "graph", "schemaRegistry", "query", "db", "initialResult", "runSync", "currentSchema", "onStoreChange", "unsubscribe", "results", "useSyncExternalStore", "useMemo", "MulticastObservable", "useMulticastObservable", "useSpaceInvitations", "spaceKey", "space", "useSpace", "useMulticastObservable", "invitations", "MulticastObservable", "empty", "useSpaceInvitation", "invitationId", "invitation", "useMemo", "find", "get", "useInvitationStatus", "useEffect", "useRef", "createSubscription", "useSubscription", "cb", "selection", "callbackRef", "useRef", "current", "subscriptionRef", "useEffect", "createSubscription", "unsubscribe", "update", "useEffect", "useState", "Context", "EdgeService", "isEdgePeerId", "peerId", "spaceId", "startsWith", "EdgeService", "AUTOMERGE_REPLICATOR", "useSyncState", "client", "useClient", "spaceState", "setSpaceState", "useState", "useEffect", "ctx", "Context", "createSubscriptions", "spaces", "space", "id", "onDispose", "crud", "subscribeToSyncState", "peers", "syncState", "find", "state", "get", "subscribe", "dispose", "useSpaceSyncState"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/halo/index.ts", "../../../../src/halo/useContacts.ts", "../../../../src/halo/useCredentials.ts", "../../../../src/halo/useDevices.ts", "../../../../src/halo/useHaloInvitations.ts", "../../../../src/halo/useIdentity.ts", "../../../../src/halo/useKeyStore.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\n// NOTE: Export * fails here.\nexport {\n type Credential,\n type Contact,\n type Identity,\n type Halo,\n Device,\n DeviceKind,\n DeviceType,\n} from '@dxos/client/halo';\n\nexport * from './useContacts';\nexport * from './useCredentials';\nexport * from './useDevices';\nexport * from './useHaloInvitations';\nexport * from './useIdentity';\nexport * from './useKeyStore';\n", "//\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 { useInvitationStatus, type CancellableInvitationObservable } 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() {\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) {\n localStorage.getItem(key);\n }\n\n setKey(key: string, value: string) {\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"],
|
|
5
|
-
"mappings": ";;;;;;;;AAKA,SAKEA,QACAC,YACAC,kBACK;;;ACRP,SAASC,8BAA8B;AAShC,IAAMC,cAAc,MAAA;AACzB,QAAMC,SAASC,UAAAA;AACf,SAAOC,uBAAuBF,OAAOG,KAAKC,QAAQ;AACpD;;;ACZA,SAASC,0BAAAA,+BAA8B;AAIhC,IAAMC,iBAAiB,MAAA;AAC5B,QAAMC,SAASC,UAAAA;AACf,SAAOC,wBAAuBF,OAAOG,KAAKC,WAAW;AACvD;;;ACPA,SAASC,0BAAAA,+BAA8B;AAIhC,IAAMC,aAAa,MAAA;AACxB,QAAMC,SAASC,UAAAA;AACf,SAAOC,wBAAuBF,OAAOG,KAAKC,OAAO;AACnD;;;ACRA,SAASC,eAAe;AAExB,SAASC,0BAAAA,+BAA8B;AAKhC,IAAMC,qBAAqB,MAAA;AAChC,QAAMC,SAASC,UAAAA;AACf,SAAOC,wBAAuBF,OAAOG,KAAKC,WAAW;AACvD;AAEO,IAAMC,oBAAoB,CAACC,iBAAAA;AAChC,QAAMF,cAAcL,mBAAAA;AACpB,QAAMQ,aAAaC,QACjB,MAAMJ,YAAYK,KAAK,CAACF,gBAAeA,YAAWG,IAAG,EAAGJ,iBAAiBA,YAAAA,GACzE;IAACF;GAAY;AAEf,SAAOO,oBAAoBJ,UAAAA;AAC7B;;;AClBA,SAASK,0BAAAA,+BAA8B;AAQhC,IAAMC,cAAc,MAAA;AACzB,QAAMC,SAASC,UAAAA;AACf,SAAOC,wBAAuBF,OAAOG,KAAKC,QAAQ;AACpD;;;ACZA,SAASC,WAAAA,UAASC,kBAAkB;AAG7B,IAAMC,WAAN,MAAMA;
|
|
6
|
-
"names": ["Device", "DeviceKind", "DeviceType", "useMulticastObservable", "useContacts", "client", "useClient", "useMulticastObservable", "halo", "contacts", "useMulticastObservable", "useCredentials", "client", "useClient", "useMulticastObservable", "halo", "credentials", "useMulticastObservable", "useDevices", "client", "useClient", "useMulticastObservable", "halo", "devices", "useMemo", "useMulticastObservable", "useHaloInvitations", "client", "useClient", "useMulticastObservable", "halo", "invitations", "useHaloInvitation", "invitationId", "invitation", "useMemo", "find", "get", "useInvitationStatus", "useMulticastObservable", "useIdentity", "client", "useClient", "useMulticastObservable", "halo", "identity", "useMemo", "useReducer", "KeyStore", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\n// NOTE: Export * fails here.\nexport {\n type Credential,\n type Contact,\n type Identity,\n type Halo,\n Device,\n DeviceKind,\n DeviceType,\n} from '@dxos/client/halo';\n\nexport * from './useContacts';\nexport * from './useCredentials';\nexport * from './useDevices';\nexport * from './useHaloInvitations';\nexport * from './useIdentity';\nexport * from './useKeyStore';\n", "//\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 { useInvitationStatus, type CancellableInvitationObservable } 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"],
|
|
5
|
+
"mappings": ";;;;;;;;AAKA,SAKEA,QACAC,YACAC,kBACK;;;ACRP,SAASC,8BAA8B;AAShC,IAAMC,cAAc,MAAA;AACzB,QAAMC,SAASC,UAAAA;AACf,SAAOC,uBAAuBF,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AI,OAAOJ,KAAaC,OAAqB;AACvCC,iBAAaI,QAAQN,KAAK,EAAA;AAC1B,SAAKL,QAAQY,IAAIP,KAAKC,KAAAA;EACxB;AACF;AAMO,IAAMO,cAAc,CACzBC,cAAwB,CAAA,MAAE;AAE1B,QAAM,CAAA,EAAGC,WAAAA,IAAeC,WAAW,CAACC,MAAMA,IAAI,GAAG,CAAA;AACjD,QAAMC,QAAQC,SAAQ,MAAM,IAAIrB,SAASgB,WAAAA,EAAaX,WAAU,GAAI;IAACW;GAAY;AACjF,QAAML,SAAS,CAACJ,KAAaC,UAAAA;AAC3BY,UAAMT,OAAOJ,KAAKC,KAAAA;AAClBS,gBAAAA;EACF;AAEA,SAAO;IAACG,MAAMhB;IAAKO;;AACrB;",
|
|
6
|
+
"names": ["Device", "DeviceKind", "DeviceType", "useMulticastObservable", "useContacts", "client", "useClient", "useMulticastObservable", "halo", "contacts", "useMulticastObservable", "useCredentials", "client", "useClient", "useMulticastObservable", "halo", "credentials", "useMulticastObservable", "useDevices", "client", "useClient", "useMulticastObservable", "halo", "devices", "useMemo", "useMulticastObservable", "useHaloInvitations", "client", "useClient", "useMulticastObservable", "halo", "invitations", "useHaloInvitation", "invitationId", "invitation", "useMemo", "find", "get", "useInvitationStatus", "useMulticastObservable", "useIdentity", "client", "useClient", "useMulticastObservable", "halo", "identity", "useMemo", "useReducer", "KeyStore", "_defaultKeys", "_keyMap", "Map", "map", "initialize", "forEach", "key", "value", "localStorage", "getItem", "setKey", "getKey", "setItem", "set", "useKeyStore", "defaultKeys", "forceUpdate", "useReducer", "x", "store", "useMemo"]
|
|
7
7
|
}
|