{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://unpkg.com/better-supabase/schemas/cli-result-v2.json",
  "title": "better-supabase CLI result",
  "description": "What a better-supabase command prints under `--json`. A run that succeeds, or reports findings, prints the result document on stdout. A run that fails prints the error document as one line on stderr and nothing on stdout.",
  "oneOf": [
    {
      "$ref": "#/$defs/result"
    },
    {
      "$ref": "#/$defs/error"
    }
  ],
  "$defs": {
    "result": {
      "type": "object",
      "additionalProperties": false,
      "required": ["$schema", "status"],
      "properties": {
        "$schema": {
          "type": "string"
        },
        "status": {
          "description": "`success` for exit code 0, `error` for a report that exits 1 (its findings are in `data`).",
          "enum": ["success", "error"]
        },
        "data": {
          "description": "The command result, keyed by noun. Its shape depends on the command."
        },
        "warnings": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string"
          }
        },
        "next": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/next"
          }
        }
      }
    },
    "error": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "$schema",
        "status",
        "reason",
        "message",
        "type",
        "next",
        "data",
        "userActionRequired",
        "retryable"
      ],
      "properties": {
        "$schema": {
          "type": "string"
        },
        "status": {
          "description": "`action_required` when a person has to give an input, confirm or log in, `error` otherwise.",
          "enum": ["error", "action_required"]
        },
        "reason": {
          "description": "Why the run failed, from a fixed list.",
          "enum": [
            "usage",
            "unknown_command",
            "unknown_flag",
            "invalid_value",
            "command_moved",
            "flag_renamed",
            "missing_value",
            "outside_root",
            "config_not_found",
            "config_invalid",
            "env_invalid",
            "not_found",
            "invalid_input",
            "dependency_missing",
            "database_unreachable",
            "supabase_cli_missing",
            "supabase_cli_failed",
            "supabase_cli_too_old",
            "network_error",
            "request_failed",
            "auth_required",
            "integrity_failed",
            "generator_failed",
            "check_failed",
            "file_conflict",
            "findings",
            "input_required",
            "confirmation_required",
            "cancelled",
            "failed",
            "internal"
          ]
        },
        "message": {
          "type": "string"
        },
        "type": {
          "description": "Links to the reason on the CLI errors page.",
          "type": "string",
          "format": "uri"
        },
        "next": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/next"
          }
        },
        "data": {
          "description": "Details of the failure.",
          "type": "object",
          "properties": {
            "suggestion": {
              "description": "The closest command or option.",
              "type": "string"
            },
            "flag": {
              "description": "The flag that supplies the missing value.",
              "type": "string"
            },
            "issues": {
              "description": "One line per problem.",
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "missing": {
              "description": "The flags the run needs, for input_required.",
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "choices": {
              "description": "The values each missing flag takes, the suggested one first.",
              "type": "object",
              "additionalProperties": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "digest": {
              "description": "The value for --effects-digest once the user agrees, for confirmation_required.",
              "type": "string"
            },
            "effects": {
              "description": "What the run would change, one line each.",
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "userActionRequired": {
          "type": "boolean"
        },
        "retryable": {
          "type": "boolean"
        }
      }
    },
    "next": {
      "type": "object",
      "additionalProperties": false,
      "required": ["command", "argv", "when"],
      "properties": {
        "command": {
          "type": "string"
        },
        "argv": {
          "description": "`command` as arguments, so a caller needs no shell parsing.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "when": {
          "type": "string"
        }
      }
    }
  }
}
