@dxos/react-client 0.6.12-main.5cc132e → 0.6.12-main.78ddbdf

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 (41) hide show
  1. package/dist/lib/browser/echo/index.mjs +5 -3
  2. package/dist/lib/browser/echo/index.mjs.map +3 -3
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/browser/testing/index.mjs +27 -20
  5. package/dist/lib/browser/testing/index.mjs.map +3 -3
  6. package/dist/lib/node/echo/index.cjs +4 -2
  7. package/dist/lib/node/echo/index.cjs.map +3 -3
  8. package/dist/lib/node/meta.json +1 -1
  9. package/dist/lib/node/testing/index.cjs +27 -20
  10. package/dist/lib/node/testing/index.cjs.map +3 -3
  11. package/dist/lib/node-esm/{chunk-ESSNDYBJ.mjs → chunk-ACLHQASD.mjs} +3 -1
  12. package/dist/lib/node-esm/{chunk-ESSNDYBJ.mjs.map → chunk-ACLHQASD.mjs.map} +1 -1
  13. package/dist/lib/node-esm/{chunk-AL2CUQ46.mjs → chunk-UYJUBYMU.mjs} +3 -1
  14. package/dist/lib/node-esm/{chunk-AL2CUQ46.mjs.map → chunk-UYJUBYMU.mjs.map} +1 -1
  15. package/dist/lib/node-esm/devtools/index.mjs +2 -1
  16. package/dist/lib/node-esm/devtools/index.mjs.map +1 -1
  17. package/dist/lib/node-esm/echo/index.mjs +8 -5
  18. package/dist/lib/node-esm/echo/index.mjs.map +3 -3
  19. package/dist/lib/node-esm/halo/index.mjs +3 -2
  20. package/dist/lib/node-esm/halo/index.mjs.map +1 -1
  21. package/dist/lib/node-esm/index.mjs +2 -1
  22. package/dist/lib/node-esm/index.mjs.map +1 -1
  23. package/dist/lib/node-esm/invitations/index.mjs +2 -1
  24. package/dist/lib/node-esm/mesh/index.mjs +2 -1
  25. package/dist/lib/node-esm/mesh/index.mjs.map +1 -1
  26. package/dist/lib/node-esm/meta.json +1 -1
  27. package/dist/lib/node-esm/testing/index.mjs +29 -21
  28. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  29. package/dist/lib/node-esm/worker.mjs +2 -0
  30. package/dist/lib/node-esm/worker.mjs.map +1 -1
  31. package/dist/types/src/echo/useQuery.d.ts.map +1 -1
  32. package/dist/types/src/testing/withClientProvider.d.ts +4 -1
  33. package/dist/types/src/testing/withClientProvider.d.ts.map +1 -1
  34. package/dist/types/src/testing/withClientProvider.stories.d.ts +4 -3
  35. package/dist/types/src/testing/withClientProvider.stories.d.ts.map +1 -1
  36. package/package.json +25 -25
  37. package/project.json +2 -1
  38. package/src/echo/useQuery.ts +3 -6
  39. package/src/testing/withClientProvider.stories.tsx +19 -10
  40. package/src/testing/withClientProvider.tsx +22 -19
  41. package/vitest.config.ts +1 -1
@@ -2,11 +2,12 @@ import '@dxos-theme';
2
2
  import React from 'react';
3
3
  declare const _default: {
4
4
  title: string;
5
- component: () => React.JSX.Element | null;
6
- decorators: import("@storybook/react/*").Decorator[];
5
+ render: () => React.JSX.Element | null;
7
6
  };
8
7
  export default _default;
9
- export declare const Default: {};
8
+ export declare const Default: {
9
+ decorators: import("@storybook/react/*").Decorator[];
10
+ };
10
11
  export declare const Multiple: {
11
12
  decorators: import("@storybook/react/*").Decorator[];
12
13
  };
