@dxos/client-services 0.1.28 → 0.1.29-next.1bc50d4

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 (150) hide show
  1. package/dist/lib/browser/{chunk-OTSGRZZI.mjs → chunk-ILMYW75X.mjs} +740 -1043
  2. package/dist/lib/browser/chunk-ILMYW75X.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +7 -41
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/packlets/testing/index.mjs +163 -50
  6. package/dist/lib/browser/packlets/testing/index.mjs.map +4 -4
  7. package/dist/lib/node/index.cjs +645 -969
  8. package/dist/lib/node/index.cjs.map +4 -4
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/packlets/testing/index.cjs +2686 -2637
  11. package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
  12. package/dist/types/src/packlets/devices/devices-service.test.d.ts +2 -0
  13. package/dist/types/src/packlets/devices/devices-service.test.d.ts.map +1 -0
  14. package/dist/types/src/packlets/identity/identity-service.test.d.ts +2 -0
  15. package/dist/types/src/packlets/identity/identity-service.test.d.ts.map +1 -0
  16. package/dist/types/src/packlets/invitations/device-invitations-handler.d.ts +1 -2
  17. package/dist/types/src/packlets/invitations/device-invitations-handler.d.ts.map +1 -1
  18. package/dist/types/src/packlets/invitations/device-invitations-service.d.ts +1 -1
  19. package/dist/types/src/packlets/invitations/device-invitations-service.d.ts.map +1 -1
  20. package/dist/types/src/packlets/invitations/index.d.ts +0 -6
  21. package/dist/types/src/packlets/invitations/index.d.ts.map +1 -1
  22. package/dist/types/src/packlets/invitations/invitations-service.d.ts +2 -3
  23. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  24. package/dist/types/src/packlets/invitations/space-invitations-handler.d.ts +2 -4
  25. package/dist/types/src/packlets/invitations/space-invitations-handler.d.ts.map +1 -1
  26. package/dist/types/src/packlets/invitations/space-invitations-service.d.ts +2 -3
  27. package/dist/types/src/packlets/invitations/space-invitations-service.d.ts.map +1 -1
  28. package/dist/types/src/packlets/network/network-service.test.d.ts +2 -0
  29. package/dist/types/src/packlets/network/network-service.test.d.ts.map +1 -0
  30. package/dist/types/src/packlets/services/index.d.ts +2 -2
  31. package/dist/types/src/packlets/services/index.d.ts.map +1 -1
  32. package/dist/types/src/packlets/services/local-client-services.d.ts +15 -0
  33. package/dist/types/src/packlets/services/local-client-services.d.ts.map +1 -0
  34. package/dist/types/src/packlets/services/service-context.d.ts +1 -1
  35. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  36. package/dist/types/src/packlets/services/service-host.d.ts +3 -5
  37. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  38. package/dist/types/src/packlets/services/utils.d.ts +7 -0
  39. package/dist/types/src/packlets/services/utils.d.ts.map +1 -0
  40. package/dist/types/src/packlets/spaces/index.d.ts +2 -0
  41. package/dist/types/src/packlets/spaces/index.d.ts.map +1 -1
  42. package/dist/types/src/packlets/spaces/spaces-service.test.d.ts +2 -0
  43. package/dist/types/src/packlets/spaces/spaces-service.test.d.ts.map +1 -0
  44. package/dist/types/src/packlets/testing/host-test-builder.d.ts +43 -0
  45. package/dist/types/src/packlets/testing/host-test-builder.d.ts.map +1 -0
  46. package/dist/types/src/packlets/testing/index.d.ts +1 -0
  47. package/dist/types/src/packlets/testing/index.d.ts.map +1 -1
  48. package/dist/types/src/packlets/testing/invitation-utils.d.ts +1 -1
  49. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  50. package/dist/types/src/packlets/testing/test-builder.d.ts +30 -34
  51. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  52. package/dist/types/src/packlets/tests/client-services.test.d.ts +2 -0
  53. package/dist/types/src/packlets/tests/client-services.test.d.ts.map +1 -0
  54. package/dist/types/src/packlets/tests/client.test.d.ts +2 -0
  55. package/dist/types/src/packlets/tests/client.test.d.ts.map +1 -0
  56. package/dist/types/src/packlets/tests/halo-credentials.test.d.ts +2 -0
  57. package/dist/types/src/packlets/tests/halo-credentials.test.d.ts.map +1 -0
  58. package/dist/types/src/packlets/tests/halo-persistent.test.d.ts +2 -0
  59. package/dist/types/src/packlets/tests/halo-persistent.test.d.ts.map +1 -0
  60. package/dist/types/src/packlets/tests/halo-profile.test.d.ts +2 -0
  61. package/dist/types/src/packlets/tests/halo-profile.test.d.ts.map +1 -0
  62. package/dist/types/src/packlets/tests/shared-worker.test.d.ts +2 -0
  63. package/dist/types/src/packlets/tests/shared-worker.test.d.ts.map +1 -0
  64. package/dist/types/src/packlets/tests/spaces-invitations.test.d.ts +2 -0
  65. package/dist/types/src/packlets/tests/spaces-invitations.test.d.ts.map +1 -0
  66. package/dist/types/src/packlets/tests/spaces.test.d.ts +2 -0
  67. package/dist/types/src/packlets/tests/spaces.test.d.ts.map +1 -0
  68. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts +2 -2
  69. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts.map +1 -1
  70. package/dist/types/src/packlets/vault/iframe-proxy-runtime.d.ts.map +1 -1
  71. package/dist/types/src/packlets/vault/index.d.ts +0 -2
  72. package/dist/types/src/packlets/vault/index.d.ts.map +1 -1
  73. package/dist/types/src/packlets/vault/shell-runtime.d.ts.map +1 -1
  74. package/dist/types/src/packlets/vault/worker-session.d.ts +1 -1
  75. package/dist/types/src/packlets/vault/worker-session.d.ts.map +1 -1
  76. package/package.json +30 -30
  77. package/src/packlets/devices/devices-service.test.ts +56 -0
  78. package/src/packlets/identity/identity-service.test.ts +82 -0
  79. package/src/packlets/invitations/device-invitations-handler.ts +10 -9
  80. package/src/packlets/invitations/device-invitations-service.test.ts +1 -1
  81. package/src/packlets/invitations/device-invitations-service.ts +1 -1
  82. package/src/packlets/invitations/index.ts +0 -6
  83. package/src/packlets/invitations/invitations-service.ts +7 -2
  84. package/src/packlets/invitations/space-invitations-handler.test.ts +3 -3
  85. package/src/packlets/invitations/space-invitations-handler.ts +11 -11
  86. package/src/packlets/invitations/space-invitations-service.test.ts +1 -1
  87. package/src/packlets/invitations/space-invitations-service.ts +2 -3
  88. package/src/packlets/network/network-service.test.ts +52 -0
  89. package/src/packlets/services/index.ts +2 -2
  90. package/src/packlets/services/local-client-services.ts +35 -0
  91. package/src/packlets/services/service-context.test.ts +4 -4
  92. package/src/packlets/services/service-context.ts +1 -1
  93. package/src/packlets/services/service-host.ts +3 -11
  94. package/src/packlets/services/service-registry.test.ts +2 -2
  95. package/src/packlets/services/utils.ts +53 -0
  96. package/src/packlets/spaces/data-space-manager.test.ts +4 -4
  97. package/src/packlets/spaces/data-space-manager.ts +1 -1
  98. package/src/packlets/spaces/index.ts +2 -0
  99. package/src/packlets/spaces/spaces-service.test.ts +107 -0
  100. package/src/packlets/testing/host-test-builder.ts +163 -0
  101. package/src/packlets/testing/index.ts +1 -0
  102. package/src/packlets/testing/invitation-utils.ts +1 -2
  103. package/src/packlets/testing/test-builder.ts +118 -140
  104. package/src/packlets/tests/client-services.test.ts +252 -0
  105. package/src/packlets/tests/client.test.ts +143 -0
  106. package/src/packlets/tests/halo-credentials.test.ts +94 -0
  107. package/src/packlets/tests/halo-persistent.test.ts +53 -0
  108. package/src/packlets/tests/halo-profile.test.ts +74 -0
  109. package/src/packlets/tests/shared-worker.test.ts +96 -0
  110. package/src/packlets/tests/spaces-invitations.test.ts +24 -0
  111. package/src/packlets/tests/spaces.test.ts +68 -0
  112. package/src/packlets/vault/iframe-host-runtime.ts +6 -3
  113. package/src/packlets/vault/iframe-proxy-runtime.ts +1 -1
  114. package/src/packlets/vault/index.ts +0 -2
  115. package/src/packlets/vault/shell-runtime.ts +1 -2
  116. package/src/packlets/vault/worker-session.ts +7 -3
  117. package/dist/lib/browser/chunk-OTSGRZZI.mjs.map +0 -7
  118. package/dist/types/src/packlets/invitations/device-invitations-proxy.d.ts +0 -8
  119. package/dist/types/src/packlets/invitations/device-invitations-proxy.d.ts.map +0 -1
  120. package/dist/types/src/packlets/invitations/encoder.d.ts +0 -9
  121. package/dist/types/src/packlets/invitations/encoder.d.ts.map +0 -1
  122. package/dist/types/src/packlets/invitations/encoder.test.d.ts +0 -2
  123. package/dist/types/src/packlets/invitations/encoder.test.d.ts.map +0 -1
  124. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +0 -56
  125. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +0 -1
  126. package/dist/types/src/packlets/invitations/invitations-proxy.d.ts +0 -18
  127. package/dist/types/src/packlets/invitations/invitations-proxy.d.ts.map +0 -1
  128. package/dist/types/src/packlets/invitations/invitations.d.ts +0 -55
  129. package/dist/types/src/packlets/invitations/invitations.d.ts.map +0 -1
  130. package/dist/types/src/packlets/invitations/space-invitations-proxy.d.ts +0 -11
  131. package/dist/types/src/packlets/invitations/space-invitations-proxy.d.ts.map +0 -1
  132. package/dist/types/src/packlets/services/service-definitions.d.ts +0 -30
  133. package/dist/types/src/packlets/services/service-definitions.d.ts.map +0 -1
  134. package/dist/types/src/packlets/services/service-proxy.d.ts +0 -17
  135. package/dist/types/src/packlets/services/service-proxy.d.ts.map +0 -1
  136. package/dist/types/src/packlets/vault/services.d.ts +0 -21
  137. package/dist/types/src/packlets/vault/services.d.ts.map +0 -1
  138. package/dist/types/src/packlets/vault/shell-controller.d.ts +0 -18
  139. package/dist/types/src/packlets/vault/shell-controller.d.ts.map +0 -1
  140. package/src/packlets/invitations/device-invitations-proxy.ts +0 -14
  141. package/src/packlets/invitations/encoder.test.ts +0 -23
  142. package/src/packlets/invitations/encoder.ts +0 -26
  143. package/src/packlets/invitations/invitations-handler.ts +0 -68
  144. package/src/packlets/invitations/invitations-proxy.ts +0 -159
  145. package/src/packlets/invitations/invitations.ts +0 -113
  146. package/src/packlets/invitations/space-invitations-proxy.ts +0 -16
  147. package/src/packlets/services/service-definitions.ts +0 -68
  148. package/src/packlets/services/service-proxy.ts +0 -54
  149. package/src/packlets/vault/services.ts +0 -42
  150. package/src/packlets/vault/shell-controller.ts +0 -56
