Fix StartOS 0.4 TypeScript packaging to match SDK API
This commit is contained in:
+183
@@ -0,0 +1,183 @@
|
||||
import * as T from '../../../base/lib/types';
|
||||
import { Affine } from '../util';
|
||||
import { InitKind, InitScript } from '../../../base/lib/inits';
|
||||
/** A password value, or a function that returns one. Functions are resolved lazily (only during restore). */
|
||||
export type LazyPassword = string | (() => string | Promise<string>) | null;
|
||||
/** Configuration for PostgreSQL dump-based backup */
|
||||
export type PgDumpConfig<M extends T.SDKManifest> = {
|
||||
/** Image ID of the PostgreSQL container (e.g. 'postgres') */
|
||||
imageId: keyof M['images'] & T.ImageId;
|
||||
/** Volume ID containing the PostgreSQL data directory */
|
||||
dbVolume: M['volumes'][number];
|
||||
/** Volume mountpoint (e.g. '/var/lib/postgresql') */
|
||||
mountpoint: string;
|
||||
/** Subpath from mountpoint to PGDATA (e.g. '/data', '/18/docker') */
|
||||
pgdataPath: string;
|
||||
/** PostgreSQL database name to dump */
|
||||
database: string;
|
||||
/** PostgreSQL user */
|
||||
user: string;
|
||||
/** PostgreSQL password (for restore). Can be a string, a function that returns one (resolved lazily after volumes are restored), or null for trust auth. */
|
||||
password: LazyPassword;
|
||||
/** Additional initdb arguments (e.g. ['--data-checksums']) */
|
||||
initdbArgs?: string[];
|
||||
/** Additional options passed to `pg_ctl start -o` (e.g. '-c shared_preload_libraries=vectorchord'). Appended after `-c listen_addresses=`. */
|
||||
pgOptions?: string;
|
||||
};
|
||||
/** Configuration for MySQL/MariaDB dump-based backup */
|
||||
export type MysqlDumpConfig<M extends T.SDKManifest> = {
|
||||
/** Image ID of the MySQL/MariaDB container (e.g. 'mysql', 'mariadb') */
|
||||
imageId: keyof M['images'] & T.ImageId;
|
||||
/** Volume ID containing the MySQL data directory */
|
||||
dbVolume: M['volumes'][number];
|
||||
/** Path to MySQL data directory within the container (typically '/var/lib/mysql') */
|
||||
datadir: string;
|
||||
/** MySQL database name to dump */
|
||||
database: string;
|
||||
/** MySQL user for dump operations */
|
||||
user: string;
|
||||
/** MySQL password. Can be a string or a function that returns one — functions are resolved lazily after volumes are restored. */
|
||||
password: LazyPassword;
|
||||
/** Database engine: 'mysql' uses --initialize-insecure, 'mariadb' uses mysql_install_db */
|
||||
engine: 'mysql' | 'mariadb';
|
||||
/** Custom readiness check command (default: ['mysqladmin', 'ping', ...]) */
|
||||
readyCommand?: string[];
|
||||
/** Additional options passed to `mysqld` on startup (e.g. '--innodb-buffer-pool-size=256M'). Appended after `--bind-address=127.0.0.1`. */
|
||||
mysqldOptions?: string[];
|
||||
};
|
||||
/** Default rsync options used for backup and restore operations */
|
||||
export declare const DEFAULT_OPTIONS: T.SyncOptions;
|
||||
/** A single source-to-destination sync pair for backup and restore */
|
||||
export type BackupSync<Volumes extends string> = {
|
||||
dataPath: `/media/startos/volumes/${Volumes}/${string}`;
|
||||
backupPath: `/media/startos/backup/${string}`;
|
||||
options?: Partial<T.SyncOptions>;
|
||||
backupOptions?: Partial<T.SyncOptions>;
|
||||
restoreOptions?: Partial<T.SyncOptions>;
|
||||
};
|
||||
/** Effects type narrowed for backup/restore contexts, preventing reuse outside that scope */
|
||||
export type BackupEffects = T.Effects & Affine<'Backups'>;
|
||||
/**
|
||||
* Configures backup and restore operations using rsync.
|
||||
*
|
||||
* Supports syncing entire volumes or custom path pairs, with optional pre/post hooks
|
||||
* for both backup and restore phases. Implements {@link InitScript} so it can be used
|
||||
* as a restore-init step in `setupInit`.
|
||||
*
|
||||
* @typeParam M - The service manifest type
|
||||
*/
|
||||
export declare class Backups<M extends T.SDKManifest> implements InitScript {
|
||||
private options;
|
||||
private restoreOptions;
|
||||
private backupOptions;
|
||||
private backupSet;
|
||||
private preBackup;
|
||||
private postBackup;
|
||||
private preRestore;
|
||||
private postRestore;
|
||||
private constructor();
|
||||
/**
|
||||
* Create a Backups configuration that backs up entire volumes by name.
|
||||
* Each volume is synced to a corresponding directory under `/media/startos/backup/volumes/`.
|
||||
* @param volumeNames - One or more volume IDs from the manifest
|
||||
*/
|
||||
static ofVolumes<M extends T.SDKManifest = never>(...volumeNames: Array<M['volumes'][number]>): Backups<M>;
|
||||
/**
|
||||
* Create a Backups configuration from explicit source/destination sync pairs.
|
||||
* @param syncs - Array of `{ dataPath, backupPath }` objects with optional per-sync options
|
||||
*/
|
||||
static ofSyncs<M extends T.SDKManifest = never>(...syncs: BackupSync<M['volumes'][number]>[]): Backups<M>;
|
||||
/**
|
||||
* Create an empty Backups configuration with custom default rsync options.
|
||||
* Chain `.addVolume()` or `.addSync()` to add sync targets.
|
||||
* @param options - Partial rsync options to override defaults (e.g. `{ exclude: ['cache'] }`)
|
||||
*/
|
||||
static withOptions<M extends T.SDKManifest = never>(options?: Partial<T.SyncOptions>): Backups<M>;
|
||||
/**
|
||||
* Configure PostgreSQL dump-based backup for a volume.
|
||||
*
|
||||
* Instead of rsyncing the raw PostgreSQL data directory (which is slow and error-prone),
|
||||
* this uses `pg_dump` to create a logical dump before backup and `pg_restore` to rebuild
|
||||
* the database after restore.
|
||||
*
|
||||
* The dump file is written directly to the backup target — no data duplication on disk.
|
||||
*
|
||||
* @returns A configured Backups instance with pre/post hooks. Chain `.addVolume()` or
|
||||
* `.addSync()` to include additional volumes/paths in the backup.
|
||||
*/
|
||||
static withPgDump<M extends T.SDKManifest = never>(config: PgDumpConfig<M>): Backups<M>;
|
||||
/**
|
||||
* Configure MySQL/MariaDB dump-based backup for a volume.
|
||||
*
|
||||
* Instead of rsyncing the raw MySQL data directory (which is slow and error-prone),
|
||||
* this uses `mysqldump` to create a logical dump before backup and `mysql` to restore
|
||||
* the database after restore.
|
||||
*
|
||||
* The dump file is stored temporarily in `dumpVolume` during backup and cleaned up afterward.
|
||||
*
|
||||
* @returns A configured Backups instance with pre/post hooks. Chain `.addVolume()` or
|
||||
* `.addSync()` to include additional volumes/paths in the backup.
|
||||
*/
|
||||
static withMysqlDump<M extends T.SDKManifest = never>(config: MysqlDumpConfig<M>): Backups<M>;
|
||||
/**
|
||||
* Override the default rsync options for both backup and restore.
|
||||
* @param options - Partial rsync options to merge with current defaults
|
||||
*/
|
||||
setOptions(options?: Partial<T.SyncOptions>): this;
|
||||
/**
|
||||
* Override rsync options used only during backup (not restore).
|
||||
* @param options - Partial rsync options for the backup phase
|
||||
*/
|
||||
setBackupOptions(options?: Partial<T.SyncOptions>): this;
|
||||
/**
|
||||
* Override rsync options used only during restore (not backup).
|
||||
* @param options - Partial rsync options for the restore phase
|
||||
*/
|
||||
setRestoreOptions(options?: Partial<T.SyncOptions>): this;
|
||||
/**
|
||||
* Register a hook to run before backup rsync begins (e.g. dump a database).
|
||||
* @param fn - Async function receiving backup-scoped effects
|
||||
*/
|
||||
setPreBackup(fn: (effects: BackupEffects) => Promise<void>): this;
|
||||
/**
|
||||
* Register a hook to run after backup rsync completes.
|
||||
* @param fn - Async function receiving backup-scoped effects
|
||||
*/
|
||||
setPostBackup(fn: (effects: BackupEffects) => Promise<void>): this;
|
||||
/**
|
||||
* Register a hook to run before restore rsync begins.
|
||||
* @param fn - Async function receiving backup-scoped effects
|
||||
*/
|
||||
setPreRestore(fn: (effects: BackupEffects) => Promise<void>): this;
|
||||
/**
|
||||
* Register a hook to run after restore rsync completes.
|
||||
* @param fn - Async function receiving backup-scoped effects
|
||||
*/
|
||||
setPostRestore(fn: (effects: BackupEffects) => Promise<void>): this;
|
||||
/**
|
||||
* Add a volume to the backup set by its ID.
|
||||
* @param volume - The volume ID from the manifest
|
||||
* @param options - Optional per-volume rsync overrides
|
||||
*/
|
||||
addVolume(volume: M['volumes'][number], options?: Partial<{
|
||||
options: T.SyncOptions;
|
||||
backupOptions: T.SyncOptions;
|
||||
restoreOptions: T.SyncOptions;
|
||||
}>): this;
|
||||
/**
|
||||
* Add a custom sync pair to the backup set.
|
||||
* @param sync - A `{ dataPath, backupPath }` object with optional per-sync rsync options
|
||||
*/
|
||||
addSync(sync: BackupSync<M['volumes'][0]>): this;
|
||||
/**
|
||||
* Execute the backup: runs pre-hook, rsyncs all configured paths, saves the data version, then runs post-hook.
|
||||
* @param effects - The effects context
|
||||
*/
|
||||
createBackup(effects: T.Effects): Promise<void>;
|
||||
init(effects: T.Effects, kind: InitKind): Promise<void>;
|
||||
/**
|
||||
* Execute the restore: runs pre-hook, rsyncs all configured paths from backup to data, restores the data version, then runs post-hook.
|
||||
* @param effects - The effects context
|
||||
*/
|
||||
restoreBackup(effects: T.Effects): Promise<void>;
|
||||
}
|
||||
Reference in New Issue
Block a user