@bool-ts/core 1.0.7 → 1.0.9

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.
@@ -1,3 +1,3 @@
1
1
  export declare const injectKey = "design:paramtypes";
2
- export declare const Inject: <T>(constructor: new (...args: any[]) => T) => (target: Object, parameterName: string | Symbol | undefined, parameterIndex: number) => void;
2
+ export declare const Inject: <T extends Object>(classDefinition: T) => (target: Object, parameterName: string | Symbol | undefined, parameterIndex: number) => void;
3
3
  export default Inject;
@@ -1,8 +1,8 @@
1
1
  export const injectKey = "design:paramtypes";
2
- export const Inject = (constructor) => {
2
+ export const Inject = (classDefinition) => {
3
3
  return (target, parameterName, parameterIndex) => {
4
4
  const designParameterTypes = Reflect.getMetadata(injectKey, target.constructor) || [];
5
- designParameterTypes[parameterIndex] = constructor;
5
+ designParameterTypes[parameterIndex] = classDefinition.constructor;
6
6
  Reflect.defineMetadata(injectKey, designParameterTypes, target.constructor);
7
7
  };
8
8
  };
@@ -119,11 +119,13 @@ export const BoolFactory = (target) => {
119
119
  console.info(`PID: ${convertedPID} - Method: ${convertedMethod} - IP: ${convertedReqIp} - ${req.originalUrl.blue} - Time: ${convertedTime}`);
120
120
  }));
121
121
  app.use((req, res, next) => {
122
- if (!allowOrigins.includes(req.headers.origin || "*")) {
123
- return res.status(403).json({
124
- ["httpCode"]: 403,
125
- ["data"]: "Invalid origin."
126
- });
122
+ if (!allowOrigins.includes("*")) {
123
+ if (!allowOrigins.includes(req.headers.origin || "*")) {
124
+ return res.status(403).json({
125
+ ["httpCode"]: 403,
126
+ ["data"]: "Invalid origin."
127
+ });
128
+ }
127
129
  }
128
130
  res.header("Access-Control-Allow-Origin", req.headers.origin || "*");
129
131
  res.header("Access-Control-Allow-Headers", "*");
@@ -6,19 +6,19 @@ export const Injector = new class {
6
6
  *
7
7
  * @param constructor
8
8
  */
9
- get(target) {
10
- if (this._mapper.has(target.constructor)) {
11
- return this._mapper.get(target.constructor);
9
+ get(classDefinition) {
10
+ if (this._mapper.has(classDefinition.constructor)) {
11
+ return this._mapper.get(classDefinition.constructor);
12
12
  }
13
- const ownMetadataKeys = Reflect.getOwnMetadataKeys(target.constructor);
13
+ const ownMetadataKeys = Reflect.getOwnMetadataKeys(classDefinition.constructor);
14
14
  if (!ownMetadataKeys.includes(injectableKey)) {
15
15
  throw Error("Missing dependency declaration, please check @Injectable() used on dependency(ies).");
16
16
  }
17
17
  // Initialize dependencies injection
18
- const dependencies = Reflect.getOwnMetadata("design:paramtypes", target) || [];
18
+ const dependencies = Reflect.getOwnMetadata("design:paramtypes", classDefinition.constructor) || [];
19
19
  const injections = dependencies.map(dependency => Injector.get(dependency));
20
- const instance = target.constructor(...injections);
21
- this._mapper.set(target.constructor, instance);
20
+ const instance = classDefinition.constructor(...injections);
21
+ this._mapper.set(classDefinition.constructor, instance);
22
22
  return instance;
23
23
  }
24
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bool-ts/core",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,7 +1,7 @@
1
1
  export const injectKey = "design:paramtypes";
2
2
 
3
- export const Inject = <T>(
4
- constructor: new (...args: any[]) => T
3
+ export const Inject = <T extends Object>(
4
+ classDefinition: T
5
5
  ) => {
6
6
  return (
7
7
  target: Object,
@@ -10,7 +10,7 @@ export const Inject = <T>(
10
10
  ) => {
11
11
  const designParameterTypes: any[] = Reflect.getMetadata(injectKey, target.constructor) || [];
12
12
 
13
- designParameterTypes[parameterIndex] = constructor;
13
+ designParameterTypes[parameterIndex] = classDefinition.constructor;
14
14
 
15
15
  Reflect.defineMetadata(injectKey, designParameterTypes, target.constructor);
16
16
  }
@@ -149,11 +149,13 @@ export const BoolFactory = (
149
149
  );
150
150
 
151
151
  app.use((req: Request, res: Response, next: NextFunction) => {
152
- if (!allowOrigins.includes(req.headers.origin || "*")) {
153
- return res.status(403).json({
154
- ["httpCode"]: 403,
155
- ["data"]: "Invalid origin."
156
- });
152
+ if (!allowOrigins.includes("*")) {
153
+ if (!allowOrigins.includes(req.headers.origin || "*")) {
154
+ return res.status(403).json({
155
+ ["httpCode"]: 403,
156
+ ["data"]: "Invalid origin."
157
+ });
158
+ }
157
159
  }
158
160
 
159
161
  res.header("Access-Control-Allow-Origin", req.headers.origin || "*");
@@ -16,24 +16,24 @@ export const Injector: IInjector = new class {
16
16
  * @param constructor
17
17
  */
18
18
  get<T extends Object>(
19
- target: T
19
+ classDefinition: T
20
20
  ) {
21
- if (this._mapper.has(target.constructor)) {
22
- return this._mapper.get(target.constructor) as T;
21
+ if (this._mapper.has(classDefinition.constructor)) {
22
+ return this._mapper.get(classDefinition.constructor) as T;
23
23
  }
24
24
 
25
- const ownMetadataKeys = Reflect.getOwnMetadataKeys(target.constructor);
25
+ const ownMetadataKeys = Reflect.getOwnMetadataKeys(classDefinition.constructor);
26
26
 
27
27
  if (!ownMetadataKeys.includes(injectableKey)) {
28
28
  throw Error("Missing dependency declaration, please check @Injectable() used on dependency(ies).");
29
29
  }
30
30
 
31
31
  // Initialize dependencies injection
32
- const dependencies: any[] = Reflect.getOwnMetadata("design:paramtypes", target) || [];
32
+ const dependencies: any[] = Reflect.getOwnMetadata("design:paramtypes", classDefinition.constructor) || [];
33
33
  const injections: any[] = dependencies.map(dependency => Injector.get(dependency));
34
- const instance = target.constructor(...injections);
34
+ const instance = classDefinition.constructor(...injections);
35
35
 
36
- this._mapper.set(target.constructor, instance);
36
+ this._mapper.set(classDefinition.constructor, instance);
37
37
 
38
38
  return instance;
39
39
  }