@kjanat/dreamcli 3.0.0 → 4.0.0-rc.1

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.
Files changed (147) hide show
  1. package/CHANGELOG.md +967 -1
  2. package/README.md +9 -3
  3. package/dist/core/cli/builtins.d.mts +47 -0
  4. package/dist/core/cli/builtins.mjs +135 -0
  5. package/dist/core/cli/compiled.d.mts +29 -0
  6. package/dist/core/cli/compiled.mjs +76 -0
  7. package/dist/core/cli/dispatch.d.mts +9 -85
  8. package/dist/core/cli/help-links.d.mts +2 -14
  9. package/dist/core/cli/index.d.mts +282 -101
  10. package/dist/core/cli/index.mjs +497 -264
  11. package/dist/core/cli/planner.d.mts +13 -86
  12. package/dist/core/cli/planner.mjs +47 -30
  13. package/dist/core/cli/plugin.d.mts +1 -1
  14. package/dist/core/cli/propagate.mjs +1 -1
  15. package/dist/core/cli/reserved-flags.d.mts +1 -0
  16. package/dist/core/cli/reserved-flags.mjs +158 -0
  17. package/dist/core/cli/root-help.d.mts +1 -47
  18. package/dist/core/cli/root-help.mjs +37 -47
  19. package/dist/core/cli/root-output-flags.d.mts +1 -0
  20. package/dist/core/cli/root-output-flags.mjs +169 -0
  21. package/dist/core/cli/root-surface.d.mts +1 -68
  22. package/dist/core/cli/root-surface.mjs +2 -2
  23. package/dist/core/cli/runtime-preflight.d.mts +1 -199
  24. package/dist/core/cli/runtime-preflight.mjs +67 -17
  25. package/dist/core/completion/index.d.mts +2 -2
  26. package/dist/core/completion/shells/bash.d.mts +0 -1
  27. package/dist/core/completion/shells/bash.mjs +2 -1
  28. package/dist/core/completion/shells/fish.d.mts +0 -1
  29. package/dist/core/completion/shells/fish.mjs +2 -1
  30. package/dist/core/completion/shells/powershell.d.mts +0 -1
  31. package/dist/core/completion/shells/powershell.mjs +2 -1
  32. package/dist/core/completion/shells/shared.d.mts +3 -114
  33. package/dist/core/completion/shells/shared.mjs +9 -39
  34. package/dist/core/completion/shells/zsh.d.mts +0 -1
  35. package/dist/core/completion/shells/zsh.mjs +2 -1
  36. package/dist/core/config/index.d.mts +3 -3
  37. package/dist/core/config/index.mjs +2 -2
  38. package/dist/core/config/package-json.d.mts +2 -33
  39. package/dist/core/config/package-json.mjs +1 -34
  40. package/dist/core/errors/index.d.mts +7 -7
  41. package/dist/core/execution/index.d.mts +1 -48
  42. package/dist/core/execution/index.mjs +42 -27
  43. package/dist/core/help/ansi.d.mts +0 -11
  44. package/dist/core/help/index.d.mts +3 -35
  45. package/dist/core/help/index.mjs +29 -6
  46. package/dist/core/help/theme.d.mts +1 -21
  47. package/dist/core/json-schema/index.d.mts +279 -10
  48. package/dist/core/json-schema/index.mjs +482 -237
  49. package/dist/core/json-schema/meta-descriptions.generated.d.mts +79 -7
  50. package/dist/core/json-schema/meta-descriptions.generated.mjs +40 -6
  51. package/dist/core/output/activity.d.mts +1 -193
  52. package/dist/core/output/activity.mjs +1 -1
  53. package/dist/core/output/bind.d.mts +1 -37
  54. package/dist/core/output/contracts.d.mts +7 -13
  55. package/dist/core/output/contracts.mjs +1 -1
  56. package/dist/core/output/display-value.d.mts +1 -19
  57. package/dist/core/output/index.d.mts +5 -187
  58. package/dist/core/output/index.mjs +44 -9
  59. package/dist/core/output/renderers.d.mts +1 -45
  60. package/dist/core/output/writer.d.mts +0 -1
  61. package/dist/core/parse/index.d.mts +27 -5
  62. package/dist/core/parse/index.mjs +350 -227
  63. package/dist/core/parse/occurrences.d.mts +89 -0
  64. package/dist/core/parse/occurrences.mjs +114 -0
  65. package/dist/core/prompt/index.d.mts +3 -3
  66. package/dist/core/read-flags/index.d.mts +150 -0
  67. package/dist/core/read-flags/index.mjs +217 -0
  68. package/dist/core/resolve/args.d.mts +35 -4
  69. package/dist/core/resolve/args.mjs +132 -55
  70. package/dist/core/resolve/coerce.d.mts +66 -9
  71. package/dist/core/resolve/coerce.mjs +834 -270
  72. package/dist/core/resolve/config.d.mts +1 -10
  73. package/dist/core/resolve/contracts.d.mts +67 -44
  74. package/dist/core/resolve/errors.mjs +29 -21
  75. package/dist/core/resolve/flags.d.mts +36 -9
  76. package/dist/core/resolve/flags.mjs +129 -151
  77. package/dist/core/resolve/index.d.mts +8 -6
  78. package/dist/core/resolve/index.mjs +51 -18
  79. package/dist/core/resolve/path-checks.d.mts +47 -0
  80. package/dist/core/resolve/path-checks.mjs +102 -0
  81. package/dist/core/resolve/redaction.d.mts +12 -0
  82. package/dist/core/resolve/redaction.mjs +14 -0
  83. package/dist/core/resolve/stages.d.mts +85 -0
  84. package/dist/core/resolve/stages.mjs +170 -0
  85. package/dist/core/resolve/standard.d.mts +1 -24
  86. package/dist/core/resolve/standard.mjs +141 -43
  87. package/dist/core/schema/activity.d.mts +16 -16
  88. package/dist/core/schema/arg.d.mts +849 -71
  89. package/dist/core/schema/arg.mjs +727 -54
  90. package/dist/core/schema/brand.d.mts +17 -0
  91. package/dist/core/schema/cardinality.d.mts +301 -0
  92. package/dist/core/schema/cardinality.mjs +514 -0
  93. package/dist/core/schema/command.d.mts +181 -112
  94. package/dist/core/schema/command.mjs +305 -42
  95. package/dist/core/schema/flag.d.mts +515 -173
  96. package/dist/core/schema/flag.mjs +576 -78
  97. package/dist/core/schema/index.d.mts +11 -8
  98. package/dist/core/schema/index.mjs +10 -0
  99. package/dist/core/schema/middleware.d.mts +15 -12
  100. package/dist/core/schema/number-constraints.d.mts +5 -5
  101. package/dist/core/schema/prompt.d.mts +4 -4
  102. package/dist/core/schema/provenance.d.mts +99 -0
  103. package/dist/core/schema/provenance.mjs +28 -0
  104. package/dist/core/schema/run.d.mts +21 -60
  105. package/dist/core/schema/source.d.mts +179 -0
  106. package/dist/core/schema/source.mjs +206 -0
  107. package/dist/core/schema/standard.d.mts +12 -19
  108. package/dist/core/schema/stdin.d.mts +87 -0
  109. package/dist/core/schema/stdin.mjs +91 -0
  110. package/dist/core/schema/string-constraints.d.mts +16 -5
  111. package/dist/core/schema/string-constraints.mjs +18 -1
  112. package/dist/core/schema/value-parsers.d.mts +81 -9
  113. package/dist/core/schema/value-parsers.mjs +19 -1
  114. package/dist/core/schema/value.d.mts +242 -0
  115. package/dist/core/schema/value.mjs +573 -0
  116. package/dist/core/testkit/index.d.mts +28 -3
  117. package/dist/core/testkit/index.mjs +40 -26
  118. package/dist/index.d.mts +21 -16
  119. package/dist/index.mjs +10 -6
  120. package/dist/runtime/adapter.d.mts +3 -3
  121. package/dist/runtime/deno.d.mts +3 -3
  122. package/dist/runtime/detect.d.mts +2 -2
  123. package/dist/runtime/node.d.mts +3 -3
  124. package/dist/runtime/paths.d.mts +1 -31
  125. package/dist/runtime.d.mts +4 -4
  126. package/dist/strings.d.mts +1 -16
  127. package/dist/testkit.d.mts +2 -2
  128. package/dist/testkit.mjs +1 -1
  129. package/dist/version.d.mts +0 -13
  130. package/dist/version.mjs +2 -2
  131. package/dreamcli.schema.json +368 -78
  132. package/examples/interactive.ts +6 -5
  133. package/package.json +10 -9
  134. package/skills/cli-creation/SKILL.md +196 -0
  135. package/skills/cli-creation/agents/openai.yaml +4 -0
  136. package/skills/cli-creation/assets/templates/multi-command.bun-test.ts.tpl +20 -0
  137. package/skills/cli-creation/assets/templates/multi-command.test.ts.tpl +20 -0
  138. package/skills/cli-creation/assets/templates/multi-command.ts.tpl +89 -0
  139. package/skills/cli-creation/assets/templates/single-command.bun-test.ts.tpl +29 -0
  140. package/skills/cli-creation/assets/templates/single-command.test.ts.tpl +29 -0
  141. package/skills/cli-creation/assets/templates/single-command.ts.tpl +47 -0
  142. package/skills/cli-creation/references/consumer-workflow.md +65 -0
  143. package/skills/cli-creation/references/pattern-cookbook.md +451 -0
  144. package/skills/cli-creation/references/runtime-notes.md +29 -0
  145. package/skills/cli-creation/scripts/scaffold_cli.py +360 -0
  146. package/dist/core/resolve/property.d.mts +0 -51
  147. package/dist/core/resolve/property.mjs +0 -53
