@dxos/react-client 0.8.4-main.74a063c4e0 → 0.8.4-main.765dc60934

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.
Files changed (88) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +1 -1
  3. package/dist/lib/browser/{chunk-PFF63FPR.mjs → chunk-3LVU7RNK.mjs} +2 -2
  4. package/dist/lib/browser/{chunk-TSF6Y5VB.mjs → chunk-CZMIVAGI.mjs} +1 -1
  5. package/dist/lib/browser/{chunk-TSF6Y5VB.mjs.map → chunk-CZMIVAGI.mjs.map} +2 -2
  6. package/dist/lib/browser/{chunk-BVDNYEYI.mjs → chunk-XT352YI6.mjs} +11 -56
  7. package/dist/lib/browser/{chunk-BVDNYEYI.mjs.map → chunk-XT352YI6.mjs.map} +2 -2
  8. package/dist/lib/browser/{chunk-LO3TU5CK.mjs → chunk-YHE6WD44.mjs} +3 -13
  9. package/dist/lib/browser/{chunk-LO3TU5CK.mjs.map → chunk-YHE6WD44.mjs.map} +2 -2
  10. package/dist/lib/browser/devtools/index.mjs +3 -8
  11. package/dist/lib/browser/devtools/index.mjs.map +2 -2
  12. package/dist/lib/browser/echo/index.mjs +14 -70
  13. package/dist/lib/browser/echo/index.mjs.map +4 -4
  14. package/dist/lib/browser/halo/index.mjs +3 -3
  15. package/dist/lib/browser/halo/index.mjs.map +2 -2
  16. package/dist/lib/browser/index.mjs +6 -21
  17. package/dist/lib/browser/index.mjs.map +2 -2
  18. package/dist/lib/browser/invitations/index.mjs +1 -1
  19. package/dist/lib/browser/mesh/index.mjs +2 -2
  20. package/dist/lib/browser/meta.json +1 -1
  21. package/dist/lib/browser/testing/index.mjs +5 -20
  22. package/dist/lib/browser/testing/index.mjs.map +3 -3
  23. package/dist/lib/node-esm/{chunk-NETTSER2.mjs → chunk-CUDKNAMV.mjs} +2 -2
  24. package/dist/lib/node-esm/{chunk-AQJH2UNZ.mjs → chunk-RQJPEHDY.mjs} +3 -13
  25. package/dist/lib/node-esm/{chunk-AQJH2UNZ.mjs.map → chunk-RQJPEHDY.mjs.map} +2 -2
  26. package/dist/lib/node-esm/{chunk-VSA674XR.mjs → chunk-WL3Z5HOH.mjs} +11 -56
  27. package/dist/lib/node-esm/{chunk-VSA674XR.mjs.map → chunk-WL3Z5HOH.mjs.map} +2 -2
  28. package/dist/lib/node-esm/{chunk-373DPHEQ.mjs → chunk-WUTK2IJF.mjs} +1 -1
  29. package/dist/lib/node-esm/{chunk-373DPHEQ.mjs.map → chunk-WUTK2IJF.mjs.map} +2 -2
  30. package/dist/lib/node-esm/devtools/index.mjs +3 -8
  31. package/dist/lib/node-esm/devtools/index.mjs.map +2 -2
  32. package/dist/lib/node-esm/echo/index.mjs +14 -70
  33. package/dist/lib/node-esm/echo/index.mjs.map +4 -4
  34. package/dist/lib/node-esm/halo/index.mjs +3 -3
  35. package/dist/lib/node-esm/halo/index.mjs.map +2 -2
  36. package/dist/lib/node-esm/index.mjs +6 -21
  37. package/dist/lib/node-esm/index.mjs.map +2 -2
  38. package/dist/lib/node-esm/invitations/index.mjs +1 -1
  39. package/dist/lib/node-esm/mesh/index.mjs +2 -2
  40. package/dist/lib/node-esm/meta.json +1 -1
  41. package/dist/lib/node-esm/testing/index.mjs +5 -20
  42. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  43. package/dist/types/src/banner.d.ts.map +1 -1
  44. package/dist/types/src/client/AgentHostingProvider.d.ts.map +1 -1
  45. package/dist/types/src/client/ClientProvider.d.ts +1 -1
  46. package/dist/types/src/client/useClientStatus.d.ts.map +1 -1
  47. package/dist/types/src/devtools/useStream.d.ts.map +1 -1
  48. package/dist/types/src/echo/index.d.ts +0 -1
  49. package/dist/types/src/echo/index.d.ts.map +1 -1
  50. package/dist/types/src/echo/useMembers.d.ts.map +1 -1
  51. package/dist/types/src/echo/useSpaceInvitations.d.ts +1 -1
  52. package/dist/types/src/echo/useSpaceInvitations.d.ts.map +1 -1
  53. package/dist/types/src/echo/useSpaceProperties.d.ts.map +1 -1
  54. package/dist/types/src/echo/useSpaces.d.ts +4 -2
  55. package/dist/types/src/echo/useSpaces.d.ts.map +1 -1
  56. package/dist/types/src/echo/useSubscription.d.ts.map +1 -1
  57. package/dist/types/src/echo/useSyncState.d.ts.map +1 -1
  58. package/dist/types/src/halo/Passkey.stories.d.ts.map +1 -1
  59. package/dist/types/src/halo/useHaloInvitations.d.ts.map +1 -1
  60. package/dist/types/src/halo/useKeyStore.d.ts.map +1 -1
  61. package/dist/types/src/invitations/useInvitationStatus.d.ts.map +1 -1
  62. package/dist/types/src/testing/ClientRepeater.d.ts +1 -1
  63. package/dist/types/src/testing/ClientRepeater.d.ts.map +1 -1
  64. package/dist/types/src/testing/ClientRepeater.stories.d.ts.map +1 -1
  65. package/dist/types/src/testing/context.d.ts +2 -1
  66. package/dist/types/src/testing/context.d.ts.map +1 -1
  67. package/dist/types/src/testing/util.d.ts.map +1 -1
  68. package/dist/types/src/testing/withClientProvider.d.ts.map +1 -1
  69. package/dist/types/src/testing/withClientProvider.stories.d.ts.map +1 -1
  70. package/dist/types/tsconfig.tsbuildinfo +1 -1
  71. package/package.json +26 -50
  72. package/src/echo/index.ts +0 -1
  73. package/src/echo/useSpaceInvitations.ts +1 -1
  74. package/src/echo/useSpaces.test.tsx +1 -1
  75. package/src/echo/useSpaces.ts +3 -2
  76. package/src/halo/Passkey.stories.tsx +2 -4
  77. package/src/testing/ClientRepeater.stories.tsx +3 -5
  78. package/src/testing/ClientRepeater.tsx +1 -1
  79. package/src/testing/context.tsx +2 -1
  80. package/src/testing/withClientProvider.stories.tsx +3 -3
  81. package/src/testing/withClientProvider.tsx +2 -1
  82. package/tsconfig.json +3 -0
  83. package/.swc/plugins/linux_x86_64_19.0.0/727453fb3a62f7f1d952a41e051ca8a6f88cadc45cee43c6a4d1aa45f9b75665.wasmer-v7 +0 -0
  84. package/dist/types/src/echo/useQueue.d.ts +0 -12
  85. package/dist/types/src/echo/useQueue.d.ts.map +0 -1
  86. package/src/echo/useQueue.ts +0 -75
  87. /package/dist/lib/browser/{chunk-PFF63FPR.mjs.map → chunk-3LVU7RNK.mjs.map} +0 -0
  88. /package/dist/lib/node-esm/{chunk-NETTSER2.mjs.map → chunk-CUDKNAMV.mjs.map} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-client",
