@alanszp/express-common-fn 10.0.3 → 12.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/commonErrorsHandler.js +29 -14
- package/dist/commonErrorsHandler.js.map +1 -1
- package/node_modules/@alanszp/audit/dist/errors/AuditError.d.ts +2 -2
- package/node_modules/@alanszp/audit/dist/errors/AuditError.js +1 -1
- package/node_modules/@alanszp/audit/dist/errors/AuditError.js.map +1 -1
- package/node_modules/@alanszp/audit/dist/errors/MissingAuditFieldsError.d.ts +3 -3
- package/node_modules/@alanszp/audit/dist/errors/MissingAuditFieldsError.js +2 -2
- package/node_modules/@alanszp/audit/dist/errors/MissingAuditFieldsError.js.map +1 -1
- package/node_modules/@alanszp/audit/package.json +5 -4
- package/node_modules/@alanszp/audit/src/errors/AuditError.ts +2 -2
- package/node_modules/@alanszp/audit/src/errors/MissingAuditFieldsError.ts +4 -7
- package/node_modules/@alanszp/errors/dist/BaseError.js.map +1 -0
- package/node_modules/@alanszp/errors/dist/HttpRenderableError.d.ts +4 -0
- package/node_modules/@alanszp/errors/dist/HttpRenderableError.js +8 -0
- package/node_modules/@alanszp/errors/dist/HttpRenderableError.js.map +1 -0
- package/node_modules/@alanszp/errors/dist/InternalServerError.d.ts +8 -0
- package/node_modules/@alanszp/errors/dist/InternalServerError.js +24 -0
- package/node_modules/@alanszp/errors/dist/InternalServerError.js.map +1 -0
- package/node_modules/@alanszp/errors/dist/RenderableError.d.ts +15 -0
- package/node_modules/@alanszp/errors/dist/RenderableError.js +27 -0
- package/node_modules/@alanszp/errors/dist/RenderableError.js.map +1 -0
- package/node_modules/@alanszp/errors/dist/index.d.ts +4 -3
- package/node_modules/@alanszp/errors/dist/index.js +4 -3
- package/node_modules/@alanszp/errors/dist/index.js.map +1 -1
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/.gitignore +3 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/.npmignore +3 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/LICENSE +21 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/app/appIdentifier.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/app/index.d.ts +1 -0
- package/node_modules/@alanszp/errors/{dist/errors/http → node_modules/@alanszp/core/dist/app}/index.js +6 -6
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/app/index.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/assignKey.d.ts +2 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/assignKey.js +20 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/assignKey.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/index.d.ts +2 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/index.js +19 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/index.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/keepOrUpdate.d.ts +3 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/keepOrUpdate.js +26 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/keepOrUpdate.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/types.d.ts +6 -0
- package/node_modules/@alanszp/errors/{dist/errors/RenderableError.js → node_modules/@alanszp/core/dist/editable/types.js} +1 -1
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/types.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/index.d.ts +4 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/index.js +21 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/index.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/ListResult.d.ts +7 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/ListResult.js +8 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/ListResult.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/Orderable.d.ts +11 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/Orderable.js +13 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/Orderable.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/Paginable.d.ts +14 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/Paginable.js +22 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/Paginable.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/index.d.ts +3 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/index.js +20 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/index.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/package.json +25 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/tsconfig.json +15 -0
- package/node_modules/@alanszp/errors/package.json +7 -2
- package/node_modules/@alanszp/errors/src/HttpRenderableError.ts +5 -0
- package/node_modules/@alanszp/errors/src/{errors/http/InternalServerError.ts → InternalServerError.ts} +8 -10
- package/node_modules/@alanszp/errors/src/RenderableError.ts +37 -0
- package/node_modules/@alanszp/errors/src/index.ts +4 -3
- package/node_modules/@alanszp/express/dist/helpers/renderErrorJson.d.ts +4 -0
- package/node_modules/@alanszp/express/dist/helpers/renderErrorJson.js +32 -0
- package/node_modules/@alanszp/express/dist/helpers/renderErrorJson.js.map +1 -0
- package/node_modules/@alanszp/express/dist/index.d.ts +0 -1
- package/node_modules/@alanszp/express/dist/index.js +0 -1
- package/node_modules/@alanszp/express/dist/index.js.map +1 -1
- package/node_modules/@alanszp/express/dist/middlewares/authedForOrg.js +3 -4
- package/node_modules/@alanszp/express/dist/middlewares/authedForOrg.js.map +1 -1
- package/node_modules/@alanszp/express/dist/middlewares/authenticateUser.js +8 -8
- package/node_modules/@alanszp/express/dist/middlewares/authenticateUser.js.map +1 -1
- package/node_modules/@alanszp/express/dist/middlewares/createContext.js +2 -2
- package/node_modules/@alanszp/express/dist/middlewares/createContext.js.map +1 -1
- package/node_modules/@alanszp/express/dist/middlewares/createContext.test.js +3 -3
- package/node_modules/@alanszp/express/dist/middlewares/createContext.test.js.map +1 -1
- package/node_modules/@alanszp/express/dist/middlewares/hasRoles.js +3 -5
- package/node_modules/@alanszp/express/dist/middlewares/hasRoles.js.map +1 -1
- package/node_modules/@alanszp/express/dist/middlewares/jsonBodyParser.js +3 -4
- package/node_modules/@alanszp/express/dist/middlewares/jsonBodyParser.js.map +1 -1
- package/node_modules/@alanszp/express/dist/middlewares/returnInternalServerError.js +1 -2
- package/node_modules/@alanszp/express/dist/middlewares/returnInternalServerError.js.map +1 -1
- package/node_modules/@alanszp/express/dist/middlewares/returnNotFound.js +2 -3
- package/node_modules/@alanszp/express/dist/middlewares/returnNotFound.js.map +1 -1
- package/node_modules/@alanszp/express/dist/test/mocks/jwtUserMocks.js +7 -6
- package/node_modules/@alanszp/express/dist/test/mocks/jwtUserMocks.js.map +1 -1
- package/node_modules/@alanszp/express/package.json +7 -7
- package/node_modules/@alanszp/express/src/helpers/renderErrorJson.ts +29 -0
- package/node_modules/@alanszp/express/src/index.ts +0 -1
- package/node_modules/@alanszp/express/src/middlewares/authedForOrg.ts +3 -4
- package/node_modules/@alanszp/express/src/middlewares/authenticateUser.ts +18 -18
- package/node_modules/@alanszp/express/src/middlewares/createContext.test.ts +1 -1
- package/node_modules/@alanszp/express/src/middlewares/createContext.ts +1 -1
- package/node_modules/@alanszp/express/src/middlewares/hasRoles.ts +3 -5
- package/node_modules/@alanszp/express/src/middlewares/jsonBodyParser.ts +3 -4
- package/node_modules/@alanszp/express/src/middlewares/returnInternalServerError.ts +1 -2
- package/node_modules/@alanszp/express/src/middlewares/returnNotFound.ts +2 -3
- package/node_modules/@alanszp/express/src/test/mocks/jwtUserMocks.ts +6 -6
- package/node_modules/@alanszp/jwt/dist/JWTUser.d.ts +31 -0
- package/node_modules/@alanszp/jwt/dist/JWTUser.js +62 -0
- package/node_modules/@alanszp/jwt/dist/JWTUser.js.map +1 -0
- package/node_modules/@alanszp/jwt/dist/index.d.ts +1 -0
- package/node_modules/@alanszp/jwt/dist/index.js +1 -0
- package/node_modules/@alanszp/jwt/dist/index.js.map +1 -1
- package/node_modules/@alanszp/jwt/dist/jwt.d.ts +2 -3
- package/node_modules/@alanszp/jwt/dist/jwt.js +4 -26
- package/node_modules/@alanszp/jwt/dist/jwt.js.map +1 -1
- package/node_modules/@alanszp/jwt/dist/types.d.ts +3 -3
- package/node_modules/@alanszp/jwt/package.json +3 -2
- package/node_modules/@alanszp/jwt/src/JWTUser.ts +85 -0
- package/node_modules/@alanszp/jwt/src/index.ts +1 -0
- package/node_modules/@alanszp/jwt/src/jwt.ts +4 -29
- package/node_modules/@alanszp/jwt/src/types.ts +3 -3
- package/node_modules/@alanszp/logger/package.json +3 -2
- package/package.json +7 -6
- package/src/commonErrorsHandler.ts +35 -16
- package/node_modules/@alanszp/errors/dist/errors/BaseError.js.map +0 -1
- package/node_modules/@alanszp/errors/dist/errors/RenderableError.d.ts +0 -6
- package/node_modules/@alanszp/errors/dist/errors/RenderableError.js.map +0 -1
- package/node_modules/@alanszp/errors/dist/errors/http/BadRequestError.d.ts +0 -8
- package/node_modules/@alanszp/errors/dist/errors/http/BadRequestError.js +0 -20
- package/node_modules/@alanszp/errors/dist/errors/http/BadRequestError.js.map +0 -1
- package/node_modules/@alanszp/errors/dist/errors/http/HttpError.d.ts +0 -8
- package/node_modules/@alanszp/errors/dist/errors/http/HttpError.js +0 -18
- package/node_modules/@alanszp/errors/dist/errors/http/HttpError.js.map +0 -1
- package/node_modules/@alanszp/errors/dist/errors/http/InternalServerError.d.ts +0 -8
- package/node_modules/@alanszp/errors/dist/errors/http/InternalServerError.js +0 -32
- package/node_modules/@alanszp/errors/dist/errors/http/InternalServerError.js.map +0 -1
- package/node_modules/@alanszp/errors/dist/errors/http/NotFoundError.d.ts +0 -4
- package/node_modules/@alanszp/errors/dist/errors/http/NotFoundError.js +0 -11
- package/node_modules/@alanszp/errors/dist/errors/http/NotFoundError.js.map +0 -1
- package/node_modules/@alanszp/errors/dist/errors/http/UnauthorizedError.d.ts +0 -8
- package/node_modules/@alanszp/errors/dist/errors/http/UnauthorizedError.js +0 -20
- package/node_modules/@alanszp/errors/dist/errors/http/UnauthorizedError.js.map +0 -1
- package/node_modules/@alanszp/errors/dist/errors/http/index.d.ts +0 -5
- package/node_modules/@alanszp/errors/dist/errors/http/index.js.map +0 -1
- package/node_modules/@alanszp/errors/src/errors/RenderableError.ts +0 -7
- package/node_modules/@alanszp/errors/src/errors/http/BadRequestError.ts +0 -21
- package/node_modules/@alanszp/errors/src/errors/http/HttpError.ts +0 -19
- package/node_modules/@alanszp/errors/src/errors/http/NotFoundError.ts +0 -7
- package/node_modules/@alanszp/errors/src/errors/http/UnauthorizedError.ts +0 -21
- package/node_modules/@alanszp/errors/src/errors/http/index.ts +0 -5
- package/node_modules/@alanszp/express/dist/helpers/appIdentifier.js.map +0 -1
- package/node_modules/@alanszp/express/dist/views/errorView.d.ts +0 -2
- package/node_modules/@alanszp/express/dist/views/errorView.js +0 -14
- package/node_modules/@alanszp/express/dist/views/errorView.js.map +0 -1
- package/node_modules/@alanszp/express/src/helpers/appIdentifier.ts +0 -5
- package/node_modules/@alanszp/express/src/views/errorView.ts +0 -11
- /package/node_modules/@alanszp/errors/dist/{errors/BaseError.d.ts → BaseError.d.ts} +0 -0
- /package/node_modules/@alanszp/errors/dist/{errors/BaseError.js → BaseError.js} +0 -0
- /package/node_modules/@alanszp/{express/dist/helpers → errors/node_modules/@alanszp/core/dist/app}/appIdentifier.d.ts +0 -0
- /package/node_modules/@alanszp/{express/dist/helpers → errors/node_modules/@alanszp/core/dist/app}/appIdentifier.js +0 -0
- /package/node_modules/@alanszp/errors/src/{errors/BaseError.ts → BaseError.ts} +0 -0
|
@@ -1,22 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.commonErrorsHandler = void 0;
|
|
4
|
-
const
|
|
4
|
+
const core_1 = require("@alanszp/core");
|
|
5
5
|
const errors_1 = require("@alanszp/errors");
|
|
6
|
-
const validations_1 = require("@alanszp/validations");
|
|
7
6
|
const typeorm_1 = require("typeorm");
|
|
8
7
|
const defaultsOption = {
|
|
9
8
|
entityNotFound: 404,
|
|
10
9
|
extraContext: {},
|
|
11
10
|
};
|
|
11
|
+
function render404Error() {
|
|
12
|
+
return {
|
|
13
|
+
code: "not_found",
|
|
14
|
+
message: "Not Found",
|
|
15
|
+
context: {},
|
|
16
|
+
origin: (0, core_1.appIdentifier)(),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function render400Error(message) {
|
|
20
|
+
return {
|
|
21
|
+
code: "bad_request",
|
|
22
|
+
message,
|
|
23
|
+
context: {},
|
|
24
|
+
origin: (0, core_1.appIdentifier)(),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
12
27
|
function commonErrorsHandler(loggerFn) {
|
|
13
28
|
return function handleCommonErrors(error, res, baseLog, options) {
|
|
14
29
|
const logger = loggerFn();
|
|
15
30
|
const opts = Object.assign(Object.assign({}, defaultsOption), options);
|
|
16
31
|
const instanceLogger = logger.child(opts.extraContext);
|
|
17
|
-
if (error instanceof
|
|
18
|
-
|
|
19
|
-
|
|
32
|
+
if (error instanceof errors_1.RenderableError) {
|
|
33
|
+
const statusCode = error instanceof errors_1.HttpRenderableError ? error.httpCode() : 500;
|
|
34
|
+
instanceLogger.info(`${baseLog}.error.${error.code()}`, {
|
|
35
|
+
statusCode,
|
|
36
|
+
error,
|
|
37
|
+
});
|
|
38
|
+
res.status(statusCode).json(error.toView());
|
|
20
39
|
return;
|
|
21
40
|
}
|
|
22
41
|
if (error instanceof typeorm_1.EntityNotFoundError) {
|
|
@@ -24,12 +43,10 @@ function commonErrorsHandler(loggerFn) {
|
|
|
24
43
|
error,
|
|
25
44
|
});
|
|
26
45
|
if (opts.entityNotFound === 400) {
|
|
27
|
-
res
|
|
28
|
-
.status(400)
|
|
29
|
-
.json((0, express_1.errorView)(new errors_1.BadRequestError("Entity not present")));
|
|
46
|
+
res.status(400).json(render400Error("Entity not present"));
|
|
30
47
|
}
|
|
31
48
|
else {
|
|
32
|
-
res.status(404).json((
|
|
49
|
+
res.status(404).json(render404Error());
|
|
33
50
|
}
|
|
34
51
|
return;
|
|
35
52
|
}
|
|
@@ -38,20 +55,18 @@ function commonErrorsHandler(loggerFn) {
|
|
|
38
55
|
instanceLogger.info(`${baseLog}.error.typeorm.query_error.duplicate`, {
|
|
39
56
|
error,
|
|
40
57
|
});
|
|
41
|
-
res
|
|
42
|
-
.status(400)
|
|
43
|
-
.json((0, express_1.errorView)(new errors_1.BadRequestError("Entity already exists")));
|
|
58
|
+
res.status(400).json(render400Error("Entity already exists"));
|
|
44
59
|
}
|
|
45
60
|
else {
|
|
46
61
|
instanceLogger.error(`${baseLog}.error.typeorm.query_error.unknown`, {
|
|
47
62
|
error,
|
|
48
63
|
});
|
|
49
|
-
res.status(500).json(
|
|
64
|
+
res.status(500).json(new errors_1.InternalServerError(error).toView());
|
|
50
65
|
}
|
|
51
66
|
return;
|
|
52
67
|
}
|
|
53
68
|
instanceLogger.error(`${baseLog}.error.unknown`, { error });
|
|
54
|
-
res.status(500).json(
|
|
69
|
+
res.status(500).json(new errors_1.InternalServerError(error).toView());
|
|
55
70
|
};
|
|
56
71
|
}
|
|
57
72
|
exports.commonErrorsHandler = commonErrorsHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commonErrorsHandler.js","sourceRoot":"","sources":["../src/commonErrorsHandler.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"commonErrorsHandler.js","sourceRoot":"","sources":["../src/commonErrorsHandler.ts"],"names":[],"mappings":";;;AAAA,wCAA8C;AAC9C,4CAKyB;AAGzB,qCAAgE;AAOhE,MAAM,cAAc,GAAuB;IACzC,cAAc,EAAE,GAAG;IACnB,YAAY,EAAE,EAAE;CACjB,CAAC;AAEF,SAAS,cAAc;IACrB,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,WAAW;QACpB,OAAO,EAAE,EAAE;QACX,MAAM,EAAE,IAAA,oBAAa,GAAE;KACxB,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,OAAe;IACrC,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,OAAO;QACP,OAAO,EAAE,EAAE;QACX,MAAM,EAAE,IAAA,oBAAa,GAAE;KACxB,CAAC;AACJ,CAAC;AAED,SAAgB,mBAAmB,CAAC,QAAuB;IACzD,OAAO,SAAS,kBAAkB,CAChC,KAAc,EACd,GAAa,EACb,OAAe,EACf,OAAqC;QAErC,MAAM,MAAM,GAAG,QAAQ,EAAE,CAAC;QAE1B,MAAM,IAAI,mCACL,cAAc,GACd,OAAO,CACX,CAAC;QACF,MAAM,cAAc,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAEvD,IAAI,KAAK,YAAY,wBAAe,EAAE;YACpC,MAAM,UAAU,GACd,KAAK,YAAY,4BAAmB,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;YAChE,cAAc,CAAC,IAAI,CAAC,GAAG,OAAO,UAAU,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE;gBACtD,UAAU;gBACV,KAAK;aACN,CAAC,CAAC;YACH,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;YAC5C,OAAO;SACR;QAED,IAAI,KAAK,YAAY,6BAAmB,EAAE;YACxC,cAAc,CAAC,IAAI,CAAC,GAAG,OAAO,iCAAiC,EAAE;gBAC/D,KAAK;aACN,CAAC,CAAC;YACH,IAAI,IAAI,CAAC,cAAc,KAAK,GAAG,EAAE;gBAC/B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC,CAAC;aAC5D;iBAAM;gBACL,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;aACxC;YACD,OAAO;SACR;QAED,IAAI,KAAK,YAAY,0BAAgB,EAAE;YACrC,IAAK,KAAqC,CAAC,IAAI,KAAK,OAAO,EAAE;gBAC3D,cAAc,CAAC,IAAI,CAAC,GAAG,OAAO,sCAAsC,EAAE;oBACpE,KAAK;iBACN,CAAC,CAAC;gBACH,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,uBAAuB,CAAC,CAAC,CAAC;aAC/D;iBAAM;gBACL,cAAc,CAAC,KAAK,CAAC,GAAG,OAAO,oCAAoC,EAAE;oBACnE,KAAK;iBACN,CAAC,CAAC;gBACH,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,4BAAmB,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;aAC/D;YACD,OAAO;SACR;QAED,cAAc,CAAC,KAAK,CAAC,GAAG,OAAO,gBAAgB,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC5D,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,4BAAmB,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IAChE,CAAC,CAAC;AACJ,CAAC;AAxDD,kDAwDC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class AuditError extends
|
|
1
|
+
import { HttpRenderableError } from "@alanszp/errors";
|
|
2
|
+
export declare abstract class AuditError extends HttpRenderableError {
|
|
3
3
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AuditError = void 0;
|
|
4
4
|
const errors_1 = require("@alanszp/errors");
|
|
5
|
-
class AuditError extends errors_1.
|
|
5
|
+
class AuditError extends errors_1.HttpRenderableError {
|
|
6
6
|
}
|
|
7
7
|
exports.AuditError = AuditError;
|
|
8
8
|
//# sourceMappingURL=AuditError.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuditError.js","sourceRoot":"","sources":["../../src/errors/AuditError.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"AuditError.js","sourceRoot":"","sources":["../../src/errors/AuditError.ts"],"names":[],"mappings":";;;AAAA,4CAAsD;AAEtD,MAAsB,UAAW,SAAQ,4BAAmB;CAAG;AAA/D,gCAA+D"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { RenderableContext
|
|
1
|
+
import { RenderableContext } from "@alanszp/errors";
|
|
2
2
|
import { AuditError } from "./AuditError";
|
|
3
|
-
export declare class MissingAuditFieldsError extends AuditError
|
|
3
|
+
export declare class MissingAuditFieldsError extends AuditError {
|
|
4
4
|
missingFields: string[];
|
|
5
5
|
constructor(missingFields: string[]);
|
|
6
|
-
|
|
6
|
+
httpCode(): number;
|
|
7
7
|
renderMessage(): string;
|
|
8
8
|
context(): RenderableContext;
|
|
9
9
|
}
|
|
@@ -7,8 +7,8 @@ class MissingAuditFieldsError extends AuditError_1.AuditError {
|
|
|
7
7
|
super("MissingAuditFieldsError");
|
|
8
8
|
this.missingFields = missingFields;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
return
|
|
10
|
+
httpCode() {
|
|
11
|
+
return 500;
|
|
12
12
|
}
|
|
13
13
|
renderMessage() {
|
|
14
14
|
return "Missing properties on audit log.";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MissingAuditFieldsError.js","sourceRoot":"","sources":["../../src/errors/MissingAuditFieldsError.ts"],"names":[],"mappings":";;;AACA,6CAA0C;AAE1C,MAAa,
|
|
1
|
+
{"version":3,"file":"MissingAuditFieldsError.js","sourceRoot":"","sources":["../../src/errors/MissingAuditFieldsError.ts"],"names":[],"mappings":";;;AACA,6CAA0C;AAE1C,MAAa,uBAAwB,SAAQ,uBAAU;IAGrD,YAAY,aAAuB;QACjC,KAAK,CAAC,yBAAyB,CAAC,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAED,QAAQ;QACN,OAAO,GAAG,CAAC;IACb,CAAC;IAED,aAAa;QACX,OAAO,kCAAkC,CAAC;IAC5C,CAAC;IAED,OAAO;QACL,OAAO;YACL,aAAa,EAAE,IAAI,CAAC,aAAa;SAClC,CAAC;IACJ,CAAC;CACF;AArBD,0DAqBC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alanszp/audit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"description": "Alan's audit util.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -19,11 +19,12 @@
|
|
|
19
19
|
"yalc-publish": "yarn run yalc publish"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@alanszp/errors": "^
|
|
23
|
-
"@alanszp/logger": "^
|
|
22
|
+
"@alanszp/errors": "^12.0.0",
|
|
23
|
+
"@alanszp/logger": "^12.0.0",
|
|
24
24
|
"lodash": "^4.17.21"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/node": "^20.11.17"
|
|
28
|
-
}
|
|
28
|
+
},
|
|
29
|
+
"gitHead": "085a76a387bc0e272e09e9cb1b6f48f814512940"
|
|
29
30
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HttpRenderableError } from "@alanszp/errors";
|
|
2
2
|
|
|
3
|
-
export class AuditError extends
|
|
3
|
+
export abstract class AuditError extends HttpRenderableError {}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { RenderableContext
|
|
1
|
+
import { RenderableContext } from "@alanszp/errors";
|
|
2
2
|
import { AuditError } from "./AuditError";
|
|
3
3
|
|
|
4
|
-
export class MissingAuditFieldsError
|
|
5
|
-
extends AuditError
|
|
6
|
-
implements RenderableError
|
|
7
|
-
{
|
|
4
|
+
export class MissingAuditFieldsError extends AuditError {
|
|
8
5
|
public missingFields: string[];
|
|
9
6
|
|
|
10
7
|
constructor(missingFields: string[]) {
|
|
@@ -12,8 +9,8 @@ export class MissingAuditFieldsError
|
|
|
12
9
|
this.missingFields = missingFields;
|
|
13
10
|
}
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
return
|
|
12
|
+
httpCode(): number {
|
|
13
|
+
return 500;
|
|
17
14
|
}
|
|
18
15
|
|
|
19
16
|
renderMessage(): string {
|
|
@@ -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,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"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
1
|
+
export * from "./BaseError";
|
|
2
|
+
export * from "./RenderableError";
|
|
3
|
+
export * from "./HttpRenderableError";
|
|
4
|
+
export * from "./InternalServerError";
|
|
@@ -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("./
|
|
14
|
-
__exportStar(require("./
|
|
15
|
-
__exportStar(require("./
|
|
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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAA4B;AAC5B,oDAAkC;AAClC,wDAAsC;AACtC,wDAAsC"}
|
|
@@ -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
|
+
{"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.
|
|
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("./
|
|
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,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"}
|
package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/keepOrUpdate.d.ts
ADDED
|
@@ -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
|
package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/keepOrUpdate.js.map
ADDED
|
@@ -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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/editable/types.ts"],"names":[],"mappings":""}
|
|
@@ -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,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"}
|