@alanszp/errors 11.0.0 → 12.0.1

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.
Files changed (85) hide show
  1. package/dist/BaseError.js.map +1 -0
  2. package/dist/HttpRenderableError.d.ts +4 -0
  3. package/dist/HttpRenderableError.js +8 -0
  4. package/dist/HttpRenderableError.js.map +1 -0
  5. package/dist/InternalServerError.d.ts +8 -0
  6. package/dist/InternalServerError.js +24 -0
  7. package/dist/InternalServerError.js.map +1 -0
  8. package/dist/RenderableError.d.ts +15 -0
  9. package/dist/RenderableError.js +27 -0
  10. package/dist/RenderableError.js.map +1 -0
  11. package/dist/index.d.ts +4 -3
  12. package/dist/index.js +4 -3
  13. package/dist/index.js.map +1 -1
  14. package/node_modules/@alanszp/core/.gitignore +3 -0
  15. package/node_modules/@alanszp/core/.npmignore +3 -0
  16. package/node_modules/@alanszp/core/LICENSE +21 -0
  17. package/node_modules/@alanszp/core/dist/app/appIdentifier.d.ts +1 -0
  18. package/node_modules/@alanszp/core/dist/app/appIdentifier.js +10 -0
  19. package/node_modules/@alanszp/core/dist/app/appIdentifier.js.map +1 -0
  20. package/node_modules/@alanszp/core/dist/app/index.d.ts +1 -0
  21. package/{dist/errors/http → node_modules/@alanszp/core/dist/app}/index.js +6 -6
  22. package/node_modules/@alanszp/core/dist/app/index.js.map +1 -0
  23. package/node_modules/@alanszp/core/dist/assignKey.d.ts +2 -0
  24. package/node_modules/@alanszp/core/dist/assignKey.js +20 -0
  25. package/node_modules/@alanszp/core/dist/assignKey.js.map +1 -0
  26. package/node_modules/@alanszp/core/dist/editable/index.d.ts +2 -0
  27. package/node_modules/@alanszp/core/dist/editable/index.js +19 -0
  28. package/node_modules/@alanszp/core/dist/editable/index.js.map +1 -0
  29. package/node_modules/@alanszp/core/dist/editable/keepOrUpdate.d.ts +3 -0
  30. package/node_modules/@alanszp/core/dist/editable/keepOrUpdate.js +26 -0
  31. package/node_modules/@alanszp/core/dist/editable/keepOrUpdate.js.map +1 -0
  32. package/node_modules/@alanszp/core/dist/editable/types.d.ts +6 -0
  33. package/{dist/errors/RenderableError.js → node_modules/@alanszp/core/dist/editable/types.js} +1 -1
  34. package/node_modules/@alanszp/core/dist/editable/types.js.map +1 -0
  35. package/node_modules/@alanszp/core/dist/index.d.ts +4 -0
  36. package/node_modules/@alanszp/core/dist/index.js +21 -0
  37. package/node_modules/@alanszp/core/dist/index.js.map +1 -0
  38. package/node_modules/@alanszp/core/dist/lists/ListResult.d.ts +7 -0
  39. package/node_modules/@alanszp/core/dist/lists/ListResult.js +8 -0
  40. package/node_modules/@alanszp/core/dist/lists/ListResult.js.map +1 -0
  41. package/node_modules/@alanszp/core/dist/lists/Orderable.d.ts +11 -0
  42. package/node_modules/@alanszp/core/dist/lists/Orderable.js +13 -0
  43. package/node_modules/@alanszp/core/dist/lists/Orderable.js.map +1 -0
  44. package/node_modules/@alanszp/core/dist/lists/Paginable.d.ts +14 -0
  45. package/node_modules/@alanszp/core/dist/lists/Paginable.js +22 -0
  46. package/node_modules/@alanszp/core/dist/lists/Paginable.js.map +1 -0
  47. package/node_modules/@alanszp/core/dist/lists/index.d.ts +3 -0
  48. package/node_modules/@alanszp/core/dist/lists/index.js +20 -0
  49. package/node_modules/@alanszp/core/dist/lists/index.js.map +1 -0
  50. package/node_modules/@alanszp/core/package.json +25 -0
  51. package/node_modules/@alanszp/core/tsconfig.json +15 -0
  52. package/package.json +9 -2
  53. package/src/HttpRenderableError.ts +5 -0
  54. package/src/{errors/http/InternalServerError.ts → InternalServerError.ts} +8 -10
  55. package/src/RenderableError.ts +37 -0
  56. package/src/index.ts +4 -3
  57. package/dist/errors/BaseError.js.map +0 -1
  58. package/dist/errors/RenderableError.d.ts +0 -6
  59. package/dist/errors/RenderableError.js.map +0 -1
  60. package/dist/errors/http/BadRequestError.d.ts +0 -8
  61. package/dist/errors/http/BadRequestError.js +0 -20
  62. package/dist/errors/http/BadRequestError.js.map +0 -1
  63. package/dist/errors/http/HttpError.d.ts +0 -8
  64. package/dist/errors/http/HttpError.js +0 -18
  65. package/dist/errors/http/HttpError.js.map +0 -1
  66. package/dist/errors/http/InternalServerError.d.ts +0 -8
  67. package/dist/errors/http/InternalServerError.js +0 -32
  68. package/dist/errors/http/InternalServerError.js.map +0 -1
  69. package/dist/errors/http/NotFoundError.d.ts +0 -4
  70. package/dist/errors/http/NotFoundError.js +0 -11
  71. package/dist/errors/http/NotFoundError.js.map +0 -1
  72. package/dist/errors/http/UnauthorizedError.d.ts +0 -8
  73. package/dist/errors/http/UnauthorizedError.js +0 -20
  74. package/dist/errors/http/UnauthorizedError.js.map +0 -1
  75. package/dist/errors/http/index.d.ts +0 -5
  76. package/dist/errors/http/index.js.map +0 -1
  77. package/src/errors/RenderableError.ts +0 -7
  78. package/src/errors/http/BadRequestError.ts +0 -21
  79. package/src/errors/http/HttpError.ts +0 -19
  80. package/src/errors/http/NotFoundError.ts +0 -7
  81. package/src/errors/http/UnauthorizedError.ts +0 -21
  82. package/src/errors/http/index.ts +0 -5
  83. /package/dist/{errors/BaseError.d.ts → BaseError.d.ts} +0 -0
  84. /package/dist/{errors/BaseError.js → BaseError.js} +0 -0
  85. /package/src/{errors/BaseError.ts → BaseError.ts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseError.js","sourceRoot":"","sources":["../src/BaseError.ts"],"names":[],"mappings":";;;AAAA,MAAa,SAAU,SAAQ,KAAK;IAClC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,IAAI,OAAO,KAAK,CAAC,iBAAiB,KAAK,UAAU,EAAE;YACjD,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;SACjD;aAAM;YACL,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC;SAC5C;QAED,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC;CACF;AAbD,8BAaC"}
@@ -0,0 +1,4 @@
1
+ import { RenderableError } from "./RenderableError";
2
+ export declare abstract class HttpRenderableError extends RenderableError {
3
+ abstract httpCode(): number;
4
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpRenderableError = void 0;
4
+ const RenderableError_1 = require("./RenderableError");
5
+ class HttpRenderableError extends RenderableError_1.RenderableError {
6
+ }
7
+ exports.HttpRenderableError = HttpRenderableError;
8
+ //# sourceMappingURL=HttpRenderableError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpRenderableError.js","sourceRoot":"","sources":["../src/HttpRenderableError.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AAEpD,MAAsB,mBAAoB,SAAQ,iCAAe;CAEhE;AAFD,kDAEC"}
@@ -0,0 +1,8 @@
1
+ import { HttpRenderableError } from "./HttpRenderableError";
2
+ import { RenderableContext } from "./RenderableError";
3
+ export declare class InternalServerError extends HttpRenderableError {
4
+ error: any;
5
+ constructor(error?: unknown);
6
+ httpCode(): number;
7
+ context(): RenderableContext;
8
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InternalServerError = void 0;
4
+ const HttpRenderableError_1 = require("./HttpRenderableError");
5
+ const RenderableError_1 = require("./RenderableError");
6
+ class InternalServerError extends HttpRenderableError_1.HttpRenderableError {
7
+ constructor(error) {
8
+ super("Internal Server Error");
9
+ this.error = error;
10
+ }
11
+ httpCode() {
12
+ return 500;
13
+ }
14
+ context() {
15
+ if (process.env.NODE_ENV === "production") {
16
+ return {};
17
+ }
18
+ return {
19
+ error: Object.assign(Object.assign({ name: this.error.name, message: this.error.message }, (this.error instanceof RenderableError_1.RenderableError ? this.error.toView() : {})), { status: this.error.status, signal: this.error.signal, stack: this.error.stack }),
20
+ };
21
+ }
22
+ }
23
+ exports.InternalServerError = InternalServerError;
24
+ //# sourceMappingURL=InternalServerError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InternalServerError.js","sourceRoot":"","sources":["../src/InternalServerError.ts"],"names":[],"mappings":";;;AAAA,+DAA4D;AAC5D,uDAAuE;AAEvE,MAAa,mBAAoB,SAAQ,yCAAmB;IAG1D,YAAY,KAAe;QACzB,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAC/B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,QAAQ;QACN,OAAO,GAAG,CAAC;IACb,CAAC;IAEM,OAAO;QACZ,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;YACzC,OAAO,EAAE,CAAC;SACX;QAED,OAAO;YACL,KAAK,gCACH,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,EACrB,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,IACxB,CAAC,IAAI,CAAC,KAAK,YAAY,iCAAe,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KACrE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,EACzB,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,EACzB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GACxB;SACF,CAAC;IACJ,CAAC;CACF;AA5BD,kDA4BC"}
@@ -0,0 +1,15 @@
1
+ import { BaseError } from "./BaseError";
2
+ export declare type RenderableContext = Record<string, unknown>;
3
+ export interface RenderableView {
4
+ code: string;
5
+ message: string;
6
+ context: RenderableContext;
7
+ origin: string;
8
+ }
9
+ export declare abstract class RenderableError extends BaseError {
10
+ constructor(renderMessage: string);
11
+ code(): string;
12
+ renderMessage(): string;
13
+ toView(): Record<string, unknown>;
14
+ abstract context(): RenderableContext;
15
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RenderableError = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const core_1 = require("@alanszp/core");
6
+ const BaseError_1 = require("./BaseError");
7
+ class RenderableError extends BaseError_1.BaseError {
8
+ constructor(renderMessage) {
9
+ super(renderMessage);
10
+ }
11
+ code() {
12
+ return (0, lodash_1.snakeCase)(this.message);
13
+ }
14
+ renderMessage() {
15
+ return this.message;
16
+ }
17
+ toView() {
18
+ return {
19
+ code: this.code(),
20
+ message: this.renderMessage(),
21
+ context: this.context(),
22
+ origin: (0, core_1.appIdentifier)(),
23
+ };
24
+ }
25
+ }
26
+ exports.RenderableError = RenderableError;
27
+ //# sourceMappingURL=RenderableError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RenderableError.js","sourceRoot":"","sources":["../src/RenderableError.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AACnC,wCAA8C;AAC9C,2CAAwC;AAWxC,MAAsB,eAAgB,SAAQ,qBAAS;IACrD,YAAY,aAAqB;QAC/B,KAAK,CAAC,aAAa,CAAC,CAAC;IACvB,CAAC;IAED,IAAI;QACF,OAAO,IAAA,kBAAS,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE;YACjB,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE;YAC7B,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;YACvB,MAAM,EAAE,IAAA,oBAAa,GAAE;SACxB,CAAC;IACJ,CAAC;CAGF;AAvBD,0CAuBC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- export * from "./errors/BaseError";
2
- export * from "./errors/RenderableError";
3
- export * from "./errors/http";
1
+ export * from "./BaseError";
2
+ export * from "./RenderableError";
3
+ export * from "./HttpRenderableError";
4
+ export * from "./InternalServerError";
package/dist/index.js CHANGED
@@ -10,7 +10,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./errors/BaseError"), exports);
14
- __exportStar(require("./errors/RenderableError"), exports);
15
- __exportStar(require("./errors/http"), exports);
13
+ __exportStar(require("./BaseError"), exports);
14
+ __exportStar(require("./RenderableError"), exports);
15
+ __exportStar(require("./HttpRenderableError"), exports);
16
+ __exportStar(require("./InternalServerError"), exports);
16
17
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAmC;AACnC,2DAAyC;AACzC,gDAA8B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAA4B;AAC5B,oDAAkC;AAClC,wDAAsC;AACtC,wDAAsC"}
@@ -0,0 +1,3 @@
1
+ node_modules
2
+ *.log
3
+ dist
@@ -0,0 +1,3 @@
1
+ node_modules
2
+ src
3
+ *.log
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Alan Szpigiel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ export declare function appIdentifier(): string;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.appIdentifier = void 0;
4
+ function appIdentifier() {
5
+ const appName = process.env.API_ORIGIN_NAME || "undefined";
6
+ const env = process.env.NODE_ENV || "development";
7
+ return `${appName}:${env}`;
8
+ }
9
+ exports.appIdentifier = appIdentifier;
10
+ //# sourceMappingURL=appIdentifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appIdentifier.js","sourceRoot":"","sources":["../../src/app/appIdentifier.ts"],"names":[],"mappings":";;;AAAA,SAAgB,aAAa;IAC3B,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,WAAW,CAAC;IAC3D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC;IAClD,OAAO,GAAG,OAAO,IAAI,GAAG,EAAE,CAAC;AAC7B,CAAC;AAJD,sCAIC"}
@@ -0,0 +1 @@
1
+ export * from "./appIdentifier";
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -10,9 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
15
  };
12
16
  Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./HttpError"), exports);
14
- __exportStar(require("./BadRequestError"), exports);
15
- __exportStar(require("./UnauthorizedError"), exports);
16
- __exportStar(require("./InternalServerError"), exports);
17
- __exportStar(require("./NotFoundError"), exports);
17
+ __exportStar(require("./appIdentifier"), exports);
18
18
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/app/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC"}
@@ -0,0 +1,2 @@
1
+ export declare function assignKey<CommonInterface, Key extends keyof CommonInterface>(target: CommonInterface, source: CommonInterface, key: Key, defaultValue?: CommonInterface[Key]): void;
2
+ export declare function assignKeys<CommonInterface>(target: CommonInterface, source: CommonInterface, keys: (keyof CommonInterface)[]): void;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assignKeys = exports.assignKey = void 0;
4
+ function assignKey(target, source, key, defaultValue) {
5
+ if (source[key] !== undefined) {
6
+ target[key] = source[key];
7
+ return;
8
+ }
9
+ if (defaultValue !== undefined) {
10
+ target[key] = defaultValue;
11
+ }
12
+ }
13
+ exports.assignKey = assignKey;
14
+ function assignKeys(target, source, keys) {
15
+ keys.forEach((key) => {
16
+ assignKey(target, source, key);
17
+ });
18
+ }
19
+ exports.assignKeys = assignKeys;
20
+ //# sourceMappingURL=assignKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assignKey.js","sourceRoot":"","sources":["../src/assignKey.ts"],"names":[],"mappings":";;;AAAA,SAAgB,SAAS,CACvB,MAAuB,EACvB,MAAuB,EACvB,GAAQ,EACR,YAAmC;IAEnC,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE;QAC7B,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,OAAO;KACR;IAED,IAAI,YAAY,KAAK,SAAS,EAAE;QAC9B,MAAM,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC;KAC5B;AACH,CAAC;AAdD,8BAcC;AAED,SAAgB,UAAU,CACxB,MAAuB,EACvB,MAAuB,EACvB,IAA+B;IAE/B,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACnB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC;AARD,gCAQC"}
@@ -0,0 +1,2 @@
1
+ export * from "./keepOrUpdate";
2
+ export * from "./types";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./keepOrUpdate"), exports);
18
+ __exportStar(require("./types"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/editable/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,0CAAwB"}
@@ -0,0 +1,3 @@
1
+ import { EditableAndNullableField } from "./types";
2
+ export declare function keepOrUpdate<FieldType extends unknown, EditionType extends unknown>(defined: FieldType, value: EditableAndNullableField<EditionType>, formatter?: (value: EditionType) => FieldType): FieldType | null;
3
+ export declare function keepOrUpdateAsync<FieldType extends unknown, EditionType extends unknown>(defined: FieldType, value: EditableAndNullableField<EditionType>, formatter?: (value: EditionType) => Promise<FieldType>): Promise<FieldType | null>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.keepOrUpdateAsync = exports.keepOrUpdate = void 0;
4
+ function id(param) {
5
+ return param;
6
+ }
7
+ function idAsync(param) {
8
+ return param;
9
+ }
10
+ function keepOrUpdate(defined, value, formatter = id) {
11
+ if (value === undefined)
12
+ return defined;
13
+ if (value === null)
14
+ return null;
15
+ return formatter(value);
16
+ }
17
+ exports.keepOrUpdate = keepOrUpdate;
18
+ function keepOrUpdateAsync(defined, value, formatter = idAsync) {
19
+ if (value === undefined)
20
+ return Promise.resolve(defined);
21
+ if (value === null)
22
+ return Promise.resolve(null);
23
+ return formatter(value);
24
+ }
25
+ exports.keepOrUpdateAsync = keepOrUpdateAsync;
26
+ //# sourceMappingURL=keepOrUpdate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keepOrUpdate.js","sourceRoot":"","sources":["../../src/editable/keepOrUpdate.ts"],"names":[],"mappings":";;;AAEA,SAAS,EAAE,CACT,KAAkB;IAElB,OAAO,KAA6B,CAAC;AACvC,CAAC;AACD,SAAS,OAAO,CACd,KAAkB;IAElB,OAAO,KAA2B,CAAC;AACrC,CAAC;AAED,SAAgB,YAAY,CAI1B,OAAkB,EAClB,KAA4C,EAC5C,YAA+C,EAAE;IAEjD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC;IAExC,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAEhC,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC;AAbD,oCAaC;AAED,SAAgB,iBAAiB,CAI/B,OAAkB,EAClB,KAA4C,EAC5C,YAAwD,OAAO;IAE/D,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEzD,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjD,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC;AAbD,8CAaC"}
@@ -0,0 +1,6 @@
1
+ export declare type JustEditableField<T> = T | undefined;
2
+ export declare type EditableAndNullableField<T> = T | undefined | null;
3
+ export declare type EditableField<T> = T extends undefined | null ? EditableAndNullableField<T> : JustEditableField<T>;
4
+ export declare type EditableObject<T> = {
5
+ [key in keyof T]: EditableField<T[key]>;
6
+ };
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=RenderableError.js.map
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/editable/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export * from "./assignKey";
2
+ export * from "./lists";
3
+ export * from "./editable";
4
+ export * from "./app";
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./assignKey"), exports);
18
+ __exportStar(require("./lists"), exports);
19
+ __exportStar(require("./editable"), exports);
20
+ __exportStar(require("./app"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,0CAAwB;AACxB,6CAA2B;AAC3B,wCAAsB"}
@@ -0,0 +1,7 @@
1
+ export interface ListResult<Result> {
2
+ elements: Result[];
3
+ total: number;
4
+ page: number;
5
+ pageSize: number;
6
+ }
7
+ export declare function mapListResult<T, R>(list: ListResult<T>, mapper: (elem: T) => R): ListResult<R>;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapListResult = void 0;
4
+ function mapListResult(list, mapper) {
5
+ return Object.assign(Object.assign({}, list), { elements: list.elements.map((c) => mapper(c)) });
6
+ }
7
+ exports.mapListResult = mapListResult;
8
+ //# sourceMappingURL=ListResult.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ListResult.js","sourceRoot":"","sources":["../../src/lists/ListResult.ts"],"names":[],"mappings":";;;AAOA,SAAgB,aAAa,CAC3B,IAAmB,EACnB,MAAsB;IAEtB,uCACK,IAAI,KACP,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAC7C;AACJ,CAAC;AARD,sCAQC"}
@@ -0,0 +1,11 @@
1
+ export declare type OrderDirection = "ASC" | "DESC";
2
+ export declare const ORDER_DIRECTIONS: string[];
3
+ export interface Orderable<T extends string | number | symbol = "id"> {
4
+ orderBy: T;
5
+ orderDirection: OrderDirection;
6
+ }
7
+ export declare function getOrderObject<K extends string | number | symbol, T extends Orderable<K>>(object: T): {
8
+ order: {
9
+ [x: string]: OrderDirection;
10
+ };
11
+ };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOrderObject = exports.ORDER_DIRECTIONS = void 0;
4
+ exports.ORDER_DIRECTIONS = ["ASC", "DESC"];
5
+ function getOrderObject(object) {
6
+ return {
7
+ order: {
8
+ [object.orderBy]: object.orderDirection,
9
+ },
10
+ };
11
+ }
12
+ exports.getOrderObject = getOrderObject;
13
+ //# sourceMappingURL=Orderable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Orderable.js","sourceRoot":"","sources":["../../src/lists/Orderable.ts"],"names":[],"mappings":";;;AAEa,QAAA,gBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAOhD,SAAgB,cAAc,CAG5B,MAAS;IACT,OAAO;QACL,KAAK,EAAE;YACL,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,cAAc;SACxC;KACF,CAAC;AACJ,CAAC;AATD,wCASC"}
@@ -0,0 +1,14 @@
1
+ export interface Paginable<Validated extends boolean = false> {
2
+ pageSize: Validated extends true ? number : number | string;
3
+ page: Validated extends true ? number : number | string;
4
+ }
5
+ export declare function getPageObject<T extends Paginable<true>>(object: T): {
6
+ skip: number;
7
+ take: number;
8
+ };
9
+ /**
10
+ * Assigns the page and pageSize keys to the target object
11
+ * @param target Paginable Input
12
+ * @param source Paginable Source
13
+ */
14
+ export declare function assignPaginableKeys<T extends Paginable<false>, K extends Partial<Paginable<false>>>(target: T, source: K): void;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assignPaginableKeys = exports.getPageObject = void 0;
4
+ function getPageObject(object) {
5
+ return {
6
+ skip: (object.page - 1) * object.pageSize,
7
+ take: object.pageSize,
8
+ };
9
+ }
10
+ exports.getPageObject = getPageObject;
11
+ /**
12
+ * Assigns the page and pageSize keys to the target object
13
+ * @param target Paginable Input
14
+ * @param source Paginable Source
15
+ */
16
+ function assignPaginableKeys(target, source) {
17
+ // Mind the || operator, it's on purpose to avoid the 0 value (cause falsy value)
18
+ target.page = Number.parseInt(source.page, 10) || 1;
19
+ target.pageSize = Number.parseInt(source.pageSize, 10) || 100;
20
+ }
21
+ exports.assignPaginableKeys = assignPaginableKeys;
22
+ //# sourceMappingURL=Paginable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Paginable.js","sourceRoot":"","sources":["../../src/lists/Paginable.ts"],"names":[],"mappings":";;;AAKA,SAAgB,aAAa,CAA4B,MAAS;IAChE,OAAO;QACL,IAAI,EAAE,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,QAAQ;QACzC,IAAI,EAAE,MAAM,CAAC,QAAQ;KACtB,CAAC;AACJ,CAAC;AALD,sCAKC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAGjC,MAAS,EAAE,MAAS;IACpB,iFAAiF;IACjF,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAc,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;IAC9D,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAkB,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC;AAC1E,CAAC;AAPD,kDAOC"}
@@ -0,0 +1,3 @@
1
+ export * from "./ListResult";
2
+ export * from "./Orderable";
3
+ export * from "./Paginable";
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ListResult"), exports);
18
+ __exportStar(require("./Orderable"), exports);
19
+ __exportStar(require("./Paginable"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lists/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,8CAA4B;AAC5B,8CAA4B"}
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@alanszp/core",
3
+ "version": "11.0.0",
4
+ "description": "Alan's core TS/JS lib.",
5
+ "main": "dist/index.js",
6
+ "typings": "dist/index.d.ts",
7
+ "license": "MIT",
8
+ "files": [
9
+ "**/*"
10
+ ],
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "scripts": {
15
+ "compile": "rm -rf ./dist && tsc --declaration",
16
+ "compile-watch": "tsc -w",
17
+ "build": "yarn run compile",
18
+ "prepack": "yarn run build",
19
+ "yalc-publish": "yarn run yalc publish"
20
+ },
21
+ "devDependencies": {
22
+ "@types/node": "^20.11.17"
23
+ },
24
+ "gitHead": "60b62fa2fff34ef094ea9af69c2bed2373c70f64"
25
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": "src",
4
+ "outDir": "dist",
5
+ "module": "commonjs",
6
+ "target": "es6",
7
+ "types": ["node"],
8
+ "esModuleInterop": true,
9
+ "sourceMap": true,
10
+
11
+ "alwaysStrict": true,
12
+ "strictNullChecks": true
13
+ },
14
+ "exclude": ["node_modules"]
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alanszp/errors",
3
- "version": "11.0.0",
3
+ "version": "12.0.1",
4
4
  "description": "Alan's basic errors classes.",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -18,10 +18,17 @@
18
18
  "prepack": "yarn run build",
19
19
  "yalc-publish": "yarn run yalc publish"
20
20
  },
21
+ "peerDependencies": {
22
+ "@alanszp/errors": ">=12.0.0"
23
+ },
21
24
  "devDependencies": {
25
+ "@alanszp/core": "^12.0.0",
22
26
  "@types/node": "^20.11.17",
23
27
  "ts-node": "^10.0.0",
24
28
  "typescript": "^4.3.4"
25
29
  },
26
- "gitHead": "60b62fa2fff34ef094ea9af69c2bed2373c70f64"
30
+ "dependencies": {
31
+ "lodash": "^4.17.21"
32
+ },
33
+ "gitHead": "2320e554850aec120e0e8bc71c00a2197187af40"
27
34
  }
@@ -0,0 +1,5 @@
1
+ import { RenderableError } from "./RenderableError";
2
+
3
+ export abstract class HttpRenderableError extends RenderableError {
4
+ abstract httpCode(): number;
5
+ }
@@ -1,16 +1,16 @@
1
- import { RenderableContext } from "../RenderableError";
2
- import { HttpError } from "./HttpError";
1
+ import { HttpRenderableError } from "./HttpRenderableError";
2
+ import { RenderableContext, RenderableError } from "./RenderableError";
3
3
 
4
- export class InternalServerError extends HttpError {
4
+ export class InternalServerError extends HttpRenderableError {
5
5
  public error;
6
6
 
7
7
  constructor(error?: unknown) {
8
- super();
8
+ super("Internal Server Error");
9
9
  this.error = error;
10
10
  }
11
11
 
12
- public renderMessage(): string {
13
- return "Internal Server Error";
12
+ httpCode(): number {
13
+ return 500;
14
14
  }
15
15
 
16
16
  public context(): RenderableContext {
@@ -22,12 +22,10 @@ export class InternalServerError extends HttpError {
22
22
  error: {
23
23
  name: this.error.name,
24
24
  message: this.error.message,
25
- code: this.error.code,
26
- context: this.error.context,
27
- renderMessage: this.error.renderMessage,
28
- stack: this.error.stack,
25
+ ...(this.error instanceof RenderableError ? this.error.toView() : {}),
29
26
  status: this.error.status,
30
27
  signal: this.error.signal,
28
+ stack: this.error.stack,
31
29
  },
32
30
  };
33
31
  }
@@ -0,0 +1,37 @@
1
+ import { snakeCase } from "lodash";
2
+ import { appIdentifier } from "@alanszp/core";
3
+ import { BaseError } from "./BaseError";
4
+
5
+ export type RenderableContext = Record<string, unknown>;
6
+
7
+ export interface RenderableView {
8
+ code: string;
9
+ message: string;
10
+ context: RenderableContext;
11
+ origin: string;
12
+ }
13
+
14
+ export abstract class RenderableError extends BaseError {
15
+ constructor(renderMessage: string) {
16
+ super(renderMessage);
17
+ }
18
+
19
+ code(): string {
20
+ return snakeCase(this.message);
21
+ }
22
+
23
+ renderMessage(): string {
24
+ return this.message;
25
+ }
26
+
27
+ toView(): Record<string, unknown> {
28
+ return {
29
+ code: this.code(),
30
+ message: this.renderMessage(),
31
+ context: this.context(),
32
+ origin: appIdentifier(),
33
+ };
34
+ }
35
+
36
+ abstract context(): RenderableContext;
37
+ }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
- export * from "./errors/BaseError";
2
- export * from "./errors/RenderableError";
3
- export * from "./errors/http";
1
+ export * from "./BaseError";
2
+ export * from "./RenderableError";
3
+ export * from "./HttpRenderableError";
4
+ export * from "./InternalServerError";
@@ -1 +0,0 @@
1
- {"version":3,"file":"BaseError.js","sourceRoot":"","sources":["../../src/errors/BaseError.ts"],"names":[],"mappings":";;;AAAA,MAAa,SAAU,SAAQ,KAAK;IAClC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,IAAI,OAAO,KAAK,CAAC,iBAAiB,KAAK,UAAU,EAAE;YACjD,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;SACjD;aAAM;YACL,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC;SAC5C;QAED,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC;CACF;AAbD,8BAaC"}
@@ -1,6 +0,0 @@
1
- export declare type RenderableContext = Record<string, unknown>;
2
- export interface RenderableError {
3
- code(): string;
4
- renderMessage(): string;
5
- context(): RenderableContext;
6
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"RenderableError.js","sourceRoot":"","sources":["../../src/errors/RenderableError.ts"],"names":[],"mappings":""}
@@ -1,8 +0,0 @@
1
- import { RenderableContext } from "../RenderableError";
2
- import { HttpError } from "./HttpError";
3
- export declare class BadRequestError extends HttpError {
4
- private errors;
5
- constructor(errors: string[] | string);
6
- renderMessage(): string;
7
- context(): RenderableContext;
8
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BadRequestError = void 0;
4
- const HttpError_1 = require("./HttpError");
5
- class BadRequestError extends HttpError_1.HttpError {
6
- constructor(errors) {
7
- super();
8
- this.errors = errors;
9
- }
10
- renderMessage() {
11
- return "Bad Request";
12
- }
13
- context() {
14
- return {
15
- errors: this.errors,
16
- };
17
- }
18
- }
19
- exports.BadRequestError = BadRequestError;
20
- //# sourceMappingURL=BadRequestError.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BadRequestError.js","sourceRoot":"","sources":["../../../src/errors/http/BadRequestError.ts"],"names":[],"mappings":";;;AACA,2CAAwC;AAExC,MAAa,eAAgB,SAAQ,qBAAS;IAG5C,YAAmB,MAAyB;QAC1C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEM,aAAa;QAClB,OAAO,aAAa,CAAC;IACvB,CAAC;IAEM,OAAO;QACZ,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC;IACJ,CAAC;CACF;AAjBD,0CAiBC"}
@@ -1,8 +0,0 @@
1
- import { BaseError } from "../BaseError";
2
- import { RenderableContext, RenderableError } from "../RenderableError";
3
- export declare abstract class HttpError extends BaseError implements RenderableError {
4
- constructor();
5
- abstract renderMessage(): string;
6
- code(): string;
7
- context(): RenderableContext;
8
- }
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpError = void 0;
4
- const lodash_1 = require("lodash");
5
- const BaseError_1 = require("../BaseError");
6
- class HttpError extends BaseError_1.BaseError {
7
- constructor() {
8
- super("HttpError");
9
- }
10
- code() {
11
- return (0, lodash_1.snakeCase)(this.renderMessage());
12
- }
13
- context() {
14
- return {};
15
- }
16
- }
17
- exports.HttpError = HttpError;
18
- //# sourceMappingURL=HttpError.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"HttpError.js","sourceRoot":"","sources":["../../../src/errors/http/HttpError.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AACnC,4CAAyC;AAGzC,MAAsB,SAAU,SAAQ,qBAAS;IAC/C;QACE,KAAK,CAAC,WAAW,CAAC,CAAC;IACrB,CAAC;IAIM,IAAI;QACT,OAAO,IAAA,kBAAS,EAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;IACzC,CAAC;IAEM,OAAO;QACZ,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AAdD,8BAcC"}
@@ -1,8 +0,0 @@
1
- import { RenderableContext } from "../RenderableError";
2
- import { HttpError } from "./HttpError";
3
- export declare class InternalServerError extends HttpError {
4
- error: any;
5
- constructor(error?: unknown);
6
- renderMessage(): string;
7
- context(): RenderableContext;
8
- }
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InternalServerError = void 0;
4
- const HttpError_1 = require("./HttpError");
5
- class InternalServerError extends HttpError_1.HttpError {
6
- constructor(error) {
7
- super();
8
- this.error = error;
9
- }
10
- renderMessage() {
11
- return "Internal Server Error";
12
- }
13
- context() {
14
- if (process.env.NODE_ENV === "production") {
15
- return {};
16
- }
17
- return {
18
- error: {
19
- name: this.error.name,
20
- message: this.error.message,
21
- code: this.error.code,
22
- context: this.error.context,
23
- renderMessage: this.error.renderMessage,
24
- stack: this.error.stack,
25
- status: this.error.status,
26
- signal: this.error.signal,
27
- },
28
- };
29
- }
30
- }
31
- exports.InternalServerError = InternalServerError;
32
- //# sourceMappingURL=InternalServerError.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InternalServerError.js","sourceRoot":"","sources":["../../../src/errors/http/InternalServerError.ts"],"names":[],"mappings":";;;AACA,2CAAwC;AAExC,MAAa,mBAAoB,SAAQ,qBAAS;IAGhD,YAAY,KAAe;QACzB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAEM,aAAa;QAClB,OAAO,uBAAuB,CAAC;IACjC,CAAC;IAEM,OAAO;QACZ,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;YACzC,OAAO,EAAE,CAAC;SACX;QAED,OAAO;YACL,KAAK,EAAE;gBACL,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI;gBACrB,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO;gBAC3B,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI;gBACrB,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO;gBAC3B,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa;gBACvC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK;gBACvB,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM;gBACzB,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM;aAC1B;SACF,CAAC;IACJ,CAAC;CACF;AA9BD,kDA8BC"}
@@ -1,4 +0,0 @@
1
- import { HttpError } from "./HttpError";
2
- export declare class NotFoundError extends HttpError {
3
- renderMessage(): string;
4
- }
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NotFoundError = void 0;
4
- const HttpError_1 = require("./HttpError");
5
- class NotFoundError extends HttpError_1.HttpError {
6
- renderMessage() {
7
- return "Not Found";
8
- }
9
- }
10
- exports.NotFoundError = NotFoundError;
11
- //# sourceMappingURL=NotFoundError.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NotFoundError.js","sourceRoot":"","sources":["../../../src/errors/http/NotFoundError.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AAExC,MAAa,aAAc,SAAQ,qBAAS;IACnC,aAAa;QAClB,OAAO,WAAW,CAAC;IACrB,CAAC;CACF;AAJD,sCAIC"}
@@ -1,8 +0,0 @@
1
- import { RenderableContext } from "../RenderableError";
2
- import { HttpError } from "./HttpError";
3
- export declare class UnauthorizedError extends HttpError {
4
- requiredChecks: any;
5
- constructor(requiredChecks: string[]);
6
- renderMessage(): string;
7
- context(): RenderableContext;
8
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UnauthorizedError = void 0;
4
- const HttpError_1 = require("./HttpError");
5
- class UnauthorizedError extends HttpError_1.HttpError {
6
- constructor(requiredChecks) {
7
- super();
8
- this.requiredChecks = requiredChecks;
9
- }
10
- renderMessage() {
11
- return "Unauthorized Error";
12
- }
13
- context() {
14
- return {
15
- requiredChecks: this.requiredChecks,
16
- };
17
- }
18
- }
19
- exports.UnauthorizedError = UnauthorizedError;
20
- //# sourceMappingURL=UnauthorizedError.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"UnauthorizedError.js","sourceRoot":"","sources":["../../../src/errors/http/UnauthorizedError.ts"],"names":[],"mappings":";;;AACA,2CAAwC;AAExC,MAAa,iBAAkB,SAAQ,qBAAS;IAG9C,YAAmB,cAAwB;QACzC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;IAEM,aAAa;QAClB,OAAO,oBAAoB,CAAC;IAC9B,CAAC;IAEM,OAAO;QACZ,OAAO;YACL,cAAc,EAAE,IAAI,CAAC,cAAc;SACpC,CAAC;IACJ,CAAC;CACF;AAjBD,8CAiBC"}
@@ -1,5 +0,0 @@
1
- export * from "./HttpError";
2
- export * from "./BadRequestError";
3
- export * from "./UnauthorizedError";
4
- export * from "./InternalServerError";
5
- export * from "./NotFoundError";
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/errors/http/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAA4B;AAC5B,oDAAkC;AAClC,sDAAoC;AACpC,wDAAsC;AACtC,kDAAgC"}
@@ -1,7 +0,0 @@
1
- export type RenderableContext = Record<string, unknown>;
2
-
3
- export interface RenderableError {
4
- code(): string;
5
- renderMessage(): string;
6
- context(): RenderableContext;
7
- }
@@ -1,21 +0,0 @@
1
- import { RenderableContext } from "../RenderableError";
2
- import { HttpError } from "./HttpError";
3
-
4
- export class BadRequestError extends HttpError {
5
- private errors;
6
-
7
- public constructor(errors: string[] | string) {
8
- super();
9
- this.errors = errors;
10
- }
11
-
12
- public renderMessage(): string {
13
- return "Bad Request";
14
- }
15
-
16
- public context(): RenderableContext {
17
- return {
18
- errors: this.errors,
19
- };
20
- }
21
- }
@@ -1,19 +0,0 @@
1
- import { snakeCase } from "lodash";
2
- import { BaseError } from "../BaseError";
3
- import { RenderableContext, RenderableError } from "../RenderableError";
4
-
5
- export abstract class HttpError extends BaseError implements RenderableError {
6
- constructor() {
7
- super("HttpError");
8
- }
9
-
10
- public abstract renderMessage(): string;
11
-
12
- public code(): string {
13
- return snakeCase(this.renderMessage());
14
- }
15
-
16
- public context(): RenderableContext {
17
- return {};
18
- }
19
- }
@@ -1,7 +0,0 @@
1
- import { HttpError } from "./HttpError";
2
-
3
- export class NotFoundError extends HttpError {
4
- public renderMessage(): string {
5
- return "Not Found";
6
- }
7
- }
@@ -1,21 +0,0 @@
1
- import { RenderableContext } from "../RenderableError";
2
- import { HttpError } from "./HttpError";
3
-
4
- export class UnauthorizedError extends HttpError {
5
- public requiredChecks;
6
-
7
- public constructor(requiredChecks: string[]) {
8
- super();
9
- this.requiredChecks = requiredChecks;
10
- }
11
-
12
- public renderMessage(): string {
13
- return "Unauthorized Error";
14
- }
15
-
16
- public context(): RenderableContext {
17
- return {
18
- requiredChecks: this.requiredChecks,
19
- };
20
- }
21
- }
@@ -1,5 +0,0 @@
1
- export * from "./HttpError";
2
- export * from "./BadRequestError";
3
- export * from "./UnauthorizedError";
4
- export * from "./InternalServerError";
5
- export * from "./NotFoundError";
File without changes
File without changes
File without changes