@optique/core 1.2.0-dev.2302 → 1.2.0-dev.2308
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.
|
@@ -62,11 +62,12 @@ function mapMaybePromiseByMode(mode, value, mapFn) {
|
|
|
62
62
|
* @internal
|
|
63
63
|
*/
|
|
64
64
|
function wrapIterableForMode(mode, value) {
|
|
65
|
+
const canCheckAsyncIterator = value != null && (typeof value === "object" || typeof value === "function");
|
|
65
66
|
return dispatchIterableByMode(mode, () => {
|
|
66
|
-
if (Symbol.asyncIterator in value) throw new TypeError("Synchronous mode cannot wrap AsyncIterable value.");
|
|
67
|
+
if (canCheckAsyncIterator && Symbol.asyncIterator in value) throw new TypeError("Synchronous mode cannot wrap AsyncIterable value.");
|
|
67
68
|
return value;
|
|
68
69
|
}, () => {
|
|
69
|
-
if (Symbol.asyncIterator in value) return value;
|
|
70
|
+
if (canCheckAsyncIterator && Symbol.asyncIterator in value) return value;
|
|
70
71
|
return async function* () {
|
|
71
72
|
yield* value;
|
|
72
73
|
}();
|
|
@@ -61,11 +61,12 @@ function mapMaybePromiseByMode(mode, value, mapFn) {
|
|
|
61
61
|
* @internal
|
|
62
62
|
*/
|
|
63
63
|
function wrapIterableForMode(mode, value) {
|
|
64
|
+
const canCheckAsyncIterator = value != null && (typeof value === "object" || typeof value === "function");
|
|
64
65
|
return dispatchIterableByMode(mode, () => {
|
|
65
|
-
if (Symbol.asyncIterator in value) throw new TypeError("Synchronous mode cannot wrap AsyncIterable value.");
|
|
66
|
+
if (canCheckAsyncIterator && Symbol.asyncIterator in value) throw new TypeError("Synchronous mode cannot wrap AsyncIterable value.");
|
|
66
67
|
return value;
|
|
67
68
|
}, () => {
|
|
68
|
-
if (Symbol.asyncIterator in value) return value;
|
|
69
|
+
if (canCheckAsyncIterator && Symbol.asyncIterator in value) return value;
|
|
69
70
|
return async function* () {
|
|
70
71
|
yield* value;
|
|
71
72
|
}();
|
package/dist/valueparser.cjs
CHANGED
|
@@ -217,7 +217,8 @@ function choice(choices, options = {}) {
|
|
|
217
217
|
};
|
|
218
218
|
}
|
|
219
219
|
function biject(mapping) {
|
|
220
|
-
if (
|
|
220
|
+
if (mapping === null || typeof mapping !== "object") throw new TypeError("Expected object.");
|
|
221
|
+
if (Array.isArray(mapping)) throw new TypeError("Expected object, got array.");
|
|
221
222
|
const keys = [];
|
|
222
223
|
for (const key in mapping) if (Object.prototype.hasOwnProperty.call(mapping, key)) keys.push(key);
|
|
223
224
|
if (keys.length < 1) throw new RangeError("Expected at least one biject entry.");
|
|
@@ -305,7 +306,7 @@ function transform(parser, mapping) {
|
|
|
305
306
|
placeholder: void 0,
|
|
306
307
|
...transformedChoices == null ? {} : { choices: transformedChoices },
|
|
307
308
|
parse(input) {
|
|
308
|
-
return require_mode_dispatch.
|
|
309
|
+
return require_mode_dispatch.mapMaybePromiseByMode(parser.mode, parser.parse(input), (result) => transformValueParserResult(result, mapping));
|
|
309
310
|
},
|
|
310
311
|
format(value) {
|
|
311
312
|
return parser.format(mapping.unmap(value));
|
|
@@ -319,6 +320,7 @@ function transform(parser, mapping) {
|
|
|
319
320
|
};
|
|
320
321
|
Object.defineProperty(transformed, "placeholder", {
|
|
321
322
|
get() {
|
|
323
|
+
if (parser.placeholder === void 0) return void 0;
|
|
322
324
|
try {
|
|
323
325
|
return mapping.map(parser.placeholder);
|
|
324
326
|
} catch {
|
|
@@ -326,7 +328,7 @@ function transform(parser, mapping) {
|
|
|
326
328
|
}
|
|
327
329
|
},
|
|
328
330
|
configurable: true,
|
|
329
|
-
enumerable:
|
|
331
|
+
enumerable: true
|
|
330
332
|
});
|
|
331
333
|
if (typeof parser.validate === "function") {
|
|
332
334
|
const validate = parser.validate.bind(parser);
|
|
@@ -345,7 +347,15 @@ function transform(parser, mapping) {
|
|
|
345
347
|
const syncParser = parser;
|
|
346
348
|
Object.defineProperty(transformed, "validate", {
|
|
347
349
|
value(value) {
|
|
348
|
-
|
|
350
|
+
let result;
|
|
351
|
+
try {
|
|
352
|
+
result = syncParser.parse(syncParser.format(mapping.unmap(value)));
|
|
353
|
+
} catch {
|
|
354
|
+
return {
|
|
355
|
+
success: true,
|
|
356
|
+
value
|
|
357
|
+
};
|
|
358
|
+
}
|
|
349
359
|
return result.success ? {
|
|
350
360
|
success: true,
|
|
351
361
|
value: mapping.map(result.value)
|
package/dist/valueparser.d.cts
CHANGED
|
@@ -420,8 +420,8 @@ declare function choice<const T extends number>(choices: readonly T[], options?:
|
|
|
420
420
|
* @param mapping A mapping whose own enumerable string keys are valid inputs.
|
|
421
421
|
* @returns A value parser that accepts one of the mapping keys and returns the
|
|
422
422
|
* corresponding value.
|
|
423
|
-
* @throws {TypeError} If `mapping` is an
|
|
424
|
-
* string.
|
|
423
|
+
* @throws {TypeError} If `mapping` is not an object, if it is an array, or if
|
|
424
|
+
* any key is the empty string.
|
|
425
425
|
* @throws {RangeError} If the mapping has no own enumerable string keys, or if
|
|
426
426
|
* two keys map to the same value according to `Map` key equality.
|
|
427
427
|
* @since 1.2.0
|
package/dist/valueparser.d.ts
CHANGED
|
@@ -420,8 +420,8 @@ declare function choice<const T extends number>(choices: readonly T[], options?:
|
|
|
420
420
|
* @param mapping A mapping whose own enumerable string keys are valid inputs.
|
|
421
421
|
* @returns A value parser that accepts one of the mapping keys and returns the
|
|
422
422
|
* corresponding value.
|
|
423
|
-
* @throws {TypeError} If `mapping` is an
|
|
424
|
-
* string.
|
|
423
|
+
* @throws {TypeError} If `mapping` is not an object, if it is an array, or if
|
|
424
|
+
* any key is the empty string.
|
|
425
425
|
* @throws {RangeError} If the mapping has no own enumerable string keys, or if
|
|
426
426
|
* two keys map to the same value according to `Map` key equality.
|
|
427
427
|
* @since 1.2.0
|
package/dist/valueparser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cloneMessage, lineBreak, message, metavar, text, valueSet } from "./message.js";
|
|
2
|
-
import { mapMaybePromiseByMode,
|
|
2
|
+
import { mapMaybePromiseByMode, wrapIterableForMode } from "./internal/mode-dispatch.js";
|
|
3
3
|
import { defaultValues, dependencyId, dependencyIds, derivedValueParserMarker, getSnapshottedDefaultDependencyValues, 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";
|
|
@@ -217,7 +217,8 @@ function choice(choices, options = {}) {
|
|
|
217
217
|
};
|
|
218
218
|
}
|
|
219
219
|
function biject(mapping) {
|
|
220
|
-
if (
|
|
220
|
+
if (mapping === null || typeof mapping !== "object") throw new TypeError("Expected object.");
|
|
221
|
+
if (Array.isArray(mapping)) throw new TypeError("Expected object, got array.");
|
|
221
222
|
const keys = [];
|
|
222
223
|
for (const key in mapping) if (Object.prototype.hasOwnProperty.call(mapping, key)) keys.push(key);
|
|
223
224
|
if (keys.length < 1) throw new RangeError("Expected at least one biject entry.");
|
|
@@ -305,7 +306,7 @@ function transform(parser, mapping) {
|
|
|
305
306
|
placeholder: void 0,
|
|
306
307
|
...transformedChoices == null ? {} : { choices: transformedChoices },
|
|
307
308
|
parse(input) {
|
|
308
|
-
return
|
|
309
|
+
return mapMaybePromiseByMode(parser.mode, parser.parse(input), (result) => transformValueParserResult(result, mapping));
|
|
309
310
|
},
|
|
310
311
|
format(value) {
|
|
311
312
|
return parser.format(mapping.unmap(value));
|
|
@@ -319,6 +320,7 @@ function transform(parser, mapping) {
|
|
|
319
320
|
};
|
|
320
321
|
Object.defineProperty(transformed, "placeholder", {
|
|
321
322
|
get() {
|
|
323
|
+
if (parser.placeholder === void 0) return void 0;
|
|
322
324
|
try {
|
|
323
325
|
return mapping.map(parser.placeholder);
|
|
324
326
|
} catch {
|
|
@@ -326,7 +328,7 @@ function transform(parser, mapping) {
|
|
|
326
328
|
}
|
|
327
329
|
},
|
|
328
330
|
configurable: true,
|
|
329
|
-
enumerable:
|
|
331
|
+
enumerable: true
|
|
330
332
|
});
|
|
331
333
|
if (typeof parser.validate === "function") {
|
|
332
334
|
const validate = parser.validate.bind(parser);
|
|
@@ -345,7 +347,15 @@ function transform(parser, mapping) {
|
|
|
345
347
|
const syncParser = parser;
|
|
346
348
|
Object.defineProperty(transformed, "validate", {
|
|
347
349
|
value(value) {
|
|
348
|
-
|
|
350
|
+
let result;
|
|
351
|
+
try {
|
|
352
|
+
result = syncParser.parse(syncParser.format(mapping.unmap(value)));
|
|
353
|
+
} catch {
|
|
354
|
+
return {
|
|
355
|
+
success: true,
|
|
356
|
+
value
|
|
357
|
+
};
|
|
358
|
+
}
|
|
349
359
|
return result.success ? {
|
|
350
360
|
success: true,
|
|
351
361
|
value: mapping.map(result.value)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/core",
|
|
3
|
-
"version": "1.2.0-dev.
|
|
3
|
+
"version": "1.2.0-dev.2308",
|
|
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.
|
|
228
|
+
"@optique/env": "1.2.0-dev.2308+ddd68ea0"
|
|
229
229
|
},
|
|
230
230
|
"scripts": {
|
|
231
231
|
"build": "tsdown",
|