@dxos/client-services 0.1.31-next.ea8f0bc → 0.1.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/lib/browser/{chunk-ZIQUYEJS.mjs → chunk-DFO3FW2W.mjs} +53 -20
  2. package/dist/lib/browser/{chunk-ZIQUYEJS.mjs.map → chunk-DFO3FW2W.mjs.map} +3 -3
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/packlets/testing/index.mjs +64 -6
  6. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/index.cjs +52 -19
  8. package/dist/lib/node/index.cjs.map +3 -3
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/packlets/testing/index.cjs +114 -22
  11. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  12. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  13. package/dist/types/src/packlets/spaces/data-space.d.ts +8 -1
  14. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  15. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  16. package/dist/types/src/packlets/spaces/spaces-service.d.ts +4 -1
  17. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  18. package/dist/types/src/packlets/testing/test-builder.d.ts +2 -0
  19. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  20. package/dist/types/src/packlets/tests/text.test.d.ts +2 -0
  21. package/dist/types/src/packlets/tests/text.test.d.ts.map +1 -0
  22. package/package.json +31 -30
  23. package/src/packlets/spaces/data-space-manager.test.ts +60 -0
  24. package/src/packlets/spaces/data-space-manager.ts +11 -7
  25. package/src/packlets/spaces/data-space.ts +13 -1
  26. package/src/packlets/spaces/notarization-plugin.ts +9 -2
  27. package/src/packlets/spaces/spaces-service.ts +25 -0
  28. package/src/packlets/testing/test-builder.ts +45 -5
  29. package/src/packlets/tests/spaces-invitations.test.ts +46 -6
  30. package/src/packlets/tests/spaces.test.ts +70 -2
  31. package/src/packlets/tests/text.test.ts +206 -0
