@dxos/client-services 0.8.4-main.406dc2a → 0.8.4-main.422d1c7879

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 (203) hide show
  1. package/dist/lib/browser/{chunk-TF7KXCT7.mjs → chunk-J7VTDH4K.mjs} +3459 -3082
  2. package/dist/lib/browser/chunk-J7VTDH4K.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-NQSC7HOE.mjs +22 -0
  4. package/dist/lib/browser/chunk-NQSC7HOE.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-QCWEHHJW.mjs +24 -0
  6. package/dist/lib/browser/chunk-QCWEHHJW.mjs.map +7 -0
  7. package/dist/lib/browser/index.mjs +584 -187
  8. package/dist/lib/browser/index.mjs.map +4 -4
  9. package/dist/lib/browser/meta.json +1 -1
  10. package/dist/lib/browser/packlets/diagnostics/browser-diagnostics-broadcast.mjs +93 -0
  11. package/dist/lib/browser/packlets/diagnostics/browser-diagnostics-broadcast.mjs.map +7 -0
  12. package/dist/lib/browser/packlets/diagnostics/diagnostics-broadcast.mjs +11 -0
  13. package/dist/lib/browser/packlets/diagnostics/diagnostics-broadcast.mjs.map +7 -0
  14. package/dist/lib/browser/packlets/locks/browser.mjs +126 -0
  15. package/dist/lib/browser/packlets/locks/browser.mjs.map +7 -0
  16. package/dist/lib/browser/packlets/locks/node.mjs +66 -0
  17. package/dist/lib/browser/packlets/locks/node.mjs.map +7 -0
  18. package/dist/lib/browser/testing/index.mjs +70 -80
  19. package/dist/lib/browser/testing/index.mjs.map +3 -3
  20. package/dist/lib/node-esm/chunk-2SZHAWBN.mjs +24 -0
  21. package/dist/lib/node-esm/chunk-2SZHAWBN.mjs.map +7 -0
  22. package/dist/lib/node-esm/{chunk-XJAHJBOC.mjs → chunk-2WCRQW4E.mjs} +3111 -2603
  23. package/dist/lib/node-esm/chunk-2WCRQW4E.mjs.map +7 -0
  24. package/dist/lib/node-esm/chunk-PKEGMOQ4.mjs +22 -0
  25. package/dist/lib/node-esm/chunk-PKEGMOQ4.mjs.map +7 -0
  26. package/dist/lib/node-esm/index.mjs +584 -187
  27. package/dist/lib/node-esm/index.mjs.map +4 -4
  28. package/dist/lib/node-esm/meta.json +1 -1
  29. package/dist/lib/node-esm/packlets/diagnostics/browser-diagnostics-broadcast.mjs +93 -0
  30. package/dist/lib/node-esm/packlets/diagnostics/browser-diagnostics-broadcast.mjs.map +7 -0
  31. package/dist/lib/node-esm/packlets/diagnostics/diagnostics-broadcast.mjs +11 -0
  32. package/dist/lib/node-esm/packlets/diagnostics/diagnostics-broadcast.mjs.map +7 -0
  33. package/dist/lib/node-esm/packlets/locks/browser.mjs +126 -0
  34. package/dist/lib/node-esm/packlets/locks/browser.mjs.map +7 -0
  35. package/dist/lib/node-esm/packlets/locks/node.mjs +66 -0
  36. package/dist/lib/node-esm/packlets/locks/node.mjs.map +7 -0
  37. package/dist/lib/node-esm/testing/index.mjs +70 -80
  38. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  39. package/dist/types/src/index.d.ts +1 -0
  40. package/dist/types/src/index.d.ts.map +1 -1
  41. package/dist/types/src/packlets/agents/edge-agent-manager.d.ts +3 -2
  42. package/dist/types/src/packlets/agents/edge-agent-manager.d.ts.map +1 -1
  43. package/dist/types/src/packlets/agents/edge-agent-service.d.ts +2 -1
  44. package/dist/types/src/packlets/agents/edge-agent-service.d.ts.map +1 -1
  45. package/dist/types/src/packlets/devtools/devtools.d.ts +2 -2
  46. package/dist/types/src/packlets/devtools/devtools.d.ts.map +1 -1
  47. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts +1 -2
  48. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -1
  49. package/dist/types/src/packlets/diagnostics/index.d.ts +1 -1
  50. package/dist/types/src/packlets/diagnostics/index.d.ts.map +1 -1
  51. package/dist/types/src/packlets/identity/authenticator.d.ts +2 -2
  52. package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
  53. package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -1
  54. package/dist/types/src/packlets/identity/identity-manager.d.ts +6 -6
  55. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  56. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts +7 -6
  57. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts.map +1 -1
  58. package/dist/types/src/packlets/identity/identity-service.d.ts +6 -10
  59. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  60. package/dist/types/src/packlets/identity/identity.d.ts +8 -11
  61. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  62. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +6 -5
  63. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  64. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts +1 -1
  65. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts.map +1 -1
  66. package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts.map +1 -1
  67. package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -1
  68. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +7 -4
  69. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  70. package/dist/types/src/packlets/invitations/invitation-state.d.ts.map +1 -1
  71. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +4 -4
  72. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  73. package/dist/types/src/packlets/invitations/invitations-manager.d.ts +3 -3
  74. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
  75. package/dist/types/src/packlets/invitations/invitations-service.d.ts +3 -3
  76. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  77. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +4 -3
  78. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  79. package/dist/types/src/packlets/locks/index.d.ts +1 -1
  80. package/dist/types/src/packlets/locks/index.d.ts.map +1 -1
  81. package/dist/types/src/packlets/logging/logging-service.d.ts +4 -0
  82. package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
  83. package/dist/types/src/packlets/network/network-service.d.ts +5 -4
  84. package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
  85. package/dist/types/src/packlets/services/client-rpc-server.d.ts +5 -5
  86. package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
  87. package/dist/types/src/packlets/services/feed-syncer.d.ts +59 -0
  88. package/dist/types/src/packlets/services/feed-syncer.d.ts.map +1 -0
  89. package/dist/types/src/packlets/services/feed-syncer.test.d.ts +2 -0
  90. package/dist/types/src/packlets/services/feed-syncer.test.d.ts.map +1 -0
  91. package/dist/types/src/packlets/services/platform.d.ts.map +1 -1
  92. package/dist/types/src/packlets/services/service-context.d.ts +13 -8
  93. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  94. package/dist/types/src/packlets/services/service-host.d.ts +20 -7
  95. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  96. package/dist/types/src/packlets/space-export/archive-format.d.ts +9 -0
  97. package/dist/types/src/packlets/space-export/archive-format.d.ts.map +1 -0
  98. package/dist/types/src/packlets/space-export/index.d.ts +4 -1
  99. package/dist/types/src/packlets/space-export/index.d.ts.map +1 -1
  100. package/dist/types/src/packlets/space-export/serialized-space-reader.d.ts +23 -0
  101. package/dist/types/src/packlets/space-export/serialized-space-reader.d.ts.map +1 -0
  102. package/dist/types/src/packlets/space-export/serialized-space-writer.d.ts +36 -0
  103. package/dist/types/src/packlets/space-export/serialized-space-writer.d.ts.map +1 -0
  104. package/dist/types/src/packlets/space-export/space-archive-reader.d.ts +9 -1
  105. package/dist/types/src/packlets/space-export/space-archive-reader.d.ts.map +1 -1
  106. package/dist/types/src/packlets/space-export/space-archive-writer.d.ts +7 -1
  107. package/dist/types/src/packlets/space-export/space-archive-writer.d.ts.map +1 -1
  108. package/dist/types/src/packlets/space-export/space-archive.test.d.ts +2 -0
  109. package/dist/types/src/packlets/space-export/space-archive.test.d.ts.map +1 -0
  110. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +28 -16
  111. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  112. package/dist/types/src/packlets/spaces/data-space.d.ts +26 -9
  113. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  114. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts +2 -2
  115. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -1
  116. package/dist/types/src/packlets/spaces/genesis.d.ts +2 -1
  117. package/dist/types/src/packlets/spaces/genesis.d.ts.map +1 -1
  118. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +6 -6
  119. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  120. package/dist/types/src/packlets/spaces/spaces-service.d.ts +17 -7
  121. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  122. package/dist/types/src/packlets/testing/invitation-utils.d.ts +6 -3
  123. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  124. package/dist/types/src/packlets/testing/test-builder.d.ts +6 -5
  125. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  126. package/dist/types/src/packlets/worker/worker-runtime.d.ts +41 -4
  127. package/dist/types/src/packlets/worker/worker-runtime.d.ts.map +1 -1
  128. package/dist/types/src/packlets/worker/worker-session.d.ts +2 -4
  129. package/dist/types/src/packlets/worker/worker-session.d.ts.map +1 -1
  130. package/dist/types/src/version.d.ts +1 -1
  131. package/dist/types/src/version.d.ts.map +1 -1
  132. package/dist/types/tsconfig.tsbuildinfo +1 -1
  133. package/package.json +70 -55
  134. package/src/index.ts +1 -0
  135. package/src/packlets/agents/edge-agent-manager.ts +8 -5
  136. package/src/packlets/agents/edge-agent-service.ts +4 -2
  137. package/src/packlets/devices/devices-service.test.ts +0 -1
  138. package/src/packlets/devtools/devtools.ts +2 -3
  139. package/src/packlets/diagnostics/diagnostics.ts +1 -2
  140. package/src/packlets/diagnostics/index.ts +1 -1
  141. package/src/packlets/identity/authenticator.ts +2 -2
  142. package/src/packlets/identity/contacts-service.ts +0 -1
  143. package/src/packlets/identity/identity-manager.test.ts +5 -5
  144. package/src/packlets/identity/identity-manager.ts +21 -18
  145. package/src/packlets/identity/identity-recovery-manager.ts +22 -18
  146. package/src/packlets/identity/identity-service.test.ts +6 -27
  147. package/src/packlets/identity/identity-service.ts +13 -81
  148. package/src/packlets/identity/identity.test.ts +2 -2
  149. package/src/packlets/identity/identity.ts +11 -34
  150. package/src/packlets/invitations/device-invitation-protocol.ts +8 -7
  151. package/src/packlets/invitations/edge-invitation-handler.ts +9 -5
  152. package/src/packlets/invitations/invitation-guest-extenstion.ts +6 -4
  153. package/src/packlets/invitations/invitation-host-extension.ts +6 -4
  154. package/src/packlets/invitations/invitation-protocol.ts +7 -4
  155. package/src/packlets/invitations/invitation-state.ts +0 -10
  156. package/src/packlets/invitations/invitations-handler.test.ts +4 -5
  157. package/src/packlets/invitations/invitations-handler.ts +69 -13
  158. package/src/packlets/invitations/invitations-manager.ts +40 -15
  159. package/src/packlets/invitations/invitations-service.ts +9 -9
  160. package/src/packlets/invitations/space-invitation-protocol.test.ts +17 -16
  161. package/src/packlets/invitations/space-invitation-protocol.ts +11 -16
  162. package/src/packlets/locks/index.ts +1 -1
  163. package/src/packlets/logging/logging-service.ts +20 -16
  164. package/src/packlets/network/network-service.test.ts +0 -1
  165. package/src/packlets/network/network-service.ts +10 -8
  166. package/src/packlets/services/client-rpc-server.ts +19 -16
  167. package/src/packlets/services/feed-syncer.test.ts +340 -0
  168. package/src/packlets/services/feed-syncer.ts +337 -0
  169. package/src/packlets/services/platform.ts +7 -1
  170. package/src/packlets/services/service-context.test.ts +3 -2
  171. package/src/packlets/services/service-context.ts +137 -51
  172. package/src/packlets/services/service-host.test.ts +8 -8
  173. package/src/packlets/services/service-host.ts +69 -31
  174. package/src/packlets/services/service-registry.test.ts +0 -1
  175. package/src/packlets/space-export/archive-format.ts +42 -0
  176. package/src/packlets/space-export/index.ts +4 -1
  177. package/src/packlets/space-export/serialized-space-reader.ts +111 -0
  178. package/src/packlets/space-export/serialized-space-writer.ts +253 -0
  179. package/src/packlets/space-export/space-archive-reader.ts +64 -3
  180. package/src/packlets/space-export/space-archive-writer.ts +41 -3
  181. package/src/packlets/space-export/space-archive.test.ts +461 -0
  182. package/src/packlets/spaces/data-space-manager.test.ts +79 -13
  183. package/src/packlets/spaces/data-space-manager.ts +114 -109
  184. package/src/packlets/spaces/data-space.ts +58 -33
  185. package/src/packlets/spaces/edge-feed-replicator.test.ts +1 -1
  186. package/src/packlets/spaces/edge-feed-replicator.ts +11 -9
  187. package/src/packlets/spaces/epoch-migrations.ts +5 -5
  188. package/src/packlets/spaces/genesis.ts +6 -1
  189. package/src/packlets/spaces/notarization-plugin.test.ts +2 -2
  190. package/src/packlets/spaces/notarization-plugin.ts +10 -9
  191. package/src/packlets/spaces/spaces-service.test.ts +18 -11
  192. package/src/packlets/spaces/spaces-service.ts +123 -24
  193. package/src/packlets/storage/storage.ts +4 -4
  194. package/src/packlets/testing/invitation-utils.ts +10 -6
  195. package/src/packlets/testing/test-builder.ts +36 -10
  196. package/src/packlets/worker/worker-runtime.ts +179 -17
  197. package/src/packlets/worker/worker-session.ts +12 -18
  198. package/src/version.ts +1 -1
  199. package/dist/lib/browser/chunk-TF7KXCT7.mjs.map +0 -7
  200. package/dist/lib/node-esm/chunk-XJAHJBOC.mjs.map +0 -7
  201. package/dist/types/src/packlets/identity/default-space-state-machine.d.ts +0 -19
  202. package/dist/types/src/packlets/identity/default-space-state-machine.d.ts.map +0 -1
  203. package/src/packlets/identity/default-space-state-machine.ts +0 -44
