-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
590 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
.DS_Store | ||
.nyc_output | ||
coverage | ||
node_modules | ||
documentation | ||
dist | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
language: node_js | ||
node_js: | ||
- "9" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,69 @@ | ||
import {Constructor, ReflectionKeys} from '../interfaces'; | ||
/** | ||
* @function InjectModel | ||
* @author Jonathan Casarrubias | ||
* @param Class | ||
* @license MIT | ||
* @description Decorator used to inject models | ||
*/ | ||
export function InjectModel(Class: Constructor) { | ||
return (target: any, property: string) => { | ||
// Verify the class is actually a model class | ||
if (!Reflect.hasMetadata(ReflectionKeys.INJECTABLE_MODEL, Class)) { | ||
throw new Error( | ||
`ONIXJS Error: Invalid injectable model class ${ | ||
Class.name | ||
}, it is not a valid model.`, | ||
export namespace Inject { | ||
/** | ||
* @function Model | ||
* @author Jonathan Casarrubias | ||
* @param Class | ||
* @license MIT | ||
* @description Decorator used to inject models | ||
*/ | ||
export function Model(Class: Constructor) { | ||
return (target: any, property: string) => { | ||
// Verify the class is actually a model class | ||
if ( | ||
!Reflect.hasMetadata(ReflectionKeys.INJECTABLE_MODEL, Class.prototype) | ||
) { | ||
throw new Error( | ||
`ONIXJS Error: Invalid injectable model class ${ | ||
Class.name | ||
}, it is not a valid model.`, | ||
); | ||
} | ||
// Temporaly intialize the property otherwise will be "invisible" | ||
// By the moment we iterate over these properties in a future | ||
target[property] = true; | ||
// Adding this class as possible injectable class. | ||
// System will verify if this class is actually installed within the module. | ||
// It is a request because not necessarily an instance will be injected. | ||
Reflect.defineMetadata( | ||
ReflectionKeys.INJECT_REQUEST, | ||
{Class, type: 'model'}, | ||
target, | ||
property, | ||
); | ||
} | ||
// Temporaly intialize the property otherwise will be "invisible" | ||
// By the moment we iterate over these properties in a future | ||
target[property] = true; | ||
// Adding this class as possible injectable class. | ||
// System will verify if this class is actually installed within the module. | ||
// It is a request because not necessarily an instance will be injected. | ||
Reflect.defineMetadata( | ||
ReflectionKeys.INJECT_REQUEST, | ||
{Class, type: 'model'}, | ||
target, | ||
property, | ||
); | ||
}; | ||
} | ||
/** | ||
* @function InjectService | ||
* @author Jonathan Casarrubias | ||
* @param Class | ||
* @license MIT | ||
* @description Decorator used to inject services | ||
*/ | ||
export function InjectService(Class: Constructor) { | ||
return (target: any, property: string) => { | ||
// Verify the class is actually a model class | ||
if (!Reflect.hasMetadata(ReflectionKeys.INJECTABLE_SERVICE, Class)) { | ||
throw new Error( | ||
`ONIXJS Error: Invalid injectable service class ${ | ||
Class.name | ||
}, it is not a valid service.`, | ||
}; | ||
} | ||
/** | ||
* @function Service | ||
* @author Jonathan Casarrubias | ||
* @param Class | ||
* @license MIT | ||
* @description Decorator used to inject services | ||
*/ | ||
export function Service(Class: Constructor) { | ||
return (target: any, property: string) => { | ||
// Verify the class is actually a model class | ||
if ( | ||
!Reflect.hasMetadata(ReflectionKeys.INJECTABLE_SERVICE, Class.prototype) | ||
) { | ||
throw new Error( | ||
`ONIXJS Error: Invalid injectable service class ${ | ||
Class.name | ||
}, it is not a valid service.`, | ||
); | ||
} | ||
// Temporaly intialize the property otherwise will be "invisible" | ||
// By the moment we iterate over these properties in a future | ||
target[property] = true; | ||
// Adding this class as possible injectable class. | ||
// System will verify if this class is actually installed within the module. | ||
// It is a request because not necessarily an instance will be injected. | ||
Reflect.defineMetadata( | ||
ReflectionKeys.INJECT_REQUEST, | ||
{Class, type: 'service'}, | ||
target, | ||
property, | ||
); | ||
} | ||
// Temporaly intialize the property otherwise will be "invisible" | ||
// By the moment we iterate over these properties in a future | ||
target[property] = true; | ||
// Adding this class as possible injectable class. | ||
// System will verify if this class is actually installed within the module. | ||
// It is a request because not necessarily an instance will be injected. | ||
Reflect.defineMetadata( | ||
ReflectionKeys.INJECT_REQUEST, | ||
{Class, type: 'service'}, | ||
target, | ||
property, | ||
); | ||
}; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.