@dxos/echo-pipeline 0.8.3 → 0.8.4-main.84f28bd
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-TQJTKNMS.mjs → chunk-ANZAS5CC.mjs} +2 -2
- package/dist/lib/browser/{chunk-35I6ERLG.mjs → chunk-GBFX5J5B.mjs} +27 -27
- package/dist/lib/browser/filter/index.mjs +1 -1
- package/dist/lib/browser/index.mjs +61 -61
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +13 -13
- package/dist/lib/node-esm/{chunk-RVK35BS7.mjs → chunk-2SAZ7CCF.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-5BHLPT24.mjs → chunk-FQFKWA3X.mjs} +27 -27
- package/dist/lib/node-esm/filter/index.mjs +1 -1
- package/dist/lib/node-esm/index.mjs +61 -61
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +13 -13
- package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +38 -38
- package/src/automerge/echo-network-adapter.ts +2 -1
- package/dist/lib/node/chunk-HOPOFWAL.cjs +0 -147
- package/dist/lib/node/chunk-HOPOFWAL.cjs.map +0 -7
- package/dist/lib/node/chunk-JXX6LF5U.cjs +0 -2084
- package/dist/lib/node/chunk-JXX6LF5U.cjs.map +0 -7
- package/dist/lib/node/chunk-Q7SFCCGT.cjs +0 -33
- package/dist/lib/node/chunk-Q7SFCCGT.cjs.map +0 -7
- package/dist/lib/node/filter/index.cjs +0 -32
- package/dist/lib/node/filter/index.cjs.map +0 -7
- package/dist/lib/node/index.cjs +0 -4699
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node/testing/index.cjs +0 -753
- package/dist/lib/node/testing/index.cjs.map +0 -7
- /package/dist/lib/browser/{chunk-TQJTKNMS.mjs.map → chunk-ANZAS5CC.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-35I6ERLG.mjs.map → chunk-GBFX5J5B.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-RVK35BS7.mjs.map → chunk-2SAZ7CCF.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-5BHLPT24.mjs.map → chunk-FQFKWA3X.mjs.map} +0 -0
|
@@ -1,753 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var testing_exports = {};
|
|
20
|
-
__export(testing_exports, {
|
|
21
|
-
MemoryNetworkManagerProvider: () => MemoryNetworkManagerProvider,
|
|
22
|
-
TestAdapter: () => TestAdapter,
|
|
23
|
-
TestAgent: () => TestAgent,
|
|
24
|
-
TestAgentBuilder: () => TestAgentBuilder,
|
|
25
|
-
TestData: () => test_data_exports,
|
|
26
|
-
TestFeedBuilder: () => TestFeedBuilder,
|
|
27
|
-
TestReplicationNetwork: () => TestReplicationNetwork,
|
|
28
|
-
TestReplicator: () => TestReplicator,
|
|
29
|
-
TestReplicatorConnection: () => TestReplicatorConnection,
|
|
30
|
-
TestSchema: () => test_schema_exports,
|
|
31
|
-
WebsocketNetworkManagerProvider: () => WebsocketNetworkManagerProvider,
|
|
32
|
-
brokenAutomergeReplicatorFactory: () => brokenAutomergeReplicatorFactory,
|
|
33
|
-
changeStorageVersionInMetadata: () => changeStorageVersionInMetadata,
|
|
34
|
-
testAutomergeReplicatorFactory: () => testAutomergeReplicatorFactory
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(testing_exports);
|
|
37
|
-
var import_chunk_JXX6LF5U = require("../chunk-JXX6LF5U.cjs");
|
|
38
|
-
var import_chunk_Q7SFCCGT = require("../chunk-Q7SFCCGT.cjs");
|
|
39
|
-
var import_log = require("@dxos/log");
|
|
40
|
-
var import_proto = require("@dxos/protocols/proto");
|
|
41
|
-
var import_context = require("@dxos/context");
|
|
42
|
-
var import_credentials = require("@dxos/credentials");
|
|
43
|
-
var import_keys = require("@dxos/keys");
|
|
44
|
-
var import_messaging = require("@dxos/messaging");
|
|
45
|
-
var import_network_manager = require("@dxos/network-manager");
|
|
46
|
-
var import_credentials2 = require("@dxos/protocols/proto/dxos/halo/credentials");
|
|
47
|
-
var import_random_access_storage = require("@dxos/random-access-storage");
|
|
48
|
-
var import_teleport_extension_gossip = require("@dxos/teleport-extension-gossip");
|
|
49
|
-
var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
|
|
50
|
-
var import_util = require("@dxos/util");
|
|
51
|
-
var import_testing = require("@dxos/feed-store/testing");
|
|
52
|
-
var import_automerge_repo = require("@automerge/automerge-repo");
|
|
53
|
-
var import_async = require("@dxos/async");
|
|
54
|
-
var import_invariant = require("@dxos/invariant");
|
|
55
|
-
var import_log2 = require("@dxos/log");
|
|
56
|
-
var import_async2 = require("@dxos/async");
|
|
57
|
-
var import_context2 = require("@dxos/context");
|
|
58
|
-
var import_invariant2 = require("@dxos/invariant");
|
|
59
|
-
var import_log3 = require("@dxos/log");
|
|
60
|
-
var import_teleport_extension_automerge_replicator = require("@dxos/teleport-extension-automerge-replicator");
|
|
61
|
-
var import_effect = require("effect");
|
|
62
|
-
var import_echo = require("@dxos/echo");
|
|
63
|
-
var import_echo_protocol = require("@dxos/echo-protocol");
|
|
64
|
-
var import_echo_schema = require("@dxos/echo-schema");
|
|
65
|
-
var import_keys2 = require("@dxos/keys");
|
|
66
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/testing/change-metadata.ts";
|
|
67
|
-
var EchoMetadata = import_proto.schema.getCodecForType("dxos.echo.metadata.EchoMetadata");
|
|
68
|
-
var changeStorageVersionInMetadata = async (storage, version) => {
|
|
69
|
-
(0, import_log.log)("Changing storage version in metadata. USE ONLY FOR TESTING.", void 0, {
|
|
70
|
-
F: __dxlog_file,
|
|
71
|
-
L: 19,
|
|
72
|
-
S: void 0,
|
|
73
|
-
C: (f, a) => f(...a)
|
|
74
|
-
});
|
|
75
|
-
const metadata = new import_chunk_JXX6LF5U.MetadataStore(storage.createDirectory("metadata"));
|
|
76
|
-
await metadata.load();
|
|
77
|
-
const echoMetadata = metadata.metadata;
|
|
78
|
-
echoMetadata.version = version;
|
|
79
|
-
const file = metadata._directory.getOrCreateFile("EchoMetadata");
|
|
80
|
-
await metadata._writeFile(file, EchoMetadata, echoMetadata);
|
|
81
|
-
await metadata._directory.flush();
|
|
82
|
-
};
|
|
83
|
-
var TestFeedBuilder = class extends import_testing.TestBuilder {
|
|
84
|
-
constructor() {
|
|
85
|
-
super({
|
|
86
|
-
valueEncoding: import_chunk_JXX6LF5U.valueEncoding
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/testing/test-agent-builder.ts";
|
|
91
|
-
var MemoryNetworkManagerProvider = (signalContext) => () => new import_network_manager.SwarmNetworkManager({
|
|
92
|
-
signalManager: new import_messaging.MemorySignalManager(signalContext),
|
|
93
|
-
transportFactory: import_network_manager.MemoryTransportFactory
|
|
94
|
-
});
|
|
95
|
-
var WebsocketNetworkManagerProvider = (signalUrl) => () => new import_network_manager.SwarmNetworkManager({
|
|
96
|
-
signalManager: new import_messaging.WebsocketSignalManager([
|
|
97
|
-
{
|
|
98
|
-
server: signalUrl
|
|
99
|
-
}
|
|
100
|
-
]),
|
|
101
|
-
transportFactory: (0, import_network_manager.createRtcTransportFactory)()
|
|
102
|
-
});
|
|
103
|
-
var TestAgentBuilder = class {
|
|
104
|
-
constructor({ storage, networkManagerProvider } = {}) {
|
|
105
|
-
this._agents = new import_util.ComplexMap(import_keys.PublicKey.hash);
|
|
106
|
-
this._storage = storage ?? (0, import_random_access_storage.createStorage)({
|
|
107
|
-
type: import_random_access_storage.StorageType.RAM
|
|
108
|
-
});
|
|
109
|
-
this._networkManagerProvider = networkManagerProvider ?? MemoryNetworkManagerProvider(new import_messaging.MemorySignalManagerContext());
|
|
110
|
-
}
|
|
111
|
-
async close() {
|
|
112
|
-
return Promise.all(this.agents.map((agent) => agent.close()));
|
|
113
|
-
}
|
|
114
|
-
get agents() {
|
|
115
|
-
return Array.from(this._agents.values());
|
|
116
|
-
}
|
|
117
|
-
getAgent(deviceKey) {
|
|
118
|
-
return this._agents.get(deviceKey);
|
|
119
|
-
}
|
|
120
|
-
async createPeer() {
|
|
121
|
-
const feedBuilder = new TestFeedBuilder().setStorage(this._storage, `agent-${this._agents.size}`);
|
|
122
|
-
const identityKey = await feedBuilder.keyring.createKey();
|
|
123
|
-
const deviceKey = await feedBuilder.keyring.createKey();
|
|
124
|
-
const agent = new TestAgent(this._networkManagerProvider, feedBuilder, identityKey, deviceKey);
|
|
125
|
-
this._agents.set(deviceKey, agent);
|
|
126
|
-
return agent;
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
var TestAgent = class {
|
|
130
|
-
get metadataStore() {
|
|
131
|
-
return this._metadataStore ??= new import_chunk_JXX6LF5U.MetadataStore(this.storage.createDirectory("metadata"));
|
|
132
|
-
}
|
|
133
|
-
get blobStore() {
|
|
134
|
-
return this._blobStore ??= new import_teleport_extension_object_sync.BlobStore(this.storage.createDirectory("blobs"));
|
|
135
|
-
}
|
|
136
|
-
constructor(_networkManagerProvider, _feedBuilder, identityKey, deviceKey) {
|
|
137
|
-
this._networkManagerProvider = _networkManagerProvider;
|
|
138
|
-
this._feedBuilder = _feedBuilder;
|
|
139
|
-
this.identityKey = identityKey;
|
|
140
|
-
this.deviceKey = deviceKey;
|
|
141
|
-
this._spaces = new import_util.ComplexMap(import_keys.PublicKey.hash);
|
|
142
|
-
this.storage = this._feedBuilder.storage;
|
|
143
|
-
this.keyring = this._feedBuilder.keyring;
|
|
144
|
-
this.feedStore = this._feedBuilder.createFeedStore();
|
|
145
|
-
}
|
|
146
|
-
async close() {
|
|
147
|
-
return Promise.all([
|
|
148
|
-
...this.spaces.map((space) => space.close())
|
|
149
|
-
]);
|
|
150
|
-
}
|
|
151
|
-
get spaces() {
|
|
152
|
-
return Array.from(this._spaces.values());
|
|
153
|
-
}
|
|
154
|
-
getSpace(spaceKey2) {
|
|
155
|
-
return this._spaces.get(spaceKey2);
|
|
156
|
-
}
|
|
157
|
-
get networkManager() {
|
|
158
|
-
if (this._networkManager) {
|
|
159
|
-
return this._networkManager;
|
|
160
|
-
}
|
|
161
|
-
this._networkManager = this._networkManagerProvider();
|
|
162
|
-
this._networkManager.setPeerInfo({
|
|
163
|
-
peerKey: this.deviceKey.toHex(),
|
|
164
|
-
identityKey: this.identityKey.toHex()
|
|
165
|
-
});
|
|
166
|
-
return this._networkManager;
|
|
167
|
-
}
|
|
168
|
-
get spaceManager() {
|
|
169
|
-
return this._spaceManager ??= new import_chunk_JXX6LF5U.SpaceManager({
|
|
170
|
-
feedStore: this.feedStore,
|
|
171
|
-
networkManager: this.networkManager,
|
|
172
|
-
metadataStore: this.metadataStore,
|
|
173
|
-
blobStore: this.blobStore
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
async createSpace(identityKey = this.identityKey, spaceKey2, genesisKey, dataKey, saveMetadata = false) {
|
|
177
|
-
if (!spaceKey2) {
|
|
178
|
-
saveMetadata = true;
|
|
179
|
-
spaceKey2 = await this.keyring.createKey();
|
|
180
|
-
}
|
|
181
|
-
if (!genesisKey) {
|
|
182
|
-
genesisKey = await this.keyring.createKey();
|
|
183
|
-
}
|
|
184
|
-
const controlFeed = await this.feedStore.openFeed(genesisKey, {
|
|
185
|
-
writable: true
|
|
186
|
-
});
|
|
187
|
-
const dataFeed = await this.feedStore.openFeed(dataKey ?? await this.keyring.createKey(), {
|
|
188
|
-
writable: true,
|
|
189
|
-
sparse: true
|
|
190
|
-
});
|
|
191
|
-
const metadata = {
|
|
192
|
-
key: spaceKey2,
|
|
193
|
-
genesisFeedKey: genesisKey,
|
|
194
|
-
controlFeedKey: controlFeed.key,
|
|
195
|
-
dataFeedKey: dataFeed.key
|
|
196
|
-
};
|
|
197
|
-
if (saveMetadata) {
|
|
198
|
-
await this.metadataStore.addSpace(metadata);
|
|
199
|
-
}
|
|
200
|
-
await this.spaceManager.open();
|
|
201
|
-
const space = await this.spaceManager.constructSpace({
|
|
202
|
-
metadata,
|
|
203
|
-
swarmIdentity: {
|
|
204
|
-
identityKey: this.identityKey,
|
|
205
|
-
peerKey: this.deviceKey,
|
|
206
|
-
credentialProvider: import_chunk_JXX6LF5U.MOCK_AUTH_PROVIDER,
|
|
207
|
-
credentialAuthenticator: import_chunk_JXX6LF5U.MOCK_AUTH_VERIFIER
|
|
208
|
-
},
|
|
209
|
-
memberKey: identityKey,
|
|
210
|
-
onAuthorizedConnection: (session) => {
|
|
211
|
-
session.addExtension("dxos.mesh.teleport.gossip", this.createGossip().createExtension({
|
|
212
|
-
remotePeerId: session.remotePeerId
|
|
213
|
-
}));
|
|
214
|
-
},
|
|
215
|
-
onDelegatedInvitationStatusChange: async () => {
|
|
216
|
-
},
|
|
217
|
-
onMemberRolesChanged: async () => {
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
await space.setControlFeed(controlFeed);
|
|
221
|
-
await space.setDataFeed(dataFeed);
|
|
222
|
-
await space.open(new import_context.Context(void 0, {
|
|
223
|
-
F: __dxlog_file2,
|
|
224
|
-
L: 205
|
|
225
|
-
}));
|
|
226
|
-
this._spaces.set(spaceKey2, space);
|
|
227
|
-
return space;
|
|
228
|
-
}
|
|
229
|
-
createSpaceProtocol(topic, gossip) {
|
|
230
|
-
return new import_chunk_JXX6LF5U.SpaceProtocol({
|
|
231
|
-
topic,
|
|
232
|
-
swarmIdentity: {
|
|
233
|
-
identityKey: this.identityKey,
|
|
234
|
-
peerKey: this.deviceKey,
|
|
235
|
-
credentialProvider: import_chunk_JXX6LF5U.MOCK_AUTH_PROVIDER,
|
|
236
|
-
credentialAuthenticator: import_chunk_JXX6LF5U.MOCK_AUTH_VERIFIER
|
|
237
|
-
},
|
|
238
|
-
networkManager: this.networkManager,
|
|
239
|
-
blobStore: this.blobStore,
|
|
240
|
-
onSessionAuth: (session) => {
|
|
241
|
-
session.addExtension("dxos.mesh.teleport.gossip", (gossip ?? this.createGossip()).createExtension({
|
|
242
|
-
remotePeerId: session.remotePeerId
|
|
243
|
-
}));
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
createGossip() {
|
|
248
|
-
return new import_teleport_extension_gossip.Gossip({
|
|
249
|
-
localPeerId: this.deviceKey
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
createPresence(gossip) {
|
|
253
|
-
return new import_teleport_extension_gossip.Presence({
|
|
254
|
-
announceInterval: 30,
|
|
255
|
-
offlineTimeout: 200,
|
|
256
|
-
identityKey: this.identityKey,
|
|
257
|
-
gossip: gossip ?? this.createGossip()
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
async spaceGenesis(space) {
|
|
261
|
-
const generator = new import_credentials.CredentialGenerator(this.keyring, this.identityKey, this.deviceKey);
|
|
262
|
-
const credentials = [
|
|
263
|
-
...await generator.createSpaceGenesis(space.key, space.controlFeedKey),
|
|
264
|
-
await generator.createFeedAdmission(space.key, space.dataFeedKey, import_credentials2.AdmittedFeed.Designation.DATA),
|
|
265
|
-
await generator.createEpochCredential(space.key)
|
|
266
|
-
];
|
|
267
|
-
for (const credential of credentials) {
|
|
268
|
-
await space.controlPipeline.writer.write({
|
|
269
|
-
credential: {
|
|
270
|
-
credential
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/testing/test-network-adapter.ts";
|
|
277
|
-
var TestAdapter = class _TestAdapter extends import_automerge_repo.NetworkAdapter {
|
|
278
|
-
static createPair(connectionStateProvider = () => "on") {
|
|
279
|
-
const adapter1 = new _TestAdapter({
|
|
280
|
-
send: (message) => connectionStateProvider() === "on" && (0, import_async.sleep)(10).then(() => adapter2.receive(message))
|
|
281
|
-
});
|
|
282
|
-
const adapter2 = new _TestAdapter({
|
|
283
|
-
send: (message) => connectionStateProvider() === "on" && (0, import_async.sleep)(10).then(() => adapter1.receive(message))
|
|
284
|
-
});
|
|
285
|
-
return [
|
|
286
|
-
adapter1,
|
|
287
|
-
adapter2
|
|
288
|
-
];
|
|
289
|
-
}
|
|
290
|
-
constructor(_params) {
|
|
291
|
-
super(), this._params = _params, this.onConnect = new import_async.Trigger();
|
|
292
|
-
}
|
|
293
|
-
isReady() {
|
|
294
|
-
return true;
|
|
295
|
-
}
|
|
296
|
-
whenReady() {
|
|
297
|
-
return Promise.resolve();
|
|
298
|
-
}
|
|
299
|
-
connect(peerId) {
|
|
300
|
-
this.peerId = peerId;
|
|
301
|
-
this.onConnect.wake();
|
|
302
|
-
}
|
|
303
|
-
peerCandidate(peerId) {
|
|
304
|
-
(0, import_invariant.invariant)(peerId, "PeerId is required", {
|
|
305
|
-
F: __dxlog_file3,
|
|
306
|
-
L: 45,
|
|
307
|
-
S: this,
|
|
308
|
-
A: [
|
|
309
|
-
"peerId",
|
|
310
|
-
"'PeerId is required'"
|
|
311
|
-
]
|
|
312
|
-
});
|
|
313
|
-
this.emit("peer-candidate", {
|
|
314
|
-
peerId,
|
|
315
|
-
peerMetadata: {}
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
peerDisconnected(peerId) {
|
|
319
|
-
(0, import_invariant.invariant)(peerId, "PeerId is required", {
|
|
320
|
-
F: __dxlog_file3,
|
|
321
|
-
L: 50,
|
|
322
|
-
S: this,
|
|
323
|
-
A: [
|
|
324
|
-
"peerId",
|
|
325
|
-
"'PeerId is required'"
|
|
326
|
-
]
|
|
327
|
-
});
|
|
328
|
-
this.emit("peer-disconnected", {
|
|
329
|
-
peerId
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
send(message) {
|
|
333
|
-
(0, import_log2.log)("send", {
|
|
334
|
-
from: message.senderId,
|
|
335
|
-
to: message.targetId,
|
|
336
|
-
type: message.type
|
|
337
|
-
}, {
|
|
338
|
-
F: __dxlog_file3,
|
|
339
|
-
L: 55,
|
|
340
|
-
S: this,
|
|
341
|
-
C: (f, a) => f(...a)
|
|
342
|
-
});
|
|
343
|
-
this._params.send(message);
|
|
344
|
-
}
|
|
345
|
-
disconnect() {
|
|
346
|
-
this.peerId = void 0;
|
|
347
|
-
}
|
|
348
|
-
receive(message) {
|
|
349
|
-
(0, import_invariant.invariant)(this.peerId, "Peer id is not set", {
|
|
350
|
-
F: __dxlog_file3,
|
|
351
|
-
L: 64,
|
|
352
|
-
S: this,
|
|
353
|
-
A: [
|
|
354
|
-
"this.peerId",
|
|
355
|
-
"'Peer id is not set'"
|
|
356
|
-
]
|
|
357
|
-
});
|
|
358
|
-
this.emit("message", message);
|
|
359
|
-
}
|
|
360
|
-
};
|
|
361
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
362
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
363
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
364
|
-
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;
|
|
365
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
366
|
-
}
|
|
367
|
-
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/testing/test-replicator.ts";
|
|
368
|
-
var TestReplicationNetwork = class extends import_context2.Resource {
|
|
369
|
-
constructor(options = {}) {
|
|
370
|
-
super();
|
|
371
|
-
this._replicators = /* @__PURE__ */ new Set();
|
|
372
|
-
this._latency = void 0;
|
|
373
|
-
this._latency = options.latency;
|
|
374
|
-
}
|
|
375
|
-
async _close(ctx) {
|
|
376
|
-
for (const replicator of this._replicators) {
|
|
377
|
-
for (const connection of replicator.connections) {
|
|
378
|
-
void connection.writable.abort();
|
|
379
|
-
void connection.readable.cancel();
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
async createReplicator() {
|
|
384
|
-
const replicator = new TestReplicator({
|
|
385
|
-
onConnect: async () => {
|
|
386
|
-
(0, import_invariant2.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
|
|
387
|
-
F: __dxlog_file4,
|
|
388
|
-
L: 45,
|
|
389
|
-
S: this,
|
|
390
|
-
A: [
|
|
391
|
-
"this._lifecycleState === LifecycleState.OPEN",
|
|
392
|
-
""
|
|
393
|
-
]
|
|
394
|
-
});
|
|
395
|
-
await this._connectReplicator(replicator);
|
|
396
|
-
},
|
|
397
|
-
onDisconnect: async () => {
|
|
398
|
-
(0, import_invariant2.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
|
|
399
|
-
F: __dxlog_file4,
|
|
400
|
-
L: 49,
|
|
401
|
-
S: this,
|
|
402
|
-
A: [
|
|
403
|
-
"this._lifecycleState === LifecycleState.OPEN",
|
|
404
|
-
""
|
|
405
|
-
]
|
|
406
|
-
});
|
|
407
|
-
await this._disconnectReplicator(replicator);
|
|
408
|
-
}
|
|
409
|
-
});
|
|
410
|
-
this._replicators.add(replicator);
|
|
411
|
-
return replicator;
|
|
412
|
-
}
|
|
413
|
-
async _connectReplicator(replicator) {
|
|
414
|
-
for (const otherReplicator of this._replicators.values()) {
|
|
415
|
-
if (otherReplicator === replicator || !otherReplicator.connected) {
|
|
416
|
-
continue;
|
|
417
|
-
}
|
|
418
|
-
(0, import_log3.log)("create connection", {
|
|
419
|
-
from: replicator.context.peerId,
|
|
420
|
-
to: otherReplicator.context.peerId
|
|
421
|
-
}, {
|
|
422
|
-
F: __dxlog_file4,
|
|
423
|
-
L: 63,
|
|
424
|
-
S: this,
|
|
425
|
-
C: (f, a) => f(...a)
|
|
426
|
-
});
|
|
427
|
-
const [connection1, connection2] = this._createConnectionPair(replicator.context.peerId, otherReplicator.context.peerId);
|
|
428
|
-
await replicator.context.onConnectionOpen(connection1);
|
|
429
|
-
await otherReplicator.context.onConnectionOpen(connection2);
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
async _disconnectReplicator(replicator) {
|
|
433
|
-
for (const connection of replicator.connections) {
|
|
434
|
-
await replicator.context.onConnectionClosed(connection);
|
|
435
|
-
await connection.otherSide.owningReplicator.removeConnection(connection.otherSide);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
_createConnectionPair(peer1, peer2) {
|
|
439
|
-
const LOG = false;
|
|
440
|
-
const forward = new TransformStream({
|
|
441
|
-
transform: async (message, controller) => {
|
|
442
|
-
if (LOG) {
|
|
443
|
-
(0, import_log3.log)("replicate", {
|
|
444
|
-
from: peer1,
|
|
445
|
-
to: peer2,
|
|
446
|
-
message
|
|
447
|
-
}, {
|
|
448
|
-
F: __dxlog_file4,
|
|
449
|
-
L: 86,
|
|
450
|
-
S: this,
|
|
451
|
-
C: (f, a) => f(...a)
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
if (this._latency !== void 0) {
|
|
455
|
-
await (0, import_async2.sleep)(this._latency);
|
|
456
|
-
}
|
|
457
|
-
controller.enqueue(message);
|
|
458
|
-
}
|
|
459
|
-
});
|
|
460
|
-
const backwards = new TransformStream({
|
|
461
|
-
transform: async (message, controller) => {
|
|
462
|
-
if (LOG) {
|
|
463
|
-
(0, import_log3.log)("replicate", {
|
|
464
|
-
from: peer2,
|
|
465
|
-
to: peer1,
|
|
466
|
-
message
|
|
467
|
-
}, {
|
|
468
|
-
F: __dxlog_file4,
|
|
469
|
-
L: 99,
|
|
470
|
-
S: this,
|
|
471
|
-
C: (f, a) => f(...a)
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
if (this._latency !== void 0) {
|
|
475
|
-
await (0, import_async2.sleep)(this._latency);
|
|
476
|
-
}
|
|
477
|
-
controller.enqueue(message);
|
|
478
|
-
}
|
|
479
|
-
});
|
|
480
|
-
const connection1 = new TestReplicatorConnection(peer2, backwards.readable, forward.writable);
|
|
481
|
-
const connection2 = new TestReplicatorConnection(peer1, forward.readable, backwards.writable);
|
|
482
|
-
connection1.otherSide = connection2;
|
|
483
|
-
connection2.otherSide = connection1;
|
|
484
|
-
return [
|
|
485
|
-
connection1,
|
|
486
|
-
connection2
|
|
487
|
-
];
|
|
488
|
-
}
|
|
489
|
-
};
|
|
490
|
-
_ts_decorate([
|
|
491
|
-
import_async2.synchronized
|
|
492
|
-
], TestReplicationNetwork.prototype, "_connectReplicator", null);
|
|
493
|
-
var TestReplicator = class {
|
|
494
|
-
constructor(_params) {
|
|
495
|
-
this._params = _params;
|
|
496
|
-
this.connected = false;
|
|
497
|
-
this.context = void 0;
|
|
498
|
-
this.connections = /* @__PURE__ */ new Set();
|
|
499
|
-
}
|
|
500
|
-
async connect(context) {
|
|
501
|
-
(0, import_log3.log)("connect", {
|
|
502
|
-
peerId: context.peerId
|
|
503
|
-
}, {
|
|
504
|
-
F: __dxlog_file4,
|
|
505
|
-
L: 131,
|
|
506
|
-
S: this,
|
|
507
|
-
C: (f, a) => f(...a)
|
|
508
|
-
});
|
|
509
|
-
this.context = context;
|
|
510
|
-
this.connected = true;
|
|
511
|
-
await this._params.onConnect();
|
|
512
|
-
}
|
|
513
|
-
async disconnect() {
|
|
514
|
-
(0, import_log3.log)("disconnect", {
|
|
515
|
-
peerId: this.context.peerId
|
|
516
|
-
}, {
|
|
517
|
-
F: __dxlog_file4,
|
|
518
|
-
L: 138,
|
|
519
|
-
S: this,
|
|
520
|
-
C: (f, a) => f(...a)
|
|
521
|
-
});
|
|
522
|
-
this.connected = false;
|
|
523
|
-
await this._params.onDisconnect();
|
|
524
|
-
}
|
|
525
|
-
async addConnection(connection) {
|
|
526
|
-
connection.owningReplicator = this;
|
|
527
|
-
this.connections.add(connection);
|
|
528
|
-
this.context.onConnectionOpen(connection);
|
|
529
|
-
}
|
|
530
|
-
async removeConnection(connection) {
|
|
531
|
-
connection.owningReplicator = void 0;
|
|
532
|
-
this.context.onConnectionClosed(connection);
|
|
533
|
-
this.connections.delete(connection);
|
|
534
|
-
}
|
|
535
|
-
};
|
|
536
|
-
var TestReplicatorConnection = class {
|
|
537
|
-
constructor(peerId, readable, writable) {
|
|
538
|
-
this.peerId = peerId;
|
|
539
|
-
this.readable = readable;
|
|
540
|
-
this.writable = writable;
|
|
541
|
-
this.otherSide = void 0;
|
|
542
|
-
this.owningReplicator = void 0;
|
|
543
|
-
}
|
|
544
|
-
async shouldAdvertise(params) {
|
|
545
|
-
return true;
|
|
546
|
-
}
|
|
547
|
-
shouldSyncCollection(params) {
|
|
548
|
-
return true;
|
|
549
|
-
}
|
|
550
|
-
};
|
|
551
|
-
var testAutomergeReplicatorFactory = (params) => {
|
|
552
|
-
return new import_teleport_extension_automerge_replicator.AutomergeReplicator({
|
|
553
|
-
...params[0],
|
|
554
|
-
sendSyncRetryPolicy: {
|
|
555
|
-
retryBackoff: 20,
|
|
556
|
-
retriesBeforeBackoff: 2,
|
|
557
|
-
maxRetries: 3
|
|
558
|
-
}
|
|
559
|
-
}, params[1]);
|
|
560
|
-
};
|
|
561
|
-
var brokenAutomergeReplicatorFactory = (params) => {
|
|
562
|
-
params[1].onSyncMessage = () => {
|
|
563
|
-
throw new Error();
|
|
564
|
-
};
|
|
565
|
-
return testAutomergeReplicatorFactory(params);
|
|
566
|
-
};
|
|
567
|
-
var test_schema_exports = {};
|
|
568
|
-
(0, import_chunk_Q7SFCCGT.__export)(test_schema_exports, {
|
|
569
|
-
Organization: () => Organization,
|
|
570
|
-
Person: () => Person,
|
|
571
|
-
Task: () => Task,
|
|
572
|
-
WorksFor: () => WorksFor
|
|
573
|
-
});
|
|
574
|
-
var Person = import_effect.Schema.Struct({
|
|
575
|
-
name: import_effect.Schema.String,
|
|
576
|
-
email: import_effect.Schema.optional(import_effect.Schema.String),
|
|
577
|
-
age: import_effect.Schema.optional(import_effect.Schema.Number)
|
|
578
|
-
}).pipe(import_echo.Type.Obj({
|
|
579
|
-
typename: "dxos.org/type/Person",
|
|
580
|
-
version: "0.1.0"
|
|
581
|
-
}));
|
|
582
|
-
var Organization = import_effect.Schema.Struct({
|
|
583
|
-
name: import_effect.Schema.String
|
|
584
|
-
}).pipe(import_echo.Type.Obj({
|
|
585
|
-
typename: "dxos.org/type/Organization",
|
|
586
|
-
version: "0.1.0"
|
|
587
|
-
}));
|
|
588
|
-
var WorksFor = import_effect.Schema.Struct({
|
|
589
|
-
since: import_effect.Schema.String
|
|
590
|
-
}).pipe(import_echo.Type.Relation({
|
|
591
|
-
typename: "dxos.org/type/WorksFor",
|
|
592
|
-
version: "0.1.0",
|
|
593
|
-
source: Person,
|
|
594
|
-
target: Organization
|
|
595
|
-
}));
|
|
596
|
-
var Task = import_effect.Schema.Struct({
|
|
597
|
-
title: import_effect.Schema.String,
|
|
598
|
-
createdAt: import_effect.Schema.String,
|
|
599
|
-
assignee: import_echo.Type.Ref(Person)
|
|
600
|
-
}).pipe(import_echo.Type.Obj({
|
|
601
|
-
typename: "dxos.org/type/Task",
|
|
602
|
-
version: "0.1.0"
|
|
603
|
-
}));
|
|
604
|
-
var test_data_exports = {};
|
|
605
|
-
(0, import_chunk_Q7SFCCGT.__export)(test_data_exports, {
|
|
606
|
-
ORGS: () => ORGS,
|
|
607
|
-
PEOPLE: () => PEOPLE,
|
|
608
|
-
TASKS: () => TASKS,
|
|
609
|
-
WORKS_FOR: () => WORKS_FOR
|
|
610
|
-
});
|
|
611
|
-
var spaceKey = import_keys2.PublicKey.random();
|
|
612
|
-
var PEOPLE = {
|
|
613
|
-
fred: import_echo_protocol.DatabaseDirectory.make({
|
|
614
|
-
spaceKey: spaceKey.toHex(),
|
|
615
|
-
objects: {
|
|
616
|
-
[import_keys2.ObjectId.random()]: import_echo_protocol.ObjectStructure.makeObject({
|
|
617
|
-
type: (0, import_echo_schema.getSchemaDXN)(Person).toString(),
|
|
618
|
-
data: {
|
|
619
|
-
name: "Fred"
|
|
620
|
-
}
|
|
621
|
-
})
|
|
622
|
-
}
|
|
623
|
-
}),
|
|
624
|
-
alice: import_echo_protocol.DatabaseDirectory.make({
|
|
625
|
-
spaceKey: spaceKey.toHex(),
|
|
626
|
-
objects: {
|
|
627
|
-
[import_keys2.ObjectId.random()]: import_echo_protocol.ObjectStructure.makeObject({
|
|
628
|
-
type: (0, import_echo_schema.getSchemaDXN)(Person).toString(),
|
|
629
|
-
data: {
|
|
630
|
-
name: "Alice"
|
|
631
|
-
}
|
|
632
|
-
})
|
|
633
|
-
}
|
|
634
|
-
})
|
|
635
|
-
};
|
|
636
|
-
var ORGS = {
|
|
637
|
-
cyberdyne: import_echo_protocol.DatabaseDirectory.make({
|
|
638
|
-
spaceKey: spaceKey.toHex(),
|
|
639
|
-
objects: {
|
|
640
|
-
[import_keys2.ObjectId.random()]: import_echo_protocol.ObjectStructure.makeObject({
|
|
641
|
-
type: (0, import_echo_schema.getSchemaDXN)(Organization).toString(),
|
|
642
|
-
data: {
|
|
643
|
-
name: "Cyberdyne Systems",
|
|
644
|
-
founded: "1984"
|
|
645
|
-
}
|
|
646
|
-
})
|
|
647
|
-
}
|
|
648
|
-
}),
|
|
649
|
-
aperture: import_echo_protocol.DatabaseDirectory.make({
|
|
650
|
-
spaceKey: spaceKey.toHex(),
|
|
651
|
-
objects: {
|
|
652
|
-
[import_keys2.ObjectId.random()]: import_echo_protocol.ObjectStructure.makeObject({
|
|
653
|
-
type: (0, import_echo_schema.getSchemaDXN)(Organization).toString(),
|
|
654
|
-
data: {
|
|
655
|
-
name: "Aperture Science",
|
|
656
|
-
founded: "1953"
|
|
657
|
-
}
|
|
658
|
-
})
|
|
659
|
-
}
|
|
660
|
-
})
|
|
661
|
-
};
|
|
662
|
-
var WORKS_FOR = {
|
|
663
|
-
fredWorksForCyberdyne: import_echo_protocol.DatabaseDirectory.make({
|
|
664
|
-
spaceKey: spaceKey.toHex(),
|
|
665
|
-
objects: {
|
|
666
|
-
[import_keys2.ObjectId.random()]: import_echo_protocol.ObjectStructure.makeRelation({
|
|
667
|
-
type: (0, import_echo_schema.getSchemaDXN)(WorksFor).toString(),
|
|
668
|
-
source: {
|
|
669
|
-
"/": import_keys2.DXN.fromLocalObjectId(Object.keys(PEOPLE.fred.objects)[0]).toString()
|
|
670
|
-
},
|
|
671
|
-
target: {
|
|
672
|
-
"/": import_keys2.DXN.fromLocalObjectId(Object.keys(ORGS.cyberdyne.objects)[0]).toString()
|
|
673
|
-
},
|
|
674
|
-
data: {
|
|
675
|
-
since: "2020",
|
|
676
|
-
position: "Engineer"
|
|
677
|
-
}
|
|
678
|
-
})
|
|
679
|
-
}
|
|
680
|
-
}),
|
|
681
|
-
aliceWorksForAperture: import_echo_protocol.DatabaseDirectory.make({
|
|
682
|
-
spaceKey: spaceKey.toHex(),
|
|
683
|
-
objects: {
|
|
684
|
-
[import_keys2.ObjectId.random()]: import_echo_protocol.ObjectStructure.makeRelation({
|
|
685
|
-
type: (0, import_echo_schema.getSchemaDXN)(WorksFor).toString(),
|
|
686
|
-
source: {
|
|
687
|
-
"/": import_keys2.DXN.fromLocalObjectId(Object.keys(PEOPLE.alice.objects)[0]).toString()
|
|
688
|
-
},
|
|
689
|
-
target: {
|
|
690
|
-
"/": import_keys2.DXN.fromLocalObjectId(Object.keys(ORGS.aperture.objects)[0]).toString()
|
|
691
|
-
},
|
|
692
|
-
data: {
|
|
693
|
-
since: "2018",
|
|
694
|
-
position: "Research Scientist"
|
|
695
|
-
}
|
|
696
|
-
})
|
|
697
|
-
}
|
|
698
|
-
})
|
|
699
|
-
};
|
|
700
|
-
var TASKS = {
|
|
701
|
-
task1: import_echo_protocol.DatabaseDirectory.make({
|
|
702
|
-
spaceKey: spaceKey.toHex(),
|
|
703
|
-
objects: {
|
|
704
|
-
[import_keys2.ObjectId.random()]: import_echo_protocol.ObjectStructure.makeObject({
|
|
705
|
-
type: (0, import_echo_schema.getSchemaDXN)(Task).toString(),
|
|
706
|
-
data: {
|
|
707
|
-
title: "Complete project documentation",
|
|
708
|
-
description: "Write comprehensive documentation for the new system",
|
|
709
|
-
status: "in-progress",
|
|
710
|
-
dueDate: "2023-12-31",
|
|
711
|
-
assignee: {
|
|
712
|
-
"/": import_keys2.DXN.fromLocalObjectId(Object.keys(PEOPLE.fred.objects)[0]).toString()
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
})
|
|
716
|
-
}
|
|
717
|
-
}),
|
|
718
|
-
task2: import_echo_protocol.DatabaseDirectory.make({
|
|
719
|
-
spaceKey: spaceKey.toHex(),
|
|
720
|
-
objects: {
|
|
721
|
-
[import_keys2.ObjectId.random()]: import_echo_protocol.ObjectStructure.makeObject({
|
|
722
|
-
type: (0, import_echo_schema.getSchemaDXN)(Task).toString(),
|
|
723
|
-
data: {
|
|
724
|
-
title: "Run experiments",
|
|
725
|
-
description: "Conduct series of experiments on the portal device",
|
|
726
|
-
status: "pending",
|
|
727
|
-
dueDate: "2023-11-15",
|
|
728
|
-
assignee: {
|
|
729
|
-
"/": import_keys2.DXN.fromLocalObjectId(Object.keys(PEOPLE.alice.objects)[0]).toString()
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
})
|
|
733
|
-
}
|
|
734
|
-
})
|
|
735
|
-
};
|
|
736
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
737
|
-
0 && (module.exports = {
|
|
738
|
-
MemoryNetworkManagerProvider,
|
|
739
|
-
TestAdapter,
|
|
740
|
-
TestAgent,
|
|
741
|
-
TestAgentBuilder,
|
|
742
|
-
TestData,
|
|
743
|
-
TestFeedBuilder,
|
|
744
|
-
TestReplicationNetwork,
|
|
745
|
-
TestReplicator,
|
|
746
|
-
TestReplicatorConnection,
|
|
747
|
-
TestSchema,
|
|
748
|
-
WebsocketNetworkManagerProvider,
|
|
749
|
-
brokenAutomergeReplicatorFactory,
|
|
750
|
-
changeStorageVersionInMetadata,
|
|
751
|
-
testAutomergeReplicatorFactory
|
|
752
|
-
});
|
|
753
|
-
//# sourceMappingURL=index.cjs.map
|