@dxos/client-services 0.1.2 → 0.1.4

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 (287) hide show
  1. package/dist/src/index.d.ts +3 -1
  2. package/dist/src/index.d.ts.map +1 -1
  3. package/dist/src/index.js +3 -1
  4. package/dist/src/index.js.map +1 -1
  5. package/dist/src/packlets/deprecated/index.d.ts +5 -0
  6. package/dist/src/packlets/deprecated/index.d.ts.map +1 -0
  7. package/dist/src/packlets/{services/impl → deprecated}/index.js +1 -3
  8. package/dist/src/packlets/deprecated/index.js.map +1 -0
  9. package/dist/src/packlets/{invitations/common.d.ts → deprecated/invitations.d.ts} +14 -2
  10. package/dist/src/packlets/deprecated/invitations.d.ts.map +1 -0
  11. package/dist/src/packlets/{invitations/common.js → deprecated/invitations.js} +1 -1
  12. package/dist/src/packlets/deprecated/invitations.js.map +1 -0
  13. package/dist/src/packlets/{services/impl → deprecated}/profile.d.ts +5 -5
  14. package/dist/src/packlets/deprecated/profile.d.ts.map +1 -0
  15. package/dist/src/packlets/{services/impl → deprecated}/profile.js +10 -10
  16. package/dist/src/packlets/deprecated/profile.js.map +1 -0
  17. package/dist/src/packlets/deprecated/space.d.ts +23 -0
  18. package/dist/src/packlets/deprecated/space.d.ts.map +1 -0
  19. package/dist/src/packlets/deprecated/space.js +206 -0
  20. package/dist/src/packlets/deprecated/space.js.map +1 -0
  21. package/dist/src/packlets/{services/impl → deprecated}/system.d.ts +2 -2
  22. package/dist/src/packlets/deprecated/system.d.ts.map +1 -0
  23. package/dist/src/packlets/{services/impl → deprecated}/system.js +3 -3
  24. package/dist/src/packlets/deprecated/system.js.map +1 -0
  25. package/dist/src/packlets/deprecated/tracing.d.ts +12 -0
  26. package/dist/src/packlets/deprecated/tracing.d.ts.map +1 -0
  27. package/dist/src/packlets/{services/impl → deprecated}/tracing.js +3 -3
  28. package/dist/src/packlets/deprecated/tracing.js.map +1 -0
  29. package/dist/src/packlets/{services/impl → devtools}/devtools.d.ts +11 -7
  30. package/dist/src/packlets/devtools/devtools.d.ts.map +1 -0
  31. package/dist/src/packlets/devtools/devtools.js +86 -0
  32. package/dist/src/packlets/devtools/devtools.js.map +1 -0
  33. package/dist/src/packlets/devtools/feeds.d.ts.map +1 -1
  34. package/dist/src/packlets/devtools/feeds.js +28 -26
  35. package/dist/src/packlets/devtools/feeds.js.map +1 -1
  36. package/dist/src/packlets/devtools/index.d.ts +1 -1
  37. package/dist/src/packlets/devtools/index.d.ts.map +1 -1
  38. package/dist/src/packlets/devtools/index.js +1 -1
  39. package/dist/src/packlets/devtools/index.js.map +1 -1
  40. package/dist/src/packlets/devtools/spaces.d.ts +2 -2
  41. package/dist/src/packlets/devtools/spaces.d.ts.map +1 -1
  42. package/dist/src/packlets/devtools/spaces.js +13 -13
  43. package/dist/src/packlets/devtools/spaces.js.map +1 -1
  44. package/dist/src/packlets/identity/devices-service-impl.d.ts +10 -0
  45. package/dist/src/packlets/identity/devices-service-impl.d.ts.map +1 -0
  46. package/dist/src/packlets/identity/devices-service-impl.js +47 -0
  47. package/dist/src/packlets/identity/devices-service-impl.js.map +1 -0
  48. package/dist/src/packlets/identity/identity-manager.test.js +7 -11
  49. package/dist/src/packlets/identity/identity-manager.test.js.map +1 -1
  50. package/dist/src/packlets/identity/identity.d.ts +2 -0
  51. package/dist/src/packlets/identity/identity.d.ts.map +1 -1
  52. package/dist/src/packlets/identity/identity.js +4 -1
  53. package/dist/src/packlets/identity/identity.js.map +1 -1
  54. package/dist/src/packlets/identity/identity.test.js +2 -3
  55. package/dist/src/packlets/identity/identity.test.js.map +1 -1
  56. package/dist/src/packlets/invitations/encoder.d.ts +9 -0
  57. package/dist/src/packlets/invitations/encoder.d.ts.map +1 -0
  58. package/dist/src/packlets/invitations/encoder.js +27 -0
  59. package/dist/src/packlets/invitations/encoder.js.map +1 -0
  60. package/dist/src/packlets/invitations/encoder.test.d.ts +2 -0
  61. package/dist/src/packlets/invitations/encoder.test.d.ts.map +1 -0
  62. package/dist/src/packlets/invitations/encoder.test.js +19 -0
  63. package/dist/src/packlets/invitations/encoder.test.js.map +1 -0
  64. package/dist/src/packlets/invitations/halo-invitations.d.ts +3 -3
  65. package/dist/src/packlets/invitations/halo-invitations.d.ts.map +1 -1
  66. package/dist/src/packlets/invitations/halo-invitations.js +14 -10
  67. package/dist/src/packlets/invitations/halo-invitations.js.map +1 -1
  68. package/dist/src/packlets/invitations/halo-invitations.test.d.ts +2 -0
  69. package/dist/src/packlets/invitations/halo-invitations.test.d.ts.map +1 -0
  70. package/dist/src/packlets/{services/testing/halo.test.js → invitations/halo-invitations.test.js} +6 -6
  71. package/dist/src/packlets/invitations/halo-invitations.test.js.map +1 -0
  72. package/dist/src/packlets/invitations/index.d.ts +6 -3
  73. package/dist/src/packlets/invitations/index.d.ts.map +1 -1
  74. package/dist/src/packlets/invitations/index.js +6 -3
  75. package/dist/src/packlets/invitations/index.js.map +1 -1
  76. package/dist/src/packlets/invitations/invitations-proxy.d.ts +14 -0
  77. package/dist/src/packlets/invitations/invitations-proxy.d.ts.map +1 -0
  78. package/dist/src/packlets/invitations/invitations-proxy.js +126 -0
  79. package/dist/src/packlets/invitations/invitations-proxy.js.map +1 -0
  80. package/dist/src/packlets/invitations/invitations.d.ts +90 -0
  81. package/dist/src/packlets/invitations/invitations.d.ts.map +1 -0
  82. package/dist/src/packlets/invitations/invitations.js +55 -0
  83. package/dist/src/packlets/invitations/invitations.js.map +1 -0
  84. package/dist/src/packlets/invitations/space-invitations-handler.d.ts +24 -0
  85. package/dist/src/packlets/invitations/space-invitations-handler.d.ts.map +1 -0
  86. package/dist/src/packlets/invitations/space-invitations-handler.js +232 -0
  87. package/dist/src/packlets/invitations/space-invitations-handler.js.map +1 -0
  88. package/dist/src/packlets/invitations/space-invitations-handler.test.d.ts +2 -0
  89. package/dist/src/packlets/invitations/space-invitations-handler.test.d.ts.map +1 -0
  90. package/dist/src/packlets/invitations/space-invitations-handler.test.js +131 -0
  91. package/dist/src/packlets/invitations/space-invitations-handler.test.js.map +1 -0
  92. package/dist/src/packlets/invitations/space-invitations-proxy.d.ts +11 -0
  93. package/dist/src/packlets/invitations/space-invitations-proxy.d.ts.map +1 -0
  94. package/dist/src/packlets/invitations/space-invitations-proxy.js +17 -0
  95. package/dist/src/packlets/invitations/space-invitations-proxy.js.map +1 -0
  96. package/dist/src/packlets/invitations/space-invitations-service.d.ts +22 -0
  97. package/dist/src/packlets/invitations/space-invitations-service.d.ts.map +1 -0
  98. package/dist/src/packlets/invitations/space-invitations-service.js +189 -0
  99. package/dist/src/packlets/invitations/space-invitations-service.js.map +1 -0
  100. package/dist/src/packlets/invitations/space-invitations-service.test.d.ts +2 -0
  101. package/dist/src/packlets/invitations/space-invitations-service.test.d.ts.map +1 -0
  102. package/dist/src/packlets/invitations/space-invitations-service.test.js +100 -0
  103. package/dist/src/packlets/invitations/space-invitations-service.test.js.map +1 -0
  104. package/dist/src/packlets/services/iframe-service-proxy.d.ts +23 -0
  105. package/dist/src/packlets/services/iframe-service-proxy.d.ts.map +1 -0
  106. package/dist/src/packlets/services/iframe-service-proxy.js +53 -0
  107. package/dist/src/packlets/services/iframe-service-proxy.js.map +1 -0
  108. package/dist/src/packlets/services/index.d.ts +3 -2
  109. package/dist/src/packlets/services/index.d.ts.map +1 -1
  110. package/dist/src/packlets/services/index.js +3 -2
  111. package/dist/src/packlets/services/index.js.map +1 -1
  112. package/dist/src/packlets/services/service-context.d.ts +4 -7
  113. package/dist/src/packlets/services/service-context.d.ts.map +1 -1
  114. package/dist/src/packlets/services/service-context.js +9 -25
  115. package/dist/src/packlets/services/service-context.js.map +1 -1
  116. package/dist/src/packlets/services/service-definitions.d.ts +30 -0
  117. package/dist/src/packlets/services/service-definitions.d.ts.map +1 -0
  118. package/dist/src/packlets/services/{services.js → service-definitions.js} +9 -5
  119. package/dist/src/packlets/services/service-definitions.js.map +1 -0
  120. package/dist/src/packlets/services/service-host.d.ts +9 -12
  121. package/dist/src/packlets/services/service-host.d.ts.map +1 -1
  122. package/dist/src/packlets/services/service-host.js +55 -54
  123. package/dist/src/packlets/services/service-host.js.map +1 -1
  124. package/dist/src/packlets/services/service-host.test.js +7 -17
  125. package/dist/src/packlets/services/service-host.test.js.map +1 -1
  126. package/dist/src/packlets/services/service-proxy.d.ts +17 -0
  127. package/dist/src/packlets/services/service-proxy.d.ts.map +1 -0
  128. package/dist/src/packlets/services/service-proxy.js +48 -0
  129. package/dist/src/packlets/services/service-proxy.js.map +1 -0
  130. package/dist/src/packlets/services/service-registry.d.ts +12 -0
  131. package/dist/src/packlets/services/service-registry.d.ts.map +1 -0
  132. package/dist/src/packlets/services/service-registry.js +24 -0
  133. package/dist/src/packlets/services/service-registry.js.map +1 -0
  134. package/dist/src/packlets/services/service-registry.test.d.ts +2 -0
  135. package/dist/src/packlets/services/service-registry.test.d.ts.map +1 -0
  136. package/dist/src/packlets/services/service-registry.test.js +75 -0
  137. package/dist/src/packlets/services/service-registry.test.js.map +1 -0
  138. package/dist/src/packlets/services/signer.d.ts +0 -3
  139. package/dist/src/packlets/services/signer.d.ts.map +1 -1
  140. package/dist/src/packlets/spaces/index.d.ts +2 -0
  141. package/dist/src/packlets/spaces/index.d.ts.map +1 -0
  142. package/dist/src/packlets/spaces/index.js +21 -0
  143. package/dist/src/packlets/spaces/index.js.map +1 -0
  144. package/dist/src/packlets/spaces/spaces-service.d.ts +11 -0
  145. package/dist/src/packlets/spaces/spaces-service.d.ts.map +1 -0
  146. package/dist/src/packlets/spaces/spaces-service.js +22 -0
  147. package/dist/src/packlets/spaces/spaces-service.js.map +1 -0
  148. package/dist/src/packlets/storage/storage.js +1 -1
  149. package/dist/src/packlets/storage/storage.js.map +1 -1
  150. package/dist/src/packlets/testing/index.d.ts +2 -0
  151. package/dist/src/packlets/testing/index.d.ts.map +1 -0
  152. package/dist/src/packlets/testing/index.js +21 -0
  153. package/dist/src/packlets/testing/index.js.map +1 -0
  154. package/dist/src/packlets/testing/test-builder.d.ts +14 -0
  155. package/dist/src/packlets/testing/test-builder.d.ts.map +1 -0
  156. package/dist/src/packlets/testing/test-builder.js +66 -0
  157. package/dist/src/packlets/testing/test-builder.js.map +1 -0
  158. package/dist/src/packlets/vault/iframe-runtime.d.ts +19 -0
  159. package/dist/src/packlets/vault/iframe-runtime.d.ts.map +1 -0
  160. package/dist/src/packlets/vault/iframe-runtime.js +54 -0
  161. package/dist/src/packlets/vault/iframe-runtime.js.map +1 -0
  162. package/dist/src/packlets/vault/index.d.ts +4 -0
  163. package/dist/src/packlets/vault/index.d.ts.map +1 -0
  164. package/dist/src/packlets/vault/index.js +23 -0
  165. package/dist/src/packlets/vault/index.js.map +1 -0
  166. package/dist/src/packlets/vault/services.d.ts +13 -0
  167. package/dist/src/packlets/vault/services.d.ts.map +1 -0
  168. package/dist/src/packlets/vault/services.js +15 -0
  169. package/dist/src/packlets/vault/services.js.map +1 -0
  170. package/dist/src/packlets/vault/worker-runtime.d.ts +32 -0
  171. package/dist/src/packlets/vault/worker-runtime.d.ts.map +1 -0
  172. package/dist/src/packlets/vault/worker-runtime.js +94 -0
  173. package/dist/src/packlets/vault/worker-runtime.js.map +1 -0
  174. package/dist/src/packlets/vault/worker-session.d.ts +29 -0
  175. package/dist/src/packlets/vault/worker-session.d.ts.map +1 -0
  176. package/dist/src/packlets/vault/worker-session.js +84 -0
  177. package/dist/src/packlets/vault/worker-session.js.map +1 -0
  178. package/package.json +26 -26
  179. package/src/index.ts +4 -2
  180. package/src/packlets/{services/impl → deprecated}/index.ts +1 -4
  181. package/src/packlets/{invitations/common.ts → deprecated/invitations.ts} +18 -3
  182. package/src/packlets/{services/impl → deprecated}/profile.ts +13 -13
  183. package/src/packlets/deprecated/space.ts +245 -0
  184. package/src/packlets/{services/impl → deprecated}/system.ts +2 -2
  185. package/src/packlets/{services/impl → deprecated}/tracing.ts +2 -2
  186. package/src/packlets/{services/impl → devtools}/devtools.ts +33 -34
  187. package/src/packlets/devtools/feeds.ts +31 -27
  188. package/src/packlets/devtools/index.ts +1 -1
  189. package/src/packlets/devtools/spaces.ts +19 -18
  190. package/src/packlets/identity/devices-service-impl.ts +54 -0
  191. package/src/packlets/identity/identity-manager.test.ts +7 -8
  192. package/src/packlets/identity/identity.test.ts +2 -3
  193. package/src/packlets/identity/identity.ts +5 -1
  194. package/src/packlets/invitations/encoder.test.ts +22 -0
  195. package/src/packlets/invitations/encoder.ts +26 -0
  196. package/src/packlets/{services/testing/halo.test.ts → invitations/halo-invitations.test.ts} +5 -5
  197. package/src/packlets/invitations/halo-invitations.ts +12 -10
  198. package/src/packlets/invitations/index.ts +6 -3
  199. package/src/packlets/invitations/invitations-proxy.ts +157 -0
  200. package/src/packlets/invitations/invitations.ts +149 -0
  201. package/src/packlets/invitations/space-invitations-handler.test.ts +154 -0
  202. package/src/packlets/invitations/space-invitations-handler.ts +266 -0
  203. package/src/packlets/invitations/space-invitations-proxy.ts +16 -0
  204. package/src/packlets/invitations/space-invitations-service.test.ts +129 -0
  205. package/src/packlets/invitations/space-invitations-service.ts +196 -0
  206. package/src/packlets/services/iframe-service-proxy.ts +71 -0
  207. package/src/packlets/services/index.ts +3 -2
  208. package/src/packlets/services/service-context.ts +9 -31
  209. package/src/packlets/services/service-definitions.ts +54 -0
  210. package/src/packlets/services/service-host.test.ts +12 -24
  211. package/src/packlets/services/service-host.ts +64 -64
  212. package/src/packlets/services/service-proxy.ts +54 -0
  213. package/src/packlets/services/service-registry.test.ts +95 -0
  214. package/src/packlets/services/service-registry.ts +24 -0
  215. package/src/packlets/services/signer.ts +1 -3
  216. package/src/packlets/spaces/index.ts +5 -0
  217. package/src/packlets/spaces/spaces-service.ts +28 -0
  218. package/src/packlets/storage/storage.ts +1 -1
  219. package/src/packlets/testing/index.ts +5 -0
  220. package/src/packlets/testing/test-builder.ts +80 -0
  221. package/src/packlets/vault/iframe-runtime.ts +68 -0
  222. package/src/packlets/vault/index.ts +7 -0
  223. package/src/packlets/vault/services.ts +26 -0
  224. package/src/packlets/vault/worker-runtime.ts +111 -0
  225. package/src/packlets/vault/worker-session.ts +113 -0
  226. package/dist/src/packlets/devtools/devtools-host-events.d.ts +0 -5
  227. package/dist/src/packlets/devtools/devtools-host-events.d.ts.map +0 -1
  228. package/dist/src/packlets/devtools/devtools-host-events.js +0 -14
  229. package/dist/src/packlets/devtools/devtools-host-events.js.map +0 -1
  230. package/dist/src/packlets/invitations/common.d.ts.map +0 -1
  231. package/dist/src/packlets/invitations/common.js.map +0 -1
  232. package/dist/src/packlets/invitations/invitation-wrapper.d.ts +0 -36
  233. package/dist/src/packlets/invitations/invitation-wrapper.d.ts.map +0 -1
  234. package/dist/src/packlets/invitations/invitation-wrapper.js +0 -104
  235. package/dist/src/packlets/invitations/invitation-wrapper.js.map +0 -1
  236. package/dist/src/packlets/invitations/space-invitations.d.ts +0 -25
  237. package/dist/src/packlets/invitations/space-invitations.d.ts.map +0 -1
  238. package/dist/src/packlets/invitations/space-invitations.js +0 -136
  239. package/dist/src/packlets/invitations/space-invitations.js.map +0 -1
  240. package/dist/src/packlets/services/impl/devtools.d.ts.map +0 -1
  241. package/dist/src/packlets/services/impl/devtools.js +0 -77
  242. package/dist/src/packlets/services/impl/devtools.js.map +0 -1
  243. package/dist/src/packlets/services/impl/halo.d.ts +0 -20
  244. package/dist/src/packlets/services/impl/halo.d.ts.map +0 -1
  245. package/dist/src/packlets/services/impl/halo.js +0 -93
  246. package/dist/src/packlets/services/impl/halo.js.map +0 -1
  247. package/dist/src/packlets/services/impl/index.d.ts +0 -6
  248. package/dist/src/packlets/services/impl/index.d.ts.map +0 -1
  249. package/dist/src/packlets/services/impl/index.js.map +0 -1
  250. package/dist/src/packlets/services/impl/party.d.ts +0 -25
  251. package/dist/src/packlets/services/impl/party.d.ts.map +0 -1
  252. package/dist/src/packlets/services/impl/party.js +0 -265
  253. package/dist/src/packlets/services/impl/party.js.map +0 -1
  254. package/dist/src/packlets/services/impl/profile.d.ts.map +0 -1
  255. package/dist/src/packlets/services/impl/profile.js.map +0 -1
  256. package/dist/src/packlets/services/impl/system.d.ts.map +0 -1
  257. package/dist/src/packlets/services/impl/system.js.map +0 -1
  258. package/dist/src/packlets/services/impl/tracing.d.ts +0 -12
  259. package/dist/src/packlets/services/impl/tracing.d.ts.map +0 -1
  260. package/dist/src/packlets/services/impl/tracing.js.map +0 -1
  261. package/dist/src/packlets/services/service-factory.d.ts +0 -15
  262. package/dist/src/packlets/services/service-factory.d.ts.map +0 -1
  263. package/dist/src/packlets/services/service-factory.js +0 -25
  264. package/dist/src/packlets/services/service-factory.js.map +0 -1
  265. package/dist/src/packlets/services/services.d.ts +0 -19
  266. package/dist/src/packlets/services/services.d.ts.map +0 -1
  267. package/dist/src/packlets/services/services.js.map +0 -1
  268. package/dist/src/packlets/services/testing/halo.test.d.ts +0 -2
  269. package/dist/src/packlets/services/testing/halo.test.d.ts.map +0 -1
  270. package/dist/src/packlets/services/testing/halo.test.js.map +0 -1
  271. package/dist/src/packlets/services/testing/spaces.test.d.ts +0 -2
  272. package/dist/src/packlets/services/testing/spaces.test.d.ts.map +0 -1
  273. package/dist/src/packlets/services/testing/spaces.test.js +0 -68
  274. package/dist/src/packlets/services/testing/spaces.test.js.map +0 -1
  275. package/dist/src/packlets/services/testing/testing.d.ts +0 -8
  276. package/dist/src/packlets/services/testing/testing.d.ts.map +0 -1
  277. package/dist/src/packlets/services/testing/testing.js +0 -23
  278. package/dist/src/packlets/services/testing/testing.js.map +0 -1
  279. package/src/packlets/devtools/devtools-host-events.ts +0 -8
  280. package/src/packlets/invitations/invitation-wrapper.ts +0 -140
  281. package/src/packlets/invitations/space-invitations.ts +0 -159
  282. package/src/packlets/services/impl/halo.ts +0 -107
  283. package/src/packlets/services/impl/party.ts +0 -305
  284. package/src/packlets/services/service-factory.ts +0 -35
  285. package/src/packlets/services/services.ts +0 -39
  286. package/src/packlets/services/testing/spaces.test.ts +0 -87
  287. package/src/packlets/services/testing/testing.ts +0 -28
