Members
(static) @Body :Express.Request.Body
This decorator is used to post the Express's Request Body when using an @Action.
- Source:
(static) @Next :Express.NextFunction
This decorator is used to get the Express's Response when using an @Action.
- Source:
(static) @Params :Express.Request.Params
This decorator is used to get the Express's Request Params when using an @Action.
- Source:
(static) @Query :Express.Request.Query
This decorator is used to get the Express's Request Query when using an @Action.
- Source:
(static) @Request :Express.Request
This decorator is used to get the Express's Request when using an @Action.
- Source:
(static) @Response :Express.Response
This decorator is used to get the Express's Response when using an @Action.
- Source:
Methods
(static) Action(pathnon-null, middlewaresnullable) → {any}
This decorator is used to define an action. Actions are automatically injected.
All the actions must be in src/actions
and to have the @Action
decorator.
The middlewares can be Class Middlewares (Injected) as strings or function middlewares.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
path |
string |
The path of the router |
|
middlewares |
Array.<(string|function())> |
<nullable> |
Middlewares |
- Source:
Example
@Action('/path', ['ClassMiddleware', functionMiddleware])
export default class ActionName {
}
(static) Copy(childopt, middlewaresnullable) → {any}
This decorator is used to define a COPY Route.
The middlewares can be Class Middlewares (Injected) as strings or function middlewares.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
child |
string |
<optional> |
/ |
The path of the route (This will have as prefix the Action's path) |
middlewares |
Array.<(string|function())> |
<nullable> |
Middlewares |
- Source:
Example
@Action('/path', ['ClassMiddleware', functionMiddleware])
export default class ActionName {
@Retrieve('Responder.Name')
private responder?: ResponderName;
// The url will be /api/path/sub-path/:id (where :id is a path parameter)
@Copy('/sub-path/:id', ['SubPathMiddleware'])
public item(
@Request req: Request,
@Response res: Response
): Promise<any> {
return this.responder!.success(res);
}
}
(static) Delete(childopt, middlewaresnullable) → {any}
This decorator is used to define a DELETE Route.
The middlewares can be Class Middlewares (Injected) as strings or function middlewares.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
child |
string |
<optional> |
/ |
The path of the route (This will have as prefix the Action's path) |
middlewares |
Array.<(string|function())> |
<nullable> |
Middlewares |
- Source:
Example
@Action('/path', ['ClassMiddleware', functionMiddleware])
export default class ActionName {
@Retrieve('Responder.Name')
private responder?: ResponderName;
// The url will be /api/path/sub-path/:id (where :id is a path parameter)
@Delete('/sub-path/:id', ['SubPathMiddleware'])
public deleteItem(
@Request req: Request,
@Response res: Response
): Promise<any> {
return this.responder!.success(res);
}
}
(static) Domain(namenon-null) → {any}
This decorator is used to define a Domain. Domain classes are automatically injected.
All the Domain classes must be in src/domain
and they must have @Inject
For an example on how the domain is used, check the example from @Post.
Parameters:
Name | Type | Description |
---|---|---|
name |
string |
The name of the domain (This will have as prefix |
- Source:
Example
@Inject
@Domain('Name') // This will be accessed as 'Domain.Name'
export default class DomainName {
public async saveUser(name: string) {
...
return {
userId: '123'
};
}
}
(static) Entity(namenon-null) → {any}
This decorator is used to define an Entity. Entities are automatically injected.
All the Entities must be in src/domain/entities
and they must have @Inject
Parameters:
Name | Type | Description |
---|---|---|
name |
string |
The name of the entity (This will have as prefix |
- Source:
Example
// This will be accessed as 'Entity.Name' but most of the ORMs such as Mongoose
// keeps an instance of the model, e.g. mongoose.models
@Inject
@Entity('Name')
export default class UserEntity implements InjectedEntity {
@Retrieve('Mongoose')
private mongoose?: MongooseClass;
public async onLoad(): Promise<void> {
if (!this.mongoose) {
return;
}
const { ObjectId } = Schema as any;
this.mongoose.model(
'User',
new Schema({
id: ObjectId,
email: {
type: String,
min: 3,
max: 255,
required: true
},
password: {
type: String,
min: 8,
required: true
}
})
);
}
}
(static) Get(childopt, middlewaresnullable) → {any}
This decorator is used to define a GET Route.
The middlewares can be Class Middlewares (Injected) as strings or function middlewares.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
child |
string |
<optional> |
/ |
The path of the route (This will have as prefix the Action's path) |
middlewares |
Array.<(string|function())> |
<nullable> |
Middlewares |
- Source:
Example
@Action('/path', ['ClassMiddleware', functionMiddleware])
export default class ActionName {
@Retrieve('Responder.Name')
private responder?: ResponderName;
@Get('/sub-path', ['SubPathMiddleware']) // The url will be /api/path/sub-path
public findAll(
@Request req: Request,
@Query query: any,
@Response res: Response
): Promise<any> {
return this.responder!.success(res);
}
// The url will be /api/path/sub-path/:id (where :id is a path parameter)
@Get('/sub-path/:id', ['SubPathMiddleware'])
public findById(
@Params params: any,
@Response res: Response
): Promise<any> {
return this.responder!.success(res);
}
}
(static) Head(childopt, middlewaresnullable) → {any}
This decorator is used to define a HEAD Route.
The middlewares can be Class Middlewares (Injected) as strings or function middlewares.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
child |
string |
<optional> |
/ |
The path of the route (This will have as prefix the Action's path) |
middlewares |
Array.<(string|function())> |
<nullable> |
Middlewares |
- Source:
Example
@Action('/path', ['ClassMiddleware', functionMiddleware])
export default class ActionName {
@Retrieve('Responder.Name')
private responder?: ResponderName;
// The url will be /api/path/sub-path/:id (where :id is a path parameter)
@Head('/sub-path/:id', ['SubPathMiddleware'])
public item(
@Request req: Request,
@Response res: Response
): Promise<any> {
return this.responder!.success(res);
}
}
(static) Lock(childopt, middlewaresnullable) → {any}
This decorator is used to define a LOCK Route.
The middlewares can be Class Middlewares (Injected) as strings or function middlewares.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
child |
string |
<optional> |
/ |
The path of the route (This will have as prefix the Action's path) |
middlewares |
Array.<(string|function())> |
<nullable> |
Middlewares |
- Source:
Example
@Action('/path', ['ClassMiddleware', functionMiddleware])
export default class ActionName {
@Retrieve('Responder.Name')
private responder?: ResponderName;
// The url will be /api/path/sub-path/:id (where :id is a path parameter)
@Lock('/sub-path/:id', ['SubPathMiddleware'])
public item(
@Request req: Request,
@Response res: Response
): Promise<any> {
return this.responder!.success(res);
}
}
(static) Options(childopt, middlewaresnullable) → {any}
This decorator is used to define a OPTIONS Route.
The middlewares can be Class Middlewares (Injected) as strings or function middlewares.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
child |
string |
<optional> |
/ |
The path of the route (This will have as prefix the Action's path) |
middlewares |
Array.<(string|function())> |
<nullable> |
Middlewares |
- Source:
Example
@Action('/path', ['ClassMiddleware', functionMiddleware])
export default class ActionName {
@Retrieve('Responder.Name')
private responder?: ResponderName;
// The url will be /api/path/sub-path/:id (where :id is a path parameter)
@Options('/sub-path/:id', ['SubPathMiddleware'])
public item(
@Request req: Request,
@Response res: Response
): Promise<any> {
return this.responder!.success(res);
}
}
(static) Patch(childopt, middlewaresnullable) → {any}
This decorator is used to define a PATCH Route.
The middlewares can be Class Middlewares (Injected) as strings or function middlewares.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
child |
string |
<optional> |
/ |
The path of the route (This will have as prefix the Action's path) |
middlewares |
Array.<(string|function())> |
<nullable> |
Middlewares |
- Source:
Example
@Action('/path', ['ClassMiddleware', functionMiddleware])
export default class ActionName {
@Retrieve('Responder.Name')
private responder?: ResponderName;
// The url will be /api/path/sub-path/:id (where :id is a path parameter)
@Patch('/sub-path/:id', ['SubPathMiddleware'])
public updateItem(
@Request req: Request,
@Response res: Response
): Promise<any> {
return this.responder!.success(res);
}
}
(static) Post(childopt, middlewaresnullable) → {any}
This decorator is used to define a POST Route.
The middlewares can be Class Middlewares (Injected) as strings or function middlewares.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
child |
string |
<optional> |
/ |
The path of the route (This will have as prefix the Action's path) |
middlewares |
Array.<(string|function())> |
<nullable> |
Middlewares |
- Source:
Example
@Action('/path', ['ClassMiddleware', functionMiddleware])
export default class ActionName {
@Retrieve('Responder.Name')
private responder?: ResponderName;
@Retrieve('Domain.Name')
private domain?: DomainName;
@Post('/sub-path', ['SubPathMiddleware']) // The url will be /api/path/sub-path
public saveItem(
@Body body: any,
@Response res: Response
): Promise<any> {
const { userId } = (
await this.domain!.saveUser('Some Name')
);
return this.responder!.created(res, userId);
}
}
(static) Purge(childopt, middlewaresnullable) → {any}
This decorator is used to define a PURGE Route.
The middlewares can be Class Middlewares (Injected) as strings or function middlewares.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
child |
string |
<optional> |
/ |
The path of the route (This will have as prefix the Action's path) |
middlewares |
Array.<(string|function())> |
<nullable> |
Middlewares |
- Source:
Example
@Action('/path', ['ClassMiddleware', functionMiddleware])
export default class ActionName {
@Retrieve('Responder.Name')
private responder?: ResponderName;
// The url will be /api/path/sub-path/:id (where :id is a path parameter)
@Purge('/sub-path/:id', ['SubPathMiddleware'])
public item(
@Request req: Request,
@Response res: Response
): Promise<any> {
return this.responder!.success(res);
}
}
(static) Put(childopt, middlewaresnullable) → {any}
This decorator is used to define a PUT Route.
The middlewares can be Class Middlewares (Injected) as strings or function middlewares.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
child |
string |
<optional> |
/ |
The path of the route (This will have as prefix the Action's path) |
middlewares |
Array.<(string|function())> |
<nullable> |
Middlewares |
- Source:
Example
@Action('/path', ['ClassMiddleware', functionMiddleware])
export default class ActionName {
@Retrieve('Responder.Name')
private responder?: ResponderName;
// The url will be /api/path/sub-path/:id (where :id is a path parameter)
@Put('/sub-path/:id', ['SubPathMiddleware'])
public replaceItem(
@Request req: Request,
@Response res: Response
): Promise<any> {
return this.responder!.success(res);
}
}
(static) Responder(namenon-null) → {any}
This decorator is used to define a Responder. Responders are automatically injected.
All the responders must be in src/responders
and they must have @Inject
For an example on how the responder is used, check the example from @Post.
Parameters:
Name | Type | Description |
---|---|---|
name |
string |
The name of the responder (This will have as prefix |
- Source:
Example
@Inject
@Responder('Name') // This will be accessed as 'Responder.Name'
export default class ResponderName {
public success(res: Response) {
return res.status(200).json({
success: true
});
}
public created(res: Response, userId: string) {
return res.status(201).json({
success: true,
userId
});
}
}
(static) Trace(childopt, middlewaresnullable) → {any}
This decorator is used to define a TRACE Route.
The middlewares can be Class Middlewares (Injected) as strings or function middlewares.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
child |
string |
<optional> |
/ |
The path of the route (This will have as prefix the Action's path) |
middlewares |
Array.<(string|function())> |
<nullable> |
Middlewares |
- Source:
Example
@Action('/path', ['ClassMiddleware', functionMiddleware])
export default class ActionName {
@Retrieve('Responder.Name')
private responder?: ResponderName;
// The url will be /api/path/sub-path/:id (where :id is a path parameter)
@Trace('/sub-path/:id', ['SubPathMiddleware'])
public item(
@Request req: Request,
@Response res: Response
): Promise<any> {
return this.responder!.success(res);
}
}
(static) Unlock(childopt, middlewaresnullable) → {any}
This decorator is used to define a UNLOCK Route.
The middlewares can be Class Middlewares (Injected) as strings or function middlewares.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
child |
string |
<optional> |
/ |
The path of the route (This will have as prefix the Action's path) |
middlewares |
Array.<(string|function())> |
<nullable> |
Middlewares |
- Source:
Example
@Action('/path', ['ClassMiddleware', functionMiddleware])
export default class ActionName {
@Retrieve('Responder.Name')
private responder?: ResponderName;
// The url will be /api/path/sub-path/:id (where :id is a path parameter)
@Unlock('/sub-path/:id', ['SubPathMiddleware'])
public item(
@Request req: Request,
@Response res: Response
): Promise<any> {
return this.responder!.success(res);
}
}