@optique/core 1.0.5 → 1.0.6
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/constructs.cjs +31 -17
- package/dist/constructs.js +31 -17
- package/package.json +1 -1
package/dist/constructs.cjs
CHANGED
|
@@ -1448,6 +1448,33 @@ function longestMatch(...args) {
|
|
|
1448
1448
|
return multiResult;
|
|
1449
1449
|
}
|
|
1450
1450
|
/**
|
|
1451
|
+
* Creates the initial parse error shared by object-like combinators.
|
|
1452
|
+
* @param context The current parser context.
|
|
1453
|
+
* @param noMatchContext The kinds of input accepted by the combinator.
|
|
1454
|
+
* @param errors Optional custom error formatters.
|
|
1455
|
+
* @returns A zero-consumption parse error.
|
|
1456
|
+
*/
|
|
1457
|
+
function createObjectLikeInitialError(context, noMatchContext, errors) {
|
|
1458
|
+
if (context.buffer.length < 1) {
|
|
1459
|
+
const customEndOfInput = errors?.endOfInput;
|
|
1460
|
+
return {
|
|
1461
|
+
consumed: 0,
|
|
1462
|
+
error: customEndOfInput ? typeof customEndOfInput === "function" ? customEndOfInput(noMatchContext) : customEndOfInput : generateNoMatchError(noMatchContext)
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1465
|
+
const token = context.buffer[0];
|
|
1466
|
+
const customMessage = errors?.unexpectedInput;
|
|
1467
|
+
if (customMessage) return {
|
|
1468
|
+
consumed: 0,
|
|
1469
|
+
error: typeof customMessage === "function" ? customMessage(token) : customMessage
|
|
1470
|
+
};
|
|
1471
|
+
const baseError = require_message.message`Unexpected option or argument: ${token}.`;
|
|
1472
|
+
return {
|
|
1473
|
+
consumed: 0,
|
|
1474
|
+
error: require_suggestion.createErrorWithSuggestions(baseError, token, context.usage, "both", errors?.suggestions)
|
|
1475
|
+
};
|
|
1476
|
+
}
|
|
1477
|
+
/**
|
|
1451
1478
|
* Internal sync helper for object suggest functionality.
|
|
1452
1479
|
* @internal
|
|
1453
1480
|
*/
|
|
@@ -1839,19 +1866,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1839
1866
|
if (!options.allowDuplicates) checkDuplicateOptionNames(parserPairs.map(([field, parser]) => [field, parser.usage]));
|
|
1840
1867
|
const noMatchContext = analyzeNoMatchContext(parserKeys.map((k) => parsers[k]));
|
|
1841
1868
|
const combinedMode = parserKeys.some((k) => parsers[k].mode === "async") ? "async" : "sync";
|
|
1842
|
-
const getInitialError = (context) => (
|
|
1843
|
-
consumed: 0,
|
|
1844
|
-
error: context.buffer.length > 0 ? (() => {
|
|
1845
|
-
const token = context.buffer[0];
|
|
1846
|
-
const customMessage = options.errors?.unexpectedInput;
|
|
1847
|
-
if (customMessage) return typeof customMessage === "function" ? customMessage(token) : customMessage;
|
|
1848
|
-
const baseError = require_message.message`Unexpected option or argument: ${token}.`;
|
|
1849
|
-
return require_suggestion.createErrorWithSuggestions(baseError, token, context.usage, "both", options.errors?.suggestions);
|
|
1850
|
-
})() : (() => {
|
|
1851
|
-
const customEndOfInput = options.errors?.endOfInput;
|
|
1852
|
-
return customEndOfInput ? typeof customEndOfInput === "function" ? customEndOfInput(noMatchContext) : customEndOfInput : generateNoMatchError(noMatchContext);
|
|
1853
|
-
})()
|
|
1854
|
-
});
|
|
1869
|
+
const getInitialError = (context) => createObjectLikeInitialError(context, noMatchContext, options.errors);
|
|
1855
1870
|
const parseSync = (context) => {
|
|
1856
1871
|
let error = getInitialError(context);
|
|
1857
1872
|
let currentContext = context;
|
|
@@ -3000,6 +3015,7 @@ function merge(...args) {
|
|
|
3000
3015
|
const syncSorted = syncWithIndex.toSorted(([a], [b]) => b.priority - a.priority);
|
|
3001
3016
|
const syncParsers = syncSorted.map(([p]) => p);
|
|
3002
3017
|
if (!options.allowDuplicates) checkDuplicateOptionNames(sorted.map(([parser, originalIndex]) => [String(originalIndex), parser.usage]));
|
|
3018
|
+
const noMatchContext = analyzeNoMatchContext(rawParsers);
|
|
3003
3019
|
const mergedFieldParsers = collectChildFieldParsers(parsers);
|
|
3004
3020
|
const duplicateOutputFieldNames = collectDuplicateFieldNames(mergedFieldParsers);
|
|
3005
3021
|
const parserStateKey = (index) => `__parser_${index}`;
|
|
@@ -3092,8 +3108,7 @@ function merge(...args) {
|
|
|
3092
3108
|
};
|
|
3093
3109
|
return {
|
|
3094
3110
|
success: false,
|
|
3095
|
-
|
|
3096
|
-
error: require_message.message`No matching option or argument found.`
|
|
3111
|
+
...createObjectLikeInitialError(context, noMatchContext)
|
|
3097
3112
|
};
|
|
3098
3113
|
};
|
|
3099
3114
|
const parseAsync = async (context) => {
|
|
@@ -3138,8 +3153,7 @@ function merge(...args) {
|
|
|
3138
3153
|
};
|
|
3139
3154
|
return {
|
|
3140
3155
|
success: false,
|
|
3141
|
-
|
|
3142
|
-
error: require_message.message`No matching option or argument found.`
|
|
3156
|
+
...createObjectLikeInitialError(context, noMatchContext)
|
|
3143
3157
|
};
|
|
3144
3158
|
};
|
|
3145
3159
|
const mergeParser = {
|
package/dist/constructs.js
CHANGED
|
@@ -1448,6 +1448,33 @@ function longestMatch(...args) {
|
|
|
1448
1448
|
return multiResult;
|
|
1449
1449
|
}
|
|
1450
1450
|
/**
|
|
1451
|
+
* Creates the initial parse error shared by object-like combinators.
|
|
1452
|
+
* @param context The current parser context.
|
|
1453
|
+
* @param noMatchContext The kinds of input accepted by the combinator.
|
|
1454
|
+
* @param errors Optional custom error formatters.
|
|
1455
|
+
* @returns A zero-consumption parse error.
|
|
1456
|
+
*/
|
|
1457
|
+
function createObjectLikeInitialError(context, noMatchContext, errors) {
|
|
1458
|
+
if (context.buffer.length < 1) {
|
|
1459
|
+
const customEndOfInput = errors?.endOfInput;
|
|
1460
|
+
return {
|
|
1461
|
+
consumed: 0,
|
|
1462
|
+
error: customEndOfInput ? typeof customEndOfInput === "function" ? customEndOfInput(noMatchContext) : customEndOfInput : generateNoMatchError(noMatchContext)
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1465
|
+
const token = context.buffer[0];
|
|
1466
|
+
const customMessage = errors?.unexpectedInput;
|
|
1467
|
+
if (customMessage) return {
|
|
1468
|
+
consumed: 0,
|
|
1469
|
+
error: typeof customMessage === "function" ? customMessage(token) : customMessage
|
|
1470
|
+
};
|
|
1471
|
+
const baseError = message`Unexpected option or argument: ${token}.`;
|
|
1472
|
+
return {
|
|
1473
|
+
consumed: 0,
|
|
1474
|
+
error: createErrorWithSuggestions(baseError, token, context.usage, "both", errors?.suggestions)
|
|
1475
|
+
};
|
|
1476
|
+
}
|
|
1477
|
+
/**
|
|
1451
1478
|
* Internal sync helper for object suggest functionality.
|
|
1452
1479
|
* @internal
|
|
1453
1480
|
*/
|
|
@@ -1839,19 +1866,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1839
1866
|
if (!options.allowDuplicates) checkDuplicateOptionNames(parserPairs.map(([field, parser]) => [field, parser.usage]));
|
|
1840
1867
|
const noMatchContext = analyzeNoMatchContext(parserKeys.map((k) => parsers[k]));
|
|
1841
1868
|
const combinedMode = parserKeys.some((k) => parsers[k].mode === "async") ? "async" : "sync";
|
|
1842
|
-
const getInitialError = (context) => (
|
|
1843
|
-
consumed: 0,
|
|
1844
|
-
error: context.buffer.length > 0 ? (() => {
|
|
1845
|
-
const token = context.buffer[0];
|
|
1846
|
-
const customMessage = options.errors?.unexpectedInput;
|
|
1847
|
-
if (customMessage) return typeof customMessage === "function" ? customMessage(token) : customMessage;
|
|
1848
|
-
const baseError = message`Unexpected option or argument: ${token}.`;
|
|
1849
|
-
return createErrorWithSuggestions(baseError, token, context.usage, "both", options.errors?.suggestions);
|
|
1850
|
-
})() : (() => {
|
|
1851
|
-
const customEndOfInput = options.errors?.endOfInput;
|
|
1852
|
-
return customEndOfInput ? typeof customEndOfInput === "function" ? customEndOfInput(noMatchContext) : customEndOfInput : generateNoMatchError(noMatchContext);
|
|
1853
|
-
})()
|
|
1854
|
-
});
|
|
1869
|
+
const getInitialError = (context) => createObjectLikeInitialError(context, noMatchContext, options.errors);
|
|
1855
1870
|
const parseSync = (context) => {
|
|
1856
1871
|
let error = getInitialError(context);
|
|
1857
1872
|
let currentContext = context;
|
|
@@ -3000,6 +3015,7 @@ function merge(...args) {
|
|
|
3000
3015
|
const syncSorted = syncWithIndex.toSorted(([a], [b]) => b.priority - a.priority);
|
|
3001
3016
|
const syncParsers = syncSorted.map(([p]) => p);
|
|
3002
3017
|
if (!options.allowDuplicates) checkDuplicateOptionNames(sorted.map(([parser, originalIndex]) => [String(originalIndex), parser.usage]));
|
|
3018
|
+
const noMatchContext = analyzeNoMatchContext(rawParsers);
|
|
3003
3019
|
const mergedFieldParsers = collectChildFieldParsers(parsers);
|
|
3004
3020
|
const duplicateOutputFieldNames = collectDuplicateFieldNames(mergedFieldParsers);
|
|
3005
3021
|
const parserStateKey = (index) => `__parser_${index}`;
|
|
@@ -3092,8 +3108,7 @@ function merge(...args) {
|
|
|
3092
3108
|
};
|
|
3093
3109
|
return {
|
|
3094
3110
|
success: false,
|
|
3095
|
-
|
|
3096
|
-
error: message`No matching option or argument found.`
|
|
3111
|
+
...createObjectLikeInitialError(context, noMatchContext)
|
|
3097
3112
|
};
|
|
3098
3113
|
};
|
|
3099
3114
|
const parseAsync = async (context) => {
|
|
@@ -3138,8 +3153,7 @@ function merge(...args) {
|
|
|
3138
3153
|
};
|
|
3139
3154
|
return {
|
|
3140
3155
|
success: false,
|
|
3141
|
-
|
|
3142
|
-
error: message`No matching option or argument found.`
|
|
3156
|
+
...createObjectLikeInitialError(context, noMatchContext)
|
|
3143
3157
|
};
|
|
3144
3158
|
};
|
|
3145
3159
|
const mergeParser = {
|