@@ -1,6 +1,5 @@
1
1
  import "@dxos/node-std/globals";
2
2
  import {
3
- ClientRpcServer,
4
3
  ClientServicesHost,
5
4
  DataSpace,
6
5
  DataSpaceManager,
@@ -17,155 +16,384 @@ import {
17
16
  InvitationsHandler,
18
17
  InvitationsManager,
19
18
  InvitationsServiceImpl,
20
- Lock,
21
19
  ServiceContext,
22
20
  ServiceRegistry,
21
+ SpaceArchiveWriter,
23
22
  SpaceInvitationProtocol,
24
23
  SpacesServiceImpl,
25
24
  TrustedKeySetAuthVerifier,
25
+ buildDatabaseDirectoryFromObjects,
26
26
  createAdmissionKeypair,
27
27
  createAuthProvider,
28
- createCollectDiagnosticsBroadcastHandler,
29
- createCollectDiagnosticsBroadcastSender,
30
28
  createDiagnostics,
31
29
  createLevel,
32
30
  createStorageObjects,
33
- decodeProfileArchive,
34
- encodeProfileArchive,
35
- exportProfileData,
31
+ detectSpaceArchiveFormat,
32
+ diagnostics_exports,
33
+ extractSpaceArchive,
36
34
  getNetworkPeers,
37
- importProfileData,
38
- isLocked,
35
+ locks_exports,
36
+ objJsonToObjectStructure,
37
+ objectStructureToObjJson,
38
+ orderObjJsonFields,
39
+ readSerializedSpaceArchive,
39
40
  subscribeToFeedBlocks,
40
41
  subscribeToFeeds,
41
42
  subscribeToNetworkStatus,
42
43
  subscribeToNetworkTopics,
43
44
  subscribeToSignal,
44
45
  subscribeToSpaces,
45
- subscribeToSwarmInfo
46
- } from "./chunk-TF7KXCT7.mjs";
46
+ subscribeToSwarmInfo,
47
+ writeSerializedSpaceArchive
48
+ } from "./chunk-J7VTDH4K.mjs";
49
+ import "./chunk-NQSC7HOE.mjs";
50
+ import {
51
+ __export,
52
+ __reExport
53
+ } from "./chunk-QCWEHHJW.mjs";
47
54
 