@@ -2,100 +2,100 @@
2
2
  // Copyright 2021 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
6
-
7
5
  import { Config } from '@dxos/config';
6
+ import { raise } from '@dxos/debug';
7
+ import { DataServiceImpl } from '@dxos/echo-db';
8
8
  import { log } from '@dxos/log';
9
- import { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager } from '@dxos/messaging';
10
9
  import { ModelFactory } from '@dxos/model-factory';
11
- import { createWebRTCTransportFactory, MemoryTransportFactory, NetworkManager } from '@dxos/network-manager';
10
+ import { NetworkManager } from '@dxos/network-manager';
12
11
  import { ObjectModel } from '@dxos/object-model';
12
+ import { TextModel } from '@dxos/text-model';
13
13
 
14
+ import { SpaceServiceImpl, ProfileServiceImpl, SystemServiceImpl, TracingServiceImpl } from '../deprecated';
15
+ import { DevtoolsServiceImpl, DevtoolsHostEvents } from '../devtools';
16
+ import { DevicesServiceImpl } from '../identity/devices-service-impl';
17
+ import { SpaceInvitationsServiceImpl } from '../invitations';
18
+ import { SpacesServiceImpl } from '../spaces';
14
19
  import { createStorageObjects } from '../storage';
15
20
  import { ServiceContext } from './service-context';
