@optique/core 1.2.0-dev.2316 → 1.2.0-dev.2320

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.
@@ -24,7 +24,11 @@ function transformValueParserResult(result, mapping) {
24
24
  deferred: true
25
25
  });
26
26
  } catch {
27
- return preserveSnapshot(transformMappingFailure());
27
+ return preserveSnapshot({
28
+ success: true,
29
+ value: void 0,
30
+ deferred: true
31
+ });
28
32
  }
29
33
  try {
30
34
  return preserveSnapshot({
@@ -262,8 +266,6 @@ function biject(mapping) {
262
266
  } catch {
263
267
  input = "";
264
268
  }
265
- const result = source.parse(input);
266
- if (!result.success) return result;
267
269
  return {
268
270
  success: false,
269
271
  error: formatDefaultChoiceError(input, keys)
@@ -302,6 +304,7 @@ function biject(mapping) {
302
304
  * @since 1.2.0
303
305
  */
304
306
  function transform(parser, mapping) {
307
+ if (require_internal_dependency.isDependencySource(parser)) throw new TypeError("Cannot transform a dependency source directly.");
305
308
  const normalize = parser.normalize?.bind(parser);
306
309
  const suggest = parser.suggest?.bind(parser);
307
310
  const transformedChoices = parser.choices == null ? void 0 : Object.freeze(parser.choices.map((choice$1) => mapping.map(choice$1)));
@@ -339,9 +342,18 @@ function transform(parser, mapping) {
339
342
  const validate = parser.validate.bind(parser);
340
343
  Object.defineProperty(transformed, "validate", {
341
344
  value(value) {
345
+ let unmapped;
346
+ try {
347
+ unmapped = mapping.unmap(value);
348
+ } catch {
349
+ return {
350
+ success: true,
351
+ value
352
+ };
353
+ }
342
354
  let result;
343
355
  try {
344
- result = validate(mapping.unmap(value));
356
+ result = validate(unmapped);
345
357
  } catch {
346
358
  return transformMappingFailure();
347
359
  }
@@ -1,6 +1,6 @@
1
1
  import { cloneMessage, lineBreak, message, metavar, text, valueSet } from "./message.js";
2
2
  import { mapMaybePromiseByMode, wrapIterableForMode } from "./internal/mode-dispatch.js";
3
- import { defaultValues, dependencyId, dependencyIds, derivedValueParserMarker, getSnapshottedDefaultDependencyValues, isDerivedValueParser, parseWithDependency, singleDefaultValue, snapshotDefaultDependencyValues, suggestWithDependency } from "./internal/dependency.js";
3
+ import { defaultValues, dependencyId, dependencyIds, derivedValueParserMarker, getSnapshottedDefaultDependencyValues, isDependencySource, isDerivedValueParser, parseWithDependency, singleDefaultValue, snapshotDefaultDependencyValues, suggestWithDependency } from "./internal/dependency.js";
4
4
  import { appendValueHint, appendValueSuggestions, deduplicateSuggestions } from "./suggestion.js";
5
5
  import { ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
6
6
 
@@ -24,7 +24,11 @@ function transformValueParserResult(result, mapping) {
24
24
  deferred: true
25
25
  });
26
26
  } catch {
27
- return preserveSnapshot(transformMappingFailure());
27
+ return preserveSnapshot({
28
+ success: true,
29
+ value: void 0,
30
+ deferred: true
31
+ });
28
32
  }
29
33
  try {
30
34
  return preserveSnapshot({
@@ -262,8 +266,6 @@ function biject(mapping) {
262
266
  } catch {
263
267
  input = "";
264
268
  }
265
- const result = source.parse(input);
266
- if (!result.success) return result;
267
269
  return {
268
270
  success: false,
269
271
  error: formatDefaultChoiceError(input, keys)
@@ -302,6 +304,7 @@ function biject(mapping) {
302
304
  * @since 1.2.0
303
305
  */
304
306
  function transform(parser, mapping) {
307
+ if (isDependencySource(parser)) throw new TypeError("Cannot transform a dependency source directly.");
305
308
  const normalize = parser.normalize?.bind(parser);
306
309
  const suggest = parser.suggest?.bind(parser);
307
310
  const transformedChoices = parser.choices == null ? void 0 : Object.freeze(parser.choices.map((choice$1) => mapping.map(choice$1)));
@@ -339,9 +342,18 @@ function transform(parser, mapping) {
339
342
  const validate = parser.validate.bind(parser);
340
343
  Object.defineProperty(transformed, "validate", {
341
344
  value(value) {
345
+ let unmapped;
346
+ try {
347
+ unmapped = mapping.unmap(value);
348
+ } catch {
349
+ return {
350
+ success: true,
351
+ value
352
+ };
353
+ }
342
354
  let result;
343
355
  try {
344
- result = validate(mapping.unmap(value));
356
+ result = validate(unmapped);
345
357
  } catch {
346
358
  return transformMappingFailure();
347
359
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.2.0-dev.2316",
3
+ "version": "1.2.0-dev.2320",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",
@@ -225,7 +225,7 @@
225
225
  "fast-check": "^4.7.0",
226
226
  "tsdown": "^0.13.0",
227
227
  "typescript": "^5.8.3",
228
- "@optique/env": "1.2.0-dev.2316+7a578ce1"
228
+ "@optique/env": "1.2.0-dev.2320+6a72f083"
229
229
  },
230
230
  "scripts": {
231
231
  "build": "tsdown",