48
- // src/packlets/worker/worker-runtime.ts
49
- import { Trigger as Trigger2 } from "@dxos/async";
50
- import { DEFAULT_WORKER_BROADCAST_CHANNEL } from "@dxos/client-protocol";
51
- import { Context } from "@dxos/context";
52
- import { invariant as invariant2 } from "@dxos/invariant";
53
- import { log as log2 } from "@dxos/log";
54
- import { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager, setIdentityTags } from "@dxos/messaging";
55
- import { RtcTransportProxyFactory } from "@dxos/network-manager";
55
+ // src/index.ts
56
+ var index_exports = {};
57
+ __export(index_exports, {
58
+ ClientRpcServer: () => ClientRpcServer,
59
+ ClientServicesHost: () => ClientServicesHost,
60
+ DataSpace: () => DataSpace,
61
+ DataSpaceManager: () => DataSpaceManager,
62
+ DeviceInvitationProtocol: () => DeviceInvitationProtocol,
63
+ DevtoolsHostEvents: () => DevtoolsHostEvents,
64
+ DevtoolsServiceImpl: () => DevtoolsServiceImpl,
65
+ DiagnosticsCollector: () => DiagnosticsCollector,
66
+ EdgeAgentManager: () => EdgeAgentManager,
67
+ EdgeAgentServiceImpl: () => EdgeAgentServiceImpl,
68
+ EdgeFeedReplicator: () => EdgeFeedReplicator,
69
+ Identity: () => Identity,
70
+ IdentityManager: () => IdentityManager,
71
+ IdentityServiceImpl: () => IdentityServiceImpl,
72
+ InvitationsHandler: () => InvitationsHandler,
73
+ InvitationsManager: () => InvitationsManager,
74
+ InvitationsServiceImpl: () => InvitationsServiceImpl,
75
+ ServiceContext: () => ServiceContext,
76
+ ServiceRegistry: () => ServiceRegistry,
77
+ SpaceArchiveWriter: () => SpaceArchiveWriter,
78
+ SpaceInvitationProtocol: () => SpaceInvitationProtocol,
79
+ SpacesServiceImpl: () => SpacesServiceImpl,
80
+ TrustedKeySetAuthVerifier: () => TrustedKeySetAuthVerifier,
81
+ WorkerRuntime: () => WorkerRuntime,
82
+ WorkerSession: () => WorkerSession,
83
+ buildDatabaseDirectoryFromObjects: () => buildDatabaseDirectoryFromObjects,
84
+ createAdmissionKeypair: () => createAdmissionKeypair,
85
+ createAuthProvider: () => createAuthProvider,
86
+ createDiagnostics: () => createDiagnostics,
87
+ createLevel: () => createLevel,
88
+ createStorageObjects: () => createStorageObjects,
89
+ decodeProfileArchive: () => decodeProfileArchive,
90
+ detectSpaceArchiveFormat: () => detectSpaceArchiveFormat,
91
+ encodeProfileArchive: () => encodeProfileArchive,
92
+ exportProfileData: () => exportProfileData,
93
+ extractSpaceArchive: () => extractSpaceArchive,
94
+ getNetworkPeers: () => getNetworkPeers,
95
+ importProfileData: () => importProfileData,
96
+ objJsonToObjectStructure: () => objJsonToObjectStructure,
97
+ objectStructureToObjJson: () => objectStructureToObjJson,
98
+ orderObjJsonFields: () => orderObjJsonFields,
99
+ readSerializedSpaceArchive: () => readSerializedSpaceArchive,
100
+ subscribeToFeedBlocks: () => subscribeToFeedBlocks,
101
+ subscribeToFeeds: () => subscribeToFeeds,
102
+ subscribeToNetworkStatus: () => subscribeToNetworkStatus,
103
+ subscribeToNetworkTopics: () => subscribeToNetworkTopics,
104
+ subscribeToSignal: () => subscribeToSignal,
105
+ subscribeToSpaces: () => subscribeToSpaces,
106
+ subscribeToSwarmInfo: () => subscribeToSwarmInfo,
107
+ writeSerializedSpaceArchive: () => writeSerializedSpaceArchive
108
+ });
109
+ __reExport(index_exports, diagnostics_exports);
110
+ __reExport(index_exports, locks_exports);
56
111
 
