@sdflc/backend-helpers v1.0.77
Backend Helpers
This library has a variety of classes and functions to simplify building backend applications with the specific architecture within @sdflc
ecosystem.
Classes
BaseCore
This is the class that should be extended when you create a new core class. This is where all the business logic should be happeninng when processing request.
Constructor
Here are the props to be passed to the BaseCore constructor:
- db: Database - an object of Database class
- context?: any - the request context where you can add all you need, optional
- gateway?: any - main gateway class object that will be working with DB or 3rd part API
- gateways?: any - an object
- isProduction: boolean - true when the app is in production
- logLevel: LoggerLevels - log leves: 0 - none, 1 - errors, 2 - warnings, 3 - messages, 4 - all
- logger?: Logger - object of Logger class to be used as logger
- name?: string - name of the core
- requestId: string - Unique ID of a request processed, can be used for troubleshooting
- doAuth: boolean - call authorize method or not an incoming request
- doingWhat?: BaseCoreDoingWhatInterface - an object with text descriptions of each action, used to generate generic error message sent to user on an exception
- validators?: BaseCoreValidatorsInterface - an object with validator functions to be used to validate incoming data
- spaceGw?: BaseGateway - gateway to find a space, i.e. configration of the app. Each app can have several configurations to be used as one instance for different applications
- interserviceApiKey?: string - API key to be used to authenticate incoming request from another microservice, optional
- jwtSecret?: string - secret to be used to validate Authorize Bearer token on incoming request, optional
- verifytokenArgs?: VerifyUserTokenArgs - optional parameters for JWT token validation, like algorithm, etc
getDb()
getRequestId()
getContext(key?: string)
getGateways()
success(data: any, code?: number): any
failure(code: number, errorMsg: string, data?: any)
validationFailure(ex: any): any
exceptionFailure(ex: any, doingWhat: string | any, data?: any)
checkResult(args: any)
runAction(opt: CoreActionInterface)
Default Actions
list(args: any)
get(args: any)
getMany(args: any)
create(args: any)
createMany(args: any)
update(args: any)
updateMany(args: any)
set(args: any)
remove(args: any)
removeMany(args: any)
Default Action related events
beforeList(params: any, opt?: BaseCoreActionsInterface): Promise
afterList(params: any, opt?: BaseCoreActionsInterface): Promise
beforeCreate(params: any, opt?: BaseCoreActionsInterface): Promise
afterCreate(params: any, opt?: BaseCoreActionsInterface): Promise
beforeCreateMany(params: any, opt?: BaseCoreActionsInterface): Promise
afterCreateMany(params: any, opt?: BaseCoreActionsInterface): Promise
beforeUpdate(params: any, opt?: BaseCoreActionsInterface): Promise
afterUpdate(params: any, opt?: BaseCoreActionsInterface): Promise
beforeUpdateMany(params: any, opt?: BaseCoreActionsInterface): Promise
afterUpdateMany(params: any, opt?: BaseCoreActionsInterface): Promise
beforeSet(params: any, opt?: BaseCoreActionsInterface): Promise
afterSet(params: any, opt?: BaseCoreActionsInterface): Promise
beforeRemove(params: any, opt?: BaseCoreActionsInterface): Promise
afterRemove(params: any, opt?: BaseCoreActionsInterface): Promise
beforeRemoveMany(params: any, opt?: BaseCoreActionsInterface): Promise
afterRemoveMany(params: any, opt?: BaseCoreActionsInterface): Promise
onException(params: any, opt?: BaseCoreActionsInterface): Promise
Authorization
authenticate(params: any, opt?: BaseCoreActionsInterface)
BaseGateway
This is the class that should be extended when you create a new gateway class. This is where your code works with database or 3rd party API or do some works of the lowest level. Gateways are used by the core classes to actually do the job to implement one or another business logic.
constructor(props: BaseGatewayInterface)
generateId(args?: any)
onListFilter(query: any, filterParams: any)
onUpdateFilter(query: any, filterParams: any)
onRemoveFilter(query: any, filterParams: any)
transformOnCreate(args: any)
transformOnUpdate(params: any, where?: any)
transformOnRemove(args?: any)
getDb()
getBuilder()
getIdField()
getCore()
setCore(core: BaseCore)
get(id: any)
getMany(ids: any[])
list(args?: ListArgsInterface)
create(args: any)
update(where: any, params: any)
updateMany(params: any): Promise<any[]>
increment(where: any, params: any)
decrement(where: any, params: any)
set(params: any): Promise<any[]>
remove(where: any, hardRemove = false)
buildDefaultGatewayProps = (args: any)
This function builds configuration object for a gateways inherited from the BaseGateway classs
BaseController
Base constroller class is used to create request handlers for RESTful API and provides some methods to simplify the task of working with requests and responses
json(method: any)
Application Context
createApiContext = async (args: ApiContextInterface)
createContextDefault = async (args: any)
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago