@my-nestjs-kit/core 0.0.0-stage → 0.1.0-dev.20261129010337

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 (273) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +32 -2
  3. package/dist/app-logger/console/app-logger.d.ts +33 -0
  4. package/dist/app-logger/console/app-logger.js +63 -0
  5. package/dist/app-logger/console/index.d.ts +2 -0
  6. package/dist/app-logger/console/index.js +18 -0
  7. package/dist/app-logger/console/log-colors.d.ts +30 -0
  8. package/dist/app-logger/console/log-colors.js +93 -0
  9. package/dist/db/index.d.ts +0 -0
  10. package/dist/db/index.js +0 -0
  11. package/dist/db/transactions/abstract-db-transactions.service.d.ts +37 -0
  12. package/dist/db/transactions/abstract-db-transactions.service.js +84 -0
  13. package/dist/db/tx/db-tx.service.d.ts +28 -0
  14. package/dist/db/tx/db-tx.service.js +97 -0
  15. package/dist/db/tx/index.d.ts +1 -0
  16. package/dist/db/tx/index.js +17 -0
  17. package/dist/db/value-transformers/decimal-column.transformer.d.ts +5 -0
  18. package/dist/db/value-transformers/decimal-column.transformer.js +46 -0
  19. package/dist/db/value-transformers/index.d.ts +1 -0
  20. package/dist/db/value-transformers/index.js +17 -0
  21. package/dist/decorators/GetCookies.decorator.d.ts +6 -0
  22. package/dist/decorators/GetCookies.decorator.js +30 -0
  23. package/dist/decorators/GetHeader.decorator.d.ts +2 -0
  24. package/dist/decorators/GetHeader.decorator.js +23 -0
  25. package/dist/decorators/PostAsQuery.decorator.d.ts +1 -0
  26. package/dist/decorators/PostAsQuery.decorator.js +16 -0
  27. package/dist/decorators/decoratorForReqOptions.d.ts +4 -0
  28. package/dist/decorators/decoratorForReqOptions.js +2 -0
  29. package/dist/decorators/index.d.ts +3 -0
  30. package/dist/decorators/index.js +19 -0
  31. package/dist/encryption/decrypted-local-cache.d.ts +9 -0
  32. package/dist/encryption/decrypted-local-cache.js +6 -0
  33. package/dist/encryption/encryption.configs.d.ts +1 -0
  34. package/dist/encryption/encryption.configs.js +4 -0
  35. package/dist/encryption/encryption.module.d.ts +6 -0
  36. package/dist/encryption/encryption.module.js +39 -0
  37. package/dist/encryption/encryption.service.d.ts +47 -0
  38. package/dist/encryption/encryption.service.js +307 -0
  39. package/dist/encryption/encryption.types.d.ts +16 -0
  40. package/dist/encryption/encryption.types.js +2 -0
  41. package/dist/encryption/error.base.d.ts +8 -0
  42. package/dist/encryption/error.base.js +17 -0
  43. package/dist/encryption/types.d.ts +37 -0
  44. package/dist/encryption/types.js +2 -0
  45. package/dist/guards/PostAsQuery.guard.d.ts +9 -0
  46. package/dist/guards/PostAsQuery.guard.js +38 -0
  47. package/dist/helpers/createRefSet.helper.d.ts +3 -0
  48. package/dist/helpers/createRefSet.helper.js +33 -0
  49. package/dist/helpers/enumToArray.d.ts +1 -0
  50. package/dist/helpers/enumToArray.js +7 -0
  51. package/dist/helpers/exceptions/app-http-exception.d.ts +49 -0
  52. package/dist/helpers/exceptions/app-http-exception.js +141 -0
  53. package/dist/helpers/exceptions/app-ws-exception.d.ts +20 -0
  54. package/dist/helpers/exceptions/app-ws-exception.js +38 -0
  55. package/dist/helpers/exceptions/index.d.ts +2 -0
  56. package/dist/helpers/exceptions/index.js +10 -0
  57. package/dist/helpers/getIdRef.d.ts +19 -0
  58. package/dist/helpers/getIdRef.js +37 -0
  59. package/dist/helpers/index.d.ts +6 -0
  60. package/dist/helpers/index.js +22 -0
  61. package/dist/helpers/readCapped.helper.d.ts +8 -0
  62. package/dist/helpers/readCapped.helper.js +27 -0
  63. package/dist/helpers/responses/http-response.d.ts +29 -0
  64. package/dist/helpers/responses/http-response.js +99 -0
  65. package/dist/helpers/responses/index.d.ts +1 -0
  66. package/dist/helpers/responses/index.js +5 -0
  67. package/dist/index.d.ts +32 -0
  68. package/dist/index.js +60 -0
  69. package/dist/pipes/body-by-key.pipe.d.ts +34 -0
  70. package/dist/pipes/body-by-key.pipe.js +66 -0
  71. package/dist/redis/configs/redis.configs.d.ts +10 -0
  72. package/dist/redis/configs/redis.configs.js +9 -0
  73. package/dist/redis/helpers/redis-storage-manager.helper.d.ts +53 -0
  74. package/dist/redis/helpers/redis-storage-manager.helper.js +154 -0
  75. package/dist/redis/redis.module.d.ts +6 -0
  76. package/dist/redis/redis.module.js +38 -0
  77. package/dist/redis/redis.service.d.ts +42 -0
  78. package/dist/redis/redis.service.js +192 -0
  79. package/dist/shared/base-controller/base-controller.abstract.d.ts +9 -0
  80. package/dist/shared/base-controller/base-controller.abstract.js +26 -0
  81. package/dist/shared/base-service/abstract-service-base.d.ts +14 -0
  82. package/dist/shared/base-service/abstract-service-base.js +37 -0
  83. package/dist/shared/base-service/base-abstract-service.helper.d.ts +93 -0
  84. package/dist/shared/base-service/base-abstract-service.helper.js +260 -0
  85. package/dist/shared/base-service/index.d.ts +2 -0
  86. package/dist/shared/base-service/index.js +18 -0
  87. package/dist/shared/constants/index.d.ts +1 -0
  88. package/dist/shared/constants/index.js +17 -0
  89. package/dist/shared/constants/uuid-example.d.ts +1 -0
  90. package/dist/shared/constants/uuid-example.js +28 -0
  91. package/dist/shared/decorators/db/UUIDColumn.decorator.d.ts +1 -0
  92. package/dist/shared/decorators/db/UUIDColumn.decorator.js +9 -0
  93. package/dist/shared/decorators/db/enum-column.decorator.d.ts +3 -0
  94. package/dist/shared/decorators/db/enum-column.decorator.js +11 -0
  95. package/dist/shared/decorators/db/fast-join-column.decorator.d.ts +2 -0
  96. package/dist/shared/decorators/db/fast-join-column.decorator.js +37 -0
  97. package/dist/shared/decorators/db/fast-join-table.decorator.d.ts +8 -0
  98. package/dist/shared/decorators/db/fast-join-table.decorator.js +20 -0
  99. package/dist/shared/decorators/db/finance-column.decorator.d.ts +4 -0
  100. package/dist/shared/decorators/db/finance-column.decorator.js +21 -0
  101. package/dist/shared/decorators/db/fk-column.decorator.d.ts +8 -0
  102. package/dist/shared/decorators/db/fk-column.decorator.js +24 -0
  103. package/dist/shared/decorators/db/index.d.ts +9 -0
  104. package/dist/shared/decorators/db/index.js +34 -0
  105. package/dist/shared/decorators/db/mpath-column.decorator.d.ts +1 -0
  106. package/dist/shared/decorators/db/mpath-column.decorator.js +10 -0
  107. package/dist/shared/decorators/db/timestamp-tz.column.decorator.d.ts +2 -0
  108. package/dist/shared/decorators/db/timestamp-tz.column.decorator.js +11 -0
  109. package/dist/shared/decorators/db/varchar-column.decorator.d.ts +9 -0
  110. package/dist/shared/decorators/db/varchar-column.decorator.js +29 -0
  111. package/dist/shared/decorators/index.d.ts +4 -0
  112. package/dist/shared/decorators/index.js +23 -0
  113. package/dist/shared/decorators/inject-forward-ref.decorator.d.ts +1 -0
  114. package/dist/shared/decorators/inject-forward-ref.decorator.js +8 -0
  115. package/dist/shared/decorators/openapi/api-prop-descriptor.decorator.d.ts +12 -0
  116. package/dist/shared/decorators/openapi/api-prop-descriptor.decorator.js +18 -0
  117. package/dist/shared/decorators/openapi/controller-meta.decorator.d.ts +17 -0
  118. package/dist/shared/decorators/openapi/controller-meta.decorator.js +25 -0
  119. package/dist/shared/decorators/openapi/index.d.ts +2 -0
  120. package/dist/shared/decorators/openapi/index.js +18 -0
  121. package/dist/shared/decorators/params/index.d.ts +5 -0
  122. package/dist/shared/decorators/params/index.js +21 -0
  123. package/dist/shared/decorators/params/is-boolean-param.decorator.d.ts +2 -0
  124. package/dist/shared/decorators/params/is-boolean-param.decorator.js +8 -0
  125. package/dist/shared/decorators/params/is-email-property.decorator.d.ts +5 -0
  126. package/dist/shared/decorators/params/is-email-property.decorator.js +10 -0
  127. package/dist/shared/decorators/params/is-ua-mobile-phone.decorator.d.ts +2 -0
  128. package/dist/shared/decorators/params/is-ua-mobile-phone.decorator.js +13 -0
  129. package/dist/shared/decorators/params/is-uuid-param.decorator.d.ts +2 -0
  130. package/dist/shared/decorators/params/is-uuid-param.decorator.js +15 -0
  131. package/dist/shared/decorators/params/is-uuid-ref-param.decorator.d.ts +2 -0
  132. package/dist/shared/decorators/params/is-uuid-ref-param.decorator.js +11 -0
  133. package/dist/shared/dto/email.dto.d.ts +3 -0
  134. package/dist/shared/dto/email.dto.js +20 -0
  135. package/dist/shared/dto/index.d.ts +3 -0
  136. package/dist/shared/dto/index.js +19 -0
  137. package/dist/shared/dto/ref.dto.d.ts +14 -0
  138. package/dist/shared/dto/ref.dto.js +47 -0
  139. package/dist/shared/dto/ua-mobile-phone.dto.d.ts +3 -0
  140. package/dist/shared/dto/ua-mobile-phone.dto.js +20 -0
  141. package/dist/shared/entites/abstract-user-base.entity.d.ts +33 -0
  142. package/dist/shared/entites/abstract-user-base.entity.js +187 -0
  143. package/dist/shared/entites/app-base.entity.d.ts +6 -0
  144. package/dist/shared/entites/app-base.entity.js +34 -0
  145. package/dist/shared/entites/global.entities.d.ts +4 -0
  146. package/dist/shared/entites/global.entities.js +21 -0
  147. package/dist/shared/entites/index.d.ts +5 -0
  148. package/dist/shared/entites/index.js +21 -0
  149. package/dist/shared/entites/invoice-url-nested.entity.d.ts +5 -0
  150. package/dist/shared/entites/invoice-url-nested.entity.js +28 -0
  151. package/dist/shared/entites/reference-nested.entity.d.ts +4 -0
  152. package/dist/shared/entites/reference-nested.entity.js +28 -0
  153. package/dist/shared/entites/user-telegram-info-embedded.entity.d.ts +6 -0
  154. package/dist/shared/entites/user-telegram-info-embedded.entity.js +46 -0
  155. package/dist/shared/helpers/QuerySearchParamsFromPaths.helper.d.ts +7 -0
  156. package/dist/shared/helpers/QuerySearchParamsFromPaths.helper.js +30 -0
  157. package/dist/shared/helpers/QuerySortParamsFromPaths.helper.d.ts +15 -0
  158. package/dist/shared/helpers/QuerySortParamsFromPaths.helper.js +39 -0
  159. package/dist/shared/helpers/RefCode.helper.d.ts +49 -0
  160. package/dist/shared/helpers/RefCode.helper.js +140 -0
  161. package/dist/shared/helpers/bolean-parsers.helper.d.ts +10 -0
  162. package/dist/shared/helpers/bolean-parsers.helper.js +33 -0
  163. package/dist/shared/helpers/createSelectsArray.helper.d.ts +2 -0
  164. package/dist/shared/helpers/createSelectsArray.helper.js +45 -0
  165. package/dist/shared/helpers/execution-time-logger.helper.d.ts +19 -0
  166. package/dist/shared/helpers/execution-time-logger.helper.js +39 -0
  167. package/dist/shared/helpers/forArray.helpers.d.ts +13 -0
  168. package/dist/shared/helpers/forArray.helpers.js +23 -0
  169. package/dist/shared/helpers/get-roles.helper.d.ts +6 -0
  170. package/dist/shared/helpers/get-roles.helper.js +15 -0
  171. package/dist/shared/helpers/getObjectPaths.helper.d.ts +2 -0
  172. package/dist/shared/helpers/getObjectPaths.helper.js +45 -0
  173. package/dist/shared/helpers/index.d.ts +13 -0
  174. package/dist/shared/helpers/index.js +29 -0
  175. package/dist/shared/helpers/setILIkeByPath.helper.d.ts +11 -0
  176. package/dist/shared/helpers/setILIkeByPath.helper.js +26 -0
  177. package/dist/shared/helpers/setJsonContainsByPath.helper.d.ts +6 -0
  178. package/dist/shared/helpers/setJsonContainsByPath.helper.js +14 -0
  179. package/dist/shared/helpers/setTableSortPyPath.helper.d.ts +3 -0
  180. package/dist/shared/helpers/setTableSortPyPath.helper.js +13 -0
  181. package/dist/shared/helpers/setValueByPath.helper.d.ts +4 -0
  182. package/dist/shared/helpers/setValueByPath.helper.js +55 -0
  183. package/dist/shared/helpers/typed-map.helper.d.ts +20 -0
  184. package/dist/shared/helpers/typed-map.helper.js +47 -0
  185. package/dist/shared/index.d.ts +2 -0
  186. package/dist/shared/index.js +27 -0
  187. package/dist/shared/lang/index.d.ts +9 -0
  188. package/dist/shared/lang/index.js +19 -0
  189. package/dist/shared/query/app-params.query.d.ts +199 -0
  190. package/dist/shared/query/app-params.query.js +809 -0
  191. package/dist/shared/query/find-one-user-query.type.d.ts +29 -0
  192. package/dist/shared/query/find-one-user-query.type.js +65 -0
  193. package/dist/shared/query/has-pagination.query.d.ts +8 -0
  194. package/dist/shared/query/has-pagination.query.js +40 -0
  195. package/dist/shared/query/has-sort.query.d.ts +9 -0
  196. package/dist/shared/query/has-sort.query.js +40 -0
  197. package/dist/shared/query/index.d.ts +4 -0
  198. package/dist/shared/query/index.js +25 -0
  199. package/dist/shared/validations/for-string.decorator.d.ts +19 -0
  200. package/dist/shared/validations/for-string.decorator.js +56 -0
  201. package/dist/shared/validations/index.d.ts +9 -0
  202. package/dist/shared/validations/index.js +25 -0
  203. package/dist/shared/validations/is-decimal-number-string.decorator.d.ts +10 -0
  204. package/dist/shared/validations/is-decimal-number-string.decorator.js +71 -0
  205. package/dist/shared/validations/is-depth-property.decorator.d.ts +2 -0
  206. package/dist/shared/validations/is-depth-property.decorator.js +20 -0
  207. package/dist/shared/validations/is-enum-prop.decorator.d.ts +2 -0
  208. package/dist/shared/validations/is-enum-prop.decorator.js +22 -0
  209. package/dist/shared/validations/is-integer.decorator.d.ts +4 -0
  210. package/dist/shared/validations/is-integer.decorator.js +21 -0
  211. package/dist/shared/validations/is-nested-property.decorator.d.ts +5 -0
  212. package/dist/shared/validations/is-nested-property.decorator.js +28 -0
  213. package/dist/shared/validations/is-number-param.decorator.d.ts +9 -0
  214. package/dist/shared/validations/is-number-param.decorator.js +33 -0
  215. package/dist/shared/validations/is-string-record.decorator.d.ts +3 -0
  216. package/dist/shared/validations/is-string-record.decorator.js +32 -0
  217. package/dist/shared/validations/is-unic-items-array.decorator.d.ts +10 -0
  218. package/dist/shared/validations/is-unic-items-array.decorator.js +20 -0
  219. package/dist/shared/validations/is-url-property.validator.d.ts +29 -0
  220. package/dist/shared/validations/is-url-property.validator.js +198 -0
  221. package/dist/types/app/app-module.interface.d.ts +3 -0
  222. package/dist/types/app/app-module.interface.js +2 -0
  223. package/dist/types/app-request-target.interface.d.ts +18 -0
  224. package/dist/types/app-request-target.interface.js +2 -0
  225. package/dist/types/auth-context.types.d.ts +23 -0
  226. package/dist/types/auth-context.types.js +2 -0
  227. package/dist/types/boolean-record.d.ts +2 -0
  228. package/dist/types/boolean-record.js +2 -0
  229. package/dist/types/cookies.types.d.ts +33 -0
  230. package/dist/types/cookies.types.js +21 -0
  231. package/dist/types/decimal.types.d.ts +1 -0
  232. package/dist/types/decimal.types.js +2 -0
  233. package/dist/types/domain.enums.d.ts +28 -0
  234. package/dist/types/domain.enums.js +39 -0
  235. package/dist/types/entity-path.types.d.ts +80 -0
  236. package/dist/types/entity-path.types.js +2 -0
  237. package/dist/types/files.types.d.ts +23 -0
  238. package/dist/types/files.types.js +27 -0
  239. package/dist/types/find-many-params.type.d.ts +17 -0
  240. package/dist/types/find-many-params.type.js +2 -0
  241. package/dist/types/find-one.params.d.ts +16 -0
  242. package/dist/types/find-one.params.js +2 -0
  243. package/dist/types/global.dto.d.ts +16 -0
  244. package/dist/types/global.dto.js +74 -0
  245. package/dist/types/global.types.d.ts +15 -0
  246. package/dist/types/global.types.js +21 -0
  247. package/dist/types/http/api.namespace.d.ts +74 -0
  248. package/dist/types/http/api.namespace.js +53 -0
  249. package/dist/types/index.d.ts +18 -0
  250. package/dist/types/index.js +28 -0
  251. package/dist/types/object-path.types.d.ts +7 -0
  252. package/dist/types/object-path.types.js +2 -0
  253. package/dist/types/path.d.ts +18 -0
  254. package/dist/types/path.js +2 -0
  255. package/dist/types/phone-number-locale.enum.d.ts +117 -0
  256. package/dist/types/phone-number-locale.enum.js +121 -0
  257. package/dist/types/providers.d.ts +66 -0
  258. package/dist/types/providers.js +74 -0
  259. package/dist/types/query-contracts.types.d.ts +18 -0
  260. package/dist/types/query-contracts.types.js +14 -0
  261. package/dist/types/remove-many.options.d.ts +21 -0
  262. package/dist/types/remove-many.options.js +11 -0
  263. package/dist/types/request-headers.interface.d.ts +8 -0
  264. package/dist/types/request-headers.interface.js +2 -0
  265. package/dist/types/sessions.types.d.ts +12 -0
  266. package/dist/types/sessions.types.js +16 -0
  267. package/dist/types/utility.types.d.ts +38 -0
  268. package/dist/types/utility.types.js +3 -0
  269. package/dist/types/utils.types.d.ts +1 -0
  270. package/dist/types/utils.types.js +2 -0
  271. package/dist/types/validation-options.types.d.ts +11 -0
  272. package/dist/types/validation-options.types.js +2 -0
  273. package/package.json +110 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 sabationok
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,33 @@
1
- # Temporary Holding Version
1
+ # @my-nestjs-kit/core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ App-agnostic NestJS server core. The base of the `@my-nestjs-kit/*` family; it depends on no other kit package.
4
+ Source: [github.com/sabationok/my-nestjs-kit](https://github.com/sabationok/my-nestjs-kit).
5
+
6
+ ```sh
7
+ npm i @my-nestjs-kit/core # latest
8
+ npm i @my-nestjs-kit/core@dev # snapshot of the dev branch
9
+ ```
10
+
11
+ Peers (the app installs them in its own versions): `@nestjs/common`, `@nestjs/core`, `@nestjs/swagger`,
12
+ `@nestjs/websockets`, `typeorm`, `ioredis`, `class-validator`, `class-transformer`, `decimal.js`, `lodash`.
13
+ Optional: `@types/express` (types of the request helpers).
14
+
15
+ ## What's in
16
+
17
+ - **Entities and columns:** `AppBaseEntity` + embedded entities, `AbstractUserBaseEntity`, column decorators
18
+ (`DecimalColumn`, `UUIDColumn`, `FastJoinTable`, `ColumnVarchar*`, `MPathColumn`, ...).
19
+ - **Validation and OpenAPI props:** `IsString*`, `IsEnumProperty`, `IsDecimalProperty`, `IsStringRecord`, ...,
20
+ `ApiPropDescriptor`, `ControllerMeta`.
21
+ - **Http:** `HttpSuccessRes`, `AppHttpException`, `AppWsException`, `@PostAsQuery` + `PostAsQueryGuard`,
22
+ `createBodyByKey`, `GetCookies` / `GetHeader`, `readCapped`.
23
+ - **Repository / controller bases:** `AbstractRepositoryService`, `AbstractServiceBase`, `AbstractAppController`,
24
+ `Ref` / query base classes.
25
+ - **Db:** `DbTx` / `activeTxManager` (TypeORM transactions over AsyncLocalStorage, retries on serialization
26
+ failures), `AbstractDbTransactionsService` (`@deprecated`, use `DbTx`), value transformers.
27
+ - **Infra:** `RedisModule` / `RedisService`, `EncryptionModule` / `EncryptionService`, console `AppLogger`.
28
+ - **Types:** utility types, query contracts, the open `AppRequestTarget`, `PermissionCTX` and `AuthParamsLike`
29
+ interfaces (narrowed by the app or by `@my-nestjs-kit/auth` with `declare module '@my-nestjs-kit/core'`).
30
+
31
+ ## License
32
+
33
+ MIT
@@ -0,0 +1,33 @@
1
+ import { LogLevel, Logger } from '@nestjs/common';
2
+ import { ColorizeFn } from './log-colors';
3
+ /** A plain message, or a callback that receives colour helpers. */
4
+ export type AppLogMessage = string | ColorizeFn;
5
+ /**
6
+ * Nest `Logger` whose level methods also accept `(c) => string`:
7
+ *
8
+ * ```ts
9
+ * this._logger.log(c => `${c.green('Loaded')} ${c.bold(count)} connections for ${c.cyan(company)}`);
10
+ * console.log({ company, ids }); // data objects stay separate, never interpolated
11
+ * ```
12
+ *
13
+ * Callbacks are resolved before Nest sees them (Nest itself would call a function message
14
+ * with no arguments). Everything else is passed through unchanged.
15
+ */
16
+ export declare class AppLogger extends Logger {
17
+ log(message: ColorizeFn, ...optionalParams: any[]): void;
18
+ log(message: any, ...optionalParams: any[]): void;
19
+ error(message: ColorizeFn, ...optionalParams: any[]): void;
20
+ error(message: any, ...optionalParams: any[]): void;
21
+ warn(message: ColorizeFn, ...optionalParams: any[]): void;
22
+ warn(message: any, ...optionalParams: any[]): void;
23
+ debug(message: ColorizeFn, ...optionalParams: any[]): void;
24
+ debug(message: any, ...optionalParams: any[]): void;
25
+ verbose(message: ColorizeFn, ...optionalParams: any[]): void;
26
+ verbose(message: any, ...optionalParams: any[]): void;
27
+ fatal(message: ColorizeFn, ...optionalParams: any[]): void;
28
+ fatal(message: any, ...optionalParams: any[]): void;
29
+ /** Whether the helpers currently emit ANSI codes. */
30
+ static get colorEnabled(): boolean;
31
+ }
32
+ /** Resolves a colour callback for `level`; non-callback messages pass through. */
33
+ export declare function resolveLogMessage(message: unknown, level: LogLevel): unknown;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveLogMessage = exports.AppLogger = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const log_colors_1 = require("./log-colors");
6
+ /**
7
+ * Foreground colour Nest's default ConsoleLogger paints each level's message with
8
+ * (see ConsoleLogger.getColorByLogLevel). Used to restore it after an inline coloured segment.
9
+ * `fatal` is bold-only, so the terminal default foreground is correct there.
10
+ */
11
+ const LEVEL_FG = {
12
+ log: 32,
13
+ error: 31,
14
+ warn: 33,
15
+ debug: 95,
16
+ verbose: 96,
17
+ fatal: log_colors_1.ANSI_FG_RESET,
18
+ };
19
+ /**
20
+ * Nest `Logger` whose level methods also accept `(c) => string`:
21
+ *
22
+ * ```ts
23
+ * this._logger.log(c => `${c.green('Loaded')} ${c.bold(count)} connections for ${c.cyan(company)}`);
24
+ * console.log({ company, ids }); // data objects stay separate, never interpolated
25
+ * ```
26
+ *
27
+ * Callbacks are resolved before Nest sees them (Nest itself would call a function message
28
+ * with no arguments). Everything else is passed through unchanged.
29
+ */
30
+ class AppLogger extends common_1.Logger {
31
+ log(message, ...optionalParams) {
32
+ super.log(resolveLogMessage(message, 'log'), ...optionalParams);
33
+ }
34
+ error(message, ...optionalParams) {
35
+ super.error(resolveLogMessage(message, 'error'), ...optionalParams);
36
+ }
37
+ warn(message, ...optionalParams) {
38
+ super.warn(resolveLogMessage(message, 'warn'), ...optionalParams);
39
+ }
40
+ debug(message, ...optionalParams) {
41
+ super.debug(resolveLogMessage(message, 'debug'), ...optionalParams);
42
+ }
43
+ verbose(message, ...optionalParams) {
44
+ super.verbose(resolveLogMessage(message, 'verbose'), ...optionalParams);
45
+ }
46
+ fatal(message, ...optionalParams) {
47
+ super.fatal(resolveLogMessage(message, 'fatal'), ...optionalParams);
48
+ }
49
+ /** Whether the helpers currently emit ANSI codes. */
50
+ static get colorEnabled() {
51
+ return (0, log_colors_1.isLogColorEnabled)();
52
+ }
53
+ }
54
+ exports.AppLogger = AppLogger;
55
+ const isClass = (fn) => typeof fn === 'function' &&
56
+ /^class\s/.test(Function.prototype.toString.call(fn));
57
+ /** Resolves a colour callback for `level`; non-callback messages pass through. */
58
+ function resolveLogMessage(message, level) {
59
+ if (typeof message !== 'function' || isClass(message))
60
+ return message;
61
+ return message((0, log_colors_1.getLogColors)(LEVEL_FG[level]));
62
+ }
63
+ exports.resolveLogMessage = resolveLogMessage;
@@ -0,0 +1,2 @@
1
+ export * from './log-colors';
2
+ export * from './app-logger';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./log-colors"), exports);
18
+ __exportStar(require("./app-logger"), exports);
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Tiny ANSI colour helpers for console logs (no dependency).
3
+ *
4
+ * Colours are emitted only when allowed:
5
+ * - `NO_COLOR` set (any value) -> off
6
+ * - `FORCE_COLOR` set and not `0`/false -> on (e.g. opt-in on Railway, whose log viewer renders ANSI)
7
+ * - otherwise -> on only when stdout is a TTY
8
+ *
9
+ * When off, every helper returns `String(value)`, so callbacks still produce plain text.
10
+ */
11
+ export type LogColorFn = (value: unknown) => string;
12
+ export declare const LOG_COLOR_NAMES: readonly ["red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "bold", "dim", "italic", "underline"];
13
+ export type LogColorName = (typeof LOG_COLOR_NAMES)[number];
14
+ export type LogColors = Readonly<Record<LogColorName, LogColorFn>>;
15
+ export type ColorizeFn = (c: LogColors) => string;
16
+ /** ANSI "default foreground" close code. */
17
+ export declare const ANSI_FG_RESET = 39;
18
+ export declare function isLogColorEnabled(): boolean;
19
+ /**
20
+ * @param fgClose foreground code restored after a coloured segment. Default `39` (terminal default);
21
+ * the logger passes the log level's own colour so the rest of the line keeps it.
22
+ */
23
+ export declare function getLogColors(fgClose?: number): LogColors;
24
+ /** Plain-text helpers (always no-op), e.g. for strings persisted to DB. */
25
+ export declare const noColors: LogColors;
26
+ /**
27
+ * Build a string with colour helpers:
28
+ * `colorize(c => `${c.yellow('warn')} ${c.bold(count)} items`)`.
29
+ */
30
+ export declare function colorize(fn: ColorizeFn): string;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ /**
3
+ * Tiny ANSI colour helpers for console logs (no dependency).
4
+ *
5
+ * Colours are emitted only when allowed:
6
+ * - `NO_COLOR` set (any value) -> off
7
+ * - `FORCE_COLOR` set and not `0`/false -> on (e.g. opt-in on Railway, whose log viewer renders ANSI)
8
+ * - otherwise -> on only when stdout is a TTY
9
+ *
10
+ * When off, every helper returns `String(value)`, so callbacks still produce plain text.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.colorize = exports.noColors = exports.getLogColors = exports.isLogColorEnabled = exports.ANSI_FG_RESET = exports.LOG_COLOR_NAMES = void 0;
14
+ exports.LOG_COLOR_NAMES = [
15
+ 'red',
16
+ 'green',
17
+ 'yellow',
18
+ 'blue',
19
+ 'magenta',
20
+ 'cyan',
21
+ 'white',
22
+ 'gray',
23
+ 'bold',
24
+ 'dim',
25
+ 'italic',
26
+ 'underline',
27
+ ];
28
+ /** ANSI "default foreground" close code. */
29
+ exports.ANSI_FG_RESET = 39;
30
+ const FG_CODES = {
31
+ red: 31,
32
+ green: 32,
33
+ yellow: 33,
34
+ blue: 34,
35
+ magenta: 35,
36
+ cyan: 36,
37
+ white: 37,
38
+ gray: 90,
39
+ };
40
+ const STYLE_CODES = {
41
+ bold: [1, 22],
42
+ dim: [2, 22],
43
+ italic: [3, 23],
44
+ underline: [4, 24],
45
+ };
46
+ function isLogColorEnabled() {
47
+ const env = process.env;
48
+ if (env.NO_COLOR !== undefined && env.NO_COLOR !== '')
49
+ return false;
50
+ const force = env.FORCE_COLOR;
51
+ if (force !== undefined && force !== '') {
52
+ return !['0', 'false'].includes(force.toLowerCase());
53
+ }
54
+ return !!process.stdout?.isTTY;
55
+ }
56
+ exports.isLogColorEnabled = isLogColorEnabled;
57
+ const sgr = (code) => `\x1b[${code}m`;
58
+ const wrap = (open, close) => (value) => `${sgr(open)}${String(value)}${sgr(close)}`;
59
+ const plain = (value) => String(value);
60
+ const buildColors = (enabled, fgClose) => {
61
+ const out = {};
62
+ for (const [name, code] of Object.entries(FG_CODES)) {
63
+ out[name] = enabled ? wrap(code, fgClose) : plain;
64
+ }
65
+ for (const [name, [open, close]] of Object.entries(STYLE_CODES)) {
66
+ out[name] = enabled ? wrap(open, close) : plain;
67
+ }
68
+ return Object.freeze(out);
69
+ };
70
+ const _cache = new Map();
71
+ /**
72
+ * @param fgClose foreground code restored after a coloured segment. Default `39` (terminal default);
73
+ * the logger passes the log level's own colour so the rest of the line keeps it.
74
+ */
75
+ function getLogColors(fgClose = exports.ANSI_FG_RESET) {
76
+ const enabled = isLogColorEnabled();
77
+ const key = `${enabled}:${fgClose}`;
78
+ let colors = _cache.get(key);
79
+ if (!colors)
80
+ _cache.set(key, (colors = buildColors(enabled, fgClose)));
81
+ return colors;
82
+ }
83
+ exports.getLogColors = getLogColors;
84
+ /** Plain-text helpers (always no-op), e.g. for strings persisted to DB. */
85
+ exports.noColors = buildColors(false, exports.ANSI_FG_RESET);
86
+ /**
87
+ * Build a string with colour helpers:
88
+ * `colorize(c => `${c.yellow('warn')} ${c.bold(count)} items`)`.
89
+ */
90
+ function colorize(fn) {
91
+ return fn(getLogColors());
92
+ }
93
+ exports.colorize = colorize;
File without changes
File without changes
@@ -0,0 +1,37 @@
1
+ import { DataSource, EntityManager } from 'typeorm';
2
+ import { HttpException, Logger } from '@nestjs/common';
3
+ import { ExceptionResponseArgs } from '../../helpers';
4
+ import { IsolationLevel } from 'typeorm/driver/types/IsolationLevel';
5
+ export interface DbTransactionConfigs {
6
+ name: string;
7
+ level?: IsolationLevel;
8
+ }
9
+ type DbTransactionCallback<Input = any, Output = any, Ctx extends DbTransactionConfigs = DbTransactionConfigs> = (input: Input, trManager: EntityManager, context: Ctx) => Promise<Output>;
10
+ type DbTransactionRunner<Input = any, Output = any> = (input: Input) => Promise<Output>;
11
+ type DbTransactionRunnerWithin<Input = any, Output = any> = (trManager: EntityManager, input: Input) => Promise<Output>;
12
+ type TransactionBuilderReturn<Input = any, Output = any> = {
13
+ run: DbTransactionRunner<Input, Output>;
14
+ runWithIn: DbTransactionRunnerWithin<Input, Output>;
15
+ runWithOut: DbTransactionRunner<Input, Output>;
16
+ };
17
+ interface DbTransactionsServiceMeta {
18
+ name: string;
19
+ }
20
+ /**
21
+ * @deprecated use `DbTx` from `@my-nestjs-kit/core`. Kept until the consumers move off it.
22
+ */
23
+ export declare abstract class AbstractDbTransactionsService {
24
+ private readonly dSource;
25
+ private readonly __logger;
26
+ protected readonly _logger: Logger;
27
+ protected readonly meta: DbTransactionsServiceMeta;
28
+ fail(res: ExceptionResponseArgs | HttpException, configs?: DbTransactionConfigs): void;
29
+ protected constructor(meta: DbTransactionsServiceMeta, dSource: DataSource);
30
+ private _runner;
31
+ private _runnerWithIn;
32
+ build<Input = any, Output = any, Configs extends DbTransactionConfigs = DbTransactionConfigs>({ configs, execute, }: {
33
+ configs: Configs;
34
+ execute: DbTransactionCallback<Input, Output, Configs>;
35
+ }): TransactionBuilderReturn<Input, Output>;
36
+ }
37
+ export {};
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbstractDbTransactionsService = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const helpers_1 = require("../../helpers");
6
+ /**
7
+ * @deprecated use `DbTx` from `@my-nestjs-kit/core`. Kept until the consumers move off it.
8
+ */
9
+ class AbstractDbTransactionsService {
10
+ fail(res, configs) {
11
+ const response = res instanceof common_1.HttpException ? res.getResponse() : res;
12
+ const exc = new helpers_1.AppHttpExceptionResponse(typeof response === 'string'
13
+ ? {
14
+ message: response,
15
+ meta: { service: this.constructor.name },
16
+ }
17
+ : response)
18
+ .setMeta('transaction', this.meta.name)
19
+ .setMeta('service', this.constructor.name);
20
+ throw new helpers_1.AppHttpException(exc);
21
+ }
22
+ constructor(meta, dSource) {
23
+ this.dSource = dSource;
24
+ this.__logger = new common_1.Logger(AbstractDbTransactionsService.name);
25
+ this.meta = meta;
26
+ this._logger = new common_1.Logger(this.constructor.name);
27
+ }
28
+ async _runner(configs, execute) {
29
+ return this.dSource.manager.transaction(configs.level ?? 'SERIALIZABLE', (trManager) => {
30
+ return this._runnerWithIn(configs, trManager, execute);
31
+ });
32
+ }
33
+ async _runnerWithIn({ name, ...configs }, trManager, execute) {
34
+ // try {
35
+ // const result = await execute(trManager);
36
+ // // this._logger.debug(`[${configs.name}] Transaction result`);
37
+ // // console.log(result);
38
+ // return result;
39
+ // } catch (e) {
40
+ // this._logger.error(`[${configs.name}] Transaction fail`);
41
+ // console.log(e);
42
+ // this.fail(
43
+ // e instanceof AppHttpException
44
+ // ? e
45
+ // : {
46
+ // message: 'Transaction fail',
47
+ // meta: {
48
+ // transaction: configs.name,
49
+ // method: this._runner?.name,
50
+ // },
51
+ // },
52
+ // configs,
53
+ // );
54
+ // }
55
+ try {
56
+ const result = await execute(trManager);
57
+ this._logger.debug(`[${name}] Transaction result`);
58
+ console.log(result);
59
+ return result;
60
+ }
61
+ catch (e) {
62
+ this._logger.error(`Transaction: "${name}" ended with fail`);
63
+ console.log(e);
64
+ this.fail(e instanceof helpers_1.AppHttpException
65
+ ? e
66
+ : {
67
+ message: 'Transaction fail',
68
+ error: e.name,
69
+ meta: {
70
+ transaction: name,
71
+ method: this._runnerWithIn?.name,
72
+ },
73
+ }, { name, ...configs });
74
+ }
75
+ }
76
+ build({ configs, execute, }) {
77
+ return {
78
+ run: (input) => this._runner(configs, (trManager) => execute(input, trManager, configs)),
79
+ runWithIn: (trManager, input) => this._runnerWithIn(configs, trManager, (trManager) => execute(input, trManager, configs)),
80
+ runWithOut: (input) => this._runnerWithIn(configs, this.dSource.manager, (trManager) => execute(input, trManager, configs)),
81
+ };
82
+ }
83
+ }
84
+ exports.AbstractDbTransactionsService = AbstractDbTransactionsService;
@@ -0,0 +1,28 @@
1
+ import { DataSource, type EntityManager } from 'typeorm';
2
+ import type { IsolationLevel } from 'typeorm/driver/types/IsolationLevel';
3
+ export interface DbTxConfig {
4
+ /** logged on failure and retry */
5
+ name?: string;
6
+ /** default READ COMMITTED; ask for more only with a reason written next to the call */
7
+ level?: IsolationLevel;
8
+ }
9
+ /** The manager of the transaction this async context runs in. Own store: crons and queues have no request. */
10
+ export declare function activeTxManager(): EntityManager | undefined;
11
+ /**
12
+ * The one way to run a transaction. With `options.em` → joins the caller's transaction; otherwise opens one
13
+ * and retries on pg `40001`, so `fn` may run more than once: no HTTP or provider calls inside it, and no
14
+ * emits a listener could observe before commit.
15
+ *
16
+ * Errors pass through as thrown. Results are never logged.
17
+ */
18
+ export declare class DbTx {
19
+ private readonly ds;
20
+ private readonly _logger;
21
+ constructor(ds: DataSource);
22
+ run<T>(options: {
23
+ em?: EntityManager;
24
+ } | undefined, fn: (em: EntityManager) => Promise<T>, cfg?: DbTxConfig): Promise<T>;
25
+ private open;
26
+ private inStore;
27
+ private logFailure;
28
+ }
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var DbTx_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.DbTx = exports.activeTxManager = void 0;
14
+ const common_1 = require("@nestjs/common");
15
+ const async_hooks_1 = require("async_hooks");
16
+ const typeorm_1 = require("typeorm");
17
+ const MAX_ATTEMPTS = 3;
18
+ const BACKOFF_BASE_MS = 50;
19
+ const SERIALIZATION_FAILURE = '40001';
20
+ const UNNAMED = 'unnamed';
21
+ const store = new async_hooks_1.AsyncLocalStorage();
22
+ /** The manager of the transaction this async context runs in. Own store: crons and queues have no request. */
23
+ function activeTxManager() {
24
+ const active = store.getStore();
25
+ return active?.open ? active.em : undefined;
26
+ }
27
+ exports.activeTxManager = activeTxManager;
28
+ const isSerializationFailure = (e) => {
29
+ const err = e;
30
+ return (err?.driverError?.code ?? err?.code) === SERIALIZATION_FAILURE;
31
+ };
32
+ const backoff = (attempt) => new Promise((resolve) => setTimeout(resolve, BACKOFF_BASE_MS * 2 ** (attempt - 1) + Math.random() * BACKOFF_BASE_MS));
33
+ /**
34
+ * The one way to run a transaction. With `options.em` → joins the caller's transaction; otherwise opens one
35
+ * and retries on pg `40001`, so `fn` may run more than once: no HTTP or provider calls inside it, and no
36
+ * emits a listener could observe before commit.
37
+ *
38
+ * Errors pass through as thrown. Results are never logged.
39
+ */
40
+ let DbTx = DbTx_1 = class DbTx {
41
+ constructor(ds) {
42
+ this.ds = ds;
43
+ this._logger = new common_1.Logger(DbTx_1.name);
44
+ }
45
+ run(options, fn, cfg) {
46
+ if (options?.em)
47
+ return fn(options.em);
48
+ // backstop: a forgotten `em` must not open a second transaction on another connection
49
+ const active = activeTxManager();
50
+ if (active) {
51
+ this._logger.warn(`"${cfg?.name ?? UNNAMED}" got no em inside "${store.getStore()?.name}": joined it`);
52
+ return fn(active);
53
+ }
54
+ return this.open(fn, cfg);
55
+ }
56
+ async open(fn, cfg) {
57
+ const name = cfg?.name ?? UNNAMED;
58
+ const level = cfg?.level ?? 'READ COMMITTED';
59
+ for (let attempt = 1;; attempt++) {
60
+ try {
61
+ return await this.ds.transaction(level, (em) => this.inStore(em, name, fn));
62
+ }
63
+ catch (e) {
64
+ if (isSerializationFailure(e) && attempt < MAX_ATTEMPTS) {
65
+ this._logger.warn(`"${name}" serialization failure, retry ${attempt}/${MAX_ATTEMPTS - 1}`);
66
+ await backoff(attempt);
67
+ continue;
68
+ }
69
+ this.logFailure(name, e);
70
+ throw e;
71
+ }
72
+ }
73
+ }
74
+ inStore(em, name, fn) {
75
+ const active = { em, name, open: true };
76
+ return store.run(active, async () => {
77
+ try {
78
+ return await fn(em);
79
+ }
80
+ finally {
81
+ active.open = false;
82
+ }
83
+ });
84
+ }
85
+ logFailure(name, e) {
86
+ const message = `Transaction "${name}" failed: ${e?.message}`;
87
+ if (e instanceof common_1.HttpException)
88
+ this._logger.warn(message);
89
+ else
90
+ this._logger.error(message, e?.stack);
91
+ }
92
+ };
93
+ exports.DbTx = DbTx;
94
+ exports.DbTx = DbTx = DbTx_1 = __decorate([
95
+ (0, common_1.Injectable)(),
96
+ __metadata("design:paramtypes", [typeorm_1.DataSource])
97
+ ], DbTx);
@@ -0,0 +1 @@
1
+ export * from './db-tx.service';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./db-tx.service"), exports);
@@ -0,0 +1,5 @@
1
+ import { ValueTransformer } from 'typeorm/decorator/options/ValueTransformer';
2
+ export declare const DecimalColumnTransformer: ValueTransformer;
3
+ export declare const decimalColumnTransformer: ({ decimals, }: {
4
+ decimals?: number;
5
+ }) => ValueTransformer;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.decimalColumnTransformer = exports.DecimalColumnTransformer = void 0;
7
+ const decimal_js_1 = __importDefault(require("decimal.js"));
8
+ exports.DecimalColumnTransformer = {
9
+ from(value) {
10
+ return !value ? null : new decimal_js_1.default(value);
11
+ },
12
+ to: (value) => {
13
+ if (typeof value === 'number') {
14
+ return new decimal_js_1.default(value).toFixed();
15
+ }
16
+ else {
17
+ return value;
18
+ }
19
+ },
20
+ };
21
+ const decimalColumnTransformer = ({ decimals, }) => {
22
+ return {
23
+ from(value) {
24
+ return !value ? null : new decimal_js_1.default(value);
25
+ },
26
+ to: (value) => {
27
+ try {
28
+ if (typeof value === 'number') {
29
+ return new decimal_js_1.default(value).toFixed(decimals ?? 2);
30
+ }
31
+ else {
32
+ return value;
33
+ }
34
+ }
35
+ catch (e) {
36
+ if (typeof value === 'number') {
37
+ return value.toFixed(decimals ?? 2);
38
+ }
39
+ else {
40
+ return value;
41
+ }
42
+ }
43
+ },
44
+ };
45
+ };
46
+ exports.decimalColumnTransformer = decimalColumnTransformer;
@@ -0,0 +1 @@
1
+ export * from './decimal-column.transformer';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./decimal-column.transformer"), exports);
@@ -0,0 +1,6 @@
1
+ import { DecoratorForReqOptions } from './decoratorForReqOptions';
2
+ import { HttpApi } from '../types/http/api.namespace';
3
+ export type AppCookiesByKey = HttpApi.Request['cookies'];
4
+ export declare const GetCookies: <Key extends "refresh_token" | "access_token" | "location" | "user_ref" | "offer_id" | "invoice_id" | "order_id" | "warehouse_id" | "payment_id" | "role" | "roles" | "track_id" | "reference" | "accessStatus" | "status" = "refresh_token" | "access_token" | "location" | "user_ref" | "offer_id" | "invoice_id" | "order_id" | "warehouse_id" | "payment_id" | "role" | "roles" | "track_id" | "reference" | "accessStatus" | "status">(...dataOrPipes: (Key | (DecoratorForReqOptions & {
5
+ key: Key;
6
+ }) | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;