57
- // src/packlets/worker/worker-session.ts
58
- import { Trigger, asyncTimeout } from "@dxos/async";
59
- import { PROXY_CONNECTION_TIMEOUT, iframeServiceBundle, workerServiceBundle } from "@dxos/client-protocol";
60
- import { invariant } from "@dxos/invariant";
61
- import { log, logInfo } from "@dxos/log";
62
- import { createProtoRpcPeer } from "@dxos/rpc";
63
- import { Callback } from "@dxos/util";
64
- function _define_property(obj, key, value) {
65
- if (key in obj) {
66
- Object.defineProperty(obj, key, {
67
- value,
68
- enumerable: true,
69
- configurable: true,
70
- writable: true
71
- });
72
- } else {
73
- obj[key] = value;
74
- }
75
- return obj;
76
- }
112
+ // src/packlets/services/client-rpc-server.ts
113
+ import { Stream } from "@dxos/codec-protobuf";
114
+ import { raise } from "@dxos/debug";
115
+ import { RpcPeer, parseMethodName } from "@dxos/rpc";
116
+ import { MapCounter, trace } from "@dxos/tracing";
77
117
  function _ts_decorate(decorators, target, key, desc) {
78
118
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
79
119
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
80
120
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
81
121
  return c > 3 && r && Object.defineProperty(target, key, r), r;
82
122
  }
