@dxos/react-client 0.6.12-main.ed7cda7 → 0.6.12-staging.0b4bb48

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 (82) hide show
  1. package/dist/lib/browser/{chunk-ESSNDYBJ.mjs → chunk-CL7JDETM.mjs} +61 -70
  2. package/dist/lib/browser/chunk-CL7JDETM.mjs.map +7 -0
  3. package/dist/lib/browser/devtools/index.mjs +1 -1
  4. package/dist/lib/browser/echo/index.mjs +4 -6
  5. package/dist/lib/browser/echo/index.mjs.map +3 -3
  6. package/dist/lib/browser/halo/index.mjs +1 -1
  7. package/dist/lib/browser/index.mjs +3 -1
  8. package/dist/lib/browser/index.mjs.map +1 -1
  9. package/dist/lib/browser/mesh/index.mjs +1 -1
  10. package/dist/lib/browser/meta.json +1 -1
  11. package/dist/lib/browser/testing/index.mjs +21 -28
  12. package/dist/lib/browser/testing/index.mjs.map +3 -3
  13. package/dist/lib/node/{chunk-N474KOAU.cjs → chunk-C4EWAKPZ.cjs} +61 -71
  14. package/dist/lib/node/chunk-C4EWAKPZ.cjs.map +7 -0
  15. package/dist/lib/node/devtools/index.cjs +2 -2
  16. package/dist/lib/node/echo/index.cjs +5 -7
  17. package/dist/lib/node/echo/index.cjs.map +3 -3
  18. package/dist/lib/node/halo/index.cjs +5 -5
  19. package/dist/lib/node/index.cjs +14 -12
  20. package/dist/lib/node/index.cjs.map +1 -1
  21. package/dist/lib/node/mesh/index.cjs +2 -2
  22. package/dist/lib/node/meta.json +1 -1
  23. package/dist/lib/node/testing/index.cjs +23 -30
  24. package/dist/lib/node/testing/index.cjs.map +3 -3
  25. package/dist/types/src/client/ClientProvider.d.ts +9 -65
  26. package/dist/types/src/client/ClientProvider.d.ts.map +1 -1
  27. package/dist/types/src/client/context.d.ts +4 -1
  28. package/dist/types/src/client/context.d.ts.map +1 -1
  29. package/dist/types/src/client/index.d.ts +1 -0
  30. package/dist/types/src/client/index.d.ts.map +1 -1
  31. package/dist/types/src/client/useClientServices.d.ts +3 -0
  32. package/dist/types/src/client/useClientServices.d.ts.map +1 -0
  33. package/dist/types/src/echo/useQuery.d.ts.map +1 -1
  34. package/dist/types/src/playwright/playwright.config.d.ts +2 -2
  35. package/dist/types/src/playwright/playwright.config.d.ts.map +1 -1
  36. package/dist/types/src/testing/util.d.ts +3 -5
  37. package/dist/types/src/testing/util.d.ts.map +1 -1
  38. package/dist/types/src/testing/withClientProvider.d.ts +1 -4
  39. package/dist/types/src/testing/withClientProvider.d.ts.map +1 -1
  40. package/dist/types/src/testing/withClientProvider.stories.d.ts +3 -4
  41. package/dist/types/src/testing/withClientProvider.stories.d.ts.map +1 -1
  42. package/package.json +38 -47
  43. package/project.json +22 -3
  44. package/src/client/ClientProvider.test.tsx +4 -7
  45. package/src/client/ClientProvider.tsx +90 -130
  46. package/src/client/context.ts +4 -4
  47. package/src/client/index.ts +3 -0
  48. package/src/client/useClientServices.ts +15 -0
  49. package/src/client/useConfig.test.tsx +11 -7
  50. package/src/echo/useQuery.ts +6 -3
  51. package/src/echo/useSpaces.test.tsx +8 -6
  52. package/src/halo/useDevices.test.tsx +5 -3
  53. package/src/playwright/playwright.config.ts +2 -13
  54. package/src/playwright/smoke.spec.ts +10 -5
  55. package/src/testing/util.tsx +6 -11
  56. package/src/testing/withClientProvider.stories.tsx +10 -19
  57. package/src/testing/withClientProvider.tsx +18 -22
  58. package/tsconfig.json +2 -4
  59. package/dist/lib/browser/chunk-ESSNDYBJ.mjs.map +0 -7
  60. package/dist/lib/node/chunk-N474KOAU.cjs.map +0 -7
  61. package/dist/lib/node-esm/chunk-ACLHQASD.mjs +0 -302
  62. package/dist/lib/node-esm/chunk-ACLHQASD.mjs.map +0 -7
  63. package/dist/lib/node-esm/chunk-UYJUBYMU.mjs +0 -165
  64. package/dist/lib/node-esm/chunk-UYJUBYMU.mjs.map +0 -7
  65. package/dist/lib/node-esm/devtools/index.mjs +0 -44
  66. package/dist/lib/node-esm/devtools/index.mjs.map +0 -7
  67. package/dist/lib/node-esm/echo/index.mjs +0 -134
  68. package/dist/lib/node-esm/echo/index.mjs.map +0 -7
  69. package/dist/lib/node-esm/halo/index.mjs +0 -100
  70. package/dist/lib/node-esm/halo/index.mjs.map +0 -7
  71. package/dist/lib/node-esm/index.mjs +0 -33
  72. package/dist/lib/node-esm/index.mjs.map +0 -7
  73. package/dist/lib/node-esm/invitations/index.mjs +0 -18
  74. package/dist/lib/node-esm/invitations/index.mjs.map +0 -7
  75. package/dist/lib/node-esm/mesh/index.mjs +0 -18
  76. package/dist/lib/node-esm/mesh/index.mjs.map +0 -7
  77. package/dist/lib/node-esm/meta.json +0 -1
  78. package/dist/lib/node-esm/testing/index.mjs +0 -173
  79. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  80. package/dist/lib/node-esm/worker.mjs +0 -5
  81. package/dist/lib/node-esm/worker.mjs.map +0 -7
  82. package/vitest.config.ts +0 -22
