jimpex 8.0.0 → 9.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.
Files changed (205) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +2 -2
  3. package/dist/app/index.d.mts +14 -0
  4. package/dist/app/index.d.ts +5 -4
  5. package/dist/app/index.js +4 -0
  6. package/dist/app/jimpex.d.mts +14 -0
  7. package/dist/app/jimpex.d.ts +3 -2
  8. package/dist/app/jimpex.js +225 -0
  9. package/dist/app/jimpex.js.map +1 -1
  10. package/dist/controllers/common/config.d.mts +79 -0
  11. package/dist/controllers/common/config.d.ts +3 -2
  12. package/dist/controllers/common/config.js +18 -0
  13. package/dist/controllers/common/config.js.map +1 -1
  14. package/dist/controllers/common/health.d.mts +83 -0
  15. package/dist/controllers/common/health.d.ts +4 -3
  16. package/dist/controllers/common/health.js +18 -0
  17. package/dist/controllers/common/health.js.map +1 -1
  18. package/dist/controllers/common/index.d.mts +21 -0
  19. package/dist/controllers/common/index.d.ts +4 -4
  20. package/dist/controllers/common/index.js +6 -0
  21. package/dist/controllers/common/statics.d.mts +215 -0
  22. package/dist/controllers/common/statics.d.ts +4 -4
  23. package/dist/controllers/common/statics.js +51 -0
  24. package/dist/controllers/common/statics.js.map +1 -1
  25. package/dist/controllers/index.d.mts +24 -0
  26. package/dist/controllers/index.d.ts +4 -4
  27. package/dist/controllers/index.js +5 -0
  28. package/dist/controllers/utils/gateway.d.mts +725 -0
  29. package/dist/controllers/utils/gateway.d.ts +4 -3
  30. package/dist/controllers/utils/gateway.js +152 -0
  31. package/dist/controllers/utils/gateway.js.map +1 -1
  32. package/dist/controllers/utils/index.d.mts +17 -0
  33. package/dist/controllers/utils/index.d.ts +4 -3
  34. package/dist/controllers/utils/index.js +4 -0
  35. package/dist/esm/app/jimpex.js +222 -1
  36. package/dist/esm/app/jimpex.js.map +1 -1
  37. package/dist/esm/{chunk-T2T6Q22Z.js → chunk-2B2CG5KL.js} +1 -1
  38. package/dist/esm/controllers/common/config.js +19 -1
  39. package/dist/esm/controllers/common/config.js.map +1 -1
  40. package/dist/esm/controllers/common/health.js +19 -1
  41. package/dist/esm/controllers/common/health.js.map +1 -1
  42. package/dist/esm/controllers/common/statics.js +48 -1
  43. package/dist/esm/controllers/common/statics.js.map +1 -1
  44. package/dist/esm/controllers/utils/gateway.js +153 -1
  45. package/dist/esm/controllers/utils/gateway.js.map +1 -1
  46. package/dist/esm/middlewares/common/errorHandler.js +25 -1
  47. package/dist/esm/middlewares/common/errorHandler.js.map +1 -1
  48. package/dist/esm/middlewares/common/forceHTTPS.js +13 -1
  49. package/dist/esm/middlewares/common/forceHTTPS.js.map +1 -1
  50. package/dist/esm/middlewares/common/hsts.js +22 -1
  51. package/dist/esm/middlewares/common/hsts.js.map +1 -1
  52. package/dist/esm/middlewares/html/fastHTML.js +55 -1
  53. package/dist/esm/middlewares/html/fastHTML.js.map +1 -1
  54. package/dist/esm/middlewares/html/showHTML.js +33 -1
  55. package/dist/esm/middlewares/html/showHTML.js.map +1 -1
  56. package/dist/esm/middlewares/utils/versionValidator.js +35 -1
  57. package/dist/esm/middlewares/utils/versionValidator.js.map +1 -1
  58. package/dist/esm/services/common/appError.js +48 -2
  59. package/dist/esm/services/common/appError.js.map +1 -1
  60. package/dist/esm/services/common/httpError.js +10 -1
  61. package/dist/esm/services/common/httpError.js.map +1 -1
  62. package/dist/esm/services/common/index.js +1 -1
  63. package/dist/esm/services/common/sendFile.js +1 -1
  64. package/dist/esm/services/frontend/frontendFs.js +29 -1
  65. package/dist/esm/services/frontend/frontendFs.js.map +1 -1
  66. package/dist/esm/services/frontend/index.js +1 -1
  67. package/dist/esm/services/html/htmlGenerator.js +51 -1
  68. package/dist/esm/services/html/htmlGenerator.js.map +1 -1
  69. package/dist/esm/services/html/index.js +1 -1
  70. package/dist/esm/services/http/apiClient.js +27 -1
  71. package/dist/esm/services/http/apiClient.js.map +1 -1
  72. package/dist/esm/services/http/http.js +50 -1
  73. package/dist/esm/services/http/http.js.map +1 -1
  74. package/dist/esm/services/http/index.js +1 -1
  75. package/dist/esm/services/http/responsesBuilder.js +49 -2
  76. package/dist/esm/services/http/responsesBuilder.js.map +1 -1
  77. package/dist/esm/services/utils/ensureBearerToken.js +17 -1
  78. package/dist/esm/services/utils/ensureBearerToken.js.map +1 -1
  79. package/dist/esm/services/utils/index.js +1 -1
  80. package/dist/esm/utils/fns/others.js +1 -1
  81. package/dist/esm/utils/fns/routes.js +1 -1
  82. package/dist/esm/utils/fns/routes.js.map +1 -1
  83. package/dist/esm/utils/fns/statuses.js +1 -1
  84. package/dist/esm/utils/fns/text.js +1 -1
  85. package/dist/esm/utils/wrappers.js +1 -1
  86. package/dist/{jimpex-7eaee271.d.ts → index-b2a04c78.d.ts} +9 -5
  87. package/dist/index-efeb437e.d.ts +1282 -0
  88. package/dist/index.d.mts +46 -0
  89. package/dist/index.d.ts +1 -1
  90. package/dist/index.js +9 -0
  91. package/dist/middlewares/common/errorHandler.d.mts +132 -0
  92. package/dist/middlewares/common/errorHandler.d.ts +4 -3
  93. package/dist/middlewares/common/errorHandler.js +24 -0
  94. package/dist/middlewares/common/errorHandler.js.map +1 -1
  95. package/dist/middlewares/common/forceHTTPS.d.mts +69 -0
  96. package/dist/middlewares/common/forceHTTPS.d.ts +5 -4
  97. package/dist/middlewares/common/forceHTTPS.js +12 -0
  98. package/dist/middlewares/common/forceHTTPS.js.map +1 -1
  99. package/dist/middlewares/common/hsts.d.mts +110 -0
  100. package/dist/middlewares/common/hsts.d.ts +5 -4
  101. package/dist/middlewares/common/hsts.js +21 -0
  102. package/dist/middlewares/common/hsts.js.map +1 -1
  103. package/dist/middlewares/common/index.d.mts +22 -0
  104. package/dist/middlewares/common/index.d.ts +4 -3
  105. package/dist/middlewares/common/index.js +6 -0
  106. package/dist/middlewares/html/fastHTML.d.mts +180 -0
  107. package/dist/middlewares/html/fastHTML.d.ts +4 -4
  108. package/dist/middlewares/html/fastHTML.js +54 -0
  109. package/dist/middlewares/html/fastHTML.js.map +1 -1
  110. package/dist/middlewares/html/index.d.mts +21 -0
  111. package/dist/middlewares/html/index.d.ts +4 -4
  112. package/dist/middlewares/html/index.js +5 -0
  113. package/dist/middlewares/html/showHTML.d.mts +127 -0
  114. package/dist/middlewares/html/showHTML.d.ts +4 -4
  115. package/dist/middlewares/html/showHTML.js +32 -0
  116. package/dist/middlewares/html/showHTML.js.map +1 -1
  117. package/dist/middlewares/index.d.mts +30 -0
  118. package/dist/middlewares/index.d.ts +4 -4
  119. package/dist/middlewares/index.js +6 -0
  120. package/dist/middlewares/utils/index.d.mts +20 -0
  121. package/dist/middlewares/utils/index.d.ts +4 -3
  122. package/dist/middlewares/utils/index.js +4 -0
  123. package/dist/middlewares/utils/versionValidator.d.mts +215 -0
  124. package/dist/middlewares/utils/versionValidator.d.ts +4 -3
  125. package/dist/middlewares/utils/versionValidator.js +34 -0
  126. package/dist/middlewares/utils/versionValidator.js.map +1 -1
  127. package/dist/services/common/appError.d.mts +139 -0
  128. package/dist/services/common/appError.d.ts +4 -3
  129. package/dist/services/common/appError.js +47 -1
  130. package/dist/services/common/appError.js.map +1 -1
  131. package/dist/services/common/httpError.d.mts +80 -0
  132. package/dist/services/common/httpError.d.ts +4 -3
  133. package/dist/services/common/httpError.js +9 -0
  134. package/dist/services/common/httpError.js.map +1 -1
  135. package/dist/services/common/index.d.mts +47 -0
  136. package/dist/services/common/index.d.ts +4 -4
  137. package/dist/services/common/index.js +4 -1
  138. package/dist/services/common/sendFile.d.mts +102 -0
  139. package/dist/services/common/sendFile.d.ts +3 -3
  140. package/dist/services/frontend/frontendFs.d.mts +96 -0
  141. package/dist/services/frontend/frontendFs.d.ts +3 -3
  142. package/dist/services/frontend/frontendFs.js +32 -0
  143. package/dist/services/frontend/frontendFs.js.map +1 -1
  144. package/dist/services/frontend/index.d.mts +40 -0
  145. package/dist/services/frontend/index.d.ts +4 -4
  146. package/dist/services/frontend/index.js +2 -1
  147. package/dist/services/html/htmlGenerator.d.mts +237 -0
  148. package/dist/services/html/htmlGenerator.d.ts +2 -2
  149. package/dist/services/html/htmlGenerator.js +50 -0
  150. package/dist/services/html/htmlGenerator.js.map +1 -1
  151. package/dist/services/html/index.d.mts +43 -0
  152. package/dist/services/html/index.d.ts +4 -4
  153. package/dist/services/html/index.js +2 -1
  154. package/dist/services/http/apiClient.d.mts +170 -0
  155. package/dist/services/http/apiClient.d.ts +4 -3
  156. package/dist/services/http/apiClient.js +26 -0
  157. package/dist/services/http/apiClient.js.map +1 -1
  158. package/dist/services/http/http.d.mts +176 -0
  159. package/dist/services/http/http.d.ts +4 -3
  160. package/dist/services/http/http.js +53 -0
  161. package/dist/services/http/http.js.map +1 -1
  162. package/dist/services/http/index.d.mts +51 -0
  163. package/dist/services/http/index.d.ts +4 -3
  164. package/dist/services/http/index.js +4 -1
  165. package/dist/services/http/responsesBuilder.d.mts +179 -0
  166. package/dist/services/http/responsesBuilder.d.ts +3 -2
  167. package/dist/services/http/responsesBuilder.js +48 -1
  168. package/dist/services/http/responsesBuilder.js.map +1 -1
  169. package/dist/services/index.d.mts +33 -0
  170. package/dist/services/index.d.ts +4 -4
  171. package/dist/services/index.js +8 -0
  172. package/dist/services/utils/ensureBearerToken.d.mts +158 -0
  173. package/dist/services/utils/ensureBearerToken.d.ts +5 -4
  174. package/dist/services/utils/ensureBearerToken.js +16 -0
  175. package/dist/services/utils/ensureBearerToken.js.map +1 -1
  176. package/dist/services/utils/index.d.mts +44 -0
  177. package/dist/services/utils/index.d.ts +4 -3
  178. package/dist/services/utils/index.js +2 -1
  179. package/dist/types/events.d.mts +14 -0
  180. package/dist/types/events.d.ts +5 -4
  181. package/dist/types/express.d.mts +10 -0
  182. package/dist/types/http.d.mts +79 -0
  183. package/dist/types/index.d.mts +14 -0
  184. package/dist/types/index.d.ts +1 -1
  185. package/dist/types/index.js +9 -0
  186. package/dist/types/options.d.mts +14 -0
  187. package/dist/types/options.d.ts +4 -3
  188. package/dist/types/utils.d.mts +48 -0
  189. package/dist/types/wootils.d.mts +4 -0
  190. package/dist/utils/fns/index.d.mts +5 -0
  191. package/dist/utils/fns/index.js +7 -0
  192. package/dist/utils/fns/others.d.mts +17 -0
  193. package/dist/utils/fns/routes.d.mts +39 -0
  194. package/dist/utils/fns/routes.js.map +1 -1
  195. package/dist/utils/fns/statuses.d.mts +45 -0
  196. package/dist/utils/fns/statuses.js +4 -0
  197. package/dist/utils/fns/statuses.js.map +1 -1
  198. package/dist/utils/fns/text.d.mts +9 -0
  199. package/dist/utils/index.d.mts +19 -0
  200. package/dist/utils/index.d.ts +5 -4
  201. package/dist/utils/index.js +5 -0
  202. package/dist/utils/wrappers.d.mts +14 -0
  203. package/dist/utils/wrappers.d.ts +4 -3
  204. package/package.json +43 -43
  205. /package/dist/esm/{chunk-T2T6Q22Z.js.map → chunk-2B2CG5KL.js.map} +0 -0
