@dxos/echo-pipeline 0.8.4-main.f9ba587 → 0.8.4-main.fcc0d83b33

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 (198) hide show
  1. package/dist/lib/{browser/chunk-GBFX5J5B.mjs → neutral/chunk-VIHYDCCC.mjs} +294 -690
  2. package/dist/lib/neutral/chunk-VIHYDCCC.mjs.map +7 -0
  3. package/dist/lib/neutral/chunk-YBC6ONBZ.mjs +247 -0
  4. package/dist/lib/neutral/chunk-YBC6ONBZ.mjs.map +7 -0
  5. package/dist/lib/{browser → neutral}/filter/index.mjs +3 -2
  6. package/dist/lib/neutral/index.mjs +6245 -0
  7. package/dist/lib/neutral/index.mjs.map +7 -0
  8. package/dist/lib/neutral/meta.json +1 -0
  9. package/dist/lib/{browser → neutral}/testing/index.mjs +73 -302
  10. package/dist/lib/neutral/testing/index.mjs.map +7 -0
  11. package/dist/types/src/automerge/automerge-host.d.ts +57 -50
  12. package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
  13. package/dist/types/src/automerge/automerge-repo.test.d.ts +1 -1
  14. package/dist/types/src/automerge/automerge-repo.test.d.ts.map +1 -1
  15. package/dist/types/src/automerge/collection-synchronizer.d.ts +6 -4
  16. package/dist/types/src/automerge/collection-synchronizer.d.ts.map +1 -1
  17. package/dist/types/src/automerge/echo-data-monitor.d.ts.map +1 -1
  18. package/dist/types/src/automerge/echo-network-adapter.d.ts +23 -10
  19. package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
  20. package/dist/types/src/automerge/echo-replicator.d.ts +38 -15
  21. package/dist/types/src/automerge/echo-replicator.d.ts.map +1 -1
  22. package/dist/types/src/automerge/heads-store.d.ts +9 -2
  23. package/dist/types/src/automerge/heads-store.d.ts.map +1 -1
  24. package/dist/types/src/automerge/index.d.ts +1 -1
  25. package/dist/types/src/automerge/index.d.ts.map +1 -1
  26. package/dist/types/src/automerge/leveldb-storage-adapter.d.ts +5 -5
  27. package/dist/types/src/automerge/leveldb-storage-adapter.d.ts.map +1 -1
  28. package/dist/types/src/automerge/mesh-echo-replicator-connection.d.ts +9 -8
  29. package/dist/types/src/automerge/mesh-echo-replicator-connection.d.ts.map +1 -1
  30. package/dist/types/src/automerge/mesh-echo-replicator.d.ts +6 -5
  31. package/dist/types/src/automerge/mesh-echo-replicator.d.ts.map +1 -1
  32. package/dist/types/src/automerge/network-protocol.d.ts.map +1 -1
  33. package/dist/types/src/automerge/space-collection.d.ts.map +1 -1
  34. package/dist/types/src/common/codec.d.ts +1 -1
  35. package/dist/types/src/common/codec.d.ts.map +1 -1
  36. package/dist/types/src/common/feeds.d.ts.map +1 -1
  37. package/dist/types/src/common/space-id.d.ts.map +1 -1
  38. package/dist/types/src/db-host/automerge-data-source.d.ts +35 -0
  39. package/dist/types/src/db-host/automerge-data-source.d.ts.map +1 -0
  40. package/dist/types/src/db-host/automerge-data-source.test.d.ts +2 -0
  41. package/dist/types/src/db-host/automerge-data-source.test.d.ts.map +1 -0
  42. package/dist/types/src/db-host/automerge-metrics.d.ts.map +1 -1
  43. package/dist/types/src/db-host/data-service.d.ts +8 -7
  44. package/dist/types/src/db-host/data-service.d.ts.map +1 -1
  45. package/dist/types/src/db-host/database-root.d.ts.map +1 -1
  46. package/dist/types/src/db-host/documents-synchronizer.d.ts +8 -7
  47. package/dist/types/src/db-host/documents-synchronizer.d.ts.map +1 -1
  48. package/dist/types/src/db-host/echo-host.d.ts +58 -28
  49. package/dist/types/src/db-host/echo-host.d.ts.map +1 -1
  50. package/dist/types/src/db-host/index.d.ts +1 -0
  51. package/dist/types/src/db-host/index.d.ts.map +1 -1
  52. package/dist/types/src/db-host/local-queue-service.d.ts +19 -0
  53. package/dist/types/src/db-host/local-queue-service.d.ts.map +1 -0
  54. package/dist/types/src/db-host/query-service.d.ts +14 -9
  55. package/dist/types/src/db-host/query-service.d.ts.map +1 -1
  56. package/dist/types/src/db-host/queue-data-source.d.ts +38 -0
  57. package/dist/types/src/db-host/queue-data-source.d.ts.map +1 -0
  58. package/dist/types/src/db-host/queue-service.test.d.ts +2 -0
  59. package/dist/types/src/db-host/queue-service.test.d.ts.map +1 -0
  60. package/dist/types/src/db-host/space-state-manager.d.ts +2 -1
  61. package/dist/types/src/db-host/space-state-manager.d.ts.map +1 -1
  62. package/dist/types/src/db-host/stub.d.ts +11 -0
  63. package/dist/types/src/db-host/stub.d.ts.map +1 -0
  64. package/dist/types/src/edge/echo-edge-replicator.d.ts +10 -7
  65. package/dist/types/src/edge/echo-edge-replicator.d.ts.map +1 -1
  66. package/dist/types/src/edge/inflight-request-limiter.d.ts.map +1 -1
  67. package/dist/types/src/filter/filter-match.d.ts +4 -1
  68. package/dist/types/src/filter/filter-match.d.ts.map +1 -1
  69. package/dist/types/src/metadata/metadata-store.d.ts +1 -1
  70. package/dist/types/src/metadata/metadata-store.d.ts.map +1 -1
  71. package/dist/types/src/pipeline/message-selector.d.ts.map +1 -1
  72. package/dist/types/src/pipeline/pipeline.d.ts +3 -3
  73. package/dist/types/src/pipeline/pipeline.d.ts.map +1 -1
  74. package/dist/types/src/pipeline/timeframe-clock.d.ts.map +1 -1
  75. package/dist/types/src/query/errors.d.ts +22 -10
  76. package/dist/types/src/query/errors.d.ts.map +1 -1
  77. package/dist/types/src/query/plan.d.ts +66 -8
  78. package/dist/types/src/query/plan.d.ts.map +1 -1
  79. package/dist/types/src/query/query-executor.d.ts +55 -10
  80. package/dist/types/src/query/query-executor.d.ts.map +1 -1
  81. package/dist/types/src/query/query-planner.d.ts +12 -1
  82. package/dist/types/src/query/query-planner.d.ts.map +1 -1
  83. package/dist/types/src/space/admission-discovery-extension.d.ts.map +1 -1
  84. package/dist/types/src/space/auth.d.ts +3 -3
  85. package/dist/types/src/space/auth.d.ts.map +1 -1
  86. package/dist/types/src/space/control-pipeline.d.ts +5 -4
  87. package/dist/types/src/space/control-pipeline.d.ts.map +1 -1
  88. package/dist/types/src/space/space-manager.d.ts +8 -8
  89. package/dist/types/src/space/space-manager.d.ts.map +1 -1
  90. package/dist/types/src/space/space-protocol.d.ts +10 -9
  91. package/dist/types/src/space/space-protocol.d.ts.map +1 -1
  92. package/dist/types/src/space/space.d.ts +6 -6
  93. package/dist/types/src/space/space.d.ts.map +1 -1
  94. package/dist/types/src/testing/change-metadata.d.ts.map +1 -1
  95. package/dist/types/src/testing/index.d.ts +0 -2
  96. package/dist/types/src/testing/index.d.ts.map +1 -1
  97. package/dist/types/src/testing/test-agent-builder.d.ts +2 -2
  98. package/dist/types/src/testing/test-agent-builder.d.ts.map +1 -1
  99. package/dist/types/src/testing/test-feed-builder.d.ts.map +1 -1
  100. package/dist/types/src/testing/test-network-adapter.d.ts +1 -1
  101. package/dist/types/src/testing/test-network-adapter.d.ts.map +1 -1
  102. package/dist/types/src/testing/test-replicator.d.ts +14 -13
  103. package/dist/types/src/testing/test-replicator.d.ts.map +1 -1
  104. package/dist/types/src/util.d.ts +1 -1
  105. package/dist/types/src/util.d.ts.map +1 -1
  106. package/dist/types/tsconfig.tsbuildinfo +1 -1
  107. package/package.json +54 -54
  108. package/src/automerge/automerge-host.test.ts +59 -30
  109. package/src/automerge/automerge-host.ts +413 -142
  110. package/src/automerge/automerge-repo.test.ts +215 -47
  111. package/src/automerge/collection-synchronizer.test.ts +21 -15
  112. package/src/automerge/collection-synchronizer.ts +71 -30
  113. package/src/automerge/echo-data-monitor.ts +1 -1
  114. package/src/automerge/echo-network-adapter.test.ts +5 -4
  115. package/src/automerge/echo-network-adapter.ts +72 -29
  116. package/src/automerge/echo-replicator.ts +41 -15
  117. package/src/automerge/heads-store.ts +42 -3
  118. package/src/automerge/index.ts +1 -1
  119. package/src/automerge/leveldb-storage-adapter.ts +11 -11
  120. package/src/automerge/mesh-echo-replicator-connection.ts +12 -8
  121. package/src/automerge/mesh-echo-replicator.ts +15 -11
  122. package/src/automerge/storage-adapter.test.ts +1 -1
  123. package/src/common/space-id.ts +1 -1
  124. package/src/db-host/automerge-data-source.test.ts +299 -0
  125. package/src/db-host/automerge-data-source.ts +186 -0
  126. package/src/db-host/data-service.ts +25 -26
  127. package/src/db-host/database-root.ts +2 -2
  128. package/src/db-host/documents-synchronizer.test.ts +143 -14
  129. package/src/db-host/documents-synchronizer.ts +61 -45
  130. package/src/db-host/echo-host.ts +275 -93
  131. package/src/db-host/index.ts +1 -0
  132. package/src/db-host/local-queue-service.ts +127 -0
  133. package/src/db-host/query-service.ts +30 -98
  134. package/src/db-host/queue-data-source.ts +159 -0
  135. package/src/db-host/queue-service.test.ts +145 -0
  136. package/src/db-host/space-state-manager.ts +7 -3
  137. package/src/db-host/stub.ts +33 -0
  138. package/src/edge/echo-edge-replicator.test.ts +12 -10
  139. package/src/edge/echo-edge-replicator.ts +144 -58
  140. package/src/filter/filter-match.test.ts +68 -32
  141. package/src/filter/filter-match.ts +184 -20
  142. package/src/metadata/metadata-store.ts +11 -8
  143. package/src/pipeline/pipeline-stress.test.ts +1 -1
  144. package/src/pipeline/pipeline.test.ts +2 -2
  145. package/src/pipeline/pipeline.ts +9 -7
  146. package/src/query/errors.ts +3 -1
  147. package/src/query/plan.ts +82 -8
  148. package/src/query/query-executor.ts +1027 -163
  149. package/src/query/query-planner.test.ts +993 -81
  150. package/src/query/query-planner.ts +467 -27
  151. package/src/space/admission-discovery-extension.ts +3 -3
  152. package/src/space/auth.ts +6 -6
  153. package/src/space/control-pipeline.test.ts +5 -4
  154. package/src/space/control-pipeline.ts +16 -13
  155. package/src/space/space-manager.browser.test.ts +1 -1
  156. package/src/space/space-manager.ts +16 -20
  157. package/src/space/space-protocol.browser.test.ts +15 -14
  158. package/src/space/space-protocol.test.ts +15 -14
  159. package/src/space/space-protocol.ts +22 -18
  160. package/src/space/space.test.ts +3 -3
  161. package/src/space/space.ts +11 -11
  162. package/src/testing/index.ts +0 -2
  163. package/src/testing/test-agent-builder.ts +3 -3
  164. package/src/testing/test-network-adapter.ts +16 -3
  165. package/src/testing/test-replicator.ts +23 -18
  166. package/src/util.ts +7 -3
  167. package/dist/lib/browser/chunk-ANZAS5CC.mjs +0 -126
  168. package/dist/lib/browser/chunk-ANZAS5CC.mjs.map +0 -7
  169. package/dist/lib/browser/chunk-CGS2ULMK.mjs +0 -11
  170. package/dist/lib/browser/chunk-CGS2ULMK.mjs.map +0 -7
  171. package/dist/lib/browser/chunk-GBFX5J5B.mjs.map +0 -7
  172. package/dist/lib/browser/index.mjs +0 -4743
  173. package/dist/lib/browser/index.mjs.map +0 -7
  174. package/dist/lib/browser/meta.json +0 -1
  175. package/dist/lib/browser/testing/index.mjs.map +0 -7
  176. package/dist/lib/node-esm/chunk-2SAZ7CCF.mjs +0 -126
  177. package/dist/lib/node-esm/chunk-2SAZ7CCF.mjs.map +0 -7
  178. package/dist/lib/node-esm/chunk-FQFKWA3X.mjs +0 -2067
  179. package/dist/lib/node-esm/chunk-FQFKWA3X.mjs.map +0 -7
  180. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
  181. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +0 -7
  182. package/dist/lib/node-esm/filter/index.mjs +0 -11
  183. package/dist/lib/node-esm/filter/index.mjs.map +0 -7
  184. package/dist/lib/node-esm/index.mjs +0 -4743
  185. package/dist/lib/node-esm/index.mjs.map +0 -7
  186. package/dist/lib/node-esm/meta.json +0 -1
  187. package/dist/lib/node-esm/testing/index.mjs +0 -742
  188. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  189. package/dist/types/src/db-host/documents-iterator.d.ts +0 -7
  190. package/dist/types/src/db-host/documents-iterator.d.ts.map +0 -1
  191. package/dist/types/src/testing/test-data.d.ts +0 -18
  192. package/dist/types/src/testing/test-data.d.ts.map +0 -1
  193. package/dist/types/src/testing/test-schema.d.ts +0 -37
  194. package/dist/types/src/testing/test-schema.d.ts.map +0 -1
  195. package/src/db-host/documents-iterator.ts +0 -74
  196. package/src/testing/test-data.ts +0 -127
  197. package/src/testing/test-schema.ts +0 -53
  198. /package/dist/lib/{browser → neutral}/filter/index.mjs.map +0 -0
