@minca/core 0.1.8 → 0.1.10
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/README.md +1 -1
- package/dist/files/file-id.d.ts +51 -0
- package/dist/files/file-id.d.ts.map +1 -0
- package/dist/files/file-id.js +97 -0
- package/dist/files/file-id.js.map +1 -0
- package/dist/files/seal.d.ts +20 -0
- package/dist/files/seal.d.ts.map +1 -0
- package/dist/files/seal.js +77 -0
- package/dist/files/seal.js.map +1 -0
- package/dist/files/space-files.d.ts +51 -0
- package/dist/files/space-files.d.ts.map +1 -0
- package/dist/files/space-files.js +476 -0
- package/dist/files/space-files.js.map +1 -0
- package/dist/identity/abilities.d.ts +3 -3
- package/dist/identity/abilities.d.ts.map +1 -1
- package/dist/identity/abilities.js +9 -11
- package/dist/identity/abilities.js.map +1 -1
- package/dist/identity/root-signer.d.ts +0 -5
- package/dist/identity/root-signer.d.ts.map +1 -1
- package/dist/identity/root-signer.js +0 -1
- package/dist/identity/root-signer.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/node/api.d.ts +5 -1
- package/dist/node/api.d.ts.map +1 -1
- package/dist/node/api.js +10 -2
- package/dist/node/api.js.map +1 -1
- package/dist/node/carrier.d.ts +17 -2
- package/dist/node/carrier.d.ts.map +1 -1
- package/dist/node/carrier.js +26 -4
- package/dist/node/carrier.js.map +1 -1
- package/dist/node/copy.d.ts +0 -4
- package/dist/node/copy.d.ts.map +1 -1
- package/dist/node/copy.js +26 -0
- package/dist/node/copy.js.map +1 -1
- package/dist/node/host.d.ts +66 -1
- package/dist/node/host.d.ts.map +1 -1
- package/dist/node/host.js +571 -5
- package/dist/node/host.js.map +1 -1
- package/dist/node/index.d.ts +2 -2
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/node.d.ts.map +1 -1
- package/dist/node/node.js +328 -269
- package/dist/node/node.js.map +1 -1
- package/dist/node/remote.d.ts +6 -5
- package/dist/node/remote.d.ts.map +1 -1
- package/dist/node/remote.js +141 -194
- package/dist/node/remote.js.map +1 -1
- package/dist/node/space-runtime.d.ts +9 -0
- package/dist/node/space-runtime.d.ts.map +1 -1
- package/dist/node/space-runtime.js +194 -98
- package/dist/node/space-runtime.js.map +1 -1
- package/dist/node/stores.d.ts +44 -8
- package/dist/node/stores.d.ts.map +1 -1
- package/dist/node/stores.js +44 -7
- package/dist/node/stores.js.map +1 -1
- package/dist/node/types.d.ts +77 -10
- package/dist/node/types.d.ts.map +1 -1
- package/dist/node/usage.d.ts +54 -0
- package/dist/node/usage.d.ts.map +1 -0
- package/dist/node/usage.js +201 -0
- package/dist/node/usage.js.map +1 -0
- package/dist/node/worker.d.ts +1 -1
- package/dist/node/worker.d.ts.map +1 -1
- package/dist/node/worker.js +10 -6
- package/dist/node/worker.js.map +1 -1
- package/dist/schema/version.d.ts +5 -0
- package/dist/schema/version.d.ts.map +1 -1
- package/dist/schema/version.js +1 -0
- package/dist/schema/version.js.map +1 -1
- package/dist/schemas/fragments.d.ts +23 -2
- package/dist/schemas/fragments.d.ts.map +1 -1
- package/dist/schemas/fragments.js +5 -2
- package/dist/schemas/fragments.js.map +1 -1
- package/dist/schemas/library/annotations.d.ts +24 -0
- package/dist/schemas/library/annotations.d.ts.map +1 -1
- package/dist/schemas/library/community.d.ts +24 -0
- package/dist/schemas/library/community.d.ts.map +1 -1
- package/dist/schemas/library/life.d.ts +72 -0
- package/dist/schemas/library/life.d.ts.map +1 -1
- package/dist/schemas/library/media.d.ts +144 -0
- package/dist/schemas/library/media.d.ts.map +1 -1
- package/dist/schemas/library/money.d.ts +24 -0
- package/dist/schemas/library/money.d.ts.map +1 -1
- package/dist/schemas/library/publishing.d.ts +96 -0
- package/dist/schemas/library/publishing.d.ts.map +1 -1
- package/dist/schemas/library/social.d.ts +72 -0
- package/dist/schemas/library/social.d.ts.map +1 -1
- package/dist/session/auth.d.ts +20 -0
- package/dist/session/auth.d.ts.map +1 -1
- package/dist/session/auth.js +88 -64
- package/dist/session/auth.js.map +1 -1
- package/dist/session/connect.d.ts +50 -8
- package/dist/session/connect.d.ts.map +1 -1
- package/dist/session/connect.js +91 -27
- package/dist/session/connect.js.map +1 -1
- package/dist/session/connection.d.ts +39 -6
- package/dist/session/connection.d.ts.map +1 -1
- package/dist/session/connection.js +107 -38
- package/dist/session/connection.js.map +1 -1
- package/dist/session/hosting.d.ts +88 -28
- package/dist/session/hosting.d.ts.map +1 -1
- package/dist/session/hosting.js +137 -6
- package/dist/session/hosting.js.map +1 -1
- package/dist/session/index.d.ts +5 -5
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/index.js +2 -2
- package/dist/session/index.js.map +1 -1
- package/dist/session/places.d.ts +2 -0
- package/dist/session/places.d.ts.map +1 -1
- package/dist/session/places.js +8 -2
- package/dist/session/places.js.map +1 -1
- package/dist/space/account-registry.d.ts +27 -4
- package/dist/space/account-registry.d.ts.map +1 -1
- package/dist/space/account-registry.js +25 -3
- package/dist/space/account-registry.js.map +1 -1
- package/dist/space/roles.d.ts +59 -140
- package/dist/space/roles.d.ts.map +1 -1
- package/dist/space/roles.js +328 -427
- package/dist/space/roles.js.map +1 -1
- package/dist/storage/blob/directory.d.ts +14 -0
- package/dist/storage/blob/directory.d.ts.map +1 -0
- package/dist/storage/blob/directory.js +80 -0
- package/dist/storage/blob/directory.js.map +1 -0
- package/dist/storage/folder-adapter.d.ts +22 -0
- package/dist/storage/folder-adapter.d.ts.map +1 -1
- package/dist/storage/folder-adapter.js +5 -5
- package/dist/storage/folder-adapter.js.map +1 -1
- package/dist/storage/mirror.d.ts +9 -2
- package/dist/storage/mirror.d.ts.map +1 -1
- package/dist/storage/mirror.js +60 -35
- package/dist/storage/mirror.js.map +1 -1
- package/dist/storage/segment.d.ts +7 -2
- package/dist/storage/segment.d.ts.map +1 -1
- package/dist/storage/segment.js +25 -3
- package/dist/storage/segment.js.map +1 -1
- package/dist/sync/sync-engine.d.ts +2 -0
- package/dist/sync/sync-engine.d.ts.map +1 -1
- package/dist/sync/sync-engine.js +5 -0
- package/dist/sync/sync-engine.js.map +1 -1
- package/dist/sync/sync-messages.d.ts +24 -0
- package/dist/sync/sync-messages.d.ts.map +1 -1
- package/dist/sync/sync-messages.js.map +1 -1
- package/docs/actions.md +3 -3
- package/docs/agents.md +2 -2
- package/docs/blueprints-and-guides.md +20 -1
- package/docs/bots.md +1 -1
- package/docs/node.md +138 -75
- package/docs/sign-in.md +16 -9
- package/docs/spaces.md +18 -10
- package/docs/standard-library.md +16 -20
- package/docs/storage.md +121 -16
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"space-runtime.d.ts","sourceRoot":"","sources":["../../src/node/space-runtime.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAkB,MAAM,aAAa,CAAC;AAC3E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AA6ClE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAI1D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C,OAAO,EAQL,KAAK,QAAQ,EACd,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAc,KAAK,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,EAIL,KAAK,UAAU,EAChB,MAAM,yBAAyB,CAAC;AA2BjC,OAAO,
|
|
1
|
+
{"version":3,"file":"space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,GAAkB,OAAO,CAAC,OAAO,CAAC;gBAI7D,MAAM,QAAQ,MAAM;kBAIlB,MAAM,QAAQ,MAAM;sBAIhB,MAAM;IAI9B,iFAAiF;oBAC3D,MAAM;IAiB5B,oEAAoE;uBAC3C,MAAM;IAO/B;;;;;;;OAOG;wBACuB,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAqCnD;;;;OAIG;qBACc,MAAM,UAAU,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAkB1D,6FAA6F;qBACtE,YAAY;qBAWZ,MAAM;;;;2BAOA,MAAM;IAYnC;;;;;OAKG;gBACe,MAAM,YAAW;QAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAQ,OAAO,CAAC,OAAO,CAAC;mBAmClE,MAAM;qBAIJ,aAAa,CAAC,MAAM,CAAC;IAI5C,0GAA0G;mBACrF,aAAa,CAAC,OAAO,CAAC;IAgB3C,gGAAgG;iBAC7E,UAAU;;;;;;;;;;;;;uBA/9CL,aAAa,CAAC,MAAM,CAAC,KAAG,OAAO;kBA+gDnC,OAAO,OAAO,MAAM;IAaxC;;;;OAIG;oBACa,aAAa,CAAC,MAAM,CAAC;aA4BtB,OAAO,CAAC,IAAI,CAAC;IAoB/B"}
|
|
@@ -24,7 +24,7 @@ import { contactKeyPair, isContactPublicKey } from '../identity/contact-key.js';
|
|
|
24
24
|
import { openValueFrom, sealValueTo } from '../identity/hpke.js';
|
|
25
25
|
import { openValue, sealValue } from '../identity/envelope.js';
|
|
26
26
|
import { verifyNote } from '../identity/ucan.js';
|
|
27
|
-
import { ACCESS_COMMAND, accessRequirement,
|
|
27
|
+
import { ACCESS_COMMAND, accessRequirement, actsForAccount, DEFINE_COMMAND, noteGrants, writeRequirement, writesRecords, } from '../identity/abilities.js';
|
|
28
28
|
import { bodyProblem, canonicalize, createVersion, getVersionId, isStub, signedPart, stubOf, } from '../schema/version.js';
|
|
29
29
|
import { createStorageProvider } from '../storage/storage-provider.js';
|
|
30
30
|
import { chainProblem, MAX_SEEN, nextVersion } from '../records/version.js';
|
|
@@ -44,12 +44,15 @@ import { createWebSocketTransport } from '../network/ws-transport.js';
|
|
|
44
44
|
import { createClientAuth, createMeshAuth, MAX_EARLIER_READ_KEYS, } from '../network/peer-auth.js';
|
|
45
45
|
import { BOX_COLLECTION, MEMBER_KEY_COLLECTION, SPACE_KEY_RECORD, SPACE_RELAYS_RECORD, SPACE_KEEPERS_RECORD, memberKeyRecordKey, BOX_LABEL, boxBound, boxKey, deriveInviteKey, deriveReadKey, generateInviteSecret, inviteKey as inviteRecordKey, assignKey, removalKey, revokeKey, roleKey, signInvite, verifyInvite, forkKey, stepDownKey, succeedKey, WARRANT_COLLECTION, } from '../space/space-access.js';
|
|
46
46
|
import { accessGenesisOf, isSpaceId } from '../space/constitution.js';
|
|
47
|
-
import { ACCESS_COLLECTIONS, ASSIGN_COLLECTION, DEFINITION_COLLECTION, INVITE_COLLECTION, KEY_COLLECTION, MAX_RELAYS, RELAYS_COLLECTION, checkRelays, KEEPERS_COLLECTION, FORK_COLLECTION, checkKeepers, REMOVE_COLLECTION, REVOKE_COLLECTION, ROLE_COLLECTION, STEPDOWN_COLLECTION, SUCCEED_COLLECTION, headless, isMember, holdsRole, may, readers, replayAccess, refusal, rolesOf, } from '../space/roles.js';
|
|
47
|
+
import { ACCESS_COLLECTIONS, ACCESS_KINDS, ASSIGN_COLLECTION, DEFINITION_COLLECTION, INVITE_COLLECTION, KEY_COLLECTION, MAX_RELAYS, RELAYS_COLLECTION, checkRelays, KEEPERS_COLLECTION, FORK_COLLECTION, checkKeepers, REMOVE_COLLECTION, REVOKE_COLLECTION, ROLE_COLLECTION, STEPDOWN_COLLECTION, SUCCEED_COLLECTION, headless, isMember, holdsRole, may, readers, replayAccess, refusal, rolesOf, } from '../space/roles.js';
|
|
48
48
|
import { checkFoundingRole, definitionBody, KEY_CHANGE, readDefinition, RECORD_DELETE, RECORD_WRITE, SPACE_RELAYS, } from '../space/grants.js';
|
|
49
49
|
import { FOUNDER } from '../space/space-manager.js';
|
|
50
50
|
import { createSyncEngine } from '../sync/sync-engine.js';
|
|
51
|
+
import { SYNC_PROTOCOL_VERSION } from '../sync/sync-messages.js';
|
|
52
|
+
import { createSpaceFiles } from '../files/space-files.js';
|
|
53
|
+
import { fileRefsIn, MAX_FILES } from '../files/file-id.js';
|
|
51
54
|
import { CATALOG_COLLECTION, checkStoredCollection, isStoredCollection, toJsonSchema, validateJsonSchema, } from '../schema/collection-def.js';
|
|
52
|
-
import { CARRIER_COLLECTION, MEMBERSHIP_COLLECTION, PROFILE_COLLECTION } from '../space/account-registry.js';
|
|
55
|
+
import { CARRIER_COLLECTION, MEMBERSHIP_COLLECTION, PROFILE_COLLECTION, isAvatarRef, } from '../space/account-registry.js';
|
|
53
56
|
import { PASS_COLLECTION } from '../space/pass.js';
|
|
54
57
|
import { base32Encode, cidOfDigest, hashedKey, sha256 } from '../utils/hash.js';
|
|
55
58
|
import { sameTags, tagsFor, topicKey, topicTag } from '../records/topics.js';
|
|
@@ -75,35 +78,12 @@ const MANAGED = new Set([
|
|
|
75
78
|
* read the records has no use for their rules.
|
|
76
79
|
*/
|
|
77
80
|
const IN_THE_CLEAR = new Set([
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
INVITE_COLLECTION,
|
|
82
|
-
REVOKE_COLLECTION,
|
|
83
|
-
KEY_COLLECTION,
|
|
81
|
+
...Object.values(ACCESS_KINDS)
|
|
82
|
+
.filter(({ clear }) => clear)
|
|
83
|
+
.map(({ collection }) => collection),
|
|
84
84
|
BOX_COLLECTION,
|
|
85
85
|
MEMBER_KEY_COLLECTION,
|
|
86
|
-
RELAYS_COLLECTION,
|
|
87
|
-
KEEPERS_COLLECTION,
|
|
88
|
-
FORK_COLLECTION,
|
|
89
|
-
STEPDOWN_COLLECTION,
|
|
90
|
-
SUCCEED_COLLECTION,
|
|
91
86
|
]);
|
|
92
|
-
/** Which collection each access record key belongs to */
|
|
93
|
-
const ACCESS_KEYS = [
|
|
94
|
-
['role:', ROLE_COLLECTION],
|
|
95
|
-
['assign:', ASSIGN_COLLECTION],
|
|
96
|
-
['remove:', REMOVE_COLLECTION],
|
|
97
|
-
['invite:', INVITE_COLLECTION],
|
|
98
|
-
['revoke:', REVOKE_COLLECTION],
|
|
99
|
-
['collection:', DEFINITION_COLLECTION],
|
|
100
|
-
['key:', KEY_COLLECTION],
|
|
101
|
-
['relays:', RELAYS_COLLECTION],
|
|
102
|
-
['keepers:', KEEPERS_COLLECTION],
|
|
103
|
-
['fork:', FORK_COLLECTION],
|
|
104
|
-
['stepdown:', STEPDOWN_COLLECTION],
|
|
105
|
-
['succeed:', SUCCEED_COLLECTION],
|
|
106
|
-
];
|
|
107
87
|
/** How many keys a cutoff may name */
|
|
108
88
|
const MAX_CUTOFF = 1024;
|
|
109
89
|
/** A change that takes nothing away covers nothing */
|
|
@@ -179,6 +159,24 @@ const grantsBeyondRecords = (proof, spaceId, cmd) => noteGrants(proof, { space:
|
|
|
179
159
|
export const CANNOT_DEFINE = "This key's note doesn't let it add or change collections. Propose them instead (collections_propose), and someone who may adds them.";
|
|
180
160
|
const CANNOT_CHANGE_ACCESS = "This key's note doesn't let it change who may do what in a space. Ask the person.";
|
|
181
161
|
const NOT_ACCOUNT = "This key's note doesn't let it change the account itself. Ask the person.";
|
|
162
|
+
/**
|
|
163
|
+
* Whether a version is about the account that signs it: its own place in the
|
|
164
|
+
* space (taking or giving up a role, leaving, stepping down), what others
|
|
165
|
+
* seal to it or see of it, or another of its keys. Only a key acting as the
|
|
166
|
+
* account itself writes one (spec 01 §8), so an app given a space never
|
|
167
|
+
* changes the account's standing there.
|
|
168
|
+
*/
|
|
169
|
+
function aboutItself(collection, body, root, author) {
|
|
170
|
+
if (collection === STEPDOWN_COLLECTION || collection === MEMBER_KEY_COLLECTION)
|
|
171
|
+
return true;
|
|
172
|
+
if (collection === PROFILE_COLLECTION)
|
|
173
|
+
return true;
|
|
174
|
+
if (!isRecord(body))
|
|
175
|
+
return false;
|
|
176
|
+
if (collection === ASSIGN_COLLECTION || collection === REMOVE_COLLECTION)
|
|
177
|
+
return body.did === root;
|
|
178
|
+
return collection === REVOKE_COLLECTION && body.key !== author;
|
|
179
|
+
}
|
|
182
180
|
const NO_ACCOUNT = Object.freeze({ account: null, recordsOnly: false });
|
|
183
181
|
/** How long a peer checked here has to become a peer before the check is forgotten: past any handshake's timeout */
|
|
184
182
|
const STALE_ADMISSION_MS = 60_000;
|
|
@@ -514,6 +512,9 @@ export async function openSpaceRuntime(deps) {
|
|
|
514
512
|
const verdict = await judge(version);
|
|
515
513
|
if (!verdict.verified || !verdict.root)
|
|
516
514
|
return null;
|
|
515
|
+
if (!actsForAccount(version.proof) &&
|
|
516
|
+
aboutItself(version.collection, version.body, verdict.root, version.author))
|
|
517
|
+
return null;
|
|
517
518
|
const seen = version.seen ?? [];
|
|
518
519
|
const base = {
|
|
519
520
|
id: version.id,
|
|
@@ -610,11 +611,12 @@ export async function openSpaceRuntime(deps) {
|
|
|
610
611
|
}
|
|
611
612
|
case INVITE_COLLECTION: {
|
|
612
613
|
const inviteDid = body.key;
|
|
613
|
-
|
|
614
|
+
// An invite carries no cutoff: closing it takes nothing from anyone but who joins through it unseen.
|
|
615
|
+
if (body.cutoff !== undefined || typeof inviteDid !== 'string' || typeof body.role !== 'string')
|
|
614
616
|
return null;
|
|
615
|
-
if (version.key !== (await inviteRecordKey(inviteDid)))
|
|
617
|
+
if (typeof body.open !== 'boolean' || version.key !== (await inviteRecordKey(inviteDid)))
|
|
616
618
|
return null;
|
|
617
|
-
return { ...base,
|
|
619
|
+
return { ...base, kind: 'invite', inviteKey: inviteDid, role: body.role, open: body.open };
|
|
618
620
|
}
|
|
619
621
|
case KEY_COLLECTION: {
|
|
620
622
|
if (version.key !== SPACE_KEY_RECORD || typeof body.keyId !== 'string' || body.keyId.length > 64)
|
|
@@ -705,7 +707,7 @@ export async function openSpaceRuntime(deps) {
|
|
|
705
707
|
let unsettled = false;
|
|
706
708
|
// By key, not by the current version's collection: whatever sits on top
|
|
707
709
|
// may be anyone's, and every version of the history counts.
|
|
708
|
-
for (const
|
|
710
|
+
for (const { prefix, collection } of Object.values(ACCESS_KINDS)) {
|
|
709
711
|
for (const versions of (await storage.histories(prefix)).values()) {
|
|
710
712
|
for (const held of versions) {
|
|
711
713
|
if (held.collection !== collection)
|
|
@@ -739,7 +741,7 @@ export async function openSpaceRuntime(deps) {
|
|
|
739
741
|
return loadAccess();
|
|
740
742
|
let pending = [];
|
|
741
743
|
for (const version of placed) {
|
|
742
|
-
if (!
|
|
744
|
+
if (!Object.values(ACCESS_KINDS).some(({ prefix, collection }) => version.key.startsWith(prefix) && version.collection === collection))
|
|
743
745
|
continue;
|
|
744
746
|
const event = await toEvent(version);
|
|
745
747
|
if (event)
|
|
@@ -947,8 +949,9 @@ export async function openSpaceRuntime(deps) {
|
|
|
947
949
|
const verdict = await judge(version);
|
|
948
950
|
if (!verdict.verified || !verdict.root)
|
|
949
951
|
return { ok: false, reason: verdict.reason ?? 'Its signature does not check out' };
|
|
950
|
-
|
|
951
|
-
|
|
952
|
+
const asAccount = deps.accountOnly || aboutItself(version.collection, version.body, verdict.root, version.author);
|
|
953
|
+
if (asAccount && !actsForAccount(version.proof))
|
|
954
|
+
return { ok: false, reason: "Its note doesn't let it act as the account itself" };
|
|
952
955
|
const { history } = await access();
|
|
953
956
|
if (ACCESS_COLLECTIONS.has(version.collection)) {
|
|
954
957
|
const event = await toEvent(version);
|
|
@@ -1728,6 +1731,9 @@ export async function openSpaceRuntime(deps) {
|
|
|
1728
1731
|
break;
|
|
1729
1732
|
found = { did: verdict.root, name: name.trim().slice(0, 64), updatedAt: version.createdAt };
|
|
1730
1733
|
}
|
|
1734
|
+
// The picture, from the newest version: one without it shows none (the older stay kept, as retained).
|
|
1735
|
+
if (!found.avatar && found.updatedAt === version.createdAt && isAvatarRef(body?.avatar))
|
|
1736
|
+
found = { ...found, avatar: body.avatar };
|
|
1731
1737
|
// The contact key from the newest version that has one: it never changes, and an app
|
|
1732
1738
|
// without it that wrote a newer version first must not hide it.
|
|
1733
1739
|
if (isContactPublicKey(body?.contactKey)) {
|
|
@@ -1747,6 +1753,9 @@ export async function openSpaceRuntime(deps) {
|
|
|
1747
1753
|
*/
|
|
1748
1754
|
let memberKeysCache = null;
|
|
1749
1755
|
const memberKeyMap = () => (memberKeysCache ??= loadMemberKeys());
|
|
1756
|
+
/** Every key box, read once until records change */
|
|
1757
|
+
let boxCache = null;
|
|
1758
|
+
const boxIndex = () => (boxCache ??= storage.histories('box:'));
|
|
1750
1759
|
async function loadMemberKeys() {
|
|
1751
1760
|
const found = new Map();
|
|
1752
1761
|
// By key: the current version may be anyone's.
|
|
@@ -1776,7 +1785,45 @@ export async function openSpaceRuntime(deps) {
|
|
|
1776
1785
|
* verdict still holds. Given nothing — another tab, a folder, new keys —
|
|
1777
1786
|
* everything is.
|
|
1778
1787
|
*/
|
|
1788
|
+
let spaceFiles = null;
|
|
1789
|
+
const missingFiles = () => {
|
|
1790
|
+
throw new Error('The space is still opening');
|
|
1791
|
+
};
|
|
1792
|
+
let filesTimer = null;
|
|
1793
|
+
/** One pass at a time; a change during one runs another after it */
|
|
1794
|
+
let filesPass = null;
|
|
1795
|
+
let filesAgain = false;
|
|
1796
|
+
/** After a change: which files are named is worked out again, and soon kept, dropped and fetched to match */
|
|
1797
|
+
function filesChanged() {
|
|
1798
|
+
spaceFiles?.changed();
|
|
1799
|
+
if (filesPass) {
|
|
1800
|
+
filesAgain = true;
|
|
1801
|
+
return;
|
|
1802
|
+
}
|
|
1803
|
+
if (filesTimer || closed)
|
|
1804
|
+
return;
|
|
1805
|
+
filesTimer = setTimeout(() => {
|
|
1806
|
+
filesTimer = null;
|
|
1807
|
+
filesPass = (async () => {
|
|
1808
|
+
await spaceFiles?.tidy();
|
|
1809
|
+
if (deps.fetchFiles === 'all')
|
|
1810
|
+
await spaceFiles?.fetchAll();
|
|
1811
|
+
})()
|
|
1812
|
+
.catch(() => {
|
|
1813
|
+
// A peer or mirror out of reach; the next change tries again.
|
|
1814
|
+
})
|
|
1815
|
+
.finally(() => {
|
|
1816
|
+
filesPass = null;
|
|
1817
|
+
if (filesAgain && !closed) {
|
|
1818
|
+
filesAgain = false;
|
|
1819
|
+
filesChanged();
|
|
1820
|
+
}
|
|
1821
|
+
});
|
|
1822
|
+
}, 2000);
|
|
1823
|
+
unref(filesTimer);
|
|
1824
|
+
}
|
|
1779
1825
|
const recordsChanged = (placed) => {
|
|
1826
|
+
filesChanged();
|
|
1780
1827
|
if (placed)
|
|
1781
1828
|
noteArrived(placed);
|
|
1782
1829
|
linkIndexCache = null;
|
|
@@ -1803,6 +1850,7 @@ export async function openSpaceRuntime(deps) {
|
|
|
1803
1850
|
catalogCache = null;
|
|
1804
1851
|
profilesCache = null;
|
|
1805
1852
|
memberKeysCache = null;
|
|
1853
|
+
boxCache = null;
|
|
1806
1854
|
accessCache = placed && accessCache ? extendAccess(accessCache, placed) : null;
|
|
1807
1855
|
standings.clear();
|
|
1808
1856
|
checkVerdicts.clear();
|
|
@@ -1864,7 +1912,7 @@ export async function openSpaceRuntime(deps) {
|
|
|
1864
1912
|
return true;
|
|
1865
1913
|
};
|
|
1866
1914
|
if (memberPair && epochs.some((epoch) => !keyring.has(epoch.keyId))) {
|
|
1867
|
-
for (const versions of (await
|
|
1915
|
+
for (const versions of (await boxIndex()).values()) {
|
|
1868
1916
|
for (const version of versions) {
|
|
1869
1917
|
if (version.collection !== BOX_COLLECTION || version.deleted || opened.has(version.id))
|
|
1870
1918
|
continue;
|
|
@@ -1983,7 +2031,7 @@ export async function openSpaceRuntime(deps) {
|
|
|
1983
2031
|
if (!epoch || !key)
|
|
1984
2032
|
return;
|
|
1985
2033
|
const boxed = new Set();
|
|
1986
|
-
for (const versions of (await
|
|
2034
|
+
for (const versions of (await boxIndex()).values()) {
|
|
1987
2035
|
for (const version of versions) {
|
|
1988
2036
|
const body = isRecord(version.body) ? version.body : null;
|
|
1989
2037
|
if (version.collection !== BOX_COLLECTION ||
|
|
@@ -2031,7 +2079,10 @@ export async function openSpaceRuntime(deps) {
|
|
|
2031
2079
|
return;
|
|
2032
2080
|
}
|
|
2033
2081
|
const mine = await memberKeyMap();
|
|
2034
|
-
if (memberPair &&
|
|
2082
|
+
if (memberPair &&
|
|
2083
|
+
mine.get(deps.rootDid) !== memberPair.publicKey &&
|
|
2084
|
+
actsForAccount(session.proof()) &&
|
|
2085
|
+
!(await cannotWrite())) {
|
|
2035
2086
|
await upsert(MEMBER_KEY_COLLECTION, await memberKeyRecordKey(deps.rootDid), {
|
|
2036
2087
|
key: memberPair.publicKey,
|
|
2037
2088
|
});
|
|
@@ -2127,6 +2178,14 @@ export async function openSpaceRuntime(deps) {
|
|
|
2127
2178
|
//
|
|
2128
2179
|
// Every mirror is one more peer: what it holds goes through the same gates
|
|
2129
2180
|
// as a peer's records, and what this node holds goes out to it.
|
|
2181
|
+
/** What a mirror holds goes through the same gates as a peer's records */
|
|
2182
|
+
const fromMirror = async (version) => {
|
|
2183
|
+
const verdict = await admit(version);
|
|
2184
|
+
if (!verdict.ok && !verdict.withdrawn)
|
|
2185
|
+
return verdict.later ? 'later' : 'refused';
|
|
2186
|
+
await storage.addVersion(version);
|
|
2187
|
+
return 'stored';
|
|
2188
|
+
};
|
|
2130
2189
|
const mirrors = [];
|
|
2131
2190
|
for (const [index, store] of (deps.mirrors ?? []).entries()) {
|
|
2132
2191
|
mirrors.push(await createMirror({
|
|
@@ -2134,15 +2193,24 @@ export async function openSpaceRuntime(deps) {
|
|
|
2134
2193
|
space: space.id,
|
|
2135
2194
|
storage,
|
|
2136
2195
|
state: await deps.stores(`mirrors/${space.id}/${index}`),
|
|
2137
|
-
accept:
|
|
2138
|
-
const verdict = await admit(version);
|
|
2139
|
-
if (!verdict.ok && !verdict.withdrawn)
|
|
2140
|
-
return verdict.later ? 'later' : 'refused';
|
|
2141
|
-
await storage.addVersion(version);
|
|
2142
|
-
return 'stored';
|
|
2143
|
-
},
|
|
2196
|
+
accept: fromMirror,
|
|
2144
2197
|
}));
|
|
2145
2198
|
}
|
|
2199
|
+
// A data folder is one more: its spaces are segments, like a bucket's, and
|
|
2200
|
+
// what this device holds of them is its own (`node/stores.ts`).
|
|
2201
|
+
const folderMirror = deps.stores.folder
|
|
2202
|
+
? await createMirror({
|
|
2203
|
+
store: deps.stores.folder,
|
|
2204
|
+
space: space.id,
|
|
2205
|
+
storage,
|
|
2206
|
+
state: await deps.stores(`folder/${space.id}`),
|
|
2207
|
+
accept: fromMirror,
|
|
2208
|
+
// Apps and the CLI on one computer meet through the folder: soon, not in a bucket's time.
|
|
2209
|
+
flushMs: 1000,
|
|
2210
|
+
})
|
|
2211
|
+
: null;
|
|
2212
|
+
if (folderMirror)
|
|
2213
|
+
mirrors.push(folderMirror);
|
|
2146
2214
|
/** Reads every mirror in the background: a space that opens from nothing — a host that lost its disk — fills in as it goes */
|
|
2147
2215
|
const pullMirrors = () => Promise.all(mirrors.map((mirror) => mirror
|
|
2148
2216
|
.pull()
|
|
@@ -2187,10 +2255,32 @@ export async function openSpaceRuntime(deps) {
|
|
|
2187
2255
|
});
|
|
2188
2256
|
/** Which network a peer was met on, so replies go back the same way */
|
|
2189
2257
|
const routes = new Map();
|
|
2258
|
+
// ─── Files ─────────────────────────────────────────────────────────
|
|
2259
|
+
//
|
|
2260
|
+
// Named on the outside of the versions that refer to them, fetched chunk by
|
|
2261
|
+
// chunk and checked as they come, kept while a body that names them is
|
|
2262
|
+
// (spec 05 §16.6).
|
|
2263
|
+
spaceFiles = createSpaceFiles({
|
|
2264
|
+
space: space.id,
|
|
2265
|
+
adapter,
|
|
2266
|
+
storage,
|
|
2267
|
+
send: (peer, message) => routes.get(peer)?.send(peer, {
|
|
2268
|
+
type: 'sync',
|
|
2269
|
+
from: session.did,
|
|
2270
|
+
payload: { ...message, v: SYNC_PROTOCOL_VERSION },
|
|
2271
|
+
}),
|
|
2272
|
+
peers: () => connectedPeers(),
|
|
2273
|
+
mirrors: () => mirrors.map((mirror) => ({ store: mirror.store, writer: mirror.writer })),
|
|
2274
|
+
stands: async (version) => {
|
|
2275
|
+
const standing = await standingOf(version);
|
|
2276
|
+
return standing.ok || !!standing.withdrawn;
|
|
2277
|
+
},
|
|
2278
|
+
});
|
|
2190
2279
|
const sync = createSyncEngine({
|
|
2191
2280
|
storageProvider: storage,
|
|
2192
2281
|
self: session.did,
|
|
2193
2282
|
holds,
|
|
2283
|
+
files: (peer, message) => spaceFiles?.onMessage(peer, message) ?? Promise.resolve(),
|
|
2194
2284
|
sendToPeer: (peerId, message) => {
|
|
2195
2285
|
routes.get(peerId)?.send(peerId, { type: 'sync', from: session.did, payload: message });
|
|
2196
2286
|
},
|
|
@@ -2442,19 +2532,28 @@ export async function openSpaceRuntime(deps) {
|
|
|
2442
2532
|
}
|
|
2443
2533
|
// ─── Writers outside this process ──────────────────────────────────
|
|
2444
2534
|
//
|
|
2445
|
-
// A folder
|
|
2446
|
-
// whatever syncs
|
|
2535
|
+
// A data folder is written by other apps, and by other devices behind
|
|
2536
|
+
// whatever syncs it; a directory store by another process (a command beside
|
|
2537
|
+
// a daemon). Nothing announces either, so both are looked for.
|
|
2538
|
+
/** Whether another writer changed anything this node holds */
|
|
2539
|
+
const look = async () => {
|
|
2540
|
+
// The same verdict as for a version from a peer.
|
|
2541
|
+
const reconciled = isFolderAdapter(adapter)
|
|
2542
|
+
? (await reconcileFolder(storage, adapter, async (version) => storable(await admit(version)))).changed
|
|
2543
|
+
: false;
|
|
2544
|
+
const pulled = folderMirror ? (await folderMirror.pull()).added > 0 : false;
|
|
2545
|
+
return reconciled || pulled;
|
|
2546
|
+
};
|
|
2447
2547
|
let watchTimer = null;
|
|
2448
|
-
if (deps.watchIntervalMs > 0 && isFolderAdapter(adapter)) {
|
|
2548
|
+
if (deps.watchIntervalMs > 0 && (folderMirror || isFolderAdapter(adapter))) {
|
|
2449
2549
|
let running = false;
|
|
2450
2550
|
watchTimer = setInterval(() => {
|
|
2451
2551
|
if (running)
|
|
2452
2552
|
return;
|
|
2453
2553
|
running = true;
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
if (!result.changed)
|
|
2554
|
+
look()
|
|
2555
|
+
.then((changed) => {
|
|
2556
|
+
if (!changed)
|
|
2458
2557
|
return;
|
|
2459
2558
|
recordsChanged();
|
|
2460
2559
|
announceSoon();
|
|
@@ -2723,7 +2822,8 @@ export async function openSpaceRuntime(deps) {
|
|
|
2723
2822
|
/** Signs and stores one version. A delete carries no body. */
|
|
2724
2823
|
async function write(collection, body, version, deleted = false, links = [], options = {}) {
|
|
2725
2824
|
const writer = options.as ?? session;
|
|
2726
|
-
|
|
2825
|
+
const asAccount = deps.accountOnly || aboutItself(collection, body, deps.rootDid, writer.did);
|
|
2826
|
+
if (asAccount && !actsForAccount(writer.proof()))
|
|
2727
2827
|
throw new Error(NOT_ACCOUNT);
|
|
2728
2828
|
// Every peer would ignore it (see buildEvent); say why here instead.
|
|
2729
2829
|
if (ACCESS_COLLECTIONS.has(collection) &&
|
|
@@ -2739,6 +2839,10 @@ export async function openSpaceRuntime(deps) {
|
|
|
2739
2839
|
}
|
|
2740
2840
|
let payload = null;
|
|
2741
2841
|
let tags = [];
|
|
2842
|
+
// The files the body refers to, named on the outside so keepers fetch and keep them.
|
|
2843
|
+
const named = deleted ? [] : fileRefsIn(body);
|
|
2844
|
+
if (named.length > MAX_FILES)
|
|
2845
|
+
throw new Error(`A record names at most ${MAX_FILES} files`);
|
|
2742
2846
|
if (!deleted) {
|
|
2743
2847
|
// Refused here, where the writer can fix it. On arrival a misfit is kept
|
|
2744
2848
|
// and flagged instead — see `conforms`.
|
|
@@ -2784,8 +2888,6 @@ export async function openSpaceRuntime(deps) {
|
|
|
2784
2888
|
collection === PROFILE_COLLECTION ||
|
|
2785
2889
|
collection === BOX_COLLECTION ||
|
|
2786
2890
|
collection === MEMBER_KEY_COLLECTION ||
|
|
2787
|
-
// What a removed carrier was is read back after the delete (`nameKeepers`).
|
|
2788
|
-
collection === CARRIER_COLLECTION ||
|
|
2789
2891
|
definition?.history === 'all' ||
|
|
2790
2892
|
(version.seq === 0 && !!(definition?.rules?.onePer || definition?.rules?.fixed)) ||
|
|
2791
2893
|
// Every version under a contract: it reads the one before, and others cite it.
|
|
@@ -2814,6 +2916,7 @@ export async function openSpaceRuntime(deps) {
|
|
|
2814
2916
|
// In the clear only where the body is: a private space sealed them above.
|
|
2815
2917
|
...(space.visibility === 'public' && !deleted && links.length ? { links } : {}),
|
|
2816
2918
|
...(tags.length ? { tags } : {}),
|
|
2919
|
+
...(named.length ? { files: named } : {}),
|
|
2817
2920
|
log,
|
|
2818
2921
|
}), writer.key);
|
|
2819
2922
|
// The same verdict every other peer will reach: refused here, with the reason, rather than there.
|
|
@@ -3369,64 +3472,47 @@ export async function openSpaceRuntime(deps) {
|
|
|
3369
3472
|
* all it holds.
|
|
3370
3473
|
*/
|
|
3371
3474
|
async function cutoffFor(did, only) {
|
|
3372
|
-
return packCutoff([(await linesOf(new Set([did]), only)).get(did) ?? []]);
|
|
3373
|
-
}
|
|
3374
|
-
/**
|
|
3375
|
-
* At most what a change may carry, shared among the accounts it reaches: one
|
|
3376
|
-
* line from each in turn, so no one's writing can use up anyone else's
|
|
3377
|
-
* share. What is left out is judged with the change.
|
|
3378
|
-
*/
|
|
3379
|
-
function packCutoff(accounts) {
|
|
3380
3475
|
const cutoff = {};
|
|
3381
|
-
|
|
3382
|
-
for (
|
|
3383
|
-
|
|
3384
|
-
const end = lines[round];
|
|
3385
|
-
if (!end || named >= MAX_CUTOFF)
|
|
3386
|
-
continue;
|
|
3387
|
-
(cutoff[end.author] ??= {})[end.collection] = end.log.n;
|
|
3388
|
-
named++;
|
|
3389
|
-
}
|
|
3476
|
+
// At most what a change may carry: what is left out is judged with the change.
|
|
3477
|
+
for (const end of (await linesOf(did, only)).slice(0, MAX_CUTOFF))
|
|
3478
|
+
(cutoff[end.author] ??= {})[end.collection] = end.log.n;
|
|
3390
3479
|
return cutoff;
|
|
3391
3480
|
}
|
|
3392
3481
|
/**
|
|
3393
|
-
* The ends of
|
|
3394
|
-
* collections first, then the rest, each in name order.
|
|
3395
|
-
* it holds, however many accounts.
|
|
3482
|
+
* The ends of an account's unbroken lines this node holds: defined
|
|
3483
|
+
* collections first, then the rest, each in name order.
|
|
3396
3484
|
*/
|
|
3397
|
-
async function linesOf(
|
|
3485
|
+
async function linesOf(did, only) {
|
|
3398
3486
|
// What it holds of theirs, whatever way it came: the lines' places are kept only for what arrived by sync.
|
|
3399
3487
|
const placed = new Map();
|
|
3400
|
-
const add = (
|
|
3488
|
+
const add = (version) => {
|
|
3401
3489
|
if (!version.log)
|
|
3402
3490
|
return;
|
|
3403
3491
|
const line = `${version.author} ${version.collection}`;
|
|
3404
|
-
const
|
|
3405
|
-
if (!
|
|
3406
|
-
|
|
3407
|
-
placed.set(line,
|
|
3492
|
+
const held = placed.get(line) ?? new Map();
|
|
3493
|
+
if (!held.has(version.log.n))
|
|
3494
|
+
held.set(version.log.n, version);
|
|
3495
|
+
placed.set(line, held);
|
|
3408
3496
|
};
|
|
3409
3497
|
for (const version of await everyCurrent()) {
|
|
3410
3498
|
if (!version.log || (only && version.author !== only) || version.space !== space.id)
|
|
3411
3499
|
continue;
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
add(root, version);
|
|
3500
|
+
if ((await judge(version)).root === did)
|
|
3501
|
+
add(version);
|
|
3415
3502
|
}
|
|
3416
3503
|
for (const name of await adapter.list(KEY_ROOT_PREFIX)) {
|
|
3417
3504
|
const key = name.slice(KEY_ROOT_PREFIX.length);
|
|
3418
|
-
|
|
3419
|
-
if ((only && key !== only) || !dids.has(did))
|
|
3505
|
+
if ((only && key !== only) || utf8Decode((await adapter.get(name)) ?? new Uint8Array()) !== did)
|
|
3420
3506
|
continue;
|
|
3421
3507
|
for (const place of await adapter.list(`${LOG_PREFIX}${key}/`)) {
|
|
3422
3508
|
const id = await adapter.get(place);
|
|
3423
3509
|
const version = id ? await storage.getVersion(utf8Decode(id)) : null;
|
|
3424
3510
|
if (version?.author === key)
|
|
3425
|
-
add(
|
|
3511
|
+
add(version);
|
|
3426
3512
|
}
|
|
3427
3513
|
}
|
|
3428
|
-
const
|
|
3429
|
-
for (const
|
|
3514
|
+
const ends = [];
|
|
3515
|
+
for (const held of placed.values()) {
|
|
3430
3516
|
let end = null;
|
|
3431
3517
|
for (let n = 0;; n++) {
|
|
3432
3518
|
const version = held.get(n);
|
|
@@ -3435,14 +3521,12 @@ export async function openSpaceRuntime(deps) {
|
|
|
3435
3521
|
end = version;
|
|
3436
3522
|
}
|
|
3437
3523
|
if (end)
|
|
3438
|
-
|
|
3524
|
+
ends.push(end);
|
|
3439
3525
|
}
|
|
3440
3526
|
// Defined collections first: writing into many undefined ones costs only whoever did.
|
|
3441
3527
|
const defined = new Set((await catalog()).keys());
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
(a.collection < b.collection ? -1 : a.collection > b.collection ? 1 : a.author < b.author ? -1 : 1));
|
|
3445
|
-
return byAccount;
|
|
3528
|
+
return ends.sort((a, b) => Number(defined.has(b.collection)) - Number(defined.has(a.collection)) ||
|
|
3529
|
+
(a.collection < b.collection ? -1 : a.collection > b.collection ? 1 : a.author < b.author ? -1 : 1));
|
|
3446
3530
|
}
|
|
3447
3531
|
/** Whether this account holds a grant, now, to do something to a record */
|
|
3448
3532
|
async function mayNow(collection, action, first) {
|
|
@@ -3466,6 +3550,8 @@ export async function openSpaceRuntime(deps) {
|
|
|
3466
3550
|
// Once at open, then after every change.
|
|
3467
3551
|
keepUp();
|
|
3468
3552
|
const pulling = pullMirrors();
|
|
3553
|
+
// What this device holds and the folder lacks (copied in, or written before the folder was) goes out soon.
|
|
3554
|
+
folderMirror?.changed();
|
|
3469
3555
|
return Object.freeze({
|
|
3470
3556
|
async list(options = {}) {
|
|
3471
3557
|
if (options.collection)
|
|
@@ -3522,6 +3608,10 @@ export async function openSpaceRuntime(deps) {
|
|
|
3522
3608
|
return false;
|
|
3523
3609
|
return mayNow(current.collection, action, await genesisOf(current));
|
|
3524
3610
|
},
|
|
3611
|
+
/** Seals a file, keeps it, and gives back the reference a body names it by (spec 05 §16.6) */
|
|
3612
|
+
addFile: (bytes) => (spaceFiles ?? missingFiles()).add(bytes),
|
|
3613
|
+
/** The bytes of a file a body refers to: held here, or fetched from peers or mirrors */
|
|
3614
|
+
readFile: (ref) => (spaceFiles ?? missingFiles()).open(ref),
|
|
3525
3615
|
/** For the node itself: writes the next version of a record in a collection `put` refuses, like the profile */
|
|
3526
3616
|
upsertSystem: (collection, recordKey, body) => upsert(collection, recordKey, body),
|
|
3527
3617
|
async profiles() {
|
|
@@ -3529,18 +3619,20 @@ export async function openSpaceRuntime(deps) {
|
|
|
3529
3619
|
},
|
|
3530
3620
|
/** For the node itself: says who this account is here, when that changed and the space takes its writes */
|
|
3531
3621
|
async publishProfile(profile) {
|
|
3532
|
-
// Someone following a space without a role in it cannot write there, and says nothing.
|
|
3533
|
-
if (await cannotWrite())
|
|
3622
|
+
// Someone following a space without a role in it cannot write there, and says nothing; nor does an app.
|
|
3623
|
+
if (!actsForAccount(session.proof()) || (await cannotWrite()))
|
|
3534
3624
|
return;
|
|
3535
3625
|
const name = profile.name.trim().slice(0, 64);
|
|
3536
3626
|
const mine = (await profileMap()).get(deps.rootDid);
|
|
3537
3627
|
// An app without the contact key must not take away the one another device published.
|
|
3538
3628
|
const contactKey = profile.contactKey ?? mine?.contactKey;
|
|
3539
|
-
if (!name ||
|
|
3629
|
+
if (!name ||
|
|
3630
|
+
(mine?.name === name && mine.contactKey === contactKey && mine.avatar?.hash === profile.avatar?.hash))
|
|
3540
3631
|
return;
|
|
3541
3632
|
await upsert(PROFILE_COLLECTION, await profileKey(deps.rootDid), {
|
|
3542
3633
|
name,
|
|
3543
3634
|
...(contactKey ? { contactKey } : {}),
|
|
3635
|
+
...(profile.avatar ? { avatar: profile.avatar } : {}),
|
|
3544
3636
|
});
|
|
3545
3637
|
},
|
|
3546
3638
|
rotateKey,
|
|
@@ -4033,6 +4125,10 @@ export async function openSpaceRuntime(deps) {
|
|
|
4033
4125
|
await keepingUp.done();
|
|
4034
4126
|
await pulling;
|
|
4035
4127
|
await Promise.all(mirrors.map((mirror) => mirror.close()));
|
|
4128
|
+
if (filesTimer)
|
|
4129
|
+
clearTimeout(filesTimer);
|
|
4130
|
+
spaceFiles?.close();
|
|
4131
|
+
await filesPass;
|
|
4036
4132
|
if (watchTimer)
|
|
4037
4133
|
clearInterval(watchTimer);
|
|
4038
4134
|
if (announceTimer)
|