@xrystal/core 3.12.1 → 3.12.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.12.1",
4
+ "version": "3.12.2",
5
5
  "description": "Project core for xrystal",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -16,16 +16,11 @@ const coreLoader = async ({}) => {
16
16
  try {
17
17
  const { configs } = core._;
18
18
  const rootFolderPath = configs.rootFolderPath;
19
- const services = [
20
- SystemService,
21
- ConfigsService,
22
- LoggerService,
23
- EventsService,
24
- LocalizationsService,
25
- ClientsService
26
- ];
27
19
  x
28
- .registerServices(services)
20
+ .load([
21
+ path.join(__dirname, 'source', 'loader', '**/*.{ts,js}'),
22
+ path.join(__dirname, 'source', 'utils', '**/class.*.{ts,js}')
23
+ ])
29
24
  .initialize([
30
25
  {
31
26
  service: SystemService,
@@ -1,17 +1,18 @@
1
1
  export declare class X {
2
2
  private container;
3
3
  constructor();
4
- registerService(ServiceClass: any): this;
5
- registerServices(services: any[]): this;
4
+ load(patterns: string | string[]): this;
5
+ register(Dependency: any): this;
6
+ registerAll(dependencies: any[]): this;
6
7
  registerInstance(name: string, instance: any): this;
7
- initialize(input: {
8
+ initialize(input?: {
8
9
  service: any;
9
10
  props?: any;
10
11
  } | {
11
12
  service: any;
12
13
  props?: any;
13
14
  }[]): Promise<this>;
14
- get<T>(name: string | any): T;
15
+ get<T>(target: string | any): T;
15
16
  get cradle(): any;
16
17
  }
17
18
  declare const _default: X;
@@ -1,4 +1,4 @@
1
- import { createContainer, asClass, asValue, InjectionMode } from 'awilix';
1
+ import { createContainer, asClass, asValue, InjectionMode, Lifetime } from 'awilix';
2
2
  export class X {
3
3
  container;
4
4
  constructor() {
@@ -7,19 +7,28 @@ export class X {
7
7
  strict: true
8
8
  });
9
9
  }
10
- registerService(ServiceClass) {
11
- const name = ServiceClass.name.charAt(0).toLowerCase() + ServiceClass.name.slice(1);
12
- this.container.register({
13
- [name]: asClass(ServiceClass).singleton()
10
+ load(patterns) {
11
+ const resolvedPatterns = Array.isArray(patterns) ? patterns : [patterns];
12
+ this.container.loadModules(resolvedPatterns, {
13
+ formatName: 'camelCase',
14
+ resolverOptions: {
15
+ lifetime: Lifetime.SINGLETON,
16
+ register: asClass
17
+ }
14
18
  });
15
19
  return this;
16
20
  }
17
- registerServices(services) {
18
- services.forEach(ServiceClass => {
19
- this.registerService(ServiceClass);
21
+ register(Dependency) {
22
+ const name = Dependency.name.charAt(0).toLowerCase() + Dependency.name.slice(1);
23
+ this.container.register({
24
+ [name]: asClass(Dependency).singleton()
20
25
  });
21
26
  return this;
22
27
  }
28
+ registerAll(dependencies) {
29
+ dependencies.forEach(dep => this.register(dep));
30
+ return this;
31
+ }
23
32
  registerInstance(name, instance) {
24
33
  this.container.register({
25
34
  [name]: asValue(instance)
@@ -27,19 +36,32 @@ export class X {
27
36
  return this;
28
37
  }
29
38
  async initialize(input) {
30
- const items = Array.isArray(input) ? input : [input];
31
- for (const item of items) {
32
- const instance = this.get(item.service);
39
+ const cradle = this.container.cradle;
40
+ const inputList = input ? (Array.isArray(input) ? input : [input]) : [];
41
+ const propsMap = new Map();
42
+ inputList.forEach(item => {
43
+ const name = typeof item.service === 'function'
44
+ ? item.service.name.charAt(0).toLowerCase() + item.service.name.slice(1)
45
+ : item.service;
46
+ propsMap.set(name, item.props);
47
+ });
48
+ for (const key of Object.keys(cradle)) {
49
+ const instance = cradle[key];
33
50
  if (instance && typeof instance.load === 'function') {
34
- await instance.load(item.props);
51
+ if (propsMap.has(key)) {
52
+ await instance.load(propsMap.get(key));
53
+ }
54
+ else {
55
+ await instance.load();
56
+ }
35
57
  }
36
58
  }
37
59
  return this;
38
60
  }
39
- get(name) {
40
- const resolveName = typeof name === 'function'
41
- ? name.name.charAt(0).toLowerCase() + name.name.slice(1)
42
- : name;
61
+ get(target) {
62
+ const resolveName = typeof target === 'function'
63
+ ? target.name.charAt(0).toLowerCase() + target.name.slice(1)
64
+ : target;
43
65
  return this.container.resolve(resolveName);
44
66
  }
45
67
  get cradle() {