@navios/core 0.1.0 → 0.1.2
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/dist/index.d.mts +485 -11
- package/dist/index.d.ts +485 -11
- package/dist/index.js +1028 -136
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +993 -135
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/config/config-service.interface.mts +16 -0
- package/src/config/config.provider.mts +63 -0
- package/src/config/config.service.mts +69 -0
- package/src/config/index.mts +5 -0
- package/src/config/types.mts +58 -0
- package/src/config/utils/helpers.mts +23 -0
- package/src/config/utils/index.mts +1 -0
- package/src/index.mts +2 -0
- package/src/logger/README.md +3 -0
- package/src/logger/console-logger.service.mts +588 -0
- package/src/logger/index.mts +7 -0
- package/src/logger/log-levels.mts +12 -0
- package/src/logger/logger-service.interface.mts +42 -0
- package/src/logger/logger.factory.mts +37 -0
- package/src/logger/logger.service.mts +214 -0
- package/src/logger/pino-wrapper.mts +63 -0
- package/src/logger/utils/cli-colors.util.mts +17 -0
- package/src/logger/utils/filter-log-levelts.util.mts +29 -0
- package/src/logger/utils/index.mts +5 -0
- package/src/logger/utils/is-log-level-enabled.mts +33 -0
- package/src/logger/utils/is-log-level.util.mts +10 -0
- package/src/logger/utils/shared.utils.mts +51 -0
- package/src/navios.application.mts +71 -18
- package/src/navios.factory.mts +18 -1
- package/src/service-locator/inject.mts +6 -1
- package/src/service-locator/injection-token.mts +11 -6
- package/src/service-locator/proxy-service-locator.mts +28 -9
- package/src/service-locator/service-locator.mts +53 -16
- package/src/service-locator/sync-injector.mts +6 -1
- package/src/services/controller-adapter.service.mts +8 -0
- package/src/services/module-loader.service.mts +6 -1
package/dist/index.js
CHANGED
|
@@ -77,7 +77,13 @@ __export(src_exports, {
|
|
|
77
77
|
Application: () => Application,
|
|
78
78
|
AttributeFactory: () => AttributeFactory,
|
|
79
79
|
BadRequestException: () => BadRequestException,
|
|
80
|
+
ConfigProvider: () => ConfigProvider,
|
|
81
|
+
ConfigProviderFactory: () => ConfigProviderFactory,
|
|
82
|
+
ConfigProviderInjectionToken: () => ConfigProviderInjectionToken,
|
|
83
|
+
ConfigProviderOptions: () => ConfigProviderOptions,
|
|
84
|
+
ConfigServiceInstance: () => ConfigServiceInstance,
|
|
80
85
|
ConflictException: () => ConflictException,
|
|
86
|
+
ConsoleLogger: () => ConsoleLogger,
|
|
81
87
|
Controller: () => Controller,
|
|
82
88
|
ControllerAdapterService: () => ControllerAdapterService,
|
|
83
89
|
ControllerMetadataKey: () => ControllerMetadataKey,
|
|
@@ -101,12 +107,19 @@ __export(src_exports, {
|
|
|
101
107
|
InstanceExpired: () => InstanceExpired,
|
|
102
108
|
InstanceNotFound: () => InstanceNotFound,
|
|
103
109
|
InternalServerErrorException: () => InternalServerErrorException,
|
|
110
|
+
LOG_LEVELS: () => LOG_LEVELS,
|
|
111
|
+
Logger: () => Logger,
|
|
112
|
+
LoggerFactory: () => LoggerFactory,
|
|
113
|
+
LoggerInjectionToken: () => LoggerInjectionToken,
|
|
114
|
+
LoggerInstance: () => LoggerInstance,
|
|
115
|
+
LoggerOptions: () => LoggerOptions,
|
|
104
116
|
Module: () => Module,
|
|
105
117
|
ModuleLoaderService: () => ModuleLoaderService,
|
|
106
118
|
ModuleMetadataKey: () => ModuleMetadataKey,
|
|
107
119
|
NaviosApplication: () => NaviosApplication,
|
|
108
120
|
NaviosFactory: () => NaviosFactory,
|
|
109
121
|
NotFoundException: () => NotFoundException,
|
|
122
|
+
PinoWrapper: () => PinoWrapper,
|
|
110
123
|
Reply: () => Reply,
|
|
111
124
|
Request: () => Request,
|
|
112
125
|
ServiceLocator: () => ServiceLocator,
|
|
@@ -117,8 +130,13 @@ __export(src_exports, {
|
|
|
117
130
|
UnauthorizedException: () => UnauthorizedException,
|
|
118
131
|
UnknownError: () => UnknownError,
|
|
119
132
|
UseGuards: () => UseGuards,
|
|
133
|
+
addLeadingSlash: () => addLeadingSlash,
|
|
134
|
+
clc: () => clc,
|
|
135
|
+
envInt: () => envInt,
|
|
136
|
+
envString: () => envString,
|
|
120
137
|
extractControllerMetadata: () => extractControllerMetadata,
|
|
121
138
|
extractModuleMetadata: () => extractModuleMetadata,
|
|
139
|
+
filterLogLevels: () => filterLogLevels,
|
|
122
140
|
getAllEndpointMetadata: () => getAllEndpointMetadata,
|
|
123
141
|
getControllerMetadata: () => getControllerMetadata,
|
|
124
142
|
getEndpointMetadata: () => getEndpointMetadata,
|
|
@@ -128,122 +146,140 @@ __export(src_exports, {
|
|
|
128
146
|
hasControllerMetadata: () => hasControllerMetadata,
|
|
129
147
|
hasModuleMetadata: () => hasModuleMetadata,
|
|
130
148
|
inject: () => inject,
|
|
149
|
+
isConstructor: () => isConstructor,
|
|
150
|
+
isEmpty: () => isEmpty,
|
|
151
|
+
isFunction: () => isFunction,
|
|
152
|
+
isLogLevel: () => isLogLevel,
|
|
153
|
+
isLogLevelEnabled: () => isLogLevelEnabled,
|
|
154
|
+
isNil: () => isNil,
|
|
155
|
+
isNumber: () => isNumber,
|
|
156
|
+
isObject: () => isObject,
|
|
157
|
+
isPlainObject: () => isPlainObject,
|
|
158
|
+
isString: () => isString,
|
|
159
|
+
isSymbol: () => isSymbol,
|
|
160
|
+
isUndefined: () => isUndefined,
|
|
161
|
+
makeConfigToken: () => makeConfigToken,
|
|
162
|
+
normalizePath: () => normalizePath,
|
|
131
163
|
override: () => override,
|
|
132
164
|
provideServiceLocator: () => provideServiceLocator,
|
|
133
165
|
setPromiseCollector: () => setPromiseCollector,
|
|
134
|
-
|
|
166
|
+
stripEndSlash: () => stripEndSlash,
|
|
167
|
+
syncInject: () => syncInject,
|
|
168
|
+
yellow: () => yellow
|
|
135
169
|
});
|
|
136
170
|
module.exports = __toCommonJS(src_exports);
|
|
137
171
|
|
|
138
|
-
// packages/core/src/
|
|
139
|
-
var
|
|
140
|
-
function
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (metadata) {
|
|
144
|
-
return metadata;
|
|
145
|
-
} else {
|
|
146
|
-
context.metadata[EndpointMetadataKey] = /* @__PURE__ */ new Set();
|
|
147
|
-
return context.metadata[EndpointMetadataKey];
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
throw new Error("[Navios] Wrong environment.");
|
|
172
|
+
// packages/core/src/config/utils/helpers.mts
|
|
173
|
+
var import_node_process = require("process");
|
|
174
|
+
function envInt(key, defaultValue) {
|
|
175
|
+
const envKey = import_node_process.env[key] || process.env[key];
|
|
176
|
+
return envKey ? parseInt(envKey, 10) : defaultValue;
|
|
151
177
|
}
|
|
152
|
-
function
|
|
153
|
-
|
|
154
|
-
const metadata = getAllEndpointMetadata(context);
|
|
155
|
-
if (metadata) {
|
|
156
|
-
const endpointMetadata = Array.from(metadata).find(
|
|
157
|
-
(item) => item.classMethod === target.name
|
|
158
|
-
);
|
|
159
|
-
if (endpointMetadata) {
|
|
160
|
-
return endpointMetadata;
|
|
161
|
-
} else {
|
|
162
|
-
const newMetadata = {
|
|
163
|
-
classMethod: target.name,
|
|
164
|
-
url: "",
|
|
165
|
-
httpMethod: "GET",
|
|
166
|
-
config: null,
|
|
167
|
-
guards: /* @__PURE__ */ new Set(),
|
|
168
|
-
customAttributes: /* @__PURE__ */ new Map()
|
|
169
|
-
};
|
|
170
|
-
metadata.add(newMetadata);
|
|
171
|
-
return newMetadata;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
throw new Error("[Navios] Wrong environment.");
|
|
178
|
+
function envString(key, defaultValue) {
|
|
179
|
+
return import_node_process.env[key] || process.env[key] || defaultValue || void 0;
|
|
176
180
|
}
|
|
177
181
|
|
|
178
|
-
// packages/core/src/
|
|
179
|
-
var
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
182
|
+
// packages/core/src/config/config.provider.mts
|
|
183
|
+
var import_zod3 = require("zod");
|
|
184
|
+
|
|
185
|
+
// packages/core/src/logger/utils/cli-colors.util.mts
|
|
186
|
+
var isColorAllowed = () => !process.env.NO_COLOR;
|
|
187
|
+
var colorIfAllowed = (colorFn) => (text) => isColorAllowed() ? colorFn(text) : text;
|
|
188
|
+
var clc = {
|
|
189
|
+
bold: colorIfAllowed((text) => `\x1B[1m${text}\x1B[0m`),
|
|
190
|
+
green: colorIfAllowed((text) => `\x1B[32m${text}\x1B[39m`),
|
|
191
|
+
yellow: colorIfAllowed((text) => `\x1B[33m${text}\x1B[39m`),
|
|
192
|
+
red: colorIfAllowed((text) => `\x1B[31m${text}\x1B[39m`),
|
|
193
|
+
magentaBright: colorIfAllowed((text) => `\x1B[95m${text}\x1B[39m`),
|
|
194
|
+
cyanBright: colorIfAllowed((text) => `\x1B[96m${text}\x1B[39m`)
|
|
195
|
+
};
|
|
196
|
+
var yellow = colorIfAllowed(
|
|
197
|
+
(text) => `\x1B[38;5;3m${text}\x1B[39m`
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
// packages/core/src/logger/log-levels.mts
|
|
201
|
+
var LOG_LEVELS = [
|
|
202
|
+
"verbose",
|
|
203
|
+
"debug",
|
|
204
|
+
"log",
|
|
205
|
+
"warn",
|
|
206
|
+
"error",
|
|
207
|
+
"fatal"
|
|
208
|
+
];
|
|
209
|
+
|
|
210
|
+
// packages/core/src/logger/utils/is-log-level.util.mts
|
|
211
|
+
function isLogLevel(maybeLogLevel) {
|
|
212
|
+
return LOG_LEVELS.includes(maybeLogLevel);
|
|
198
213
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
214
|
+
|
|
215
|
+
// packages/core/src/logger/utils/filter-log-levelts.util.mts
|
|
216
|
+
function filterLogLevels(parseableString = "") {
|
|
217
|
+
const sanitizedString = parseableString.replaceAll(" ", "").toLowerCase();
|
|
218
|
+
if (sanitizedString[0] === ">") {
|
|
219
|
+
const orEqual = sanitizedString[1] === "=";
|
|
220
|
+
const logLevelIndex = LOG_LEVELS.indexOf(
|
|
221
|
+
sanitizedString.substring(orEqual ? 2 : 1)
|
|
204
222
|
);
|
|
223
|
+
if (logLevelIndex === -1) {
|
|
224
|
+
throw new Error(`parse error (unknown log level): ${sanitizedString}`);
|
|
225
|
+
}
|
|
226
|
+
return LOG_LEVELS.slice(orEqual ? logLevelIndex : logLevelIndex + 1);
|
|
227
|
+
} else if (sanitizedString.includes(",")) {
|
|
228
|
+
return sanitizedString.split(",").filter(isLogLevel);
|
|
205
229
|
}
|
|
206
|
-
return
|
|
207
|
-
}
|
|
208
|
-
function hasControllerMetadata(target) {
|
|
209
|
-
const metadata = target[ControllerMetadataKey];
|
|
210
|
-
return !!metadata;
|
|
230
|
+
return isLogLevel(sanitizedString) ? [sanitizedString] : LOG_LEVELS;
|
|
211
231
|
}
|
|
212
232
|
|
|
213
|
-
// packages/core/src/
|
|
214
|
-
var
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
};
|
|
227
|
-
context.metadata[ModuleMetadataKey] = newMetadata;
|
|
228
|
-
target[ModuleMetadataKey] = newMetadata;
|
|
229
|
-
return newMetadata;
|
|
230
|
-
}
|
|
233
|
+
// packages/core/src/logger/utils/is-log-level-enabled.mts
|
|
234
|
+
var LOG_LEVEL_VALUES = {
|
|
235
|
+
verbose: 0,
|
|
236
|
+
debug: 1,
|
|
237
|
+
log: 2,
|
|
238
|
+
warn: 3,
|
|
239
|
+
error: 4,
|
|
240
|
+
fatal: 5
|
|
241
|
+
};
|
|
242
|
+
function isLogLevelEnabled(targetLevel, logLevels) {
|
|
243
|
+
var _a;
|
|
244
|
+
if (!logLevels || Array.isArray(logLevels) && (logLevels == null ? void 0 : logLevels.length) === 0) {
|
|
245
|
+
return false;
|
|
231
246
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
function extractModuleMetadata(target) {
|
|
235
|
-
const metadata = target[ModuleMetadataKey];
|
|
236
|
-
if (!metadata) {
|
|
237
|
-
throw new Error(
|
|
238
|
-
"[Navios] Module metadata not found. Make sure to use @Module decorator."
|
|
239
|
-
);
|
|
247
|
+
if (logLevels.includes(targetLevel)) {
|
|
248
|
+
return true;
|
|
240
249
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
return !!target[ModuleMetadataKey];
|
|
250
|
+
const highestLogLevelValue = (_a = logLevels.map((level) => LOG_LEVEL_VALUES[level]).sort((a, b) => b - a)) == null ? void 0 : _a[0];
|
|
251
|
+
const targetLevelValue = LOG_LEVEL_VALUES[targetLevel];
|
|
252
|
+
return targetLevelValue >= highestLogLevelValue;
|
|
245
253
|
}
|
|
246
254
|
|
|
255
|
+
// packages/core/src/logger/utils/shared.utils.mts
|
|
256
|
+
var isUndefined = (obj) => typeof obj === "undefined";
|
|
257
|
+
var isObject = (fn) => !isNil(fn) && typeof fn === "object";
|
|
258
|
+
var isPlainObject = (fn) => {
|
|
259
|
+
if (!isObject(fn)) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
const proto = Object.getPrototypeOf(fn);
|
|
263
|
+
if (proto === null) {
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
const ctor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
267
|
+
return typeof ctor === "function" && ctor instanceof ctor && Function.prototype.toString.call(ctor) === Function.prototype.toString.call(Object);
|
|
268
|
+
};
|
|
269
|
+
var addLeadingSlash = (path) => path && typeof path === "string" ? path.charAt(0) !== "/" && path.substring(0, 2) !== "{/" ? "/" + path : path : "";
|
|
270
|
+
var normalizePath = (path) => path ? path.startsWith("/") ? ("/" + path.replace(/\/+$/, "")).replace(/\/+/g, "/") : "/" + path.replace(/\/+$/, "") : "/";
|
|
271
|
+
var stripEndSlash = (path) => path[path.length - 1] === "/" ? path.slice(0, path.length - 1) : path;
|
|
272
|
+
var isFunction = (val) => typeof val === "function";
|
|
273
|
+
var isString = (val) => typeof val === "string";
|
|
274
|
+
var isNumber = (val) => typeof val === "number";
|
|
275
|
+
var isConstructor = (val) => val === "constructor";
|
|
276
|
+
var isNil = (val) => isUndefined(val) || val === null;
|
|
277
|
+
var isEmpty = (array) => !(array && array.length > 0);
|
|
278
|
+
var isSymbol = (val) => typeof val === "symbol";
|
|
279
|
+
|
|
280
|
+
// packages/core/src/logger/console-logger.service.mts
|
|
281
|
+
var import_util = require("util");
|
|
282
|
+
|
|
247
283
|
// packages/core/src/service-locator/enums/injectable-scope.enum.mts
|
|
248
284
|
var InjectableScope = /* @__PURE__ */ ((InjectableScope2) => {
|
|
249
285
|
InjectableScope2["Singleton"] = "Singleton";
|
|
@@ -253,6 +289,7 @@ var InjectableScope = /* @__PURE__ */ ((InjectableScope2) => {
|
|
|
253
289
|
|
|
254
290
|
// packages/core/src/service-locator/injection-token.mts
|
|
255
291
|
var import_crypto = require("crypto");
|
|
292
|
+
var import_zod = require("zod");
|
|
256
293
|
var InjectionToken = class _InjectionToken {
|
|
257
294
|
constructor(name2, schema) {
|
|
258
295
|
this.name = name2;
|
|
@@ -801,7 +838,15 @@ var ServiceLocator = class {
|
|
|
801
838
|
).then(() => null);
|
|
802
839
|
}
|
|
803
840
|
makeInstanceName(token, args) {
|
|
804
|
-
let stringifiedArgs = args ? ":" + JSON.stringify(args
|
|
841
|
+
let stringifiedArgs = args ? ":" + JSON.stringify(args, (_, value) => {
|
|
842
|
+
if (typeof value === "function") {
|
|
843
|
+
return `function:${value.name}(${value.length})`;
|
|
844
|
+
}
|
|
845
|
+
if (typeof value === "symbol") {
|
|
846
|
+
return value.toString();
|
|
847
|
+
}
|
|
848
|
+
return value;
|
|
849
|
+
}).replaceAll(/"/g, "").replaceAll(/:/g, "=").replaceAll(/,/g, "|") : "";
|
|
805
850
|
const { name: name2 } = token;
|
|
806
851
|
if (typeof name2 === "function") {
|
|
807
852
|
const className = name2.name;
|
|
@@ -1077,6 +1122,761 @@ function override(token, target) {
|
|
|
1077
1122
|
};
|
|
1078
1123
|
}
|
|
1079
1124
|
|
|
1125
|
+
// packages/core/src/logger/console-logger.service.mts
|
|
1126
|
+
var DEFAULT_DEPTH = 5;
|
|
1127
|
+
var DEFAULT_LOG_LEVELS = [
|
|
1128
|
+
"log",
|
|
1129
|
+
"error",
|
|
1130
|
+
"warn",
|
|
1131
|
+
"debug",
|
|
1132
|
+
"verbose",
|
|
1133
|
+
"fatal"
|
|
1134
|
+
];
|
|
1135
|
+
var dateTimeFormatter = new Intl.DateTimeFormat(void 0, {
|
|
1136
|
+
year: "numeric",
|
|
1137
|
+
hour: "numeric",
|
|
1138
|
+
minute: "numeric",
|
|
1139
|
+
second: "numeric",
|
|
1140
|
+
day: "2-digit",
|
|
1141
|
+
month: "2-digit"
|
|
1142
|
+
});
|
|
1143
|
+
var _ConsoleLogger_decorators, _init;
|
|
1144
|
+
_ConsoleLogger_decorators = [Injectable()];
|
|
1145
|
+
var _ConsoleLogger = class _ConsoleLogger {
|
|
1146
|
+
/**
|
|
1147
|
+
* The options of the logger.
|
|
1148
|
+
*/
|
|
1149
|
+
options;
|
|
1150
|
+
/**
|
|
1151
|
+
* The context of the logger (can be set manually or automatically inferred).
|
|
1152
|
+
*/
|
|
1153
|
+
context;
|
|
1154
|
+
/**
|
|
1155
|
+
* The original context of the logger (set in the constructor).
|
|
1156
|
+
*/
|
|
1157
|
+
originalContext;
|
|
1158
|
+
/**
|
|
1159
|
+
* The options used for the "inspect" method.
|
|
1160
|
+
*/
|
|
1161
|
+
inspectOptions;
|
|
1162
|
+
/**
|
|
1163
|
+
* The last timestamp at which the log message was printed.
|
|
1164
|
+
*/
|
|
1165
|
+
static lastTimestampAt;
|
|
1166
|
+
constructor(contextOrOptions, options) {
|
|
1167
|
+
let [context, opts] = isString(contextOrOptions) ? [contextOrOptions, options] : options ? [void 0, options] : [contextOrOptions == null ? void 0 : contextOrOptions.context, contextOrOptions];
|
|
1168
|
+
opts = opts ?? {};
|
|
1169
|
+
opts.logLevels ??= DEFAULT_LOG_LEVELS;
|
|
1170
|
+
opts.colors ??= opts.colors ?? (opts.json ? false : true);
|
|
1171
|
+
opts.prefix ??= "Navios";
|
|
1172
|
+
this.options = opts;
|
|
1173
|
+
this.inspectOptions = this.getInspectOptions();
|
|
1174
|
+
if (context) {
|
|
1175
|
+
this.context = context;
|
|
1176
|
+
this.originalContext = context;
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
log(message, ...optionalParams) {
|
|
1180
|
+
if (!this.isLevelEnabled("log")) {
|
|
1181
|
+
return;
|
|
1182
|
+
}
|
|
1183
|
+
const { messages, context } = this.getContextAndMessagesToPrint([
|
|
1184
|
+
message,
|
|
1185
|
+
...optionalParams
|
|
1186
|
+
]);
|
|
1187
|
+
this.printMessages(messages, context, "log");
|
|
1188
|
+
}
|
|
1189
|
+
error(message, ...optionalParams) {
|
|
1190
|
+
if (!this.isLevelEnabled("error")) {
|
|
1191
|
+
return;
|
|
1192
|
+
}
|
|
1193
|
+
const { messages, context, stack } = this.getContextAndStackAndMessagesToPrint([message, ...optionalParams]);
|
|
1194
|
+
this.printMessages(messages, context, "error", "stderr", stack);
|
|
1195
|
+
this.printStackTrace(stack);
|
|
1196
|
+
}
|
|
1197
|
+
warn(message, ...optionalParams) {
|
|
1198
|
+
if (!this.isLevelEnabled("warn")) {
|
|
1199
|
+
return;
|
|
1200
|
+
}
|
|
1201
|
+
const { messages, context } = this.getContextAndMessagesToPrint([
|
|
1202
|
+
message,
|
|
1203
|
+
...optionalParams
|
|
1204
|
+
]);
|
|
1205
|
+
this.printMessages(messages, context, "warn");
|
|
1206
|
+
}
|
|
1207
|
+
debug(message, ...optionalParams) {
|
|
1208
|
+
if (!this.isLevelEnabled("debug")) {
|
|
1209
|
+
return;
|
|
1210
|
+
}
|
|
1211
|
+
const { messages, context } = this.getContextAndMessagesToPrint([
|
|
1212
|
+
message,
|
|
1213
|
+
...optionalParams
|
|
1214
|
+
]);
|
|
1215
|
+
this.printMessages(messages, context, "debug");
|
|
1216
|
+
}
|
|
1217
|
+
verbose(message, ...optionalParams) {
|
|
1218
|
+
if (!this.isLevelEnabled("verbose")) {
|
|
1219
|
+
return;
|
|
1220
|
+
}
|
|
1221
|
+
const { messages, context } = this.getContextAndMessagesToPrint([
|
|
1222
|
+
message,
|
|
1223
|
+
...optionalParams
|
|
1224
|
+
]);
|
|
1225
|
+
this.printMessages(messages, context, "verbose");
|
|
1226
|
+
}
|
|
1227
|
+
fatal(message, ...optionalParams) {
|
|
1228
|
+
if (!this.isLevelEnabled("fatal")) {
|
|
1229
|
+
return;
|
|
1230
|
+
}
|
|
1231
|
+
const { messages, context } = this.getContextAndMessagesToPrint([
|
|
1232
|
+
message,
|
|
1233
|
+
...optionalParams
|
|
1234
|
+
]);
|
|
1235
|
+
this.printMessages(messages, context, "fatal");
|
|
1236
|
+
}
|
|
1237
|
+
/**
|
|
1238
|
+
* Set log levels
|
|
1239
|
+
* @param levels log levels
|
|
1240
|
+
*/
|
|
1241
|
+
setLogLevels(levels) {
|
|
1242
|
+
if (!this.options) {
|
|
1243
|
+
this.options = {};
|
|
1244
|
+
}
|
|
1245
|
+
this.options.logLevels = levels;
|
|
1246
|
+
}
|
|
1247
|
+
/**
|
|
1248
|
+
* Set logger context
|
|
1249
|
+
* @param context context
|
|
1250
|
+
*/
|
|
1251
|
+
setContext(context) {
|
|
1252
|
+
this.context = context;
|
|
1253
|
+
}
|
|
1254
|
+
/**
|
|
1255
|
+
* Resets the logger context to the value that was passed in the constructor.
|
|
1256
|
+
*/
|
|
1257
|
+
resetContext() {
|
|
1258
|
+
this.context = this.originalContext;
|
|
1259
|
+
}
|
|
1260
|
+
isLevelEnabled(level) {
|
|
1261
|
+
var _a;
|
|
1262
|
+
const logLevels = (_a = this.options) == null ? void 0 : _a.logLevels;
|
|
1263
|
+
return isLogLevelEnabled(level, logLevels);
|
|
1264
|
+
}
|
|
1265
|
+
getTimestamp() {
|
|
1266
|
+
return dateTimeFormatter.format(Date.now());
|
|
1267
|
+
}
|
|
1268
|
+
printMessages(messages, context = "", logLevel = "log", writeStreamType, errorStack) {
|
|
1269
|
+
messages.forEach((message) => {
|
|
1270
|
+
if (this.options.json) {
|
|
1271
|
+
this.printAsJson(message, {
|
|
1272
|
+
context,
|
|
1273
|
+
logLevel,
|
|
1274
|
+
writeStreamType,
|
|
1275
|
+
errorStack
|
|
1276
|
+
});
|
|
1277
|
+
return;
|
|
1278
|
+
}
|
|
1279
|
+
const pidMessage = this.formatPid(process.pid);
|
|
1280
|
+
const contextMessage = this.formatContext(context);
|
|
1281
|
+
const timestampDiff = this.updateAndGetTimestampDiff();
|
|
1282
|
+
const formattedLogLevel = logLevel.toUpperCase().padStart(7, " ");
|
|
1283
|
+
const formattedMessage = this.formatMessage(
|
|
1284
|
+
logLevel,
|
|
1285
|
+
message,
|
|
1286
|
+
pidMessage,
|
|
1287
|
+
formattedLogLevel,
|
|
1288
|
+
contextMessage,
|
|
1289
|
+
timestampDiff
|
|
1290
|
+
);
|
|
1291
|
+
process[writeStreamType ?? "stdout"].write(formattedMessage);
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1294
|
+
printAsJson(message, options) {
|
|
1295
|
+
const logObject = {
|
|
1296
|
+
level: options.logLevel,
|
|
1297
|
+
pid: process.pid,
|
|
1298
|
+
timestamp: Date.now(),
|
|
1299
|
+
message
|
|
1300
|
+
};
|
|
1301
|
+
if (options.context) {
|
|
1302
|
+
logObject.context = options.context;
|
|
1303
|
+
}
|
|
1304
|
+
if (options.errorStack) {
|
|
1305
|
+
logObject.stack = options.errorStack;
|
|
1306
|
+
}
|
|
1307
|
+
const formattedMessage = !this.options.colors && this.inspectOptions.compact === true ? JSON.stringify(logObject, this.stringifyReplacer) : (0, import_util.inspect)(logObject, this.inspectOptions);
|
|
1308
|
+
process[options.writeStreamType ?? "stdout"].write(`${formattedMessage}
|
|
1309
|
+
`);
|
|
1310
|
+
}
|
|
1311
|
+
formatPid(pid) {
|
|
1312
|
+
return `[${this.options.prefix}] ${pid} - `;
|
|
1313
|
+
}
|
|
1314
|
+
formatContext(context) {
|
|
1315
|
+
if (!context) {
|
|
1316
|
+
return "";
|
|
1317
|
+
}
|
|
1318
|
+
context = `[${context}] `;
|
|
1319
|
+
return this.options.colors ? yellow(context) : context;
|
|
1320
|
+
}
|
|
1321
|
+
formatMessage(logLevel, message, pidMessage, formattedLogLevel, contextMessage, timestampDiff) {
|
|
1322
|
+
const output = this.stringifyMessage(message, logLevel);
|
|
1323
|
+
pidMessage = this.colorize(pidMessage, logLevel);
|
|
1324
|
+
formattedLogLevel = this.colorize(formattedLogLevel, logLevel);
|
|
1325
|
+
return `${pidMessage}${this.getTimestamp()} ${formattedLogLevel} ${contextMessage}${output}${timestampDiff}
|
|
1326
|
+
`;
|
|
1327
|
+
}
|
|
1328
|
+
stringifyMessage(message, logLevel) {
|
|
1329
|
+
if (isFunction(message)) {
|
|
1330
|
+
const messageAsStr = Function.prototype.toString.call(message);
|
|
1331
|
+
const isClass = messageAsStr.startsWith("class ");
|
|
1332
|
+
if (isClass) {
|
|
1333
|
+
return this.stringifyMessage(message.name, logLevel);
|
|
1334
|
+
}
|
|
1335
|
+
return this.stringifyMessage(message(), logLevel);
|
|
1336
|
+
}
|
|
1337
|
+
if (typeof message === "string") {
|
|
1338
|
+
return this.colorize(message, logLevel);
|
|
1339
|
+
}
|
|
1340
|
+
const outputText = (0, import_util.inspect)(message, this.inspectOptions);
|
|
1341
|
+
if (isPlainObject(message)) {
|
|
1342
|
+
return `Object(${Object.keys(message).length}) ${outputText}`;
|
|
1343
|
+
}
|
|
1344
|
+
if (Array.isArray(message)) {
|
|
1345
|
+
return `Array(${message.length}) ${outputText}`;
|
|
1346
|
+
}
|
|
1347
|
+
return outputText;
|
|
1348
|
+
}
|
|
1349
|
+
colorize(message, logLevel) {
|
|
1350
|
+
if (!this.options.colors || this.options.json) {
|
|
1351
|
+
return message;
|
|
1352
|
+
}
|
|
1353
|
+
const color = this.getColorByLogLevel(logLevel);
|
|
1354
|
+
return color(message);
|
|
1355
|
+
}
|
|
1356
|
+
printStackTrace(stack) {
|
|
1357
|
+
if (!stack || this.options.json) {
|
|
1358
|
+
return;
|
|
1359
|
+
}
|
|
1360
|
+
process.stderr.write(`${stack}
|
|
1361
|
+
`);
|
|
1362
|
+
}
|
|
1363
|
+
updateAndGetTimestampDiff() {
|
|
1364
|
+
var _a;
|
|
1365
|
+
const includeTimestamp = _ConsoleLogger.lastTimestampAt && ((_a = this.options) == null ? void 0 : _a.timestamp);
|
|
1366
|
+
const result = includeTimestamp ? this.formatTimestampDiff(Date.now() - _ConsoleLogger.lastTimestampAt) : "";
|
|
1367
|
+
_ConsoleLogger.lastTimestampAt = Date.now();
|
|
1368
|
+
return result;
|
|
1369
|
+
}
|
|
1370
|
+
formatTimestampDiff(timestampDiff) {
|
|
1371
|
+
const formattedDiff = ` +${timestampDiff}ms`;
|
|
1372
|
+
return this.options.colors ? yellow(formattedDiff) : formattedDiff;
|
|
1373
|
+
}
|
|
1374
|
+
getInspectOptions() {
|
|
1375
|
+
let breakLength = this.options.breakLength;
|
|
1376
|
+
if (typeof breakLength === "undefined") {
|
|
1377
|
+
breakLength = this.options.colors ? this.options.compact ? Infinity : void 0 : this.options.compact === false ? void 0 : Infinity;
|
|
1378
|
+
}
|
|
1379
|
+
const inspectOptions = {
|
|
1380
|
+
depth: this.options.depth ?? DEFAULT_DEPTH,
|
|
1381
|
+
sorted: this.options.sorted,
|
|
1382
|
+
showHidden: this.options.showHidden,
|
|
1383
|
+
compact: this.options.compact ?? (this.options.json ? true : false),
|
|
1384
|
+
colors: this.options.colors,
|
|
1385
|
+
breakLength
|
|
1386
|
+
};
|
|
1387
|
+
if (this.options.maxArrayLength) {
|
|
1388
|
+
inspectOptions.maxArrayLength = this.options.maxArrayLength;
|
|
1389
|
+
}
|
|
1390
|
+
if (this.options.maxStringLength) {
|
|
1391
|
+
inspectOptions.maxStringLength = this.options.maxStringLength;
|
|
1392
|
+
}
|
|
1393
|
+
return inspectOptions;
|
|
1394
|
+
}
|
|
1395
|
+
stringifyReplacer(key, value) {
|
|
1396
|
+
if (typeof value === "bigint") {
|
|
1397
|
+
return value.toString();
|
|
1398
|
+
}
|
|
1399
|
+
if (typeof value === "symbol") {
|
|
1400
|
+
return value.toString();
|
|
1401
|
+
}
|
|
1402
|
+
if (value instanceof Map || value instanceof Set || value instanceof Error) {
|
|
1403
|
+
return `${(0, import_util.inspect)(value, this.inspectOptions)}`;
|
|
1404
|
+
}
|
|
1405
|
+
return value;
|
|
1406
|
+
}
|
|
1407
|
+
getContextAndMessagesToPrint(args) {
|
|
1408
|
+
if ((args == null ? void 0 : args.length) <= 1) {
|
|
1409
|
+
return { messages: args, context: this.context };
|
|
1410
|
+
}
|
|
1411
|
+
const lastElement = args[args.length - 1];
|
|
1412
|
+
const isContext = isString(lastElement);
|
|
1413
|
+
if (!isContext) {
|
|
1414
|
+
return { messages: args, context: this.context };
|
|
1415
|
+
}
|
|
1416
|
+
return {
|
|
1417
|
+
context: lastElement,
|
|
1418
|
+
messages: args.slice(0, args.length - 1)
|
|
1419
|
+
};
|
|
1420
|
+
}
|
|
1421
|
+
getContextAndStackAndMessagesToPrint(args) {
|
|
1422
|
+
if (args.length === 2) {
|
|
1423
|
+
return this.isStackFormat(args[1]) ? {
|
|
1424
|
+
messages: [args[0]],
|
|
1425
|
+
stack: args[1],
|
|
1426
|
+
context: this.context
|
|
1427
|
+
} : {
|
|
1428
|
+
messages: [args[0]],
|
|
1429
|
+
context: args[1]
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
const { messages, context } = this.getContextAndMessagesToPrint(args);
|
|
1433
|
+
if ((messages == null ? void 0 : messages.length) <= 1) {
|
|
1434
|
+
return { messages, context };
|
|
1435
|
+
}
|
|
1436
|
+
const lastElement = messages[messages.length - 1];
|
|
1437
|
+
const isStack = isString(lastElement);
|
|
1438
|
+
if (!isStack && !isUndefined(lastElement)) {
|
|
1439
|
+
return { messages, context };
|
|
1440
|
+
}
|
|
1441
|
+
return {
|
|
1442
|
+
stack: lastElement,
|
|
1443
|
+
messages: messages.slice(0, messages.length - 1),
|
|
1444
|
+
context
|
|
1445
|
+
};
|
|
1446
|
+
}
|
|
1447
|
+
isStackFormat(stack) {
|
|
1448
|
+
if (!isString(stack) && !isUndefined(stack)) {
|
|
1449
|
+
return false;
|
|
1450
|
+
}
|
|
1451
|
+
return /^(.)+\n\s+at .+:\d+:\d+/.test(stack);
|
|
1452
|
+
}
|
|
1453
|
+
getColorByLogLevel(level) {
|
|
1454
|
+
switch (level) {
|
|
1455
|
+
case "debug":
|
|
1456
|
+
return clc.magentaBright;
|
|
1457
|
+
case "warn":
|
|
1458
|
+
return clc.yellow;
|
|
1459
|
+
case "error":
|
|
1460
|
+
return clc.red;
|
|
1461
|
+
case "verbose":
|
|
1462
|
+
return clc.cyanBright;
|
|
1463
|
+
case "fatal":
|
|
1464
|
+
return clc.bold;
|
|
1465
|
+
default:
|
|
1466
|
+
return clc.green;
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
};
|
|
1470
|
+
_init = __decoratorStart(null);
|
|
1471
|
+
_ConsoleLogger = __decorateElement(_init, 0, "ConsoleLogger", _ConsoleLogger_decorators, _ConsoleLogger);
|
|
1472
|
+
__runInitializers(_init, 1, _ConsoleLogger);
|
|
1473
|
+
var ConsoleLogger = _ConsoleLogger;
|
|
1474
|
+
|
|
1475
|
+
// packages/core/src/logger/logger.factory.mts
|
|
1476
|
+
var import_zod2 = require("zod");
|
|
1477
|
+
|
|
1478
|
+
// packages/core/src/logger/logger.service.mts
|
|
1479
|
+
var DEFAULT_LOGGER = new ConsoleLogger();
|
|
1480
|
+
var dateTimeFormatter2 = new Intl.DateTimeFormat(void 0, {
|
|
1481
|
+
year: "numeric",
|
|
1482
|
+
hour: "numeric",
|
|
1483
|
+
minute: "numeric",
|
|
1484
|
+
second: "numeric",
|
|
1485
|
+
day: "2-digit",
|
|
1486
|
+
month: "2-digit"
|
|
1487
|
+
});
|
|
1488
|
+
var _LoggerInstance_decorators, _init2;
|
|
1489
|
+
_LoggerInstance_decorators = [Injectable()];
|
|
1490
|
+
var _LoggerInstance = class _LoggerInstance {
|
|
1491
|
+
constructor(context, options = {}) {
|
|
1492
|
+
this.context = context;
|
|
1493
|
+
this.options = options;
|
|
1494
|
+
}
|
|
1495
|
+
static staticInstanceRef = DEFAULT_LOGGER;
|
|
1496
|
+
static logLevels;
|
|
1497
|
+
localInstanceRef;
|
|
1498
|
+
get localInstance() {
|
|
1499
|
+
if (_LoggerInstance.staticInstanceRef === DEFAULT_LOGGER) {
|
|
1500
|
+
return this.registerLocalInstanceRef();
|
|
1501
|
+
} else if (_LoggerInstance.staticInstanceRef instanceof _LoggerInstance) {
|
|
1502
|
+
const prototype = Object.getPrototypeOf(_LoggerInstance.staticInstanceRef);
|
|
1503
|
+
if (prototype.constructor === _LoggerInstance) {
|
|
1504
|
+
return this.registerLocalInstanceRef();
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
return _LoggerInstance.staticInstanceRef;
|
|
1508
|
+
}
|
|
1509
|
+
error(message, ...optionalParams) {
|
|
1510
|
+
var _a;
|
|
1511
|
+
optionalParams = this.context ? (optionalParams.length ? optionalParams : [void 0]).concat(
|
|
1512
|
+
this.context
|
|
1513
|
+
) : optionalParams;
|
|
1514
|
+
(_a = this.localInstance) == null ? void 0 : _a.error(message, ...optionalParams);
|
|
1515
|
+
}
|
|
1516
|
+
log(message, ...optionalParams) {
|
|
1517
|
+
var _a;
|
|
1518
|
+
optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
|
|
1519
|
+
(_a = this.localInstance) == null ? void 0 : _a.log(message, ...optionalParams);
|
|
1520
|
+
}
|
|
1521
|
+
warn(message, ...optionalParams) {
|
|
1522
|
+
var _a;
|
|
1523
|
+
optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
|
|
1524
|
+
(_a = this.localInstance) == null ? void 0 : _a.warn(message, ...optionalParams);
|
|
1525
|
+
}
|
|
1526
|
+
debug(message, ...optionalParams) {
|
|
1527
|
+
var _a, _b;
|
|
1528
|
+
optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
|
|
1529
|
+
(_b = (_a = this.localInstance) == null ? void 0 : _a.debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
|
|
1530
|
+
}
|
|
1531
|
+
verbose(message, ...optionalParams) {
|
|
1532
|
+
var _a, _b;
|
|
1533
|
+
optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
|
|
1534
|
+
(_b = (_a = this.localInstance) == null ? void 0 : _a.verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
|
|
1535
|
+
}
|
|
1536
|
+
fatal(message, ...optionalParams) {
|
|
1537
|
+
var _a, _b;
|
|
1538
|
+
optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
|
|
1539
|
+
(_b = (_a = this.localInstance) == null ? void 0 : _a.fatal) == null ? void 0 : _b.call(_a, message, ...optionalParams);
|
|
1540
|
+
}
|
|
1541
|
+
static error(message, ...optionalParams) {
|
|
1542
|
+
var _a;
|
|
1543
|
+
(_a = this.staticInstanceRef) == null ? void 0 : _a.error(message, ...optionalParams);
|
|
1544
|
+
}
|
|
1545
|
+
static log(message, ...optionalParams) {
|
|
1546
|
+
var _a;
|
|
1547
|
+
(_a = this.staticInstanceRef) == null ? void 0 : _a.log(message, ...optionalParams);
|
|
1548
|
+
}
|
|
1549
|
+
static warn(message, ...optionalParams) {
|
|
1550
|
+
var _a;
|
|
1551
|
+
(_a = this.staticInstanceRef) == null ? void 0 : _a.warn(message, ...optionalParams);
|
|
1552
|
+
}
|
|
1553
|
+
static debug(message, ...optionalParams) {
|
|
1554
|
+
var _a, _b;
|
|
1555
|
+
(_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
|
|
1556
|
+
}
|
|
1557
|
+
static verbose(message, ...optionalParams) {
|
|
1558
|
+
var _a, _b;
|
|
1559
|
+
(_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
|
|
1560
|
+
}
|
|
1561
|
+
static fatal(message, ...optionalParams) {
|
|
1562
|
+
var _a, _b;
|
|
1563
|
+
(_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.fatal) == null ? void 0 : _b.call(_a, message, ...optionalParams);
|
|
1564
|
+
}
|
|
1565
|
+
static getTimestamp() {
|
|
1566
|
+
return dateTimeFormatter2.format(Date.now());
|
|
1567
|
+
}
|
|
1568
|
+
static overrideLogger(logger) {
|
|
1569
|
+
var _a, _b;
|
|
1570
|
+
console.log(logger);
|
|
1571
|
+
if (Array.isArray(logger)) {
|
|
1572
|
+
_LoggerInstance.logLevels = logger;
|
|
1573
|
+
return (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.setLogLevels) == null ? void 0 : _b.call(_a, logger);
|
|
1574
|
+
}
|
|
1575
|
+
if (isObject(logger)) {
|
|
1576
|
+
this.staticInstanceRef = logger;
|
|
1577
|
+
} else {
|
|
1578
|
+
this.staticInstanceRef = void 0;
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
static isLevelEnabled(level) {
|
|
1582
|
+
const logLevels = _LoggerInstance.logLevels;
|
|
1583
|
+
return isLogLevelEnabled(level, logLevels);
|
|
1584
|
+
}
|
|
1585
|
+
registerLocalInstanceRef() {
|
|
1586
|
+
var _a;
|
|
1587
|
+
if (this.localInstanceRef) {
|
|
1588
|
+
return this.localInstanceRef;
|
|
1589
|
+
}
|
|
1590
|
+
this.localInstanceRef = new ConsoleLogger(this.context, {
|
|
1591
|
+
timestamp: (_a = this.options) == null ? void 0 : _a.timestamp,
|
|
1592
|
+
logLevels: _LoggerInstance.logLevels
|
|
1593
|
+
});
|
|
1594
|
+
return this.localInstanceRef;
|
|
1595
|
+
}
|
|
1596
|
+
};
|
|
1597
|
+
_init2 = __decoratorStart(null);
|
|
1598
|
+
_LoggerInstance = __decorateElement(_init2, 0, "LoggerInstance", _LoggerInstance_decorators, _LoggerInstance);
|
|
1599
|
+
__runInitializers(_init2, 1, _LoggerInstance);
|
|
1600
|
+
var LoggerInstance = _LoggerInstance;
|
|
1601
|
+
|
|
1602
|
+
// packages/core/src/logger/logger.factory.mts
|
|
1603
|
+
var LoggerInjectionToken = "LoggerInjectionToken";
|
|
1604
|
+
var LoggerOptions = import_zod2.z.object({
|
|
1605
|
+
context: import_zod2.z.string().optional(),
|
|
1606
|
+
options: import_zod2.z.object({
|
|
1607
|
+
timestamp: import_zod2.z.boolean().optional()
|
|
1608
|
+
}).optional()
|
|
1609
|
+
}).optional();
|
|
1610
|
+
var Logger = InjectionToken.create(LoggerInjectionToken, LoggerOptions);
|
|
1611
|
+
var _LoggerFactory_decorators, _init3;
|
|
1612
|
+
_LoggerFactory_decorators = [Injectable({
|
|
1613
|
+
type: "Factory" /* Factory */,
|
|
1614
|
+
token: Logger
|
|
1615
|
+
})];
|
|
1616
|
+
var LoggerFactory = class {
|
|
1617
|
+
create(ctx, args) {
|
|
1618
|
+
return new LoggerInstance(args == null ? void 0 : args.context, args == null ? void 0 : args.options);
|
|
1619
|
+
}
|
|
1620
|
+
};
|
|
1621
|
+
_init3 = __decoratorStart(null);
|
|
1622
|
+
LoggerFactory = __decorateElement(_init3, 0, "LoggerFactory", _LoggerFactory_decorators, LoggerFactory);
|
|
1623
|
+
__runInitializers(_init3, 1, LoggerFactory);
|
|
1624
|
+
|
|
1625
|
+
// packages/core/src/logger/pino-wrapper.mts
|
|
1626
|
+
var PinoWrapper = class _PinoWrapper {
|
|
1627
|
+
constructor(logger) {
|
|
1628
|
+
this.logger = logger;
|
|
1629
|
+
}
|
|
1630
|
+
fatal(message, ...optionalParams) {
|
|
1631
|
+
if (this.logger.fatal === void 0) {
|
|
1632
|
+
return this.error(message, ...optionalParams);
|
|
1633
|
+
}
|
|
1634
|
+
this.logger.fatal(message, ...optionalParams);
|
|
1635
|
+
}
|
|
1636
|
+
error(message, ...optionalParams) {
|
|
1637
|
+
this.logger.error(message, ...optionalParams);
|
|
1638
|
+
}
|
|
1639
|
+
warn(message, ...optionalParams) {
|
|
1640
|
+
this.logger.warn(message, ...optionalParams);
|
|
1641
|
+
}
|
|
1642
|
+
info(message, ...optionalParams) {
|
|
1643
|
+
this.logger.log(message, ...optionalParams);
|
|
1644
|
+
}
|
|
1645
|
+
debug(message, ...optionalParams) {
|
|
1646
|
+
var _a, _b;
|
|
1647
|
+
(_b = (_a = this.logger).debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
|
|
1648
|
+
}
|
|
1649
|
+
trace(message, ...optionalParams) {
|
|
1650
|
+
var _a, _b;
|
|
1651
|
+
(_b = (_a = this.logger).verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
|
|
1652
|
+
}
|
|
1653
|
+
silent(message, ...optionalParams) {
|
|
1654
|
+
}
|
|
1655
|
+
child(options) {
|
|
1656
|
+
const keys = Object.keys(options);
|
|
1657
|
+
let newContext = this.logger["context"] ?? "";
|
|
1658
|
+
if (keys.length > 1) {
|
|
1659
|
+
newContext = `${this.logger["context"] ?? ""}:${JSON.stringify(options)}`;
|
|
1660
|
+
}
|
|
1661
|
+
return new _PinoWrapper(
|
|
1662
|
+
// @ts-expect-error We don't need to support this in the current version
|
|
1663
|
+
new LoggerInstance(newContext, this.logger["options"])
|
|
1664
|
+
);
|
|
1665
|
+
}
|
|
1666
|
+
get level() {
|
|
1667
|
+
if ("level" in this.logger && this.logger.level) {
|
|
1668
|
+
return this.logger.level;
|
|
1669
|
+
}
|
|
1670
|
+
const levels = LoggerInstance["logLevels"];
|
|
1671
|
+
if (levels) {
|
|
1672
|
+
return levels[0];
|
|
1673
|
+
}
|
|
1674
|
+
return "info";
|
|
1675
|
+
}
|
|
1676
|
+
};
|
|
1677
|
+
|
|
1678
|
+
// packages/core/src/config/config.service.mts
|
|
1679
|
+
var import_common = require("@navios/common");
|
|
1680
|
+
var ConfigServiceInstance = class {
|
|
1681
|
+
constructor(config = {}, logger) {
|
|
1682
|
+
this.config = config;
|
|
1683
|
+
this.logger = logger;
|
|
1684
|
+
}
|
|
1685
|
+
getConfig() {
|
|
1686
|
+
return this.config;
|
|
1687
|
+
}
|
|
1688
|
+
get(key) {
|
|
1689
|
+
var _a, _b;
|
|
1690
|
+
try {
|
|
1691
|
+
const parts = String(key).split(".");
|
|
1692
|
+
let value = this.config;
|
|
1693
|
+
for (const part of parts) {
|
|
1694
|
+
if (value === null || value === void 0 || typeof value !== "object") {
|
|
1695
|
+
return null;
|
|
1696
|
+
}
|
|
1697
|
+
value = value[part];
|
|
1698
|
+
}
|
|
1699
|
+
return value ?? null;
|
|
1700
|
+
} catch (error) {
|
|
1701
|
+
(_b = (_a = this.logger).debug) == null ? void 0 : _b.call(
|
|
1702
|
+
_a,
|
|
1703
|
+
`Failed to get config value for key ${String(key)}`,
|
|
1704
|
+
error
|
|
1705
|
+
);
|
|
1706
|
+
return null;
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
getOrDefault(key, defaultValue) {
|
|
1710
|
+
const value = this.get(key);
|
|
1711
|
+
return value !== null ? value : defaultValue;
|
|
1712
|
+
}
|
|
1713
|
+
getOrThrow(key, errorMessage) {
|
|
1714
|
+
const value = this.get(key);
|
|
1715
|
+
if (value === null) {
|
|
1716
|
+
const message = errorMessage || `Configuration value for key "${String(key)}" is not defined`;
|
|
1717
|
+
this.logger.error(message);
|
|
1718
|
+
throw new import_common.NaviosException(message);
|
|
1719
|
+
}
|
|
1720
|
+
return value;
|
|
1721
|
+
}
|
|
1722
|
+
};
|
|
1723
|
+
|
|
1724
|
+
// packages/core/src/config/config.provider.mts
|
|
1725
|
+
var ConfigProviderInjectionToken = "ConfigProvider";
|
|
1726
|
+
var ConfigProviderOptions = import_zod3.z.object({
|
|
1727
|
+
load: import_zod3.z.function()
|
|
1728
|
+
});
|
|
1729
|
+
var ConfigProvider = InjectionToken.create(ConfigProviderInjectionToken, ConfigProviderOptions);
|
|
1730
|
+
var _ConfigProviderFactory_decorators, _init4;
|
|
1731
|
+
_ConfigProviderFactory_decorators = [Injectable({
|
|
1732
|
+
token: ConfigProvider,
|
|
1733
|
+
type: "Factory" /* Factory */
|
|
1734
|
+
})];
|
|
1735
|
+
var ConfigProviderFactory = class {
|
|
1736
|
+
logger = inject(Logger, {
|
|
1737
|
+
context: "ConfigService"
|
|
1738
|
+
});
|
|
1739
|
+
async create(ctx, args) {
|
|
1740
|
+
const { load } = args;
|
|
1741
|
+
const logger = await this.logger;
|
|
1742
|
+
try {
|
|
1743
|
+
const config = await load();
|
|
1744
|
+
return new ConfigServiceInstance(config, logger);
|
|
1745
|
+
} catch (error) {
|
|
1746
|
+
logger.error("Error loading config", error);
|
|
1747
|
+
throw error;
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
};
|
|
1751
|
+
_init4 = __decoratorStart(null);
|
|
1752
|
+
ConfigProviderFactory = __decorateElement(_init4, 0, "ConfigProviderFactory", _ConfigProviderFactory_decorators, ConfigProviderFactory);
|
|
1753
|
+
__runInitializers(_init4, 1, ConfigProviderFactory);
|
|
1754
|
+
function makeConfigToken(options) {
|
|
1755
|
+
var _ConfigServiceImpl_decorators, _init9;
|
|
1756
|
+
_ConfigServiceImpl_decorators = [Injectable({
|
|
1757
|
+
type: "Factory" /* Factory */
|
|
1758
|
+
})];
|
|
1759
|
+
class ConfigServiceImpl {
|
|
1760
|
+
configService = inject(ConfigProvider, options);
|
|
1761
|
+
create() {
|
|
1762
|
+
return this.configService;
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
_init9 = __decoratorStart(null);
|
|
1766
|
+
ConfigServiceImpl = __decorateElement(_init9, 0, "ConfigServiceImpl", _ConfigServiceImpl_decorators, ConfigServiceImpl);
|
|
1767
|
+
__runInitializers(_init9, 1, ConfigServiceImpl);
|
|
1768
|
+
return getInjectableToken(ConfigServiceImpl);
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
// packages/core/src/metadata/endpoint.metadata.mts
|
|
1772
|
+
var EndpointMetadataKey = Symbol("EndpointMetadataKey");
|
|
1773
|
+
function getAllEndpointMetadata(context) {
|
|
1774
|
+
if (context.metadata) {
|
|
1775
|
+
const metadata = context.metadata[EndpointMetadataKey];
|
|
1776
|
+
if (metadata) {
|
|
1777
|
+
return metadata;
|
|
1778
|
+
} else {
|
|
1779
|
+
context.metadata[EndpointMetadataKey] = /* @__PURE__ */ new Set();
|
|
1780
|
+
return context.metadata[EndpointMetadataKey];
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
throw new Error("[Navios] Wrong environment.");
|
|
1784
|
+
}
|
|
1785
|
+
function getEndpointMetadata(target, context) {
|
|
1786
|
+
if (context.metadata) {
|
|
1787
|
+
const metadata = getAllEndpointMetadata(context);
|
|
1788
|
+
if (metadata) {
|
|
1789
|
+
const endpointMetadata = Array.from(metadata).find(
|
|
1790
|
+
(item) => item.classMethod === target.name
|
|
1791
|
+
);
|
|
1792
|
+
if (endpointMetadata) {
|
|
1793
|
+
return endpointMetadata;
|
|
1794
|
+
} else {
|
|
1795
|
+
const newMetadata = {
|
|
1796
|
+
classMethod: target.name,
|
|
1797
|
+
url: "",
|
|
1798
|
+
httpMethod: "GET",
|
|
1799
|
+
config: null,
|
|
1800
|
+
guards: /* @__PURE__ */ new Set(),
|
|
1801
|
+
customAttributes: /* @__PURE__ */ new Map()
|
|
1802
|
+
};
|
|
1803
|
+
metadata.add(newMetadata);
|
|
1804
|
+
return newMetadata;
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
throw new Error("[Navios] Wrong environment.");
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1811
|
+
// packages/core/src/metadata/controller.metadata.mts
|
|
1812
|
+
var ControllerMetadataKey = Symbol("ControllerMetadataKey");
|
|
1813
|
+
function getControllerMetadata(target, context) {
|
|
1814
|
+
if (context.metadata) {
|
|
1815
|
+
const metadata = context.metadata[ControllerMetadataKey];
|
|
1816
|
+
if (metadata) {
|
|
1817
|
+
return metadata;
|
|
1818
|
+
} else {
|
|
1819
|
+
const endpointsMetadata = getAllEndpointMetadata(context);
|
|
1820
|
+
const newMetadata = {
|
|
1821
|
+
endpoints: endpointsMetadata,
|
|
1822
|
+
guards: /* @__PURE__ */ new Set(),
|
|
1823
|
+
customAttributes: /* @__PURE__ */ new Map()
|
|
1824
|
+
};
|
|
1825
|
+
context.metadata[ControllerMetadataKey] = newMetadata;
|
|
1826
|
+
target[ControllerMetadataKey] = newMetadata;
|
|
1827
|
+
return newMetadata;
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
throw new Error("[Navios] Wrong environment.");
|
|
1831
|
+
}
|
|
1832
|
+
function extractControllerMetadata(target) {
|
|
1833
|
+
const metadata = target[ControllerMetadataKey];
|
|
1834
|
+
if (!metadata) {
|
|
1835
|
+
throw new Error(
|
|
1836
|
+
"[Navios] Controller metadata not found. Make sure to use @Controller decorator."
|
|
1837
|
+
);
|
|
1838
|
+
}
|
|
1839
|
+
return metadata;
|
|
1840
|
+
}
|
|
1841
|
+
function hasControllerMetadata(target) {
|
|
1842
|
+
const metadata = target[ControllerMetadataKey];
|
|
1843
|
+
return !!metadata;
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
// packages/core/src/metadata/module.metadata.mts
|
|
1847
|
+
var ModuleMetadataKey = Symbol("ControllerMetadataKey");
|
|
1848
|
+
function getModuleMetadata(target, context) {
|
|
1849
|
+
if (context.metadata) {
|
|
1850
|
+
const metadata = context.metadata[ModuleMetadataKey];
|
|
1851
|
+
if (metadata) {
|
|
1852
|
+
return metadata;
|
|
1853
|
+
} else {
|
|
1854
|
+
const newMetadata = {
|
|
1855
|
+
controllers: /* @__PURE__ */ new Set(),
|
|
1856
|
+
imports: /* @__PURE__ */ new Set(),
|
|
1857
|
+
guards: /* @__PURE__ */ new Set(),
|
|
1858
|
+
customAttributes: /* @__PURE__ */ new Map()
|
|
1859
|
+
};
|
|
1860
|
+
context.metadata[ModuleMetadataKey] = newMetadata;
|
|
1861
|
+
target[ModuleMetadataKey] = newMetadata;
|
|
1862
|
+
return newMetadata;
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
throw new Error("[Navios] Wrong environment.");
|
|
1866
|
+
}
|
|
1867
|
+
function extractModuleMetadata(target) {
|
|
1868
|
+
const metadata = target[ModuleMetadataKey];
|
|
1869
|
+
if (!metadata) {
|
|
1870
|
+
throw new Error(
|
|
1871
|
+
"[Navios] Module metadata not found. Make sure to use @Module decorator."
|
|
1872
|
+
);
|
|
1873
|
+
}
|
|
1874
|
+
return metadata;
|
|
1875
|
+
}
|
|
1876
|
+
function hasModuleMetadata(target) {
|
|
1877
|
+
return !!target[ModuleMetadataKey];
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1080
1880
|
// packages/core/src/decorators/controller.decorator.mts
|
|
1081
1881
|
function Controller({ guards } = {}) {
|
|
1082
1882
|
return function(target, context) {
|
|
@@ -1306,7 +2106,7 @@ var ExecutionContext2 = class {
|
|
|
1306
2106
|
};
|
|
1307
2107
|
|
|
1308
2108
|
// packages/core/src/services/guard-runner.service.mts
|
|
1309
|
-
var _GuardRunnerService_decorators,
|
|
2109
|
+
var _GuardRunnerService_decorators, _init5;
|
|
1310
2110
|
_GuardRunnerService_decorators = [Injectable()];
|
|
1311
2111
|
var GuardRunnerService = class {
|
|
1312
2112
|
async runGuards(allGuards, executionContext) {
|
|
@@ -1369,15 +2169,18 @@ var GuardRunnerService = class {
|
|
|
1369
2169
|
return guards;
|
|
1370
2170
|
}
|
|
1371
2171
|
};
|
|
1372
|
-
|
|
1373
|
-
GuardRunnerService = __decorateElement(
|
|
1374
|
-
__runInitializers(
|
|
2172
|
+
_init5 = __decoratorStart(null);
|
|
2173
|
+
GuardRunnerService = __decorateElement(_init5, 0, "GuardRunnerService", _GuardRunnerService_decorators, GuardRunnerService);
|
|
2174
|
+
__runInitializers(_init5, 1, GuardRunnerService);
|
|
1375
2175
|
|
|
1376
2176
|
// packages/core/src/services/controller-adapter.service.mts
|
|
1377
|
-
var _ControllerAdapterService_decorators,
|
|
2177
|
+
var _ControllerAdapterService_decorators, _init6;
|
|
1378
2178
|
_ControllerAdapterService_decorators = [Injectable()];
|
|
1379
|
-
var
|
|
2179
|
+
var _ControllerAdapterService = class _ControllerAdapterService {
|
|
1380
2180
|
guardRunner = syncInject(GuardRunnerService);
|
|
2181
|
+
logger = syncInject(Logger, {
|
|
2182
|
+
context: _ControllerAdapterService.name
|
|
2183
|
+
});
|
|
1381
2184
|
setupController(controller, instance, moduleMetadata) {
|
|
1382
2185
|
const controllerMetadata = extractControllerMetadata(controller);
|
|
1383
2186
|
for (const endpoint of controllerMetadata.endpoints) {
|
|
@@ -1472,17 +2275,24 @@ var ControllerAdapterService = class {
|
|
|
1472
2275
|
}
|
|
1473
2276
|
}
|
|
1474
2277
|
});
|
|
2278
|
+
this.logger.debug(
|
|
2279
|
+
`Registered ${httpMethod} ${url} for ${controller.name}:${classMethod}`
|
|
2280
|
+
);
|
|
1475
2281
|
}
|
|
1476
2282
|
}
|
|
1477
2283
|
};
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
__runInitializers(
|
|
2284
|
+
_init6 = __decoratorStart(null);
|
|
2285
|
+
_ControllerAdapterService = __decorateElement(_init6, 0, "ControllerAdapterService", _ControllerAdapterService_decorators, _ControllerAdapterService);
|
|
2286
|
+
__runInitializers(_init6, 1, _ControllerAdapterService);
|
|
2287
|
+
var ControllerAdapterService = _ControllerAdapterService;
|
|
1481
2288
|
|
|
1482
2289
|
// packages/core/src/services/module-loader.service.mts
|
|
1483
|
-
var _ModuleLoaderService_decorators,
|
|
2290
|
+
var _ModuleLoaderService_decorators, _init7;
|
|
1484
2291
|
_ModuleLoaderService_decorators = [Injectable()];
|
|
1485
|
-
var
|
|
2292
|
+
var _ModuleLoaderService = class _ModuleLoaderService {
|
|
2293
|
+
logger = syncInject(Logger, {
|
|
2294
|
+
context: _ModuleLoaderService.name
|
|
2295
|
+
});
|
|
1486
2296
|
modulesMetadata = /* @__PURE__ */ new Map();
|
|
1487
2297
|
loadedModules = /* @__PURE__ */ new Map();
|
|
1488
2298
|
initialized = false;
|
|
@@ -1512,6 +2322,7 @@ var ModuleLoaderService = class {
|
|
|
1512
2322
|
if (instance.onModuleInit) {
|
|
1513
2323
|
await instance.onModuleInit();
|
|
1514
2324
|
}
|
|
2325
|
+
this.logger.debug(`Module ${moduleName} loaded`);
|
|
1515
2326
|
this.loadedModules.set(moduleName, instance);
|
|
1516
2327
|
}
|
|
1517
2328
|
mergeMetadata(metadata, parentMetadata) {
|
|
@@ -1533,9 +2344,10 @@ var ModuleLoaderService = class {
|
|
|
1533
2344
|
return this.modulesMetadata;
|
|
1534
2345
|
}
|
|
1535
2346
|
};
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
__runInitializers(
|
|
2347
|
+
_init7 = __decoratorStart(null);
|
|
2348
|
+
_ModuleLoaderService = __decorateElement(_init7, 0, "ModuleLoaderService", _ModuleLoaderService_decorators, _ModuleLoaderService);
|
|
2349
|
+
__runInitializers(_init7, 1, _ModuleLoaderService);
|
|
2350
|
+
var ModuleLoaderService = _ModuleLoaderService;
|
|
1539
2351
|
|
|
1540
2352
|
// packages/core/src/attribute.factory.mts
|
|
1541
2353
|
var AttributeFactory = class {
|
|
@@ -1598,11 +2410,14 @@ var AttributeFactory = class {
|
|
|
1598
2410
|
var import_cors = __toESM(require("@fastify/cors"), 1);
|
|
1599
2411
|
var import_fastify = require("fastify");
|
|
1600
2412
|
var import_fastify_type_provider_zod = require("fastify-type-provider-zod");
|
|
1601
|
-
var _NaviosApplication_decorators,
|
|
2413
|
+
var _NaviosApplication_decorators, _init8;
|
|
1602
2414
|
_NaviosApplication_decorators = [Injectable()];
|
|
1603
|
-
var
|
|
2415
|
+
var _NaviosApplication = class _NaviosApplication {
|
|
1604
2416
|
moduleLoader = syncInject(ModuleLoaderService);
|
|
1605
2417
|
controllerAdapter = syncInject(ControllerAdapterService);
|
|
2418
|
+
logger = syncInject(Logger, {
|
|
2419
|
+
context: _NaviosApplication.name
|
|
2420
|
+
});
|
|
1606
2421
|
server = null;
|
|
1607
2422
|
corsOptions = null;
|
|
1608
2423
|
globalPrefix = null;
|
|
@@ -1617,40 +2432,72 @@ var NaviosApplication = class {
|
|
|
1617
2432
|
throw new Error("App module is not set. Call setAppModule() first.");
|
|
1618
2433
|
}
|
|
1619
2434
|
await this.moduleLoader.loadModules(this.appModule);
|
|
1620
|
-
this.server =
|
|
2435
|
+
this.server = await this.getFastifyInstance(this.options);
|
|
1621
2436
|
getServiceLocator().registerInstance(Application, this.server);
|
|
1622
2437
|
this.server.setValidatorCompiler(import_fastify_type_provider_zod.validatorCompiler);
|
|
1623
2438
|
this.server.setSerializerCompiler(import_fastify_type_provider_zod.serializerCompiler);
|
|
1624
2439
|
if (this.corsOptions) {
|
|
1625
2440
|
await this.server.register(import_cors.default, this.corsOptions);
|
|
1626
2441
|
}
|
|
2442
|
+
await this.initModules();
|
|
2443
|
+
this.logger.debug("Navios application initialized");
|
|
2444
|
+
}
|
|
2445
|
+
async getFastifyInstance(rawOptions) {
|
|
2446
|
+
const { logger, ...options } = rawOptions;
|
|
2447
|
+
if (logger) {
|
|
2448
|
+
const fastifyOptions = options;
|
|
2449
|
+
if (typeof logger === "boolean") {
|
|
2450
|
+
if (!logger) {
|
|
2451
|
+
fastifyOptions.logger = false;
|
|
2452
|
+
}
|
|
2453
|
+
} else {
|
|
2454
|
+
fastifyOptions.loggerInstance = new PinoWrapper(
|
|
2455
|
+
await inject(Logger, {
|
|
2456
|
+
context: "FastifyAdapter"
|
|
2457
|
+
})
|
|
2458
|
+
);
|
|
2459
|
+
}
|
|
2460
|
+
return (0, import_fastify.fastify)(fastifyOptions);
|
|
2461
|
+
} else {
|
|
2462
|
+
return (0, import_fastify.fastify)({
|
|
2463
|
+
...options,
|
|
2464
|
+
loggerInstance: new PinoWrapper(
|
|
2465
|
+
await inject(Logger, {
|
|
2466
|
+
context: "FastifyAdapter"
|
|
2467
|
+
})
|
|
2468
|
+
)
|
|
2469
|
+
});
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
async initModules() {
|
|
1627
2473
|
const modules = this.moduleLoader.getAllModules();
|
|
1628
|
-
const
|
|
2474
|
+
const promises = [];
|
|
1629
2475
|
for (const [moduleName, moduleMetadata] of modules) {
|
|
1630
2476
|
if (!moduleMetadata.controllers || moduleMetadata.controllers.size === 0) {
|
|
1631
2477
|
continue;
|
|
1632
2478
|
}
|
|
1633
|
-
|
|
1634
|
-
(
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
2479
|
+
promises.push(
|
|
2480
|
+
this.server.register(
|
|
2481
|
+
(instance, opts, done) => {
|
|
2482
|
+
for (const controller of moduleMetadata.controllers) {
|
|
2483
|
+
this.controllerAdapter.setupController(
|
|
2484
|
+
controller,
|
|
2485
|
+
instance,
|
|
2486
|
+
moduleMetadata
|
|
2487
|
+
);
|
|
2488
|
+
}
|
|
2489
|
+
done();
|
|
2490
|
+
},
|
|
2491
|
+
{
|
|
2492
|
+
prefix: this.globalPrefix ?? ""
|
|
1641
2493
|
}
|
|
1642
|
-
|
|
1643
|
-
},
|
|
1644
|
-
{
|
|
1645
|
-
prefix: globalPrefix
|
|
1646
|
-
}
|
|
2494
|
+
)
|
|
1647
2495
|
);
|
|
1648
2496
|
}
|
|
2497
|
+
await Promise.all(promises);
|
|
1649
2498
|
}
|
|
1650
2499
|
enableCors(options) {
|
|
1651
|
-
var _a;
|
|
1652
2500
|
this.corsOptions = options;
|
|
1653
|
-
(_a = this.server) == null ? void 0 : _a.register;
|
|
1654
2501
|
}
|
|
1655
2502
|
setGlobalPrefix(prefix) {
|
|
1656
2503
|
this.globalPrefix = prefix;
|
|
@@ -1668,24 +2515,41 @@ var NaviosApplication = class {
|
|
|
1668
2515
|
await this.server.listen(options);
|
|
1669
2516
|
}
|
|
1670
2517
|
};
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
__runInitializers(
|
|
2518
|
+
_init8 = __decoratorStart(null);
|
|
2519
|
+
_NaviosApplication = __decorateElement(_init8, 0, "NaviosApplication", _NaviosApplication_decorators, _NaviosApplication);
|
|
2520
|
+
__runInitializers(_init8, 1, _NaviosApplication);
|
|
2521
|
+
var NaviosApplication = _NaviosApplication;
|
|
1674
2522
|
|
|
1675
2523
|
// packages/core/src/navios.factory.mts
|
|
1676
2524
|
var NaviosFactory = class {
|
|
1677
2525
|
static async create(appModule, options = {}) {
|
|
1678
2526
|
const app = await inject(NaviosApplication);
|
|
2527
|
+
this.registerLoggerConfiguration(options);
|
|
1679
2528
|
app.setup(appModule, options);
|
|
1680
2529
|
return app;
|
|
1681
2530
|
}
|
|
2531
|
+
static registerLoggerConfiguration(options) {
|
|
2532
|
+
if (!options) {
|
|
2533
|
+
return;
|
|
2534
|
+
}
|
|
2535
|
+
const { logger } = options;
|
|
2536
|
+
if (logger !== true && !isNil(logger)) {
|
|
2537
|
+
LoggerInstance.overrideLogger(logger);
|
|
2538
|
+
}
|
|
2539
|
+
}
|
|
1682
2540
|
};
|
|
1683
2541
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1684
2542
|
0 && (module.exports = {
|
|
1685
2543
|
Application,
|
|
1686
2544
|
AttributeFactory,
|
|
1687
2545
|
BadRequestException,
|
|
2546
|
+
ConfigProvider,
|
|
2547
|
+
ConfigProviderFactory,
|
|
2548
|
+
ConfigProviderInjectionToken,
|
|
2549
|
+
ConfigProviderOptions,
|
|
2550
|
+
ConfigServiceInstance,
|
|
1688
2551
|
ConflictException,
|
|
2552
|
+
ConsoleLogger,
|
|
1689
2553
|
Controller,
|
|
1690
2554
|
ControllerAdapterService,
|
|
1691
2555
|
ControllerMetadataKey,
|
|
@@ -1709,12 +2573,19 @@ var NaviosFactory = class {
|
|
|
1709
2573
|
InstanceExpired,
|
|
1710
2574
|
InstanceNotFound,
|
|
1711
2575
|
InternalServerErrorException,
|
|
2576
|
+
LOG_LEVELS,
|
|
2577
|
+
Logger,
|
|
2578
|
+
LoggerFactory,
|
|
2579
|
+
LoggerInjectionToken,
|
|
2580
|
+
LoggerInstance,
|
|
2581
|
+
LoggerOptions,
|
|
1712
2582
|
Module,
|
|
1713
2583
|
ModuleLoaderService,
|
|
1714
2584
|
ModuleMetadataKey,
|
|
1715
2585
|
NaviosApplication,
|
|
1716
2586
|
NaviosFactory,
|
|
1717
2587
|
NotFoundException,
|
|
2588
|
+
PinoWrapper,
|
|
1718
2589
|
Reply,
|
|
1719
2590
|
Request,
|
|
1720
2591
|
ServiceLocator,
|
|
@@ -1725,8 +2596,13 @@ var NaviosFactory = class {
|
|
|
1725
2596
|
UnauthorizedException,
|
|
1726
2597
|
UnknownError,
|
|
1727
2598
|
UseGuards,
|
|
2599
|
+
addLeadingSlash,
|
|
2600
|
+
clc,
|
|
2601
|
+
envInt,
|
|
2602
|
+
envString,
|
|
1728
2603
|
extractControllerMetadata,
|
|
1729
2604
|
extractModuleMetadata,
|
|
2605
|
+
filterLogLevels,
|
|
1730
2606
|
getAllEndpointMetadata,
|
|
1731
2607
|
getControllerMetadata,
|
|
1732
2608
|
getEndpointMetadata,
|
|
@@ -1736,9 +2612,25 @@ var NaviosFactory = class {
|
|
|
1736
2612
|
hasControllerMetadata,
|
|
1737
2613
|
hasModuleMetadata,
|
|
1738
2614
|
inject,
|
|
2615
|
+
isConstructor,
|
|
2616
|
+
isEmpty,
|
|
2617
|
+
isFunction,
|
|
2618
|
+
isLogLevel,
|
|
2619
|
+
isLogLevelEnabled,
|
|
2620
|
+
isNil,
|
|
2621
|
+
isNumber,
|
|
2622
|
+
isObject,
|
|
2623
|
+
isPlainObject,
|
|
2624
|
+
isString,
|
|
2625
|
+
isSymbol,
|
|
2626
|
+
isUndefined,
|
|
2627
|
+
makeConfigToken,
|
|
2628
|
+
normalizePath,
|
|
1739
2629
|
override,
|
|
1740
2630
|
provideServiceLocator,
|
|
1741
2631
|
setPromiseCollector,
|
|
1742
|
-
|
|
2632
|
+
stripEndSlash,
|
|
2633
|
+
syncInject,
|
|
2634
|
+
yellow
|
|
1743
2635
|
});
|
|
1744
2636
|
//# sourceMappingURL=index.js.map
|