@@ -0,0 +1,139 @@
1
+ import * as _homer0_jimple from '@homer0/jimple';
2
+ import { J as Jimpex } from '../../index-efeb437e.js';
3
+ import { Statuses } from '../../utils/fns/statuses.mjs';
4
+ import '../../types/express.mjs';
5
+ import 'express';
6
+ import '../../types/http.mjs';
7
+ import 'https';
8
+ import 'http';
9
+ import 'spdy';
10
+ import 'node-fetch';
11
+ import '../../types/utils.mjs';
12
+ import '@homer0/path-utils';
13
+ import '@homer0/simple-logger';
14
+ import '@homer0/simple-config';
15
+ import '@homer0/events-hub';
16
+ import 'statuses';
17
+
18
+ /**
19
+ * A dictionary with some context information that can be provided to {@link AppError}.
20
+ *
21
+ * @group Services/AppError
22
+ */
23
+ type AppErrorContext = {
24
+ /**
25
+ * Extra information that the error handler can pick and include the response.
26
+ */
27
+ response?: unknown;
28
+ /**
29
+ * A status code or name for the error handler to set in the response.
30
+ */
31
+ status?: string | number;
32
+ } & Record<string, unknown>;
33
+ /**
34
+ * A simple subclass of `Error` but with support for context information.
35
+ *
36
+ * @group Services
37
+ * @group Services/AppError
38
+ */
39
+ declare class AppError extends Error {
40
+ /**
41
+ * The date of when the error was generated.
42
+ */
43
+ readonly _date: Date;
44
+ /**
45
+ * The context information that can be provided to the error, and picked by the error
46
+ * handler.
47
+ */
48
+ readonly _context: AppErrorContext;
49
+ /**
50
+ * The service that generates HTTP status codes.
51
+ */
52
+ protected _statuses: Statuses;
53
+ /**
54
+ * @param message The message of the error.
55
+ * @param context The context information, for the error handler.
56
+ * @param statuses A reference to the service that generates HTTP status codes. This
57
+ * is in case the implementation wants to use a special version from
58
+ * the container; otherwise, it will use the `statuses` library
59
+ * directly.
60
+ */
61
+ constructor(message: string, context?: AppErrorContext, statuses?: Statuses);
62
+ /**
63
+ * Gets an object that can be included in a response from the application. This method
64
+ * is a helper for the `response` getter, as it allows for the assertion of the response
65
+ * type.
66
+ *
67
+ * @template T The type of the response.
68
+ */
69
+ getResponse<T>(): T;
70
+ /**
71
+ * Information about the error that can be included in a response. This is set using the
72
+ * `response` key in the `context` option.
73
+ */
74
+ get response(): unknown;
75
+ /**
76
+ * An HTTP status code related to the error. This is set using the `status` key on the
77
+ * `context`.
78
+ */
79
+ get status(): number | undefined;
80
+ /**
81
+ * Context information related to the error.
82
+ */
83
+ get context(): unknown;
84
+ /**
85
+ * The date of when the error was generated.
86
+ */
87
+ get date(): Date;
88
+ /**
89
+ * Utility method that formats the context before saving it in the instance:
90
+ * - If the context includes a `status` as a `string`, it will try to replace it with
91
+ * its actual status code from the `statuses `service.
92
+ *
93
+ * @param context The original context sent to the constructor.
94
+ */
95
+ protected _parseContext(context: AppErrorContext): AppErrorContext;
96
+ }
97
+ /**
98
+ * Shorthand for `new AppError()`.
99
+ *
100
+ * @param args The same parameters as the {@link AppError} constructor.
101
+ * @returns A new instance of {@link AppError}.
102
+ * @group Services
103
+ * @group Services/AppError
104
+ */
105
+ declare const createAppError: (message: string, context?: AppErrorContext | undefined, statuses?: Statuses | undefined) => AppError;
106
+ /**
107
+ * The type of the function that generates a new instance of {@link AppError}.
108
+ * This is exported to make it easy to type the dependency injection.
109
+ *
110
+ * @group Services/AppError
111
+ */
112
+ type CreateAppErrorFn = typeof createAppError;
113
+ /**
114
+ * THe type of the {@link AppError} class.
115
+ * This is exported to make it easy to type the dependency injection.
116
+ *
117
+ * @group Services/AppError
118
+ */
119
+ type AppErrorClass = typeof AppError;
120
+ /**
121
+ * A service provider that will register both, {@link AppError} and
122
+ * {@link createAppError}, on the container. `AppError` will be the key for class, and
123
+ * `appError` will be for the generator function.
124
+ *
125
+ * @example
126
+ *
127
+ * // Register it on the container
128
+ * container.register(appErrorProvider);
129
+ * // Getting access to the class.
130
+ * const AppError = container.get<AppErrorClass>('AppError');
131
+ * // Getting access to the function.
132
+ * const appError = container.get<CreateAppErrorFn>('appError');
133
+ *
134
+ * @group Providers
135
+ * @group Services/AppError
136
+ */
137
+ declare const appErrorProvider: _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>;
138
+
139
+ export { AppError, AppErrorClass, AppErrorContext, CreateAppErrorFn, appErrorProvider, createAppError };
@@ -1,7 +1,6 @@
1
1
  import * as _homer0_jimple from '@homer0/jimple';