@@ -0,0 +1,360 @@
1
+ #!/usr/bin/env python3
2
+ # /// script
3
+ # requires-python = ">=3.13"
4
+ # dependencies = []
5
+ # ///
6
+ """
7
+ Generate DreamCLI starter files from bundled templates.
8
+ """
9
+
10
+ import argparse
11
+ import json
12
+ import re
13
+ import sys
14
+ from pathlib import Path
15
+
16
+ MANIFEST_FILENAMES = (
17
+ "package.json",
18
+ "package.json5",
19
+ "package.yaml",
20
+ "package.yml",
21
+ )
22
+
23
+ LOCKFILE_TO_MANAGER = (
24
+ ("bun.lock", "bun"),
25
+ ("bun.lockb", "bun"),
26
+ ("pnpm-lock.yaml", "pnpm"),
27
+ ("pnpm-lock.yml", "pnpm"),
28
+ ("pnpm-workspace.yaml", "pnpm"),
29
+ ("pnpm-workspace.yml", "pnpm"),
30
+ ("yarn.lock", "yarn"),
31
+ ("package-lock.json", "npm"),
32
+ ("npm-shrinkwrap.json", "npm"),
33
+ )
34
+
35
+
36
+ def normalize_name(raw: str) -> str:
37
+ name = raw.strip().lower()
38
+ name = re.sub(r"[^a-z0-9]+", "-", name)
39
+ name = name.strip("-")
40
+ name = re.sub(r"-{2,}", "-", name)
41
+ return name
42
+
43
+
44
+ def read_template(path: Path) -> str:
45
+ if not path.exists():
46
+ raise FileNotFoundError(f"Template not found: {path}")
47
+ return path.read_text()
48
+
49
+
50
+ def render_template(template: str, replacements: dict[str, str]) -> str:
51
+ rendered = template
52
+ for key, value in replacements.items():
53
+ rendered = rendered.replace(key, value)
54
+ if not rendered.endswith("\n"):
55
+ rendered += "\n"
56
+ return rendered
57
+
58
+
59
+ def write_file(path: Path, content: str, force: bool) -> None:
60
+ if path.exists() and not force:
61
+ raise FileExistsError(f"Refusing to overwrite existing file: {path}. Use --force to overwrite.")
62
+ path.parent.mkdir(parents=True, exist_ok=True)
63
+ path.write_text(content)
64
+
65
+
66
+ def iter_ancestors(path: Path):
67
+ current = path.resolve()
68
+ while True:
69
+ yield current
70
+ if current.parent == current:
71
+ break
72
+ current = current.parent
73
+
74
+
75
+ def lockfiles_for_directory(directory: Path) -> list[Path]:
76
+ lockfiles: list[Path] = []
77
+ for lockfile, _ in LOCKFILE_TO_MANAGER:
78
+ candidate = directory / lockfile
79
+ if candidate.exists():
80
+ lockfiles.append(candidate)
81
+
82
+ pnpm_globs = (
83
+ "pnpm-*.yaml",
84
+ "pnpm-*.yml",
85
+ )
86
+ for pattern in pnpm_globs:
87
+ for candidate in sorted(directory.glob(pattern)):
88
+ if candidate not in lockfiles:
89
+ lockfiles.append(candidate)
90
+ return lockfiles
91
+
92
+
93
+ def manifests_for_directory(directory: Path) -> list[Path]:
94
+ manifests: list[Path] = []
95
+ for filename in MANIFEST_FILENAMES:
96
+ candidate = directory / filename
97
+ if candidate.exists():
98
+ manifests.append(candidate)
99
+ return manifests
100
+
101
+
102
+ def package_manager_from_lockfiles(directory: Path) -> str | None:
103
+ for candidate in lockfiles_for_directory(directory):
104
+ if candidate.name.startswith("pnpm-") and candidate.suffix in {".yaml", ".yml"}:
105
+ return "pnpm"
106
+ for lockfile, manager in LOCKFILE_TO_MANAGER:
107
+ if candidate.name == lockfile:
108
+ return manager
109
+ return None
110
+
111
+
112
+ def package_manager_from_manifest(manifest: dict) -> str | None:
113
+ raw_value = manifest.get("packageManager")
114
+ if not isinstance(raw_value, str) or not raw_value.strip():
115
+ return None
116
+ manager = raw_value.split("@", 1)[0].strip().lower()
117
+ if manager in {"bun", "pnpm", "npm", "yarn"}:
118
+ return manager
119
+ return None
120
+
121
+
122
+ def read_text_file(path: Path) -> str | None:
123
+ try:
124
+ return path.read_text(errors="ignore")
125
+ except OSError:
126
+ return None
127
+
128
+
129
+ def package_manager_from_text(raw_text: str) -> str | None:
130
+ match = re.search(
131
+ r'(?mi)^[ \t]*["\']?packageManager["\']?[ \t]*:[ \t]*["\']?([^"\',\n\r#]+)',
132
+ raw_text,
133
+ )
134
+ if match is None:
135
+ return None
136
+
137
+ value = match.group(1).strip()
138
+ manager = value.split("@", 1)[0].strip().lower()
139
+ if manager in {"bun", "pnpm", "npm", "yarn"}:
140
+ return manager
141
+ return None
142
+
143
+
144
+ def manifest_text_uses_vitest(raw_text: str) -> bool:
145
+ return re.search(r"\bvitest\b", raw_text) is not None
146
+
147
+
148
+ def detect_package_manager_with_root(start: Path) -> tuple[str | None, Path | None]:
149
+ for directory in iter_ancestors(start):
150
+ for manifest_path in manifests_for_directory(directory):
151
+ if manifest_path.name == "package.json":
152
+ manifest = read_package_json(manifest_path)
153
+ if manifest is not None:
154
+ from_manifest = package_manager_from_manifest(manifest)
155
+ if from_manifest is not None:
156
+ return (from_manifest, directory)
157
+
158
+ raw_text = read_text_file(manifest_path)
159
+ if raw_text is not None:
160
+ from_text = package_manager_from_text(raw_text)
161
+ if from_text is not None:
162
+ return (from_text, directory)
163
+
164
+ from_lockfile = package_manager_from_lockfiles(directory)
165
+ if from_lockfile is not None:
166
+ return (from_lockfile, directory)
167
+ return (None, None)
168
+
169
+
170
+ def read_package_json(path: Path) -> dict | None:
171
+ try:
172
+ raw = path.read_text()
173
+ parsed = json.loads(raw)
174
+ except (OSError, json.JSONDecodeError):
175
+ return None
176
+ if isinstance(parsed, dict):
177
+ return parsed
178
+ return None
179
+
180
+
181
+ def manifest_uses_vitest(manifest: dict) -> bool:
182
+ dependency_fields = (
183
+ "dependencies",
184
+ "devDependencies",
185
+ "peerDependencies",
186
+ "optionalDependencies",
187
+ )
188
+ for field in dependency_fields:
189
+ deps = manifest.get(field)
190
+ if isinstance(deps, dict) and "vitest" in deps:
191
+ return True
192
+
193
+ scripts = manifest.get("scripts")
194
+ if isinstance(scripts, dict):
195
+ for script in scripts.values():
196
+ if isinstance(script, str) and "vitest" in script:
197
+ return True
198
+
199
+ return False
200
+
201
+
202
+ def find_project_root(start: Path) -> Path | None:
203
+ for directory in iter_ancestors(start):
204
+ if package_manager_from_lockfiles(directory) is not None:
205
+ return directory
206
+ if manifests_for_directory(directory):
207
+ return directory
208
+ return None
209
+
210
+
211
+ def iter_to_ancestor(start: Path, ancestor: Path):
212
+ current = start.resolve()
213
+ target = ancestor.resolve()
214
+ while True:
215
+ yield current
216
+ if current == target:
217
+ break
218
+ if current.parent == current:
219
+ break
220
+ current = current.parent
221
+
222
+
223
+ def detect_vitest_usage_in_project(project_root: Path, manager_root: Path | None) -> bool:
224
+ stop_at = manager_root.resolve() if manager_root is not None else project_root.resolve()
225
+ for directory in iter_to_ancestor(project_root, stop_at):
226
+ for manifest_path in manifests_for_directory(directory):
227
+ if manifest_path.name == "package.json":
228
+ manifest = read_package_json(manifest_path)
229
+ if manifest and manifest_uses_vitest(manifest):
230
+ return True
231
+
232
+ raw_text = read_text_file(manifest_path)
233
+ if raw_text is not None and manifest_text_uses_vitest(raw_text):
234
+ return True
235
+
236
+ if (stop_at / "node_modules" / "vitest" / "package.json").exists():
237
+ return True
238
+
239
+ for lockfile in lockfiles_for_directory(stop_at):
240
+ try:
241
+ if "vitest" in lockfile.read_text(errors="ignore"):
242
+ return True
243
+ except OSError:
244
+ continue
245
+
246
+ return False
247
+
248
+
249
+ def choose_test_template(mode: str, package_manager: str | None, uses_vitest: bool) -> tuple[str, str]:
250
+ if package_manager == "bun" and not uses_vitest:
251
+ return (f"{mode}-command.bun-test.ts.tpl", "bun:test")
252
+ return (f"{mode}-command.test.ts.tpl", "vitest")
253
+
254
+
255
+ def choose_test_command(package_manager: str | None, test_framework: str, test_path: str) -> str:
256
+ if test_framework == "bun:test":
257
+ return f"bun test {test_path}"
258
+ if package_manager == "bun":
259
+ return f"bun test {test_path}"
260
+ if package_manager == "pnpm":
261
+ return f"pnpm vitest run {test_path}"
262
+ if package_manager == "yarn":
263
+ return f"yarn vitest run {test_path}"
264
+ return f"npx vitest run {test_path}"
265
+
266
+
267
+ def format_run_path(path: Path, cwd: Path) -> str:
268
+ try:
269
+ relative = path.relative_to(cwd).as_posix()
270
+ if not relative.startswith((".", "..")):
271
+ return f"./{relative}"
272
+ return relative
273
+ except ValueError:
274
+ return path.as_posix()
275
+
276
+
277
+ def main() -> int:
278
+ parser = argparse.ArgumentParser(description="Scaffold Bun-first DreamCLI starter files from templates.")
279
+ parser.add_argument("--name", required=True, help="CLI name (e.g. mycli)")
280
+ parser.add_argument(
281
+ "--mode",
282
+ choices=["single", "multi"],
283
+ default="single",
284
+ help="Starter shape. single=one root command, multi=nested command groups.",
285
+ )
286
+ parser.add_argument("--out", required=True, help="Output directory")
287
+ parser.add_argument(
288
+ "--no-test",
289
+ action="store_true",
290
+ help="Skip generating the starter test file.",
291
+ )
292
+ parser.add_argument(
293
+ "--force",
294
+ action="store_true",
295
+ help="Overwrite existing files if present.",
296
+ )
297
+ args = parser.parse_args()
298
+
299
+ cli_name = normalize_name(args.name)
300
+ if not cli_name:
301
+ print("[ERROR] --name must include at least one letter or digit.")
302
+ return 1
303
+
304
+ output_dir = Path(args.out).resolve()
305
+ output_dir.mkdir(parents=True, exist_ok=True)
306
+
307
+ skill_root = Path(__file__).resolve().parent.parent
308
+ templates_dir = skill_root / "assets" / "templates"
309
+
310
+ entry_template_path = templates_dir / f"{args.mode}-command.ts.tpl"
311
+ test_template_path = templates_dir / f"{args.mode}-command.test.ts.tpl"
312
+
313
+ entry_filename = f"{cli_name}.ts"
314
+ entry_path = output_dir / entry_filename
315
+ test_path = output_dir / f"{cli_name}.test.ts"
316
+ include_test = not args.no_test
317
+ project_root = find_project_root(output_dir) or find_project_root(Path.cwd()) or output_dir
318
+ package_manager, manager_root = detect_package_manager_with_root(project_root)
319
+ uses_vitest = detect_vitest_usage_in_project(project_root, manager_root)
320
+ test_framework = "none"
321
+
322
+ replacements = {
323
+ "__CLI_NAME__": cli_name,
324
+ "__ENTRY_FILE__": f"./{entry_filename}",
325
+ }
326
+
327
+ try:
328
+ entry_template = read_template(entry_template_path)
329
+ entry_content = render_template(entry_template, replacements)
330
+ write_file(entry_path, entry_content, args.force)
331
+ print(f"[OK] Wrote {entry_path}")
332
+
333
+ if include_test:
334
+ test_template_name, test_framework = choose_test_template(args.mode, package_manager, uses_vitest)
335
+ test_template_path = templates_dir / test_template_name
336
+ test_template = read_template(test_template_path)
337
+ test_content = render_template(test_template, replacements)
338
+ write_file(test_path, test_content, args.force)
339
+ print(f"[OK] Wrote {test_path}")
340
+ except (FileExistsError, FileNotFoundError) as error:
341
+ print(f"[ERROR] {error}")
342
+ return 1
343
+
344
+ print("\nNext steps:")
345
+ run_path = format_run_path(entry_path, Path.cwd())
346
+ test_run_path = format_run_path(test_path, Path.cwd())
347
+ print(f"1. Run: bun {run_path} --help")
348
+ if include_test:
349
+ test_command = choose_test_command(package_manager, test_framework, test_run_path)
350
+ print(f"2. Test: {test_command}")
351
+ if test_framework == "bun:test":
352
+ print(" Detected Bun without vitest; generated a bun:test starter test.")
353
+ else:
354
+ print("2. Re-run without --no-test to include a starter test file")
355
+ print("3. Adapt commands, flags, and prompts to the user request")
356
+ return 0
357
+
358
+
359
+ if __name__ == "__main__":
360
+ sys.exit(main())
@@ -1,51 +0,0 @@
1
- import { NumberConstraints } from "../schema/number-constraints.mjs";
2
- import { ArgSchema } from "../schema/arg.mjs";
3
- import { StringConstraints } from "../schema/string-constraints.mjs";
4
- import { FlagSchema } from "../schema/flag.mjs";
5
- import "../schema/index.mjs";
6
- //#region src/core/resolve/property.d.ts
7
- /** Flag/arg kinds that share a common coercion path. */
8
- declare const SHARED_PROPERTY_MODEL_KINDS: readonly ["string", "number", "enum", "custom"];
9
- /** Union of kind discriminants that participate in shared coercion. */
10
- type SharedPropertyKind = (typeof SHARED_PROPERTY_MODEL_KINDS)[number];
11
- /** Minimal coercion-relevant slice of a flag or arg schema, discriminated by kind. */
12
- type SharedPropertySchema = {
13
- readonly kind: 'string';
14
- readonly stringConstraints: StringConstraints | undefined;
15
- } | {
16
- readonly kind: 'number';
17
- readonly numberConstraints: NumberConstraints | undefined;
18
- } | {
19
- readonly kind: 'enum';
20
- readonly enumValues: readonly string[] | undefined;
21
- } | {
22
- readonly kind: 'custom';
23
- readonly parseFn?: (raw: unknown) => unknown;
24
- };
25
- /** Contract asserting which concerns are shared vs. kept separate between flags and args. */
26
- interface SharedPropertyModelContract {
27
- /** Only coercion logic is shared; resolution orchestration is not. */
28
- readonly scope: 'coercion';
29
- /** The kind discriminants that participate in shared coercion. */
30
- readonly sharedKinds: readonly SharedPropertyKind[];
31
- /** Flag and arg precedence chains remain independent. */
32
- readonly keepsFlagAndArgPrecedenceSeparate: true;
33
- /** Fallback-on-coercion-error rules remain independent. */
34
- readonly keepsFallbackRulesSeparate: true;
35
- /** Required-value validation remains independent. */
36
- readonly keepsRequiredValueRulesSeparate: true;
37
- }
38
- /** Runtime-accessible contract instance for property model tests. */
39
- declare const sharedPropertyModelContract: {
40
- scope: "coercion";
41
- sharedKinds: readonly ["string", "number", "enum", "custom"];
42
- keepsFlagAndArgPrecedenceSeparate: true;
43
- keepsFallbackRulesSeparate: true;
44
- keepsRequiredValueRulesSeparate: true;
45
- };
46
- /** Extract the shared coercion slice from a flag schema, or `undefined` for boolean/array (handled separately). */
47
- declare function toSharedFlagPropertySchema(schema: FlagSchema): SharedPropertySchema | undefined;
48
- /** Extract the shared coercion slice from an arg schema (all arg kinds are shared). */
49
- declare function toSharedArgPropertySchema(schema: ArgSchema): SharedPropertySchema;
50
- //#endregion
51
- export { SHARED_PROPERTY_MODEL_KINDS, type SharedPropertyKind, type SharedPropertyModelContract, type SharedPropertySchema, sharedPropertyModelContract, toSharedArgPropertySchema, toSharedFlagPropertySchema };
@@ -1,53 +0,0 @@
1
- //#region src/core/resolve/property.ts
2
- /** Extract the shared coercion slice from a flag schema, or `undefined` for boolean/array (handled separately). */
3
- function toSharedFlagPropertySchema(schema) {
4
- switch (schema.kind) {
5
- case "string": return {
6
- kind: "string",
7
- stringConstraints: schema.stringConstraints
8
- };
9
- case "number": return {
10
- kind: "number",
11
- numberConstraints: schema.numberConstraints
12
- };
13
- case "enum": return {
14
- kind: "enum",
15
- enumValues: schema.enumValues
16
- };
17
- case "custom": return schema.parseFn === void 0 ? { kind: "custom" } : {
18
- kind: "custom",
19
- parseFn: schema.parseFn
20
- };
21
- case "boolean":
22
- case "array":
23
- case "count":
24
- case "keyValue": return;
25
- }
26
- }
27
- /** Extract the shared coercion slice from an arg schema (all arg kinds are shared). */
28
- function toSharedArgPropertySchema(schema) {
29
- switch (schema.kind) {
30
- case "string": return {
31
- kind: "string",
32
- stringConstraints: void 0
33
- };
34
- case "number": return {
35
- kind: "number",
36
- numberConstraints: schema.numberConstraints
37
- };
38
- case "enum": return {
39
- kind: "enum",
40
- enumValues: schema.enumValues
41
- };
42
- case "custom": {
43
- if (schema.parseFn === void 0) return { kind: "custom" };
44
- const parseFn = schema.parseFn;
45
- return {
46
- kind: "custom",
47
- parseFn: (raw) => parseFn(typeof raw === "string" ? raw : String(raw))
48
- };
49
- }
50
- }
51
- }
52
- //#endregion
53
- export { toSharedArgPropertySchema, toSharedFlagPropertySchema };