import { S3Client } from '@aws-sdk/client-s3'; import type { SnapshotStorage, SnapshotLocation } from './storage.js'; import type { Snapshot, SnapshotManifest } from './types.js'; /** * Configuration options for S3Storage */ export type S3StorageConfig = { /** S3 bucket name */ bucket: string; /** Optional key prefix for all objects */ prefix?: string; /** AWS region (default: us-east-1). Cannot be used with s3Client */ region?: string; /** Pre-configured S3 client. Cannot be used with region */ s3Client?: S3Client; }; /** * S3-based implementation of SnapshotStorage. * Persists session snapshots as JSON objects in an S3 bucket. * * Object key layout: * ``` * [/]/scopes///snapshots/ * snapshot_latest.json * immutable_history/ * snapshot_.json * ``` */ export declare class S3Storage implements SnapshotStorage { /** S3 client instance */ private readonly _s3; /** S3 bucket name */ private readonly _bucket; /** Key prefix for all objects */ private readonly _prefix; /** * Creates new S3Storage instance * @param config - Configuration options */ constructor(config: S3StorageConfig); /** * Resolves the full S3 object key for a given scope location and path. * Validates sessionId and scopeId before constructing the key. */ private _getKey; /** * Resolves the S3 key prefix for an entire session (`[/]/`). * Used by deleteSession to list and remove all objects under the session. */ private _getSessionPrefix; /** * Persists a snapshot to S3. * If `isLatest` is true, writes to `snapshot_latest.json` (overwriting any previous). * Otherwise, writes to `immutable_history/snapshot_.json`. */ saveSnapshot(params: { location: SnapshotLocation; snapshotId: string; isLatest: boolean; snapshot: Snapshot; }): Promise; /** * Loads a snapshot from S3. * If `snapshotId` is omitted, loads `snapshot_latest.json`. * Returns null if the object does not exist. */ loadSnapshot(params: { location: SnapshotLocation; snapshotId?: string; }): Promise; /** * Lists immutable snapshot IDs for a scope, sorted chronologically. * Since IDs are UUID v7, lexicographic sort equals chronological order. * Pushes `startAfter` and `limit` down to S3 via `StartAfter` and `MaxKeys` * to avoid fetching unnecessary objects. * Returns an empty array if no snapshots exist yet. */ listSnapshotIds(params: { location: SnapshotLocation; limit?: number; startAfter?: string; }): Promise; /** * Deletes all S3 objects belonging to a session by listing and batch-deleting * everything under `[/]/`. * Handles buckets with more than 1000 objects via continuation token pagination. * No-ops if the session has no objects. */ deleteSession(params: { sessionId: string; }): Promise; /** * Loads the snapshot manifest for a scope from S3. * Returns a default manifest with the current timestamp if none exists yet. */ loadManifest(params: { location: SnapshotLocation; }): Promise; /** * Persists the snapshot manifest for a scope to S3. */ saveManifest(params: { location: SnapshotLocation; manifest: SnapshotManifest; }): Promise; /** * Serializes data as JSON and writes it to S3 with `application/json` content type. */ private _writeJSON; /** * Reads and parses a JSON object from S3. Returns null if the object does not exist. * Throws SessionError on parse failure or unexpected S3 errors. */ private _readJSON; /** Returns true if the error represents a missing S3 object (`NoSuchKey`) or bucket (`NoSuchBucket`). */ private _isNotFoundError; /** Returns the S3 key for `snapshot_latest.json` within the given scope. */ private _getLatestSnapshotKey; /** Returns the S3 key for an immutable snapshot in `immutable_history/`. Validates the snapshotId before constructing the key. */ private _getHistorySnapshotKey; } //# sourceMappingURL=s3-storage.d.ts.map