swarm-deploy 0.0.0 → 0.2.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.
- package/CHANGELOG.md +76 -0
- package/LICENSE.md +201 -0
- package/NOTICE.md +13 -0
- package/README.md +1283 -0
- package/RELEASING.md +71 -0
- package/SECURITY.md +40 -0
- package/dist/abort.d.ts +16 -0
- package/dist/abort.js +52 -0
- package/dist/abort.js.map +1 -0
- package/dist/allowlist.d.ts +2 -0
- package/dist/allowlist.js +21 -0
- package/dist/allowlist.js.map +1 -0
- package/dist/bin/swarm-deploy.d.ts +2 -0
- package/dist/bin/swarm-deploy.js +41 -0
- package/dist/bin/swarm-deploy.js.map +1 -0
- package/dist/cli.d.ts +27 -0
- package/dist/cli.js +751 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.d.ts +111 -0
- package/dist/client.js +276 -0
- package/dist/client.js.map +1 -0
- package/dist/direct-dht.d.ts +81 -0
- package/dist/direct-dht.js +254 -0
- package/dist/direct-dht.js.map +1 -0
- package/dist/error-code.d.ts +15 -0
- package/dist/error-code.js +30 -0
- package/dist/error-code.js.map +1 -0
- package/dist/errors.d.ts +31 -0
- package/dist/errors.js +37 -0
- package/dist/errors.js.map +1 -0
- package/dist/events-node.d.ts +2 -0
- package/dist/events-node.js +7 -0
- package/dist/events-node.js.map +1 -0
- package/dist/files.d.ts +32 -0
- package/dist/files.js +85 -0
- package/dist/files.js.map +1 -0
- package/dist/fs-node.d.ts +2 -0
- package/dist/fs-node.js +7 -0
- package/dist/fs-node.js.map +1 -0
- package/dist/hooks-module.d.ts +9 -0
- package/dist/hooks-module.js +118 -0
- package/dist/hooks-module.js.map +1 -0
- package/dist/hooks.d.ts +69 -0
- package/dist/hooks.js +88 -0
- package/dist/hooks.js.map +1 -0
- package/dist/identity.d.ts +7 -0
- package/dist/identity.js +50 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/os-node.d.ts +2 -0
- package/dist/os-node.js +7 -0
- package/dist/os-node.js.map +1 -0
- package/dist/path-node.d.ts +2 -0
- package/dist/path-node.js +7 -0
- package/dist/path-node.js.map +1 -0
- package/dist/process-node.d.ts +2 -0
- package/dist/process-node.js +7 -0
- package/dist/process-node.js.map +1 -0
- package/dist/release.d.ts +26 -0
- package/dist/release.js +419 -0
- package/dist/release.js.map +1 -0
- package/dist/server.d.ts +239 -0
- package/dist/server.js +928 -0
- package/dist/server.js.map +1 -0
- package/dist/storage/atomic-file.d.ts +15 -0
- package/dist/storage/atomic-file.js +172 -0
- package/dist/storage/atomic-file.js.map +1 -0
- package/dist/storage/commit-journal.d.ts +120 -0
- package/dist/storage/commit-journal.js +417 -0
- package/dist/storage/commit-journal.js.map +1 -0
- package/dist/storage/commit-store.d.ts +307 -0
- package/dist/storage/commit-store.js +1691 -0
- package/dist/storage/commit-store.js.map +1 -0
- package/dist/storage/layout.d.ts +16 -0
- package/dist/storage/layout.js +409 -0
- package/dist/storage/layout.js.map +1 -0
- package/dist/storage/link-store.d.ts +70 -0
- package/dist/storage/link-store.js +363 -0
- package/dist/storage/link-store.js.map +1 -0
- package/dist/storage/recovery.d.ts +100 -0
- package/dist/storage/recovery.js +260 -0
- package/dist/storage/recovery.js.map +1 -0
- package/dist/storage/retention.d.ts +183 -0
- package/dist/storage/retention.js +619 -0
- package/dist/storage/retention.js.map +1 -0
- package/dist/storage/root-coordinator.d.ts +7 -0
- package/dist/storage/root-coordinator.js +27 -0
- package/dist/storage/root-coordinator.js.map +1 -0
- package/dist/storage/session-store.d.ts +2 -0
- package/dist/storage/session-store.js +7 -0
- package/dist/storage/session-store.js.map +1 -0
- package/dist/storage/tar-session-store.d.ts +147 -0
- package/dist/storage/tar-session-store.js +1044 -0
- package/dist/storage/tar-session-store.js.map +1 -0
- package/dist/storage/tree-fs.d.ts +44 -0
- package/dist/storage/tree-fs.js +580 -0
- package/dist/storage/tree-fs.js.map +1 -0
- package/dist/storage/tree-staging.d.ts +9 -0
- package/dist/storage/tree-staging.js +64 -0
- package/dist/storage/tree-staging.js.map +1 -0
- package/dist/storage/types.d.ts +77 -0
- package/dist/storage/types.js +3 -0
- package/dist/storage/types.js.map +1 -0
- package/dist/symlinks.d.ts +36 -0
- package/dist/symlinks.js +128 -0
- package/dist/symlinks.js.map +1 -0
- package/dist/tar-protocol/controls.d.ts +73 -0
- package/dist/tar-protocol/controls.js +291 -0
- package/dist/tar-protocol/controls.js.map +1 -0
- package/dist/tar-protocol/direct-wire.d.ts +43 -0
- package/dist/tar-protocol/direct-wire.js +194 -0
- package/dist/tar-protocol/direct-wire.js.map +1 -0
- package/dist/tar-protocol/extract.d.ts +18 -0
- package/dist/tar-protocol/extract.js +124 -0
- package/dist/tar-protocol/extract.js.map +1 -0
- package/dist/tar-protocol/hash.d.ts +10 -0
- package/dist/tar-protocol/hash.js +44 -0
- package/dist/tar-protocol/hash.js.map +1 -0
- package/dist/tar-protocol/lifecycle.d.ts +13 -0
- package/dist/tar-protocol/lifecycle.js +90 -0
- package/dist/tar-protocol/lifecycle.js.map +1 -0
- package/dist/tar-protocol/manifest.d.ts +58 -0
- package/dist/tar-protocol/manifest.js +312 -0
- package/dist/tar-protocol/manifest.js.map +1 -0
- package/dist/tar-protocol/tree-extract.d.ts +37 -0
- package/dist/tar-protocol/tree-extract.js +240 -0
- package/dist/tar-protocol/tree-extract.js.map +1 -0
- package/dist/tar-protocol/tree-manifest.d.ts +45 -0
- package/dist/tar-protocol/tree-manifest.js +277 -0
- package/dist/tar-protocol/tree-manifest.js.map +1 -0
- package/dist/tar-protocol/tree-path.d.ts +15 -0
- package/dist/tar-protocol/tree-path.js +68 -0
- package/dist/tar-protocol/tree-path.js.map +1 -0
- package/dist/tar-protocol/tree.d.ts +68 -0
- package/dist/tar-protocol/tree.js +269 -0
- package/dist/tar-protocol/tree.js.map +1 -0
- package/dist/tar-protocol/ustar.d.ts +36 -0
- package/dist/tar-protocol/ustar.js +167 -0
- package/dist/tar-protocol/ustar.js.map +1 -0
- package/dist/types.d.ts +61 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/validation.d.ts +4 -0
- package/dist/validation.js +26 -0
- package/dist/validation.js.map +1 -0
- package/package.json +103 -1
|
@@ -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,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,147 @@
|
|
|
1
|
+
import { type AnyMetadataRecord } from '../tar-protocol/controls.js';
|
|
2
|
+
import type { StorageAdapter, StorageLayout } from './types.js';
|
|
3
|
+
import type { ArtifactKind, Clock } from '../types.js';
|
|
4
|
+
/** Directory sessions are persisted at a version no file-only server understands. */
|
|
5
|
+
export declare const TREE_SESSION_VERSION = 4;
|
|
6
|
+
declare const RECEIVING = "receiving";
|
|
7
|
+
declare const VERIFIED = "verified";
|
|
8
|
+
declare const DELETING = "deleting";
|
|
9
|
+
type State = typeof RECEIVING | typeof VERIFIED | typeof DELETING;
|
|
10
|
+
export interface TarSession {
|
|
11
|
+
id: string;
|
|
12
|
+
transferId: Buffer;
|
|
13
|
+
ownerKey: Buffer;
|
|
14
|
+
kind: ArtifactKind;
|
|
15
|
+
name: string;
|
|
16
|
+
sourceParent?: string;
|
|
17
|
+
/** Payload bytes: the file size, or the aggregate tree payload size. */
|
|
18
|
+
size: number;
|
|
19
|
+
/** The file digest, or the canonical tree digest. */
|
|
20
|
+
digest: Buffer;
|
|
21
|
+
/** Present only for a directory session. */
|
|
22
|
+
entryCount?: number;
|
|
23
|
+
tarSize: number;
|
|
24
|
+
tarDigest: Buffer;
|
|
25
|
+
tarPath: string;
|
|
26
|
+
/** Present only for a directory session. */
|
|
27
|
+
treePath?: string;
|
|
28
|
+
state: State;
|
|
29
|
+
createdAt: number;
|
|
30
|
+
updatedAt: number;
|
|
31
|
+
partialTarSize: number;
|
|
32
|
+
}
|
|
33
|
+
export type TarAdmission = {
|
|
34
|
+
status: 'ACCEPT';
|
|
35
|
+
offset: 0;
|
|
36
|
+
} | {
|
|
37
|
+
status: 'RESUME';
|
|
38
|
+
offset: number;
|
|
39
|
+
prefixSha256: Buffer;
|
|
40
|
+
} | {
|
|
41
|
+
status: 'VERIFIED';
|
|
42
|
+
};
|
|
43
|
+
export interface TarSessionStoreOptions {
|
|
44
|
+
layout: StorageLayout;
|
|
45
|
+
maxStagingBytes: number;
|
|
46
|
+
minFreeBytes?: number;
|
|
47
|
+
clock?: Clock;
|
|
48
|
+
resumeTtl?: number;
|
|
49
|
+
isSessionActive?: (session: TarSession) => boolean;
|
|
50
|
+
storage?: StorageAdapter;
|
|
51
|
+
}
|
|
52
|
+
/** Durable direct-TAR session authority. */
|
|
53
|
+
export declare class TarSessionStore {
|
|
54
|
+
readonly layout: StorageLayout;
|
|
55
|
+
readonly maxStagingBytes: number;
|
|
56
|
+
readonly minFreeBytes: number;
|
|
57
|
+
readonly clock: Clock;
|
|
58
|
+
readonly resumeTtl: number | undefined;
|
|
59
|
+
readonly isSessionActive: (session: TarSession) => boolean;
|
|
60
|
+
readonly storage: StorageAdapter;
|
|
61
|
+
readonly sessions: Map<string, TarSession>;
|
|
62
|
+
reservedBytes: number;
|
|
63
|
+
purgedSessions: number;
|
|
64
|
+
/** Sessions dropped from memory whose staging files could not be unlinked. */
|
|
65
|
+
strandedSessions: number;
|
|
66
|
+
initialized: boolean;
|
|
67
|
+
closed: boolean;
|
|
68
|
+
private closing;
|
|
69
|
+
private pending;
|
|
70
|
+
private closePromise;
|
|
71
|
+
private readonly verifying;
|
|
72
|
+
private readonly verificationTasks;
|
|
73
|
+
private run;
|
|
74
|
+
constructor({ layout, maxStagingBytes, minFreeBytes, clock, resumeTtl, isSessionActive, storage }: TarSessionStoreOptions);
|
|
75
|
+
private sessionPath;
|
|
76
|
+
private tarPath;
|
|
77
|
+
private filePath;
|
|
78
|
+
private treeStagingPath;
|
|
79
|
+
/** Removes a staged tree through the contained primitives; never `storage.rm`. */
|
|
80
|
+
private removeStagedTree;
|
|
81
|
+
private journalPath;
|
|
82
|
+
private reserve;
|
|
83
|
+
private assertReady;
|
|
84
|
+
private metadata;
|
|
85
|
+
private fileMetadata;
|
|
86
|
+
private treeFromDisk;
|
|
87
|
+
private fromDisk;
|
|
88
|
+
/**
|
|
89
|
+
* Version 3 only adds `sourceParent`, so a session without one is written as
|
|
90
|
+
* version 2. An older server can then still read, and resume, every session
|
|
91
|
+
* whose record it fully understands; only parent-bearing ones are lost to a
|
|
92
|
+
* downgrade.
|
|
93
|
+
*/
|
|
94
|
+
private serialize;
|
|
95
|
+
private writeSession;
|
|
96
|
+
private remove;
|
|
97
|
+
/** A verified directory session must still own its staging tree. */
|
|
98
|
+
private assertStagedTree;
|
|
99
|
+
/** Verified directory sessions mid-commit may only have a durable journal tree. */
|
|
100
|
+
private assertVerifiedDirectorySession;
|
|
101
|
+
private purgeCorruptSession;
|
|
102
|
+
/** Removes only a regular crash residue and syncs its parent before reporting it purged. */
|
|
103
|
+
private purgeSafeResidue;
|
|
104
|
+
private hashPrefix;
|
|
105
|
+
private ensureTarLength;
|
|
106
|
+
private diskReserve;
|
|
107
|
+
init(): Promise<void>;
|
|
108
|
+
admit(ownerKey: Uint8Array, input: AnyMetadataRecord): Promise<TarAdmission>;
|
|
109
|
+
append(ownerKey: Uint8Array, input: AnyMetadataRecord, offset: number, data: Uint8Array): Promise<number>;
|
|
110
|
+
private rollbackTar;
|
|
111
|
+
private rollbackOrQuarantine;
|
|
112
|
+
private resetUnlocked;
|
|
113
|
+
private quarantineVerificationFailure;
|
|
114
|
+
verify(ownerKey: Uint8Array, input: AnyMetadataRecord): Promise<TarSession>;
|
|
115
|
+
/**
|
|
116
|
+
* Extracts the complete directory archive into its staging tree, then proves
|
|
117
|
+
* the tree from the bytes on disk alone: the recomputed canonical digest,
|
|
118
|
+
* entry count, and payload size must equal the offered values.
|
|
119
|
+
*/
|
|
120
|
+
private extractTree;
|
|
121
|
+
private readTar;
|
|
122
|
+
readVerified(transferId: Uint8Array): Promise<TarSession>;
|
|
123
|
+
/**
|
|
124
|
+
* Drops a session from the in-memory authority exactly once.
|
|
125
|
+
*
|
|
126
|
+
* `reservedBytes` must always equal the sum of `reserve()` over `sessions`,
|
|
127
|
+
* so the bookkeeping runs in a `finally`: a failed unlink would otherwise
|
|
128
|
+
* strand the reservation for the lifetime of the process, and leave the name
|
|
129
|
+
* permanently colliding in `admit()`. Any file that survives the failure is a
|
|
130
|
+
* crash residue, which `init()` purges on the next start.
|
|
131
|
+
*/
|
|
132
|
+
private removeSession;
|
|
133
|
+
delete(transferId: Uint8Array): Promise<boolean>;
|
|
134
|
+
/**
|
|
135
|
+
* Sweeps expired sessions without letting one failure abort the rest.
|
|
136
|
+
*
|
|
137
|
+
* `admit()` runs this opportunistically on every offer, so a single session
|
|
138
|
+
* whose files cannot be unlinked must not deny service to every later
|
|
139
|
+
* upload. Failures are counted in `strandedSessions` and reported to the
|
|
140
|
+
* explicit `expire()` caller, which asked for the sweep and can act on it.
|
|
141
|
+
*/
|
|
142
|
+
private expireUnlocked;
|
|
143
|
+
expire(ttl: number, predicate?: (session: TarSession) => boolean): Promise<number>;
|
|
144
|
+
retireCommitted(transferId: Uint8Array): Promise<boolean>;
|
|
145
|
+
close(): Promise<void>;
|
|
146
|
+
}
|
|
147
|
+
export {};
|