@dxos/echo-pipeline 0.1.55-main.ff36828 → 0.1.55
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.
- package/dist/lib/browser/{chunk-OJGL5427.mjs → chunk-4VJRJ4SY.mjs} +877 -872
- package/dist/lib/browser/chunk-4VJRJ4SY.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/browser/testing/index.mjs.map +1 -1
- package/dist/lib/node/index.cjs +787 -784
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +78 -73
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/types/src/db-host/data-service-host.d.ts.map +1 -0
- package/dist/types/src/db-host/data-service.d.ts.map +1 -0
- package/dist/types/src/db-host/database-host.d.ts.map +1 -0
- package/dist/types/src/db-host/index.d.ts.map +1 -0
- package/dist/types/src/db-host/snapshot-manager.d.ts.map +1 -0
- package/dist/types/src/db-host/snapshot-store.d.ts.map +1 -0
- package/dist/types/src/db-host/snapshot-store.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/pipeline/pipeline.d.ts +3 -2
- package/dist/types/src/pipeline/pipeline.d.ts.map +1 -1
- package/dist/types/src/space/control-pipeline.d.ts.map +1 -1
- package/dist/types/src/space/data-pipeline.d.ts +4 -4
- package/dist/types/src/space/data-pipeline.d.ts.map +1 -1
- package/dist/types/src/space/space-manager.d.ts +1 -1
- package/dist/types/src/space/space-manager.d.ts.map +1 -1
- package/dist/types/src/space/space-protocol.d.ts +2 -3
- package/dist/types/src/space/space-protocol.d.ts.map +1 -1
- package/dist/types/src/space/space.d.ts +1 -1
- package/dist/types/src/space/space.d.ts.map +1 -1
- package/dist/types/src/testing/database-test-rig.d.ts +1 -1
- package/dist/types/src/testing/database-test-rig.d.ts.map +1 -1
- package/dist/types/src/testing/test-agent-builder.d.ts +1 -1
- package/dist/types/src/testing/test-agent-builder.d.ts.map +1 -1
- package/dist/types/src/testing/util.d.ts +1 -1
- package/dist/types/src/testing/util.d.ts.map +1 -1
- package/package.json +30 -30
- package/src/{dbhost → db-host}/database-host.ts +0 -2
- package/src/index.ts +2 -2
- package/src/pipeline/pipeline.ts +19 -26
- package/src/space/control-pipeline.ts +4 -1
- package/src/space/data-pipeline.ts +12 -9
- package/src/space/space-manager.ts +1 -1
- package/src/space/space-protocol.ts +2 -3
- package/src/space/space.ts +1 -1
- package/src/testing/database-test-rig.ts +1 -1
- package/src/testing/test-agent-builder.ts +1 -1
- package/src/testing/util.ts +1 -1
- package/src/tests/database.test.ts +1 -1
- package/dist/lib/browser/chunk-OJGL5427.mjs.map +0 -7
- package/dist/types/src/dbhost/data-service-host.d.ts.map +0 -1
- package/dist/types/src/dbhost/data-service.d.ts.map +0 -1
- package/dist/types/src/dbhost/database-host.d.ts.map +0 -1
- package/dist/types/src/dbhost/index.d.ts.map +0 -1
- package/dist/types/src/dbhost/snapshot-manager.d.ts.map +0 -1
- package/dist/types/src/dbhost/snapshot-store.d.ts.map +0 -1
- package/dist/types/src/dbhost/snapshot-store.test.d.ts.map +0 -1
- /package/dist/types/src/{dbhost → db-host}/data-service-host.d.ts +0 -0
- /package/dist/types/src/{dbhost → db-host}/data-service.d.ts +0 -0
- /package/dist/types/src/{dbhost → db-host}/database-host.d.ts +0 -0
- /package/dist/types/src/{dbhost → db-host}/index.d.ts +0 -0
- /package/dist/types/src/{dbhost → db-host}/snapshot-manager.d.ts +0 -0
- /package/dist/types/src/{dbhost → db-host}/snapshot-store.d.ts +0 -0
- /package/dist/types/src/{dbhost → db-host}/snapshot-store.test.d.ts +0 -0
- /package/src/{dbhost → db-host}/data-service-host.ts +0 -0
- /package/src/{dbhost → db-host}/data-service.ts +0 -0
- /package/src/{dbhost → db-host}/index.ts +0 -0
- /package/src/{dbhost → db-host}/snapshot-manager.ts +0 -0
- /package/src/{dbhost → db-host}/snapshot-store.test.ts +0 -0
- /package/src/{dbhost → db-host}/snapshot-store.ts +0 -0
package/dist/lib/node/index.cjs
CHANGED
|
@@ -64,64 +64,184 @@ __export(src_exports, {
|
|
|
64
64
|
});
|
|
65
65
|
module.exports = __toCommonJS(src_exports);
|
|
66
66
|
|
|
67
|
-
// packages/core/echo/echo-pipeline/src/
|
|
68
|
-
var
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
// packages/core/echo/echo-pipeline/src/common/codec.ts
|
|
68
|
+
var import_hypercore = require("@dxos/hypercore");
|
|
69
|
+
var import_protocols = require("@dxos/protocols");
|
|
70
|
+
var codec = import_protocols.schema.getCodecForType("dxos.echo.feed.FeedMessage");
|
|
71
|
+
var valueEncoding = (0, import_hypercore.createCodecEncoding)(codec);
|
|
72
|
+
|
|
73
|
+
// packages/core/echo/echo-pipeline/src/common/feeds.ts
|
|
74
|
+
var import_tiny_invariant = __toESM(require("tiny-invariant"));
|
|
75
|
+
var createMappedFeedWriter = (mapper, writer) => {
|
|
76
|
+
(0, import_tiny_invariant.default)(mapper);
|
|
77
|
+
(0, import_tiny_invariant.default)(writer);
|
|
78
|
+
return {
|
|
79
|
+
write: async (data, options) => await writer.write(await mapper(data), options)
|
|
80
|
+
};
|
|
75
81
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
|
|
83
|
+
// packages/core/echo/echo-pipeline/src/db-host/data-service-host.ts
|
|
84
|
+
var import_tiny_invariant2 = __toESM(require("tiny-invariant"));
|
|
85
|
+
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
86
|
+
var import_context = require("@dxos/context");
|
|
87
|
+
var import_echo_db = require("@dxos/echo-db");
|
|
88
|
+
var import_log = require("@dxos/log");
|
|
89
|
+
var import_util = require("@dxos/util");
|
|
90
|
+
var __dxlog_file = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/db-host/data-service-host.ts";
|
|
91
|
+
var DataServiceHost = class {
|
|
92
|
+
constructor(_itemManager, _itemDemuxer, _writeStream) {
|
|
93
|
+
this._itemManager = _itemManager;
|
|
94
|
+
this._itemDemuxer = _itemDemuxer;
|
|
95
|
+
this._writeStream = _writeStream;
|
|
96
|
+
this._ctx = new import_context.Context();
|
|
97
|
+
this._clientTagMap = new import_util.ComplexMap(([feedKey, seq]) => `${feedKey.toHex()}:${seq}`);
|
|
79
98
|
}
|
|
80
|
-
|
|
81
|
-
var InvalidInvitationError = class extends DBError {
|
|
82
|
-
constructor() {
|
|
83
|
-
super("INVALID_INVITATION", "Invitation is invalid.");
|
|
99
|
+
async open() {
|
|
84
100
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
constructor(expected, actual) {
|
|
88
|
-
super("INVALID_STORAGE_VERSION", "Invalid storage version.", {
|
|
89
|
-
expected,
|
|
90
|
-
actual
|
|
91
|
-
});
|
|
101
|
+
async close() {
|
|
102
|
+
await this._ctx.dispose();
|
|
92
103
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Real-time subscription to data objects in a space.
|
|
106
|
+
*/
|
|
107
|
+
subscribe() {
|
|
108
|
+
return new import_codec_protobuf.Stream(({ next, close, ctx }) => {
|
|
109
|
+
ctx.onDispose(this._ctx.onDispose(close));
|
|
110
|
+
const objects = Array.from(this._itemManager.entities.values()).map((entity) => entity.createSnapshot());
|
|
111
|
+
next({
|
|
112
|
+
batch: {
|
|
113
|
+
objects
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
this._itemDemuxer.mutation.on(ctx, (message) => {
|
|
117
|
+
var _a;
|
|
118
|
+
const { batch, meta } = message;
|
|
119
|
+
(0, import_tiny_invariant2.default)(!meta.clientTag, "Unexpected client tag in mutation message");
|
|
120
|
+
(0, import_log.log)("message", {
|
|
121
|
+
batch,
|
|
122
|
+
meta
|
|
123
|
+
}, {
|
|
124
|
+
F: __dxlog_file,
|
|
125
|
+
L: 63,
|
|
126
|
+
S: this,
|
|
127
|
+
C: (f, a) => f(...a)
|
|
128
|
+
});
|
|
129
|
+
const clientTag = this._clientTagMap.get([
|
|
130
|
+
message.meta.feedKey,
|
|
131
|
+
message.meta.seq
|
|
132
|
+
]);
|
|
133
|
+
(_a = batch.objects) == null ? void 0 : _a.forEach((object) => {
|
|
134
|
+
(0, import_echo_db.setMetadataOnObject)(object, {
|
|
135
|
+
...meta
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
if (clientTag) {
|
|
139
|
+
(0, import_echo_db.tagMutationsInBatch)(batch, clientTag, 0);
|
|
140
|
+
}
|
|
141
|
+
next({
|
|
142
|
+
clientTag,
|
|
143
|
+
feedKey: message.meta.feedKey,
|
|
144
|
+
seq: message.meta.seq,
|
|
145
|
+
batch
|
|
146
|
+
});
|
|
147
|
+
});
|
|
98
148
|
});
|
|
99
149
|
}
|
|
100
|
-
|
|
101
|
-
var
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
150
|
+
async write(request) {
|
|
151
|
+
var _a, _b;
|
|
152
|
+
(0, import_tiny_invariant2.default)(!this._ctx.disposed, "Cannot write to closed DataServiceHost");
|
|
153
|
+
(0, import_tiny_invariant2.default)(this._writeStream, "Cannot write mutations in readonly mode");
|
|
154
|
+
(0, import_log.log)("write", {
|
|
155
|
+
clientTag: request.clientTag,
|
|
156
|
+
objectCount: (_b = (_a = request.batch.objects) == null ? void 0 : _a.length) != null ? _b : 0
|
|
157
|
+
}, {
|
|
158
|
+
F: __dxlog_file,
|
|
159
|
+
L: 92,
|
|
160
|
+
S: this,
|
|
161
|
+
C: (f, a) => f(...a)
|
|
162
|
+
});
|
|
163
|
+
const message = createDataMessage(request.batch);
|
|
164
|
+
const receipt = await this._writeStream.write(message, {
|
|
165
|
+
afterWrite: async (receipt2) => {
|
|
166
|
+
if (request.clientTag) {
|
|
167
|
+
(0, import_log.log)("tag", {
|
|
168
|
+
clientTag: request.clientTag,
|
|
169
|
+
feedKey: receipt2.feedKey,
|
|
170
|
+
seq: receipt2.seq
|
|
171
|
+
}, {
|
|
172
|
+
F: __dxlog_file,
|
|
173
|
+
L: 101,
|
|
174
|
+
S: this,
|
|
175
|
+
C: (f, a) => f(...a)
|
|
176
|
+
});
|
|
177
|
+
this._clientTagMap.set([
|
|
178
|
+
receipt2.feedKey,
|
|
179
|
+
receipt2.seq
|
|
180
|
+
], request.clientTag);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
105
183
|
});
|
|
184
|
+
return receipt;
|
|
106
185
|
}
|
|
107
186
|
};
|
|
108
|
-
var
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
187
|
+
var createDataMessage = (batch) => {
|
|
188
|
+
var _a;
|
|
189
|
+
return {
|
|
190
|
+
batch: {
|
|
191
|
+
objects: (_a = batch.objects) == null ? void 0 : _a.map((object) => {
|
|
192
|
+
var _a2;
|
|
193
|
+
return {
|
|
194
|
+
...object,
|
|
195
|
+
mutations: (_a2 = object.mutations) == null ? void 0 : _a2.map((mutation) => ({
|
|
196
|
+
...mutation,
|
|
197
|
+
meta: void 0
|
|
198
|
+
})),
|
|
199
|
+
meta: void 0
|
|
200
|
+
};
|
|
201
|
+
})
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// packages/core/echo/echo-pipeline/src/db-host/database-host.ts
|
|
207
|
+
var import_echo_db2 = require("@dxos/echo-db");
|
|
208
|
+
var DatabaseHost = class {
|
|
209
|
+
constructor(_outboundStream) {
|
|
210
|
+
this._outboundStream = _outboundStream;
|
|
211
|
+
}
|
|
212
|
+
get isReadOnly() {
|
|
213
|
+
return !!this._outboundStream;
|
|
214
|
+
}
|
|
215
|
+
get echoProcessor() {
|
|
216
|
+
return this._echoProcessor;
|
|
217
|
+
}
|
|
218
|
+
async open(itemManager, modelFactory) {
|
|
219
|
+
this._itemManager = itemManager;
|
|
220
|
+
this._itemManager._debugLabel = "host";
|
|
221
|
+
this._itemDemuxer = new import_echo_db2.ItemDemuxer(itemManager, modelFactory);
|
|
222
|
+
this._echoProcessor = this._itemDemuxer.open();
|
|
223
|
+
}
|
|
224
|
+
async close() {
|
|
225
|
+
}
|
|
226
|
+
getWriteStream() {
|
|
227
|
+
return this._outboundStream;
|
|
228
|
+
}
|
|
229
|
+
createSnapshot() {
|
|
230
|
+
return this._itemDemuxer.createSnapshot();
|
|
231
|
+
}
|
|
232
|
+
createDataServiceHost() {
|
|
233
|
+
var _a;
|
|
234
|
+
return new DataServiceHost(this._itemManager, this._itemDemuxer, (_a = this._outboundStream) != null ? _a : void 0);
|
|
113
235
|
}
|
|
114
236
|
};
|
|
115
237
|
|
|
116
|
-
// packages/core/echo/echo-pipeline/src/
|
|
117
|
-
var import_crc_32 = __toESM(require("crc-32"));
|
|
118
|
-
var import_tiny_invariant = __toESM(require("tiny-invariant"));
|
|
238
|
+
// packages/core/echo/echo-pipeline/src/db-host/snapshot-manager.ts
|
|
119
239
|
var import_async = require("@dxos/async");
|
|
120
|
-
var
|
|
121
|
-
var
|
|
122
|
-
var
|
|
123
|
-
var
|
|
124
|
-
var
|
|
240
|
+
var import_context2 = require("@dxos/context");
|
|
241
|
+
var import_debug = require("@dxos/debug");
|
|
242
|
+
var import_keys = require("@dxos/keys");
|
|
243
|
+
var import_protocols2 = require("@dxos/protocols");
|
|
244
|
+
var import_blob = require("@dxos/protocols/proto/dxos/echo/blob");
|
|
125
245
|
function _ts_decorate(decorators, target, key, desc) {
|
|
126
246
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
127
247
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -132,58 +252,273 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
132
252
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
133
253
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
134
254
|
}
|
|
135
|
-
var
|
|
136
|
-
var
|
|
137
|
-
version: import_protocols.STORAGE_VERSION,
|
|
138
|
-
spaces: [],
|
|
139
|
-
created: new Date(),
|
|
140
|
-
updated: new Date()
|
|
141
|
-
});
|
|
142
|
-
var EchoMetadata = import_protocols.schema.getCodecForType("dxos.echo.metadata.EchoMetadata");
|
|
143
|
-
var MetadataStore = class {
|
|
255
|
+
var SpaceSnapshot = import_protocols2.schema.getCodecForType("dxos.echo.snapshot.SpaceSnapshot");
|
|
256
|
+
var SnapshotManager = class SnapshotManager2 {
|
|
144
257
|
// prettier-ignore
|
|
145
|
-
constructor(
|
|
146
|
-
this.
|
|
147
|
-
this.
|
|
148
|
-
this.
|
|
258
|
+
constructor(_snapshotStore, _blobStore, _blobSync) {
|
|
259
|
+
this._snapshotStore = _snapshotStore;
|
|
260
|
+
this._blobStore = _blobStore;
|
|
261
|
+
this._blobSync = _blobSync;
|
|
149
262
|
}
|
|
150
|
-
|
|
151
|
-
|
|
263
|
+
async _getBlob(blobId) {
|
|
264
|
+
const blob = await this._blobStore.get(blobId);
|
|
265
|
+
return SpaceSnapshot.decode(blob);
|
|
152
266
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
267
|
+
async load(ctx, id) {
|
|
268
|
+
const blobId = import_keys.PublicKey.fromHex(id).asUint8Array();
|
|
269
|
+
const blobMeta = await this._blobStore.getMeta(blobId);
|
|
270
|
+
if (blobMeta && blobMeta.state === import_blob.BlobMeta.State.FULLY_PRESENT) {
|
|
271
|
+
return this._getBlob(blobId);
|
|
272
|
+
}
|
|
273
|
+
const fallbackStore = await (0, import_context2.cancelWithContext)(ctx, this._snapshotStore.loadSnapshot(id));
|
|
274
|
+
if (fallbackStore) {
|
|
275
|
+
return fallbackStore;
|
|
276
|
+
}
|
|
277
|
+
await this._blobSync.download(ctx, blobId);
|
|
278
|
+
return this._getBlob(blobId);
|
|
156
279
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
get spaces() {
|
|
162
|
-
var _a;
|
|
163
|
-
return (_a = this._metadata.spaces) != null ? _a : [];
|
|
280
|
+
async store(snapshot) {
|
|
281
|
+
const { id } = await this._blobStore.set(SpaceSnapshot.encode(snapshot));
|
|
282
|
+
await this._blobSync.notifyBlobAdded(id);
|
|
283
|
+
return import_keys.PublicKey.from(id).toHex();
|
|
164
284
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
285
|
+
};
|
|
286
|
+
_ts_decorate([
|
|
287
|
+
(0, import_debug.timed)(1e4)
|
|
288
|
+
], SnapshotManager.prototype, "load", null);
|
|
289
|
+
SnapshotManager = _ts_decorate([
|
|
290
|
+
(0, import_async.trackLeaks)("open", "close")
|
|
291
|
+
], SnapshotManager);
|
|
292
|
+
|
|
293
|
+
// packages/core/echo/echo-pipeline/src/db-host/snapshot-store.ts
|
|
294
|
+
var import_crypto = require("@dxos/crypto");
|
|
295
|
+
var import_protocols3 = require("@dxos/protocols");
|
|
296
|
+
var SpaceSnapshot2 = import_protocols3.schema.getCodecForType("dxos.echo.snapshot.SpaceSnapshot");
|
|
297
|
+
var SnapshotStore = class {
|
|
298
|
+
// prettier-ignore
|
|
299
|
+
constructor(_directory) {
|
|
300
|
+
this._directory = _directory;
|
|
301
|
+
}
|
|
302
|
+
async saveSnapshot(snapshot) {
|
|
303
|
+
const encoded = SpaceSnapshot2.encode(snapshot);
|
|
304
|
+
const key = await import_crypto.subtleCrypto.digest("SHA-256", encoded);
|
|
305
|
+
const keyString = Buffer.from(key).toString("hex");
|
|
306
|
+
const file = await this._directory.getOrCreateFile(keyString);
|
|
307
|
+
try {
|
|
308
|
+
await file.write(0, Buffer.from(encoded));
|
|
309
|
+
} finally {
|
|
310
|
+
await file.close();
|
|
311
|
+
}
|
|
312
|
+
return keyString;
|
|
313
|
+
}
|
|
314
|
+
async loadSnapshot(key) {
|
|
315
|
+
const file = await this._directory.getOrCreateFile(key);
|
|
316
|
+
try {
|
|
317
|
+
const { size } = await file.stat();
|
|
318
|
+
if (size === 0) {
|
|
319
|
+
return void 0;
|
|
320
|
+
}
|
|
321
|
+
const buffer = await file.read(0, size);
|
|
322
|
+
return SpaceSnapshot2.decode(buffer);
|
|
323
|
+
} finally {
|
|
324
|
+
await file.close();
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
async listSnapshots() {
|
|
328
|
+
const entries = await this._directory.list();
|
|
329
|
+
return await Promise.all(entries.map(async (key) => {
|
|
330
|
+
const { size } = await this._directory.getOrCreateFile(key).stat();
|
|
331
|
+
return {
|
|
332
|
+
key,
|
|
333
|
+
size
|
|
334
|
+
};
|
|
335
|
+
}));
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
// packages/core/echo/echo-pipeline/src/db-host/data-service.ts
|
|
340
|
+
var import_tiny_invariant3 = __toESM(require("tiny-invariant"));
|
|
341
|
+
var import_debug2 = require("@dxos/debug");
|
|
342
|
+
var import_keys2 = require("@dxos/keys");
|
|
343
|
+
var import_log2 = require("@dxos/log");
|
|
344
|
+
var import_util2 = require("@dxos/util");
|
|
345
|
+
var __dxlog_file2 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/db-host/data-service.ts";
|
|
346
|
+
var DataServiceSubscriptions = class {
|
|
347
|
+
constructor() {
|
|
348
|
+
this._spaces = new import_util2.ComplexMap(import_keys2.PublicKey.hash);
|
|
349
|
+
}
|
|
350
|
+
clear() {
|
|
351
|
+
this._spaces.clear();
|
|
352
|
+
}
|
|
353
|
+
async registerSpace(spaceKey, host) {
|
|
354
|
+
(0, import_log2.log)("Registering space", {
|
|
355
|
+
spaceKey
|
|
356
|
+
}, {
|
|
357
|
+
F: __dxlog_file2,
|
|
358
|
+
L: 31,
|
|
359
|
+
S: this,
|
|
360
|
+
C: (f, a) => f(...a)
|
|
361
|
+
});
|
|
362
|
+
(0, import_tiny_invariant3.default)(!this._spaces.has(spaceKey));
|
|
363
|
+
await host.open();
|
|
364
|
+
this._spaces.set(spaceKey, host);
|
|
365
|
+
}
|
|
366
|
+
async unregisterSpace(spaceKey) {
|
|
367
|
+
(0, import_log2.log)("Unregistering space", {
|
|
368
|
+
spaceKey
|
|
369
|
+
}, {
|
|
370
|
+
F: __dxlog_file2,
|
|
371
|
+
L: 38,
|
|
372
|
+
S: this,
|
|
373
|
+
C: (f, a) => f(...a)
|
|
374
|
+
});
|
|
375
|
+
const host = this._spaces.get(spaceKey);
|
|
376
|
+
await (host == null ? void 0 : host.close());
|
|
377
|
+
this._spaces.delete(spaceKey);
|
|
378
|
+
}
|
|
379
|
+
getDataService(spaceKey) {
|
|
380
|
+
return this._spaces.get(spaceKey);
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
var DataServiceImpl = class {
|
|
384
|
+
constructor(_subscriptions) {
|
|
385
|
+
this._subscriptions = _subscriptions;
|
|
386
|
+
}
|
|
387
|
+
subscribe(request) {
|
|
388
|
+
var _a;
|
|
389
|
+
(0, import_tiny_invariant3.default)(request.spaceKey);
|
|
390
|
+
const host = (_a = this._subscriptions.getDataService(request.spaceKey)) != null ? _a : (0, import_debug2.raise)(new Error(`space not found: ${request.spaceKey}`));
|
|
391
|
+
return host.subscribe();
|
|
392
|
+
}
|
|
393
|
+
write(request) {
|
|
394
|
+
var _a;
|
|
395
|
+
(0, import_tiny_invariant3.default)(request.spaceKey);
|
|
396
|
+
(0, import_tiny_invariant3.default)(request.batch);
|
|
397
|
+
const host = (_a = this._subscriptions.getDataService(request.spaceKey)) != null ? _a : (0, import_debug2.raise)(new Error(`space not found: ${request.spaceKey}`));
|
|
398
|
+
return host.write(request);
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
// packages/core/echo/echo-pipeline/src/errors/errors.ts
|
|
403
|
+
var DBError = class extends Error {
|
|
404
|
+
constructor(code, message, context) {
|
|
405
|
+
super(message ? `${code}: ${message}` : code.toString());
|
|
406
|
+
this.code = code;
|
|
407
|
+
this.context = context;
|
|
408
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
var IdentityNotInitializedError = class extends DBError {
|
|
412
|
+
constructor() {
|
|
413
|
+
super("IDENTITY_NOT_INITIALIZED", "Identity not initialized.");
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
var InvalidInvitationError = class extends DBError {
|
|
417
|
+
constructor() {
|
|
418
|
+
super("INVALID_INVITATION", "Invitation is invalid.");
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
var InvalidStorageVersionError = class extends DBError {
|
|
422
|
+
constructor(expected, actual) {
|
|
423
|
+
super("INVALID_STORAGE_VERSION", "Invalid storage version.", {
|
|
424
|
+
expected,
|
|
425
|
+
actual
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
var SpaceNotFoundError = class extends DBError {
|
|
430
|
+
constructor(spaceKey) {
|
|
431
|
+
super("SPACE_NOT_FOUND", "Space not found.", {
|
|
432
|
+
spaceKey
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
var EntityNotFoundError = class extends DBError {
|
|
437
|
+
constructor(entityId) {
|
|
438
|
+
super("ITEM_NOT_FOUND", "Item not found.", {
|
|
439
|
+
entityId
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
var UnknownModelError = class extends DBError {
|
|
444
|
+
constructor(model) {
|
|
445
|
+
super("UNKNOWN_MODEL", "Unknown model.", {
|
|
446
|
+
model
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
// packages/core/echo/echo-pipeline/src/metadata/metadata-store.ts
|
|
452
|
+
var import_crc_32 = __toESM(require("crc-32"));
|
|
453
|
+
var import_tiny_invariant4 = __toESM(require("tiny-invariant"));
|
|
454
|
+
var import_async2 = require("@dxos/async");
|
|
455
|
+
var import_errors = require("@dxos/errors");
|
|
456
|
+
var import_log3 = require("@dxos/log");
|
|
457
|
+
var import_protocols4 = require("@dxos/protocols");
|
|
458
|
+
var import_services = require("@dxos/protocols/proto/dxos/client/services");
|
|
459
|
+
var import_util3 = require("@dxos/util");
|
|
460
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
461
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
462
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
463
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
464
|
+
else
|
|
465
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
466
|
+
if (d = decorators[i])
|
|
467
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
468
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
469
|
+
}
|
|
470
|
+
var __dxlog_file3 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/metadata/metadata-store.ts";
|
|
471
|
+
var emptyEchoMetadata = () => ({
|
|
472
|
+
version: import_protocols4.STORAGE_VERSION,
|
|
473
|
+
spaces: [],
|
|
474
|
+
created: new Date(),
|
|
475
|
+
updated: new Date()
|
|
476
|
+
});
|
|
477
|
+
var EchoMetadata = import_protocols4.schema.getCodecForType("dxos.echo.metadata.EchoMetadata");
|
|
478
|
+
var MetadataStore = class {
|
|
479
|
+
// prettier-ignore
|
|
480
|
+
constructor(_directory) {
|
|
481
|
+
this._directory = _directory;
|
|
482
|
+
this._metadata = emptyEchoMetadata();
|
|
483
|
+
this.update = new import_async2.Event();
|
|
484
|
+
}
|
|
485
|
+
get metadata() {
|
|
486
|
+
return this._metadata;
|
|
487
|
+
}
|
|
488
|
+
get version() {
|
|
489
|
+
var _a;
|
|
490
|
+
return (_a = this._metadata.version) != null ? _a : 0;
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Returns a list of currently saved spaces. The list and objects in it can be modified addSpace and
|
|
494
|
+
* addSpaceFeed functions.
|
|
495
|
+
*/
|
|
496
|
+
get spaces() {
|
|
497
|
+
var _a;
|
|
498
|
+
return (_a = this._metadata.spaces) != null ? _a : [];
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Loads metadata from persistent storage.
|
|
502
|
+
*/
|
|
503
|
+
async load() {
|
|
504
|
+
var _a;
|
|
505
|
+
const file = this._directory.getOrCreateFile("EchoMetadata");
|
|
506
|
+
try {
|
|
507
|
+
const { size: fileLength } = await file.stat();
|
|
508
|
+
if (fileLength < 8) {
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
const dataSize = fromBytesInt32(await file.read(0, 4));
|
|
512
|
+
const checksum = fromBytesInt32(await file.read(4, 4));
|
|
513
|
+
(0, import_log3.log)("loaded", {
|
|
514
|
+
size: dataSize,
|
|
515
|
+
checksum
|
|
516
|
+
}, {
|
|
517
|
+
F: __dxlog_file3,
|
|
518
|
+
L: 72,
|
|
519
|
+
S: this,
|
|
520
|
+
C: (f, a) => f(...a)
|
|
521
|
+
});
|
|
187
522
|
if (fileLength < dataSize + 8) {
|
|
188
523
|
throw new import_errors.DataCorruptionError("Metadata size is smaller than expected.");
|
|
189
524
|
}
|
|
@@ -198,10 +533,10 @@ var MetadataStore = class {
|
|
|
198
533
|
(_a2 = space.state) != null ? _a2 : space.state = import_services.SpaceState.ACTIVE;
|
|
199
534
|
});
|
|
200
535
|
} catch (err) {
|
|
201
|
-
|
|
536
|
+
import_log3.log.error("failed to load metadata", {
|
|
202
537
|
err
|
|
203
538
|
}, {
|
|
204
|
-
F:
|
|
539
|
+
F: __dxlog_file3,
|
|
205
540
|
L: 92,
|
|
206
541
|
S: this,
|
|
207
542
|
C: (f, a) => f(...a)
|
|
@@ -215,25 +550,25 @@ var MetadataStore = class {
|
|
|
215
550
|
var _a;
|
|
216
551
|
const data = {
|
|
217
552
|
...this._metadata,
|
|
218
|
-
version:
|
|
553
|
+
version: import_protocols4.STORAGE_VERSION,
|
|
219
554
|
created: (_a = this._metadata.created) != null ? _a : new Date(),
|
|
220
555
|
updated: new Date()
|
|
221
556
|
};
|
|
222
557
|
this.update.emit(data);
|
|
223
558
|
const file = this._directory.getOrCreateFile("EchoMetadata");
|
|
224
559
|
try {
|
|
225
|
-
const encoded = (0,
|
|
560
|
+
const encoded = (0, import_util3.arrayToBuffer)(EchoMetadata.encode(data));
|
|
226
561
|
const checksum = import_crc_32.default.buf(encoded);
|
|
227
562
|
const result = Buffer.alloc(8 + encoded.length);
|
|
228
563
|
result.writeInt32LE(encoded.length, 0);
|
|
229
564
|
result.writeInt32LE(checksum, 4);
|
|
230
565
|
encoded.copy(result, 8);
|
|
231
566
|
await file.write(0, result);
|
|
232
|
-
(0,
|
|
567
|
+
(0, import_log3.log)("saved", {
|
|
233
568
|
size: encoded.length,
|
|
234
569
|
checksum
|
|
235
570
|
}, {
|
|
236
|
-
F:
|
|
571
|
+
F: __dxlog_file3,
|
|
237
572
|
L: 124,
|
|
238
573
|
S: this,
|
|
239
574
|
C: (f, a) => f(...a)
|
|
@@ -248,15 +583,15 @@ var MetadataStore = class {
|
|
|
248
583
|
return this._metadata.identity.haloSpace;
|
|
249
584
|
}
|
|
250
585
|
const space = this.spaces.find((space2) => space2.key === spaceKey);
|
|
251
|
-
(0,
|
|
586
|
+
(0, import_tiny_invariant4.default)(space, "Space not found");
|
|
252
587
|
return space;
|
|
253
588
|
}
|
|
254
589
|
/**
|
|
255
590
|
* Clears storage - doesn't work for now.
|
|
256
591
|
*/
|
|
257
592
|
async clear() {
|
|
258
|
-
(0,
|
|
259
|
-
F:
|
|
593
|
+
(0, import_log3.log)("clearing all metadata", void 0, {
|
|
594
|
+
F: __dxlog_file3,
|
|
260
595
|
L: 145,
|
|
261
596
|
S: this,
|
|
262
597
|
C: (f, a) => f(...a)
|
|
@@ -268,13 +603,13 @@ var MetadataStore = class {
|
|
|
268
603
|
return this._metadata.identity;
|
|
269
604
|
}
|
|
270
605
|
async setIdentityRecord(record) {
|
|
271
|
-
(0,
|
|
606
|
+
(0, import_tiny_invariant4.default)(!this._metadata.identity, "Cannot overwrite existing identity in metadata");
|
|
272
607
|
this._metadata.identity = record;
|
|
273
608
|
await this._save();
|
|
274
609
|
}
|
|
275
610
|
async addSpace(record) {
|
|
276
611
|
var _a, _b, _c;
|
|
277
|
-
(0,
|
|
612
|
+
(0, import_tiny_invariant4.default)(!((_a = this._metadata.spaces) != null ? _a : []).find((space) => space.key === record.key), "Cannot overwrite existing space in metadata");
|
|
278
613
|
((_c = (_b = this._metadata).spaces) != null ? _c : _b.spaces = []).push(record);
|
|
279
614
|
await this._save();
|
|
280
615
|
}
|
|
@@ -301,56 +636,40 @@ var MetadataStore = class {
|
|
|
301
636
|
await this._save();
|
|
302
637
|
}
|
|
303
638
|
};
|
|
304
|
-
|
|
305
|
-
|
|
639
|
+
_ts_decorate2([
|
|
640
|
+
import_async2.synchronized
|
|
306
641
|
], MetadataStore.prototype, "load", null);
|
|
307
|
-
|
|
308
|
-
|
|
642
|
+
_ts_decorate2([
|
|
643
|
+
import_async2.synchronized
|
|
309
644
|
], MetadataStore.prototype, "_save", null);
|
|
310
645
|
var fromBytesInt32 = (buf) => buf.readInt32LE(0);
|
|
311
646
|
|
|
312
647
|
// packages/core/echo/echo-pipeline/src/pipeline/pipeline.ts
|
|
313
|
-
var
|
|
314
|
-
var
|
|
315
|
-
var
|
|
316
|
-
var
|
|
648
|
+
var import_tiny_invariant6 = __toESM(require("tiny-invariant"));
|
|
649
|
+
var import_async4 = require("@dxos/async");
|
|
650
|
+
var import_context3 = require("@dxos/context");
|
|
651
|
+
var import_debug4 = require("@dxos/debug");
|
|
317
652
|
var import_feed_store = require("@dxos/feed-store");
|
|
318
|
-
var
|
|
319
|
-
var
|
|
653
|
+
var import_keys3 = require("@dxos/keys");
|
|
654
|
+
var import_log6 = require("@dxos/log");
|
|
320
655
|
var import_timeframe2 = require("@dxos/timeframe");
|
|
321
|
-
var
|
|
322
|
-
|
|
323
|
-
// packages/core/echo/echo-pipeline/src/common/codec.ts
|
|
324
|
-
var import_hypercore = require("@dxos/hypercore");
|
|
325
|
-
var import_protocols2 = require("@dxos/protocols");
|
|
326
|
-
var codec = import_protocols2.schema.getCodecForType("dxos.echo.feed.FeedMessage");
|
|
327
|
-
var valueEncoding = (0, import_hypercore.createCodecEncoding)(codec);
|
|
328
|
-
|
|
329
|
-
// packages/core/echo/echo-pipeline/src/common/feeds.ts
|
|
330
|
-
var import_tiny_invariant2 = __toESM(require("tiny-invariant"));
|
|
331
|
-
var createMappedFeedWriter = (mapper, writer) => {
|
|
332
|
-
(0, import_tiny_invariant2.default)(mapper);
|
|
333
|
-
(0, import_tiny_invariant2.default)(writer);
|
|
334
|
-
return {
|
|
335
|
-
write: async (data, options) => await writer.write(await mapper(data), options)
|
|
336
|
-
};
|
|
337
|
-
};
|
|
656
|
+
var import_util4 = require("@dxos/util");
|
|
338
657
|
|
|
339
658
|
// packages/core/echo/echo-pipeline/src/pipeline/message-selector.ts
|
|
340
|
-
var
|
|
341
|
-
var
|
|
342
|
-
var
|
|
659
|
+
var import_tiny_invariant5 = __toESM(require("tiny-invariant"));
|
|
660
|
+
var import_log4 = require("@dxos/log");
|
|
661
|
+
var __dxlog_file4 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/pipeline/message-selector.ts";
|
|
343
662
|
var createMessageSelector = (timeframeClock) => {
|
|
344
663
|
return (messages) => {
|
|
345
664
|
for (let i = 0; i < messages.length; i++) {
|
|
346
665
|
const { data: { timeframe } } = messages[i];
|
|
347
|
-
(0,
|
|
666
|
+
(0, import_tiny_invariant5.default)(timeframe);
|
|
348
667
|
if (!timeframeClock.hasGaps(timeframe)) {
|
|
349
668
|
return i;
|
|
350
669
|
}
|
|
351
670
|
}
|
|
352
|
-
(0,
|
|
353
|
-
F:
|
|
671
|
+
(0, import_log4.log)("Skipping...", void 0, {
|
|
672
|
+
F: __dxlog_file4,
|
|
354
673
|
L: 34,
|
|
355
674
|
S: void 0,
|
|
356
675
|
C: (f, a) => f(...a)
|
|
@@ -359,11 +678,11 @@ var createMessageSelector = (timeframeClock) => {
|
|
|
359
678
|
};
|
|
360
679
|
|
|
361
680
|
// packages/core/echo/echo-pipeline/src/pipeline/timeframe-clock.ts
|
|
362
|
-
var
|
|
363
|
-
var
|
|
364
|
-
var
|
|
681
|
+
var import_async3 = require("@dxos/async");
|
|
682
|
+
var import_debug3 = require("@dxos/debug");
|
|
683
|
+
var import_log5 = require("@dxos/log");
|
|
365
684
|
var import_timeframe = require("@dxos/timeframe");
|
|
366
|
-
function
|
|
685
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
367
686
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
368
687
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
369
688
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -373,7 +692,7 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
373
692
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
374
693
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
375
694
|
}
|
|
376
|
-
var
|
|
695
|
+
var __dxlog_file5 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/pipeline/timeframe-clock.ts";
|
|
377
696
|
var mapTimeframeToFeedIndexes = (timeframe) => timeframe.frames().map(([feedKey, index]) => ({
|
|
378
697
|
feedKey,
|
|
379
698
|
index
|
|
@@ -390,7 +709,7 @@ var TimeframeClock = class {
|
|
|
390
709
|
// prettier-ignore
|
|
391
710
|
constructor(_timeframe = new import_timeframe.Timeframe()) {
|
|
392
711
|
this._timeframe = _timeframe;
|
|
393
|
-
this.update = new
|
|
712
|
+
this.update = new import_async3.Event();
|
|
394
713
|
this._pendingTimeframe = _timeframe;
|
|
395
714
|
}
|
|
396
715
|
/**
|
|
@@ -428,22 +747,22 @@ var TimeframeClock = class {
|
|
|
428
747
|
return !gaps.isEmpty();
|
|
429
748
|
}
|
|
430
749
|
async waitUntilReached(target) {
|
|
431
|
-
(0,
|
|
750
|
+
(0, import_log5.log)("waitUntilReached", {
|
|
432
751
|
target,
|
|
433
752
|
current: this._timeframe
|
|
434
753
|
}, {
|
|
435
|
-
F:
|
|
754
|
+
F: __dxlog_file5,
|
|
436
755
|
L: 73,
|
|
437
756
|
S: this,
|
|
438
757
|
C: (f, a) => f(...a)
|
|
439
758
|
});
|
|
440
759
|
await this.update.waitForCondition(() => {
|
|
441
|
-
(0,
|
|
760
|
+
(0, import_log5.log)("check if reached", {
|
|
442
761
|
target,
|
|
443
762
|
current: this._timeframe,
|
|
444
763
|
deps: import_timeframe.Timeframe.dependencies(target, this._timeframe)
|
|
445
764
|
}, {
|
|
446
|
-
F:
|
|
765
|
+
F: __dxlog_file5,
|
|
447
766
|
L: 75,
|
|
448
767
|
S: this,
|
|
449
768
|
C: (f, a) => f(...a)
|
|
@@ -452,12 +771,12 @@ var TimeframeClock = class {
|
|
|
452
771
|
});
|
|
453
772
|
}
|
|
454
773
|
};
|
|
455
|
-
|
|
456
|
-
(0,
|
|
774
|
+
_ts_decorate3([
|
|
775
|
+
(0, import_debug3.timed)(5e3)
|
|
457
776
|
], TimeframeClock.prototype, "waitUntilReached", null);
|
|
458
777
|
|
|
459
778
|
// packages/core/echo/echo-pipeline/src/pipeline/pipeline.ts
|
|
460
|
-
function
|
|
779
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
461
780
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
462
781
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
463
782
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -467,15 +786,15 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
467
786
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
468
787
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
469
788
|
}
|
|
470
|
-
var
|
|
789
|
+
var __dxlog_file6 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/pipeline/pipeline.ts";
|
|
471
790
|
var PipelineState = class {
|
|
472
791
|
// prettier-ignore
|
|
473
792
|
constructor(_feeds, _timeframeClock) {
|
|
474
793
|
this._feeds = _feeds;
|
|
475
794
|
this._timeframeClock = _timeframeClock;
|
|
476
|
-
this._ctx = new
|
|
795
|
+
this._ctx = new import_context3.Context();
|
|
477
796
|
this.timeframeUpdate = this._timeframeClock.update;
|
|
478
|
-
this.stalled = new
|
|
797
|
+
this.stalled = new import_async4.Event();
|
|
479
798
|
this._startTimeframe = new import_timeframe2.Timeframe();
|
|
480
799
|
}
|
|
481
800
|
/**
|
|
@@ -517,14 +836,14 @@ var PipelineState = class {
|
|
|
517
836
|
*
|
|
518
837
|
* @param timeout Timeout in milliseconds to specify the maximum wait time.
|
|
519
838
|
*/
|
|
520
|
-
async waitUntilReachedTargetTimeframe({ ctx = new
|
|
839
|
+
async waitUntilReachedTargetTimeframe({ ctx = new import_context3.Context(), timeout, breakOnStall = true } = {}) {
|
|
521
840
|
var _a;
|
|
522
|
-
(0,
|
|
841
|
+
(0, import_log6.log)("waitUntilReachedTargetTimeframe", {
|
|
523
842
|
timeout,
|
|
524
843
|
current: this.timeframe,
|
|
525
844
|
target: this.targetTimeframe
|
|
526
845
|
}, {
|
|
527
|
-
F:
|
|
846
|
+
F: __dxlog_file6,
|
|
528
847
|
L: 126,
|
|
529
848
|
S: this,
|
|
530
849
|
C: (f, a) => f(...a)
|
|
@@ -540,22 +859,22 @@ var PipelineState = class {
|
|
|
540
859
|
let done = false;
|
|
541
860
|
if (timeout) {
|
|
542
861
|
return Promise.race([
|
|
543
|
-
(0,
|
|
544
|
-
(0,
|
|
862
|
+
(0, import_context3.rejectOnDispose)(ctx),
|
|
863
|
+
(0, import_context3.rejectOnDispose)(this._ctx),
|
|
545
864
|
this._reachedTargetPromise.then(() => {
|
|
546
865
|
done = true;
|
|
547
866
|
}),
|
|
548
|
-
(0,
|
|
867
|
+
(0, import_async4.sleep)(timeout).then(() => {
|
|
549
868
|
if (done) {
|
|
550
869
|
return;
|
|
551
870
|
}
|
|
552
|
-
|
|
871
|
+
import_log6.log.warn("waitUntilReachedTargetTimeframe timed out", {
|
|
553
872
|
timeout,
|
|
554
873
|
current: this.timeframe,
|
|
555
874
|
target: this.targetTimeframe,
|
|
556
875
|
dependencies: import_timeframe2.Timeframe.dependencies(this.targetTimeframe, this.timeframe)
|
|
557
876
|
}, {
|
|
558
|
-
F:
|
|
877
|
+
F: __dxlog_file6,
|
|
559
878
|
L: 153,
|
|
560
879
|
S: this,
|
|
561
880
|
C: (f, a) => f(...a)
|
|
@@ -570,12 +889,12 @@ var PipelineState = class {
|
|
|
570
889
|
var Pipeline = class {
|
|
571
890
|
constructor() {
|
|
572
891
|
this._timeframeClock = new TimeframeClock(new import_timeframe2.Timeframe());
|
|
573
|
-
this._feeds = new
|
|
892
|
+
this._feeds = new import_util4.ComplexMap(import_keys3.PublicKey.hash);
|
|
574
893
|
// External state accessor.
|
|
575
894
|
this._state = new PipelineState(this._feeds, this._timeframeClock);
|
|
576
895
|
// Waits for the message consumer to process the message and yield control back to the pipeline.
|
|
577
|
-
this._processingTrigger = new
|
|
578
|
-
this._pauseTrigger = new
|
|
896
|
+
this._processingTrigger = new import_async4.Trigger().wake();
|
|
897
|
+
this._pauseTrigger = new import_async4.Trigger().wake();
|
|
579
898
|
this._isStopping = false;
|
|
580
899
|
this._isStarted = false;
|
|
581
900
|
this._isOpen = false;
|
|
@@ -585,9 +904,12 @@ var Pipeline = class {
|
|
|
585
904
|
return this._state;
|
|
586
905
|
}
|
|
587
906
|
get writer() {
|
|
588
|
-
(0,
|
|
907
|
+
(0, import_tiny_invariant6.default)(this._writer, "Writer not set.");
|
|
589
908
|
return this._writer;
|
|
590
909
|
}
|
|
910
|
+
hasFeed(feedKey) {
|
|
911
|
+
return this._feeds.has(feedKey);
|
|
912
|
+
}
|
|
591
913
|
getFeeds() {
|
|
592
914
|
return this._feedSetIterator.feeds;
|
|
593
915
|
}
|
|
@@ -600,39 +922,36 @@ var Pipeline = class {
|
|
|
600
922
|
}
|
|
601
923
|
this._setFeedDownloadState(feed);
|
|
602
924
|
}
|
|
603
|
-
hasFeed(feedKey) {
|
|
604
|
-
return this._feeds.has(feedKey);
|
|
605
|
-
}
|
|
606
925
|
setWriteFeed(feed) {
|
|
607
|
-
(0,
|
|
608
|
-
(0,
|
|
926
|
+
(0, import_tiny_invariant6.default)(!this._writer, "Writer already set.");
|
|
927
|
+
(0, import_tiny_invariant6.default)(feed.properties.writable, "Feed must be writable.");
|
|
609
928
|
this._writer = createMappedFeedWriter((payload) => ({
|
|
610
929
|
timeframe: this._timeframeClock.timeframe,
|
|
611
930
|
payload
|
|
612
931
|
}), feed.createFeedWriter());
|
|
613
932
|
}
|
|
614
933
|
async start() {
|
|
615
|
-
(0,
|
|
616
|
-
F:
|
|
617
|
-
L:
|
|
934
|
+
(0, import_log6.log)("starting...", void 0, {
|
|
935
|
+
F: __dxlog_file6,
|
|
936
|
+
L: 268,
|
|
618
937
|
S: this,
|
|
619
938
|
C: (f, a) => f(...a)
|
|
620
939
|
});
|
|
621
940
|
await this._initIterator();
|
|
622
941
|
await this._feedSetIterator.open();
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
942
|
+
this._isStarted = true;
|
|
943
|
+
(0, import_log6.log)("started", void 0, {
|
|
944
|
+
F: __dxlog_file6,
|
|
945
|
+
L: 272,
|
|
626
946
|
S: this,
|
|
627
947
|
C: (f, a) => f(...a)
|
|
628
948
|
});
|
|
629
|
-
this._isStarted = true;
|
|
630
949
|
}
|
|
631
950
|
async stop() {
|
|
632
951
|
var _a;
|
|
633
|
-
(0,
|
|
634
|
-
F:
|
|
635
|
-
L:
|
|
952
|
+
(0, import_log6.log)("stopping...", void 0, {
|
|
953
|
+
F: __dxlog_file6,
|
|
954
|
+
L: 277,
|
|
636
955
|
S: this,
|
|
637
956
|
C: (f, a) => f(...a)
|
|
638
957
|
});
|
|
@@ -640,21 +959,22 @@ var Pipeline = class {
|
|
|
640
959
|
await ((_a = this._feedSetIterator) == null ? void 0 : _a.close());
|
|
641
960
|
await this._processingTrigger.wait();
|
|
642
961
|
await this._state._ctx.dispose();
|
|
643
|
-
this._state._ctx = new
|
|
962
|
+
this._state._ctx = new import_context3.Context();
|
|
644
963
|
this._state._reachedTargetPromise = void 0;
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
964
|
+
this._isStarted = false;
|
|
965
|
+
(0, import_log6.log)("stopped", void 0, {
|
|
966
|
+
F: __dxlog_file6,
|
|
967
|
+
L: 285,
|
|
648
968
|
S: this,
|
|
649
969
|
C: (f, a) => f(...a)
|
|
650
970
|
});
|
|
651
|
-
this._isStarted = false;
|
|
652
971
|
}
|
|
653
972
|
/**
|
|
654
|
-
* @param timeframe Timeframe of already processed messages.
|
|
973
|
+
* @param timeframe Timeframe of already processed messages.
|
|
974
|
+
* The pipeline will start processing messages AFTER this timeframe.
|
|
655
975
|
*/
|
|
656
976
|
async setCursor(timeframe) {
|
|
657
|
-
(0,
|
|
977
|
+
(0, import_tiny_invariant6.default)(!this._isStarted || this._isPaused, "Invalid state.");
|
|
658
978
|
this._state._startTimeframe = timeframe;
|
|
659
979
|
this._timeframeClock.setTimeframe(timeframe);
|
|
660
980
|
for (const feed of this._feeds.values()) {
|
|
@@ -670,7 +990,7 @@ var Pipeline = class {
|
|
|
670
990
|
* Calling pause while processing will cause a deadlock.
|
|
671
991
|
*/
|
|
672
992
|
async pause() {
|
|
673
|
-
(0,
|
|
993
|
+
(0, import_tiny_invariant6.default)(this._isStarted, "Pipeline is not open.");
|
|
674
994
|
if (this._isPaused) {
|
|
675
995
|
return;
|
|
676
996
|
}
|
|
@@ -679,8 +999,8 @@ var Pipeline = class {
|
|
|
679
999
|
this._isPaused = true;
|
|
680
1000
|
}
|
|
681
1001
|
async unpause() {
|
|
682
|
-
(0,
|
|
683
|
-
(0,
|
|
1002
|
+
(0, import_tiny_invariant6.default)(this._isStarted, "Pipeline is not open.");
|
|
1003
|
+
(0, import_tiny_invariant6.default)(this._isPaused, "Pipeline is not paused.");
|
|
684
1004
|
this._pauseTrigger.wake();
|
|
685
1005
|
this._isPaused = false;
|
|
686
1006
|
}
|
|
@@ -689,28 +1009,27 @@ var Pipeline = class {
|
|
|
689
1009
|
* Updates the timeframe clock after the message has bee processed.
|
|
690
1010
|
*/
|
|
691
1011
|
async *consume() {
|
|
692
|
-
(0,
|
|
1012
|
+
(0, import_tiny_invariant6.default)(!this._isOpen, "Pipeline is already being consumed.");
|
|
693
1013
|
this._isOpen = true;
|
|
694
|
-
(0,
|
|
1014
|
+
(0, import_tiny_invariant6.default)(this._feedSetIterator, "Iterator not initialized.");
|
|
695
1015
|
let lastFeedSetIterator = this._feedSetIterator;
|
|
696
1016
|
let iterable = lastFeedSetIterator[Symbol.asyncIterator]();
|
|
697
1017
|
while (!this._isStopping) {
|
|
698
1018
|
await this._pauseTrigger.wait();
|
|
699
1019
|
if (lastFeedSetIterator !== this._feedSetIterator) {
|
|
700
|
-
(0,
|
|
1020
|
+
(0, import_tiny_invariant6.default)(this._feedSetIterator, "Iterator not initialized.");
|
|
701
1021
|
lastFeedSetIterator = this._feedSetIterator;
|
|
702
1022
|
iterable = lastFeedSetIterator[Symbol.asyncIterator]();
|
|
703
1023
|
}
|
|
704
1024
|
const { done, value } = await iterable.next();
|
|
705
|
-
if (done) {
|
|
706
|
-
|
|
1025
|
+
if (!done) {
|
|
1026
|
+
const block = value != null ? value : (0, import_debug4.failUndefined)();
|
|
1027
|
+
this._processingTrigger.reset();
|
|
1028
|
+
this._timeframeClock.updatePendingTimeframe(import_keys3.PublicKey.from(block.feedKey), block.seq);
|
|
1029
|
+
yield block;
|
|
1030
|
+
this._processingTrigger.wake();
|
|
1031
|
+
this._timeframeClock.updateTimeframe();
|
|
707
1032
|
}
|
|
708
|
-
const block = value != null ? value : (0, import_debug2.failUndefined)();
|
|
709
|
-
this._processingTrigger.reset();
|
|
710
|
-
this._timeframeClock.updatePendingTimeframe(import_keys.PublicKey.from(block.feedKey), block.seq);
|
|
711
|
-
yield block;
|
|
712
|
-
this._processingTrigger.wake();
|
|
713
|
-
this._timeframeClock.updateTimeframe();
|
|
714
1033
|
}
|
|
715
1034
|
this._isOpen = false;
|
|
716
1035
|
}
|
|
@@ -719,9 +1038,9 @@ var Pipeline = class {
|
|
|
719
1038
|
const timeframe = this._state._startTimeframe;
|
|
720
1039
|
const seq = (_a = timeframe.get(feed.key)) != null ? _a : 0;
|
|
721
1040
|
feed.undownload({
|
|
722
|
-
callback: () => (0,
|
|
723
|
-
F:
|
|
724
|
-
L:
|
|
1041
|
+
callback: () => (0, import_log6.log)("undownload", void 0, {
|
|
1042
|
+
F: __dxlog_file6,
|
|
1043
|
+
L: 376,
|
|
725
1044
|
S: this,
|
|
726
1045
|
C: (f, a) => f(...a)
|
|
727
1046
|
})
|
|
@@ -730,11 +1049,11 @@ var Pipeline = class {
|
|
|
730
1049
|
start: seq + 1,
|
|
731
1050
|
linear: true
|
|
732
1051
|
}).catch((err) => {
|
|
733
|
-
(0,
|
|
1052
|
+
(0, import_log6.log)("failed to download feed", {
|
|
734
1053
|
err
|
|
735
1054
|
}, {
|
|
736
|
-
F:
|
|
737
|
-
L:
|
|
1055
|
+
F: __dxlog_file6,
|
|
1056
|
+
L: 378,
|
|
738
1057
|
S: this,
|
|
739
1058
|
C: (f, a) => f(...a)
|
|
740
1059
|
});
|
|
@@ -746,9 +1065,9 @@ var Pipeline = class {
|
|
|
746
1065
|
stallTimeout: 1e3
|
|
747
1066
|
});
|
|
748
1067
|
this._feedSetIterator.stalled.on((iterator) => {
|
|
749
|
-
|
|
750
|
-
F:
|
|
751
|
-
L:
|
|
1068
|
+
import_log6.log.warn(`Stalled after ${iterator.options.stallTimeout}ms with ${iterator.size} feeds.`, void 0, {
|
|
1069
|
+
F: __dxlog_file6,
|
|
1070
|
+
L: 389,
|
|
752
1071
|
S: this,
|
|
753
1072
|
C: (f, a) => f(...a)
|
|
754
1073
|
});
|
|
@@ -759,591 +1078,273 @@ var Pipeline = class {
|
|
|
759
1078
|
}
|
|
760
1079
|
}
|
|
761
1080
|
};
|
|
762
|
-
|
|
763
|
-
|
|
1081
|
+
_ts_decorate4([
|
|
1082
|
+
import_async4.synchronized
|
|
764
1083
|
], Pipeline.prototype, "start", null);
|
|
765
|
-
|
|
766
|
-
|
|
1084
|
+
_ts_decorate4([
|
|
1085
|
+
import_async4.synchronized
|
|
767
1086
|
], Pipeline.prototype, "stop", null);
|
|
768
|
-
|
|
769
|
-
|
|
1087
|
+
_ts_decorate4([
|
|
1088
|
+
import_async4.synchronized
|
|
770
1089
|
], Pipeline.prototype, "setCursor", null);
|
|
771
|
-
|
|
772
|
-
|
|
1090
|
+
_ts_decorate4([
|
|
1091
|
+
import_async4.synchronized
|
|
773
1092
|
], Pipeline.prototype, "pause", null);
|
|
774
|
-
_ts_decorate3([
|
|
775
|
-
import_async3.synchronized
|
|
776
|
-
], Pipeline.prototype, "unpause", null);
|
|
777
|
-
|
|
778
|
-
// packages/core/echo/echo-pipeline/src/space/auth.ts
|
|
779
|
-
var import_tiny_invariant5 = __toESM(require("tiny-invariant"));
|
|
780
|
-
var import_async4 = require("@dxos/async");
|
|
781
|
-
var import_context2 = require("@dxos/context");
|
|
782
|
-
var import_crypto = require("@dxos/crypto");
|
|
783
|
-
var import_log5 = require("@dxos/log");
|
|
784
|
-
var import_protocols3 = require("@dxos/protocols");
|
|
785
|
-
var import_teleport = require("@dxos/teleport");
|
|
786
|
-
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/auth.ts";
|
|
787
|
-
var AuthExtension = class extends import_teleport.RpcExtension {
|
|
788
|
-
constructor(_authParams) {
|
|
789
|
-
super({
|
|
790
|
-
requested: {
|
|
791
|
-
AuthService: import_protocols3.schema.getService("dxos.mesh.teleport.auth.AuthService")
|
|
792
|
-
},
|
|
793
|
-
exposed: {
|
|
794
|
-
AuthService: import_protocols3.schema.getService("dxos.mesh.teleport.auth.AuthService")
|
|
795
|
-
},
|
|
796
|
-
timeout: 60 * 1e3
|
|
797
|
-
});
|
|
798
|
-
this._authParams = _authParams;
|
|
799
|
-
this._ctx = new import_context2.Context({
|
|
800
|
-
onError: (err) => {
|
|
801
|
-
import_log5.log.catch(err, void 0, {
|
|
802
|
-
F: __dxlog_file5,
|
|
803
|
-
L: 29,
|
|
804
|
-
S: this,
|
|
805
|
-
C: (f, a) => f(...a)
|
|
806
|
-
});
|
|
807
|
-
}
|
|
808
|
-
});
|
|
809
|
-
}
|
|
810
|
-
async getHandlers() {
|
|
811
|
-
return {
|
|
812
|
-
AuthService: {
|
|
813
|
-
authenticate: async ({ challenge }) => {
|
|
814
|
-
try {
|
|
815
|
-
const credential = await this._authParams.provider(challenge);
|
|
816
|
-
if (!credential) {
|
|
817
|
-
throw new Error("auth rejected");
|
|
818
|
-
}
|
|
819
|
-
return {
|
|
820
|
-
credential
|
|
821
|
-
};
|
|
822
|
-
} catch (err) {
|
|
823
|
-
import_log5.log.error("failed to generate auth credentials", err, {
|
|
824
|
-
F: __dxlog_file5,
|
|
825
|
-
L: 56,
|
|
826
|
-
S: this,
|
|
827
|
-
C: (f, a) => f(...a)
|
|
828
|
-
});
|
|
829
|
-
throw new Error("auth rejected");
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
};
|
|
834
|
-
}
|
|
835
|
-
async onOpen(context) {
|
|
836
|
-
await super.onOpen(context);
|
|
837
|
-
(0, import_async4.scheduleTask)(this._ctx, async () => {
|
|
838
|
-
try {
|
|
839
|
-
const challenge = (0, import_crypto.randomBytes)(32);
|
|
840
|
-
const { credential } = await this.rpc.AuthService.authenticate({
|
|
841
|
-
challenge
|
|
842
|
-
});
|
|
843
|
-
(0, import_tiny_invariant5.default)((credential == null ? void 0 : credential.length) > 0, "invalid credential");
|
|
844
|
-
const success = await this._authParams.verifier(challenge, credential);
|
|
845
|
-
(0, import_tiny_invariant5.default)(success, "credential not verified");
|
|
846
|
-
(0, import_async4.runInContext)(this._ctx, () => this._authParams.onAuthSuccess());
|
|
847
|
-
} catch (err) {
|
|
848
|
-
(0, import_log5.log)("auth failed", err, {
|
|
849
|
-
F: __dxlog_file5,
|
|
850
|
-
L: 75,
|
|
851
|
-
S: this,
|
|
852
|
-
C: (f, a) => f(...a)
|
|
853
|
-
});
|
|
854
|
-
this.close();
|
|
855
|
-
this._authParams.onAuthFailure();
|
|
856
|
-
}
|
|
857
|
-
});
|
|
858
|
-
}
|
|
859
|
-
async onClose() {
|
|
860
|
-
await this._ctx.dispose();
|
|
861
|
-
await super.onClose();
|
|
862
|
-
}
|
|
863
|
-
};
|
|
864
|
-
|
|
865
|
-
// packages/core/echo/echo-pipeline/src/space/space.ts
|
|
866
|
-
var import_tiny_invariant9 = __toESM(require("tiny-invariant"));
|
|
867
|
-
var import_async7 = require("@dxos/async");
|
|
868
|
-
var import_log10 = require("@dxos/log");
|
|
869
|
-
var import_credentials4 = require("@dxos/protocols/proto/dxos/halo/credentials");
|
|
870
|
-
var import_util6 = require("@dxos/util");
|
|
871
|
-
|
|
872
|
-
// packages/core/echo/echo-pipeline/src/space/control-pipeline.ts
|
|
873
|
-
var import_credentials = require("@dxos/credentials");
|
|
874
|
-
var import_keys2 = require("@dxos/keys");
|
|
875
|
-
var import_log6 = require("@dxos/log");
|
|
876
|
-
var import_credentials2 = require("@dxos/protocols/proto/dxos/halo/credentials");
|
|
877
|
-
var import_timeframe3 = require("@dxos/timeframe");
|
|
878
|
-
var import_util3 = require("@dxos/util");
|
|
879
|
-
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/control-pipeline.ts";
|
|
880
|
-
var TIMEFRAME_SAVE_DEBOUNCE_INTERVAL = 500;
|
|
881
|
-
var ControlPipeline = class {
|
|
882
|
-
constructor({ spaceKey, genesisFeed, feedProvider, metadataStore }) {
|
|
883
|
-
this._lastTimeframeSaveTime = Date.now();
|
|
884
|
-
this.onFeedAdmitted = new import_util3.Callback();
|
|
885
|
-
this._spaceKey = spaceKey;
|
|
886
|
-
this._metadata = metadataStore;
|
|
887
|
-
this._pipeline = new Pipeline();
|
|
888
|
-
void this._pipeline.addFeed(genesisFeed);
|
|
889
|
-
this._spaceStateMachine = new import_credentials.SpaceStateMachine(spaceKey);
|
|
890
|
-
this._spaceStateMachine.onFeedAdmitted.set(async (info) => {
|
|
891
|
-
(0, import_log6.log)("feed admitted", {
|
|
892
|
-
key: info.key
|
|
893
|
-
}, {
|
|
894
|
-
F: __dxlog_file6,
|
|
895
|
-
L: 51,
|
|
896
|
-
S: this,
|
|
897
|
-
C: (f, a) => f(...a)
|
|
898
|
-
});
|
|
899
|
-
if (info.assertion.designation === import_credentials2.AdmittedFeed.Designation.CONTROL && !info.key.equals(genesisFeed.key)) {
|
|
900
|
-
try {
|
|
901
|
-
const feed = await feedProvider(info.key);
|
|
902
|
-
await this._pipeline.addFeed(feed);
|
|
903
|
-
} catch (err) {
|
|
904
|
-
import_log6.log.catch(err, void 0, {
|
|
905
|
-
F: __dxlog_file6,
|
|
906
|
-
L: 59,
|
|
907
|
-
S: this,
|
|
908
|
-
C: (f, a) => f(...a)
|
|
909
|
-
});
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
await this.onFeedAdmitted.callIfSet(info);
|
|
913
|
-
});
|
|
914
|
-
this.onMemberAdmitted = this._spaceStateMachine.onMemberAdmitted;
|
|
915
|
-
this.onCredentialProcessed = this._spaceStateMachine.onCredentialProcessed;
|
|
916
|
-
}
|
|
917
|
-
get spaceState() {
|
|
918
|
-
return this._spaceStateMachine;
|
|
919
|
-
}
|
|
920
|
-
get pipeline() {
|
|
921
|
-
return this._pipeline;
|
|
922
|
-
}
|
|
923
|
-
setWriteFeed(feed) {
|
|
924
|
-
this._pipeline.setWriteFeed(feed);
|
|
925
|
-
}
|
|
926
|
-
async start() {
|
|
927
|
-
(0, import_log6.log)("starting...", void 0, {
|
|
928
|
-
F: __dxlog_file6,
|
|
929
|
-
L: 83,
|
|
930
|
-
S: this,
|
|
931
|
-
C: (f, a) => f(...a)
|
|
932
|
-
});
|
|
933
|
-
setTimeout(async () => {
|
|
934
|
-
for await (const msg of this._pipeline.consume()) {
|
|
935
|
-
try {
|
|
936
|
-
(0, import_log6.log)("processing", {
|
|
937
|
-
key: msg.feedKey,
|
|
938
|
-
seq: msg.seq
|
|
939
|
-
}, {
|
|
940
|
-
F: __dxlog_file6,
|
|
941
|
-
L: 88,
|
|
942
|
-
S: this,
|
|
943
|
-
C: (f, a) => f(...a)
|
|
944
|
-
});
|
|
945
|
-
if (msg.data.payload.credential) {
|
|
946
|
-
const result = await this._spaceStateMachine.process(msg.data.payload.credential.credential, import_keys2.PublicKey.from(msg.feedKey));
|
|
947
|
-
if (!result) {
|
|
948
|
-
import_log6.log.warn("processing failed", {
|
|
949
|
-
msg
|
|
950
|
-
}, {
|
|
951
|
-
F: __dxlog_file6,
|
|
952
|
-
L: 95,
|
|
953
|
-
S: this,
|
|
954
|
-
C: (f, a) => f(...a)
|
|
955
|
-
});
|
|
956
|
-
} else {
|
|
957
|
-
await this._noteTargetStateIfNeeded(this._pipeline.state.pendingTimeframe);
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
} catch (err) {
|
|
961
|
-
import_log6.log.catch(err, void 0, {
|
|
962
|
-
F: __dxlog_file6,
|
|
963
|
-
L: 101,
|
|
964
|
-
S: this,
|
|
965
|
-
C: (f, a) => f(...a)
|
|
966
|
-
});
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
});
|
|
970
|
-
await this._pipeline.start();
|
|
971
|
-
(0, import_log6.log)("started", void 0, {
|
|
972
|
-
F: __dxlog_file6,
|
|
973
|
-
L: 107,
|
|
974
|
-
S: this,
|
|
975
|
-
C: (f, a) => f(...a)
|
|
976
|
-
});
|
|
977
|
-
}
|
|
978
|
-
async _noteTargetStateIfNeeded(timeframe) {
|
|
979
|
-
if (Date.now() - this._lastTimeframeSaveTime > TIMEFRAME_SAVE_DEBOUNCE_INTERVAL) {
|
|
980
|
-
this._lastTimeframeSaveTime = Date.now();
|
|
981
|
-
await this._saveTargetTimeframe(timeframe);
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
async stop() {
|
|
985
|
-
(0, import_log6.log)("stopping...", void 0, {
|
|
986
|
-
F: __dxlog_file6,
|
|
987
|
-
L: 121,
|
|
988
|
-
S: this,
|
|
989
|
-
C: (f, a) => f(...a)
|
|
990
|
-
});
|
|
991
|
-
await this._pipeline.stop();
|
|
992
|
-
await this._saveTargetTimeframe(this._pipeline.state.timeframe);
|
|
993
|
-
(0, import_log6.log)("stopped", void 0, {
|
|
994
|
-
F: __dxlog_file6,
|
|
995
|
-
L: 124,
|
|
996
|
-
S: this,
|
|
997
|
-
C: (f, a) => f(...a)
|
|
998
|
-
});
|
|
999
|
-
}
|
|
1000
|
-
async _saveTargetTimeframe(timeframe) {
|
|
1001
|
-
var _a;
|
|
1002
|
-
try {
|
|
1003
|
-
const newTimeframe = import_timeframe3.Timeframe.merge((_a = this._targetTimeframe) != null ? _a : new import_timeframe3.Timeframe(), timeframe);
|
|
1004
|
-
await this._metadata.setSpaceControlLatestTimeframe(this._spaceKey, newTimeframe);
|
|
1005
|
-
this._targetTimeframe = newTimeframe;
|
|
1006
|
-
} catch (err) {
|
|
1007
|
-
(0, import_log6.log)(err, void 0, {
|
|
1008
|
-
F: __dxlog_file6,
|
|
1009
|
-
L: 133,
|
|
1010
|
-
S: this,
|
|
1011
|
-
C: (f, a) => f(...a)
|
|
1012
|
-
});
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
};
|
|
1016
|
-
|
|
1017
|
-
// packages/core/echo/echo-pipeline/src/space/data-pipeline.ts
|
|
1018
|
-
var import_tiny_invariant8 = __toESM(require("tiny-invariant"));
|
|
1019
|
-
var import_async6 = require("@dxos/async");
|
|
1020
|
-
var import_context5 = require("@dxos/context");
|
|
1021
|
-
var import_credentials3 = require("@dxos/credentials");
|
|
1022
|
-
var import_echo_db3 = require("@dxos/echo-db");
|
|
1023
|
-
var import_errors2 = require("@dxos/errors");
|
|
1024
|
-
var import_log9 = require("@dxos/log");
|
|
1025
|
-
var import_timeframe4 = require("@dxos/timeframe");
|
|
1026
|
-
|
|
1027
|
-
// packages/core/echo/echo-pipeline/src/dbhost/data-service-host.ts
|
|
1028
|
-
var import_tiny_invariant6 = __toESM(require("tiny-invariant"));
|
|
1029
|
-
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
1030
|
-
var import_context3 = require("@dxos/context");
|
|
1031
|
-
var import_echo_db = require("@dxos/echo-db");
|
|
1032
|
-
var import_log7 = require("@dxos/log");
|
|
1033
|
-
var import_util4 = require("@dxos/util");
|
|
1034
|
-
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/dbhost/data-service-host.ts";
|
|
1035
|
-
var DataServiceHost = class {
|
|
1036
|
-
constructor(_itemManager, _itemDemuxer, _writeStream) {
|
|
1037
|
-
this._itemManager = _itemManager;
|
|
1038
|
-
this._itemDemuxer = _itemDemuxer;
|
|
1039
|
-
this._writeStream = _writeStream;
|
|
1040
|
-
this._ctx = new import_context3.Context();
|
|
1041
|
-
this._clientTagMap = new import_util4.ComplexMap(([feedKey, seq]) => `${feedKey.toHex()}:${seq}`);
|
|
1042
|
-
}
|
|
1043
|
-
async open() {
|
|
1044
|
-
}
|
|
1045
|
-
async close() {
|
|
1046
|
-
await this._ctx.dispose();
|
|
1047
|
-
}
|
|
1048
|
-
/**
|
|
1049
|
-
* Real-time subscription to data objects in a space.
|
|
1050
|
-
*/
|
|
1051
|
-
subscribe() {
|
|
1052
|
-
return new import_codec_protobuf.Stream(({ next, close, ctx }) => {
|
|
1053
|
-
ctx.onDispose(this._ctx.onDispose(close));
|
|
1054
|
-
const objects = Array.from(this._itemManager.entities.values()).map((entity) => entity.createSnapshot());
|
|
1055
|
-
next({
|
|
1056
|
-
batch: {
|
|
1057
|
-
objects
|
|
1058
|
-
}
|
|
1059
|
-
});
|
|
1060
|
-
this._itemDemuxer.mutation.on(ctx, (message) => {
|
|
1061
|
-
var _a;
|
|
1062
|
-
const { batch, meta } = message;
|
|
1063
|
-
(0, import_tiny_invariant6.default)(!meta.clientTag, "Unexpected client tag in mutation message");
|
|
1064
|
-
(0, import_log7.log)("message", {
|
|
1065
|
-
batch,
|
|
1066
|
-
meta
|
|
1067
|
-
}, {
|
|
1068
|
-
F: __dxlog_file7,
|
|
1069
|
-
L: 63,
|
|
1070
|
-
S: this,
|
|
1071
|
-
C: (f, a) => f(...a)
|
|
1072
|
-
});
|
|
1073
|
-
const clientTag = this._clientTagMap.get([
|
|
1074
|
-
message.meta.feedKey,
|
|
1075
|
-
message.meta.seq
|
|
1076
|
-
]);
|
|
1077
|
-
(_a = batch.objects) == null ? void 0 : _a.forEach((object) => {
|
|
1078
|
-
(0, import_echo_db.setMetadataOnObject)(object, {
|
|
1079
|
-
...meta
|
|
1080
|
-
});
|
|
1081
|
-
});
|
|
1082
|
-
if (clientTag) {
|
|
1083
|
-
(0, import_echo_db.tagMutationsInBatch)(batch, clientTag, 0);
|
|
1084
|
-
}
|
|
1085
|
-
next({
|
|
1086
|
-
clientTag,
|
|
1087
|
-
feedKey: message.meta.feedKey,
|
|
1088
|
-
seq: message.meta.seq,
|
|
1089
|
-
batch
|
|
1090
|
-
});
|
|
1091
|
-
});
|
|
1092
|
-
});
|
|
1093
|
-
}
|
|
1094
|
-
async write(request) {
|
|
1095
|
-
var _a, _b;
|
|
1096
|
-
(0, import_tiny_invariant6.default)(!this._ctx.disposed, "Cannot write to closed DataServiceHost");
|
|
1097
|
-
(0, import_tiny_invariant6.default)(this._writeStream, "Cannot write mutations in readonly mode");
|
|
1098
|
-
(0, import_log7.log)("write", {
|
|
1099
|
-
clientTag: request.clientTag,
|
|
1100
|
-
objectCount: (_b = (_a = request.batch.objects) == null ? void 0 : _a.length) != null ? _b : 0
|
|
1101
|
-
}, {
|
|
1102
|
-
F: __dxlog_file7,
|
|
1103
|
-
L: 92,
|
|
1104
|
-
S: this,
|
|
1105
|
-
C: (f, a) => f(...a)
|
|
1106
|
-
});
|
|
1107
|
-
const message = createDataMessage(request.batch);
|
|
1108
|
-
const receipt = await this._writeStream.write(message, {
|
|
1109
|
-
afterWrite: async (receipt2) => {
|
|
1110
|
-
if (request.clientTag) {
|
|
1111
|
-
(0, import_log7.log)("tag", {
|
|
1112
|
-
clientTag: request.clientTag,
|
|
1113
|
-
feedKey: receipt2.feedKey,
|
|
1114
|
-
seq: receipt2.seq
|
|
1115
|
-
}, {
|
|
1116
|
-
F: __dxlog_file7,
|
|
1117
|
-
L: 101,
|
|
1118
|
-
S: this,
|
|
1119
|
-
C: (f, a) => f(...a)
|
|
1120
|
-
});
|
|
1121
|
-
this._clientTagMap.set([
|
|
1122
|
-
receipt2.feedKey,
|
|
1123
|
-
receipt2.seq
|
|
1124
|
-
], request.clientTag);
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
});
|
|
1128
|
-
return receipt;
|
|
1129
|
-
}
|
|
1130
|
-
};
|
|
1131
|
-
var createDataMessage = (batch) => {
|
|
1132
|
-
var _a;
|
|
1133
|
-
return {
|
|
1134
|
-
batch: {
|
|
1135
|
-
objects: (_a = batch.objects) == null ? void 0 : _a.map((object) => {
|
|
1136
|
-
var _a2;
|
|
1137
|
-
return {
|
|
1138
|
-
...object,
|
|
1139
|
-
mutations: (_a2 = object.mutations) == null ? void 0 : _a2.map((mutation) => ({
|
|
1140
|
-
...mutation,
|
|
1141
|
-
meta: void 0
|
|
1142
|
-
})),
|
|
1143
|
-
meta: void 0
|
|
1144
|
-
};
|
|
1145
|
-
})
|
|
1146
|
-
}
|
|
1147
|
-
};
|
|
1148
|
-
};
|
|
1149
|
-
|
|
1150
|
-
// packages/core/echo/echo-pipeline/src/dbhost/database-host.ts
|
|
1151
|
-
var import_echo_db2 = require("@dxos/echo-db");
|
|
1152
|
-
var DatabaseHost = class {
|
|
1153
|
-
constructor(_outboundStream) {
|
|
1154
|
-
this._outboundStream = _outboundStream;
|
|
1155
|
-
}
|
|
1156
|
-
get isReadOnly() {
|
|
1157
|
-
return !!this._outboundStream;
|
|
1158
|
-
}
|
|
1159
|
-
get echoProcessor() {
|
|
1160
|
-
return this._echoProcessor;
|
|
1161
|
-
}
|
|
1162
|
-
async open(itemManager, modelFactory) {
|
|
1163
|
-
this._itemManager = itemManager;
|
|
1164
|
-
this._itemManager._debugLabel = "host";
|
|
1165
|
-
this._itemDemuxer = new import_echo_db2.ItemDemuxer(itemManager, modelFactory);
|
|
1166
|
-
this._echoProcessor = this._itemDemuxer.open();
|
|
1167
|
-
}
|
|
1168
|
-
async close() {
|
|
1169
|
-
}
|
|
1170
|
-
getWriteStream() {
|
|
1171
|
-
return this._outboundStream;
|
|
1172
|
-
}
|
|
1173
|
-
createSnapshot() {
|
|
1174
|
-
return this._itemDemuxer.createSnapshot();
|
|
1175
|
-
}
|
|
1176
|
-
createDataServiceHost() {
|
|
1177
|
-
var _a;
|
|
1178
|
-
return new DataServiceHost(this._itemManager, this._itemDemuxer, (_a = this._outboundStream) != null ? _a : void 0);
|
|
1179
|
-
}
|
|
1180
|
-
};
|
|
1181
|
-
|
|
1182
|
-
// packages/core/echo/echo-pipeline/src/dbhost/snapshot-manager.ts
|
|
1183
|
-
var import_async5 = require("@dxos/async");
|
|
1184
|
-
var import_context4 = require("@dxos/context");
|
|
1185
|
-
var import_debug3 = require("@dxos/debug");
|
|
1186
|
-
var import_keys3 = require("@dxos/keys");
|
|
1187
|
-
var import_protocols4 = require("@dxos/protocols");
|
|
1188
|
-
var import_blob = require("@dxos/protocols/proto/dxos/echo/blob");
|
|
1189
|
-
function _ts_decorate4(decorators, target, key, desc) {
|
|
1190
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1191
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1192
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
1193
|
-
else
|
|
1194
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
1195
|
-
if (d = decorators[i])
|
|
1196
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1197
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1198
|
-
}
|
|
1199
|
-
var SpaceSnapshot = import_protocols4.schema.getCodecForType("dxos.echo.snapshot.SpaceSnapshot");
|
|
1200
|
-
var SnapshotManager = class SnapshotManager2 {
|
|
1201
|
-
// prettier-ignore
|
|
1202
|
-
constructor(_snapshotStore, _blobStore, _blobSync) {
|
|
1203
|
-
this._snapshotStore = _snapshotStore;
|
|
1204
|
-
this._blobStore = _blobStore;
|
|
1205
|
-
this._blobSync = _blobSync;
|
|
1206
|
-
}
|
|
1207
|
-
async _getBlob(blobId) {
|
|
1208
|
-
const blob = await this._blobStore.get(blobId);
|
|
1209
|
-
return SpaceSnapshot.decode(blob);
|
|
1210
|
-
}
|
|
1211
|
-
async load(ctx, id) {
|
|
1212
|
-
const blobId = import_keys3.PublicKey.fromHex(id).asUint8Array();
|
|
1213
|
-
const blobMeta = await this._blobStore.getMeta(blobId);
|
|
1214
|
-
if (blobMeta && blobMeta.state === import_blob.BlobMeta.State.FULLY_PRESENT) {
|
|
1215
|
-
return this._getBlob(blobId);
|
|
1216
|
-
}
|
|
1217
|
-
const fallbackStore = await (0, import_context4.cancelWithContext)(ctx, this._snapshotStore.loadSnapshot(id));
|
|
1218
|
-
if (fallbackStore) {
|
|
1219
|
-
return fallbackStore;
|
|
1220
|
-
}
|
|
1221
|
-
await this._blobSync.download(ctx, blobId);
|
|
1222
|
-
return this._getBlob(blobId);
|
|
1223
|
-
}
|
|
1224
|
-
async store(snapshot) {
|
|
1225
|
-
const { id } = await this._blobStore.set(SpaceSnapshot.encode(snapshot));
|
|
1226
|
-
await this._blobSync.notifyBlobAdded(id);
|
|
1227
|
-
return import_keys3.PublicKey.from(id).toHex();
|
|
1228
|
-
}
|
|
1229
|
-
};
|
|
1230
1093
|
_ts_decorate4([
|
|
1231
|
-
|
|
1232
|
-
],
|
|
1233
|
-
SnapshotManager = _ts_decorate4([
|
|
1234
|
-
(0, import_async5.trackLeaks)("open", "close")
|
|
1235
|
-
], SnapshotManager);
|
|
1094
|
+
import_async4.synchronized
|
|
1095
|
+
], Pipeline.prototype, "unpause", null);
|
|
1236
1096
|
|
|
1237
|
-
// packages/core/echo/echo-pipeline/src/
|
|
1097
|
+
// packages/core/echo/echo-pipeline/src/space/auth.ts
|
|
1098
|
+
var import_tiny_invariant7 = __toESM(require("tiny-invariant"));
|
|
1099
|
+
var import_async5 = require("@dxos/async");
|
|
1100
|
+
var import_context4 = require("@dxos/context");
|
|
1238
1101
|
var import_crypto2 = require("@dxos/crypto");
|
|
1102
|
+
var import_log7 = require("@dxos/log");
|
|
1239
1103
|
var import_protocols5 = require("@dxos/protocols");
|
|
1240
|
-
var
|
|
1241
|
-
var
|
|
1242
|
-
|
|
1243
|
-
constructor(
|
|
1244
|
-
|
|
1104
|
+
var import_teleport = require("@dxos/teleport");
|
|
1105
|
+
var __dxlog_file7 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/space/auth.ts";
|
|
1106
|
+
var AuthExtension = class extends import_teleport.RpcExtension {
|
|
1107
|
+
constructor(_authParams) {
|
|
1108
|
+
super({
|
|
1109
|
+
requested: {
|
|
1110
|
+
AuthService: import_protocols5.schema.getService("dxos.mesh.teleport.auth.AuthService")
|
|
1111
|
+
},
|
|
1112
|
+
exposed: {
|
|
1113
|
+
AuthService: import_protocols5.schema.getService("dxos.mesh.teleport.auth.AuthService")
|
|
1114
|
+
},
|
|
1115
|
+
timeout: 60 * 1e3
|
|
1116
|
+
});
|
|
1117
|
+
this._authParams = _authParams;
|
|
1118
|
+
this._ctx = new import_context4.Context({
|
|
1119
|
+
onError: (err) => {
|
|
1120
|
+
import_log7.log.catch(err, void 0, {
|
|
1121
|
+
F: __dxlog_file7,
|
|
1122
|
+
L: 29,
|
|
1123
|
+
S: this,
|
|
1124
|
+
C: (f, a) => f(...a)
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
});
|
|
1245
1128
|
}
|
|
1246
|
-
async
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1129
|
+
async getHandlers() {
|
|
1130
|
+
return {
|
|
1131
|
+
AuthService: {
|
|
1132
|
+
authenticate: async ({ challenge }) => {
|
|
1133
|
+
try {
|
|
1134
|
+
const credential = await this._authParams.provider(challenge);
|
|
1135
|
+
if (!credential) {
|
|
1136
|
+
throw new Error("auth rejected");
|
|
1137
|
+
}
|
|
1138
|
+
return {
|
|
1139
|
+
credential
|
|
1140
|
+
};
|
|
1141
|
+
} catch (err) {
|
|
1142
|
+
import_log7.log.error("failed to generate auth credentials", err, {
|
|
1143
|
+
F: __dxlog_file7,
|
|
1144
|
+
L: 56,
|
|
1145
|
+
S: this,
|
|
1146
|
+
C: (f, a) => f(...a)
|
|
1147
|
+
});
|
|
1148
|
+
throw new Error("auth rejected");
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
1257
1153
|
}
|
|
1258
|
-
async
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1154
|
+
async onOpen(context) {
|
|
1155
|
+
await super.onOpen(context);
|
|
1156
|
+
(0, import_async5.scheduleTask)(this._ctx, async () => {
|
|
1157
|
+
try {
|
|
1158
|
+
const challenge = (0, import_crypto2.randomBytes)(32);
|
|
1159
|
+
const { credential } = await this.rpc.AuthService.authenticate({
|
|
1160
|
+
challenge
|
|
1161
|
+
});
|
|
1162
|
+
(0, import_tiny_invariant7.default)((credential == null ? void 0 : credential.length) > 0, "invalid credential");
|
|
1163
|
+
const success = await this._authParams.verifier(challenge, credential);
|
|
1164
|
+
(0, import_tiny_invariant7.default)(success, "credential not verified");
|
|
1165
|
+
(0, import_async5.runInContext)(this._ctx, () => this._authParams.onAuthSuccess());
|
|
1166
|
+
} catch (err) {
|
|
1167
|
+
(0, import_log7.log)("auth failed", err, {
|
|
1168
|
+
F: __dxlog_file7,
|
|
1169
|
+
L: 75,
|
|
1170
|
+
S: this,
|
|
1171
|
+
C: (f, a) => f(...a)
|
|
1172
|
+
});
|
|
1173
|
+
this.close();
|
|
1174
|
+
this._authParams.onAuthFailure();
|
|
1264
1175
|
}
|
|
1265
|
-
|
|
1266
|
-
return SpaceSnapshot2.decode(buffer);
|
|
1267
|
-
} finally {
|
|
1268
|
-
await file.close();
|
|
1269
|
-
}
|
|
1176
|
+
});
|
|
1270
1177
|
}
|
|
1271
|
-
async
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
const { size } = await this._directory.getOrCreateFile(key).stat();
|
|
1275
|
-
return {
|
|
1276
|
-
key,
|
|
1277
|
-
size
|
|
1278
|
-
};
|
|
1279
|
-
}));
|
|
1178
|
+
async onClose() {
|
|
1179
|
+
await this._ctx.dispose();
|
|
1180
|
+
await super.onClose();
|
|
1280
1181
|
}
|
|
1281
1182
|
};
|
|
1282
1183
|
|
|
1283
|
-
// packages/core/echo/echo-pipeline/src/
|
|
1284
|
-
var
|
|
1285
|
-
var
|
|
1184
|
+
// packages/core/echo/echo-pipeline/src/space/space.ts
|
|
1185
|
+
var import_tiny_invariant9 = __toESM(require("tiny-invariant"));
|
|
1186
|
+
var import_async7 = require("@dxos/async");
|
|
1187
|
+
var import_log10 = require("@dxos/log");
|
|
1188
|
+
var import_credentials4 = require("@dxos/protocols/proto/dxos/halo/credentials");
|
|
1189
|
+
var import_util7 = require("@dxos/util");
|
|
1190
|
+
|
|
1191
|
+
// packages/core/echo/echo-pipeline/src/space/control-pipeline.ts
|
|
1192
|
+
var import_credentials = require("@dxos/credentials");
|
|
1286
1193
|
var import_keys4 = require("@dxos/keys");
|
|
1287
1194
|
var import_log8 = require("@dxos/log");
|
|
1195
|
+
var import_credentials2 = require("@dxos/protocols/proto/dxos/halo/credentials");
|
|
1196
|
+
var import_timeframe3 = require("@dxos/timeframe");
|
|
1288
1197
|
var import_util5 = require("@dxos/util");
|
|
1289
|
-
var __dxlog_file8 = "/
|
|
1290
|
-
var
|
|
1291
|
-
|
|
1292
|
-
|
|
1198
|
+
var __dxlog_file8 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/space/control-pipeline.ts";
|
|
1199
|
+
var TIMEFRAME_SAVE_DEBOUNCE_INTERVAL = 500;
|
|
1200
|
+
var ControlPipeline = class {
|
|
1201
|
+
constructor({ spaceKey, genesisFeed, feedProvider, metadataStore }) {
|
|
1202
|
+
this._lastTimeframeSaveTime = Date.now();
|
|
1203
|
+
this.onFeedAdmitted = new import_util5.Callback();
|
|
1204
|
+
this._spaceKey = spaceKey;
|
|
1205
|
+
this._metadata = metadataStore;
|
|
1206
|
+
this._pipeline = new Pipeline();
|
|
1207
|
+
void this._pipeline.addFeed(genesisFeed);
|
|
1208
|
+
this._spaceStateMachine = new import_credentials.SpaceStateMachine(spaceKey);
|
|
1209
|
+
this._spaceStateMachine.onFeedAdmitted.set(async (info) => {
|
|
1210
|
+
(0, import_log8.log)("feed admitted", {
|
|
1211
|
+
key: info.key
|
|
1212
|
+
}, {
|
|
1213
|
+
F: __dxlog_file8,
|
|
1214
|
+
L: 51,
|
|
1215
|
+
S: this,
|
|
1216
|
+
C: (f, a) => f(...a)
|
|
1217
|
+
});
|
|
1218
|
+
if (info.assertion.designation === import_credentials2.AdmittedFeed.Designation.CONTROL && !info.key.equals(genesisFeed.key)) {
|
|
1219
|
+
try {
|
|
1220
|
+
const feed = await feedProvider(info.key);
|
|
1221
|
+
await this._pipeline.addFeed(feed);
|
|
1222
|
+
} catch (err) {
|
|
1223
|
+
import_log8.log.catch(err, void 0, {
|
|
1224
|
+
F: __dxlog_file8,
|
|
1225
|
+
L: 59,
|
|
1226
|
+
S: this,
|
|
1227
|
+
C: (f, a) => f(...a)
|
|
1228
|
+
});
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
await this.onFeedAdmitted.callIfSet(info);
|
|
1232
|
+
});
|
|
1233
|
+
this.onMemberAdmitted = this._spaceStateMachine.onMemberAdmitted;
|
|
1234
|
+
this.onCredentialProcessed = this._spaceStateMachine.onCredentialProcessed;
|
|
1293
1235
|
}
|
|
1294
|
-
|
|
1295
|
-
this.
|
|
1236
|
+
get spaceState() {
|
|
1237
|
+
return this._spaceStateMachine;
|
|
1296
1238
|
}
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1239
|
+
get pipeline() {
|
|
1240
|
+
return this._pipeline;
|
|
1241
|
+
}
|
|
1242
|
+
setWriteFeed(feed) {
|
|
1243
|
+
this._pipeline.setWriteFeed(feed);
|
|
1244
|
+
}
|
|
1245
|
+
async start() {
|
|
1246
|
+
(0, import_log8.log)("starting...", void 0, {
|
|
1301
1247
|
F: __dxlog_file8,
|
|
1302
|
-
L:
|
|
1248
|
+
L: 83,
|
|
1303
1249
|
S: this,
|
|
1304
1250
|
C: (f, a) => f(...a)
|
|
1305
1251
|
});
|
|
1306
|
-
(
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1252
|
+
setTimeout(async () => {
|
|
1253
|
+
for await (const msg of this._pipeline.consume()) {
|
|
1254
|
+
try {
|
|
1255
|
+
(0, import_log8.log)("processing", {
|
|
1256
|
+
key: msg.feedKey,
|
|
1257
|
+
seq: msg.seq
|
|
1258
|
+
}, {
|
|
1259
|
+
F: __dxlog_file8,
|
|
1260
|
+
L: 88,
|
|
1261
|
+
S: this,
|
|
1262
|
+
C: (f, a) => f(...a)
|
|
1263
|
+
});
|
|
1264
|
+
if (msg.data.payload.credential) {
|
|
1265
|
+
const timer = import_util5.tracer.mark("dxos.echo.pipeline.control");
|
|
1266
|
+
const result = await this._spaceStateMachine.process(msg.data.payload.credential.credential, import_keys4.PublicKey.from(msg.feedKey));
|
|
1267
|
+
timer.end();
|
|
1268
|
+
if (!result) {
|
|
1269
|
+
import_log8.log.warn("processing failed", {
|
|
1270
|
+
msg
|
|
1271
|
+
}, {
|
|
1272
|
+
F: __dxlog_file8,
|
|
1273
|
+
L: 98,
|
|
1274
|
+
S: this,
|
|
1275
|
+
C: (f, a) => f(...a)
|
|
1276
|
+
});
|
|
1277
|
+
} else {
|
|
1278
|
+
await this._noteTargetStateIfNeeded(this._pipeline.state.pendingTimeframe);
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
} catch (err) {
|
|
1282
|
+
import_log8.log.catch(err, void 0, {
|
|
1283
|
+
F: __dxlog_file8,
|
|
1284
|
+
L: 104,
|
|
1285
|
+
S: this,
|
|
1286
|
+
C: (f, a) => f(...a)
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
});
|
|
1291
|
+
await this._pipeline.start();
|
|
1292
|
+
(0, import_log8.log)("started", void 0, {
|
|
1314
1293
|
F: __dxlog_file8,
|
|
1315
|
-
L:
|
|
1294
|
+
L: 110,
|
|
1316
1295
|
S: this,
|
|
1317
1296
|
C: (f, a) => f(...a)
|
|
1318
1297
|
});
|
|
1319
|
-
const host = this._spaces.get(spaceKey);
|
|
1320
|
-
await (host == null ? void 0 : host.close());
|
|
1321
|
-
this._spaces.delete(spaceKey);
|
|
1322
|
-
}
|
|
1323
|
-
getDataService(spaceKey) {
|
|
1324
|
-
return this._spaces.get(spaceKey);
|
|
1325
1298
|
}
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1299
|
+
async _noteTargetStateIfNeeded(timeframe) {
|
|
1300
|
+
if (Date.now() - this._lastTimeframeSaveTime > TIMEFRAME_SAVE_DEBOUNCE_INTERVAL) {
|
|
1301
|
+
this._lastTimeframeSaveTime = Date.now();
|
|
1302
|
+
await this._saveTargetTimeframe(timeframe);
|
|
1303
|
+
}
|
|
1330
1304
|
}
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1305
|
+
async stop() {
|
|
1306
|
+
(0, import_log8.log)("stopping...", void 0, {
|
|
1307
|
+
F: __dxlog_file8,
|
|
1308
|
+
L: 124,
|
|
1309
|
+
S: this,
|
|
1310
|
+
C: (f, a) => f(...a)
|
|
1311
|
+
});
|
|
1312
|
+
await this._pipeline.stop();
|
|
1313
|
+
await this._saveTargetTimeframe(this._pipeline.state.timeframe);
|
|
1314
|
+
(0, import_log8.log)("stopped", void 0, {
|
|
1315
|
+
F: __dxlog_file8,
|
|
1316
|
+
L: 127,
|
|
1317
|
+
S: this,
|
|
1318
|
+
C: (f, a) => f(...a)
|
|
1319
|
+
});
|
|
1336
1320
|
}
|
|
1337
|
-
|
|
1321
|
+
async _saveTargetTimeframe(timeframe) {
|
|
1338
1322
|
var _a;
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1323
|
+
try {
|
|
1324
|
+
const newTimeframe = import_timeframe3.Timeframe.merge((_a = this._targetTimeframe) != null ? _a : new import_timeframe3.Timeframe(), timeframe);
|
|
1325
|
+
await this._metadata.setSpaceControlLatestTimeframe(this._spaceKey, newTimeframe);
|
|
1326
|
+
this._targetTimeframe = newTimeframe;
|
|
1327
|
+
} catch (err) {
|
|
1328
|
+
(0, import_log8.log)(err, void 0, {
|
|
1329
|
+
F: __dxlog_file8,
|
|
1330
|
+
L: 136,
|
|
1331
|
+
S: this,
|
|
1332
|
+
C: (f, a) => f(...a)
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1343
1335
|
}
|
|
1344
1336
|
};
|
|
1345
1337
|
|
|
1346
1338
|
// packages/core/echo/echo-pipeline/src/space/data-pipeline.ts
|
|
1339
|
+
var import_tiny_invariant8 = __toESM(require("tiny-invariant"));
|
|
1340
|
+
var import_async6 = require("@dxos/async");
|
|
1341
|
+
var import_context5 = require("@dxos/context");
|
|
1342
|
+
var import_credentials3 = require("@dxos/credentials");
|
|
1343
|
+
var import_echo_db3 = require("@dxos/echo-db");
|
|
1344
|
+
var import_errors2 = require("@dxos/errors");
|
|
1345
|
+
var import_log9 = require("@dxos/log");
|
|
1346
|
+
var import_timeframe4 = require("@dxos/timeframe");
|
|
1347
|
+
var import_util6 = require("@dxos/util");
|
|
1347
1348
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
1348
1349
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1349
1350
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -1354,7 +1355,7 @@ function _ts_decorate5(decorators, target, key, desc) {
|
|
|
1354
1355
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1355
1356
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1356
1357
|
}
|
|
1357
|
-
var __dxlog_file9 = "/
|
|
1358
|
+
var __dxlog_file9 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/space/data-pipeline.ts";
|
|
1358
1359
|
var MESSAGES_PER_SNAPSHOT = 10;
|
|
1359
1360
|
var AUTOMATIC_SNAPSHOT_DEBOUNCE_INTERVAL = 5e3;
|
|
1360
1361
|
var TIMEFRAME_SAVE_DEBOUNCE_INTERVAL2 = 500;
|
|
@@ -1368,9 +1369,9 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1368
1369
|
this._isOpen = false;
|
|
1369
1370
|
this._lastTimeframeSaveTime = 0;
|
|
1370
1371
|
this._lastSnapshotSaveTime = 0;
|
|
1372
|
+
this._lastProcessedEpoch = -1;
|
|
1371
1373
|
this.currentEpoch = void 0;
|
|
1372
1374
|
this.appliedEpoch = void 0;
|
|
1373
|
-
this._lastProcessedEpoch = -1;
|
|
1374
1375
|
this.onNewEpoch = new import_async6.Event();
|
|
1375
1376
|
}
|
|
1376
1377
|
get isOpen() {
|
|
@@ -1485,7 +1486,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1485
1486
|
if (data.payload.data) {
|
|
1486
1487
|
const feedInfo = this._params.feedInfoProvider(feedKey);
|
|
1487
1488
|
if (!feedInfo) {
|
|
1488
|
-
import_log9.log.
|
|
1489
|
+
import_log9.log.warn("Could not find feed", {
|
|
1489
1490
|
feedKey
|
|
1490
1491
|
}, {
|
|
1491
1492
|
F: __dxlog_file9,
|
|
@@ -1495,7 +1496,8 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1495
1496
|
});
|
|
1496
1497
|
continue;
|
|
1497
1498
|
}
|
|
1498
|
-
|
|
1499
|
+
const timer = import_util6.tracer.mark("dxos.echo.pipeline.data");
|
|
1500
|
+
this.databaseHost.echoProcessor({
|
|
1499
1501
|
batch: data.payload.data.batch,
|
|
1500
1502
|
meta: {
|
|
1501
1503
|
feedKey,
|
|
@@ -1504,13 +1506,14 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1504
1506
|
memberKey: feedInfo.assertion.identityKey
|
|
1505
1507
|
}
|
|
1506
1508
|
});
|
|
1509
|
+
timer.end();
|
|
1507
1510
|
import_log9.log.trace("dxos.echo.data-pipeline.processed", {
|
|
1508
1511
|
feedKey: feedKey.toHex(),
|
|
1509
1512
|
seq,
|
|
1510
1513
|
spaceKey: this._params.spaceKey.toHex()
|
|
1511
1514
|
}, {
|
|
1512
1515
|
F: __dxlog_file9,
|
|
1513
|
-
L:
|
|
1516
|
+
L: 233,
|
|
1514
1517
|
S: this,
|
|
1515
1518
|
C: (f, a) => f(...a)
|
|
1516
1519
|
});
|
|
@@ -1519,7 +1522,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1519
1522
|
} catch (err) {
|
|
1520
1523
|
import_log9.log.catch(err, void 0, {
|
|
1521
1524
|
F: __dxlog_file9,
|
|
1522
|
-
L:
|
|
1525
|
+
L: 243,
|
|
1523
1526
|
S: this,
|
|
1524
1527
|
C: (f, a) => f(...a)
|
|
1525
1528
|
});
|
|
@@ -1554,7 +1557,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1554
1557
|
} catch (err) {
|
|
1555
1558
|
import_log9.log.warn("Failed to cache properties", err, {
|
|
1556
1559
|
F: __dxlog_file9,
|
|
1557
|
-
L:
|
|
1560
|
+
L: 278,
|
|
1558
1561
|
S: this,
|
|
1559
1562
|
C: (f, a) => f(...a)
|
|
1560
1563
|
});
|
|
@@ -1581,14 +1584,14 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1581
1584
|
if (err instanceof import_errors2.CancelledError) {
|
|
1582
1585
|
(0, import_log9.log)("Epoch processing cancelled.", void 0, {
|
|
1583
1586
|
F: __dxlog_file9,
|
|
1584
|
-
L:
|
|
1587
|
+
L: 310,
|
|
1585
1588
|
S: this,
|
|
1586
1589
|
C: (f, a) => f(...a)
|
|
1587
1590
|
});
|
|
1588
1591
|
} else {
|
|
1589
1592
|
import_log9.log.catch(err, void 0, {
|
|
1590
1593
|
F: __dxlog_file9,
|
|
1591
|
-
L:
|
|
1594
|
+
L: 312,
|
|
1592
1595
|
S: this,
|
|
1593
1596
|
C: (f, a) => f(...a)
|
|
1594
1597
|
});
|
|
@@ -1604,7 +1607,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1604
1607
|
epoch
|
|
1605
1608
|
}, {
|
|
1606
1609
|
F: __dxlog_file9,
|
|
1607
|
-
L:
|
|
1610
|
+
L: 322,
|
|
1608
1611
|
S: this,
|
|
1609
1612
|
C: (f, a) => f(...a)
|
|
1610
1613
|
});
|
|
@@ -1621,7 +1624,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1621
1624
|
epoch
|
|
1622
1625
|
}, {
|
|
1623
1626
|
F: __dxlog_file9,
|
|
1624
|
-
L:
|
|
1627
|
+
L: 336,
|
|
1625
1628
|
S: this,
|
|
1626
1629
|
C: (f, a) => f(...a)
|
|
1627
1630
|
});
|
|
@@ -1631,7 +1634,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1631
1634
|
}
|
|
1632
1635
|
(0, import_log9.log)("restarting pipeline for epoch", void 0, {
|
|
1633
1636
|
F: __dxlog_file9,
|
|
1634
|
-
L:
|
|
1637
|
+
L: 344,
|
|
1635
1638
|
S: this,
|
|
1636
1639
|
C: (f, a) => f(...a)
|
|
1637
1640
|
});
|
|
@@ -1689,11 +1692,11 @@ function _ts_decorate6(decorators, target, key, desc) {
|
|
|
1689
1692
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1690
1693
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1691
1694
|
}
|
|
1692
|
-
var __dxlog_file10 = "/
|
|
1695
|
+
var __dxlog_file10 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/space/space.ts";
|
|
1693
1696
|
var Space = class Space2 {
|
|
1694
1697
|
constructor(params) {
|
|
1695
1698
|
this._addFeedLock = new import_async7.Lock();
|
|
1696
|
-
this.onCredentialProcessed = new
|
|
1699
|
+
this.onCredentialProcessed = new import_util7.Callback();
|
|
1697
1700
|
this.stateUpdate = new import_async7.Event();
|
|
1698
1701
|
this._isOpen = false;
|
|
1699
1702
|
(0, import_tiny_invariant9.default)(params.spaceKey && params.feedProvider);
|
|
@@ -1899,7 +1902,7 @@ var import_debug5 = require("@dxos/debug");
|
|
|
1899
1902
|
var import_keys6 = require("@dxos/keys");
|
|
1900
1903
|
var import_log12 = require("@dxos/log");
|
|
1901
1904
|
var import_protocols6 = require("@dxos/protocols");
|
|
1902
|
-
var
|
|
1905
|
+
var import_util9 = require("@dxos/util");
|
|
1903
1906
|
|
|
1904
1907
|
// packages/core/echo/echo-pipeline/src/space/space-protocol.ts
|
|
1905
1908
|
var import_crypto3 = require("@dxos/crypto");
|
|
@@ -1909,7 +1912,7 @@ var import_network_manager = require("@dxos/network-manager");
|
|
|
1909
1912
|
var import_teleport2 = require("@dxos/teleport");
|
|
1910
1913
|
var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
|
|
1911
1914
|
var import_teleport_extension_replicator = require("@dxos/teleport-extension-replicator");
|
|
1912
|
-
var
|
|
1915
|
+
var import_util8 = require("@dxos/util");
|
|
1913
1916
|
function _ts_decorate7(decorators, target, key, desc) {
|
|
1914
1917
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1915
1918
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -1920,13 +1923,13 @@ function _ts_decorate7(decorators, target, key, desc) {
|
|
|
1920
1923
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1921
1924
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1922
1925
|
}
|
|
1923
|
-
var __dxlog_file11 = "/
|
|
1926
|
+
var __dxlog_file11 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/space/space-protocol.ts";
|
|
1924
1927
|
var MOCK_AUTH_PROVIDER = async (nonce) => Buffer.from("mock");
|
|
1925
1928
|
var MOCK_AUTH_VERIFIER = async (nonce, credential) => true;
|
|
1926
1929
|
var SpaceProtocol = class {
|
|
1927
1930
|
constructor({ topic, swarmIdentity, networkManager, onSessionAuth, onAuthFailure, blobStore }) {
|
|
1928
1931
|
this._feeds = /* @__PURE__ */ new Set();
|
|
1929
|
-
this._sessions = new
|
|
1932
|
+
this._sessions = new import_util8.ComplexMap(import_keys5.PublicKey.hash);
|
|
1930
1933
|
this._networkManager = networkManager;
|
|
1931
1934
|
this._swarmIdentity = swarmIdentity;
|
|
1932
1935
|
this._onSessionAuth = onSessionAuth;
|
|
@@ -1951,7 +1954,7 @@ var SpaceProtocol = class {
|
|
|
1951
1954
|
key: feed.key
|
|
1952
1955
|
}, {
|
|
1953
1956
|
F: __dxlog_file11,
|
|
1954
|
-
L:
|
|
1957
|
+
L: 95,
|
|
1955
1958
|
S: this,
|
|
1956
1959
|
C: (f, a) => f(...a)
|
|
1957
1960
|
});
|
|
@@ -1973,7 +1976,7 @@ var SpaceProtocol = class {
|
|
|
1973
1976
|
await this.blobSync.open();
|
|
1974
1977
|
(0, import_log11.log)("starting...", void 0, {
|
|
1975
1978
|
F: __dxlog_file11,
|
|
1976
|
-
L:
|
|
1979
|
+
L: 120,
|
|
1977
1980
|
S: this,
|
|
1978
1981
|
C: (f, a) => f(...a)
|
|
1979
1982
|
});
|
|
@@ -1986,7 +1989,7 @@ var SpaceProtocol = class {
|
|
|
1986
1989
|
});
|
|
1987
1990
|
(0, import_log11.log)("started", void 0, {
|
|
1988
1991
|
F: __dxlog_file11,
|
|
1989
|
-
L:
|
|
1992
|
+
L: 129,
|
|
1990
1993
|
S: this,
|
|
1991
1994
|
C: (f, a) => f(...a)
|
|
1992
1995
|
});
|
|
@@ -1996,14 +1999,14 @@ var SpaceProtocol = class {
|
|
|
1996
1999
|
if (this._connection) {
|
|
1997
2000
|
(0, import_log11.log)("stopping...", void 0, {
|
|
1998
2001
|
F: __dxlog_file11,
|
|
1999
|
-
L:
|
|
2002
|
+
L: 136,
|
|
2000
2003
|
S: this,
|
|
2001
2004
|
C: (f, a) => f(...a)
|
|
2002
2005
|
});
|
|
2003
2006
|
await this._connection.close();
|
|
2004
2007
|
(0, import_log11.log)("stopped", void 0, {
|
|
2005
2008
|
F: __dxlog_file11,
|
|
2006
|
-
L:
|
|
2009
|
+
L: 138,
|
|
2007
2010
|
S: this,
|
|
2008
2011
|
C: (f, a) => f(...a)
|
|
2009
2012
|
});
|
|
@@ -2071,7 +2074,7 @@ var SpaceProtocolSession = class {
|
|
|
2071
2074
|
var _a;
|
|
2072
2075
|
(0, import_log11.log)("Peer authenticated", void 0, {
|
|
2073
2076
|
F: __dxlog_file11,
|
|
2074
|
-
L:
|
|
2077
|
+
L: 235,
|
|
2075
2078
|
S: this,
|
|
2076
2079
|
C: (f, a) => f(...a)
|
|
2077
2080
|
});
|
|
@@ -2109,10 +2112,10 @@ function _ts_decorate8(decorators, target, key, desc) {
|
|
|
2109
2112
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2110
2113
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2111
2114
|
}
|
|
2112
|
-
var __dxlog_file12 = "/
|
|
2115
|
+
var __dxlog_file12 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/space/space-manager.ts";
|
|
2113
2116
|
var SpaceManager = class SpaceManager2 {
|
|
2114
2117
|
constructor({ feedStore, networkManager, modelFactory, metadataStore, snapshotStore, blobStore }) {
|
|
2115
|
-
this._spaces = new
|
|
2118
|
+
this._spaces = new import_util9.ComplexMap(import_keys6.PublicKey.hash);
|
|
2116
2119
|
this._instanceId = import_keys6.PublicKey.random().toHex();
|
|
2117
2120
|
this._feedStore = feedStore;
|
|
2118
2121
|
this._networkManager = networkManager;
|