@carno.js/core 0.2.7 → 0.2.8
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.
|
@@ -9,12 +9,12 @@ class HttpException {
|
|
|
9
9
|
this.initMessage();
|
|
10
10
|
}
|
|
11
11
|
initMessage() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this.message = this.response;
|
|
12
|
+
const formatted = (0, utils_1.formatValidationErrors)(this.response);
|
|
13
|
+
if ((0, utils_1.isObject)(formatted)) {
|
|
14
|
+
this.message = formatted;
|
|
15
|
+
return;
|
|
17
16
|
}
|
|
17
|
+
this.message = formatted;
|
|
18
18
|
}
|
|
19
19
|
getResponse() {
|
|
20
20
|
return this.message;
|
package/dist/route/memoirist.js
CHANGED
|
@@ -179,6 +179,10 @@ class Memoirist {
|
|
|
179
179
|
}
|
|
180
180
|
if (node.params?.store === oldStore) {
|
|
181
181
|
node.params.store = newStore;
|
|
182
|
+
const paramName = node.params.names.get(oldStore);
|
|
183
|
+
if (paramName) {
|
|
184
|
+
node.params.names.set(newStore, paramName);
|
|
185
|
+
}
|
|
182
186
|
this.updateHistoryStore(method, path, newStore);
|
|
183
187
|
return true;
|
|
184
188
|
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatValidationErrors = formatValidationErrors;
|
|
4
|
+
function formatValidationErrors(value) {
|
|
5
|
+
if (!shouldFormatErrors(value)) {
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
return collectIssues(value);
|
|
9
|
+
}
|
|
10
|
+
function shouldFormatErrors(value) {
|
|
11
|
+
if (!Array.isArray(value)) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (value.length === 0) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return isValidationError(value[0]);
|
|
18
|
+
}
|
|
19
|
+
function isValidationError(value) {
|
|
20
|
+
if (!value) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
if (typeof value !== "object") {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return hasValidationShape(value);
|
|
27
|
+
}
|
|
28
|
+
function hasValidationShape(value) {
|
|
29
|
+
if ("constraints" in value) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
if ("property" in value) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
if ("children" in value) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
function collectIssues(errors) {
|
|
41
|
+
const issues = [];
|
|
42
|
+
for (const error of errors) {
|
|
43
|
+
appendIssues(error, "", issues);
|
|
44
|
+
}
|
|
45
|
+
return issues;
|
|
46
|
+
}
|
|
47
|
+
function appendIssues(error, prefix, issues) {
|
|
48
|
+
const field = buildField(prefix, error.property);
|
|
49
|
+
appendConstraints(error, field, issues);
|
|
50
|
+
appendChildren(error, field, issues);
|
|
51
|
+
}
|
|
52
|
+
function appendConstraints(error, field, issues) {
|
|
53
|
+
const constraints = error.constraints;
|
|
54
|
+
if (!constraints) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const messages = Object.values(constraints);
|
|
58
|
+
if (messages.length === 0) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
issues.push({ field, messages });
|
|
62
|
+
}
|
|
63
|
+
function appendChildren(error, prefix, issues) {
|
|
64
|
+
const children = error.children;
|
|
65
|
+
if (!children || children.length === 0) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
for (const child of children) {
|
|
69
|
+
appendIssues(child, prefix, issues);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function buildField(prefix, property) {
|
|
73
|
+
if (!property) {
|
|
74
|
+
return prefix || "body";
|
|
75
|
+
}
|
|
76
|
+
if (!prefix) {
|
|
77
|
+
return property;
|
|
78
|
+
}
|
|
79
|
+
return `${prefix}.${property}`;
|
|
80
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carno.js/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "Carno.js is a framework for building web applications object oriented with TypeScript and Bun.sh",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "2793d412b70bb432d2c825bae58522ccac87baff"
|
|
55
55
|
}
|