@dxos/client-services 0.5.9-main.b8d8fee → 0.5.9-main.bd9c8b3
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-2EFXBSRZ.mjs → chunk-KI7FY3ZO.mjs} +718 -555
- package/dist/lib/browser/chunk-KI7FY3ZO.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -3
- package/dist/lib/browser/index.mjs.map +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/testing/index.mjs +2 -3
- package/dist/lib/browser/packlets/testing/index.mjs.map +2 -2
- package/dist/lib/node/{chunk-2SS7JAIR.cjs → chunk-XWMOEZYI.cjs} +869 -709
- package/dist/lib/node/chunk-XWMOEZYI.cjs.map +7 -0
- package/dist/lib/node/index.cjs +41 -43
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/packlets/testing/index.cjs +9 -10
- package/dist/lib/node/packlets/testing/index.cjs.map +2 -2
- package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +4 -1
- package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +9 -9
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/epoch-migrations.d.ts +23 -0
- package/dist/types/src/packlets/spaces/epoch-migrations.d.ts.map +1 -0
- package/dist/types/src/packlets/spaces/spaces-service.d.ts +2 -2
- package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/version.d.ts +1 -1
- package/package.json +36 -36
- package/src/packlets/identity/identity-service.ts +33 -7
- package/src/packlets/services/service-context.ts +1 -4
- package/src/packlets/spaces/automerge-space-state.ts +11 -2
- package/src/packlets/spaces/data-space-manager.ts +35 -14
- package/src/packlets/spaces/data-space.ts +76 -148
- package/src/packlets/spaces/epoch-migrations.ts +135 -0
- package/src/packlets/spaces/spaces-service.ts +16 -4
- package/src/packlets/testing/test-builder.ts +1 -4
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-2EFXBSRZ.mjs.map +0 -7
- package/dist/lib/node/chunk-2SS7JAIR.cjs.map +0 -7
|
@@ -355,7 +355,7 @@ import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
|
|
|
355
355
|
import { TRACE_PROCESSOR } from "@dxos/tracing";
|
|
356
356
|
|
|
357
357
|
// packages/sdk/client-services/src/version.ts
|
|
358
|
-
var DXOS_VERSION = "0.5.9-main.
|
|
358
|
+
var DXOS_VERSION = "0.5.9-main.bd9c8b3";
|
|
359
359
|
|
|
360
360
|
// packages/sdk/client-services/src/packlets/services/platform.ts
|
|
361
361
|
import { Platform } from "@dxos/protocols/proto/dxos/client/services";
|
|
@@ -1519,13 +1519,17 @@ IdentityManager = _ts_decorate3([
|
|
|
1519
1519
|
], IdentityManager);
|
|
1520
1520
|
|
|
1521
1521
|
// packages/sdk/client-services/src/packlets/identity/identity-service.ts
|
|
1522
|
+
import { Trigger as Trigger3, sleep } from "@dxos/async";
|
|
1522
1523
|
import { Stream as Stream8 } from "@dxos/codec-protobuf";
|
|
1523
1524
|
import { Resource } from "@dxos/context";
|
|
1524
1525
|
import { signPresentation } from "@dxos/credentials";
|
|
1525
1526
|
import { todo } from "@dxos/debug";
|
|
1526
1527
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
1528
|
+
import { log as log6 } from "@dxos/log";
|
|
1527
1529
|
import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
|
|
1530
|
+
import { safeAwaitAll } from "@dxos/util";
|
|
1528
1531
|
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
|
|
1532
|
+
var DEFAULT_SPACE_SEARCH_TIMEOUT = 1e4;
|
|
1529
1533
|
var IdentityServiceImpl = class extends Resource {
|
|
1530
1534
|
constructor(_identityManager, _keyring, _dataSpaceManagerProvider, _createIdentity, _onProfileUpdate) {
|
|
1531
1535
|
super();
|
|
@@ -1555,7 +1559,7 @@ var IdentityServiceImpl = class extends Resource {
|
|
|
1555
1559
|
const identity = this._identityManager.identity;
|
|
1556
1560
|
invariant4(identity, void 0, {
|
|
1557
1561
|
F: __dxlog_file7,
|
|
1558
|
-
L:
|
|
1562
|
+
L: 59,
|
|
1559
1563
|
S: this,
|
|
1560
1564
|
A: [
|
|
1561
1565
|
"identity",
|
|
@@ -1589,7 +1593,7 @@ var IdentityServiceImpl = class extends Resource {
|
|
|
1589
1593
|
async updateProfile(profile) {
|
|
1590
1594
|
invariant4(this._identityManager.identity, "Identity not initialized.", {
|
|
1591
1595
|
F: __dxlog_file7,
|
|
1592
|
-
L:
|
|
1596
|
+
L: 89,
|
|
1593
1597
|
S: this,
|
|
1594
1598
|
A: [
|
|
1595
1599
|
"this._identityManager.identity",
|
|
@@ -1603,7 +1607,7 @@ var IdentityServiceImpl = class extends Resource {
|
|
|
1603
1607
|
async signPresentation({ presentation, nonce }) {
|
|
1604
1608
|
invariant4(this._identityManager.identity, "Identity not initialized.", {
|
|
1605
1609
|
F: __dxlog_file7,
|
|
1606
|
-
L:
|
|
1610
|
+
L: 96,
|
|
1607
1611
|
S: this,
|
|
1608
1612
|
A: [
|
|
1609
1613
|
"this._identityManager.identity",
|
|
@@ -1619,20 +1623,43 @@ var IdentityServiceImpl = class extends Resource {
|
|
|
1619
1623
|
});
|
|
1620
1624
|
}
|
|
1621
1625
|
async _fixIdentityWithoutDefaultSpace(identity) {
|
|
1622
|
-
let
|
|
1626
|
+
let recodedDefaultSpace = false;
|
|
1627
|
+
let foundDefaultSpace = false;
|
|
1623
1628
|
const dataSpaceManager = this._dataSpaceManagerProvider();
|
|
1624
|
-
|
|
1629
|
+
const recordedDefaultSpaceTrigger = new Trigger3();
|
|
1630
|
+
const allProcessed = safeAwaitAll(dataSpaceManager.spaces.values(), async (space) => {
|
|
1625
1631
|
if (space.state === SpaceState.CLOSED) {
|
|
1626
1632
|
await space.open();
|
|
1627
|
-
|
|
1633
|
+
const requiresMigration = space.stateUpdate.waitForCondition(() => space.state === SpaceState.REQUIRES_MIGRATION);
|
|
1634
|
+
await Promise.race([
|
|
1635
|
+
space.initializeDataPipeline(),
|
|
1636
|
+
requiresMigration
|
|
1637
|
+
]);
|
|
1628
1638
|
}
|
|
1629
1639
|
if (await dataSpaceManager.isDefaultSpace(space)) {
|
|
1640
|
+
if (foundDefaultSpace) {
|
|
1641
|
+
log6.warn("Multiple default spaces found. Using the first one.", {
|
|
1642
|
+
duplicate: space.id
|
|
1643
|
+
}, {
|
|
1644
|
+
F: __dxlog_file7,
|
|
1645
|
+
L: 127,
|
|
1646
|
+
S: this,
|
|
1647
|
+
C: (f, a) => f(...a)
|
|
1648
|
+
});
|
|
1649
|
+
return;
|
|
1650
|
+
}
|
|
1651
|
+
foundDefaultSpace = true;
|
|
1630
1652
|
await identity.updateDefaultSpace(space.id);
|
|
1631
|
-
|
|
1632
|
-
|
|
1653
|
+
recodedDefaultSpace = true;
|
|
1654
|
+
recordedDefaultSpaceTrigger.wake();
|
|
1633
1655
|
}
|
|
1634
|
-
}
|
|
1635
|
-
|
|
1656
|
+
});
|
|
1657
|
+
await Promise.race([
|
|
1658
|
+
allProcessed,
|
|
1659
|
+
recordedDefaultSpaceTrigger.wait(),
|
|
1660
|
+
sleep(DEFAULT_SPACE_SEARCH_TIMEOUT)
|
|
1661
|
+
]);
|
|
1662
|
+
if (!recodedDefaultSpace) {
|
|
1636
1663
|
await this._createDefaultSpace(dataSpaceManager);
|
|
1637
1664
|
}
|
|
1638
1665
|
}
|
|
@@ -1756,7 +1783,7 @@ import { ContextDisposedError as ContextDisposedError2 } from "@dxos/context";
|
|
|
1756
1783
|
import { createKeyPair, sign } from "@dxos/crypto";
|
|
1757
1784
|
import { invariant as invariant9 } from "@dxos/invariant";
|
|
1758
1785
|
import { PublicKey as PublicKey7 } from "@dxos/keys";
|
|
1759
|
-
import { log as
|
|
1786
|
+
import { log as log10 } from "@dxos/log";
|
|
1760
1787
|
import { createTeleportProtocolFactory } from "@dxos/network-manager";
|
|
1761
1788
|
import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError3, trace as trace5 } from "@dxos/protocols";
|
|
1762
1789
|
import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
|
|
@@ -1765,10 +1792,10 @@ import { Options as Options4 } from "@dxos/protocols/proto/dxos/halo/invitations
|
|
|
1765
1792
|
import { ComplexSet as ComplexSet3 } from "@dxos/util";
|
|
1766
1793
|
|
|
1767
1794
|
// packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts
|
|
1768
|
-
import { Trigger as
|
|
1795
|
+
import { Trigger as Trigger4 } from "@dxos/async";
|
|
1769
1796
|
import { cancelWithContext as cancelWithContext2, Context as Context4 } from "@dxos/context";
|
|
1770
1797
|
import { invariant as invariant6 } from "@dxos/invariant";
|
|
1771
|
-
import { log as
|
|
1798
|
+
import { log as log7 } from "@dxos/log";
|
|
1772
1799
|
import { InvalidInvitationExtensionRoleError, schema as schema2 } from "@dxos/protocols";
|
|
1773
1800
|
import { Options } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
1774
1801
|
import { RpcExtension } from "@dxos/teleport";
|
|
@@ -1808,7 +1835,7 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1808
1835
|
this._invitationFlowMutex = _invitationFlowMutex;
|
|
1809
1836
|
this._callbacks = _callbacks;
|
|
1810
1837
|
this._ctx = new Context4();
|
|
1811
|
-
this._remoteOptionsTrigger = new
|
|
1838
|
+
this._remoteOptionsTrigger = new Trigger4();
|
|
1812
1839
|
this._invitationFlowLock = null;
|
|
1813
1840
|
}
|
|
1814
1841
|
hasFlowLock() {
|
|
@@ -1845,14 +1872,14 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1845
1872
|
async onOpen(context) {
|
|
1846
1873
|
await super.onOpen(context);
|
|
1847
1874
|
try {
|
|
1848
|
-
|
|
1875
|
+
log7("guest acquire lock", void 0, {
|
|
1849
1876
|
F: __dxlog_file9,
|
|
1850
1877
|
L: 84,
|
|
1851
1878
|
S: this,
|
|
1852
1879
|
C: (f, a) => f(...a)
|
|
1853
1880
|
});
|
|
1854
1881
|
this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
|
|
1855
|
-
|
|
1882
|
+
log7("guest lock acquired", void 0, {
|
|
1856
1883
|
F: __dxlog_file9,
|
|
1857
1884
|
L: 86,
|
|
1858
1885
|
S: this,
|
|
@@ -1861,7 +1888,7 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1861
1888
|
await cancelWithContext2(this._ctx, this.rpc.InvitationHostService.options({
|
|
1862
1889
|
role: Options.Role.GUEST
|
|
1863
1890
|
}));
|
|
1864
|
-
|
|
1891
|
+
log7("options sent", void 0, {
|
|
1865
1892
|
F: __dxlog_file9,
|
|
1866
1893
|
L: 88,
|
|
1867
1894
|
S: this,
|
|
@@ -1870,7 +1897,7 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1870
1897
|
await cancelWithContext2(this._ctx, this._remoteOptionsTrigger.wait({
|
|
1871
1898
|
timeout: OPTIONS_TIMEOUT
|
|
1872
1899
|
}));
|
|
1873
|
-
|
|
1900
|
+
log7("options received", void 0, {
|
|
1874
1901
|
F: __dxlog_file9,
|
|
1875
1902
|
L: 90,
|
|
1876
1903
|
S: this,
|
|
@@ -1904,7 +1931,7 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1904
1931
|
if (this._invitationFlowLock != null) {
|
|
1905
1932
|
this._invitationFlowLock.release();
|
|
1906
1933
|
this._invitationFlowLock = null;
|
|
1907
|
-
|
|
1934
|
+
log7("invitation flow lock released", void 0, {
|
|
1908
1935
|
F: __dxlog_file9,
|
|
1909
1936
|
L: 123,
|
|
1910
1937
|
S: this,
|
|
@@ -1915,12 +1942,12 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1915
1942
|
};
|
|
1916
1943
|
|
|
1917
1944
|
// packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts
|
|
1918
|
-
import { Trigger as
|
|
1945
|
+
import { Trigger as Trigger5, scheduleTask as scheduleTask2 } from "@dxos/async";
|
|
1919
1946
|
import { cancelWithContext as cancelWithContext3, Context as Context5 } from "@dxos/context";
|
|
1920
1947
|
import { randomBytes, verify } from "@dxos/crypto";
|
|
1921
1948
|
import { invariant as invariant7, InvariantViolation } from "@dxos/invariant";
|
|
1922
1949
|
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
1923
|
-
import { log as
|
|
1950
|
+
import { log as log8 } from "@dxos/log";
|
|
1924
1951
|
import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2, schema as schema3, trace as trace4 } from "@dxos/protocols";
|
|
1925
1952
|
import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
|
|
1926
1953
|
import { AuthenticationResponse, Options as Options2 } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
@@ -1941,12 +1968,12 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1941
1968
|
this._invitationFlowMutex = _invitationFlowMutex;
|
|
1942
1969
|
this._callbacks = _callbacks;
|
|
1943
1970
|
this._ctx = new Context5();
|
|
1944
|
-
this._remoteOptionsTrigger = new
|
|
1971
|
+
this._remoteOptionsTrigger = new Trigger5();
|
|
1945
1972
|
this._challenge = void 0;
|
|
1946
1973
|
this.guestProfile = void 0;
|
|
1947
1974
|
this.authenticationPassed = false;
|
|
1948
1975
|
this.authenticationRetry = 0;
|
|
1949
|
-
this.completedTrigger = new
|
|
1976
|
+
this.completedTrigger = new Trigger5();
|
|
1950
1977
|
this._invitationFlowLock = null;
|
|
1951
1978
|
}
|
|
1952
1979
|
hasFlowLock() {
|
|
@@ -1973,7 +2000,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1973
2000
|
introduce: async (request) => {
|
|
1974
2001
|
const { profile, invitationId } = request;
|
|
1975
2002
|
const traceId = PublicKey5.random().toHex();
|
|
1976
|
-
|
|
2003
|
+
log8.trace("dxos.sdk.invitation-handler.host.introduce", trace4.begin({
|
|
1977
2004
|
id: traceId
|
|
1978
2005
|
}), {
|
|
1979
2006
|
F: __dxlog_file10,
|
|
@@ -1984,7 +2011,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1984
2011
|
const invitation = this._requireActiveInvitation();
|
|
1985
2012
|
this._assertInvitationState(Invitation3.State.CONNECTED);
|
|
1986
2013
|
if (invitationId !== invitation?.invitationId) {
|
|
1987
|
-
|
|
2014
|
+
log8.warn("incorrect invitationId", {
|
|
1988
2015
|
expected: invitation.invitationId,
|
|
1989
2016
|
actual: invitationId
|
|
1990
2017
|
}, {
|
|
@@ -1999,7 +2026,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1999
2026
|
authMethod: Invitation3.AuthMethod.NONE
|
|
2000
2027
|
};
|
|
2001
2028
|
}
|
|
2002
|
-
|
|
2029
|
+
log8("guest introduced themselves", {
|
|
2003
2030
|
guestProfile: profile
|
|
2004
2031
|
}, {
|
|
2005
2032
|
F: __dxlog_file10,
|
|
@@ -2010,7 +2037,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
2010
2037
|
this.guestProfile = profile;
|
|
2011
2038
|
this._callbacks.onStateUpdate(Invitation3.State.READY_FOR_AUTHENTICATION);
|
|
2012
2039
|
this._challenge = invitation.authMethod === Invitation3.AuthMethod.KNOWN_PUBLIC_KEY ? randomBytes(32) : void 0;
|
|
2013
|
-
|
|
2040
|
+
log8.trace("dxos.sdk.invitation-handler.host.introduce", trace4.end({
|
|
2014
2041
|
id: traceId
|
|
2015
2042
|
}), {
|
|
2016
2043
|
F: __dxlog_file10,
|
|
@@ -2025,7 +2052,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
2025
2052
|
},
|
|
2026
2053
|
authenticate: async ({ authCode: code, signedChallenge }) => {
|
|
2027
2054
|
const traceId = PublicKey5.random().toHex();
|
|
2028
|
-
|
|
2055
|
+
log8.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.begin({
|
|
2029
2056
|
id: traceId
|
|
2030
2057
|
}), {
|
|
2031
2058
|
F: __dxlog_file10,
|
|
@@ -2034,7 +2061,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
2034
2061
|
C: (f, a) => f(...a)
|
|
2035
2062
|
});
|
|
2036
2063
|
const invitation = this._requireActiveInvitation();
|
|
2037
|
-
|
|
2064
|
+
log8("received authentication request", {
|
|
2038
2065
|
authCode: code
|
|
2039
2066
|
}, {
|
|
2040
2067
|
F: __dxlog_file10,
|
|
@@ -2050,7 +2077,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
2050
2077
|
this._callbacks.onStateUpdate(Invitation3.State.AUTHENTICATING);
|
|
2051
2078
|
switch (invitation.authMethod) {
|
|
2052
2079
|
case Invitation3.AuthMethod.NONE: {
|
|
2053
|
-
|
|
2080
|
+
log8("authentication not required", void 0, {
|
|
2054
2081
|
F: __dxlog_file10,
|
|
2055
2082
|
L: 152,
|
|
2056
2083
|
S: this,
|
|
@@ -2086,7 +2113,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
2086
2113
|
break;
|
|
2087
2114
|
}
|
|
2088
2115
|
default: {
|
|
2089
|
-
|
|
2116
|
+
log8.error("invalid authentication method", {
|
|
2090
2117
|
authMethod: invitation.authMethod
|
|
2091
2118
|
}, {
|
|
2092
2119
|
F: __dxlog_file10,
|
|
@@ -2108,7 +2135,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
2108
2135
|
status
|
|
2109
2136
|
};
|
|
2110
2137
|
}
|
|
2111
|
-
|
|
2138
|
+
log8.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.end({
|
|
2112
2139
|
id: traceId,
|
|
2113
2140
|
data: {
|
|
2114
2141
|
status
|
|
@@ -2125,7 +2152,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
2125
2152
|
},
|
|
2126
2153
|
admit: async (request) => {
|
|
2127
2154
|
const traceId = PublicKey5.random().toHex();
|
|
2128
|
-
|
|
2155
|
+
log8.trace("dxos.sdk.invitation-handler.host.admit", trace4.begin({
|
|
2129
2156
|
id: traceId
|
|
2130
2157
|
}), {
|
|
2131
2158
|
F: __dxlog_file10,
|
|
@@ -2142,7 +2169,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
2142
2169
|
}
|
|
2143
2170
|
}
|
|
2144
2171
|
const response = await this._callbacks.admit(request);
|
|
2145
|
-
|
|
2172
|
+
log8.trace("dxos.sdk.invitation-handler.host.admit", trace4.end({
|
|
2146
2173
|
id: traceId
|
|
2147
2174
|
}), {
|
|
2148
2175
|
F: __dxlog_file10,
|
|
@@ -2162,14 +2189,14 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
2162
2189
|
async onOpen(context) {
|
|
2163
2190
|
await super.onOpen(context);
|
|
2164
2191
|
try {
|
|
2165
|
-
|
|
2192
|
+
log8("host acquire lock", void 0, {
|
|
2166
2193
|
F: __dxlog_file10,
|
|
2167
2194
|
L: 237,
|
|
2168
2195
|
S: this,
|
|
2169
2196
|
C: (f, a) => f(...a)
|
|
2170
2197
|
});
|
|
2171
2198
|
this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
|
|
2172
|
-
|
|
2199
|
+
log8("host lock acquired", void 0, {
|
|
2173
2200
|
F: __dxlog_file10,
|
|
2174
2201
|
L: 239,
|
|
2175
2202
|
S: this,
|
|
@@ -2180,7 +2207,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
2180
2207
|
await this.rpc.InvitationHostService.options({
|
|
2181
2208
|
role: Options2.Role.HOST
|
|
2182
2209
|
});
|
|
2183
|
-
|
|
2210
|
+
log8("options sent", void 0, {
|
|
2184
2211
|
F: __dxlog_file10,
|
|
2185
2212
|
L: 243,
|
|
2186
2213
|
S: this,
|
|
@@ -2189,7 +2216,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
2189
2216
|
await cancelWithContext3(this._ctx, this._remoteOptionsTrigger.wait({
|
|
2190
2217
|
timeout: OPTIONS_TIMEOUT2
|
|
2191
2218
|
}));
|
|
2192
|
-
|
|
2219
|
+
log8("options received", void 0, {
|
|
2193
2220
|
F: __dxlog_file10,
|
|
2194
2221
|
L: 245,
|
|
2195
2222
|
S: this,
|
|
@@ -2243,7 +2270,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
2243
2270
|
if (this._invitationFlowLock != null) {
|
|
2244
2271
|
this._invitationFlowLock?.release();
|
|
2245
2272
|
this._invitationFlowLock = null;
|
|
2246
|
-
|
|
2273
|
+
log8("invitation flow lock released", void 0, {
|
|
2247
2274
|
F: __dxlog_file10,
|
|
2248
2275
|
L: 300,
|
|
2249
2276
|
S: this,
|
|
@@ -2257,7 +2284,7 @@ var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitat
|
|
|
2257
2284
|
// packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts
|
|
2258
2285
|
import { invariant as invariant8 } from "@dxos/invariant";
|
|
2259
2286
|
import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
2260
|
-
import { log as
|
|
2287
|
+
import { log as log9 } from "@dxos/log";
|
|
2261
2288
|
import { Options as Options3 } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
2262
2289
|
import { ComplexSet as ComplexSet2 } from "@dxos/util";
|
|
2263
2290
|
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
|
|
@@ -2299,7 +2326,7 @@ var InvitationTopology = class {
|
|
|
2299
2326
|
const firstUnknownPeer = candidates.find((peerId) => !this._seenPeers.has(peerId));
|
|
2300
2327
|
this._seenPeers = new ComplexSet2(PublicKey6.hash, allPeers.filter((peerId) => this._seenPeers.has(peerId)));
|
|
2301
2328
|
if (firstUnknownPeer != null) {
|
|
2302
|
-
|
|
2329
|
+
log9("invitation connect", {
|
|
2303
2330
|
ownPeerId,
|
|
2304
2331
|
remotePeerId: firstUnknownPeer
|
|
2305
2332
|
}, {
|
|
@@ -2384,7 +2411,7 @@ var InvitationsHandler = class {
|
|
|
2384
2411
|
scheduleTask3(connectionCtx, async () => {
|
|
2385
2412
|
const traceId = PublicKey7.random().toHex();
|
|
2386
2413
|
try {
|
|
2387
|
-
|
|
2414
|
+
log10.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.begin({
|
|
2388
2415
|
id: traceId
|
|
2389
2416
|
}), {
|
|
2390
2417
|
F: __dxlog_file12,
|
|
@@ -2392,7 +2419,7 @@ var InvitationsHandler = class {
|
|
|
2392
2419
|
S: this,
|
|
2393
2420
|
C: (f, a) => f(...a)
|
|
2394
2421
|
});
|
|
2395
|
-
|
|
2422
|
+
log10("connected", {
|
|
2396
2423
|
...protocol.toJSON()
|
|
2397
2424
|
}, {
|
|
2398
2425
|
F: __dxlog_file12,
|
|
@@ -2403,7 +2430,7 @@ var InvitationsHandler = class {
|
|
|
2403
2430
|
const deviceKey = await extension.completedTrigger.wait({
|
|
2404
2431
|
timeout: invitation.timeout
|
|
2405
2432
|
});
|
|
2406
|
-
|
|
2433
|
+
log10("admitted guest", {
|
|
2407
2434
|
guest: deviceKey,
|
|
2408
2435
|
...protocol.toJSON()
|
|
2409
2436
|
}, {
|
|
@@ -2413,7 +2440,7 @@ var InvitationsHandler = class {
|
|
|
2413
2440
|
C: (f, a) => f(...a)
|
|
2414
2441
|
});
|
|
2415
2442
|
guardedState.set(extension, Invitation4.State.SUCCESS);
|
|
2416
|
-
|
|
2443
|
+
log10.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.end({
|
|
2417
2444
|
id: traceId
|
|
2418
2445
|
}), {
|
|
2419
2446
|
F: __dxlog_file12,
|
|
@@ -2428,7 +2455,7 @@ var InvitationsHandler = class {
|
|
|
2428
2455
|
} catch (err) {
|
|
2429
2456
|
if (err instanceof TimeoutError) {
|
|
2430
2457
|
if (guardedState.set(extension, Invitation4.State.TIMEOUT)) {
|
|
2431
|
-
|
|
2458
|
+
log10("timeout", {
|
|
2432
2459
|
...protocol.toJSON()
|
|
2433
2460
|
}, {
|
|
2434
2461
|
F: __dxlog_file12,
|
|
@@ -2439,7 +2466,7 @@ var InvitationsHandler = class {
|
|
|
2439
2466
|
}
|
|
2440
2467
|
} else {
|
|
2441
2468
|
if (guardedState.error(extension, err)) {
|
|
2442
|
-
|
|
2469
|
+
log10.error("failed", err, {
|
|
2443
2470
|
F: __dxlog_file12,
|
|
2444
2471
|
L: 133,
|
|
2445
2472
|
S: this,
|
|
@@ -2447,7 +2474,7 @@ var InvitationsHandler = class {
|
|
|
2447
2474
|
});
|
|
2448
2475
|
}
|
|
2449
2476
|
}
|
|
2450
|
-
|
|
2477
|
+
log10.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.error({
|
|
2451
2478
|
id: traceId,
|
|
2452
2479
|
error: err
|
|
2453
2480
|
}), {
|
|
@@ -2462,7 +2489,7 @@ var InvitationsHandler = class {
|
|
|
2462
2489
|
},
|
|
2463
2490
|
onError: (err) => {
|
|
2464
2491
|
if (err instanceof InvalidInvitationExtensionRoleError3) {
|
|
2465
|
-
|
|
2492
|
+
log10("invalid role", {
|
|
2466
2493
|
...err.context
|
|
2467
2494
|
}, {
|
|
2468
2495
|
F: __dxlog_file12,
|
|
@@ -2474,7 +2501,7 @@ var InvitationsHandler = class {
|
|
|
2474
2501
|
}
|
|
2475
2502
|
if (err instanceof TimeoutError) {
|
|
2476
2503
|
if (guardedState.set(extension, Invitation4.State.TIMEOUT)) {
|
|
2477
|
-
|
|
2504
|
+
log10("timeout", {
|
|
2478
2505
|
err
|
|
2479
2506
|
}, {
|
|
2480
2507
|
F: __dxlog_file12,
|
|
@@ -2485,7 +2512,7 @@ var InvitationsHandler = class {
|
|
|
2485
2512
|
}
|
|
2486
2513
|
} else {
|
|
2487
2514
|
if (guardedState.error(extension, err)) {
|
|
2488
|
-
|
|
2515
|
+
log10.error("failed", err, {
|
|
2489
2516
|
F: __dxlog_file12,
|
|
2490
2517
|
L: 153,
|
|
2491
2518
|
S: this,
|
|
@@ -2499,7 +2526,7 @@ var InvitationsHandler = class {
|
|
|
2499
2526
|
};
|
|
2500
2527
|
if (invitation.lifetime && invitation.created) {
|
|
2501
2528
|
if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
|
|
2502
|
-
|
|
2529
|
+
log10.warn("invitation has already expired", void 0, {
|
|
2503
2530
|
F: __dxlog_file12,
|
|
2504
2531
|
L: 164,
|
|
2505
2532
|
S: this,
|
|
@@ -2536,7 +2563,7 @@ var InvitationsHandler = class {
|
|
|
2536
2563
|
const guardedState = this._createGuardedState(ctx, invitation, stream);
|
|
2537
2564
|
const shouldCancelInvitationFlow = (extension) => {
|
|
2538
2565
|
const isLockedByAnotherConnection = guardedState.mutex.isLocked() && !extension.hasFlowLock();
|
|
2539
|
-
|
|
2566
|
+
log10("should cancel invitation flow", {
|
|
2540
2567
|
isLockedByAnotherConnection,
|
|
2541
2568
|
invitationType: Invitation4.Type.DELEGATED,
|
|
2542
2569
|
triedPeers: triedPeersIds.size
|
|
@@ -2564,7 +2591,7 @@ var InvitationsHandler = class {
|
|
|
2564
2591
|
return;
|
|
2565
2592
|
}
|
|
2566
2593
|
connectionCtx.onDispose(async () => {
|
|
2567
|
-
|
|
2594
|
+
log10("extension disposed", {
|
|
2568
2595
|
admitted,
|
|
2569
2596
|
currentState: guardedState.current.state
|
|
2570
2597
|
}, {
|
|
@@ -2583,7 +2610,7 @@ var InvitationsHandler = class {
|
|
|
2583
2610
|
scheduleTask3(connectionCtx, async () => {
|
|
2584
2611
|
const traceId = PublicKey7.random().toHex();
|
|
2585
2612
|
try {
|
|
2586
|
-
|
|
2613
|
+
log10.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.begin({
|
|
2587
2614
|
id: traceId
|
|
2588
2615
|
}), {
|
|
2589
2616
|
F: __dxlog_file12,
|
|
@@ -2595,7 +2622,7 @@ var InvitationsHandler = class {
|
|
|
2595
2622
|
guardedState.set(extension, Invitation4.State.TIMEOUT);
|
|
2596
2623
|
extensionCtx.close();
|
|
2597
2624
|
}, timeout);
|
|
2598
|
-
|
|
2625
|
+
log10("connected", {
|
|
2599
2626
|
...protocol.toJSON()
|
|
2600
2627
|
}, {
|
|
2601
2628
|
F: __dxlog_file12,
|
|
@@ -2604,7 +2631,7 @@ var InvitationsHandler = class {
|
|
|
2604
2631
|
C: (f, a) => f(...a)
|
|
2605
2632
|
});
|
|
2606
2633
|
guardedState.set(extension, Invitation4.State.CONNECTED);
|
|
2607
|
-
|
|
2634
|
+
log10("introduce", {
|
|
2608
2635
|
...protocol.toJSON()
|
|
2609
2636
|
}, {
|
|
2610
2637
|
F: __dxlog_file12,
|
|
@@ -2616,7 +2643,7 @@ var InvitationsHandler = class {
|
|
|
2616
2643
|
invitationId: invitation.invitationId,
|
|
2617
2644
|
...protocol.createIntroduction()
|
|
2618
2645
|
});
|
|
2619
|
-
|
|
2646
|
+
log10("introduce response", {
|
|
2620
2647
|
...protocol.toJSON(),
|
|
2621
2648
|
response: introductionResponse
|
|
2622
2649
|
}, {
|
|
@@ -2638,7 +2665,7 @@ var InvitationsHandler = class {
|
|
|
2638
2665
|
break;
|
|
2639
2666
|
}
|
|
2640
2667
|
}
|
|
2641
|
-
|
|
2668
|
+
log10("request admission", {
|
|
2642
2669
|
...protocol.toJSON()
|
|
2643
2670
|
}, {
|
|
2644
2671
|
F: __dxlog_file12,
|
|
@@ -2650,7 +2677,7 @@ var InvitationsHandler = class {
|
|
|
2650
2677
|
const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
|
|
2651
2678
|
admitted = true;
|
|
2652
2679
|
const result = await protocol.accept(admissionResponse, admissionRequest);
|
|
2653
|
-
|
|
2680
|
+
log10("admitted by host", {
|
|
2654
2681
|
...protocol.toJSON()
|
|
2655
2682
|
}, {
|
|
2656
2683
|
F: __dxlog_file12,
|
|
@@ -2663,7 +2690,7 @@ var InvitationsHandler = class {
|
|
|
2663
2690
|
...result,
|
|
2664
2691
|
state: Invitation4.State.SUCCESS
|
|
2665
2692
|
});
|
|
2666
|
-
|
|
2693
|
+
log10.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.end({
|
|
2667
2694
|
id: traceId
|
|
2668
2695
|
}), {
|
|
2669
2696
|
F: __dxlog_file12,
|
|
@@ -2673,7 +2700,7 @@ var InvitationsHandler = class {
|
|
|
2673
2700
|
});
|
|
2674
2701
|
} catch (err) {
|
|
2675
2702
|
if (err instanceof TimeoutError) {
|
|
2676
|
-
|
|
2703
|
+
log10("timeout", {
|
|
2677
2704
|
...protocol.toJSON()
|
|
2678
2705
|
}, {
|
|
2679
2706
|
F: __dxlog_file12,
|
|
@@ -2683,7 +2710,7 @@ var InvitationsHandler = class {
|
|
|
2683
2710
|
});
|
|
2684
2711
|
guardedState.set(extension, Invitation4.State.TIMEOUT);
|
|
2685
2712
|
} else {
|
|
2686
|
-
|
|
2713
|
+
log10("auth failed", err, {
|
|
2687
2714
|
F: __dxlog_file12,
|
|
2688
2715
|
L: 314,
|
|
2689
2716
|
S: this,
|
|
@@ -2692,7 +2719,7 @@ var InvitationsHandler = class {
|
|
|
2692
2719
|
guardedState.error(extension, err);
|
|
2693
2720
|
}
|
|
2694
2721
|
extensionCtx.close(err);
|
|
2695
|
-
|
|
2722
|
+
log10.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.error({
|
|
2696
2723
|
id: traceId,
|
|
2697
2724
|
error: err
|
|
2698
2725
|
}), {
|
|
@@ -2709,7 +2736,7 @@ var InvitationsHandler = class {
|
|
|
2709
2736
|
return;
|
|
2710
2737
|
}
|
|
2711
2738
|
if (err instanceof TimeoutError) {
|
|
2712
|
-
|
|
2739
|
+
log10("timeout", {
|
|
2713
2740
|
...protocol.toJSON()
|
|
2714
2741
|
}, {
|
|
2715
2742
|
F: __dxlog_file12,
|
|
@@ -2719,7 +2746,7 @@ var InvitationsHandler = class {
|
|
|
2719
2746
|
});
|
|
2720
2747
|
guardedState.set(extension, Invitation4.State.TIMEOUT);
|
|
2721
2748
|
} else {
|
|
2722
|
-
|
|
2749
|
+
log10("auth failed", err, {
|
|
2723
2750
|
F: __dxlog_file12,
|
|
2724
2751
|
L: 330,
|
|
2725
2752
|
S: this,
|
|
@@ -2832,7 +2859,7 @@ var InvitationsHandler = class {
|
|
|
2832
2859
|
};
|
|
2833
2860
|
}
|
|
2834
2861
|
_logStateUpdate(invitation, actor, newState) {
|
|
2835
|
-
|
|
2862
|
+
log10("invitation state update", {
|
|
2836
2863
|
actor: actor?.constructor.name,
|
|
2837
2864
|
newState: stateToString(newState),
|
|
2838
2865
|
oldState: stateToString(invitation.state)
|
|
@@ -2854,7 +2881,7 @@ var InvitationsHandler = class {
|
|
|
2854
2881
|
}
|
|
2855
2882
|
async _handleGuestOtpAuth(extension, setState, authenticated, options) {
|
|
2856
2883
|
for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
|
|
2857
|
-
|
|
2884
|
+
log10("guest waiting for authentication code...", void 0, {
|
|
2858
2885
|
F: __dxlog_file12,
|
|
2859
2886
|
L: 462,
|
|
2860
2887
|
S: this,
|
|
@@ -2862,7 +2889,7 @@ var InvitationsHandler = class {
|
|
|
2862
2889
|
});
|
|
2863
2890
|
setState(Invitation4.State.READY_FOR_AUTHENTICATION);
|
|
2864
2891
|
const authCode = await authenticated.wait(options);
|
|
2865
|
-
|
|
2892
|
+
log10("sending authentication request", void 0, {
|
|
2866
2893
|
F: __dxlog_file12,
|
|
2867
2894
|
L: 466,
|
|
2868
2895
|
S: this,
|
|
@@ -2879,7 +2906,7 @@ var InvitationsHandler = class {
|
|
|
2879
2906
|
if (attempt === MAX_OTP_ATTEMPTS) {
|
|
2880
2907
|
throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
|
|
2881
2908
|
} else {
|
|
2882
|
-
|
|
2909
|
+
log10("retrying invalid code", {
|
|
2883
2910
|
attempt
|
|
2884
2911
|
}, {
|
|
2885
2912
|
F: __dxlog_file12,
|
|
@@ -2899,7 +2926,7 @@ var InvitationsHandler = class {
|
|
|
2899
2926
|
if (introductionResponse.challenge == null) {
|
|
2900
2927
|
throw new Error("challenge missing in the introduction");
|
|
2901
2928
|
}
|
|
2902
|
-
|
|
2929
|
+
log10("sending authentication request", void 0, {
|
|
2903
2930
|
F: __dxlog_file12,
|
|
2904
2931
|
L: 496,
|
|
2905
2932
|
S: this,
|
|
@@ -3024,7 +3051,7 @@ var InvitationsServiceImpl = class {
|
|
|
3024
3051
|
import { createAdmissionCredentials, createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
|
|
3025
3052
|
import { writeMessages as writeMessages2 } from "@dxos/feed-store";
|
|
3026
3053
|
import { invariant as invariant10 } from "@dxos/invariant";
|
|
3027
|
-
import { log as
|
|
3054
|
+
import { log as log11 } from "@dxos/log";
|
|
3028
3055
|
import { AlreadyJoinedError as AlreadyJoinedError2, AuthorizationError, InvalidInvitationError, SpaceNotFoundError } from "@dxos/protocols";
|
|
3029
3056
|
import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
|
|
3030
3057
|
import { SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
@@ -3094,7 +3121,7 @@ var SpaceInvitationProtocol = class {
|
|
|
3094
3121
|
if (space.inner.spaceState.getMemberRole(identityKey) !== SpaceMember2.Role.REMOVED) {
|
|
3095
3122
|
throw new AlreadyJoinedError2();
|
|
3096
3123
|
}
|
|
3097
|
-
|
|
3124
|
+
log11("writing guest credentials", {
|
|
3098
3125
|
host: this._signingContext.deviceKey,
|
|
3099
3126
|
guest: deviceKey
|
|
3100
3127
|
}, {
|
|
@@ -3162,7 +3189,7 @@ var SpaceInvitationProtocol = class {
|
|
|
3162
3189
|
]
|
|
3163
3190
|
});
|
|
3164
3191
|
}
|
|
3165
|
-
|
|
3192
|
+
log11("writing delegate space invitation", {
|
|
3166
3193
|
host: this._signingContext.deviceKey,
|
|
3167
3194
|
id: invitation.invitationId
|
|
3168
3195
|
}, {
|
|
@@ -3223,7 +3250,7 @@ var SpaceInvitationProtocol = class {
|
|
|
3223
3250
|
""
|
|
3224
3251
|
]
|
|
3225
3252
|
});
|
|
3226
|
-
|
|
3253
|
+
log11("cancelling delegated space invitation", {
|
|
3227
3254
|
host: this._signingContext.deviceKey,
|
|
3228
3255
|
id: invitation.invitationId
|
|
3229
3256
|
}, {
|
|
@@ -3318,14 +3345,14 @@ var SpaceInvitationProtocol = class {
|
|
|
3318
3345
|
};
|
|
3319
3346
|
|
|
3320
3347
|
// packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts
|
|
3321
|
-
import { Event as Event3, PushStream, TimeoutError as TimeoutError2, Trigger as
|
|
3348
|
+
import { Event as Event3, PushStream, TimeoutError as TimeoutError2, Trigger as Trigger6 } from "@dxos/async";
|
|
3322
3349
|
import { AuthenticatingInvitation, AUTHENTICATION_CODE_LENGTH, CancellableInvitation, INVITATION_TIMEOUT as INVITATION_TIMEOUT2 } from "@dxos/client-protocol";
|
|
3323
3350
|
import { Context as Context6 } from "@dxos/context";
|
|
3324
3351
|
import { generatePasscode } from "@dxos/credentials";
|
|
3325
3352
|
import { hasInvitationExpired } from "@dxos/echo-pipeline";
|
|
3326
3353
|
import { invariant as invariant11 } from "@dxos/invariant";
|
|
3327
3354
|
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
3328
|
-
import { log as
|
|
3355
|
+
import { log as log12 } from "@dxos/log";
|
|
3329
3356
|
import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/services";
|
|
3330
3357
|
import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
3331
3358
|
var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
|
|
@@ -3370,7 +3397,7 @@ var InvitationsManager = class {
|
|
|
3370
3397
|
try {
|
|
3371
3398
|
await this._persistIfRequired(handler, stream, invitation);
|
|
3372
3399
|
} catch (err) {
|
|
3373
|
-
|
|
3400
|
+
log12.catch(err, void 0, {
|
|
3374
3401
|
F: __dxlog_file14,
|
|
3375
3402
|
L: 82,
|
|
3376
3403
|
S: this,
|
|
@@ -3412,7 +3439,7 @@ var InvitationsManager = class {
|
|
|
3412
3439
|
invitations: cInvitations.map((invitation) => invitation.get())
|
|
3413
3440
|
};
|
|
3414
3441
|
} catch (err) {
|
|
3415
|
-
|
|
3442
|
+
log12.catch(err, void 0, {
|
|
3416
3443
|
F: __dxlog_file14,
|
|
3417
3444
|
L: 110,
|
|
3418
3445
|
S: this,
|
|
@@ -3444,7 +3471,7 @@ var InvitationsManager = class {
|
|
|
3444
3471
|
return invitation;
|
|
3445
3472
|
}
|
|
3446
3473
|
async authenticate({ invitationId, authCode }) {
|
|
3447
|
-
|
|
3474
|
+
log12("authenticating...", void 0, {
|
|
3448
3475
|
F: __dxlog_file14,
|
|
3449
3476
|
L: 140,
|
|
3450
3477
|
S: this,
|
|
@@ -3461,7 +3488,7 @@ var InvitationsManager = class {
|
|
|
3461
3488
|
});
|
|
3462
3489
|
const observable = this._acceptInvitations.get(invitationId);
|
|
3463
3490
|
if (!observable) {
|
|
3464
|
-
|
|
3491
|
+
log12.warn("invalid invitation", {
|
|
3465
3492
|
invitationId
|
|
3466
3493
|
}, {
|
|
3467
3494
|
F: __dxlog_file14,
|
|
@@ -3474,7 +3501,7 @@ var InvitationsManager = class {
|
|
|
3474
3501
|
}
|
|
3475
3502
|
}
|
|
3476
3503
|
async cancelInvitation({ invitationId }) {
|
|
3477
|
-
|
|
3504
|
+
log12("cancelInvitation...", {
|
|
3478
3505
|
invitationId
|
|
3479
3506
|
}, {
|
|
3480
3507
|
F: __dxlog_file14,
|
|
@@ -3559,7 +3586,7 @@ var InvitationsManager = class {
|
|
|
3559
3586
|
}
|
|
3560
3587
|
});
|
|
3561
3588
|
ctx.onDispose(() => {
|
|
3562
|
-
|
|
3589
|
+
log12("complete", {
|
|
3563
3590
|
...handler.toJSON()
|
|
3564
3591
|
}, {
|
|
3565
3592
|
F: __dxlog_file14,
|
|
@@ -3587,12 +3614,12 @@ var InvitationsManager = class {
|
|
|
3587
3614
|
};
|
|
3588
3615
|
}
|
|
3589
3616
|
_createObservableAcceptingInvitation(handler, initialState) {
|
|
3590
|
-
const otpEnteredTrigger = new
|
|
3617
|
+
const otpEnteredTrigger = new Trigger6();
|
|
3591
3618
|
const stream = new PushStream();
|
|
3592
3619
|
const ctx = new Context6({
|
|
3593
3620
|
onError: (err) => {
|
|
3594
3621
|
if (err instanceof TimeoutError2) {
|
|
3595
|
-
|
|
3622
|
+
log12("timeout", {
|
|
3596
3623
|
...handler.toJSON()
|
|
3597
3624
|
}, {
|
|
3598
3625
|
F: __dxlog_file14,
|
|
@@ -3605,7 +3632,7 @@ var InvitationsManager = class {
|
|
|
3605
3632
|
state: Invitation6.State.TIMEOUT
|
|
3606
3633
|
});
|
|
3607
3634
|
} else {
|
|
3608
|
-
|
|
3635
|
+
log12.warn("auth failed", err, {
|
|
3609
3636
|
F: __dxlog_file14,
|
|
3610
3637
|
L: 264,
|
|
3611
3638
|
S: this,
|
|
@@ -3620,7 +3647,7 @@ var InvitationsManager = class {
|
|
|
3620
3647
|
}
|
|
3621
3648
|
});
|
|
3622
3649
|
ctx.onDispose(() => {
|
|
3623
|
-
|
|
3650
|
+
log12("complete", {
|
|
3624
3651
|
...handler.toJSON()
|
|
3625
3652
|
}, {
|
|
3626
3653
|
F: __dxlog_file14,
|
|
@@ -3667,7 +3694,7 @@ var InvitationsManager = class {
|
|
|
3667
3694
|
try {
|
|
3668
3695
|
await this._metadataStore.removeInvitation(invitation.invitationId);
|
|
3669
3696
|
} catch (err) {
|
|
3670
|
-
|
|
3697
|
+
log12.catch(err, void 0, {
|
|
3671
3698
|
F: __dxlog_file14,
|
|
3672
3699
|
L: 307,
|
|
3673
3700
|
S: this,
|
|
@@ -3683,33 +3710,40 @@ var InvitationsManager = class {
|
|
|
3683
3710
|
};
|
|
3684
3711
|
|
|
3685
3712
|
// packages/sdk/client-services/src/packlets/spaces/data-space.ts
|
|
3686
|
-
import { Event as Event6,
|
|
3713
|
+
import { Event as Event6, Mutex as Mutex2, scheduleTask as scheduleTask5, sleep as sleep3, synchronized, trackLeaks } from "@dxos/async";
|
|
3687
3714
|
import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
|
|
3688
|
-
import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as
|
|
3715
|
+
import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as cancelWithContext5 } from "@dxos/context";
|
|
3689
3716
|
import { timed, warnAfterTimeout } from "@dxos/debug";
|
|
3690
|
-
import {
|
|
3691
|
-
import {
|
|
3692
|
-
import { failedInvariant
|
|
3717
|
+
import { createMappedFeedWriter } from "@dxos/echo-pipeline";
|
|
3718
|
+
import { SpaceDocVersion } from "@dxos/echo-protocol";
|
|
3719
|
+
import { failedInvariant } from "@dxos/invariant";
|
|
3693
3720
|
import { PublicKey as PublicKey10 } from "@dxos/keys";
|
|
3694
|
-
import { log as
|
|
3721
|
+
import { log as log15 } from "@dxos/log";
|
|
3695
3722
|
import { CancelledError, SystemError } from "@dxos/protocols";
|
|
3696
|
-
import {
|
|
3723
|
+
import { SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
3697
3724
|
import { AdmittedFeed as AdmittedFeed3, SpaceMember as SpaceMember4 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
3698
3725
|
import { Timeframe as Timeframe3 } from "@dxos/timeframe";
|
|
3699
3726
|
import { trace as trace6 } from "@dxos/tracing";
|
|
3700
|
-
import { ComplexSet as ComplexSet5
|
|
3727
|
+
import { ComplexSet as ComplexSet5 } from "@dxos/util";
|
|
3701
3728
|
|
|
3702
3729
|
// packages/sdk/client-services/src/packlets/spaces/automerge-space-state.ts
|
|
3703
3730
|
import { Event as Event4 } from "@dxos/async";
|
|
3731
|
+
import { Resource as Resource2 } from "@dxos/context";
|
|
3704
3732
|
import { checkCredentialType } from "@dxos/credentials";
|
|
3705
|
-
var AutomergeSpaceState = class {
|
|
3733
|
+
var AutomergeSpaceState = class extends Resource2 {
|
|
3706
3734
|
constructor(_onNewRoot) {
|
|
3735
|
+
super();
|
|
3707
3736
|
this._onNewRoot = _onNewRoot;
|
|
3708
3737
|
this.rootUrl = void 0;
|
|
3709
3738
|
this.lastEpoch = void 0;
|
|
3710
3739
|
this.onNewEpoch = new Event4();
|
|
3711
3740
|
this._isProcessingRootDocs = false;
|
|
3712
3741
|
}
|
|
3742
|
+
async _open(ctx) {
|
|
3743
|
+
}
|
|
3744
|
+
async _close(ctx) {
|
|
3745
|
+
this._isProcessingRootDocs = false;
|
|
3746
|
+
}
|
|
3713
3747
|
async processCredential(credential) {
|
|
3714
3748
|
if (!checkCredentialType(credential, "dxos.halo.credentials.Epoch")) {
|
|
3715
3749
|
return;
|
|
@@ -3737,16 +3771,162 @@ var AutomergeSpaceState = class {
|
|
|
3737
3771
|
}
|
|
3738
3772
|
};
|
|
3739
3773
|
|
|
3774
|
+
// packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts
|
|
3775
|
+
import { asyncTimeout as asyncTimeout2 } from "@dxos/async";
|
|
3776
|
+
import { next as am } from "@dxos/automerge/automerge";
|
|
3777
|
+
import { cancelWithContext as cancelWithContext4 } from "@dxos/context";
|
|
3778
|
+
import { convertLegacyReferences, convertLegacySpaceRootDoc, findInlineObjectOfType, migrateDocument } from "@dxos/echo-db";
|
|
3779
|
+
import { AutomergeDocumentLoaderImpl } from "@dxos/echo-pipeline";
|
|
3780
|
+
import { TYPE_PROPERTIES } from "@dxos/echo-schema";
|
|
3781
|
+
import { invariant as invariant12 } from "@dxos/invariant";
|
|
3782
|
+
import { log as log13 } from "@dxos/log";
|
|
3783
|
+
import { CreateEpochRequest } from "@dxos/protocols/proto/dxos/client/services";
|
|
3784
|
+
import { assignDeep } from "@dxos/util";
|
|
3785
|
+
var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts";
|
|
3786
|
+
var runEpochMigration = async (ctx, context) => {
|
|
3787
|
+
switch (context.migration) {
|
|
3788
|
+
case CreateEpochRequest.Migration.INIT_AUTOMERGE: {
|
|
3789
|
+
const document = context.repo.create();
|
|
3790
|
+
await context.repo.flush();
|
|
3791
|
+
return {
|
|
3792
|
+
newRoot: document.url
|
|
3793
|
+
};
|
|
3794
|
+
}
|
|
3795
|
+
case CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY: {
|
|
3796
|
+
if (!context.currentRoot) {
|
|
3797
|
+
throw new Error("Space does not have an automerge root");
|
|
3798
|
+
}
|
|
3799
|
+
const rootHandle = context.repo.find(context.currentRoot);
|
|
3800
|
+
await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
|
|
3801
|
+
const newRoot = context.repo.create(rootHandle.docSync());
|
|
3802
|
+
await context.repo.flush();
|
|
3803
|
+
return {
|
|
3804
|
+
newRoot: newRoot.url
|
|
3805
|
+
};
|
|
3806
|
+
}
|
|
3807
|
+
case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT: {
|
|
3808
|
+
log13.info("Fragmenting", void 0, {
|
|
3809
|
+
F: __dxlog_file15,
|
|
3810
|
+
L: 63,
|
|
3811
|
+
S: void 0,
|
|
3812
|
+
C: (f, a) => f(...a)
|
|
3813
|
+
});
|
|
3814
|
+
const currentRootUrl = context.currentRoot;
|
|
3815
|
+
const rootHandle = context.repo.find(currentRootUrl);
|
|
3816
|
+
await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
|
|
3817
|
+
const objects = Object.entries(rootHandle.docSync().objects);
|
|
3818
|
+
const properties = findInlineObjectOfType(rootHandle.docSync(), TYPE_PROPERTIES);
|
|
3819
|
+
const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
|
|
3820
|
+
invariant12(properties, "Properties not found", {
|
|
3821
|
+
F: __dxlog_file15,
|
|
3822
|
+
L: 73,
|
|
3823
|
+
S: void 0,
|
|
3824
|
+
A: [
|
|
3825
|
+
"properties",
|
|
3826
|
+
"'Properties not found'"
|
|
3827
|
+
]
|
|
3828
|
+
});
|
|
3829
|
+
const newSpaceDoc = {
|
|
3830
|
+
...rootHandle.docSync(),
|
|
3831
|
+
objects: Object.fromEntries([
|
|
3832
|
+
properties
|
|
3833
|
+
])
|
|
3834
|
+
};
|
|
3835
|
+
const newRoot = context.repo.create(newSpaceDoc);
|
|
3836
|
+
invariant12(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
|
|
3837
|
+
F: __dxlog_file15,
|
|
3838
|
+
L: 78,
|
|
3839
|
+
S: void 0,
|
|
3840
|
+
A: [
|
|
3841
|
+
"typeof newRoot.url === 'string' && newRoot.url.length > 0",
|
|
3842
|
+
""
|
|
3843
|
+
]
|
|
3844
|
+
});
|
|
3845
|
+
const docLoader = new AutomergeDocumentLoaderImpl(context.spaceId, context.repo, context.spaceKey);
|
|
3846
|
+
await docLoader.loadSpaceRootDocHandle(ctx, {
|
|
3847
|
+
rootUrl: newRoot.url
|
|
3848
|
+
});
|
|
3849
|
+
otherObjects.forEach(([key, value]) => {
|
|
3850
|
+
const handle = docLoader.createDocumentForObject(key);
|
|
3851
|
+
handle.change((doc) => {
|
|
3852
|
+
assignDeep(doc, [
|
|
3853
|
+
"objects",
|
|
3854
|
+
key
|
|
3855
|
+
], value);
|
|
3856
|
+
});
|
|
3857
|
+
});
|
|
3858
|
+
await context.repo.flush();
|
|
3859
|
+
return {
|
|
3860
|
+
newRoot: newRoot.url
|
|
3861
|
+
};
|
|
3862
|
+
}
|
|
3863
|
+
case CreateEpochRequest.Migration.MIGRATE_REFERENCES_TO_DXN: {
|
|
3864
|
+
const currentRootUrl = context.currentRoot;
|
|
3865
|
+
const rootHandle = context.repo.find(currentRootUrl);
|
|
3866
|
+
await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
|
|
3867
|
+
invariant12(rootHandle.docSync(), "Root doc not found", {
|
|
3868
|
+
F: __dxlog_file15,
|
|
3869
|
+
L: 100,
|
|
3870
|
+
S: void 0,
|
|
3871
|
+
A: [
|
|
3872
|
+
"rootHandle.docSync()",
|
|
3873
|
+
"'Root doc not found'"
|
|
3874
|
+
]
|
|
3875
|
+
});
|
|
3876
|
+
const newRootContent = await convertLegacySpaceRootDoc(structuredClone(rootHandle.docSync()));
|
|
3877
|
+
for (const [id, url] of Object.entries(newRootContent.links ?? {})) {
|
|
3878
|
+
const handle = context.repo.find(url);
|
|
3879
|
+
await cancelWithContext4(ctx, asyncTimeout2(handle.whenReady(), 1e4));
|
|
3880
|
+
invariant12(handle.docSync(), "Doc not found", {
|
|
3881
|
+
F: __dxlog_file15,
|
|
3882
|
+
L: 107,
|
|
3883
|
+
S: void 0,
|
|
3884
|
+
A: [
|
|
3885
|
+
"handle.docSync()",
|
|
3886
|
+
"'Doc not found'"
|
|
3887
|
+
]
|
|
3888
|
+
});
|
|
3889
|
+
const newDoc = await convertLegacyReferences(structuredClone(handle.docSync()));
|
|
3890
|
+
const migratedDoc = migrateDocument(handle.docSync(), newDoc);
|
|
3891
|
+
const newHandle = context.repo.import(am.save(migratedDoc));
|
|
3892
|
+
newRootContent.links[id] = newHandle.url;
|
|
3893
|
+
}
|
|
3894
|
+
const migratedRoot = migrateDocument(rootHandle.docSync(), newRootContent);
|
|
3895
|
+
const newRoot = context.repo.import(am.save(migratedRoot));
|
|
3896
|
+
await context.repo.flush();
|
|
3897
|
+
return {
|
|
3898
|
+
newRoot: newRoot.url
|
|
3899
|
+
};
|
|
3900
|
+
}
|
|
3901
|
+
case CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT: {
|
|
3902
|
+
invariant12(context.newAutomergeRoot, void 0, {
|
|
3903
|
+
F: __dxlog_file15,
|
|
3904
|
+
L: 124,
|
|
3905
|
+
S: void 0,
|
|
3906
|
+
A: [
|
|
3907
|
+
"context.newAutomergeRoot",
|
|
3908
|
+
""
|
|
3909
|
+
]
|
|
3910
|
+
});
|
|
3911
|
+
await context.repo.flush();
|
|
3912
|
+
return {
|
|
3913
|
+
newRoot: context.newAutomergeRoot
|
|
3914
|
+
};
|
|
3915
|
+
}
|
|
3916
|
+
}
|
|
3917
|
+
return {};
|
|
3918
|
+
};
|
|
3919
|
+
|
|
3740
3920
|
// packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
|
|
3741
|
-
import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep, TimeoutError as TimeoutError3, Trigger as
|
|
3921
|
+
import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep as sleep2, TimeoutError as TimeoutError3, Trigger as Trigger7 } from "@dxos/async";
|
|
3742
3922
|
import { Context as Context7, rejectOnDispose } from "@dxos/context";
|
|
3743
|
-
import { invariant as
|
|
3923
|
+
import { invariant as invariant13 } from "@dxos/invariant";
|
|
3744
3924
|
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
3745
|
-
import { log as
|
|
3925
|
+
import { log as log14 } from "@dxos/log";
|
|
3746
3926
|
import { schema as schema4 } from "@dxos/protocols";
|
|
3747
3927
|
import { RpcExtension as RpcExtension3 } from "@dxos/teleport";
|
|
3748
3928
|
import { ComplexMap as ComplexMap2, ComplexSet as ComplexSet4, entry } from "@dxos/util";
|
|
3749
|
-
var
|
|
3929
|
+
var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
|
|
3750
3930
|
var DEFAULT_RETRY_TIMEOUT = 1e3;
|
|
3751
3931
|
var DEFAULT_SUCCESS_DELAY = 1e3;
|
|
3752
3932
|
var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
|
|
@@ -3771,16 +3951,16 @@ var NotarizationPlugin = class {
|
|
|
3771
3951
|
* Request credentials to be notarized.
|
|
3772
3952
|
*/
|
|
3773
3953
|
async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
|
|
3774
|
-
|
|
3954
|
+
log14("notarize", {
|
|
3775
3955
|
credentials
|
|
3776
3956
|
}, {
|
|
3777
|
-
F:
|
|
3957
|
+
F: __dxlog_file16,
|
|
3778
3958
|
L: 90,
|
|
3779
3959
|
S: this,
|
|
3780
3960
|
C: (f, a) => f(...a)
|
|
3781
3961
|
});
|
|
3782
|
-
|
|
3783
|
-
F:
|
|
3962
|
+
invariant13(credentials.every((credential) => credential.id), "Credentials must have an id", {
|
|
3963
|
+
F: __dxlog_file16,
|
|
3784
3964
|
L: 91,
|
|
3785
3965
|
S: this,
|
|
3786
3966
|
A: [
|
|
@@ -3788,13 +3968,13 @@ var NotarizationPlugin = class {
|
|
|
3788
3968
|
"'Credentials must have an id'"
|
|
3789
3969
|
]
|
|
3790
3970
|
});
|
|
3791
|
-
const errors = new
|
|
3971
|
+
const errors = new Trigger7();
|
|
3792
3972
|
const ctx = this._ctx.derive({
|
|
3793
3973
|
onError: (err) => {
|
|
3794
|
-
|
|
3974
|
+
log14.warn("Notarization error", {
|
|
3795
3975
|
err
|
|
3796
3976
|
}, {
|
|
3797
|
-
F:
|
|
3977
|
+
F: __dxlog_file16,
|
|
3798
3978
|
L: 99,
|
|
3799
3979
|
S: this,
|
|
3800
3980
|
C: (f, a) => f(...a)
|
|
@@ -3806,11 +3986,11 @@ var NotarizationPlugin = class {
|
|
|
3806
3986
|
opCtx?.onDispose(() => ctx.dispose());
|
|
3807
3987
|
if (timeout !== 0) {
|
|
3808
3988
|
scheduleTask4(ctx, () => {
|
|
3809
|
-
|
|
3989
|
+
log14.warn("Notarization timeout", {
|
|
3810
3990
|
timeout,
|
|
3811
3991
|
peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
|
|
3812
3992
|
}, {
|
|
3813
|
-
F:
|
|
3993
|
+
F: __dxlog_file16,
|
|
3814
3994
|
L: 111,
|
|
3815
3995
|
S: this,
|
|
3816
3996
|
C: (f, a) => f(...a)
|
|
@@ -3830,10 +4010,10 @@ var NotarizationPlugin = class {
|
|
|
3830
4010
|
...this._extensions
|
|
3831
4011
|
].find((peer2) => !peersTried.has(peer2));
|
|
3832
4012
|
if (!peer) {
|
|
3833
|
-
|
|
4013
|
+
log14.info("Exhausted all peers to notarize with", {
|
|
3834
4014
|
retryIn: retryTimeout
|
|
3835
4015
|
}, {
|
|
3836
|
-
F:
|
|
4016
|
+
F: __dxlog_file16,
|
|
3837
4017
|
L: 136,
|
|
3838
4018
|
S: this,
|
|
3839
4019
|
C: (f, a) => f(...a)
|
|
@@ -3843,11 +4023,11 @@ var NotarizationPlugin = class {
|
|
|
3843
4023
|
return;
|
|
3844
4024
|
}
|
|
3845
4025
|
peersTried.add(peer);
|
|
3846
|
-
|
|
4026
|
+
log14("try notarizing", {
|
|
3847
4027
|
peer: peer.localPeerId,
|
|
3848
4028
|
credentialId: credentials.map((credential) => credential.id)
|
|
3849
4029
|
}, {
|
|
3850
|
-
F:
|
|
4030
|
+
F: __dxlog_file16,
|
|
3851
4031
|
L: 143,
|
|
3852
4032
|
S: this,
|
|
3853
4033
|
C: (f, a) => f(...a)
|
|
@@ -3855,17 +4035,17 @@ var NotarizationPlugin = class {
|
|
|
3855
4035
|
await peer.rpc.NotarizationService.notarize({
|
|
3856
4036
|
credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
|
|
3857
4037
|
});
|
|
3858
|
-
|
|
3859
|
-
F:
|
|
4038
|
+
log14("success", void 0, {
|
|
4039
|
+
F: __dxlog_file16,
|
|
3860
4040
|
L: 147,
|
|
3861
4041
|
S: this,
|
|
3862
4042
|
C: (f, a) => f(...a)
|
|
3863
4043
|
});
|
|
3864
|
-
await
|
|
4044
|
+
await sleep2(successDelay);
|
|
3865
4045
|
} catch (err) {
|
|
3866
4046
|
if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
|
|
3867
|
-
|
|
3868
|
-
F:
|
|
4047
|
+
log14.info("error notarizing (recoverable)", err, {
|
|
4048
|
+
F: __dxlog_file16,
|
|
3869
4049
|
L: 151,
|
|
3870
4050
|
S: this,
|
|
3871
4051
|
C: (f, a) => f(...a)
|
|
@@ -3882,8 +4062,8 @@ var NotarizationPlugin = class {
|
|
|
3882
4062
|
allNotarized,
|
|
3883
4063
|
errors.wait()
|
|
3884
4064
|
]);
|
|
3885
|
-
|
|
3886
|
-
F:
|
|
4065
|
+
log14("done", void 0, {
|
|
4066
|
+
F: __dxlog_file16,
|
|
3887
4067
|
L: 162,
|
|
3888
4068
|
S: this,
|
|
3889
4069
|
C: (f, a) => f(...a)
|
|
@@ -3904,8 +4084,8 @@ var NotarizationPlugin = class {
|
|
|
3904
4084
|
this._processCredentialsTriggers.delete(credential.id);
|
|
3905
4085
|
}
|
|
3906
4086
|
setWriter(writer) {
|
|
3907
|
-
|
|
3908
|
-
F:
|
|
4087
|
+
invariant13(!this._writer, "Writer already set.", {
|
|
4088
|
+
F: __dxlog_file16,
|
|
3909
4089
|
L: 181,
|
|
3910
4090
|
S: this,
|
|
3911
4091
|
A: [
|
|
@@ -3919,7 +4099,7 @@ var NotarizationPlugin = class {
|
|
|
3919
4099
|
if (this._processedCredentials.has(id)) {
|
|
3920
4100
|
return;
|
|
3921
4101
|
}
|
|
3922
|
-
await entry(this._processCredentialsTriggers, id).orInsert(new
|
|
4102
|
+
await entry(this._processCredentialsTriggers, id).orInsert(new Trigger7()).value.wait();
|
|
3923
4103
|
}
|
|
3924
4104
|
/**
|
|
3925
4105
|
* Requests from other peers to notarize credentials.
|
|
@@ -3929,8 +4109,8 @@ var NotarizationPlugin = class {
|
|
|
3929
4109
|
throw new Error(WRITER_NOT_SET_ERROR_CODE);
|
|
3930
4110
|
}
|
|
3931
4111
|
for (const credential of request.credentials ?? []) {
|
|
3932
|
-
|
|
3933
|
-
F:
|
|
4112
|
+
invariant13(credential.id, "Credential must have an id", {
|
|
4113
|
+
F: __dxlog_file16,
|
|
3934
4114
|
L: 200,
|
|
3935
4115
|
S: this,
|
|
3936
4116
|
A: [
|
|
@@ -3947,10 +4127,10 @@ var NotarizationPlugin = class {
|
|
|
3947
4127
|
createExtension() {
|
|
3948
4128
|
const extension = new NotarizationTeleportExtension({
|
|
3949
4129
|
onOpen: async () => {
|
|
3950
|
-
|
|
4130
|
+
log14("extension opened", {
|
|
3951
4131
|
peer: extension.localPeerId
|
|
3952
4132
|
}, {
|
|
3953
|
-
F:
|
|
4133
|
+
F: __dxlog_file16,
|
|
3954
4134
|
L: 211,
|
|
3955
4135
|
S: this,
|
|
3956
4136
|
C: (f, a) => f(...a)
|
|
@@ -3959,10 +4139,10 @@ var NotarizationPlugin = class {
|
|
|
3959
4139
|
this._extensionOpened.emit();
|
|
3960
4140
|
},
|
|
3961
4141
|
onClose: async () => {
|
|
3962
|
-
|
|
4142
|
+
log14("extension closed", {
|
|
3963
4143
|
peer: extension.localPeerId
|
|
3964
4144
|
}, {
|
|
3965
|
-
F:
|
|
4145
|
+
F: __dxlog_file16,
|
|
3966
4146
|
L: 216,
|
|
3967
4147
|
S: this,
|
|
3968
4148
|
C: (f, a) => f(...a)
|
|
@@ -4016,7 +4196,70 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
4016
4196
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
4017
4197
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
4018
4198
|
}
|
|
4019
|
-
|
|
4199
|
+
function _using_ctx() {
|
|
4200
|
+
var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
|
|
4201
|
+
var err = new Error();
|
|
4202
|
+
err.name = "SuppressedError";
|
|
4203
|
+
err.suppressed = suppressed;
|
|
4204
|
+
err.error = error;
|
|
4205
|
+
return err;
|
|
4206
|
+
}, empty = {}, stack = [];
|
|
4207
|
+
function using(isAwait, value) {
|
|
4208
|
+
if (value != null) {
|
|
4209
|
+
if (Object(value) !== value) {
|
|
4210
|
+
throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
|
|
4211
|
+
}
|
|
4212
|
+
if (isAwait) {
|
|
4213
|
+
var dispose = value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
|
|
4214
|
+
}
|
|
4215
|
+
if (dispose == null) {
|
|
4216
|
+
dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")];
|
|
4217
|
+
}
|
|
4218
|
+
if (typeof dispose !== "function") {
|
|
4219
|
+
throw new TypeError(`Property [Symbol.dispose] is not a function.`);
|
|
4220
|
+
}
|
|
4221
|
+
stack.push({
|
|
4222
|
+
v: value,
|
|
4223
|
+
d: dispose,
|
|
4224
|
+
a: isAwait
|
|
4225
|
+
});
|
|
4226
|
+
} else if (isAwait) {
|
|
4227
|
+
stack.push({
|
|
4228
|
+
d: value,
|
|
4229
|
+
a: isAwait
|
|
4230
|
+
});
|
|
4231
|
+
}
|
|
4232
|
+
return value;
|
|
4233
|
+
}
|
|
4234
|
+
return {
|
|
4235
|
+
e: empty,
|
|
4236
|
+
u: using.bind(null, false),
|
|
4237
|
+
a: using.bind(null, true),
|
|
4238
|
+
d: function() {
|
|
4239
|
+
var error = this.e;
|
|
4240
|
+
function next() {
|
|
4241
|
+
while (resource = stack.pop()) {
|
|
4242
|
+
try {
|
|
4243
|
+
var resource, disposalResult = resource.d && resource.d.call(resource.v);
|
|
4244
|
+
if (resource.a) {
|
|
4245
|
+
return Promise.resolve(disposalResult).then(next, err);
|
|
4246
|
+
}
|
|
4247
|
+
} catch (e) {
|
|
4248
|
+
return err(e);
|
|
4249
|
+
}
|
|
4250
|
+
}
|
|
4251
|
+
if (error !== empty)
|
|
4252
|
+
throw error;
|
|
4253
|
+
}
|
|
4254
|
+
function err(e) {
|
|
4255
|
+
error = error !== empty ? new _disposeSuppressedError(error, e) : e;
|
|
4256
|
+
return next();
|
|
4257
|
+
}
|
|
4258
|
+
return next();
|
|
4259
|
+
}
|
|
4260
|
+
};
|
|
4261
|
+
}
|
|
4262
|
+
var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
|
|
4020
4263
|
var DataSpace = class {
|
|
4021
4264
|
constructor(params) {
|
|
4022
4265
|
this._ctx = new Context8();
|
|
@@ -4024,7 +4267,9 @@ var DataSpace = class {
|
|
|
4024
4267
|
this._cache = void 0;
|
|
4025
4268
|
// TODO(dmaretskyi): Move into Space?
|
|
4026
4269
|
this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
|
|
4270
|
+
this._epochProcessingMutex = new Mutex2();
|
|
4027
4271
|
this._state = SpaceState2.CLOSED;
|
|
4272
|
+
this._databaseRoot = null;
|
|
4028
4273
|
/**
|
|
4029
4274
|
* Error for _state === SpaceState.ERROR.
|
|
4030
4275
|
*/
|
|
@@ -4048,11 +4293,11 @@ var DataSpace = class {
|
|
|
4048
4293
|
});
|
|
4049
4294
|
this._cache = params.cache;
|
|
4050
4295
|
this._state = params.initialState;
|
|
4051
|
-
|
|
4296
|
+
log15("new state", {
|
|
4052
4297
|
state: SpaceState2[this._state]
|
|
4053
4298
|
}, {
|
|
4054
|
-
F:
|
|
4055
|
-
L:
|
|
4299
|
+
F: __dxlog_file17,
|
|
4300
|
+
L: 146,
|
|
4056
4301
|
S: this,
|
|
4057
4302
|
C: (f, a) => f(...a)
|
|
4058
4303
|
});
|
|
@@ -4085,6 +4330,9 @@ var DataSpace = class {
|
|
|
4085
4330
|
get automergeSpaceState() {
|
|
4086
4331
|
return this._automergeSpaceState;
|
|
4087
4332
|
}
|
|
4333
|
+
get databaseRoot() {
|
|
4334
|
+
return this._databaseRoot;
|
|
4335
|
+
}
|
|
4088
4336
|
get _automergeInfo() {
|
|
4089
4337
|
return {
|
|
4090
4338
|
rootUrl: this._automergeSpaceState.rootUrl,
|
|
@@ -4101,14 +4349,15 @@ var DataSpace = class {
|
|
|
4101
4349
|
await this._gossip.open();
|
|
4102
4350
|
await this._notarizationPlugin.open();
|
|
4103
4351
|
await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
|
|
4352
|
+
await this._automergeSpaceState.open();
|
|
4104
4353
|
await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
|
|
4105
4354
|
await this._inner.open(new Context8());
|
|
4106
4355
|
this._state = SpaceState2.CONTROL_ONLY;
|
|
4107
|
-
|
|
4356
|
+
log15("new state", {
|
|
4108
4357
|
state: SpaceState2[this._state]
|
|
4109
4358
|
}, {
|
|
4110
|
-
F:
|
|
4111
|
-
L:
|
|
4359
|
+
F: __dxlog_file17,
|
|
4360
|
+
L: 217,
|
|
4112
4361
|
S: this,
|
|
4113
4362
|
C: (f, a) => f(...a)
|
|
4114
4363
|
});
|
|
@@ -4122,11 +4371,11 @@ var DataSpace = class {
|
|
|
4122
4371
|
async _close() {
|
|
4123
4372
|
await this._callbacks.beforeClose?.();
|
|
4124
4373
|
this._state = SpaceState2.CLOSED;
|
|
4125
|
-
|
|
4374
|
+
log15("new state", {
|
|
4126
4375
|
state: SpaceState2[this._state]
|
|
4127
4376
|
}, {
|
|
4128
|
-
F:
|
|
4129
|
-
L:
|
|
4377
|
+
F: __dxlog_file17,
|
|
4378
|
+
L: 231,
|
|
4130
4379
|
S: this,
|
|
4131
4380
|
C: (f, a) => f(...a)
|
|
4132
4381
|
});
|
|
@@ -4135,6 +4384,7 @@ var DataSpace = class {
|
|
|
4135
4384
|
await this.authVerifier.close();
|
|
4136
4385
|
await this._inner.close();
|
|
4137
4386
|
await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
|
|
4387
|
+
await this._automergeSpaceState.close();
|
|
4138
4388
|
await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
|
|
4139
4389
|
await this._notarizationPlugin.close();
|
|
4140
4390
|
await this._presence.close();
|
|
@@ -4156,26 +4406,26 @@ var DataSpace = class {
|
|
|
4156
4406
|
await this.initializeDataPipeline();
|
|
4157
4407
|
} catch (err) {
|
|
4158
4408
|
if (err instanceof CancelledError || err instanceof ContextDisposedError3) {
|
|
4159
|
-
|
|
4160
|
-
F:
|
|
4161
|
-
L:
|
|
4409
|
+
log15("data pipeline initialization cancelled", err, {
|
|
4410
|
+
F: __dxlog_file17,
|
|
4411
|
+
L: 265,
|
|
4162
4412
|
S: this,
|
|
4163
4413
|
C: (f, a) => f(...a)
|
|
4164
4414
|
});
|
|
4165
4415
|
return;
|
|
4166
4416
|
}
|
|
4167
|
-
|
|
4168
|
-
F:
|
|
4169
|
-
L:
|
|
4417
|
+
log15.error("Error initializing data pipeline", err, {
|
|
4418
|
+
F: __dxlog_file17,
|
|
4419
|
+
L: 269,
|
|
4170
4420
|
S: this,
|
|
4171
4421
|
C: (f, a) => f(...a)
|
|
4172
4422
|
});
|
|
4173
4423
|
this._state = SpaceState2.ERROR;
|
|
4174
|
-
|
|
4424
|
+
log15("new state", {
|
|
4175
4425
|
state: SpaceState2[this._state]
|
|
4176
4426
|
}, {
|
|
4177
|
-
F:
|
|
4178
|
-
L:
|
|
4427
|
+
F: __dxlog_file17,
|
|
4428
|
+
L: 271,
|
|
4179
4429
|
S: this,
|
|
4180
4430
|
C: (f, a) => f(...a)
|
|
4181
4431
|
});
|
|
@@ -4191,31 +4441,28 @@ var DataSpace = class {
|
|
|
4191
4441
|
throw new SystemError("Invalid operation");
|
|
4192
4442
|
}
|
|
4193
4443
|
this._state = SpaceState2.INITIALIZING;
|
|
4194
|
-
|
|
4444
|
+
log15("new state", {
|
|
4195
4445
|
state: SpaceState2[this._state]
|
|
4196
4446
|
}, {
|
|
4197
|
-
F:
|
|
4198
|
-
L:
|
|
4447
|
+
F: __dxlog_file17,
|
|
4448
|
+
L: 287,
|
|
4199
4449
|
S: this,
|
|
4200
4450
|
C: (f, a) => f(...a)
|
|
4201
4451
|
});
|
|
4202
4452
|
await this._initializeAndReadControlPipeline();
|
|
4203
|
-
await
|
|
4453
|
+
await sleep3(1);
|
|
4454
|
+
const ready = this.stateUpdate.waitForCondition(() => this._state === SpaceState2.READY);
|
|
4204
4455
|
this._automergeSpaceState.startProcessingRootDocs();
|
|
4205
|
-
await
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
L: 290,
|
|
4209
|
-
S: this,
|
|
4210
|
-
C: (f, a) => f(...a)
|
|
4211
|
-
});
|
|
4456
|
+
await ready;
|
|
4457
|
+
}
|
|
4458
|
+
async _enterReadyState() {
|
|
4212
4459
|
await this._callbacks.beforeReady?.();
|
|
4213
4460
|
this._state = SpaceState2.READY;
|
|
4214
|
-
|
|
4461
|
+
log15("new state", {
|
|
4215
4462
|
state: SpaceState2[this._state]
|
|
4216
4463
|
}, {
|
|
4217
|
-
F:
|
|
4218
|
-
L:
|
|
4464
|
+
F: __dxlog_file17,
|
|
4465
|
+
L: 306,
|
|
4219
4466
|
S: this,
|
|
4220
4467
|
C: (f, a) => f(...a)
|
|
4221
4468
|
});
|
|
@@ -4229,9 +4476,9 @@ var DataSpace = class {
|
|
|
4229
4476
|
});
|
|
4230
4477
|
this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
|
|
4231
4478
|
await this._createWritableFeeds();
|
|
4232
|
-
|
|
4233
|
-
F:
|
|
4234
|
-
L:
|
|
4479
|
+
log15("writable feeds created", void 0, {
|
|
4480
|
+
F: __dxlog_file17,
|
|
4481
|
+
L: 322,
|
|
4235
4482
|
S: this,
|
|
4236
4483
|
C: (f, a) => f(...a)
|
|
4237
4484
|
});
|
|
@@ -4289,57 +4536,66 @@ var DataSpace = class {
|
|
|
4289
4536
|
}
|
|
4290
4537
|
}
|
|
4291
4538
|
_onNewAutomergeRoot(rootUrl) {
|
|
4292
|
-
|
|
4539
|
+
log15("loading automerge root doc for space", {
|
|
4293
4540
|
space: this.key,
|
|
4294
4541
|
rootUrl
|
|
4295
4542
|
}, {
|
|
4296
|
-
F:
|
|
4297
|
-
L:
|
|
4543
|
+
F: __dxlog_file17,
|
|
4544
|
+
L: 388,
|
|
4298
4545
|
S: this,
|
|
4299
4546
|
C: (f, a) => f(...a)
|
|
4300
4547
|
});
|
|
4301
|
-
this._echoHost.replicateDocument(rootUrl);
|
|
4302
4548
|
const handle = this._echoHost.automergeRepo.find(rootUrl);
|
|
4303
4549
|
queueMicrotask(async () => {
|
|
4304
4550
|
try {
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
return;
|
|
4310
|
-
}
|
|
4311
|
-
const doc = handle.docSync() ?? failedInvariant();
|
|
4312
|
-
if (!doc.access?.spaceKey) {
|
|
4313
|
-
handle.change((doc2) => {
|
|
4314
|
-
doc2.access = {
|
|
4315
|
-
spaceKey: this.key.toHex()
|
|
4316
|
-
};
|
|
4317
|
-
});
|
|
4318
|
-
}
|
|
4319
|
-
if (!this._echoHost.roots.has(handle.documentId)) {
|
|
4320
|
-
await this._echoHost.openSpaceRoot(handle.url);
|
|
4321
|
-
} else {
|
|
4322
|
-
log13.warn("echo database root already exists", {
|
|
4323
|
-
space: this.key,
|
|
4324
|
-
rootUrl
|
|
4325
|
-
}, {
|
|
4326
|
-
F: __dxlog_file16,
|
|
4327
|
-
L: 403,
|
|
4328
|
-
S: this,
|
|
4329
|
-
C: (f, a) => f(...a)
|
|
4551
|
+
try {
|
|
4552
|
+
var _usingCtx = _using_ctx();
|
|
4553
|
+
await warnAfterTimeout(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
|
|
4554
|
+
await cancelWithContext5(this._ctx, handle.whenReady());
|
|
4330
4555
|
});
|
|
4556
|
+
if (this._ctx.disposed) {
|
|
4557
|
+
return;
|
|
4558
|
+
}
|
|
4559
|
+
const _guard = (
|
|
4560
|
+
// Ensure only one root is processed at a time.
|
|
4561
|
+
_usingCtx.u(await this._epochProcessingMutex.acquire())
|
|
4562
|
+
);
|
|
4563
|
+
const doc = handle.docSync() ?? failedInvariant();
|
|
4564
|
+
if (!doc.access?.spaceKey) {
|
|
4565
|
+
handle.change((doc2) => {
|
|
4566
|
+
doc2.access = {
|
|
4567
|
+
spaceKey: this.key.toHex()
|
|
4568
|
+
};
|
|
4569
|
+
});
|
|
4570
|
+
}
|
|
4571
|
+
const root = await this._echoHost.openSpaceRoot(handle.url);
|
|
4572
|
+
this._databaseRoot = root;
|
|
4573
|
+
if (root.getVersion() !== SpaceDocVersion.CURRENT) {
|
|
4574
|
+
if (this._state !== SpaceState2.REQUIRES_MIGRATION) {
|
|
4575
|
+
this._state = SpaceState2.REQUIRES_MIGRATION;
|
|
4576
|
+
this.stateUpdate.emit();
|
|
4577
|
+
}
|
|
4578
|
+
} else {
|
|
4579
|
+
if (this._state !== SpaceState2.READY) {
|
|
4580
|
+
await this._enterReadyState();
|
|
4581
|
+
}
|
|
4582
|
+
}
|
|
4583
|
+
} catch (_) {
|
|
4584
|
+
_usingCtx.e = _;
|
|
4585
|
+
} finally {
|
|
4586
|
+
_usingCtx.d();
|
|
4331
4587
|
}
|
|
4332
4588
|
} catch (err) {
|
|
4333
4589
|
if (err instanceof ContextDisposedError3) {
|
|
4334
4590
|
return;
|
|
4335
4591
|
}
|
|
4336
|
-
|
|
4592
|
+
log15.warn("error loading automerge root doc", {
|
|
4337
4593
|
space: this.key,
|
|
4338
4594
|
rootUrl,
|
|
4339
4595
|
err
|
|
4340
4596
|
}, {
|
|
4341
|
-
F:
|
|
4342
|
-
L:
|
|
4597
|
+
F: __dxlog_file17,
|
|
4598
|
+
L: 431,
|
|
4343
4599
|
S: this,
|
|
4344
4600
|
C: (f, a) => f(...a)
|
|
4345
4601
|
});
|
|
@@ -4362,148 +4618,34 @@ var DataSpace = class {
|
|
|
4362
4618
|
});
|
|
4363
4619
|
}
|
|
4364
4620
|
async createEpoch(options) {
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
case CreateEpochRequest.Migration.NONE:
|
|
4369
|
-
{
|
|
4370
|
-
epoch = {
|
|
4371
|
-
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
4372
|
-
number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
|
|
4373
|
-
timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe3(),
|
|
4374
|
-
automergeRoot: this._automergeSpaceState.lastEpoch?.subject.assertion?.automergeRoot
|
|
4375
|
-
};
|
|
4376
|
-
}
|
|
4377
|
-
break;
|
|
4378
|
-
case CreateEpochRequest.Migration.INIT_AUTOMERGE:
|
|
4379
|
-
{
|
|
4380
|
-
const document = this._echoHost.automergeRepo.create();
|
|
4381
|
-
epoch = {
|
|
4382
|
-
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
4383
|
-
number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
|
|
4384
|
-
timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe3(),
|
|
4385
|
-
automergeRoot: document.url
|
|
4386
|
-
};
|
|
4387
|
-
}
|
|
4388
|
-
break;
|
|
4389
|
-
case CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
|
|
4390
|
-
{
|
|
4391
|
-
const currentRootUrl = this._automergeSpaceState.rootUrl;
|
|
4392
|
-
const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
|
|
4393
|
-
await cancelWithContext4(this._ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
|
|
4394
|
-
const newRoot = this._echoHost.automergeRepo.create(rootHandle.docSync());
|
|
4395
|
-
await this._echoHost.automergeRepo.flush([
|
|
4396
|
-
newRoot.documentId
|
|
4397
|
-
]);
|
|
4398
|
-
invariant13(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
|
|
4399
|
-
F: __dxlog_file16,
|
|
4400
|
-
L: 460,
|
|
4401
|
-
S: this,
|
|
4402
|
-
A: [
|
|
4403
|
-
"typeof newRoot.url === 'string' && newRoot.url.length > 0",
|
|
4404
|
-
""
|
|
4405
|
-
]
|
|
4406
|
-
});
|
|
4407
|
-
epoch = {
|
|
4408
|
-
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
4409
|
-
number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
|
|
4410
|
-
timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe3(),
|
|
4411
|
-
automergeRoot: newRoot.url
|
|
4412
|
-
};
|
|
4413
|
-
}
|
|
4414
|
-
break;
|
|
4415
|
-
case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
|
|
4416
|
-
{
|
|
4417
|
-
log13.info("Fragmenting", void 0, {
|
|
4418
|
-
F: __dxlog_file16,
|
|
4419
|
-
L: 472,
|
|
4420
|
-
S: this,
|
|
4421
|
-
C: (f, a) => f(...a)
|
|
4422
|
-
});
|
|
4423
|
-
const currentRootUrl = this._automergeSpaceState.rootUrl;
|
|
4424
|
-
const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
|
|
4425
|
-
await cancelWithContext4(this._ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
|
|
4426
|
-
const objects = Object.entries(rootHandle.docSync().objects);
|
|
4427
|
-
const properties = findPropertiesObject(rootHandle.docSync());
|
|
4428
|
-
const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
|
|
4429
|
-
invariant13(properties, "Properties not found", {
|
|
4430
|
-
F: __dxlog_file16,
|
|
4431
|
-
L: 482,
|
|
4432
|
-
S: this,
|
|
4433
|
-
A: [
|
|
4434
|
-
"properties",
|
|
4435
|
-
"'Properties not found'"
|
|
4436
|
-
]
|
|
4437
|
-
});
|
|
4438
|
-
const newSpaceDoc = {
|
|
4439
|
-
...rootHandle.docSync(),
|
|
4440
|
-
objects: Object.fromEntries([
|
|
4441
|
-
properties
|
|
4442
|
-
])
|
|
4443
|
-
};
|
|
4444
|
-
const newRoot = this._echoHost.automergeRepo.create(newSpaceDoc);
|
|
4445
|
-
invariant13(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
|
|
4446
|
-
F: __dxlog_file16,
|
|
4447
|
-
L: 487,
|
|
4448
|
-
S: this,
|
|
4449
|
-
A: [
|
|
4450
|
-
"typeof newRoot.url === 'string' && newRoot.url.length > 0",
|
|
4451
|
-
""
|
|
4452
|
-
]
|
|
4453
|
-
});
|
|
4454
|
-
const docLoader = new AutomergeDocumentLoaderImpl(await createIdFromSpaceKey(this.key), this._echoHost.automergeRepo, this.key);
|
|
4455
|
-
await docLoader.loadSpaceRootDocHandle(this._ctx, {
|
|
4456
|
-
rootUrl: newRoot.url
|
|
4457
|
-
});
|
|
4458
|
-
otherObjects.forEach(([key, value]) => {
|
|
4459
|
-
const handle = docLoader.createDocumentForObject(key);
|
|
4460
|
-
handle.change((doc) => {
|
|
4461
|
-
assignDeep(doc, [
|
|
4462
|
-
"objects",
|
|
4463
|
-
key
|
|
4464
|
-
], value);
|
|
4465
|
-
});
|
|
4466
|
-
});
|
|
4467
|
-
epoch = {
|
|
4468
|
-
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
4469
|
-
number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
|
|
4470
|
-
timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe3(),
|
|
4471
|
-
automergeRoot: newRoot.url
|
|
4472
|
-
};
|
|
4473
|
-
}
|
|
4474
|
-
break;
|
|
4475
|
-
case CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT:
|
|
4476
|
-
{
|
|
4477
|
-
invariant13(options.newAutomergeRoot, void 0, {
|
|
4478
|
-
F: __dxlog_file16,
|
|
4479
|
-
L: 517,
|
|
4480
|
-
S: this,
|
|
4481
|
-
A: [
|
|
4482
|
-
"options.newAutomergeRoot",
|
|
4483
|
-
""
|
|
4484
|
-
]
|
|
4485
|
-
});
|
|
4486
|
-
epoch = {
|
|
4487
|
-
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
4488
|
-
number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
|
|
4489
|
-
timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe3(),
|
|
4490
|
-
automergeRoot: options.newAutomergeRoot
|
|
4491
|
-
};
|
|
4492
|
-
}
|
|
4493
|
-
break;
|
|
4494
|
-
}
|
|
4495
|
-
if (!epoch) {
|
|
4496
|
-
return;
|
|
4621
|
+
const ctx = this._ctx.derive();
|
|
4622
|
+
if (!options?.migration) {
|
|
4623
|
+
return null;
|
|
4497
4624
|
}
|
|
4625
|
+
const { newRoot } = await runEpochMigration(ctx, {
|
|
4626
|
+
repo: this._echoHost.automergeRepo,
|
|
4627
|
+
spaceId: this.id,
|
|
4628
|
+
spaceKey: this.key,
|
|
4629
|
+
migration: options.migration,
|
|
4630
|
+
currentRoot: this._automergeSpaceState.rootUrl ?? null,
|
|
4631
|
+
newAutomergeRoot: options.newAutomergeRoot
|
|
4632
|
+
});
|
|
4633
|
+
const epoch = {
|
|
4634
|
+
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
4635
|
+
number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
|
|
4636
|
+
timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe3(),
|
|
4637
|
+
automergeRoot: newRoot ?? this._automergeSpaceState.rootUrl
|
|
4638
|
+
};
|
|
4639
|
+
const credential = await this._signingContext.credentialSigner.createCredential({
|
|
4640
|
+
subject: this.key,
|
|
4641
|
+
assertion: {
|
|
4642
|
+
"@type": "dxos.halo.credentials.Epoch",
|
|
4643
|
+
...epoch
|
|
4644
|
+
}
|
|
4645
|
+
});
|
|
4498
4646
|
const receipt = await this.inner.controlPipeline.writer.write({
|
|
4499
4647
|
credential: {
|
|
4500
|
-
credential
|
|
4501
|
-
subject: this.key,
|
|
4502
|
-
assertion: {
|
|
4503
|
-
"@type": "dxos.halo.credentials.Epoch",
|
|
4504
|
-
...epoch
|
|
4505
|
-
}
|
|
4506
|
-
})
|
|
4648
|
+
credential
|
|
4507
4649
|
}
|
|
4508
4650
|
});
|
|
4509
4651
|
await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe3([
|
|
@@ -4513,6 +4655,7 @@ var DataSpace = class {
|
|
|
4513
4655
|
]
|
|
4514
4656
|
]));
|
|
4515
4657
|
await this._echoHost.updateIndexes();
|
|
4658
|
+
return credential;
|
|
4516
4659
|
}
|
|
4517
4660
|
async activate() {
|
|
4518
4661
|
if (![
|
|
@@ -4534,11 +4677,11 @@ var DataSpace = class {
|
|
|
4534
4677
|
await this._close();
|
|
4535
4678
|
}
|
|
4536
4679
|
this._state = SpaceState2.INACTIVE;
|
|
4537
|
-
|
|
4680
|
+
log15("new state", {
|
|
4538
4681
|
state: SpaceState2[this._state]
|
|
4539
4682
|
}, {
|
|
4540
|
-
F:
|
|
4541
|
-
L:
|
|
4683
|
+
F: __dxlog_file17,
|
|
4684
|
+
L: 512,
|
|
4542
4685
|
S: this,
|
|
4543
4686
|
C: (f, a) => f(...a)
|
|
4544
4687
|
});
|
|
@@ -4593,36 +4736,25 @@ DataSpace = _ts_decorate4([
|
|
|
4593
4736
|
trackLeaks("open", "close"),
|
|
4594
4737
|
trace6.resource()
|
|
4595
4738
|
], DataSpace);
|
|
4596
|
-
var findPropertiesObject = (spaceDoc) => {
|
|
4597
|
-
for (const id in spaceDoc.objects ?? {}) {
|
|
4598
|
-
const obj = spaceDoc.objects[id];
|
|
4599
|
-
if (obj.system.type?.itemId === TYPE_PROPERTIES) {
|
|
4600
|
-
return [
|
|
4601
|
-
id,
|
|
4602
|
-
obj
|
|
4603
|
-
];
|
|
4604
|
-
}
|
|
4605
|
-
}
|
|
4606
|
-
return void 0;
|
|
4607
|
-
};
|
|
4608
4739
|
|
|
4609
4740
|
// packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
|
|
4610
4741
|
import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
|
|
4611
4742
|
import { PropertiesType } from "@dxos/client-protocol";
|
|
4612
|
-
import {
|
|
4743
|
+
import { Context as Context9, cancelWithContext as cancelWithContext6 } from "@dxos/context";
|
|
4613
4744
|
import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
|
|
4745
|
+
import { convertLegacyReferences as convertLegacyReferences2, findInlineObjectOfType as findInlineObjectOfType2 } from "@dxos/echo-db";
|
|
4614
4746
|
import { AuthStatus } from "@dxos/echo-pipeline";
|
|
4615
|
-
import { encodeReference } from "@dxos/echo-protocol";
|
|
4616
|
-
import { getTypeReference } from "@dxos/echo-schema";
|
|
4747
|
+
import { LEGACY_TYPE_PROPERTIES, SpaceDocVersion as SpaceDocVersion2, encodeReference } from "@dxos/echo-protocol";
|
|
4748
|
+
import { TYPE_PROPERTIES as TYPE_PROPERTIES2, generateEchoId, getTypeReference } from "@dxos/echo-schema";
|
|
4617
4749
|
import { invariant as invariant14 } from "@dxos/invariant";
|
|
4618
4750
|
import { PublicKey as PublicKey11 } from "@dxos/keys";
|
|
4619
|
-
import { log as
|
|
4751
|
+
import { log as log16 } from "@dxos/log";
|
|
4620
4752
|
import { trace as Trace2 } from "@dxos/protocols";
|
|
4621
4753
|
import { Invitation as Invitation7, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
|
|
4622
4754
|
import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
4623
4755
|
import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extension-gossip";
|
|
4624
4756
|
import { trace as trace7 } from "@dxos/tracing";
|
|
4625
|
-
import {
|
|
4757
|
+
import { ComplexMap as ComplexMap3, assignDeep as assignDeep2, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
|
|
4626
4758
|
|
|
4627
4759
|
// packages/sdk/client-services/src/packlets/spaces/genesis.ts
|
|
4628
4760
|
import { createCredential } from "@dxos/credentials";
|
|
@@ -4705,7 +4837,7 @@ function _ts_decorate5(decorators, target, key, desc) {
|
|
|
4705
4837
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
4706
4838
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
4707
4839
|
}
|
|
4708
|
-
var
|
|
4840
|
+
var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
|
|
4709
4841
|
var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
|
|
4710
4842
|
var PRESENCE_OFFLINE_TIMEOUT = 2e4;
|
|
4711
4843
|
var DEFAULT_SPACE_KEY = "__DEFAULT__";
|
|
@@ -4732,7 +4864,7 @@ var DataSpaceManager = class {
|
|
|
4732
4864
|
const rootUrl = space.automergeSpaceState.rootUrl;
|
|
4733
4865
|
const rootHandle = rootUrl ? this._echoHost.automergeRepo.find(rootUrl) : void 0;
|
|
4734
4866
|
const rootDoc = rootHandle?.docSync();
|
|
4735
|
-
const properties = rootDoc &&
|
|
4867
|
+
const properties = rootDoc && findInlineObjectOfType2(rootDoc, TYPE_PROPERTIES2);
|
|
4736
4868
|
return {
|
|
4737
4869
|
key: space.key.toHex(),
|
|
4738
4870
|
state: SpaceState3[space.state],
|
|
@@ -4752,46 +4884,46 @@ var DataSpaceManager = class {
|
|
|
4752
4884
|
return this._spaces;
|
|
4753
4885
|
}
|
|
4754
4886
|
async open() {
|
|
4755
|
-
|
|
4756
|
-
F:
|
|
4757
|
-
L:
|
|
4887
|
+
log16("open", void 0, {
|
|
4888
|
+
F: __dxlog_file18,
|
|
4889
|
+
L: 146,
|
|
4758
4890
|
S: this,
|
|
4759
4891
|
C: (f, a) => f(...a)
|
|
4760
4892
|
});
|
|
4761
|
-
|
|
4893
|
+
log16.trace("dxos.echo.data-space-manager.open", Trace2.begin({
|
|
4762
4894
|
id: this._instanceId
|
|
4763
4895
|
}), {
|
|
4764
|
-
F:
|
|
4765
|
-
L:
|
|
4896
|
+
F: __dxlog_file18,
|
|
4897
|
+
L: 147,
|
|
4766
4898
|
S: this,
|
|
4767
4899
|
C: (f, a) => f(...a)
|
|
4768
4900
|
});
|
|
4769
|
-
|
|
4901
|
+
log16("metadata loaded", {
|
|
4770
4902
|
spaces: this._metadataStore.spaces.length
|
|
4771
4903
|
}, {
|
|
4772
|
-
F:
|
|
4773
|
-
L:
|
|
4904
|
+
F: __dxlog_file18,
|
|
4905
|
+
L: 148,
|
|
4774
4906
|
S: this,
|
|
4775
4907
|
C: (f, a) => f(...a)
|
|
4776
4908
|
});
|
|
4777
4909
|
await forEachAsync(this._metadataStore.spaces, async (spaceMetadata) => {
|
|
4778
4910
|
try {
|
|
4779
|
-
|
|
4911
|
+
log16("load space", {
|
|
4780
4912
|
spaceMetadata
|
|
4781
4913
|
}, {
|
|
4782
|
-
F:
|
|
4783
|
-
L:
|
|
4914
|
+
F: __dxlog_file18,
|
|
4915
|
+
L: 152,
|
|
4784
4916
|
S: this,
|
|
4785
4917
|
C: (f, a) => f(...a)
|
|
4786
4918
|
});
|
|
4787
4919
|
await this._constructSpace(spaceMetadata);
|
|
4788
4920
|
} catch (err) {
|
|
4789
|
-
|
|
4921
|
+
log16.error("Error loading space", {
|
|
4790
4922
|
spaceMetadata,
|
|
4791
4923
|
err
|
|
4792
4924
|
}, {
|
|
4793
|
-
F:
|
|
4794
|
-
L:
|
|
4925
|
+
F: __dxlog_file18,
|
|
4926
|
+
L: 155,
|
|
4795
4927
|
S: this,
|
|
4796
4928
|
C: (f, a) => f(...a)
|
|
4797
4929
|
});
|
|
@@ -4799,19 +4931,19 @@ var DataSpaceManager = class {
|
|
|
4799
4931
|
});
|
|
4800
4932
|
this._isOpen = true;
|
|
4801
4933
|
this.updated.emit();
|
|
4802
|
-
|
|
4934
|
+
log16.trace("dxos.echo.data-space-manager.open", Trace2.end({
|
|
4803
4935
|
id: this._instanceId
|
|
4804
4936
|
}), {
|
|
4805
|
-
F:
|
|
4806
|
-
L:
|
|
4937
|
+
F: __dxlog_file18,
|
|
4938
|
+
L: 162,
|
|
4807
4939
|
S: this,
|
|
4808
4940
|
C: (f, a) => f(...a)
|
|
4809
4941
|
});
|
|
4810
4942
|
}
|
|
4811
4943
|
async close() {
|
|
4812
|
-
|
|
4813
|
-
F:
|
|
4814
|
-
L:
|
|
4944
|
+
log16("close", void 0, {
|
|
4945
|
+
F: __dxlog_file18,
|
|
4946
|
+
L: 167,
|
|
4815
4947
|
S: this,
|
|
4816
4948
|
C: (f, a) => f(...a)
|
|
4817
4949
|
});
|
|
@@ -4827,8 +4959,8 @@ var DataSpaceManager = class {
|
|
|
4827
4959
|
*/
|
|
4828
4960
|
async createSpace() {
|
|
4829
4961
|
invariant14(this._isOpen, "Not open.", {
|
|
4830
|
-
F:
|
|
4831
|
-
L:
|
|
4962
|
+
F: __dxlog_file18,
|
|
4963
|
+
L: 181,
|
|
4832
4964
|
S: this,
|
|
4833
4965
|
A: [
|
|
4834
4966
|
"this._isOpen",
|
|
@@ -4845,11 +4977,11 @@ var DataSpaceManager = class {
|
|
|
4845
4977
|
dataFeedKey,
|
|
4846
4978
|
state: SpaceState3.ACTIVE
|
|
4847
4979
|
};
|
|
4848
|
-
|
|
4980
|
+
log16("creating space...", {
|
|
4849
4981
|
spaceKey
|
|
4850
4982
|
}, {
|
|
4851
|
-
F:
|
|
4852
|
-
L:
|
|
4983
|
+
F: __dxlog_file18,
|
|
4984
|
+
L: 193,
|
|
4853
4985
|
S: this,
|
|
4854
4986
|
C: (f, a) => f(...a)
|
|
4855
4987
|
});
|
|
@@ -4860,8 +4992,8 @@ var DataSpaceManager = class {
|
|
|
4860
4992
|
await this._metadataStore.addSpace(metadata);
|
|
4861
4993
|
const memberCredential = credentials[1];
|
|
4862
4994
|
invariant14(getCredentialAssertion3(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
4863
|
-
F:
|
|
4864
|
-
L:
|
|
4995
|
+
F: __dxlog_file18,
|
|
4996
|
+
L: 203,
|
|
4865
4997
|
S: this,
|
|
4866
4998
|
A: [
|
|
4867
4999
|
"getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
|
|
@@ -4874,9 +5006,31 @@ var DataSpaceManager = class {
|
|
|
4874
5006
|
return space;
|
|
4875
5007
|
}
|
|
4876
5008
|
async isDefaultSpace(space) {
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
5009
|
+
if (!space.databaseRoot) {
|
|
5010
|
+
return false;
|
|
5011
|
+
}
|
|
5012
|
+
switch (space.databaseRoot.getVersion()) {
|
|
5013
|
+
case SpaceDocVersion2.CURRENT: {
|
|
5014
|
+
const [_, properties] = findInlineObjectOfType2(space.databaseRoot.docSync(), TYPE_PROPERTIES2) ?? [];
|
|
5015
|
+
return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
|
|
5016
|
+
}
|
|
5017
|
+
case SpaceDocVersion2.LEGACY: {
|
|
5018
|
+
const convertedDoc = await convertLegacyReferences2(space.databaseRoot.docSync());
|
|
5019
|
+
const [_, properties] = findInlineObjectOfType2(convertedDoc, LEGACY_TYPE_PROPERTIES) ?? [];
|
|
5020
|
+
return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
|
|
5021
|
+
}
|
|
5022
|
+
default:
|
|
5023
|
+
log16.warn("unknown space version", {
|
|
5024
|
+
version: space.databaseRoot.getVersion(),
|
|
5025
|
+
spaceId: space.id
|
|
5026
|
+
}, {
|
|
5027
|
+
F: __dxlog_file18,
|
|
5028
|
+
L: 228,
|
|
5029
|
+
S: this,
|
|
5030
|
+
C: (f, a) => f(...a)
|
|
5031
|
+
});
|
|
5032
|
+
return false;
|
|
5033
|
+
}
|
|
4880
5034
|
}
|
|
4881
5035
|
async createDefaultSpace() {
|
|
4882
5036
|
const space = await this.createSpace();
|
|
@@ -4892,7 +5046,7 @@ var DataSpaceManager = class {
|
|
|
4892
5046
|
keys: []
|
|
4893
5047
|
}
|
|
4894
5048
|
};
|
|
4895
|
-
const propertiesId =
|
|
5049
|
+
const propertiesId = generateEchoId();
|
|
4896
5050
|
document.change((doc) => {
|
|
4897
5051
|
assignDeep2(doc, [
|
|
4898
5052
|
"objects",
|
|
@@ -4905,8 +5059,8 @@ var DataSpaceManager = class {
|
|
|
4905
5059
|
async _getSpaceRootDocument(space) {
|
|
4906
5060
|
const automergeIndex = space.automergeSpaceState.rootUrl;
|
|
4907
5061
|
invariant14(automergeIndex, void 0, {
|
|
4908
|
-
F:
|
|
4909
|
-
L:
|
|
5062
|
+
F: __dxlog_file18,
|
|
5063
|
+
L: 261,
|
|
4910
5064
|
S: this,
|
|
4911
5065
|
A: [
|
|
4912
5066
|
"automergeIndex",
|
|
@@ -4919,17 +5073,17 @@ var DataSpaceManager = class {
|
|
|
4919
5073
|
}
|
|
4920
5074
|
// TODO(burdon): Rename join space.
|
|
4921
5075
|
async acceptSpace(opts) {
|
|
4922
|
-
|
|
5076
|
+
log16("accept space", {
|
|
4923
5077
|
opts
|
|
4924
5078
|
}, {
|
|
4925
|
-
F:
|
|
4926
|
-
L:
|
|
5079
|
+
F: __dxlog_file18,
|
|
5080
|
+
L: 270,
|
|
4927
5081
|
S: this,
|
|
4928
5082
|
C: (f, a) => f(...a)
|
|
4929
5083
|
});
|
|
4930
5084
|
invariant14(this._isOpen, "Not open.", {
|
|
4931
|
-
F:
|
|
4932
|
-
L:
|
|
5085
|
+
F: __dxlog_file18,
|
|
5086
|
+
L: 271,
|
|
4933
5087
|
S: this,
|
|
4934
5088
|
A: [
|
|
4935
5089
|
"this._isOpen",
|
|
@@ -4937,8 +5091,8 @@ var DataSpaceManager = class {
|
|
|
4937
5091
|
]
|
|
4938
5092
|
});
|
|
4939
5093
|
invariant14(!this._spaces.has(opts.spaceKey), "Space already exists.", {
|
|
4940
|
-
F:
|
|
4941
|
-
L:
|
|
5094
|
+
F: __dxlog_file18,
|
|
5095
|
+
L: 272,
|
|
4942
5096
|
S: this,
|
|
4943
5097
|
A: [
|
|
4944
5098
|
"!this._spaces.has(opts.spaceKey)",
|
|
@@ -4964,17 +5118,17 @@ var DataSpaceManager = class {
|
|
|
4964
5118
|
* TODO(dmaretskyi): Consider removing.
|
|
4965
5119
|
*/
|
|
4966
5120
|
async waitUntilSpaceReady(spaceKey) {
|
|
4967
|
-
await
|
|
5121
|
+
await cancelWithContext6(this._ctx, this.updated.waitForCondition(() => {
|
|
4968
5122
|
const space = this._spaces.get(spaceKey);
|
|
4969
5123
|
return !!space && space.state === SpaceState3.READY;
|
|
4970
5124
|
}));
|
|
4971
5125
|
}
|
|
4972
5126
|
async _constructSpace(metadata) {
|
|
4973
|
-
|
|
5127
|
+
log16("construct space", {
|
|
4974
5128
|
metadata
|
|
4975
5129
|
}, {
|
|
4976
|
-
F:
|
|
4977
|
-
L:
|
|
5130
|
+
F: __dxlog_file18,
|
|
5131
|
+
L: 306,
|
|
4978
5132
|
S: this,
|
|
4979
5133
|
C: (f, a) => f(...a)
|
|
4980
5134
|
});
|
|
@@ -5010,9 +5164,9 @@ var DataSpaceManager = class {
|
|
|
5010
5164
|
session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
|
|
5011
5165
|
},
|
|
5012
5166
|
onAuthFailure: () => {
|
|
5013
|
-
|
|
5014
|
-
F:
|
|
5015
|
-
L:
|
|
5167
|
+
log16.warn("auth failure", void 0, {
|
|
5168
|
+
F: __dxlog_file18,
|
|
5169
|
+
L: 343,
|
|
5016
5170
|
S: this,
|
|
5017
5171
|
C: (f, a) => f(...a)
|
|
5018
5172
|
});
|
|
@@ -5041,22 +5195,22 @@ var DataSpaceManager = class {
|
|
|
5041
5195
|
signingContext: this._signingContext,
|
|
5042
5196
|
callbacks: {
|
|
5043
5197
|
beforeReady: async () => {
|
|
5044
|
-
|
|
5198
|
+
log16("before space ready", {
|
|
5045
5199
|
space: space.key
|
|
5046
5200
|
}, {
|
|
5047
|
-
F:
|
|
5048
|
-
L:
|
|
5201
|
+
F: __dxlog_file18,
|
|
5202
|
+
L: 370,
|
|
5049
5203
|
S: this,
|
|
5050
5204
|
C: (f, a) => f(...a)
|
|
5051
5205
|
});
|
|
5052
5206
|
},
|
|
5053
5207
|
afterReady: async () => {
|
|
5054
|
-
|
|
5208
|
+
log16("after space ready", {
|
|
5055
5209
|
space: space.key,
|
|
5056
5210
|
open: this._isOpen
|
|
5057
5211
|
}, {
|
|
5058
|
-
F:
|
|
5059
|
-
L:
|
|
5212
|
+
F: __dxlog_file18,
|
|
5213
|
+
L: 373,
|
|
5060
5214
|
S: this,
|
|
5061
5215
|
C: (f, a) => f(...a)
|
|
5062
5216
|
});
|
|
@@ -5071,11 +5225,11 @@ var DataSpaceManager = class {
|
|
|
5071
5225
|
}
|
|
5072
5226
|
},
|
|
5073
5227
|
beforeClose: async () => {
|
|
5074
|
-
|
|
5228
|
+
log16("before space close", {
|
|
5075
5229
|
space: space.key
|
|
5076
5230
|
}, {
|
|
5077
|
-
F:
|
|
5078
|
-
L:
|
|
5231
|
+
F: __dxlog_file18,
|
|
5232
|
+
L: 381,
|
|
5079
5233
|
S: this,
|
|
5080
5234
|
C: (f, a) => f(...a)
|
|
5081
5235
|
});
|
|
@@ -5106,17 +5260,17 @@ var DataSpaceManager = class {
|
|
|
5106
5260
|
return (s && member.role === SpaceMember6.Role.REMOVED !== (s.authStatus === AuthStatus.FAILURE)) ?? false;
|
|
5107
5261
|
});
|
|
5108
5262
|
sessionsToClose.forEach((session) => {
|
|
5109
|
-
void session.close().catch(
|
|
5263
|
+
void session.close().catch(log16.error);
|
|
5110
5264
|
});
|
|
5111
5265
|
closedSessions += sessionsToClose.length;
|
|
5112
5266
|
}
|
|
5113
|
-
|
|
5267
|
+
log16("processed member role changes", {
|
|
5114
5268
|
roleChangeCount: memberInfo.length,
|
|
5115
5269
|
peersOnline: presence.getPeersOnline().length,
|
|
5116
5270
|
closedSessions
|
|
5117
5271
|
}, {
|
|
5118
|
-
F:
|
|
5119
|
-
L:
|
|
5272
|
+
F: __dxlog_file18,
|
|
5273
|
+
L: 417,
|
|
5120
5274
|
S: this,
|
|
5121
5275
|
C: (f, a) => f(...a)
|
|
5122
5276
|
});
|
|
@@ -5127,15 +5281,15 @@ var DataSpaceManager = class {
|
|
|
5127
5281
|
if (role === SpaceMember6.Role.REMOVED) {
|
|
5128
5282
|
const session = peerState.peerId && space.protocol.sessions.get(peerState.peerId);
|
|
5129
5283
|
if (session != null) {
|
|
5130
|
-
|
|
5284
|
+
log16("closing a session with a removed peer", {
|
|
5131
5285
|
peerId: peerState.peerId
|
|
5132
5286
|
}, {
|
|
5133
|
-
F:
|
|
5134
|
-
L:
|
|
5287
|
+
F: __dxlog_file18,
|
|
5288
|
+
L: 431,
|
|
5135
5289
|
S: this,
|
|
5136
5290
|
C: (f, a) => f(...a)
|
|
5137
5291
|
});
|
|
5138
|
-
void session.close().catch(
|
|
5292
|
+
void session.close().catch(log16.error);
|
|
5139
5293
|
}
|
|
5140
5294
|
}
|
|
5141
5295
|
}
|
|
@@ -5198,11 +5352,11 @@ import { createAdmissionCredentials as createAdmissionCredentials2, getCredentia
|
|
|
5198
5352
|
import { raise as raise2 } from "@dxos/debug";
|
|
5199
5353
|
import { writeMessages as writeMessages3 } from "@dxos/feed-store";
|
|
5200
5354
|
import { invariant as invariant15 } from "@dxos/invariant";
|
|
5201
|
-
import { log as
|
|
5355
|
+
import { log as log17 } from "@dxos/log";
|
|
5202
5356
|
import { ApiError, SpaceNotFoundError as SpaceNotFoundError2, encodeError, IdentityNotInitializedError, AuthorizationError as AuthorizationError2 } from "@dxos/protocols";
|
|
5203
5357
|
import { SpaceMember as SpaceMember7, SpaceState as SpaceState4 } from "@dxos/protocols/proto/dxos/client/services";
|
|
5204
5358
|
import { trace as trace8 } from "@dxos/tracing";
|
|
5205
|
-
var
|
|
5359
|
+
var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
|
|
5206
5360
|
var SpacesServiceImpl = class {
|
|
5207
5361
|
constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
|
|
5208
5362
|
this._identityManager = _identityManager;
|
|
@@ -5246,8 +5400,8 @@ var SpacesServiceImpl = class {
|
|
|
5246
5400
|
}
|
|
5247
5401
|
const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
|
|
5248
5402
|
invariant15(credentials[0].credential, void 0, {
|
|
5249
|
-
F:
|
|
5250
|
-
L:
|
|
5403
|
+
F: __dxlog_file19,
|
|
5404
|
+
L: 98,
|
|
5251
5405
|
S: this,
|
|
5252
5406
|
A: [
|
|
5253
5407
|
"credentials[0].credential",
|
|
@@ -5256,8 +5410,8 @@ var SpacesServiceImpl = class {
|
|
|
5256
5410
|
});
|
|
5257
5411
|
const spaceMemberCredential = credentials[0].credential.credential;
|
|
5258
5412
|
invariant15(getCredentialAssertion4(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
5259
|
-
F:
|
|
5260
|
-
L:
|
|
5413
|
+
F: __dxlog_file19,
|
|
5414
|
+
L: 100,
|
|
5261
5415
|
S: this,
|
|
5262
5416
|
A: [
|
|
5263
5417
|
"getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
|
|
@@ -5271,11 +5425,11 @@ var SpacesServiceImpl = class {
|
|
|
5271
5425
|
const scheduler = new UpdateScheduler(ctx, async () => {
|
|
5272
5426
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
5273
5427
|
const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
|
|
5274
|
-
|
|
5428
|
+
log17("update", {
|
|
5275
5429
|
spaces
|
|
5276
5430
|
}, {
|
|
5277
|
-
F:
|
|
5278
|
-
L:
|
|
5431
|
+
F: __dxlog_file19,
|
|
5432
|
+
L: 111,
|
|
5279
5433
|
S: this,
|
|
5280
5434
|
C: (f, a) => f(...a)
|
|
5281
5435
|
});
|
|
@@ -5293,7 +5447,15 @@ var SpacesServiceImpl = class {
|
|
|
5293
5447
|
const subscribeSpaces = () => {
|
|
5294
5448
|
subscriptions.clear();
|
|
5295
5449
|
for (const space of dataSpaceManager.spaces.values()) {
|
|
5296
|
-
|
|
5450
|
+
let lastState;
|
|
5451
|
+
subscriptions.add(space.stateUpdate.on(ctx, () => {
|
|
5452
|
+
if (space.state !== lastState) {
|
|
5453
|
+
scheduler.forceTrigger();
|
|
5454
|
+
} else {
|
|
5455
|
+
scheduler.trigger();
|
|
5456
|
+
}
|
|
5457
|
+
lastState = space.state;
|
|
5458
|
+
}));
|
|
5297
5459
|
subscriptions.add(space.presence.updated.on(ctx, () => scheduler.trigger()));
|
|
5298
5460
|
subscriptions.add(space.automergeSpaceState.onNewEpoch.on(ctx, () => scheduler.trigger()));
|
|
5299
5461
|
subscriptions.add(space.inner.controlPipeline.state.timeframeUpdate.on(ctx, () => scheduler.trigger()));
|
|
@@ -5358,8 +5520,8 @@ var SpacesServiceImpl = class {
|
|
|
5358
5520
|
});
|
|
5359
5521
|
} else {
|
|
5360
5522
|
invariant15(!credential.id, "Id on unsigned credentials is not allowed", {
|
|
5361
|
-
F:
|
|
5362
|
-
L:
|
|
5523
|
+
F: __dxlog_file19,
|
|
5524
|
+
L: 209,
|
|
5363
5525
|
S: this,
|
|
5364
5526
|
A: [
|
|
5365
5527
|
"!credential.id",
|
|
@@ -5367,8 +5529,8 @@ var SpacesServiceImpl = class {
|
|
|
5367
5529
|
]
|
|
5368
5530
|
});
|
|
5369
5531
|
invariant15(this._identityManager.identity, "Identity is not available", {
|
|
5370
|
-
F:
|
|
5371
|
-
L:
|
|
5532
|
+
F: __dxlog_file19,
|
|
5533
|
+
L: 210,
|
|
5372
5534
|
S: this,
|
|
5373
5535
|
A: [
|
|
5374
5536
|
"this._identityManager.identity",
|
|
@@ -5377,8 +5539,8 @@ var SpacesServiceImpl = class {
|
|
|
5377
5539
|
});
|
|
5378
5540
|
const signer = this._identityManager.identity.getIdentityCredentialSigner();
|
|
5379
5541
|
invariant15(credential.issuer.equals(signer.getIssuer()), void 0, {
|
|
5380
|
-
F:
|
|
5381
|
-
L:
|
|
5542
|
+
F: __dxlog_file19,
|
|
5543
|
+
L: 212,
|
|
5382
5544
|
S: this,
|
|
5383
5545
|
A: [
|
|
5384
5546
|
"credential.issuer.equals(signer.getIssuer())",
|
|
@@ -5400,10 +5562,13 @@ var SpacesServiceImpl = class {
|
|
|
5400
5562
|
async createEpoch({ spaceKey, migration, automergeRootUrl }) {
|
|
5401
5563
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
5402
5564
|
const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError2(spaceKey));
|
|
5403
|
-
await space.createEpoch({
|
|
5565
|
+
const credential = await space.createEpoch({
|
|
5404
5566
|
migration,
|
|
5405
5567
|
newAutomergeRoot: automergeRootUrl
|
|
5406
5568
|
});
|
|
5569
|
+
return {
|
|
5570
|
+
epochCredential: credential ?? void 0
|
|
5571
|
+
};
|
|
5407
5572
|
}
|
|
5408
5573
|
_serializeSpace(space) {
|
|
5409
5574
|
return {
|
|
@@ -5466,8 +5631,8 @@ var SpacesServiceImpl = class {
|
|
|
5466
5631
|
var getChannelId = (channel) => `user-channel/${channel}`;
|
|
5467
5632
|
|
|
5468
5633
|
// packages/sdk/client-services/src/packlets/services/service-context.ts
|
|
5469
|
-
import { Trigger as
|
|
5470
|
-
import { Context as Context10, Resource as
|
|
5634
|
+
import { Trigger as Trigger8 } from "@dxos/async";
|
|
5635
|
+
import { Context as Context10, Resource as Resource3 } from "@dxos/context";
|
|
5471
5636
|
import { getCredentialAssertion as getCredentialAssertion5 } from "@dxos/credentials";
|
|
5472
5637
|
import { failUndefined as failUndefined2 } from "@dxos/debug";
|
|
5473
5638
|
import { EchoHost } from "@dxos/echo-db";
|
|
@@ -5476,7 +5641,7 @@ import { FeedFactory, FeedStore } from "@dxos/feed-store";
|
|
|
5476
5641
|
import { invariant as invariant16 } from "@dxos/invariant";
|
|
5477
5642
|
import { Keyring } from "@dxos/keyring";
|
|
5478
5643
|
import { PublicKey as PublicKey12 } from "@dxos/keys";
|
|
5479
|
-
import { log as
|
|
5644
|
+
import { log as log18 } from "@dxos/log";
|
|
5480
5645
|
import { InvalidStorageVersionError, STORAGE_VERSION as STORAGE_VERSION2, trace as trace9 } from "@dxos/protocols";
|
|
5481
5646
|
import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
|
|
5482
5647
|
import { BlobStore } from "@dxos/teleport-extension-object-sync";
|
|
@@ -5492,8 +5657,8 @@ function _ts_decorate6(decorators, target, key, desc) {
|
|
|
5492
5657
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5493
5658
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5494
5659
|
}
|
|
5495
|
-
var
|
|
5496
|
-
var ServiceContext = class extends
|
|
5660
|
+
var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
|
|
5661
|
+
var ServiceContext = class extends Resource3 {
|
|
5497
5662
|
constructor(storage, level, networkManager, signalManager, _runtimeParams) {
|
|
5498
5663
|
super();
|
|
5499
5664
|
this.storage = storage;
|
|
@@ -5501,7 +5666,7 @@ var ServiceContext = class extends Resource2 {
|
|
|
5501
5666
|
this.networkManager = networkManager;
|
|
5502
5667
|
this.signalManager = signalManager;
|
|
5503
5668
|
this._runtimeParams = _runtimeParams;
|
|
5504
|
-
this.initialized = new
|
|
5669
|
+
this.initialized = new Trigger8();
|
|
5505
5670
|
this._handlerFactories = /* @__PURE__ */ new Map();
|
|
5506
5671
|
this._instanceId = PublicKey12.random().toHex();
|
|
5507
5672
|
this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
|
|
@@ -5527,8 +5692,7 @@ var ServiceContext = class extends Resource2 {
|
|
|
5527
5692
|
});
|
|
5528
5693
|
this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
|
|
5529
5694
|
this.echoHost = new EchoHost({
|
|
5530
|
-
kv: this.level
|
|
5531
|
-
storage: this.storage
|
|
5695
|
+
kv: this.level
|
|
5532
5696
|
});
|
|
5533
5697
|
this.invitations = new InvitationsHandler(this.networkManager, _runtimeParams?.invitationConnectionDefaultParams);
|
|
5534
5698
|
this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
|
|
@@ -5536,17 +5700,17 @@ var ServiceContext = class extends Resource2 {
|
|
|
5536
5700
|
}
|
|
5537
5701
|
async _open(ctx) {
|
|
5538
5702
|
await this._checkStorageVersion();
|
|
5539
|
-
|
|
5540
|
-
F:
|
|
5541
|
-
L:
|
|
5703
|
+
log18("opening...", void 0, {
|
|
5704
|
+
F: __dxlog_file20,
|
|
5705
|
+
L: 149,
|
|
5542
5706
|
S: this,
|
|
5543
5707
|
C: (f, a) => f(...a)
|
|
5544
5708
|
});
|
|
5545
|
-
|
|
5709
|
+
log18.trace("dxos.sdk.service-context.open", trace9.begin({
|
|
5546
5710
|
id: this._instanceId
|
|
5547
5711
|
}), {
|
|
5548
|
-
F:
|
|
5549
|
-
L:
|
|
5712
|
+
F: __dxlog_file20,
|
|
5713
|
+
L: 150,
|
|
5550
5714
|
S: this,
|
|
5551
5715
|
C: (f, a) => f(...a)
|
|
5552
5716
|
});
|
|
@@ -5560,33 +5724,33 @@ var ServiceContext = class extends Resource2 {
|
|
|
5560
5724
|
await this._initialize(ctx);
|
|
5561
5725
|
}
|
|
5562
5726
|
const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
|
|
5563
|
-
|
|
5727
|
+
log18("loaded persistent invitations", {
|
|
5564
5728
|
count: loadedInvitations.invitations?.length
|
|
5565
5729
|
}, {
|
|
5566
|
-
F:
|
|
5567
|
-
L:
|
|
5730
|
+
F: __dxlog_file20,
|
|
5731
|
+
L: 163,
|
|
5568
5732
|
S: this,
|
|
5569
5733
|
C: (f, a) => f(...a)
|
|
5570
5734
|
});
|
|
5571
|
-
|
|
5735
|
+
log18.trace("dxos.sdk.service-context.open", trace9.end({
|
|
5572
5736
|
id: this._instanceId
|
|
5573
5737
|
}), {
|
|
5574
|
-
F:
|
|
5575
|
-
L:
|
|
5738
|
+
F: __dxlog_file20,
|
|
5739
|
+
L: 165,
|
|
5576
5740
|
S: this,
|
|
5577
5741
|
C: (f, a) => f(...a)
|
|
5578
5742
|
});
|
|
5579
|
-
|
|
5580
|
-
F:
|
|
5581
|
-
L:
|
|
5743
|
+
log18("opened", void 0, {
|
|
5744
|
+
F: __dxlog_file20,
|
|
5745
|
+
L: 166,
|
|
5582
5746
|
S: this,
|
|
5583
5747
|
C: (f, a) => f(...a)
|
|
5584
5748
|
});
|
|
5585
5749
|
}
|
|
5586
5750
|
async _close(ctx) {
|
|
5587
|
-
|
|
5588
|
-
F:
|
|
5589
|
-
L:
|
|
5751
|
+
log18("closing...", void 0, {
|
|
5752
|
+
F: __dxlog_file20,
|
|
5753
|
+
L: 170,
|
|
5590
5754
|
S: this,
|
|
5591
5755
|
C: (f, a) => f(...a)
|
|
5592
5756
|
});
|
|
@@ -5601,9 +5765,9 @@ var ServiceContext = class extends Resource2 {
|
|
|
5601
5765
|
await this.echoHost.close(ctx);
|
|
5602
5766
|
await this.networkManager.close();
|
|
5603
5767
|
await this.signalManager.close();
|
|
5604
|
-
|
|
5605
|
-
F:
|
|
5606
|
-
L:
|
|
5768
|
+
log18("closed", void 0, {
|
|
5769
|
+
F: __dxlog_file20,
|
|
5770
|
+
L: 182,
|
|
5607
5771
|
S: this,
|
|
5608
5772
|
C: (f, a) => f(...a)
|
|
5609
5773
|
});
|
|
@@ -5616,8 +5780,8 @@ var ServiceContext = class extends Resource2 {
|
|
|
5616
5780
|
getInvitationHandler(invitation) {
|
|
5617
5781
|
const factory = this._handlerFactories.get(invitation.kind);
|
|
5618
5782
|
invariant16(factory, `Unknown invitation kind: ${invitation.kind}`, {
|
|
5619
|
-
F:
|
|
5620
|
-
L:
|
|
5783
|
+
F: __dxlog_file20,
|
|
5784
|
+
L: 193,
|
|
5621
5785
|
S: this,
|
|
5622
5786
|
A: [
|
|
5623
5787
|
"factory",
|
|
@@ -5647,9 +5811,9 @@ var ServiceContext = class extends Resource2 {
|
|
|
5647
5811
|
}
|
|
5648
5812
|
// Called when identity is created.
|
|
5649
5813
|
async _initialize(ctx) {
|
|
5650
|
-
|
|
5651
|
-
F:
|
|
5652
|
-
L:
|
|
5814
|
+
log18("initializing spaces...", void 0, {
|
|
5815
|
+
F: __dxlog_file20,
|
|
5816
|
+
L: 224,
|
|
5653
5817
|
S: this,
|
|
5654
5818
|
C: (f, a) => f(...a)
|
|
5655
5819
|
});
|
|
@@ -5671,8 +5835,8 @@ var ServiceContext = class extends Resource2 {
|
|
|
5671
5835
|
await this.dataSpaceManager.open();
|
|
5672
5836
|
this._handlerFactories.set(Invitation8.Kind.SPACE, (invitation) => {
|
|
5673
5837
|
invariant16(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
|
|
5674
|
-
F:
|
|
5675
|
-
L:
|
|
5838
|
+
F: __dxlog_file20,
|
|
5839
|
+
L: 249,
|
|
5676
5840
|
S: this,
|
|
5677
5841
|
A: [
|
|
5678
5842
|
"this.dataSpaceManager",
|
|
@@ -5692,33 +5856,33 @@ var ServiceContext = class extends Resource2 {
|
|
|
5692
5856
|
return;
|
|
5693
5857
|
}
|
|
5694
5858
|
if (!this.dataSpaceManager) {
|
|
5695
|
-
|
|
5859
|
+
log18("dataSpaceManager not initialized yet, ignoring space admission", {
|
|
5696
5860
|
details: assertion
|
|
5697
5861
|
}, {
|
|
5698
|
-
F:
|
|
5699
|
-
L:
|
|
5862
|
+
F: __dxlog_file20,
|
|
5863
|
+
L: 265,
|
|
5700
5864
|
S: this,
|
|
5701
5865
|
C: (f, a) => f(...a)
|
|
5702
5866
|
});
|
|
5703
5867
|
return;
|
|
5704
5868
|
}
|
|
5705
5869
|
if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
|
|
5706
|
-
|
|
5870
|
+
log18("space already exists, ignoring space admission", {
|
|
5707
5871
|
details: assertion
|
|
5708
5872
|
}, {
|
|
5709
|
-
F:
|
|
5710
|
-
L:
|
|
5873
|
+
F: __dxlog_file20,
|
|
5874
|
+
L: 269,
|
|
5711
5875
|
S: this,
|
|
5712
5876
|
C: (f, a) => f(...a)
|
|
5713
5877
|
});
|
|
5714
5878
|
return;
|
|
5715
5879
|
}
|
|
5716
5880
|
try {
|
|
5717
|
-
|
|
5881
|
+
log18("accepting space recorded in halo", {
|
|
5718
5882
|
details: assertion
|
|
5719
5883
|
}, {
|
|
5720
|
-
F:
|
|
5721
|
-
L:
|
|
5884
|
+
F: __dxlog_file20,
|
|
5885
|
+
L: 274,
|
|
5722
5886
|
S: this,
|
|
5723
5887
|
C: (f, a) => f(...a)
|
|
5724
5888
|
});
|
|
@@ -5727,9 +5891,9 @@ var ServiceContext = class extends Resource2 {
|
|
|
5727
5891
|
genesisFeedKey: assertion.genesisFeedKey
|
|
5728
5892
|
});
|
|
5729
5893
|
} catch (err) {
|
|
5730
|
-
|
|
5731
|
-
F:
|
|
5732
|
-
L:
|
|
5894
|
+
log18.catch(err, void 0, {
|
|
5895
|
+
F: __dxlog_file20,
|
|
5896
|
+
L: 280,
|
|
5733
5897
|
S: this,
|
|
5734
5898
|
C: (f, a) => f(...a)
|
|
5735
5899
|
});
|
|
@@ -5775,9 +5939,9 @@ var ServiceRegistry = class {
|
|
|
5775
5939
|
};
|
|
5776
5940
|
|
|
5777
5941
|
// packages/sdk/client-services/src/packlets/locks/browser.ts
|
|
5778
|
-
import { asyncTimeout as asyncTimeout3, Trigger as
|
|
5942
|
+
import { asyncTimeout as asyncTimeout3, Trigger as Trigger9 } from "@dxos/async";
|
|
5779
5943
|
import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
|
|
5780
|
-
import { log as
|
|
5944
|
+
import { log as log19, logInfo } from "@dxos/log";
|
|
5781
5945
|
function _ts_decorate7(decorators, target, key, desc) {
|
|
5782
5946
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5783
5947
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -5788,7 +5952,7 @@ function _ts_decorate7(decorators, target, key, desc) {
|
|
|
5788
5952
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5789
5953
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5790
5954
|
}
|
|
5791
|
-
var
|
|
5955
|
+
var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
|
|
5792
5956
|
var Message;
|
|
5793
5957
|
(function(Message2) {
|
|
5794
5958
|
Message2["ACQUIRING"] = "acquiring";
|
|
@@ -5796,7 +5960,7 @@ var Message;
|
|
|
5796
5960
|
var Lock = class {
|
|
5797
5961
|
constructor({ lockKey, onAcquire, onRelease }) {
|
|
5798
5962
|
this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
|
|
5799
|
-
this._releaseTrigger = new
|
|
5963
|
+
this._releaseTrigger = new Trigger9();
|
|
5800
5964
|
this._lockKey = lockKey;
|
|
5801
5965
|
this._onAcquire = onAcquire;
|
|
5802
5966
|
this._onRelease = onRelease;
|
|
@@ -5810,29 +5974,29 @@ var Lock = class {
|
|
|
5810
5974
|
message: "acquiring"
|
|
5811
5975
|
});
|
|
5812
5976
|
try {
|
|
5813
|
-
|
|
5814
|
-
F:
|
|
5977
|
+
log19("aquiring lock...", void 0, {
|
|
5978
|
+
F: __dxlog_file21,
|
|
5815
5979
|
L: 42,
|
|
5816
5980
|
S: this,
|
|
5817
5981
|
C: (f, a) => f(...a)
|
|
5818
5982
|
});
|
|
5819
5983
|
await asyncTimeout3(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
|
|
5820
|
-
|
|
5821
|
-
F:
|
|
5984
|
+
log19("acquired lock", void 0, {
|
|
5985
|
+
F: __dxlog_file21,
|
|
5822
5986
|
L: 44,
|
|
5823
5987
|
S: this,
|
|
5824
5988
|
C: (f, a) => f(...a)
|
|
5825
5989
|
});
|
|
5826
5990
|
} catch {
|
|
5827
|
-
|
|
5828
|
-
F:
|
|
5991
|
+
log19("stealing lock...", void 0, {
|
|
5992
|
+
F: __dxlog_file21,
|
|
5829
5993
|
L: 46,
|
|
5830
5994
|
S: this,
|
|
5831
5995
|
C: (f, a) => f(...a)
|
|
5832
5996
|
});
|
|
5833
5997
|
await this._requestLock(true);
|
|
5834
|
-
|
|
5835
|
-
F:
|
|
5998
|
+
log19("stolen lock", void 0, {
|
|
5999
|
+
F: __dxlog_file21,
|
|
5836
6000
|
L: 48,
|
|
5837
6001
|
S: this,
|
|
5838
6002
|
C: (f, a) => f(...a)
|
|
@@ -5848,31 +6012,31 @@ var Lock = class {
|
|
|
5848
6012
|
}
|
|
5849
6013
|
}
|
|
5850
6014
|
async _requestLock(steal = false) {
|
|
5851
|
-
|
|
6015
|
+
log19("requesting lock...", {
|
|
5852
6016
|
steal
|
|
5853
6017
|
}, {
|
|
5854
|
-
F:
|
|
6018
|
+
F: __dxlog_file21,
|
|
5855
6019
|
L: 63,
|
|
5856
6020
|
S: this,
|
|
5857
6021
|
C: (f, a) => f(...a)
|
|
5858
6022
|
});
|
|
5859
|
-
const acquired = new
|
|
6023
|
+
const acquired = new Trigger9();
|
|
5860
6024
|
void navigator.locks.request(this._lockKey, {
|
|
5861
6025
|
steal
|
|
5862
6026
|
}, async () => {
|
|
5863
6027
|
await this._onAcquire?.();
|
|
5864
6028
|
acquired.wake();
|
|
5865
|
-
this._releaseTrigger = new
|
|
6029
|
+
this._releaseTrigger = new Trigger9();
|
|
5866
6030
|
await this._releaseTrigger.wait();
|
|
5867
|
-
|
|
5868
|
-
F:
|
|
6031
|
+
log19("releasing lock...", void 0, {
|
|
6032
|
+
F: __dxlog_file21,
|
|
5869
6033
|
L: 72,
|
|
5870
6034
|
S: this,
|
|
5871
6035
|
C: (f, a) => f(...a)
|
|
5872
6036
|
});
|
|
5873
6037
|
await this._onRelease?.();
|
|
5874
|
-
|
|
5875
|
-
F:
|
|
6038
|
+
log19("released lock", void 0, {
|
|
6039
|
+
F: __dxlog_file21,
|
|
5876
6040
|
L: 74,
|
|
5877
6041
|
S: this,
|
|
5878
6042
|
C: (f, a) => f(...a)
|
|
@@ -5881,10 +6045,10 @@ var Lock = class {
|
|
|
5881
6045
|
await this._onRelease?.();
|
|
5882
6046
|
});
|
|
5883
6047
|
await acquired.wait();
|
|
5884
|
-
|
|
6048
|
+
log19("recieved lock", {
|
|
5885
6049
|
steal
|
|
5886
6050
|
}, {
|
|
5887
|
-
F:
|
|
6051
|
+
F: __dxlog_file21,
|
|
5888
6052
|
L: 81,
|
|
5889
6053
|
S: this,
|
|
5890
6054
|
C: (f, a) => f(...a)
|
|
@@ -5978,7 +6142,7 @@ import { clientServiceBundle } from "@dxos/client-protocol";
|
|
|
5978
6142
|
import { Context as Context11 } from "@dxos/context";
|
|
5979
6143
|
import { invariant as invariant18 } from "@dxos/invariant";
|
|
5980
6144
|
import { PublicKey as PublicKey16 } from "@dxos/keys";
|
|
5981
|
-
import { log as
|
|
6145
|
+
import { log as log21 } from "@dxos/log";
|
|
5982
6146
|
import { WebsocketSignalManager } from "@dxos/messaging";
|
|
5983
6147
|
import { SwarmNetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
|
|
5984
6148
|
import { trace as trace10 } from "@dxos/protocols";
|
|
@@ -5991,7 +6155,7 @@ import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
|
|
|
5991
6155
|
import { Stream as Stream11 } from "@dxos/codec-protobuf";
|
|
5992
6156
|
import { invariant as invariant17 } from "@dxos/invariant";
|
|
5993
6157
|
import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
5994
|
-
var
|
|
6158
|
+
var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
|
|
5995
6159
|
var DevicesServiceImpl = class {
|
|
5996
6160
|
constructor(_identityManager) {
|
|
5997
6161
|
this._identityManager = _identityManager;
|
|
@@ -6009,7 +6173,7 @@ var DevicesServiceImpl = class {
|
|
|
6009
6173
|
});
|
|
6010
6174
|
} else {
|
|
6011
6175
|
invariant17(this._identityManager.identity?.presence, "presence not present", {
|
|
6012
|
-
F:
|
|
6176
|
+
F: __dxlog_file22,
|
|
6013
6177
|
L: 32,
|
|
6014
6178
|
S: this,
|
|
6015
6179
|
A: [
|
|
@@ -6119,7 +6283,7 @@ var findConfigs = () => {
|
|
|
6119
6283
|
import { Event as Event8 } from "@dxos/async";
|
|
6120
6284
|
import { Stream as Stream12 } from "@dxos/codec-protobuf";
|
|
6121
6285
|
import { PublicKey as PublicKey15 } from "@dxos/keys";
|
|
6122
|
-
import { getContextFromEntry, log as
|
|
6286
|
+
import { getContextFromEntry, log as log20 } from "@dxos/log";
|
|
6123
6287
|
import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
|
|
6124
6288
|
import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
|
|
6125
6289
|
var LoggingServiceImpl = class {
|
|
@@ -6132,11 +6296,11 @@ var LoggingServiceImpl = class {
|
|
|
6132
6296
|
};
|
|
6133
6297
|
}
|
|
6134
6298
|
async open() {
|
|
6135
|
-
|
|
6299
|
+
log20.runtimeConfig.processors.push(this._logProcessor);
|
|
6136
6300
|
}
|
|
6137
6301
|
async close() {
|
|
6138
|
-
const index =
|
|
6139
|
-
|
|
6302
|
+
const index = log20.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
|
|
6303
|
+
log20.runtimeConfig.processors.splice(index, 1);
|
|
6140
6304
|
}
|
|
6141
6305
|
async controlMetrics({ reset, record }) {
|
|
6142
6306
|
if (reset) {
|
|
@@ -6340,7 +6504,7 @@ function _ts_decorate8(decorators, target, key, desc) {
|
|
|
6340
6504
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6341
6505
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6342
6506
|
}
|
|
6343
|
-
var
|
|
6507
|
+
var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
|
|
6344
6508
|
var ClientServicesHost = class {
|
|
6345
6509
|
constructor({
|
|
6346
6510
|
config,
|
|
@@ -6429,7 +6593,7 @@ var ClientServicesHost = class {
|
|
|
6429
6593
|
*/
|
|
6430
6594
|
initialize({ config, ...options }) {
|
|
6431
6595
|
invariant18(!this._open, "service host is open", {
|
|
6432
|
-
F:
|
|
6596
|
+
F: __dxlog_file23,
|
|
6433
6597
|
L: 186,
|
|
6434
6598
|
S: this,
|
|
6435
6599
|
A: [
|
|
@@ -6437,15 +6601,15 @@ var ClientServicesHost = class {
|
|
|
6437
6601
|
"'service host is open'"
|
|
6438
6602
|
]
|
|
6439
6603
|
});
|
|
6440
|
-
|
|
6441
|
-
F:
|
|
6604
|
+
log21("initializing...", void 0, {
|
|
6605
|
+
F: __dxlog_file23,
|
|
6442
6606
|
L: 187,
|
|
6443
6607
|
S: this,
|
|
6444
6608
|
C: (f, a) => f(...a)
|
|
6445
6609
|
});
|
|
6446
6610
|
if (config) {
|
|
6447
6611
|
invariant18(!this._config, "config already set", {
|
|
6448
|
-
F:
|
|
6612
|
+
F: __dxlog_file23,
|
|
6449
6613
|
L: 190,
|
|
6450
6614
|
S: this,
|
|
6451
6615
|
A: [
|
|
@@ -6459,8 +6623,8 @@ var ClientServicesHost = class {
|
|
|
6459
6623
|
}
|
|
6460
6624
|
}
|
|
6461
6625
|
if (!options.signalManager) {
|
|
6462
|
-
|
|
6463
|
-
F:
|
|
6626
|
+
log21.warn("running signaling without telemetry metadata.", void 0, {
|
|
6627
|
+
F: __dxlog_file23,
|
|
6464
6628
|
L: 198,
|
|
6465
6629
|
S: this,
|
|
6466
6630
|
C: (f, a) => f(...a)
|
|
@@ -6471,7 +6635,7 @@ var ClientServicesHost = class {
|
|
|
6471
6635
|
}), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
|
|
6472
6636
|
this._signalManager = signalManager;
|
|
6473
6637
|
invariant18(!this._networkManager, "network manager already set", {
|
|
6474
|
-
F:
|
|
6638
|
+
F: __dxlog_file23,
|
|
6475
6639
|
L: 209,
|
|
6476
6640
|
S: this,
|
|
6477
6641
|
A: [
|
|
@@ -6484,8 +6648,8 @@ var ClientServicesHost = class {
|
|
|
6484
6648
|
transportFactory,
|
|
6485
6649
|
signalManager
|
|
6486
6650
|
});
|
|
6487
|
-
|
|
6488
|
-
F:
|
|
6651
|
+
log21("initialized", void 0, {
|
|
6652
|
+
F: __dxlog_file23,
|
|
6489
6653
|
L: 216,
|
|
6490
6654
|
S: this,
|
|
6491
6655
|
C: (f, a) => f(...a)
|
|
@@ -6496,16 +6660,16 @@ var ClientServicesHost = class {
|
|
|
6496
6660
|
return;
|
|
6497
6661
|
}
|
|
6498
6662
|
const traceId = PublicKey16.random().toHex();
|
|
6499
|
-
|
|
6663
|
+
log21.trace("dxos.client-services.host.open", trace10.begin({
|
|
6500
6664
|
id: traceId
|
|
6501
6665
|
}), {
|
|
6502
|
-
F:
|
|
6666
|
+
F: __dxlog_file23,
|
|
6503
6667
|
L: 227,
|
|
6504
6668
|
S: this,
|
|
6505
6669
|
C: (f, a) => f(...a)
|
|
6506
6670
|
});
|
|
6507
6671
|
invariant18(this._config, "config not set", {
|
|
6508
|
-
F:
|
|
6672
|
+
F: __dxlog_file23,
|
|
6509
6673
|
L: 229,
|
|
6510
6674
|
S: this,
|
|
6511
6675
|
A: [
|
|
@@ -6514,7 +6678,7 @@ var ClientServicesHost = class {
|
|
|
6514
6678
|
]
|
|
6515
6679
|
});
|
|
6516
6680
|
invariant18(this._storage, "storage not set", {
|
|
6517
|
-
F:
|
|
6681
|
+
F: __dxlog_file23,
|
|
6518
6682
|
L: 230,
|
|
6519
6683
|
S: this,
|
|
6520
6684
|
A: [
|
|
@@ -6523,7 +6687,7 @@ var ClientServicesHost = class {
|
|
|
6523
6687
|
]
|
|
6524
6688
|
});
|
|
6525
6689
|
invariant18(this._signalManager, "signal manager not set", {
|
|
6526
|
-
F:
|
|
6690
|
+
F: __dxlog_file23,
|
|
6527
6691
|
L: 231,
|
|
6528
6692
|
S: this,
|
|
6529
6693
|
A: [
|
|
@@ -6532,7 +6696,7 @@ var ClientServicesHost = class {
|
|
|
6532
6696
|
]
|
|
6533
6697
|
});
|
|
6534
6698
|
invariant18(this._networkManager, "network manager not set", {
|
|
6535
|
-
F:
|
|
6699
|
+
F: __dxlog_file23,
|
|
6536
6700
|
L: 232,
|
|
6537
6701
|
S: this,
|
|
6538
6702
|
A: [
|
|
@@ -6541,10 +6705,10 @@ var ClientServicesHost = class {
|
|
|
6541
6705
|
]
|
|
6542
6706
|
});
|
|
6543
6707
|
this._opening = true;
|
|
6544
|
-
|
|
6708
|
+
log21("opening...", {
|
|
6545
6709
|
lockKey: this._resourceLock?.lockKey
|
|
6546
6710
|
}, {
|
|
6547
|
-
F:
|
|
6711
|
+
F: __dxlog_file23,
|
|
6548
6712
|
L: 235,
|
|
6549
6713
|
S: this,
|
|
6550
6714
|
C: (f, a) => f(...a)
|
|
@@ -6595,18 +6759,18 @@ var ClientServicesHost = class {
|
|
|
6595
6759
|
this._open = true;
|
|
6596
6760
|
this._statusUpdate.emit();
|
|
6597
6761
|
const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
|
|
6598
|
-
|
|
6762
|
+
log21("opened", {
|
|
6599
6763
|
deviceKey
|
|
6600
6764
|
}, {
|
|
6601
|
-
F:
|
|
6765
|
+
F: __dxlog_file23,
|
|
6602
6766
|
L: 314,
|
|
6603
6767
|
S: this,
|
|
6604
6768
|
C: (f, a) => f(...a)
|
|
6605
6769
|
});
|
|
6606
|
-
|
|
6770
|
+
log21.trace("dxos.client-services.host.open", trace10.end({
|
|
6607
6771
|
id: traceId
|
|
6608
6772
|
}), {
|
|
6609
|
-
F:
|
|
6773
|
+
F: __dxlog_file23,
|
|
6610
6774
|
L: 315,
|
|
6611
6775
|
S: this,
|
|
6612
6776
|
C: (f, a) => f(...a)
|
|
@@ -6617,10 +6781,10 @@ var ClientServicesHost = class {
|
|
|
6617
6781
|
return;
|
|
6618
6782
|
}
|
|
6619
6783
|
const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
|
|
6620
|
-
|
|
6784
|
+
log21("closing...", {
|
|
6621
6785
|
deviceKey
|
|
6622
6786
|
}, {
|
|
6623
|
-
F:
|
|
6787
|
+
F: __dxlog_file23,
|
|
6624
6788
|
L: 326,
|
|
6625
6789
|
S: this,
|
|
6626
6790
|
C: (f, a) => f(...a)
|
|
@@ -6635,10 +6799,10 @@ var ClientServicesHost = class {
|
|
|
6635
6799
|
await this._level?.close();
|
|
6636
6800
|
this._open = false;
|
|
6637
6801
|
this._statusUpdate.emit();
|
|
6638
|
-
|
|
6802
|
+
log21("closed", {
|
|
6639
6803
|
deviceKey
|
|
6640
6804
|
}, {
|
|
6641
|
-
F:
|
|
6805
|
+
F: __dxlog_file23,
|
|
6642
6806
|
L: 335,
|
|
6643
6807
|
S: this,
|
|
6644
6808
|
C: (f, a) => f(...a)
|
|
@@ -6646,32 +6810,32 @@ var ClientServicesHost = class {
|
|
|
6646
6810
|
}
|
|
6647
6811
|
async reset() {
|
|
6648
6812
|
const traceId = PublicKey16.random().toHex();
|
|
6649
|
-
|
|
6813
|
+
log21.trace("dxos.sdk.client-services-host.reset", trace10.begin({
|
|
6650
6814
|
id: traceId
|
|
6651
6815
|
}), {
|
|
6652
|
-
F:
|
|
6816
|
+
F: __dxlog_file23,
|
|
6653
6817
|
L: 340,
|
|
6654
6818
|
S: this,
|
|
6655
6819
|
C: (f, a) => f(...a)
|
|
6656
6820
|
});
|
|
6657
|
-
|
|
6658
|
-
F:
|
|
6821
|
+
log21.info("resetting...", void 0, {
|
|
6822
|
+
F: __dxlog_file23,
|
|
6659
6823
|
L: 342,
|
|
6660
6824
|
S: this,
|
|
6661
6825
|
C: (f, a) => f(...a)
|
|
6662
6826
|
});
|
|
6663
6827
|
await this._serviceContext?.close();
|
|
6664
6828
|
await this._storage.reset();
|
|
6665
|
-
|
|
6666
|
-
F:
|
|
6829
|
+
log21.info("reset", void 0, {
|
|
6830
|
+
F: __dxlog_file23,
|
|
6667
6831
|
L: 345,
|
|
6668
6832
|
S: this,
|
|
6669
6833
|
C: (f, a) => f(...a)
|
|
6670
6834
|
});
|
|
6671
|
-
|
|
6835
|
+
log21.trace("dxos.sdk.client-services-host.reset", trace10.end({
|
|
6672
6836
|
id: traceId
|
|
6673
6837
|
}), {
|
|
6674
|
-
F:
|
|
6838
|
+
F: __dxlog_file23,
|
|
6675
6839
|
L: 346,
|
|
6676
6840
|
S: this,
|
|
6677
6841
|
C: (f, a) => f(...a)
|
|
@@ -6730,7 +6894,6 @@ export {
|
|
|
6730
6894
|
SpaceInvitationProtocol,
|
|
6731
6895
|
InvitationsManager,
|
|
6732
6896
|
DataSpace,
|
|
6733
|
-
findPropertiesObject,
|
|
6734
6897
|
DataSpaceManager,
|
|
6735
6898
|
SpacesServiceImpl,
|
|
6736
6899
|
ServiceContext,
|
|
@@ -6743,4 +6906,4 @@ export {
|
|
|
6743
6906
|
ClientServicesProviderResource,
|
|
6744
6907
|
DiagnosticsCollector
|
|
6745
6908
|
};
|
|
6746
|
-
//# sourceMappingURL=chunk-
|
|
6909
|
+
//# sourceMappingURL=chunk-KI7FY3ZO.mjs.map
|