@kjanat/dreamcli 3.0.0-rc.6 → 3.0.0-rc.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +49 -1
- package/dist/core/cli/dispatch.d.mts +0 -1
- package/dist/core/cli/dispatch.mjs +1 -1
- package/dist/core/cli/help-links.d.mts +0 -1
- package/dist/core/cli/index.d.mts +0 -1
- package/dist/core/cli/index.mjs +9 -7
- package/dist/core/cli/planner.d.mts +0 -1
- package/dist/core/cli/planner.mjs +3 -3
- package/dist/core/cli/plugin.d.mts +1 -1
- package/dist/core/cli/propagate.d.mts +1 -1
- package/dist/core/cli/root-help.d.mts +0 -1
- package/dist/core/cli/root-help.mjs +6 -1
- package/dist/core/cli/root-surface.d.mts +0 -1
- package/dist/core/cli/runtime-preflight.d.mts +5 -1
- package/dist/core/cli/runtime-preflight.mjs +2 -1
- package/dist/core/completion/index.d.mts +0 -1
- package/dist/core/completion/index.mjs +1 -1
- package/dist/core/completion/shells/bash.d.mts +0 -1
- package/dist/core/completion/shells/bash.mjs +3 -2
- package/dist/core/completion/shells/fish.d.mts +0 -1
- package/dist/core/completion/shells/fish.mjs +3 -2
- package/dist/core/completion/shells/powershell.d.mts +0 -1
- package/dist/core/completion/shells/powershell.mjs +2 -1
- package/dist/core/completion/shells/shared.d.mts +1 -1
- package/dist/core/completion/shells/shared.mjs +5 -0
- package/dist/core/completion/shells/zsh.d.mts +0 -1
- package/dist/core/completion/shells/zsh.mjs +3 -2
- package/dist/core/config/index.d.mts +0 -1
- package/dist/core/config/index.mjs +2 -2
- package/dist/core/config/package-json.d.mts +0 -1
- package/dist/core/execution/index.d.mts +0 -1
- package/dist/core/execution/index.mjs +3 -2
- package/dist/core/help/ansi.mjs +3 -2
- package/dist/core/help/index.d.mts +1 -1
- package/dist/core/help/index.mjs +12 -6
- package/dist/core/json-schema/index.d.mts +1 -1
- package/dist/core/json-schema/index.mjs +25 -7
- package/dist/core/output/activity.d.mts +0 -1
- package/dist/core/output/contracts.d.mts +0 -1
- package/dist/core/output/contracts.mjs +1 -1
- package/dist/core/output/index.d.mts +0 -1
- package/dist/core/output/index.mjs +1 -1
- package/dist/core/output/renderers.d.mts +0 -1
- package/dist/core/parse/index.d.mts +1 -1
- package/dist/core/parse/index.mjs +75 -9
- package/dist/core/prompt/index.d.mts +1 -0
- package/dist/core/resolve/args.d.mts +1 -1
- package/dist/core/resolve/coerce.d.mts +1 -1
- package/dist/core/resolve/coerce.mjs +71 -14
- package/dist/core/resolve/contracts.d.mts +6 -1
- package/dist/core/resolve/errors.d.mts +0 -1
- package/dist/core/resolve/flags.d.mts +7 -2
- package/dist/core/resolve/flags.mjs +61 -6
- package/dist/core/resolve/index.d.mts +1 -1
- package/dist/core/resolve/index.mjs +1 -1
- package/dist/core/resolve/property.d.mts +3 -0
- package/dist/core/resolve/property.mjs +11 -3
- package/dist/core/schema/activity.d.mts +31 -11
- package/dist/core/schema/arg.d.mts +1 -2
- package/dist/core/schema/command.d.mts +8 -6
- package/dist/core/schema/command.mjs +3 -1
- package/dist/core/schema/flag.d.mts +337 -10
- package/dist/core/schema/flag.mjs +185 -3
- package/dist/core/schema/index.d.mts +4 -2
- package/dist/core/schema/middleware.d.mts +4 -3
- package/dist/core/schema/prompt.d.mts +5 -2
- package/dist/core/schema/run.d.mts +9 -1
- package/dist/core/schema/string-constraints.d.mts +97 -0
- package/dist/core/schema/string-constraints.mjs +69 -0
- package/dist/core/schema/value-parsers.d.mts +78 -0
- package/dist/core/schema/value-parsers.mjs +142 -0
- package/dist/core/schema-dsl/to-json-schema.d.mts +0 -1
- package/dist/core/testkit/index.d.mts +0 -31
- package/dist/core/testkit/index.mjs +1 -1
- package/dist/index.d.mts +5 -2
- package/dist/index.mjs +5 -5
- package/dist/runtime/adapter.d.mts +22 -1
- package/dist/runtime/adapter.mjs +3 -0
- package/dist/runtime/auto.d.mts +0 -1
- package/dist/runtime/deno.d.mts +15 -5
- package/dist/runtime/deno.mjs +9 -0
- package/dist/runtime/node.d.mts +2 -2
- package/dist/runtime/node.mjs +10 -0
- package/dist/runtime.d.mts +1 -0
- package/dist/testkit.d.mts +1 -0
- package/dist/version.mjs +2 -2
- package/dreamcli.schema.json +3 -1
- package/package.json +12 -13
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
//#region src/core/schema/value-parsers.ts
|
|
2
|
+
/**
|
|
3
|
+
* Strict ISO-8601 shapes accepted by {@link parseDateValue}:
|
|
4
|
+
* `YYYY-MM-DD`, optionally followed by `THH:MM`, `:SS`, `.mmm`, and a
|
|
5
|
+
* `Z` / `±HH:MM` offset. Anything else — including `Date.parse`-lenient
|
|
6
|
+
* inputs like `'0'` or `'March 5'` — is rejected.
|
|
7
|
+
*/
|
|
8
|
+
const ISO_DATE_PATTERN = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
9
|
+
/**
|
|
10
|
+
* Parse a strict ISO-8601 date string into a `Date`.
|
|
11
|
+
*
|
|
12
|
+
* Rejects non-string input, non-ISO shapes, and calendar-invalid components
|
|
13
|
+
* (`2026-02-31` does not silently roll over to March). Offset-less datetimes
|
|
14
|
+
* are interpreted as UTC so results never depend on the machine's timezone.
|
|
15
|
+
*
|
|
16
|
+
* @param raw - Raw flag value.
|
|
17
|
+
* @param options - Optional inclusive date bounds.
|
|
18
|
+
* @returns The parsed `Date`.
|
|
19
|
+
* @throws Error with a human-readable reason on invalid input.
|
|
20
|
+
*/
|
|
21
|
+
function parseDateValue(raw, options) {
|
|
22
|
+
if (raw instanceof Date) return validateDateBounds(raw, options);
|
|
23
|
+
if (typeof raw !== "string") throw new Error(`Invalid date '${String(raw)}': expected an ISO-8601 string`);
|
|
24
|
+
const match = ISO_DATE_PATTERN.exec(raw);
|
|
25
|
+
if (match === null) throw new Error(`Invalid date '${raw}': expected ISO-8601 (e.g. 2026-07-10 or 2026-07-10T14:30:00Z)`);
|
|
26
|
+
const [, yearPart, monthPart, dayPart, hourPart, minutePart, secondPart] = match;
|
|
27
|
+
const year = Number(yearPart);
|
|
28
|
+
const month = Number(monthPart);
|
|
29
|
+
const day = Number(dayPart);
|
|
30
|
+
if (month < 1 || month > 12) throw new Error(`Invalid date '${raw}': month must be 01-12`);
|
|
31
|
+
if (day < 1 || day > daysInMonth(year, month)) throw new Error(`Invalid date '${raw}': not a real calendar date`);
|
|
32
|
+
if (hourPart !== void 0 && Number(hourPart) > 23) throw new Error(`Invalid date '${raw}': hours must be 00-23`);
|
|
33
|
+
if (minutePart !== void 0 && Number(minutePart) > 59) throw new Error(`Invalid date '${raw}': minutes must be 00-59`);
|
|
34
|
+
if (secondPart !== void 0 && Number(secondPart) > 59) throw new Error(`Invalid date '${raw}': seconds must be 00-59`);
|
|
35
|
+
const hasTime = match[4] !== void 0;
|
|
36
|
+
const hasOffset = match[8] !== void 0;
|
|
37
|
+
const parsed = new Date(hasTime && !hasOffset ? `${raw}Z` : raw);
|
|
38
|
+
if (Number.isNaN(parsed.getTime())) throw new Error(`Invalid date '${raw}'`);
|
|
39
|
+
return validateDateBounds(parsed, options, raw);
|
|
40
|
+
}
|
|
41
|
+
/** Number of days in a month (1-12), accounting for leap years. */
|
|
42
|
+
function daysInMonth(year, month) {
|
|
43
|
+
return new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
44
|
+
}
|
|
45
|
+
/** Enforce inclusive date bounds, throwing a human-readable error on violation. */
|
|
46
|
+
function validateDateBounds(value, options, raw) {
|
|
47
|
+
const display = raw ?? value.toISOString();
|
|
48
|
+
if (options?.min !== void 0 && value.getTime() < options.min.getTime()) throw new Error(`Date '${display}' is before the earliest allowed ${options.min.toISOString()}`);
|
|
49
|
+
if (options?.max !== void 0 && value.getTime() > options.max.getTime()) throw new Error(`Date '${display}' is after the latest allowed ${options.max.toISOString()}`);
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Parse a URL string into a `URL`, optionally restricting protocols.
|
|
54
|
+
*
|
|
55
|
+
* @param raw - Raw flag value.
|
|
56
|
+
* @param options - Optional protocol allowlist.
|
|
57
|
+
* @returns The parsed `URL`.
|
|
58
|
+
* @throws Error with a human-readable reason on invalid input.
|
|
59
|
+
*/
|
|
60
|
+
function parseUrlValue(raw, options) {
|
|
61
|
+
if (typeof raw !== "string" && !(raw instanceof URL)) throw new Error(`Invalid URL '${String(raw)}': expected a URL string`);
|
|
62
|
+
let parsed;
|
|
63
|
+
try {
|
|
64
|
+
parsed = raw instanceof URL ? raw : new URL(raw);
|
|
65
|
+
} catch {
|
|
66
|
+
throw new Error(`Invalid URL '${String(raw)}'`);
|
|
67
|
+
}
|
|
68
|
+
if (options?.protocols !== void 0) {
|
|
69
|
+
const protocol = parsed.protocol.replace(/:$/, "");
|
|
70
|
+
if (!options.protocols.includes(protocol)) throw new Error(`URL protocol '${protocol}' is not allowed. Allowed: ${options.protocols.join(", ")}`);
|
|
71
|
+
}
|
|
72
|
+
return parsed;
|
|
73
|
+
}
|
|
74
|
+
/** Duration unit suffixes mapped to their length in milliseconds. */
|
|
75
|
+
const DURATION_UNITS = {
|
|
76
|
+
ms: 1,
|
|
77
|
+
s: 1e3,
|
|
78
|
+
m: 6e4,
|
|
79
|
+
h: 36e5,
|
|
80
|
+
d: 864e5
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Parse a human duration (`'30s'`, `'5m'`, `'1.5h'`, `'250ms'`, `'2d'`) into
|
|
84
|
+
* milliseconds. A bare number (`'1500'`) is treated as milliseconds. Compound
|
|
85
|
+
* values (`'1h30m'`) are supported.
|
|
86
|
+
*
|
|
87
|
+
* @param raw - Raw flag value.
|
|
88
|
+
* @returns Duration in milliseconds.
|
|
89
|
+
* @throws Error with a human-readable reason on invalid input.
|
|
90
|
+
*/
|
|
91
|
+
function parseDurationValue(raw) {
|
|
92
|
+
if (typeof raw === "number") {
|
|
93
|
+
if (!Number.isFinite(raw) || raw < 0) throw new Error(`Invalid duration '${String(raw)}': must be a non-negative number`);
|
|
94
|
+
return raw;
|
|
95
|
+
}
|
|
96
|
+
if (typeof raw !== "string" || raw.length === 0) throw new Error(`Invalid duration '${String(raw)}': expected e.g. 30s, 5m, 1h30m, or 250ms`);
|
|
97
|
+
if (/^\d+(?:\.\d+)?$/.test(raw)) return Number(raw);
|
|
98
|
+
const segmentPattern = /(\d+(?:\.\d+)?)(ms|s|m|h|d)/gy;
|
|
99
|
+
let total = 0;
|
|
100
|
+
let consumed = 0;
|
|
101
|
+
for (const segment of raw.matchAll(segmentPattern)) {
|
|
102
|
+
const [text, amount, unit] = segment;
|
|
103
|
+
const scale = unit === void 0 ? void 0 : DURATION_UNITS[unit];
|
|
104
|
+
if (amount === void 0 || scale === void 0) break;
|
|
105
|
+
total += Number(amount) * scale;
|
|
106
|
+
consumed += text.length;
|
|
107
|
+
}
|
|
108
|
+
if (consumed !== raw.length || consumed === 0) throw new Error(`Invalid duration '${raw}': expected e.g. 30s, 5m, 1h30m, or 250ms`);
|
|
109
|
+
return total;
|
|
110
|
+
}
|
|
111
|
+
/** Byte unit suffixes mapped to their size (binary, 1 kb = 1024 bytes). */
|
|
112
|
+
const BYTE_UNITS = {
|
|
113
|
+
b: 1,
|
|
114
|
+
kb: 1024,
|
|
115
|
+
mb: 1024 ** 2,
|
|
116
|
+
gb: 1024 ** 3,
|
|
117
|
+
tb: 1024 ** 4
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Parse a human byte size (`'512mb'`, `'1.5gb'`, `'64kb'`, `'100b'`) into a
|
|
121
|
+
* byte count. Units are binary (`1kb` = 1024 bytes) and case-insensitive; a
|
|
122
|
+
* bare number is treated as bytes.
|
|
123
|
+
*
|
|
124
|
+
* @param raw - Raw flag value.
|
|
125
|
+
* @returns Size in bytes.
|
|
126
|
+
* @throws Error with a human-readable reason on invalid input.
|
|
127
|
+
*/
|
|
128
|
+
function parseBytesValue(raw) {
|
|
129
|
+
if (typeof raw === "number") {
|
|
130
|
+
if (!Number.isFinite(raw) || raw < 0) throw new Error(`Invalid size '${String(raw)}': must be a non-negative number`);
|
|
131
|
+
return raw;
|
|
132
|
+
}
|
|
133
|
+
if (typeof raw !== "string" || raw.length === 0) throw new Error(`Invalid size '${String(raw)}': expected e.g. 512mb, 1.5gb, or 64kb`);
|
|
134
|
+
const match = /^(\d+(?:\.\d+)?)\s*(b|kb|mb|gb|tb)?$/i.exec(raw);
|
|
135
|
+
if (match === null || match[1] === void 0) throw new Error(`Invalid size '${raw}': expected e.g. 512mb, 1.5gb, or 64kb`);
|
|
136
|
+
const unit = (match[2] ?? "b").toLowerCase();
|
|
137
|
+
const scale = BYTE_UNITS[unit];
|
|
138
|
+
if (scale === void 0) throw new Error(`Invalid size '${raw}': unknown unit '${match[2] ?? ""}'`);
|
|
139
|
+
return Math.round(Number(match[1]) * scale);
|
|
140
|
+
}
|
|
141
|
+
//#endregion
|
|
142
|
+
export { parseBytesValue, parseDateValue, parseDurationValue, parseUrlValue };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { RunOptions, RunResult } from "../schema/run.mjs";
|
|
2
2
|
import { RunnableCommand } from "../schema/command.mjs";
|
|
3
|
-
|
|
4
3
|
//#region src/core/testkit/index.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Run a command builder against the given argv with injected options.
|
|
@@ -24,35 +23,5 @@ import { RunnableCommand } from "../schema/command.mjs";
|
|
|
24
23
|
* @returns Structured run result with exit code and captured output
|
|
25
24
|
*/
|
|
26
25
|
declare function runCommand(cmd: RunnableCommand, argv: readonly string[], options?: RunOptions): Promise<RunResult>;
|
|
27
|
-
/**
|
|
28
|
-
* Options for {@linkcode runCommand} — process-free command execution.
|
|
29
|
-
*
|
|
30
|
-
* Every field is optional. Inject env, config, prompt answers, and
|
|
31
|
-
* output capture without touching process state.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```ts
|
|
35
|
-
* const result = await runCommand(cmd, ['--verbose'], {
|
|
36
|
-
* env: { LOG_LEVEL: 'debug' },
|
|
37
|
-
* config: { theme: 'dark' },
|
|
38
|
-
* });
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
/**
|
|
42
|
-
* Structured result from {@linkcode runCommand}.
|
|
43
|
-
*
|
|
44
|
-
* Contains the exit code, captured stdout/stderr output, recorded
|
|
45
|
-
* {@linkcode ActivityEvent | activity events}, and an `error` field
|
|
46
|
-
* that is `undefined` on success and a {@linkcode CLIError} on failure.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```ts
|
|
50
|
-
* const result = await runCommand(greetCmd, ['World']);
|
|
51
|
-
*
|
|
52
|
-
* expect(result.exitCode).toBe(0);
|
|
53
|
-
* expect(result.stdout).toContain('Hello, World!');
|
|
54
|
-
* expect(result.error).toBeUndefined();
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
26
|
//#endregion
|
|
58
27
|
export { type RunOptions, type RunResult, runCommand };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createCaptureOutput } from "../output/index.mjs";
|
|
2
1
|
import { includesBeforeSeparator, stripBeforeSeparator } from "../parse/index.mjs";
|
|
2
|
+
import { createCaptureOutput } from "../output/index.mjs";
|
|
3
3
|
import { buildRunResult, executeCommand } from "../execution/index.mjs";
|
|
4
4
|
//#region src/core/testkit/index.ts
|
|
5
5
|
/**
|
package/dist/index.d.mts
CHANGED
|
@@ -2,8 +2,11 @@ import { ActivityEvent, Fallback, ProgressHandle, ProgressOptions, SpinnerHandle
|
|
|
2
2
|
import { NumberConstraintViolation, NumberConstraints } from "./core/schema/number-constraints.mjs";
|
|
3
3
|
import { ArgBuilder, ArgConfig, ArgFactory, ArgKind, ArgParseFn, ArgPresence, ArgSchema, InferArg, InferArgs, ResolvedArgValue, WithArgPresence, WithVariadic, arg, createArgSchema } from "./core/schema/arg.mjs";
|
|
4
4
|
import { ConfirmPromptConfig, InputPromptConfig, MultiselectPromptConfig, PromptConfig, PromptConfigBase, PromptKind, PromptResult, SelectChoice, SelectPromptConfig } from "./core/schema/prompt.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { StringConstraintViolation, StringConstraints } from "./core/schema/string-constraints.mjs";
|
|
6
|
+
import { DateFlagOptions, UrlFlagOptions } from "./core/schema/value-parsers.mjs";
|
|
7
|
+
import { FlagBuilder, FlagConfig, FlagFactory, FlagKind, FlagParseFn, FlagPresence, FlagSchema, InferFlag, InferFlags, PathChecks, PathFlagOptions, ResolvedValue, WithPresence, createSchema, flag } from "./core/schema/flag.mjs";
|
|
6
8
|
import { Middleware, MiddlewareHandler, MiddlewareParams, middleware } from "./core/schema/middleware.mjs";
|
|
9
|
+
import "./core/schema/index.mjs";
|
|
7
10
|
import { ParseResult, Token, parse, tokenize } from "./core/parse/index.mjs";
|
|
8
11
|
import { WriteFn } from "./core/output/writer.mjs";
|
|
9
12
|
import { Verbosity } from "./core/output/contracts.mjs";
|
|
@@ -29,4 +32,4 @@ import { ConfigAdapter, ConfigDiscoveryOptions, ConfigDiscoveryResult, ConfigFou
|
|
|
29
32
|
import { CLIBuilder, CLIOptions, CLIRunOptions, CLISchema, ConfigSettings, DefaultCommandOptions, InferNameOption, ManifestPresetSettings, ManifestSettings, PackageJsonSettings, ResolvedManifestSettings, cli } from "./core/cli/index.mjs";
|
|
30
33
|
import { JsonSchemaOptions, definitionMetaSchema, generateInputSchema, generateSchema } from "./core/json-schema/index.mjs";
|
|
31
34
|
import { Colors } from "ansispeck";
|
|
32
|
-
export { type ActionHandler, type ActionParams, type ActivityEvent, type AnyCommandBuilder, ArgBuilder, type ArgConfig, type ArgFactory, type ArgKind, type ArgParseFn, type ArgPresence, type ArgSchema, type BeforeParseParams, CLIBuilder, CLIError, type CLIErrorJSON, type CLIErrorOptions, type CLIOptions, type CLIPlugin, type CLIPluginHooks, type CLIRunOptions, type CLISchema, type Colors, type CommandArgEntry, CommandBuilder, type CommandConfig, type CommandExample, type CommandMeta, type CommandSchema, type CompletionOptions, type ConfigAdapter, type ConfigDiscoveryOptions, type ConfigDiscoveryResult, type ConfigFound, type ConfigNotFound, type ConfigSettings, type ConfirmPromptConfig, type DefaultCommandOptions, type DeprecationWarning, type DeriveHandler, type DeriveParams, type ErrorCode, type Fallback, FlagBuilder, type FlagConfig, type FlagFactory, type FlagKind, type FlagParseFn, type FlagPresence, type FlagSchema, type FormatLoader, type HelpLinks, type HelpOptions, type InferArg, type InferArgs, type InferFlag, type InferFlags, type InferNameOption, type InputPromptConfig, type InteractiveParams, type InteractiveResolver, type InteractiveResult, type JsonSchemaOptions, type ManifestDiscoveryOptions, type ManifestPresetSettings, type ManifestSettings, type Middleware, type MiddlewareHandler, type MiddlewareParams, type MultiselectPromptConfig, type NumberConstraintViolation, type NumberConstraints, type Out, type OutputOptions, type PackageJsonAdapter, type PackageJsonData, type PackageJsonSettings, type PackageRepository, ParseError, type ParseErrorCode, type ParseErrorOptions, type ParseResult, type PluginCommandContext, type ProgressHandle, type ProgressOptions, type PromptConfig, type PromptConfigBase, type PromptEngine, type PromptKind, type PromptResult, type ReadFn, type ResolveOptions, type ResolveResult, type ResolvedArgValue, type ResolvedCommandParams, type ResolvedManifestSettings, type ResolvedMultiselectPromptConfig, type ResolvedPromptConfig, type ResolvedSelectPromptConfig, type ResolvedValue, type RunResult, SHELLS, type SelectChoice, type SelectPromptConfig, type Shell, type SpinnerHandle, type SpinnerOptions, type TableColumn, type TableFormat, type TableOptions, type TableStream, type Token, ValidationError, type ValidationErrorCode, type ValidationErrorOptions, type Verbosity, type WithArgPresence, type WithPresence, type WithVariadic, type WriteFn, arg, buildConfigSearchPaths, cli, command, configFormat, createArgSchema, createOutput, createSchema, createTerminalPrompter, definitionMetaSchema, discoverConfig, discoverManifest, discoverPackageJson, flag, formatHelp, generateBashCompletion, generateCompletion, generateFishCompletion, generateInputSchema, generatePowerShellCompletion, generateSchema, generateZshCompletion, group, inferCliName, isCLIError, isParseError, isValidationError, middleware, osc8, packageRepositoryUrl, parse, plugin, resolve, resolvePromptConfig, tokenize, visibleWidth };
|
|
35
|
+
export { type ActionHandler, type ActionParams, type ActivityEvent, type AnyCommandBuilder, ArgBuilder, type ArgConfig, type ArgFactory, type ArgKind, type ArgParseFn, type ArgPresence, type ArgSchema, type BeforeParseParams, CLIBuilder, CLIError, type CLIErrorJSON, type CLIErrorOptions, type CLIOptions, type CLIPlugin, type CLIPluginHooks, type CLIRunOptions, type CLISchema, type Colors, type CommandArgEntry, CommandBuilder, type CommandConfig, type CommandExample, type CommandMeta, type CommandSchema, type CompletionOptions, type ConfigAdapter, type ConfigDiscoveryOptions, type ConfigDiscoveryResult, type ConfigFound, type ConfigNotFound, type ConfigSettings, type ConfirmPromptConfig, type DateFlagOptions, type DefaultCommandOptions, type DeprecationWarning, type DeriveHandler, type DeriveParams, type ErrorCode, type Fallback, FlagBuilder, type FlagConfig, type FlagFactory, type FlagKind, type FlagParseFn, type FlagPresence, type FlagSchema, type FormatLoader, type HelpLinks, type HelpOptions, type InferArg, type InferArgs, type InferFlag, type InferFlags, type InferNameOption, type InputPromptConfig, type InteractiveParams, type InteractiveResolver, type InteractiveResult, type JsonSchemaOptions, type ManifestDiscoveryOptions, type ManifestPresetSettings, type ManifestSettings, type Middleware, type MiddlewareHandler, type MiddlewareParams, type MultiselectPromptConfig, type NumberConstraintViolation, type NumberConstraints, type Out, type OutputOptions, type PackageJsonAdapter, type PackageJsonData, type PackageJsonSettings, type PackageRepository, ParseError, type ParseErrorCode, type ParseErrorOptions, type ParseResult, type PathChecks, type PathFlagOptions, type PluginCommandContext, type ProgressHandle, type ProgressOptions, type PromptConfig, type PromptConfigBase, type PromptEngine, type PromptKind, type PromptResult, type ReadFn, type ResolveOptions, type ResolveResult, type ResolvedArgValue, type ResolvedCommandParams, type ResolvedManifestSettings, type ResolvedMultiselectPromptConfig, type ResolvedPromptConfig, type ResolvedSelectPromptConfig, type ResolvedValue, type RunResult, SHELLS, type SelectChoice, type SelectPromptConfig, type Shell, type SpinnerHandle, type SpinnerOptions, type StringConstraintViolation, type StringConstraints, type TableColumn, type TableFormat, type TableOptions, type TableStream, type Token, type UrlFlagOptions, ValidationError, type ValidationErrorCode, type ValidationErrorOptions, type Verbosity, type WithArgPresence, type WithPresence, type WithVariadic, type WriteFn, arg, buildConfigSearchPaths, cli, command, configFormat, createArgSchema, createOutput, createSchema, createTerminalPrompter, definitionMetaSchema, discoverConfig, discoverManifest, discoverPackageJson, flag, formatHelp, generateBashCompletion, generateCompletion, generateFishCompletion, generateInputSchema, generatePowerShellCompletion, generateSchema, generateZshCompletion, group, inferCliName, isCLIError, isParseError, isValidationError, middleware, osc8, packageRepositoryUrl, parse, plugin, resolve, resolvePromptConfig, tokenize, visibleWidth };
|
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
+
import { CLIError, ParseError, ValidationError, isCLIError, isParseError, isValidationError } from "./core/errors/index.mjs";
|
|
1
2
|
import { FlagBuilder, createSchema, flag } from "./core/schema/flag.mjs";
|
|
3
|
+
import { ArgBuilder, arg, createArgSchema } from "./core/schema/arg.mjs";
|
|
4
|
+
import { CommandBuilder, command, group } from "./core/schema/command.mjs";
|
|
5
|
+
import { middleware } from "./core/schema/middleware.mjs";
|
|
6
|
+
import { parse, tokenize } from "./core/parse/index.mjs";
|
|
2
7
|
import { generateBashCompletion } from "./core/completion/shells/bash.mjs";
|
|
3
8
|
import { generateFishCompletion } from "./core/completion/shells/fish.mjs";
|
|
4
9
|
import { generatePowerShellCompletion } from "./core/completion/shells/powershell.mjs";
|
|
5
|
-
import { CLIError, ParseError, ValidationError, isCLIError, isParseError, isValidationError } from "./core/errors/index.mjs";
|
|
6
10
|
import { generateZshCompletion } from "./core/completion/shells/zsh.mjs";
|
|
7
11
|
import { SHELLS, generateCompletion } from "./core/completion/index.mjs";
|
|
8
12
|
import { osc8, visibleWidth } from "./core/help/ansi.mjs";
|
|
9
13
|
import { formatHelp } from "./core/help/index.mjs";
|
|
10
14
|
import { createOutput } from "./core/output/index.mjs";
|
|
11
|
-
import { ArgBuilder, arg, createArgSchema } from "./core/schema/arg.mjs";
|
|
12
|
-
import { CommandBuilder, command, group } from "./core/schema/command.mjs";
|
|
13
|
-
import { middleware } from "./core/schema/middleware.mjs";
|
|
14
|
-
import { parse, tokenize } from "./core/parse/index.mjs";
|
|
15
15
|
import { createTerminalPrompter, resolvePromptConfig } from "./core/prompt/index.mjs";
|
|
16
16
|
import { resolve } from "./core/resolve/index.mjs";
|
|
17
17
|
import { discoverManifest, discoverPackageJson, inferCliName, packageRepositoryUrl } from "./core/config/package-json.mjs";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WriteFn } from "../core/output/writer.mjs";
|
|
2
|
+
import "../core/output/index.mjs";
|
|
2
3
|
import { ReadFn } from "../core/prompt/index.mjs";
|
|
3
|
-
|
|
4
4
|
//#region src/runtime/adapter.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Runtime adapter interface.
|
|
@@ -82,6 +82,15 @@ interface RuntimeAdapter {
|
|
|
82
82
|
* Used by config file discovery to probe multiple candidate paths.
|
|
83
83
|
*/
|
|
84
84
|
readonly readFile: (path: string) => Promise<string | null>;
|
|
85
|
+
/**
|
|
86
|
+
* Probe what exists at a filesystem path.
|
|
87
|
+
*
|
|
88
|
+
* Returns `'file'` or `'directory'` for existing paths (other kinds such
|
|
89
|
+
* as sockets report `'file'`), or `null` when nothing exists there.
|
|
90
|
+
*
|
|
91
|
+
* Used by `flag.path()` existence/type checks after resolution.
|
|
92
|
+
*/
|
|
93
|
+
readonly stat: (path: string) => Promise<'file' | 'directory' | null>;
|
|
85
94
|
/**
|
|
86
95
|
* User home directory (absolute path).
|
|
87
96
|
*
|
|
@@ -173,6 +182,18 @@ interface TestAdapterOptions {
|
|
|
173
182
|
* ```
|
|
174
183
|
*/
|
|
175
184
|
readonly readFile?: (path: string) => Promise<string | null>;
|
|
185
|
+
/**
|
|
186
|
+
* Filesystem probe stub for `flag.path()` checks (defaults to returning
|
|
187
|
+
* `null` — nothing exists).
|
|
188
|
+
*
|
|
189
|
+
* Supply a custom function to simulate a virtual filesystem in tests:
|
|
190
|
+
* ```ts
|
|
191
|
+
* createTestAdapter({
|
|
192
|
+
* stat: (path) => Promise.resolve(path === '/data' ? 'directory' : null),
|
|
193
|
+
* })
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
readonly stat?: (path: string) => Promise<'file' | 'directory' | null>;
|
|
176
197
|
/** Home directory (defaults to `'/home/test'`). */
|
|
177
198
|
readonly homedir?: string;
|
|
178
199
|
/** Config directory (defaults to `'/home/test/.config'`). */
|
package/dist/runtime/adapter.mjs
CHANGED
|
@@ -32,6 +32,8 @@ const noopWrite = () => {};
|
|
|
32
32
|
const eofRead = () => Promise.resolve(null);
|
|
33
33
|
/** Noop file reader — returns `null` (not found) for all paths. */
|
|
34
34
|
const noopReadFile = () => Promise.resolve(null);
|
|
35
|
+
/** Noop stat — reports `null` (nothing exists) for all paths. */
|
|
36
|
+
const noopStat = () => Promise.resolve(null);
|
|
35
37
|
/**
|
|
36
38
|
* Create a test runtime adapter with injectable process state.
|
|
37
39
|
*
|
|
@@ -76,6 +78,7 @@ function createTestAdapter(options) {
|
|
|
76
78
|
throw new ExitError(code);
|
|
77
79
|
}),
|
|
78
80
|
readFile: options?.readFile ?? noopReadFile,
|
|
81
|
+
stat: options?.stat ?? noopStat,
|
|
79
82
|
homedir: options?.homedir ?? "/home/test",
|
|
80
83
|
configDir: options?.configDir ?? "/home/test/.config"
|
|
81
84
|
};
|
package/dist/runtime/auto.d.mts
CHANGED
package/dist/runtime/deno.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { RuntimeAdapter } from "./adapter.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/runtime/deno.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Minimal subset of the Deno namespace needed by the adapter.
|
|
@@ -24,14 +23,18 @@ interface DenoNamespace {
|
|
|
24
23
|
readonly args: readonly string[];
|
|
25
24
|
/** Environment variable access (requires `--allow-env`). */
|
|
26
25
|
readonly env: {
|
|
27
|
-
/** Get a single env var. Returns `undefined` if unset or permission denied. */
|
|
26
|
+
/** Get a single env var. Returns `undefined` if unset or permission denied. */
|
|
27
|
+
get(key: string): string | undefined;
|
|
28
|
+
/** Get all env vars as a plain object. Throws on permission denied. */
|
|
28
29
|
toObject(): Record<string, string>;
|
|
29
30
|
};
|
|
30
31
|
/** Current working directory (may throw if `--allow-read` is denied for cwd). */
|
|
31
32
|
cwd(): string;
|
|
32
33
|
/** Standard output — synchronous byte writer with TTY detection. */
|
|
33
34
|
readonly stdout: {
|
|
34
|
-
/** Write raw bytes to stdout synchronously. */
|
|
35
|
+
/** Write raw bytes to stdout synchronously. */
|
|
36
|
+
writeSync(p: Uint8Array): number;
|
|
37
|
+
/** Whether stdout is connected to a TTY. */
|
|
35
38
|
isTerminal(): boolean;
|
|
36
39
|
};
|
|
37
40
|
/** Current console dimensions. */
|
|
@@ -45,17 +48,24 @@ interface DenoNamespace {
|
|
|
45
48
|
removeSignalListener?(signal: 'SIGWINCH', listener: () => void): void;
|
|
46
49
|
/** Standard error — synchronous byte writer. */
|
|
47
50
|
readonly stderr: {
|
|
48
|
-
/** Write raw bytes to stderr synchronously. */
|
|
51
|
+
/** Write raw bytes to stderr synchronously. */
|
|
52
|
+
writeSync(p: Uint8Array): number;
|
|
49
53
|
};
|
|
50
54
|
/** Standard input — TTY detection and readable byte stream. */
|
|
51
55
|
readonly stdin: {
|
|
52
|
-
/** Whether stdin is connected to a TTY. */
|
|
56
|
+
/** Whether stdin is connected to a TTY. */
|
|
57
|
+
isTerminal(): boolean;
|
|
58
|
+
/** Readable stream for stdin bytes. */
|
|
53
59
|
readonly readable: ReadableStream<Uint8Array>;
|
|
54
60
|
};
|
|
55
61
|
/** Exit the process with the given code. */
|
|
56
62
|
exit(code: number): never;
|
|
57
63
|
/** Read a file as UTF-8 text (requires `--allow-read`). */
|
|
58
64
|
readTextFile(path: string): Promise<string>;
|
|
65
|
+
/** Probe a filesystem path (requires `--allow-read`). */
|
|
66
|
+
stat(path: string): Promise<{
|
|
67
|
+
readonly isDirectory: boolean;
|
|
68
|
+
}>;
|
|
59
69
|
}
|
|
60
70
|
/**
|
|
61
71
|
* Create a runtime adapter backed by the Deno namespace.
|
package/dist/runtime/deno.mjs
CHANGED
|
@@ -87,6 +87,14 @@ function createDenoAdapter(ns) {
|
|
|
87
87
|
throw err;
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
|
+
const stat = async (path) => {
|
|
91
|
+
try {
|
|
92
|
+
return (await d.stat(path)).isDirectory ? "directory" : "file";
|
|
93
|
+
} catch (err) {
|
|
94
|
+
if (isDenoErrorNamed(err, "NotFound")) return null;
|
|
95
|
+
throw err;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
90
98
|
const homedir = resolveDenoHomedir(env, d.build.os === "windows");
|
|
91
99
|
const configDir = resolveDenoConfigDir(env, homedir, d.build.os === "windows");
|
|
92
100
|
const stdinIsTTY = d.stdin.isTerminal();
|
|
@@ -104,6 +112,7 @@ function createDenoAdapter(ns) {
|
|
|
104
112
|
onTerminalResize: (listener) => onDenoTerminalResize(d, listener),
|
|
105
113
|
exit: (code) => d.exit(code),
|
|
106
114
|
readFile,
|
|
115
|
+
stat,
|
|
107
116
|
homedir,
|
|
108
117
|
configDir
|
|
109
118
|
};
|
package/dist/runtime/node.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { RuntimeAdapter } from "./adapter.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/runtime/node.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Minimal subset of the Node.js `process` object needed by the adapter.
|
|
@@ -24,7 +23,8 @@ interface NodeProcess {
|
|
|
24
23
|
readonly platform: string;
|
|
25
24
|
/** Standard input stream with TTY detection and async iteration. */
|
|
26
25
|
readonly stdin: {
|
|
27
|
-
readonly isTTY?: boolean;
|
|
26
|
+
readonly isTTY?: boolean;
|
|
27
|
+
/** Async iterable for reading all of stdin (used by readStdin). */
|
|
28
28
|
[Symbol.asyncIterator](): AsyncIterator<Uint8Array>;
|
|
29
29
|
};
|
|
30
30
|
/** Standard output stream with TTY detection and write. */
|
package/dist/runtime/node.mjs
CHANGED
|
@@ -90,6 +90,15 @@ function createNodeAdapter(proc) {
|
|
|
90
90
|
throw err;
|
|
91
91
|
}
|
|
92
92
|
};
|
|
93
|
+
const stat = async (path) => {
|
|
94
|
+
const fs = await import("node:fs/promises");
|
|
95
|
+
try {
|
|
96
|
+
return (await fs.stat(path)).isDirectory() ? "directory" : "file";
|
|
97
|
+
} catch (err) {
|
|
98
|
+
if (isNodeSystemError(err) && (err.code === "ENOENT" || err.code === "ENOTDIR")) return null;
|
|
99
|
+
throw err;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
93
102
|
const homedir = resolveHomedir(p.env, p.platform);
|
|
94
103
|
const configDir = resolveConfigDir(p.env, p.platform, homedir);
|
|
95
104
|
const stdinIsTTY = p.stdin.isTTY === true;
|
|
@@ -107,6 +116,7 @@ function createNodeAdapter(proc) {
|
|
|
107
116
|
onTerminalResize: (listener) => onNodeTerminalResize(p, listener),
|
|
108
117
|
exit: (code) => p.exit(code),
|
|
109
118
|
readFile,
|
|
119
|
+
stat,
|
|
110
120
|
homedir,
|
|
111
121
|
configDir
|
|
112
122
|
};
|
package/dist/runtime.d.mts
CHANGED
|
@@ -3,4 +3,5 @@ import { RUNTIMES, Runtime, detectRuntime } from "./runtime/detect.mjs";
|
|
|
3
3
|
import { createAdapter } from "./runtime/auto.mjs";
|
|
4
4
|
import { createDenoAdapter } from "./runtime/deno.mjs";
|
|
5
5
|
import { createNodeAdapter } from "./runtime/node.mjs";
|
|
6
|
+
import "./runtime/index.mjs";
|
|
6
7
|
export { ExitError, RUNTIMES, type Runtime, type RuntimeAdapter, type TerminalSize, createAdapter, createDenoAdapter, createNodeAdapter, detectRuntime };
|
package/dist/testkit.d.mts
CHANGED
|
@@ -3,4 +3,5 @@ import { PROMPT_CANCEL, TestAnswer, TestPrompterOptions, createTestPrompter } fr
|
|
|
3
3
|
import { RunOptions, RunResult } from "./core/schema/run.mjs";
|
|
4
4
|
import { TestAdapterOptions, createTestAdapter } from "./runtime/adapter.mjs";
|
|
5
5
|
import { runCommand } from "./core/testkit/index.mjs";
|
|
6
|
+
import "./runtime/index.mjs";
|
|
6
7
|
export { type CapturedOutput, PROMPT_CANCEL, type RunOptions, type RunResult, type TestAdapterOptions, type TestAnswer, type TestPrompterOptions, createCaptureOutput, createTestAdapter, createTestPrompter, runCommand };
|
package/dist/version.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region src/version.ts
|
|
2
2
|
/** Package version (e.g. `"0.9.1"`). `"dev"` when running unbundled. */
|
|
3
|
-
const DREAMCLI_VERSION = "3.0.0-rc.
|
|
3
|
+
const DREAMCLI_VERSION = "3.0.0-rc.7";
|
|
4
4
|
/** Git short SHA (e.g. `"f9b5f1a"`). `"dev"` when running unbundled. */
|
|
5
|
-
const DREAMCLI_REVISION = "
|
|
5
|
+
const DREAMCLI_REVISION = "e87f393";
|
|
6
6
|
//#endregion
|
|
7
7
|
export { DREAMCLI_REVISION, DREAMCLI_VERSION };
|
package/dreamcli.schema.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kjanat/dreamcli",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.7",
|
|
4
4
|
"description": "Schema-first, fully typed TypeScript CLI framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dreamcli",
|
|
@@ -100,9 +100,8 @@
|
|
|
100
100
|
"test:gh": "run --dir examples/gh test",
|
|
101
101
|
"test:node": "npx -y vitest run",
|
|
102
102
|
"test:watch": "vitest",
|
|
103
|
-
"typecheck": "
|
|
103
|
+
"typecheck": "bun node_modules/@typescript/native/bin/tsc --noEmit",
|
|
104
104
|
"typecheck:gh": "run --dir examples/gh typecheck",
|
|
105
|
-
"typecheck:tsc": "tsc --noEmit",
|
|
106
105
|
"upgrade": "bun update --latest && bun add -D vitepress@next",
|
|
107
106
|
"version:check": "bun scripts/check-version-sync.ts"
|
|
108
107
|
},
|
|
@@ -113,29 +112,29 @@
|
|
|
113
112
|
"ansispeck": "^0.1.2"
|
|
114
113
|
},
|
|
115
114
|
"devDependencies": {
|
|
116
|
-
"@arethetypeswrong/core": "^0.18.
|
|
115
|
+
"@arethetypeswrong/core": "^0.18.5",
|
|
117
116
|
"@biomejs/biome": "^2.5.2",
|
|
118
117
|
"@iarna/toml": "^2.2.5",
|
|
119
118
|
"@shikijs/transformers": "^4.3.1",
|
|
120
119
|
"@shikijs/vitepress-twoslash": "^4.3.1",
|
|
121
120
|
"@types/bun": "^1.3.14",
|
|
122
121
|
"@types/deno": "^2.7.0",
|
|
123
|
-
"@types/node": ">=26.1.
|
|
124
|
-
"@typescript/native
|
|
122
|
+
"@types/node": ">=26.1.1",
|
|
123
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
125
124
|
"@vitest/coverage-v8": "^4.1.10",
|
|
126
125
|
"dprint": "^0.55.1",
|
|
127
126
|
"floating-vue": "^5.2.2",
|
|
128
|
-
"knip": "^6.
|
|
127
|
+
"knip": "^6.25.0",
|
|
129
128
|
"mermaid": "^11.16.0",
|
|
130
129
|
"publint": "^0.3.21",
|
|
131
130
|
"runner-run": "0.19.1",
|
|
132
|
-
"tsdown": "^0.22.
|
|
131
|
+
"tsdown": "^0.22.4",
|
|
133
132
|
"typedoc": "^0.28.20",
|
|
134
|
-
"typescript": "^6.0.
|
|
135
|
-
"vite": "^8.1.
|
|
133
|
+
"typescript": "^6.0.2",
|
|
134
|
+
"vite": "^8.1.4",
|
|
136
135
|
"vitepress": "^2.0.0-alpha.18",
|
|
137
136
|
"vitest": "^4.1.10",
|
|
138
|
-
"wrangler": "^4.
|
|
137
|
+
"wrangler": "^4.110.0",
|
|
139
138
|
"yaml": "^2.9.0"
|
|
140
139
|
},
|
|
141
140
|
"packageManager": "bun@1.3.14",
|
|
@@ -163,7 +162,7 @@
|
|
|
163
162
|
},
|
|
164
163
|
"catalog": {
|
|
165
164
|
"@types/bun": "^1.3.14",
|
|
166
|
-
"@types/node": ">=26.1.
|
|
167
|
-
"typescript": "^6.0.
|
|
165
|
+
"@types/node": ">=26.1.1",
|
|
166
|
+
"typescript": "^6.0.2"
|
|
168
167
|
}
|
|
169
168
|
}
|