@dxos/client-services 0.4.10-main.35cfb0c → 0.4.10-main.36e0428

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 (105) hide show
  1. package/dist/lib/browser/{chunk-RKIUEUQW.mjs → chunk-T4NJPSMU.mjs} +1413 -1144
  2. package/dist/lib/browser/chunk-T4NJPSMU.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +18 -6
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +138 -118
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-JQCOIA5N.cjs → chunk-2L6Y2DJQ.cjs} +1306 -1116
  9. package/dist/lib/node/chunk-2L6Y2DJQ.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +54 -42
  11. package/dist/lib/node/index.cjs.map +3 -3
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/packlets/testing/index.cjs +137 -120
  14. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  15. package/dist/types/src/index.d.ts +1 -0
  16. package/dist/types/src/index.d.ts.map +1 -1
  17. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts +5 -0
  18. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts.map +1 -0
  19. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts +5 -0
  20. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts.map +1 -0
  21. package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts +15 -0
  22. package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts.map +1 -0
  23. package/dist/types/src/packlets/{services → diagnostics}/diagnostics.d.ts +1 -1
  24. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -0
  25. package/dist/types/src/packlets/diagnostics/index.d.ts +4 -0
  26. package/dist/types/src/packlets/diagnostics/index.d.ts.map +1 -0
  27. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  28. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +3 -1
  29. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  30. package/dist/types/src/packlets/invitations/index.d.ts +1 -0
  31. package/dist/types/src/packlets/invitations/index.d.ts.map +1 -1
  32. package/dist/types/src/packlets/invitations/invitation-extension.d.ts +1 -0
  33. package/dist/types/src/packlets/invitations/invitation-extension.d.ts.map +1 -1
  34. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +6 -1
  35. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  36. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +8 -4
  37. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  38. package/dist/types/src/packlets/invitations/invitations-manager.d.ts +44 -0
  39. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -0
  40. package/dist/types/src/packlets/invitations/invitations-service.d.ts +7 -23
  41. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  42. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +2 -1
  43. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  44. package/dist/types/src/packlets/services/index.d.ts +1 -1
  45. package/dist/types/src/packlets/services/index.d.ts.map +1 -1
  46. package/dist/types/src/packlets/services/service-context.d.ts +6 -6
  47. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  48. package/dist/types/src/packlets/services/service-host.d.ts +4 -1
  49. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  50. package/dist/types/src/packlets/services/util.d.ts +1 -0
  51. package/dist/types/src/packlets/services/util.d.ts.map +1 -1
  52. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +8 -3
  53. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  54. package/dist/types/src/packlets/spaces/data-space.d.ts +4 -3
  55. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  56. package/dist/types/src/packlets/storage/level.d.ts.map +1 -1
  57. package/dist/types/src/packlets/system/system-service.d.ts +1 -1
  58. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  59. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  60. package/dist/types/src/packlets/testing/test-builder.d.ts +9 -3
  61. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  62. package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
  63. package/dist/types/src/version.d.ts +1 -1
  64. package/package.json +35 -34
  65. package/src/index.ts +1 -0
  66. package/src/packlets/diagnostics/browser-diagnostics-broadcast.ts +94 -0
  67. package/src/packlets/diagnostics/diagnostics-broadcast.ts +20 -0
  68. package/src/packlets/diagnostics/diagnostics-collector.ts +65 -0
  69. package/src/packlets/{services → diagnostics}/diagnostics.ts +2 -2
  70. package/src/packlets/diagnostics/index.ts +7 -0
  71. package/src/packlets/identity/identity-manager.ts +1 -0
  72. package/src/packlets/identity/identity.test.ts +3 -0
  73. package/src/packlets/invitations/device-invitation-protocol.ts +6 -1
  74. package/src/packlets/invitations/index.ts +1 -0
  75. package/src/packlets/invitations/invitation-extension.ts +28 -1
  76. package/src/packlets/invitations/invitation-protocol.ts +7 -1
  77. package/src/packlets/invitations/invitations-handler.ts +75 -96
  78. package/src/packlets/invitations/invitations-manager.ts +271 -0
  79. package/src/packlets/invitations/invitations-service.ts +23 -168
  80. package/src/packlets/invitations/space-invitation-protocol.ts +45 -3
  81. package/src/packlets/services/automerge-host.test.ts +13 -7
  82. package/src/packlets/services/index.ts +1 -1
  83. package/src/packlets/services/service-context.test.ts +4 -1
  84. package/src/packlets/services/service-context.ts +23 -23
  85. package/src/packlets/services/service-host.test.ts +6 -0
  86. package/src/packlets/services/service-host.ts +22 -23
  87. package/src/packlets/services/util.ts +2 -0
  88. package/src/packlets/spaces/data-space-manager.test.ts +4 -4
  89. package/src/packlets/spaces/data-space-manager.ts +56 -13
  90. package/src/packlets/spaces/data-space.ts +14 -19
  91. package/src/packlets/storage/level.ts +2 -1
  92. package/src/packlets/system/system-service.ts +1 -1
  93. package/src/packlets/testing/invitation-utils.ts +100 -97
  94. package/src/packlets/testing/test-builder.ts +37 -8
  95. package/src/packlets/vault/worker-runtime.ts +3 -1
  96. package/src/version.ts +1 -1
  97. package/dist/lib/browser/chunk-RKIUEUQW.mjs.map +0 -7
  98. package/dist/lib/node/chunk-JQCOIA5N.cjs.map +0 -7
  99. package/dist/types/src/packlets/indexing/index.d.ts +0 -2
  100. package/dist/types/src/packlets/indexing/index.d.ts.map +0 -1
  101. package/dist/types/src/packlets/indexing/util.d.ts +0 -15
  102. package/dist/types/src/packlets/indexing/util.d.ts.map +0 -1
  103. package/dist/types/src/packlets/services/diagnostics.d.ts.map +0 -1
  104. package/src/packlets/indexing/index.ts +0 -5
  105. package/src/packlets/indexing/util.ts +0 -89
