swarm-deploy 0.0.0 → 0.1.0

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.
Files changed (115) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/LICENSE.md +201 -0
  3. package/NOTICE.md +13 -0
  4. package/README.md +652 -0
  5. package/RELEASING.md +71 -0
  6. package/SECURITY.md +41 -0
  7. package/dist/abort.d.ts +16 -0
  8. package/dist/abort.js +52 -0
  9. package/dist/abort.js.map +1 -0
  10. package/dist/allowlist.d.ts +2 -0
  11. package/dist/allowlist.js +21 -0
  12. package/dist/allowlist.js.map +1 -0
  13. package/dist/bin/swarm-deploy.d.ts +2 -0
  14. package/dist/bin/swarm-deploy.js +41 -0
  15. package/dist/bin/swarm-deploy.js.map +1 -0
  16. package/dist/cli.d.ts +25 -0
  17. package/dist/cli.js +694 -0
  18. package/dist/cli.js.map +1 -0
  19. package/dist/client.d.ts +121 -0
  20. package/dist/client.js +285 -0
  21. package/dist/client.js.map +1 -0
  22. package/dist/direct-dht.d.ts +81 -0
  23. package/dist/direct-dht.js +254 -0
  24. package/dist/direct-dht.js.map +1 -0
  25. package/dist/error-code.d.ts +15 -0
  26. package/dist/error-code.js +30 -0
  27. package/dist/error-code.js.map +1 -0
  28. package/dist/errors.d.ts +27 -0
  29. package/dist/errors.js +33 -0
  30. package/dist/errors.js.map +1 -0
  31. package/dist/events-node.d.ts +2 -0
  32. package/dist/events-node.js +7 -0
  33. package/dist/events-node.js.map +1 -0
  34. package/dist/files.d.ts +47 -0
  35. package/dist/files.js +150 -0
  36. package/dist/files.js.map +1 -0
  37. package/dist/fs-node.d.ts +2 -0
  38. package/dist/fs-node.js +7 -0
  39. package/dist/fs-node.js.map +1 -0
  40. package/dist/identity.d.ts +7 -0
  41. package/dist/identity.js +50 -0
  42. package/dist/identity.js.map +1 -0
  43. package/dist/index.d.ts +8 -0
  44. package/dist/index.js +19 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/os-node.d.ts +2 -0
  47. package/dist/os-node.js +7 -0
  48. package/dist/os-node.js.map +1 -0
  49. package/dist/path-node.d.ts +2 -0
  50. package/dist/path-node.js +7 -0
  51. package/dist/path-node.js.map +1 -0
  52. package/dist/process-node.d.ts +2 -0
  53. package/dist/process-node.js +7 -0
  54. package/dist/process-node.js.map +1 -0
  55. package/dist/server.d.ts +153 -0
  56. package/dist/server.js +576 -0
  57. package/dist/server.js.map +1 -0
  58. package/dist/storage/atomic-file.d.ts +15 -0
  59. package/dist/storage/atomic-file.js +172 -0
  60. package/dist/storage/atomic-file.js.map +1 -0
  61. package/dist/storage/commit-journal.d.ts +83 -0
  62. package/dist/storage/commit-journal.js +279 -0
  63. package/dist/storage/commit-journal.js.map +1 -0
  64. package/dist/storage/commit-store.d.ts +246 -0
  65. package/dist/storage/commit-store.js +1339 -0
  66. package/dist/storage/commit-store.js.map +1 -0
  67. package/dist/storage/layout.d.ts +16 -0
  68. package/dist/storage/layout.js +403 -0
  69. package/dist/storage/layout.js.map +1 -0
  70. package/dist/storage/recovery.d.ts +99 -0
  71. package/dist/storage/recovery.js +253 -0
  72. package/dist/storage/recovery.js.map +1 -0
  73. package/dist/storage/retention.d.ts +163 -0
  74. package/dist/storage/retention.js +465 -0
  75. package/dist/storage/retention.js.map +1 -0
  76. package/dist/storage/root-coordinator.d.ts +7 -0
  77. package/dist/storage/root-coordinator.js +27 -0
  78. package/dist/storage/root-coordinator.js.map +1 -0
  79. package/dist/storage/session-store.d.ts +2 -0
  80. package/dist/storage/session-store.js +7 -0
  81. package/dist/storage/session-store.js.map +1 -0
  82. package/dist/storage/tar-session-store.d.ts +116 -0
  83. package/dist/storage/tar-session-store.js +816 -0
  84. package/dist/storage/tar-session-store.js.map +1 -0
  85. package/dist/storage/types.d.ts +62 -0
  86. package/dist/storage/types.js +3 -0
  87. package/dist/storage/types.js.map +1 -0
  88. package/dist/tar-protocol/controls.d.ts +48 -0
  89. package/dist/tar-protocol/controls.js +185 -0
  90. package/dist/tar-protocol/controls.js.map +1 -0
  91. package/dist/tar-protocol/direct-wire.d.ts +43 -0
  92. package/dist/tar-protocol/direct-wire.js +194 -0
  93. package/dist/tar-protocol/direct-wire.js.map +1 -0
  94. package/dist/tar-protocol/extract.d.ts +18 -0
  95. package/dist/tar-protocol/extract.js +124 -0
  96. package/dist/tar-protocol/extract.js.map +1 -0
  97. package/dist/tar-protocol/hash.d.ts +10 -0
  98. package/dist/tar-protocol/hash.js +44 -0
  99. package/dist/tar-protocol/hash.js.map +1 -0
  100. package/dist/tar-protocol/lifecycle.d.ts +13 -0
  101. package/dist/tar-protocol/lifecycle.js +90 -0
  102. package/dist/tar-protocol/lifecycle.js.map +1 -0
  103. package/dist/tar-protocol/manifest.d.ts +46 -0
  104. package/dist/tar-protocol/manifest.js +287 -0
  105. package/dist/tar-protocol/manifest.js.map +1 -0
  106. package/dist/tar-protocol/ustar.d.ts +22 -0
  107. package/dist/tar-protocol/ustar.js +87 -0
  108. package/dist/tar-protocol/ustar.js.map +1 -0
  109. package/dist/types.d.ts +58 -0
  110. package/dist/types.js +3 -0
  111. package/dist/types.js.map +1 -0
  112. package/dist/validation.d.ts +4 -0
  113. package/dist/validation.js +26 -0
  114. package/dist/validation.js.map +1 -0
  115. package/package.json +101 -1