@@ -10,24 +10,8 @@ var valueEncoding = createCodecEncoding(codec);
10
10
  import { invariant } from "@dxos/invariant";
11
11
  var __dxlog_file = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/common/feeds.ts";
12
12
  var createMappedFeedWriter = (mapper, writer) => {
13
- invariant(mapper, void 0, {
14
- F: __dxlog_file,
15
- L: 16,
16
- S: void 0,
17
- A: [
18
- "mapper",
19
- ""
20
- ]
21
- });
22
- invariant(writer, void 0, {
23
- F: __dxlog_file,
24
- L: 17,
25
- S: void 0,
26
- A: [
27
- "writer",
28
- ""
29
- ]
30
- });
13
+ invariant(mapper, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 8, S: void 0, A: ["mapper", ""] });
14
+ invariant(writer, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 9, S: void 0, A: ["writer", ""] });
31
15
  return {
32
16
  write: async (data, options) => await writer.write(await mapper(data), options)
33
17
  };
@@ -61,13 +45,13 @@ import { DataCorruptionError, STORAGE_VERSION } from "@dxos/protocols";
61
45
  import { schema as schema2 } from "@dxos/protocols/proto";
62
46
  import { Invitation, SpaceState } from "@dxos/protocols/proto/dxos/client/services";
63
47
  import { ComplexMap as ComplexMap2, arrayToBuffer, forEachAsync, isNonNullable } from "@dxos/util";
48
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/metadata/metadata-store.ts";
64
49
  function _ts_decorate(decorators, target, key, desc) {
65
50
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
66
51
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
67
52
  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;
68
53
  return c > 3 && r && Object.defineProperty(target, key, r), r;
69
54
  }
70
- var __dxlog_file2 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/metadata/metadata-store.ts";
71
55
  var EXPIRED_INVITATION_CLEANUP_INTERVAL = 60 * 60 * 1e3;
72
56
  var emptyEchoMetadata = () => ({
73
57
  version: STORAGE_VERSION,
@@ -79,15 +63,16 @@ var emptyLargeSpaceMetadata = () => ({});
79
63
  var EchoMetadata = schema2.getCodecForType("dxos.echo.metadata.EchoMetadata");
80
64
  var LargeSpaceMetadata = schema2.getCodecForType("dxos.echo.metadata.LargeSpaceMetadata");
81
65
  var MetadataStore = class {
66
+ _metadata = emptyEchoMetadata();
67
+ _spaceLargeMetadata = new ComplexMap2(PublicKey2.hash);
68
+ _metadataFile = void 0;
69
+ update = new Event();
70
+ _invitationCleanupCtx = new Context(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 35 });
71
+ /**
72
+ * @internal
73
+ */
74
+ _directory;
82
75
  constructor(directory) {
83
- this._metadata = emptyEchoMetadata();
84
- this._spaceLargeMetadata = new ComplexMap2(PublicKey2.hash);
85
- this._metadataFile = void 0;
86
- this.update = new Event();
87
- this._invitationCleanupCtx = new Context(void 0, {
88
- F: __dxlog_file2,
89
- L: 55
90
- });
91
76
  this._directory = directory;
92
77
  }
93
78
  get metadata() {
@@ -115,22 +100,22 @@ var MetadataStore = class {
115
100
  size: dataSize,
116
101
  checksum,
117
102
  name: file.filename
118
- }, {
119
- F: __dxlog_file2,
120
- L: 91,
121
- S: this,
122
- C: (f, a) => f(...a)
123
- });
103
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 63, S: this });
124
104
  if (fileLength < dataSize + 8) {
125
- throw new DataCorruptionError("Metadata size is smaller than expected.", {
126
- fileLength,
127
- dataSize
105
+ throw new DataCorruptionError({
106
+ message: "Metadata size is smaller than expected.",
107
+ context: {
108
+ fileLength,
109
+ dataSize
110
+ }
128
111
  });
129
112
  }
130
113
  const data = await file.read(8, dataSize);
131
114
  const calculatedChecksum = CRC32.buf(data);
132
115
  if (calculatedChecksum !== checksum) {
133
- throw new DataCorruptionError("Metadata checksum is invalid.");
116
+ throw new DataCorruptionError({
117
+ message: "Metadata checksum is invalid."
118
+ });
134
119
  }
135
120
  return codec2.decode(data);
136
121
  } finally {
@@ -151,12 +136,7 @@ var MetadataStore = class {
151
136
  log("saved", {
152
137
  size: encoded.length,
153
138
  checksum
154
- }, {
155
- F: __dxlog_file2,
156
- L: 126,
157
- S: this,
158
- C: (f, a) => f(...a)
159
- });
139
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 100, S: this });
160
140
  }
161
141
  async close() {
162
142
  await this._invitationCleanupCtx.dispose();
@@ -184,12 +164,7 @@ var MetadataStore = class {
184
164
  } catch (err) {
185
165
  log.error("failed to load metadata", {
186
166
  err
187
- }, {
188
- F: __dxlog_file2,
189
- L: 158,
190
- S: this,
191
- C: (f, a) => f(...a)
192
- });
167
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 129, S: this });
193
168
  this._metadata = emptyEchoMetadata();
194
169
  }
195
170
  await forEachAsync([
@@ -201,12 +176,7 @@ var MetadataStore = class {
201
176
  } catch (err) {
202
177
  log.error("failed to load space large metadata", {
203
178
  err
204
- }, {
205
- F: __dxlog_file2,
206
- L: 170,
207
- S: this,
208
- C: (f, a) => f(...a)
209
- });
179
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 141, S: this });
210
180
  }
211
181
  });
212
182
  scheduleTaskInterval(this._invitationCleanupCtx, async () => {
@@ -238,12 +208,7 @@ var MetadataStore = class {
238
208
  } catch (err) {
239
209
  log.error("failed to load space large metadata", {
240
210
  err
241
- }, {
242
- F: __dxlog_file2,
243
- L: 212,
244
- S: this,
245
- C: (f, a) => f(...a)
246
- });
211
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 174, S: this });
247
212
  }
248
213
  }
249
214
  async _saveSpaceLargeMetadata(key) {
@@ -259,15 +224,7 @@ var MetadataStore = class {
259
224
  return this._metadata.identity.haloSpace;
260
225
  }
261
226
  const space = this.spaces.find((space2) => space2.key.equals(spaceKey));
262
- invariant2(space, "Space not found", {
263
- F: __dxlog_file2,
264
- L: 234,
265
- S: this,
266
- A: [
267
- "space",
268
- "'Space not found'"
269
- ]
270
- });
227
+ invariant2(space, "Space not found", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 193, S: this, A: ["space", "'Space not found'"] });
271
228
  return space;
272
229
  }