16
- import { createServices } from './service-factory';
17
- import { ClientServiceProvider, ClientServices } from './services';
18
- import { HaloSigner } from './signer';
19
- // import { DevtoolsHostEvents } from '../devtools';
20
-
21
- // TODO(burdon): Remove (no memory defaults).
22
- const memorySignalManagerContext = new MemorySignalManagerContext();
23
-
24
- // TODO(burdon): Factor out.
25
- export const createNetworkManager = (config: Config): NetworkManager => {
26
- const signalServer = config.get('runtime.services.signal.server');
27
- // TODO(burdon): Remove.
28
- if (!signalServer) {
29
- log.warn('DEPRECATED: falling back to MemorySignalManager');
30
- return new NetworkManager({
31
- log: true,
32
- signalManager: new MemorySignalManager(memorySignalManagerContext),
33
- transportFactory: MemoryTransportFactory
34
- });
35
- }
36
- assert(signalServer);
37
-
38
- return new NetworkManager({
39
- log: true,
40
- signalManager: new WebsocketSignalManager([signalServer]),
41
- transportFactory: createWebRTCTransportFactory({
42
- iceServers: config.get('runtime.services.ice')
43
- })
44
- });
45
- };
21
+ import { ClientServicesProvider, ClientServices, clientServiceBundle } from './service-definitions';
22
+ import { ServiceRegistry } from './service-registry';
46
23
 