3
- "version": "0.8.4-main.74a063c4e0",
3
+ "version": "0.8.4-main.765dc60934",
4
4
  "description": "React client API",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -8,7 +8,7 @@
8
8
  "type": "git",
9
9
  "url": "https://github.com/dxos/dxos"
10
10
  },
11
- "license": "MIT",
11
+ "license": "FSL-1.1-Apache-2.0",
12
12
  "author": "DXOS.org",
13
13
  "sideEffects": false,
14
14
  "type": "module",
@@ -63,46 +63,22 @@
63
63
  }
64
64
  },
65
65
  "types": "dist/types/src/index.d.ts",
66
- "typesVersions": {
67
- "*": {
68
- "devtools": [
69
- "dist/types/src/devtools/index.d.ts"
70
- ],
71
- "echo": [
72
- "dist/types/src/echo/index.d.ts"
73
- ],
74
- "halo": [
75
- "dist/types/src/halo/index.d.ts"
76
- ],
77
- "invitations": [
78
- "dist/types/src/invitations/index.d.ts"
79
- ],
80
- "mesh": [
81
- "dist/types/src/mesh/index.d.ts"
82
- ],
83
- "testing": [
84
- "dist/types/src/testing/index.d.ts"
85
- ],
86
- "worker": [
87
- "dist/types/src/worker.d.ts"
88
- ]
89
- }
90
- },
91
66
  "dependencies": {
92
- "@dxos/async": "0.8.4-main.74a063c4e0",
93
- "@dxos/codec-protobuf": "0.8.4-main.74a063c4e0",
94
- "@dxos/config": "0.8.4-main.74a063c4e0",
95
- "@dxos/client": "0.8.4-main.74a063c4e0",
96
- "@dxos/context": "0.8.4-main.74a063c4e0",
97
- "@dxos/debug": "0.8.4-main.74a063c4e0",
98
- "@dxos/echo-react": "0.8.4-main.74a063c4e0",
99
- "@dxos/invariant": "0.8.4-main.74a063c4e0",
100
- "@dxos/echo": "0.8.4-main.74a063c4e0",
101
- "@dxos/log": "0.8.4-main.74a063c4e0",
102
- "@dxos/node-std": "0.8.4-main.74a063c4e0",
103
- "@dxos/util": "0.8.4-main.74a063c4e0",
104
- "@dxos/react-hooks": "0.8.4-main.74a063c4e0",
105
- "@dxos/protocols": "0.8.4-main.74a063c4e0"
67
+ "@dxos/async": "0.8.4-main.765dc60934",
68
+ "@dxos/client": "0.8.4-main.765dc60934",
69
+ "@dxos/config": "0.8.4-main.765dc60934",
70
+ "@dxos/context": "0.8.4-main.765dc60934",
71
+ "@dxos/debug": "0.8.4-main.765dc60934",
72
+ "@dxos/echo-react": "0.8.4-main.765dc60934",
73
+ "@dxos/echo": "0.8.4-main.765dc60934",
74
+ "@dxos/invariant": "0.8.4-main.765dc60934",
75
+ "@dxos/keys": "0.8.4-main.765dc60934",
76
+ "@dxos/log": "0.8.4-main.765dc60934",
77
+ "@dxos/codec-protobuf": "0.8.4-main.765dc60934",
78
+ "@dxos/node-std": "0.8.4-main.765dc60934",
79
+ "@dxos/protocols": "0.8.4-main.765dc60934",
80
+ "@dxos/react-hooks": "0.8.4-main.765dc60934",
81
+ "@dxos/util": "0.8.4-main.765dc60934"
106
82
  },
