@xrystal/core 3.28.3 → 3.37.3

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 (233) hide show
  1. package/README.md +2331 -21
  2. package/package.json +66 -24
  3. package/tsconfig.base.json +15 -0
  4. package/x/bin/commands/create.mjs +136 -0
  5. package/x/bin/commands/doctor.mjs +149 -0
  6. package/x/bin/commands/hooks.mjs +55 -0
  7. package/x/bin/commands/project.mjs +126 -0
  8. package/x/bin/commands/release.mjs +66 -0
  9. package/x/bin/commands/sync-toolchain.mjs +43 -0
  10. package/x/bin/commands/tmp.mjs +57 -0
  11. package/x/bin/constants/index.mjs +6 -0
  12. package/x/bin/helpers/.generated/.generated-from +1 -0
  13. package/x/bin/helpers/.generated/tmp-schema.mjs +192 -0
  14. package/x/bin/helpers/banner.mjs +80 -0
  15. package/x/bin/helpers/build-config.mjs +342 -0
  16. package/x/bin/helpers/cli-help.mjs +164 -0
  17. package/x/bin/helpers/cli-identity.mjs +17 -0
  18. package/x/bin/helpers/create-target.mjs +35 -0
  19. package/{bin → x/bin}/helpers/index.mjs +44 -1
  20. package/x/bin/helpers/project-artifacts.mjs +140 -0
  21. package/x/bin/helpers/project-root.mjs +70 -0
  22. package/x/bin/helpers/runtime-info.mjs +172 -0
  23. package/x/bin/helpers/tmp-config.mjs +67 -0
  24. package/x/bin/helpers/tmp-layout.mjs +281 -0
  25. package/x/bin/helpers/tmp-schema.mjs +9 -0
  26. package/x/bin/helpers/toolchain-config.mjs +233 -0
  27. package/x/bin/main-cli.js +80 -0
  28. package/x/bin/paths.mjs +14 -0
  29. package/x/bin/scripts/clean-source-types.mjs +19 -0
  30. package/x/bin/scripts/fix-dist-imports.mjs +80 -0
  31. package/x/bin/scripts/install-git-hooks.mjs +86 -0
  32. package/x/bin/scripts/minify-dist.mjs +50 -0
  33. package/x/bin/scripts/prepare-npm-publish.mjs +49 -0
  34. package/x/bin/scripts/release-prepare.mjs +56 -0
  35. package/x/bin/scripts/tag.mjs +17 -0
  36. package/x/bin/scripts/unpublish-leaked-versions.mjs +62 -0
  37. package/x/bin/scripts/verify-npm-pack.mjs +45 -0
  38. package/x/bin/scripts/verify-version-bump.mjs +27 -0
  39. package/x/bin/scripts/version-check.mjs +370 -0
  40. package/x/dist/index.d.ts +3 -0
  41. package/x/dist/index.js +1 -0
  42. package/{source → x/dist}/loader/clients/index.d.ts +2 -1
  43. package/x/dist/loader/clients/index.js +1 -0
  44. package/{source → x/dist}/loader/configs/index.d.ts +3 -2
  45. package/x/dist/loader/configs/index.js +1 -0
  46. package/x/dist/loader/controller/index.d.ts +69 -0
  47. package/x/dist/loader/controller/index.js +1 -0
  48. package/x/dist/loader/dto/index.d.ts +39 -0
  49. package/x/dist/loader/dto/index.js +1 -0
  50. package/{source → x/dist}/loader/events/index.d.ts +1 -1
  51. package/x/dist/loader/events/index.js +1 -0
  52. package/{source → x/dist}/loader/index.d.ts +2 -1
  53. package/x/dist/loader/index.js +1 -0
  54. package/{source → x/dist}/loader/kafka/index.d.ts +6 -3
  55. package/x/dist/loader/kafka/index.js +1 -0
  56. package/{source → x/dist}/loader/localizations/index.d.ts +4 -3
  57. package/x/dist/loader/localizations/index.js +1 -0
  58. package/{source → x/dist}/loader/logger/index.d.ts +10 -7
  59. package/x/dist/loader/logger/index.js +2 -0
  60. package/x/dist/loader/service/index.js +1 -0
  61. package/{source → x/dist}/loader/system/index.d.ts +4 -3
  62. package/x/dist/loader/system/index.js +1 -0
  63. package/{source → x/dist}/project/index.d.ts +2 -2
  64. package/x/dist/project/index.js +1 -0
  65. package/x/dist/utils/constants/defaults.json +44 -0
  66. package/x/dist/utils/constants/index.d.ts +27 -0
  67. package/x/dist/utils/constants/index.js +1 -0
  68. package/x/dist/utils/helpers/configs/index.js +1 -0
  69. package/x/dist/utils/helpers/context/controller-store.d.ts +51 -0
  70. package/x/dist/utils/helpers/context/controller-store.js +1 -0
  71. package/x/dist/utils/helpers/context/index.d.ts +18 -0
  72. package/x/dist/utils/helpers/context/index.js +1 -0
  73. package/{source → x/dist}/utils/helpers/core/index.d.ts +8 -6
  74. package/x/dist/utils/helpers/core/index.js +1 -0
  75. package/x/dist/utils/helpers/core/paths.d.ts +2 -0
  76. package/x/dist/utils/helpers/core/paths.js +1 -0
  77. package/x/dist/utils/helpers/core/tmp-layout.d.ts +45 -0
  78. package/x/dist/utils/helpers/core/tmp-layout.js +1 -0
  79. package/{source → x/dist}/utils/helpers/date/index.d.ts +1 -1
  80. package/x/dist/utils/helpers/date/index.js +1 -0
  81. package/x/dist/utils/helpers/dispatch/index.d.ts +9 -0
  82. package/x/dist/utils/helpers/dispatch/index.js +1 -0
  83. package/x/dist/utils/helpers/dto/index.d.ts +10 -0
  84. package/x/dist/utils/helpers/dto/index.js +1 -0
  85. package/x/dist/utils/helpers/filters/index.js +1 -0
  86. package/x/dist/utils/helpers/framework/index.d.ts +3 -0
  87. package/x/dist/utils/helpers/framework/index.js +1 -0
  88. package/x/dist/utils/helpers/handlers/adapters.d.ts +10 -0
  89. package/x/dist/utils/helpers/handlers/adapters.js +1 -0
  90. package/x/dist/utils/helpers/handlers/execute.d.ts +5 -0
  91. package/x/dist/utils/helpers/handlers/execute.js +1 -0
  92. package/x/dist/utils/helpers/handlers/index.d.ts +18 -0
  93. package/x/dist/utils/helpers/handlers/index.js +1 -0
  94. package/x/dist/utils/helpers/hash/crypto.js +1 -0
  95. package/x/dist/utils/helpers/id/index.js +1 -0
  96. package/x/dist/utils/helpers/index.d.ts +26 -0
  97. package/x/dist/utils/helpers/index.js +1 -0
  98. package/x/dist/utils/helpers/ip/index.js +1 -0
  99. package/x/dist/utils/helpers/is/index.js +1 -0
  100. package/{source → x/dist}/utils/helpers/locales/index.d.ts +1 -0
  101. package/x/dist/utils/helpers/locales/index.js +1 -0
  102. package/x/dist/utils/helpers/math/index.js +1 -0
  103. package/x/dist/utils/helpers/middleware/index.d.ts +19 -0
  104. package/x/dist/utils/helpers/middleware/index.js +1 -0
  105. package/x/dist/utils/helpers/objects/index.js +1 -0
  106. package/x/dist/utils/helpers/path/index.js +1 -0
  107. package/x/dist/utils/helpers/protocol/index.d.ts +20 -0
  108. package/x/dist/utils/helpers/protocol/index.js +1 -0
  109. package/x/dist/utils/helpers/protocol/options.d.ts +6 -0
  110. package/x/dist/utils/helpers/protocol/options.js +1 -0
  111. package/x/dist/utils/helpers/regex/checkSpecialRegexControl.js +1 -0
  112. package/x/dist/utils/helpers/runtime/dto-access.d.ts +3 -0
  113. package/x/dist/utils/helpers/runtime/dto-access.js +1 -0
  114. package/x/dist/utils/helpers/runtime/dto-types.d.ts +19 -0
  115. package/x/dist/utils/helpers/runtime/dto-types.js +1 -0
  116. package/x/dist/utils/helpers/runtime/index.d.ts +3 -0
  117. package/x/dist/utils/helpers/runtime/index.js +1 -0
  118. package/x/dist/utils/helpers/runtime/shutdown.d.ts +3 -0
  119. package/x/dist/utils/helpers/runtime/shutdown.js +1 -0
  120. package/x/dist/utils/helpers/state/index.d.ts +59 -0
  121. package/x/dist/utils/helpers/state/index.js +1 -0
  122. package/x/dist/utils/helpers/state/props-from-tmp.d.ts +9 -0
  123. package/x/dist/utils/helpers/state/props-from-tmp.js +1 -0
  124. package/x/dist/utils/helpers/state/request-key-guard.d.ts +3 -0
  125. package/x/dist/utils/helpers/state/request-key-guard.js +1 -0
  126. package/x/dist/utils/helpers/state/scopes.d.ts +21 -0
  127. package/x/dist/utils/helpers/state/scopes.js +1 -0
  128. package/x/dist/utils/helpers/string/index.js +1 -0
  129. package/x/dist/utils/helpers/tests/tmp-schema.test.js +1 -0
  130. package/{source/utils/models/types/index.js → x/dist/utils/helpers/tests/tmp-watch.test.d.ts} +0 -1
  131. package/x/dist/utils/helpers/tests/tmp-watch.test.js +1 -0
  132. package/x/dist/utils/helpers/timer/index.js +1 -0
  133. package/x/dist/utils/helpers/tmp/index.d.ts +5 -0
  134. package/x/dist/utils/helpers/tmp/index.js +1 -0
  135. package/x/dist/utils/helpers/tmp/loader-tmp-sync.d.ts +4 -0
  136. package/x/dist/utils/helpers/tmp/loader-tmp-sync.js +1 -0
  137. package/x/dist/utils/helpers/tmp/runtime-tmp.d.ts +9 -0
  138. package/x/dist/utils/helpers/tmp/runtime-tmp.js +1 -0
  139. package/x/dist/utils/helpers/tmp/tmp-loader.d.ts +7 -0
  140. package/x/dist/utils/helpers/tmp/tmp-loader.js +1 -0
  141. package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +47 -0
  142. package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -0
  143. package/x/dist/utils/helpers/tmp/tmp-watch.d.ts +1 -0
  144. package/x/dist/utils/helpers/tmp/tmp-watch.js +1 -0
  145. package/x/dist/utils/helpers/validates/index.js +1 -0
  146. package/x/dist/utils/index.d.ts +3 -0
  147. package/x/dist/utils/index.js +1 -0
  148. package/x/dist/utils/models/classes/class.clients.js +1 -0
  149. package/x/dist/utils/models/classes/class.interfaces.js +1 -0
  150. package/x/dist/utils/models/classes/class.service-locator.js +1 -0
  151. package/{source → x/dist}/utils/models/classes/class.tmp-file-loader.d.ts +3 -2
  152. package/x/dist/utils/models/classes/class.tmp-file-loader.js +1 -0
  153. package/x/dist/utils/models/classes/class.x.js +1 -0
  154. package/{source → x/dist}/utils/models/enums/index.d.ts +14 -1
  155. package/x/dist/utils/models/enums/index.js +1 -0
  156. package/x/dist/utils/models/index.d.ts +9 -0
  157. package/x/dist/utils/models/index.js +1 -0
  158. package/x/dist/utils/models/types/index.d.ts +5 -0
  159. package/x/dist/utils/models/types/index.js +1 -0
  160. package/x/dist/utils/package-root.d.ts +2 -0
  161. package/x/dist/utils/package-root.js +1 -0
  162. package/x/tmp.yml +48 -17
  163. package/bin/constants/index.mjs +0 -17
  164. package/bin/main-cli.js +0 -131
  165. package/source/index.js +0 -6
  166. package/source/loader/clients/index.js +0 -18
  167. package/source/loader/configs/index.js +0 -81
  168. package/source/loader/controller/index.d.ts +0 -129
  169. package/source/loader/controller/index.js +0 -327
  170. package/source/loader/events/index.js +0 -44
  171. package/source/loader/index.js +0 -10
  172. package/source/loader/kafka/index.js +0 -122
  173. package/source/loader/localizations/index.js +0 -40
  174. package/source/loader/logger/index.js +0 -183
  175. package/source/loader/service/index.js +0 -7
  176. package/source/loader/system/index.js +0 -19
  177. package/source/project/index.js +0 -66
  178. package/source/utils/constants/index.d.ts +0 -10
  179. package/source/utils/constants/index.js +0 -11
  180. package/source/utils/helpers/configs/index.js +0 -1
  181. package/source/utils/helpers/core/index.js +0 -105
  182. package/source/utils/helpers/date/index.js +0 -48
  183. package/source/utils/helpers/filters/index.js +0 -44
  184. package/source/utils/helpers/hash/crypto.js +0 -22
  185. package/source/utils/helpers/id/index.js +0 -24
  186. package/source/utils/helpers/index.d.ts +0 -17
  187. package/source/utils/helpers/index.js +0 -17
  188. package/source/utils/helpers/ip/index.js +0 -21
  189. package/source/utils/helpers/is/index.js +0 -35
  190. package/source/utils/helpers/locales/index.js +0 -63
  191. package/source/utils/helpers/math/index.js +0 -14
  192. package/source/utils/helpers/middlewares/index.d.ts +0 -1
  193. package/source/utils/helpers/middlewares/index.js +0 -26
  194. package/source/utils/helpers/objects/index.js +0 -55
  195. package/source/utils/helpers/path/index.js +0 -4
  196. package/source/utils/helpers/regex/checkSpecialRegexControl.js +0 -3
  197. package/source/utils/helpers/string/index.js +0 -9
  198. package/source/utils/helpers/timer/index.js +0 -5
  199. package/source/utils/helpers/validates/index.js +0 -20
  200. package/source/utils/index.d.ts +0 -3
  201. package/source/utils/index.js +0 -3
  202. package/source/utils/models/classes/class.clients.js +0 -142
  203. package/source/utils/models/classes/class.dtos.d.ts +0 -47
  204. package/source/utils/models/classes/class.dtos.js +0 -36
  205. package/source/utils/models/classes/class.interfaces.js +0 -10
  206. package/source/utils/models/classes/class.response.d.ts +0 -17
  207. package/source/utils/models/classes/class.response.js +0 -35
  208. package/source/utils/models/classes/class.service-locator.js +0 -16
  209. package/source/utils/models/classes/class.tmp-file-loader.js +0 -38
  210. package/source/utils/models/classes/class.x.js +0 -179
  211. package/source/utils/models/enums/index.js +0 -133
  212. package/source/utils/models/index.d.ts +0 -11
  213. package/source/utils/models/index.js +0 -11
  214. package/source/utils/models/types/index.d.ts +0 -3
  215. /package/{source → x/dist}/loader/service/index.d.ts +0 -0
  216. /package/{source → x/dist}/utils/helpers/configs/index.d.ts +0 -0
  217. /package/{source → x/dist}/utils/helpers/filters/index.d.ts +0 -0
  218. /package/{source → x/dist}/utils/helpers/hash/crypto.d.ts +0 -0
  219. /package/{source → x/dist}/utils/helpers/id/index.d.ts +0 -0
  220. /package/{source → x/dist}/utils/helpers/ip/index.d.ts +0 -0
  221. /package/{source → x/dist}/utils/helpers/is/index.d.ts +0 -0
  222. /package/{source → x/dist}/utils/helpers/math/index.d.ts +0 -0
  223. /package/{source → x/dist}/utils/helpers/objects/index.d.ts +0 -0
  224. /package/{source → x/dist}/utils/helpers/path/index.d.ts +0 -0
  225. /package/{source → x/dist}/utils/helpers/regex/checkSpecialRegexControl.d.ts +0 -0
  226. /package/{source → x/dist}/utils/helpers/string/index.d.ts +0 -0
  227. /package/{source/index.d.ts → x/dist/utils/helpers/tests/tmp-schema.test.d.ts} +0 -0
  228. /package/{source → x/dist}/utils/helpers/timer/index.d.ts +0 -0
  229. /package/{source → x/dist}/utils/helpers/validates/index.d.ts +0 -0
  230. /package/{source → x/dist}/utils/models/classes/class.clients.d.ts +0 -0
  231. /package/{source → x/dist}/utils/models/classes/class.interfaces.d.ts +0 -0
  232. /package/{source → x/dist}/utils/models/classes/class.service-locator.d.ts +0 -0
  233. /package/{source → x/dist}/utils/models/classes/class.x.d.ts +0 -0
