import { Bt as FlagKind, Pn as NumberConstraints, Q as ArgKind, T as ExampleMeta, Ut as FlagPresence, b as CommandSchema, et as ArgPresence, jt as DuplicatePolicy, kn as PromptKind, vt as DuplicateKeys } from "./index-BziI2aKc.mjs"; import "./index-DWsnGZlx.mjs"; import { o as CLISchema } from "./index-DXROeDPC.mjs"; //#region src/core/json-schema/constants.d.ts /** * Identifiers of the definition document format. * * @module dreamcli/core/json-schema/constants */ /** * `$schema` URL for definition documents. * * Self-hosted. The `v1` segment is the definition format version, the value * every document reports as `schemaVersion`, so it resolves for every package * release that emits `schemaVersion: 1`. Two mirrors carry identical bytes: * `./node_modules/@kjanat/dreamcli/dreamcli.schema.json` for offline or * local-first workflows, and * `https://cdn.jsdelivr.net/npm/@kjanat/dreamcli/dreamcli.schema.json` on the * npm CDN. */ declare const DEFINITION_SCHEMA_URL = "https://dreamcli.kjanat.dev/schemas/definition/v1.schema.json"; /** * Version of the definition document format emitted by `generateSchema()` * and `generateCommandSchema()` from `@kjanat/dreamcli/json-schema`. */ declare const DEFINITION_SCHEMA_VERSION = 1; //#endregion //#region src/core/json-schema/index.d.ts /** * Options for JSON Schema generation. * * Both {@link generateSchema} and {@link generateInputSchema} accept these * options to control which parts of the CLI schema are included in the output. */ interface JsonSchemaOptions { /** * Include commands marked as hidden. * * When `true` (default), hidden commands appear in the output with * `hidden: true` (definition schema) or as valid branches (input schema). * When `false`, hidden commands and their entire subtrees are excluded. * * @defaultValue `true` */ readonly includeHidden?: boolean; /** * Include prompt configuration on flags. * * When `false`, prompt configs are omitted even if defined on flags. * Useful for producing a schema focused on the non-interactive CLI * surface only. * * Only affects {@link generateSchema} output — prompt configs are never * included in {@link generateInputSchema} output. * * @defaultValue `true` */ readonly includePrompts?: boolean; } /** * A usage example inside a definition document. * * Function-form examples are resolved to strings during serialization. */ type ExampleDefinitionFragmentV1 = { readonly command: string; readonly description?: string; }; /** A selectable choice of a `select` or `multiselect` prompt fragment. */ type PromptChoiceFragmentV1 = { readonly value: string; readonly label?: string; readonly description?: string; }; /** * Prompt configuration attached to a flag fragment. * * Validation callbacks are dropped. Only the serializable description of the * prompt survives. */ type PromptDefinitionFragmentV1 = { readonly kind: PromptKind; readonly message: string; readonly placeholder?: string; readonly choices?: readonly PromptChoiceFragmentV1[]; readonly min?: number; readonly max?: number; }; /** * Stdin binding of a flag or arg fragment. * * Every field is always written, so a document states the trigger, the sharing * mode, and the trimming without a reader having to know the builder's defaults. */ type StdinBindingFragmentV1 = { readonly when: 'dash' | 'missing' | 'dash-or-missing'; readonly consume: 'exclusive' | 'broadcast'; readonly trim: boolean; }; /** * How one source's text decodes into collection elements. * * A delimiter carries its own literal; every other format is named alone. */ type SplitPolicyFragmentV1 = { readonly format: 'whole'; } | { readonly format: 'delimiter'; readonly delimiter: string; } | { readonly format: 'lines'; } | { readonly format: 'json'; }; /** * Non-CLI split policies of a collection fragment. * * The CLI delimiter is the fragment's own `separator`. A source absent here * takes its default: comma-delimited for env, line-delimited for stdin. */ type SourceSplitFragmentV1 = { readonly env?: SplitPolicyFragmentV1; readonly stdin?: SplitPolicyFragmentV1; }; /** Negated-spelling settings of a boolean flag fragment. */ type FlagNegationFragmentV1 = { readonly alias?: string; readonly hidden?: true; }; /** * String constraints of a flag or arg fragment, with the pattern split into * source and flags. */ type FlagStringConstraintsFragmentV1 = { readonly nonEmpty?: boolean; readonly minLength?: number; readonly maxLength?: number; readonly pattern?: { readonly source: string; readonly flags: string; }; }; /** Filesystem expectations of a flag or arg fragment. */ type FlagPathChecksFragmentV1 = { readonly mustExist: boolean; readonly type?: 'file' | 'directory'; readonly create?: true; }; /** A collection flag's element fragment, excluding input-level metadata. */ type FlagElementFragmentV1 = { readonly kind: FlagKind; readonly presence: FlagPresence; readonly defaultValue?: unknown; readonly aliases?: readonly string[]; readonly stdin?: StdinBindingFragmentV1; readonly envVar?: string; readonly configPath?: string; readonly description?: string; readonly enumValues?: readonly string[]; readonly numberConstraints?: NumberConstraints; readonly stringConstraints?: FlagStringConstraintsFragmentV1; readonly elementSchema?: FlagElementFragmentV1; readonly separator?: string; readonly split?: SourceSplitFragmentV1; readonly duplicateKeys?: DuplicateKeys; readonly unique?: true; readonly pathChecks?: FlagPathChecksFragmentV1; readonly valueHint?: string; readonly prompt?: PromptDefinitionFragmentV1; readonly deprecated?: string | true; readonly propagate?: true; readonly negation?: FlagNegationFragmentV1; readonly duplicates?: DuplicatePolicy; }; /** * A flag entry inside a definition document. * * Optional fields appear only when the flag sets them; `defaultValue` appears * only for non-sensitive inputs when the value survives a JSON round-trip. */ type FlagDefinitionFragmentV1 = FlagElementFragmentV1 & { readonly defaultDescription?: string | false; readonly sensitive?: true; }; /** * The supported value-axis fields of an entries arg's `elementSchema`. * * Entry values have a codec, constraints, path checks, and a value hint. They * do not independently declare sources, presence, metadata, collections, or * another key-value layer. */ type ArgElementFragmentV1 = { readonly kind: Exclude; /** Entry values are required once their containing key-value argument is present. */ readonly presence: 'required'; readonly enumValues?: readonly string[]; readonly numberConstraints?: NumberConstraints; readonly stringConstraints?: FlagStringConstraintsFragmentV1; readonly pathChecks?: FlagPathChecksFragmentV1; readonly valueHint?: string; }; /** * A positional arg entry inside a definition document. * * Array order carries the CLI position. */ type ArgDefinitionFragmentV1 = { readonly name: string; readonly kind: ArgKind; readonly presence: ArgPresence; readonly variadic?: true; readonly stdin?: StdinBindingFragmentV1; readonly defaultValue?: unknown; readonly defaultDescription?: string | false; readonly sensitive?: true; readonly description?: string; readonly envVar?: string; readonly configPath?: string; readonly enumValues?: readonly string[]; readonly elementSchema?: ArgElementFragmentV1; readonly numberConstraints?: NumberConstraints; readonly stringConstraints?: FlagStringConstraintsFragmentV1; readonly pathChecks?: FlagPathChecksFragmentV1; readonly valueHint?: string; readonly separator?: string; readonly split?: SourceSplitFragmentV1; readonly duplicateKeys?: DuplicateKeys; readonly unique?: true; readonly prompt?: PromptDefinitionFragmentV1; readonly deprecated?: string | true; }; /** * A command nested inside a definition document. * * Fragments carry no `schemaVersion`. They inherit the version of the document * they sit in. The standalone form is {@link CommandDefinitionDocumentV1}. */ type CommandDefinitionFragmentV1 = { /** The command name used for dispatch. */ readonly name: string; /** Human-readable description for help text. */ readonly description?: string; /** Alternative names accepted for this command. */ readonly aliases?: readonly string[]; /** Whether the command is omitted from help listings. */ readonly hidden?: true; /** Usage examples attached to the command. */ readonly examples?: readonly ExampleDefinitionFragmentV1[]; /** Named flag definitions keyed by flag name. */ readonly flags: Readonly>; /** Positional argument definitions in CLI order. */ readonly args: readonly ArgDefinitionFragmentV1[]; /** Nested subcommand definitions. */ readonly commands: readonly CommandDefinitionFragmentV1[]; }; /** * A whole-CLI definition document, version 1. * * Produced by {@link generateSchema}. Validated by {@link definitionMetaSchema} * and served at {@link DEFINITION_SCHEMA_URL}. */ type DefinitionDocumentV1 = { readonly $schema: string; readonly schemaVersion: 1; readonly name: string; readonly version?: string; readonly description?: string; readonly defaultCommand?: CommandDefinitionFragmentV1; readonly commands: readonly CommandDefinitionFragmentV1[]; }; /** * A single-command definition document, version 1. * * Produced by {@link generateCommandSchema}. Same shape as a * {@link CommandDefinitionFragmentV1} plus the `schemaVersion` every standalone * document carries. */ type CommandDefinitionDocumentV1 = CommandDefinitionFragmentV1 & { /** Definition document format version. */ readonly schemaVersion: 1; }; /** The current whole-CLI definition document. */ type DefinitionDocument = DefinitionDocumentV1; /** The current single-command definition document. */ type CommandDefinitionDocument = CommandDefinitionDocumentV1; /** A JSON Schema fragment describing one flag or arg as an input property. */ type InputSchemaProperty = Readonly>; /** The JSON Schema object describing one command's flags and args. */ type InputSchemaBranch = { readonly type: 'object'; readonly properties: Readonly>; readonly additionalProperties: false; readonly required?: readonly string[]; }; /** * A JSON Schema (draft 2020-12) document produced by {@link generateInputSchema}. * * This document sits outside the definition-document family. It holds one * branch for a single invocable command, a `oneOf` union for several, and a * bare object schema when a CLI has none. */ type InputSchemaDocument = ({ readonly $schema: string; } & InputSchemaBranch) | { readonly $schema: string; readonly oneOf: readonly InputSchemaBranch[]; } | { readonly $schema: string; readonly type: 'object'; }; /** * Generate a definition metadata document describing the CLI's structure. * * Walks the full command tree and produces a plain JSON-serializable object * representing all commands, subcommands, flags, args, and metadata. * Non-serializable runtime values (parse functions, interactive resolvers) * are omitted. * * @param schema - The CLI schema from `CLIBuilder.schema`. * @param options - Generation options. * @param meta - Program name/version for function-form examples; defaults to * the CLI schema's own `name`/`version`. * @returns A plain object suitable for `JSON.stringify()`. * * @example * ```ts * const app = cli('myapp').version('1.0.0').command(deploy); * const definition = generateSchema(app.schema); * writeFileSync('cli-schema.json', JSON.stringify(definition, null, 2)); * ``` */ declare function generateSchema(schema: CLISchema, options?: JsonSchemaOptions, meta?: ExampleMeta): DefinitionDocumentV1; /** * Generate the definition metadata document for a single command. * * The per-command counterpart of {@link generateSchema}: one entry of its * `commands` array (flags, args, subcommands, examples), plus the * `schemaVersion` every standalone document carries. Powers `--help` in * `--json` mode and is useful for embedding one command's definition into * custom tooling. * * @param schema - The command schema to serialize. * @param options - Generation options. * @param meta - Program name/version for function-form examples; defaults to * the command's own name with no version. * @returns A plain object suitable for `JSON.stringify()`. * @remarks Validate standalone output against * `https://dreamcli.kjanat.dev/schemas/definition/v1.schema.json#/$defs/commandDocument`. */ declare function generateCommandSchema(schema: CommandSchema, options?: JsonSchemaOptions, meta?: ExampleMeta): CommandDefinitionDocumentV1; /** * Generate a JSON Schema (draft 2020-12) for validating CLI input as JSON. * * Accepts either a full {@link CLISchema} (producing a discriminated union * across all commands) or a single {@link CommandSchema} (producing a flat * object schema for that command's flags and args). * * **Single command** — produces an object schema where flag/arg names are * properties with appropriate JSON Schema types. * * **Multi-command CLI** — produces a `oneOf` discriminated union with a * `command` property identifying each branch. Nested subcommands use * dot-delimited paths (e.g. `"deploy.rollback"`). * * Only commands with action handlers are included (group commands without * actions are not directly invocable and are skipped). * * @param schema - A CLI schema or a single command schema. * @param options - Generation options. * @returns A JSON Schema object suitable for `JSON.stringify()`. * * @example * ```ts * // Validate a config file against the CLI's input shape * const inputSchema = generateInputSchema(app.schema); * writeFileSync('input-schema.json', JSON.stringify(inputSchema, null, 2)); * ``` */ declare function generateInputSchema(schema: CLISchema | CommandSchema, options?: JsonSchemaOptions): InputSchemaDocument; /** * JSON Schema (draft 2020-12) that validates the output of {@link generateSchema}. * * Hosted at {@link DEFINITION_SCHEMA_URL} for `$schema` resolution. Also * exported so tooling can validate definition documents without a network * round-trip. * * @example * ```ts * import Ajv from 'ajv/dist/2020'; * import { definitionMetaSchema, generateSchema } from '@kjanat/dreamcli'; * * const ajv = new Ajv(); * const validate = ajv.compile(definitionMetaSchema); * const valid = validate(generateSchema(myCli.schema)); * ``` */ declare const definitionMetaSchema: Record; //#endregion export { definitionMetaSchema as C, DEFINITION_SCHEMA_URL as D, generateSchema as E, DEFINITION_SCHEMA_VERSION as O, StdinBindingFragmentV1 as S, generateInputSchema as T, JsonSchemaOptions as _, CommandDefinitionFragmentV1 as a, SourceSplitFragmentV1 as b, ExampleDefinitionFragmentV1 as c, FlagNegationFragmentV1 as d, FlagPathChecksFragmentV1 as f, InputSchemaProperty as g, InputSchemaDocument as h, CommandDefinitionDocumentV1 as i, FlagDefinitionFragmentV1 as l, InputSchemaBranch as m, ArgElementFragmentV1 as n, DefinitionDocument as o, FlagStringConstraintsFragmentV1 as p, CommandDefinitionDocument as r, DefinitionDocumentV1 as s, ArgDefinitionFragmentV1 as t, FlagElementFragmentV1 as u, PromptChoiceFragmentV1 as v, generateCommandSchema as w, SplitPolicyFragmentV1 as x, PromptDefinitionFragmentV1 as y };