107
83
  "devDependencies": {
108
84
  "@types/react": "~19.2.7",
@@ -110,21 +86,21 @@
110
86
  "react": "~19.2.3",
111
87
  "react-dom": "~19.2.3",
112
88
  "typedoc": "0.28.1",
113
- "@dxos/random": "0.8.4-main.74a063c4e0",
114
- "@dxos/react-ui-syntax-highlighter": "0.8.4-main.74a063c4e0",
115
- "@dxos/storybook-utils": "0.8.4-main.74a063c4e0",
116
- "@dxos/ui-theme": "0.8.4-main.74a063c4e0",
117
- "@dxos/test-utils": "0.8.4-main.74a063c4e0",
118
- "@dxos/react-ui": "0.8.4-main.74a063c4e0"
89
+ "@dxos/random": "0.8.4-main.765dc60934",
90
+ "@dxos/react-ui": "0.8.4-main.765dc60934",
91
+ "@dxos/react-ui-syntax-highlighter": "0.8.4-main.765dc60934",
92
+ "@dxos/storybook-utils": "0.8.4-main.765dc60934",
93
+ "@dxos/test-utils": "0.8.4-main.765dc60934",
94
+ "@dxos/ui-theme": "0.8.4-main.765dc60934"
119
95
  },
120
96
  "peerDependencies": {
121
97
  "react": "~19.2.3",
122
98
  "react-dom": "~19.2.3"
123
99
  },
