@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.
- package/README.md +2331 -21
- package/package.json +66 -24
- package/tsconfig.base.json +15 -0
- package/x/bin/commands/create.mjs +136 -0
- package/x/bin/commands/doctor.mjs +149 -0
- package/x/bin/commands/hooks.mjs +55 -0
- package/x/bin/commands/project.mjs +126 -0
- package/x/bin/commands/release.mjs +66 -0
- package/x/bin/commands/sync-toolchain.mjs +43 -0
- package/x/bin/commands/tmp.mjs +57 -0
- package/x/bin/constants/index.mjs +6 -0
- package/x/bin/helpers/.generated/.generated-from +1 -0
- package/x/bin/helpers/.generated/tmp-schema.mjs +192 -0
- package/x/bin/helpers/banner.mjs +80 -0
- package/x/bin/helpers/build-config.mjs +342 -0
- package/x/bin/helpers/cli-help.mjs +164 -0
- package/x/bin/helpers/cli-identity.mjs +17 -0
- package/x/bin/helpers/create-target.mjs +35 -0
- package/{bin → x/bin}/helpers/index.mjs +44 -1
- package/x/bin/helpers/project-artifacts.mjs +140 -0
- package/x/bin/helpers/project-root.mjs +70 -0
- package/x/bin/helpers/runtime-info.mjs +172 -0
- package/x/bin/helpers/tmp-config.mjs +67 -0
- package/x/bin/helpers/tmp-layout.mjs +281 -0
- package/x/bin/helpers/tmp-schema.mjs +9 -0
- package/x/bin/helpers/toolchain-config.mjs +233 -0
- package/x/bin/main-cli.js +80 -0
- package/x/bin/paths.mjs +14 -0
- package/x/bin/scripts/clean-source-types.mjs +19 -0
- package/x/bin/scripts/fix-dist-imports.mjs +80 -0
- package/x/bin/scripts/install-git-hooks.mjs +86 -0
- package/x/bin/scripts/minify-dist.mjs +50 -0
- package/x/bin/scripts/prepare-npm-publish.mjs +49 -0
- package/x/bin/scripts/release-prepare.mjs +56 -0
- package/x/bin/scripts/tag.mjs +17 -0
- package/x/bin/scripts/unpublish-leaked-versions.mjs +62 -0
- package/x/bin/scripts/verify-npm-pack.mjs +45 -0
- package/x/bin/scripts/verify-version-bump.mjs +27 -0
- package/x/bin/scripts/version-check.mjs +370 -0
- package/x/dist/index.d.ts +3 -0
- package/x/dist/index.js +1 -0
- package/{source → x/dist}/loader/clients/index.d.ts +2 -1
- package/x/dist/loader/clients/index.js +1 -0
- package/{source → x/dist}/loader/configs/index.d.ts +3 -2
- package/x/dist/loader/configs/index.js +1 -0
- package/x/dist/loader/controller/index.d.ts +69 -0
- package/x/dist/loader/controller/index.js +1 -0
- package/x/dist/loader/dto/index.d.ts +39 -0
- package/x/dist/loader/dto/index.js +1 -0
- package/{source → x/dist}/loader/events/index.d.ts +1 -1
- package/x/dist/loader/events/index.js +1 -0
- package/{source → x/dist}/loader/index.d.ts +2 -1
- package/x/dist/loader/index.js +1 -0
- package/{source → x/dist}/loader/kafka/index.d.ts +6 -3
- package/x/dist/loader/kafka/index.js +1 -0
- package/{source → x/dist}/loader/localizations/index.d.ts +4 -3
- package/x/dist/loader/localizations/index.js +1 -0
- package/{source → x/dist}/loader/logger/index.d.ts +10 -7
- package/x/dist/loader/logger/index.js +2 -0
- package/x/dist/loader/service/index.js +1 -0
- package/{source → x/dist}/loader/system/index.d.ts +4 -3
- package/x/dist/loader/system/index.js +1 -0
- package/{source → x/dist}/project/index.d.ts +2 -2
- package/x/dist/project/index.js +1 -0
- package/x/dist/utils/constants/defaults.json +44 -0
- package/x/dist/utils/constants/index.d.ts +27 -0
- package/x/dist/utils/constants/index.js +1 -0
- package/x/dist/utils/helpers/configs/index.js +1 -0
- package/x/dist/utils/helpers/context/controller-store.d.ts +51 -0
- package/x/dist/utils/helpers/context/controller-store.js +1 -0
- package/x/dist/utils/helpers/context/index.d.ts +18 -0
- package/x/dist/utils/helpers/context/index.js +1 -0
- package/{source → x/dist}/utils/helpers/core/index.d.ts +8 -6
- package/x/dist/utils/helpers/core/index.js +1 -0
- package/x/dist/utils/helpers/core/paths.d.ts +2 -0
- package/x/dist/utils/helpers/core/paths.js +1 -0
- package/x/dist/utils/helpers/core/tmp-layout.d.ts +45 -0
- package/x/dist/utils/helpers/core/tmp-layout.js +1 -0
- package/{source → x/dist}/utils/helpers/date/index.d.ts +1 -1
- package/x/dist/utils/helpers/date/index.js +1 -0
- package/x/dist/utils/helpers/dispatch/index.d.ts +9 -0
- package/x/dist/utils/helpers/dispatch/index.js +1 -0
- package/x/dist/utils/helpers/dto/index.d.ts +10 -0
- package/x/dist/utils/helpers/dto/index.js +1 -0
- package/x/dist/utils/helpers/filters/index.js +1 -0
- package/x/dist/utils/helpers/framework/index.d.ts +3 -0
- package/x/dist/utils/helpers/framework/index.js +1 -0
- package/x/dist/utils/helpers/handlers/adapters.d.ts +10 -0
- package/x/dist/utils/helpers/handlers/adapters.js +1 -0
- package/x/dist/utils/helpers/handlers/execute.d.ts +5 -0
- package/x/dist/utils/helpers/handlers/execute.js +1 -0
- package/x/dist/utils/helpers/handlers/index.d.ts +18 -0
- package/x/dist/utils/helpers/handlers/index.js +1 -0
- package/x/dist/utils/helpers/hash/crypto.js +1 -0
- package/x/dist/utils/helpers/id/index.js +1 -0
- package/x/dist/utils/helpers/index.d.ts +26 -0
- package/x/dist/utils/helpers/index.js +1 -0
- package/x/dist/utils/helpers/ip/index.js +1 -0
- package/x/dist/utils/helpers/is/index.js +1 -0
- package/{source → x/dist}/utils/helpers/locales/index.d.ts +1 -0
- package/x/dist/utils/helpers/locales/index.js +1 -0
- package/x/dist/utils/helpers/math/index.js +1 -0
- package/x/dist/utils/helpers/middleware/index.d.ts +19 -0
- package/x/dist/utils/helpers/middleware/index.js +1 -0
- package/x/dist/utils/helpers/objects/index.js +1 -0
- package/x/dist/utils/helpers/path/index.js +1 -0
- package/x/dist/utils/helpers/protocol/index.d.ts +20 -0
- package/x/dist/utils/helpers/protocol/index.js +1 -0
- package/x/dist/utils/helpers/protocol/options.d.ts +6 -0
- package/x/dist/utils/helpers/protocol/options.js +1 -0
- package/x/dist/utils/helpers/regex/checkSpecialRegexControl.js +1 -0
- package/x/dist/utils/helpers/runtime/dto-access.d.ts +3 -0
- package/x/dist/utils/helpers/runtime/dto-access.js +1 -0
- package/x/dist/utils/helpers/runtime/dto-types.d.ts +19 -0
- package/x/dist/utils/helpers/runtime/dto-types.js +1 -0
- package/x/dist/utils/helpers/runtime/index.d.ts +3 -0
- package/x/dist/utils/helpers/runtime/index.js +1 -0
- package/x/dist/utils/helpers/runtime/shutdown.d.ts +3 -0
- package/x/dist/utils/helpers/runtime/shutdown.js +1 -0
- package/x/dist/utils/helpers/state/index.d.ts +59 -0
- package/x/dist/utils/helpers/state/index.js +1 -0
- package/x/dist/utils/helpers/state/props-from-tmp.d.ts +9 -0
- package/x/dist/utils/helpers/state/props-from-tmp.js +1 -0
- package/x/dist/utils/helpers/state/request-key-guard.d.ts +3 -0
- package/x/dist/utils/helpers/state/request-key-guard.js +1 -0
- package/x/dist/utils/helpers/state/scopes.d.ts +21 -0
- package/x/dist/utils/helpers/state/scopes.js +1 -0
- package/x/dist/utils/helpers/string/index.js +1 -0
- package/x/dist/utils/helpers/tests/tmp-schema.test.js +1 -0
- package/{source/utils/models/types/index.js → x/dist/utils/helpers/tests/tmp-watch.test.d.ts} +0 -1
- package/x/dist/utils/helpers/tests/tmp-watch.test.js +1 -0
- package/x/dist/utils/helpers/timer/index.js +1 -0
- package/x/dist/utils/helpers/tmp/index.d.ts +5 -0
- package/x/dist/utils/helpers/tmp/index.js +1 -0
- package/x/dist/utils/helpers/tmp/loader-tmp-sync.d.ts +4 -0
- package/x/dist/utils/helpers/tmp/loader-tmp-sync.js +1 -0
- package/x/dist/utils/helpers/tmp/runtime-tmp.d.ts +9 -0
- package/x/dist/utils/helpers/tmp/runtime-tmp.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-loader.d.ts +7 -0
- package/x/dist/utils/helpers/tmp/tmp-loader.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +47 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-watch.d.ts +1 -0
- package/x/dist/utils/helpers/tmp/tmp-watch.js +1 -0
- package/x/dist/utils/helpers/validates/index.js +1 -0
- package/x/dist/utils/index.d.ts +3 -0
- package/x/dist/utils/index.js +1 -0
- package/x/dist/utils/models/classes/class.clients.js +1 -0
- package/x/dist/utils/models/classes/class.interfaces.js +1 -0
- package/x/dist/utils/models/classes/class.service-locator.js +1 -0
- package/{source → x/dist}/utils/models/classes/class.tmp-file-loader.d.ts +3 -2
- package/x/dist/utils/models/classes/class.tmp-file-loader.js +1 -0
- package/x/dist/utils/models/classes/class.x.js +1 -0
- package/{source → x/dist}/utils/models/enums/index.d.ts +14 -1
- package/x/dist/utils/models/enums/index.js +1 -0
- package/x/dist/utils/models/index.d.ts +9 -0
- package/x/dist/utils/models/index.js +1 -0
- package/x/dist/utils/models/types/index.d.ts +5 -0
- package/x/dist/utils/models/types/index.js +1 -0
- package/x/dist/utils/package-root.d.ts +2 -0
- package/x/dist/utils/package-root.js +1 -0
- package/x/tmp.yml +48 -17
- package/bin/constants/index.mjs +0 -17
- package/bin/main-cli.js +0 -131
- package/source/index.js +0 -6
- package/source/loader/clients/index.js +0 -18
- package/source/loader/configs/index.js +0 -81
- package/source/loader/controller/index.d.ts +0 -129
- package/source/loader/controller/index.js +0 -327
- package/source/loader/events/index.js +0 -44
- package/source/loader/index.js +0 -10
- package/source/loader/kafka/index.js +0 -122
- package/source/loader/localizations/index.js +0 -40
- package/source/loader/logger/index.js +0 -183
- package/source/loader/service/index.js +0 -7
- package/source/loader/system/index.js +0 -19
- package/source/project/index.js +0 -66
- package/source/utils/constants/index.d.ts +0 -10
- package/source/utils/constants/index.js +0 -11
- package/source/utils/helpers/configs/index.js +0 -1
- package/source/utils/helpers/core/index.js +0 -105
- package/source/utils/helpers/date/index.js +0 -48
- package/source/utils/helpers/filters/index.js +0 -44
- package/source/utils/helpers/hash/crypto.js +0 -22
- package/source/utils/helpers/id/index.js +0 -24
- package/source/utils/helpers/index.d.ts +0 -17
- package/source/utils/helpers/index.js +0 -17
- package/source/utils/helpers/ip/index.js +0 -21
- package/source/utils/helpers/is/index.js +0 -35
- package/source/utils/helpers/locales/index.js +0 -63
- package/source/utils/helpers/math/index.js +0 -14
- package/source/utils/helpers/middlewares/index.d.ts +0 -1
- package/source/utils/helpers/middlewares/index.js +0 -26
- package/source/utils/helpers/objects/index.js +0 -55
- package/source/utils/helpers/path/index.js +0 -4
- package/source/utils/helpers/regex/checkSpecialRegexControl.js +0 -3
- package/source/utils/helpers/string/index.js +0 -9
- package/source/utils/helpers/timer/index.js +0 -5
- package/source/utils/helpers/validates/index.js +0 -20
- package/source/utils/index.d.ts +0 -3
- package/source/utils/index.js +0 -3
- package/source/utils/models/classes/class.clients.js +0 -142
- package/source/utils/models/classes/class.dtos.d.ts +0 -47
- package/source/utils/models/classes/class.dtos.js +0 -36
- package/source/utils/models/classes/class.interfaces.js +0 -10
- package/source/utils/models/classes/class.response.d.ts +0 -17
- package/source/utils/models/classes/class.response.js +0 -35
- package/source/utils/models/classes/class.service-locator.js +0 -16
- package/source/utils/models/classes/class.tmp-file-loader.js +0 -38
- package/source/utils/models/classes/class.x.js +0 -179
- package/source/utils/models/enums/index.js +0 -133
- package/source/utils/models/index.d.ts +0 -11
- package/source/utils/models/index.js +0 -11
- package/source/utils/models/types/index.d.ts +0 -3
- /package/{source → x/dist}/loader/service/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/configs/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/filters/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/hash/crypto.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/id/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/ip/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/is/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/math/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/objects/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/path/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/regex/checkSpecialRegexControl.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/string/index.d.ts +0 -0
- /package/{source/index.d.ts → x/dist/utils/helpers/tests/tmp-schema.test.d.ts} +0 -0
- /package/{source → x/dist}/utils/helpers/timer/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/validates/index.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.clients.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.interfaces.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.service-locator.d.ts +0 -0
- /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,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
|
-
}
|