@dxos/react-client 0.8.1-main.ba2dec9 → 0.8.1-staging.5be625a

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/echo/index.ts"],"names":[],"mappings":"AAIA,cAAc,mBAAmB,CAAC;AAElC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/echo/index.ts"],"names":[],"mappings":"AAIA,cAAc,mBAAmB,CAAC;AAElC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { Queue } from '@dxos/client/echo';
2
+ import type { BaseEchoObject } from '@dxos/echo-schema';
3
+ import { type DXN } from '@dxos/keys';
4
+ export type UseQueueOptions = {
5
+ pollInterval?: number;
6
+ };
7
+ /**
8
+ * Polls the given Edge queue.
9
+ */
10
+ export declare const useQueue: <T extends BaseEchoObject>(queueDxn?: DXN, options?: UseQueueOptions) => Queue<T> | undefined;
11
+ //# sourceMappingURL=useQueue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useQueue.d.ts","sourceRoot":"","sources":["../../../../src/echo/useQueue.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,YAAY,CAAC;AAMtC,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;GAEG;AAIH,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,cAAc,aACpC,GAAG,YACL,eAAe,KACvB,KAAK,CAAC,CAAC,CAAC,GAAG,SAgCb,CAAC"}
@@ -1,7 +1,8 @@
1
+ import { type Client } from '@dxos/client';
1
2
  import { type Space } from '@dxos/client/echo';
2
- import { type EchoSchema } from '@dxos/echo-schema';
3
+ import { type BaseSchema } from '@dxos/echo-schema';
3
4
  /**
4
5
  * Subscribe to and retrieve schema changes from a space's schema registry.
5
6
  */
6
- export declare const useSchema: (space: Space | undefined, typename: string | undefined) => EchoSchema | undefined;
7
+ export declare const useSchema: (client: Client, space: Space | undefined, typename: string | undefined) => BaseSchema | undefined;
7
8
  //# sourceMappingURL=useSchema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSchema.d.ts","sourceRoot":"","sources":["../../../../src/echo/useSchema.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;GAEG;AACH,eAAO,MAAM,SAAS,UAAW,KAAK,GAAG,SAAS,YAAY,MAAM,GAAG,SAAS,KAAG,UAAU,GAAG,SA0B/F,CAAC"}