package/bin/main-cli.js DELETED
@@ -1,131 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { execSync } from "node:child_process"
4
- import fs from "node:fs"
5
- import path from "node:path"
6
- import { Command } from "commander"
7
- import chalk from "chalk"
8
- import ora from "ora"
9
- import yaml from "yaml"
10
-
11
- import { Constants } from "./constants/index.mjs"
12
- import { findFileRecursively, resolveObjWithHandlebars } from "./helpers/index.mjs"
13
-
14
- const setupCLI = async () => {
15
- const cli = new Command()
16
-
17
- const isBun = !!process.versions.bun
18
- const runtimeName = isBun ? "Bun" : "Node.js"
19
- const packageManager = isBun ? "bun" : "npm"
20
- const installCommand = isBun ? "bun install" : "npm install"
21
- const devCommand = isBun ? "bun run dev:local" : "npm run dev:local"
22
-
23
- try {
24
- let ownerTmpFilePath = findFileRecursively(".", Constants.defaultTmpFileName, Constants.defaultTmpFileExt)
25
-
26
- if (!ownerTmpFilePath) {
27
- if (!Constants.defaultTmpFilePath || !fs.existsSync(Constants.defaultTmpFilePath)) {
28
- throw new Error("Default template configuration file not found in package")
29
- }
30
-
31
- const folderPath = path.resolve(Constants.defaultRootFolderName)
32
- if (!fs.existsSync(folderPath)) {
33
- fs.mkdirSync(folderPath, { recursive: true })
34
- }
35
-
36
- const tmpFilePathBuffer = fs.readFileSync(Constants.defaultTmpFilePath)
37
- fs.writeFileSync(Constants.defaultOwnerTmpFilePath, tmpFilePathBuffer)
38
- ownerTmpFilePath = Constants.defaultOwnerTmpFilePath
39
- }
40
-
41
- const ownerTmpFile = fs.readFileSync(ownerTmpFilePath, "utf8")
42
- const parsedTmpObject = yaml.parse(ownerTmpFile)
43
- const resolvedTmpObject = resolveObjWithHandlebars(parsedTmpObject, parsedTmpObject)
44
-
45
- cli
46
- .command("create <project-name> [target-path]")
47
- .description(`Project initializer using ${runtimeName}`)
48
- .action(async (projectName, targetDir) => {
49
- let targetPath = ""
50
- const isCurrentDir = projectName === "."
51
-
52
- if (targetDir) {
53
- const baseDir = path.resolve(process.cwd(), targetDir)
54
- targetPath = isCurrentDir ? baseDir : path.join(baseDir, projectName)
55
- } else {
56
- targetPath = isCurrentDir ? process.cwd() : path.resolve(process.cwd(), projectName)
57
- }
58
-
59
- if (fs.existsSync(targetPath) && fs.readdirSync(targetPath).length > 0) {
60
- console.log(chalk.red(`❌ Error: Target directory '${targetPath}' is not empty!`))
61
- process.exit(1)
62
- }
63
-
64
- const mainPath = resolvedTmpObject?.configs?.mainFolderPath || "./source"
65
-
66
- if (!fs.existsSync(targetPath)) {
67
- fs.mkdirSync(targetPath, { recursive: true })
68
- }
69
-
70
- const spinner = ora(`${runtimeName} environment detected. Cloning template...`).start()
71
-
72
- try {
73
- execSync(`git clone --depth 1 ${Constants.templateRepoUri} "${targetPath}"`, { stdio: "ignore" })
74
-
75
- const gitFolder = path.join(targetPath, ".git")
76
- if (fs.existsSync(gitFolder)) {
77
- fs.rmSync(gitFolder, { recursive: true, force: true })
78
- }
79
-
80
- try {
81
- execSync(`git init`, { cwd: targetPath, stdio: "ignore" })
82
- } catch (e) {
83
- // Git init fail
84
- }
85
-
86
- const projectMainFolderPath = path.resolve(targetPath, mainPath)
87
- if (!fs.existsSync(projectMainFolderPath)) {
88
- fs.mkdirSync(projectMainFolderPath, { recursive: true })
89
- }
90
-
91
- spinner.succeed(chalk.green("Template cloned and git initialized!"))
92
- console.log(chalk.blue(`\n📦 Installing dependencies with ${packageManager}...`))
93
-
94
- execSync(installCommand, { cwd: targetPath, stdio: "inherit" })
95
-
96
- console.log(chalk.green("\n✅ Done!"))
97
-
98
- const relativePath = path.relative(process.cwd(), targetPath)
99
- if (relativePath && relativePath !== ".") {
100
- console.log(chalk.cyan(`\n cd ${relativePath}`))
101
- }
102
- console.log(chalk.cyan(` ${devCommand}`))
103
-
104
- } catch (err) {
105
- spinner.fail(chalk.red("Failed!"))
106
- console.error(chalk.red(`\nDetails: ${err.message}`))
107
-
108
- if (fs.existsSync(targetPath) && !isCurrentDir) {
109
- const files = fs.readdirSync(targetPath)
110
-
111
- if (files.length < 5) {
112
- fs.rmSync(targetPath, { recursive: true, force: true })
113
- console.log(chalk.yellow(`🧹 Cleaned up failed installation at ${targetPath}`))
114
- }
115
- }
116
- }
117
- })
118
-
119
- cli.parse(process.argv)
120
-
121
- } catch (error) {
122
- console.error(`${Constants.packageName || "CLI"} Initialization Error:`, error?.message)
123
- }
124
- }
125
-
126
- process.on("uncaughtException", (error) => {
127
- console.error("Critical Error:", error.message)
128
- process.exit(1)
129
- })
130
-
131
- setupCLI()
package/source/index.js DELETED
@@ -1,6 +0,0 @@
1
- import coreLoader from "./project/index.js";
2
- // => tmp project tool => xrystal
3
- await (async () => {
4
- const core = await coreLoader({});
5
- })();
6
- //
@@ -1,18 +0,0 @@
1
- import { BaseApiClient, CoreClientsEnum } from "../../utils";
2
- export default class Clients {
3
- _instances = {};
4
- #configs;
5
- constructor({ configs }) {
6
- this.#configs = configs;
7
- }
8
- async onInit() {
9
- const baseClient = new BaseApiClient({
10
- clientName: CoreClientsEnum.BASE_API_CLIENT,
11
- baseURL: this.#configs.all.baseApiUri || ''
12
- });
13
- this._instances[CoreClientsEnum.BASE_API_CLIENT] = baseClient;
14
- }
15
- get instances() {
16
- return this._instances;
17
- }
18
- }
@@ -1,81 +0,0 @@
1
- import path from 'node:path';
2
- import { merge } from 'lodash';
3
- import { pathToFileURL } from 'node:url';
4
- import { Constants } from '../../utils';
5
- export default class Configs {
6
- publicFolderName = Constants.publicFolderName;
7
- kafkaLogsTopic = Constants.kafkaLogsTopic;
8
- #system;
9
- #config;
10
- constructor({ system }) {
11
- this.#system = system;
12
- const proxy = new Proxy(this, {
13
- get: (target, prop) => {
14
- return target[prop] || target.config?.[prop];
15
- }
16
- });
17
- return proxy;
18
- }
19
- onInit = async ({}) => {
20
- const cwd = process.cwd();
21
- const tmp = this.#system.tmp;
22
- const extendConfigs = tmp.configs.loaders.configs.loadPath;
23
- const fullPath = extendConfigs.startsWith('@/')
24
- ? path.join(process.cwd(), extendConfigs.slice(2))
25
- : path.resolve(tmp.configs.rootFolderPath, extendConfigs);
26
- const fileUrl = pathToFileURL(fullPath).href;
27
- const modulePromise = import(fileUrl);
28
- this.#config = {
29
- worker: process.env.WORKER === 'true' ? true : false || false,
30
- mode: process.env.MODE,
31
- nodeEnv: process.env.NODE_ENV,
32
- debug: process.env.SYSTEM_LOGGER_LAYER,
33
- https: process.env.HTTPS,
34
- httpsfileEncoding: process.env.ENCODING || 'utf8',
35
- httpsCertfile: process.env.HTTPS_CERT_FILE,
36
- httpsKeyfile: process.env.HTTPS_KEY_FILE,
37
- rootFolderPath: tmp.configs.rootFolderPath || 'x',
38
- projectName: tmp.project.name,
39
- serviceName: tmp.configs.service,
40
- projectNamePrefixEnv: process.env.PROJECT_NAME_PREFIX || '',
41
- projectNameEnv: process.env.PROJECT_NAME || '',
42
- projectNameSuffixEnv: process.env.PROJECT_NAME_SUFFIX || '',
43
- systemStaticFolderPath: path.resolve(tmp.configs.rootFolderPath, this.publicFolderName),
44
- systemLoggerLayer: process.env.SYSTEM_LOGGER_LAYER,
45
- isKafkaPassive: process.env.IS_KAFKA_PASSIVE === 'true' ? true : false,
46
- kafkaClientId: tmp.configs.service,
47
- kafkaBrokers: process.env?.KAFKA_BROKERS,
48
- kafkaUsername: process.env?.KAFKA_USERNAME,
49
- kafkaPassword: process.env?.KAFKA_PASSWORD,
50
- kafkaTopics: [
51
- this.kafkaLogsTopic,
52
- ],
53
- kafkaLogsTopic: this.kafkaLogsTopic,
54
- baseApiUri: process.env.HTTPS === 'true' ? process.env.SYSTEM_HTTPS_BASE_API_URI : process.env.SYSTEM_BASE_API_URI,
55
- port: Number(process.env.PORT),
56
- internalSecret: process.env.INTERNAL_SECRET,
57
- secret: process.env.SECRET,
58
- cwd,
59
- env: process.env.NODE_ENV,
60
- };
61
- try {
62
- const moduleData = await modulePromise;
63
- const importedConfigs = moduleData?.default || moduleData?.configs || moduleData || {};
64
- const merged = merge({}, this.#config, importedConfigs || {});
65
- this.#config = Object.freeze(merged);
66
- }
67
- catch (e) {
68
- // error
69
- }
70
- };
71
- setConfig(newConfigs) {
72
- const mergedDObj = Object.assign(this.#config, newConfigs);
73
- this.#config = Object.freeze(mergedDObj);
74
- }
75
- _(key) {
76
- return this.#config[key];
77
- }
78
- get all() {
79
- return this.#config;
80
- }
81
- }
@@ -1,129 +0,0 @@
1
- import { AsyncLocalStorage } from 'node:async_hooks';
2
- import Logger from '../logger';
3
- import System from '../system';
4
- import { IProvide, ProtocolEnum } from '../../utils/index';
5
- export interface CustomRequest<B = any, Q = any, P = any> {
6
- headers: Record<string, any>;
7
- method: string;
8
- url: string;
9
- body: B;
10
- params: P;
11
- query: Q;
12
- cookies: Record<string, any>;
13
- ip: string;
14
- lang: string;
15
- t: (k: string, args?: any) => string;
16
- }
17
- export interface CustomResponse {
18
- status: (code: number) => CustomResponse;
19
- send: (data: any) => any;
20
- json: (data: any) => any;
21
- cookie: (name: string, value: string, options?: any) => CustomResponse;
22
- locals: Record<string, any>;
23
- }
24
- export declare const controllerContextStorage: AsyncLocalStorage<{
25
- protocol?: ProtocolEnum;
26
- ctx?: any;
27
- req?: any;
28
- res?: any;
29
- metadata?: {
30
- locals: Record<string, any>;
31
- _code?: number;
32
- _statusCode?: number;
33
- _contentType?: string;
34
- _isRaw?: boolean;
35
- _parsedBody?: any;
36
- _parsedQuery?: any;
37
- _cookiesToSet?: Record<string, {
38
- value: string;
39
- options?: any;
40
- }>;
41
- };
42
- }>;
43
- export declare const getControllerCtx: () => {
44
- protocol?: ProtocolEnum;
45
- ctx?: any;
46
- req?: any;
47
- res?: any;
48
- metadata?: {
49
- locals: Record<string, any>;
50
- _code?: number;
51
- _statusCode?: number;
52
- _contentType?: string;
53
- _isRaw?: boolean;
54
- _parsedBody?: any;
55
- _parsedQuery?: any;
56
- _cookiesToSet?: Record<string, {
57
- value: string;
58
- options?: any;
59
- }>;
60
- };
61
- };
62
- export declare abstract class BaseController {
63
- protected system: System;
64
- protected logger: Logger;
65
- protected supportedProtocols: ProtocolEnum[];
66
- protected get protocol(): ProtocolEnum;
67
- protected get currentStore(): {
68
- protocol?: ProtocolEnum;
69
- ctx?: any;
70
- req?: any;
71
- res?: any;
72
- metadata?: {
73
- locals: Record<string, any>;
74
- _code?: number;
75
- _statusCode?: number;
76
- _contentType?: string;
77
- _isRaw?: boolean;
78
- _parsedBody?: any;
79
- _parsedQuery?: any;
80
- _cookiesToSet?: Record<string, {
81
- value: string;
82
- options?: any;
83
- }>;
84
- };
85
- };
86
- protected get req(): CustomRequest;
87
- protected get res(): CustomResponse;
88
- }
89
- export default abstract class Controller extends BaseController implements IProvide<any> {
90
- constructor();
91
- onInit(): Promise<void>;
92
- protected parseMessage(msg: any, t: Function, isError?: boolean): string;
93
- schema<B = any, Q = any, P = any>({ checks, logic, response }: {
94
- checks?: (args: {
95
- req: CustomRequest<B, Q, P>;
96
- res: CustomResponse;
97
- body: B;
98
- query: Q;
99
- queries: Q;
100
- params: P;
101
- cookies: Record<string, any>;
102
- locals: Record<string, any>;
103
- t: Function;
104
- }) => Promise<any>;
105
- logic?: (args: {
106
- req: CustomRequest<B, Q, P>;
107
- res: CustomResponse;
108
- body: B;
109
- query: Q;
110
- queries: Q;
111
- params: P;
112
- cookies: Record<string, any>;
113
- locals: Record<string, any>;
114
- t: Function;
115
- }) => Promise<any>;
116
- response?: (args: {
117
- req: CustomRequest<B, Q, P>;
118
- res: CustomResponse;
119
- body: B;
120
- query: Q;
121
- queries: Q;
122
- params: P;
123
- cookies: Record<string, any>;
124
- locals: Record<string, any>;
125
- t: Function;
126
- logicResult: any;
127
- }) => Promise<any>;
128
- }): Promise<any>;
129
- }