2
- import { J as Jimpex } from '../../jimpex-7eaee271.js';
2
+ import { J as Jimpex } from '../../index-b2a04c78.js';
3
3
  import { Statuses } from '../../utils/fns/statuses.js';
4
- import '@homer0/events-hub';
5
4
  import '../../types/express.js';
6
5
  import 'express';
7
6
  import '../../types/http.js';
@@ -9,9 +8,11 @@ import 'https';
9
8
  import 'http';
10
9
  import 'spdy';
11
10
  import 'node-fetch';
12
- import '@homer0/simple-config';
13
11
  import '../../types/utils.js';
12
+ import '@homer0/path-utils';
14
13
  import '@homer0/simple-logger';
14
+ import '@homer0/simple-config';
15
+ import '@homer0/events-hub';
15
16
  import 'statuses';
16
17
 
17
18
  /**
@@ -30,34 +30,80 @@ __export(appError_exports, {
30
30
  module.exports = __toCommonJS(appError_exports);
31
31
  var import_utils = require("../../utils");
32
32
  class AppError extends Error {
33
+ /**
34
+ * @param message The message of the error.
35
+ * @param context The context information, for the error handler.
36
+ * @param statuses A reference to the service that generates HTTP status codes. This
37
+ * is in case the implementation wants to use a special version from
38
+ * the container; otherwise, it will use the `statuses` library
39
+ * directly.
40
+ */
33
41
  constructor(message, context = {}, statuses = import_utils.statuses) {
34
42
  super(message);
43
+ /**
44
+ * The date of when the error was generated.
45
+ */
35
46
  __publicField(this, "_date");
47
+ /**
48
+ * The context information that can be provided to the error, and picked by the error
49
+ * handler.
50
+ */
36
51
  __publicField(this, "_context");
52
+ /**
53
+ * The service that generates HTTP status codes.
54
+ */
37
55
  __publicField(this, "_statuses");
38
56
  this.name = this.constructor.name;
39
- this._date = new Date();
57
+ this._date = /* @__PURE__ */ new Date();
40
58
  this._statuses = statuses;
41
59
  this._context = this._parseContext(context);
42
60
  if (Error.captureStackTrace) {
43
61
  Error.captureStackTrace(this, this.constructor);
44
62
  }
45
63
  }
