Moonshard
README / Globals
# Moonshard
# Index
# Enumerations
# Classes
# Interfaces
- ControllerOptions
- CrudOptions
- IAppOptions
- IGetResponseParams
- IHttpError
- IHttpErrorStatics
- TransformValidationOptions
# Type aliases
# Variables
- All
- Body
- Ctrl
- Delete
- Get
- Head
- Headers
- MOONSHARD_INJECTABLE
- MOONSHARD_PARAMS
- MOONSHARD_ROUTES
- Options
- PARAMTYPES_METADATA
- Param
- Patch
- Post
- Put
- Query
- Reply
- Request
- app
# Functions
- Controller
- Header
- HttpCode
- Injectable
- Pipe
- Redirect
- buildMethodDecorator
- buildParamDecorator
- buildParamDecoratorWithParamType
- castToBoolean
- castToInt
- castToNumber
- close
- createApp
- defaultErrorHandler
- getApp
- getInstance
- getStatusByMethod
- inject
- injectParams
- injectableInstance
- loadControllers
- spellbook
- start
- transformAndValidate
- transformAndValidateSync
# Type aliases
# ClassType
Ƭ ClassType<T>: {}
# Type parameters:
Name |
---|
T |
# CustomObject
Ƭ CustomObject: Record<string, unknown>
# Variables
# All
• Const
All: (Anonymous function) = buildMethodDecorator(RequestMethod.ALL)
# Body
• Const
Body: (Anonymous function) = buildParamDecoratorWithParamType(RouteParamtypes.BODY)
# Ctrl
• Const
Ctrl: Controller = Controller
# Delete
• Const
Delete: (Anonymous function) = buildMethodDecorator(RequestMethod.DELETE)
# Get
• Const
Get: (Anonymous function) = buildMethodDecorator(RequestMethod.GET)
# Head
• Const
Head: (Anonymous function) = buildMethodDecorator(RequestMethod.HEAD)
# Headers
• Const
Headers: (Anonymous function) = buildParamDecorator(RouteParamtypes.HEADERS)
# MOONSHARD_INJECTABLE
• Const
MOONSHARD_INJECTABLE: "moonshard:injectable" = "moonshard:injectable"
# MOONSHARD_PARAMS
• Const
MOONSHARD_PARAMS: "moonshard:params" = "moonshard:params"
# MOONSHARD_ROUTES
• Const
MOONSHARD_ROUTES: "moonshard:routes" = "moonshard:routes"
# Options
• Const
Options: (Anonymous function) = buildMethodDecorator(RequestMethod.OPTIONS)
# PARAMTYPES_METADATA
• Const
PARAMTYPES_METADATA: "design:paramtypes" = "design:paramtypes"
# Param
• Const
Param: (Anonymous function) = buildParamDecoratorWithParamType(RouteParamtypes.PARAM)
# Patch
• Const
Patch: (Anonymous function) = buildMethodDecorator(RequestMethod.PATCH)
# Post
• Const
Post: (Anonymous function) = buildMethodDecorator(RequestMethod.POST)
# Put
• Const
Put: (Anonymous function) = buildMethodDecorator(RequestMethod.PUT)
# Query
• Const
Query: (Anonymous function) = buildParamDecoratorWithParamType(RouteParamtypes.QUERY)
# Reply
• Const
Reply: (Anonymous function) = buildParamDecorator(RouteParamtypes.REPLY)
# Request
• Const
Request: (Anonymous function) = buildParamDecorator(RouteParamtypes.REQUEST)
# app
• Let
app: any
# Functions
# Controller
▸ Const
Controller(options
: ControllerOptions | string): any
# Parameters:
Name | Type | Default value |
---|---|---|
options | ControllerOptions | string | "/" |
Returns: any
# Header
▸ Const
Header(name
: string, value
: string): (Anonymous function)
# Parameters:
Name | Type |
---|---|
name | string |
value | string |
Returns: (Anonymous function)
# HttpCode
▸ Const
HttpCode(status
: number): (Anonymous function)
# Parameters:
Name | Type |
---|---|
status | number |
Returns: (Anonymous function)
# Injectable
▸ Injectable(): (Anonymous function)
Returns: (Anonymous function)
# Pipe
▸ Const
Pipe(...funtions
: any[]): (Anonymous function)
# Parameters:
Name | Type |
---|---|
...funtions | any[] |
Returns: (Anonymous function)
# Redirect
▸ Const
Redirect(url
: string, statusCode
: number): (Anonymous function)
# Parameters:
Name | Type | Default value |
---|---|---|
url | string | "" |
statusCode | number | 302 |
Returns: (Anonymous function)
# buildMethodDecorator
▸ Const
buildMethodDecorator(method
: string): (Anonymous function)
# Parameters:
Name | Type |
---|---|
method | string |
Returns: (Anonymous function)
# buildParamDecorator
▸ Const
buildParamDecorator(type
: any): (Anonymous function)
# Parameters:
Name | Type |
---|---|
type | any |
Returns: (Anonymous function)
# buildParamDecoratorWithParamType
▸ Const
buildParamDecoratorWithParamType(type
: any): (Anonymous function)
# Parameters:
Name | Type |
---|---|
type | any |
Returns: (Anonymous function)
# castToBoolean
▸ castToBoolean(value
: boolean | string): boolean
# Parameters:
Name | Type |
---|---|
value | boolean | string |
Returns: boolean
# castToInt
▸ castToInt(value
: number | string): number
# Parameters:
Name | Type |
---|---|
value | number | string |
Returns: number
# castToNumber
▸ castToNumber(value
: string | number): number
# Parameters:
Name | Type |
---|---|
value | string | number |
Returns: number
# close
▸ Const
close(): Promise<void>
Returns: Promise<void>
# createApp
▸ Const
createApp<Server, Logger>(options?
: FastifyServerOptions<Server, Logger>, __namedParameters
: { globOptions: undefined | IOptions ; pattern: undefined | string }): FastifyInstance
# Type parameters:
Name | Type | Default |
---|---|---|
Server | Server | - |
Logger | FastifyLoggerInstance | FastifyLoggerInstance |
# Parameters:
Name | Type | Default value |
---|---|---|
options? | FastifyServerOptions<Server, Logger> | - |
__namedParameters | { globOptions: undefined | IOptions ; pattern: undefined | string } | { |
pattern: 'src/**/*.@(ctrl|controller).ts',
globOptions: { matchBase: true },
} |
Returns: FastifyInstance
# defaultErrorHandler
▸ defaultErrorHandler(error
: any, request
: any, reply
: any): any
# Parameters:
Name | Type |
---|---|
error | any |
request | any |
reply | any |
Returns: any
# getApp
▸ Const
getApp(): FastifyInstance
Returns: FastifyInstance
# getInstance
▸ getInstance<T>(target
: {}): T
# Type parameters:
Name |
---|
T |
# Parameters:
Name | Type |
---|---|
target | {} |
Returns: T
# getStatusByMethod
▸ Const
getStatusByMethod(method
: string): 201 | 204 | 200
# Parameters:
Name | Type |
---|---|
method | string |
Returns: 201 | 204 | 200
# inject
▸ Const
inject(options
: InjectOptions | string): Promise<LightMyRequestResponse>
# Parameters:
Name | Type |
---|---|
options | InjectOptions | string |
Returns: Promise<LightMyRequestResponse>
# injectParams
▸ Const
injectParams(__namedParameters
: { paramsMetadata: any ; reply: any ; request: any }): any[]
# Parameters:
Name | Type |
---|---|
__namedParameters | { paramsMetadata: any ; reply: any ; request: any } |
Returns: any[]
# injectableInstance
▸ injectableInstance(instance
: any): void
# Parameters:
Name | Type |
---|---|
instance | any |
Returns: void
# loadControllers
▸ Const
loadControllers(pattern
: string, options
: GlobOptions): void
# Parameters:
Name | Type | Default value |
---|---|---|
pattern | string | "src/**/*.@(ctrl |
options | GlobOptions | { matchBase: true } |
Returns: void
# spellbook
▸ spellbook(target
: any): any
# Parameters:
Name | Type |
---|---|
target | any |
Returns: any
# start
▸ Const
start(port
: number, options
: IAppOptions, globOptions
: {}): Promise<void>
# Parameters:
Name | Type | Default value |
---|---|---|
port | number | 3000 |
options | IAppOptions | { logger: true } |
globOptions | {} | {} |
Returns: Promise<void>
# transformAndValidate
▸ transformAndValidate<T>(classType
: ClassType<T>, jsonString
: string, options?
: TransformValidationOptions): Promise<T | T[]>
Asynchronously converts JSON string to class (constructor) object. Reject the promise if the object parsed from string doesn't pass validation.
# Type parameters:
Name | Type |
---|---|
T | CustomObject |
# Parameters:
Name | Type | Description |
---|---|---|
classType | ClassType<T> | The Class to parse and convert JSON to |
jsonString | string | The string containing JSON |
options? | TransformValidationOptions | - |
Returns: Promise<T | T[]>
Promise of object of given class T or array of objects given class T
▸ transformAndValidate<T>(classType
: ClassType<T>, array
: CustomObject[], options?
: TransformValidationOptions): Promise<T[]>
Asynchronously converts array of plain objects to array of class (constructor) objects. Reject the promise if any of the objects in array doesn't pass validation.
# Type parameters:
Name | Type |
---|---|
T | CustomObject |
# Parameters:
Name | Type | Description |
---|---|---|
classType | ClassType<T> | The Class to convert object to |
array | CustomObject[] | The array of objects to instantiate and validate |
options? | TransformValidationOptions | - |
Returns: Promise<T[]>
Promise of object of given class T
▸ transformAndValidate<T>(classType
: ClassType<T>, object
: CustomObject, options?
: TransformValidationOptions): Promise<T>
Asynchronously converts plain object to class (constructor) object. Reject the promise if the object doesn't pass validation.
# Type parameters:
Name | Type |
---|---|
T | CustomObject |
# Parameters:
Name | Type | Description |
---|---|---|
classType | ClassType<T> | The Class to convert object to |
object | CustomObject | The object to instantiate and validate |
options? | TransformValidationOptions | - |
Returns: Promise<T>
Promise of object of given class T
# transformAndValidateSync
▸ transformAndValidateSync<T>(classType
: ClassType<T>, jsonString
: string, options?
: TransformValidationOptions): T | T[]
Synchronously converts JSON string to class (constructor) object. Throws error if the object parsed from string doesn't pass validation.
# Type parameters:
Name | Type |
---|---|
T | CustomObject |
# Parameters:
Name | Type | Description |
---|---|---|
classType | ClassType<T> | The Class to parse and convert JSON to |
jsonString | string | The string containing JSON |
options? | TransformValidationOptions | - |
Returns: T | T[]
Object of given class T or array of objects given class T
▸ transformAndValidateSync<T>(classType
: ClassType<T>, array
: CustomObject[], options?
: TransformValidationOptions): T[]
Synchronously converts array of plain objects to array of class (constructor) objects. Throws error if any of the objects in array doesn't pass validation.
# Type parameters:
Name | Type |
---|---|
T | CustomObject |
# Parameters:
Name | Type | Description |
---|---|---|
classType | ClassType<T> | The Class to convert object to |
array | CustomObject[] | The array of objects to instantiate and validate |
options? | TransformValidationOptions | - |
Returns: T[]
Array of objects of given class T
▸ transformAndValidateSync<T>(classType
: ClassType<T>, object
: CustomObject, options?
: TransformValidationOptions): T
Synchronously converts plain object to class (constructor) object. Throws error if the object doesn't pass validation.
# Type parameters:
Name | Type |
---|---|
T | CustomObject |
# Parameters:
Name | Type | Description |
---|---|---|
classType | ClassType<T> | The Class to convert object to |
object | CustomObject | The object to instantiate and validate |
options? | TransformValidationOptions | - |
Returns: T
Object of given class T