@@ -1 +1 @@
1
- {"version":3,"file":"withClientProvider.stories.d.ts","sourceRoot":"","sources":["../../../../src/testing/withClientProvider.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAErB,OAAO,KAAK,MAAM,OAAO,CAAC;;;;;;AA+B1B,wBAIE;AAEF,eAAO,MAAM,OAAO,IAAK,CAAC;AAE1B,eAAO,MAAM,QAAQ;;CAUpB,CAAC"}
1
+ {"version":3,"file":"withClientProvider.stories.d.ts","sourceRoot":"","sources":["../../../../src/testing/withClientProvider.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAErB,OAAO,KAAK,MAAM,OAAO,CAAC;;;;;AAgC1B,wBAGE;AAaF,eAAO,MAAM,OAAO;;CAEnB,CAAC;AAEF,eAAO,MAAM,QAAQ;;CAMpB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-client",
3
- "version": "0.6.12-main.5cc132e",
3
+ "version": "0.6.12-main.78ddbdf",
4
4
  "description": "React client API",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -100,19 +100,19 @@
100
100
  },
101
101
  "dependencies": {
102
102
  "react-error-boundary": "^4.0.13",
103
- "@dxos/async": "0.6.12-main.5cc132e",
104
- "@dxos/codec-protobuf": "0.6.12-main.5cc132e",
105
- "@dxos/client": "0.6.12-main.5cc132e",
106
- "@dxos/config": "0.6.12-main.5cc132e",
107
- "@dxos/debug": "0.6.12-main.5cc132e",
108
- "@dxos/echo-schema": "0.6.12-main.5cc132e",
109
- "@dxos/invariant": "0.6.12-main.5cc132e",
110
- "@dxos/log": "0.6.12-main.5cc132e",
111
- "@dxos/echo-signals": "0.6.12-main.5cc132e",
112
- "@dxos/node-std": "0.6.12-main.5cc132e",
113
- "@dxos/protocols": "0.6.12-main.5cc132e",
114
- "@dxos/react-hooks": "0.6.12-main.5cc132e",
115
- "@dxos/util": "0.6.12-main.5cc132e"
103
+ "@dxos/async": "0.6.12-main.78ddbdf",
104
+ "@dxos/client": "0.6.12-main.78ddbdf",
105
+ "@dxos/codec-protobuf": "0.6.12-main.78ddbdf",
106
+ "@dxos/echo-schema": "0.6.12-main.78ddbdf",
107
+ "@dxos/config": "0.6.12-main.78ddbdf",
108
+ "@dxos/debug": "0.6.12-main.78ddbdf",
109
+ "@dxos/invariant": "0.6.12-main.78ddbdf",
110
+ "@dxos/log": "0.6.12-main.78ddbdf",
111
+ "@dxos/node-std": "0.6.12-main.78ddbdf",
112
+ "@dxos/echo-signals": "0.6.12-main.78ddbdf",
113
+ "@dxos/protocols": "0.6.12-main.78ddbdf",
114
+ "@dxos/react-hooks": "0.6.12-main.78ddbdf",
115
+ "@dxos/util": "0.6.12-main.78ddbdf"
116
116
  },
117
117
  "devDependencies": {
118
118
  "@testing-library/dom": "^8.17.1",
@@ -122,21 +122,21 @@
122
122
  "@types/react-dom": "~18.2.0",
123
123
  "react": "~18.2.0",
124
124
  "react-dom": "~18.2.0",
125
- "@dxos/random": "0.6.12-main.5cc132e",
126
- "@dxos/react-ui": "0.6.12-main.5cc132e",
127
- "@dxos/react-ui-syntax-highlighter": "0.6.12-main.5cc132e",
128
- "@dxos/test-utils": "0.6.12-main.5cc132e",
129
- "@dxos/react-ui-theme": "0.6.12-main.5cc132e",
130
- "@dxos/storybook-utils": "0.6.12-main.5cc132e"
125
+ "@dxos/random": "0.6.12-main.78ddbdf",
126
+ "@dxos/react-ui": "0.6.12-main.78ddbdf",
127
+ "@dxos/react-ui-syntax-highlighter": "0.6.12-main.78ddbdf",
128
+ "@dxos/react-ui-theme": "0.6.12-main.78ddbdf",
129
+ "@dxos/storybook-utils": "0.6.12-main.78ddbdf",
130
+ "@dxos/test-utils": "0.6.12-main.78ddbdf"
131
131
  },
132
132
  "peerDependencies": {
133
- "react": "^18.0.0",
134
- "react-dom": "^18.0.0",
135
- "@dxos/react-ui": "0.6.12-main.5cc132e",
136
- "@dxos/react-ui-theme": "0.6.12-main.5cc132e"
133
+ "react": "~18.2.0",
134
+ "react-dom": "~18.2.0",
135
+ "@dxos/react-ui": "0.6.12-main.78ddbdf",
136
+ "@dxos/react-ui-theme": "0.6.12-main.78ddbdf"
137
137
  },
138
138
  "optionalDependencies": {
139
- "@dxos/random": "0.6.12-main.5cc132e"
139
+ "@dxos/random": "0.6.12-main.78ddbdf"
140
140
  },
141
141
  "publishConfig": {
142
142
  "access": "public"
package/project.json CHANGED
@@ -32,6 +32,7 @@
32
32
  "test": {}
33
33
  },
34
34
  "implicitDependencies": [
35
- "esbuild"
35
+ "esbuild",
36
+ "node-std"
36
37
  ]
37
38
  }
@@ -5,6 +5,7 @@
5
5
  import { useMemo, useSyncExternalStore } from 'react';
6
6
 
7
7
  import {
8
+ Filter,
8
9
  isSpace,
9
10
  type Echo,
10
11
  type EchoReactiveObject,
@@ -41,18 +42,14 @@ export const useQuery = <T extends EchoReactiveObject<any>>(
41
42
  },
42
43
  getObjects: () => (subscribed && query ? query.objects : EMPTY_ARRAY),
43
44
  };
44
- }, [spaceOrEcho, ...(typeof filter === 'function' ? [] : filterToDepsArray(filter)), ...(deps ?? [])]);
45
+ }, [spaceOrEcho, ...filterToDepsArray(filter), ...(deps ?? [])]);
45
46
 
