@xrystal/core 3.18.2 → 3.18.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.18.2",
4
+ "version": "3.18.6",
5
5
  "description": "Project core for xrystal",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -1,5 +1,30 @@
1
1
  import SystemService from '../system/index';
2
2
  import { IService } from '../../utils';
3
+ export interface IConfig {
4
+ worker: boolean;
5
+ nodeEnv: string;
6
+ debug: string;
7
+ https: string;
8
+ httpsfileEncoding: string;
9
+ httpsCertfile: string;
10
+ httpsKeyfile: string;
11
+ rootFolderPath: string;
12
+ projectName: string;
13
+ serviceName: string;
14
+ projectNamePrefixEnv: string;
15
+ projectNameEnv: string;
16
+ projectNameSuffixEnv: string;
17
+ systemStaticFolderPath: string;
18
+ systemLoggerLayer: string;
19
+ kafkaBrokers: string;
20
+ kafkaLogsTopic: string;
21
+ baseApiUri: string;
22
+ port: number;
23
+ internalSecret: string;
24
+ secret: string;
25
+ cwd: string;
26
+ env: string;
27
+ }
3
28
  export default class ConfigsService implements IService {
4
29
  #private;
5
30
  private config;
@@ -9,5 +34,6 @@ export default class ConfigsService implements IService {
9
34
  systemService: SystemService;
10
35
  });
11
36
  load: ({}: {}) => void;
12
- get all(): Record<string, any>;
37
+ setConfig(newConfigs: any): void;
38
+ get all(): IConfig;
13
39
  }
@@ -1,7 +1,7 @@
1
1
  import path from 'node:path';
2
2
  import { Constants } from '../../utils';
