@xrystal/core 3.18.2 → 3.18.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json 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.7",
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;
@@ -8,6 +33,7 @@ export default class ConfigsService implements IService {
8
33
  constructor({ systemService }: {
9
34
  systemService: SystemService;
10
35
  });
11
- load: ({}: {}) => void;
12
- get all(): Record<string, any>;
36
+ load: ({}: {}) => Promise<void>;
37
+ setConfig(newConfigs: any): void;
38
+ get all(): IConfig;
13
39
  }
@@ -1,43 +1,61 @@
1
1
  import path from 'node:path';
2
2
  import { Constants } from '../../utils';
3
+ import { pathToFileURL } from 'node:url';
3
4
  export default class ConfigsService {
4
- config = {};
5
+ config;
5
6
  publicFolderName = Constants.publicFolderName;
6
7
  kafkaLogsTopic = Constants.kafkaLogsTopic;
7
8
  #systemService;
8
9
  constructor({ systemService }) {
9
10
  this.#systemService = systemService;
10
11
  }
11
- load = ({}) => {
12
+ load = async ({}) => {
12
13
  const tmp = this.#systemService.tmp;
13
- const rawConfigs = tmp?.configs || tmp?.configs || {};
14
+ const extendConfigs = tmp.configs.loaders.configs.loadPath;
15
+ let importedModule;
16
+ const cwd = process.cwd();
17
+ if (extendConfigs.startsWith('@/')) {
18
+ const fullPath = path.join(cwd, extendConfigs.slice(2));
19
+ importedModule = await import(pathToFileURL(fullPath).href);
20
+ }
21
+ else {
22
+ const fullPath = path.resolve(tmp.configs.rootFolderPath, extendConfigs);
23
+ importedModule = await import(pathToFileURL(fullPath).href);
24
+ }
14
25
  this.config = {
15
26
  worker: process.env.WORKER === 'true' ? true : false || false,
16
- nodeEnv: process.env.NODE_ENV === 'true' ? true : false || false,
27
+ nodeEnv: process.env.NODE_ENV,
17
28
  debug: process.env.SYSTEM_LOGGER_LAYER,
18
29
  https: process.env.HTTPS,
19
30
  httpsfileEncoding: process.env.ENCODING || 'utf8',
20
31
  httpsCertfile: process.env.HTTPS_CERT_FILE,
21
32
  httpsKeyfile: process.env.HTTPS_KEY_FILE,
22
- rootFolderPath: rawConfigs.rootFolderPath || 'x',
33
+ rootFolderPath: tmp.configs.rootFolderPath || 'x',
23
34
  projectName: tmp.project.name,
24
- serviceName: rawConfigs.service,
35
+ serviceName: tmp.configs.service,
25
36
  projectNamePrefixEnv: process.env.PROJECT_NAME_PREFIX || '',
26
37
  projectNameEnv: process.env.PROJECT_NAME || '',
27
38
  projectNameSuffixEnv: process.env.PROJECT_NAME_SUFFIX || '',
28
- systemStaticFolderPath: path.resolve(rawConfigs.rootFolderPath, this.publicFolderName),
39
+ systemStaticFolderPath: path.resolve(tmp.configs.rootFolderPath, this.publicFolderName),
29
40
  systemLoggerLayer: process.env.SYSTEM_LOGGER_LAYER,
30
41
  kafkaBrokers: process.env?.KAFKA_BROKERS,
31
42
  kafkaLogsTopic: this.kafkaLogsTopic,
32
43
  baseApiUri: process.env.HTTPS === 'true' ? process.env.SYSTEM_HTTPS_BASE_API_URI : process.env.SYSTEM_BASE_API_URI,
33
- port: process.env.PORT || rawConfigs.port || 3000,
44
+ port: Number(process.env.PORT),
34
45
  internalSecret: process.env.INTERNAL_SECRET,
35
46
  secret: process.env.SECRET,
36
- cwd: process.cwd(),
47
+ cwd,
37
48
  env: process.env.NODE_ENV,
38
- ...rawConfigs
49
+ ...importedModule.configs,
39
50
  };
40
51
  };
52
+ setConfig(newConfigs) {
53
+ const mergedData = {
54
+ ...this.config,
55
+ ...newConfigs
56
+ };
57
+ this.config = Object.freeze(mergedData);
58
+ }
41
59
  get all() {
42
60
  return this.config;
43
61
  }
@@ -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);
@@ -0,0 +1 @@
1
+ export declare const configs: {};
@@ -0,0 +1 @@
1
+ export const configs = {};
@@ -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 };
package/x/tmp.yml CHANGED
@@ -7,7 +7,7 @@ configs:
7
7
 
8
8
  loaders:
9
9
  configs:
10
- envLoadPath: environments
10
+ loadPath: '@/source/utils/models/classes/configs.project.ts'
11
11
 
12
12
  loggers:
13
13
  loadPath: logs