@panenco/papi / Exports
- Body
- ConditionalExpose
- Date
- DefaultValue
- Lower
- Nested
- Numeric
- Query
- Representer
- ListRepresenter
- ArrayRepresenter
- TransformBooleanString
Ƭ IRequirement: (request
: Request
) => Promise
<void
> | void
▸ (request
): Promise
<void
> | void
Authorization definition base type
Implementation should validate required check and throw [[Unauthorized]] or [[Forbidden]] Exception
Name | Type |
---|---|
request |
Request |
Promise
<void
> | void
authorization/requirement.interface.ts:10
▸ createAccessToken(secret
, expiresIn
, data
): Promise
<IAccessToken
>
Generate an HS256 JWT Bearer token signed by a provided secret
Name | Type | Description |
---|---|---|
secret |
string |
Secret used to sign the JWT |
expiresIn |
number |
Expiry Time in seconds |
data |
object |
Data to be serialized in the JWT |
Promise
<IAccessToken
>
An object containing the expiry time and the generated token
authorization/accessTokens.ts:15
▸ getAccessTokenData(token
, secret
): any
Decode and verify JWT token
Name | Type | Description |
---|---|---|
token |
string |
JWT token to decode and validate |
secret |
string |
The secret that should have been used to sign the token |
any
Decoded token data
authorization/accessTokens.ts:30
▸ getAuthenticator(jwtSecret
): (action
: Action
, requirements
: IRequirement
| (IRequirement
| IRequirement
[])[]) => Promise
<boolean
>
Integrates with routing controller @Authorize
decorator
Supply an array of groups where within a group all requirements need to be valid
Example1: [[valid1, valid2], [valid3, invalid1]] => success
Example2: [valid1, invalid1] => success
Example3: [[valid1, invalid1]] => fail
Name | Type | Description |
---|---|---|
jwtSecret |
string |
JWT secret to be used to verify tokens |
fn
Authentication checker that should be passed into useExpressServer => authorizationChecker
▸ (action
, requirements
): Promise
<boolean
>
Name | Type |
---|---|
action |
Action |
requirements |
IRequirement | (IRequirement | IRequirement [])[] |
Promise
<boolean
>
authorization/authenticator.ts:16
▸ createListRepresentation<TChild
>(type
): ClassType
<ListRepresentation
<TChild
>>
Output DTO for paginated lists. In order to generate the correct metadata for the validation and API documentation for the list schema we need to generate the class with the class type of the child DTO of the list. This function can be used in combination with the representer. But a shorthand [[listRepresenter]] als o exists.
Name |
---|
TChild |
Name | Type | Description |
---|---|---|
type |
ClassType <TChild > |
The class type of a single list item |
ClassType
<ListRepresentation
<TChild
>>
The class type of a list representation with the necessary metadata for the items array. Similar to [[ListRepresentation]] but with metadata.
contracts/representations/list.representation.ts:28
▸ Body(bodyOptions?
, validatorOptions?
, type?
): (target
: Object
, propertyKey
: string
, parameterIndex
: number
) => void
Allows to inject and validate a request body value to the controller action parameter.
Must be applied on a controller action parameter.
Name | Type | Description |
---|---|---|
bodyOptions? |
InputOptions |
routing-controllers body options for binding the request body |
validatorOptions? |
ValidatorOptions |
class-validator validation options for the validation to be performed. |
type? |
Newable <any > |
Override inferred type, set the expected type of the body |
fn
▸ (target
, propertyKey
, parameterIndex
): void
Name | Type |
---|---|
target |
Object |
propertyKey |
string |
parameterIndex |
number |
void
decorators/body.decorator.ts:22
▸ ConditionalExpose(condition
): (target
: any
, key
: string
) => void
Extended version of [[class-transformer]][[Expose]] decorator where a condition can be passed to optionally return the property this is applied on.
Name | Type | Description |
---|---|---|
condition |
(object : any ) => boolean |
Condition to Expose the property. With argument the complete current object. |
fn
▸ (target
, key
): void
Name | Type |
---|---|
target |
any |
key |
string |
void
decorators/conditionalExpose.decorator.ts:11
▸ Date(): (target
: any
, key
: string
) => void
Extended version of [[class-validator]][[IsDate]] decorator
Checks if a value is a date.
Transforms string dates into JS Dates.
fn
▸ (target
, key
): void
Name | Type |
---|---|
target |
any |
key |
string |
void
decorators/date.decorator.ts:13
▸ DefaultValue(value
): (target
: any
, key
: string
) => void
Decorator that produces a default value for non-existing or empty properties when transforming with [[class-transformer]]
Name | Type | Description |
---|---|---|
value |
any |
The default value to be set. |
fn
▸ (target
, key
): void
Name | Type |
---|---|
target |
any |
key |
string |
void
decorators/defaultValue.decorator.ts:9
▸ Lower(): PropertyDecorator
Transforms strings to lowercase.
PropertyDecorator
decorators/lower.decorator.ts:8
▸ Nested<T
>(type
, isArray?
): (object
: any
, propertyName
: string
) => void
Nested objects with this decorator will also be validated.
Transforms the nested objects to the defined type
Name |
---|
T |
Name | Type | Default value | Description |
---|---|---|---|
type |
ClassType <T > |
undefined |
The type to validate and transform the nested property |
isArray |
boolean |
false |
Whether the property is an object or an array of objects |
fn
▸ (object
, propertyName
): void
Name | Type |
---|---|
object |
any |
propertyName |
string |
void
decorators/nested.decorator.ts:16
▸ Numeric(): (target
: any
, key
: string
) => void
Checks if a value is a number.
Transforms strings and other matching types to numbers
fn
▸ (target
, key
): void
Name | Type |
---|---|
target |
any |
key |
string |
void
decorators/numeric.decorator.ts:11
▸ Query(options?
, validatorOptions?
, type?
): (target
: Object
, propertyKey
: string
| symbol
, parameterIndex
: number
) => void
Allows to inject and validate a request query params to the controller action parameter.
Must be applied on a controller action parameter.
Name | Type | Description |
---|---|---|
options |
InputOptions |
[[routing-controllers]] param options for binding the request query |
validatorOptions? |
ValidatorOptions |
[[class-validator]] validation options for the validation to be performed. |
type? |
Newable <any > |
Override inferred type, set the expected type of the query |
fn
▸ (target
, propertyKey
, parameterIndex
): void
Name | Type |
---|---|
target |
Object |
propertyKey |
string | symbol |
parameterIndex |
number |
void
decorators/query.decorator.ts:16
▸ Representer(representation
, statusCode?
, options?
): (target
: any
, key
: string
) => void
Decorator to be used on [[routing-controllers]] controller method
Apply representation transformation on a controller method output.
The result of the transformed return value will be JSON serialized as the response body.
Must be applied on a controller method.
Name | Type | Description |
---|---|---|
representation |
ClassType <any > |
class type of the representation to be used by [[class-transformer]] |
statusCode? |
number |
Optional Status code of the success response |
options |
Object |
OpenAPI options for API documentation |
options.contentType? |
string |
- |
options.description? |
string |
- |
fn
▸ (target
, key
): void
Name | Type |
---|---|
target |
any |
key |
string |
void
decorators/representer.decorator.ts:20
▸ ListRepresenter(representation
, statusCode?
, options?
): (target
: any
, key
: string
) => void
Decorator to be used on [[routing-controllers]] controller method
Apply paginated list representation transformation on a controller method output.
The result of the transformed return value will be JSON serialized as the response body.
Must be applied on a controller method.
Name | Type | Default value | Description |
---|---|---|---|
representation |
ClassType <any > |
undefined |
class type of the representation to be used by [[class-transformer]] |
statusCode |
number |
200 |
Optional Status code of the success response |
options |
Object |
{} |
OpenAPI options for API documentation Structure of the response: { items: object[], count: number } |
options.contentType? |
string |
undefined |
- |
options.description? |
string |
undefined |
- |
fn
▸ (target
, key
): void
Name | Type |
---|---|
target |
any |
key |
string |
void
decorators/representer.decorator.ts:58
▸ ArrayRepresenter(representation
, statusCode?
, options?
): (target
: any
, key
: string
) => void
Decorator to be used on [[routing-controllers]] controller method
Apply array representation transformation on a controller method output.
The result of the transformed return value will be JSON serialized as the response body.
Must be applied on a controller method.
Name | Type | Default value | Description |
---|---|---|---|
representation |
ClassType <any > |
undefined |
class type of the representation to be used by [[class-transformer]] |
statusCode |
number |
200 |
Optional Status code of the success response |
options |
Object |
{} |
OpenAPI options for API documentation Structure of the response: object[] |
options.contentType? |
string |
undefined |
- |
options.description? |
string |
undefined |
- |
fn
▸ (target
, key
): void
Name | Type |
---|---|
target |
any |
key |
string |
void
decorators/representer.decorator.ts:91
▸ TransformBooleanString(): PropertyDecorator
Transformation decorator
Transforms string boolean into JS boolean.
PropertyDecorator
decorators/transformBooleanString.decorator.ts:10
▸ importClasses<TClassType
>(directories
): [ClassType
<TClassType
>]
Import all classes within a list of directories (js files)
Name | Type |
---|---|
TClassType |
any |
Name | Type | Description |
---|---|---|
directories |
string [] |
directories glob to scan for classes |
[ClassType
<TClassType
>]
Array of class types
utils/helpers/importClasses.ts:12
▸ stringToObject(path
, value
, obj?
): object
Creates an object from a property path
Name | Type | Description |
---|---|---|
path |
string |
Path to create an object from. Ex. root.child.subChild |
value |
any |
The value to set on the lowest level Ex. true |
obj |
object |
Optional root object |
object
The object that has been created from the path. Ex. { root: { child: { subChild: true } } }
utils/helpers/stringToObject.ts:10
▸ validator(object
, options?
): Promise
<void
>
Validates an object with class-validator [[validate
]]
Name | Type | Description |
---|---|---|
object |
object |
The object to validate |
options? |
ValidatorOptions |
validation options |
Promise
<void
>
▸ errorMiddleware(error
, req
, res
, next
): void
Express middleware to process and output errors.
Errors extended from [[ErrorBase
]] or [[HttpError
]] will be handled and serialized to the response with the corresponding code
Name | Type | Description |
---|---|---|
error |
Error |
Error to be processed. ErrorBase will be processed accordingly. Any other Error will result into a 500 with the specified message. |
req |
Request <ParamsDictionary , any , any , ParsedQs , Record <string , any >> |
express Request |
res |
Response <any , Record <string , any >> |
express Response |
next |
NextFunction |
express NextFunction |
void