@@ -1 +1 @@
1
- {"version":3,"file":"withClientProvider.d.ts","sourceRoot":"","sources":["../../../../src/testing/withClientProvider.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAKlD,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,EAAkB,KAAK,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAErE,KAAK,eAAe,GAAG;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;CAClF,CAAC;AA8BF,MAAM,MAAM,uBAAuB,GAAG,eAAe,GAAG,mBAAmB,CAAC;AAE5E;;GAEG;AACH,eAAO,MAAM,kBAAkB,8EAM5B,uBAAuB,KAAQ,SAcjC,CAAC;AAKF,MAAM,MAAM,4BAA4B,GAAG,eAAe,GAAG,mBAAmB,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3G;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,yFAOjC,4BAA4B,KAAG,SAuCjC,CAAC"}
1
+ {"version":3,"file":"withClientProvider.d.ts","sourceRoot":"","sources":["../../../../src/testing/withClientProvider.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAKlD,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,EAAkB,KAAK,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAErE,KAAK,eAAe,GAAG;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;CACvE,CAAC;AA4BF,MAAM,MAAM,uBAAuB,GAAG,eAAe,GAAG,mBAAmB,CAAC;AAE5E;;GAEG;AACH,eAAO,MAAM,kBAAkB,8EAM5B,uBAAuB,KAAQ,SAYjC,CAAC;AAKF,MAAM,MAAM,4BAA4B,GAAG,eAAe,GAAG,mBAAmB,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3G;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,yFAOjC,4BAA4B,KAAG,SAuCjC,CAAC"}
@@ -2,12 +2,11 @@ import '@dxos-theme';
2
2
  import React from 'react';
3
3
  declare const _default: {
4
4
  title: string;
5
- render: () => React.JSX.Element | null;
6
- };
7
- export default _default;
8
- export declare const Default: {
5
+ component: () => React.JSX.Element | null;
9
6
  decorators: import("@storybook/react/*").Decorator[];
10
7
  };
8
+ export default _default;
9
+ export declare const Default: {};
11
10
  export declare const Multiple: {
12
11
  decorators: import("@storybook/react/*").Decorator[];
13
12
  };
@@ -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;;;;;AAgC1B,wBAGE;AAaF,eAAO,MAAM,OAAO;;CAEnB,CAAC;AAEF,eAAO,MAAM,QAAQ;;CAMpB,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;;;;;;AA+B1B,wBAIE;AAEF,eAAO,MAAM,OAAO,IAAK,CAAC;AAE1B,eAAO,MAAM,QAAQ;;CAUpB,CAAC"}
package/package.json CHANGED
@@ -1,73 +1,65 @@
1
1
  {
2
2
  "name": "@dxos/react-client",
3
- "version": "0.6.12-main.ed7cda7",
3
+ "version": "0.6.12-staging.0b4bb48",
4
4
  "description": "React client API",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
7
7
  "license": "MIT",
8
8
  "author": "DXOS.org",
9
9
  "exports": {
10
+ ".": {
11
+ "browser": "./dist/lib/browser/index.mjs",
12
+ "node": {
13
+ "default": "./dist/lib/node/index.cjs"
14
+ },
15
+ "types": "./dist/types/src/index.d.ts"
16
+ },
10
17
  "./devtools": {
11
18
  "browser": "./dist/lib/browser/devtools/index.mjs",
12
19
  "node": {
13
- "require": "./dist/lib/node/devtools/index.cjs",
14
- "default": "./dist/lib/node-esm/devtools/index.mjs"
20
+ "default": "./dist/lib/node/devtools/index.cjs"
15
21
  },
16
22
  "types": "./dist/types/src/devtools/index.d.ts"
17
23
  },
18
24
  "./echo": {
19
25
  "browser": "./dist/lib/browser/echo/index.mjs",
20
26
  "node": {
21
- "require": "./dist/lib/node/echo/index.cjs",
22
- "default": "./dist/lib/node-esm/echo/index.mjs"
27
+ "default": "./dist/lib/node/echo/index.cjs"
23
28
  },
24
29
  "types": "./dist/types/src/echo/index.d.ts"
25
30
  },
26
31
  "./halo": {
27
32
  "browser": "./dist/lib/browser/halo/index.mjs",
28
33
  "node": {
29
- "require": "./dist/lib/node/halo/index.cjs",
30
- "default": "./dist/lib/node-esm/halo/index.mjs"
34
+ "default": "./dist/lib/node/halo/index.cjs"
31
35
  },
32
36
  "types": "./dist/types/src/halo/index.d.ts"
33
37
  },
34
- ".": {
35
- "browser": "./dist/lib/browser/index.mjs",
36
- "node": {
37
- "require": "./dist/lib/node/index.cjs",
38
- "default": "./dist/lib/node-esm/index.mjs"
39
- },
40
- "types": "./dist/types/src/index.d.ts"
41
- },
42
38
  "./invitations": {
43
39
  "browser": "./dist/lib/browser/invitations/index.mjs",
44
40
  "node": {
45
- "require": "./dist/lib/node/invitations/index.cjs",
46
- "default": "./dist/lib/node-esm/invitations/index.mjs"
41
+ "default": "./dist/lib/node/invitations/index.cjs"
47
42
  },
48
43
  "types": "./dist/types/src/invitations/index.d.ts"
49
44
  },
50
45
  "./mesh": {
51
46
  "browser": "./dist/lib/browser/mesh/index.mjs",
52
47
  "node": {
53
- "require": "./dist/lib/node/mesh/index.cjs",
54
- "default": "./dist/lib/node-esm/mesh/index.mjs"
48
+ "default": "./dist/lib/node/mesh/index.cjs"
55
49
  },
56
50
  "types": "./dist/types/src/mesh/index.d.ts"
57
51
  },
58
52
  "./testing": {
59
53
  "browser": "./dist/lib/browser/testing/index.mjs",
60
54
  "node": {
61
- "require": "./dist/lib/node/testing/index.cjs",
62
- "default": "./dist/lib/node-esm/testing/index.mjs"
55
+ "default": "./dist/lib/node/testing/index.cjs"
63
56
  },
64
57
  "types": "./dist/types/src/testing/index.d.ts"
65
58
  },
66
59
  "./worker": {
67
60
  "browser": "./dist/lib/browser/worker.mjs",
68
61
  "node": {
69
- "require": "./dist/lib/node/worker.cjs",
70
- "default": "./dist/lib/node-esm/worker.mjs"
62
+ "default": "./dist/lib/node/worker.cjs"
71
63
  },
72
64
  "types": "./dist/types/src/worker.d.ts"
73
65
  }
@@ -100,19 +92,19 @@
100
92
  },
101
93
  "dependencies": {
102
94
  "react-error-boundary": "^4.0.13",
103
- "@dxos/async": "0.6.12-main.ed7cda7",
104
- "@dxos/client": "0.6.12-main.ed7cda7",
105
- "@dxos/codec-protobuf": "0.6.12-main.ed7cda7",
106
- "@dxos/echo-schema": "0.6.12-main.ed7cda7",
107
- "@dxos/invariant": "0.6.12-main.ed7cda7",
108
- "@dxos/config": "0.6.12-main.ed7cda7",
109
- "@dxos/log": "0.6.12-main.ed7cda7",
110
- "@dxos/echo-signals": "0.6.12-main.ed7cda7",
111
- "@dxos/debug": "0.6.12-main.ed7cda7",
112
- "@dxos/node-std": "0.6.12-main.ed7cda7",
113
- "@dxos/react-hooks": "0.6.12-main.ed7cda7",
114
- "@dxos/protocols": "0.6.12-main.ed7cda7",
115
- "@dxos/util": "0.6.12-main.ed7cda7"
95
+ "@dxos/async": "0.6.12-staging.0b4bb48",
96
+ "@dxos/codec-protobuf": "0.6.12-staging.0b4bb48",
97
+ "@dxos/debug": "0.6.12-staging.0b4bb48",
98
+ "@dxos/client": "0.6.12-staging.0b4bb48",
99
+ "@dxos/config": "0.6.12-staging.0b4bb48",
100
+ "@dxos/echo-schema": "0.6.12-staging.0b4bb48",
101
+ "@dxos/echo-signals": "0.6.12-staging.0b4bb48",
102
+ "@dxos/invariant": "0.6.12-staging.0b4bb48",
103
+ "@dxos/log": "0.6.12-staging.0b4bb48",
104
+ "@dxos/node-std": "0.6.12-staging.0b4bb48",
105
+ "@dxos/protocols": "0.6.12-staging.0b4bb48",
106
+ "@dxos/react-hooks": "0.6.12-staging.0b4bb48",
107
+ "@dxos/util": "0.6.12-staging.0b4bb48"
116
108
  },
117
109
  "devDependencies": {
118
110
  "@testing-library/dom": "^8.17.1",
@@ -122,21 +114,20 @@
122
114
  "@types/react-dom": "~18.2.0",
123
115
  "react": "~18.2.0",
124
116
  "react-dom": "~18.2.0",
125
- "@dxos/random": "0.6.12-main.ed7cda7",
126
- "@dxos/react-ui": "0.6.12-main.ed7cda7",
127
- "@dxos/storybook-utils": "0.6.12-main.ed7cda7",
128
- "@dxos/react-ui-syntax-highlighter": "0.6.12-main.ed7cda7",
129
- "@dxos/react-ui-theme": "0.6.12-main.ed7cda7",
130
- "@dxos/test-utils": "0.6.12-main.ed7cda7"
117
+ "@dxos/random": "0.6.12-staging.0b4bb48",
118
+ "@dxos/react-ui-theme": "0.6.12-staging.0b4bb48",
119
+ "@dxos/react-ui": "0.6.12-staging.0b4bb48",
120
+ "@dxos/react-ui-syntax-highlighter": "0.6.12-staging.0b4bb48",
121
+ "@dxos/storybook-utils": "0.6.12-staging.0b4bb48"
131
122
  },
132
123
  "peerDependencies": {
133
- "react": "~18.2.0",
134
- "react-dom": "~18.2.0",
135
- "@dxos/react-ui-theme": "0.6.12-main.ed7cda7",
136
- "@dxos/react-ui": "0.6.12-main.ed7cda7"
124
+ "react": "^18.0.0",
125
+ "react-dom": "^18.0.0",
126
+ "@dxos/react-ui": "0.6.12-staging.0b4bb48",
127
+ "@dxos/react-ui-theme": "0.6.12-staging.0b4bb48"
137
128
  },
138
129
  "optionalDependencies": {
139
- "@dxos/random": "0.6.12-main.ed7cda7"
130
+ "@dxos/random": "0.6.12-staging.0b4bb48"
140
131
  },
141
132
  "publishConfig": {
142
133
  "access": "public"
package/project.json CHANGED
@@ -26,13 +26,32 @@
26
26
  "dependsOn": [
27
27
  "^compile",
28
28
  "stories:mkdist"
29
- ]
29
+ ],
30
+ "options": {
31
+ "playwrightConfigPath": "{projectRoot}/src/playwright/playwright.config.ts",
32
+ "serve": "stories:storybook-e2e",
33
+ "testPatterns": [
34
+ "{projectRoot}/src/playwright/**/*.spec.{ts,js}"
35
+ ],
36
+ "timeout": 60000,
37
+ "watchPatterns": [
38
+ "{projectRoot}/src/**/*"
39
+ ]
40
+ }
30
41
  },
31
42
  "lint": {},
32
- "test": {}
43
+ "test": {
44
+ "options": {
45
+ "ciEnvironments": [
46
+ "nodejs"
47
+ ],
48
+ "domRequired": true,
49
+ "forceExit": true
50
+ }
51
+ }
33
52
  },
34
53
  "implicitDependencies": [
35
54
  "esbuild",
36
- "node-std"
55
+ "test"
37
56
  ]
38
57
  }
