@optique/core 1.0.0-dev.1598 → 1.0.0-dev.1608

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.
@@ -2,6 +2,7 @@ const require_annotations = require('./annotations.cjs');
2
2
  const require_message = require('./message.cjs');
3
3
  const require_dependency = require('./dependency.cjs');
4
4
  const require_mode_dispatch = require('./mode-dispatch.cjs');
5
+ const require_dependency_metadata = require('./dependency-metadata.cjs');
5
6
 
6
7
  //#region src/modifiers.ts
7
8
  /**
@@ -186,6 +187,10 @@ function optional(parser) {
186
187
  enumerable: false
187
188
  });
188
189
  }
190
+ if (parser.dependencyMetadata != null) {
191
+ const composed = require_dependency_metadata.composeDependencyMetadata(parser.dependencyMetadata, "optional");
192
+ if (composed != null) optionalParser.dependencyMetadata = composed;
193
+ }
189
194
  return optionalParser;
190
195
  }
191
196
  /**
@@ -434,6 +439,28 @@ function withDefault(parser, defaultValue, options) {
434
439
  enumerable: false
435
440
  });
436
441
  }
442
+ if (parser.dependencyMetadata != null) {
443
+ const composed = require_dependency_metadata.composeDependencyMetadata(parser.dependencyMetadata, "withDefault", { defaultValue: () => {
444
+ let v;
445
+ try {
446
+ v = typeof defaultValue === "function" ? defaultValue() : defaultValue;
447
+ } catch (e) {
448
+ const error = e instanceof WithDefaultError ? e.errorMessage : require_message.message`${e instanceof Error ? e.message : String(e)}`;
449
+ return {
450
+ success: false,
451
+ error
452
+ };
453
+ }
454
+ if (typeof parser.normalizeValue === "function") try {
455
+ v = parser.normalizeValue(v);
456
+ } catch {}
457
+ return {
458
+ success: true,
459
+ value: v
460
+ };
461
+ } });
462
+ if (composed != null) withDefaultParser.dependencyMetadata = composed;
463
+ }
437
464
  return withDefaultParser;
438
465
  }
439
466
  /**
@@ -559,6 +586,43 @@ function map(parser, transform) {
559
586
  configurable: true,
560
587
  enumerable: false
561
588
  });
589
+ if (parser.dependencyMetadata != null) {
590
+ let composed = require_dependency_metadata.composeDependencyMetadata(parser.dependencyMetadata, "map");
591
+ if (composed?.derived != null) {
592
+ const innerReplay = composed.derived.replayParse;
593
+ const applyMappedReplay = (r) => {
594
+ if (!r.success) return r;
595
+ if (r.deferred) try {
596
+ return {
597
+ success: true,
598
+ value: transform(r.value),
599
+ deferred: true
600
+ };
601
+ } catch {
602
+ return {
603
+ success: true,
604
+ value: void 0,
605
+ deferred: true
606
+ };
607
+ }
608
+ return {
609
+ success: true,
610
+ value: transform(r.value)
611
+ };
612
+ };
613
+ composed = {
614
+ ...composed,
615
+ derived: {
616
+ ...composed.derived,
617
+ replayParse: (rawInput, depValues) => {
618
+ const result = innerReplay(rawInput, depValues);
619
+ return result instanceof Promise ? result.then(applyMappedReplay) : applyMappedReplay(result);
620
+ }
621
+ }
622
+ };
623
+ }
624
+ if (composed != null) mappedParser.dependencyMetadata = composed;
625
+ }
562
626
  return mappedParser;
563
627
  }
564
628
  /**
package/dist/modifiers.js CHANGED
@@ -2,6 +2,7 @@ import { annotateFreshArray, getAnnotations, inheritAnnotations, isInjectedAnnot
2
2
  import { formatMessage, message, text } from "./message.js";
3
3
  import { createDependencySourceState, dependencyId, isDependencySourceState, isPendingDependencySourceState, isWrappedDependencySource, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker } from "./dependency.js";
4
4
  import { dispatchByMode, dispatchIterableByMode, mapModeValue } from "./mode-dispatch.js";
5
+ import { composeDependencyMetadata } from "./dependency-metadata.js";
5
6
 
6
7
  //#region src/modifiers.ts
7
8
  /**
@@ -186,6 +187,10 @@ function optional(parser) {
186
187
  enumerable: false
187
188
  });
188
189
  }
190
+ if (parser.dependencyMetadata != null) {
191
+ const composed = composeDependencyMetadata(parser.dependencyMetadata, "optional");
192
+ if (composed != null) optionalParser.dependencyMetadata = composed;
193
+ }
189
194
  return optionalParser;
190
195
  }
191
196
  /**
@@ -434,6 +439,28 @@ function withDefault(parser, defaultValue, options) {
434
439
  enumerable: false
435
440
  });
436
441
  }
442
+ if (parser.dependencyMetadata != null) {
443
+ const composed = composeDependencyMetadata(parser.dependencyMetadata, "withDefault", { defaultValue: () => {
444
+ let v;
445
+ try {
446
+ v = typeof defaultValue === "function" ? defaultValue() : defaultValue;
447
+ } catch (e) {
448
+ const error = e instanceof WithDefaultError ? e.errorMessage : message`${e instanceof Error ? e.message : String(e)}`;
449
+ return {
450
+ success: false,
451
+ error
452
+ };
453
+ }
454
+ if (typeof parser.normalizeValue === "function") try {
455
+ v = parser.normalizeValue(v);
456
+ } catch {}
457
+ return {
458
+ success: true,
459
+ value: v
460
+ };
461
+ } });
462
+ if (composed != null) withDefaultParser.dependencyMetadata = composed;
463
+ }
437
464
  return withDefaultParser;
438
465
  }
439
466
  /**
@@ -559,6 +586,43 @@ function map(parser, transform) {
559
586
  configurable: true,
560
587
  enumerable: false
561
588
  });
589
+ if (parser.dependencyMetadata != null) {
590
+ let composed = composeDependencyMetadata(parser.dependencyMetadata, "map");
591
+ if (composed?.derived != null) {
592
+ const innerReplay = composed.derived.replayParse;
593
+ const applyMappedReplay = (r) => {
594
+ if (!r.success) return r;
595
+ if (r.deferred) try {
596
+ return {
597
+ success: true,
598
+ value: transform(r.value),
599
+ deferred: true
600
+ };
601
+ } catch {
602
+ return {
603
+ success: true,
604
+ value: void 0,
605
+ deferred: true
606
+ };
607
+ }
608
+ return {
609
+ success: true,
610
+ value: transform(r.value)
611
+ };
612
+ };
613
+ composed = {
614
+ ...composed,
615
+ derived: {
616
+ ...composed.derived,
617
+ replayParse: (rawInput, depValues) => {
618
+ const result = innerReplay(rawInput, depValues);
619
+ return result instanceof Promise ? result.then(applyMappedReplay) : applyMappedReplay(result);
620
+ }
621
+ }
622
+ };
623
+ }
624
+ if (composed != null) mappedParser.dependencyMetadata = composed;
625
+ }
562
626
  return mappedParser;
563
627
  }
564
628
  /**
package/dist/parser.d.cts CHANGED
@@ -4,6 +4,8 @@ import { Usage } from "./usage.cjs";
4
4
  import { DocFragments, DocPage } from "./doc.cjs";
5
5
  import { DependencyRegistryLike } from "./registry-types.cjs";
6
6
  import { DeferredMap, ValueParserResult } from "./valueparser.cjs";
7
+ import { ParserDependencyMetadata } from "./dependency-metadata.cjs";
8
+ import { DependencyRuntimeContext } from "./dependency-runtime.cjs";
7
9
  import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, GroupOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.cjs";
8
10
  import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.cjs";
9
11
  import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, option, passThrough } from "./primitives.cjs";
@@ -251,6 +253,14 @@ interface Parser<M extends Mode = "sync", TValue = unknown, TState = unknown> {
251
253
  * @since 1.0.0
252
254
  */
