@optique/core 0.10.0-dev.294 → 0.10.0-dev.296

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/dist/index.d.ts CHANGED
@@ -5,9 +5,9 @@ import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, Doc
5
5
  import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.js";
6
6
  import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
7
7
  import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, optional, withDefault } from "./modifiers.js";
8
- import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, ResolvedDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser } from "./dependency.js";
8
+ import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, PendingDependencySourceState, PendingDependencySourceStateMarker, ResolvedDependency, TransformsDependencyValueMarker, WrappedDependencySourceMarker, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, transformsDependencyValue } from "./dependency.js";
9
9
  import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, flag, option, passThrough } from "./primitives.js";
10
10
  import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, ModeValue, Parser, ParserContext, ParserResult, Result, Suggestion, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
11
11
  import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.js";
12
12
  import { RunError, RunOptions, RunParserError, run, runParser, runParserAsync, runParserSync } from "./facade.js";
13
- export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, ParseWithDependency, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, ResolvedDependency, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
13
+ export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, ParseWithDependency, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PendingDependencySourceStateMarker, ResolvedDependency, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TransformsDependencyValueMarker, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, WrappedDependencySourceMarker, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, transformsDependencyValue, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
2
2
  import { bash, fish, nu, pwsh, zsh } from "./completion.js";
