@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
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import winston, { format } from "winston";
|
|
2
|
-
import Transport from "winston-transport";
|
|
3
|
-
import "winston-daily-rotate-file";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
6
|
-
import { Partitioners } from "kafkajs";
|
|
7
|
-
import { LoggerLayerEnum } from '../../utils/models/enums/index';
|
|
8
|
-
import { LogDTO } from "../../utils";
|
|
9
|
-
class KafkaTransport extends Transport {
|
|
10
|
-
service;
|
|
11
|
-
constructor(opts, service) {
|
|
12
|
-
super(opts);
|
|
13
|
-
this.service = service;
|
|
14
|
-
}
|
|
15
|
-
log(info, callback) {
|
|
16
|
-
setImmediate(() => this.emit("logged", info));
|
|
17
|
-
this.service["logToKafka"](info).finally(() => callback());
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
const customLevels = {
|
|
21
|
-
critical: LoggerLayerEnum.CRITICAL,
|
|
22
|
-
error: LoggerLayerEnum.ERROR,
|
|
23
|
-
warn: LoggerLayerEnum.WARN,
|
|
24
|
-
info: LoggerLayerEnum.INFO,
|
|
25
|
-
http: LoggerLayerEnum.HTTP,
|
|
26
|
-
debug: LoggerLayerEnum.DEBUG,
|
|
27
|
-
};
|
|
28
|
-
const customColors = {
|
|
29
|
-
critical: "red",
|
|
30
|
-
error: "magenta",
|
|
31
|
-
warn: "yellow",
|
|
32
|
-
info: "green",
|
|
33
|
-
http: "cyan",
|
|
34
|
-
debug: "blue"
|
|
35
|
-
};
|
|
36
|
-
export default class Logger {
|
|
37
|
-
static storage = new AsyncLocalStorage();
|
|
38
|
-
serviceName = "";
|
|
39
|
-
isKafkaReady = false;
|
|
40
|
-
kafkaProducer = null;
|
|
41
|
-
kafkaLogsTopic = "";
|
|
42
|
-
winston;
|
|
43
|
-
#system;
|
|
44
|
-
#configs;
|
|
45
|
-
#kafka;
|
|
46
|
-
constructor({ system, configs, kafkaForCore, }) {
|
|
47
|
-
this.#system = system;
|
|
48
|
-
this.#configs = configs;
|
|
49
|
-
this.#kafka = kafkaForCore;
|
|
50
|
-
}
|
|
51
|
-
onInit = async () => {
|
|
52
|
-
this.serviceName = this.#system?.tmp?.configs?.service;
|
|
53
|
-
this.kafkaLogsTopic = this.#configs?.all?.kafkaLogsTopic;
|
|
54
|
-
winston.addColors(customColors);
|
|
55
|
-
this.winston = winston.createLogger({
|
|
56
|
-
level: this.#configs?.all?.systemLoggerLayer || 'info',
|
|
57
|
-
levels: customLevels,
|
|
58
|
-
format: this.getConsoleFormat(),
|
|
59
|
-
transports: [new winston.transports.Console()]
|
|
60
|
-
});
|
|
61
|
-
const loggersConfigs = this.#system?.tmp?.configs?.loaders?.loggers;
|
|
62
|
-
const { kafkaClientId, kafkaUsername, kafkaPassword, kafkaBrokers, isKafkaPassive } = this.#configs.all;
|
|
63
|
-
const brokers = kafkaBrokers ? String(kafkaBrokers).split(",").map((b) => b.trim()) : [];
|
|
64
|
-
const isKafkaEnabled = isKafkaPassive === false && brokers.length > 0;
|
|
65
|
-
if (isKafkaEnabled) {
|
|
66
|
-
this.kafkaProducer = this.#kafka.instance.producer({
|
|
67
|
-
createPartitioner: Partitioners.DefaultPartitioner,
|
|
68
|
-
retry: { initialRetryTime: 500, retries: 5 }
|
|
69
|
-
});
|
|
70
|
-
try {
|
|
71
|
-
await this.kafkaProducer.connect();
|
|
72
|
-
this.isKafkaReady = true;
|
|
73
|
-
}
|
|
74
|
-
catch (err) {
|
|
75
|
-
this.isKafkaReady = false;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
const logPath = loggersConfigs?.loadPath || "logs";
|
|
79
|
-
const loggerLevel = loggersConfigs?.loggerLevel || "info";
|
|
80
|
-
this.winstonLoader({
|
|
81
|
-
loadPath: path.join(this.#configs.all.rootFolderPath, logPath),
|
|
82
|
-
loggerLevel: loggerLevel
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
winstonLoader = ({ loadPath, loggerLevel }) => {
|
|
86
|
-
const { combine, timestamp, json, errors } = format;
|
|
87
|
-
const tracing = this.getTracingFormat();
|
|
88
|
-
const jsonFileFormat = combine(tracing, timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), errors({ stack: true }), json({ replacer: this.safeReplacer }));
|
|
89
|
-
const transports = [
|
|
90
|
-
new winston.transports.Console({
|
|
91
|
-
format: this.getConsoleFormat()
|
|
92
|
-
}),
|
|
93
|
-
new winston.transports.DailyRotateFile({
|
|
94
|
-
filename: path.resolve(loadPath, "error", "%DATE%_error.log"),
|
|
95
|
-
level: "error",
|
|
96
|
-
format: jsonFileFormat,
|
|
97
|
-
maxSize: "2mb",
|
|
98
|
-
maxFiles: "7d"
|
|
99
|
-
}),
|
|
100
|
-
new winston.transports.DailyRotateFile({
|
|
101
|
-
filename: path.resolve(loadPath, "critical", "%DATE%_critical.log"),
|
|
102
|
-
level: "critical",
|
|
103
|
-
format: jsonFileFormat,
|
|
104
|
-
maxSize: "2mb",
|
|
105
|
-
maxFiles: "14d"
|
|
106
|
-
})
|
|
107
|
-
];
|
|
108
|
-
if (this.isKafkaReady && this.kafkaProducer) {
|
|
109
|
-
transports.push(new KafkaTransport({ level: loggerLevel }, this));
|
|
110
|
-
}
|
|
111
|
-
this.winston = winston.createLogger({
|
|
112
|
-
level: loggerLevel,
|
|
113
|
-
levels: customLevels,
|
|
114
|
-
format: tracing,
|
|
115
|
-
transports
|
|
116
|
-
});
|
|
117
|
-
return this.winston;
|
|
118
|
-
};
|
|
119
|
-
safeReplacer = (key, value) => {
|
|
120
|
-
if (value instanceof Headers)
|
|
121
|
-
return Object.fromEntries(value.entries());
|
|
122
|
-
if (value instanceof Error)
|
|
123
|
-
return { message: value.message, stack: value.stack };
|
|
124
|
-
return value;
|
|
125
|
-
};
|
|
126
|
-
getTracingFormat = format((info) => {
|
|
127
|
-
const store = Logger.storage.getStore();
|
|
128
|
-
if (store && store.has("correlationId")) {
|
|
129
|
-
info.id = store.get("correlationId");
|
|
130
|
-
}
|
|
131
|
-
return info;
|
|
132
|
-
});
|
|
133
|
-
getConsoleFormat() {
|
|
134
|
-
return format.combine(this.getTracingFormat(), format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), format.colorize({ all: true }), format.printf((info) => {
|
|
135
|
-
const msg = typeof info.message === "object"
|
|
136
|
-
? JSON.stringify(info.message, this.safeReplacer)
|
|
137
|
-
: info.message;
|
|
138
|
-
const idPart = info.id ? ` : id: ${info.id}` : "";
|
|
139
|
-
const payloadPart = info.payload ? `\nPayload: ${JSON.stringify(info.payload, this.safeReplacer)}` : "";
|
|
140
|
-
const codePart = info.code ? ` [Code: ${info.code}]` : "";
|
|
141
|
-
return `${info.timestamp} [${this.serviceName}] ${info.level}${codePart}: ${msg}${idPart}${payloadPart}`;
|
|
142
|
-
}));
|
|
143
|
-
}
|
|
144
|
-
runWithId = (id, callback) => {
|
|
145
|
-
const store = new Map();
|
|
146
|
-
store.set("correlationId", id);
|
|
147
|
-
return Logger.storage.run(store, callback);
|
|
148
|
-
};
|
|
149
|
-
async logToKafka(info) {
|
|
150
|
-
if (!this.kafkaProducer || !this.isKafkaReady)
|
|
151
|
-
return;
|
|
152
|
-
try {
|
|
153
|
-
const { id, level, message, payload, code } = info;
|
|
154
|
-
await this.kafkaProducer.send({
|
|
155
|
-
topic: this.kafkaLogsTopic,
|
|
156
|
-
messages: [{
|
|
157
|
-
value: JSON.stringify(LogDTO.getSchema({
|
|
158
|
-
level,
|
|
159
|
-
service: this.serviceName,
|
|
160
|
-
message,
|
|
161
|
-
payload,
|
|
162
|
-
code,
|
|
163
|
-
timestamp: new Date().toISOString(),
|
|
164
|
-
id: id || null,
|
|
165
|
-
env: this.#configs.all.env
|
|
166
|
-
}), this.safeReplacer)
|
|
167
|
-
}],
|
|
168
|
-
acks: 1
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
catch (err) {
|
|
172
|
-
this.isKafkaReady = false;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
log(arg1, arg2, arg3, arg4) {
|
|
176
|
-
const isObj = typeof arg1 === 'object' && arg1 !== null && 'level' in arg1;
|
|
177
|
-
const { level, message, payload, code } = isObj
|
|
178
|
-
? arg1
|
|
179
|
-
: { level: arg1, message: arg2, payload: arg3, code: arg4 };
|
|
180
|
-
const levelKey = typeof level === 'string' ? level.toLowerCase() : LoggerLayerEnum[level].toLowerCase();
|
|
181
|
-
this.winston.log(levelKey, message, { payload, code });
|
|
182
|
-
}
|
|
183
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export default class System {
|
|
2
|
-
_core = {};
|
|
3
|
-
_tmp = {};
|
|
4
|
-
cwd = process.cwd();
|
|
5
|
-
onInit = async ({ core }) => {
|
|
6
|
-
this._core = core;
|
|
7
|
-
this._tmp = this._core._;
|
|
8
|
-
await this._systemLoader({});
|
|
9
|
-
};
|
|
10
|
-
_systemLoader = async ({}) => {
|
|
11
|
-
return;
|
|
12
|
-
};
|
|
13
|
-
get core() {
|
|
14
|
-
return this._core;
|
|
15
|
-
}
|
|
16
|
-
get tmp() {
|
|
17
|
-
return this._tmp;
|
|
18
|
-
}
|
|
19
|
-
}
|
package/source/project/index.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { System, Configs, Logger, Events, Localizations, Clients, Controller, KafkaForCore } from '../loader';
|
|
3
|
-
import { Constants, getCore, x, } from '../utils';
|
|
4
|
-
//
|
|
5
|
-
export const core = getCore();
|
|
6
|
-
export const coreInit = async (params) => {
|
|
7
|
-
const { locales } = params;
|
|
8
|
-
if (locales)
|
|
9
|
-
globalThis.__LOCAL_MESSAGES__ = locales;
|
|
10
|
-
};
|
|
11
|
-
let coreHasRun = false;
|
|
12
|
-
const coreLoader = async ({}) => {
|
|
13
|
-
if (coreHasRun)
|
|
14
|
-
return {};
|
|
15
|
-
try {
|
|
16
|
-
await (await x.load([
|
|
17
|
-
path.join(__dirname, '..', 'loader', '**/*.{ts,js}'),
|
|
18
|
-
], {
|
|
19
|
-
exclude: [
|
|
20
|
-
path.join(__dirname, '..', 'utils', '**/class.x.{ts,js}'),
|
|
21
|
-
]
|
|
22
|
-
}))
|
|
23
|
-
.initialize([
|
|
24
|
-
{
|
|
25
|
-
service: System,
|
|
26
|
-
props: {
|
|
27
|
-
core
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
service: Configs,
|
|
32
|
-
props: {}
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
service: KafkaForCore,
|
|
36
|
-
props: {}
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
service: Logger,
|
|
40
|
-
props: {}
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
service: Events,
|
|
44
|
-
props: {}
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
service: Localizations,
|
|
48
|
-
props: {}
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
service: Controller,
|
|
52
|
-
props: {}
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
service: Clients,
|
|
56
|
-
props: {}
|
|
57
|
-
},
|
|
58
|
-
]);
|
|
59
|
-
coreHasRun = true;
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
63
|
-
console.error(`[${Constants.packageName} core failure]: ${errorMessage}`);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
export default coreLoader;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare class Constants {
|
|
2
|
-
static readonly packageName: string;
|
|
3
|
-
static readonly defaultRootFolderName: string;
|
|
4
|
-
static readonly defaultTmpFileName: string;
|
|
5
|
-
static readonly defaultTmpFileExt = ".yml";
|
|
6
|
-
static readonly defaultTmpFilePath: string;
|
|
7
|
-
static readonly defaultOwnerTmpFilePath: string;
|
|
8
|
-
static readonly publicFolderName = "public";
|
|
9
|
-
static readonly kafkaLogsTopic = "logs";
|
|
10
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
export class Constants {
|
|
3
|
-
static packageName = '@xrystal/core';
|
|
4
|
-
static defaultRootFolderName = 'x';
|
|
5
|
-
static defaultTmpFileName = 'tmp';
|
|
6
|
-
static defaultTmpFileExt = '.yml';
|
|
7
|
-
static defaultTmpFilePath = path.join(__dirname, `../../${Constants.defaultRootFolderName}/${Constants.defaultTmpFileName}.${Constants.defaultTmpFileExt}`);
|
|
8
|
-
static defaultOwnerTmpFilePath = path.join(process.cwd(), `./${Constants.defaultRootFolderName}/${Constants.defaultTmpFileName}.${Constants.defaultTmpFileExt}`);
|
|
9
|
-
static publicFolderName = 'public';
|
|
10
|
-
static kafkaLogsTopic = 'logs';
|
|
11
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const configs = {};
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import Handlebars from 'handlebars';
|
|
4
|
-
import { Constants, ProtocolEnum, TmpFileLoader } from "../../index.js";
|
|
5
|
-
import { controllerContextStorage } from "../../../loader/controller";
|
|
6
|
-
export const getCore = () => {
|
|
7
|
-
const ownerTmpFilePath = findFileRecursively(".", Constants.defaultTmpFileName, Constants.defaultTmpFileExt);
|
|
8
|
-
if (!ownerTmpFilePath) {
|
|
9
|
-
throw new Error(`${Constants.defaultTmpFileName} file not found`);
|
|
10
|
-
}
|
|
11
|
-
const tmpFileObject = getTmpConfig({});
|
|
12
|
-
return {
|
|
13
|
-
_: tmpFileObject
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
export const getTmpConfig = ({ root = process.cwd(), tmpFileName = Constants.defaultTmpFileName, ext = Constants.defaultTmpFileExt }) => {
|
|
17
|
-
const path = findFileRecursively(root, tmpFileName, ext);
|
|
18
|
-
if (!path) {
|
|
19
|
-
throw new Error(`${name}.${ext} file not found`);
|
|
20
|
-
}
|
|
21
|
-
const loader = new TmpFileLoader({ filePath: path });
|
|
22
|
-
return loader.getResolvedTmpFile();
|
|
23
|
-
};
|
|
24
|
-
export function resolveObjWithHandlebars(obj, context) {
|
|
25
|
-
if (typeof obj === "string") {
|
|
26
|
-
const compileResult = Handlebars.compile(obj);
|
|
27
|
-
return compileResult(context);
|
|
28
|
-
}
|
|
29
|
-
else if (typeof obj === "object" && obj !== null) {
|
|
30
|
-
for (const key in obj) {
|
|
31
|
-
obj[key] = resolveObjWithHandlebars(obj[key], context);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return obj;
|
|
35
|
-
}
|
|
36
|
-
export function findFileRecursively(startDir, baseName, extName = '', excludedDirs = ['node_modules', '.git']) {
|
|
37
|
-
if (typeof startDir !== 'string' || !fs.existsSync(startDir)) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
const targetName = baseName + (extName.startsWith('.') ? extName : (extName ? `.${extName}` : ''));
|
|
41
|
-
try {
|
|
42
|
-
const entries = fs.readdirSync(startDir, { withFileTypes: true });
|
|
43
|
-
for (const entry of entries) {
|
|
44
|
-
const fullPath = path.join(startDir, entry.name);
|
|
45
|
-
if (entry.isFile()) {
|
|
46
|
-
if (!extName) {
|
|
47
|
-
const entryExt = path.extname(entry.name);
|
|
48
|
-
const entryBase = path.basename(entry.name, entryExt);
|
|
49
|
-
if (entryBase === baseName) {
|
|
50
|
-
return fullPath;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
if (entry.name === targetName) {
|
|
55
|
-
return fullPath;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
if (entry.isDirectory()) {
|
|
60
|
-
const isHiddenOrExcluded = entry.name.startsWith('.') || excludedDirs.includes(entry.name);
|
|
61
|
-
if (isHiddenOrExcluded) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
const foundPath = findFileRecursively(fullPath, baseName, extName, excludedDirs);
|
|
65
|
-
if (foundPath) {
|
|
66
|
-
return foundPath;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
if (error.code === 'EACCES') {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
export const protocol = async (callback, protocol = ProtocolEnum.HTTP) => {
|
|
80
|
-
const store = controllerContextStorage.getStore();
|
|
81
|
-
if (store) {
|
|
82
|
-
store.protocol = protocol;
|
|
83
|
-
}
|
|
84
|
-
return await callback();
|
|
85
|
-
};
|
|
86
|
-
// => ---
|
|
87
|
-
export const argvsConverter = (argvs) => {
|
|
88
|
-
const reelArgvs = argvs?.slice(2);
|
|
89
|
-
const reelConvertedArgvs = {};
|
|
90
|
-
reelArgvs.forEach((argv) => {
|
|
91
|
-
if (argv.startsWith('--')) {
|
|
92
|
-
console.log(argv);
|
|
93
|
-
const [key, value] = argv.split('=');
|
|
94
|
-
reelConvertedArgvs[key.replace('--', '')] = value || '';
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
return reelConvertedArgvs;
|
|
98
|
-
};
|
|
99
|
-
export const findExt = (filename) => {
|
|
100
|
-
const split = filename.split('.');
|
|
101
|
-
return split[split.length - 1];
|
|
102
|
-
};
|
|
103
|
-
export const changeExtensions = (filename, repalceExt) => {
|
|
104
|
-
return filename.replace(findExt(filename), repalceExt);
|
|
105
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { PolarityTypeEnum } from "../../models";
|
|
2
|
-
export function dateZoneConverter({ polarity, date, zone, factor = 1000 }) {
|
|
3
|
-
let convertedZoneTime = null;
|
|
4
|
-
if (polarity === PolarityTypeEnum.NEGATIVE) {
|
|
5
|
-
convertedZoneTime = date.getTime() - factor * zone;
|
|
6
|
-
}
|
|
7
|
-
else {
|
|
8
|
-
convertedZoneTime = date.getTime() + factor * zone;
|
|
9
|
-
}
|
|
10
|
-
return new Date(convertedZoneTime).toISOString();
|
|
11
|
-
}
|
|
12
|
-
export function convertDate(date, splitCharacter = '/', replaceCharacter = '-') {
|
|
13
|
-
const convertDate = date.split(splitCharacter).map((value, index) => index !== 2 ? replaceCharacter : value);
|
|
14
|
-
return convertDate;
|
|
15
|
-
}
|
|
16
|
-
export function convertTime(time, splitCharacter = ':', replaceCharacter = '-') {
|
|
17
|
-
const convertDate = time.split(splitCharacter).map((value, index) => index !== 2 ? replaceCharacter : value);
|
|
18
|
-
return convertDate;
|
|
19
|
-
}
|
|
20
|
-
export function getDateAndTime({ getDate = true, getTime = true, dateCharacter = '-', timeCharacter = ':', separatorCharacter = '&' }) {
|
|
21
|
-
const date = new Date();
|
|
22
|
-
let formattedDate = '';
|
|
23
|
-
if (!getDate && !getTime) {
|
|
24
|
-
throw new Error("Invalid options! Required one true value");
|
|
25
|
-
}
|
|
26
|
-
if (getDate) {
|
|
27
|
-
const day = date.getDate().toString().padStart(2, '0');
|
|
28
|
-
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
29
|
-
const year = date.getFullYear();
|
|
30
|
-
formattedDate = `${year}${dateCharacter}${month}${dateCharacter}${day}`;
|
|
31
|
-
}
|
|
32
|
-
if (getTime) {
|
|
33
|
-
const hours = date.getHours().toString().padStart(2, '0');
|
|
34
|
-
const minutes = date.getMinutes().toString().padStart(2, '0');
|
|
35
|
-
const seconds = date.getSeconds().toString().padStart(2, '0');
|
|
36
|
-
formattedDate = `${hours}${timeCharacter}${minutes}${timeCharacter}${seconds}`;
|
|
37
|
-
}
|
|
38
|
-
if (getDate && getTime) {
|
|
39
|
-
const day = date.getDate().toString().padStart(2, '0');
|
|
40
|
-
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
41
|
-
const year = date.getFullYear();
|
|
42
|
-
const hours = date.getHours().toString().padStart(2, '0');
|
|
43
|
-
const minutes = date.getMinutes().toString().padStart(2, '0');
|
|
44
|
-
const seconds = date.getSeconds().toString().padStart(2, '0');
|
|
45
|
-
formattedDate = `${year}${dateCharacter}${month}${dateCharacter}${day}${separatorCharacter}${hours}${timeCharacter}${minutes}${timeCharacter}${seconds}`;
|
|
46
|
-
}
|
|
47
|
-
return formattedDate;
|
|
48
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
function mongoFilter(start, end, objPath) {
|
|
2
|
-
const filter = {};
|
|
3
|
-
if (!objPath) {
|
|
4
|
-
throw new Error('MongoFilter helper property is required.');
|
|
5
|
-
}
|
|
6
|
-
filter[objPath] = filter[objPath] || {};
|
|
7
|
-
if (start && end) {
|
|
8
|
-
filter[objPath].$gte = start;
|
|
9
|
-
filter[objPath].$lte = end;
|
|
10
|
-
}
|
|
11
|
-
else if (start) {
|
|
12
|
-
filter[objPath].$gte = start;
|
|
13
|
-
}
|
|
14
|
-
else if (end) {
|
|
15
|
-
filter[objPath].$lte = end;
|
|
16
|
-
}
|
|
17
|
-
return filter;
|
|
18
|
-
}
|
|
19
|
-
function filterUniqueOnce({ arr, key, uniqueOnceValues }) {
|
|
20
|
-
const seen = new Set();
|
|
21
|
-
return arr.filter(item => {
|
|
22
|
-
const val = item[key];
|
|
23
|
-
if (uniqueOnceValues.includes(val)) {
|
|
24
|
-
if (seen.has(val))
|
|
25
|
-
return false;
|
|
26
|
-
seen.add(val);
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
return true;
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
function filterSortByPropOrder({ arr, key, desiredOrder }) {
|
|
33
|
-
const orderMap = new Map();
|
|
34
|
-
desiredOrder.forEach((value, index) => orderMap.set(value, index));
|
|
35
|
-
return [...arr].sort((a, b) => {
|
|
36
|
-
const aIndex = orderMap.get(a[key]) ?? Infinity;
|
|
37
|
-
const bIndex = orderMap.get(b[key]) ?? Infinity;
|
|
38
|
-
return aIndex - bIndex;
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
function filterRemoveItemsByProps({ arr, key, valuesToRemove }) {
|
|
42
|
-
return arr.filter(item => !valuesToRemove.includes(item[key]));
|
|
43
|
-
}
|
|
44
|
-
export { mongoFilter, filterUniqueOnce, filterSortByPropOrder, filterRemoveItemsByProps };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import crypto from 'crypto';
|
|
2
|
-
export function generateSHA256Hash(secret, payload) {
|
|
3
|
-
return crypto
|
|
4
|
-
.createHmac('sha256', secret)
|
|
5
|
-
.update(payload ? payload : '')
|
|
6
|
-
.digest('hex');
|
|
7
|
-
}
|
|
8
|
-
export function generateNumberAndLetter(length = 8) {
|
|
9
|
-
const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
10
|
-
const array = new Uint8Array(length);
|
|
11
|
-
crypto.getRandomValues(array);
|
|
12
|
-
return Array.from(array, byte => charset[byte % charset.length]).join('');
|
|
13
|
-
}
|
|
14
|
-
export function generateCodeChallenge(codeVerifier) {
|
|
15
|
-
return crypto
|
|
16
|
-
.createHash('sha256')
|
|
17
|
-
.update(codeVerifier)
|
|
18
|
-
.digest('base64')
|
|
19
|
-
.replace(/\+/g, '-')
|
|
20
|
-
.replace(/\//g, '_')
|
|
21
|
-
.replace(/=+$/, '');
|
|
22
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import crypto from 'crypto';
|
|
2
|
-
export const serverIdNameGenerator = ({ prefix, payload, suffix }) => {
|
|
3
|
-
return `${prefix}-${payload.toString()}-${suffix}`;
|
|
4
|
-
};
|
|
5
|
-
export function generateRandomKey(options) {
|
|
6
|
-
const { length = 48, format = 'hex', prefix = '', suffix = '', separator = '-', } = options;
|
|
7
|
-
const randomPart = crypto.randomBytes(length).toString(format);
|
|
8
|
-
const parts = [prefix, randomPart, suffix].filter(Boolean);
|
|
9
|
-
return parts.join(separator);
|
|
10
|
-
}
|
|
11
|
-
export function generateReferenceCode(length, prefix = "", middle = "", suffix = "") {
|
|
12
|
-
const totalLength = prefix.length + length + middle.length + suffix.length;
|
|
13
|
-
if (totalLength <= 0) {
|
|
14
|
-
throw new Error("The total length (including prefix, middle, and suffix) must be greater than 0.");
|
|
15
|
-
}
|
|
16
|
-
let referenceCode = "";
|
|
17
|
-
for (let i = 0; i < length; i++) {
|
|
18
|
-
const randomDigit = Math.floor(Math.random() * 10);
|
|
19
|
-
referenceCode += randomDigit.toString();
|
|
20
|
-
}
|
|
21
|
-
const middleIndex = Math.floor(referenceCode.length / 2);
|
|
22
|
-
const referenceWithMiddle = referenceCode.slice(0, middleIndex) + middle + referenceCode.slice(middleIndex);
|
|
23
|
-
return `${prefix}${referenceWithMiddle}${suffix}`;
|
|
24
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export { default as pic } from "picocolors";
|
|
2
|
-
export * from './core/index';
|
|
3
|
-
export * from './path/index';
|
|
4
|
-
export * from './is/index';
|
|
5
|
-
export * from './id/index';
|
|
6
|
-
export * from './validates/index';
|
|
7
|
-
export * from './ip/index';
|
|
8
|
-
export * from './hash/crypto';
|
|
9
|
-
export * from './string/index';
|
|
10
|
-
export * from './objects/index';
|
|
11
|
-
export * from './locales/index';
|
|
12
|
-
export * from './timer/index';
|
|
13
|
-
export * from './date/index';
|
|
14
|
-
export * from './math/index';
|
|
15
|
-
export * from './regex/checkSpecialRegexControl';
|
|
16
|
-
export * from './filters/index';
|
|
17
|
-
export * from './locales/index';
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export { default as pic } from "picocolors";
|
|
2
|
-
export * from './core/index';
|
|
3
|
-
export * from './path/index';
|
|
4
|
-
export * from './is/index';
|
|
5
|
-
export * from './id/index';
|
|
6
|
-
export * from './validates/index';
|
|
7
|
-
export * from './ip/index';
|
|
8
|
-
export * from './hash/crypto';
|
|
9
|
-
export * from './string/index';
|
|
10
|
-
export * from './objects/index';
|
|
11
|
-
export * from './locales/index';
|
|
12
|
-
export * from './timer/index';
|
|
13
|
-
export * from './date/index';
|
|
14
|
-
export * from './math/index';
|
|
15
|
-
export * from './regex/checkSpecialRegexControl';
|
|
16
|
-
export * from './filters/index';
|
|
17
|
-
export * from './locales/index';
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export const getClientIp = (req, ctx = {}) => {
|
|
2
|
-
try {
|
|
3
|
-
const forwarded = req?.headers?.["x-forwarded-for"] || ctx?.headers?.["x-forwarded-for"];
|
|
4
|
-
if (forwarded)
|
|
5
|
-
return forwarded.split(",")[0].trim().replace("::ffff:", "");
|
|
6
|
-
if (ctx?.ip)
|
|
7
|
-
return ctx.ip.replace("::ffff:", "");
|
|
8
|
-
if (req?.ip)
|
|
9
|
-
return req.ip.replace("::ffff:", "");
|
|
10
|
-
const remoteAddr = req?.socket?.remoteAddress ||
|
|
11
|
-
ctx?.req?.socket?.remoteAddress ||
|
|
12
|
-
req?.remoteAddress ||
|
|
13
|
-
ctx?.address;
|
|
14
|
-
if (remoteAddr)
|
|
15
|
-
return remoteAddr.replace("::ffff:", "");
|
|
16
|
-
return "127.0.0.1";
|
|
17
|
-
}
|
|
18
|
-
catch (e) {
|
|
19
|
-
return "127.0.0.1";
|
|
20
|
-
}
|
|
21
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export function isFalsy(value, options) {
|
|
2
|
-
if (!options.ignoreFalse && value === false)
|
|
3
|
-
return true;
|
|
4
|
-
if (!options.ignoreZero && value === 0)
|
|
5
|
-
return true;
|
|
6
|
-
if (!options.ignoreEmptyString && value === '')
|
|
7
|
-
return true;
|
|
8
|
-
if (!options.ignoreNull && value === null)
|
|
9
|
-
return true;
|
|
10
|
-
if (!options.ignoreUndefined && value === undefined)
|
|
11
|
-
return true;
|
|
12
|
-
if (!options.ignoreNaN && typeof value === 'number' && isNaN(value))
|
|
13
|
-
return true;
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
export function isType(data, type) {
|
|
17
|
-
if (typeof data === type) {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
export function isInstance(data, type) {
|
|
25
|
-
if (data instanceof type) {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export function isBcryptHash(value) {
|
|
33
|
-
const bcryptRegex = /^\$2[aby]\$\d{2}\$.{53}$/;
|
|
34
|
-
return bcryptRegex.test(value);
|
|
35
|
-
}
|