---
source: lib/src/sdk/typescript/types.rs
expression: "get_file(&output, \"client.ts\")"
---
// @generated by usage-cli from test.usage.kdl. Do not edit manually.
import { CliRunner, CliResult } from "./runtime";
import { CreateArgs, CreateFlags, RunFlags } from "./types";

export class App {
  private runner: CliRunner;
  /** Database operations */
  readonly db: Db;

  constructor(binPath?: string) {
    this.runner = new CliRunner(binPath ?? "app");
    this.db = new Db(this.runner);
  }
  /** <SUBCOMMAND> */
  async exec(): Promise<CliResult> {
    return this.runner.run([]);
  }
}

/** Database operations */
export class Db {
  private runner: CliRunner;
  /** Migration management */
  readonly migration: Migration;

  constructor(runner: CliRunner) {
    this.runner = runner;
    this.migration = new Migration(this.runner);
  }
  /** db <SUBCOMMAND> */
  async exec(): Promise<CliResult> {
    return this.runner.run(["db"]);
  }
}

/** Migration management */
export class Migration {
  private runner: CliRunner;
  /** Create a new migration */
  readonly create: Create;
  /** Run pending migrations */
  readonly run: Run;

  constructor(runner: CliRunner) {
    this.runner = runner;
    this.create = new Create(this.runner);
    this.run = new Run(this.runner);
  }
  /** db migration <SUBCOMMAND> */
  async exec(): Promise<CliResult> {
    return this.runner.run(["db", "migration"]);
  }
}

/** Create a new migration */
export class Create {
  private runner: CliRunner;

  constructor(runner: CliRunner) {
    this.runner = runner;
  }
  /** db migration create [--template <t>] <name> */
  async exec(args: CreateArgs, flags?: CreateFlags): Promise<CliResult> {
    const cmdArgs: string[] = ["db", "migration", "create"];
    if (args.name !== undefined) { cmdArgs.push(String(args.name)); }
    const flagArgs = this.buildFlagArgs(flags);
    return this.runner.run([...cmdArgs, ...flagArgs]);
  }

  private buildFlagArgs(flags?: CreateFlags): string[] {
    const result: string[] = [];
    if (!flags) return result;
    if (flags.template !== undefined) { result.push("--template", String(flags.template)); }
    return result;
  }
}

/** Run pending migrations */
export class Run {
  private runner: CliRunner;

  constructor(runner: CliRunner) {
    this.runner = runner;
  }
  /** db migration run [--step <n>] */
  async exec(flags?: RunFlags): Promise<CliResult> {
    const cmdArgs: string[] = ["db", "migration", "run"];
    const flagArgs = this.buildFlagArgs(flags);
    return this.runner.run([...cmdArgs, ...flagArgs]);
  }

  private buildFlagArgs(flags?: RunFlags): string[] {
    const result: string[] = [];
    if (!flags) return result;
    if (flags.step !== undefined) { result.push("--step", String(flags.step)); }
    return result;
  }
}
