@xrystal/core 3.55.6 → 3.55.7
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/package.json +1 -1
- package/x/bin/helpers/.generated/tmp-schema.mjs +9 -0
- package/x/dist/loader/configs/index.js +16 -6
- package/x/dist/loader/events/index.d.ts +1 -0
- package/x/dist/loader/events/index.js +11 -2
- package/x/dist/loader/localizations/index.js +2 -1
- package/x/dist/loader/logger/index.js +3 -2
- package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +1 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.js +8 -0
- package/x/dist/utils/models/classes/class.x.js +2 -2
package/package.json
CHANGED
|
@@ -362,6 +362,14 @@ function readTmpDependsBlock(configs) {
|
|
|
362
362
|
loaders
|
|
363
363
|
};
|
|
364
364
|
}
|
|
365
|
+
function resolveTmpLoaders(configs) {
|
|
366
|
+
const dependsLoaders = readTmpDependsBlock(configs).loaders;
|
|
367
|
+
if (dependsLoaders)
|
|
368
|
+
return dependsLoaders;
|
|
369
|
+
const service = isRecord2(configs?.service) ? configs.service : {};
|
|
370
|
+
const legacy = isRecord2(service.loaders) ? service.loaders : {};
|
|
371
|
+
return { ...legacy };
|
|
372
|
+
}
|
|
365
373
|
function resolveTmpDeploymentName(tmp) {
|
|
366
374
|
assertNoLegacyTmpKeys(isRecord2(tmp?.configs) ? tmp.configs : undefined);
|
|
367
375
|
const project = isRecord2(tmp?.project) ? tmp.project : {};
|
|
@@ -434,6 +442,7 @@ function resolveTmpAbsPath(projectRoot, configs) {
|
|
|
434
442
|
}
|
|
435
443
|
export {
|
|
436
444
|
resolveTmpRuntimeConfigs,
|
|
445
|
+
resolveTmpLoaders,
|
|
437
446
|
resolveTmpDeploymentName,
|
|
438
447
|
resolveTmpAbsPath,
|
|
439
448
|
resolveProjectRootFromTmpPath,
|
|
@@ -6,6 +6,7 @@ import { resolveTmpLoadPath } from '../../utils/helpers/path/resolve-alias-path.
|
|
|
6
6
|
import { bindLoaderTmpSync } from '../../utils/helpers/tmp/loader-tmp-sync.js';
|
|
7
7
|
import { normalizeNodeEnv } from '../../utils/helpers/node-env/index.js';
|
|
8
8
|
import { readKafkaLoaderOptions } from '../../utils/helpers/kafka-loader-options/index.js';
|
|
9
|
+
import { resolveTmpLoaders } from '../../utils/helpers/tmp/tmp-schema.js';
|
|
9
10
|
export default class Configs {
|
|
10
11
|
publicFolderName = Constants.publicFolderName;
|
|
11
12
|
kafkaLogsTopic = Constants.kafkaLogsTopic;
|
|
@@ -27,7 +28,16 @@ export default class Configs {
|
|
|
27
28
|
syncFromTmp = async () => {
|
|
28
29
|
const cwd = process.cwd();
|
|
29
30
|
const tmp = this.#system.tmp;
|
|
30
|
-
const
|
|
31
|
+
const runtimeConfigs = tmp.configs;
|
|
32
|
+
const rootFolderPath = runtimeConfigs.rootFolderPath ?? 'x';
|
|
33
|
+
const deploymentName = runtimeConfigs.deploymentName
|
|
34
|
+
?? (typeof tmp.project?.name === 'string' ? tmp.project.name : '')
|
|
35
|
+
?? '';
|
|
36
|
+
const loaders = resolveTmpLoaders(tmp.configs);
|
|
37
|
+
const extendConfigs = loaders.configs?.loadPath;
|
|
38
|
+
if (!extendConfigs) {
|
|
39
|
+
throw new Error(`${Constants.packageName}: configs.depends.loaders.configs.loadPath is required in tmp.yml`);
|
|
40
|
+
}
|
|
31
41
|
const fullPath = resolveTmpLoadPath(extendConfigs, tmp, cwd);
|
|
32
42
|
const fileUrl = pathToFileURL(fullPath).href;
|
|
33
43
|
const modulePromise = import(fileUrl);
|
|
@@ -40,16 +50,16 @@ export default class Configs {
|
|
|
40
50
|
httpsfileEncoding: process.env.ENCODING || 'utf8',
|
|
41
51
|
httpsCertfile: process.env.HTTPS_CERT_FILE ?? '',
|
|
42
52
|
httpsKeyfile: process.env.HTTPS_KEY_FILE ?? '',
|
|
43
|
-
rootFolderPath
|
|
53
|
+
rootFolderPath,
|
|
44
54
|
projectName: tmp.project.name,
|
|
45
|
-
serviceName:
|
|
55
|
+
serviceName: deploymentName,
|
|
46
56
|
projectNamePrefixEnv: process.env.PROJECT_NAME_PREFIX || '',
|
|
47
57
|
projectNameEnv: process.env.PROJECT_NAME || '',
|
|
48
58
|
projectNameSuffixEnv: process.env.PROJECT_NAME_SUFFIX || '',
|
|
49
|
-
systemStaticFolderPath: path.resolve(
|
|
59
|
+
systemStaticFolderPath: path.resolve(rootFolderPath, this.publicFolderName),
|
|
50
60
|
systemLoggerLayer: process.env.SYSTEM_LOGGER_LAYER ?? 'info',
|
|
51
|
-
isKafkaPassive: !readKafkaLoaderOptions(
|
|
52
|
-
kafkaClientId:
|
|
61
|
+
isKafkaPassive: !readKafkaLoaderOptions(loaders).enabled,
|
|
62
|
+
kafkaClientId: deploymentName,
|
|
53
63
|
kafkaBrokers: process.env.KAFKA_BROKERS ?? '',
|
|
54
64
|
kafkaUsername: process.env.KAFKA_USERNAME ?? '',
|
|
55
65
|
kafkaPassword: process.env.KAFKA_PASSWORD ?? '',
|
|
@@ -8,9 +8,18 @@ export default class Events {
|
|
|
8
8
|
this._globalLoader();
|
|
9
9
|
this._DILoader();
|
|
10
10
|
};
|
|
11
|
+
safeLog(params) {
|
|
12
|
+
try {
|
|
13
|
+
this.#logger.log(params);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
const msg = params?.message ?? 'unknown';
|
|
17
|
+
console.error('[events]', msg, params?.payload, error);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
11
20
|
_globalLoader = () => {
|
|
12
21
|
process.on("uncaughtException", (error, origin) => {
|
|
13
|
-
this
|
|
22
|
+
this.safeLog({
|
|
14
23
|
level: LoggerLayerEnum.CRITICAL,
|
|
15
24
|
message: `Uncaught Exception: ${error.message}`,
|
|
16
25
|
payload: {
|
|
@@ -21,7 +30,7 @@ export default class Events {
|
|
|
21
30
|
});
|
|
22
31
|
process.on("unhandledRejection", (reason, promise) => {
|
|
23
32
|
const error = reason instanceof Error ? reason : new Error(String(reason));
|
|
24
|
-
this
|
|
33
|
+
this.safeLog({
|
|
25
34
|
level: LoggerLayerEnum.CRITICAL,
|
|
26
35
|
message: `Unhandled Rejection: ${error.message}`,
|
|
27
36
|
payload: {
|
|
@@ -3,6 +3,7 @@ import i18next from "i18next";
|
|
|
3
3
|
import Backend from 'i18next-fs-backend';
|
|
4
4
|
import * as middleware from 'i18next-http-middleware';
|
|
5
5
|
import { bindLoaderTmpSync } from '../../utils/index.js';
|
|
6
|
+
import { resolveTmpLoaders } from '../../utils/helpers/tmp/tmp-schema.js';
|
|
6
7
|
export default class Localizations {
|
|
7
8
|
_instance = null;
|
|
8
9
|
#system;
|
|
@@ -17,7 +18,7 @@ export default class Localizations {
|
|
|
17
18
|
};
|
|
18
19
|
syncFromTmp = async () => {
|
|
19
20
|
this._instance = null;
|
|
20
|
-
const localization = this.#system.tmp.configs.
|
|
21
|
+
const localization = resolveTmpLoaders(this.#system.tmp.configs).localization;
|
|
21
22
|
this.i18next({
|
|
22
23
|
loadPath: path.join(this.#system.tmp.configs.rootFolderPath, localization.loadPath),
|
|
23
24
|
fallbackLang: localization.fallbackLang,
|
|
@@ -4,6 +4,7 @@ import "winston-daily-rotate-file";
|
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { Partitioners } from "kafkajs";
|
|
6
6
|
import { LoggerLayerEnum } from '../../utils/index.js';
|
|
7
|
+
import { normalizeNodeEnv } from '../../utils/helpers/node-env/index.js';
|
|
7
8
|
import { loggerLayerName, meetsLoggerLayerThreshold, normalizeLoggerLayer, } from '../../utils/helpers/logger-layer/index.js';
|
|
8
9
|
import { readKafkaLoaderOptions } from '../../utils/helpers/kafka-loader-options/index.js';
|
|
9
10
|
import { LogDTO } from "../../utils/index.js";
|
|
@@ -66,7 +67,7 @@ export default class Logger {
|
|
|
66
67
|
this.kafkaLogsTopic = this.#configs?.all?.kafkaLogsTopic;
|
|
67
68
|
winston.addColors(customColors);
|
|
68
69
|
const loggersConfigs = (loaders?.loggers ?? {});
|
|
69
|
-
const { kafkaBrokers } = this.#configs
|
|
70
|
+
const { kafkaBrokers } = this.#configs?.all ?? {};
|
|
70
71
|
const brokers = kafkaBrokers ? String(kafkaBrokers).split(',').map((b) => b.trim()) : [];
|
|
71
72
|
const kafkaOpts = readKafkaLoaderOptions(loaders);
|
|
72
73
|
const isKafkaLogEnabled = kafkaOpts.enabled && kafkaOpts.queueLogEnabled && brokers.length > 0;
|
|
@@ -184,7 +185,7 @@ export default class Logger {
|
|
|
184
185
|
code: params.code,
|
|
185
186
|
timestamp: params.timestamp ?? new Date().toISOString(),
|
|
186
187
|
id: params.id ?? getRequestId() ?? undefined,
|
|
187
|
-
env: this.#configs
|
|
188
|
+
env: (this.#configs?.all?.env ?? normalizeNodeEnv(process.env.NODE_ENV)),
|
|
188
189
|
}).build();
|
|
189
190
|
}
|
|
190
191
|
async logToKafka(info) {
|
|
@@ -59,6 +59,7 @@ export declare function assertNoLegacyTmpKeys(configs?: Record<string, unknown>)
|
|
|
59
59
|
/** Build options from configs.global.build only. */
|
|
60
60
|
export declare function readTmpBuildBlock(configs?: Record<string, unknown>): TmpBuildBlock;
|
|
61
61
|
export declare function readTmpDependsBlock(configs?: Record<string, unknown>): TmpDependsBlock;
|
|
62
|
+
export declare function resolveTmpLoaders(configs?: Record<string, unknown>): Record<string, unknown>;
|
|
62
63
|
export declare function resolveTmpDeploymentName(tmp?: Record<string, unknown> | null): string | undefined;
|
|
63
64
|
export declare function buildTmpVarContext(global: TmpGlobalBlock): Record<string, unknown>;
|
|
64
65
|
export declare function applyTmpGlobalVars(tmp: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -170,6 +170,14 @@ export function readTmpDependsBlock(configs) {
|
|
|
170
170
|
loaders,
|
|
171
171
|
};
|
|
172
172
|
}
|
|
173
|
+
export function resolveTmpLoaders(configs) {
|
|
174
|
+
const dependsLoaders = readTmpDependsBlock(configs).loaders;
|
|
175
|
+
if (dependsLoaders)
|
|
176
|
+
return dependsLoaders;
|
|
177
|
+
const service = isRecord(configs?.service) ? configs.service : {};
|
|
178
|
+
const legacy = isRecord(service.loaders) ? service.loaders : {};
|
|
179
|
+
return { ...legacy };
|
|
180
|
+
}
|
|
173
181
|
export function resolveTmpDeploymentName(tmp) {
|
|
174
182
|
assertNoLegacyTmpKeys(isRecord(tmp?.configs) ? tmp.configs : undefined);
|
|
175
183
|
const project = isRecord(tmp?.project) ? tmp.project : {};
|
|
@@ -113,8 +113,8 @@ class DIM extends X {
|
|
|
113
113
|
this.initializedNames.add(name);
|
|
114
114
|
}
|
|
115
115
|
catch (err) {
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
console.error(`[DI] Priority onInit Failed (${name}):`, err.message);
|
|
117
|
+
throw err;
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
const allKeys = Object.keys(this.container.registrations);
|