@@ -0,0 +1,96 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ import chai, { expect } from 'chai';
6
+ import chaiAsPromised from 'chai-as-promised';
7
+
8
+ import { sleep } from '@dxos/async';
9
+ import { Client, ClientServicesProxy, fromIFrame } from '@dxos/client';
10
+ import { Config } from '@dxos/config';
11
+ import { createLinkedPorts } from '@dxos/rpc';
12
+ import { describe, test, afterTest } from '@dxos/test';
13
+
14
+ import { TestBuilder } from '../testing';
15
+ import { IFrameProxyRuntime, WorkerRuntime } from '../vault';
16
+
17
+ chai.use(chaiAsPromised);
18
+
19
+ describe('Shared worker', () => {
20
+ test('client connects to the worker', async () => {
21
+ const workerRuntime = new WorkerRuntime(() => new Config({}));
22
+
23
+ const systemPorts = createLinkedPorts();
24
+ const workerProxyPorts = createLinkedPorts();
25
+ const proxyWindowPorts = createLinkedPorts();
26
+ const shellPorts = createLinkedPorts();
27
+ void workerRuntime.createSession({
28
+ systemPort: systemPorts[1],
29
+ appPort: workerProxyPorts[1],
30
+ shellPort: shellPorts[1]
31
+ });
32
+ const clientProxy = new IFrameProxyRuntime({
33
+ systemPort: systemPorts[0],
34
+ windowAppPort: proxyWindowPorts[0],
35
+ workerAppPort: workerProxyPorts[0],
36
+ shellPort: shellPorts[0]
37
+ });
38
+ const client = new Client({
39
+ services: new ClientServicesProxy(proxyWindowPorts[1])
40
+ });
41
+
42
+ await Promise.all([workerRuntime.start(), clientProxy.open('*'), client.initialize()]);
43
+
44
+ await client.halo.createIdentity();
45
+ });
46
+
47
+ test('initialization errors get propagated to the client', async () => {
48
+ const workerRuntime = new WorkerRuntime(async () => {
49
+ await sleep(1);
50
+ throw new Error('Test error');
51
+ });
52
+
53
+ const systemPorts = createLinkedPorts();
54
+ const workerProxyPorts = createLinkedPorts();
55
+ const proxyWindowPorts = createLinkedPorts();
56
+ const shellPorts = createLinkedPorts();
57
+ void workerRuntime.createSession({
58
+ systemPort: systemPorts[1],
59
+ appPort: workerProxyPorts[1],
60
+ shellPort: shellPorts[1]
61
+ });
62
+
63
+ const clientProxy = new IFrameProxyRuntime({
64
+ systemPort: systemPorts[0],
65
+ windowAppPort: proxyWindowPorts[0],
66
+ workerAppPort: workerProxyPorts[0],
67
+ shellPort: shellPorts[0]
68
+ });
69
+
70
+ const client = new Client({
71
+ services: new ClientServicesProxy(proxyWindowPorts[1])
72
+ });
73
+
74
+ const promise = Promise.all([
75
+ workerRuntime.start().catch(() => {}), // This error should be propagated to client.initialize() call.
76
+ clientProxy.open('*')
77
+ ]);
78
+
79
+ await expect(client.initialize()).to.be.rejectedWith('Test error');
80
+
81
+ await promise;
82
+ });
83
+
84
+ // TODO(burdon): Browser-only.
85
+ test.skip('creates client with remote iframe', async () => {
86
+ const testBuilder = new TestBuilder();
87
+
88
+ const client = new Client({
89
+ services: fromIFrame(testBuilder.config)
90
+ });
91
+
92
+ await client.initialize();
93
+ afterTest(() => client.destroy());
94
+ expect(client.initialized).to.be.true;
95
+ });
96
+ });
@@ -0,0 +1,24 @@
1
+ //
2
+ // Copyright 2021 DXOS.org
3
+ //
4
+
5
+ import { Client } from '@dxos/client';
6
+ import { describe, test, afterTest } from '@dxos/test';
7
+
8
+ import { TestBuilder, testSpace } from '../testing';
9
+
10
+ describe('Spaces/invitations', () => {
11
+ test('creates a space and invites a peer', async () => {
12
+ const testBuilder = new TestBuilder();
13
+
14
+ const client = new Client({ services: testBuilder.createLocal() });
15
+ afterTest(() => client.destroy());
16
+ await client.initialize();
17
+ await client.halo.createIdentity({ displayName: 'test-user' });
18
+
19
+ {
20
+ const space = await client.echo.createSpace();
21
+ await testSpace(space.internal.db);
22
+ }
23
+ });
24
+ });
@@ -0,0 +1,68 @@
1
+ //
2
+ // Copyright 2021 DXOS.org
3
+ //
4
+
5
+ import { expect } from 'chai';
6
+
7
+ import { Client } from '@dxos/client';
8
+ import { Config } from '@dxos/config';
9
+ import { log } from '@dxos/log';
10
+ import { createStorage, StorageType } from '@dxos/random-access-storage';
11
+ import { describe, test, afterTest } from '@dxos/test';
12
+
13
+ import { TestBuilder, testSpace } from '../testing';
14
+
15
+ describe('Spaces', () => {
16
+ test('creates a space', async () => {
17
+ const testBuilder = new TestBuilder();
18
+
19
+ const client = new Client({ services: testBuilder.createLocal() });
20
+ afterTest(() => client.destroy());
21
+
22
+ await client.initialize();
23
+ await client.halo.createIdentity({ displayName: 'test-user' });
24
+
25
+ // TODO(burdon): Extend basic queries.
26
+ const space = await client.echo.createSpace();
27
+ await testSpace(space.internal.db);
28
+
29
+ expect(space.getMembers()).to.be.length(1);
30
+ });
31
+
32
+ test('creates a space re-opens the client', async () => {
33
+ const testBuilder = new TestBuilder(new Config({ version: 1 }));
34
+ testBuilder.storage = createStorage({ type: StorageType.RAM });
35
+
36
+ const client = new Client({ services: testBuilder.createLocal() });
37
+ await client.initialize();
38
+ await client.halo.createIdentity({ displayName: 'test-user' });
39
+
40
+ let itemId: string;
41
+ {
42
+ // TODO(burdon): API (client.echo/client.halo).
43
+ const space = await client.echo.createSpace();
44
+ const {
45
+ objectsCreated: [item]
46
+ } = await testSpace(space.internal.db);
47
+ itemId = item.id;
48
+ expect(space.getMembers()).to.be.length(1);
49
+ }
50
+
51
+ await client.destroy();
52
+
53
+ log.break();
54
+
55
+ await client.initialize();
56
+
57
+ {
58
+ const result = client.echo.getSpaces();
59
+ expect(result).to.have.length(1);
60
+ const space = result[0];
61
+
62
+ const item = space.internal.db._itemManager.getItem(itemId)!;
63
+ expect(item).to.exist;
64
+ }
65
+
66
+ await client.destroy();
67
+ });
68
+ });
@@ -3,6 +3,7 @@
3
3
  //