64
+ /**
65
+ * Gets an object that can be included in a response from the application. This method
66
+ * is a helper for the `response` getter, as it allows for the assertion of the response
67
+ * type.
68
+ *
69
+ * @template T The type of the response.
70
+ */
46
71
  getResponse() {
47
72
  return this.response;
48
73
  }
74
+ /**
75
+ * Information about the error that can be included in a response. This is set using the
76
+ * `response` key in the `context` option.
77
+ */
49
78
  get response() {
50
79
  return this._context.response || {};
51
80
  }
81
+ /**
82
+ * An HTTP status code related to the error. This is set using the `status` key on the
83
+ * `context`.
84
+ */
52
85
  get status() {
53
86
  return this._context.status;
54
87
  }
88
+ /**
89
+ * Context information related to the error.
90
+ */
55
91
  get context() {
56
92
  return this._context;
57
93
  }
94
+ /**
95
+ * The date of when the error was generated.
96
+ */
58
97
  get date() {
59
98
  return this._date;
60
99
  }
100
+ /**
101
+ * Utility method that formats the context before saving it in the instance:
102
+ * - If the context includes a `status` as a `string`, it will try to replace it with
103
+ * its actual status code from the `statuses `service.
104
+ *
105
+ * @param context The original context sent to the constructor.
106
+ */
61
107
  _parseContext(context) {
62
108
  const result = { ...context };
63
109
  if (result.status && typeof result.status === "string") {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/services/common/appError.ts"],"sourcesContent":["import { provider, statuses as statusesFn, type Statuses } from '../../utils';\n/**\n * A dictionary with some context information that can be provided to {@link AppError}.\n *\n * @group Services/AppError\n */\nexport type AppErrorContext = {\n /**\n * Extra information that the error handler can pick and include the response.\n */\n response?: unknown;\n /**\n * A status code or name for the error handler to set in the response.\n */\n status?: string | number;\n} & Record<string, unknown>;\n/**\n * A simple subclass of `Error` but with support for context information.\n *\n * @group Services\n * @group Services/AppError\n */\nexport class AppError extends Error {\n /**\n * The date of when the error was generated.\n */\n readonly _date: Date;\n /**\n * The context information that can be provided to the error, and picked by the error\n * handler.\n */\n readonly _context: AppErrorContext;\n /**\n * The service that generates HTTP status codes.\n */\n protected _statuses: Statuses;\n /**\n * @param message The message of the error.\n * @param context The context information, for the error handler.\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 context: AppErrorContext = {},\n statuses: Statuses = statusesFn,\n ) {\n super(message);\n this.name = this.constructor.name;\n this._date = new Date();\n this._statuses = statuses;\n this._context = this._parseContext(context);\n\n // Limit the stack trace if possible.\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n /**\n * Gets an object that can be included in a response from the application. This method\n * is a helper for the `response` getter, as it allows for the assertion of the response\n * type.\n *\n * @template T The type of the response.\n */\n getResponse<T>(): T {\n return this.response as T;\n }\n /**\n * Information about the error that can be included in a response. This is set using the\n * `response` key in the `context` option.\n */\n get response(): unknown {\n return this._context.response || {};\n }\n /**\n * An HTTP status code related to the error. This is set using the `status` key on the\n * `context`.\n */\n get status(): number | undefined {\n return this._context.status as number | undefined;\n }\n /**\n * Context information related to the error.\n */\n get context(): unknown {\n return this._context;\n }\n /**\n * The date of when the error was generated.\n */\n get date(): Date {\n return this._date;\n }\n /**\n * Utility method that formats the context before saving it in the instance:\n * - If the context includes a `status` as a `string`, it will try to replace it with\n * its actual status code from the `statuses `service.\n *\n * @param context The original context sent to the constructor.\n */\n protected _parseContext(context: AppErrorContext): AppErrorContext {\n const result = { ...context };\n if (result.status && typeof result.status === 'string') {\n result.status = this._statuses.code[result.status.toLowerCase()] || result.status;\n }\n\n return result;\n }\n}\n/**\n * Shorthand for `new AppError()`.\n *\n * @param args The same parameters as the {@link AppError} constructor.\n * @returns A new instance of {@link AppError}.\n * @group Services\n * @group Services/AppError\n */\nexport const createAppError = (\n ...args: ConstructorParameters<typeof AppError>\n): AppError => new AppError(...args);\n/**\n * The type of the function that generates a new instance of {@link AppError}.\n * This is exported to make it easy to type the dependency injection.\n *\n * @group Services/AppError\n */\nexport type CreateAppErrorFn = typeof createAppError;\n/**\n * THe type of the {@link AppError} class.\n * This is exported to make it easy to type the dependency injection.\n *\n * @group Services/AppError\n */\nexport type AppErrorClass = typeof AppError;\n/**\n * A service provider that will register both, {@link AppError} and\n * {@link createAppError}, on the container. `AppError` will be the key for class, and\n * `appError` will be for the generator function.\n *\n * @example\n *\n * // Register it on the container\n * container.register(appErrorProvider);\n * // Getting access to the class.\n * const AppError = container.get<AppErrorClass>('AppError');\n * // Getting access to the function.\n * const appError = container.get<CreateAppErrorFn>('appError');\n *\n * @group Providers\n * @group Services/AppError\n */\nexport const appErrorProvider = provider((app) => {\n app.set('AppError', () => AppError);\n app.set('appError', () => createAppError);\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAgE;AAsBzD,MAAM,iBAAiB,MAAM;AAAA,EAsBlC,YACE,SACA,UAA2B,CAAC,GAC5B,WAAqB,aAAAA,UACrB;AACA,UAAM,OAAO;AAvBf,wBAAS;AAKT,wBAAS;AAIT,wBAAU;AAeR,SAAK,OAAO,KAAK,YAAY;AAC7B,SAAK,QAAQ,IAAI,KAAK;AACtB,SAAK,YAAY;AACjB,SAAK,WAAW,KAAK,cAAc,OAAO;AAG1C,QAAI,MAAM,mBAAmB;AAC3B,YAAM,kBAAkB,MAAM,KAAK,WAAW;AAAA,IAChD;AAAA,EACF;AAAA,EAQA,cAAoB;AAClB,WAAO,KAAK;AAAA,EACd;AAAA,EAKA,IAAI,WAAoB;AACtB,WAAO,KAAK,SAAS,YAAY,CAAC;AAAA,EACpC;AAAA,EAKA,IAAI,SAA6B;AAC/B,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EAIA,IAAI,UAAmB;AACrB,WAAO,KAAK;AAAA,EACd;AAAA,EAIA,IAAI,OAAa;AACf,WAAO,KAAK;AAAA,EACd;AAAA,EAQU,cAAc,SAA2C;AACjE,UAAM,SAAS,EAAE,GAAG,QAAQ;AAC5B,QAAI,OAAO,UAAU,OAAO,OAAO,WAAW,UAAU;AACtD,aAAO,SAAS,KAAK,UAAU,KAAK,OAAO,OAAO,YAAY,MAAM,OAAO;AAAA,IAC7E;AAEA,WAAO;AAAA,EACT;AACF;AASO,MAAM,iBAAiB,IACzB,SACU,IAAI,SAAS,GAAG,IAAI;AAgC5B,MAAM,uBAAmB,uBAAS,CAAC,QAAQ;AAChD,MAAI,IAAI,YAAY,MAAM,QAAQ;AAClC,MAAI,IAAI,YAAY,MAAM,cAAc;AAC1C,CAAC;","names":["statusesFn"]}
1
+ {"version":3,"sources":["../../../src/services/common/appError.ts"],"sourcesContent":["import { provider, statuses as statusesFn, type Statuses } from '../../utils';\n/**\n * A dictionary with some context information that can be provided to {@link AppError}.\n *\n * @group Services/AppError\n */\nexport type AppErrorContext = {\n /**\n * Extra information that the error handler can pick and include the response.\n */\n response?: unknown;\n /**\n * A status code or name for the error handler to set in the response.\n */\n status?: string | number;\n} & Record<string, unknown>;\n/**\n * A simple subclass of `Error` but with support for context information.\n *\n * @group Services\n * @group Services/AppError\n */\nexport class AppError extends Error {\n /**\n * The date of when the error was generated.\n */\n readonly _date: Date;\n /**\n * The context information that can be provided to the error, and picked by the error\n * handler.\n */\n readonly _context: AppErrorContext;\n /**\n * The service that generates HTTP status codes.\n */\n protected _statuses: Statuses;\n /**\n * @param message The message of the error.\n * @param context The context information, for the error handler.\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 context: AppErrorContext = {},\n statuses: Statuses = statusesFn,\n ) {\n super(message);\n this.name = this.constructor.name;\n this._date = new Date();\n this._statuses = statuses;\n this._context = this._parseContext(context);\n\n // Limit the stack trace if possible.\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n /**\n * Gets an object that can be included in a response from the application. This method\n * is a helper for the `response` getter, as it allows for the assertion of the response\n * type.\n *\n * @template T The type of the response.\n */\n getResponse<T>(): T {\n return this.response as T;\n }\n /**\n * Information about the error that can be included in a response. This is set using the\n * `response` key in the `context` option.\n */\n get response(): unknown {\n return this._context.response || {};\n }\n /**\n * An HTTP status code related to the error. This is set using the `status` key on the\n * `context`.\n */\n get status(): number | undefined {\n return this._context.status as number | undefined;\n }\n /**\n * Context information related to the error.\n */\n get context(): unknown {\n return this._context;\n }\n /**\n * The date of when the error was generated.\n */\n get date(): Date {\n return this._date;\n }\n /**\n * Utility method that formats the context before saving it in the instance:\n * - If the context includes a `status` as a `string`, it will try to replace it with\n * its actual status code from the `statuses `service.\n *\n * @param context The original context sent to the constructor.\n */\n protected _parseContext(context: AppErrorContext): AppErrorContext {\n const result = { ...context };\n if (result.status && typeof result.status === 'string') {\n result.status = this._statuses.code[result.status.toLowerCase()] || result.status;\n }\n\n return result;\n }\n}\n/**\n * Shorthand for `new AppError()`.\n *\n * @param args The same parameters as the {@link AppError} constructor.\n * @returns A new instance of {@link AppError}.\n * @group Services\n * @group Services/AppError\n */\nexport const createAppError = (\n ...args: ConstructorParameters<typeof AppError>\n): AppError => new AppError(...args);\n/**\n * The type of the function that generates a new instance of {@link AppError}.\n * This is exported to make it easy to type the dependency injection.\n *\n * @group Services/AppError\n */\nexport type CreateAppErrorFn = typeof createAppError;\n/**\n * THe type of the {@link AppError} class.\n * This is exported to make it easy to type the dependency injection.\n *\n * @group Services/AppError\n */\nexport type AppErrorClass = typeof AppError;\n/**\n * A service provider that will register both, {@link AppError} and\n * {@link createAppError}, on the container. `AppError` will be the key for class, and\n * `appError` will be for the generator function.\n *\n * @example\n *\n * // Register it on the container\n * container.register(appErrorProvider);\n * // Getting access to the class.\n * const AppError = container.get<AppErrorClass>('AppError');\n * // Getting access to the function.\n * const appError = container.get<CreateAppErrorFn>('appError');\n *\n * @group Providers\n * @group Services/AppError\n */\nexport const appErrorProvider = provider((app) => {\n app.set('AppError', () => AppError);\n app.set('appError', () => createAppError);\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAgE;AAsBzD,MAAM,iBAAiB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBlC,YACE,SACA,UAA2B,CAAC,GAC5B,WAAqB,aAAAA,UACrB;AACA,UAAM,OAAO;AAvBf;AAAA;AAAA;AAAA,wBAAS;AAKT;AAAA;AAAA;AAAA;AAAA,wBAAS;AAIT;AAAA;AAAA;AAAA,wBAAU;AAeR,SAAK,OAAO,KAAK,YAAY;AAC7B,SAAK,QAAQ,oBAAI,KAAK;AACtB,SAAK,YAAY;AACjB,SAAK,WAAW,KAAK,cAAc,OAAO;AAG1C,QAAI,MAAM,mBAAmB;AAC3B,YAAM,kBAAkB,MAAM,KAAK,WAAW;AAAA,IAChD;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,cAAoB;AAClB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,WAAoB;AACtB,WAAO,KAAK,SAAS,YAAY,CAAC;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,SAA6B;AAC/B,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAIA,IAAI,UAAmB;AACrB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAIA,IAAI,OAAa;AACf,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQU,cAAc,SAA2C;AACjE,UAAM,SAAS,EAAE,GAAG,QAAQ;AAC5B,QAAI,OAAO,UAAU,OAAO,OAAO,WAAW,UAAU;AACtD,aAAO,SAAS,KAAK,UAAU,KAAK,OAAO,OAAO,YAAY,CAAC,KAAK,OAAO;AAAA,IAC7E;AAEA,WAAO;AAAA,EACT;AACF;AASO,MAAM,iBAAiB,IACzB,SACU,IAAI,SAAS,GAAG,IAAI;AAgC5B,MAAM,uBAAmB,uBAAS,CAAC,QAAQ;AAChD,MAAI,IAAI,YAAY,MAAM,QAAQ;AAClC,MAAI,IAAI,YAAY,MAAM,cAAc;AAC1C,CAAC;","names":["statusesFn"]}
@@ -0,0 +1,80 @@
1
+ import * as _homer0_jimple from '@homer0/jimple';
2
+ import { J as Jimpex } from '../../index-efeb437e.js';
3
+ import { Statuses } from '../../utils/fns/statuses.mjs';
4
+ import { AppError, AppErrorContext } from './appError.mjs';
5
+ import '../../types/express.mjs';
6
+ import 'express';
7
+ import '../../types/http.mjs';
8
+ import 'https';
9
+ import 'http';
10
+ import 'spdy';
11
+ import 'node-fetch';
12
+ import '../../types/utils.mjs';
13
+ import '@homer0/path-utils';
14
+ import '@homer0/simple-logger';
15
+ import '@homer0/simple-config';
16
+ import '@homer0/events-hub';
17
+ import 'statuses';
18
+
19
+ /**
20
+ * A type of error to be used on HTTP requests. This is the most common type of error used
21
+ * by Jimpex.
22
+ *
23
+ * @group Services
24
+ * @group Services/HTTPError
25
+ */
26
+ declare class HTTPError extends AppError {
27
+ /**
28
+ * @param message The error message.
29
+ * @param status The HTTP status code.
30
+ * @param context Context information related to the error.
31
+ * @param statuses A reference to the service that generates HTTP status codes. This
32
+ * is in case the implementation wants to use a special version from
33
+ * the container; otherwise, it will use the `statuses` library
34
+ * directly.
35
+ */
36
+ constructor(message: string, status?: number | string, context?: AppErrorContext, statuses?: Statuses);
37
+ }
38
+ /**
39
+ * Shorthand for `new HTTPError()`.
40
+ *
41
+ * @param args The same parameters as the {@link HTTPError} constructor.
42
+ * @returns A new instance of {@link HTTPError}.
43
+ * @group Services
44
+ * @group Services/HTTPError
45
+ */
46
+ declare const createHTTPError: (message: string, status?: string | number | undefined, context?: AppErrorContext | undefined, statuses?: Statuses | undefined) => HTTPError;
47
+ /**
48
+ * The type of the function that generates a new instance of {@link HTTPError}.
49
+ * This is exported to make it easy to type the dependency injection.
50
+ *
51
+ * @group Services/HTTPError
52
+ */
53
+ type CreateHTTPErrorFn = typeof createHTTPError;
54
+ /**
55
+ * THe type of the {@link HTTPError} class.
56
+ * This is exported to make it easy to type the dependency injection.
57
+ *
58
+ * @group Services/HTTPError
59
+ */
60
+ type HTTPErrorClass = typeof HTTPError;
61
+ /**
62
+ * A service provider that will register both the {@link HTTPError} and a generator
63
+ * function on the container. `HTTPError` will be the key for class, and `httpError` will
64
+ * be for the generator function.
65
+ *
66
+ * @example
67
+ *
68
+ * // Register it on the container
69
+ * container.register(httpErrorProvider);
70
+ * // Getting access to the class.
71
+ * const HTTPError = container.get<HTTPErrorClass>('HTTPError');
72
+ * // Getting access to the function.
73
+ * const httpError = container.get<CreateHTTPErrorFn>('httpError');
74
+ *
75
+ * @group Providers
76
+ * @group Services/HTTPError
77
+ */
78
+ declare const httpErrorProvider: _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>;
79
+
80
+ export { CreateHTTPErrorFn, HTTPError, HTTPErrorClass, createHTTPError, httpErrorProvider };
@@ -1,8 +1,7 @@
1
1
  import * as _homer0_jimple from '@homer0/jimple';
2
- import { J as Jimpex } from '../../jimpex-7eaee271.js';
2
+ import { J as Jimpex } from '../../index-b2a04c78.js';
3
3
  import { Statuses } from '../../utils/fns/statuses.js';
4
4
  import { AppError, AppErrorContext } from './appError.js';
5
- import '@homer0/events-hub';
6
5
  import '../../types/express.js';
7
6
  import 'express';
8
7
  import '../../types/http.js';
@@ -10,9 +9,11 @@ import 'https';
10
9
  import 'http';
11
10
  import 'spdy';
12
11
  import 'node-fetch';
13
- import '@homer0/simple-config';
14
12
  import '../../types/utils.js';
13
+ import '@homer0/path-utils';
15
14
  import '@homer0/simple-logger';
15
+ import '@homer0/simple-config';
16
+ import '@homer0/events-hub';
16
17
  import 'statuses';
17
18
 
18
19
  /**
@@ -26,6 +26,15 @@ module.exports = __toCommonJS(httpError_exports);
26
26
  var import_utils = require("../../utils");
27
27
  var import_appError = require("./appError");
28
28
  class HTTPError extends import_appError.AppError {
29
+ /**
30
+ * @param message The error message.
31
+ * @param status The HTTP status code.
32
+ * @param context Context information related to the error.
33
+ * @param statuses A reference to the service that generates HTTP status codes. This
34
+ * is in case the implementation wants to use a special version from
35
+ * the container; otherwise, it will use the `statuses` library
36
+ * directly.
37
+ */
29
38
  constructor(message, status = (0, import_utils.statuses)("ok"), context = {}, statuses = import_utils.statuses) {
30
39
  super(message, { ...context, status }, statuses);
31
40
  }
@@ -1 +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"]}
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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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 '../../index-efeb437e.js';
3
+ export { AppError, AppErrorClass, AppErrorContext, CreateAppErrorFn, appErrorProvider, createAppError } from './appError.mjs';
4
+ export { CreateHTTPErrorFn, HTTPError, HTTPErrorClass, createHTTPError, httpErrorProvider } from './httpError.mjs';
5
+ export { SendFile, SendFileGeneratorOptions, SendFileOptions, sendFile, sendFileProvider } from './sendFile.mjs';
6
+ import '../../types/express.mjs';
7
+ import 'express';
8
+ import '../../types/http.mjs';
9
+ import 'https';
10
+ import 'http';
11
+ import 'spdy';
12
+ import 'node-fetch';
13
+ import '../../types/utils.mjs';
14
+ import '@homer0/path-utils';
15
+ import '@homer0/simple-logger';
16
+ import '@homer0/simple-config';
17
+ import '@homer0/events-hub';
18
+ import '../../utils/fns/statuses.mjs';
19
+ import 'statuses';
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 };
@@ -1,9 +1,8 @@
1
1
  import * as _homer0_jimple from '@homer0/jimple';
2
- import { J as Jimpex } from '../../jimpex-7eaee271.js';
2
+ import { J as Jimpex } from '../../index-b2a04c78.js';
3
3
  export { AppError, AppErrorClass, AppErrorContext, CreateAppErrorFn, appErrorProvider, createAppError } from './appError.js';
4
4
  export { CreateHTTPErrorFn, HTTPError, HTTPErrorClass, createHTTPError, httpErrorProvider } from './httpError.js';
5
5
  export { SendFile, SendFileGeneratorOptions, SendFileOptions, sendFile, sendFileProvider } from './sendFile.js';
6
- import '@homer0/events-hub';
7
6
  import '../../types/express.js';
8
7
  import 'express';
9
8
  import '../../types/http.js';
@@ -11,12 +10,13 @@ import 'https';
11
10
  import 'http';
12
11
  import 'spdy';
13
12
  import 'node-fetch';
14
- import '@homer0/simple-config';
15
13
  import '../../types/utils.js';
14
+ import '@homer0/path-utils';
16
15
  import '@homer0/simple-logger';
16
+ import '@homer0/simple-config';
17
+ import '@homer0/events-hub';
17
18
  import '../../utils/fns/statuses.js';
18
19
  import 'statuses';
19
- import '@homer0/path-utils';
20
20
 
21
21
  /**
22
22
  * Registers all the common services on the container.
@@ -36,6 +36,9 @@ const commonServicesProvider = (0, import_utils.providers)({
36
36
  });
37
37
  // Annotate the CommonJS export names for ESM import in node:
38
38
  0 && (module.exports = {
39
- commonServicesProvider
39
+ commonServicesProvider,
40
+ ...require("./appError"),
41
+ ...require("./httpError"),
42
+ ...require("./sendFile")
40
43
  });
41
44
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,102 @@
1
+ import * as _homer0_jimple from '@homer0/jimple';
2
+ import { J as Jimpex } from '../../index-efeb437e.js';
3
+ import { Response, NextFunction } from 'express';
4
+ import { PathUtils } from '@homer0/path-utils';
5
+ import '../../types/express.mjs';
6
+ import '../../types/http.mjs';
7
+ import 'https';
8
+ import 'http';
9
+ import 'spdy';
10
+ import 'node-fetch';
11
+ import '../../types/utils.mjs';
12
+ import '@homer0/simple-logger';
13
+ import '@homer0/simple-config';
14
+ import '@homer0/events-hub';
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 };
@@ -1,17 +1,17 @@
1
1
  import * as _homer0_jimple from '@homer0/jimple';
2
- import { J as Jimpex } from '../../jimpex-7eaee271.js';
2
+ import { J as Jimpex } from '../../index-b2a04c78.js';
3
3
  import { Response, NextFunction } from 'express';
4
4
  import { PathUtils } from '@homer0/path-utils';
5
- import '@homer0/events-hub';
6
5
  import '../../types/express.js';
7
6
  import '../../types/http.js';
8
7
  import 'https';
9
8
  import 'http';
10
9
  import 'spdy';
11
10
  import 'node-fetch';
12
- import '@homer0/simple-config';
13
11
  import '../../types/utils.js';
14
12
  import '@homer0/simple-logger';
13
+ import '@homer0/simple-config';
14
+ import '@homer0/events-hub';
15
15
 
16
16
  /**
17
17
  * The options to create a {@link SendFile} function.