@dxos/client-services 0.1.50 → 0.1.51-main.04d9478

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.
@@ -969,8 +969,8 @@ var DeviceInvitationProtocol = class {
969
969
 
970
970
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
971
971
  import assert6 from "@dxos/node-std/assert";
972
- import { PushStream, scheduleTask as scheduleTask2, sleep, TimeoutError, Trigger as Trigger3 } from "@dxos/async";
973
- import { AuthenticatingInvitationObservable, AUTHENTICATION_CODE_LENGTH, CancellableInvitationObservable, INVITATION_TIMEOUT, ON_CLOSE_DELAY } from "@dxos/client-protocol";
972
+ import { PushStream, scheduleTask as scheduleTask2, TimeoutError, Trigger as Trigger3 } from "@dxos/async";
973
+ import { AuthenticatingInvitationObservable, AUTHENTICATION_CODE_LENGTH, CancellableInvitationObservable, INVITATION_TIMEOUT } from "@dxos/client-protocol";
974
974
  import { Context as Context4 } from "@dxos/context";
975
975
  import { generatePasscode } from "@dxos/credentials";
976
976
  import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2 } from "@dxos/errors";
@@ -1326,7 +1326,7 @@ var InvitationsHandler = class {
1326
1326
  ...protocol.toJSON()
1327
1327
  }, {
1328
1328
  file: "invitations-handler.ts",
1329
- line: 100,
1329
+ line: 99,
1330
1330
  scope: this,
1331
1331
  callSite: (f, a) => f(...a)
1332
1332
  });
@@ -1367,7 +1367,7 @@ var InvitationsHandler = class {
1367
1367
  id: traceId
1368
1368
  }), {
1369
1369
  file: "invitations-handler.ts",
1370
- line: 139,
1370
+ line: 138,
1371
1371
  scope: this,
1372
1372
  callSite: (f, a) => f(...a)
1373
1373
  });
@@ -1375,7 +1375,7 @@ var InvitationsHandler = class {
1375
1375
  ...protocol.toJSON()
1376
1376
  }, {
1377
1377
  file: "invitations-handler.ts",
1378
- line: 140,
1378
+ line: 139,
1379
1379
  scope: this,
1380
1380
  callSite: (f, a) => f(...a)
1381
1381
  });
@@ -1391,7 +1391,7 @@ var InvitationsHandler = class {
1391
1391
  ...protocol.toJSON()
1392
1392
  }, {
1393
1393
  file: "invitations-handler.ts",
1394
- line: 143,
1394
+ line: 142,
1395
1395
  scope: this,
1396
1396
  callSite: (f, a) => f(...a)
1397
1397
  });
@@ -1403,7 +1403,7 @@ var InvitationsHandler = class {
1403
1403
  id: traceId
1404
1404
  }), {
1405
1405
  file: "invitations-handler.ts",
1406
- line: 145,
1406
+ line: 144,
1407
1407
  scope: this,
1408
1408
  callSite: (f, a) => f(...a)
1409
1409
  });
@@ -1413,7 +1413,7 @@ var InvitationsHandler = class {
1413
1413
  ...protocol.toJSON()
1414
1414
  }, {
1415
1415
  file: "invitations-handler.ts",
1416
- line: 148,
1416
+ line: 147,
1417
1417
  scope: this,
1418
1418
  callSite: (f, a) => f(...a)
1419
1419
  });
@@ -1424,7 +1424,7 @@ var InvitationsHandler = class {
1424
1424
  } else {
1425
1425
  log5.error("failed", err, {
1426
1426
  file: "invitations-handler.ts",
1427
- line: 151,
1427
+ line: 150,
1428
1428
  scope: this,
1429
1429
  callSite: (f, a) => f(...a)
1430
1430
  });
@@ -1435,13 +1435,13 @@ var InvitationsHandler = class {
1435
1435
  error: err
1436
1436
  }), {
1437
1437
  file: "invitations-handler.ts",
1438
- line: 154,
1438
+ line: 153,
1439
1439
  scope: this,
1440
1440
  callSite: (f, a) => f(...a)
1441
1441
  });