46
47
  // https://beta.reactjs.org/reference/react/useSyncExternalStore
47
48
  // NOTE: This hook will resubscribe whenever the callback passed to the first argument changes -- make sure it is stable.
48
49
  return useSyncExternalStore<T[] | undefined>(subscribe, getObjects) ?? [];
49
50
  };
50
51
 
51
- // TODO(dmaretskyi): Serialize the filter here instead.
52
- const filterToDepsArray = (filter?: FilterSource<any>) =>
53
- Object.entries(filter ?? {})
54
- .flat(10)
55
- .map((x) => (typeof x === 'function' || typeof x === 'object' ? null : x));
52
+ const filterToDepsArray = (filter?: FilterSource<any>) => [JSON.stringify(Filter.from(filter).toProto())];
56
53
 
57
54
  const noop = () => {};
58
55
 
@@ -6,10 +6,11 @@ import '@dxos-theme';
6
6
 
7
7
  import React from 'react';
8
8
 
9
+ import { log } from '@dxos/log';
9
10
  import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
10
11
  import { withLayout, withTheme } from '@dxos/storybook-utils';
11
12
 
12
- import { withClientProvider, withMultiClientProvider } from './withClientProvider';
13
+ import { withClientProvider, type WithClientProviderProps, withMultiClientProvider } from './withClientProvider';
13
14
  import { useClient } from '../client';
14
15
  import { type Space, useSpaces } from '../echo';
15
16
 
