114 lines
4.3 KiB
JavaScript
114 lines
4.3 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.Mounts = void 0;
|
|
/**
|
|
* Immutable builder for declaring filesystem mounts into a subcontainer.
|
|
*
|
|
* Supports mounting volumes, static assets, dependency volumes, and backup directories.
|
|
* Each `mount*` method returns a new `Mounts` instance (immutable builder pattern).
|
|
*
|
|
* @typeParam Manifest - The service manifest type
|
|
* @typeParam Backups - Tracks whether backup mounts have been added (type-level flag)
|
|
*/
|
|
class Mounts {
|
|
constructor(volumes, assets, dependencies, backups) {
|
|
this.volumes = volumes;
|
|
this.assets = assets;
|
|
this.dependencies = dependencies;
|
|
this.backups = backups;
|
|
}
|
|
/**
|
|
* Create an empty Mounts builder with no mounts configured.
|
|
* @returns A new Mounts instance ready for chaining mount declarations
|
|
*/
|
|
static of() {
|
|
return new Mounts([], [], [], []);
|
|
}
|
|
/**
|
|
* Add a volume mount from the service's own volumes.
|
|
* @param options - Volume ID, mountpoint, readonly flag, and optional subpath
|
|
* @returns A new Mounts instance with this volume added
|
|
*/
|
|
mountVolume(options) {
|
|
return new Mounts([...this.volumes, options], [...this.assets], [...this.dependencies], [...this.backups]);
|
|
}
|
|
/**
|
|
* Add a read-only mount of the service's packaged static assets.
|
|
* @param options - Mountpoint and optional subpath within the assets directory
|
|
* @returns A new Mounts instance with this asset mount added
|
|
*/
|
|
mountAssets(options) {
|
|
return new Mounts([...this.volumes], [...this.assets, options], [...this.dependencies], [...this.backups]);
|
|
}
|
|
/**
|
|
* Add a mount from a dependency package's volume.
|
|
* @param options - Dependency ID, volume ID, mountpoint, readonly flag, and optional subpath
|
|
* @returns A new Mounts instance with this dependency mount added
|
|
*/
|
|
mountDependency(options) {
|
|
return new Mounts([...this.volumes], [...this.assets], [...this.dependencies, options], [...this.backups]);
|
|
}
|
|
/**
|
|
* Add a mount of the backup directory. Only valid during backup/restore operations.
|
|
* @param options - Mountpoint and optional subpath within the backup directory
|
|
* @returns A new Mounts instance with this backup mount added
|
|
*/
|
|
mountBackups(options) {
|
|
return new Mounts([...this.volumes], [...this.assets], [...this.dependencies], [...this.backups, options]);
|
|
}
|
|
/**
|
|
* Compile all declared mounts into the low-level mount array consumed by the subcontainer runtime.
|
|
* @throws If any two mounts share the same mountpoint
|
|
* @returns An array of `{ mountpoint, options }` objects
|
|
*/
|
|
build() {
|
|
const mountpoints = new Set();
|
|
for (let mountpoint of this.volumes
|
|
.map((v) => v.mountpoint)
|
|
.concat(this.assets.map((a) => a.mountpoint))
|
|
.concat(this.dependencies.map((d) => d.mountpoint))) {
|
|
if (mountpoints.has(mountpoint)) {
|
|
throw new Error(`cannot mount more than once to mountpoint ${mountpoint}`);
|
|
}
|
|
mountpoints.add(mountpoint);
|
|
}
|
|
return []
|
|
.concat(this.volumes.map((v) => ({
|
|
mountpoint: v.mountpoint,
|
|
options: {
|
|
type: 'volume',
|
|
volumeId: v.volumeId,
|
|
subpath: v.subpath,
|
|
readonly: v.readonly,
|
|
filetype: v.type ?? 'directory',
|
|
idmap: [],
|
|
},
|
|
})))
|
|
.concat(this.assets.map((a) => ({
|
|
mountpoint: a.mountpoint,
|
|
options: {
|
|
type: 'assets',
|
|
subpath: a.subpath,
|
|
filetype: a.type ?? 'directory',
|
|
idmap: [],
|
|
},
|
|
})))
|
|
.concat(this.dependencies.map((d) => ({
|
|
mountpoint: d.mountpoint,
|
|
options: {
|
|
type: 'pointer',
|
|
packageId: d.dependencyId,
|
|
volumeId: d.volumeId,
|
|
subpath: d.subpath,
|
|
readonly: d.readonly,
|
|
filetype: d.type ?? 'directory',
|
|
idmap: [],
|
|
},
|
|
})));
|
|
}
|
|
}
|
|
exports.Mounts = Mounts;
|
|
const a = Mounts.of().mountBackups({ subpath: null, mountpoint: '' });
|
|
// @ts-expect-error
|
|
const m = a;
|
|
//# sourceMappingURL=Mounts.js.map
|