@@ -60,146 +60,149 @@ export const performInvitation = ({
60
60
  const guestComplete = new Trigger<Result>();
61
61
  const authCode = new Trigger<string>();
62
62
 
63
- const hostObservable = createInvitation(host, options);
64
- hostObservable.subscribe(
65
- async (hostInvitation: Invitation) => {
66
- switch (hostInvitation.state) {
67
- case Invitation.State.CONNECTING: {
68
- if (hooks?.host?.onConnecting?.(hostObservable)) {
69
- break;
70
- }
71
- const guestObservable = acceptInvitation(guest, hostInvitation, guestDeviceProfile);
72
- guestObservable.subscribe(
73
- async (guestInvitation: Invitation) => {
74
- switch (guestInvitation.state) {
75
- case Invitation.State.CONNECTING: {
76
- if (hooks?.guest?.onConnecting?.(guestObservable)) {
63
+ void createInvitation(host, options).then((hostObservable) => {
64
+ hostObservable.subscribe(
65
+ async (hostInvitation: Invitation) => {
66
+ switch (hostInvitation.state) {
67
+ case Invitation.State.CONNECTING: {
68
+ if (hooks?.host?.onConnecting?.(hostObservable)) {
69
+ break;
70
+ }
71
+ const guestObservable = acceptInvitation(guest, hostInvitation, guestDeviceProfile);
72
+ guestObservable.subscribe(
73
+ async (guestInvitation: Invitation) => {
74
+ switch (guestInvitation.state) {
75
+ case Invitation.State.CONNECTING: {
76
+ if (hooks?.guest?.onConnecting?.(guestObservable)) {
77
+ break;
78
+ }
79
+ invariant(hostInvitation.swarmKey!.equals(guestInvitation.swarmKey!));
77
80
  break;
78
81
  }
79
- invariant(hostInvitation.swarmKey!.equals(guestInvitation.swarmKey!));
80
- break;
81
- }
82
82
 
83
- case Invitation.State.CONNECTED: {
84
- hooks?.guest?.onConnected?.(guestObservable);
85
- break;
86
- }
83
+ case Invitation.State.CONNECTED: {
84
+ hooks?.guest?.onConnected?.(guestObservable);
85
+ break;
86
+ }
87
87
 
88
- case Invitation.State.READY_FOR_AUTHENTICATION: {
89
- if (hooks?.guest?.onReady?.(guestObservable)) {
88
+ case Invitation.State.READY_FOR_AUTHENTICATION: {
89
+ if (hooks?.guest?.onReady?.(guestObservable)) {
90
+ break;
91
+ }
92
+ await guestObservable.authenticate(await authCode.wait());
90
93
  break;
91
94
  }
92
- await guestObservable.authenticate(await authCode.wait());
93
- break;
94
- }
95
95
 
96
- case Invitation.State.AUTHENTICATING: {
97
- hooks?.guest?.onAuthenticating?.(guestObservable);
98
- break;
99
- }
96
+ case Invitation.State.AUTHENTICATING: {
97
+ hooks?.guest?.onAuthenticating?.(guestObservable);
98
+ break;
99
+ }
100
100
 
101
- case Invitation.State.SUCCESS: {
102
- if (hooks?.guest?.onSuccess?.(guestObservable)) {
101
+ case Invitation.State.SUCCESS: {
102
+ if (hooks?.guest?.onSuccess?.(guestObservable)) {
103
+ break;
104
+ }
105
+ guestComplete.wake({ invitation: guestInvitation });
103
106
  break;
104
107
  }
105
- guestComplete.wake({ invitation: guestInvitation });
106
- break;
107
- }
108
108
 
109
- case Invitation.State.CANCELLED: {
110
- if (hooks?.guest?.onCancelled?.(guestObservable)) {
109
+ case Invitation.State.CANCELLED: {
110
+ if (hooks?.guest?.onCancelled?.(guestObservable)) {
111
+ break;
112
+ }
113
+ guestComplete.wake({ invitation: guestInvitation });
111
114
  break;
112
115
  }
113
- guestComplete.wake({ invitation: guestInvitation });
114
- break;
115
- }
116
116
 
117
- case Invitation.State.TIMEOUT: {
118
- if (hooks?.guest?.onTimeout?.(guestObservable)) {
119
- return;
117
+ case Invitation.State.TIMEOUT: {
118
+ if (hooks?.guest?.onTimeout?.(guestObservable)) {
119
+ return;
120
+ }
121
+ guestComplete.wake({ invitation: guestInvitation });
120
122
  }
121
- guestComplete.wake({ invitation: guestInvitation });
122
123
  }
123
- }
124
- },
125
- (error: Error) => {
126
- if (hooks?.guest?.onError?.(guestObservable)) {
127
- return;
128
- }
129
- guestComplete.wake({ error });
130
- },
131
- );
132
- break;
133
- }
134
-
135
- case Invitation.State.CONNECTED: {
136
- hooks?.host?.onConnected?.(hostObservable);
137
- break;
138
- }
124
+ },
125
+ (error: Error) => {
126
+ if (hooks?.guest?.onError?.(guestObservable)) {
127
+ return;
128
+ }
129
+ guestComplete.wake({ error });
130
+ },
131
+ );
132
+ break;
133
+ }
139
134
 
140
- case Invitation.State.READY_FOR_AUTHENTICATION: {
141
- if (hooks?.host?.onReady?.(hostObservable)) {
135
+ case Invitation.State.CONNECTED: {
136
+ hooks?.host?.onConnected?.(hostObservable);
142
137
  break;
143
138
  }
144
- if (hostInvitation.authCode) {
145
- authCode.wake(hostInvitation.authCode);
139
+
140
+ case Invitation.State.READY_FOR_AUTHENTICATION: {
141
+ if (hooks?.host?.onReady?.(hostObservable)) {
142
+ break;
143
+ }
144
+ if (hostInvitation.authCode) {
145
+ authCode.wake(hostInvitation.authCode);
146
+ }
147
+ break;
146
148
  }
147
- break;
148
- }
149
149
 
150
- case Invitation.State.AUTHENTICATING: {
151
- hooks?.host?.onAuthenticating?.(hostObservable);
152
- break;
153
- }
150
+ case Invitation.State.AUTHENTICATING: {
151
+ hooks?.host?.onAuthenticating?.(hostObservable);
152
+ break;
153
+ }
154
154
 
155
- case Invitation.State.SUCCESS: {
156
- if (hooks?.host?.onSuccess?.(hostObservable)) {
155
+ case Invitation.State.SUCCESS: {
156
+ if (hooks?.host?.onSuccess?.(hostObservable)) {
157
+ break;
158
+ }
159
+ hostComplete.wake({ invitation: hostInvitation });
157
160
  break;
158
161
  }
159
- hostComplete.wake({ invitation: hostInvitation });
160
- break;
161
- }
162
162
 
163
- case Invitation.State.CANCELLED: {
164
- if (hooks?.host?.onCancelled?.(hostObservable)) {
163
+ case Invitation.State.CANCELLED: {
164
+ if (hooks?.host?.onCancelled?.(hostObservable)) {
165
+ break;
166
+ }
167
+ hostComplete.wake({ invitation: hostInvitation });
165
168
  break;
166
169
  }
167
- hostComplete.wake({ invitation: hostInvitation });
168
- break;
169
- }
170
170
 
171
- case Invitation.State.TIMEOUT: {
172
- if (hooks?.host?.onTimeout?.(hostObservable)) {
171
+ case Invitation.State.TIMEOUT: {
172
+ if (hooks?.host?.onTimeout?.(hostObservable)) {
173
+ break;
174
+ }
175
+ hostComplete.wake({ invitation: hostInvitation });
173
176
  break;
174
177
  }
175
- hostComplete.wake({ invitation: hostInvitation });
176
- break;
177
178
  }
178
- }
179
- },
180
- (error: Error) => {
181
- if (hooks?.host?.onError?.(hostObservable)) {
182
- return;
183
- }
184
- hostComplete.wake({ error });
185
- },
186
- );
179
+ },
180
+ (error: Error) => {
181
+ if (hooks?.host?.onError?.(hostObservable)) {
182
+ return;
183
+ }
184
+ hostComplete.wake({ error });
185
+ },
186
+ );
187
+ });
187
188
 
188
189
  return [hostComplete.wait(), guestComplete.wait()];
189
190
  };
190
191
 
191
- const createInvitation = (
192
+ const createInvitation = async (
192
193
  host: ServiceContext | InvitationHost,
193
194
  options?: Partial<Invitation>,
194
- ): CancellableInvitation => {
195
+ ): Promise<CancellableInvitation> => {
195
196
  options ??= {
196
197
  authMethod: Invitation.AuthMethod.NONE,
197
198
  ...(options ?? {}),
198
199
  };
199
200
 
200
201
  if (host instanceof ServiceContext) {
201
- const hostHandler = host.getInvitationHandler({ kind: Invitation.Kind.SPACE, ...options });
202
- return host.invitations.createInvitation(hostHandler, options);
202
+ return host.invitationsManager.createInvitation({
203
+ kind: Invitation.Kind.SPACE,
204
+ ...options,
205
+ });
203
206
  }
204
207
 
205
208
  return host.share(options);
@@ -6,15 +6,18 @@ import { type Config } from '@dxos/config';
6
6
  import { Context } from '@dxos/context';
7
7
  import { createCredentialSignerWithChain, CredentialGenerator } from '@dxos/credentials';
8
8
  import { failUndefined } from '@dxos/debug';
9
- import { AutomergeHost, MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from '@dxos/echo-pipeline';
9
+ import { EchoHost } from '@dxos/echo-db';
10
+ import { MetadataStore, type LevelDB, SnapshotStore, SpaceManager, valueEncoding } from '@dxos/echo-pipeline';
11
+ import { createTestLevel } from '@dxos/echo-pipeline/testing';
10
12
  import { FeedFactory, FeedStore } from '@dxos/feed-store';
11
- import { createTestLevel } from '@dxos/indexing/testing';
12
13
  import { Keyring } from '@dxos/keyring';
13
14
  import { MemorySignalManager, MemorySignalManagerContext } from '@dxos/messaging';
14
15
  import { MemoryTransportFactory, NetworkManager } from '@dxos/network-manager';
16
+ import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
15
17
  import { createStorage, StorageType, type Storage } from '@dxos/random-access-storage';
16
18
  import { BlobStore } from '@dxos/teleport-extension-object-sync';
17
19
 
20
+ import { InvitationsHandler, InvitationsManager, SpaceInvitationProtocol } from '../invitations';
18
21
  import { ClientServicesHost, ServiceContext } from '../services';
19
22
  import { DataSpaceManager, type SigningContext } from '../spaces';
20
23
 
@@ -42,7 +45,8 @@ export const createServiceContext = async ({
42
45
  signalManager,
43
46
  transportFactory: MemoryTransportFactory,
44
47
  });
45
- const level = await createTestLevel();
48
+ const level = createTestLevel();
49
+ await level.open();
46
50
 
47
51
  return new ServiceContext(storage, level, networkManager, signalManager);
48
52
  };
@@ -85,6 +89,7 @@ export type TestPeerOpts = {
85
89
 
86
90
  export type TestPeerProps = {
87
91
  storage?: Storage;
92
+ level?: LevelDB;
88
93
  feedStore?: FeedStore<any>;
89
94
  metadataStore?: MetadataStore;
90
95
  keyring?: Keyring;
@@ -94,7 +99,8 @@ export type TestPeerProps = {
94
99
  snapshotStore?: SnapshotStore;
95
100
  signingContext?: SigningContext;
96
101
  blobStore?: BlobStore;
97
- automergeHost?: AutomergeHost;
102
+ echoHost?: EchoHost;
103
+ invitationsManager?: InvitationsManager;
98
104
  };
99
105
 
100
106
  export class TestPeer {
@@ -117,6 +123,10 @@ export class TestPeer {
117
123
  return (this._props.keyring ??= new Keyring(this.storage.createDirectory('keyring')));
118
124
  }
119
125
 
126
+ get level() {
127
+ return (this._props.level ??= createTestLevel());
128
+ }
129
+
120
130
  get feedStore() {
121
131
  return (this._props.feedStore ??= new FeedStore({
122
132
  factory: new FeedFactory({
@@ -162,18 +172,36 @@ export class TestPeer {
162
172
  return this._props.signingContext ?? failUndefined();
163
173
  }
164
174
 
165
- get automergeHost() {
166
- return (this._props.automergeHost ??= new AutomergeHost({ directory: this.storage.createDirectory('automerge') }));
175
+ get echoHost() {
176
+ return (this._props.echoHost ??= new EchoHost({
177
+ kv: this.level,
178
+ storage: this.storage,
179
+ }));
167
180
  }
168
181
 
169
- get dataSpaceManager() {
182
+ get dataSpaceManager(): DataSpaceManager {
170
183
  return (this._props.dataSpaceManager ??= new DataSpaceManager(
171
184
  this.spaceManager,
172
185
  this.metadataStore,
173
186
  this.keyring,
174
187
  this.identity,
175
188
  this.feedStore,
176
- this.automergeHost,
189
+ this.echoHost,
190
+ this.invitationsManager,
191
+ ));
192
+ }
193
+
194
+ get invitationsManager() {
195
+ return (this._props.invitationsManager ??= new InvitationsManager(
196
+ new InvitationsHandler(this.networkManager),
197
+ (invitation) => {
198
+ if (invitation.kind === Invitation.Kind.SPACE) {
199
+ return new SpaceInvitationProtocol(this.dataSpaceManager, this.identity!, this.keyring, invitation.spaceKey!);
200
+ } else {
201
+ throw new Error('not implemented');
202
+ }
203
+ },
204
+ this.metadataStore,
177
205
  ));
178
206
  }
179
207
 
@@ -182,6 +210,7 @@ export class TestPeer {
182
210
  }
183
211
 
184
212
  async destroy() {
213
+ await this.level.close();
185
214
  await this.storage.reset();
186
215
  }
187
216
  }
@@ -120,7 +120,9 @@ export class WorkerRuntime {
120
120
  this._sessions.delete(session);
121
121
  if (this._sessions.size === 0) {
122
122
  // Terminate the worker when all sessions are closed.
123
- self.close();
123
+ if (globalThis.self) {
124
+ self.close();
125
+ }
124
126
  } else {
125
127
  this._reconnectWebrtc();
126
128
  }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const DXOS_VERSION = "0.4.10-main.35cfb0c";
1
+ export const DXOS_VERSION = "0.4.10-main.36e0428";