@matatbread/matbot-tool-types 0.4.17 → 0.4.18
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/package.json +5 -5
- package/src/validator.ts +9 -3
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"matbotRuntime": [
|
|
4
4
|
"node"
|
|
5
5
|
],
|
|
6
|
-
"version": "0.4.
|
|
6
|
+
"version": "0.4.18",
|
|
7
7
|
"engines": {
|
|
8
8
|
"node": ">=24.0.0"
|
|
9
9
|
},
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
"typescript": "^6.0.3"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@matatbread/matbot-plugin-api": "^0.4.
|
|
40
|
-
"@matatbread/matbot-core": "^0.4.
|
|
39
|
+
"@matatbread/matbot-plugin-api": "^0.4.18",
|
|
40
|
+
"@matatbread/matbot-core": "^0.4.18"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "^22.0.0",
|
|
44
44
|
"typescript": "^6.0.3",
|
|
45
|
-
"@matatbread/matbot-plugin-api": "^0.4.
|
|
46
|
-
"@matatbread/matbot-core": "^0.4.
|
|
45
|
+
"@matatbread/matbot-plugin-api": "^0.4.18",
|
|
46
|
+
"@matatbread/matbot-core": "^0.4.18"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"typecheck": "tsc --noEmit"
|
package/src/validator.ts
CHANGED
|
@@ -246,12 +246,18 @@ export function generateValidator(
|
|
|
246
246
|
return `${OBJ_GUARD} switch (${access('v', disc.name)}) {\n${cases}\n`
|
|
247
247
|
+ ` default: E(p + ${lit(propPath(disc.name))}, 'expected one of ${disc.vals.map(lit).join(', ')}', ${access('v', disc.name)}, e); return false;\n }`;
|
|
248
248
|
}
|
|
249
|
-
// No discriminant: try each arm against
|
|
249
|
+
// No discriminant: try each arm against its own scratch buffer so a failed arm's errors don't leak.
|
|
250
|
+
// If none matches, say why EACH was refused. Nothing says which arm the caller meant, and a bare
|
|
251
|
+
// "no union member matched" leaves them to guess: `background` with `name` on its run-now form read
|
|
252
|
+
// as nothing at all, when the arms said exactly "drop .name, or add .at / .interval".
|
|
250
253
|
const attempts = arms.map((a, i) => {
|
|
251
254
|
const c = check(a, 'v', 'p', `${where}|${i}`);
|
|
252
|
-
return ` if (${c.reports ? c.expr.replace(/, e\)$/,
|
|
255
|
+
return ` const s${i} = [];\n if (${c.reports ? c.expr.replace(/, e\)$/, `, s${i})`) : c.expr}) return true;`;
|
|
253
256
|
}).join('\n');
|
|
254
|
-
|
|
257
|
+
const why = `[${arms.map((_, i) => `s${i}`).join(', ')}].map((s, i) => '(' + (i + 1) + ') ' + `
|
|
258
|
+
+ `(s.length ? s.slice(0, 2).map(x => x.path + ': ' + x.message).join(', ') : 'wrong type')).join('; ')`;
|
|
259
|
+
return `${excessAcrossArms(arms)}${attempts}\n`
|
|
260
|
+
+ ` E(p, 'matches none of the ${arms.length} accepted forms: ' + ${why}, v, e);\n return false;`;
|
|
255
261
|
}
|
|
256
262
|
|
|
257
263
|
// A key no arm declares fails EVERY arm, so it can be reported by name before the arms are tried —
|