273
230
  hasSpace(spaceKey) {
@@ -289,12 +246,7 @@ var MetadataStore = class {
289
246
  * Clears storage - doesn't work for now.
290
247
  */
291
248
  async clear() {
292
- log("clearing all metadata", void 0, {
293
- F: __dxlog_file2,
294
- L: 262,
295
- S: this,
296
- C: (f, a) => f(...a)
297
- });
249
+ log("clearing all metadata", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 215, S: this });
298
250
  await this._directory.delete();
299
251
  this._metadata = emptyEchoMetadata();
300
252
  }
@@ -302,15 +254,7 @@ var MetadataStore = class {
302
254
  return this._metadata.identity;
303
255
  }
304
256
  async setIdentityRecord(record) {
305
- invariant2(!this._metadata.identity, "Cannot overwrite existing identity in metadata", {
306
- F: __dxlog_file2,
307
- L: 272,
308
- S: this,
309
- A: [
310
- "!this._metadata.identity",
311
- "'Cannot overwrite existing identity in metadata'"
312
- ]
313
- });
257
+ invariant2(!this._metadata.identity, "Cannot overwrite existing identity in metadata", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 223, S: this, A: ["!this._metadata.identity", "'Cannot overwrite existing identity in metadata'"] });
314
258
  this._metadata.identity = record;
315
259
  await this._save();
316
260
  await this.flush();
@@ -332,15 +276,7 @@ var MetadataStore = class {
332
276
  await this.flush();
333
277
  }
334
278
  async addSpace(record) {
335
- invariant2(!(this._metadata.spaces ?? []).find((space) => space.key.equals(record.key)), "Cannot overwrite existing space in metadata", {
336
- F: __dxlog_file2,
337
- L: 300,
338
- S: this,
339
- A: [
340
- "!(this._metadata.spaces ?? []).find((space) => space.key.equals(record.key))",
341
- "'Cannot overwrite existing space in metadata'"
342
- ]
343
- });
279
+ invariant2(!(this._metadata.spaces ?? []).find((space) => space.key.equals(record.key)), "Cannot overwrite existing space in metadata", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 245, S: this, A: ["!(this._metadata.spaces ?? []).find((space)=>space.key.equals(record.key))", "'Cannot overwrite existing space in metadata'"] });
344
280
  (this._metadata.spaces ??= []).push(record);
345
281
  await this._save();
346
282
  await this.flush();
@@ -409,13 +345,13 @@ import { Event as Event2 } from "@dxos/async";
409
345
  import { timed } from "@dxos/debug";
410
346
  import { log as log2 } from "@dxos/log";
411
347
  import { Timeframe } from "@dxos/timeframe";
348
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/pipeline/timeframe-clock.ts";
412
349
  function _ts_decorate2(decorators, target, key, desc) {
413
350
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
414
351
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
415
352
  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;
416
353
  return c > 3 && r && Object.defineProperty(target, key, r), r;
417
354
  }
418
- var __dxlog_file3 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/pipeline/timeframe-clock.ts";
419
355
  var mapTimeframeToFeedIndexes = (timeframe) => timeframe.frames().map(([feedKey, index]) => ({
420
356
  feedKey,
421
357
  index
@@ -429,9 +365,11 @@ var startAfter = (timeframe) => timeframe.frames().map(([feedKey, index]) => ({
429
365
  index: index + 1
430
366
  }));
431
367
  var TimeframeClock = class {
368
+ _timeframe;
369
+ update = new Event2();
370
+ _pendingTimeframe;
432
371
  constructor(_timeframe = new Timeframe()) {
433
372
  this._timeframe = _timeframe;
434
- this.update = new Event2();
435
373
  this._pendingTimeframe = _timeframe;
436
374
  }
437
375
  /**
@@ -472,23 +410,13 @@ var TimeframeClock = class {
472
410
  log2("waitUntilReached", {
473
411
  target,
474
412
  current: this._timeframe
475
- }, {
476
- F: __dxlog_file3,
477
- L: 70,
478
- S: this,
479
- C: (f, a) => f(...a)
480
- });
413
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 69, S: this });
481
414
  await this.update.waitForCondition(() => {
482
415
  log2("check if reached", {
483
416
  target,
484
417
  current: this._timeframe,
485
418
  deps: Timeframe.dependencies(target, this._timeframe)
486
- }, {
487
- F: __dxlog_file3,
488
- L: 72,
489
- S: this,
490
- C: (f, a) => f(...a)
491
- });
419
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 74, S: this });
492
420
  return Timeframe.dependencies(target, this._timeframe).isEmpty();
493
421
  });
494
422
  }
@@ -498,7 +426,7 @@ _ts_decorate2([
498
426
  ], TimeframeClock.prototype, "waitUntilReached", null);
499
427
 
500
428
  // src/pipeline/pipeline.ts
501
- import { Event as Event3, sleepWithContext, synchronized as synchronized2, Trigger } from "@dxos/async";
429
+ import { Event as Event3, Trigger, sleepWithContext, synchronized as synchronized2 } from "@dxos/async";
502
430
  import { Context as Context2, rejectOnDispose } from "@dxos/context";
503
431
  import { failUndefined } from "@dxos/debug";
504
432
  import { FeedSetIterator } from "@dxos/feed-store";
@@ -516,48 +444,54 @@ var createMessageSelector = (timeframeClock) => {
516
444
  return (messages) => {
517
445
  for (let i = 0; i < messages.length; i++) {
518
446
  const { data: { timeframe } } = messages[i];
519
- invariant3(timeframe, void 0, {
520
- F: __dxlog_file4,
521
- L: 25,
522
- S: void 0,
523
- A: [
524
- "timeframe",
525
- ""
526
- ]
527
- });
447
+ invariant3(timeframe, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 16, S: void 0, A: ["timeframe", ""] });
528
448
  if (!timeframeClock.hasGaps(timeframe)) {
529
449
  return i;
530
450
  }
531
451
  }
532
- log3("Skipping...", void 0, {
533
- F: __dxlog_file4,
534
- L: 33,
535
- S: void 0,
536
- C: (f, a) => f(...a)
537
- });
452
+ log3("Skipping...", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 22, S: void 0 });
538
453
  };
539
454
  };
540
455
 
541
456
  // src/pipeline/pipeline.ts
457
+ var __dxlog_file5 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/pipeline/pipeline.ts";
542
458
  function _ts_decorate3(decorators, target, key, desc) {
543
459
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
544
460
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
545
461
  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;
546
462
  return c > 3 && r && Object.defineProperty(target, key, r), r;
547
463
  }
548
- var __dxlog_file5 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/pipeline/pipeline.ts";
549
464
  var PipelineState = class {
465
+ _feeds;
466
+ _timeframeClock;
467
+ /**
468
+ * @internal
469
+ */
470
+ _ctx = new Context2(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 29 });
471
+ // TODO(dmaretskyi): Remove?. Avoid accessing `_timeframeClock` before constructor initialization.
472
+ get timeframeUpdate() {
473
+ return this._timeframeClock.update;
474
+ }
475
+ stalled = new Event3();
476
+ /**
477
+ * @internal
478
+ */
479
+ _startTimeframe = new Timeframe2();
480
+ /**
481
+ * Target timeframe we are waiting to reach.
482
+ */
483
+ _targetTimeframe;
484
+ /**
485
+ * @internal
486
+ */
487
+ _reachedTargetPromise;
488
+ /**
489
+ * @internal
490
+ */
491
+ _reachedTarget = false;
550
492
  constructor(_feeds, _timeframeClock) {
551
493
  this._feeds = _feeds;
552
494
  this._timeframeClock = _timeframeClock;
553
- this._ctx = new Context2(void 0, {
554
- F: __dxlog_file5,
555
- L: 41
556
- });
557
- this.timeframeUpdate = this._timeframeClock.update;
558
- this.stalled = new Event3();
559
- this._startTimeframe = new Timeframe2();
560
- this._reachedTarget = false;
561
495
  }
562
496
  /**
563
497
  * Latest theoretical timeframe based on the last mutation in each feed.
@@ -601,20 +535,12 @@ var PipelineState = class {
601
535
  *
602
536
  * @param timeout Timeout in milliseconds to specify the maximum wait time.
603
537
  */
604
- async waitUntilReachedTargetTimeframe({ ctx = new Context2(void 0, {
605
- F: __dxlog_file5,
606
- L: 129
607
- }), timeout, breakOnStall = true } = {}) {
538
+ async waitUntilReachedTargetTimeframe({ ctx = new Context2(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 91 }), timeout, breakOnStall = true } = {}) {
608
539
  log4("waitUntilReachedTargetTimeframe", {
609
540
  timeout,
610
541
  current: this.timeframe,
611
542
  target: this.targetTimeframe
612
- }, {
613
- F: __dxlog_file5,
614
- L: 133,
615
- S: this,
616
- C: (f, a) => f(...a)
617
- });
543
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 92, S: this });
618
544
  this._reachedTargetPromise ??= Promise.race([
619
545
  this._timeframeClock.update.waitForCondition(() => {
620
546
  return Timeframe2.dependencies(this.targetTimeframe, this.timeframe).isEmpty();
@@ -641,12 +567,7 @@ var PipelineState = class {
641
567
  current: this.timeframe,
642
568
  target: this.targetTimeframe,
643
569
  dependencies: Timeframe2.dependencies(this.targetTimeframe, this.timeframe)
644
- }, {
645
- F: __dxlog_file5,
646
- L: 161,
647
- S: this,
648
- C: (f, a) => f(...a)
649
- });
570
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 118, S: this });
650
571
  })
651
572
  ]);
652
573
  } else {
@@ -655,34 +576,28 @@ var PipelineState = class {
655
576
  }
656
577
  };