@@ -0,0 +1,465 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.MAX_CLEANUP_INTERVAL = exports.DEFAULT_CLEANUP_INTERVAL = exports.DEFAULT_RESUME_TTL = exports.RetentionManager = void 0;
7
+ const b4a_1 = __importDefault(require("b4a"));
8
+ const error_code_js_1 = require("../error-code.js");
9
+ const _fs_1 = __importDefault(require("#fs"));
10
+ const _path_1 = __importDefault(require("#path"));
11
+ const errors_js_1 = require("../errors.js");
12
+ const layout_js_1 = require("./layout.js");
13
+ const hash_js_1 = require("../tar-protocol/hash.js");
14
+ const validation_js_1 = require("../validation.js");
15
+ const root_coordinator_js_1 = require("./root-coordinator.js");
16
+ const DEFAULT_RESUME_TTL = 7 * 24 * 60 * 60 * 1000;
17
+ exports.DEFAULT_RESUME_TTL = DEFAULT_RESUME_TTL;
18
+ const DEFAULT_CLEANUP_INTERVAL = 15 * 60 * 1000;
19
+ exports.DEFAULT_CLEANUP_INTERVAL = DEFAULT_CLEANUP_INTERVAL;
20
+ const MAX_CLEANUP_INTERVAL = 0x7fffffff;
21
+ exports.MAX_CLEANUP_INTERVAL = MAX_CLEANUP_INTERVAL;
22
+ function unrefTimer(timer) {
23
+ if (typeof timer !== 'object' || timer === null || !('unref' in timer))
24
+ return;
25
+ if (typeof timer.unref === 'function')
26
+ timer.unref();
27
+ }
28
+ function errorMessage(error) {
29
+ return error instanceof Error ? error.message : String(error);
30
+ }
31
+ function storageError(message, cause = null) {
32
+ return new errors_js_1.SwarmDeployError(errors_js_1.ERRORS.PROTOCOL_INVALID, message, cause);
33
+ }
34
+ function cleanupError(message, cause = null) {
35
+ return new errors_js_1.SwarmDeployError(errors_js_1.ERRORS.CLEANUP_FAILED, message, cause);
36
+ }
37
+ function assertPositiveSafeUint(value, name) {
38
+ (0, validation_js_1.assertSafeUint)(value, name);
39
+ if (value === 0)
40
+ throw storageError(`Invalid ${name}`);
41
+ }
42
+ function report(logger, level, message, details) {
43
+ if (!logger || typeof logger[level] !== 'function')
44
+ return;
45
+ try {
46
+ logger[level]?.(message, details);
47
+ }
48
+ catch { }
49
+ }
50
+ function compareRecords(left, right) {
51
+ if (left.committedAt !== right.committedAt)
52
+ return left.committedAt - right.committedAt;
53
+ return left.name < right.name ? -1 : left.name > right.name ? 1 : 0;
54
+ }
55
+ function identityMatches(left, right) {
56
+ return left.dev === right.dev && left.ino === right.ino;
57
+ }
58
+ async function readExactly(handle, bytes, position) {
59
+ let offset = 0;
60
+ while (offset < bytes.byteLength) {
61
+ const read = await handle.read(bytes, offset, bytes.byteLength - offset, position + offset);
62
+ const count = typeof read === 'number' ? read : read.bytesRead;
63
+ if (!Number.isSafeInteger(count) || count <= 0)
64
+ return false;
65
+ offset += count;
66
+ }
67
+ return true;
68
+ }
69
+ function inspectManagedFinal(record, { layout, storage, hash }) {
70
+ const finalPath = _path_1.default.join(layout.root, record.name);
71
+ return (0, layout_js_1.withSafeDirectoryIdentity)(layout.root, storage, async () => {
72
+ let initial;
73
+ try {
74
+ initial = await storage.lstat(finalPath);
75
+ }
76
+ catch (err) {
77
+ if ((0, error_code_js_1.isMissing)(err))
78
+ return 'MISSING';
79
+ throw err;
80
+ }
81
+ if (initial.isSymbolicLink())
82
+ return 'SYMLINK';
83
+ if (!initial.isFile())
84
+ return 'NON_REGULAR';
85
+ if (initial.size !== record.size)
86
+ return 'WRONG_SIZE';
87
+ if (!hash)
88
+ return 'VALID';
89
+ const digest = new hash_js_1.SodiumSha256();
90
+ let handle = null;
91
+ try {
92
+ handle = await (0, layout_js_1.openSafeRegularFile)(finalPath, 'read', storage);
93
+ const before = await handle.stat();
94
+ if (!before.isFile() || before.size !== record.size || !identityMatches(initial, before)) {
95
+ return 'CHANGED';
96
+ }
97
+ let position = 0;
98
+ while (position < record.size) {
99
+ const bytes = b4a_1.default.alloc(Math.min(64 * 1024, record.size - position));
100
+ if (!(await readExactly(handle, bytes, position)))
101
+ return 'TRUNCATED';
102
+ digest.update(bytes);
103
+ position += bytes.byteLength;
104
+ }
105
+ const after = await handle.stat();
106
+ if (!after.isFile() || after.size !== record.size || !identityMatches(before, after)) {
107
+ return 'CHANGED';
108
+ }
109
+ if (!(0, hash_js_1.digestMatches)(digest.digest(), b4a_1.default.from(record.sha256, 'hex')))
110
+ return 'DIGEST_INVALID';
111
+ let visible;
112
+ try {
113
+ visible = await storage.lstat(finalPath);
114
+ }
115
+ catch (err) {
116
+ if ((0, error_code_js_1.isMissing)(err))
117
+ return 'CHANGED';
118
+ throw err;
119
+ }
120
+ if (!visible.isFile() || visible.size !== record.size || !identityMatches(initial, visible)) {
121
+ return 'CHANGED';
122
+ }
123
+ return 'VALID';
124
+ }
125
+ finally {
126
+ if (handle)
127
+ await handle.close();
128
+ }
129
+ });
130
+ }
131
+ class RetentionManager {
132
+ layout;
133
+ sessionStore;
134
+ commitStore;
135
+ maxAge;
136
+ maxStorageBytes;
137
+ resumeTtl;
138
+ cleanupInterval;
139
+ clock;
140
+ storage;
141
+ isSessionActive;
142
+ hasActiveUploads;
143
+ isPinned;
144
+ logger;
145
+ timer;
146
+ cleanupFailure;
147
+ scheduler;
148
+ onEvent;
149
+ startPromise;
150
+ tickPromise;
151
+ tickQueued;
152
+ lifecycle;
153
+ constructor({ layout, sessionStore, commitStore, maxAge, maxStorageBytes, resumeTtl = DEFAULT_RESUME_TTL, cleanupInterval = DEFAULT_CLEANUP_INTERVAL, clock = Date, storage = commitStore?.storage || _fs_1.default.promises, isSessionActive, hasActiveUploads = () => false, isPinned = () => false, logger = null, scheduler = { setInterval, clearInterval }, onEvent = null }) {
154
+ if (!layout || typeof layout !== 'object')
155
+ throw storageError('Invalid storage layout');
156
+ if (!sessionStore || typeof sessionStore.expire !== 'function') {
157
+ throw storageError('Invalid session store');
158
+ }
159
+ if (!commitStore ||
160
+ typeof commitStore.list !== 'function' ||
161
+ typeof commitStore.scrubRecords !== 'function' ||
162
+ typeof commitStore.delete !== 'function' ||
163
+ typeof commitStore.purge !== 'function') {
164
+ throw storageError('Invalid commit store');
165
+ }
166
+ if (!clock || typeof clock.now !== 'function')
167
+ throw storageError('Invalid clock');
168
+ if (!storage || typeof storage !== 'object')
169
+ throw storageError('Invalid storage adapter');
170
+ if (!scheduler ||
171
+ typeof scheduler.setInterval !== 'function' ||
172
+ typeof scheduler.clearInterval !== 'function') {
173
+ throw storageError('Invalid retention scheduler');
174
+ }
175
+ if (typeof isSessionActive !== 'function') {
176
+ throw storageError('Invalid session activity predicate');
177
+ }
178
+ if (typeof hasActiveUploads !== 'function') {
179
+ throw storageError('Invalid active upload predicate');
180
+ }
181
+ if (typeof isPinned !== 'function')
182
+ throw storageError('Invalid retention pin predicate');
183
+ if (onEvent !== null && typeof onEvent !== 'function') {
184
+ throw storageError('Invalid retention event callback');
185
+ }
186
+ if (maxAge !== undefined)
187
+ (0, validation_js_1.assertSafeUint)(maxAge, 'maxAge');
188
+ if (maxStorageBytes !== undefined)
189
+ (0, validation_js_1.assertSafeUint)(maxStorageBytes, 'maxStorageBytes');
190
+ assertPositiveSafeUint(resumeTtl, 'resumeTtl');
191
+ assertPositiveSafeUint(cleanupInterval, 'cleanupInterval');
192
+ if (cleanupInterval > MAX_CLEANUP_INTERVAL)
193
+ throw storageError('Invalid cleanupInterval');
194
+ this.layout = layout;
195
+ this.sessionStore = sessionStore;
196
+ this.commitStore = commitStore;
197
+ this.maxAge = maxAge;
198
+ this.maxStorageBytes = maxStorageBytes;
199
+ this.resumeTtl = resumeTtl;
200
+ this.cleanupInterval = cleanupInterval;
201
+ this.clock = clock;
202
+ this.storage = storage;
203
+ this.isSessionActive = isSessionActive;
204
+ this.hasActiveUploads = hasActiveUploads;
205
+ this.isPinned = isPinned;
206
+ this.logger = logger;
207
+ this.timer = null;
208
+ this.cleanupFailure = null;
209
+ this.scheduler = scheduler;
210
+ this.onEvent = onEvent;
211
+ this.startPromise = null;
212
+ this.tickPromise = null;
213
+ this.tickQueued = false;
214
+ this.lifecycle = 0;
215
+ }
216
+ _emit(payload) {
217
+ if (!this.onEvent)
218
+ return;
219
+ try {
220
+ this.onEvent({ type: 'retention', ...payload });
221
+ }
222
+ catch { }
223
+ }
224
+ _hasActiveReceivingUpload() {
225
+ if (this.hasActiveUploads())
226
+ return true;
227
+ if (!(this.sessionStore.sessions instanceof Map))
228
+ return false;
229
+ for (const session of this.sessionStore.sessions.values()) {
230
+ if (session.state === 'receiving' && this.isSessionActive(session))
231
+ return true;
232
+ }
233
+ return false;
234
+ }
235
+ expireSessions() {
236
+ return this.sessionStore.expire(this.resumeTtl, (session) => !this.isSessionActive(session));
237
+ }
238
+ async scrubCommitted({ hash = true } = {}) {
239
+ if (typeof hash !== 'boolean')
240
+ throw storageError('Invalid scrub hash option');
241
+ for (const directory of [this.layout.root, this.layout.internal, this.layout.commits]) {
242
+ await (0, layout_js_1.assertSafeDirectory)(directory, this.storage);
243
+ }
244
+ let scanned;
245
+ try {
246
+ scanned = await this.commitStore.scrubRecords();
247
+ }
248
+ catch (err) {
249
+ throw cleanupError('Unable to scrub managed commit metadata', err);
250
+ }
251
+ const records = scanned.records;
252
+ const knownNames = new Set(records.map((record) => record.name));
253
+ const rootNames = await (0, layout_js_1.withSafeDirectoryIdentity)(this.layout.root, this.storage, () => this.storage.readdir(this.layout.root));
254
+ const unknown = rootNames
255
+ .filter((name) => name !== '.swarm-deploy' && !knownNames.has(name))
256
+ .sort();
257
+ for (const name of unknown) {
258
+ report(this.logger, 'warn', 'Ignoring unknown committed path', { name });
259
+ }
260
+ const valid = [];
261
+ let deleted = scanned.deleted;
262
+ for (const record of records) {
263
+ const status = await inspectManagedFinal(record, {
264
+ layout: this.layout,
265
+ storage: this.storage,
266
+ hash
267
+ });
268
+ if (status === 'VALID') {
269
+ valid.push(record);
270
+ continue;
271
+ }
272
+ let purged;
273
+ try {
274
+ purged = await this.commitStore.purge(record, { preservePath: status === 'CHANGED' });
275
+ if (!purged) {
276
+ throw storageError('Managed commit record disappeared during scrub');
277
+ }
278
+ }
279
+ catch (err) {
280
+ throw cleanupError('Unable to remove invalid managed commit', err);
281
+ }
282
+ deleted++;
283
+ if (purged.preservedPath) {
284
+ unknown.push(record.name);
285
+ report(this.logger, 'warn', 'Preserving non-empty managed directory', {
286
+ name: record.name
287
+ });
288
+ }
289
+ report(this.logger, 'warn', 'Removed invalid managed commit', {
290
+ name: record.name,
291
+ reason: status
292
+ });
293
+ }
294
+ return { records: valid, deleted, unknown: unknown.sort() };
295
+ }
296
+ async _deleteRecord(record, reason) {
297
+ try {
298
+ if (!(await this.commitStore.delete(record))) {
299
+ throw storageError('Managed commit record disappeared during retention');
300
+ }
301
+ }
302
+ catch (err) {
303
+ throw cleanupError('Unable to remove managed commit', err);
304
+ }
305
+ report(this.logger, 'info', 'Removed managed commit', { name: record.name, reason });
306
+ }
307
+ /**
308
+ * Configured mutable current records survive age and quota eviction. Their
309
+ * size still counts toward the logical total so a replacement that cannot be
310
+ * afforded fails instead of silently exceeding the limit.
311
+ */
312
+ _isPinned(record) {
313
+ return this.isPinned(record) === true;
314
+ }
315
+ _totalSize(records) {
316
+ let total = 0;
317
+ for (const record of records) {
318
+ if (total > Number.MAX_SAFE_INTEGER - record.size) {
319
+ throw storageError('Managed commit size exceeds safe integer range');
320
+ }
321
+ total += record.size;
322
+ }
323
+ return total;
324
+ }
325
+ run(options = {}) {
326
+ return (0, root_coordinator_js_1.withRootLease)(this.layout.root, () => this._runUnlocked(options));
327
+ }
328
+ async _runUnlocked(options = {}) {
329
+ const trigger = options.trigger || 'manual';
330
+ try {
331
+ const result = await this._run(options);
332
+ this.cleanupFailure = null;
333
+ this._emit({ trigger, status: 'completed', ...result });
334
+ return result;
335
+ }
336
+ catch (err) {
337
+ this.cleanupFailure = err;
338
+ this._emit({ trigger, status: 'failed', reason: (0, error_code_js_1.errorCode)(err) || errors_js_1.ERRORS.CLEANUP_FAILED });
339
+ throw err;
340
+ }
341
+ }
342
+ async _run({ incomingBytes = 0 } = {}) {
343
+ (0, validation_js_1.assertSafeUint)(incomingBytes, 'incomingBytes');
344
+ if (this.maxStorageBytes !== undefined && incomingBytes > this.maxStorageBytes) {
345
+ throw new errors_js_1.SwarmDeployError(errors_js_1.ERRORS.FILE_TOO_LARGE, 'Incoming artifact exceeds committed storage limit');
346
+ }
347
+ const expiredSessions = await this.expireSessions();
348
+ const scrub = await this.scrubCommitted({ hash: false });
349
+ const current = scrub.records.slice();
350
+ let ageDeleted = 0;
351
+ if (this.maxAge !== undefined) {
352
+ const now = this.clock.now();
353
+ (0, validation_js_1.assertSafeUint)(now, 'current timestamp');
354
+ for (const record of current.slice().sort(compareRecords)) {
355
+ if (this._isPinned(record))
356
+ continue;
357
+ if (now < record.committedAt || now - record.committedAt < this.maxAge)
358
+ continue;
359
+ await this._deleteRecord(record, 'MAX_AGE');
360
+ current.splice(current.indexOf(record), 1);
361
+ ageDeleted++;
362
+ }
363
+ }
364
+ let storageDeleted = 0;
365
+ if (this.maxStorageBytes !== undefined) {
366
+ const permitted = this.maxStorageBytes - incomingBytes;
367
+ let total = this._totalSize(current);
368
+ for (const record of current.slice().sort(compareRecords)) {
369
+ if (total <= permitted)
370
+ break;
371
+ if (this._isPinned(record))
372
+ continue;
373
+ await this._deleteRecord(record, 'MAX_STORAGE');
374
+ total -= record.size;
375
+ storageDeleted++;
376
+ }
377
+ if (total > permitted)
378
+ throw storageError('Unable to reserve committed storage capacity');
379
+ }
380
+ return { expiredSessions, scrubbed: scrub.deleted, ageDeleted, storageDeleted };
381
+ }
382
+ afterCommit() {
383
+ return (0, root_coordinator_js_1.withRootLease)(this.layout.root, () => this._afterCommitUnlocked());
384
+ }
385
+ async _afterCommitUnlocked() {
386
+ try {
387
+ await this._runUnlocked({ trigger: 'post-commit' });
388
+ return true;
389
+ }
390
+ catch (err) {
391
+ this.cleanupFailure = err;
392
+ report(this.logger, 'error', 'Post-commit retention failed', { message: errorMessage(err) });
393
+ return false;
394
+ }
395
+ }
396
+ start() {
397
+ if (this.timer)
398
+ return Promise.resolve();
399
+ if (this.startPromise)
400
+ return this.startPromise;
401
+ const lifecycle = ++this.lifecycle;
402
+ const start = (async () => {
403
+ await this.run({ trigger: 'startup' });
404
+ if (lifecycle !== this.lifecycle || this.timer)
405
+ return;
406
+ this.timer = this.scheduler.setInterval(() => this._scheduleTick(lifecycle), this.cleanupInterval);
407
+ unrefTimer(this.timer);
408
+ })();
409
+ this.startPromise = start;
410
+ start.then(() => {
411
+ if (this.startPromise === start)
412
+ this.startPromise = null;
413
+ }, () => {
414
+ if (this.startPromise === start)
415
+ this.startPromise = null;
416
+ });
417
+ return start;
418
+ }
419
+ _scheduleTick(lifecycle) {
420
+ if (lifecycle !== this.lifecycle || !this.timer)
421
+ return;
422
+ if (this.tickPromise) {
423
+ this.tickQueued = true;
424
+ return;
425
+ }
426
+ const tick = this._drainTicks(lifecycle);
427
+ this.tickPromise = tick;
428
+ tick.then(() => {
429
+ if (this.tickPromise === tick)
430
+ this.tickPromise = null;
431
+ }, () => {
432
+ if (this.tickPromise === tick)
433
+ this.tickPromise = null;
434
+ });
435
+ }
436
+ async _drainTicks(lifecycle) {
437
+ do {
438
+ this.tickQueued = false;
439
+ if (this._hasActiveReceivingUpload()) {
440
+ this._emit({ trigger: 'scheduled', status: 'deferred', reason: 'ACTIVE_RECEIVE' });
441
+ return;
442
+ }
443
+ try {
444
+ await this.run({ trigger: 'scheduled' });
445
+ }
446
+ catch (err) {
447
+ this.cleanupFailure = err;
448
+ report(this.logger, 'error', 'Scheduled retention failed', { message: errorMessage(err) });
449
+ }
450
+ } while (this.tickQueued && lifecycle === this.lifecycle && this.timer);
451
+ }
452
+ async stop() {
453
+ this.lifecycle++;
454
+ if (this.timer)
455
+ this.scheduler.clearInterval(this.timer);
456
+ this.timer = null;
457
+ this.tickQueued = false;
458
+ await Promise.allSettled([this.startPromise, this.tickPromise].filter(Boolean));
459
+ }
460
+ close() {
461
+ return this.stop();
462
+ }
463
+ }
464
+ exports.RetentionManager = RetentionManager;
465
+ //# sourceMappingURL=retention.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retention.js","sourceRoot":"","sources":["../../src/storage/retention.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAqB;AACrB,oDAAuD;AACvD,8CAAoB;AACpB,kDAAwB;AACxB,4CAAuD;AACvD,2CAAiG;AACjG,qDAAqE;AACrE,oDAAiD;AACjD,+DAAqD;AAIrD,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;QAykBvB,kBAAkB;AAxkB7C,MAAM,wBAAwB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAA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G,CAAC,EAAE,CAAC,CAAA;YAC5F,CAAC;QACH,CAAC,QAAQ,IAAI,CAAC,UAAU,IAAI,SAAS,KAAK,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,KAAK,EAAC;IACzE,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,SAAS,EAAE,CAAA;QAChB,IAAI,IAAI,CAAC,KAAK;YAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACxD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;QACjB,IAAI,CAAC,UAAU,GAAG,KAAK,CAAA;QACvB,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;IACjF,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,IAAI,EAAE,CAAA;IACpB,CAAC;CACF;QAEQ,gBAAgB"}
@@ -0,0 +1,7 @@
1
+ export declare function withRootLease<T>(root: string, operation: () => Promise<T> | T): Promise<T>;
2
+ /**
3
+ * Serializes inspection, admission, replacement, and recovery for one visible
4
+ * name. Distinct names stay concurrent. Callers that also need the root lease
5
+ * must take the name lease first.
6
+ */
7
+ export declare function withNameLease<T>(root: string, name: string, operation: () => Promise<T> | T): Promise<T>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withRootLease = withRootLease;
4
+ exports.withNameLease = withNameLease;
5
+ const leases = new Map();
6
+ function withLease(key, operation) {
7
+ const previous = leases.get(key) || Promise.resolve();
8
+ const result = previous.then(operation, operation);
9
+ const tracked = result.then(() => undefined, () => undefined);
10
+ leases.set(key, tracked);
11
+ return result.finally(() => {
12
+ if (leases.get(key) === tracked)
13
+ leases.delete(key);
14
+ });
15
+ }
16
+ function withRootLease(root, operation) {
17
+ return withLease(root, operation);
18
+ }
19
+ /**
20
+ * Serializes inspection, admission, replacement, and recovery for one visible
21
+ * name. Distinct names stay concurrent. Callers that also need the root lease
22
+ * must take the name lease first.
23
+ */
24
+ function withNameLease(root, name, operation) {
25
+ return withLease(`${root}\u0000${name}`, operation);
26
+ }
27
+ //# sourceMappingURL=root-coordinator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"root-coordinator.js","sourceRoot":"","sources":["../../src/storage/root-coordinator.ts"],"names":[],"mappings":";;;;AAAA,MAAM,MAAM,GAAG,IAAI,GAAG,EAAyB,CAAA;AAE/C,SAAS,SAAS,CAAI,GAAW,EAAE,SAA+B;IAChE,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,CAAA;IACrD,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;IAClD,MAAM,OAAO,GAAkB,MAAM,CAAC,IAAI,CACxC,GAAG,EAAE,CAAC,SAAS,EACf,GAAG,EAAE,CAAC,SAAS,CAChB,CAAA;IACD,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACxB,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE;QACzB,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,OAAO;YAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IACrD,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,uBAAiC,IAAY,EAAE,SAA+B;IAC5E,OAAO,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;AACnC,CAAC;AAED;;;;GAIG;AACH,uBACE,IAAY,EACZ,IAAY,EACZ,SAA+B;IAE/B,OAAO,SAAS,CAAC,GAAG,IAAI,SAAS,IAAI,EAAE,EAAE,SAAS,CAAC,CAAA;AACrD,CAAC"}
@@ -0,0 +1,2 @@
1
+ /** Durable direct-TAR storage authority. */
2
+ export { TarSessionStore as SessionStore, type TarAdmission, type TarSession } from './tar-session-store.js';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SessionStore = void 0;
4
+ /** Durable direct-TAR storage authority. */
5
+ var tar_session_store_js_1 = require("./tar-session-store.js");
6
+ Object.defineProperty(exports, "SessionStore", { enumerable: true, get: function () { return tar_session_store_js_1.TarSessionStore; } });
7
+ //# sourceMappingURL=session-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-store.js","sourceRoot":"","sources":["../../src/storage/session-store.ts"],"names":[],"mappings":";;;AAAA,4CAA4C;AAC5C,+DAI+B;AAH7B,oHAAA,eAAe,OAAgB"}
@@ -0,0 +1,116 @@
1
+ import { type MetadataRecord } from '../tar-protocol/controls.js';
2
+ import type { StorageAdapter, StorageLayout } from './types.js';
3
+ import type { Clock } from '../types.js';
4
+ declare const RECEIVING = "receiving";
5
+ declare const VERIFIED = "verified";
6
+ declare const DELETING = "deleting";
7
+ type State = typeof RECEIVING | typeof VERIFIED | typeof DELETING;
8
+ export interface TarSession {
9
+ id: string;
10
+ transferId: Buffer;
11
+ ownerKey: Buffer;
12
+ name: string;
13
+ size: number;
14
+ digest: Buffer;
15
+ tarSize: number;
16
+ tarDigest: Buffer;
17
+ tarPath: string;
18
+ state: State;
19
+ createdAt: number;
20
+ updatedAt: number;
21
+ partialTarSize: number;
22
+ }
23
+ export type TarAdmission = {
24
+ status: 'ACCEPT';
25
+ offset: 0;
26
+ } | {
27
+ status: 'RESUME';
28
+ offset: number;
29
+ prefixSha256: Buffer;
30
+ } | {
31
+ status: 'VERIFIED';
32
+ };
33
+ export interface TarSessionStoreOptions {
34
+ layout: StorageLayout;
35
+ maxStagingBytes: number;
36
+ minFreeBytes?: number;
37
+ clock?: Clock;
38
+ resumeTtl?: number;
39
+ isSessionActive?: (session: TarSession) => boolean;
40
+ storage?: StorageAdapter;
41
+ }
42
+ /** Durable direct-TAR session authority. */
43
+ export declare class TarSessionStore {
44
+ readonly layout: StorageLayout;
45
+ readonly maxStagingBytes: number;
46
+ readonly minFreeBytes: number;
47
+ readonly clock: Clock;
48
+ readonly resumeTtl: number | undefined;
49
+ readonly isSessionActive: (session: TarSession) => boolean;
50
+ readonly storage: StorageAdapter;
51
+ readonly sessions: Map<string, TarSession>;
52
+ reservedBytes: number;
53
+ purgedSessions: number;
54
+ /** Sessions dropped from memory whose staging files could not be unlinked. */
55
+ strandedSessions: number;
56
+ initialized: boolean;
57
+ closed: boolean;
58
+ private closing;
59
+ private pending;
60
+ private closePromise;
61
+ private readonly verifying;
62
+ private readonly verificationTasks;
63
+ private run;
64
+ constructor({ layout, maxStagingBytes, minFreeBytes, clock, resumeTtl, isSessionActive, storage }: TarSessionStoreOptions);
65
+ private sessionPath;
66
+ private tarPath;
67
+ private filePath;
68
+ private journalPath;
69
+ private reserve;
70
+ private assertReady;
71
+ private metadata;
72
+ private fromDisk;
73
+ private serialize;
74
+ private writeSession;
75
+ private remove;
76
+ private purgeCorruptSession;
77
+ /** Removes only a regular crash residue and syncs its parent before reporting it purged. */
78
+ private purgeSafeResidue;
79
+ private hashPrefix;
80
+ private ensureTarLength;
81
+ private diskReserve;
82
+ init(): Promise<void>;
83
+ admit(ownerKey: Uint8Array, input: MetadataRecord): Promise<TarAdmission>;
84
+ append(ownerKey: Uint8Array, input: MetadataRecord, offset: number, data: Uint8Array): Promise<number>;
85
+ private rollbackTar;
86
+ private rollbackOrQuarantine;
87
+ private resetUnlocked;
88
+ private quarantineVerificationFailure;
89
+ verify(ownerKey: Uint8Array, input: MetadataRecord): Promise<TarSession>;
90
+ private readTar;
91
+ readVerified(transferId: Uint8Array): Promise<TarSession>;
92
+ /**
93
+ * Drops a session from the in-memory authority exactly once.
94
+ *
95
+ * `reservedBytes` must always equal the sum of `reserve()` over `sessions`,
96
+ * so the bookkeeping runs in a `finally`: a failed unlink would otherwise
97
+ * strand the reservation for the lifetime of the process, and leave the name
98
+ * permanently colliding in `admit()`. Any file that survives the failure is a
99
+ * crash residue, which `init()` purges on the next start.
100
+ */
101
+ private removeSession;
102
+ delete(transferId: Uint8Array): Promise<boolean>;
103
+ /**
104
+ * Sweeps expired sessions without letting one failure abort the rest.
105
+ *
106
+ * `admit()` runs this opportunistically on every offer, so a single session
107
+ * whose files cannot be unlinked must not deny service to every later
108
+ * upload. Failures are counted in `strandedSessions` and reported to the
109
+ * explicit `expire()` caller, which asked for the sweep and can act on it.
110
+ */
111
+ private expireUnlocked;
112
+ expire(ttl: number, predicate?: (session: TarSession) => boolean): Promise<number>;
113
+ retireCommitted(transferId: Uint8Array): Promise<boolean>;
114
+ close(): Promise<void>;
115
+ }
116
+ export {};