@telecrypt-io/storage 0.5.29 → 0.5.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -132,7 +132,7 @@ function matrixRequestTimeout(options) {
|
|
|
132
132
|
const value = options?.timeoutMs ?? options?.localTimeoutMs ?? MATRIX_HTTP_TIMEOUT_MS;
|
|
133
133
|
if (!Number.isFinite(value) || value <= 0)
|
|
134
134
|
throw new Error("invalid Matrix request timeout");
|
|
135
|
-
return
|
|
135
|
+
return value;
|
|
136
136
|
}
|
|
137
137
|
function matrixRequestSignal(options) {
|
|
138
138
|
return options?.signal ?? options?.abortSignal;
|
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.js
CHANGED
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
import { TeleCryptIOStorage } from "../TeleCryptIOStorage.js";
|
|
14
14
|
import type { DownloadedFile, FolderDetails, FolderInfo, FileDetails, FileInfo, VaultDetails, VaultInfo, DeleteResult, JoinResult, Member, RecoveryRestore, RecoverySetup, RenameResult, ShareResult, UnshareResult } from "./types.js";
|
|
15
15
|
export interface OperationOptions {
|
|
16
|
-
/** Cancels
|
|
16
|
+
/** Cancels waits and rate-limit backoff before the next mutation. */
|
|
17
17
|
signal?: AbortSignal;
|
|
18
|
-
/**
|
|
18
|
+
/** Optional wall-clock budget supplied by the caller. */
|
|
19
19
|
timeoutMs?: number;
|
|
20
20
|
}
|
|
21
21
|
export declare function createVault(storage: TeleCryptIOStorage, name: string, options?: OperationOptions): Promise<VaultInfo>;
|
package/dist/core/operations.js
CHANGED
|
@@ -31,13 +31,10 @@ const RATE_LIMIT_DEFAULT_DELAY_MS = 15_000;
|
|
|
31
31
|
// JavaScript timers cannot represent a longer delay reliably. The operation's
|
|
32
32
|
// own deadline remains the authority that stops retrying.
|
|
33
33
|
const MAX_TIMER_DELAY_MS = 2_147_483_647;
|
|
34
|
-
const MAX_DELETION_ROOMS = 4096;
|
|
35
|
-
const MAX_DELETION_DEPTH = 128;
|
|
36
|
-
const DEFAULT_MUTATION_TIMEOUT_MS = 5 * 60_000;
|
|
37
|
-
const MAX_MUTATION_TIMEOUT_MS = 15 * 60_000;
|
|
38
34
|
function createOperationDeadline(options) {
|
|
39
|
-
const timeoutMs = options?.timeoutMs
|
|
40
|
-
if (
|
|
35
|
+
const timeoutMs = options?.timeoutMs;
|
|
36
|
+
if (timeoutMs !== undefined &&
|
|
37
|
+
(!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs > MAX_TIMER_DELAY_MS)) {
|
|
41
38
|
throw new StorageError("invalid operation timeout");
|
|
42
39
|
}
|
|
43
40
|
const controller = new AbortController();
|
|
@@ -45,11 +42,14 @@ function createOperationDeadline(options) {
|
|
|
45
42
|
options?.signal?.addEventListener("abort", onAbort, { once: true });
|
|
46
43
|
if (options?.signal?.aborted)
|
|
47
44
|
onAbort();
|
|
48
|
-
const timer =
|
|
45
|
+
const timer = timeoutMs === undefined
|
|
46
|
+
? undefined
|
|
47
|
+
: setTimeout(() => controller.abort(new Error("operation timed out")), timeoutMs);
|
|
49
48
|
return {
|
|
50
49
|
signal: controller.signal,
|
|
51
50
|
close: () => {
|
|
52
|
-
|
|
51
|
+
if (timer !== undefined)
|
|
52
|
+
clearTimeout(timer);
|
|
53
53
|
options?.signal?.removeEventListener("abort", onAbort);
|
|
54
54
|
},
|
|
55
55
|
};
|
|
@@ -205,37 +205,6 @@ async function resolveFile(storage, tree, fileId, signal) {
|
|
|
205
205
|
throw new StorageError("file lookup failed", { cause: error });
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
|
-
function snapshotTreeSpaces(root, tooLargeMessage = "storage tree is too large") {
|
|
209
|
-
const spaces = [];
|
|
210
|
-
const seen = new Set();
|
|
211
|
-
const pending = [{ tree: root, depth: 0 }];
|
|
212
|
-
while (pending.length > 0) {
|
|
213
|
-
const next = pending.pop();
|
|
214
|
-
if (!next)
|
|
215
|
-
continue;
|
|
216
|
-
const { tree, depth } = next;
|
|
217
|
-
if (seen.has(tree.id))
|
|
218
|
-
continue;
|
|
219
|
-
if (depth > MAX_DELETION_DEPTH || spaces.length >= MAX_DELETION_ROOMS) {
|
|
220
|
-
throw new StorageError(tooLargeMessage);
|
|
221
|
-
}
|
|
222
|
-
seen.add(tree.id);
|
|
223
|
-
spaces.push(tree);
|
|
224
|
-
let children;
|
|
225
|
-
try {
|
|
226
|
-
children = tree.getDirectories();
|
|
227
|
-
}
|
|
228
|
-
catch (error) {
|
|
229
|
-
throw new StorageError("could not enumerate storage space descendants safely", { cause: error });
|
|
230
|
-
}
|
|
231
|
-
if (children.length > MAX_DELETION_ROOMS) {
|
|
232
|
-
throw new StorageError(tooLargeMessage);
|
|
233
|
-
}
|
|
234
|
-
for (const child of children)
|
|
235
|
-
pending.push({ tree: child, depth: depth + 1 });
|
|
236
|
-
}
|
|
237
|
-
return spaces;
|
|
238
|
-
}
|
|
239
208
|
/**
|
|
240
209
|
* Deleting a tree is deliberately a one-room operation. File versions are
|
|
241
210
|
* physical Matrix media events, so callers must delete files explicitly and
|
|
@@ -318,6 +287,55 @@ function isActiveRelationEvent(event) {
|
|
|
318
287
|
!Array.isArray(content) &&
|
|
319
288
|
Object.keys(content).length > 0);
|
|
320
289
|
}
|
|
290
|
+
function activeTreeDirectories(client, tree) {
|
|
291
|
+
const childEvents = readRelationEvents(client, tree.id, EventType.SpaceChild);
|
|
292
|
+
if (childEvents === null)
|
|
293
|
+
throw new StorageError("delete graph is unsafe");
|
|
294
|
+
const activeChildIds = new Set();
|
|
295
|
+
for (const event of childEvents) {
|
|
296
|
+
if (!isActiveRelationEvent(event))
|
|
297
|
+
continue;
|
|
298
|
+
const childId = relationStateKey(event);
|
|
299
|
+
if (!childId)
|
|
300
|
+
throw new StorageError("delete graph is unsafe");
|
|
301
|
+
activeChildIds.add(childId);
|
|
302
|
+
}
|
|
303
|
+
const knownChildren = new Map(tree.getDirectories().map((child) => [child.id, child]));
|
|
304
|
+
return [...activeChildIds].map((childId) => {
|
|
305
|
+
const child = knownChildren.get(childId);
|
|
306
|
+
if (!child)
|
|
307
|
+
throw new StorageError("delete graph is unsafe");
|
|
308
|
+
return child;
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
function snapshotTreeSpaces(root, activeRelationClient) {
|
|
312
|
+
const spaces = [];
|
|
313
|
+
const seen = new Set();
|
|
314
|
+
const pending = [root];
|
|
315
|
+
while (pending.length > 0) {
|
|
316
|
+
const tree = pending.pop();
|
|
317
|
+
if (!tree)
|
|
318
|
+
continue;
|
|
319
|
+
if (seen.has(tree.id))
|
|
320
|
+
continue;
|
|
321
|
+
seen.add(tree.id);
|
|
322
|
+
spaces.push(tree);
|
|
323
|
+
let children;
|
|
324
|
+
try {
|
|
325
|
+
children = activeRelationClient
|
|
326
|
+
? activeTreeDirectories(activeRelationClient, tree)
|
|
327
|
+
: tree.getDirectories();
|
|
328
|
+
}
|
|
329
|
+
catch (error) {
|
|
330
|
+
if (error instanceof StorageError)
|
|
331
|
+
throw error;
|
|
332
|
+
throw new StorageError("could not enumerate storage space descendants safely", { cause: error });
|
|
333
|
+
}
|
|
334
|
+
for (const child of children)
|
|
335
|
+
pending.push(child);
|
|
336
|
+
}
|
|
337
|
+
return spaces;
|
|
338
|
+
}
|
|
321
339
|
/**
|
|
322
340
|
* A deleted MSC3089 branch is represented by an authoritative empty state
|
|
323
341
|
* event. Inactive branches with metadata are historical versions, and a
|
|
@@ -358,13 +376,7 @@ function validateDeletionGraph(client, root, ids, deletedRooms) {
|
|
|
358
376
|
const tree = client.unstableGetFileTreeSpace(id);
|
|
359
377
|
if (!tree)
|
|
360
378
|
throw new StorageError("delete graph is unsafe");
|
|
361
|
-
|
|
362
|
-
try {
|
|
363
|
-
directories = tree.getDirectories();
|
|
364
|
-
}
|
|
365
|
-
catch (error) {
|
|
366
|
-
throw new StorageError("delete graph is unsafe", { cause: error });
|
|
367
|
-
}
|
|
379
|
+
const directories = activeTreeDirectories(client, tree);
|
|
368
380
|
for (const child of directories)
|
|
369
381
|
addEdge(id, child.id);
|
|
370
382
|
const childEvents = readRelationEvents(client, id, EventType.SpaceChild);
|
|
@@ -1013,8 +1025,7 @@ export async function listSubfolders(storage, parentId, options) {
|
|
|
1013
1025
|
const tree = await resolveTree(storage, parentId, signal);
|
|
1014
1026
|
await storage.refreshRoomState(parentId, { signal });
|
|
1015
1027
|
ensureOperationActive(signal);
|
|
1016
|
-
const directories = tree
|
|
1017
|
-
.getDirectories()
|
|
1028
|
+
const directories = activeTreeDirectories(storage.getClient(), tree)
|
|
1018
1029
|
.filter((directory) => !isMarkedTreeDeleted(storage, directory.id));
|
|
1019
1030
|
return directories.map((d) => ({ id: d.id, name: d.room.name }));
|
|
1020
1031
|
});
|
|
@@ -1094,7 +1105,7 @@ async function deleteTree(storage, treeId, options) {
|
|
|
1094
1105
|
// part of this operation and must not block deletion merely because
|
|
1095
1106
|
// their membership is not joined.
|
|
1096
1107
|
await refreshDeletionRooms(storage, tree.id, operation.signal);
|
|
1097
|
-
const spaces = snapshotTreeSpaces(tree,
|
|
1108
|
+
const spaces = snapshotTreeSpaces(tree, client);
|
|
1098
1109
|
const activeSpaces = spaces.filter((space) => !removedRooms.has(space.id));
|
|
1099
1110
|
const ids = new Set(activeSpaces.map((space) => space.id));
|
|
1100
1111
|
if (!ids.has(tree.id)) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
/** Shared name contract used by SDK inputs and remote projections. */
|
|
2
|
-
export declare const MAX_NAME_LENGTH = 512;
|
|
3
2
|
export declare function isValidName(value: unknown): value is string;
|
|
4
3
|
export declare function validateName(value: unknown, label: string): asserts value is string;
|
package/dist/core/validation.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/** Shared name contract used by SDK inputs and remote projections. */
|
|
2
|
-
export const MAX_NAME_LENGTH = 512;
|
|
3
2
|
export function isValidName(value) {
|
|
4
3
|
return (typeof value === "string" &&
|
|
5
4
|
value.length > 0 &&
|
|
6
|
-
value.length <= MAX_NAME_LENGTH &&
|
|
7
5
|
!/[\u0000-\u001f\u007f]/.test(value));
|
|
8
6
|
}
|
|
9
7
|
export function validateName(value, label) {
|