657
578
  var Pipeline = class {
658
- constructor() {
659
- this._timeframeClock = new TimeframeClock(new Timeframe2());
660
- this._feeds = new ComplexMap3(PublicKey3.hash);
661
- // External state accessor.
662
- this._state = new PipelineState(this._feeds, this._timeframeClock);
663
- // Waits for the message consumer to process the message and yield control back to the pipeline.
664
- this._processingTrigger = new Trigger().wake();
665
- this._pauseTrigger = new Trigger().wake();
666
- // Pending downloads.
667
- this._downloads = new ComplexMap3((value) => PublicKey3.hash(value.key));
668
- this._isStopping = false;
669
- this._isStarted = false;
670
- this._isBeingConsumed = false;
671
- this._isPaused = false;
672
- }
579
+ _timeframeClock = new TimeframeClock(new Timeframe2());
580
+ _feeds = new ComplexMap3(PublicKey3.hash);
581
+ // External state accessor.
582
+ _state = new PipelineState(this._feeds, this._timeframeClock);
583
+ // Waits for the message consumer to process the message and yield control back to the pipeline.
584
+ _processingTrigger = new Trigger().wake();
585
+ _pauseTrigger = new Trigger().wake();
586
+ // Pending downloads.
587
+ _downloads = new ComplexMap3((value) => PublicKey3.hash(value.key));
588
+ // Inbound feed stream.
589
+ _feedSetIterator;
590
+ // Outbound feed writer.
591
+ _writer;
592
+ _isStopping = false;
593
+ _isStarted = false;
594
+ _isBeingConsumed = false;
595
+ _isPaused = false;
673
596
  get state() {
674
597
  return this._state;
675
598
  }
676
599
  get writer() {
677
- invariant4(this._writer, "Writer not set.", {
678
- F: __dxlog_file5,
679
- L: 243,
680
- S: this,
681
- A: [
682
- "this._writer",
683
- "'Writer not set.'"
684
- ]
685
- });
600
+ invariant4(this._writer, "Writer not set.", { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 184, S: this, A: ["this._writer", "'Writer not set.'"] });
686
601
  return this._writer;
687
602
  }
688
603
  hasFeed(feedKey) {
@@ -703,54 +618,20 @@ var Pipeline = class {
703
618
  }
704
619
  }
705
620
  setWriteFeed(feed) {
706
- invariant4(!this._writer, "Writer already set.", {
707
- F: __dxlog_file5,
708
- L: 270,
709
- S: this,
710
- A: [
711
- "!this._writer",
712
- "'Writer already set.'"
713
- ]
714
- });
715
- invariant4(feed.properties.writable, "Feed must be writable.", {
716
- F: __dxlog_file5,
717
- L: 271,
718
- S: this,
719
- A: [
720
- "feed.properties.writable",
721
- "'Feed must be writable.'"
722
- ]
723
- });
621
+ invariant4(!this._writer, "Writer already set.", { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 205, S: this, A: ["!this._writer", "'Writer already set.'"] });
622
+ invariant4(feed.properties.writable, "Feed must be writable.", { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 206, S: this, A: ["feed.properties.writable", "'Feed must be writable.'"] });
724
623
  this._writer = createMappedFeedWriter((payload) => ({
725
624
  timeframe: this._timeframeClock.timeframe,
726
625
  payload
727
626
  }), feed.createFeedWriter());
728
627
  }
729
628
  async start() {
730
- invariant4(!this._isStarted, "Pipeline is already started.", {
731
- F: __dxlog_file5,
732
- L: 284,
733
- S: this,
734
- A: [
735
- "!this._isStarted",
736
- "'Pipeline is already started.'"
737
- ]
738
- });
739
- log4("starting...", void 0, {
740
- F: __dxlog_file5,
741
- L: 285,
742
- S: this,
743
- C: (f, a) => f(...a)
744
- });
629
+ invariant4(!this._isStarted, "Pipeline is already started.", { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 213, S: this, A: ["!this._isStarted", "'Pipeline is already started.'"] });
630
+ log4("starting...", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 214, S: this });
745
631
  await this._initIterator();
746
632
  await this._feedSetIterator.open();
747
633
  this._isStarted = true;
748
- log4("started", void 0, {
749
- F: __dxlog_file5,
750
- L: 289,
751
- S: this,
752
- C: (f, a) => f(...a)
753
- });
634
+ log4("started", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 218, S: this });
754
635
  if (!this._isPaused) {
755
636
  for (const feed of this._feeds.values()) {
756
637
  this._setFeedDownloadState(feed);
@@ -758,12 +639,7 @@ var Pipeline = class {
758
639
  }
759
640
  }
760
641
  async stop() {
761
- log4("stopping...", void 0, {
762
- F: __dxlog_file5,
763
- L: 300,
764
- S: this,
765
- C: (f, a) => f(...a)
766
- });
642
+ log4("stopping...", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 226, S: this });
767
643
  this._isStopping = true;
768
644
  for (const [feed, handle] of this._downloads.entries()) {
769
645
  feed.undownload(handle);
@@ -772,34 +648,18 @@ var Pipeline = class {
772
648
  await this._feedSetIterator?.close();
773
649
  await this._processingTrigger.wait();
774
650
  await this._state._ctx.dispose();
775
- this._state._ctx = new Context2(void 0, {
776
- F: __dxlog_file5,
777
- L: 309
778
- });
651
+ this._state._ctx = new Context2(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 235 });
779
652
  this._state._reachedTargetPromise = void 0;
780
653
  this._state._reachedTarget = false;
781
654
  this._isStarted = false;
782
- log4("stopped", void 0, {
783
- F: __dxlog_file5,
784
- L: 313,
785
- S: this,
786
- C: (f, a) => f(...a)
787
- });
655
+ log4("stopped", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 239, S: this });
788
656
  }
789
657
  /**
790
658
  * @param timeframe Timeframe of already processed messages.
791
659
  * The pipeline will start processing messages AFTER this timeframe.
792
660
  */
793
661
  async setCursor(timeframe) {
794
- invariant4(!this._isStarted || this._isPaused, "Invalid state.", {
795
- F: __dxlog_file5,
796
- L: 322,
797
- S: this,
798
- A: [
799
- "!this._isStarted || this._isPaused",
800
- "'Invalid state.'"
801
- ]
802
- });
662
+ invariant4(!this._isStarted || this._isPaused, "Invalid state.", { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 245, S: this, A: ["!this._isStarted || this._isPaused", "'Invalid state.'"] });
803
663
  this._state._startTimeframe = timeframe;
804
664
  this._timeframeClock.setTimeframe(timeframe);
805
665
  if (this._feedSetIterator) {
@@ -820,15 +680,7 @@ var Pipeline = class {
820
680
  this._isPaused = true;
821
681
  }
822
682
  async unpause() {
823
- invariant4(this._isPaused, "Pipeline is not paused.", {
824
- F: __dxlog_file5,
825
- L: 351,
826
- S: this,
827
- A: [
828
- "this._isPaused",
829
- "'Pipeline is not paused.'"
830
- ]
831
- });
683
+ invariant4(this._isPaused, "Pipeline is not paused.", { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 266, S: this, A: ["this._isPaused", "'Pipeline is not paused.'"] });
832
684
  this._pauseTrigger.wake();
833
685
  this._isPaused = false;
834
686
  for (const feed of this._feeds.values()) {
@@ -840,39 +692,15 @@ var Pipeline = class {
840
692
  * Updates the timeframe clock after the message has bee processed.
841
693
  */
842
694
  async *consume() {
843
- invariant4(!this._isBeingConsumed, "Pipeline is already being consumed.", {
844
- F: __dxlog_file5,
845
- L: 366,
846
- S: this,
847
- A: [
848
- "!this._isBeingConsumed",
849
- "'Pipeline is already being consumed.'"
850
- ]
851
- });
695
+ invariant4(!this._isBeingConsumed, "Pipeline is already being consumed.", { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 277, S: this, A: ["!this._isBeingConsumed", "'Pipeline is already being consumed.'"] });
852
696
  this._isBeingConsumed = true;
853
- invariant4(this._feedSetIterator, "Iterator not initialized.", {
854
- F: __dxlog_file5,
855
- L: 369,
856
- S: this,
857
- A: [
858
- "this._feedSetIterator",
859
- "'Iterator not initialized.'"
860
- ]
861
- });
697
+ invariant4(this._feedSetIterator, "Iterator not initialized.", { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 279, S: this, A: ["this._feedSetIterator", "'Iterator not initialized.'"] });
862
698
  let lastFeedSetIterator = this._feedSetIterator;
863
699
  let iterable = lastFeedSetIterator[Symbol.asyncIterator]();
864
700
  while (!this._isStopping) {
865
701
  await this._pauseTrigger.wait();
866
702
  if (lastFeedSetIterator !== this._feedSetIterator) {
867
- invariant4(this._feedSetIterator, "Iterator not initialized.", {
868
- F: __dxlog_file5,
869
- L: 378,
870
- S: this,
871
- A: [
872
- "this._feedSetIterator",
873
- "'Iterator not initialized.'"
874
- ]
875
- });
703
+ invariant4(this._feedSetIterator, "Iterator not initialized.", { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 286, S: this, A: ["this._feedSetIterator", "'Iterator not initialized.'"] });
876
704
  lastFeedSetIterator = this._feedSetIterator;
877
705
  iterable = lastFeedSetIterator[Symbol.asyncIterator]();
878
706
  }
@@ -899,12 +727,7 @@ var Pipeline = class {
899
727
  feed: feed.key.truncate(),
900
728
  seq,
901
729
  length: feed.length
902
- }, {
903
- F: __dxlog_file5,
904
- L: 407,
905
- S: this,
906
- C: (f, a) => f(...a)
907
- });
730
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 311, S: this });
908
731
  handle = feed.download({
909
732
  start: seq + 1,
910
733
  linear: true
@@ -913,12 +736,7 @@ var Pipeline = class {
913
736
  } else {
914
737
  log4("downloaded", {
915
738
  data
916
- }, {
917
- F: __dxlog_file5,
918
- L: 412,
919
- S: this,
920
- C: (f, a) => f(...a)
921
- });
739
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 323, S: this });
922
740
  }
923
741
  });
924
742
  this._downloads.set(feed, handle);
@@ -932,12 +750,7 @@ var Pipeline = class {
932
750
  log4.warn(`Stalled after ${iterator.options.stallTimeout}ms with ${iterator.size} feeds.`, {
933
751
  currentTimeframe: this._timeframeClock.timeframe,
934
752
  targetTimeframe: this._state.targetTimeframe
935
- }, {
936
- F: __dxlog_file5,
937
- L: 426,
938
- S: this,
939
- C: (f, a) => f(...a)
940
- });
753
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 336, S: this });
941
754
  this._state.stalled.emit();
942
755
  });
943
756
  for (const feed of this._feeds.values()) {
@@ -971,7 +784,13 @@ import { schema as schema3 } from "@dxos/protocols/proto";
971
784
  import { RpcExtension } from "@dxos/teleport";
972
785
  var __dxlog_file6 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/space/auth.ts";
973
786
  var AuthExtension = class extends RpcExtension {
974
- constructor(_authParams) {
787
+ _authProps;
788
+ _ctx = new Context3({
789
+ onError: (err) => {
790
+ log5.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 15, S: this });
791
+ }
792
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 13 });
793
+ constructor(_authProps) {
975
794
  super({
976
795
  requested: {
977
796
  AuthService: schema3.getService("dxos.mesh.teleport.auth.AuthService")
@@ -980,26 +799,14 @@ var AuthExtension = class extends RpcExtension {
980
799
  AuthService: schema3.getService("dxos.mesh.teleport.auth.AuthService")
981
800
  },
982
801
  timeout: 60 * 1e3
983
- }), this._authParams = _authParams, this._ctx = new Context3({
984
- onError: (err) => {
985
- log5.catch(err, void 0, {
986
- F: __dxlog_file6,
987
- L: 28,
988
- S: this,
989
- C: (f, a) => f(...a)
990
- });
991
- }
992
- }, {
993
- F: __dxlog_file6,
994
- L: 26
995
- });
802
+ }), this._authProps = _authProps;
996
803
  }