1442
1442
  } finally {
1443
1443
  if (type !== Invitation3.Type.MULTIUSE) {
1444
- await sleep(ON_CLOSE_DELAY);
1444
+ await swarmConnection.close();
1445
1445
  await ctx.dispose();
1446
1446
  }
1447
1447
  }
@@ -1477,9 +1477,10 @@ var InvitationsHandler = class {
1477
1477
  });
1478
1478
  return extension;
1479
1479
  };
1480
+ let swarmConnection;
1480
1481
  scheduleTask2(ctx, async () => {
1481
1482
  const topic = invitation.swarmKey;
1482
- const swarmConnection = await this._networkManager.joinSwarm({
1483
+ swarmConnection = await this._networkManager.joinSwarm({
1483
1484
  topic,
1484
1485
  peerId: topic,
1485
1486
  protocolProvider: createTeleportProtocolFactory(async (teleport) => {
@@ -1510,6 +1511,7 @@ var InvitationsHandler = class {
1510
1511
  const { timeout = INVITATION_TIMEOUT } = invitation;
1511
1512
  assert6(protocol);
1512
1513
  const authenticated = new Trigger3();
1514
+ let admitted = false;
1513
1515
  let currentState;
1514
1516
  const stream = new PushStream();
1515
1517
  const setState = (newData) => {
@@ -1527,7 +1529,7 @@ var InvitationsHandler = class {
1527
1529
  ...protocol.toJSON()
1528
1530
  }, {
1529
1531
  file: "invitations-handler.ts",
1530
- line: 225,
1532
+ line: 230,
1531
1533
  scope: this,
1532
1534
  callSite: (f, a) => f(...a)
1533
1535
  });
@@ -1537,7 +1539,7 @@ var InvitationsHandler = class {
1537
1539
  } else {
1538
1540
  log5.warn("auth failed", err, {
1539
1541
  file: "invitations-handler.ts",
1540
- line: 228,
1542
+ line: 233,
1541
1543
  scope: this,
1542
1544
  callSite: (f, a) => f(...a)
1543
1545
  });
@@ -1551,7 +1553,7 @@ var InvitationsHandler = class {
1551
1553
  ...protocol.toJSON()
1552
1554
  }, {
1553
1555
  file: "invitations-handler.ts",
1554
- line: 236,
1556
+ line: 241,
1555
1557
  scope: this,
1556
1558
  callSite: (f, a) => f(...a)
1557
1559
  });
@@ -1566,11 +1568,11 @@ var InvitationsHandler = class {
1566
1568
  currentState
1567
1569
  }, {
1568
1570
  file: "invitations-handler.ts",
1569
- line: 246,
1571
+ line: 251,
1570
1572
  scope: this,
1571
1573
  callSite: (f, a) => f(...a)
1572
1574
  });
1573
- if (currentState !== Invitation3.State.SUCCESS) {
1575
+ if (!admitted) {
1574
1576
  stream.error(new Error("Remote peer disconnected."));
1575
1577
  }
1576
1578
  });
@@ -1581,7 +1583,7 @@ var InvitationsHandler = class {
1581
1583
  id: traceId
1582
1584
  }), {
1583
1585
  file: "invitations-handler.ts",
1584
- line: 255,
1586
+ line: 260,
1585
1587
  scope: this,
1586
1588
  callSite: (f, a) => f(...a)
1587
1589
  });
@@ -1593,7 +1595,7 @@ var InvitationsHandler = class {
1593
1595
  ...protocol.toJSON()
1594
1596
  }, {
1595
1597
  file: "invitations-handler.ts",
1596
- line: 263,
1598
+ line: 268,
1597
1599
  scope: this,
1598
1600
  callSite: (f, a) => f(...a)
1599
1601
  });
@@ -1604,7 +1606,7 @@ var InvitationsHandler = class {
1604
1606
  ...protocol.toJSON()
1605
1607
  }, {
1606
1608
  file: "invitations-handler.ts",
1607
- line: 267,
1609
+ line: 272,
1608
1610
  scope: this,
1609
1611
  callSite: (f, a) => f(...a)
1610
1612
  });
@@ -1614,7 +1616,7 @@ var InvitationsHandler = class {
1614
1616
  response: introductionResponse
1615
1617
  }, {
1616
1618
  file: "invitations-handler.ts",
1617
- line: 271,
1619
+ line: 276,
1618
1620
  scope: this,
1619
1621
  callSite: (f, a) => f(...a)
1620
1622
  });
@@ -1626,7 +1628,7 @@ var InvitationsHandler = class {
1626
1628
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
1627
1629
  log5("guest waiting for authentication code...", {}, {
1628
1630
  file: "invitations-handler.ts",
1629
- line: 280,
1631
+ line: 285,
1630
1632
  scope: this,
1631
1633
  callSite: (f, a) => f(...a)
1632
1634
  });
@@ -1638,7 +1640,7 @@ var InvitationsHandler = class {
1638
1640
  });
1639
1641
  log5("sending authentication request", {}, {
1640
1642
  file: "invitations-handler.ts",
1641
- line: 284,
1643
+ line: 289,
1642
1644
  scope: this,
1643
1645
  callSite: (f, a) => f(...a)
1644
1646
  });
@@ -1659,7 +1661,7 @@ var InvitationsHandler = class {
1659
1661
  attempt
1660
1662
  }, {
1661
1663
  file: "invitations-handler.ts",
1662
- line: 295,
1664
+ line: 300,
1663
1665
  scope: this,
1664
1666
  callSite: (f, a) => f(...a)
1665
1667
  });
@@ -1676,18 +1678,19 @@ var InvitationsHandler = class {
1676
1678
  ...protocol.toJSON()
1677
1679
  }, {
1678
1680
  file: "invitations-handler.ts",
1679
- line: 306,
1681
+ line: 311,
1680
1682
  scope: this,
1681
1683
  callSite: (f, a) => f(...a)
1682
1684
  });