253
255
  normalizeValue?(value: TValue): TValue;
256
+ /**
257
+ * Internal dependency metadata describing this parser's dependency
258
+ * capabilities. Used by the dependency runtime to resolve dependencies
259
+ * without relying on state-shape protocols.
260
+ * @internal
261
+ * @since 1.0.0
262
+ */
263
+ readonly dependencyMetadata?: ParserDependencyMetadata;
254
264
  }
255
265
  /**
256
266
  * Parser-local frame data containing the input buffer and parser state.
@@ -308,6 +318,13 @@ interface ExecutionContext {
308
318
  * @since 0.10.0
309
319
  */
310
320
  readonly dependencyRegistry?: DependencyRegistryLike;
321
+ /**
322
+ * The dependency runtime context for dependency resolution.
323
+ * Coexists with `dependencyRegistry` during the transition period.
324
+ * @internal
325
+ * @since 1.0.0
326
+ */
327
+ readonly dependencyRuntime?: DependencyRuntimeContext;
311
328
  }
312
329
  /**
313
330
  * The context of the parser, which includes the input buffer and the state.
package/dist/parser.d.ts CHANGED
@@ -4,6 +4,8 @@ import { Usage } from "./usage.js";
4
4
  import { DocFragments, DocPage } from "./doc.js";
5
5
  import { DependencyRegistryLike } from "./registry-types.js";
6
6
  import { DeferredMap, ValueParserResult } from "./valueparser.js";
7
+ import { ParserDependencyMetadata } from "./dependency-metadata.js";
8
+ import { DependencyRuntimeContext } from "./dependency-runtime.js";
7
9
  import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, GroupOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
8
10
  import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
9
11
  import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, option, passThrough } from "./primitives.js";
@@ -251,6 +253,14 @@ interface Parser<M extends Mode = "sync", TValue = unknown, TState = unknown> {
251
253
  * @since 1.0.0
252
254
  */