@@ -39,6 +39,7 @@ __export(testing_exports, {
39
39
  createServiceContext: () => createServiceContext,
40
40
  createServiceHost: () => createServiceHost,
41
41
  createSigningContext: () => createSigningContext,
42
+ joinCommonSpace: () => joinCommonSpace,
42
43
  performInvitation: () => performInvitation,
43
44
  syncItems: () => syncItems,
44
45
  syncItemsLocal: () => syncItemsLocal,
@@ -1995,7 +1996,7 @@ var import_credentials11 = require("@dxos/credentials");
1995
1996
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
1996
1997
  var import_keys9 = require("@dxos/keys");
1997
1998
  var import_log8 = require("@dxos/log");
1998
- var import_teleport_extension_presence = require("@dxos/teleport-extension-presence");
1999
+ var import_teleport_extension_gossip = require("@dxos/teleport-extension-gossip");
1999
2000
  var import_util5 = require("@dxos/util");
2000
2001
 
2001
2002
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
@@ -2017,6 +2018,7 @@ var import_protocols4 = require("@dxos/protocols");
2017
2018
  var import_teleport3 = require("@dxos/teleport");
2018
2019
  var import_util3 = require("@dxos/util");
2019
2020
  var RETRY_TIMEOUT = 1e3;
2021
+ var SUCCESS_DELAY = 1e3;
2020
2022
  var NOTARIZE_TIMEOUT = 1e4;
2021
2023
  var NotarizationPlugin = class {
2022
2024
  constructor() {
@@ -2039,7 +2041,7 @@ var NotarizationPlugin = class {
2039
2041
  credentials
2040
2042
  }, {
2041
2043
  file: "notarization-plugin.ts",
2042
- line: 44,
2044
+ line: 50,
2043
2045
  scope: this,
2044
2046
  callSite: (f, a) => f(...a)
2045
2047
  });
@@ -2051,7 +2053,7 @@ var NotarizationPlugin = class {
2051
2053
  err
2052
2054
  }, {
2053
2055
  file: "notarization-plugin.ts",
2054
- line: 53,
2056
+ line: 59,
2055
2057
  scope: this,
2056
2058
  callSite: (f, a) => f(...a)
2057
2059
  });
@@ -2062,7 +2064,7 @@ var NotarizationPlugin = class {
2062
2064
  (0, import_async9.scheduleTask)(ctx, () => {
2063
2065
  import_log7.log.warn("Notarization timeout", {}, {
2064
2066
  file: "notarization-plugin.ts",
2065
- line: 61,
2067
+ line: 67,
2066
2068
  scope: this,
2067
2069
  callSite: (f, a) => f(...a)
2068
2070
  });
@@ -2076,7 +2078,7 @@ var NotarizationPlugin = class {
2076
2078
  if (this._extensions.size === 0) {
2077
2079
  import_log7.log.warn("No peers to notarize with", {}, {
2078
2080
  file: "notarization-plugin.ts",
2079
- line: 76,
2081
+ line: 82,
2080
2082
  scope: this,
2081
2083
  callSite: (f, a) => f(...a)
2082
2084
  });
@@ -2090,7 +2092,7 @@ var NotarizationPlugin = class {
2090
2092
  retryIn: RETRY_TIMEOUT
2091
2093
  }, {
2092
2094
  file: "notarization-plugin.ts",
2093
- line: 83,
2095
+ line: 89,
2094
2096
  scope: this,
2095
2097
  callSite: (f, a) => f(...a)
2096
2098
  });
@@ -2104,7 +2106,7 @@ var NotarizationPlugin = class {
2104
2106
  credentialId: credentials.map((credential) => credential.id)
2105
2107
  }, {
2106
2108
  file: "notarization-plugin.ts",
2107
- line: 90,
2109
+ line: 96,
2108
2110
  scope: this,
2109
2111
  callSite: (f, a) => f(...a)
2110
2112
  });
@@ -2113,14 +2115,15 @@ var NotarizationPlugin = class {
2113
2115
  });
2114
2116
  (0, import_log7.log)("success", {}, {
2115
2117
  file: "notarization-plugin.ts",
2116
- line: 94,
2118
+ line: 100,
2117
2119
  scope: this,
2118
2120
  callSite: (f, a) => f(...a)
2119
2121
  });
2122
+ await (0, import_async9.sleep)(SUCCESS_DELAY);
2120
2123
  } catch (err) {
2121
2124
  import_log7.log.warn("error notarizing (recoverable)", err, {
2122
2125
  file: "notarization-plugin.ts",
2123
- line: 96,
2126
+ line: 103,
2124
2127
  scope: this,
2125
2128
  callSite: (f, a) => f(...a)
2126
2129
  });
@@ -2136,7 +2139,7 @@ var NotarizationPlugin = class {
2136
2139
  ]);
2137
2140
  (0, import_log7.log)("done", {}, {
2138
2141
  file: "notarization-plugin.ts",
2139
- line: 107,
2142
+ line: 114,
2140
2143
  scope: this,
2141
2144
  callSite: (f, a) => f(...a)
2142
2145
  });
@@ -2189,7 +2192,7 @@ var NotarizationPlugin = class {
2189
2192
  peer: extension.localPeerId
2190
2193
  }, {
2191
2194
  file: "notarization-plugin.ts",
2192
- line: 156,
2195
+ line: 163,
2193
2196
  scope: this,
2194
2197
  callSite: (f, a) => f(...a)
2195
2198
  });
@@ -2201,7 +2204,7 @@ var NotarizationPlugin = class {
2201
2204
  peer: extension.localPeerId
2202
2205
  }, {
2203
2206
  file: "notarization-plugin.ts",
2204
- line: 161,
2207
+ line: 168,
2205
2208
  scope: this,
2206
2209
  callSite: (f, a) => f(...a)
2207
2210
  });
@@ -2260,6 +2263,7 @@ var DataSpace = class DataSpace2 {
2260
2263
  constructor(params) {
2261
2264
  this._ctx = new import_context6.Context();
2262
2265
  this._inner = params.inner;
2266
+ this._gossip = params.gossip;
2263
2267
  this._presence = params.presence;
2264
2268
  this._keyring = params.keyring;
2265
2269
  this._feedStore = params.feedStore;
@@ -2316,6 +2320,12 @@ var DataSpace = class DataSpace2 {
2316
2320
  await this.notarizationPlugin.close();
2317
2321
  await this._presence.destroy();
2318
2322
  }
2323
+ async postMessage(channel, message) {
2324
+ return this._gossip.postMessage(channel, message);
2325
+ }
2326
+ listen(channel, callback) {
2327
+ return this._gossip.listen(channel, callback);
2328
+ }
2319
2329
  async initializeDataPipeline() {
2320
2330
  await this._inner.controlPipeline.state.waitUntilReachedTargetTimeframe({
2321
2331
  timeout: CONTROL_PIPELINE_READY_TIMEFRAME
@@ -2496,11 +2506,14 @@ var DataSpaceManager = class DataSpaceManager2 {
2496
2506
  return space;
2497
2507
  }
2498
2508
  async _constructSpace(metadata) {
2499
- const presence = new import_teleport_extension_presence.Presence({
2500
- localPeerId: this._signingContext.deviceKey,
2501
- announceInterval: 1e3,
2502
- offlineTimeout: 1e4,
2503
- identityKey: this._signingContext.identityKey
2509
+ const gossip = new import_teleport_extension_gossip.Gossip({
2510
+ localPeerId: this._signingContext.deviceKey
2511
+ });
2512
+ const presence = new import_teleport_extension_gossip.Presence({
2513
+ announceInterval: 500,
2514
+ offlineTimeout: 5e3,
2515
+ identityKey: this._signingContext.identityKey,
2516
+ gossip
2504
2517
  });
2505
2518
  const snapshotManager = new import_echo_pipeline2.SnapshotManager(this._snapshotStore);
2506
2519
  const controlFeed = metadata.controlFeedKey && await this._feedStore.openFeed(metadata.controlFeedKey, {
@@ -2517,7 +2530,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2517
2530
  credentialAuthenticator: (0, import_util5.deferFunction)(() => dataSpace.authVerifier.verifier)
2518
2531
  },
2519
2532
  onNetworkConnection: (session) => {
2520
- session.addExtension("dxos.mesh.teleport.presence", presence.createExtension({
2533
+ session.addExtension("dxos.mesh.teleport.gossip", gossip.createExtension({
2521
2534
  remotePeerId: session.remotePeerId
2522
2535
  }));
2523
2536
  session.addExtension("dxos.mesh.teleport.objectsync", snapshotManager.objectSync.createExtension());
@@ -2531,6 +2544,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2531
2544
  modelFactory: this._modelFactory,
2532
2545
  metadataStore: this._metadataStore,
2533
2546
  snapshotManager,
2547
+ gossip,
2534
2548
  presence,
2535
2549
  memberKey: this._signingContext.identityKey,
2536
2550
  keyring: this._keyring,
@@ -2594,7 +2608,7 @@ var SpacesServiceImpl = class {
2594
2608
  spaces
2595
2609
  }, {
2596
2610
  file: "spaces-service.ts",
2597
- line: 59,
2611
+ line: 62,
2598
2612
  scope: this,
2599
2613
  callSite: (f, a) => f(...a)
2600
2614
  });
@@ -2632,6 +2646,25 @@ var SpacesServiceImpl = class {
2632
2646
  }
2633
2647
  });
2634
2648
  }
2649
+ async postMessage({ spaceKey, channel, message }) {
2650
+ var _a;
2651
+ const dataSpaceManager = await this._getDataSpaceManager();
2652
+ const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug4.raise)(new import_echo_pipeline3.SpaceNotFoundError(spaceKey));
2653
+ await space.postMessage(getChannelId(channel), message);
2654
+ }
2655
+ subscribeMessages({ spaceKey, channel }) {
2656
+ return new import_codec_protobuf10.Stream(({ ctx, next }) => {
2657
+ (0, import_async12.scheduleTask)(ctx, async () => {
2658
+ var _a;
2659
+ const dataSpaceManager = await this._getDataSpaceManager();
2660
+ const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug4.raise)(new import_echo_pipeline3.SpaceNotFoundError(spaceKey));
2661
+ const handle = space.listen(getChannelId(channel), (message) => {
2662
+ next(message);
2663
+ });
2664
+ ctx.onDispose(() => handle.unsubscribe());
2665
+ });
2666
+ });
2667
+ }
2635
2668
  queryCredentials({ spaceKey }) {
2636
2669
  return new import_codec_protobuf10.Stream(({ ctx, next }) => {
2637
2670
  var _a;
@@ -2675,6 +2708,7 @@ var SpacesServiceImpl = class {
2675
2708
  };
2676
2709
  }
2677
2710
  };
2711
+ var getChannelId = (channel) => `user-channel/${channel}`;
2678
2712
 
2679
2713
  // packages/sdk/client-services/src/packlets/storage/storage.ts
2680
2714
  var import_errors = require("@dxos/errors");
@@ -3833,9 +3867,11 @@ var import_node_assert14 = __toESM(require("node:assert"));
3833
3867
  var import_async21 = require("@dxos/async");
3834
3868
  var import_client8 = require("@dxos/client");
3835
3869
  var import_config3 = require("@dxos/config");
3870
+ var import_debug9 = require("@dxos/debug");
3836
3871
  var import_document_model = require("@dxos/document-model");
3837
3872
  var import_echo_db = require("@dxos/echo-db");
3838
3873
  var import_keys10 = require("@dxos/keys");
3874
+ var import_log17 = require("@dxos/log");
3839
3875
  var import_messaging5 = require("@dxos/messaging");
3840
3876
  var import_network_manager8 = require("@dxos/network-manager");
3841
3877
  var import_rpc5 = require("@dxos/rpc");
@@ -3926,15 +3962,70 @@ var TestBuilder = class {
3926
3962
  var testSpace = async (create, check = create) => {
3927
3963
  const objectId = import_keys10.PublicKey.random().toHex();
3928
3964
  const result = create.mutate((0, import_echo_db.genesisMutation)(objectId, import_document_model.DocumentModel.meta.type));
3929
- await result.getReceipt();
3930
- (0, import_node_assert14.default)(create._itemManager.entities.has(result.objectsCreated[0].id));
3931
- await (0, import_async21.asyncTimeout)(check._itemManager.update.waitForCondition(() => check._itemManager.entities.has(objectId)), 1e3);
3965
+ await result.batch.getReceipt();
3966
+ (0, import_node_assert14.default)(create._itemManager.entities.has(result.objectsUpdated[0].id));
3967
+ await (0, import_async21.asyncTimeout)(check.itemUpdate.waitForCondition(() => check._itemManager.entities.has(objectId)), 1e3);
3932
3968
  return result;
3933
3969
  };
3934
3970
  var syncItems = async (db1, db2) => {
3935
3971
  await testSpace(db1, db2);
3936
3972
  await testSpace(db2, db1);
3937
3973
  };
3974
+ var joinCommonSpace = async ([initialPeer, ...peers], spaceKey) => {
3975
+ const rootSpace = spaceKey ? initialPeer.echo.getSpace(spaceKey) : await initialPeer.echo.createSpace();
3976
+ (0, import_node_assert14.default)(rootSpace, "Space not found.");
3977
+ await Promise.all(peers.map(async (peer) => {
3978
+ const hostDone = new import_async21.Trigger();
3979
+ const guestDone = new import_async21.Trigger();
3980
+ const hostObservabli = rootSpace.createInvitation({
3981
+ type: import_client8.Invitation.Type.INTERACTIVE_TESTING
3982
+ });
3983
+ (0, import_log17.log)("invitation created", {}, {
3984
+ file: "test-builder.ts",
3985
+ line: 154,
3986
+ scope: void 0,
3987
+ callSite: (f, a) => f(...a)
3988
+ });
3989
+ hostObservabli.subscribe({
3990
+ onConnecting: (invitation) => {
3991
+ const guestObservable = peer.echo.acceptInvitation(invitation);
3992
+ (0, import_log17.log)("invitation accepted", {}, {
3993
+ file: "test-builder.ts",
3994
+ line: 158,
3995
+ scope: void 0,
3996
+ callSite: (f, a) => f(...a)
3997
+ });
3998
+ guestObservable.subscribe({
3999
+ onSuccess: (invitation2) => {
4000
+ guestDone.wake(invitation2);
4001
+ (0, import_log17.log)("invitation guestDone", {}, {
4002
+ file: "test-builder.ts",
4003
+ line: 163,
4004
+ scope: void 0,
4005
+ callSite: (f, a) => f(...a)
4006
+ });
4007
+ },
4008
+ onError: (err) => (0, import_debug9.raise)(err)
4009
+ });
4010
+ },
4011
+ onSuccess: (invitation) => {
4012
+ hostDone.wake(invitation);
4013
+ (0, import_log17.log)("invitation hostDone", {}, {
4014
+ file: "test-builder.ts",
4015
+ line: 170,
4016
+ scope: void 0,
4017
+ callSite: (f, a) => f(...a)
4018
+ });
4019
+ },
4020
+ onError: (err) => (0, import_debug9.raise)(err)
4021
+ });
4022
+ await Promise.all([
4023
+ hostDone.wait(),
4024
+ guestDone.wait()
4025
+ ]);
4026
+ }));
4027
+ return rootSpace.key;
4028
+ };
3938
4029
  // Annotate the CommonJS export names for ESM import in node:
3939
4030
  0 && (module.exports = {
3940
4031
  HostTestBuilder,
@@ -3946,6 +4037,7 @@ var syncItems = async (db1, db2) => {
3946
4037
  createServiceContext,
3947
4038
  createServiceHost,
3948
4039
  createSigningContext,
4040
+ joinCommonSpace,
3949
4041
  performInvitation,
3950
4042
  syncItems,
3951
4043
  syncItemsLocal,