{"version":3,"sources":["../../../../src/batch-settlement/client/fileStorage.ts"],"sourcesContent":["import { unlink } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\nimport { isNodeEnoent, readJsonFile, writeJsonAtomic } from \"../storage-utils\";\nimport type { FileChannelStorageOptions } from \"../types\";\nimport type { ClientChannelStorage, BatchSettlementClientContext } from \"./storage\";\n\nexport type { FileChannelStorageOptions };\n\n/**\n * Node.js file-backed {@link ClientChannelStorage} for the batched client scheme.\n * Each channel's context is persisted as `{root}/client/{channelId}.json` so that channel\n * records survive process restarts.\n */\nexport class FileClientChannelStorage implements ClientChannelStorage {\n  private readonly root: string;\n\n  /**\n   * Creates file-backed client channel storage under the given root directory.\n   *\n   * @param options - Configuration including the storage root directory.\n   */\n  constructor(options: FileChannelStorageOptions) {\n    this.root = options.directory;\n  }\n\n  /**\n   * Loads the stored client context for a channel, if present.\n   *\n   * @param key - Channel storage key (typically a lowercased channelId).\n   * @returns Parsed context or `undefined` when the file is missing.\n   */\n  async get(key: string): Promise<BatchSettlementClientContext | undefined> {\n    return readJsonFile<BatchSettlementClientContext>(this.filePath(key));\n  }\n\n  /**\n   * Persists the client context for a channel.\n   *\n   * @param key - Channel storage key.\n   * @param context - Context record to write.\n   */\n  async set(key: string, context: BatchSettlementClientContext): Promise<void> {\n    await writeJsonAtomic(this.filePath(key), context);\n  }\n\n  /**\n   * Removes the persisted context file for a channel, if it exists.\n   *\n   * @param key - Channel storage key.\n   */\n  async delete(key: string): Promise<void> {\n    try {\n      await unlink(this.filePath(key));\n    } catch (err: unknown) {\n      if (isNodeEnoent(err)) return;\n      throw err;\n    }\n  }\n\n  /**\n   * Absolute path to the JSON file for a channel.\n   *\n   * @param key - Channel storage key.\n   * @returns Filesystem path under `{root}/client/...`.\n   */\n  private filePath(key: string): string {\n    return join(this.root, \"client\", `${key.toLowerCase()}.json`);\n  }\n}\n"],"mappings":";;;;;;;AAAA,SAAS,cAAc;AACvB,SAAS,YAAY;AAad,IAAM,2BAAN,MAA+D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQpE,YAAY,SAAoC;AAC9C,SAAK,OAAO,QAAQ;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,IAAI,KAAgE;AACxE,WAAO,aAA2C,KAAK,SAAS,GAAG,CAAC;AAAA,EACtE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,IAAI,KAAa,SAAsD;AAC3E,UAAM,gBAAgB,KAAK,SAAS,GAAG,GAAG,OAAO;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,OAAO,KAA4B;AACvC,QAAI;AACF,YAAM,OAAO,KAAK,SAAS,GAAG,CAAC;AAAA,IACjC,SAAS,KAAc;AACrB,UAAI,aAAa,GAAG,EAAG;AACvB,YAAM;AAAA,IACR;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,SAAS,KAAqB;AACpC,WAAO,KAAK,KAAK,MAAM,UAAU,GAAG,IAAI,YAAY,CAAC,OAAO;AAAA,EAC9D;AACF;","names":[]}