{"version":3,"file":"snapshot.cjs","names":["NotSupportedError"],"sources":["../src/snapshot.ts"],"sourcesContent":["import type { SnapshotMetadata } from \"./api-client/index.js\";\nimport { WebixApiClient, NotSupportedError } from \"./api-client/index.js\";\n\nexport interface SerializedSnapshot {\n  snapshot: SnapshotMetadata;\n}\n\n/**\n * A Snapshot is a saved state of a Sandbox that can be used to create new Sandboxes\n *\n * Use {@link Sandbox.snapshot} or {@link Snapshot.get} to construct.\n * @hideconstructor\n */\nexport class Snapshot {\n  private _client: WebixApiClient | null = null;\n\n  /**\n   * Return the in-browser sandbox client bound at construction.\n   * @internal\n   */\n  private async ensureClient(): Promise<WebixApiClient> {\n    if (this._client) return this._client;\n    throw new Error(\n      \"Snapshot is not attached to a live in-browser sandbox host.\",\n    );\n  }\n\n  /**\n   * Unique ID of this snapshot.\n   */\n  public get snapshotId(): string {\n    return this.snapshot.id;\n  }\n\n  /**\n   * The ID of the session from which this snapshot was created.\n   */\n  public get sourceSessionId(): string {\n    return this.snapshot.sourceSessionId;\n  }\n\n  /**\n   * The status of the snapshot.\n   */\n  public get status(): SnapshotMetadata[\"status\"] {\n    return this.snapshot.status;\n  }\n\n  /**\n   * The size of the snapshot in bytes, or null if not available.\n   */\n  public get sizeBytes(): number {\n    return this.snapshot.sizeBytes;\n  }\n\n  /**\n   * The creation date of this snapshot.\n   */\n  public get createdAt(): Date {\n    return new Date(this.snapshot.createdAt);\n  }\n\n  /**\n   * When this snapshot was last updated.\n   */\n  public get updatedAt(): Date {\n    return new Date(this.snapshot.updatedAt);\n  }\n\n  /**\n   * The expiration date of this snapshot, or undefined if it does not expire.\n   */\n  public get expiresAt(): Date | undefined {\n    if (this.snapshot.expiresAt === undefined) {\n      return undefined;\n    }\n\n    return new Date(this.snapshot.expiresAt);\n  }\n\n  /**\n   * Internal metadata about this snapshot.\n   */\n  private snapshot: SnapshotMetadata;\n\n  constructor({\n    client,\n    snapshot,\n  }: {\n    client?: WebixApiClient;\n    snapshot: SnapshotMetadata;\n  }) {\n    this._client = client ?? null;\n    this.snapshot = snapshot;\n  }\n\n  /**\n   * Allow to get a list of snapshots for a team narrowed to the given params.\n   * It returns both the snapshots and the pagination metadata to allow getting\n   * the next page of results.\n   *\n   * The returned object is async-iterable to auto-paginate through all pages:\n   *\n   * ```ts\n   * const result = await Snapshot.list({ name: \"my-sandbox\" });\n   * for await (const snapshot of result) { ... }\n   * // or: await result.toArray();\n   * // or: for await (const page of result.pages()) { ... }\n   * ```\n   */\n  static async list(): Promise<never> {\n    throw new NotSupportedError(\n      \"Snapshot.list is unavailable in the self-contained sandbox: snapshots are held by a live in-browser host, not a remote account. Use sandbox.snapshot() and keep the returned Snapshot.\",\n    );\n  }\n\n  /**\n   * Fetch the snapshot ancestry tree anchored on a given snapshot.\n   * It returns both the tree nodes and the pagination metadata to allow\n   * walking the next page of results in the same direction.\n   *\n   * The returned object is async-iterable to auto-paginate through all pages\n   * in the direction set by `sortOrder` (`\"desc\"` walks ancestors, `\"asc\"`\n   * walks descendants):\n   *\n   * ```ts\n   * const result = await Snapshot.tree({ snapshotId: \"snap_abc\", sortOrder: \"desc\" });\n   * for await (const node of result) { ... }\n   * // or: await result.toArray();\n   * // or: for await (const page of result.pages()) { ... }\n   * ```\n   */\n  static async tree(): Promise<never> {\n    throw new NotSupportedError(\n      \"Snapshot.tree is unavailable in the self-contained sandbox.\",\n    );\n  }\n\n  /**\n   * Retrieve an existing snapshot. Unavailable in the self-contained sandbox —\n   * snapshots are held in memory by the live host, not addressable by ID across\n   * processes. Use the {@link Snapshot} returned by `sandbox.snapshot()`.\n   */\n  static async get(): Promise<never> {\n    throw new NotSupportedError(\n      \"Snapshot.get is unavailable in the self-contained sandbox: keep the Snapshot returned by sandbox.snapshot().\",\n    );\n  }\n\n  /**\n   * Delete this snapshot.\n   *\n   * @param opts - Optional parameters.\n   * @param opts.signal - An AbortSignal to cancel the operation.\n   * @returns A promise that resolves once the snapshot has been deleted.\n   */\n  async delete(opts?: { signal?: AbortSignal }): Promise<void> {\n    const client = await this.ensureClient();\n    const response = await client.deleteSnapshot({\n      snapshotId: this.snapshot.id,\n      signal: opts?.signal,\n    });\n\n    this.snapshot = response.json.snapshot;\n  }\n}\n"],"mappings":";;;;;;;;;;AAaA,IAAa,WAAb,MAAsB;;;;;CAOpB,MAAc,eAAwC;AACpD,MAAI,KAAK,QAAS,QAAO,KAAK;AAC9B,QAAM,IAAI,MACR,8DACD;;;;;CAMH,IAAW,aAAqB;AAC9B,SAAO,KAAK,SAAS;;;;;CAMvB,IAAW,kBAA0B;AACnC,SAAO,KAAK,SAAS;;;;;CAMvB,IAAW,SAAqC;AAC9C,SAAO,KAAK,SAAS;;;;;CAMvB,IAAW,YAAoB;AAC7B,SAAO,KAAK,SAAS;;;;;CAMvB,IAAW,YAAkB;AAC3B,SAAO,IAAI,KAAK,KAAK,SAAS,UAAU;;;;;CAM1C,IAAW,YAAkB;AAC3B,SAAO,IAAI,KAAK,KAAK,SAAS,UAAU;;;;;CAM1C,IAAW,YAA8B;AACvC,MAAI,KAAK,SAAS,cAAc,OAC9B;AAGF,SAAO,IAAI,KAAK,KAAK,SAAS,UAAU;;CAQ1C,YAAY,EACV,QACA,YAIC;OA7EK,UAAiC;AA8EvC,OAAK,UAAU,UAAU;AACzB,OAAK,WAAW;;;;;;;;;;;;;;;;CAiBlB,aAAa,OAAuB;AAClC,QAAM,IAAIA,uCACR,yLACD;;;;;;;;;;;;;;;;;;CAmBH,aAAa,OAAuB;AAClC,QAAM,IAAIA,uCACR,8DACD;;;;;;;CAQH,aAAa,MAAsB;AACjC,QAAM,IAAIA,uCACR,+GACD;;;;;;;;;CAUH,MAAM,OAAO,MAAgD;AAO3D,OAAK,YALY,OADF,MAAM,KAAK,cAAc,EACV,eAAe;GAC3C,YAAY,KAAK,SAAS;GAC1B,QAAQ,MAAM;GACf,CAAC,EAEuB,KAAK"}