@imcms/core 1.0.1 → 1.0.3
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/index.cjs +27 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +18 -0
- package/package.json +2 -2
- package/src/defaultLogger.ts +16 -0
- package/src/formatZodError.ts +35 -0
- package/src/index.ts +2 -1
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
6
10
|
var __copyProps = (to, from, except, desc) => {
|
|
7
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
12
|
for (let key of __getOwnPropNames(from))
|
|
@@ -15,4 +19,27 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
15
19
|
|
|
16
20
|
// src/index.ts
|
|
17
21
|
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
DefaultLogger: () => DefaultLogger
|
|
24
|
+
});
|
|
18
25
|
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/defaultLogger.ts
|
|
28
|
+
var DefaultLogger = {
|
|
29
|
+
info: (msg, ...i) => {
|
|
30
|
+
console.info(msg, ...i);
|
|
31
|
+
},
|
|
32
|
+
error: (msg, ...i) => {
|
|
33
|
+
console.error(msg, ...i);
|
|
34
|
+
},
|
|
35
|
+
warn: (msg, ...i) => {
|
|
36
|
+
console.warn(msg, ...i);
|
|
37
|
+
},
|
|
38
|
+
debug: (msg, ...i) => {
|
|
39
|
+
console.debug(msg, ...i);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
DefaultLogger
|
|
45
|
+
});
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/defaultLogger.ts
|
|
2
|
+
var DefaultLogger = {
|
|
3
|
+
info: (msg, ...i) => {
|
|
4
|
+
console.info(msg, ...i);
|
|
5
|
+
},
|
|
6
|
+
error: (msg, ...i) => {
|
|
7
|
+
console.error(msg, ...i);
|
|
8
|
+
},
|
|
9
|
+
warn: (msg, ...i) => {
|
|
10
|
+
console.warn(msg, ...i);
|
|
11
|
+
},
|
|
12
|
+
debug: (msg, ...i) => {
|
|
13
|
+
console.debug(msg, ...i);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
DefaultLogger
|
|
18
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imcms/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"typescript": "^5.9.3"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"
|
|
35
|
+
"zod": "^4.6.7"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Logger } from "./logger.js";
|
|
2
|
+
|
|
3
|
+
export const DefaultLogger: Logger = {
|
|
4
|
+
info: (msg, ...i) => {
|
|
5
|
+
console.info(msg, ...i)
|
|
6
|
+
},
|
|
7
|
+
error: (msg, ...i) => {
|
|
8
|
+
console.error(msg, ...i)
|
|
9
|
+
},
|
|
10
|
+
warn: (msg, ...i) => {
|
|
11
|
+
console.warn(msg, ...i)
|
|
12
|
+
},
|
|
13
|
+
debug: (msg, ...i) => {
|
|
14
|
+
console.debug(msg, ...i)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ZodError, ZodIssue } from "zod";
|
|
2
|
+
|
|
3
|
+
export interface FormatZodErrorOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Prefixo exibido no início de cada linha de erro.
|
|
6
|
+
* @default " • "
|
|
7
|
+
*/
|
|
8
|
+
prefix?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Formata um erro do Zod (ZodError ou array de ZodIssue) em uma string legível para logs e terminal.
|
|
13
|
+
*
|
|
14
|
+
* Exemplo de saída:
|
|
15
|
+
* • [PORT]: Expected number, received string
|
|
16
|
+
* • [DATABASE_URL]: Required
|
|
17
|
+
*/
|
|
18
|
+
export function formatZodError(
|
|
19
|
+
error: ZodError | ZodIssue[],
|
|
20
|
+
options: FormatZodErrorOptions = {}
|
|
21
|
+
): string {
|
|
22
|
+
const { prefix = " • " } = options;
|
|
23
|
+
const issues = Array.isArray(error) ? error : error.issues;
|
|
24
|
+
|
|
25
|
+
if (!issues || issues.length === 0) {
|
|
26
|
+
return `${prefix}Erro de validação desconhecido.`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return issues
|
|
30
|
+
.map((issue) => {
|
|
31
|
+
const path = issue.path.length > 0 ? issue.path.join(".") : "ENV";
|
|
32
|
+
return `${prefix}[${path}]: ${issue.message}`;
|
|
33
|
+
})
|
|
34
|
+
.join("\n");
|
|
35
|
+
}
|
package/src/index.ts
CHANGED