3
3
  export default class ConfigsService {
4
- config = {};
4
+ config;
5
5
  publicFolderName = Constants.publicFolderName;
6
6
  kafkaLogsTopic = Constants.kafkaLogsTopic;
7
7
  #systemService;
@@ -13,7 +13,7 @@ export default class ConfigsService {
13
13
  const rawConfigs = tmp?.configs || tmp?.configs || {};
14
14
  this.config = {
15
15
  worker: process.env.WORKER === 'true' ? true : false || false,
16
- nodeEnv: process.env.NODE_ENV === 'true' ? true : false || false,
16
+ nodeEnv: process.env.NODE_ENV,
17
17
  debug: process.env.SYSTEM_LOGGER_LAYER,
18
18
  https: process.env.HTTPS,
19
19
  httpsfileEncoding: process.env.ENCODING || 'utf8',
@@ -34,10 +34,16 @@ export default class ConfigsService {
34
34
  internalSecret: process.env.INTERNAL_SECRET,
35
35
  secret: process.env.SECRET,
36
36
  cwd: process.cwd(),
37
- env: process.env.NODE_ENV,
38
- ...rawConfigs
37
+ env: process.env.NODE_ENV
39
38
  };
40
39
  };
40
+ setConfig(newConfigs) {
41
+ const mergedData = {
42
+ ...this.config,
43
+ ...newConfigs
44
+ };
45
+ this.config = Object.freeze(mergedData);
46
+ }
41
47
  get all() {
42
48
  return this.config;
43
49
  }
@@ -2,11 +2,11 @@ import winston from "winston";
2
2
  import "winston-daily-rotate-file";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
4
  import { LoggerLayerEnum, IService } from "../../utils";
5
- interface CustomLogger extends winston.Logger {
5
+ export interface ICustomLogger extends winston.Logger {
6
6
  critical: winston.LeveledLogMethod;
7
7
  http: winston.LeveledLogMethod;
8
8
  }
9
- interface LogOptions {
9
+ export interface ILog {
10
10
  level: LoggerLayerEnum;
11
11
  message: any;
12
12
  payload?: any;
@@ -17,9 +17,9 @@ export default class LoggerService implements IService {
17
17
  static readonly storage: AsyncLocalStorage<Map<string, string>>;
18
18
  private serviceName;
19
19
  private kafkaProducer;
20
- private kafkaTopic;
20
+ private kafkaLogsTopic;
21
21
  private isKafkaReady;
22
- winston: CustomLogger;
22
+ winston: ICustomLogger;
23
23
  constructor({ configsService }: {
24
24
  configsService: any;
25
25
  });
@@ -27,13 +27,12 @@ export default class LoggerService implements IService {
27
27
  winstonLoader: ({ loadPath, loggerLevel }: {
28
28
  loadPath: string;
29
29
  loggerLevel: string;
30
- }) => CustomLogger;
30
+ }) => ICustomLogger;
31
31
  private safeReplacer;
32
32
  private getTracingFormat;
33
33
  private getConsoleFormat;
34
34
  runWithId: <T>(id: string, callback: () => T) => T;
35
35
  logToKafka(info: any): Promise<void>;
36
36
  log(level: LoggerLayerEnum, message: any, payload?: any, code?: string | number): void;
37
- log(options: LogOptions): void;
37
+ log(options: ILog): void;
38
38
  }
39
- export {};
@@ -35,13 +35,13 @@ export default class LoggerService {
35
35
  static storage = new AsyncLocalStorage();
36
36
  serviceName = "";
37
37
  kafkaProducer = null;
38
- kafkaTopic = "";
38
+ kafkaLogsTopic = "";
39
39
  isKafkaReady = false;
40
40
  winston;
41
41
  #configsService;
42
42
  constructor({ configsService }) {
43
43
  this.#configsService = configsService;
44
- this.kafkaTopic = this.#configsService?.all.kafkaTopic;
44
+ this.kafkaLogsTopic = this.#configsService?.all.kafkaLogsTopic;
45
45
  winston.addColors(customColors);
46
46
  this.winston = winston.createLogger({
47
47
  level: this.#configsService.all.systemLoggerLayer,
@@ -152,7 +152,7 @@ export default class LoggerService {
152
152
  try {
153
153
  const { id, level, message, payload, code } = info;
154
154
  await this.kafkaProducer.send({
155
- topic: this.kafkaTopic,
155
+ topic: this.kafkaLogsTopic,
156
156
  messages: [{
157
157
  value: JSON.stringify({
158
158
  service: this.serviceName,
@@ -1,5 +1,5 @@
1
1
  import { LifetimeType } from 'awilix';
2
- export declare class X {
2
+ declare class X {
3
3
  private container;
4
4
  private initializedNames;
5
5
  constructor();
@@ -12,14 +12,14 @@ export declare class X {
12
12
  register(Dependency: any, lifetime?: LifetimeType): this;
13
13
  registerAll(dependencies: any[], lifetime?: LifetimeType): this;
14
14
  registerInstance(name: string, instance: any): this;
15
- initialize(input?: {
15
+ initialize<T = any>(input?: {
16
16
  service: any;
17
- props?: any;
17
+ props?: T;
18
18
  } | {
19
19
  service: any;
20
- props?: any;
20
+ props?: T;
21
21
  }[], verbose?: boolean): Promise<this>;
22
- get<T>(target: string | any): T;
22
+ get<T>(target: any): T;
23
23
  get cradle(): any;
24
24
  private isRegistered;
25
25
  }
@@ -1,7 +1,7 @@
1
1
  import { createContainer, asClass, asValue, InjectionMode, listModules, Lifetime } from 'awilix';
2
2
  import path from 'node:path';
3
3
  import { pathToFileURL } from 'node:url';
4
- export class X {
4
+ class X {
5
5
  container;
6
6
  initializedNames = new Set();
7
7
  constructor() {
@@ -28,7 +28,6 @@ export class X {
28
28
  modules = listModules(resolvedPatterns);
29
29
  }
30
30
  catch (err) {
31
- console.error(`[DI][CRITICAL] Path resolution failed: ${err.message}`);
32
31
  return this;
33
32
  }
34
33
  for (const m of modules) {
@@ -43,11 +42,8 @@ export class X {
43
42
  }
44
43
  return false;
45
44
  });
46
- if (isPathExcluded) {
47
- if (verbose)
48
- console.log(`[DI][${source}] Excluded: ${m.name}`);
45
+ if (isPathExcluded)
49
46
  continue;
50
- }
51
47
  try {
52
48
  const fileUrl = pathToFileURL(m.path).href;
53
49
  const loaded = await import(fileUrl);
@@ -66,14 +62,12 @@ export class X {
66
62
  this.container.register({
67
63
  [name]: asClass(dependency).setLifetime(lifetime)
68
64
  });
69
- if (verbose)
70
- console.log(`[DI][${source}] Registered: ${name}`);
71
65
  }
72
66
  }
73
67
  }
74
68
  catch (err) {
75
69
  if (verbose)
76
- console.error(`[DI][${source}] Load Error in ${m.name}:`, err.message);
70
+ console.error(`[DI][${source}] Load Error:`, err.message);
77
71
  }
78
72
  }
79
73
  return this;
@@ -126,8 +120,6 @@ export class X {
126
120
  const props = propsMap.get(key) || {};
127
121
  await instance.load(props);
128
122
  this.initializedNames.add(key);
129
- if (verbose)
130
- console.log(`[DI] Initialized: ${key}`);
131
123
  }
132
124
  catch (err) {
133
125
  console.error(`[DI] Initialization Failed: ${key} ->`, err.message);
@@ -1,4 +1,4 @@
1
- import x, { X } from './classes/class.x';
1
+ import x from './classes/class.x';
2
2
  import locator, { Locator } from './classes/class.service-locator';
3
3
  export * from './classes/class.tmp-file-loader';
4
4
  export * from './classes/class.response';
@@ -6,4 +6,4 @@ export * from './classes/class.services';
6
6
  export * from './classes/class.interfaces';
7
7
  export * from './types';
8
8
  export * from './enums';
9
- export { x, X, locator, Locator };
9
+ export { x, locator, Locator };
@@ -1,4 +1,4 @@
1
- import x, { X } from './classes/class.x';
1
+ import x from './classes/class.x';
2
2
  import locator, { Locator } from './classes/class.service-locator';
3
3
  export * from './classes/class.tmp-file-loader';
4
4
  export * from './classes/class.response';
@@ -6,4 +6,4 @@ export * from './classes/class.services';
6
6
  export * from './classes/class.interfaces';
7
7
  export * from './types';
8
8
  export * from './enums';
9
- export { x, X, locator, Locator };
9
+ export { x, locator, Locator };