83
- var __dxlog_file = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/worker/worker-session.ts";
84
- var WorkerSession = class {
123
+ var ClientRpcServer = class {
124
+ _serviceRegistry;
125
+ _rpcPeer;
126
+ _handlerCache = /* @__PURE__ */ new Map();
127
+ _handleCall;
128
+ _handleStream;
129
+ _callMetrics = new MapCounter();
130
+ get _services() {
131
+ return Object.keys(this._serviceRegistry.services);
132
+ }
133
+ constructor(params) {
134
+ const { serviceRegistry, handleCall, handleStream, ...rpcOptions } = params;
135
+ this._handleCall = handleCall;
136
+ this._handleStream = handleStream;
137
+ this._serviceRegistry = serviceRegistry;
138
+ this._rpcPeer = new RpcPeer({
139
+ ...rpcOptions,
140
+ callHandler: (method, params2, options) => {
141
+ const [serviceName, methodName] = parseMethodName(method);
142
+ const handler = (method2, params3, handlerOptions) => this._getServiceHandler(serviceName).call(method2, params3, handlerOptions);
143
+ this._callMetrics.inc(`${serviceName}.${methodName} request`);
144
+ if (this._handleCall) {
145
+ return this._handleCall(methodName, params2, handler, options);
146
+ } else {
147
+ return handler(methodName, params2, options);
148
+ }
149
+ },
150
+ streamHandler: (method, params2, options) => {
151
+ const [serviceName, methodName] = parseMethodName(method);
152
+ const handler = (method2, params3, handlerOptions) => this._getServiceHandler(serviceName).callStream(method2, params3, handlerOptions);
153
+ this._callMetrics.inc(`${serviceName}.${methodName} request stream`);
154
+ if (this._handleStream) {
155
+ return Stream.map(Stream.unwrapPromise(this._handleStream(methodName, params2, handler, options)), (data) => {
156
+ this._callMetrics.inc(`${serviceName}.${methodName} response stream`);
157
+ return data;
158
+ });
159
+ } else {
160
+ return handler(methodName, params2, options);
161
+ }
162
+ }
163
+ });
164
+ }
85
165
  async open() {
86
- log.info("opening...", void 0, {
166
+ await this._rpcPeer.open();
167
+ }
168
+ async close() {
169
+ await this._rpcPeer.close();
170
+ }
171
+ _getServiceHandler(serviceName) {
172
+ if (!this._handlerCache.has(serviceName)) {
173
+ const [key, descriptor] = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName) ?? raise(new Error(`Service not available: ${serviceName}`));
174
+ const service = this._serviceRegistry.services[key];
175
+ if (!service) {
176
+ throw new Error(`Service not available: ${serviceName}`);
177
+ }
178
+ this._handlerCache.set(serviceName, descriptor.createServer(service));
179
+ }
180
+ return this._handlerCache.get(serviceName);
181
+ }
182
+ };
183
+ _ts_decorate([
184
+ trace.metricsCounter()
185
+ ], ClientRpcServer.prototype, "_callMetrics", void 0);
186
+ _ts_decorate([
187
+ trace.info()
188
+ ], ClientRpcServer.prototype, "_services", null);
189
+ ClientRpcServer = _ts_decorate([
190
+ trace.resource()
191
+ ], ClientRpcServer);
192
+
193
+ // src/packlets/storage/profile-archive.ts
194
+ import { cbor } from "@automerge/automerge-repo";
195
+ import { invariant } from "@dxos/invariant";
196
+ import { log } from "@dxos/log";
197
+ import { ProfileArchiveEntryType } from "@dxos/protocols";
198
+ import { arrayToBuffer } from "@dxos/util";
199
+ var __dxlog_file = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/storage/profile-archive.ts";
200
+ var encodeProfileArchive = (profile) => cbor.encode(profile);
201
+ var decodeProfileArchive = (data) => cbor.decode(data);
202
+ var exportProfileData = async ({ storage, level }) => {
203
+ const archive = {
204
+ storage: [],
205
+ meta: {
206
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
207
+ }
208
+ };
209
+ {
210
+ const directory = await storage.createDirectory();
211
+ const files = await directory.list();
212
+ log.info("begin exporting files", {
213
+ count: files.length
214
+ }, {
87
215
  F: __dxlog_file,
88
- L: 122,
89
- S: this,
216
+ L: 31,
217
+ S: void 0,
90
218
  C: (f, a) => f(...a)
91
219
  });
92
- await Promise.all([
93
- this._clientRpc.open(),
94
- this._iframeRpc.open(),
95
- this._maybeOpenShell()
96
- ]);
97
- await this._startTrigger.wait({
98
- timeout: PROXY_CONNECTION_TIMEOUT
99
- });
100
- if (this.lockKey) {
101
- void this._afterLockReleases(this.lockKey, () => this.close());
220
+ for (const filename of files) {
221
+ const file = await directory.getOrCreateFile(filename);
222
+ const { size } = await file.stat();
223
+ const data = await file.read(0, size);
224
+ archive.storage.push({
225
+ type: ProfileArchiveEntryType.FILE,
226
+ key: filename,
227
+ value: data
228
+ });
102
229
  }
103
- log.info("opened", void 0, {
230
+ log.info("done exporting files", {
231
+ count: files.length
232
+ }, {
104
233
  F: __dxlog_file,
105
- L: 133,
106
- S: this,
234
+ L: 42,
235
+ S: void 0,
107
236
  C: (f, a) => f(...a)
108
237
  });
109
238
  }
110
- async close() {
111
- log.info("closing...", void 0, {
239
+ {
240
+ log.info("begin exporting kv pairs", void 0, {
112
241
  F: __dxlog_file,
113
- L: 137,
114
- S: this,
242
+ L: 46,
243
+ S: void 0,
115
244
  C: (f, a) => f(...a)
116
245
  });
117
- try {
118
- await this.onClose.callIfSet();
119
- } catch (err) {
120
- log.catch(err, void 0, {
121
- F: __dxlog_file,
122
- L: 141,
123
- S: this,
124
- C: (f, a) => f(...a)
246
+ const iter = await level.iterator({
247
+ keyEncoding: "binary",
248
+ valueEncoding: "binary"
249
+ });
250
+ let count = 0;
251
+ for await (const [key, value] of iter) {
252
+ archive.storage.push({
253
+ type: ProfileArchiveEntryType.KEY_VALUE,
254
+ key,
255
+ value
125
256
  });
257
+ count++;
126
258
  }
127
- await Promise.all([
128
- this._clientRpc.close(),
129
- this._iframeRpc.close()
130
- ]);
131
- log.info("closed", void 0, {
259
+ log.info("done exporting kv pairs", {
260
+ count
261
+ }, {
132
262
  F: __dxlog_file,
133
- L: 145,
134
- S: this,
263
+ L: 57,
264
+ S: void 0,
135
265
  C: (f, a) => f(...a)
136
266
  });
137
267
  }
138
- async _maybeOpenShell() {
139
- try {
140
- this._shellClientRpc && await asyncTimeout(this._shellClientRpc.open(), 1e3);
141
- } catch {
142
- log.info("No shell connected.", void 0, {
268
+ return archive;
269
+ };
270
+ var importProfileData = async ({ storage, level }, archive) => {
271
+ let batch = level.batch();
272
+ let count = 0;
273
+ for (const entry of archive.storage) {
274
+ switch (entry.type) {
275
+ case ProfileArchiveEntryType.FILE: {
276
+ const directory = await storage.createDirectory();
277
+ invariant(typeof entry.key === "string", "Invalid key type", {
278
+ F: __dxlog_file,
279
+ L: 80,
280
+ S: void 0,
281
+ A: [
282
+ "typeof entry.key === 'string'",
283
+ "'Invalid key type'"
284
+ ]
285
+ });
286
+ const file = await directory.getOrCreateFile(entry.key);
287
+ invariant(entry.value instanceof Uint8Array, "Invalid value type", {
288
+ F: __dxlog_file,
289
+ L: 82,
290
+ S: void 0,
291
+ A: [
292
+ "entry.value instanceof Uint8Array",
293
+ "'Invalid value type'"
294
+ ]
295
+ });
296
+ await file.write(0, arrayToBuffer(entry.value));
297
+ await file.close();
298
+ break;
299
+ }
300
+ case ProfileArchiveEntryType.KEY_VALUE: {
301
+ invariant(entry.key instanceof Uint8Array, "Invalid key type", {
302
+ F: __dxlog_file,
303
+ L: 88,
304
+ S: void 0,
305
+ A: [
306
+ "entry.key instanceof Uint8Array",
307
+ "'Invalid key type'"
308
+ ]
309
+ });
310
+ invariant(entry.value instanceof Uint8Array, "Invalid value type", {
311
+ F: __dxlog_file,
312
+ L: 89,
313
+ S: void 0,
314
+ A: [
315
+ "entry.value instanceof Uint8Array",
316
+ "'Invalid value type'"
317
+ ]
318
+ });
319
+ batch.put(entry.key, entry.value, {
320
+ keyEncoding: "binary",
321
+ valueEncoding: "binary"
322
+ });
323
+ break;
324
+ }
325
+ default:
326
+ throw new Error(`Invalid entry type: ${entry.type}`);
327
+ }
328
+ if (++count % 1e3 === 0) {
329
+ await batch.write();
330
+ batch = level.batch();
331
+ log.info("importing", {
332
+ count,
333
+ total: archive.storage.length,
334
+ progress: `${(count / archive.storage.length * 100).toFixed()}%`
335
+ }, {
143
336
  F: __dxlog_file,
144
- L: 152,
145
- S: this,
337
+ L: 102,
338
+ S: void 0,
146
339
  C: (f, a) => f(...a)
147
340
  });
148
341
  }
149
342
  }
150
- _afterLockReleases(lockKey, callback) {
151
- return navigator.locks.request(lockKey, () => {
152
- }).then(callback);
153
- }
343
+ log.info("committing changes..", void 0, {
344
+ F: __dxlog_file,
345
+ L: 110,
346
+ S: void 0,
347
+ C: (f, a) => f(...a)
348
+ });
349
+ await batch.write();
350
+ };
351
+
352
+ // src/packlets/worker/worker-runtime.ts
353
+ import * as Reactivity from "@effect/experimental/Reactivity";
354
+ import * as Effect from "effect/Effect";
355
+ import * as Layer from "effect/Layer";
356
+ import * as ManagedRuntime from "effect/ManagedRuntime";
357
+ import { Trigger as Trigger2 } from "@dxos/async";
358
+ import { DEFAULT_WORKER_BROADCAST_CHANNEL } from "@dxos/client-protocol";
359
+ import { Context } from "@dxos/context";
360
+ import { invariant as invariant3 } from "@dxos/invariant";
361
+ import { log as log3 } from "@dxos/log";
362
+ import { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager, setIdentityTags } from "@dxos/messaging";
363
+ import { RtcTransportProxyFactory } from "@dxos/network-manager";
364
+ import * as OpfsWorker from "@dxos/sql-sqlite/OpfsWorker";
365
+ import * as SqlExport from "@dxos/sql-sqlite/SqlExport";
366
+ import * as SqliteClient from "@dxos/sql-sqlite/SqliteClient";
367
+ import * as SqlTransaction from "@dxos/sql-sqlite/SqlTransaction";
368
+
369
+ // src/packlets/worker/worker-session.ts
370
+ import { Trigger, asyncTimeout } from "@dxos/async";
371
+ import { PROXY_CONNECTION_TIMEOUT, iframeServiceBundle, workerServiceBundle } from "@dxos/client-protocol";
372
+ import { invariant as invariant2 } from "@dxos/invariant";
373
+ import { log as log2, logInfo } from "@dxos/log";
374
+ import { createProtoRpcPeer } from "@dxos/rpc";
375
+ import { Callback } from "@dxos/util";
376
+ function _ts_decorate2(decorators, target, key, desc) {
377
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
378
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
379
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
380
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
381
+ }
382
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/worker/worker-session.ts";
383
+ var WorkerSession = class {
384
+ _clientRpc;
385
+ _shellClientRpc;
386
+ _iframeRpc;
387
+ _startTrigger = new Trigger();
388
+ _serviceHost;
389
+ onClose = new Callback();
390
+ origin;
391
+ lockKey;
392
+ bridgeService;
154
393
  constructor({ serviceHost, systemPort, appPort, shellPort, readySignal }) {
155
- _define_property(this, "_clientRpc", void 0);
156
- _define_property(this, "_shellClientRpc", void 0);
157
- _define_property(this, "_iframeRpc", void 0);
158
- _define_property(this, "_startTrigger", new Trigger());
159
- _define_property(this, "_serviceHost", void 0);
160
- _define_property(this, "onClose", new Callback());
161
- _define_property(this, "origin", void 0);
162
- _define_property(this, "observabilityGroup", void 0);
163
- _define_property(this, "signalTelemetryEnabled", void 0);
164
- _define_property(this, "lockKey", void 0);
165
- _define_property(this, "bridgeService", void 0);
166
- invariant(serviceHost, void 0, {
167
- F: __dxlog_file,
168
- L: 54,
394
+ invariant2(serviceHost, void 0, {
395
+ F: __dxlog_file2,
396
+ L: 50,
169
397
  S: this,
170
398
  A: [
171
399
  "serviceHost",
@@ -174,23 +402,23 @@ var WorkerSession = class {
174
402
  });
175
403
  this._serviceHost = serviceHost;
176
404
  const middleware = {
177
- handleCall: async (method, params, handler) => {
405
+ handleCall: async (method, params, handler, options) => {
178
406
  const error = await readySignal.wait({
179
407
  timeout: PROXY_CONNECTION_TIMEOUT
180
408
  });
181
409
  if (error) {
182
410
  throw error;
183
411
  }
184
- return handler(method, params);
412
+ return handler(method, params, options);
185
413
  },
186
- handleStream: async (method, params, handler) => {
414
+ handleStream: async (method, params, handler, options) => {
187
415
  const error = await readySignal.wait({
188
416
  timeout: PROXY_CONNECTION_TIMEOUT
189
417
  });
190
418
  if (error) {
191
419
  throw error;
192
420
  }
193
- return handler(method, params);
421
+ return handler(method, params, options);
194
422
  }
195
423
  };
196
424
  this._clientRpc = new ClientRpcServer({
@@ -211,8 +439,6 @@ var WorkerSession = class {
211
439
  start: async (request) => {
212
440
  this.origin = request.origin;
213
441
  this.lockKey = request.lockKey;
214
- this.observabilityGroup = request.observabilityGroup;
215
- this.signalTelemetryEnabled = request.signalTelemetryEnabled;
216
442
  this._startTrigger.wake();
217
443
  },
218
444
  stop: async () => {
@@ -220,9 +446,9 @@ var WorkerSession = class {
220
446
  try {
221
447
  await this.close();
222
448
  } catch (err) {
223
- log.catch(err, void 0, {
224
- F: __dxlog_file,
225
- L: 108,
449
+ log2.catch(err, void 0, {
450
+ F: __dxlog_file2,
451
+ L: 102,
226
452
  S: this,
227
453
  C: (f, a) => f(...a)
228
454
  });
@@ -236,41 +462,147 @@ var WorkerSession = class {
236
462
  });
237
463
  this.bridgeService = this._iframeRpc.rpc.BridgeService;
238
464
  }
465
+ async open() {
466
+ log2("opening...", void 0, {
467
+ F: __dxlog_file2,
468
+ L: 116,
469
+ S: this,
470
+ C: (f, a) => f(...a)
471
+ });
472
+ await Promise.all([
473
+ this._clientRpc.open(),
474
+ this._iframeRpc.open(),
475
+ this._maybeOpenShell()
476
+ ]);
477
+ await this._startTrigger.wait({
478
+ timeout: PROXY_CONNECTION_TIMEOUT
479
+ });
480
+ if (this.lockKey) {
481
+ void this._afterLockReleases(this.lockKey, () => this.close());
482
+ }
483
+ log2("opened", void 0, {
484
+ F: __dxlog_file2,
485
+ L: 127,
486
+ S: this,
487
+ C: (f, a) => f(...a)
488
+ });
489
+ }
490
+ async close() {
491
+ log2.debug("closing...", void 0, {
492
+ F: __dxlog_file2,
493
+ L: 131,
494
+ S: this,
495
+ C: (f, a) => f(...a)
496
+ });
497
+ try {
498
+ await this.onClose.callIfSet();
499
+ } catch (err) {
500
+ log2.catch(err, void 0, {
501
+ F: __dxlog_file2,
502
+ L: 135,
503
+ S: this,
504
+ C: (f, a) => f(...a)
505
+ });
506
+ }
507
+ await Promise.all([
508
+ this._clientRpc.close(),
509
+ this._iframeRpc.close()
510
+ ]);
511
+ log2.debug("closed", void 0, {
512
+ F: __dxlog_file2,
513
+ L: 139,
514
+ S: this,
515
+ C: (f, a) => f(...a)
516
+ });
517
+ }
518
+ async _maybeOpenShell() {
519
+ try {
520
+ this._shellClientRpc && await asyncTimeout(this._shellClientRpc.open(), 1e3);
521
+ } catch {
522
+ log2.info("No shell connected.", void 0, {
523
+ F: __dxlog_file2,
524
+ L: 146,
525
+ S: this,
526
+ C: (f, a) => f(...a)
527
+ });
528
+ }
529
+ }
530
+ _afterLockReleases(lockKey, callback) {
531
+ return navigator.locks.request(lockKey, () => {
532
+ }).then(callback);
533
+ }
239
534
  };
240
- _ts_decorate([
535
+ _ts_decorate2([
241
536
  logInfo
242
537
  ], WorkerSession.prototype, "origin", void 0);
243
- _ts_decorate([
538
+ _ts_decorate2([
244
539
  logInfo
245
540
  ], WorkerSession.prototype, "lockKey", void 0);
246
541
 
247
542
  // src/packlets/worker/worker-runtime.ts
248
- function _define_property2(obj, key, value) {
249
- if (key in obj) {
250
- Object.defineProperty(obj, key, {
251
- value,
252
- enumerable: true,
253
- configurable: true,
254
- writable: true
543
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/worker/worker-runtime.ts";
544
+ var WorkerRuntime = class {
545
+ _configProvider;
546
+ _acquireLock;
547
+ _releaseLock;
548
+ _onStop;
549
+ _transportFactory = new RtcTransportProxyFactory();
550
+ _ready = new Trigger2();
551
+ _sessions = /* @__PURE__ */ new Set();
552
+ _clientServices;
553
+ _channel;
554
+ _automaticallyConnectWebrtc;
555
+ _livenessLock = new WebLockWrapper(`@dxos/client-services/WorkerRuntime/${crypto.randomUUID()}`);
556
+ _broadcastChannel;
557
+ _sessionForNetworking;
558
+ _config;
559
+ _signalMetadataTags = {
560
+ runtime: "worker-runtime"
561
+ };
562
+ _signalTelemetryEnabled = false;
563
+ _runtime;
564
+ constructor({ channel = DEFAULT_WORKER_BROADCAST_CHANNEL, configProvider, acquireLock, releaseLock, onStop, automaticallyConnectWebrtc = true, sqliteLayer }) {
565
+ this._configProvider = configProvider;
566
+ this._acquireLock = acquireLock;
567
+ this._releaseLock = releaseLock;
568
+ this._onStop = onStop;
569
+ this._channel = channel;
570
+ if (sqliteLayer) {
571
+ log3.warn("Using testing SQLite layer", void 0, {
572
+ F: __dxlog_file3,
573
+ L: 102,
574
+ S: this,
575
+ C: (f, a) => f(...a)
576
+ });
577
+ }
578
+ this._runtime = ManagedRuntime.make(SqlTransaction.layer.pipe(Layer.provideMerge(sqliteLayer ?? LocalSqliteOpfsLayer), Layer.provideMerge(Reactivity.layer)).pipe(Layer.orDie));
579
+ this._clientServices = new ClientServicesHost({
580
+ callbacks: {
581
+ onReset: async () => this.stop()
582
+ },
583
+ runtime: this._runtime.runtimeEffect,
584
+ runtimeProps: {
585
+ // Auto-activate spaces that were previously active after leader changeover.
586
+ autoActivateSpaces: true
587
+ }
255
588
  });
256
- } else {
257
- obj[key] = value;
589
+ this._automaticallyConnectWebrtc = automaticallyConnectWebrtc;
258
590
  }
259
- return obj;
260
- }
261
- var __dxlog_file2 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/worker/worker-runtime.ts";
262
- var WorkerRuntime = class {
263
591
  get host() {
264
592
  return this._clientServices;
265
593
  }
594
+ get livenessLockKey() {
595
+ return this._livenessLock.key;
596
+ }
266
597
  async start() {
267
- log2("starting...", void 0, {
268
- F: __dxlog_file2,
269
- L: 85,
598
+ log3("starting...", void 0, {
599
+ F: __dxlog_file3,
600
+ L: 131,
270
601
  S: this,
271
602
  C: (f, a) => f(...a)
272
603
  });
273
604
  try {
605
+ void this._livenessLock.acquire();
274
606
  this._broadcastChannel = new BroadcastChannel(this._channel);
275
607
  this._broadcastChannel.postMessage({
276
608
  action: "stop"
@@ -282,6 +614,11 @@ var WorkerRuntime = class {
282
614
  };
283
615
  await this._acquireLock();
284
616
  this._config = await this._configProvider();
617
+ this._signalTelemetryEnabled = this._config.get("runtime.client.signalTelemetryEnabled") ?? false;
618
+ const observabilityGroup = this._config.get("runtime.client.observabilityGroup");
619
+ if (observabilityGroup) {
620
+ this._signalMetadataTags.group = observabilityGroup;
621
+ }
285
622
  const signals = this._config.get("runtime.services.signaling");
286
623
  this._clientServices.initialize({
287
624
  config: this._config,
@@ -289,13 +626,13 @@ var WorkerRuntime = class {
289
626
  transportFactory: this._transportFactory
290
627
  });
291
628
  await this._clientServices.open(new Context(void 0, {
292
- F: __dxlog_file2,
293
- L: 108
629
+ F: __dxlog_file3,
630
+ L: 162
294
631
  }));
295
632
  this._ready.wake(void 0);
296
- log2("started", void 0, {
297
- F: __dxlog_file2,
298
- L: 110,
633
+ log3("started", void 0, {
634
+ F: __dxlog_file3,
635
+ L: 164,
299
636
  S: this,
300
637
  C: (f, a) => f(...a)
301
638
  });
@@ -308,9 +645,9 @@ var WorkerRuntime = class {
308
645
  });
309
646
  } catch (err) {
310
647
  this._ready.wake(err);
311
- log2.error("starting", err, {
312
- F: __dxlog_file2,
313
- L: 120,
648
+ log3.error("starting", err, {
649
+ F: __dxlog_file3,
650
+ L: 174,
314
651
  S: this,
315
652
  C: (f, a) => f(...a)
316
653
  });
@@ -320,13 +657,39 @@ var WorkerRuntime = class {
320
657
  this._releaseLock();
321
658
  this._broadcastChannel?.close();
322
659
  this._broadcastChannel = void 0;
323
- await this._clientServices.close();
660
+ await this._clientServices.close(Context.default(void 0, {
661
+ F: __dxlog_file3,
662
+ L: 183
663
+ }));
664
+ await this._runtime.dispose();
324
665
  await this._onStop?.();
666
+ await this._livenessLock.release();
667
+ }
668
+ /**
669
+ * Update signaling telemetry tags from a client-supplied config overlay.
670
+ *
671
+ * The worker services outlive individual client connections, so the first client seeds the
672
+ * worker's core config (storage, signaling, edge features). For fields that can legitimately
673
+ * differ per tab — `observabilityGroup` and `signalTelemetryEnabled` — this method lets later
674
+ * connections refresh the signal metadata the worker attaches to its signaling requests
675
+ * (last-writer-wins, matching the pre-DX-930 per-session RPC behaviour).
676
+ */
677
+ updateSignalMetadata(config) {
678
+ const observabilityGroup = config.get("runtime.client.observabilityGroup");
679
+ if (observabilityGroup) {
680
+ this._signalMetadataTags.group = observabilityGroup;
681
+ } else {
682
+ delete this._signalMetadataTags.group;
683
+ }
684
+ const signalTelemetryEnabled = config.get("runtime.client.signalTelemetryEnabled");
685
+ if (signalTelemetryEnabled !== void 0) {
686
+ this._signalTelemetryEnabled = signalTelemetryEnabled;
687
+ }
325
688
  }
326
689
  /**
327
690
  * Create a new session.
328
691
  */
329
- async createSession({ appPort, systemPort, shellPort }) {
692
+ async createSession({ appPort, systemPort, shellPort, onClose }) {
330
693
  const session = new WorkerSession({
331
694
  serviceHost: this._clientServices,
332
695
  appPort,
@@ -339,34 +702,48 @@ var WorkerRuntime = class {
339
702
  if (this._sessions.size === 0) {
340
703
  await this.stop();
341
704
  } else {
342
- this._reconnectWebrtc();
705
+ if (this._automaticallyConnectWebrtc) {
706
+ this._reconnectWebrtc();
707
+ }
343
708
  }
709
+ await onClose?.();
344
710
  });
345
711
  await session.open();
346
- invariant2(!this._signalMetadataTags.origin || this._signalMetadataTags.origin === session.origin, `worker origin changed from ${this._signalMetadataTags.origin} to ${session.origin}?`, {
347
- F: __dxlog_file2,
348
- L: 158,
712
+ invariant3(!this._signalMetadataTags.origin || this._signalMetadataTags.origin === session.origin, `worker origin changed from ${this._signalMetadataTags.origin} to ${session.origin}?`, {
713
+ F: __dxlog_file3,
714
+ L: 241,
349
715
  S: this,
350
716
  A: [
351
717
  "!this._signalMetadataTags.origin || this._signalMetadataTags.origin === session.origin",
352
718
  "`worker origin changed from ${this._signalMetadataTags.origin} to ${session.origin}?`"
353
719
  ]
354
720
  });
355
- if (session.observabilityGroup) {
356
- this._signalMetadataTags.group = session.observabilityGroup;
357
- }
358
- this._signalTelemetryEnabled = session.signalTelemetryEnabled ?? false;
359
721
  this._signalMetadataTags.origin = session.origin;
360
722
  this._sessions.add(session);
361
- this._reconnectWebrtc();
723
+ if (this._automaticallyConnectWebrtc) {
724
+ this._reconnectWebrtc();
725
+ }
726
+ return session;
727
+ }
728
+ /**
729
+ * Connects the WebRTC bridge to the specified session.
730
+ * If no session is provided, disconnects the WebRTC bridge.
731
+ *
732
+ * Called automatically if `automaticallyConnectWebrtc` is true.
733
+ *
734
+ * @param session The session to connect the WebRTC bridge to.
735
+ */
736
+ connectWebrtcBridge(session) {
737
+ this._sessionForNetworking = session;
738
+ this._transportFactory.setBridgeService(session?.bridgeService);
362
739
  }
363
740
  /**
364
741
  * Selects one of the existing session for WebRTC networking.
365
742
  */
366
743
  _reconnectWebrtc() {
367
- log2("reconnecting webrtc...", void 0, {
368
- F: __dxlog_file2,
369
- L: 176,
744
+ log3("reconnecting webrtc...", void 0, {
745
+ F: __dxlog_file3,
746
+ L: 272,
370
747
  S: this,
371
748
  C: (f, a) => f(...a)
372
749
  });
@@ -377,42 +754,57 @@ var WorkerRuntime = class {
377
754
  }
378
755
  if (!this._sessionForNetworking) {
379
756
  const selected = Array.from(this._sessions).find((session) => session.bridgeService);
380
- if (selected) {
381
- this._sessionForNetworking = selected;
382
- this._transportFactory.setBridgeService(selected.bridgeService);
383
- } else {
384
- this._transportFactory.setBridgeService(void 0);
385
- }
757
+ this.connectWebrtcBridge(selected);
386
758
  }
387
759
  }
388
- constructor({ channel = DEFAULT_WORKER_BROADCAST_CHANNEL, configProvider, acquireLock, releaseLock, onStop }) {
389
- _define_property2(this, "_configProvider", void 0);
390
- _define_property2(this, "_acquireLock", void 0);
391
- _define_property2(this, "_releaseLock", void 0);
392
- _define_property2(this, "_onStop", void 0);
393
- _define_property2(this, "_transportFactory", new RtcTransportProxyFactory());
394
- _define_property2(this, "_ready", new Trigger2());
395
- _define_property2(this, "_sessions", /* @__PURE__ */ new Set());
396
- _define_property2(this, "_clientServices", void 0);
397
- _define_property2(this, "_channel", void 0);
398
- _define_property2(this, "_broadcastChannel", void 0);
399
- _define_property2(this, "_sessionForNetworking", void 0);
400
- _define_property2(this, "_config", void 0);
401
- _define_property2(this, "_signalMetadataTags", {
402
- runtime: "worker-runtime"
403
- });
404
- _define_property2(this, "_signalTelemetryEnabled", false);
405
- this._configProvider = configProvider;
406
- this._acquireLock = acquireLock;
407
- this._releaseLock = releaseLock;
408
- this._onStop = onStop;
409
- this._channel = channel;
410
- this._clientServices = new ClientServicesHost({
411
- callbacks: {
412
- onReset: async () => this.stop()
413
- }
760
+ };
761
+ var DB_NAME = "DXOS";
762
+ var SqlExportLayer = Layer.effect(SqlExport.SqlExport, Effect.gen(function* () {
763
+ const sql = yield* SqliteClient.SqliteClient;
764
+ return {
765
+ export: sql.export
766
+ };
767
+ }));
768
+ var LocalSqliteOpfsLayer = Layer.unwrapScoped(Effect.gen(function* () {
769
+ const { port1: clientPort, port2: serverPort } = new MessageChannel();
770
+ clientPort.start();
771
+ serverPort.start();
772
+ yield* Effect.addFinalizer(() => Effect.sync(() => {
773
+ clientPort.close();
774
+ serverPort.close();
775
+ }));
776
+ yield* Effect.forkScoped(OpfsWorker.run({
777
+ port: serverPort,
778
+ dbName: DB_NAME
779
+ }));
780
+ return SqlExportLayer.pipe(Layer.provideMerge(SqliteClient.layer({
781
+ worker: Effect.succeed(clientPort)
782
+ })));
783
+ }));
784
+ var WebLockWrapper = class {
785
+ #key;
786
+ #release;
787
+ constructor(key) {
788
+ this.#key = key;
789
+ }
790
+ get key() {
791
+ return this.#key;
792
+ }
793
+ acquire(options = {}) {
794
+ return navigator.locks.request(this.#key, options, async () => {
795
+ await new Promise((resolve) => {
796
+ this.#release = resolve;
797
+ });
798
+ this.#release = void 0;
414
799
  });
415
800
  }
801
+ release() {
802
+ this.#release?.();
803
+ this.#release = void 0;
804
+ }
805
+ [Symbol.dispose]() {
806
+ this.release();
807
+ }
416
808
  };
417
809
  export {
418
810
  ClientRpcServer,
@@ -432,33 +824,38 @@ export {
432
824
  InvitationsHandler,
433
825
  InvitationsManager,
434
826
  InvitationsServiceImpl,
435
- Lock,
436
827
  ServiceContext,
437
828
  ServiceRegistry,
829
+ SpaceArchiveWriter,
438
830
  SpaceInvitationProtocol,
439
831
  SpacesServiceImpl,
440
832
  TrustedKeySetAuthVerifier,
441
833
  WorkerRuntime,
442
834
  WorkerSession,
835
+ buildDatabaseDirectoryFromObjects,
443
836
  createAdmissionKeypair,
444
837
  createAuthProvider,
445
- createCollectDiagnosticsBroadcastHandler,
446
- createCollectDiagnosticsBroadcastSender,
447
838
  createDiagnostics,
448
839
  createLevel,
449
840
  createStorageObjects,
450
841
  decodeProfileArchive,
842
+ detectSpaceArchiveFormat,
451
843
  encodeProfileArchive,
452
844
  exportProfileData,
845
+ extractSpaceArchive,
453
846
  getNetworkPeers,
454
847
  importProfileData,
455
- isLocked,
848
+ objJsonToObjectStructure,
849
+ objectStructureToObjJson,
850
+ orderObjJsonFields,
851
+ readSerializedSpaceArchive,
456
852
  subscribeToFeedBlocks,
457
853
  subscribeToFeeds,
458
854
  subscribeToNetworkStatus,
459
855
  subscribeToNetworkTopics,
460
856
  subscribeToSignal,
461
857
  subscribeToSpaces,
462
- subscribeToSwarmInfo
858
+ subscribeToSwarmInfo,
859
+ writeSerializedSpaceArchive
463
860
  };
464
861
  //# sourceMappingURL=index.mjs.map