alemonjs 2.1.75 → 2.1.76
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/lib/app/router/dsl.js +1 -1
- package/lib/app/router/fallback.js +13 -0
- package/package.json +1 -1
package/lib/app/router/dsl.js
CHANGED
|
@@ -672,7 +672,7 @@ class Router {
|
|
|
672
672
|
const md = Format.createMarkdown();
|
|
673
673
|
const format = Format.create();
|
|
674
674
|
const routeEntry = (result.eventName && result.matchedPath
|
|
675
|
-
? this.routes.get(result.eventName)?.one.get(result.matchedPath) ?? this.routes.get(result.eventName)?.two.get(result.matchedPath)
|
|
675
|
+
? (this.routes.get(result.eventName)?.one.get(result.matchedPath) ?? this.routes.get(result.eventName)?.two.get(result.matchedPath))
|
|
676
676
|
: undefined) ?? undefined;
|
|
677
677
|
const description = formatRouteDescription(routeEntry?.config.description);
|
|
678
678
|
const schemaHints = buildSchemaHints(routeEntry?.config.schema);
|
|
@@ -21,6 +21,12 @@ function levenshteinDistance(a, b) {
|
|
|
21
21
|
function normalizeForCompare(text) {
|
|
22
22
|
return text.replace(/^([!!/##])\s*/, '').trim();
|
|
23
23
|
}
|
|
24
|
+
function shouldCheckCandidate(messageText, candidate) {
|
|
25
|
+
if (!messageText || !candidate) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return messageText.startsWith(candidate);
|
|
29
|
+
}
|
|
24
30
|
function getAdaptiveMaxDistance(input) {
|
|
25
31
|
if (input.length <= 2) {
|
|
26
32
|
return 1;
|
|
@@ -44,6 +50,10 @@ function checkFallbackHint(messageText, routeKeys, options = {}) {
|
|
|
44
50
|
if (options.suggest === false) {
|
|
45
51
|
return { matched: false };
|
|
46
52
|
}
|
|
53
|
+
const normalizedMessage = normalizeForCompare(String(messageText ?? ''));
|
|
54
|
+
if (!normalizedMessage) {
|
|
55
|
+
return { matched: false };
|
|
56
|
+
}
|
|
47
57
|
const parsed = parseMessageText(messageText);
|
|
48
58
|
if (!parsed) {
|
|
49
59
|
return { matched: false };
|
|
@@ -60,6 +70,9 @@ function checkFallbackHint(messageText, routeKeys, options = {}) {
|
|
|
60
70
|
let bestMatch = null;
|
|
61
71
|
for (const routeKey of routeKeys) {
|
|
62
72
|
const normalizedKey = normalizeForCompare(routeKey);
|
|
73
|
+
if (!shouldCheckCandidate(normalizedMessage, normalizedKey)) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
63
76
|
const distance = levenshteinDistance(attemptedKey, normalizedKey);
|
|
64
77
|
if (!bestMatch || distance < bestMatch.distance) {
|
|
65
78
|
bestMatch = {
|