@@ -37,20 +38,28 @@ const Test = () => {
37
38
 
38
39
  export default {
39
40
  title: 'react-client/withClientProvider',
40
- component: Test,
41
- decorators: [withTheme, withClientProvider({ createIdentity: true })],
41
+ render: Test,
42
42
  };
43
43
 
44
- export const Default = {};
44
+ const clientProps: WithClientProviderProps = {
45
+ createIdentity: true,
46
+ createSpace: true,
47
+ onInitialized: async (client) => {
48
+ log.info('onInitialized', { client });
49
+ },
50
+ onSpaceCreated: async ({ client, space }) => {
51
+ log.info('onSpaceCreated', { client, space });
52
+ },
53
+ };
54
+
55
+ export const Default = {
56
+ decorators: [withClientProvider(clientProps), withTheme, withLayout({ classNames: ['flex gap-2'] })],
57
+ };
45
58
 
46
59
  export const Multiple = {
47
60
  decorators: [
48
- withMultiClientProvider({
49
- numClients: 3,
50
- createIdentity: true,
51
- createSpace: true,
52
- }),
53
- withLayout({ classNames: ['flex gap-2'] }),
61
+ withMultiClientProvider({ ...clientProps, numClients: 3 }),
54
62
  withTheme,
63
+ withLayout({ classNames: ['flex gap-2'] }),
55
64
  ],
56
65
  };
@@ -17,7 +17,7 @@ import { ClientProvider, type ClientProviderProps } from '../client';
17
17
  type InitializeProps = {
18
18
  createIdentity?: boolean;
19
19
  createSpace?: boolean;
20
- onSpaceCreated?: (client: Client, space: Space) => MaybePromise<void>;
20
+ onSpaceCreated?: (props: { client: Client; space: Space }) => MaybePromise<void>;
21
21
  };
22
22
 
23
23
  /**
@@ -32,14 +32,16 @@ const initializeClient = async (
32
32
  onInitialized,
33
33
  }: InitializeProps & Pick<WithClientProviderProps, 'onInitialized'>,
34
34
  ): Promise<Space | undefined> => {
35
- if (createIdentity) {
36
- await client.halo.createIdentity();
35
+ if (createIdentity || createSpace) {
36
+ if (!client.halo.identity.get()) {
37
+ await client.halo.createIdentity();
38
+ }
37
39
  }
38
40
 
39
41
  let space: Space | undefined;
40
42
  if (createSpace) {
41
43
  space = await client.spaces.create({ name: 'Test Space' });
42
- await onSpaceCreated?.(client, space);
44
+ await onSpaceCreated?.({ client, space });
43
45
  }
44
46
 
45
47
  await onInitialized?.(client);
@@ -58,17 +60,19 @@ export const withClientProvider = ({
58
60
  onInitialized,
59
61
  ...props
60
62
  }: WithClientProviderProps = {}): Decorator => {
61
- const handleInitialized = async (client: Client) => {
62
- await initializeClient(client, { createIdentity, createSpace, onSpaceCreated, onInitialized });
63
- };
63
+ return (Story) => {
64
+ const handleInitialized = async (client: Client) => {
65
+ await initializeClient(client, { createIdentity, createSpace, onSpaceCreated, onInitialized });
66
+ };
64
67
 
65
- return (Story) => (
66
- <ErrorBoundary FallbackComponent={ErrorFallback}>
67
- <ClientProvider onInitialized={handleInitialized} {...props}>
68
- <Story />
69
- </ClientProvider>
70
- </ErrorBoundary>
71
- );
68
+ return (
69
+ <ErrorBoundary FallbackComponent={ErrorFallback}>
70
+ <ClientProvider onInitialized={handleInitialized} {...props}>
71
+ <Story />
72
+ </ClientProvider>
73
+ </ErrorBoundary>
74
+ );
75
+ };
72
76
  };
73
77
 
74
78
  // TODO(burdon): Implement context per client for context.
@@ -81,7 +85,6 @@ export type WithMultiClientProviderProps = InitializeProps & ClientProviderProps
81
85
  * Orchestrates invitations between a randomly selected host and the remaining clients.
82
86
  * NOTE: Should come before withLayout.
83
87
  */
84
- // TODO(burdon): Create test.
85
88
  export const withMultiClientProvider = ({
86
89
  numClients = 2,
87
90
  createIdentity,
@@ -96,7 +99,7 @@ export const withMultiClientProvider = ({
96
99
  const spaceReady = useRef(new Trigger<Space | undefined>());
97
100
 
98
101
  // Handle invitations.
99
- const handleClientInitialized = async (client: Client) => {
102
+ const handleInitialized = async (client: Client) => {
100
103
  if (createSpace) {
101
104
  if (!hostRef.current) {
102
105
  hostRef.current = client;
@@ -118,7 +121,7 @@ export const withMultiClientProvider = ({
118
121
  <ErrorBoundary key={index} FallbackComponent={ErrorFallback}>
119
122
  <ClientProvider
120
123
  services={builder.current.createLocalClientServices()}
121
- onInitialized={handleClientInitialized}
124
+ onInitialized={handleInitialized}
122
125
  {...props}
123
126
  >
124
127
  <Story />
@@ -134,10 +137,10 @@ const ErrorFallback = ({ error }: FallbackProps) => {
134
137
  const { name, message, stack } =
135
138
  error instanceof Error ? error : { name: 'Error', message: String(error), stack: undefined };
136
139
  return (
137
- <div role='alert' className='flex flex-col gap-4'>
140
+ <div role='alert' className='flex flex-col overflow-hidden p-4 gap-4'>
138
141
  <h1 className='text-xl text-red-500'>{name}</h1>
139
142
  <div className='text-lg'>{message}</div>
140
- {stack && <pre className='text-sm text-subdued'>{stack}</pre>}
143
+ {stack && <pre className='whitespace-pre-wrap text-sm text-subdued'>{stack}</pre>}
141
144
  </div>
142
145
  );
143
146
  };
package/vitest.config.ts CHANGED
@@ -11,7 +11,7 @@ const specifiedEnv = (process.env.VITEST_ENV ?? 'node').toLowerCase();
11
11
  const environment = specifiedEnv === 'node' ? 'jsdom' : undefined;
12
12
 
13
13
  export default mergeConfig(
14
- baseConfig(),
14
+ baseConfig({ cwd: __dirname }),
15
15
  defineConfig({
16
16
  test: {
17
17
  environment,