997
804
  async getHandlers() {
998
805
  return {
999
806
  AuthService: {
1000
807
  authenticate: async ({ challenge }) => {
1001
808
  try {
1002
- const credential = await this._authParams.provider(challenge);
809
+ const credential = await this._authProps.provider(challenge);
1003
810
  if (!credential) {
1004
811
  throw new Error("auth rejected");
1005
812
  }
@@ -1007,12 +814,7 @@ var AuthExtension = class extends RpcExtension {
1007
814
  credential
1008
815
  };
1009
816
  } catch (err) {
1010
- log5.error("failed to generate auth credentials", err, {
1011
- F: __dxlog_file6,
1012
- L: 55,
1013
- S: this,
1014
- C: (f, a) => f(...a)
1015
- });
817
+ log5.error("failed to generate auth credentials", err, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 42, S: this });
1016
818
  throw new Error("auth rejected");
1017
819
  }
1018
820
  }
@@ -1027,35 +829,14 @@ var AuthExtension = class extends RpcExtension {
1027
829
  const { credential } = await this.rpc.AuthService.authenticate({
1028
830
  challenge
1029
831
  });
1030
- invariant5(credential?.length > 0, "invalid credential", {
1031
- F: __dxlog_file6,
1032
- L: 69,
1033
- S: this,
1034
- A: [
1035
- "credential?.length > 0",
1036
- "'invalid credential'"
1037
- ]
1038
- });
1039
- const success = await this._authParams.verifier(challenge, credential);
1040
- invariant5(success, "credential not verified", {
1041
- F: __dxlog_file6,
1042
- L: 71,
1043
- S: this,
1044
- A: [
1045
- "success",
1046
- "'credential not verified'"
1047
- ]
1048
- });
1049
- runInContext(this._ctx, () => this._authParams.onAuthSuccess());
832
+ invariant5(credential?.length > 0, "invalid credential", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 57, S: this, A: ["credential?.length > 0", "'invalid credential'"] });
833
+ const success = await this._authProps.verifier(challenge, credential);
834
+ invariant5(success, "credential not verified", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 59, S: this, A: ["success", "'credential not verified'"] });
835
+ runInContext(this._ctx, () => this._authProps.onAuthSuccess());
1050
836
  } catch (err) {
1051
- log5("auth failed", err, {
1052
- F: __dxlog_file6,
1053
- L: 74,
1054
- S: this,
1055
- C: (f, a) => f(...a)
1056
- });
837
+ log5("auth failed", err, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 62, S: this });
1057
838
  this.close();
1058
- this._authParams.onAuthFailure();
839
+ this._authProps.onAuthFailure();
1059
840
  }
1060
841
  });
1061
842
  }
@@ -1070,7 +851,7 @@ var AuthExtension = class extends RpcExtension {
1070
851
  };
1071
852
 
1072
853
  // src/space/space.ts
1073
- import { Event as Event4, scheduleMicroTask, synchronized as synchronized3, trackLeaks as trackLeaks2 } from "@dxos/async";
854
+ import { Event as Event4, scheduleMicroTask as scheduleMicroTask2, synchronized as synchronized3, trackLeaks as trackLeaks2 } from "@dxos/async";
1074
855
  import { Resource } from "@dxos/context";
1075
856
  import { invariant as invariant6 } from "@dxos/invariant";
1076
857
  import { log as log7, logInfo } from "@dxos/log";
@@ -1079,7 +860,7 @@ import { trace as trace2 } from "@dxos/tracing";
1079
860
  import { Callback as Callback2 } from "@dxos/util";
1080
861
 
1081
862
  // src/space/control-pipeline.ts
1082
- import { DeferredTask, sleepWithContext as sleepWithContext2, trackLeaks } from "@dxos/async";
863
+ import { DeferredTask, scheduleMicroTask, sleepWithContext as sleepWithContext2, trackLeaks } from "@dxos/async";
1083
864
  import { Context as Context4 } from "@dxos/context";
1084
865
  import { SpaceStateMachine } from "@dxos/credentials";
1085
866
  import { PublicKey as PublicKey4 } from "@dxos/keys";
@@ -1088,30 +869,36 @@ import { AdmittedFeed } from "@dxos/protocols/proto/dxos/halo/credentials";
1088
869
  import { Timeframe as Timeframe3 } from "@dxos/timeframe";
1089
870
  import { TimeSeriesCounter, TimeUsageCounter, trace } from "@dxos/tracing";
1090
871
  import { Callback, tracer } from "@dxos/util";
872
+ var __dxlog_file7 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/space/control-pipeline.ts";
1091
873
  function _ts_decorate4(decorators, target, key, desc) {
1092
874
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1093
875
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1094
876
  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;
1095
877
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1096
878
  }
1097
- var __dxlog_file7 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/space/control-pipeline.ts";
1098
879
  var TIMEFRAME_SAVE_DEBOUNCE_INTERVAL = 500;
1099
880
  var CONTROL_PIPELINE_SNAPSHOT_DELAY = 1e4;
1100
881
  var USE_SNAPSHOTS = true;
1101
882
  var ControlPipeline = class {
883
+ _ctx = new Context4(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 24 });
884
+ _pipeline;
885
+ _spaceStateMachine;
886
+ _spaceKey;
887
+ _metadata;
888
+ _targetTimeframe;
889
+ _lastTimeframeSaveTime = Date.now();
890
+ onFeedAdmitted = new Callback();
891
+ onMemberRoleChanged;
892
+ onCredentialProcessed;
893
+ onDelegatedInvitation;
894
+ onDelegatedInvitationRemoved;
895
+ _usage = new TimeUsageCounter();
896
+ _mutations = new TimeSeriesCounter();
897
+ _snapshotTask = new DeferredTask(this._ctx, async () => {
898
+ await sleepWithContext2(this._ctx, CONTROL_PIPELINE_SNAPSHOT_DELAY);
899
+ await this._saveSnapshot();
900
+ });
1102
901
  constructor({ spaceKey, genesisFeed, feedProvider, metadataStore }) {
1103
- this._ctx = new Context4(void 0, {
1104
- F: __dxlog_file7,
1105
- L: 47
1106
- });
1107
- this._lastTimeframeSaveTime = Date.now();
1108
- this.onFeedAdmitted = new Callback();
1109
- this._usage = new TimeUsageCounter();
1110
- this._mutations = new TimeSeriesCounter();
1111
- this._snapshotTask = new DeferredTask(this._ctx, async () => {
1112
- await sleepWithContext2(this._ctx, CONTROL_PIPELINE_SNAPSHOT_DELAY);
1113
- await this._saveSnapshot();
1114
- });
1115
902
  this._spaceKey = spaceKey;
1116
903
  this._metadata = metadataStore;
1117
904
  this._pipeline = new Pipeline();
@@ -1120,26 +907,19 @@ var ControlPipeline = class {
1120
907
  this._spaceStateMachine.onFeedAdmitted.set(async (info) => {
1121
908
  log6("feed admitted", {
1122
909
  key: info.key
1123
- }, {
1124
- F: __dxlog_file7,
1125
- L: 82,
1126
- S: this,
1127
- C: (f, a) => f(...a)
1128
- });
910
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 50, S: this });
1129
911
  if (info.assertion.designation === AdmittedFeed.Designation.CONTROL && !info.key.equals(genesisFeed.key)) {
1130
- queueMicrotask(async () => {
912
+ scheduleMicroTask(this._ctx, async () => {
1131
913
  try {
1132
914
  const feed = await feedProvider(info.key);
915
+ if (this._ctx.disposed) {
916
+ return;
917
+ }
1133
918
  if (!this._pipeline.hasFeed(feed.key)) {
1134
919
  await this._pipeline.addFeed(feed);
1135
920
  }
1136
921
  } catch (err) {
1137
- log6.catch(err, void 0, {
1138
- F: __dxlog_file7,
1139
- L: 93,
1140
- S: this,
1141
- C: (f, a) => f(...a)
1142
- });
922
+ log6.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 65, S: this });
1143
923
  }
1144
924
  });
1145
925
  }
@@ -1160,40 +940,22 @@ var ControlPipeline = class {
1160
940
  await this._pipeline.addFeed(feed);
1161
941
  this._pipeline.setWriteFeed(feed);
1162
942
  }
1163
- async start() {
943
+ async start(ctx) {
1164
944
  const snapshot = this._metadata.getSpaceControlPipelineSnapshot(this._spaceKey);
1165
945
  log6("load snapshot", {
1166
946
  key: this._spaceKey,
1167
947
  present: !!snapshot,
1168
948
  tf: snapshot?.timeframe
1169
- }, {
1170
- F: __dxlog_file7,
1171
- L: 123,
1172
- S: this,
1173
- C: (f, a) => f(...a)
1174
- });
949
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 88, S: this });
1175
950
  if (USE_SNAPSHOTS && snapshot) {
1176
951
  await this._processSnapshot(snapshot);
1177
952
  }
1178
- log6("starting...", void 0, {
1179
- F: __dxlog_file7,
1180
- L: 128,
1181
- S: this,
1182
- C: (f, a) => f(...a)
1183
- });
953
+ log6("starting...", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 96, S: this });
1184
954
  setTimeout(async () => {
1185
- void this._consumePipeline(new Context4(void 0, {
1186
- F: __dxlog_file7,
1187
- L: 130
1188
- }));
955
+ void this._consumePipeline(ctx);
1189
956
  });
1190
957
  await this._pipeline.start();
1191
- log6("started", void 0, {
1192
- F: __dxlog_file7,
1193
- L: 134,
1194
- S: this,
1195
- C: (f, a) => f(...a)
1196
- });
958
+ log6("started", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 101, S: this });
1197
959
  }
1198
960
  async _processSnapshot(snapshot) {
1199
961
  await this._pipeline.setCursor(snapshot.timeframe);
@@ -1205,12 +967,7 @@ var ControlPipeline = class {
1205
967
  if (!result) {
1206
968
  log6.warn("credential processing failed from snapshot", {
1207
969
  message
1208
- }, {
1209
- F: __dxlog_file7,
1210
- L: 147,
1211
- S: this,
1212
- C: (f, a) => f(...a)
1213
- });
970
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 111, S: this });
1214
971
  }
1215
972
  }
1216
973
  }
@@ -1227,12 +984,7 @@ var ControlPipeline = class {
1227
984
  log6("save snapshot", {
1228
985
  key: this._spaceKey,
1229
986
  snapshot: getSnapshotLoggerContext(snapshot)
1230
- }, {
1231
- F: __dxlog_file7,
1232
- L: 163,
1233
- S: this,
1234
- C: (f, a) => f(...a)
1235
- });
987
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 127, S: this });
1236
988
  await this._metadata.setSpaceControlPipelineSnapshot(this._spaceKey, snapshot);
1237
989
  }