253
255
  normalizeValue?(value: TValue): TValue;
256
+ /**
257
+ * Internal dependency metadata describing this parser's dependency
258
+ * capabilities. Used by the dependency runtime to resolve dependencies
259
+ * without relying on state-shape protocols.
260
+ * @internal
261
+ * @since 1.0.0
262
+ */
263
+ readonly dependencyMetadata?: ParserDependencyMetadata;
254
264
  }
255
265
  /**
256
266
  * Parser-local frame data containing the input buffer and parser state.
@@ -308,6 +318,13 @@ interface ExecutionContext {
308
318
  * @since 0.10.0
309
319
  */
310
320
  readonly dependencyRegistry?: DependencyRegistryLike;
321
+ /**
322
+ * The dependency runtime context for dependency resolution.
323
+ * Coexists with `dependencyRegistry` during the transition period.
324
+ * @internal
325
+ * @since 1.0.0
326
+ */
327
+ readonly dependencyRuntime?: DependencyRuntimeContext;
311
328
  }
312
329
  /**
313
330
  * The context of the parser, which includes the input buffer and the state.
@@ -6,6 +6,7 @@ const require_validate = require('./validate.cjs');
6
6
  const require_usage = require('./usage.cjs');
7
7
  const require_suggestion = require('./suggestion.cjs');
8
8
  const require_usage_internals = require('./usage-internals.cjs');
9
+ const require_dependency_metadata = require('./dependency-metadata.cjs');
9
10
  const require_valueparser = require('./valueparser.cjs');
10
11
 
11
12
  //#region src/primitives.ts
@@ -598,6 +599,10 @@ function option(...args) {
598
599
  enumerable: false,
599
600
  writable: false
600
601
  });
602
+ if (valueParser != null) {
603
+ const depMeta = require_dependency_metadata.extractDependencyMetadata(valueParser);
604
+ if (depMeta != null) result.dependencyMetadata = depMeta;
605
+ }
601
606
  return result;
602
607
  }
603
608
  /**
@@ -963,6 +968,8 @@ function argument(valueParser, options = {}) {
963
968
  configurable: true,
964
969
  enumerable: false
965
970
  });
971
+ const depMeta = require_dependency_metadata.extractDependencyMetadata(valueParser);
972
+ if (depMeta != null) result.dependencyMetadata = depMeta;
966
973
  return result;
967
974
  }
968
975
  function* suggestCommandSync(context, prefix, name, parser, options) {
@@ -6,6 +6,7 @@ import { validateCommandNames, validateOptionNames } from "./validate.js";
6
6
  import { extractOptionNames, isDocHidden, isSuggestionHidden } from "./usage.js";
7
7
  import { DEFAULT_FIND_SIMILAR_OPTIONS, createErrorWithSuggestions, createSuggestionMessage, findSimilar } from "./suggestion.js";
8
8
  import { extractLeadingCommandNames } from "./usage-internals.js";
9
+ import { extractDependencyMetadata } from "./dependency-metadata.js";
9
10
  import { isValueParser } from "./valueparser.js";
10
11
 
11
12
  //#region src/primitives.ts
@@ -598,6 +599,10 @@ function option(...args) {
598
599
  enumerable: false,
599
600
  writable: false
600
601
  });
602
+ if (valueParser != null) {
603
+ const depMeta = extractDependencyMetadata(valueParser);
604
+ if (depMeta != null) result.dependencyMetadata = depMeta;
605
+ }
601
606
  return result;
602
607
  }
603
608
  /**
@@ -963,6 +968,8 @@ function argument(valueParser, options = {}) {
963
968
  configurable: true,
964
969
  enumerable: false
965
970
  });
971
+ const depMeta = extractDependencyMetadata(valueParser);
972
+ if (depMeta != null) result.dependencyMetadata = depMeta;
966
973
  return result;
967
974
  }
968
975
  function* suggestCommandSync(context, prefix, name, parser, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1598+6650da3a",
3
+ "version": "1.0.0-dev.1608+66e67b9f",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",