1683
1685
  const admissionRequest = await protocol.createAdmissionRequest();
1684
1686
  const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
1687
+ admitted = true;
1685
1688
  const result = await protocol.accept(admissionResponse, admissionRequest);
1686
1689
  log5("admitted by host", {
1687
1690
  ...protocol.toJSON()
1688
1691
  }, {
1689
1692
  file: "invitations-handler.ts",
1690
- line: 314,
1693
+ line: 322,
1691
1694
  scope: this,
1692
1695
  callSite: (f, a) => f(...a)
1693
1696
  });
@@ -1699,7 +1702,7 @@ var InvitationsHandler = class {
1699
1702
  id: traceId
1700
1703
  }), {
1701
1704
  file: "invitations-handler.ts",
1702
- line: 316,
1705
+ line: 324,
1703
1706
  scope: this,
1704
1707
  callSite: (f, a) => f(...a)
1705
1708
  });
@@ -1709,7 +1712,7 @@ var InvitationsHandler = class {
1709
1712
  ...protocol.toJSON()
1710
1713
  }, {
1711
1714
  file: "invitations-handler.ts",
1712
- line: 319,
1715
+ line: 327,
1713
1716
  scope: this,
1714
1717
  callSite: (f, a) => f(...a)
1715
1718
  });
@@ -1719,7 +1722,7 @@ var InvitationsHandler = class {
1719
1722
  } else {
1720
1723
  log5("auth failed", err, {
1721
1724
  file: "invitations-handler.ts",
1722
- line: 322,
1725
+ line: 330,
1723
1726
  scope: this,
1724
1727
  callSite: (f, a) => f(...a)
1725
1728
  });
@@ -1730,7 +1733,7 @@ var InvitationsHandler = class {
1730
1733
  error: err
1731
1734
  }), {
1732
1735
  file: "invitations-handler.ts",
1733
- line: 325,
1736
+ line: 333,
1734
1737
  scope: this,
1735
1738
  callSite: (f, a) => f(...a)
1736
1739
  });