1238
990
  async _consumePipeline(ctx) {
@@ -1242,12 +994,7 @@ var ControlPipeline = class {
1242
994
  try {
1243
995
  await this._processMessage(ctx, msg);
1244
996
  } catch (err) {
1245
- log6.catch(err, void 0, {
1246
- F: __dxlog_file7,
1247
- L: 176,
1248
- S: this,
1249
- C: (f, a) => f(...a)
1250
- });
997
+ log6.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 140, S: this });
1251
998
  }
1252
999
  span.end();
1253
1000
  }
@@ -1256,12 +1003,7 @@ var ControlPipeline = class {
1256
1003
  log6("processing", {
1257
1004
  key: msg.feedKey,
1258
1005
  seq: msg.seq
1259
- }, {
1260
- F: __dxlog_file7,
1261
- L: 185,
1262
- S: this,
1263
- C: (f, a) => f(...a)
1264
- });
1006
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 146, S: this });
1265
1007
  if (msg.data.payload.credential) {
1266
1008
  const timer = tracer.mark("dxos.echo.pipeline.control");
1267
1009
  const result = await this._spaceStateMachine.process(msg.data.payload.credential.credential, {
@@ -1271,12 +1013,7 @@ var ControlPipeline = class {
1271
1013
  if (!result) {
1272
1014
  log6.warn("processing failed", {
1273
1015
  msg
1274
- }, {
1275
- F: __dxlog_file7,
1276
- L: 194,
1277
- S: this,
1278
- C: (f, a) => f(...a)
1279
- });
1016
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 157, S: this });
1280
1017
  } else {
1281
1018
  await this._noteTargetStateIfNeeded(this._pipeline.state.pendingTimeframe);
1282
1019
  }
@@ -1290,21 +1027,11 @@ var ControlPipeline = class {
1290
1027
  }
1291
1028
  }
1292
1029
  async stop() {
1293
- log6("stopping...", void 0, {
1294
- F: __dxlog_file7,
1295
- L: 214,
1296
- S: this,
1297
- C: (f, a) => f(...a)
1298
- });
1030
+ log6("stopping...", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 174, S: this });
1299
1031
  await this._ctx.dispose();
1300
1032
  await this._pipeline.stop();
1301
1033
  await this._saveTargetTimeframe(this._pipeline.state.timeframe);
1302
- log6("stopped", void 0, {
1303
- F: __dxlog_file7,
1304
- L: 218,
1305
- S: this,
1306
- C: (f, a) => f(...a)
1307
- });
1034
+ log6("stopped", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 178, S: this });
1308
1035
  }
1309
1036
  async _saveTargetTimeframe(timeframe) {
1310
1037
  try {
@@ -1312,15 +1039,15 @@ var ControlPipeline = class {
1312
1039
  await this._metadata.setSpaceControlLatestTimeframe(this._spaceKey, newTimeframe);
1313
1040
  this._targetTimeframe = newTimeframe;
1314
1041
  } catch (err) {
1315
- log6(err, void 0, {
1316
- F: __dxlog_file7,
1317
- L: 227,
1318
- S: this,
1319
- C: (f, a) => f(...a)
1320
- });
1042
+ log6(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 186, S: this });
1321
1043
  }
1322
1044
  }
1323
1045
  };
1046
+ _ts_decorate4([
1047
+ trace.info({
1048
+ spanAttribute: true
1049
+ })
1050
+ ], ControlPipeline.prototype, "_spaceKey", void 0);
1324
1051
  _ts_decorate4([
1325
1052
  trace.metricsCounter()
1326
1053
  ], ControlPipeline.prototype, "_usage", void 0);
@@ -1329,14 +1056,15 @@ _ts_decorate4([
1329
1056
  ], ControlPipeline.prototype, "_mutations", void 0);
1330
1057
  _ts_decorate4([
1331
1058
  trace.span({
1332
- showInBrowserTimeline: true
1059
+ showInBrowserTimeline: true,
1060
+ op: "lifecycle"
1333
1061
  })
1334
1062
  ], ControlPipeline.prototype, "start", null);
1335
1063
  _ts_decorate4([
1336
- trace.span()
1337
- ], ControlPipeline.prototype, "_consumePipeline", null);
1338
- _ts_decorate4([
1339
- trace.span()
1064
+ trace.span({
1065
+ showInBrowserTimeline: true,
1066
+ showInRemoteTracing: false
1067
+ })
1340
1068
  ], ControlPipeline.prototype, "_processMessage", null);
1341
1069
  ControlPipeline = _ts_decorate4([
1342
1070
  trace.resource(),
@@ -1356,27 +1084,27 @@ var getSnapshotLoggerContext = (snapshot) => {
1356
1084
  };
1357
1085
 
1358
1086
  // src/space/space.ts
1087
+ var __dxlog_file8 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space.ts";
1359
1088
  function _ts_decorate5(decorators, target, key, desc) {
1360
1089
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1361
1090
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1362
1091
  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;
1363
1092
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1364
1093
  }
1365
- var __dxlog_file8 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space.ts";
1366
1094
  var Space = class extends Resource {
1095
+ onCredentialProcessed = new Callback2();
1096
+ stateUpdate = new Event4();
1097
+ protocol;
1098
+ _id;
1099
+ _key;
1100
+ _genesisFeedKey;
1101
+ _feedProvider;
1102
+ _controlPipeline;
1103
+ _controlFeed;
1104
+ _dataFeed;
1367
1105
  constructor(params) {
1368
1106
  super();
1369
- this.onCredentialProcessed = new Callback2();
1370
- this.stateUpdate = new Event4();
1371
- invariant6(params.spaceKey && params.feedProvider, void 0, {
1372
- F: __dxlog_file8,
1373
- L: 72,
1374
- S: this,
1375
- A: [
1376
- "params.spaceKey && params.feedProvider",
1377
- ""
1378
- ]
1379
- });
1107
+ invariant6(params.spaceKey && params.feedProvider, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 31, S: this, A: ["params.spaceKey && params.feedProvider", ""] });
1380
1108
  this._id = params.id;
1381
1109
  this._key = params.spaceKey;
1382
1110
  this._genesisFeedKey = params.genesisFeed.key;
@@ -1390,7 +1118,7 @@ var Space = class extends Resource {
1390
1118
  this._controlPipeline.onFeedAdmitted.set(async (info) => {
1391
1119
  const sparse = info.assertion.designation === AdmittedFeed2.Designation.DATA;
1392
1120
  if (!info.key.equals(params.genesisFeed.key)) {
1393
- scheduleMicroTask(this._ctx, async () => {
1121
+ scheduleMicroTask2(this._ctx, async () => {
1394
1122
  await this.protocol.addFeed(await params.feedProvider(info.key, {
1395
1123
  sparse
1396
1124
  }));
@@ -1401,34 +1129,19 @@ var Space = class extends Resource {
1401
1129
  await this.onCredentialProcessed.callIfSet(credential);
1402
1130
  log7("onCredentialProcessed", {
1403
1131
  credential
1404
- }, {
1405
- F: __dxlog_file8,
1406
- L: 99,
1407
- S: this,
1408
- C: (f, a) => f(...a)
1409
- });
1132
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 56, S: this });
1410
1133
  this.stateUpdate.emit();
1411
1134
  });
1412
1135
  this._controlPipeline.onDelegatedInvitation.set(async (invitation) => {
1413
1136
  log7("onDelegatedInvitation", {
1414
1137
  invitation
1415
- }, {
1416
- F: __dxlog_file8,
1417
- L: 103,
1418
- S: this,
1419
- C: (f, a) => f(...a)
1420
- });
1138
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 62, S: this });
1421
1139
  await params.onDelegatedInvitationStatusChange(invitation, true);
1422
1140
  });
1423
1141
  this._controlPipeline.onDelegatedInvitationRemoved.set(async (invitation) => {
1424
1142
  log7("onDelegatedInvitationRemoved", {
1425
1143
  invitation
1426
- }, {
1427
- F: __dxlog_file8,
1428
- L: 107,
1429
- S: this,
1430
- C: (f, a) => f(...a)
1431
- });
1144
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 68, S: this });
1432
1145
  await params.onDelegatedInvitationStatusChange(invitation, false);
1433
1146
  });
1434
1147
  this._controlPipeline.onMemberRoleChanged.set(async (changedMembers) => {
@@ -1437,12 +1150,7 @@ var Space = class extends Resource {
1437
1150
  m.key,
1438
1151
  m.role
1439
1152
  ])
1440
- }), {
1441
- F: __dxlog_file8,
1442
- L: 111,
1443
- S: this,
1444
- C: (f, a) => f(...a)
1445
- });
1153
+ }), { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 74, S: this });
1446
1154
  await params.onMemberRolesChanged(changedMembers);
1447
1155
  });
1448
1156
  this.protocol = params.protocol;
@@ -1472,29 +1180,13 @@ var Space = class extends Resource {
1472
1180
  return this._controlPipeline.pipeline;
1473
1181
  }
1474
1182
  async setControlFeed(feed) {
1475
- invariant6(!this._controlFeed, "Control feed already set.", {
1476
- F: __dxlog_file8,
1477
- L: 155,
1478
- S: this,
1479
- A: [
1480
- "!this._controlFeed",
1481
- "'Control feed already set.'"
1482
- ]
1483
- });
1183
+ invariant6(!this._controlFeed, "Control feed already set.", { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 109, S: this, A: ["!this._controlFeed", "'Control feed already set.'"] });
1484
1184
  this._controlFeed = feed;
1485
1185
  await this._controlPipeline.setWriteFeed(feed);
1486
1186
  return this;
1487
1187
  }
1488
1188
  async setDataFeed(feed) {
1489
- invariant6(!this._dataFeed, "Data feed already set.", {
1490
- F: __dxlog_file8,
1491
- L: 162,
1492
- S: this,
1493
- A: [
1494
- "!this._dataFeed",
1495
- "'Data feed already set.'"
1496
- ]
1497
- });
1189
+ invariant6(!this._dataFeed, "Data feed already set.", { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 115, S: this, A: ["!this._dataFeed", "'Data feed already set.'"] });
1498
1190
  this._dataFeed = feed;
1499
1191
  return this;
1500
1192
  }
@@ -1505,50 +1197,22 @@ var Space = class extends Resource {
1505
1197
  return Array.from(this._controlPipeline.spaceState.feeds.values());
1506
1198
  }
1507
1199
  async _open(ctx) {
1508
- log7("opening...", void 0, {
1509
- F: __dxlog_file8,
1510
- L: 176,
1511
- S: this,
1512
- C: (f, a) => f(...a)
1513
- });
1514
- await this._controlPipeline.start();
1515
- log7("opened", void 0, {
1516
- F: __dxlog_file8,
1517
- L: 181,
1518
- S: this,
1519
- C: (f, a) => f(...a)
1520
- });
1200
+ log7("opening...", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 125, S: this });
1201
+ await this._controlPipeline.start(ctx);
1202
+ log7("opened", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 128, S: this });
1521
1203
  }
