@longzai-intelligence/error-core 0.0.1 → 0.0.2

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 CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=class extends Error{constructor(e,t=`DOMAIN_ERROR`,n){super(e),this.code=t,this.context=n,this.name=`DomainError`}toJSON(){return{name:this.name,code:this.code,message:this.message,context:this.context,stack:this.stack}}},t=class extends e{constructor(e,t,n){super(e,`VALIDATION_ERROR`,{field:t,value:n}),this.field=t,this.value=n,this.name=`ValidationError`}},n=class extends e{constructor(e,t){super(`${e} 未找到: ${t}`,`ENTITY_NOT_FOUND`,{entityType:e,entityId:t}),this.entityType=e,this.entityId=t,this.name=`EntityNotFoundError`}},r=class extends e{constructor(e,t,n){super(e,`REPOSITORY_ERROR`,n),this.cause=t,this.name=`RepositoryError`}toJSON(){return{...super.toJSON(),cause:this.cause?.message}}},i=class extends e{constructor(e,t){super(`无权限执行操作: ${t} on ${e}`,`PERMISSION_DENIED`,{resource:e,action:t}),this.resource=e,this.action=t,this.name=`PermissionDeniedError`}},a=class extends e{constructor(e,t){super(e,`BUSINESS_RULE_ERROR`,{rule:t}),this.name=`BusinessRuleError`}},o=class extends e{constructor(e=`并发冲突,请重试`){super(e,`CONCURRENCY_ERROR`),this.name=`ConcurrencyError`}},s=class extends e{constructor(e,t){super(e,`CONFIGURATION_ERROR`,{key:t}),this.key=t,this.name=`ConfigurationError`}},c=class extends e{constructor(e,t,n){super(t,`EXTERNAL_SERVICE_ERROR`,{service:e}),this.service=e,this.name=`ExternalServiceError`,n&&(this.cause=n)}},l=class extends e{constructor(e,t){super(`${e} 已存在: ${t}`,`DUPLICATE_ENTITY`,{entityType:e,entityId:t}),this.entityType=e,this.entityId=t,this.name=`DuplicateEntityError`}},u=class extends e{constructor(e){super(e,`AUTHENTICATION_ERROR`),this.name=`AuthenticationError`}},d=class extends e{constructor(e){super(e,`NOT_FOUND`),this.name=`NotFoundError`}};function f(e,n,r){return new t(e,n,r)}function p(e,t){return new n(e,t)}function m(e,t){return new r(e,t)}function h(e,t){return new i(e,t)}function g(e,t){return new l(e,t)}function _(e){return new u(e)}function v(e){return new d(e)}exports.AuthenticationError=u,exports.BusinessRuleError=a,exports.ConcurrencyError=o,exports.ConfigurationError=s,exports.DomainError=e,exports.DuplicateEntityError=l,exports.EntityNotFoundError=n,exports.ExternalServiceError=c,exports.NotFoundError=d,exports.PermissionDeniedError=i,exports.RepositoryError=r,exports.ValidationError=t,exports.createAuthenticationError=_,exports.createDuplicateEntityError=g,exports.createEntityNotFoundError=p,exports.createNotFoundError=v,exports.createPermissionDeniedError=h,exports.createRepositoryError=m,exports.createValidationError=f;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=class extends Error{constructor(e,t=`DOMAIN_ERROR`,n){super(e),this.code=t,this.context=n,this.name=`DomainError`}toJSON(){return{name:this.name,code:this.code,message:this.message,context:this.context,stack:this.stack}}},t=class extends e{constructor(e,t,n){super(e,`VALIDATION_ERROR`,{field:t,value:n}),this.field=t,this.value=n,this.name=`ValidationError`}},n=class extends e{constructor(e,t){super(`${e} 未找到: ${t}`,`ENTITY_NOT_FOUND`,{entityType:e,entityId:t}),this.entityType=e,this.entityId=t,this.name=`EntityNotFoundError`}};function r(e,t){return new n(e,t)}var i=class extends e{constructor(e,t,n){super(e,`REPOSITORY_ERROR`,n),this.cause=t,this.name=`RepositoryError`}toJSON(){return{...super.toJSON(),cause:this.cause?.message}}};function a(e,t){return new i(e,t)}var o=class extends e{constructor(e,t){super(`无权限执行操作: ${t} on ${e}`,`PERMISSION_DENIED`,{resource:e,action:t}),this.resource=e,this.action=t,this.name=`PermissionDeniedError`}};function s(e,t){return new o(e,t)}var c=class extends e{constructor(e,t){super(e,`BUSINESS_RULE_ERROR`,{rule:t}),this.name=`BusinessRuleError`}},l=class extends e{constructor(e=`并发冲突,请重试`){super(e,`CONCURRENCY_ERROR`),this.name=`ConcurrencyError`}},u=class extends e{constructor(e,t){super(e,`CONFIGURATION_ERROR`,{key:t}),this.key=t,this.name=`ConfigurationError`}},d=class extends e{constructor(e,t,n){super(t,`EXTERNAL_SERVICE_ERROR`,{service:e}),this.service=e,this.name=`ExternalServiceError`,n&&(this.cause=n)}},f=class extends e{constructor(e,t){super(`${e} 已存在: ${t}`,`DUPLICATE_ENTITY`,{entityType:e,entityId:t}),this.entityType=e,this.entityId=t,this.name=`DuplicateEntityError`}};function p(e,t){return new f(e,t)}var m=class extends e{constructor(e){super(e,`AUTHENTICATION_ERROR`),this.name=`AuthenticationError`}};function h(e){return new m(e)}var g=class extends e{constructor(e){super(e,`NOT_FOUND`),this.name=`NotFoundError`}};function _(e){return new g(e)}exports.AuthenticationError=m,exports.BusinessRuleError=c,exports.ConcurrencyError=l,exports.ConfigurationError=u,exports.DomainError=e,exports.DuplicateEntityError=f,exports.EntityNotFoundError=n,exports.ExternalServiceError=d,exports.NotFoundError=g,exports.PermissionDeniedError=o,exports.RepositoryError=i,exports.ValidationError=t,exports.createAuthenticationError=h,exports.createDuplicateEntityError=p,exports.createEntityNotFoundError=r,exports.createNotFoundError=_,exports.createPermissionDeniedError=s,exports.createRepositoryError=a;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/domain.errors.d.ts
1
+ //#region src/errors/domain.errors.d.ts
2
2
  declare abstract class DomainError extends Error {
3
3
  readonly code: string;
4
4
  readonly context?: Record<string, unknown> | undefined;
@@ -6,80 +6,77 @@ declare abstract class DomainError extends Error {
6
6
  toJSON(): object;
7
7
  }
8
8
  //#endregion
9
- //#region src/validation.errors.d.ts
9
+ //#region src/errors/validation.errors.d.ts
10
10
  declare class ValidationError extends DomainError {
11
11
  readonly field?: string | undefined;
12
12
  readonly value?: unknown | undefined;
13
13
  constructor(message: string, field?: string | undefined, value?: unknown | undefined);
14
14
  }
15
15
  //#endregion
16
- //#region src/entity-not-found.errors.d.ts
16
+ //#region src/errors/entity-not-found.errors.d.ts
17
17
  declare class EntityNotFoundError extends DomainError {
18
18
  readonly entityType: string;
19
19
  readonly entityId: string;
20
20
  constructor(entityType: string, entityId: string);
21
21
  }
22
+ declare function createEntityNotFoundError(entityType: string, entityId: string): EntityNotFoundError;
22
23
  //#endregion
23
- //#region src/repository.errors.d.ts
24
+ //#region src/errors/repository.errors.d.ts
24
25
  declare class RepositoryError extends DomainError {
25
26
  readonly cause?: Error | undefined;
26
27
  constructor(message: string, cause?: Error | undefined, context?: Record<string, unknown>);
27
28
  toJSON(): object;
28
29
  }
30
+ declare function createRepositoryError(message: string, cause?: Error): RepositoryError;
29
31
  //#endregion
30
- //#region src/permission-denied.errors.d.ts
32
+ //#region src/errors/permission-denied.errors.d.ts
31
33
  declare class PermissionDeniedError extends DomainError {
32
34
  readonly resource: string;
33
35
  readonly action: string;
34
36
  constructor(resource: string, action: string);
35
37
  }
38
+ declare function createPermissionDeniedError(resource: string, action: string): PermissionDeniedError;
36
39
  //#endregion
37
- //#region src/business-rule.errors.d.ts
40
+ //#region src/errors/business-rule.errors.d.ts
38
41
  declare class BusinessRuleError extends DomainError {
39
42
  constructor(message: string, rule?: string);
40
43
  }
41
44
  //#endregion
42
- //#region src/concurrency.errors.d.ts
45
+ //#region src/errors/concurrency.errors.d.ts
43
46
  declare class ConcurrencyError extends DomainError {
44
47
  constructor(message?: string);
45
48
  }
46
49
  //#endregion
47
- //#region src/configuration.errors.d.ts
50
+ //#region src/errors/configuration.errors.d.ts
48
51
  declare class ConfigurationError extends DomainError {
49
52
  readonly key?: string | undefined;
50
53
  constructor(message: string, key?: string | undefined);
51
54
  }
52
55
  //#endregion
53
- //#region src/external-service.errors.d.ts
56
+ //#region src/errors/external-service.errors.d.ts
54
57
  declare class ExternalServiceError extends DomainError {
55
58
  readonly service: string;
56
59
  constructor(service: string, message: string, cause?: Error);
57
60
  }
58
61
  //#endregion
59
- //#region src/duplicate-entity.errors.d.ts
62
+ //#region src/errors/duplicate-entity.errors.d.ts
60
63
  declare class DuplicateEntityError extends DomainError {
61
64
  readonly entityType: string;
62
65
  readonly entityId: string;
63
66
  constructor(entityType: string, entityId: string);
64
67
  }
68
+ declare function createDuplicateEntityError(entityType: string, entityId: string): DuplicateEntityError;
65
69
  //#endregion
66
- //#region src/authentication.errors.d.ts
70
+ //#region src/errors/authentication.errors.d.ts
67
71
  declare class AuthenticationError extends DomainError {
68
72
  constructor(message: string);
69
73
  }
74
+ declare function createAuthenticationError(message: string): AuthenticationError;
70
75
  //#endregion
71
- //#region src/not-found.errors.d.ts
76
+ //#region src/errors/not-found.errors.d.ts
72
77
  declare class NotFoundError extends DomainError {
73
78
  constructor(message: string);
74
79
  }
75
- //#endregion
76
- //#region src/factories.d.ts
77
- declare function createValidationError(message: string, field?: string, value?: unknown): ValidationError;
78
- declare function createEntityNotFoundError(entityType: string, entityId: string): EntityNotFoundError;
79
- declare function createRepositoryError(message: string, cause?: Error): RepositoryError;
80
- declare function createPermissionDeniedError(resource: string, action: string): PermissionDeniedError;
81
- declare function createDuplicateEntityError(entityType: string, entityId: string): DuplicateEntityError;
82
- declare function createAuthenticationError(message: string): AuthenticationError;
83
80
  declare function createNotFoundError(message: string): NotFoundError;
84
81
  //#endregion
85
- export { AuthenticationError, BusinessRuleError, ConcurrencyError, ConfigurationError, DomainError, DuplicateEntityError, EntityNotFoundError, ExternalServiceError, NotFoundError, PermissionDeniedError, RepositoryError, ValidationError, createAuthenticationError, createDuplicateEntityError, createEntityNotFoundError, createNotFoundError, createPermissionDeniedError, createRepositoryError, createValidationError };
82
+ export { AuthenticationError, BusinessRuleError, ConcurrencyError, ConfigurationError, DomainError, DuplicateEntityError, EntityNotFoundError, ExternalServiceError, NotFoundError, PermissionDeniedError, RepositoryError, ValidationError, createAuthenticationError, createDuplicateEntityError, createEntityNotFoundError, createNotFoundError, createPermissionDeniedError, createRepositoryError };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/domain.errors.d.ts
1
+ //#region src/errors/domain.errors.d.ts
2
2
  declare abstract class DomainError extends Error {
3
3
  readonly code: string;
4
4
  readonly context?: Record<string, unknown> | undefined;
@@ -6,80 +6,77 @@ declare abstract class DomainError extends Error {
6
6
  toJSON(): object;
7
7
  }
8
8
  //#endregion
9
- //#region src/validation.errors.d.ts
9
+ //#region src/errors/validation.errors.d.ts
10
10
  declare class ValidationError extends DomainError {
11
11
  readonly field?: string | undefined;
12
12
  readonly value?: unknown | undefined;
13
13
  constructor(message: string, field?: string | undefined, value?: unknown | undefined);
14
14
  }
15
15
  //#endregion
16
- //#region src/entity-not-found.errors.d.ts
16
+ //#region src/errors/entity-not-found.errors.d.ts
17
17
  declare class EntityNotFoundError extends DomainError {
18
18
  readonly entityType: string;
19
19
  readonly entityId: string;
20
20
  constructor(entityType: string, entityId: string);
21
21
  }
22
+ declare function createEntityNotFoundError(entityType: string, entityId: string): EntityNotFoundError;
22
23
  //#endregion
23
- //#region src/repository.errors.d.ts
24
+ //#region src/errors/repository.errors.d.ts
24
25
  declare class RepositoryError extends DomainError {
25
26
  readonly cause?: Error | undefined;
26
27
  constructor(message: string, cause?: Error | undefined, context?: Record<string, unknown>);
27
28
  toJSON(): object;
28
29
  }
30
+ declare function createRepositoryError(message: string, cause?: Error): RepositoryError;
29
31
  //#endregion
30
- //#region src/permission-denied.errors.d.ts
32
+ //#region src/errors/permission-denied.errors.d.ts
31
33
  declare class PermissionDeniedError extends DomainError {
32
34
  readonly resource: string;
33
35
  readonly action: string;
34
36
  constructor(resource: string, action: string);
35
37
  }
38
+ declare function createPermissionDeniedError(resource: string, action: string): PermissionDeniedError;
36
39
  //#endregion
37
- //#region src/business-rule.errors.d.ts
40
+ //#region src/errors/business-rule.errors.d.ts
38
41
  declare class BusinessRuleError extends DomainError {
39
42
  constructor(message: string, rule?: string);
40
43
  }
41
44
  //#endregion
42
- //#region src/concurrency.errors.d.ts
45
+ //#region src/errors/concurrency.errors.d.ts
43
46
  declare class ConcurrencyError extends DomainError {
44
47
  constructor(message?: string);
45
48
  }
46
49
  //#endregion
47
- //#region src/configuration.errors.d.ts
50
+ //#region src/errors/configuration.errors.d.ts
48
51
  declare class ConfigurationError extends DomainError {
49
52
  readonly key?: string | undefined;
50
53
  constructor(message: string, key?: string | undefined);
51
54
  }
52
55
  //#endregion
53
- //#region src/external-service.errors.d.ts
56
+ //#region src/errors/external-service.errors.d.ts
54
57
  declare class ExternalServiceError extends DomainError {
55
58
  readonly service: string;
56
59
  constructor(service: string, message: string, cause?: Error);
57
60
  }
58
61
  //#endregion
59
- //#region src/duplicate-entity.errors.d.ts
62
+ //#region src/errors/duplicate-entity.errors.d.ts
60
63
  declare class DuplicateEntityError extends DomainError {
61
64
  readonly entityType: string;
62
65
  readonly entityId: string;
63
66
  constructor(entityType: string, entityId: string);
64
67
  }
68
+ declare function createDuplicateEntityError(entityType: string, entityId: string): DuplicateEntityError;
65
69
  //#endregion
66
- //#region src/authentication.errors.d.ts
70
+ //#region src/errors/authentication.errors.d.ts
67
71
  declare class AuthenticationError extends DomainError {
68
72
  constructor(message: string);
69
73
  }
74
+ declare function createAuthenticationError(message: string): AuthenticationError;
70
75
  //#endregion
71
- //#region src/not-found.errors.d.ts
76
+ //#region src/errors/not-found.errors.d.ts
72
77
  declare class NotFoundError extends DomainError {
73
78
  constructor(message: string);
74
79
  }
75
- //#endregion
76
- //#region src/factories.d.ts
77
- declare function createValidationError(message: string, field?: string, value?: unknown): ValidationError;
78
- declare function createEntityNotFoundError(entityType: string, entityId: string): EntityNotFoundError;
79
- declare function createRepositoryError(message: string, cause?: Error): RepositoryError;
80
- declare function createPermissionDeniedError(resource: string, action: string): PermissionDeniedError;
81
- declare function createDuplicateEntityError(entityType: string, entityId: string): DuplicateEntityError;
82
- declare function createAuthenticationError(message: string): AuthenticationError;
83
80
  declare function createNotFoundError(message: string): NotFoundError;
84
81
  //#endregion
85
- export { AuthenticationError, BusinessRuleError, ConcurrencyError, ConfigurationError, DomainError, DuplicateEntityError, EntityNotFoundError, ExternalServiceError, NotFoundError, PermissionDeniedError, RepositoryError, ValidationError, createAuthenticationError, createDuplicateEntityError, createEntityNotFoundError, createNotFoundError, createPermissionDeniedError, createRepositoryError, createValidationError };
82
+ export { AuthenticationError, BusinessRuleError, ConcurrencyError, ConfigurationError, DomainError, DuplicateEntityError, EntityNotFoundError, ExternalServiceError, NotFoundError, PermissionDeniedError, RepositoryError, ValidationError, createAuthenticationError, createDuplicateEntityError, createEntityNotFoundError, createNotFoundError, createPermissionDeniedError, createRepositoryError };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var e=class extends Error{constructor(e,t=`DOMAIN_ERROR`,n){super(e),this.code=t,this.context=n,this.name=`DomainError`}toJSON(){return{name:this.name,code:this.code,message:this.message,context:this.context,stack:this.stack}}},t=class extends e{constructor(e,t,n){super(e,`VALIDATION_ERROR`,{field:t,value:n}),this.field=t,this.value=n,this.name=`ValidationError`}},n=class extends e{constructor(e,t){super(`${e} 未找到: ${t}`,`ENTITY_NOT_FOUND`,{entityType:e,entityId:t}),this.entityType=e,this.entityId=t,this.name=`EntityNotFoundError`}},r=class extends e{constructor(e,t,n){super(e,`REPOSITORY_ERROR`,n),this.cause=t,this.name=`RepositoryError`}toJSON(){return{...super.toJSON(),cause:this.cause?.message}}},i=class extends e{constructor(e,t){super(`无权限执行操作: ${t} on ${e}`,`PERMISSION_DENIED`,{resource:e,action:t}),this.resource=e,this.action=t,this.name=`PermissionDeniedError`}},a=class extends e{constructor(e,t){super(e,`BUSINESS_RULE_ERROR`,{rule:t}),this.name=`BusinessRuleError`}},o=class extends e{constructor(e=`并发冲突,请重试`){super(e,`CONCURRENCY_ERROR`),this.name=`ConcurrencyError`}},s=class extends e{constructor(e,t){super(e,`CONFIGURATION_ERROR`,{key:t}),this.key=t,this.name=`ConfigurationError`}},c=class extends e{constructor(e,t,n){super(t,`EXTERNAL_SERVICE_ERROR`,{service:e}),this.service=e,this.name=`ExternalServiceError`,n&&(this.cause=n)}},l=class extends e{constructor(e,t){super(`${e} 已存在: ${t}`,`DUPLICATE_ENTITY`,{entityType:e,entityId:t}),this.entityType=e,this.entityId=t,this.name=`DuplicateEntityError`}},u=class extends e{constructor(e){super(e,`AUTHENTICATION_ERROR`),this.name=`AuthenticationError`}},d=class extends e{constructor(e){super(e,`NOT_FOUND`),this.name=`NotFoundError`}};function f(e,n,r){return new t(e,n,r)}function p(e,t){return new n(e,t)}function m(e,t){return new r(e,t)}function h(e,t){return new i(e,t)}function g(e,t){return new l(e,t)}function _(e){return new u(e)}function v(e){return new d(e)}export{u as AuthenticationError,a as BusinessRuleError,o as ConcurrencyError,s as ConfigurationError,e as DomainError,l as DuplicateEntityError,n as EntityNotFoundError,c as ExternalServiceError,d as NotFoundError,i as PermissionDeniedError,r as RepositoryError,t as ValidationError,_ as createAuthenticationError,g as createDuplicateEntityError,p as createEntityNotFoundError,v as createNotFoundError,h as createPermissionDeniedError,m as createRepositoryError,f as createValidationError};
1
+ var e=class extends Error{constructor(e,t=`DOMAIN_ERROR`,n){super(e),this.code=t,this.context=n,this.name=`DomainError`}toJSON(){return{name:this.name,code:this.code,message:this.message,context:this.context,stack:this.stack}}},t=class extends e{constructor(e,t,n){super(e,`VALIDATION_ERROR`,{field:t,value:n}),this.field=t,this.value=n,this.name=`ValidationError`}},n=class extends e{constructor(e,t){super(`${e} 未找到: ${t}`,`ENTITY_NOT_FOUND`,{entityType:e,entityId:t}),this.entityType=e,this.entityId=t,this.name=`EntityNotFoundError`}};function r(e,t){return new n(e,t)}var i=class extends e{constructor(e,t,n){super(e,`REPOSITORY_ERROR`,n),this.cause=t,this.name=`RepositoryError`}toJSON(){return{...super.toJSON(),cause:this.cause?.message}}};function a(e,t){return new i(e,t)}var o=class extends e{constructor(e,t){super(`无权限执行操作: ${t} on ${e}`,`PERMISSION_DENIED`,{resource:e,action:t}),this.resource=e,this.action=t,this.name=`PermissionDeniedError`}};function s(e,t){return new o(e,t)}var c=class extends e{constructor(e,t){super(e,`BUSINESS_RULE_ERROR`,{rule:t}),this.name=`BusinessRuleError`}},l=class extends e{constructor(e=`并发冲突,请重试`){super(e,`CONCURRENCY_ERROR`),this.name=`ConcurrencyError`}},u=class extends e{constructor(e,t){super(e,`CONFIGURATION_ERROR`,{key:t}),this.key=t,this.name=`ConfigurationError`}},d=class extends e{constructor(e,t,n){super(t,`EXTERNAL_SERVICE_ERROR`,{service:e}),this.service=e,this.name=`ExternalServiceError`,n&&(this.cause=n)}},f=class extends e{constructor(e,t){super(`${e} 已存在: ${t}`,`DUPLICATE_ENTITY`,{entityType:e,entityId:t}),this.entityType=e,this.entityId=t,this.name=`DuplicateEntityError`}};function p(e,t){return new f(e,t)}var m=class extends e{constructor(e){super(e,`AUTHENTICATION_ERROR`),this.name=`AuthenticationError`}};function h(e){return new m(e)}var g=class extends e{constructor(e){super(e,`NOT_FOUND`),this.name=`NotFoundError`}};function _(e){return new g(e)}export{m as AuthenticationError,c as BusinessRuleError,l as ConcurrencyError,u as ConfigurationError,e as DomainError,f as DuplicateEntityError,n as EntityNotFoundError,d as ExternalServiceError,g as NotFoundError,o as PermissionDeniedError,i as RepositoryError,t as ValidationError,h as createAuthenticationError,p as createDuplicateEntityError,r as createEntityNotFoundError,_ as createNotFoundError,s as createPermissionDeniedError,a as createRepositoryError};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longzai-intelligence/error-core",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "types": "./dist/index.d.mts",