47
- type ClientServiceHostParams = {
24
+ type ClientServicesHostParams = {
48
25
  config: Config;
49
- signer?: HaloSigner;
50
26
  modelFactory?: ModelFactory;
51
27
  networkManager: NetworkManager;
52
28
  };
53
29
 
30
+ // TODO(burdon): Factor out to spaces.
31
+ // TODO(burdon): Defaults (with TextModel).
32
+ export const createDefaultModelFactory = () => {
33
+ return new ModelFactory().registerModel(ObjectModel).registerModel(TextModel);
34
+ };
35
+
54
36
  /**
55
37
  * Remote service implementation.
56
38
  */
57
- export class ClientServiceHost implements ClientServiceProvider {
58
- private readonly _config: Config;
59
- private readonly _signer?: HaloSigner;
60
- private readonly _context: ServiceContext;
61
- private readonly _services: ClientServices;
39
+ // TODO(burdon): Reconcile Host/Backend, etc.
40
+ export class ClientServicesHost implements ClientServicesProvider {
41
+ private readonly _serviceContext: ServiceContext;
42
+ private readonly _serviceRegistry: ServiceRegistry<ClientServices>;
62
43
 
63
44
  constructor({
64
45
  config,
65
- modelFactory = new ModelFactory().registerModel(ObjectModel),
66
- signer,
46
+ modelFactory = createDefaultModelFactory(),
47
+ // TODO(burdon): Create ApolloLink abstraction (see Client).
67
48
  networkManager
68
- }: ClientServiceHostParams) {
69
- this._config = config;
70
- this._signer = signer;
71
-
49
+ }: ClientServicesHostParams) {
72
50
  // TODO(dmaretskyi): Remove keyStorage.
73
- const { storage } = createStorageObjects(this._config.get('runtime.client.storage', {})!);
74
- this._context = new ServiceContext(storage, networkManager, modelFactory);
51
+ const { storage } = createStorageObjects(config.get('runtime.client.storage', {})!);
52
+
53
+ // TODO(burdon): Break into components.
54
+ this._serviceContext = new ServiceContext(storage, networkManager, modelFactory);
55
+
56
+ // TODO(burdon): Start to think of DMG (dynamic services).
57
+ this._serviceRegistry = new ServiceRegistry<ClientServices>(clientServiceBundle, {
58
+ SpacesService: new SpacesServiceImpl(),
59
+ SpaceInvitationsService: new SpaceInvitationsServiceImpl(
60
+ this._serviceContext.identityManager,
61
+ () => this._serviceContext.spaceManager ?? raise(new Error('SpaceManager not initialized')),
62
+ () => this._serviceContext.spaceInvitations ?? raise(new Error('SpaceInvitations not initialized'))
63
+ ),
75
64
 
76
- this._services = createServices({
77
- config: this._config,
78
- context: this._context,
79
- signer: this._signer,
80
- networkManager
65
+ SpaceService: new SpaceServiceImpl(this._serviceContext),
66
+ DataService: new DataServiceImpl(this._serviceContext.dataServiceSubscriptions),
67
+
68
+ ProfileService: new ProfileServiceImpl(this._serviceContext),
69
+ SystemService: new SystemServiceImpl(config),
70
+ TracingService: new TracingServiceImpl(config),
71
+ DevtoolsHost: new DevtoolsServiceImpl({
72
+ events: new DevtoolsHostEvents(),
73
+ config,
74
+ context: this._serviceContext
75
+ }),
76
+ DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager)
81
77
  });
82
78
  }
83
79
 
80
+ get descriptors() {
81
+ return this._serviceRegistry.descriptors;
82
+ }
83
+
84
84
  get services() {
85
- return this._services;
85
+ return this._serviceRegistry.services;
86
86
  }
87
87
 
88
- // TODO(dmaretskyi): progress.
89
- async open(onProgressCallback?: ((progress: any) => void) | undefined) {
90
- log('opening...');
91
- await this._context.open();
92
- // this._devtoolsEvents.ready.emit();
93
- log('opened');
88
+ async open() {
89
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
90
+ log('opening...', { deviceKey });
91
+ await this._serviceContext.open();
92
+ log('opened', { deviceKey });
94
93
  }
95
94
 
96
95
  async close() {
97
- log('closing...');
98
- await this._context.close();
99
- log('closed');
96
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
97
+ log('closing...', { deviceKey });
98
+ await this._serviceContext.close();
99
+ log('closed', { deviceKey });
100
100
  }
101
101
  }
@@ -0,0 +1,54 @@
1
+ //
2
+ // Copyright 2021 DXOS.org
3
+ //
4
+
5
+ import { asyncTimeout } from '@dxos/async';
6
+ import { createProtoRpcPeer, ProtoRpcPeer, RpcPort } from '@dxos/rpc';
7
+
8
+ import { RemoteServiceConnectionTimeout } from '../../errors';
9
+ import { ClientServicesProvider, ClientServices, clientServiceBundle } from './service-definitions';
10
+
11
+ /**
12
+ * Implements services that are not local to the app.
13
+ * For example, the services can be located in Wallet Extension.
14
+ */
15
+ // TODO(burdon): Separate construction of port from availability of services.
16
+ // TODO(burdon): Create `@dxos/client-proxy` package with thin-client only dependencies (for code-splitting).
17
+ export class ClientServicesProxy implements ClientServicesProvider {
18
+ private readonly _proxy: ProtoRpcPeer<ClientServices>;
19
+
20
+ // prettier-ignore
21
+ constructor(
22
+ port: RpcPort,
23
+ // NOTE: With lower timeout the shared worker does not have enough time to start.
24
+ // TODO(dmaretskyi): Find better ways to detected when the worker has finished loading. It might take a while on slow connections.
25
+ private readonly _timeout = 1000
26
+ ) {
27
+ this._proxy = createProtoRpcPeer({
28
+ requested: clientServiceBundle,
29
+ exposed: {},
30
+ handlers: {},
31
+ port
32
+ });
33
+ }
34
+
35
+ get proxy() {
36
+ return this._proxy;
37
+ }
38
+
39
+ get descriptors() {
40
+ return clientServiceBundle;
41
+ }
42
+
43
+ get services() {
44
+ return this._proxy.rpc;
45
+ }
46
+
47
+ async open() {
48
+ await asyncTimeout(this._proxy.open(), this._timeout, new RemoteServiceConnectionTimeout());
49
+ }
50
+
51
+ async close() {
52
+ await this._proxy.close();
53
+ }
54
+ }
@@ -0,0 +1,95 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ import assert from 'assert';
6
+
7
+ import { Trigger } from '@dxos/async';
8
+ import { log } from '@dxos/log';
9
+ import { schema } from '@dxos/protocols';
10
+ import { Invitation, InvitationsService } from '@dxos/protocols/proto/dxos/client/services';
11
+ import { createLinkedPorts, createProtoRpcPeer, createServiceBundle } from '@dxos/rpc';
12
+
13
+ import { SpaceInvitationsProxy, SpaceInvitationsServiceImpl } from '../invitations';
14
+ import { createServiceContext } from '../testing';
15
+ import { ServiceRegistry } from './service-registry';
16
+
17
+ // TODO(burdon): Create TestService (that doesn't require peers).
18
+
19
+ type TestServices = {
20
+ SpaceInvitationsService: InvitationsService;
21
+ };
22
+
23
+ const serviceBundle = createServiceBundle<TestServices>({
24
+ SpaceInvitationsService: schema.getService('dxos.client.services.InvitationsService')
25
+ });
26
+
27
+ describe('service registry', function () {
28
+ it('builds a service registry', async function () {
29
+ const serviceContext = createServiceContext();
30
+ await serviceContext.open();
31
+ await serviceContext.createIdentity();
32
+
33
+ assert(serviceContext.spaceManager);
34
+ assert(serviceContext.spaceInvitations);
35
+ const space = await serviceContext.spaceManager.createSpace();
36
+
37
+ const serviceRegistry = new ServiceRegistry(serviceBundle, {
38
+ SpaceInvitationsService: new SpaceInvitationsServiceImpl(
39
+ serviceContext.identityManager,
40
+ () => serviceContext.spaceManager!,
41
+ () => serviceContext.spaceInvitations!
42
+ )
43
+ });
44
+
45
+ const [proxyPort, serverPort] = createLinkedPorts();
46
+
47
+ const proxy = createProtoRpcPeer({
48
+ requested: serviceRegistry.descriptors,
49
+ exposed: {},
50
+ handlers: {},
51
+ port: proxyPort
52
+ });
53
+
54
+ const server = createProtoRpcPeer({
55
+ exposed: serviceRegistry.descriptors,
56
+ handlers: serviceRegistry.services,
57
+ port: serverPort
58
+ });
59
+
60
+ log('opening...');
61
+ await Promise.all([proxy.open(), server.open()]);
62
+ log('open');
63
+
64
+ const done = new Trigger(); // createRpcServer
65
+
66
+ {
67
+ const spaceInvitationsProxy = new SpaceInvitationsProxy(proxy.rpc.SpaceInvitationsService);
68
+ const observer = spaceInvitationsProxy.createInvitation(space.key);
69
+ observer.subscribe({
70
+ onConnecting: (invitation: Invitation) => {
71
+ log('connecting', invitation);
72
+ void observer.cancel();
73
+ },
74
+ onCancelled: () => {
75
+ done.wake();
76
+ },
77
+ onSuccess: (_invitation: Invitation) => {
78
+ throw new Error('Not not implemented.');
79
+ },
80
+ onError: () => {
81
+ throw new Error('Not not implemented.');
82
+ }
83
+ });
84
+ }
85
+
86
+ await done.wait();
87
+
88
+ // TODO(burdon): Error handling (create tests).
89
+ // Uncaught Error: Request was terminated because the RPC endpoint is closed.
90
+ // log('closing...');
91
+ // await Promise.all([proxy.close(), server.close()]);
92
+ // await serviceContext.close();
93
+ // log('closed');
94
+ });
95
+ });
@@ -0,0 +1,24 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ import { ServiceBundle } from '@dxos/rpc';
6
+
7
+ /**
8
+ * Registry of operational services.
9
+ */
10
+ export class ServiceRegistry<Services> {
11
+ // prettier-ignore
12
+ constructor (
13
+ private readonly _serviceBundle: ServiceBundle<Services>,
14
+ private readonly _handlers: Services
15
+ ) {}
16
+
17
+ get descriptors() {
18
+ return this._serviceBundle;
19
+ }
20
+
21
+ get services() {
22
+ return this._handlers;
23
+ }
24
+ }
@@ -5,9 +5,7 @@
5
5
  import { SignRequest, SignResponse } from '@dxos/protocols/proto/dxos/client';
6
6
  import { KeyRecord } from '@dxos/protocols/proto/dxos/halo/keys';
7
7
 
8
- /**
9
- *
10
- */
8
+ // TODO(burdon): Remove (was required for registry client).
11
9
  export interface HaloSigner {
12
10
  sign: (request: SignRequest, key: KeyRecord) => Promise<SignResponse>;
13
11
  }
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ export * from './spaces-service';
@@ -0,0 +1,28 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ import { Stream } from '@dxos/codec-protobuf';
6
+ import {
7
+ QueryMembersRequest,
8
+ QueryMembersResponse,
9
+ Space,
10
+ SpacesService
11
+ } from '@dxos/protocols/proto/dxos/client/services';
12
+
13
+ /**
14
+ *
15
+ */
16
+ export class SpacesServiceImpl implements SpacesService {
17
+ async createSpace(): Promise<Space> {
18
+ throw new Error();
19
+ }
20
+
21
+ querySpaces(): Stream<Space> {
22
+ throw new Error();
23
+ }
24
+
25
+ queryMembers(query: QueryMembersRequest): Stream<QueryMembersResponse> {
26
+ throw new Error();
27
+ }
28
+ }
@@ -2,7 +2,7 @@
2
2
  // Copyright 2021 DXOS.org
3
3
  //
4
4
 
5
- import jsondown from 'jsondown';
5
+ import jsondown from 'jsondown'; // TODO(burdon): Uses custom implementation.
6
6
  import leveljs from 'level-js';
7
7
  import memdown from 'memdown';
8
8
 
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ export * from './test-builder';
@@ -0,0 +1,80 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ import { expect } from 'chai';
6
+
7
+ import { Config } from '@dxos/config';
8
+ import { ISpace } from '@dxos/echo-db';
9
+ import { MemorySignalManager, MemorySignalManagerContext } from '@dxos/messaging';
10
+ import { MemoryTransportFactory, NetworkManager } from '@dxos/network-manager';
11
+ import { createStorage, Storage, StorageType } from '@dxos/random-access-storage';
12
+
13
+ import { createDefaultModelFactory, ClientServicesHost, ServiceContext } from '../services';
14
+
15
+ //
16
+ // TODO(burdon): Replace with test builder.
17
+ //
18
+
19
+ export const createServiceHost = (config: Config, signalManagerContext: MemorySignalManagerContext) => {
20
+ const networkManager = new NetworkManager({
21
+ signalManager: new MemorySignalManager(signalManagerContext),
22
+ transportFactory: MemoryTransportFactory
23
+ });
24
+
25
+ return new ClientServicesHost({
26
+ config,
27
+ networkManager
28
+ });
29
+ };
30
+
31
+ export const createServiceContext = ({
32
+ signalContext = new MemorySignalManagerContext(),
33
+ storage = createStorage({ type: StorageType.RAM })
34
+ }: {
35
+ signalContext?: MemorySignalManagerContext;
36
+ storage?: Storage;
37
+ } = {}) => {
38
+ const networkManager = new NetworkManager({
39
+ signalManager: new MemorySignalManager(signalContext),
40
+ transportFactory: MemoryTransportFactory
41
+ });
42
+
43
+ const modelFactory = createDefaultModelFactory();
44
+ return new ServiceContext(storage, networkManager, modelFactory);
45
+ };
46
+
47
+ export const createPeers = async (numPeers: number) => {
48
+ const signalContext = new MemorySignalManagerContext();
49
+
50
+ return await Promise.all(
51
+ Array.from(Array(numPeers)).map(async () => {
52
+ const peer = createServiceContext({ signalContext });
53
+ await peer.open();
54
+ return peer;
55
+ })
56
+ );
57
+ };
58
+
59
+ export const createIdentity = async (peer: ServiceContext) => {
60
+ await peer.createIdentity();
61
+ return peer;
62
+ };
63
+
64
+ // TODO(wittjosiah): Factor out to client-testing?
65
+ // TODO(burdon): Create builder and make configurable.
66
+ export const syncItems = async (space1: ISpace, space2: ISpace) => {
67
+ {
68
+ // Check item replicated from 1 => 2.
69
+ const item1 = await space1.database!.createItem({ type: 'type-1' });
70
+ const item2 = await space2.database!.waitForItem({ type: 'type-1' });
71
+ expect(item1.id).to.eq(item2.id);
72
+ }
73
+
74
+ {
75
+ // Check item replicated from 2 => 1.
76
+ const item1 = await space2.database!.createItem({ type: 'type-2' });
77
+ const item2 = await space1.database!.waitForItem({ type: 'type-2' });
78
+ expect(item1.id).to.eq(item2.id);
79
+ }
80
+ };
@@ -0,0 +1,68 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ import { WebRTCTransportService } from '@dxos/network-manager';
6
+ import { BridgeService } from '@dxos/protocols/proto/dxos/mesh/bridge';
7
+ import { createProtoRpcPeer, ProtoRpcPeer, RpcPort } from '@dxos/rpc';
8
+ import { PortMuxer } from '@dxos/rpc-tunnel';
9
+
10
+ import { iframeServiceBundle, WorkerServiceBundle, workerServiceBundle } from './services';
11
+
12
+ export type IframeRuntimeParams = {
13
+ portMuxer: PortMuxer;
14
+ };
15
+
16
+ /**
17
+ * Manages the client connection to the shared worker.
18
+ */
19
+ export class IFrameRuntime {
20
+ private readonly _systemPort: RpcPort;
21
+ private readonly _windowAppPort: RpcPort;
22
+ private readonly _workerAppPort: RpcPort;
23
+ private readonly _systemRpc: ProtoRpcPeer<WorkerServiceBundle>;
24
+ private readonly _transportService = new WebRTCTransportService();
25
+
26
+ constructor({ portMuxer }: IframeRuntimeParams) {
27
+ this._systemPort = portMuxer.createWorkerPort({ channel: 'dxos:system' });
28
+ this._workerAppPort = portMuxer.createWorkerPort({ channel: 'dxos:app' });
29
+ this._windowAppPort = portMuxer.createIFramePort({
30
+ channel: 'dxos:app',
31
+ onOrigin: (origin) => this.open(origin)
32
+ });
33
+
34
+ this._systemRpc = createProtoRpcPeer({
35
+ requested: workerServiceBundle,
36
+ exposed: iframeServiceBundle,
37
+ handlers: {
38
+ BridgeService: this._transportService as BridgeService,
39
+ IframeService: {
40
+ async heartbeat() {
41
+ // Ok.
42
+ }
43
+ }
44
+ },
45
+ port: this._systemPort,
46
+ timeout: 200
47
+ });
48
+ }
49
+
50
+ start() {
51
+ this._workerAppPort.subscribe((msg) => this._windowAppPort.send(msg));
52
+ this._windowAppPort.subscribe((msg) => this._workerAppPort.send(msg));
53
+
54
+ window.addEventListener('beforeunload', () => {
55
+ this.close().catch((err) => console.error(err));
56
+ });
57
+ }
58
+
59
+ async open(origin: string) {
60
+ await this._systemRpc.open();
61
+ await this._systemRpc.rpc.WorkerService.start({ origin });
62
+ }
63
+
64
+ async close() {
65
+ await this._systemRpc.rpc.WorkerService.stop();
66
+ await this._systemRpc.close();
67
+ }
68
+ }
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ export * from './iframe-runtime';
6
+ export * from './worker-runtime';
7
+ export * from './worker-session';
@@ -0,0 +1,26 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ import { schema } from '@dxos/protocols';
6
+ import type { IframeService, WorkerService } from '@dxos/protocols/proto/dxos/iframe';
7
+ import type { BridgeService } from '@dxos/protocols/proto/dxos/mesh/bridge';
8
+ import { ServiceBundle } from '@dxos/rpc';
9
+
10
+ export type IframeServiceBundle = {
11
+ IframeService: IframeService;
12
+ BridgeService: BridgeService;
13
+ };
14
+
15
+ export const iframeServiceBundle: ServiceBundle<IframeServiceBundle> = {
16
+ IframeService: schema.getService('dxos.iframe.IframeService'),
17
+ BridgeService: schema.getService('dxos.mesh.bridge.BridgeService')
18
+ };
19
+
20
+ export type WorkerServiceBundle = {
21
+ WorkerService: WorkerService;
22
+ };
23
+
24
+ export const workerServiceBundle: ServiceBundle<WorkerServiceBundle> = {
25
+ WorkerService: schema.getService('dxos.iframe.WorkerService')
26
+ };