1522
- async startProtocol() {
1523
- invariant6(this.isOpen, void 0, {
1524
- F: __dxlog_file8,
1525
- L: 186,
1526
- S: this,
1527
- A: [
1528
- "this.isOpen",
1529
- ""
1530
- ]
1531
- });
1532
- await this.protocol.start();
1204
+ async startProtocol(ctx) {
1205
+ invariant6(this.isOpen, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 131, S: this, A: ["this.isOpen", ""] });
1206
+ await this.protocol.start(ctx);
1533
1207
  await this.protocol.addFeed(await this._feedProvider(this._genesisFeedKey));
1534
1208
  }
1535
- async _close() {
1209
+ async _close(ctx) {
1536
1210
  log7("closing...", {
1537
1211
  key: this._key
1538
- }, {
1539
- F: __dxlog_file8,
1540
- L: 193,
1541
- S: this,
1542
- C: (f, a) => f(...a)
1543
- });
1544
- await this.protocol.stop();
1212
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 136, S: this });
1213
+ await this.protocol.stop(ctx);
1545
1214
  await this._controlPipeline.stop();
1546
- log7("closed", void 0, {
1547
- F: __dxlog_file8,
1548
- L: 199,
1549
- S: this,
1550
- C: (f, a) => f(...a)
1551
- });
1215
+ log7("closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 142, S: this });
1552
1216
  }
1553
1217
  };
