@dxos/client-services 0.5.9-main.51854a6 → 0.5.9-main.55e2125

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.
@@ -359,7 +359,7 @@ import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
359
359
  import { TRACE_PROCESSOR } from "@dxos/tracing";
360
360
 
361
361
  // packages/sdk/client-services/src/version.ts
362
- var DXOS_VERSION = "0.5.9-main.51854a6";
362
+ var DXOS_VERSION = "0.5.9-main.55e2125";
363
363
 
364
364
  // packages/sdk/client-services/src/packlets/services/platform.ts
365
365
  import { Platform } from "@dxos/protocols/proto/dxos/client/services";
@@ -3880,21 +3880,35 @@ var runEpochMigration = async (ctx, context) => {
3880
3880
  });
3881
3881
  const newRootContent = await convertLegacySpaceRootDoc(structuredClone(rootHandle.docSync()));
3882
3882
  for (const [id, url] of Object.entries(newRootContent.links ?? {})) {
3883
- const handle = context.repo.find(url);
3884
- await cancelWithContext4(ctx, asyncTimeout2(handle.whenReady(), 1e4));
3885
- invariant12(handle.docSync(), "Doc not found", {
3886
- F: __dxlog_file16,
3887
- L: 107,
3888
- S: void 0,
3889
- A: [
3890
- "handle.docSync()",
3891
- "'Doc not found'"
3892
- ]
3893
- });
3894
- const newDoc = await convertLegacyReferences(structuredClone(handle.docSync()));
3895
- const migratedDoc = migrateDocument(handle.docSync(), newDoc);
3896
- const newHandle = context.repo.import(am.save(migratedDoc));
3897
- newRootContent.links[id] = newHandle.url;
3883
+ try {
3884
+ const handle = context.repo.find(url);
3885
+ await cancelWithContext4(ctx, asyncTimeout2(handle.whenReady(), 1e4));
3886
+ invariant12(handle.docSync(), "Doc not found", {
3887
+ F: __dxlog_file16,
3888
+ L: 108,
3889
+ S: void 0,
3890
+ A: [
3891
+ "handle.docSync()",
3892
+ "'Doc not found'"
3893
+ ]
3894
+ });
3895
+ const newDoc = await convertLegacyReferences(structuredClone(handle.docSync()));
3896
+ const migratedDoc = migrateDocument(handle.docSync(), newDoc);
3897
+ const newHandle = context.repo.import(am.save(migratedDoc));
3898
+ newRootContent.links[id] = newHandle.url;
3899
+ } catch (err) {
3900
+ log13.warn("Failed to migrate reference", {
3901
+ id,
3902
+ url,
3903
+ error: err
3904
+ }, {
3905
+ F: __dxlog_file16,
3906
+ L: 114,
3907
+ S: void 0,
3908
+ C: (f, a) => f(...a)
3909
+ });
3910
+ delete newRootContent.links[id];
3911
+ }
3898
3912
  }
3899
3913
  const migratedRoot = migrateDocument(rootHandle.docSync(), newRootContent);
3900
3914
  const newRoot = context.repo.import(am.save(migratedRoot));
