@optique/core 1.2.0-dev.2308 → 1.2.0-dev.2310
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/internal/mode-dispatch.cjs +3 -2
- package/dist/internal/mode-dispatch.js +3 -2
- package/dist/valueparser.cjs +36 -19
- package/dist/valueparser.js +36 -19
- package/package.json +2 -2
|
@@ -63,11 +63,12 @@ function mapMaybePromiseByMode(mode, value, mapFn) {
|
|
|
63
63
|
*/
|
|
64
64
|
function wrapIterableForMode(mode, value) {
|
|
65
65
|
const canCheckAsyncIterator = value != null && (typeof value === "object" || typeof value === "function");
|
|
66
|
+
const isAsyncIterable = canCheckAsyncIterator && Symbol.asyncIterator in value;
|
|
66
67
|
return dispatchIterableByMode(mode, () => {
|
|
67
|
-
if (
|
|
68
|
+
if (isAsyncIterable) throw new TypeError("Synchronous mode cannot wrap AsyncIterable value.");
|
|
68
69
|
return value;
|
|
69
70
|
}, () => {
|
|
70
|
-
if (
|
|
71
|
+
if (isAsyncIterable) return value;
|
|
71
72
|
return async function* () {
|
|
72
73
|
yield* value;
|
|
73
74
|
}();
|
|
@@ -62,11 +62,12 @@ function mapMaybePromiseByMode(mode, value, mapFn) {
|
|
|
62
62
|
*/
|
|
63
63
|
function wrapIterableForMode(mode, value) {
|
|
64
64
|
const canCheckAsyncIterator = value != null && (typeof value === "object" || typeof value === "function");
|
|
65
|
+
const isAsyncIterable = canCheckAsyncIterator && Symbol.asyncIterator in value;
|
|
65
66
|
return dispatchIterableByMode(mode, () => {
|
|
66
|
-
if (
|
|
67
|
+
if (isAsyncIterable) throw new TypeError("Synchronous mode cannot wrap AsyncIterable value.");
|
|
67
68
|
return value;
|
|
68
69
|
}, () => {
|
|
69
|
-
if (
|
|
70
|
+
if (isAsyncIterable) return value;
|
|
70
71
|
return async function* () {
|
|
71
72
|
yield* value;
|
|
72
73
|
}();
|
package/dist/valueparser.cjs
CHANGED
|
@@ -5,6 +5,12 @@ const require_suggestion = require('./suggestion.cjs');
|
|
|
5
5
|
const require_nonempty = require('./nonempty.cjs');
|
|
6
6
|
|
|
7
7
|
//#region src/valueparser.ts
|
|
8
|
+
function transformMappingFailure() {
|
|
9
|
+
return {
|
|
10
|
+
success: false,
|
|
11
|
+
error: require_message.message`Failed to transform value.`
|
|
12
|
+
};
|
|
13
|
+
}
|
|
8
14
|
function transformValueParserResult(result, mapping) {
|
|
9
15
|
if (!result.success) return result;
|
|
10
16
|
const preserveSnapshot = (mapped) => {
|
|
@@ -18,16 +24,16 @@ function transformValueParserResult(result, mapping) {
|
|
|
18
24
|
deferred: true
|
|
19
25
|
});
|
|
20
26
|
} catch {
|
|
27
|
+
return preserveSnapshot(transformMappingFailure());
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
21
30
|
return preserveSnapshot({
|
|
22
31
|
success: true,
|
|
23
|
-
value:
|
|
24
|
-
deferred: true
|
|
32
|
+
value: mapping.map(result.value)
|
|
25
33
|
});
|
|
34
|
+
} catch {
|
|
35
|
+
return preserveSnapshot(transformMappingFailure());
|
|
26
36
|
}
|
|
27
|
-
return preserveSnapshot({
|
|
28
|
-
success: true,
|
|
29
|
-
value: mapping.map(result.value)
|
|
30
|
-
});
|
|
31
37
|
}
|
|
32
38
|
/**
|
|
33
39
|
* A predicate function that checks if an object is a {@link ValueParser}.
|
|
@@ -219,8 +225,7 @@ function choice(choices, options = {}) {
|
|
|
219
225
|
function biject(mapping) {
|
|
220
226
|
if (mapping === null || typeof mapping !== "object") throw new TypeError("Expected object.");
|
|
221
227
|
if (Array.isArray(mapping)) throw new TypeError("Expected object, got array.");
|
|
222
|
-
const keys =
|
|
223
|
-
for (const key in mapping) if (Object.prototype.hasOwnProperty.call(mapping, key)) keys.push(key);
|
|
228
|
+
const keys = Object.keys(mapping);
|
|
224
229
|
if (keys.length < 1) throw new RangeError("Expected at least one biject entry.");
|
|
225
230
|
const source = choice(keys);
|
|
226
231
|
const forward = /* @__PURE__ */ new Map();
|
|
@@ -315,7 +320,7 @@ function transform(parser, mapping) {
|
|
|
315
320
|
return mapping.map(normalize(mapping.unmap(value)));
|
|
316
321
|
} },
|
|
317
322
|
...suggest == null ? {} : { suggest(prefix) {
|
|
318
|
-
return suggest(prefix);
|
|
323
|
+
return require_mode_dispatch.wrapIterableForMode(parser.mode, suggest(prefix));
|
|
319
324
|
} }
|
|
320
325
|
};
|
|
321
326
|
Object.defineProperty(transformed, "placeholder", {
|
|
@@ -334,11 +339,21 @@ function transform(parser, mapping) {
|
|
|
334
339
|
const validate = parser.validate.bind(parser);
|
|
335
340
|
Object.defineProperty(transformed, "validate", {
|
|
336
341
|
value(value) {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
+
let result;
|
|
343
|
+
try {
|
|
344
|
+
result = validate(mapping.unmap(value));
|
|
345
|
+
} catch {
|
|
346
|
+
return transformMappingFailure();
|
|
347
|
+
}
|
|
348
|
+
if (!result.success) return result;
|
|
349
|
+
try {
|
|
350
|
+
return {
|
|
351
|
+
success: true,
|
|
352
|
+
value: mapping.map(result.value)
|
|
353
|
+
};
|
|
354
|
+
} catch {
|
|
355
|
+
return transformMappingFailure();
|
|
356
|
+
}
|
|
342
357
|
},
|
|
343
358
|
configurable: true,
|
|
344
359
|
enumerable: true
|
|
@@ -351,15 +366,17 @@ function transform(parser, mapping) {
|
|
|
351
366
|
try {
|
|
352
367
|
result = syncParser.parse(syncParser.format(mapping.unmap(value)));
|
|
353
368
|
} catch {
|
|
369
|
+
return transformMappingFailure();
|
|
370
|
+
}
|
|
371
|
+
if (!result.success) return result;
|
|
372
|
+
try {
|
|
354
373
|
return {
|
|
355
374
|
success: true,
|
|
356
|
-
value
|
|
375
|
+
value: mapping.map(result.value)
|
|
357
376
|
};
|
|
377
|
+
} catch {
|
|
378
|
+
return transformMappingFailure();
|
|
358
379
|
}
|
|
359
|
-
return result.success ? {
|
|
360
|
-
success: true,
|
|
361
|
-
value: mapping.map(result.value)
|
|
362
|
-
} : result;
|
|
363
380
|
},
|
|
364
381
|
configurable: true,
|
|
365
382
|
enumerable: true
|
package/dist/valueparser.js
CHANGED
|
@@ -5,6 +5,12 @@ import { appendValueHint, appendValueSuggestions, deduplicateSuggestions } from
|
|
|
5
5
|
import { ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
|
|
6
6
|
|
|
7
7
|
//#region src/valueparser.ts
|
|
8
|
+
function transformMappingFailure() {
|
|
9
|
+
return {
|
|
10
|
+
success: false,
|
|
11
|
+
error: message`Failed to transform value.`
|
|
12
|
+
};
|
|
13
|
+
}
|
|
8
14
|
function transformValueParserResult(result, mapping) {
|
|
9
15
|
if (!result.success) return result;
|
|
10
16
|
const preserveSnapshot = (mapped) => {
|
|
@@ -18,16 +24,16 @@ function transformValueParserResult(result, mapping) {
|
|
|
18
24
|
deferred: true
|
|
19
25
|
});
|
|
20
26
|
} catch {
|
|
27
|
+
return preserveSnapshot(transformMappingFailure());
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
21
30
|
return preserveSnapshot({
|
|
22
31
|
success: true,
|
|
23
|
-
value:
|
|
24
|
-
deferred: true
|
|
32
|
+
value: mapping.map(result.value)
|
|
25
33
|
});
|
|
34
|
+
} catch {
|
|
35
|
+
return preserveSnapshot(transformMappingFailure());
|
|
26
36
|
}
|
|
27
|
-
return preserveSnapshot({
|
|
28
|
-
success: true,
|
|
29
|
-
value: mapping.map(result.value)
|
|
30
|
-
});
|
|
31
37
|
}
|
|
32
38
|
/**
|
|
33
39
|
* A predicate function that checks if an object is a {@link ValueParser}.
|
|
@@ -219,8 +225,7 @@ function choice(choices, options = {}) {
|
|
|
219
225
|
function biject(mapping) {
|
|
220
226
|
if (mapping === null || typeof mapping !== "object") throw new TypeError("Expected object.");
|
|
221
227
|
if (Array.isArray(mapping)) throw new TypeError("Expected object, got array.");
|
|
222
|
-
const keys =
|
|
223
|
-
for (const key in mapping) if (Object.prototype.hasOwnProperty.call(mapping, key)) keys.push(key);
|
|
228
|
+
const keys = Object.keys(mapping);
|
|
224
229
|
if (keys.length < 1) throw new RangeError("Expected at least one biject entry.");
|
|
225
230
|
const source = choice(keys);
|
|
226
231
|
const forward = /* @__PURE__ */ new Map();
|
|
@@ -315,7 +320,7 @@ function transform(parser, mapping) {
|
|
|
315
320
|
return mapping.map(normalize(mapping.unmap(value)));
|
|
316
321
|
} },
|
|
317
322
|
...suggest == null ? {} : { suggest(prefix) {
|
|
318
|
-
return suggest(prefix);
|
|
323
|
+
return wrapIterableForMode(parser.mode, suggest(prefix));
|
|
319
324
|
} }
|
|
320
325
|
};
|
|
321
326
|
Object.defineProperty(transformed, "placeholder", {
|
|
@@ -334,11 +339,21 @@ function transform(parser, mapping) {
|
|
|
334
339
|
const validate = parser.validate.bind(parser);
|
|
335
340
|
Object.defineProperty(transformed, "validate", {
|
|
336
341
|
value(value) {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
+
let result;
|
|
343
|
+
try {
|
|
344
|
+
result = validate(mapping.unmap(value));
|
|
345
|
+
} catch {
|
|
346
|
+
return transformMappingFailure();
|
|
347
|
+
}
|
|
348
|
+
if (!result.success) return result;
|
|
349
|
+
try {
|
|
350
|
+
return {
|
|
351
|
+
success: true,
|
|
352
|
+
value: mapping.map(result.value)
|
|
353
|
+
};
|
|
354
|
+
} catch {
|
|
355
|
+
return transformMappingFailure();
|
|
356
|
+
}
|
|
342
357
|
},
|
|
343
358
|
configurable: true,
|
|
344
359
|
enumerable: true
|
|
@@ -351,15 +366,17 @@ function transform(parser, mapping) {
|
|
|
351
366
|
try {
|
|
352
367
|
result = syncParser.parse(syncParser.format(mapping.unmap(value)));
|
|
353
368
|
} catch {
|
|
369
|
+
return transformMappingFailure();
|
|
370
|
+
}
|
|
371
|
+
if (!result.success) return result;
|
|
372
|
+
try {
|
|
354
373
|
return {
|
|
355
374
|
success: true,
|
|
356
|
-
value
|
|
375
|
+
value: mapping.map(result.value)
|
|
357
376
|
};
|
|
377
|
+
} catch {
|
|
378
|
+
return transformMappingFailure();
|
|
358
379
|
}
|
|
359
|
-
return result.success ? {
|
|
360
|
-
success: true,
|
|
361
|
-
value: mapping.map(result.value)
|
|
362
|
-
} : result;
|
|
363
380
|
},
|
|
364
381
|
configurable: true,
|
|
365
382
|
enumerable: true
|
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.2310",
|
|
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.2310+1dd4b70d"
|
|
229
229
|
},
|
|
230
230
|
"scripts": {
|
|
231
231
|
"build": "tsdown",
|