1554
1218
  _ts_decorate5([
@@ -1566,7 +1230,9 @@ _ts_decorate5([
1566
1230
  trace2.info()
1567
1231
  ], Space.prototype, "key", null);
1568
1232
  _ts_decorate5([
1569
- trace2.span()
1233
+ trace2.span({
1234
+ op: "lifecycle"
1235
+ })
1570
1236
  ], Space.prototype, "_open", null);
1571
1237
  _ts_decorate5([
1572
1238
  synchronized3
@@ -1587,15 +1253,15 @@ import { schema as schema4 } from "@dxos/protocols/proto";
1587
1253
  import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
1588
1254
  var __dxlog_file9 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/space/admission-discovery-extension.ts";
1589
1255
  var CredentialRetrieverExtension = class extends RpcExtension2 {
1256
+ _request;
1257
+ _onResult;
1258
+ _ctx = new Context5(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 14 });
1590
1259
  constructor(_request, _onResult) {
1591
1260
  super({
1592
1261
  requested: {
1593
1262
  AdmissionDiscoveryService: schema4.getService("dxos.mesh.teleport.AdmissionDiscoveryService")
1594
1263
  }
1595
- }), this._request = _request, this._onResult = _onResult, this._ctx = new Context5(void 0, {
1596
- F: __dxlog_file9,
1597
- L: 26
1598
- });
1264
+ }), this._request = _request, this._onResult = _onResult;
1599
1265
  }
1600
1266
  async getHandlers() {
1601
1267
  return {};
@@ -1619,6 +1285,7 @@ var CredentialRetrieverExtension = class extends RpcExtension2 {
1619
1285
  }
1620
1286
  };
1621
1287
  var CredentialServerExtension = class extends RpcExtension2 {
1288
+ _space;
1622
1289
  constructor(_space) {
1623
1290
  super({
1624
1291
  exposed: {
@@ -1632,7 +1299,12 @@ var CredentialServerExtension = class extends RpcExtension2 {
1632
1299
  getAdmissionCredential: async (request) => {
1633
1300
  const memberInfo = this._space.spaceState.members.get(request.memberKey);
1634
1301
  if (!memberInfo?.credential) {
1635
- throw new ProtocolError("Space member not found.", request);
1302
+ throw new ProtocolError({
1303
+ message: "Space member not found.",
1304
+ context: {
1305
+ ...request
1306
+ }
1307
+ });
1636
1308
  }
1637
1309
  return {
1638
1310
  admissionCredential: memberInfo.credential
@@ -1653,26 +1325,44 @@ import { BlobSync } from "@dxos/teleport-extension-object-sync";
1653
1325
  import { ReplicatorExtension } from "@dxos/teleport-extension-replicator";
1654
1326
  import { trace as trace3 } from "@dxos/tracing";
1655
1327
  import { CallbackCollection, ComplexMap as ComplexMap4 } from "@dxos/util";
1328
+ var __dxlog_file10 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-protocol.ts";
1656
1329
  function _ts_decorate6(decorators, target, key, desc) {
1657
1330
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1658
1331
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1659
1332
  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;
1660
1333
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1661
1334
  }
1662
- var __dxlog_file10 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-protocol.ts";
1663
1335
  var MOCK_AUTH_PROVIDER = async (nonce) => Buffer.from("mock");
1664
1336
  var MOCK_AUTH_VERIFIER = async (nonce, credential) => true;
1665
1337
  var SpaceProtocol = class {
1338
+ _networkManager;
1339
+ _swarmIdentity;
1340
+ _onSessionAuth;
1341
+ _onAuthFailure;
1342
+ blobSync;
1343
+ _disableP2pReplication;
1344
+ _topic;
1345
+ _spaceKey;
1346
+ _feeds = /* @__PURE__ */ new Set();
1347
+ _sessions = new ComplexMap4(PublicKey5.hash);
1348
+ // TODO(burdon): Move to config (with sensible defaults).
1349
+ _topology = new MMSTTopology({
1350
+ originateConnections: 4,
1351
+ maxPeers: 10,
1352
+ sampleSize: 20
1353
+ });
1354
+ _connection;
1355
+ feedAdded = new CallbackCollection();
1356
+ get sessions() {
1357
+ return this._sessions;
1358
+ }
1359
+ get feeds() {
1360
+ return this._feeds;
1361
+ }
1362
+ get _ownPeerKey() {
1363
+ return this._swarmIdentity.peerKey;
1364
+ }
1666
1365
  constructor({ topic, swarmIdentity, networkManager, onSessionAuth, onAuthFailure, blobStore, disableP2pReplication }) {
1667
- this._feeds = /* @__PURE__ */ new Set();
1668
- this._sessions = new ComplexMap4(PublicKey5.hash);
1669
- // TODO(burdon): Move to config (with sensible defaults).
1670
- this._topology = new MMSTTopology({
1671
- originateConnections: 4,
1672
- maxPeers: 10,
1673
- sampleSize: 20
1674
- });
1675
- this.feedAdded = new CallbackCollection();
1676
1366
  this._spaceKey = topic;
1677
1367
  this._networkManager = networkManager;
1678
1368
  this._swarmIdentity = swarmIdentity;
@@ -1684,25 +1374,11 @@ var SpaceProtocol = class {
1684
1374
  this._topic = subtleCrypto2.digest("SHA-256", topic.asBuffer()).then(discoveryKey).then(PublicKey5.from);
1685
1375
  this._disableP2pReplication = disableP2pReplication ?? false;
1686
1376
  }
1687
- get sessions() {
1688
- return this._sessions;
1689
- }
1690
- get feeds() {
1691
- return this._feeds;
1692
- }
1693
- get _ownPeerKey() {
1694
- return this._swarmIdentity.peerKey;
1695
- }
1696
1377
  // TODO(burdon): Create abstraction for Space (e.g., add keys and have provider).
1697
1378
  async addFeed(feed) {
1698
1379
  log8("addFeed", {
1699
1380
  key: feed.key
1700
- }, {
1701
- F: __dxlog_file10,
1702
- L: 128,
1703
- S: this,
1704
- C: (f, a) => f(...a)
1705
- });
1381
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 65, S: this });
1706
1382
  this._feeds.add(feed);
1707
1383
  for (const session of this._sessions.values()) {
1708
1384
  session.replicator.addFeed(feed);
@@ -1710,64 +1386,44 @@ var SpaceProtocol = class {
1710
1386
  await this.feedAdded.callSerial(feed);
1711
1387
  }
1712
1388
  // TODO(burdon): Rename open? Common open/close interfaces for all services?
1713
- async start() {
1389
+ async start(ctx) {
1714
1390
  if (this._connection) {
1715
1391
  return;
1716
1392
  }
1717
1393
  const credentials = await this._swarmIdentity.credentialProvider(Buffer.from(""));
1718
1394
  await this.blobSync.open();
1719
- log8("starting...", void 0, {
1720
- F: __dxlog_file10,
1721
- L: 149,
1722
- S: this,
1723
- C: (f, a) => f(...a)
1724
- });
1395
+ log8("starting...", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 82, S: this });
1725
1396
  const topic = await this._topic;
1726
- this._connection = await this._networkManager.joinSwarm({
1397
+ this._connection = await this._networkManager.joinSwarm(ctx, {
1727
1398
  protocolProvider: this._createProtocolProvider(credentials),
1728
1399
  topic,
1729
1400
  topology: this._topology,
1730
1401
  label: `swarm ${topic.truncate()} for space ${this._spaceKey.truncate()}`
1731
1402
  });
1732
- log8("started", void 0, {
1733
- F: __dxlog_file10,
1734
- L: 158,
1735
- S: this,
1736
- C: (f, a) => f(...a)
1737
- });
1403
+ log8("started", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 90, S: this });
1738
1404
  }
1739
1405
  updateTopology() {
1740
1406
  this._topology.forceUpdate();
1741
1407
  }
1742
- async stop() {
1408
+ async stop(ctx) {
1743
1409
  await this.blobSync.close();
1744
1410
  if (this._connection) {
1745
- log8("stopping...", void 0, {
1746
- F: __dxlog_file10,
1747
- L: 169,
1748
- S: this,
1749
- C: (f, a) => f(...a)
1750
- });
1751
- await this._connection.close();
1752
- log8("stopped", void 0, {
1753
- F: __dxlog_file10,
1754
- L: 171,
1755
- S: this,
1756
- C: (f, a) => f(...a)
1757
- });
1411
+ log8("stopping...", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 98, S: this });
1412
+ await this._connection.close(ctx);
1413
+ log8("stopped", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 100, S: this });
1758
1414
  }
1759
1415
  }
1760
1416
  _createProtocolProvider(credentials) {
1761
- return (wireParams) => {
1417
+ return (wireProps) => {
1762
1418
  const session = new SpaceProtocolSession({
1763
- wireParams,
1419
+ wireProps,
1764
1420
  swarmIdentity: this._swarmIdentity,
1765
1421
  onSessionAuth: this._onSessionAuth,
1766
1422
  onAuthFailure: this._onAuthFailure,
1767
1423
  blobSync: this.blobSync,
1768
1424
  disableP2pReplication: this._disableP2pReplication
1769
1425
  });
1770
- this._sessions.set(wireParams.remotePeerId, session);
1426
+ this._sessions.set(wireProps.remotePeerId, session);
1771
1427
  for (const feed of this._feeds) {
1772
1428
  session.replicator.addFeed(feed);
1773
1429
  }
@@ -1788,34 +1444,41 @@ _ts_decorate6([
1788
1444
  SpaceProtocol = _ts_decorate6([
1789
1445
  trace3.resource()
1790
1446
  ], SpaceProtocol);
1791
- var AuthStatus = /* @__PURE__ */ function(AuthStatus2) {
1447
+ var AuthStatus = /* @__PURE__ */ (function(AuthStatus2) {
1792
1448
  AuthStatus2["INITIAL"] = "INITIAL";
1793
1449
  AuthStatus2["SUCCESS"] = "SUCCESS";
1794
1450
  AuthStatus2["FAILURE"] = "FAILURE";
1795
1451
  return AuthStatus2;
1796
- }({});
1452
+ })({});
1797
1453
  var SpaceProtocolSession = class {
1454
+ _wireProps;
1455
+ _disableP2pReplication;
1456
+ _onSessionAuth;
1457
+ _onAuthFailure;
1458
+ _swarmIdentity;
1459
+ _blobSync;
1460
+ _teleport;
1461
+ // TODO(dmaretskyi): Start with upload=false when switching it on the fly works.
1462
+ replicator = new ReplicatorExtension().setOptions({
1463
+ upload: true
1464
+ });
1465
+ _authStatus = "INITIAL";
1466
+ get authStatus() {
1467
+ return this._authStatus;
1468
+ }
1469
+ get stats() {
1470
+ return this._teleport.stats;
1471
+ }
1798
1472
  // TODO(dmaretskyi): Allow to pass in extra extensions.
1799
- constructor({ wireParams, swarmIdentity, onSessionAuth, onAuthFailure, blobSync, disableP2pReplication }) {
1800
- // TODO(dmaretskyi): Start with upload=false when switching it on the fly works.
1801
- this.replicator = new ReplicatorExtension().setOptions({
1802
- upload: true
1803
- });
1804
- this._authStatus = "INITIAL";
1805
- this._wireParams = wireParams;
1473
+ constructor({ wireProps, swarmIdentity, onSessionAuth, onAuthFailure, blobSync, disableP2pReplication }) {
1474
+ this._wireProps = wireProps;
1806
1475
  this._swarmIdentity = swarmIdentity;
1807
1476
  this._onSessionAuth = onSessionAuth;
1808
1477
  this._onAuthFailure = onAuthFailure;
1809
1478
  this._blobSync = blobSync;
1810
- this._teleport = new Teleport(wireParams);
1479
+ this._teleport = new Teleport(wireProps);
1811
1480
  this._disableP2pReplication = disableP2pReplication ?? false;
1812
1481
  }
1813
- get authStatus() {
1814
- return this._authStatus;
1815
- }
1816
- get stats() {
1817
- return this._teleport.stats;
1818
- }
1819
1482
  get stream() {
1820
1483
  return this._teleport.stream;
1821
1484
  }
@@ -1825,12 +1488,7 @@ var SpaceProtocolSession = class {
1825
1488
  provider: this._swarmIdentity.credentialProvider,
1826
1489
  verifier: this._swarmIdentity.credentialAuthenticator,
1827
1490
  onAuthSuccess: () => {
1828
- log8("Peer authenticated", void 0, {
1829
- F: __dxlog_file10,
1830
- L: 282,
1831
- S: this,
1832
- C: (f, a) => f(...a)
1833
- });
1491
+ log8("Peer authenticated", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 181, S: this });
1834
1492
  this._authStatus = "SUCCESS";
1835
1493
  this._onSessionAuth?.(this._teleport);
1836
1494
  },
@@ -1845,12 +1503,7 @@ var SpaceProtocolSession = class {
1845
1503
  this._teleport.addExtension("dxos.mesh.teleport.blobsync", this._blobSync.createExtension());
1846
1504
  }
1847
1505
  async close() {
1848
- log8("close", void 0, {
1849
- F: __dxlog_file10,
1850
- L: 301,
1851
- S: this,
1852
- C: (f, a) => f(...a)
1853
- });
1506
+ log8("close", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 197, S: this });
1854
1507
  await this._teleport.close();
1855
1508
  }
1856
1509
  async abort() {
@@ -1859,31 +1512,34 @@ var SpaceProtocolSession = class {
1859
1512
  };
1860
1513
  _ts_decorate6([
1861
1514
  logInfo2
1862
- ], SpaceProtocolSession.prototype, "_wireParams", void 0);
1515
+ ], SpaceProtocolSession.prototype, "_wireProps", void 0);
1863
1516
  _ts_decorate6([
1864
1517
  logInfo2
1865
1518
  ], SpaceProtocolSession.prototype, "authStatus", null);
1866
1519
 
1867
1520
  // src/space/space-manager.ts
1868
1521
  import { parseAutomergeUrl } from "@automerge/automerge-repo";
1869
- import { synchronized as synchronized4, trackLeaks as trackLeaks3, Trigger as Trigger2 } from "@dxos/async";
1522
+ import { Trigger as Trigger2, synchronized as synchronized4, trackLeaks as trackLeaks3 } from "@dxos/async";
1870
1523
  import { getCredentialAssertion } from "@dxos/credentials";
1871
1524
  import { failUndefined as failUndefined2 } from "@dxos/debug";
1872
1525
  import { PublicKey as PublicKey6 } from "@dxos/keys";
1873
1526
  import { log as log9 } from "@dxos/log";
1874
- import { trace as trace4 } from "@dxos/protocols";
1875
1527
  import { ComplexMap as ComplexMap5 } from "@dxos/util";
1528
+ var __dxlog_file11 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-manager.ts";
1876
1529
  function _ts_decorate7(decorators, target, key, desc) {
1877
1530
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1878
1531
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1879
1532
  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;
1880
1533
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1881
1534
  }
1882
- var __dxlog_file11 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-manager.ts";
1883
1535
  var SpaceManager = class {
1536
+ _spaces = new ComplexMap5(PublicKey6.hash);
1537
+ _feedStore;
1538
+ _networkManager;
1539
+ _metadataStore;
1540
+ _blobStore;
1541
+ _disableP2pReplication;
1884
1542
  constructor({ feedStore, networkManager, metadataStore, blobStore, disableP2pReplication }) {
1885
- this._spaces = new ComplexMap5(PublicKey6.hash);
1886
- this._instanceId = PublicKey6.random().toHex();
1887
1543
  this._feedStore = feedStore;
1888
1544
  this._networkManager = networkManager;
1889
1545
  this._metadataStore = metadataStore;
@@ -1902,22 +1558,9 @@ var SpaceManager = class {
1902
1558
  ].map((space) => space.close()));
1903
1559
  }
1904
1560
  async constructSpace({ metadata, swarmIdentity, onAuthorizedConnection, onAuthFailure, onDelegatedInvitationStatusChange, onMemberRolesChanged, memberKey }) {
1905
- log9.trace("dxos.echo.space-manager.construct-space", trace4.begin({
1906
- id: this._instanceId
1907
- }), {
1908
- F: __dxlog_file11,
1909
- L: 102,
1910
- S: this,
1911
- C: (f, a) => f(...a)
1912
- });
1913
1561
  log9("constructing space...", {
1914
1562
  spaceKey: metadata.genesisFeedKey
1915
- }, {
1916
- F: __dxlog_file11,
1917
- L: 103,
1918
- S: this,
1919
- C: (f, a) => f(...a)
1920
- });
1563
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 47, S: this });
1921
1564
  const genesisFeed = await this._feedStore.openFeed(metadata.genesisFeedKey ?? failUndefined2());
1922
1565
  const spaceKey = metadata.key;
1923
1566
  const spaceId = await createIdFromSpaceKey(spaceKey);
@@ -1942,34 +1585,12 @@ var SpaceManager = class {
1942
1585
  onMemberRolesChanged
1943
1586
  });
1944
1587
  this._spaces.set(space.key, space);
1945
- log9.trace("dxos.echo.space-manager.construct-space", trace4.end({
1946
- id: this._instanceId
1947
- }), {
1948
- F: __dxlog_file11,
1949
- L: 133,
1950
- S: this,
1951
- C: (f, a) => f(...a)
1952
- });
1953
1588
  return space;
1954
1589
  }
1955
- async requestSpaceAdmissionCredential(params) {
1956
- const traceKey = "dxos.echo.space-manager.request-space-admission";
1957
- log9.trace(traceKey, trace4.begin({
1958
- id: this._instanceId
1959
- }), {
1960
- F: __dxlog_file11,
1961
- L: 139,
1962
- S: this,
1963
- C: (f, a) => f(...a)
1964
- });
1590
+ async requestSpaceAdmissionCredential(ctx, params) {
1965
1591
  log9("requesting space admission credential...", {
1966
1592
  spaceKey: params.spaceKey
1967
- }, {
1968
- F: __dxlog_file11,
1969
- L: 140,
1970
- S: this,
1971
- C: (f, a) => f(...a)
1972
- });
1593
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 78, S: this });
1973
1594
  const onCredentialResolved = new Trigger2();
1974
1595
  const protocol = new SpaceProtocol({
1975
1596
  topic: params.spaceKey,
@@ -1986,32 +1607,15 @@ var SpaceManager = class {
1986
1607
  disableP2pReplication: this._disableP2pReplication
1987
1608
  });
1988
1609
  try {
1989
- await protocol.start();
1610
+ await protocol.start(ctx);
1990
1611
  const credential = await onCredentialResolved.wait({
1991
1612
  timeout: params.timeout
1992
1613
  });
1993
- log9.trace(traceKey, trace4.end({
1994
- id: this._instanceId
1995
- }), {
1996
- F: __dxlog_file11,
1997
- L: 164,
1998
- S: this,
1999
- C: (f, a) => f(...a)
2000
- });
2001
1614
  return credential;
2002
1615
  } catch (err) {
2003
- log9.trace(traceKey, trace4.error({
2004
- id: this._instanceId,
2005
- error: err
2006
- }), {
2007
- F: __dxlog_file11,
2008
- L: 167,
2009
- S: this,
2010
- C: (f, a) => f(...a)
2011
- });
2012
1616
  throw err;
2013
1617
  } finally {
2014
- await protocol.stop();
1618
+ await protocol.stop(ctx);
2015
1619
  }
2016
1620
  }
2017
1621
  findSpaceByRootDocumentId(documentId) {
@@ -2064,4 +1668,4 @@ export {
2064
1668
  SpaceProtocolSession,
2065
1669
  SpaceManager
2066
1670
  };
2067
- //# sourceMappingURL=chunk-GBFX5J5B.mjs.map
1671
+ //# sourceMappingURL=chunk-VIHYDCCC.mjs.map