124
100
  "optionalDependencies": {
125
- "@dxos/react-ui": "0.8.4-main.74a063c4e0",
126
- "@dxos/ui-theme": "0.8.4-main.74a063c4e0",
127
- "@dxos/random": "0.8.4-main.74a063c4e0"
101
+ "@dxos/random": "0.8.4-main.765dc60934",
102
+ "@dxos/react-ui": "0.8.4-main.765dc60934",
103
+ "@dxos/ui-theme": "0.8.4-main.765dc60934"
128
104
  },
129
105
  "publishConfig": {
130
106
  "access": "public"
package/src/echo/index.ts CHANGED
@@ -6,7 +6,6 @@ export * from '@dxos/client/echo';
6
6
  export * from '@dxos/echo-react';
7
7
 
8
8
  export * from './useMembers';
9
- export * from './useQueue';
10
9
  export * from './useSpaces';
11
10
  export * from './useSpaceInvitations';
12
11
  export * from './useSpaceProperties';
@@ -6,7 +6,7 @@ import { useMemo } from 'react';
6
6
 
7
7
  import { MulticastObservable } from '@dxos/async';
8
8
  import { type PublicKey } from '@dxos/client';
9
- import { type SpaceId } from '@dxos/client/echo';
9
+ import { type SpaceId } from '@dxos/keys';
10
10
  import { useMulticastObservable } from '@dxos/react-hooks';
11
11
 
12
12
  import { type CancellableInvitationObservable, useInvitationStatus } from '../invitations';
@@ -33,7 +33,7 @@ describe('useSpace', () => {
33
33
  test('returns undefined when no id provided', async () => {
34
34
  const { client } = await createClient({ createIdentity: true });
35
35
  const wrapper = await createClientContextProvider(client);
36
- const { result } = renderHook(() => useSpace(), { wrapper });
36
+ const { result } = renderHook(() => useSpace(undefined), { wrapper });
37
37
  expect(result.current).to.be.undefined;
38
38
  });
39
39
 
@@ -3,7 +3,8 @@
3
3
  //
4
4
 
5
5
  import { PublicKey } from '@dxos/client';
6
- import { type Space, type SpaceId, SpaceState } from '@dxos/client/echo';
6
+ import { type Space, SpaceState } from '@dxos/client/echo';
7
+ import { type SpaceId } from '@dxos/keys';
7
8
  import { useMulticastObservable } from '@dxos/react-hooks';
8
9
 
9
10
  import { useClient } from '../client';
@@ -21,7 +22,6 @@ import { useClient } from '../client';
21
22
  export const useSpace = (spaceId?: SpaceId | PublicKey): Space | undefined => {
22
23
  const client = useClient();
23
24
  const spaces = useMulticastObservable<Space[]>(client.spaces);
24
-
25
25
  if (!spaceId) {
26
26
  return undefined;
27
27
  }
@@ -42,6 +42,7 @@ export const useSpace = (spaceId?: SpaceId | PublicKey): Space | undefined => {
42
42
  * Requires a ClientProvider somewhere in the parent tree.
43
43
  *
44
44
  * @param spaceId the id of the space to look for.
45
+ * @deprecated Use useSpace.
45
46
  */
46
47
  export const useDatabase = (spaceId?: SpaceId): Space['db'] | undefined => {
47
48
  const space = useSpace(spaceId);
@@ -9,7 +9,7 @@ import { Config, PublicKey } from '@dxos/client';
9
9
  import { invariant } from '@dxos/invariant';
10
10
  import { log } from '@dxos/log';
11
11
  import { Button } from '@dxos/react-ui';
12
- import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
12
+ import { JsonHighlighter } from '@dxos/react-ui-syntax-highlighter';
13
13
  import { withTheme } from '@dxos/react-ui/testing';
14
14
 
15
15
  import { useClient } from '../client';
@@ -116,9 +116,7 @@ const Test = () => {
116
116
  </Button>
117
117
  </div>
118
118
  <div className='flex flex-col min-w-[28rem] divide-y divide-separator border border-separator rounded-sm'>
119
- <SyntaxHighlighter language='json'>
120
- {JSON.stringify({ identity, credentials: credentials.length }, null, 2)}
121
- </SyntaxHighlighter>
119
+ <JsonHighlighter data={{ identity, credentials: credentials.length }} />
122
120
  </div>
123
121
  </>
124
122
  );
@@ -7,7 +7,7 @@ import React from 'react';
7
7
 
8
8
  import { Obj } from '@dxos/echo';
9
9
  import { Input } from '@dxos/react-ui';
10
- import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
10
+ import { JsonHighlighter } from '@dxos/react-ui-syntax-highlighter';
11
11
  import { withTheme } from '@dxos/react-ui/testing';
12
12
 
13
13
  import { useClient } from '../client';
@@ -23,9 +23,7 @@ export default meta;
23
23
 
24
24
  type Story = StoryObj<typeof meta>;
25
25
 
26
- const JsonPanel = ({ value }: { value: any }) => (
27
- <SyntaxHighlighter language='json'>{JSON.stringify(value, undefined, 2)}</SyntaxHighlighter>
28
- );
26
+ const JsonPanel = ({ value }: { value: any }) => <JsonHighlighter data={value} />;
29
27
 
30
28
  const ClientStory = () => {
31
29
  const client = useClient();
@@ -46,7 +44,7 @@ const ClientSpace = ({ spaceId }: ClientRepeatedComponentProps) => {
46
44
  placeholder='Name'
47
45
  value={space.properties.name}
48
46
  onChange={(event) =>
49
- Obj.change(space.properties, (obj) => {
47
+ Obj.update(space.properties, (obj) => {
50
48
  obj.name = event.target.value;
51
49
  })
52
50
  }
@@ -7,11 +7,11 @@ import React, { type FC, useRef, useState } from 'react';
7
7
  import { Client } from '@dxos/client';
8
8
  import { TestBuilder, performInvitation } from '@dxos/client/testing';
9
9
  import { type Type } from '@dxos/echo';
10
+ import { type SpaceId } from '@dxos/keys';
10
11
  import { random } from '@dxos/random';
11
12
  import { useAsyncEffect } from '@dxos/react-hooks';
12
13
 
13
14
  import { ClientProvider } from '../client';
14
- import { type SpaceId } from '../echo';
15
15
  import { type WithClientProviderProps } from './withClientProvider';
16
16
 
17
17
  export type ClientRepeatedComponentProps = { id: number; count: number; spaceId?: SpaceId };
@@ -4,8 +4,9 @@
4
4
 
5
5
  import { createContext, useContext } from 'react';
6
6
 
7
- import { type Space, type SpaceId } from '@dxos/client/echo';
7
+ import { type Space } from '@dxos/client/echo';
8
8
  import { raise } from '@dxos/debug';
9
+ import { type SpaceId } from '@dxos/keys';
9
10
 
10
11
  export type ClientStory = {
11
12
  index?: number;
@@ -7,7 +7,7 @@ import React from 'react';
7
7
  import { expect, within } from 'storybook/test';
8
8
 
9
9
  import { log } from '@dxos/log';
10
- import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
10
+ import { JsonHighlighter } from '@dxos/react-ui-syntax-highlighter';
11
11
  import { withLayout, withTheme, Loading } from '@dxos/react-ui/testing';
12
12
 
13
13
  import { useClient } from '../client';
@@ -16,7 +16,7 @@ import { type WithClientProviderProps, withClientProvider, withMultiClientProvid
16
16
 
17
17
  const SpaceInfo = ({ space }: { space: Space }) => {
18
18
  const name = space.isOpen ? space.properties.name : '';
19
- return <SyntaxHighlighter language='json'>{JSON.stringify({ id: space.id, name }, null, 2)}</SyntaxHighlighter>;
19
+ return <JsonHighlighter data={{ id: space.id, name }} />;
20
20
  };
21
21
 
22
22
  const DefaultStory = () => {
@@ -28,7 +28,7 @@ const DefaultStory = () => {
28
28
 
29
29
  return (
30
30
  <div className='flex flex-col divide-y divide-separator border border-separator'>
31
- <SyntaxHighlighter language='json'>{JSON.stringify(client.toJSON(), null, 2)}</SyntaxHighlighter>
31
+ <JsonHighlighter data={client.toJSON()} />
32
32
  {spaces.map((space) => (
33
33
  <SpaceInfo key={space.id} space={space} />
34
34
  ))}
@@ -7,8 +7,9 @@ import React, { useCallback, useMemo, useRef, useState } from 'react';
7
7
 
8
8
  import { Trigger } from '@dxos/async';
9
9
  import { type Client } from '@dxos/client';
10
- import { type Space, type SpaceId } from '@dxos/client/echo';
10
+ import { type Space } from '@dxos/client/echo';
11
11
  import { TestBuilder, performInvitation } from '@dxos/client/testing';
12
+ import { type SpaceId } from '@dxos/keys';
12
13
  import { log } from '@dxos/log';
13
14
  import { ErrorBoundary } from '@dxos/react-ui';
14
15
  import { type MaybePromise } from '@dxos/util';
package/tsconfig.json CHANGED
@@ -23,6 +23,9 @@
23
23
  {
24
24
  "path": "../../common/invariant"
25
25
  },
26
+ {
27
+ "path": "../../common/keys"
28
+ },
26
29
  {
27
30
  "path": "../../common/log"
28
31
  },
@@ -1,12 +0,0 @@
1
- import { type Queue } from '@dxos/client/echo';
2
- import { type Entity } from '@dxos/echo';
3
- import { type DXN } from '@dxos/keys';
4
- export type UseQueueOptions = {
5
- pollInterval?: number;
6
- };
7
- /**
8
- * Polls the given Edge queue.
9
- * @deprecated Use `useQuery` instead.
10
- */
11
- export declare const useQueue: <T extends Entity.Unknown>(queueDxn?: DXN, options?: UseQueueOptions) => Queue<T> | undefined;
12
- //# sourceMappingURL=useQueue.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useQueue.d.ts","sourceRoot":"","sources":["../../../../src/echo/useQueue.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,YAAY,CAAC;AAMtC,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;GAGG;AAKH,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,MAAM,CAAC,OAAO,EAC/C,WAAW,GAAG,EACd,UAAS,eAAoB,KAC5B,KAAK,CAAC,CAAC,CAAC,GAAG,SA4Cb,CAAC"}
@@ -1,75 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { useEffect, useMemo, useRef } from 'react';
6
-
7
- import { type Queue } from '@dxos/client/echo';
8
- import { raise } from '@dxos/debug';
9
- import { type Entity } from '@dxos/echo';
10
- import { type DXN } from '@dxos/keys';
11
-
12
- import { useClient } from '../client';
13
-
14
- const MIN_POLL_INTERVAL = 1_000;
15
-
16
- export type UseQueueOptions = {
17
- pollInterval?: number;
18
- };
19
-
20
- /**
21
- * Polls the given Edge queue.
22
- * @deprecated Use `useQuery` instead.
23
- */
24
- // TODO(burdon): Replace polling with socket?
25
- // TODO(dmaretskyi): Move into client package.
26
- // TODO(dmaretskyi): Consider passing the space into the hook to support queue DXNs without space id.
27
- // TODO(ZaymonFC): If queue is unchanged returned object should be refferentially stable on poll.
28
- export const useQueue = <T extends Entity.Unknown>(
29
- queueDxn?: DXN,
30
- options: UseQueueOptions = {},
31
- ): Queue<T> | undefined => {
32
- const client = useClient();
33
- const mountedRef = useRef(true);
34
-
35
- const queue = useMemo<Queue<T> | undefined>(() => {
36
- if (!queueDxn) {
37
- return undefined;
38
- }
39
-
40
- const { spaceId } = queueDxn.asQueueDXN() ?? raise(new TypeError('Invalid queue DXN'));
41
- return client.spaces.get(spaceId)?.queues.get<T>(queueDxn);
42
- }, [client, queueDxn?.toString()]);
43
-
44
- useEffect(() => {
45
- void queue?.refresh();
46
- }, [queue]);
47
-
48
- useEffect(() => {
49
- let timeout: NodeJS.Timeout;
50
- mountedRef.current = true;
51
-
52
- const poll = () => {
53
- if (!mountedRef.current) {
54
- return;
55
- }
56
-
57
- void queue?.refresh().finally(() => {
58
- if (mountedRef.current && options.pollInterval) {
59
- timeout = setTimeout(poll, Math.max(options.pollInterval ?? 0, MIN_POLL_INTERVAL));
60
- }
61
- });
62
- };
63
-
64
- if (options.pollInterval) {
65
- poll();
66
- }
67
-
68
- return () => {
69
- mountedRef.current = false;
70
- clearTimeout(timeout);
71
- };
72
- }, [queue, options.pollInterval]);
73
-
74
- return queue;
75
- };