@@ -1748,7 +1751,7 @@ var InvitationsHandler = class {
1748
1751
  ...protocol.toJSON()
1749
1752
  }, {
1750
1753
  file: "invitations-handler.ts",
1751
- line: 336,
1754
+ line: 344,
1752
1755
  scope: this,
1753
1756
  callSite: (f, a) => f(...a)
1754
1757
  });
@@ -1758,7 +1761,7 @@ var InvitationsHandler = class {
1758
1761
  } else {
1759
1762
  log5("auth failed", err, {
1760
1763
  file: "invitations-handler.ts",
1761
- line: 339,
1764
+ line: 347,
1762
1765
  scope: this,
1763
1766
  callSite: (f, a) => f(...a)
1764
1767
  });
@@ -2195,11 +2198,12 @@ import { PublicKey as PublicKey7 } from "@dxos/keys";
2195
2198
  import { log as log10 } from "@dxos/log";
2196
2199
  import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
2197
2200
  import { AdmittedFeed as AdmittedFeed3 } from "@dxos/protocols/proto/dxos/halo/credentials";
2201
+ import { Timeframe } from "@dxos/timeframe";
2198
2202
  import { ComplexSet as ComplexSet2 } from "@dxos/util";
2199
2203
 
2200
2204
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2201
2205
  import assert9 from "@dxos/node-std/assert";
2202
- import { DeferredTask, Event as Event4, scheduleTask as scheduleTask3, sleep as sleep2, TimeoutError as TimeoutError2, Trigger as Trigger5 } from "@dxos/async";
2206
+ import { DeferredTask, Event as Event4, scheduleTask as scheduleTask3, sleep, TimeoutError as TimeoutError2, Trigger as Trigger5 } from "@dxos/async";
2203
2207
  import { Context as Context5, rejectOnDispose } from "@dxos/context";
2204
2208
  import { PublicKey as PublicKey6 } from "@dxos/keys";
2205
2209
  import { log as log9 } from "@dxos/log";
@@ -2309,7 +2313,7 @@ var NotarizationPlugin = class {
2309
2313
  scope: this,
2310
2314
  callSite: (f, a) => f(...a)
2311
2315
  });
