jimpex 7.0.1 → 8.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/CHANGELOG.md +87 -0
- package/LICENSE +1 -1
- package/README.md +446 -434
- package/dist/app/index.d.ts +13 -0
- package/dist/app/index.js +19 -0
- package/dist/app/index.js.map +1 -0
- package/dist/app/jimpex.d.ts +13 -0
- package/dist/app/jimpex.js +440 -0
- package/dist/app/jimpex.js.map +1 -0
- package/dist/controllers/common/config.d.ts +78 -0
- package/dist/controllers/common/config.js +89 -0
- package/dist/controllers/common/config.js.map +1 -0
- package/dist/controllers/common/health.d.ts +82 -0
- package/dist/controllers/common/health.js +97 -0
- package/dist/controllers/common/health.js.map +1 -0
- package/dist/controllers/common/index.d.ts +21 -0
- package/dist/controllers/common/index.js +21 -0
- package/dist/controllers/common/index.js.map +1 -0
- package/dist/controllers/common/statics.d.ts +215 -0
- package/dist/controllers/common/statics.js +202 -0
- package/dist/controllers/common/statics.js.map +1 -0
- package/dist/controllers/index.d.ts +24 -0
- package/dist/controllers/index.js +20 -0
- package/dist/controllers/index.js.map +1 -0
- package/dist/controllers/utils/gateway.d.ts +724 -0
- package/dist/controllers/utils/gateway.js +425 -0
- package/dist/controllers/utils/gateway.js.map +1 -0
- package/dist/controllers/utils/index.d.ts +16 -0
- package/dist/controllers/utils/index.js +19 -0
- package/dist/controllers/utils/index.js.map +1 -0
- package/dist/esm/app/index.js +2 -0
- package/dist/esm/app/index.js.map +1 -0
- package/dist/esm/app/jimpex.js +415 -0
- package/dist/esm/app/jimpex.js.map +1 -0
- package/dist/esm/chunk-T2T6Q22Z.js +11 -0
- package/dist/esm/chunk-T2T6Q22Z.js.map +1 -0
- package/dist/esm/controllers/common/config.js +62 -0
- package/dist/esm/controllers/common/config.js.map +1 -0
- package/dist/esm/controllers/common/health.js +70 -0
- package/dist/esm/controllers/common/health.js.map +1 -0
- package/dist/esm/controllers/common/index.js +4 -0
- package/dist/esm/controllers/common/index.js.map +1 -0
- package/dist/esm/controllers/common/statics.js +173 -0
- package/dist/esm/controllers/common/statics.js.map +1 -0
- package/dist/esm/controllers/index.js +3 -0
- package/dist/esm/controllers/index.js.map +1 -0
- package/dist/esm/controllers/utils/gateway.js +404 -0
- package/dist/esm/controllers/utils/gateway.js.map +1 -0
- package/dist/esm/controllers/utils/index.js +2 -0
- package/dist/esm/controllers/utils/index.js.map +1 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/middlewares/common/errorHandler.js +92 -0
- package/dist/esm/middlewares/common/errorHandler.js.map +1 -0
- package/dist/esm/middlewares/common/forceHTTPS.js +41 -0
- package/dist/esm/middlewares/common/forceHTTPS.js.map +1 -0
- package/dist/esm/middlewares/common/hsts.js +53 -0
- package/dist/esm/middlewares/common/hsts.js.map +1 -0
- package/dist/esm/middlewares/common/index.js +4 -0
- package/dist/esm/middlewares/common/index.js.map +1 -0
- package/dist/esm/middlewares/html/fastHTML.js +104 -0
- package/dist/esm/middlewares/html/fastHTML.js.map +1 -0
- package/dist/esm/middlewares/html/index.js +3 -0
- package/dist/esm/middlewares/html/index.js.map +1 -0
- package/dist/esm/middlewares/html/showHTML.js +68 -0
- package/dist/esm/middlewares/html/showHTML.js.map +1 -0
- package/dist/esm/middlewares/index.js +4 -0
- package/dist/esm/middlewares/index.js.map +1 -0
- package/dist/esm/middlewares/utils/index.js +2 -0
- package/dist/esm/middlewares/utils/index.js.map +1 -0
- package/dist/esm/middlewares/utils/versionValidator.js +101 -0
- package/dist/esm/middlewares/utils/versionValidator.js.map +1 -0
- package/dist/esm/services/common/appError.js +52 -0
- package/dist/esm/services/common/appError.js.map +1 -0
- package/dist/esm/services/common/httpError.js +19 -0
- package/dist/esm/services/common/httpError.js.map +1 -0
- package/dist/esm/services/common/index.js +17 -0
- package/dist/esm/services/common/index.js.map +1 -0
- package/dist/esm/services/common/sendFile.js +27 -0
- package/dist/esm/services/common/sendFile.js.map +1 -0
- package/dist/esm/services/frontend/frontendFs.js +38 -0
- package/dist/esm/services/frontend/frontendFs.js.map +1 -0
- package/dist/esm/services/frontend/index.js +11 -0
- package/dist/esm/services/frontend/index.js.map +1 -0
- package/dist/esm/services/html/htmlGenerator.js +144 -0
- package/dist/esm/services/html/htmlGenerator.js.map +1 -0
- package/dist/esm/services/html/index.js +11 -0
- package/dist/esm/services/html/index.js.map +1 -0
- package/dist/esm/services/http/apiClient.js +71 -0
- package/dist/esm/services/http/apiClient.js.map +1 -0
- package/dist/esm/services/http/http.js +125 -0
- package/dist/esm/services/http/http.js.map +1 -0
- package/dist/esm/services/http/index.js +17 -0
- package/dist/esm/services/http/index.js.map +1 -0
- package/dist/esm/services/http/responsesBuilder.js +105 -0
- package/dist/esm/services/http/responsesBuilder.js.map +1 -0
- package/dist/esm/services/index.js +6 -0
- package/dist/esm/services/index.js.map +1 -0
- package/dist/esm/services/utils/ensureBearerToken.js +78 -0
- package/dist/esm/services/utils/ensureBearerToken.js.map +1 -0
- package/dist/esm/services/utils/index.js +11 -0
- package/dist/esm/services/utils/index.js.map +1 -0
- package/dist/esm/types/events.js +1 -0
- package/dist/esm/types/events.js.map +1 -0
- package/dist/esm/types/express.js +1 -0
- package/dist/esm/types/express.js.map +1 -0
- package/dist/esm/types/http.js +1 -0
- package/dist/esm/types/http.js.map +1 -0
- package/dist/esm/types/index.js +7 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/options.js +1 -0
- package/dist/esm/types/options.js.map +1 -0
- package/dist/esm/types/utils.js +1 -0
- package/dist/esm/types/utils.js.map +1 -0
- package/dist/esm/types/wootils.js +1 -0
- package/dist/esm/types/wootils.js.map +1 -0
- package/dist/esm/utils/fns/index.js +5 -0
- package/dist/esm/utils/fns/index.js.map +1 -0
- package/dist/esm/utils/fns/others.js +6 -0
- package/dist/esm/utils/fns/others.js.map +1 -0
- package/dist/esm/utils/fns/routes.js +25 -0
- package/dist/esm/utils/fns/routes.js.map +1 -0
- package/dist/esm/utils/fns/statuses.js +6 -0
- package/dist/esm/utils/fns/statuses.js.map +1 -0
- package/dist/esm/utils/fns/text.js +6 -0
- package/dist/esm/utils/fns/text.js.map +1 -0
- package/dist/esm/utils/index.js +3 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/wrappers.js +41 -0
- package/dist/esm/utils/wrappers.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/jimpex-7eaee271.d.ts +1278 -0
- package/dist/middlewares/common/errorHandler.d.ts +131 -0
- package/dist/middlewares/common/errorHandler.js +119 -0
- package/dist/middlewares/common/errorHandler.js.map +1 -0
- package/dist/middlewares/common/forceHTTPS.d.ts +68 -0
- package/dist/middlewares/common/forceHTTPS.js +68 -0
- package/dist/middlewares/common/forceHTTPS.js.map +1 -0
- package/dist/middlewares/common/hsts.d.ts +109 -0
- package/dist/middlewares/common/hsts.js +80 -0
- package/dist/middlewares/common/hsts.js.map +1 -0
- package/dist/middlewares/common/index.d.ts +21 -0
- package/dist/middlewares/common/index.js +21 -0
- package/dist/middlewares/common/index.js.map +1 -0
- package/dist/middlewares/html/fastHTML.d.ts +180 -0
- package/dist/middlewares/html/fastHTML.js +131 -0
- package/dist/middlewares/html/fastHTML.js.map +1 -0
- package/dist/middlewares/html/index.d.ts +21 -0
- package/dist/middlewares/html/index.js +20 -0
- package/dist/middlewares/html/index.js.map +1 -0
- package/dist/middlewares/html/showHTML.d.ts +127 -0
- package/dist/middlewares/html/showHTML.js +95 -0
- package/dist/middlewares/html/showHTML.js.map +1 -0
- package/dist/middlewares/index.d.ts +30 -0
- package/dist/middlewares/index.js +21 -0
- package/dist/middlewares/index.js.map +1 -0
- package/dist/middlewares/utils/index.d.ts +19 -0
- package/dist/middlewares/utils/index.js +19 -0
- package/dist/middlewares/utils/index.js.map +1 -0
- package/dist/middlewares/utils/versionValidator.d.ts +214 -0
- package/dist/middlewares/utils/versionValidator.js +128 -0
- package/dist/middlewares/utils/versionValidator.js.map +1 -0
- package/dist/services/common/appError.d.ts +138 -0
- package/dist/services/common/appError.js +80 -0
- package/dist/services/common/appError.js.map +1 -0
- package/dist/services/common/httpError.d.ts +79 -0
- package/dist/services/common/httpError.js +44 -0
- package/dist/services/common/httpError.js.map +1 -0
- package/dist/services/common/index.d.ts +47 -0
- package/dist/services/common/index.js +41 -0
- package/dist/services/common/index.js.map +1 -0
- package/dist/services/common/sendFile.d.ts +102 -0
- package/dist/services/common/sendFile.js +51 -0
- package/dist/services/common/sendFile.js.map +1 -0
- package/dist/services/frontend/frontendFs.d.ts +96 -0
- package/dist/services/frontend/frontendFs.js +71 -0
- package/dist/services/frontend/frontendFs.js.map +1 -0
- package/dist/services/frontend/index.d.ts +40 -0
- package/dist/services/frontend/index.js +35 -0
- package/dist/services/frontend/index.js.map +1 -0
- package/dist/services/html/htmlGenerator.d.ts +237 -0
- package/dist/services/html/htmlGenerator.js +171 -0
- package/dist/services/html/htmlGenerator.js.map +1 -0
- package/dist/services/html/index.d.ts +43 -0
- package/dist/services/html/index.js +35 -0
- package/dist/services/html/index.js.map +1 -0
- package/dist/services/http/apiClient.d.ts +169 -0
- package/dist/services/http/apiClient.js +96 -0
- package/dist/services/http/apiClient.js.map +1 -0
- package/dist/services/http/http.d.ts +175 -0
- package/dist/services/http/http.js +158 -0
- package/dist/services/http/http.js.map +1 -0
- package/dist/services/http/index.d.ts +50 -0
- package/dist/services/http/index.js +41 -0
- package/dist/services/http/index.js.map +1 -0
- package/dist/services/http/responsesBuilder.d.ts +178 -0
- package/dist/services/http/responsesBuilder.js +132 -0
- package/dist/services/http/responsesBuilder.js.map +1 -0
- package/dist/services/index.d.ts +33 -0
- package/dist/services/index.js +23 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/utils/ensureBearerToken.d.ts +157 -0
- package/dist/services/utils/ensureBearerToken.js +105 -0
- package/dist/services/utils/ensureBearerToken.js.map +1 -0
- package/dist/services/utils/index.d.ts +43 -0
- package/dist/services/utils/index.js +35 -0
- package/dist/services/utils/index.js.map +1 -0
- package/dist/types/events.d.ts +13 -0
- package/dist/types/events.js +17 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/express.d.ts +10 -0
- package/dist/types/express.js +17 -0
- package/dist/types/express.js.map +1 -0
- package/dist/types/http.d.ts +79 -0
- package/dist/types/http.js +17 -0
- package/dist/types/http.js.map +1 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.js +24 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/options.d.ts +13 -0
- package/dist/types/options.js +17 -0
- package/dist/types/options.js.map +1 -0
- package/dist/types/utils.d.ts +48 -0
- package/dist/types/utils.js +17 -0
- package/dist/types/utils.js.map +1 -0
- package/dist/types/wootils.d.ts +4 -0
- package/dist/types/wootils.js +17 -0
- package/dist/types/wootils.js.map +1 -0
- package/dist/utils/fns/index.d.ts +5 -0
- package/dist/utils/fns/index.js +22 -0
- package/dist/utils/fns/index.js.map +1 -0
- package/dist/utils/fns/others.d.ts +17 -0
- package/dist/utils/fns/others.js +29 -0
- package/dist/utils/fns/others.js.map +1 -0
- package/dist/utils/fns/routes.d.ts +39 -0
- package/dist/utils/fns/routes.js +51 -0
- package/dist/utils/fns/routes.js.map +1 -0
- package/dist/utils/fns/statuses.d.ts +45 -0
- package/dist/utils/fns/statuses.js +35 -0
- package/dist/utils/fns/statuses.js.map +1 -0
- package/dist/utils/fns/text.d.ts +9 -0
- package/dist/utils/fns/text.js +29 -0
- package/dist/utils/fns/text.js.map +1 -0
- package/dist/utils/index.d.ts +18 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/wrappers.d.ts +13 -0
- package/dist/utils/wrappers.js +68 -0
- package/dist/utils/wrappers.js.map +1 -0
- package/examples/basic/404.html +12 -0
- package/examples/basic/README.md +30 -0
- package/examples/basic/app.ts +18 -0
- package/examples/basic/controller.ts +45 -0
- package/examples/basic/index.ts +19 -0
- package/examples/basic/middleware.ts +13 -0
- package/examples/basic/service.ts +11 -0
- package/package.json +59 -38
- package/src/app/index.ts +1 -0
- package/src/app/jimpex.ts +743 -0
- package/src/controllers/common/config.ts +115 -0
- package/src/controllers/common/health.ts +128 -0
- package/src/controllers/common/index.ts +3 -0
- package/src/controllers/common/statics.ts +380 -0
- package/src/controllers/index.ts +2 -0
- package/src/controllers/utils/gateway.ts +1186 -0
- package/src/controllers/utils/index.ts +1 -0
- package/src/index.ts +6 -0
- package/src/middlewares/common/errorHandler.ts +203 -0
- package/src/middlewares/common/forceHTTPS.ts +83 -0
- package/src/middlewares/common/hsts.ts +135 -0
- package/src/middlewares/common/index.ts +3 -0
- package/src/middlewares/html/fastHTML.ts +255 -0
- package/src/middlewares/html/index.ts +2 -0
- package/src/middlewares/html/showHTML.ts +165 -0
- package/src/middlewares/index.ts +3 -0
- package/src/middlewares/utils/index.ts +1 -0
- package/src/middlewares/utils/versionValidator.ts +289 -0
- package/src/services/common/appError.ts +158 -0
- package/src/services/common/httpError.ts +74 -0
- package/src/services/common/index.ts +29 -0
- package/src/services/common/sendFile.ts +106 -0
- package/src/services/frontend/frontendFs.ts +101 -0
- package/src/services/frontend/index.ts +21 -0
- package/src/services/html/htmlGenerator.ts +356 -0
- package/src/services/html/index.ts +21 -0
- package/src/services/http/apiClient.ts +221 -0
- package/src/services/http/http.ts +286 -0
- package/src/services/http/index.ts +29 -0
- package/src/services/http/responsesBuilder.ts +265 -0
- package/src/services/index.ts +5 -0
- package/src/services/utils/ensureBearerToken.ts +202 -0
- package/src/services/utils/index.ts +21 -0
- package/src/types/events.ts +303 -0
- package/src/types/express.ts +21 -0
- package/src/types/http.ts +77 -0
- package/src/types/index.ts +6 -0
- package/src/types/options.ts +248 -0
- package/src/types/utils.ts +52 -0
- package/src/types/wootils.ts +4 -0
- package/src/utils/fns/index.ts +4 -0
- package/src/utils/fns/others.ts +15 -0
- package/src/utils/fns/routes.ts +64 -0
- package/src/utils/fns/statuses.ts +44 -0
- package/src/utils/fns/text.ts +8 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/wrappers.ts +537 -0
- package/tsconfig.json +5 -8
- package/tsup.config.ts +10 -0
- package/src/app/index.js +0 -692
- package/src/constants/eventNames.js +0 -48
- package/src/constants/index.js +0 -7
- package/src/controllers/common/configuration.js +0 -116
- package/src/controllers/common/health.js +0 -79
- package/src/controllers/common/index.js +0 -7
- package/src/controllers/common/statics.js +0 -336
- package/src/controllers/index.js +0 -9
- package/src/controllers/utils/gateway.js +0 -1039
- package/src/controllers/utils/index.js +0 -3
- package/src/index.js +0 -30
- package/src/middlewares/common/errorHandler.js +0 -185
- package/src/middlewares/common/forceHTTPS.js +0 -80
- package/src/middlewares/common/hsts.js +0 -122
- package/src/middlewares/common/index.js +0 -7
- package/src/middlewares/html/fastHTML.js +0 -298
- package/src/middlewares/html/index.js +0 -5
- package/src/middlewares/html/showHTML.js +0 -167
- package/src/middlewares/index.js +0 -11
- package/src/middlewares/utils/index.js +0 -3
- package/src/middlewares/utils/versionValidator.js +0 -261
- package/src/services/common/appError.js +0 -136
- package/src/services/common/httpError.js +0 -60
- package/src/services/common/index.js +0 -25
- package/src/services/common/sendFile.js +0 -68
- package/src/services/frontend/frontendFs.js +0 -85
- package/src/services/frontend/index.js +0 -17
- package/src/services/html/htmlGenerator.js +0 -391
- package/src/services/html/index.js +0 -17
- package/src/services/http/apiClient.js +0 -148
- package/src/services/http/http.js +0 -256
- package/src/services/http/index.js +0 -25
- package/src/services/http/responsesBuilder.js +0 -193
- package/src/services/index.js +0 -15
- package/src/services/utils/ensureBearerToken.js +0 -147
- package/src/services/utils/index.js +0 -19
- package/src/types.js +0 -377
- package/src/utils/functions.js +0 -78
- package/src/utils/wrappers.js +0 -131
- package/types/app/index.d.ts +0 -417
- package/types/constants/eventNames.d.ts +0 -93
- package/types/constants/index.d.ts +0 -2
- package/types/controllers/common/configuration.d.ts +0 -71
- package/types/controllers/common/health.d.ts +0 -55
- package/types/controllers/common/index.d.ts +0 -4
- package/types/controllers/common/statics.d.ts +0 -271
- package/types/controllers/index.d.ts +0 -3
- package/types/controllers/utils/gateway.d.ts +0 -947
- package/types/controllers/utils/index.d.ts +0 -2
- package/types/index.d.ts +0 -15
- package/types/middlewares/common/errorHandler.d.ts +0 -143
- package/types/middlewares/common/forceHTTPS.d.ts +0 -64
- package/types/middlewares/common/hsts.d.ts +0 -111
- package/types/middlewares/common/index.d.ts +0 -4
- package/types/middlewares/html/fastHTML.d.ts +0 -238
- package/types/middlewares/html/index.d.ts +0 -3
- package/types/middlewares/html/showHTML.d.ts +0 -128
- package/types/middlewares/index.d.ts +0 -4
- package/types/middlewares/utils/index.d.ts +0 -2
- package/types/middlewares/utils/versionValidator.d.ts +0 -247
- package/types/services/common/appError.d.ts +0 -89
- package/types/services/common/httpError.d.ts +0 -37
- package/types/services/common/index.d.ts +0 -18
- package/types/services/common/sendFile.d.ts +0 -56
- package/types/services/frontend/frontendFs.d.ts +0 -72
- package/types/services/frontend/index.d.ts +0 -3
- package/types/services/html/htmlGenerator.d.ts +0 -298
- package/types/services/html/index.d.ts +0 -3
- package/types/services/http/apiClient.d.ts +0 -141
- package/types/services/http/http.d.ts +0 -159
- package/types/services/http/index.d.ts +0 -18
- package/types/services/http/responsesBuilder.d.ts +0 -140
- package/types/services/index.d.ts +0 -6
- package/types/services/utils/ensureBearerToken.d.ts +0 -137
- package/types/services/utils/index.d.ts +0 -16
- package/types/types.d.ts +0 -280
- package/types/utils/functions.d.ts +0 -55
- package/types/utils/wrappers.d.ts +0 -127
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
+
import { J as Jimpex } from '../../jimpex-7eaee271.js';
|
|
3
|
+
import { Statuses } from '../../utils/fns/statuses.js';
|
|
4
|
+
import { AppError, AppErrorContext } from './appError.js';
|
|
5
|
+
import '@homer0/events-hub';
|
|
6
|
+
import '../../types/express.js';
|
|
7
|
+
import 'express';
|
|
8
|
+
import '../../types/http.js';
|
|
9
|
+
import 'https';
|
|
10
|
+
import 'http';
|
|
11
|
+
import 'spdy';
|
|
12
|
+
import 'node-fetch';
|
|
13
|
+
import '@homer0/simple-config';
|
|
14
|
+
import '../../types/utils.js';
|
|
15
|
+
import '@homer0/simple-logger';
|
|
16
|
+
import 'statuses';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A type of error to be used on HTTP requests. This is the most common type of error used
|
|
20
|
+
* by Jimpex.
|
|
21
|
+
*
|
|
22
|
+
* @group Services
|
|
23
|
+
* @group Services/HTTPError
|
|
24
|
+
*/
|
|
25
|
+
declare class HTTPError extends AppError {
|
|
26
|
+
/**
|
|
27
|
+
* @param message The error message.
|
|
28
|
+
* @param status The HTTP status code.
|
|
29
|
+
* @param context Context information related to the error.
|
|
30
|
+
* @param statuses A reference to the service that generates HTTP status codes. This
|
|
31
|
+
* is in case the implementation wants to use a special version from
|
|
32
|
+
* the container; otherwise, it will use the `statuses` library
|
|
33
|
+
* directly.
|
|
34
|
+
*/
|
|
35
|
+
constructor(message: string, status?: number | string, context?: AppErrorContext, statuses?: Statuses);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Shorthand for `new HTTPError()`.
|
|
39
|
+
*
|
|
40
|
+
* @param args The same parameters as the {@link HTTPError} constructor.
|
|
41
|
+
* @returns A new instance of {@link HTTPError}.
|
|
42
|
+
* @group Services
|
|
43
|
+
* @group Services/HTTPError
|
|
44
|
+
*/
|
|
45
|
+
declare const createHTTPError: (message: string, status?: string | number | undefined, context?: AppErrorContext | undefined, statuses?: Statuses | undefined) => HTTPError;
|
|
46
|
+
/**
|
|
47
|
+
* The type of the function that generates a new instance of {@link HTTPError}.
|
|
48
|
+
* This is exported to make it easy to type the dependency injection.
|
|
49
|
+
*
|
|
50
|
+
* @group Services/HTTPError
|
|
51
|
+
*/
|
|
52
|
+
type CreateHTTPErrorFn = typeof createHTTPError;
|
|
53
|
+
/**
|
|
54
|
+
* THe type of the {@link HTTPError} class.
|
|
55
|
+
* This is exported to make it easy to type the dependency injection.
|
|
56
|
+
*
|
|
57
|
+
* @group Services/HTTPError
|
|
58
|
+
*/
|
|
59
|
+
type HTTPErrorClass = typeof HTTPError;
|
|
60
|
+
/**
|
|
61
|
+
* A service provider that will register both the {@link HTTPError} and a generator
|
|
62
|
+
* function on the container. `HTTPError` will be the key for class, and `httpError` will
|
|
63
|
+
* be for the generator function.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
*
|
|
67
|
+
* // Register it on the container
|
|
68
|
+
* container.register(httpErrorProvider);
|
|
69
|
+
* // Getting access to the class.
|
|
70
|
+
* const HTTPError = container.get<HTTPErrorClass>('HTTPError');
|
|
71
|
+
* // Getting access to the function.
|
|
72
|
+
* const httpError = container.get<CreateHTTPErrorFn>('httpError');
|
|
73
|
+
*
|
|
74
|
+
* @group Providers
|
|
75
|
+
* @group Services/HTTPError
|
|
76
|
+
*/
|
|
77
|
+
declare const httpErrorProvider: _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>;
|
|
78
|
+
|
|
79
|
+
export { CreateHTTPErrorFn, HTTPError, HTTPErrorClass, createHTTPError, httpErrorProvider };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var httpError_exports = {};
|
|
20
|
+
__export(httpError_exports, {
|
|
21
|
+
HTTPError: () => HTTPError,
|
|
22
|
+
createHTTPError: () => createHTTPError,
|
|
23
|
+
httpErrorProvider: () => httpErrorProvider
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(httpError_exports);
|
|
26
|
+
var import_utils = require("../../utils");
|
|
27
|
+
var import_appError = require("./appError");
|
|
28
|
+
class HTTPError extends import_appError.AppError {
|
|
29
|
+
constructor(message, status = (0, import_utils.statuses)("ok"), context = {}, statuses = import_utils.statuses) {
|
|
30
|
+
super(message, { ...context, status }, statuses);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const createHTTPError = (...args) => new HTTPError(...args);
|
|
34
|
+
const httpErrorProvider = (0, import_utils.provider)((app) => {
|
|
35
|
+
app.set("HTTPError", () => HTTPError);
|
|
36
|
+
app.set("httpError", () => createHTTPError);
|
|
37
|
+
});
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
HTTPError,
|
|
41
|
+
createHTTPError,
|
|
42
|
+
httpErrorProvider
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=httpError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/services/common/httpError.ts"],"sourcesContent":["import { provider, statuses as statusesFn, type Statuses } from '../../utils';\nimport { AppError, type AppErrorContext } from './appError';\n/**\n * A type of error to be used on HTTP requests. This is the most common type of error used\n * by Jimpex.\n *\n * @group Services\n * @group Services/HTTPError\n */\nexport class HTTPError extends AppError {\n /**\n * @param message The error message.\n * @param status The HTTP status code.\n * @param context Context information related to the error.\n * @param statuses A reference to the service that generates HTTP status codes. This\n * is in case the implementation wants to use a special version from\n * the container; otherwise, it will use the `statuses` library\n * directly.\n */\n constructor(\n message: string,\n status: number | string = statusesFn('ok'),\n context: AppErrorContext = {},\n statuses: Statuses = statusesFn,\n ) {\n super(message, { ...context, status }, statuses);\n }\n}\n/**\n * Shorthand for `new HTTPError()`.\n *\n * @param args The same parameters as the {@link HTTPError} constructor.\n * @returns A new instance of {@link HTTPError}.\n * @group Services\n * @group Services/HTTPError\n */\nexport const createHTTPError = (\n ...args: ConstructorParameters<typeof HTTPError>\n): HTTPError => new HTTPError(...args);\n/**\n * The type of the function that generates a new instance of {@link HTTPError}.\n * This is exported to make it easy to type the dependency injection.\n *\n * @group Services/HTTPError\n */\nexport type CreateHTTPErrorFn = typeof createHTTPError;\n/**\n * THe type of the {@link HTTPError} class.\n * This is exported to make it easy to type the dependency injection.\n *\n * @group Services/HTTPError\n */\nexport type HTTPErrorClass = typeof HTTPError;\n/**\n * A service provider that will register both the {@link HTTPError} and a generator\n * function on the container. `HTTPError` will be the key for class, and `httpError` will\n * be for the generator function.\n *\n * @example\n *\n * // Register it on the container\n * container.register(httpErrorProvider);\n * // Getting access to the class.\n * const HTTPError = container.get<HTTPErrorClass>('HTTPError');\n * // Getting access to the function.\n * const httpError = container.get<CreateHTTPErrorFn>('httpError');\n *\n * @group Providers\n * @group Services/HTTPError\n */\nexport const httpErrorProvider = provider((app) => {\n app.set('HTTPError', () => HTTPError);\n app.set('httpError', () => createHTTPError);\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAgE;AAChE,sBAA+C;AAQxC,MAAM,kBAAkB,yBAAS;AAAA,EAUtC,YACE,SACA,aAA0B,aAAAA,UAAW,IAAI,GACzC,UAA2B,CAAC,GAC5B,WAAqB,aAAAA,UACrB;AACA,UAAM,SAAS,EAAE,GAAG,SAAS,OAAO,GAAG,QAAQ;AAAA,EACjD;AACF;AASO,MAAM,kBAAkB,IAC1B,SACW,IAAI,UAAU,GAAG,IAAI;AAgC9B,MAAM,wBAAoB,uBAAS,CAAC,QAAQ;AACjD,MAAI,IAAI,aAAa,MAAM,SAAS;AACpC,MAAI,IAAI,aAAa,MAAM,eAAe;AAC5C,CAAC;","names":["statusesFn"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
+
import { J as Jimpex } from '../../jimpex-7eaee271.js';
|
|
3
|
+
export { AppError, AppErrorClass, AppErrorContext, CreateAppErrorFn, appErrorProvider, createAppError } from './appError.js';
|
|
4
|
+
export { CreateHTTPErrorFn, HTTPError, HTTPErrorClass, createHTTPError, httpErrorProvider } from './httpError.js';
|
|
5
|
+
export { SendFile, SendFileGeneratorOptions, SendFileOptions, sendFile, sendFileProvider } from './sendFile.js';
|
|
6
|
+
import '@homer0/events-hub';
|
|
7
|
+
import '../../types/express.js';
|
|
8
|
+
import 'express';
|
|
9
|
+
import '../../types/http.js';
|
|
10
|
+
import 'https';
|
|
11
|
+
import 'http';
|
|
12
|
+
import 'spdy';
|
|
13
|
+
import 'node-fetch';
|
|
14
|
+
import '@homer0/simple-config';
|
|
15
|
+
import '../../types/utils.js';
|
|
16
|
+
import '@homer0/simple-logger';
|
|
17
|
+
import '../../utils/fns/statuses.js';
|
|
18
|
+
import 'statuses';
|
|
19
|
+
import '@homer0/path-utils';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Registers all the common services on the container.
|
|
23
|
+
*
|
|
24
|
+
* - {@link AppError | appError}
|
|
25
|
+
* - {@link HTTPError | httpError}
|
|
26
|
+
* - {@link SendFile | sendFile}
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
*
|
|
30
|
+
* // Register the collection on the container
|
|
31
|
+
* container.register(commonServicesProvider);
|
|
32
|
+
* // Getting access to one the services instance
|
|
33
|
+
* const sendFile = container.get<SendFile>('sendFile');
|
|
34
|
+
*
|
|
35
|
+
* @group Providers
|
|
36
|
+
*/
|
|
37
|
+
declare const commonServicesProvider: {
|
|
38
|
+
appErrorProvider: _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>;
|
|
39
|
+
httpErrorProvider: _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>;
|
|
40
|
+
sendFileProvider: _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>;
|
|
41
|
+
} & Record<string, _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>> & {
|
|
42
|
+
provider: true;
|
|
43
|
+
} & {
|
|
44
|
+
register: _homer0_jimple.ProviderRegisterFn<Jimpex>;
|
|
45
|
+
} & Record<string, unknown>;
|
|
46
|
+
|
|
47
|
+
export { commonServicesProvider };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var common_exports = {};
|
|
21
|
+
__export(common_exports, {
|
|
22
|
+
commonServicesProvider: () => commonServicesProvider
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(common_exports);
|
|
25
|
+
var import_utils = require("../../utils");
|
|
26
|
+
var import_appError = require("./appError");
|
|
27
|
+
var import_httpError = require("./httpError");
|
|
28
|
+
var import_sendFile = require("./sendFile");
|
|
29
|
+
__reExport(common_exports, require("./appError"), module.exports);
|
|
30
|
+
__reExport(common_exports, require("./httpError"), module.exports);
|
|
31
|
+
__reExport(common_exports, require("./sendFile"), module.exports);
|
|
32
|
+
const commonServicesProvider = (0, import_utils.providers)({
|
|
33
|
+
appErrorProvider: import_appError.appErrorProvider,
|
|
34
|
+
httpErrorProvider: import_httpError.httpErrorProvider,
|
|
35
|
+
sendFileProvider: import_sendFile.sendFileProvider
|
|
36
|
+
});
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
commonServicesProvider
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/services/common/index.ts"],"sourcesContent":["import { providers } from '../../utils';\nimport { appErrorProvider } from './appError';\nimport { httpErrorProvider } from './httpError';\nimport { sendFileProvider } from './sendFile';\n/**\n * Registers all the common services on the container.\n *\n * - {@link AppError | appError}\n * - {@link HTTPError | httpError}\n * - {@link SendFile | sendFile}\n *\n * @example\n *\n * // Register the collection on the container\n * container.register(commonServicesProvider);\n * // Getting access to one the services instance\n * const sendFile = container.get<SendFile>('sendFile');\n *\n * @group Providers\n */\nexport const commonServicesProvider = providers({\n appErrorProvider,\n httpErrorProvider,\n sendFileProvider,\n});\n\nexport * from './appError';\nexport * from './httpError';\nexport * from './sendFile';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAC1B,sBAAiC;AACjC,uBAAkC;AAClC,sBAAiC;AAuBjC,2BAAc,uBA1Bd;AA2BA,2BAAc,wBA3Bd;AA4BA,2BAAc,uBA5Bd;AAoBO,MAAM,6BAAyB,wBAAU;AAAA,EAC9C;AAAA,EACA;AAAA,EACA;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
+
import { J as Jimpex } from '../../jimpex-7eaee271.js';
|
|
3
|
+
import { Response, NextFunction } from 'express';
|
|
4
|
+
import { PathUtils } from '@homer0/path-utils';
|
|
5
|
+
import '@homer0/events-hub';
|
|
6
|
+
import '../../types/express.js';
|
|
7
|
+
import '../../types/http.js';
|
|
8
|
+
import 'https';
|
|
9
|
+
import 'http';
|
|
10
|
+
import 'spdy';
|
|
11
|
+
import 'node-fetch';
|
|
12
|
+
import '@homer0/simple-config';
|
|
13
|
+
import '../../types/utils.js';
|
|
14
|
+
import '@homer0/simple-logger';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The options to create a {@link SendFile} function.
|
|
18
|
+
*
|
|
19
|
+
* @group Services/SendFile
|
|
20
|
+
*/
|
|
21
|
+
type SendFileGeneratorOptions = {
|
|
22
|
+
/**
|
|
23
|
+
* A dictionary with the dependencies to inject.
|
|
24
|
+
*/
|
|
25
|
+
inject: {
|
|
26
|
+
pathUtils: PathUtils;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The options for the function that actually serves a file.
|
|
31
|
+
*
|
|
32
|
+
* @group Services/SendFile
|
|
33
|
+
*/
|
|
34
|
+
type SendFileOptions = {
|
|
35
|
+
/**
|
|
36
|
+
* The response object sent by the application. Necessary to write the file.
|
|
37
|
+
*/
|
|
38
|
+
res: Response;
|
|
39
|
+
/**
|
|
40
|
+
* The path of the file to serve. Depending on the `from` option, it will be either
|
|
41
|
+
* relative to the project root, or the application executable.
|
|
42
|
+
*/
|
|
43
|
+
filepath: string;
|
|
44
|
+
/**
|
|
45
|
+
* The name of a location on the `pathUtils` service from where the `filepath` is
|
|
46
|
+
* relative to. It can be `app` for the directory containing the application executable,
|
|
47
|
+
* or `project` for the project root. It could also be any other location that the
|
|
48
|
+
* implementation may have registered.
|
|
49
|
+
*
|
|
50
|
+
* @default 'app'
|
|
51
|
+
*/
|
|
52
|
+
from?: string;
|
|
53
|
+
/**
|
|
54
|
+
* The function to move to the next middleware. It can be used to report an error in
|
|
55
|
+
* case the file can't be served.
|
|
56
|
+
*
|
|
57
|
+
* @default {() => {}}
|
|
58
|
+
*/
|
|
59
|
+
next?: NextFunction;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* The type of the function that serves a file.
|
|
63
|
+
* This is exported to make it easy to type the dependency injection.
|
|
64
|
+
*
|
|
65
|
+
* @group Services/SendFile
|
|
66
|
+
*/
|
|
67
|
+
type SendFile = (options: SendFileOptions) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Generates a function to send files on the application response.
|
|
70
|
+
*
|
|
71
|
+
* @param options To inject the required dependencies.
|
|
72
|
+
* @example
|
|
73
|
+
*
|
|
74
|
+
* <caption>Basic usage</caption>
|
|
75
|
+
*
|
|
76
|
+
* // Let's say this is inside an Express middleware.
|
|
77
|
+
* // Get the function
|
|
78
|
+
* const send = sendFile(pathUtils);
|
|
79
|
+
* send({ res, filepath: 'some-file.html', next });
|
|
80
|
+
* // If your app is on "/app/index.js", this will send "/app/some-file.html".
|
|
81
|
+
*
|
|
82
|
+
* @group Services
|
|
83
|
+
* @group Services/SendFile
|
|
84
|
+
*/
|
|
85
|
+
declare const sendFile: ({ inject: { pathUtils } }: SendFileGeneratorOptions) => SendFile;
|
|
86
|
+
/**
|
|
87
|
+
* The service provider that once registered on the container will set the result of
|
|
88
|
+
* {@link sendFile} as the `sendFile` service.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
*
|
|
92
|
+
* // Register it on the container
|
|
93
|
+
* container.register(sendFileProvider);
|
|
94
|
+
* // Getting access to the service instance
|
|
95
|
+
* const sendFile = container.get<SendFile>('sendFile');
|
|
96
|
+
*
|
|
97
|
+
* @group Providers
|
|
98
|
+
* @group Services/SendFile
|
|
99
|
+
*/
|
|
100
|
+
declare const sendFileProvider: _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>;
|
|
101
|
+
|
|
102
|
+
export { SendFile, SendFileGeneratorOptions, SendFileOptions, sendFile, sendFileProvider };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var sendFile_exports = {};
|
|
20
|
+
__export(sendFile_exports, {
|
|
21
|
+
sendFile: () => sendFile,
|
|
22
|
+
sendFileProvider: () => sendFileProvider
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(sendFile_exports);
|
|
25
|
+
var import_utils = require("../../utils");
|
|
26
|
+
const sendFile = ({ inject: { pathUtils } }) => ({ res, filepath, from = "app", next = () => {
|
|
27
|
+
} }) => {
|
|
28
|
+
res.sendFile(pathUtils.joinFrom(from, filepath), (error) => {
|
|
29
|
+
if (error) {
|
|
30
|
+
next(error);
|
|
31
|
+
} else {
|
|
32
|
+
res.end();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
const sendFileProvider = (0, import_utils.provider)((app) => {
|
|
37
|
+
app.set(
|
|
38
|
+
"sendFile",
|
|
39
|
+
() => sendFile({
|
|
40
|
+
inject: {
|
|
41
|
+
pathUtils: app.get("pathUtils")
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
sendFile,
|
|
49
|
+
sendFileProvider
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=sendFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/services/common/sendFile.ts"],"sourcesContent":["import { provider } from '../../utils';\nimport type { Response, NextFunction, PathUtils } from '../../types';\n/**\n * The options to create a {@link SendFile} function.\n *\n * @group Services/SendFile\n */\nexport type SendFileGeneratorOptions = {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n pathUtils: PathUtils;\n };\n};\n/**\n * The options for the function that actually serves a file.\n *\n * @group Services/SendFile\n */\nexport type SendFileOptions = {\n /**\n * The response object sent by the application. Necessary to write the file.\n */\n res: Response;\n /**\n * The path of the file to serve. Depending on the `from` option, it will be either\n * relative to the project root, or the application executable.\n */\n filepath: string;\n /**\n * The name of a location on the `pathUtils` service from where the `filepath` is\n * relative to. It can be `app` for the directory containing the application executable,\n * or `project` for the project root. It could also be any other location that the\n * implementation may have registered.\n *\n * @default 'app'\n */\n from?: string;\n /**\n * The function to move to the next middleware. It can be used to report an error in\n * case the file can't be served.\n *\n * @default {() => {}}\n */\n next?: NextFunction;\n};\n/**\n * The type of the function that serves a file.\n * This is exported to make it easy to type the dependency injection.\n *\n * @group Services/SendFile\n */\nexport type SendFile = (options: SendFileOptions) => void;\n/**\n * Generates a function to send files on the application response.\n *\n * @param options To inject the required dependencies.\n * @example\n *\n * <caption>Basic usage</caption>\n *\n * // Let's say this is inside an Express middleware.\n * // Get the function\n * const send = sendFile(pathUtils);\n * send({ res, filepath: 'some-file.html', next });\n * // If your app is on \"/app/index.js\", this will send \"/app/some-file.html\".\n *\n * @group Services\n * @group Services/SendFile\n */\nexport const sendFile =\n ({ inject: { pathUtils } }: SendFileGeneratorOptions): SendFile =>\n ({ res, filepath, from = 'app', next = () => {} }) => {\n res.sendFile(pathUtils.joinFrom(from, filepath), (error) => {\n if (error) {\n next(error);\n } else {\n res.end();\n }\n });\n };\n\n/**\n * The service provider that once registered on the container will set the result of\n * {@link sendFile} as the `sendFile` service.\n *\n * @example\n *\n * // Register it on the container\n * container.register(sendFileProvider);\n * // Getting access to the service instance\n * const sendFile = container.get<SendFile>('sendFile');\n *\n * @group Providers\n * @group Services/SendFile\n */\nexport const sendFileProvider = provider((app) => {\n app.set('sendFile', () =>\n sendFile({\n inject: {\n pathUtils: app.get('pathUtils'),\n },\n }),\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAyB;AAuElB,MAAM,WACX,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,MACzB,CAAC,EAAE,KAAK,UAAU,OAAO,OAAO,OAAO,MAAM;AAAC,EAAE,MAAM;AACpD,MAAI,SAAS,UAAU,SAAS,MAAM,QAAQ,GAAG,CAAC,UAAU;AAC1D,QAAI,OAAO;AACT,WAAK,KAAK;AAAA,IACZ,OAAO;AACL,UAAI,IAAI;AAAA,IACV;AAAA,EACF,CAAC;AACH;AAgBK,MAAM,uBAAmB,uBAAS,CAAC,QAAQ;AAChD,MAAI;AAAA,IAAI;AAAA,IAAY,MAClB,SAAS;AAAA,MACP,QAAQ;AAAA,QACN,WAAW,IAAI,IAAI,WAAW;AAAA,MAChC;AAAA,IACF,CAAC;AAAA,EACH;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
+
import { J as Jimpex } from '../../jimpex-7eaee271.js';
|
|
3
|
+
import { PathUtils } from '@homer0/path-utils';
|
|
4
|
+
import fs from 'fs/promises';
|
|
5
|
+
import '@homer0/events-hub';
|
|
6
|
+
import '../../types/express.js';
|
|
7
|
+
import 'express';
|
|
8
|
+
import '../../types/http.js';
|
|
9
|
+
import 'https';
|
|
10
|
+
import 'http';
|
|
11
|
+
import 'spdy';
|
|
12
|
+
import 'node-fetch';
|
|
13
|
+
import '@homer0/simple-config';
|
|
14
|
+
import '../../types/utils.js';
|
|
15
|
+
import '@homer0/simple-logger';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The options to construct a {@link FrontendFs}.
|
|
19
|
+
*
|
|
20
|
+
* @group Services/FrontendFs
|
|
21
|
+
*/
|
|
22
|
+
type FrontendFsOptions = {
|
|
23
|
+
/**
|
|
24
|
+
* A dictionary with the dependencies to inject.
|
|
25
|
+
*/
|
|
26
|
+
inject: {
|
|
27
|
+
pathUtils: PathUtils;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* This service allows the application to easily work with the filesystem. The idea behind
|
|
32
|
+
* centralizing this functionalities into a service is that is pretty common to have
|
|
33
|
+
* bundling tools to generate the frontend, and on that process files can have different
|
|
34
|
+
* paths or not even be generated all. The service can be extended/overwritten to
|
|
35
|
+
* accommodate any requirements and avoid having to update or add `if`s to every `fs` call
|
|
36
|
+
* the application does.
|
|
37
|
+
* Another _'feature'_ of this service is that all the paths are relative to the directory
|
|
38
|
+
* where the app executable is located, so you don't have to remember the relative path
|
|
39
|
+
* from the place you are accessing a file to the place where it's located.
|
|
40
|
+
*
|
|
41
|
+
* @group Services
|
|
42
|
+
* @group Services/FrontendFs
|
|
43
|
+
*/
|
|
44
|
+
declare class FrontendFs {
|
|
45
|
+
/**
|
|
46
|
+
* The service that generates the relative paths.
|
|
47
|
+
*/
|
|
48
|
+
protected readonly _pathUtils: PathUtils;
|
|
49
|
+
/**
|
|
50
|
+
* @param options The options to construct the service.
|
|
51
|
+
*/
|
|
52
|
+
constructor({ inject: { pathUtils } }: FrontendFsOptions);
|
|
53
|
+
/**
|
|
54
|
+
* Deletes a file from the file system.
|
|
55
|
+
*
|
|
56
|
+
* @param filepath The path to the file.
|
|
57
|
+
*/
|
|
58
|
+
delete(filepath: string): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Reads a file from the file system.
|
|
61
|
+
*
|
|
62
|
+
* @param filepath The path to the file.
|
|
63
|
+
* @param encoding The text encoding in which the file should be read.
|
|
64
|
+
*/
|
|
65
|
+
read(filepath: string, encoding?: BufferEncoding): Promise<string>;
|
|
66
|
+
/**
|
|
67
|
+
* Writes a file on the file system.
|
|
68
|
+
*
|
|
69
|
+
* @param filepath The path to the file.
|
|
70
|
+
* @param content The contents of the file.
|
|
71
|
+
*/
|
|
72
|
+
write(filepath: string, content: Parameters<typeof fs.writeFile>[1]): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Utility method to get the path of a file relative to the application executable.
|
|
75
|
+
*
|
|
76
|
+
* @param filepath The path to the file.
|
|
77
|
+
*/
|
|
78
|
+
protected getAppPath(filepath: string): string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The service provider that once registered on the container will set an instance of
|
|
82
|
+
* {@link FrontendFs} as the `frontendFs` service.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
*
|
|
86
|
+
* // Register it on the container
|
|
87
|
+
* container.register(frontendFsProvider);
|
|
88
|
+
* // Getting access to the service instance
|
|
89
|
+
* const frontendFs = container.get<FrontendFs>('frontendFs');
|
|
90
|
+
*
|
|
91
|
+
* @group Providers
|
|
92
|
+
* @group Services/FrontendFs
|
|
93
|
+
*/
|
|
94
|
+
declare const frontendFsProvider: _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>;
|
|
95
|
+
|
|
96
|
+
export { FrontendFs, FrontendFsOptions, frontendFsProvider };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
|
+
var __publicField = (obj, key, value) => {
|
|
27
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
28
|
+
return value;
|
|
29
|
+
};
|
|
30
|
+
var frontendFs_exports = {};
|
|
31
|
+
__export(frontendFs_exports, {
|
|
32
|
+
FrontendFs: () => FrontendFs,
|
|
33
|
+
frontendFsProvider: () => frontendFsProvider
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(frontendFs_exports);
|
|
36
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
37
|
+
var import_utils = require("../../utils");
|
|
38
|
+
class FrontendFs {
|
|
39
|
+
constructor({ inject: { pathUtils } }) {
|
|
40
|
+
__publicField(this, "_pathUtils");
|
|
41
|
+
this._pathUtils = pathUtils;
|
|
42
|
+
}
|
|
43
|
+
delete(filepath) {
|
|
44
|
+
return import_promises.default.unlink(this.getAppPath(filepath));
|
|
45
|
+
}
|
|
46
|
+
read(filepath, encoding = "utf-8") {
|
|
47
|
+
return import_promises.default.readFile(this.getAppPath(filepath), encoding);
|
|
48
|
+
}
|
|
49
|
+
write(filepath, content) {
|
|
50
|
+
return import_promises.default.writeFile(this.getAppPath(filepath), content);
|
|
51
|
+
}
|
|
52
|
+
getAppPath(filepath) {
|
|
53
|
+
return this._pathUtils.joinFrom("app", filepath);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const frontendFsProvider = (0, import_utils.provider)((app) => {
|
|
57
|
+
app.set(
|
|
58
|
+
"frontendFs",
|
|
59
|
+
() => new FrontendFs({
|
|
60
|
+
inject: {
|
|
61
|
+
pathUtils: app.get("pathUtils")
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
FrontendFs,
|
|
69
|
+
frontendFsProvider
|
|
70
|
+
});
|
|
71
|
+
//# sourceMappingURL=frontendFs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/services/frontend/frontendFs.ts"],"sourcesContent":["import fs from 'fs/promises';\nimport { provider } from '../../utils';\nimport type { PathUtils } from '../../types';\n/**\n * The options to construct a {@link FrontendFs}.\n *\n * @group Services/FrontendFs\n */\nexport type FrontendFsOptions = {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n pathUtils: PathUtils;\n };\n};\n/**\n * This service allows the application to easily work with the filesystem. The idea behind\n * centralizing this functionalities into a service is that is pretty common to have\n * bundling tools to generate the frontend, and on that process files can have different\n * paths or not even be generated all. The service can be extended/overwritten to\n * accommodate any requirements and avoid having to update or add `if`s to every `fs` call\n * the application does.\n * Another _'feature'_ of this service is that all the paths are relative to the directory\n * where the app executable is located, so you don't have to remember the relative path\n * from the place you are accessing a file to the place where it's located.\n *\n * @group Services\n * @group Services/FrontendFs\n */\nexport class FrontendFs {\n /**\n * The service that generates the relative paths.\n */\n protected readonly _pathUtils: PathUtils;\n /**\n * @param options The options to construct the service.\n */\n constructor({ inject: { pathUtils } }: FrontendFsOptions) {\n this._pathUtils = pathUtils;\n }\n /**\n * Deletes a file from the file system.\n *\n * @param filepath The path to the file.\n */\n delete(filepath: string): Promise<void> {\n return fs.unlink(this.getAppPath(filepath));\n }\n /**\n * Reads a file from the file system.\n *\n * @param filepath The path to the file.\n * @param encoding The text encoding in which the file should be read.\n */\n read(filepath: string, encoding: BufferEncoding = 'utf-8'): Promise<string> {\n return fs.readFile(this.getAppPath(filepath), encoding);\n }\n /**\n * Writes a file on the file system.\n *\n * @param filepath The path to the file.\n * @param content The contents of the file.\n */\n write(filepath: string, content: Parameters<typeof fs.writeFile>[1]): Promise<void> {\n return fs.writeFile(this.getAppPath(filepath), content);\n }\n /**\n * Utility method to get the path of a file relative to the application executable.\n *\n * @param filepath The path to the file.\n */\n protected getAppPath(filepath: string): string {\n return this._pathUtils.joinFrom('app', filepath);\n }\n}\n/**\n * The service provider that once registered on the container will set an instance of\n * {@link FrontendFs} as the `frontendFs` service.\n *\n * @example\n *\n * // Register it on the container\n * container.register(frontendFsProvider);\n * // Getting access to the service instance\n * const frontendFs = container.get<FrontendFs>('frontendFs');\n *\n * @group Providers\n * @group Services/FrontendFs\n */\nexport const frontendFsProvider = provider((app) => {\n app.set(\n 'frontendFs',\n () =>\n new FrontendFs({\n inject: {\n pathUtils: app.get<PathUtils>('pathUtils'),\n },\n }),\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAe;AACf,mBAAyB;AA6BlB,MAAM,WAAW;AAAA,EAQtB,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAsB;AAJ1D,wBAAmB;AAKjB,SAAK,aAAa;AAAA,EACpB;AAAA,EAMA,OAAO,UAAiC;AACtC,WAAO,gBAAAA,QAAG,OAAO,KAAK,WAAW,QAAQ,CAAC;AAAA,EAC5C;AAAA,EAOA,KAAK,UAAkB,WAA2B,SAA0B;AAC1E,WAAO,gBAAAA,QAAG,SAAS,KAAK,WAAW,QAAQ,GAAG,QAAQ;AAAA,EACxD;AAAA,EAOA,MAAM,UAAkB,SAA4D;AAClF,WAAO,gBAAAA,QAAG,UAAU,KAAK,WAAW,QAAQ,GAAG,OAAO;AAAA,EACxD;AAAA,EAMU,WAAW,UAA0B;AAC7C,WAAO,KAAK,WAAW,SAAS,OAAO,QAAQ;AAAA,EACjD;AACF;AAeO,MAAM,yBAAqB,uBAAS,CAAC,QAAQ;AAClD,MAAI;AAAA,IACF;AAAA,IACA,MACE,IAAI,WAAW;AAAA,MACb,QAAQ;AAAA,QACN,WAAW,IAAI,IAAe,WAAW;AAAA,MAC3C;AAAA,IACF,CAAC;AAAA,EACL;AACF,CAAC;","names":["fs"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
+
import { J as Jimpex } from '../../jimpex-7eaee271.js';
|
|
3
|
+
export { FrontendFs, FrontendFsOptions, frontendFsProvider } from './frontendFs.js';
|
|
4
|
+
import '@homer0/events-hub';
|
|
5
|
+
import '../../types/express.js';
|
|
6
|
+
import 'express';
|
|
7
|
+
import '../../types/http.js';
|
|
8
|
+
import 'https';
|
|
9
|
+
import 'http';
|
|
10
|
+
import 'spdy';
|
|
11
|
+
import 'node-fetch';
|
|
12
|
+
import '@homer0/simple-config';
|
|
13
|
+
import '../../types/utils.js';
|
|
14
|
+
import '@homer0/simple-logger';
|
|
15
|
+
import '@homer0/path-utils';
|
|
16
|
+
import 'fs/promises';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Registers all the frontend services on the container.
|
|
20
|
+
*
|
|
21
|
+
* - {@link FrontendFs | frontendFs}
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
*
|
|
25
|
+
* // Register the collection on the container
|
|
26
|
+
* container.register(frontendServicesProvider);
|
|
27
|
+
* // Getting access to one the services instance
|
|
28
|
+
* const frontendFs = container.get<FrontendFs>('frontendFs');
|
|
29
|
+
*
|
|
30
|
+
* @group Providers
|
|
31
|
+
*/
|
|
32
|
+
declare const frontendServicesProvider: {
|
|
33
|
+
frontendFsProvider: _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>;
|
|
34
|
+
} & Record<string, _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>> & {
|
|
35
|
+
provider: true;
|
|
36
|
+
} & {
|
|
37
|
+
register: _homer0_jimple.ProviderRegisterFn<Jimpex>;
|
|
38
|
+
} & Record<string, unknown>;
|
|
39
|
+
|
|
40
|
+
export { frontendServicesProvider };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var frontend_exports = {};
|
|
21
|
+
__export(frontend_exports, {
|
|
22
|
+
frontendServicesProvider: () => frontendServicesProvider
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(frontend_exports);
|
|
25
|
+
var import_utils = require("../../utils");
|
|
26
|
+
var import_frontendFs = require("./frontendFs");
|
|
27
|
+
__reExport(frontend_exports, require("./frontendFs"), module.exports);
|
|
28
|
+
const frontendServicesProvider = (0, import_utils.providers)({
|
|
29
|
+
frontendFsProvider: import_frontendFs.frontendFsProvider
|
|
30
|
+
});
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
frontendServicesProvider
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/services/frontend/index.ts"],"sourcesContent":["import { providers } from '../../utils';\nimport { frontendFsProvider } from './frontendFs';\n/**\n * Registers all the frontend services on the container.\n *\n * - {@link FrontendFs | frontendFs}\n *\n * @example\n *\n * // Register the collection on the container\n * container.register(frontendServicesProvider);\n * // Getting access to one the services instance\n * const frontendFs = container.get<FrontendFs>('frontendFs');\n *\n * @group Providers\n */\nexport const frontendServicesProvider = providers({\n frontendFsProvider,\n});\n\nexport * from './frontendFs';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAC1B,wBAAmC;AAmBnC,6BAAc,yBApBd;AAgBO,MAAM,+BAA2B,wBAAU;AAAA,EAChD;AACF,CAAC;","names":[]}
|