@@ -3906,7 +3920,7 @@ var runEpochMigration = async (ctx, context) => {
3906
3920
  case CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT: {
3907
3921
  invariant12(context.newAutomergeRoot, void 0, {
3908
3922
  F: __dxlog_file16,
3909
- L: 124,
3923
+ L: 129,
3910
3924
  S: void 0,
3911
3925
  A: [
3912
3926
  "context.newAutomergeRoot",
@@ -6267,13 +6281,151 @@ var createLevel = async (config) => {
6267
6281
  return level;
6268
6282
  };
6269
6283
 
6284
+ // packages/sdk/client-services/src/packlets/storage/profile-archive.ts
6285
+ import { cbor } from "@dxos/automerge/automerge-repo";
6286
+ import { invariant as invariant17 } from "@dxos/invariant";
6287
+ import { log as log20 } from "@dxos/log";
6288
+ import { ProfileArchiveEntryType } from "@dxos/protocols";
6289
+ import { arrayToBuffer } from "@dxos/util";
6290
+ var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/storage/profile-archive.ts";
6291
+ var encodeProfileArchive = (profile) => cbor.encode(profile);
6292
+ var decodeProfileArchive = (data) => cbor.decode(data);
6293
+ var exportProfileData = async ({ storage, level }) => {
6294
+ const archive = {
6295
+ storage: [],
6296
+ meta: {
6297
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
6298
+ }
6299
+ };
6300
+ {
6301
+ const directory = await storage.createDirectory();
6302
+ const files = await directory.list();
6303
+ log20.info("begin exporting files", {
6304
+ count: files.length
6305
+ }, {
6306
+ F: __dxlog_file23,
6307
+ L: 30,
6308
+ S: void 0,
6309
+ C: (f, a) => f(...a)
6310
+ });
6311
+ for (const filename of files) {
6312
+ const file = await directory.getOrCreateFile(filename);
6313
+ const { size } = await file.stat();
6314
+ const data = await file.read(0, size);
6315
+ archive.storage.push({
6316
+ type: ProfileArchiveEntryType.FILE,
6317
+ key: filename,
6318
+ value: data
6319
+ });
6320
+ }
6321
+ log20.info("done exporting files", {
6322
+ count: files.length
6323
+ }, {
6324
+ F: __dxlog_file23,
6325
+ L: 41,
6326
+ S: void 0,
6327
+ C: (f, a) => f(...a)
6328
+ });
6329
+ }
6330
+ {
6331
+ log20.info("begin exporting kv pairs", void 0, {
6332
+ F: __dxlog_file23,
6333
+ L: 45,
6334
+ S: void 0,
6335
+ C: (f, a) => f(...a)
6336
+ });
6337
+ const iter = await level.iterator({
6338
+ keyEncoding: "binary",
6339
+ valueEncoding: "binary"
6340
+ });
6341
+ let count = 0;
6342
+ for await (const [key, value] of iter) {
6343
+ archive.storage.push({
6344
+ type: ProfileArchiveEntryType.KEY_VALUE,
6345
+ key,
6346
+ value
6347
+ });
6348
+ count++;
6349
+ }
6350
+ log20.info("done exporting kv pairs", {
6351
+ count
6352
+ }, {
6353
+ F: __dxlog_file23,
6354
+ L: 56,
6355
+ S: void 0,
6356
+ C: (f, a) => f(...a)
6357
+ });
6358
+ }
6359
+ return archive;
6360
+ };
6361
+ var importProfileData = async ({ storage, level }, archive) => {
6362
+ const batch = level.batch();
6363
+ for (const entry2 of archive.storage) {
6364
+ switch (entry2.type) {
6365
+ case ProfileArchiveEntryType.FILE: {
6366
+ const directory = await storage.createDirectory();
6367
+ invariant17(typeof entry2.key === "string", "Invalid key type", {
6368
+ F: __dxlog_file23,
6369
+ L: 78,
6370
+ S: void 0,
6371
+ A: [
6372
+ "typeof entry.key === 'string'",
6373
+ "'Invalid key type'"
6374
+ ]
6375
+ });
6376
+ const file = await directory.getOrCreateFile(entry2.key);
6377
+ invariant17(entry2.value instanceof Uint8Array, "Invalid value type", {
6378
+ F: __dxlog_file23,
6379
+ L: 80,
6380
+ S: void 0,
6381
+ A: [
6382
+ "entry.value instanceof Uint8Array",
6383
+ "'Invalid value type'"
6384
+ ]
6385
+ });
6386
+ await file.write(0, arrayToBuffer(entry2.value));
6387
+ await file.close();
6388
+ break;
6389
+ }
6390
+ case ProfileArchiveEntryType.KEY_VALUE: {
6391
+ invariant17(entry2.key instanceof Uint8Array, "Invalid key type", {
6392
+ F: __dxlog_file23,
6393
+ L: 86,
6394
+ S: void 0,
6395
+ A: [
6396
+ "entry.key instanceof Uint8Array",
6397
+ "'Invalid key type'"
6398
+ ]
6399
+ });
6400
+ invariant17(entry2.value instanceof Uint8Array, "Invalid value type", {
6401
+ F: __dxlog_file23,
6402
+ L: 87,
6403
+ S: void 0,
6404
+ A: [
6405
+ "entry.value instanceof Uint8Array",
6406
+ "'Invalid value type'"
6407
+ ]
6408
+ });
6409
+ batch.put(entry2.key, entry2.value, {
6410
+ keyEncoding: "binary",
6411
+ valueEncoding: "binary"
6412
+ });
6413
+ break;
6414
+ }
6415
+ default:
6416
+ throw new Error(`Invalid entry type: ${entry2.type}`);
6417
+ }
6418
+ }
6419
+ await batch.write();
6420
+ };
6421
+
6270
6422
  // packages/sdk/client-services/src/packlets/services/service-host.ts
6271
6423
  import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
6272
6424
  import { clientServiceBundle } from "@dxos/client-protocol";
6273
6425
  import { Context as Context11 } from "@dxos/context";
6274
- import { invariant as invariant18 } from "@dxos/invariant";
6426
+ import { invariant as invariant19 } from "@dxos/invariant";
6275
6427
  import { PublicKey as PublicKey17 } from "@dxos/keys";
6276
- import { log as log21 } from "@dxos/log";
6428
+ import { log as log22 } from "@dxos/log";
6277
6429
  import { WebsocketSignalManager } from "@dxos/messaging";
6278
6430
  import { SwarmNetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
6279
6431
  import { trace as trace10 } from "@dxos/protocols";
@@ -6284,9 +6436,9 @@ import { WebsocketRpcClient } from "@dxos/websocket-rpc";
6284
6436
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
6285
6437
  import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
6286
6438
  import { Stream as Stream11 } from "@dxos/codec-protobuf";
6287
- import { invariant as invariant17 } from "@dxos/invariant";
6439
+ import { invariant as invariant18 } from "@dxos/invariant";
6288
6440
  import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
6289
- var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
6441
+ var __dxlog_file24 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
6290
6442
  var DevicesServiceImpl = class {
6291
6443
  constructor(_identityManager) {
6292
6444
  this._identityManager = _identityManager;
@@ -6303,8 +6455,8 @@ var DevicesServiceImpl = class {
6303
6455
  devices: []
6304
6456
  });
6305
6457
  } else {
6306
- invariant17(this._identityManager.identity?.presence, "presence not present", {
6307
- F: __dxlog_file23,
6458
+ invariant18(this._identityManager.identity?.presence, "presence not present", {
6459
+ F: __dxlog_file24,
6308
6460
  L: 32,
6309
6461
  S: this,
6310
6462
  A: [
@@ -6497,7 +6649,7 @@ var ContactsServiceImpl = class {
6497
6649
  import { Event as Event8 } from "@dxos/async";
6498
6650
  import { Stream as Stream13 } from "@dxos/codec-protobuf";
6499
6651
  import { PublicKey as PublicKey16 } from "@dxos/keys";
6500
- import { getContextFromEntry, log as log20 } from "@dxos/log";
6652
+ import { getContextFromEntry, log as log21 } from "@dxos/log";
6501
6653
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
6502
6654
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
6503
6655
  var LoggingServiceImpl = class {
@@ -6510,11 +6662,11 @@ var LoggingServiceImpl = class {
6510
6662
  };
6511
6663
  }
6512
6664
  async open() {
6513
- log20.runtimeConfig.processors.push(this._logProcessor);
6665
+ log21.runtimeConfig.processors.push(this._logProcessor);
6514
6666
  }
6515
6667
  async close() {
6516
- const index = log20.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
6517
- log20.runtimeConfig.processors.splice(index, 1);
6668
+ const index = log21.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
6669
+ log21.runtimeConfig.processors.splice(index, 1);
6518
6670
  }
6519
6671
  async controlMetrics({ reset, record }) {
6520
6672
  if (reset) {
@@ -6718,7 +6870,7 @@ function _ts_decorate8(decorators, target, key, desc) {
6718
6870
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6719
6871
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6720
6872
  }
6721
- var __dxlog_file24 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6873
+ var __dxlog_file25 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6722
6874
  var ClientServicesHost = class {
6723
6875
  constructor({
6724
6876
  config,
@@ -6752,7 +6904,7 @@ var ClientServicesHost = class {
6752
6904
  onAcquire: () => {
6753
6905
  if (!this._opening) {
6754
6906
  void this.open(new Context11(void 0, {
6755
- F: __dxlog_file24,
6907
+ F: __dxlog_file25,
6756
6908
  L: 121
6757
6909
  }));
6758
6910
  }
@@ -6809,8 +6961,8 @@ var ClientServicesHost = class {
6809
6961
  * Can only be called once.
6810
6962
  */
6811
6963
  initialize({ config, ...options }) {
6812
- invariant18(!this._open, "service host is open", {
6813
- F: __dxlog_file24,
6964
+ invariant19(!this._open, "service host is open", {
6965
+ F: __dxlog_file25,
6814
6966
  L: 187,
6815
6967
  S: this,
6816
6968
  A: [
@@ -6818,15 +6970,15 @@ var ClientServicesHost = class {
6818
6970
  "'service host is open'"
6819
6971
  ]
6820
6972
  });
6821
- log21("initializing...", void 0, {
6822
- F: __dxlog_file24,
6973
+ log22("initializing...", void 0, {
6974
+ F: __dxlog_file25,
6823
6975
  L: 188,
6824
6976
  S: this,
6825
6977
  C: (f, a) => f(...a)
6826
6978
  });
6827
6979
  if (config) {
6828
- invariant18(!this._config, "config already set", {
6829
- F: __dxlog_file24,
6980
+ invariant19(!this._config, "config already set", {
6981
+ F: __dxlog_file25,
6830
6982
  L: 191,
6831
6983
  S: this,
6832
6984
  A: [
@@ -6840,8 +6992,8 @@ var ClientServicesHost = class {
6840
6992
  }
6841
6993
  }
6842
6994
  if (!options.signalManager) {
6843
- log21.warn("running signaling without telemetry metadata.", void 0, {
6844
- F: __dxlog_file24,
6995
+ log22.warn("running signaling without telemetry metadata.", void 0, {
6996
+ F: __dxlog_file25,
6845
6997
  L: 199,
6846
6998
  S: this,
6847
6999
  C: (f, a) => f(...a)
@@ -6851,8 +7003,8 @@ var ClientServicesHost = class {
6851
7003
  iceServers: this._config?.get("runtime.services.ice")
6852
7004
  }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
6853
7005
  this._signalManager = signalManager;
6854
- invariant18(!this._networkManager, "network manager already set", {
6855
- F: __dxlog_file24,
7006
+ invariant19(!this._networkManager, "network manager already set", {
7007
+ F: __dxlog_file25,
6856
7008
  L: 210,
6857
7009
  S: this,
6858
7010
  A: [
@@ -6865,8 +7017,8 @@ var ClientServicesHost = class {
6865
7017
  transportFactory,
6866
7018
  signalManager
6867
7019
  });
6868
- log21("initialized", void 0, {
6869
- F: __dxlog_file24,
7020
+ log22("initialized", void 0, {
7021
+ F: __dxlog_file25,
6870
7022
  L: 217,
6871
7023
  S: this,
6872
7024
  C: (f, a) => f(...a)
@@ -6877,16 +7029,16 @@ var ClientServicesHost = class {
6877
7029
  return;
6878
7030
  }
6879
7031
  const traceId = PublicKey17.random().toHex();
6880
- log21.trace("dxos.client-services.host.open", trace10.begin({
7032
+ log22.trace("dxos.client-services.host.open", trace10.begin({
6881
7033
  id: traceId
6882
7034
  }), {
6883
- F: __dxlog_file24,
7035
+ F: __dxlog_file25,
6884
7036
  L: 228,
6885
7037
  S: this,
6886
7038
  C: (f, a) => f(...a)
6887
7039
  });
6888
- invariant18(this._config, "config not set", {
6889
- F: __dxlog_file24,
7040
+ invariant19(this._config, "config not set", {
7041
+ F: __dxlog_file25,
6890
7042
  L: 230,
6891
7043
  S: this,
6892
7044
  A: [
@@ -6894,8 +7046,8 @@ var ClientServicesHost = class {
6894
7046
  "'config not set'"
6895
7047
  ]
6896
7048
  });
6897
- invariant18(this._storage, "storage not set", {
6898
- F: __dxlog_file24,
7049
+ invariant19(this._storage, "storage not set", {
7050
+ F: __dxlog_file25,
6899
7051
  L: 231,
6900
7052
  S: this,
6901
7053
  A: [
@@ -6903,8 +7055,8 @@ var ClientServicesHost = class {
6903
7055
  "'storage not set'"
6904
7056
  ]
6905
7057
  });
6906
- invariant18(this._signalManager, "signal manager not set", {
6907
- F: __dxlog_file24,
7058
+ invariant19(this._signalManager, "signal manager not set", {
7059
+ F: __dxlog_file25,
6908
7060
  L: 232,
6909
7061
  S: this,
6910
7062
  A: [
@@ -6912,8 +7064,8 @@ var ClientServicesHost = class {
6912
7064
  "'signal manager not set'"
6913
7065
  ]
6914
7066
  });
6915
- invariant18(this._networkManager, "network manager not set", {
6916
- F: __dxlog_file24,
7067
+ invariant19(this._networkManager, "network manager not set", {
7068
+ F: __dxlog_file25,
6917
7069
  L: 233,
6918
7070
  S: this,
6919
7071
  A: [
@@ -6922,10 +7074,10 @@ var ClientServicesHost = class {
6922
7074
  ]
6923
7075
  });
6924
7076
  this._opening = true;
6925
- log21("opening...", {
7077
+ log22("opening...", {
6926
7078
  lockKey: this._resourceLock?.lockKey
6927
7079
  }, {
6928
- F: __dxlog_file24,
7080
+ F: __dxlog_file25,
6929
7081
  L: 236,
6930
7082
  S: this,
6931
7083
  C: (f, a) => f(...a)
@@ -6978,18 +7130,18 @@ var ClientServicesHost = class {
6978
7130
  this._open = true;
6979
7131
  this._statusUpdate.emit();
6980
7132
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6981
- log21("opened", {
7133
+ log22("opened", {
6982
7134
  deviceKey
6983
7135
  }, {
6984
- F: __dxlog_file24,
7136
+ F: __dxlog_file25,
6985
7137
  L: 322,
6986
7138
  S: this,
6987
7139
  C: (f, a) => f(...a)
6988
7140
  });
6989
- log21.trace("dxos.client-services.host.open", trace10.end({
7141
+ log22.trace("dxos.client-services.host.open", trace10.end({
6990
7142
  id: traceId
6991
7143
  }), {
6992
- F: __dxlog_file24,
7144
+ F: __dxlog_file25,
6993
7145
  L: 323,
6994
7146
  S: this,
6995
7147
  C: (f, a) => f(...a)
@@ -7000,10 +7152,10 @@ var ClientServicesHost = class {
7000
7152
  return;
7001
7153
  }
7002
7154
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
7003
- log21("closing...", {
7155
+ log22("closing...", {
7004
7156
  deviceKey
7005
7157
  }, {
7006
- F: __dxlog_file24,
7158
+ F: __dxlog_file25,
7007
7159
  L: 334,
7008
7160
  S: this,
7009
7161
  C: (f, a) => f(...a)
@@ -7018,10 +7170,10 @@ var ClientServicesHost = class {
7018
7170
  await this._level?.close();
7019
7171
  this._open = false;
7020
7172
  this._statusUpdate.emit();
7021
- log21("closed", {
7173
+ log22("closed", {
7022
7174
  deviceKey
7023
7175
  }, {
7024
- F: __dxlog_file24,
7176
+ F: __dxlog_file25,
7025
7177
  L: 343,
7026
7178
  S: this,
7027
7179
  C: (f, a) => f(...a)
@@ -7029,32 +7181,32 @@ var ClientServicesHost = class {
7029
7181
  }
7030
7182
  async reset() {
7031
7183
  const traceId = PublicKey17.random().toHex();
7032
- log21.trace("dxos.sdk.client-services-host.reset", trace10.begin({
7184
+ log22.trace("dxos.sdk.client-services-host.reset", trace10.begin({
7033
7185
  id: traceId
7034
7186
  }), {
7035
- F: __dxlog_file24,
7187
+ F: __dxlog_file25,
7036
7188
  L: 348,
7037
7189
  S: this,
7038
7190
  C: (f, a) => f(...a)
7039
7191
  });
7040
- log21.info("resetting...", void 0, {
7041
- F: __dxlog_file24,
7192
+ log22.info("resetting...", void 0, {
7193
+ F: __dxlog_file25,
7042
7194
  L: 350,
7043
7195
  S: this,
7044
7196
  C: (f, a) => f(...a)
7045
7197
  });
7046
7198
  await this._serviceContext?.close();
7047
7199
  await this._storage.reset();
7048
- log21.info("reset", void 0, {
7049
- F: __dxlog_file24,
7200
+ log22.info("reset", void 0, {
7201
+ F: __dxlog_file25,
7050
7202
  L: 353,
7051
7203
  S: this,
7052
7204
  C: (f, a) => f(...a)
7053
7205
  });
7054
- log21.trace("dxos.sdk.client-services-host.reset", trace10.end({
7206
+ log22.trace("dxos.sdk.client-services-host.reset", trace10.end({
7055
7207
  id: traceId
7056
7208
  }), {
7057
- F: __dxlog_file24,
7209
+ F: __dxlog_file25,
7058
7210
  L: 354,
7059
7211
  S: this,
7060
7212
  C: (f, a) => f(...a)
@@ -7121,8 +7273,12 @@ export {
7121
7273
  isLocked,
7122
7274
  createStorageObjects,
7123
7275
  createLevel,
7276
+ encodeProfileArchive,
7277
+ decodeProfileArchive,
7278
+ exportProfileData,
7279
+ importProfileData,
7124
7280
  ClientServicesHost,
7125
7281
  ClientServicesProviderResource,
7126
7282
  DiagnosticsCollector
7127
7283
  };
7128
- //# sourceMappingURL=chunk-LFGNDWPO.mjs.map
7284
+ //# sourceMappingURL=chunk-CXKIPEH7.mjs.map