@kozojs/core 0.3.9 → 0.3.11
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/index.d.ts +3 -0
- package/lib/index.js +4 -1
- package/lib/index.js.map +1 -1
- package/package.json +11 -7
package/lib/index.d.ts
CHANGED
|
@@ -336,6 +336,8 @@ declare function createKozo<TServices extends Services = Services>(config?: Kozo
|
|
|
336
336
|
type ZValidatorErrors = {
|
|
337
337
|
instancePath: string;
|
|
338
338
|
message: string;
|
|
339
|
+
keyword?: string;
|
|
340
|
+
path?: (string | number)[];
|
|
339
341
|
}[];
|
|
340
342
|
type ZValidator = ((data: unknown) => boolean) & {
|
|
341
343
|
errors: ZValidatorErrors | null;
|
|
@@ -416,6 +418,7 @@ declare function fastWriteError(err: unknown, res: ServerResponse): void;
|
|
|
416
418
|
*/
|
|
417
419
|
interface ValidationError {
|
|
418
420
|
field: string;
|
|
421
|
+
path?: (string | number)[];
|
|
419
422
|
message: string;
|
|
420
423
|
code: string;
|
|
421
424
|
value?: unknown;
|
package/lib/index.js
CHANGED
|
@@ -257,6 +257,7 @@ function formatAjvErrors(errors) {
|
|
|
257
257
|
if (!errors || errors.length === 0) return [];
|
|
258
258
|
return errors.map((err) => ({
|
|
259
259
|
field: err.instancePath?.replace(/^\//, "").replace(/\//g, ".") || err.params?.missingProperty || "unknown",
|
|
260
|
+
path: err.path,
|
|
260
261
|
message: err.message || "Invalid value",
|
|
261
262
|
code: err.keyword || "invalid",
|
|
262
263
|
value: err.data
|
|
@@ -741,7 +742,9 @@ function makeZValidator(schema) {
|
|
|
741
742
|
}
|
|
742
743
|
fn.errors = r.error.issues.map((i) => ({
|
|
743
744
|
instancePath: i.path.length ? "/" + i.path.join("/") : "",
|
|
744
|
-
message: i.message
|
|
745
|
+
message: i.message,
|
|
746
|
+
keyword: i.code,
|
|
747
|
+
path: i.path
|
|
745
748
|
}));
|
|
746
749
|
return false;
|
|
747
750
|
};
|