2312
- await sleep2(successDelay);
2316
+ await sleep(successDelay);
2313
2317
  } catch (err) {
2314
2318
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
2315
2319
  log9.warn("error notarizing (recoverable)", err, {
@@ -2537,7 +2541,7 @@ var DataSpace = class DataSpace2 {
2537
2541
  if (err instanceof CancelledError) {
2538
2542
  log10("Data pipeline initialization cancelled", err, {
2539
2543
  file: "data-space.ts",
2540
- line: 172,
2544
+ line: 173,
2541
2545
  scope: this,
2542
2546
  callSite: (f, a) => f(...a)
2543
2547
  });
@@ -2545,7 +2549,7 @@ var DataSpace = class DataSpace2 {
2545
2549
  }
2546
2550
  log10.error("Error initializing data pipeline", err, {
2547
2551
  file: "data-space.ts",
2548
- line: 176,
2552
+ line: 177,
2549
2553
  scope: this,
2550
2554
  callSite: (f, a) => f(...a)
2551
2555
  });
@@ -2652,7 +2656,7 @@ var DataSpace = class DataSpace2 {
2652
2656
  async createEpoch() {
2653
2657
  var _a, _b;
2654
2658
  const epoch = await this.dataPipeline.createEpoch();
2655
- await this.inner.controlPipeline.writer.write({
2659
+ const receipt = await this.inner.controlPipeline.writer.write({
2656
2660
  credential: {
2657
2661
  credential: await this._signingContext.credentialSigner.createCredential({
2658
2662
  subject: this.key,
@@ -2663,6 +2667,12 @@ var DataSpace = class DataSpace2 {
2663
2667
  })
2664
2668
  }
2665
2669
  });
2670
+ await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe([
2671
+ [
2672
+ receipt.feedKey,
2673
+ receipt.seq
2674
+ ]
2675
+ ]));
2666
2676
  for (const feed of (_b = (_a = this.inner.dataPipeline.pipelineState) == null ? void 0 : _a.feeds) != null ? _b : []) {
2667
2677
  const indexBeforeEpoch = epoch.timeframe.get(feed.key);
2668
2678
  if (indexBeforeEpoch) {
@@ -2694,7 +2704,7 @@ import { ComplexMap as ComplexMap3, deferFunction as deferFunction2 } from "@dxo
2694
2704
  import { createCredential } from "@dxos/credentials";
2695
2705
  import { failUndefined as failUndefined2 } from "@dxos/debug";
2696
2706
  import { AdmittedFeed as AdmittedFeed4, SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
2697
- import { Timeframe } from "@dxos/timeframe";
2707
+ import { Timeframe as Timeframe2 } from "@dxos/timeframe";
2698
2708
  var spaceGenesis = async (keyring, signingContext, space) => {
2699
2709
  var _a, _b, _c, _d;
2700
2710
  const credentials = [
@@ -2745,7 +2755,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
2745
2755
  "@type": "dxos.halo.credentials.Epoch",
2746
2756
  number: 0,
2747
2757
  previousId: void 0,
2748
- timeframe: new Timeframe(),
2758
+ timeframe: new Timeframe2(),
2749
2759
  snapshotCid: void 0
2750
2760
  }
2751
2761
  })
@@ -3079,7 +3089,7 @@ var SpacesServiceImpl = class {
3079
3089
  spaces
3080
3090
  }, {
3081
3091
  file: "spaces-service.ts",
3082
- line: 59,
3092
+ line: 60,
3083
3093
  scope: this,
3084
3094
  callSite: (f, a) => f(...a)
3085
3095
  });
@@ -3166,12 +3176,13 @@ var SpacesServiceImpl = class {
3166
3176
  await space.createEpoch();
3167
3177
  }
3168
3178
  _transformSpace(space) {
3169
- var _a, _b, _c, _d, _e;
3179
+ var _a, _b, _c, _d, _e, _f;
3170
3180
  return {
3171
3181
  spaceKey: space.key,
3172
3182
  state: space.state,
3173
3183
  error: space.error ? encodeError(space.error) : void 0,
3174
3184
  pipeline: {
3185
+ currentEpoch: space.dataPipeline.currentEpoch,
3175
3186
  controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
3176
3187
  currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
3177
3188
  targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
@@ -3193,6 +3204,7 @@ var SpacesServiceImpl = class {
3193
3204
  presence: ((_c2 = this._identityManager.identity) == null ? void 0 : _c2.identityKey.equals(member.key)) || space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember2.PresenceState.ONLINE : SpaceMember2.PresenceState.OFFLINE
3194
3205
  };
3195
3206
  }),
3207
+ creator: (_f = space.inner.spaceState.creator) == null ? void 0 : _f.key,
3196
3208
  cache: space.cache,
3197
3209
  metrics: space.metrics
3198
3210
  };
@@ -3554,7 +3566,8 @@ var DevicesServiceImpl = class {
3554
3566
  // packages/sdk/client-services/src/packlets/logging/logging-service.ts
3555
3567
  import { Event as Event7 } from "@dxos/async";
3556
3568
  import { Stream as Stream11 } from "@dxos/codec-protobuf";
3557
- import { log as log14, shouldLog, getContextFromEntry } from "@dxos/log";
3569
+ import { getContextFromEntry, log as log14 } from "@dxos/log";
3570
+ import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
3558
3571
  import { jsonify } from "@dxos/util";
3559
3572
  var LoggingServiceImpl = class {
3560
3573
  constructor() {
@@ -3571,31 +3584,60 @@ var LoggingServiceImpl = class {
3571
3584
  log14.runtimeConfig.processors.splice(index, 1);
3572
3585
  }
3573
3586
  queryLogs(request) {
3574
- var _a;
3575
- const filters = ((_a = request.filters) == null ? void 0 : _a.length) ? request.filters : void 0;
3576
3587
  return new Stream11(({ ctx, next }) => {
3577
3588
  const handler = (entry2) => {
3578
- var _a2, _b, _c;
3579
- if (((_a2 = entry2.meta) == null ? void 0 : _a2.file.includes("logging-service")) || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
3589
+ var _a, _b, _c, _d, _e;
3590
+ if (LOG_PROCESSING > 0) {
3580
3591
  return;
3581
3592
  }
3582
- if (shouldLog(entry2, filters)) {
3583
- const record = {
3584
- ...entry2,
3585
- context: jsonify(getContextFromEntry(entry2))
3586
- };
3587
- (_b = record.meta) == null ? true : delete _b.bugcheck;
3588
- (_c = record.meta) == null ? true : delete _c.scope;
3593
+ if (((_a = entry2.meta) == null ? void 0 : _a.file.includes("logging-service")) || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
3594
+ return;
3595
+ }
3596
+ if (!shouldLog(entry2, request)) {
3597
+ return;
3598
+ }
3599
+ const record = {
3600
+ ...entry2,
3601
+ context: jsonify(getContextFromEntry(entry2)),
3602
+ timestamp: new Date(),
3603
+ meta: {
3604
+ // TODO(dmaretskyi): Fix proto.
3605
+ file: (_c = (_b = entry2.meta) == null ? void 0 : _b.file) != null ? _c : "",
3606
+ line: (_e = (_d = entry2.meta) == null ? void 0 : _d.line) != null ? _e : 0
3607
+ }
3608
+ };
3609
+ try {
3610
+ LOG_PROCESSING++;
3589
3611
  next(record);
3612
+ } finally {
3613
+ LOG_PROCESSING--;
3590
3614
  }
3591
3615
  };
3592
- ctx.onDispose(() => {
3593
- this._logs.off(handler);
3594
- });
3595
- this._logs.on(handler);
3616
+ this._logs.on(ctx, handler);
3617
+ });
3618
+ }
3619
+ };
3620
+ var matchFilter = (filter, level, path, options) => {
3621
+ switch (options) {
3622
+ case QueryLogsRequest.MatchingOptions.INCLUSIVE:
3623
+ return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
3624
+ case QueryLogsRequest.MatchingOptions.EXPLICIT:
3625
+ return level === filter.level && (!filter.pattern || path.includes(filter.pattern));
3626
+ }
3627
+ };
3628
+ var shouldLog = (entry2, request) => {
3629
+ var _a;
3630
+ const options = (_a = request.options) != null ? _a : QueryLogsRequest.MatchingOptions.INCLUSIVE;
3631
+ if (request.filters === void 0) {
3632
+ return options === QueryLogsRequest.MatchingOptions.INCLUSIVE;
3633
+ } else {
3634
+ return request.filters.some((filter) => {
3635
+ var _a2, _b;
3636
+ return matchFilter(filter, entry2.level, (_b = (_a2 = entry2.meta) == null ? void 0 : _a2.file) != null ? _b : "", options);
3596
3637
  });
3597
3638
  }
3598
3639
  };
3640
+ var LOG_PROCESSING = 0;
3599
3641
 
3600
3642
  // packages/sdk/client-services/src/packlets/network/network-service.ts
3601
3643
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
@@ -3952,4 +3994,4 @@ export {
3952
3994
  ClientServicesHost,
3953
3995
  LocalClientServices
3954
3996
  };
3955
- //# sourceMappingURL=chunk-BAHSFG33.mjs.map
3997
+ //# sourceMappingURL=chunk-QUJROKKU.mjs.map