@cargolift-cdi/common 1.0.0
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/errors/business.error.d.ts +22 -0
- package/dist/errors/business.error.js +63 -0
- package/dist/errors/business.error.js.map +1 -0
- package/dist/errors/not-found-business.error.d.ts +6 -0
- package/dist/errors/not-found-business.error.js +13 -0
- package/dist/errors/not-found-business.error.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/package.json +32 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type BusinessErrorOptions = {
|
|
2
|
+
code?: string;
|
|
3
|
+
cause?: unknown;
|
|
4
|
+
meta?: Record<string, unknown>;
|
|
5
|
+
};
|
|
6
|
+
export declare abstract class BusinessError extends Error {
|
|
7
|
+
readonly code?: string;
|
|
8
|
+
readonly meta?: Record<string, unknown>;
|
|
9
|
+
readonly cause?: unknown;
|
|
10
|
+
protected constructor(name: string, message?: string, options?: BusinessErrorOptions);
|
|
11
|
+
toJSON(): {
|
|
12
|
+
name: string;
|
|
13
|
+
message: string;
|
|
14
|
+
code: string | undefined;
|
|
15
|
+
meta: Record<string, unknown> | undefined;
|
|
16
|
+
stack: string | undefined;
|
|
17
|
+
cause: unknown;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export declare class GenericBusinessError extends BusinessError {
|
|
21
|
+
constructor(message?: string, options?: BusinessErrorOptions);
|
|
22
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export class BusinessError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
meta;
|
|
4
|
+
cause;
|
|
5
|
+
constructor(name, message, options) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = name;
|
|
8
|
+
this.code = options?.code;
|
|
9
|
+
this.meta = options?.meta;
|
|
10
|
+
this.cause = options?.cause;
|
|
11
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
12
|
+
if (Error.captureStackTrace) {
|
|
13
|
+
Error.captureStackTrace(this, new.target);
|
|
14
|
+
}
|
|
15
|
+
// Torna stack enumerável para JSON.stringify
|
|
16
|
+
if (this.stack) {
|
|
17
|
+
const stack = this.stack;
|
|
18
|
+
Object.defineProperty(this, "stack", {
|
|
19
|
+
value: stack,
|
|
20
|
+
enumerable: true,
|
|
21
|
+
writable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
toJSON() {
|
|
27
|
+
return {
|
|
28
|
+
name: this.name,
|
|
29
|
+
message: this.message,
|
|
30
|
+
code: this.code,
|
|
31
|
+
meta: this.meta,
|
|
32
|
+
stack: this.stack,
|
|
33
|
+
// Serializa causa se for Error, de forma segura
|
|
34
|
+
cause: this.cause instanceof Error
|
|
35
|
+
? {
|
|
36
|
+
name: this.cause.name,
|
|
37
|
+
message: this.cause.message,
|
|
38
|
+
stack: this.cause.stack,
|
|
39
|
+
}
|
|
40
|
+
: this.cause,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/*
|
|
45
|
+
export function isBusinessError(err: unknown): err is BusinessError {
|
|
46
|
+
return !!err && typeof err === "object" && "name" in err && (err as any).name?.endsWith("BusinessError");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function fromUnknown(err: unknown, fallbackMessage = "Unknown error"): BusinessError {
|
|
50
|
+
if (isBusinessError(err)) return err;
|
|
51
|
+
if (err instanceof Error) {
|
|
52
|
+
// Encapsula sem perder stack, útil para padronização
|
|
53
|
+
return new GenericBusinessError(err.message, { cause: err, code: "GENERIC_ERROR" });
|
|
54
|
+
}
|
|
55
|
+
return new GenericBusinessError(fallbackMessage, { cause: err, code: "GENERIC_ERROR" });
|
|
56
|
+
}
|
|
57
|
+
*/
|
|
58
|
+
export class GenericBusinessError extends BusinessError {
|
|
59
|
+
constructor(message, options) {
|
|
60
|
+
super("GenericBusinessError", message ?? "Generic Business error", options);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=business.error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"business.error.js","sourceRoot":"","sources":["../../errors/business.error.ts"],"names":[],"mappings":"AAMA,MAAM,OAAgB,aAAc,SAAQ,KAAK;IAC/B,IAAI,CAAU;IACd,IAAI,CAA2B;IAC/B,KAAK,CAAW;IAEhC,YAAsB,IAAY,EAAE,OAAgB,EAAE,OAA8B;QAClF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,CAAC;QAE5B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAElD,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;QAC5C,CAAC;QAED,6CAA6C;QAC7C,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;YACzB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE;gBACnC,KAAK,EAAE,KAAK;gBACZ,UAAU,EAAE,IAAI;gBAChB,QAAQ,EAAE,IAAI;gBACd,YAAY,EAAE,IAAI;aACnB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,gDAAgD;YAChD,KAAK,EACH,IAAI,CAAC,KAAK,YAAY,KAAK;gBACzB,CAAC,CAAC;oBACE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI;oBACrB,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO;oBAC3B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK;iBACxB;gBACH,CAAC,CAAC,IAAI,CAAC,KAAK;SACjB,CAAC;IACJ,CAAC;CACF;AACD;;;;;;;;;;;;;EAaE;AAEF,MAAM,OAAO,oBAAqB,SAAQ,aAAa;IACrD,YAAY,OAAgB,EAAE,OAA8B;QAC1D,KAAK,CAAC,sBAAsB,EAAE,OAAO,IAAI,wBAAwB,EAAE,OAAO,CAAC,CAAC;IAC9E,CAAC;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BusinessError, BusinessErrorOptions } from "./business.error";
|
|
2
|
+
export declare class NotFoundDomainError extends BusinessError {
|
|
3
|
+
constructor(resourceType: string, resourceId: string | number, message?: string, options?: BusinessErrorOptions);
|
|
4
|
+
get resourceType(): string | undefined;
|
|
5
|
+
get resourceId(): string | number | undefined;
|
|
6
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BusinessError } from "./business.error";
|
|
2
|
+
export class NotFoundDomainError extends BusinessError {
|
|
3
|
+
constructor(resourceType, resourceId, message, options) {
|
|
4
|
+
super("NotFoundDomainError", message ?? `${resourceType} ${resourceId} not found`, { ...options, code: options?.code ?? "RESOURCE_NOT_FOUND", meta: { resourceType, resourceId, ...(options?.meta ?? {}) } });
|
|
5
|
+
}
|
|
6
|
+
get resourceType() {
|
|
7
|
+
return this.meta?.resourceType ?? undefined;
|
|
8
|
+
}
|
|
9
|
+
get resourceId() {
|
|
10
|
+
return this.meta?.resourceId ?? undefined;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=not-found-business.error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"not-found-business.error.js","sourceRoot":"","sources":["../../errors/not-found-business.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAwB,MAAM,kBAAkB,CAAC;AAEvE,MAAM,OAAO,mBAAoB,SAAQ,aAAa;IACpD,YAAY,YAAoB,EAAE,UAA2B,EAAE,OAAgB,EAAE,OAA8B;QAC7G,KAAK,CACH,qBAAqB,EACrB,OAAO,IAAI,GAAG,YAAY,IAAI,UAAU,YAAY,EACpD,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,IAAI,oBAAoB,EAAE,IAAI,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,CAAC,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,EAAE,EAAE,CAC1H,CAAC;IACJ,CAAC;IAED,IAAI,YAAY;QACd,OAAQ,IAAI,CAAC,IAAI,EAAE,YAAuB,IAAI,SAAS,CAAC;IAC1D,CAAC;IAED,IAAI,UAAU;QACZ,OAAQ,IAAI,CAAC,IAAI,EAAE,UAA8B,IAAI,SAAS,CAAC;IACjE,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,cAAc,yBAAyB,CAAC;AACxC,cAAc,mCAAmC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cargolift-cdi/common",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.mjs",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.mjs",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"files": ["dist"],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
21
|
+
"build": "npm run clean && tsc -p tsconfig.json",
|
|
22
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"typescript": "^5.4.0",
|
|
26
|
+
"typescript-eslint": "^8.20.0",
|
|
27
|
+
"@types/node": "^22.10.7"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=18.0.0"
|
|
31
|
+
}
|
|
32
|
+
}
|