@venizia/ignis-helpers 0.0.1-2 → 0.0.1-4
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/LICENSE.md +102 -0
- package/README.md +43 -0
- package/dist/common/constants/app.d.ts +1 -1
- package/dist/common/constants/app.js +8 -8
- package/dist/common/constants/http.d.ts +1 -1
- package/dist/common/constants/http.js +13 -13
- package/dist/common/constants/index.d.ts +3 -3
- package/dist/common/constants/mime.d.ts +1 -1
- package/dist/common/constants/mime.js +4 -4
- package/dist/common/index.d.ts +2 -2
- package/dist/common/types.d.ts +13 -13
- package/dist/common/types.js +2 -2
- package/dist/helpers/base.d.ts +1 -1
- package/dist/helpers/base.js +3 -3
- package/dist/helpers/cron/cron.helper.d.ts +2 -2
- package/dist/helpers/cron/cron.helper.js +2 -2
- package/dist/helpers/cron/index.d.ts +1 -1
- package/dist/helpers/crypto/algorithms/aes.algorithm.d.ts +3 -3
- package/dist/helpers/crypto/algorithms/aes.algorithm.js +10 -10
- package/dist/helpers/crypto/algorithms/base.algorithm.d.ts +2 -2
- package/dist/helpers/crypto/algorithms/base.algorithm.js +1 -1
- package/dist/helpers/crypto/algorithms/index.d.ts +3 -3
- package/dist/helpers/crypto/algorithms/rsa.algorithm.d.ts +3 -3
- package/dist/helpers/crypto/algorithms/rsa.algorithm.js +10 -10
- package/dist/helpers/crypto/common/index.d.ts +2 -2
- package/dist/helpers/crypto/index.d.ts +2 -2
- package/dist/helpers/env/app-env.d.ts +1 -1
- package/dist/helpers/env/app-env.js +9 -9
- package/dist/helpers/env/index.d.ts +2 -2
- package/dist/helpers/error/app-error.d.ts +1 -1
- package/dist/helpers/error/index.d.ts +2 -2
- package/dist/helpers/error/types.d.ts +1 -1
- package/dist/helpers/error/types.js +5 -5
- package/dist/helpers/index.d.ts +14 -14
- package/dist/helpers/inversion/common/index.d.ts +2 -2
- package/dist/helpers/inversion/common/keys.js +6 -6
- package/dist/helpers/inversion/common/types.d.ts +4 -4
- package/dist/helpers/inversion/container.d.ts +2 -2
- package/dist/helpers/inversion/index.d.ts +4 -4
- package/dist/helpers/inversion/registry.d.ts +2 -2
- package/dist/helpers/logger/application-logger.d.ts +2 -2
- package/dist/helpers/logger/application-logger.js +8 -8
- package/dist/helpers/logger/default-logger.d.ts +3 -3
- package/dist/helpers/logger/default-logger.js +23 -23
- package/dist/helpers/logger/factory.d.ts +1 -1
- package/dist/helpers/logger/factory.js +1 -1
- package/dist/helpers/logger/index.d.ts +5 -5
- package/dist/helpers/logger/transports/dgram.transport.d.ts +2 -2
- package/dist/helpers/logger/transports/dgram.transport.js +5 -5
- package/dist/helpers/logger/transports/index.d.ts +1 -1
- package/dist/helpers/logger/types.d.ts +1 -1
- package/dist/helpers/logger/types.js +9 -9
- package/dist/helpers/network/http-request/base-network-request.helper.d.ts +12 -12
- package/dist/helpers/network/http-request/base-network-request.helper.js +10 -10
- package/dist/helpers/network/http-request/fetcher/axios-fetcher.d.ts +5 -5
- package/dist/helpers/network/http-request/fetcher/axios-fetcher.js +5 -5
- package/dist/helpers/network/http-request/fetcher/base-fetcher.d.ts +1 -1
- package/dist/helpers/network/http-request/fetcher/base-fetcher.js +8 -8
- package/dist/helpers/network/http-request/fetcher/index.d.ts +3 -3
- package/dist/helpers/network/http-request/fetcher/node-fetcher.d.ts +2 -2
- package/dist/helpers/network/http-request/fetcher/node-fetcher.js +6 -6
- package/dist/helpers/network/http-request/index.d.ts +2 -2
- package/dist/helpers/network/http-request/types.d.ts +4 -4
- package/dist/helpers/network/index.d.ts +3 -3
- package/dist/helpers/network/tcp-socket/base-tcp-client.helper.d.ts +4 -4
- package/dist/helpers/network/tcp-socket/base-tcp-client.helper.js +17 -17
- package/dist/helpers/network/tcp-socket/base-tcp-server.helper.d.ts +6 -6
- package/dist/helpers/network/tcp-socket/base-tcp-server.helper.js +18 -18
- package/dist/helpers/network/tcp-socket/index.d.ts +6 -6
- package/dist/helpers/network/tcp-socket/network-tcp-client.helper.d.ts +4 -4
- package/dist/helpers/network/tcp-socket/network-tcp-server.helper.d.ts +4 -4
- package/dist/helpers/network/tcp-socket/network-tls-tcp-client.helper.d.ts +4 -4
- package/dist/helpers/network/tcp-socket/network-tls-tcp-server.helper.d.ts +4 -4
- package/dist/helpers/network/udp-socket/index.d.ts +1 -1
- package/dist/helpers/network/udp-socket/network-udp-client.helper.d.ts +3 -3
- package/dist/helpers/network/udp-socket/network-udp-client.helper.js +14 -14
- package/dist/helpers/queue/bullmq/helper.d.ts +4 -4
- package/dist/helpers/queue/bullmq/helper.js +10 -10
- package/dist/helpers/queue/bullmq/index.d.ts +1 -1
- package/dist/helpers/queue/common/index.d.ts +1 -1
- package/dist/helpers/queue/common/types.d.ts +1 -1
- package/dist/helpers/queue/index.d.ts +4 -4
- package/dist/helpers/queue/internal/helper.d.ts +3 -3
- package/dist/helpers/queue/internal/helper.js +11 -11
- package/dist/helpers/queue/internal/index.d.ts +1 -1
- package/dist/helpers/queue/mqtt/helper.d.ts +2 -2
- package/dist/helpers/queue/mqtt/helper.js +8 -8
- package/dist/helpers/queue/mqtt/index.d.ts +1 -1
- package/dist/helpers/redis/cluster.helper.d.ts +3 -3
- package/dist/helpers/redis/default.helper.d.ts +3 -3
- package/dist/helpers/redis/default.helper.js +40 -40
- package/dist/helpers/redis/index.d.ts +4 -4
- package/dist/helpers/redis/single.helper.d.ts +3 -3
- package/dist/helpers/redis/types.d.ts +3 -3
- package/dist/helpers/socket-io/client/helper.d.ts +3 -3
- package/dist/helpers/socket-io/client/helper.js +8 -8
- package/dist/helpers/socket-io/client/index.d.ts +1 -1
- package/dist/helpers/socket-io/common/constants.js +10 -10
- package/dist/helpers/socket-io/common/index.d.ts +2 -2
- package/dist/helpers/socket-io/common/types.d.ts +6 -6
- package/dist/helpers/socket-io/index.d.ts +3 -3
- package/dist/helpers/socket-io/server/helper.d.ts +3 -3
- package/dist/helpers/socket-io/server/helper.js +41 -41
- package/dist/helpers/socket-io/server/index.d.ts +1 -1
- package/dist/helpers/storage/in-memory/helper.d.ts +2 -2
- package/dist/helpers/storage/in-memory/index.d.ts +1 -1
- package/dist/helpers/storage/index.d.ts +2 -2
- package/dist/helpers/storage/minio/helper.d.ts +3 -3
- package/dist/helpers/storage/minio/helper.js +7 -7
- package/dist/helpers/storage/minio/index.d.ts +1 -1
- package/dist/helpers/testing/base-test-plan.d.ts +2 -2
- package/dist/helpers/testing/base-test-plan.js +4 -4
- package/dist/helpers/testing/common/constants.d.ts +1 -1
- package/dist/helpers/testing/common/constants.js +3 -3
- package/dist/helpers/testing/common/index.d.ts +2 -2
- package/dist/helpers/testing/common/types.d.ts +3 -3
- package/dist/helpers/testing/describe.d.ts +2 -2
- package/dist/helpers/testing/describe.js +5 -5
- package/dist/helpers/testing/index.d.ts +6 -6
- package/dist/helpers/testing/test-case.d.ts +3 -3
- package/dist/helpers/testing/test-case.js +1 -1
- package/dist/helpers/testing/test-handler.d.ts +3 -3
- package/dist/helpers/testing/test-handler.js +2 -2
- package/dist/helpers/testing/test-plan.d.ts +2 -2
- package/dist/helpers/worker-thread/base.d.ts +6 -6
- package/dist/helpers/worker-thread/base.js +15 -15
- package/dist/helpers/worker-thread/base.js.map +1 -1
- package/dist/helpers/worker-thread/index.d.ts +4 -4
- package/dist/helpers/worker-thread/types.d.ts +2 -2
- package/dist/helpers/worker-thread/worker-bus.d.ts +4 -4
- package/dist/helpers/worker-thread/worker-bus.d.ts.map +1 -1
- package/dist/helpers/worker-thread/worker-bus.js +14 -9
- package/dist/helpers/worker-thread/worker-bus.js.map +1 -1
- package/dist/helpers/worker-thread/worker-pool.d.ts +2 -2
- package/dist/helpers/worker-thread/worker-pool.js +6 -6
- package/dist/index.d.ts +4 -4
- package/dist/utilities/crypto.utility.d.ts +1 -1
- package/dist/utilities/crypto.utility.js +2 -2
- package/dist/utilities/date.utility.d.ts +1 -1
- package/dist/utilities/date.utility.js +6 -6
- package/dist/utilities/index.d.ts +7 -7
- package/dist/utilities/module.utility.js +2 -2
- package/dist/utilities/parse.utility.js +18 -18
- package/dist/utilities/performance.utility.d.ts +1 -1
- package/dist/utilities/performance.utility.js +5 -5
- package/dist/utilities/promise.utility.d.ts +1 -1
- package/dist/utilities/promise.utility.js +3 -3
- package/dist/utilities/request.utility.d.ts +1 -1
- package/dist/utilities/request.utility.js +7 -7
- package/package.json +23 -29
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.applicationEnvironment = exports.ApplicationEnvironment = exports.Environment = void 0;
|
|
4
4
|
class Environment {
|
|
5
|
-
static { this.LOCAL =
|
|
6
|
-
static { this.DEBUG =
|
|
7
|
-
static { this.DEVELOPMENT =
|
|
8
|
-
static { this.ALPHA =
|
|
9
|
-
static { this.BETA =
|
|
10
|
-
static { this.STAGING =
|
|
11
|
-
static { this.PRODUCTION =
|
|
5
|
+
static { this.LOCAL = 'local'; }
|
|
6
|
+
static { this.DEBUG = 'debug'; }
|
|
7
|
+
static { this.DEVELOPMENT = 'development'; }
|
|
8
|
+
static { this.ALPHA = 'alpha'; }
|
|
9
|
+
static { this.BETA = 'beta'; }
|
|
10
|
+
static { this.STAGING = 'staging'; }
|
|
11
|
+
static { this.PRODUCTION = 'production'; }
|
|
12
12
|
static { this.COMMON_ENVS = new Set([
|
|
13
13
|
this.LOCAL,
|
|
14
14
|
this.DEBUG,
|
|
@@ -44,7 +44,7 @@ class ApplicationEnvironment {
|
|
|
44
44
|
this.arguments[key] = value;
|
|
45
45
|
}
|
|
46
46
|
isDevelopment() {
|
|
47
|
-
return process.env.NODE_ENV ===
|
|
47
|
+
return process.env.NODE_ENV === 'development';
|
|
48
48
|
}
|
|
49
49
|
keys() {
|
|
50
50
|
return Object.keys(this.arguments);
|
|
@@ -52,7 +52,7 @@ class ApplicationEnvironment {
|
|
|
52
52
|
}
|
|
53
53
|
exports.ApplicationEnvironment = ApplicationEnvironment;
|
|
54
54
|
exports.applicationEnvironment = new ApplicationEnvironment({
|
|
55
|
-
prefix: process.env.APPLICATION_ENV_PREFIX ??
|
|
55
|
+
prefix: process.env.APPLICATION_ENV_PREFIX ?? 'APP_ENV',
|
|
56
56
|
envs: process.env,
|
|
57
57
|
});
|
|
58
58
|
//# sourceMappingURL=app-env.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './app-env';
|
|
2
|
+
export * from './types';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './app-error';
|
|
2
|
+
export * from './types';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -11,12 +11,12 @@ exports.ErrorSchema = zod_openapi_1.z
|
|
|
11
11
|
})
|
|
12
12
|
.catchall(zod_openapi_1.z.any())
|
|
13
13
|
.openapi({
|
|
14
|
-
description:
|
|
14
|
+
description: 'Error Schema',
|
|
15
15
|
example: {
|
|
16
|
-
name:
|
|
17
|
-
statusCode:
|
|
18
|
-
messageCode:
|
|
19
|
-
message:
|
|
16
|
+
name: 'ErrorName',
|
|
17
|
+
statusCode: '4xx | 5xx',
|
|
18
|
+
messageCode: 'app.example.error_code',
|
|
19
|
+
message: 'Example Message',
|
|
20
20
|
},
|
|
21
21
|
});
|
|
22
22
|
//# sourceMappingURL=types.js.map
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
13
|
-
export * from
|
|
14
|
-
export * from
|
|
1
|
+
export * from './base';
|
|
2
|
+
export * from './cron';
|
|
3
|
+
export * from './crypto';
|
|
4
|
+
export * from './env';
|
|
5
|
+
export * from './error';
|
|
6
|
+
export * from './inversion';
|
|
7
|
+
export * from './logger';
|
|
8
|
+
export * from './network';
|
|
9
|
+
export * from './queue';
|
|
10
|
+
export * from './redis';
|
|
11
|
+
export * from './socket-io';
|
|
12
|
+
export * from './storage';
|
|
13
|
+
export * from './testing';
|
|
14
|
+
export * from './worker-thread';
|
|
15
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './keys';
|
|
2
|
+
export * from './types';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -4,13 +4,13 @@ exports.MetadataKeys = void 0;
|
|
|
4
4
|
const ignis_inversion_1 = require("@venizia/ignis-inversion");
|
|
5
5
|
exports.MetadataKeys = Object.assign({}, ignis_inversion_1.MetadataKeys, {
|
|
6
6
|
// Controller metadata
|
|
7
|
-
CONTROLLER: Symbol.for(
|
|
8
|
-
CONTROLLER_ROUTE: Symbol.for(
|
|
7
|
+
CONTROLLER: Symbol.for('ignis:controller'),
|
|
8
|
+
CONTROLLER_ROUTE: Symbol.for('ignis:controller:route'),
|
|
9
9
|
// Model metadata
|
|
10
|
-
MODEL: Symbol.for(
|
|
11
|
-
DATASOURCE: Symbol.for(
|
|
12
|
-
REPOSITORY: Symbol.for(
|
|
10
|
+
MODEL: Symbol.for('ignis:model'),
|
|
11
|
+
DATASOURCE: Symbol.for('ignis:datasource'),
|
|
12
|
+
REPOSITORY: Symbol.for('ignis:repository'),
|
|
13
13
|
// Injection metadata
|
|
14
|
-
INJECTABLE: Symbol.for(
|
|
14
|
+
INJECTABLE: Symbol.for('ignis:injectable'),
|
|
15
15
|
});
|
|
16
16
|
//# sourceMappingURL=keys.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { TAuthStrategy } from
|
|
2
|
-
import { RouteConfig } from
|
|
3
|
-
import { IInjectMetadata as _IInjectMetadata, IPropertyMetadata as _IPropertyMetadata, TBindingScope } from
|
|
1
|
+
import type { TAuthStrategy } from '../../../common/types';
|
|
2
|
+
import { RouteConfig } from '@hono/zod-openapi';
|
|
3
|
+
import { IInjectMetadata as _IInjectMetadata, IPropertyMetadata as _IPropertyMetadata, TBindingScope } from '@venizia/ignis-inversion';
|
|
4
4
|
export type TRouteMetadata = RouteConfig & {
|
|
5
5
|
authStrategies?: readonly TAuthStrategy[];
|
|
6
6
|
};
|
|
@@ -18,7 +18,7 @@ export interface IInjectableMetadata {
|
|
|
18
18
|
tags?: Record<string, any>;
|
|
19
19
|
}
|
|
20
20
|
export interface IModelMetadata {
|
|
21
|
-
type:
|
|
21
|
+
type: 'entity' | 'view';
|
|
22
22
|
skipMigrate?: boolean;
|
|
23
23
|
}
|
|
24
24
|
export interface IDataSourceMetadata {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Container as _Container, MetadataRegistry as _MetadataRegistry } from
|
|
2
|
-
import { ApplicationLogger } from
|
|
1
|
+
import { Container as _Container, MetadataRegistry as _MetadataRegistry } from '@venizia/ignis-inversion';
|
|
2
|
+
import { ApplicationLogger } from '../logger';
|
|
3
3
|
export declare class Container extends _Container {
|
|
4
4
|
logger: ApplicationLogger;
|
|
5
5
|
constructor(opts?: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { Binding, BindingKeys, BindingScopes, BindingValueTypes } from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export { Binding, BindingKeys, BindingScopes, BindingValueTypes } from '@venizia/ignis-inversion';
|
|
2
|
+
export * from './common';
|
|
3
|
+
export * from './container';
|
|
4
|
+
export * from './registry';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IControllerMetadata, IDataSourceMetadata, IInjectableMetadata, IModelMetadata, IRepositoryMetadata, TRouteMetadata } from
|
|
2
|
-
import { MetadataRegistry as _MetadataRegistry } from
|
|
1
|
+
import type { IControllerMetadata, IDataSourceMetadata, IInjectableMetadata, IModelMetadata, IRepositoryMetadata, TRouteMetadata } from './common';
|
|
2
|
+
import { MetadataRegistry as _MetadataRegistry } from '@venizia/ignis-inversion';
|
|
3
3
|
/**
|
|
4
4
|
* Central metadata registry for storing and retrieving decorator metadata
|
|
5
5
|
*/
|
|
@@ -9,7 +9,7 @@ const utilities_1 = require("../../utilities");
|
|
|
9
9
|
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
10
10
|
const default_logger_1 = require("./default-logger");
|
|
11
11
|
const env_1 = require("../env");
|
|
12
|
-
const extraLogEnvs = (process.env.APP_ENV_EXTRA_LOG_ENVS ??
|
|
12
|
+
const extraLogEnvs = (process.env.APP_ENV_EXTRA_LOG_ENVS ?? '').split(',').map(el => el.trim()) ?? [];
|
|
13
13
|
const LOG_ENVIRONMENTS = new Set([...Array.from(env_1.Environment.COMMON_ENVS), ...extraLogEnvs]);
|
|
14
14
|
const isDebug = (0, utilities_1.toBoolean)(process.env.DEBUG);
|
|
15
15
|
class Logger {
|
|
@@ -24,12 +24,12 @@ class Logger {
|
|
|
24
24
|
}
|
|
25
25
|
// ---------------------------------------------------------------------
|
|
26
26
|
_enhanceMessage(parts, message) {
|
|
27
|
-
const enhanced = parts?.reduce((prevState =
|
|
27
|
+
const enhanced = parts?.reduce((prevState = '', current) => {
|
|
28
28
|
if ((0, isEmpty_1.default)(prevState)) {
|
|
29
29
|
return current;
|
|
30
30
|
}
|
|
31
31
|
return prevState.concat(`-${current}`);
|
|
32
|
-
},
|
|
32
|
+
}, '');
|
|
33
33
|
return `[${enhanced}]${message}`;
|
|
34
34
|
}
|
|
35
35
|
// ---------------------------------------------------------------------
|
|
@@ -61,23 +61,23 @@ class Logger {
|
|
|
61
61
|
if (!isDebug) {
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
|
-
this.log(
|
|
64
|
+
this.log('debug', message, ...args);
|
|
65
65
|
}
|
|
66
66
|
// ---------------------------------------------------------------------
|
|
67
67
|
info(message, ...args) {
|
|
68
|
-
this.log(
|
|
68
|
+
this.log('info', message, ...args);
|
|
69
69
|
}
|
|
70
70
|
// ---------------------------------------------------------------------
|
|
71
71
|
warn(message, ...args) {
|
|
72
|
-
this.log(
|
|
72
|
+
this.log('warn', message, ...args);
|
|
73
73
|
}
|
|
74
74
|
// ---------------------------------------------------------------------
|
|
75
75
|
error(message, ...args) {
|
|
76
|
-
this.log(
|
|
76
|
+
this.log('error', message, ...args);
|
|
77
77
|
}
|
|
78
78
|
// ---------------------------------------------------------------------
|
|
79
79
|
emerg(message, ...args) {
|
|
80
|
-
this.log(
|
|
80
|
+
this.log('emerg', message, ...args);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
exports.Logger = Logger;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import winston from
|
|
2
|
-
import
|
|
3
|
-
import { IDgramTransportOptions } from
|
|
1
|
+
import winston from 'winston';
|
|
2
|
+
import 'winston-daily-rotate-file';
|
|
3
|
+
import { IDgramTransportOptions } from './transports';
|
|
4
4
|
export declare const defineCustomLoggerFormatter: (opts: {
|
|
5
5
|
label: string;
|
|
6
6
|
}) => winston.Logform.Format;
|
|
@@ -10,7 +10,7 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
10
10
|
const winston_1 = __importDefault(require("winston"));
|
|
11
11
|
require("winston-daily-rotate-file");
|
|
12
12
|
const transports_1 = require("./transports");
|
|
13
|
-
const LOGGER_FOLDER_PATH = process.env.APP_ENV_LOGGER_FOLDER_PATH ??
|
|
13
|
+
const LOGGER_FOLDER_PATH = process.env.APP_ENV_LOGGER_FOLDER_PATH ?? './';
|
|
14
14
|
const LOGGER_PREFIX = constants_1.Defaults.APPLICATION_NAME;
|
|
15
15
|
const f = winston_1.default.format;
|
|
16
16
|
// -------------------------------------------------------------------------------------------
|
|
@@ -35,17 +35,17 @@ const defineCustomLogger = (opts) => {
|
|
|
35
35
|
debug: 5,
|
|
36
36
|
silly: 6,
|
|
37
37
|
}, logColors = {
|
|
38
|
-
error:
|
|
39
|
-
alert:
|
|
40
|
-
emerg:
|
|
41
|
-
warn:
|
|
42
|
-
info:
|
|
43
|
-
http:
|
|
44
|
-
verbose:
|
|
45
|
-
debug:
|
|
46
|
-
silly:
|
|
38
|
+
error: 'red',
|
|
39
|
+
alert: 'red',
|
|
40
|
+
emerg: 'red',
|
|
41
|
+
warn: 'yellow',
|
|
42
|
+
info: 'green',
|
|
43
|
+
http: 'magenta',
|
|
44
|
+
verbose: 'gray',
|
|
45
|
+
debug: 'blue',
|
|
46
|
+
silly: 'gray',
|
|
47
47
|
}, loggerFormatter = exports.applicationLogFormatter, transports: { info: infoTransportOptions, error: errorTransportOptions }, } = opts;
|
|
48
|
-
const consoleLogTransport = new winston_1.default.transports.Console({ level:
|
|
48
|
+
const consoleLogTransport = new winston_1.default.transports.Console({ level: 'debug' });
|
|
49
49
|
const transports = {
|
|
50
50
|
general: [consoleLogTransport],
|
|
51
51
|
exception: [consoleLogTransport],
|
|
@@ -53,23 +53,23 @@ const defineCustomLogger = (opts) => {
|
|
|
53
53
|
// File configure
|
|
54
54
|
if (infoTransportOptions.file) {
|
|
55
55
|
const transport = new winston_1.default.transports.DailyRotateFile({
|
|
56
|
-
frequency:
|
|
57
|
-
maxSize:
|
|
58
|
-
maxFiles:
|
|
59
|
-
datePattern:
|
|
56
|
+
frequency: '1h',
|
|
57
|
+
maxSize: '100m',
|
|
58
|
+
maxFiles: '5d',
|
|
59
|
+
datePattern: 'YYYYMMDD_HH',
|
|
60
60
|
filename: node_path_1.default.join(infoTransportOptions.file.folder, `/${infoTransportOptions.file.prefix}-info-%DATE%.log`),
|
|
61
|
-
level:
|
|
61
|
+
level: 'info',
|
|
62
62
|
});
|
|
63
63
|
transports.general.push(transport);
|
|
64
64
|
}
|
|
65
65
|
if (errorTransportOptions.file) {
|
|
66
66
|
const transport = new winston_1.default.transports.DailyRotateFile({
|
|
67
|
-
frequency:
|
|
68
|
-
maxSize:
|
|
69
|
-
maxFiles:
|
|
70
|
-
datePattern:
|
|
67
|
+
frequency: '1h',
|
|
68
|
+
maxSize: '100m',
|
|
69
|
+
maxFiles: '5d',
|
|
70
|
+
datePattern: 'YYYYMMDD_HH',
|
|
71
71
|
filename: node_path_1.default.join(errorTransportOptions.file.folder, `/${errorTransportOptions.file.prefix}-error-%DATE%.log`),
|
|
72
|
-
level:
|
|
72
|
+
level: 'error',
|
|
73
73
|
});
|
|
74
74
|
transports.general.push(transport);
|
|
75
75
|
transports.exception.push(transport);
|
|
@@ -102,11 +102,11 @@ exports.defineCustomLogger = defineCustomLogger;
|
|
|
102
102
|
// -------------------------------------------------------------------------------------------
|
|
103
103
|
const fileOptions = { folder: LOGGER_FOLDER_PATH, prefix: LOGGER_PREFIX };
|
|
104
104
|
const dgramOptions = {
|
|
105
|
-
socketOptions: { type:
|
|
105
|
+
socketOptions: { type: 'udp4' },
|
|
106
106
|
host: process.env.APP_ENV_LOGGER_DGRAM_HOST,
|
|
107
107
|
port: (0, parse_utility_1.int)(process.env.APP_ENV_LOGGER_DGRAM_PORT),
|
|
108
108
|
label: process.env.APP_ENV_LOGGER_DGRAM_LABEL,
|
|
109
|
-
levels: process.env.APP_ENV_LOGGER_DGRAM_LEVELS?.split(
|
|
109
|
+
levels: process.env.APP_ENV_LOGGER_DGRAM_LEVELS?.split(',').map(el => el.trim()) ?? [],
|
|
110
110
|
};
|
|
111
111
|
// -------------------------------------------------------------------------------------------
|
|
112
112
|
exports.applicationLogger = (0, exports.defineCustomLogger)({
|
|
@@ -5,7 +5,7 @@ const application_logger_1 = require("./application-logger");
|
|
|
5
5
|
class LoggerFactory {
|
|
6
6
|
static getLogger(scopes, customLogger) {
|
|
7
7
|
const logger = customLogger ?? new application_logger_1.ApplicationLogger();
|
|
8
|
-
logger.withScope(scopes.join(
|
|
8
|
+
logger.withScope(scopes.join('-'));
|
|
9
9
|
return logger;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from './application-logger';
|
|
2
|
+
export * from './default-logger';
|
|
3
|
+
export * from './factory';
|
|
4
|
+
export * from './transports';
|
|
5
|
+
export * from './types';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import dgram from
|
|
2
|
-
import Transport from
|
|
1
|
+
import dgram from 'node:dgram';
|
|
2
|
+
import Transport from 'winston-transport';
|
|
3
3
|
export interface IDgramTransportOptions extends Transport.TransportStreamOptions {
|
|
4
4
|
label: string;
|
|
5
5
|
host: string;
|
|
@@ -31,7 +31,7 @@ class DgramTransport extends winston_transport_1.default {
|
|
|
31
31
|
}
|
|
32
32
|
establish(opts) {
|
|
33
33
|
this.client = node_dgram_1.default.createSocket(opts.socketOptions);
|
|
34
|
-
this.client.on(
|
|
34
|
+
this.client.on('error', error => {
|
|
35
35
|
this.client?.close();
|
|
36
36
|
this.client = null;
|
|
37
37
|
throw (0, error_1.getError)({
|
|
@@ -42,13 +42,13 @@ class DgramTransport extends winston_transport_1.default {
|
|
|
42
42
|
}
|
|
43
43
|
formatMessage(opts) {
|
|
44
44
|
const { timestamp, label, message, ...rest } = opts;
|
|
45
|
-
return [timestamp, `[${this.label ?? label}]`, rest[Symbol.for(
|
|
45
|
+
return [timestamp, `[${this.label ?? label}]`, rest[Symbol.for('level')], message].join(' ');
|
|
46
46
|
}
|
|
47
47
|
log(opts, callback) {
|
|
48
48
|
setImmediate(() => {
|
|
49
|
-
this.emit(
|
|
49
|
+
this.emit('logged', opts);
|
|
50
50
|
});
|
|
51
|
-
const logLevel = opts[Symbol.for(
|
|
51
|
+
const logLevel = opts[Symbol.for('level')];
|
|
52
52
|
if (!this.triggerLevels.has(logLevel)) {
|
|
53
53
|
callback();
|
|
54
54
|
return;
|
|
@@ -59,7 +59,7 @@ class DgramTransport extends winston_transport_1.default {
|
|
|
59
59
|
const message = this.formatMessage(opts);
|
|
60
60
|
this.client?.send(message, this.port, this.host, error => {
|
|
61
61
|
if (error) {
|
|
62
|
-
this.emit(
|
|
62
|
+
this.emit('error', error);
|
|
63
63
|
}
|
|
64
64
|
callback();
|
|
65
65
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './dgram.transport';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LogLevels = void 0;
|
|
4
4
|
class LogLevels {
|
|
5
|
-
static { this.ERROR =
|
|
6
|
-
static { this.ALERT =
|
|
7
|
-
static { this.EMERG =
|
|
8
|
-
static { this.WARN =
|
|
9
|
-
static { this.INFO =
|
|
10
|
-
static { this.HTTP =
|
|
11
|
-
static { this.VERBOSE =
|
|
12
|
-
static { this.DEBUG =
|
|
13
|
-
static { this.SILLY =
|
|
5
|
+
static { this.ERROR = 'error'; }
|
|
6
|
+
static { this.ALERT = 'alert'; }
|
|
7
|
+
static { this.EMERG = 'emerg'; }
|
|
8
|
+
static { this.WARN = 'warn'; }
|
|
9
|
+
static { this.INFO = 'info'; }
|
|
10
|
+
static { this.HTTP = 'http'; }
|
|
11
|
+
static { this.VERBOSE = 'verbose'; }
|
|
12
|
+
static { this.DEBUG = 'debug'; }
|
|
13
|
+
static { this.SILLY = 'silly'; }
|
|
14
14
|
static { this.SCHEME_SET = new Set([
|
|
15
15
|
this.ERROR,
|
|
16
16
|
this.ALERT,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BaseHelper } from
|
|
2
|
-
import { AnyObject } from
|
|
3
|
-
import { IFetchable, IRequestOptions } from
|
|
4
|
-
import { TFetcherResponse, TFetcherVariant } from
|
|
1
|
+
import { BaseHelper } from '../../../helpers/base';
|
|
2
|
+
import { AnyObject } from '../../../common/types';
|
|
3
|
+
import { IFetchable, IRequestOptions } from './fetcher';
|
|
4
|
+
import { TFetcherResponse, TFetcherVariant } from './types';
|
|
5
5
|
export interface IFetcherRequestOptions<T extends TFetcherVariant> {
|
|
6
6
|
name: string;
|
|
7
7
|
variant: TFetcherVariant;
|
|
@@ -13,11 +13,11 @@ export interface IFetcherRequestOptions<T extends TFetcherVariant> {
|
|
|
13
13
|
};
|
|
14
14
|
fetcher: IFetchable<T, IRequestOptions, TFetcherResponse<T>>;
|
|
15
15
|
}
|
|
16
|
-
export interface IAxiosNetworkOptions extends IFetcherRequestOptions<
|
|
17
|
-
variant:
|
|
16
|
+
export interface IAxiosNetworkOptions extends IFetcherRequestOptions<'axios'> {
|
|
17
|
+
variant: 'axios';
|
|
18
18
|
}
|
|
19
|
-
export interface INodeFetchNetworkOptions extends IFetcherRequestOptions<
|
|
20
|
-
variant:
|
|
19
|
+
export interface INodeFetchNetworkOptions extends IFetcherRequestOptions<'node-fetch'> {
|
|
20
|
+
variant: 'node-fetch';
|
|
21
21
|
}
|
|
22
22
|
export declare class BaseNetworkRequest<T extends TFetcherVariant> extends BaseHelper {
|
|
23
23
|
protected baseUrl: string;
|
|
@@ -33,10 +33,10 @@ export declare class BaseNetworkRequest<T extends TFetcherVariant> extends BaseH
|
|
|
33
33
|
getNetworkService(): IFetchable<T, IRequestOptions, TFetcherResponse<T>>;
|
|
34
34
|
getWorker(): import("./types").TFetcherWorker<T>;
|
|
35
35
|
}
|
|
36
|
-
export declare class AxiosNetworkRequest extends BaseNetworkRequest<
|
|
37
|
-
constructor(opts: Omit<IAxiosNetworkOptions,
|
|
36
|
+
export declare class AxiosNetworkRequest extends BaseNetworkRequest<'axios'> {
|
|
37
|
+
constructor(opts: Omit<IAxiosNetworkOptions, 'fetcher' | 'variant'>);
|
|
38
38
|
}
|
|
39
|
-
export declare class NodeFetchNetworkRequest extends BaseNetworkRequest<
|
|
40
|
-
constructor(opts: Omit<INodeFetchNetworkOptions,
|
|
39
|
+
export declare class NodeFetchNetworkRequest extends BaseNetworkRequest<'node-fetch'> {
|
|
40
|
+
constructor(opts: Omit<INodeFetchNetworkOptions, 'fetcher' | 'variant'>);
|
|
41
41
|
}
|
|
42
42
|
//# sourceMappingURL=base-network-request.helper.d.ts.map
|
|
@@ -14,7 +14,7 @@ class BaseNetworkRequest extends base_1.BaseHelper {
|
|
|
14
14
|
constructor(opts) {
|
|
15
15
|
super({ scope: opts.name, identifier: opts.name });
|
|
16
16
|
const { networkOptions } = opts;
|
|
17
|
-
const { baseUrl =
|
|
17
|
+
const { baseUrl = '' } = networkOptions;
|
|
18
18
|
this.baseUrl = baseUrl;
|
|
19
19
|
this.fetcher = opts.fetcher;
|
|
20
20
|
}
|
|
@@ -22,24 +22,24 @@ class BaseNetworkRequest extends base_1.BaseHelper {
|
|
|
22
22
|
const paths = opts?.paths ?? [];
|
|
23
23
|
const rs = paths
|
|
24
24
|
.map((path) => {
|
|
25
|
-
if (!path.startsWith(
|
|
25
|
+
if (!path.startsWith('/')) {
|
|
26
26
|
path = `/${path}`; // Add / to the start of url path
|
|
27
27
|
}
|
|
28
28
|
return path;
|
|
29
29
|
})
|
|
30
|
-
.join(
|
|
30
|
+
.join('');
|
|
31
31
|
return rs;
|
|
32
32
|
}
|
|
33
33
|
getRequestUrl(opts) {
|
|
34
|
-
let baseUrl = opts?.baseUrl ?? this.baseUrl ??
|
|
34
|
+
let baseUrl = opts?.baseUrl ?? this.baseUrl ?? '';
|
|
35
35
|
const paths = opts?.paths ?? [];
|
|
36
36
|
if (!baseUrl || (0, isEmpty_1.default)(baseUrl)) {
|
|
37
37
|
throw (0, error_1.getError)({
|
|
38
38
|
statusCode: 500,
|
|
39
|
-
message:
|
|
39
|
+
message: '[getRequestUrl] Invalid configuration for third party request base url!',
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
if (baseUrl.endsWith(
|
|
42
|
+
if (baseUrl.endsWith('/')) {
|
|
43
43
|
baseUrl = baseUrl.slice(0, -1); // Remove / at the end
|
|
44
44
|
}
|
|
45
45
|
const joined = this.getRequestPath({ paths });
|
|
@@ -63,14 +63,14 @@ class AxiosNetworkRequest extends BaseNetworkRequest {
|
|
|
63
63
|
baseURL: baseUrl,
|
|
64
64
|
withCredentials: true,
|
|
65
65
|
headers: Object.assign({}, headers, {
|
|
66
|
-
[
|
|
66
|
+
['content-type']: headers['content-type'] ?? 'application/json; charset=utf-8',
|
|
67
67
|
}),
|
|
68
68
|
validateStatus: (status) => status < 500,
|
|
69
69
|
timeout,
|
|
70
70
|
};
|
|
71
71
|
super({
|
|
72
72
|
...opts,
|
|
73
|
-
variant:
|
|
73
|
+
variant: 'axios',
|
|
74
74
|
fetcher: new axios_fetcher_1.AxiosFetcher({ name, defaultConfigs }),
|
|
75
75
|
});
|
|
76
76
|
}
|
|
@@ -84,12 +84,12 @@ class NodeFetchNetworkRequest extends BaseNetworkRequest {
|
|
|
84
84
|
const defaultConfigs = {
|
|
85
85
|
...rest,
|
|
86
86
|
headers: Object.assign({}, headers, {
|
|
87
|
-
[
|
|
87
|
+
['content-type']: headers['content-type'] ?? 'application/json; charset=utf-8',
|
|
88
88
|
}),
|
|
89
89
|
};
|
|
90
90
|
super({
|
|
91
91
|
...opts,
|
|
92
|
-
variant:
|
|
92
|
+
variant: 'node-fetch',
|
|
93
93
|
fetcher: new node_fetcher_1.NodeFetcher({ name, defaultConfigs }),
|
|
94
94
|
});
|
|
95
95
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { AnyObject } from
|
|
2
|
-
import axios, { AxiosRequestConfig } from
|
|
3
|
-
import { AbstractNetworkFetchableHelper, IRequestOptions } from
|
|
1
|
+
import { AnyObject } from '../../../../common';
|
|
2
|
+
import axios, { AxiosRequestConfig } from 'axios';
|
|
3
|
+
import { AbstractNetworkFetchableHelper, IRequestOptions } from './base-fetcher';
|
|
4
4
|
export interface IAxiosRequestOptions extends AxiosRequestConfig, IRequestOptions {
|
|
5
5
|
url: string;
|
|
6
|
-
method?:
|
|
6
|
+
method?: 'get' | 'post' | 'put' | 'patch' | 'delete' | 'options';
|
|
7
7
|
params?: AnyObject;
|
|
8
8
|
body?: AnyObject;
|
|
9
9
|
headers?: AnyObject;
|
|
10
10
|
}
|
|
11
|
-
export declare class AxiosFetcher extends AbstractNetworkFetchableHelper<
|
|
11
|
+
export declare class AxiosFetcher extends AbstractNetworkFetchableHelper<'axios', IAxiosRequestOptions, axios.AxiosResponse<any, any>['data']> {
|
|
12
12
|
constructor(opts: {
|
|
13
13
|
name: string;
|
|
14
14
|
defaultConfigs: AxiosRequestConfig;
|