3
- import { DeferredParseMarker, DependencyId, DependencyIds, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, ParseWithDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser } from "./dependency.js";
3
+ import { DeferredParseMarker, DependencyId, DependencyIds, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, ParseWithDependency, PendingDependencySourceStateMarker, TransformsDependencyValueMarker, WrappedDependencySourceMarker, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, transformsDependencyValue } from "./dependency.js";
4
4
  import { extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.js";
5
5
  import { DuplicateOptionError, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
6
6
  import { formatDocPage } from "./doc.js";
@@ -11,4 +11,4 @@ import { argument, command, constant, flag, option, passThrough } from "./primit
11
11
  import { getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
12
12
  import { RunError, RunParserError, run, runParser, runParserAsync, runParserSync } from "./facade.js";
13
13
 
14
- export { DeferredParseMarker, DependencyId, DependencyIds, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, DuplicateOptionError, ParseWithDependency, RunError, RunParserError, WithDefaultError, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
14
+ export { DeferredParseMarker, DependencyId, DependencyIds, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, DuplicateOptionError, ParseWithDependency, PendingDependencySourceStateMarker, RunError, RunParserError, TransformsDependencyValueMarker, WithDefaultError, WrappedDependencySourceMarker, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, transformsDependencyValue, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
@@ -1,4 +1,5 @@
1
1
  const require_message = require('./message.cjs');
2
+ const require_dependency = require('./dependency.cjs');
2
3
 
3
4
  //#region src/modifiers.ts
4
5
  /**
@@ -89,6 +90,11 @@ function optional(parser) {
89
90
  }, prefix);
90
91
  for await (const s of suggestions) yield s;
91
92
  }
93
+ const innerHasWrappedDependency = require_dependency.isWrappedDependencySource(parser);
94
+ const innerHasDirectDependency = require_dependency.isPendingDependencySourceState(syncParser.initialState);
95
+ const wrappedDependencyMarker = innerHasWrappedDependency ? { [require_dependency.WrappedDependencySourceMarker]: parser[require_dependency.WrappedDependencySourceMarker] } : innerHasDirectDependency ? { [require_dependency.WrappedDependencySourceMarker]: syncParser.initialState } : {};
96
+ const hasWrappedDependencySource = require_dependency.WrappedDependencySourceMarker in wrappedDependencyMarker;
97
+ const wrappedPendingState = hasWrappedDependencySource ? wrappedDependencyMarker[require_dependency.WrappedDependencySourceMarker] : void 0;
92
98
  return {
93
99
  $mode: parser.$mode,
94
100
  $valueType: [],
@@ -99,15 +105,32 @@ function optional(parser) {
99
105
  terms: parser.usage
100
106
  }],
101
107
  initialState: void 0,
108
+ ...wrappedDependencyMarker,
102
109
  parse(context) {
103
110
  if (isAsync) return parseOptionalStyleAsync(context, parser);
104
111
  return parseOptionalStyleSync(context, syncParser);
105
112
  },
106
113
  complete(state) {
107
- if (typeof state === "undefined") return {
108
- success: true,
109
- value: void 0
110
- };
114
+ if (typeof state === "undefined") {
115
+ if (innerHasWrappedDependency && wrappedPendingState) {
116
+ if (!isAsync) return syncParser.complete([wrappedPendingState]);
117
+ return parser.complete([wrappedPendingState]);
118
+ }
119
+ return {
120
+ success: true,
121
+ value: void 0
122
+ };
123
+ }
124
+ if (Array.isArray(state) && state.length === 1 && require_dependency.isPendingDependencySourceState(state[0])) {
125
+ if (innerHasWrappedDependency) {
126
+ if (!isAsync) return syncParser.complete(state);
127
+ return parser.complete(state);
128
+ }
129
+ return {
130
+ success: true,
131
+ value: void 0
132
+ };
133
+ }
111
134
  if (!isAsync) return syncParser.complete(state[0]);
112
135
  return parser.complete(state[0]);
113
136
  },
@@ -176,6 +199,8 @@ function withDefault(parser, defaultValue, options) {
176
199
  }, prefix);
177
200
  for await (const s of suggestions) yield s;
178
201
  }
202
+ const innerInitialState = syncParser.initialState;
203
+ const wrappedDependencyMarker = require_dependency.isPendingDependencySourceState(innerInitialState) ? { [require_dependency.WrappedDependencySourceMarker]: innerInitialState } : require_dependency.isWrappedDependencySource(parser) ? { [require_dependency.WrappedDependencySourceMarker]: parser[require_dependency.WrappedDependencySourceMarker] } : {};
179
204
  return {
180
205
  $mode: parser.$mode,
181
206
  $valueType: [],
@@ -186,22 +211,114 @@ function withDefault(parser, defaultValue, options) {
186
211
  terms: parser.usage
187
212
  }],
188
213
  initialState: void 0,
214
+ ...wrappedDependencyMarker,
189
215
  parse(context) {
190
216
  if (isAsync) return parseOptionalStyleAsync(context, parser);
191
217
  return parseOptionalStyleSync(context, syncParser);
192
218
  },
193
219
  complete(state) {
194
- if (typeof state === "undefined") try {
195
- const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
196
- return {
197
- success: true,
198
- value
199
- };
200
- } catch (error) {
201
- return {
202
- success: false,
203
- error: error instanceof WithDefaultError ? error.errorMessage : require_message.message`${require_message.text(String(error))}`
204
- };
220
+ if (typeof state === "undefined") {
221
+ if (require_dependency.transformsDependencyValue(parser)) {
222
+ const innerResult = !isAsync ? syncParser.complete(void 0) : parser.complete(void 0);
223
+ const handleInnerResult = (res) => {
224
+ if (require_dependency.isDependencySourceState(res)) try {
225
+ const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
226
+ return require_dependency.createDependencySourceState({
227
+ success: true,
228
+ value
229
+ }, res[require_dependency.DependencyId]);
230
+ } catch (error) {
231
+ return {
232
+ success: false,
233
+ error: error instanceof WithDefaultError ? error.errorMessage : require_message.message`${require_message.text(String(error))}`
234
+ };
235
+ }
236
+ try {
237
+ const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
238
+ return {
239
+ success: true,
240
+ value
241
+ };
242
+ } catch (error) {
243
+ return {
244
+ success: false,
245
+ error: error instanceof WithDefaultError ? error.errorMessage : require_message.message`${require_message.text(String(error))}`
246
+ };
247
+ }
248
+ };
249
+ if (innerResult instanceof Promise) return innerResult.then(handleInnerResult);
250
+ return handleInnerResult(innerResult);
251
+ }
252
+ if (require_dependency.isWrappedDependencySource(parser)) try {
253
+ const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
254
+ const pendingState = parser[require_dependency.WrappedDependencySourceMarker];
255
+ return require_dependency.createDependencySourceState({
256
+ success: true,
257
+ value
258
+ }, pendingState[require_dependency.DependencyId]);
259
+ } catch (error) {
260
+ return {
261
+ success: false,
262
+ error: error instanceof WithDefaultError ? error.errorMessage : require_message.message`${require_message.text(String(error))}`
263
+ };
264
+ }
265
+ try {
266
+ const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
267
+ return {
268
+ success: true,
269
+ value
270
+ };
271
+ } catch (error) {
272
+ return {
273
+ success: false,
274
+ error: error instanceof WithDefaultError ? error.errorMessage : require_message.message`${require_message.text(String(error))}`
275
+ };
276
+ }
277
+ }
278
+ if (require_dependency.isPendingDependencySourceState(state[0])) {
279
+ if (require_dependency.transformsDependencyValue(parser)) {
280
+ const innerResult = !isAsync ? syncParser.complete(state) : parser.complete(state);
281
+ const handleInnerResult = (res) => {
282
+ if (require_dependency.isDependencySourceState(res)) try {
283
+ const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
284
+ return require_dependency.createDependencySourceState({
285
+ success: true,
286
+ value
287
+ }, res[require_dependency.DependencyId]);
288
+ } catch (error) {
289
+ return {
290
+ success: false,
291
+ error: error instanceof WithDefaultError ? error.errorMessage : require_message.message`${require_message.text(String(error))}`
292
+ };
293
+ }
294
+ try {
295
+ const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
296
+ return {
297
+ success: true,
298
+ value
299
+ };
300
+ } catch (error) {
301
+ return {
302
+ success: false,
303
+ error: error instanceof WithDefaultError ? error.errorMessage : require_message.message`${require_message.text(String(error))}`
304
+ };
305
+ }
306
+ };
307
+ if (innerResult instanceof Promise) return innerResult.then(handleInnerResult);
308
+ return handleInnerResult(innerResult);
309
+ }
310
+ try {
311
+ const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
312
+ return require_dependency.createDependencySourceState({
313
+ success: true,
314
+ value
315
+ }, state[0][require_dependency.DependencyId]);
316
+ } catch (error) {
317
+ return {
318
+ success: false,
319
+ error: error instanceof WithDefaultError ? error.errorMessage : require_message.message`${require_message.text(String(error))}`
320
+ };
321
+ }
205
322
  }
206
323
  if (!isAsync) return syncParser.complete(state[0]);
207
324
  return parser.complete(state[0]);
@@ -284,10 +401,15 @@ function map(parser, transform) {
284
401
  };
285
402
  return res;
286
403
  };
404
+ const dependencyMarkers = require_dependency.isWrappedDependencySource(parser) ? {
405
+ [require_dependency.WrappedDependencySourceMarker]: parser[require_dependency.WrappedDependencySourceMarker],
406
+ [require_dependency.TransformsDependencyValueMarker]: true
407
+ } : {};
287
408
  return {
288
409
  ...parser,
289
410
  $valueType: [],
290
411
  complete,
412
+ ...dependencyMarkers,
291
413
  getDocFragments(state, _defaultValue) {
292
414
  return parser.getDocFragments(state, void 0);
293
415
  }
package/dist/modifiers.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { formatMessage, message, text } from "./message.js";
2
+ import { DependencyId, TransformsDependencyValueMarker, WrappedDependencySourceMarker, createDependencySourceState, isDependencySourceState, isPendingDependencySourceState, isWrappedDependencySource, transformsDependencyValue } from "./dependency.js";
2
3
 
3
4
  //#region src/modifiers.ts
4
5
  /**
@@ -89,6 +90,11 @@ function optional(parser) {
89
90
  }, prefix);
90
91
  for await (const s of suggestions) yield s;
91
92
  }
93
+ const innerHasWrappedDependency = isWrappedDependencySource(parser);
94
+ const innerHasDirectDependency = isPendingDependencySourceState(syncParser.initialState);
95
+ const wrappedDependencyMarker = innerHasWrappedDependency ? { [WrappedDependencySourceMarker]: parser[WrappedDependencySourceMarker] } : innerHasDirectDependency ? { [WrappedDependencySourceMarker]: syncParser.initialState } : {};
96
+ const hasWrappedDependencySource = WrappedDependencySourceMarker in wrappedDependencyMarker;
97
+ const wrappedPendingState = hasWrappedDependencySource ? wrappedDependencyMarker[WrappedDependencySourceMarker] : void 0;
92
98
  return {
93
99
  $mode: parser.$mode,
94
100
  $valueType: [],
@@ -99,15 +105,32 @@ function optional(parser) {
99
105
  terms: parser.usage
100
106
  }],
101
107
  initialState: void 0,
108
+ ...wrappedDependencyMarker,
102
109
  parse(context) {
103
110
  if (isAsync) return parseOptionalStyleAsync(context, parser);
104
111
  return parseOptionalStyleSync(context, syncParser);
105
112
  },
106
113
  complete(state) {
107
- if (typeof state === "undefined") return {
108
- success: true,
109
- value: void 0
110
- };
114
+ if (typeof state === "undefined") {
115
+ if (innerHasWrappedDependency && wrappedPendingState) {
116
+ if (!isAsync) return syncParser.complete([wrappedPendingState]);
117
+ return parser.complete([wrappedPendingState]);
118
+ }
119
+ return {
120
+ success: true,
121
+ value: void 0
122
+ };
123
+ }
124
+ if (Array.isArray(state) && state.length === 1 && isPendingDependencySourceState(state[0])) {
125
+ if (innerHasWrappedDependency) {
126
+ if (!isAsync) return syncParser.complete(state);
127
+ return parser.complete(state);
128
+ }
129
+ return {
130
+ success: true,
131
+ value: void 0
132
+ };
133
+ }
111
134
  if (!isAsync) return syncParser.complete(state[0]);
112
135
  return parser.complete(state[0]);
113
136
  },
@@ -176,6 +199,8 @@ function withDefault(parser, defaultValue, options) {
176
199
  }, prefix);
177
200
  for await (const s of suggestions) yield s;
178
201
  }
202
+ const innerInitialState = syncParser.initialState;
203
+ const wrappedDependencyMarker = isPendingDependencySourceState(innerInitialState) ? { [WrappedDependencySourceMarker]: innerInitialState } : isWrappedDependencySource(parser) ? { [WrappedDependencySourceMarker]: parser[WrappedDependencySourceMarker] } : {};
179
204
  return {
180
205
  $mode: parser.$mode,
181
206
  $valueType: [],
@@ -186,22 +211,114 @@ function withDefault(parser, defaultValue, options) {
186
211
  terms: parser.usage
187
212
  }],
188
213
  initialState: void 0,
214
+ ...wrappedDependencyMarker,
189
215
  parse(context) {
190
216
  if (isAsync) return parseOptionalStyleAsync(context, parser);
191
217
  return parseOptionalStyleSync(context, syncParser);
192
218
  },
193
219
  complete(state) {
194
- if (typeof state === "undefined") try {
195
- const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
196
- return {
197
- success: true,
198
- value
199
- };
200
- } catch (error) {
201
- return {
202
- success: false,
203
- error: error instanceof WithDefaultError ? error.errorMessage : message`${text(String(error))}`
204
- };
220
+ if (typeof state === "undefined") {
221
+ if (transformsDependencyValue(parser)) {
222
+ const innerResult = !isAsync ? syncParser.complete(void 0) : parser.complete(void 0);
223
+ const handleInnerResult = (res) => {
224
+ if (isDependencySourceState(res)) try {
225
+ const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
226
+ return createDependencySourceState({
227
+ success: true,
228
+ value
229
+ }, res[DependencyId]);
230
+ } catch (error) {
231
+ return {
232
+ success: false,
233
+ error: error instanceof WithDefaultError ? error.errorMessage : message`${text(String(error))}`
234
+ };
235
+ }
236
+ try {
237
+ const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
238
+ return {
239
+ success: true,
240
+ value
241
+ };
242
+ } catch (error) {
243
+ return {
244
+ success: false,
245
+ error: error instanceof WithDefaultError ? error.errorMessage : message`${text(String(error))}`
246
+ };
247
+ }
248
+ };
249
+ if (innerResult instanceof Promise) return innerResult.then(handleInnerResult);
250
+ return handleInnerResult(innerResult);
251
+ }
252
+ if (isWrappedDependencySource(parser)) try {
253
+ const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
254
+ const pendingState = parser[WrappedDependencySourceMarker];
255
+ return createDependencySourceState({
256
+ success: true,
257
+ value
258
+ }, pendingState[DependencyId]);
259
+ } catch (error) {
260
+ return {
261
+ success: false,
262
+ error: error instanceof WithDefaultError ? error.errorMessage : message`${text(String(error))}`
263
+ };
264
+ }
265
+ try {
266
+ const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
267
+ return {
268
+ success: true,
269
+ value
270
+ };
271
+ } catch (error) {
272
+ return {
273
+ success: false,
274
+ error: error instanceof WithDefaultError ? error.errorMessage : message`${text(String(error))}`
275
+ };
276
+ }
277
+ }
278
+ if (isPendingDependencySourceState(state[0])) {
279
+ if (transformsDependencyValue(parser)) {
280
+ const innerResult = !isAsync ? syncParser.complete(state) : parser.complete(state);
281
+ const handleInnerResult = (res) => {
282
+ if (isDependencySourceState(res)) try {
283
+ const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
284
+ return createDependencySourceState({
285
+ success: true,
286
+ value
287
+ }, res[DependencyId]);
288
+ } catch (error) {
289
+ return {
290
+ success: false,
291
+ error: error instanceof WithDefaultError ? error.errorMessage : message`${text(String(error))}`
292
+ };
293
+ }
294
+ try {
295
+ const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
296
+ return {
297
+ success: true,
298
+ value
299
+ };
300
+ } catch (error) {
301
+ return {
302
+ success: false,
303
+ error: error instanceof WithDefaultError ? error.errorMessage : message`${text(String(error))}`
304
+ };
305
+ }
306
+ };
307
+ if (innerResult instanceof Promise) return innerResult.then(handleInnerResult);
308
+ return handleInnerResult(innerResult);
309
+ }
310
+ try {
311
+ const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
312
+ return createDependencySourceState({
313
+ success: true,
314
+ value
315
+ }, state[0][DependencyId]);
316
+ } catch (error) {
317
+ return {
318
+ success: false,
319
+ error: error instanceof WithDefaultError ? error.errorMessage : message`${text(String(error))}`
320
+ };
321
+ }
205
322
  }
206
323
  if (!isAsync) return syncParser.complete(state[0]);
207
324
  return parser.complete(state[0]);
@@ -284,10 +401,15 @@ function map(parser, transform) {
284
401
  };
285
402
  return res;
286
403
  };
404
+ const dependencyMarkers = isWrappedDependencySource(parser) ? {
405
+ [WrappedDependencySourceMarker]: parser[WrappedDependencySourceMarker],
406
+ [TransformsDependencyValueMarker]: true
407
+ } : {};
287
408
  return {
288
409
  ...parser,
289
410
  $valueType: [],
290
411
  complete,
412
+ ...dependencyMarkers,
291
413
  getDocFragments(state, _defaultValue) {
292
414
  return parser.getDocFragments(state, void 0);
293
415
  }
@@ -203,7 +203,7 @@ function option(...args) {
203
203
  initialState: valueParser == null ? {
204
204
  success: true,
205
205
  value: false
206
- } : {
206
+ } : require_dependency.isDependencySource(valueParser) ? require_dependency.createPendingDependencySourceState(valueParser[require_dependency.DependencyId]) : {
207
207
  success: false,
208
208
  error: options.errors?.missing ? typeof options.errors.missing === "function" ? options.errors.missing(optionNames$1) : options.errors.missing : require_message.message`Missing option ${require_message.optionNames(optionNames$1)}.`
209
209
  },
@@ -357,6 +357,10 @@ function option(...args) {
357
357
  success: false,
358
358
  error: options.errors?.missing ? typeof options.errors.missing === "function" ? options.errors.missing(optionNames$1) : options.errors.missing : require_message.message`Missing option ${require_message.optionNames(optionNames$1)}.`
359
359
  };
360
+ if (require_dependency.isPendingDependencySourceState(state)) return {
361
+ success: false,
362
+ error: options.errors?.missing ? typeof options.errors.missing === "function" ? options.errors.missing(optionNames$1) : options.errors.missing : require_message.message`Missing option ${require_message.optionNames(optionNames$1)}.`
363
+ };
360
364
  if (require_dependency.isDeferredParseState(state)) {
361
365
  const preliminaryResult = state.preliminaryResult;
362
366
  if (preliminaryResult.success) return preliminaryResult;
@@ -1,16 +1,17 @@
1
1
  import { Message } from "./message.cjs";
2
2
  import { OptionName } from "./usage.cjs";
3
3
  import { ValueParser, ValueParserResult } from "./valueparser.cjs";
4
- import { DeferredParseState } from "./dependency.cjs";
4
+ import { DeferredParseState, PendingDependencySourceState } from "./dependency.cjs";
5
5
  import { Mode, Parser } from "./parser.cjs";
6
6
 
7
7
  //#region src/primitives.d.ts
8
8
  /**
9
9
  * State type for options that may use deferred parsing (DerivedValueParser).
10
- * This extends the normal ValueParserResult to also support DeferredParseState.
10
+ * This extends the normal ValueParserResult to also support DeferredParseState
11
+ * and PendingDependencySourceState.
11
12
  * @internal
12
13
  */
13
- type OptionState<T> = ValueParserResult<T> | DeferredParseState<T> | undefined;
14
+ type OptionState<T> = ValueParserResult<T> | DeferredParseState<T> | PendingDependencySourceState | undefined;
14
15
  /**
15
16
  * Creates a parser that always succeeds without consuming any input and
16
17
  * produces a constant value of the type {@link T}.
@@ -1,16 +1,17 @@
1
1
  import { Message } from "./message.js";
2
2
  import { OptionName } from "./usage.js";
3
3
  import { ValueParser, ValueParserResult } from "./valueparser.js";
4
- import { DeferredParseState } from "./dependency.js";
4
+ import { DeferredParseState, PendingDependencySourceState } from "./dependency.js";
5
5
  import { Mode, Parser } from "./parser.js";
6
6
 
7
7
  //#region src/primitives.d.ts
8
8
  /**
9
9
  * State type for options that may use deferred parsing (DerivedValueParser).
10
- * This extends the normal ValueParserResult to also support DeferredParseState.
10
+ * This extends the normal ValueParserResult to also support DeferredParseState
11
+ * and PendingDependencySourceState.
11
12
  * @internal
12
13
  */
13
- type OptionState<T> = ValueParserResult<T> | DeferredParseState<T> | undefined;
14
+ type OptionState<T> = ValueParserResult<T> | DeferredParseState<T> | PendingDependencySourceState | undefined;
14
15
  /**
15
16
  * Creates a parser that always succeeds without consuming any input and
16
17
  * produces a constant value of the type {@link T}.
@@ -1,5 +1,5 @@
1
1
  import { message, metavar, optionName, optionNames } from "./message.js";
2
- import { DependencyId, createDeferredParseState, createDependencySourceState, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser } from "./dependency.js";
2
+ import { DependencyId, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState } from "./dependency.js";
3
3
  import { extractCommandNames, extractOptionNames } from "./usage.js";
4
4
  import { DEFAULT_FIND_SIMILAR_OPTIONS, createErrorWithSuggestions, findSimilar } from "./suggestion.js";
5
5
  import { isValueParser } from "./valueparser.js";
@@ -203,7 +203,7 @@ function option(...args) {
203
203
  initialState: valueParser == null ? {
204
204
  success: true,
205
205
  value: false
206
- } : {
206
+ } : isDependencySource(valueParser) ? createPendingDependencySourceState(valueParser[DependencyId]) : {
207
207
  success: false,
208
208
  error: options.errors?.missing ? typeof options.errors.missing === "function" ? options.errors.missing(optionNames$1) : options.errors.missing : message`Missing option ${optionNames(optionNames$1)}.`
209
209
  },
@@ -357,6 +357,10 @@ function option(...args) {
357
357
  success: false,
358
358
  error: options.errors?.missing ? typeof options.errors.missing === "function" ? options.errors.missing(optionNames$1) : options.errors.missing : message`Missing option ${optionNames(optionNames$1)}.`
359
359
  };
360
+ if (isPendingDependencySourceState(state)) return {
361
+ success: false,
362
+ error: options.errors?.missing ? typeof options.errors.missing === "function" ? options.errors.missing(optionNames$1) : options.errors.missing : message`Missing option ${optionNames(optionNames$1)}.`
363
+ };
360
364
  if (isDeferredParseState(state)) {
361
365
  const preliminaryResult = state.preliminaryResult;
362
366
  if (preliminaryResult.success) return preliminaryResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.10.0-dev.294+7d6c1ae6",
3
+ "version": "0.10.0-dev.296+80e4ca45",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",