@@ -2,13 +2,14 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import { renderHook, screen, render, act, cleanup } from '@testing-library/react';
5
+ import { renderHook, screen, render, act } from '@testing-library/react';
6
+ import expect from 'expect';
6
7
  import React, { Component, type PropsWithChildren } from 'react';
7
- import { afterEach, beforeEach, describe, expect, test } from 'vitest';
8
8
 
9
9
  import { waitForCondition } from '@dxos/async';
10
10
  import { Client, Config, SystemStatus, fromHost } from '@dxos/client';
11
11
  import { log } from '@dxos/log';
12
+ import { describe, test } from '@dxos/test';
12
13
 
13
14
  import { ClientProvider } from './ClientProvider';
14
15
  import { useClient } from './useClient';
@@ -96,10 +97,6 @@ describe('ClientProvider', () => {
96
97
  await client.halo.createIdentity({ displayName: 'test-user' });
97
98
  });
98
99
 
99
- afterEach(() => {
100
- cleanup();
101
- });
102
-
103
100
  test('Renders with children', async () => {
104
101
  render(
105
102
  <ClientProvider client={client}>
@@ -151,7 +148,7 @@ describe('ClientProvider', () => {
151
148
 
152
149
  await act(async () => {
153
150
  await waitForCondition({
154
- condition: () => !client.initialized && newClient.status.get() === SystemStatus.ACTIVE,
151
+ condition: () => newClient.status.get() === SystemStatus.ACTIVE && !client.initialized,
155
152
  });
156
153
  });
157
154
  expect(client.initialized).toBe(false);
@@ -2,19 +2,12 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import React, {
6
- forwardRef,
7
- type FunctionComponent,
8
- type ReactNode,
9
- useEffect,
10
- useImperativeHandle,
11
- useState,
12
- } from 'react';
5
+ import React, { type FunctionComponent, type ReactNode, useEffect, useMemo, useState } from 'react';
13
6
 
14
7
  import { Client, type ClientOptions, type ClientServicesProvider, SystemStatus } from '@dxos/client';
15
8
  import { type Config } from '@dxos/config';
16
9
  import { type S } from '@dxos/echo-schema';
17
- import { registerSignalRuntime } from '@dxos/echo-signals/react';
10
+ import { registerSignalFactory } from '@dxos/echo-signals/react';
18
11
  import { log } from '@dxos/log';
19
12
  import { useControlledValue } from '@dxos/react-hooks';
20
13
  import { getAsyncProviderValue, type MaybePromise, type Provider } from '@dxos/util';
@@ -30,30 +23,29 @@ export type ClientProviderProps = Pick<ClientContextProps, 'status'> &
30
23
  children?: ReactNode;
31
24
 
32
25
  /**
33
- * Client object or async provider to enable to caller to do custom initialization.
34
- *
35
- * NOTE: For advanced use cases only.
26
+ * Config object or async provider.
36
27
  */
37
- client?: Client | Provider<Promise<Client>>;
28
+ config?: Config | Provider<Promise<Config>>;
38
29
 
39
30
  /**
40
- * Config object or async provider.
31
+ * Client object or async provider to enable to caller to do custom initialization.
41
32
  *
42
- * NOTE: If a `client` is provided then `config` is ignored.
33
+ * Most apps won't need this.
43
34
  */
44
- config?: Config | Provider<Promise<Config>>;
35
+ // TODO(wittjosiah): Remove async and just use to keep reference to client?
36
+ // (Preferring `onInitialized` for custom initialization.)
37
+ // TODO(burdon): Use useImperativeHandle to expose client.
38
+ client?: Client | Provider<Promise<Client>>;
45
39
 
46
40
  /**
47
41
  * Callback to enable the caller to create a custom ClientServicesProvider.
48
42
  *
49
- * NOTE: If a `client` is provided then `services` is ignored.
43
+ * Most apps won't need this.
50
44
  */
51
45
  services?: ClientServicesProvider | ((config?: Config) => MaybePromise<ClientServicesProvider>);
52
46
 
53
47
  /**
54
48
  * List of schema to register.
55
- *
56
- * NOTE: If a `client` is provided then `types` will not be added until after the children are first rendered.
57
49
  */
58
50
  types?: S.Schema<any>[];
59
51
 
@@ -63,16 +55,10 @@ export type ClientProviderProps = Pick<ClientContextProps, 'status'> &
63
55
  fallback?: FunctionComponent<Partial<ClientContextProps>>;
64
56
 
65
57
  /**
66
- * Set to false to stop default signal runtime from being registered.
67
- *
68
- * The signals runtime is used to provide reactive updates to ECHO objects.
69
- */
70
- registerSignalRuntime?: boolean;
71
-
72
- /**
73
- * Skip the DXOS banner print.
58
+ * Set to false to stop default signal factory from being registered.
74
59
  */
75
- disableBanner?: boolean;
60
+ // TODO(burdon): Move to options.
61
+ registerSignalFactory?: boolean;
76
62
 
77
63
  /**
78
64
  * Post initialization hook to enable to caller to do custom initialization.
@@ -86,111 +72,85 @@ export type ClientProviderProps = Pick<ClientContextProps, 'status'> &
86
72
  * Root component that provides the DXOS client instance to child components.
87
73
  * To be used with the `useClient` hook.
88
74
  */
89
- export const ClientProvider = forwardRef<Client | undefined, ClientProviderProps>(
90
- (
91
- {
92
- children,
93
- config: configProvider,
94
- client: clientProvider,
95
- services: servicesProvider,
96
- types,
97
- status: controlledStatus,
98
- fallback: Fallback = () => null,
99
- registerSignalRuntime: _registerSignalRuntime = true,
100
- disableBanner,
101
- onInitialized,
102
- ...options
103
- },
104
- forwardedRef,
105
- ) => {
106
- useEffect(() => {
107
- // TODO(wittjosiah): Ideally this should be imported asynchronously because it is optional.
108
- // Unfortunately, async import seemed to break signals React instrumentation.
109
- _registerSignalRuntime && registerSignalRuntime();
110
- }, [_registerSignalRuntime]);
111
-
112
- // The client is initialized asynchronously.
113
- // If an error occurs during initialization, it is caught and the state is set.
114
- // This allows the error to be thrown in the render method.
115
- // The assumption is that a client initialization error is fatal to the app.
116
- // This error will be caught by the nearest error boundary.
117
- const [error, setError] = useState();
118
- if (error) {
119
- throw error;
75
+ export const ClientProvider = ({
76
+ children,
77
+ config: configProvider,
78
+ client: clientProvider,
79
+ services: servicesProvider,
80
+ types,
81
+ status: controlledStatus,
82
+ fallback: Fallback = () => null,
83
+ registerSignalFactory: _registerSignalFactory = true,
84
+ onInitialized,
85
+ ...options
86
+ }: ClientProviderProps) => {
87
+ useMemo(() => {
88
+ // TODO(wittjosiah): Ideally this should be imported asynchronously because it is optional.
89
+ // Unfortunately, async import seemed to break signals React instrumentation.
90
+ _registerSignalFactory && registerSignalFactory();
91
+ }, []);
92
+
93
+ const [client, setClient] = useState(clientProvider instanceof Client ? clientProvider : undefined);
94
+
95
+ const [error, setError] = useState();
96
+ if (error) {
97
+ throw error;
98
+ }
99
+
100
+ // Status subscription.
101
+ const [status, setStatus] = useControlledValue(controlledStatus);
102
+ useEffect(() => {
103
+ if (!client) {
104
+ return;
120
105
  }
121
106
 
122
- const [client, setClient] = useState(clientProvider instanceof Client ? clientProvider : undefined);
123
-
124
- // Provide external access.
125
- useImperativeHandle(forwardedRef, () => client, [client]);
107
+ const subscription = client.status.subscribe((status) => setStatus(status));
108
+ return () => subscription.unsubscribe();
109
+ }, [client, setStatus]);
110
+
111
+ // Initialize client.
112
+ useEffect(() => {
113
+ const done = async (client: Client) => {
114
+ await client.initialize().catch(setError);
115
+ log('client ready');
116
+ await onInitialized?.(client);
117
+ log('initialization complete');
118
+ if (types) {
119
+ client.addTypes(types);
120
+ }
126
121
 
127
- // Client status subscription.
128
- const [status, setStatus] = useControlledValue(controlledStatus);
129
- useEffect(() => {
130
- if (!client) {
131
- return;
122
+ setClient(client);
123
+ setStatus(client.status.get() ?? SystemStatus.ACTIVE);
124
+ printBanner(client);
125
+ };
126
+
127
+ const t = setTimeout(async () => {
128
+ if (clientProvider) {
129
+ // Asynchronously request client.
130
+ const client = await getAsyncProviderValue(clientProvider);
131
+ await done(client);
132
+ } else {
133
+ // Asynchronously construct client (config may be undefined).
134
+ const config = await getAsyncProviderValue(configProvider);
135
+ log('resolved config', { config });
136
+ const services = await getAsyncProviderValue(servicesProvider, config);
137
+ log('created services', { services });
138
+ const client = new Client({ config, services, ...options });
139
+ log('created client');
140
+ await done(client);
132
141
  }
142
+ });
133
143
 
134
- const subscription = client.status.subscribe((status) => setStatus(status));
135
- return () => subscription.unsubscribe();
136
- }, [client]);
137
-
138
- // Create and/or initialize client.
139
- useEffect(() => {
140
- const initialize = async (client: Client) => {
141
- if (!client.initialized) {
142
- await client.initialize().catch(setError);
143
- log('client ready');
144
- if (types) {
145
- client.addTypes(types);
146
- }
147
- await onInitialized?.(client);
148
- log('initialization complete');
149
- } else if (types) {
150
- client.addTypes(types);
151
- }
152
-
153
- setClient(client);
154
-
155
- if (!disableBanner) {
156
- printBanner(client);
157
- }
158
- };
159
-
160
- let client: Client;
161
- const t = setTimeout(async () => {
162
- if (clientProvider) {
163
- // Asynchronously request client.
164
- client = await getAsyncProviderValue(clientProvider);
165
- await initialize(client);
166
- } else {
167
- // Asynchronously construct client (config may be undefined).
168
- const config = await getAsyncProviderValue(configProvider);
169
- log('resolved config', { config });
170
- const services = await getAsyncProviderValue(servicesProvider, config);
171
- log('created services', { services });
172
- client = new Client({ config, services, ...options });
173
- log('created client');
174
- await initialize(client);
175
- }
176
- });
177
-
178
- return () => {
179
- log('clean up');
180
- clearTimeout(t);
181
- void client
182
- ?.destroy()
183
- .then(() => {
184
- log('destroyed');
185
- })
186
- .catch((err) => log.catch(err));
187
- };
188
- }, [configProvider, clientProvider, servicesProvider, disableBanner]);
189
-
190
- if (!client?.initialized || status !== SystemStatus.ACTIVE) {
191
- return <Fallback client={client} status={status} />;
192
- }
144
+ return () => {
145
+ log('clean up');
146
+ clearTimeout(t);
147
+ void client?.destroy().catch((err) => log.catch(err));
148
+ };
149
+ }, [clientProvider, configProvider, servicesProvider]);
150
+
151
+ if (!client || status !== SystemStatus.ACTIVE) {
152
+ return <Fallback client={client} status={status} />;
153
+ }
193
154
 
194
- return <ClientContext.Provider value={{ client, status }}>{children}</ClientContext.Provider>;
195
- },
196
- );
155
+ return <ClientContext.Provider value={{ client, status }}>{children}</ClientContext.Provider>;
156
+ };
@@ -4,17 +4,17 @@
4
4
 
5
5
  import { type Context, createContext } from 'react';
6
6
 
7
- import { type Client, type SystemStatus } from '@dxos/client';
7
+ import { type Client, type ClientServices, type SystemStatus } from '@dxos/client';
8
8
 
9
9
  export type ClientContextProps = {
10
10
  client: Client;
11
11
 
12
+ // Optionally expose services (e.g., for devtools).
13
+ services?: ClientServices;
14
+
12
15
  status?: SystemStatus | null;
13
16
  };
14
17
 
15
- /**
16
- * @internal Use ClientProvider to create or initialize the Client.
17
- */
18
18
  export const ClientContext: Context<ClientContextProps | undefined> = createContext<ClientContextProps | undefined>(
19
19
  undefined,
20
20
  );
@@ -4,9 +4,12 @@
4
4
 
5
5
  export * from './AgentHostingProvider';
6
6
  export * from './ClientProvider';
7
+
8
+ // TODO(burdon): Remove.
7
9
  export * from './context';
8
10
 
9
11
  export * from './useClient';
12
+ export * from './useClientServices';
10
13
  export * from './useClientStatus';
11
14
  export * from './useConfig';
12
15
  export * from './useShell';
@@ -0,0 +1,15 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ import { useContext } from 'react';
6
+
7
+ import { type ClientServices } from '@dxos/client';
8
+ import { raise } from '@dxos/debug';
9
+
10
+ import { ClientContext } from './context';
11
+
12
+ export const useClientServices = (): ClientServices | undefined => {
13
+ const { services } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));
14
+ return services;
15
+ };
@@ -3,13 +3,15 @@
3
3
  //
4
4
 
5
5
  import { act, renderHook } from '@testing-library/react';
6
- import { describe, expect, test } from 'vitest';
6
+ import expect from 'expect';
7
+ import React from 'react';
7
8
 
8
9
  import { waitForCondition } from '@dxos/async';
9
- import { Config, SystemStatus } from '@dxos/client';
10
+ import { Client, Config, SystemStatus, fromHost } from '@dxos/client';
11
+ import { describe, test } from '@dxos/test';
10
12
 
13
+ import { ClientProvider } from './ClientProvider';
11
14
  import { useConfig } from './useConfig';
12
- import { createClient, createClientContextProvider } from '../testing/util';
13
15
 
14
16
  describe('Config hook', () => {
15
17
  const render = () => useConfig();
@@ -20,8 +22,9 @@ describe('Config hook', () => {
20
22
  });
21
23
 
22
24
  test('should return default client config when no config is passed in a context', async () => {
23
- const { client } = await createClient();
24
- const wrapper = await createClientContextProvider(client);
25
+ const client = new Client({ services: fromHost() });
26
+ await client.initialize();
27
+ const wrapper = ({ children }: any) => <ClientProvider client={client}>{children}</ClientProvider>;
25
28
  const { result } = renderHook(render, { wrapper });
26
29
  await act(async () => {
27
30
  await waitForCondition({ condition: () => client.status.get() === SystemStatus.ACTIVE });
@@ -40,8 +43,9 @@ describe('Config hook', () => {
40
43
  },
41
44
  },
42
45
  });
43
- const { client } = await createClient({ config });
44
- const wrapper = await createClientContextProvider(client);
46
+ const client = new Client({ config, services: fromHost(config) });
47
+ await client.initialize();
48
+ const wrapper = ({ children }: any) => <ClientProvider client={client}>{children}</ClientProvider>;
45
49
  const { result } = renderHook(render, { wrapper });
46
50
  await act(async () => {
47
51
  await waitForCondition({ condition: () => client.status.get() === SystemStatus.ACTIVE });
@@ -5,7 +5,6 @@
5
5
  import { useMemo, useSyncExternalStore } from 'react';
6
6
 
7
7
  import {
8
- Filter,
9
8
  isSpace,
10
9
  type Echo,
11
10
  type EchoReactiveObject,
@@ -42,14 +41,18 @@ export const useQuery = <T extends EchoReactiveObject<any>>(
42
41
  },
43
42
  getObjects: () => (subscribed && query ? query.objects : EMPTY_ARRAY),
44
43
  };
45
- }, [spaceOrEcho, ...filterToDepsArray(filter), ...(deps ?? [])]);
44
+ }, [spaceOrEcho, ...(typeof filter === 'function' ? [] : filterToDepsArray(filter)), ...(deps ?? [])]);
46
45
 
47
46
  // https://beta.reactjs.org/reference/react/useSyncExternalStore
48
47
  // NOTE: This hook will resubscribe whenever the callback passed to the first argument changes -- make sure it is stable.
49
48
  return useSyncExternalStore<T[] | undefined>(subscribe, getObjects) ?? [];
50
49
  };
51
50
 
52
- const filterToDepsArray = (filter?: FilterSource<any>) => [JSON.stringify(Filter.from(filter).toProto())];
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));
53
56
 
54
57
  const noop = () => {};
55
58