1
+ {"version":3,"file":"useSchema.d.ts","sourceRoot":"","sources":["../../../../src/echo/useSchema.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAmB,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAErE;;GAEG;AACH,eAAO,MAAM,SAAS,WACZ,MAAM,SACP,KAAK,GAAG,SAAS,YACd,MAAM,GAAG,SAAS,KAC3B,UAAU,GAAG,SAqCf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-client",
3
- "version": "0.8.1-main.ba2dec9",
3
+ "version": "0.8.1-staging.5be625a",
4
4
  "description": "React client API",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -78,40 +78,40 @@
78
78
  },
79
79
  "dependencies": {
80
80
  "react-error-boundary": "^4.0.13",
81
- "@dxos/codec-protobuf": "0.8.1-main.ba2dec9",
82
- "@dxos/async": "0.8.1-main.ba2dec9",
83
- "@dxos/client": "0.8.1-main.ba2dec9",
84
- "@dxos/config": "0.8.1-main.ba2dec9",
85
- "@dxos/debug": "0.8.1-main.ba2dec9",
86
- "@dxos/echo-signals": "0.8.1-main.ba2dec9",
87
- "@dxos/echo-schema": "0.8.1-main.ba2dec9",
88
- "@dxos/invariant": "0.8.1-main.ba2dec9",
89
- "@dxos/log": "0.8.1-main.ba2dec9",
90
- "@dxos/node-std": "0.8.1-main.ba2dec9",
91
- "@dxos/protocols": "0.8.1-main.ba2dec9",
92
- "@dxos/react-hooks": "0.8.1-main.ba2dec9",
93
- "@dxos/util": "0.8.1-main.ba2dec9"
81
+ "@dxos/async": "0.8.1-staging.5be625a",
82
+ "@dxos/codec-protobuf": "0.8.1-staging.5be625a",
83
+ "@dxos/client": "0.8.1-staging.5be625a",
84
+ "@dxos/config": "0.8.1-staging.5be625a",
85
+ "@dxos/echo-schema": "0.8.1-staging.5be625a",
86
+ "@dxos/echo-signals": "0.8.1-staging.5be625a",
87
+ "@dxos/log": "0.8.1-staging.5be625a",
88
+ "@dxos/node-std": "0.8.1-staging.5be625a",
89
+ "@dxos/debug": "0.8.1-staging.5be625a",
90
+ "@dxos/invariant": "0.8.1-staging.5be625a",
91
+ "@dxos/protocols": "0.8.1-staging.5be625a",
92
+ "@dxos/react-hooks": "0.8.1-staging.5be625a",
93
+ "@dxos/util": "0.8.1-staging.5be625a"
94
94
  },
95
95
  "devDependencies": {
96
96
  "@types/react": "~18.2.0",
97
97
  "@types/react-dom": "~18.2.0",
98
98
  "react": "~18.2.0",
99
99
  "react-dom": "~18.2.0",
100
- "@dxos/random": "0.8.1-main.ba2dec9",
101
- "@dxos/react-ui": "0.8.1-main.ba2dec9",
102
- "@dxos/react-ui-syntax-highlighter": "0.8.1-main.ba2dec9",
103
- "@dxos/react-ui-theme": "0.8.1-main.ba2dec9",
104
- "@dxos/storybook-utils": "0.8.1-main.ba2dec9",
105
- "@dxos/test-utils": "0.8.1-main.ba2dec9"
100
+ "@dxos/random": "0.8.1-staging.5be625a",
101
+ "@dxos/react-ui-theme": "0.8.1-staging.5be625a",
102
+ "@dxos/react-ui-syntax-highlighter": "0.8.1-staging.5be625a",
103
+ "@dxos/storybook-utils": "0.8.1-staging.5be625a",
104
+ "@dxos/react-ui": "0.8.1-staging.5be625a",
105
+ "@dxos/test-utils": "0.8.1-staging.5be625a"
106
106
  },
107
107
  "peerDependencies": {
108
108
  "react": "~18.2.0",
109
109
  "react-dom": "~18.2.0"
110
110
  },
111
111
  "optionalDependencies": {
112
- "@dxos/react-ui": "0.8.1-main.ba2dec9",
113
- "@dxos/react-ui-theme": "0.8.1-main.ba2dec9",
114
- "@dxos/random": "0.8.1-main.ba2dec9"
112
+ "@dxos/random": "0.8.1-staging.5be625a",
113
+ "@dxos/react-ui": "0.8.1-staging.5be625a",
114
+ "@dxos/react-ui-theme": "0.8.1-staging.5be625a"
115
115
  },
116
116
  "publishConfig": {
117
117
  "access": "public"
package/src/echo/index.ts CHANGED
@@ -10,3 +10,4 @@ export * from './useSchema';
10
10
  export * from './useSpaces';
11
11
  export * from './useSpaceInvitations';
12
12
  export * from './useSubscription';
13
+ export * from './useQueue';
@@ -0,0 +1,61 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { useEffect, useMemo } from 'react';
6
+
7
+ import type { Queue } from '@dxos/client/echo';
8
+ import { raise } from '@dxos/debug';
9
+ import type { BaseEchoObject } from '@dxos/echo-schema';
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
+ */
23
+ // TODO(burdon): Replace polling with socket?
24
+ // TODO(dmaretskyi): Move into client package.
25
+ // TODO(dmaretskyi): Consider passing the space into the hook to support queue DXNs without space id.
26
+ export const useQueue = <T extends BaseEchoObject>(
27
+ queueDxn?: DXN,
28
+ options: UseQueueOptions = {},
29
+ ): Queue<T> | undefined => {
30
+ const client = useClient();
31
+ const queue = useMemo<Queue<T> | undefined>(() => {
32
+ if (!queueDxn) {
33
+ return undefined;
34
+ }
35
+
36
+ const { spaceId } = queueDxn.asQueueDXN() ?? raise(new TypeError('Invalid queue DXN'));
37
+
38
+ return client.spaces.get(spaceId)?.queues.get<T>(queueDxn);
39
+ }, [client, queueDxn?.toString()]);
40
+
41
+ useEffect(() => {
42
+ void queue?.refresh();
43
+ }, [queue]);
44
+
45
+ useEffect(() => {
46
+ let timeout: NodeJS.Timeout;
47
+ if (options.pollInterval) {
48
+ const poll = () => {
49
+ void queue?.refresh().finally(() => {
50
+ timeout = setTimeout(poll, Math.max(options.pollInterval ?? 0, MIN_POLL_INTERVAL));
51
+ });
52
+ };
53
+
54
+ poll();
55
+ }
56
+
57
+ return () => clearTimeout(timeout);
58
+ }, [queue, options.pollInterval]);
59
+
60
+ return queue;
61
+ };
@@ -4,13 +4,18 @@
4
4
 
5
5
  import { useMemo, useSyncExternalStore } from 'react';
6
6
 
7
+ import { type Client } from '@dxos/client';
7
8
  import { type Space } from '@dxos/client/echo';
8
- import { type EchoSchema } from '@dxos/echo-schema';
9
+ import { ImmutableSchema, type BaseSchema } from '@dxos/echo-schema';
9
10
 
10
11
  /**
11
12
  * Subscribe to and retrieve schema changes from a space's schema registry.
12
13
  */
13
- export const useSchema = (space: Space | undefined, typename: string | undefined): EchoSchema | undefined => {
14
+ export const useSchema = (
15
+ client: Client,
16
+ space: Space | undefined,
17
+ typename: string | undefined,
18
+ ): BaseSchema | undefined => {
14
19
  const { subscribe, getSchema } = useMemo(() => {
15
20
  if (!typename || !space) {
16
21
  return {
@@ -19,8 +24,18 @@ export const useSchema = (space: Space | undefined, typename: string | undefined
19
24
  };
20
25
  }
21
26
 
27
+ const staticSchema = client.graph.schemaRegistry.getSchema(typename);
28
+ if (staticSchema) {
29
+ // Don't inline into getSchema, need a stable reference.
30
+ const immutableSchema = new ImmutableSchema(staticSchema);
31
+ return {
32
+ subscribe: () => () => {},
33
+ getSchema: () => immutableSchema,
34
+ };
35
+ }
36
+
22
37
  const query = space.db.schemaRegistry.query({ typename });
23
- const initialResult = query.runSync()[0];
38
+ const initialResult: BaseSchema = query.runSync()[0];
24
39
  let currentSchema = initialResult;
25
40
 
26
41
  return {
@@ -29,6 +44,7 @@ export const useSchema = (space: Space | undefined, typename: string | undefined
29
44
  currentSchema = query.results[0];
30
45
  onStoreChange();
31
46
  });
47
+
32
48
  return unsubscribe;
33
49
  },
34
50
  getSchema: () => currentSchema,