@nest-omni/core 3.1.1-9 → 3.1.2-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 (310) hide show
  1. package/.hygen/new/crud/controller.ejs.t +82 -0
  2. package/.hygen/new/crud/create.dto.ejs.t +12 -0
  3. package/.hygen/new/crud/entity.ejs.t +26 -0
  4. package/.hygen/new/crud/get.dto.ejs.t +19 -0
  5. package/.hygen/new/crud/index-dto.ejs.t +29 -0
  6. package/.hygen/new/crud/index-response.dto.ejs.t +18 -0
  7. package/.hygen/new/crud/module.ejs.t +32 -0
  8. package/.hygen/new/crud/prompt.js +89 -0
  9. package/.hygen/new/crud/service.ejs.t +76 -0
  10. package/.hygen/new/crud/update.dto.ejs.t +11 -0
  11. package/.hygen/new/module/controller.ejs.t +93 -0
  12. package/.hygen/new/module/create-command.ejs.t +90 -0
  13. package/.hygen/new/module/create.dto.ejs.t +11 -0
  14. package/.hygen/new/module/dto.ejs.t +24 -0
  15. package/.hygen/new/module/entity.ejs.t +33 -0
  16. package/.hygen/new/module/get-query.ejs.t +57 -0
  17. package/.hygen/new/module/module.ejs.t +44 -0
  18. package/.hygen/new/module/not-found.exception.ejs.t +18 -0
  19. package/.hygen/new/module/page-options.dto.ejs.t +12 -0
  20. package/.hygen/new/module/prompt.js +104 -0
  21. package/.hygen/new/module/repository.ejs.t +16 -0
  22. package/.hygen/new/module/service.ejs.t +139 -0
  23. package/.hygen/new/module/translation-dto.ejs.t +27 -0
  24. package/.hygen/new/module/translation-entity.ejs.t +40 -0
  25. package/.hygen/new/module/translation-repository.ejs.t +16 -0
  26. package/.hygen/new/module/update.dto.ejs.t +10 -0
  27. package/.hygen.js +116 -0
  28. package/cache/cache-metrics.service.d.ts +83 -0
  29. package/cache/cache-metrics.service.js +298 -0
  30. package/cache/cache-serialization.service.d.ts +22 -0
  31. package/cache/cache-serialization.service.js +122 -0
  32. package/cache/cache.constants.d.ts +2 -0
  33. package/cache/cache.constants.js +5 -0
  34. package/cache/cache.health.d.ts +35 -0
  35. package/cache/cache.health.js +193 -0
  36. package/cache/cache.module.d.ts +26 -0
  37. package/cache/cache.module.js +155 -0
  38. package/cache/cache.service.d.ts +37 -0
  39. package/cache/cache.service.js +308 -0
  40. package/cache/cache.warmup.service.d.ts +34 -0
  41. package/cache/cache.warmup.service.js +199 -0
  42. package/cache/decorators/cache-evict.decorator.d.ts +2 -0
  43. package/cache/decorators/cache-evict.decorator.js +72 -0
  44. package/cache/decorators/cache-put.decorator.d.ts +2 -0
  45. package/cache/decorators/cache-put.decorator.js +48 -0
  46. package/cache/decorators/cacheable.decorator.d.ts +4 -0
  47. package/cache/decorators/cacheable.decorator.js +68 -0
  48. package/cache/decorators/index.d.ts +3 -0
  49. package/cache/decorators/index.js +11 -0
  50. package/cache/dependencies/callback.dependency.d.ts +11 -0
  51. package/cache/dependencies/callback.dependency.js +92 -0
  52. package/cache/dependencies/chain.dependency.d.ts +20 -0
  53. package/cache/dependencies/chain.dependency.js +113 -0
  54. package/cache/dependencies/db.dependency.d.ts +15 -0
  55. package/cache/dependencies/db.dependency.js +71 -0
  56. package/cache/dependencies/file.dependency.d.ts +17 -0
  57. package/cache/dependencies/file.dependency.js +63 -0
  58. package/cache/dependencies/index.d.ts +6 -0
  59. package/cache/dependencies/index.js +22 -0
  60. package/cache/dependencies/tag.dependency.d.ts +16 -0
  61. package/cache/dependencies/tag.dependency.js +75 -0
  62. package/cache/dependencies/time.dependency.d.ts +19 -0
  63. package/cache/dependencies/time.dependency.js +71 -0
  64. package/cache/examples/basic-usage.d.ts +58 -0
  65. package/cache/examples/basic-usage.js +379 -0
  66. package/cache/index.d.ts +15 -0
  67. package/cache/index.js +44 -0
  68. package/cache/interfaces/cache-dependency.interface.d.ts +11 -0
  69. package/cache/interfaces/cache-dependency.interface.js +2 -0
  70. package/cache/interfaces/cache-options.interface.d.ts +32 -0
  71. package/cache/interfaces/cache-options.interface.js +9 -0
  72. package/cache/interfaces/cache-provider.interface.d.ts +28 -0
  73. package/cache/interfaces/cache-provider.interface.js +2 -0
  74. package/cache/interfaces/index.d.ts +3 -0
  75. package/cache/interfaces/index.js +19 -0
  76. package/cache/providers/base-cache.provider.d.ts +16 -0
  77. package/cache/providers/base-cache.provider.js +32 -0
  78. package/cache/providers/cls-cache.provider.d.ts +16 -0
  79. package/cache/providers/cls-cache.provider.js +140 -0
  80. package/cache/providers/index.d.ts +4 -0
  81. package/cache/providers/index.js +23 -0
  82. package/cache/providers/memory-cache.provider.d.ts +26 -0
  83. package/cache/providers/memory-cache.provider.js +171 -0
  84. package/cache/providers/redis-cache.provider.d.ts +23 -0
  85. package/cache/providers/redis-cache.provider.js +215 -0
  86. package/cache/utils/dependency-manager.util.d.ts +15 -0
  87. package/cache/utils/dependency-manager.util.js +141 -0
  88. package/cache/utils/index.d.ts +2 -0
  89. package/cache/utils/index.js +18 -0
  90. package/cache/utils/key-generator.util.d.ts +13 -0
  91. package/cache/utils/key-generator.util.js +74 -0
  92. package/common/abstract.entity.d.ts +20 -0
  93. package/common/abstract.entity.js +81 -0
  94. package/common/boilerplate.polyfill.d.ts +50 -0
  95. package/common/boilerplate.polyfill.js +152 -0
  96. package/common/dto/abstract.dto.d.ts +13 -0
  97. package/common/dto/abstract.dto.js +59 -0
  98. package/common/dto/bulk-id.dto.d.ts +3 -0
  99. package/common/dto/bulk-id.dto.js +27 -0
  100. package/common/dto/create-translation.dto.d.ts +5 -0
  101. package/common/dto/create-translation.dto.js +25 -0
  102. package/common/dto/dto-container.d.ts +9 -0
  103. package/common/dto/dto-container.js +59 -0
  104. package/common/dto/dto-decorators.d.ts +18 -0
  105. package/common/dto/dto-decorators.js +59 -0
  106. package/common/dto/dto-extensions.d.ts +12 -0
  107. package/common/dto/dto-extensions.js +63 -0
  108. package/common/dto/dto-service-accessor.d.ts +7 -0
  109. package/common/dto/dto-service-accessor.js +49 -0
  110. package/common/dto/dto-transformer.d.ts +11 -0
  111. package/common/dto/dto-transformer.js +49 -0
  112. package/common/dto/index.d.ts +12 -0
  113. package/common/dto/index.js +28 -0
  114. package/common/dto/page-meta.dto.d.ts +15 -0
  115. package/common/dto/page-meta.dto.js +48 -0
  116. package/common/dto/page-options.dto.d.ts +5 -0
  117. package/common/dto/page-options.dto.js +40 -0
  118. package/common/dto/page.dto.d.ts +11 -0
  119. package/common/dto/page.dto.js +53 -0
  120. package/common/examples/paginate-and-map.example.d.ts +14 -0
  121. package/common/examples/paginate-and-map.example.js +158 -0
  122. package/common/index.d.ts +6 -0
  123. package/common/index.js +22 -0
  124. package/common/snake-naming.strategy.d.ts +11 -0
  125. package/common/snake-naming.strategy.js +37 -0
  126. package/common/types.d.ts +9 -0
  127. package/common/types.js +2 -0
  128. package/common/utils.d.ts +3 -0
  129. package/common/utils.js +24 -0
  130. package/constants/index.d.ts +2 -0
  131. package/constants/index.js +18 -0
  132. package/constants/language-code.d.ts +5 -0
  133. package/constants/language-code.js +9 -0
  134. package/constants/order.d.ts +4 -0
  135. package/constants/order.js +8 -0
  136. package/decorators/api-page-ok-response.decorator.d.ts +5 -0
  137. package/decorators/api-page-ok-response.decorator.js +24 -0
  138. package/decorators/api-paginated-response.decorator.d.ts +2 -0
  139. package/decorators/api-paginated-response.decorator.js +9 -0
  140. package/decorators/auth-user.decorator.d.ts +1 -0
  141. package/decorators/auth-user.decorator.js +14 -0
  142. package/decorators/controller.decorator.d.ts +1 -0
  143. package/decorators/controller.decorator.js +10 -0
  144. package/decorators/examples/validation-decorators.example.d.ts +69 -0
  145. package/decorators/examples/validation-decorators.example.js +331 -0
  146. package/decorators/field.decorators.d.ts +79 -0
  147. package/decorators/field.decorators.js +499 -0
  148. package/decorators/http.decorators.d.ts +3 -0
  149. package/decorators/http.decorators.js +7 -0
  150. package/decorators/index.d.ts +14 -0
  151. package/decorators/index.js +30 -0
  152. package/decorators/operation.decorator.d.ts +1 -0
  153. package/decorators/operation.decorator.js +6 -0
  154. package/decorators/paginated-response.decorator.d.ts +11 -0
  155. package/decorators/paginated-response.decorator.js +60 -0
  156. package/decorators/property.decorators.d.ts +15 -0
  157. package/decorators/property.decorators.js +31 -0
  158. package/decorators/public-route.decorator.d.ts +3 -0
  159. package/decorators/public-route.decorator.js +7 -0
  160. package/decorators/swagger.schema.d.ts +5 -0
  161. package/decorators/swagger.schema.js +78 -0
  162. package/decorators/timestamp-column.decorator.d.ts +1 -0
  163. package/decorators/timestamp-column.decorator.js +27 -0
  164. package/decorators/transform.decorators.d.ts +8 -0
  165. package/decorators/transform.decorators.js +100 -0
  166. package/decorators/translate.decorator.d.ts +5 -0
  167. package/decorators/translate.decorator.js +17 -0
  168. package/decorators/use-dto.decorator.d.ts +4 -0
  169. package/decorators/use-dto.decorator.js +8 -0
  170. package/decorators/user-check.decorator.d.ts +6 -0
  171. package/decorators/user-check.decorator.js +21 -0
  172. package/decorators/user.decorator.d.ts +12 -0
  173. package/decorators/user.decorator.js +44 -0
  174. package/decorators/user_auth.decorator.d.ts +1 -0
  175. package/decorators/user_auth.decorator.js +15 -0
  176. package/decorators/validator.decorators.d.ts +18 -0
  177. package/decorators/validator.decorators.js +193 -0
  178. package/exceptions/file-not-image.exception.d.ts +4 -0
  179. package/exceptions/file-not-image.exception.js +10 -0
  180. package/exceptions/index.d.ts +2 -0
  181. package/exceptions/index.js +18 -0
  182. package/exceptions/page-type.exception.d.ts +4 -0
  183. package/exceptions/page-type.exception.js +10 -0
  184. package/exceptions/user-not-found.exception.d.ts +4 -0
  185. package/exceptions/user-not-found.exception.js +10 -0
  186. package/filters/bad-request.filter.d.ts +5 -0
  187. package/filters/bad-request.filter.js +71 -0
  188. package/filters/constraint-errors.d.ts +1 -0
  189. package/filters/constraint-errors.js +6 -0
  190. package/filters/index.d.ts +3 -0
  191. package/filters/index.js +19 -0
  192. package/filters/query-failed.filter.d.ts +10 -0
  193. package/filters/query-failed.filter.js +42 -0
  194. package/health-checker/health-checker.controller.d.ts +13 -0
  195. package/health-checker/health-checker.controller.js +69 -0
  196. package/health-checker/health-checker.module.d.ts +2 -0
  197. package/health-checker/health-checker.module.js +24 -0
  198. package/health-checker/index.d.ts +2 -0
  199. package/health-checker/index.js +18 -0
  200. package/helpers/common.helper.d.ts +3 -0
  201. package/helpers/common.helper.js +36 -0
  202. package/helpers/date.helper.d.ts +10 -0
  203. package/helpers/date.helper.js +57 -0
  204. package/helpers/index.d.ts +2 -0
  205. package/helpers/index.js +18 -0
  206. package/i18n/en_US/validation.json +44 -0
  207. package/i18n/zh_CN/validation.json +44 -0
  208. package/index.d.ts +18 -0
  209. package/index.js +3 -0
  210. package/interceptors/index.d.ts +2 -0
  211. package/interceptors/index.js +18 -0
  212. package/interceptors/language-interceptor.service.d.ts +6 -0
  213. package/interceptors/language-interceptor.service.js +29 -0
  214. package/interceptors/translation-interceptor.service.d.ts +5 -0
  215. package/interceptors/translation-interceptor.service.js +34 -0
  216. package/interfaces/IApiFile.d.ts +4 -0
  217. package/interfaces/IApiFile.js +2 -0
  218. package/interfaces/IFile.d.ts +8 -0
  219. package/interfaces/IFile.js +2 -0
  220. package/interfaces/ITranslationDecoratorInterface.d.ts +3 -0
  221. package/interfaces/ITranslationDecoratorInterface.js +2 -0
  222. package/interfaces/index.d.ts +3 -0
  223. package/interfaces/index.js +19 -0
  224. package/interfaces/response.d.ts +25 -0
  225. package/interfaces/response.js +2 -0
  226. package/middlewares/index.d.ts +4 -0
  227. package/middlewares/index.js +20 -0
  228. package/middlewares/omni-auth.middleware.d.ts +1 -0
  229. package/middlewares/omni-auth.middleware.js +13 -0
  230. package/middlewares/powerby.middleware.d.ts +1 -0
  231. package/middlewares/powerby.middleware.js +10 -0
  232. package/middlewares/request-id.middleware.d.ts +7 -0
  233. package/middlewares/request-id.middleware.js +22 -0
  234. package/middlewares/xml.middleware.d.ts +4 -0
  235. package/middlewares/xml.middleware.js +24 -0
  236. package/package.json +41 -116
  237. package/providers/context.provider.d.ts +34 -0
  238. package/providers/context.provider.js +80 -0
  239. package/providers/generator.provider.d.ts +9 -0
  240. package/providers/generator.provider.js +50 -0
  241. package/providers/index.d.ts +2 -0
  242. package/providers/index.js +18 -0
  243. package/redis-lock/examples/lock-strategy.examples.d.ts +73 -0
  244. package/redis-lock/examples/lock-strategy.examples.js +387 -0
  245. package/redis-lock/index.d.ts +4 -0
  246. package/redis-lock/index.js +16 -0
  247. package/redis-lock/redis-lock.decorator.d.ts +12 -0
  248. package/redis-lock/redis-lock.decorator.js +125 -0
  249. package/redis-lock/redis-lock.module.d.ts +23 -0
  250. package/redis-lock/redis-lock.module.js +117 -0
  251. package/redis-lock/redis-lock.service.d.ts +66 -0
  252. package/redis-lock/redis-lock.service.js +413 -0
  253. package/setup/bootstrap.setup.d.ts +2 -0
  254. package/setup/bootstrap.setup.js +184 -0
  255. package/setup/index.d.ts +4 -0
  256. package/setup/index.js +20 -0
  257. package/setup/mode.setup.d.ts +12 -0
  258. package/setup/mode.setup.js +60 -0
  259. package/setup/schedule.decorator.d.ts +23 -0
  260. package/setup/schedule.decorator.js +233 -0
  261. package/setup/worker.decorator.d.ts +14 -0
  262. package/setup/worker.decorator.js +130 -0
  263. package/shared/index.d.ts +2 -0
  264. package/shared/index.js +18 -0
  265. package/shared/serviceRegistryModule.d.ts +2 -0
  266. package/shared/serviceRegistryModule.js +170 -0
  267. package/shared/services/api-config.service.d.ts +54 -0
  268. package/shared/services/api-config.service.js +287 -0
  269. package/shared/services/generator.service.d.ts +4 -0
  270. package/shared/services/generator.service.js +23 -0
  271. package/shared/services/index.d.ts +4 -0
  272. package/shared/services/index.js +20 -0
  273. package/shared/services/translation.service.d.ts +9 -0
  274. package/shared/services/translation.service.js +70 -0
  275. package/shared/services/validator.service.d.ts +3 -0
  276. package/shared/services/validator.service.js +20 -0
  277. package/validator-json/decorators.d.ts +6 -0
  278. package/validator-json/decorators.js +22 -0
  279. package/validator-json/default.d.ts +6 -0
  280. package/validator-json/default.js +138 -0
  281. package/validator-json/defaultConverters.d.ts +8 -0
  282. package/validator-json/defaultConverters.js +376 -0
  283. package/validator-json/index.d.ts +4 -0
  284. package/validator-json/index.js +20 -0
  285. package/validator-json/options.d.ts +11 -0
  286. package/validator-json/options.js +10 -0
  287. package/validators/file-mimetype.validator.d.ts +13 -0
  288. package/validators/file-mimetype.validator.js +21 -0
  289. package/validators/index.d.ts +6 -0
  290. package/validators/index.js +22 -0
  291. package/validators/is-exists.validator.d.ts +18 -0
  292. package/validators/is-exists.validator.js +60 -0
  293. package/validators/is-unique.validator.d.ts +17 -0
  294. package/validators/is-unique.validator.js +91 -0
  295. package/validators/phone-country-code.validator.d.ts +2 -0
  296. package/validators/phone-country-code.validator.js +29 -0
  297. package/validators/same-as.validator.d.ts +2 -0
  298. package/validators/same-as.validator.js +24 -0
  299. package/validators/skip-empty.validator.d.ts +1 -0
  300. package/validators/skip-empty.validator.js +17 -0
  301. package/vault/index.d.ts +4 -0
  302. package/vault/index.js +20 -0
  303. package/vault/interfaces/vault-options.interface.d.ts +22 -0
  304. package/vault/interfaces/vault-options.interface.js +2 -0
  305. package/vault/vault-config.loader.d.ts +13 -0
  306. package/vault/vault-config.loader.js +246 -0
  307. package/vault/vault-config.service.d.ts +18 -0
  308. package/vault/vault-config.service.js +174 -0
  309. package/vault/vault.module.d.ts +2 -0
  310. package/vault/vault.module.js +21 -0
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.bootstrapSetup = bootstrapSetup;
13
+ const Sentry = require("@sentry/nestjs");
14
+ const profiling_node_1 = require("@sentry/profiling-node");
15
+ const dotenv = require("dotenv");
16
+ const fs_1 = require("fs");
17
+ const path_1 = require("path");
18
+ const process = require("process");
19
+ const mode_setup_1 = require("./mode.setup");
20
+ function findValidRootPath() {
21
+ const getAppRootPath = () => {
22
+ if (require.main && require.main.filename) {
23
+ return (0, path_1.dirname)(require.main.filename);
24
+ }
25
+ if (process.argv[1]) {
26
+ return (0, path_1.dirname)(process.argv[1]);
27
+ }
28
+ return process.cwd();
29
+ };
30
+ const possibleRootPaths = [getAppRootPath(), process.cwd(), __dirname];
31
+ const envFile = `${process.env.NODE_ENV || ''}.env`;
32
+ const isTest = process.env.NODE_ENV === 'test';
33
+ let envFilePath = '';
34
+ for (const rootPath of possibleRootPaths) {
35
+ const configPath = (0, path_1.join)(rootPath, 'config');
36
+ const baseEnvFilePath = (0, path_1.join)(configPath, 'base.env');
37
+ if (isTest) {
38
+ envFilePath = (0, path_1.join)(configPath, 'test.env');
39
+ if ((0, fs_1.existsSync)(envFilePath)) {
40
+ return { rootPath, baseEnvFilePath, envFilePath };
41
+ }
42
+ else {
43
+ envFilePath = (0, path_1.join)(configPath, 'dev.env');
44
+ if ((0, fs_1.existsSync)(envFilePath)) {
45
+ return { rootPath, baseEnvFilePath, envFilePath };
46
+ }
47
+ }
48
+ }
49
+ else {
50
+ envFilePath = (0, path_1.join)(configPath, envFile);
51
+ if ((0, fs_1.existsSync)(envFilePath)) {
52
+ return { rootPath, baseEnvFilePath, envFilePath };
53
+ }
54
+ }
55
+ }
56
+ throw new Error(`No valid .env file: ${envFilePath}`);
57
+ }
58
+ const { envFilePath, rootPath, baseEnvFilePath } = findValidRootPath();
59
+ dotenv.config({ path: [envFilePath, baseEnvFilePath] });
60
+ process.env.ROOT_PATH = rootPath;
61
+ process.env.ENV_FILE_PATH = envFilePath;
62
+ process.env.BASE_ENV_FILE_PATH = baseEnvFilePath;
63
+ const requiredEnvVars = ['SENTRY_DSN', 'API_VERSION', 'NODE_ENV'];
64
+ requiredEnvVars.forEach((envVar) => {
65
+ if (!process.env[envVar]) {
66
+ throw new Error(`Missing required environment variable: ${envVar}`);
67
+ }
68
+ });
69
+ Sentry.init({
70
+ dsn: process.env.SENTRY_DSN || '',
71
+ release: process.env.API_VERSION || '',
72
+ environment: process.env.NODE_ENV || 'unkown',
73
+ debug: false,
74
+ sampleRate: 1.0,
75
+ tracesSampleRate: 0.01,
76
+ profileSessionSampleRate: 0.01,
77
+ profileLifecycle: 'trace',
78
+ sendDefaultPii: true,
79
+ integrations: [profiling_node_1.nodeProfilingIntegration],
80
+ });
81
+ const crud_1 = require("@dataui/crud");
82
+ crud_1.CrudConfigService.load({
83
+ auth: {
84
+ property: 'user',
85
+ },
86
+ params: {
87
+ id: {
88
+ field: 'id',
89
+ type: 'string',
90
+ primary: true,
91
+ },
92
+ },
93
+ query: {
94
+ limit: 10,
95
+ alwaysPaginate: true,
96
+ },
97
+ routes: {
98
+ updateOneBase: {
99
+ allowParamsOverride: false,
100
+ },
101
+ deleteOneBase: {
102
+ returnDeleted: false,
103
+ },
104
+ createOneBase: {
105
+ returnShallow: false,
106
+ },
107
+ },
108
+ });
109
+ const core_1 = require("@nestjs/core");
110
+ const nestjs_pino_1 = require("nestjs-pino");
111
+ const session = require("express-session");
112
+ const bodyParse = require("body-parser");
113
+ const compression = require("compression");
114
+ const __1 = require("../");
115
+ const common_1 = require("@nestjs/common");
116
+ const nestjs_i18n_1 = require("nestjs-i18n");
117
+ const nestjs_cls_1 = require("nestjs-cls");
118
+ const class_validator_1 = require("class-validator");
119
+ const setup_1 = require("@sentry/nestjs/setup");
120
+ const vault_1 = require("../vault");
121
+ const dto_1 = require("../common/dto");
122
+ function bootstrapSetup(AppModule, SetupSwagger) {
123
+ return __awaiter(this, void 0, void 0, function* () {
124
+ yield vault_1.VaultConfigLoader.loadVaultConfig();
125
+ const shouldStartHttp = (0, mode_setup_1.shouldStartHttpServer)();
126
+ const app = yield core_1.NestFactory.create(AppModule, {
127
+ bufferLogs: true,
128
+ autoFlushLogs: true,
129
+ });
130
+ const appModuleRef = app.select(AppModule);
131
+ (0, class_validator_1.useContainer)(appModuleRef, { fallbackOnErrors: true });
132
+ dto_1.DtoContainer.useContainer(appModuleRef);
133
+ const configService = app.select(__1.ServiceRegistryModule).get(__1.ApiConfigService);
134
+ const logger = app.get(nestjs_pino_1.Logger);
135
+ app.useLogger(logger);
136
+ app.flushLogs();
137
+ logger.log(`Application Mode: ${(0, mode_setup_1.getModeDescription)()}`);
138
+ logger.log(`Environment: ${process.env.NODE_ENV || 'unknown'}`);
139
+ app.enableShutdownHooks();
140
+ app.enableVersioning();
141
+ app.enable('trust proxy');
142
+ app.use(bodyParse.json({ limit: '50mb' }), new nestjs_cls_1.ClsMiddleware({
143
+ saveReq: true,
144
+ }).use, (0, __1.RequestIdMiddleware)(), (0, __1.PowerByMiddleware)(), (0, __1.OmniAuthMiddleware)(), compression());
145
+ const reflector = app.get(core_1.Reflector);
146
+ app.useGlobalFilters(new setup_1.SentryGlobalFilter(), new __1.HttpExceptionFilter(), new __1.QueryFailedFilter(reflector));
147
+ app.useGlobalInterceptors(new __1.LanguageInterceptor(), new __1.TranslationInterceptor(), new nestjs_pino_1.LoggerErrorInterceptor());
148
+ app.useGlobalPipes(new nestjs_i18n_1.I18nValidationPipe({
149
+ whitelist: true,
150
+ errorHttpStatusCode: common_1.HttpStatus.UNPROCESSABLE_ENTITY,
151
+ transform: true,
152
+ stopAtFirstError: true,
153
+ validationError: { target: false, value: false },
154
+ }));
155
+ if (shouldStartHttp) {
156
+ if (configService.documentationEnabled && SetupSwagger) {
157
+ SetupSwagger(app, configService.documentationPath);
158
+ logger.log(`Swagger docs available at ${configService.documentationPath}`);
159
+ }
160
+ if (configService.viewsEnabled) {
161
+ app.setBaseViewsDir((0, path_1.join)(__1.ApiConfigService.rootPath, 'views'));
162
+ app.setViewEngine('ejs');
163
+ logger.log('View engine initialized');
164
+ }
165
+ if (configService.sessionEnabled) {
166
+ app.use(session(configService.sessionConfig));
167
+ logger.log('Session middleware enabled');
168
+ }
169
+ if (configService.corsEnabled) {
170
+ app.enableCors(configService.corsConfig);
171
+ logger.log('CORS configuration applied');
172
+ }
173
+ const port = configService.appConfig.port;
174
+ yield app.listen(port);
175
+ logger.log(`HTTP Server running on ${yield app.getUrl()}`);
176
+ }
177
+ else {
178
+ logger.log('Running in Worker-only mode - HTTP server not started');
179
+ logger.log('Application is ready to process background tasks');
180
+ yield app.init();
181
+ }
182
+ return app;
183
+ });
184
+ }
@@ -0,0 +1,4 @@
1
+ export * from './bootstrap.setup';
2
+ export * from './mode.setup';
3
+ export * from './worker.decorator';
4
+ export * from './schedule.decorator';
package/setup/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./bootstrap.setup"), exports);
18
+ __exportStar(require("./mode.setup"), exports);
19
+ __exportStar(require("./worker.decorator"), exports);
20
+ __exportStar(require("./schedule.decorator"), exports);
@@ -0,0 +1,12 @@
1
+ export declare enum ApplicationMode {
2
+ HTTP = "http",
3
+ WORKER = "worker",
4
+ HYBRID = "hybrid"
5
+ }
6
+ export declare function getApplicationMode(): ApplicationMode;
7
+ export declare function shouldProcessQueues(): boolean;
8
+ export declare function shouldStartHttpServer(): boolean;
9
+ export declare function isHttpMode(): boolean;
10
+ export declare function isWorkerMode(): boolean;
11
+ export declare function isHybridMode(): boolean;
12
+ export declare function getModeDescription(): string;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApplicationMode = void 0;
4
+ exports.getApplicationMode = getApplicationMode;
5
+ exports.shouldProcessQueues = shouldProcessQueues;
6
+ exports.shouldStartHttpServer = shouldStartHttpServer;
7
+ exports.isHttpMode = isHttpMode;
8
+ exports.isWorkerMode = isWorkerMode;
9
+ exports.isHybridMode = isHybridMode;
10
+ exports.getModeDescription = getModeDescription;
11
+ var ApplicationMode;
12
+ (function (ApplicationMode) {
13
+ ApplicationMode["HTTP"] = "http";
14
+ ApplicationMode["WORKER"] = "worker";
15
+ ApplicationMode["HYBRID"] = "hybrid";
16
+ })(ApplicationMode || (exports.ApplicationMode = ApplicationMode = {}));
17
+ function getApplicationMode() {
18
+ const mode = (process.env.APP_MODE || process.env.MODE || 'hybrid')
19
+ .toLowerCase()
20
+ .trim();
21
+ switch (mode) {
22
+ case 'http':
23
+ return ApplicationMode.HTTP;
24
+ case 'worker':
25
+ return ApplicationMode.WORKER;
26
+ case 'hybrid':
27
+ default:
28
+ return ApplicationMode.HYBRID;
29
+ }
30
+ }
31
+ function shouldProcessQueues() {
32
+ const mode = getApplicationMode();
33
+ return mode === ApplicationMode.WORKER || mode === ApplicationMode.HYBRID;
34
+ }
35
+ function shouldStartHttpServer() {
36
+ const mode = getApplicationMode();
37
+ return mode === ApplicationMode.HTTP || mode === ApplicationMode.HYBRID;
38
+ }
39
+ function isHttpMode() {
40
+ return getApplicationMode() === ApplicationMode.HTTP;
41
+ }
42
+ function isWorkerMode() {
43
+ return getApplicationMode() === ApplicationMode.WORKER;
44
+ }
45
+ function isHybridMode() {
46
+ return getApplicationMode() === ApplicationMode.HYBRID;
47
+ }
48
+ function getModeDescription() {
49
+ const mode = getApplicationMode();
50
+ switch (mode) {
51
+ case ApplicationMode.HTTP:
52
+ return 'HTTP-only mode (no background workers)';
53
+ case ApplicationMode.WORKER:
54
+ return 'Worker-only mode (no HTTP server)';
55
+ case ApplicationMode.HYBRID:
56
+ return 'Hybrid mode (HTTP server + background workers)';
57
+ default:
58
+ return 'Unknown mode';
59
+ }
60
+ }
@@ -0,0 +1,23 @@
1
+ import type { CronOptions } from '@nestjs/schedule';
2
+ export interface ScheduleWithLockOptions {
3
+ lockTtl?: number;
4
+ retryCount?: number;
5
+ retryDelay?: number;
6
+ useExponentialBackoff?: boolean;
7
+ maxRetryDelay?: number;
8
+ logExecution?: boolean;
9
+ lockKeyPrefix?: string;
10
+ autoExtendLock?: number;
11
+ onSuccess?: (duration: number) => void | Promise<void>;
12
+ onError?: (error: Error) => void | Promise<void>;
13
+ skipIfLocked?: boolean;
14
+ }
15
+ export declare function WorkerCron(cronTime: string | Date, options?: CronOptions): MethodDecorator;
16
+ export declare function WorkerInterval(timeout: number, name?: string): MethodDecorator;
17
+ export declare function WorkerTimeout(timeout: number, name?: string): MethodDecorator;
18
+ export declare function WorkerCronWithLock(cronTime: string | Date, lockKeyOrOptions: string | ScheduleWithLockOptions, lockTtl?: number, cronOptions?: CronOptions): MethodDecorator;
19
+ export declare function WorkerIntervalWithLock(timeout: number, lockKeyOrOptions: string | ScheduleWithLockOptions, lockTtl?: number): MethodDecorator;
20
+ export declare function WorkerTimeoutWithLock(timeout: number, lockKeyOrOptions: string | ScheduleWithLockOptions, lockTtl?: number): MethodDecorator;
21
+ export declare function WorkerCronSmart(cronTime: string | Date, options?: ScheduleWithLockOptions, cronOptions?: CronOptions): MethodDecorator;
22
+ export declare function WorkerIntervalSmart(timeout: number, options?: ScheduleWithLockOptions): MethodDecorator;
23
+ export declare function WorkerCronAdvanced(cronTime: string | Date, lockKeyOrOptions: string | ScheduleWithLockOptions, options?: ScheduleWithLockOptions, cronOptions?: CronOptions): MethodDecorator;
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.WorkerCron = WorkerCron;
13
+ exports.WorkerInterval = WorkerInterval;
14
+ exports.WorkerTimeout = WorkerTimeout;
15
+ exports.WorkerCronWithLock = WorkerCronWithLock;
16
+ exports.WorkerIntervalWithLock = WorkerIntervalWithLock;
17
+ exports.WorkerTimeoutWithLock = WorkerTimeoutWithLock;
18
+ exports.WorkerCronSmart = WorkerCronSmart;
19
+ exports.WorkerIntervalSmart = WorkerIntervalSmart;
20
+ exports.WorkerCronAdvanced = WorkerCronAdvanced;
21
+ const common_1 = require("@nestjs/common");
22
+ const schedule_1 = require("@nestjs/schedule");
23
+ const mode_setup_1 = require("./mode.setup");
24
+ const redis_lock_service_1 = require("../redis-lock/redis-lock.service");
25
+ function generateLockKey(className, methodName) {
26
+ return `${className}.${methodName}`;
27
+ }
28
+ function executeWithRetry(fn, options) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ const { retryCount = 0, retryDelay = 1000, useExponentialBackoff = false, maxRetryDelay = 60000, logger, taskName, } = options;
31
+ let lastError;
32
+ let attempt = 0;
33
+ while (attempt <= retryCount) {
34
+ try {
35
+ return yield fn();
36
+ }
37
+ catch (error) {
38
+ lastError = error;
39
+ attempt++;
40
+ if (attempt <= retryCount) {
41
+ let delay = retryDelay;
42
+ if (useExponentialBackoff) {
43
+ delay = Math.min(retryDelay * Math.pow(2, attempt - 1), maxRetryDelay);
44
+ }
45
+ logger.warn(`Task "${taskName}" failed (attempt ${attempt}/${retryCount + 1}), ` +
46
+ `retrying in ${delay}ms... Error: ${error.message}`);
47
+ yield new Promise((resolve) => setTimeout(resolve, delay));
48
+ }
49
+ }
50
+ }
51
+ throw lastError;
52
+ });
53
+ }
54
+ function createWorkerDecorator(baseDecorator, decoratorName) {
55
+ return function (target, propertyKey, descriptor) {
56
+ const originalMethod = descriptor.value;
57
+ descriptor.value = function (...args) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ if (!(0, mode_setup_1.shouldProcessQueues)()) {
60
+ return;
61
+ }
62
+ return originalMethod.apply(this, args);
63
+ });
64
+ };
65
+ baseDecorator(target, propertyKey, descriptor);
66
+ return descriptor;
67
+ };
68
+ }
69
+ function createWorkerDecoratorWithLock(baseDecorator, decoratorName, lockKey, options = {}) {
70
+ return function (target, propertyKey, descriptor) {
71
+ const originalMethod = descriptor.value;
72
+ const className = target.constructor.name;
73
+ const methodName = String(propertyKey);
74
+ const logger = new common_1.Logger(`${className}.${methodName}`);
75
+ const resolvedLockKey = typeof lockKey === 'function' ? lockKey() : lockKey;
76
+ descriptor.value = function (...args) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ if (!(0, mode_setup_1.shouldProcessQueues)()) {
79
+ return;
80
+ }
81
+ const lockService = redis_lock_service_1.RedisLockService.getOrCreateGlobalInstance();
82
+ const { lockTtl = 3600000, retryCount = 0, retryDelay = 1000, useExponentialBackoff = false, maxRetryDelay = 60000, logExecution = true, lockKeyPrefix = 'schedule', autoExtendLock = 0, onSuccess, onError, skipIfLocked = true, } = options;
83
+ const fullLockKey = `${lockKeyPrefix}:${resolvedLockKey}`;
84
+ const startTime = Date.now();
85
+ if (logExecution) {
86
+ logger.log(`Task starting...`);
87
+ }
88
+ try {
89
+ const lockResult = yield lockService.acquireLock(resolvedLockKey, {
90
+ ttl: lockTtl,
91
+ keyPrefix: lockKeyPrefix,
92
+ autoExtend: autoExtendLock,
93
+ });
94
+ if (!lockResult.acquired) {
95
+ if (skipIfLocked) {
96
+ logger.debug(`Lock "${fullLockKey}" is held by another instance, skipping execution`);
97
+ return null;
98
+ }
99
+ else {
100
+ throw new Error(`Failed to acquire lock "${fullLockKey}"`);
101
+ }
102
+ }
103
+ try {
104
+ const result = yield executeWithRetry(() => originalMethod.apply(this, args), {
105
+ retryCount,
106
+ retryDelay,
107
+ useExponentialBackoff,
108
+ maxRetryDelay,
109
+ logger,
110
+ taskName: `${className}.${methodName}`,
111
+ });
112
+ const duration = Date.now() - startTime;
113
+ if (logExecution) {
114
+ logger.log(`Task completed successfully in ${duration}ms`);
115
+ }
116
+ if (onSuccess) {
117
+ yield onSuccess.call(this, duration);
118
+ }
119
+ return result;
120
+ }
121
+ finally {
122
+ if (lockResult.autoExtendTimer) {
123
+ clearInterval(lockResult.autoExtendTimer);
124
+ }
125
+ yield lockService.releaseLock(resolvedLockKey, lockResult.lockValue, lockKeyPrefix);
126
+ if (logExecution) {
127
+ logger.debug(`Lock "${fullLockKey}" released`);
128
+ }
129
+ }
130
+ }
131
+ catch (error) {
132
+ const duration = Date.now() - startTime;
133
+ if (logExecution) {
134
+ logger.error(`Task failed after ${duration}ms: ${error.message}`, error.stack);
135
+ }
136
+ if (onError) {
137
+ yield onError.call(this, error);
138
+ }
139
+ throw error;
140
+ }
141
+ });
142
+ };
143
+ baseDecorator(target, propertyKey, descriptor);
144
+ return descriptor;
145
+ };
146
+ }
147
+ function WorkerCron(cronTime, options) {
148
+ return createWorkerDecorator((0, schedule_1.Cron)(cronTime, options), 'WorkerCron');
149
+ }
150
+ function WorkerInterval(timeout, name) {
151
+ if (name) {
152
+ return createWorkerDecorator((0, schedule_1.Interval)(name, timeout), 'WorkerInterval');
153
+ }
154
+ return createWorkerDecorator((0, schedule_1.Interval)(timeout), 'WorkerInterval');
155
+ }
156
+ function WorkerTimeout(timeout, name) {
157
+ if (name) {
158
+ return createWorkerDecorator((0, schedule_1.Timeout)(name, timeout), 'WorkerTimeout');
159
+ }
160
+ return createWorkerDecorator((0, schedule_1.Timeout)(timeout), 'WorkerTimeout');
161
+ }
162
+ function WorkerCronWithLock(cronTime, lockKeyOrOptions, lockTtl, cronOptions) {
163
+ return function (target, propertyKey, descriptor) {
164
+ let lockKey;
165
+ let options;
166
+ if (typeof lockKeyOrOptions === 'string') {
167
+ lockKey = lockKeyOrOptions;
168
+ options = { lockTtl: lockTtl || 3600000 };
169
+ }
170
+ else {
171
+ lockKey = generateLockKey(target.constructor.name, String(propertyKey));
172
+ options = lockKeyOrOptions;
173
+ }
174
+ return createWorkerDecoratorWithLock((0, schedule_1.Cron)(cronTime, cronOptions), 'WorkerCronWithLock', lockKey, options)(target, propertyKey, descriptor);
175
+ };
176
+ }
177
+ function WorkerIntervalWithLock(timeout, lockKeyOrOptions, lockTtl) {
178
+ return function (target, propertyKey, descriptor) {
179
+ let lockKey;
180
+ let options;
181
+ if (typeof lockKeyOrOptions === 'string') {
182
+ lockKey = lockKeyOrOptions;
183
+ options = { lockTtl: lockTtl || Math.floor(timeout * 0.8) };
184
+ }
185
+ else {
186
+ lockKey = generateLockKey(target.constructor.name, String(propertyKey));
187
+ options = Object.assign({ lockTtl: Math.floor(timeout * 0.8) }, lockKeyOrOptions);
188
+ }
189
+ return createWorkerDecoratorWithLock((0, schedule_1.Interval)(timeout), 'WorkerIntervalWithLock', lockKey, options)(target, propertyKey, descriptor);
190
+ };
191
+ }
192
+ function WorkerTimeoutWithLock(timeout, lockKeyOrOptions, lockTtl) {
193
+ return function (target, propertyKey, descriptor) {
194
+ let lockKey;
195
+ let options;
196
+ if (typeof lockKeyOrOptions === 'string') {
197
+ lockKey = lockKeyOrOptions;
198
+ options = { lockTtl: lockTtl || 300000 };
199
+ }
200
+ else {
201
+ lockKey = generateLockKey(target.constructor.name, String(propertyKey));
202
+ options = Object.assign({ lockTtl: 300000 }, lockKeyOrOptions);
203
+ }
204
+ return createWorkerDecoratorWithLock((0, schedule_1.Timeout)(timeout), 'WorkerTimeoutWithLock', lockKey, options)(target, propertyKey, descriptor);
205
+ };
206
+ }
207
+ function WorkerCronSmart(cronTime, options = {}, cronOptions) {
208
+ return function (target, propertyKey, descriptor) {
209
+ const lockKey = generateLockKey(target.constructor.name, String(propertyKey));
210
+ return createWorkerDecoratorWithLock((0, schedule_1.Cron)(cronTime, cronOptions), 'WorkerCronSmart', lockKey, Object.assign({ lockTtl: 3600000, logExecution: true }, options))(target, propertyKey, descriptor);
211
+ };
212
+ }
213
+ function WorkerIntervalSmart(timeout, options = {}) {
214
+ return function (target, propertyKey, descriptor) {
215
+ const lockKey = generateLockKey(target.constructor.name, String(propertyKey));
216
+ return createWorkerDecoratorWithLock((0, schedule_1.Interval)(timeout), 'WorkerIntervalSmart', lockKey, Object.assign({ lockTtl: Math.floor(timeout * 0.8), logExecution: true }, options))(target, propertyKey, descriptor);
217
+ };
218
+ }
219
+ function WorkerCronAdvanced(cronTime, lockKeyOrOptions, options, cronOptions) {
220
+ return function (target, propertyKey, descriptor) {
221
+ let lockKey;
222
+ let finalOptions;
223
+ if (typeof lockKeyOrOptions === 'string') {
224
+ lockKey = lockKeyOrOptions;
225
+ finalOptions = Object.assign({ lockTtl: 3600000, logExecution: true }, options);
226
+ }
227
+ else {
228
+ lockKey = generateLockKey(target.constructor.name, String(propertyKey));
229
+ finalOptions = Object.assign({ lockTtl: 3600000, logExecution: true }, lockKeyOrOptions);
230
+ }
231
+ return createWorkerDecoratorWithLock((0, schedule_1.Cron)(cronTime, cronOptions), 'WorkerCronAdvanced', lockKey, finalOptions)(target, propertyKey, descriptor);
232
+ };
233
+ }
@@ -0,0 +1,14 @@
1
+ export declare function WorkerProcessor(queueName?: string): ClassDecorator;
2
+ export declare function WorkerProcess(name?: string): MethodDecorator;
3
+ export declare function WorkerOnQueueActive(): MethodDecorator;
4
+ export declare function WorkerOnQueueCompleted(): MethodDecorator;
5
+ export declare function WorkerOnQueueProgress(): MethodDecorator;
6
+ export declare function WorkerOnQueueFailed(): MethodDecorator;
7
+ export declare function WorkerOnQueueError(): MethodDecorator;
8
+ export declare function WorkerOnQueueWaiting(): MethodDecorator;
9
+ export declare function WorkerOnQueueStalled(): MethodDecorator;
10
+ export declare function WorkerOnQueueRemoved(): MethodDecorator;
11
+ export declare function WorkerOnQueueCleaned(): MethodDecorator;
12
+ export declare function WorkerOnQueueDrained(): MethodDecorator;
13
+ export declare function WorkerOnQueuePaused(): MethodDecorator;
14
+ export declare function WorkerOnQueueResumed(): MethodDecorator;