4
4
 
5
5
  import { Trigger } from '@dxos/async';
6
+ import { clientServiceBundle, ClientServices } from '@dxos/client';
6
7
  import { Config } from '@dxos/config';
7
8
  import { log, logInfo } from '@dxos/log';
8
9
  import { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager } from '@dxos/messaging';
@@ -10,7 +11,7 @@ import { createWebRTCTransportFactory, NetworkManager } from '@dxos/network-mana
10
11
  import { createProtoRpcPeer, ProtoRpcPeer, RpcPort } from '@dxos/rpc';
11
12
  import { getAsyncValue, Provider } from '@dxos/util';
12
13
 
13
- import { clientServiceBundle, ClientServices, ClientServicesHost } from '../services';
14
+ import { LocalClientServices } from '../services';
14
15
  import { ShellRuntime, ShellRuntimeImpl } from './shell-runtime';
15
16
 
16
17
  const LOCK_KEY = 'DXOS_RESOURCE_LOCK';
@@ -38,7 +39,9 @@ export class IFrameHostRuntime {
38
39
  private readonly _appPort: RpcPort;
39
40
  private readonly _shellPort?: RpcPort;
40
41
  private _config!: Config;
41
- private _clientServices!: ClientServicesHost;
42
+
43
+ // TODO(dmaretskyi): Replace with host and figure out how to return services provider here.
44
+ private _clientServices!: LocalClientServices;
42
45
  private _clientRpc!: ProtoRpcPeer<ClientServices>;
43
46
  private _shellRuntime?: ShellRuntimeImpl;
44
47
 
@@ -82,7 +85,7 @@ export class IFrameHostRuntime {
82
85
  try {
83
86
  this._config = await getAsyncValue(this._configProvider);
84
87
  const signalServer = this._config.get('runtime.services.signal.server');
85
- this._clientServices = new ClientServicesHost({
88
+ this._clientServices = new LocalClientServices({
86
89
  lockKey: LOCK_KEY,
87
90
  config: this._config,
88
91
  networkManager: new NetworkManager({
@@ -2,11 +2,11 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
+ import { iframeServiceBundle, workerServiceBundle, WorkerServiceBundle } from '@dxos/client';
5
6
  import { WebRTCTransportService } from '@dxos/network-manager';
6
7
  import { BridgeService } from '@dxos/protocols/proto/dxos/mesh/bridge';
7
8
  import { createProtoRpcPeer, ProtoRpcPeer, RpcPort } from '@dxos/rpc';
8
9
 
9
- import { iframeServiceBundle, WorkerServiceBundle, workerServiceBundle } from './services';
10
10
  import { ShellRuntime, ShellRuntimeImpl } from './shell-runtime';
11
11
 
12
12
  // NOTE: Keep as RpcPorts to avoid dependency on @dxos/rpc-tunnel so we don't depend on browser-specific apis.
@@ -4,8 +4,6 @@
4
4
 
5
5
  export * from './iframe-host-runtime';
6
6
  export * from './iframe-proxy-runtime';
7
- export * from './services';
8
- export * from './shell-controller';
9
7
  export * from './shell-runtime';
10
8
  export * from './vault-resource-lock';
11
9
  export * from './worker-runtime';
@@ -5,12 +5,11 @@
5
5
  import assert from 'node:assert';
6
6
 
7
7
  import { Event } from '@dxos/async';
8
+ import { appServiceBundle, AppServiceBundle, shellServiceBundle } from '@dxos/client';
8
9
  import { PublicKey } from '@dxos/keys';
9
10
  import { AppContextRequest, LayoutRequest, ShellLayout } from '@dxos/protocols/proto/dxos/iframe';
10
11
  import { createProtoRpcPeer, ProtoRpcPeer, RpcPort } from '@dxos/rpc';
11
12
 
12
- import { AppServiceBundle, appServiceBundle, shellServiceBundle } from './services';
13
-
14
13
  export interface ShellRuntime {
15
14
  layoutUpdate: Event<LayoutRequest>;
16
15
  layout: ShellLayout;
@@ -5,14 +5,18 @@
5
5
  import assert from 'node:assert';
6
6
 
7
7
  import { asyncTimeout, Trigger } from '@dxos/async';
8
+ import {
9
+ clientServiceBundle,
10
+ ClientServices,
11
+ iframeServiceBundle,
12
+ IframeServiceBundle,
13
+ workerServiceBundle
14
+ } from '@dxos/client';
8
15
  import { log, logInfo } from '@dxos/log';
9
16
  import { BridgeService } from '@dxos/protocols/proto/dxos/mesh/bridge';
10
17
  import { createProtoRpcPeer, ProtoRpcPeer, RpcPort } from '@dxos/rpc';
11
18
  import { Callback } from '@dxos/util';
12
19
 
13
- import { clientServiceBundle, ClientServices } from '../services';
14
- import { IframeServiceBundle, iframeServiceBundle, workerServiceBundle } from './services';
15
-
16
20
  export type WorkerSessionParams = {
17
21
  getService: <Service>(find: (services: Partial<ClientServices>) => Service | undefined) => Promise<Service>;
18
22
  systemPort: RpcPort;