1.0.77 • Published 1 year ago

@sdflc/backend-helpers v1.0.77

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

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.0.77

1 year ago

1.0.76

1 year ago

1.0.73

1 year ago

1.0.72

1 year ago

1.0.71

1 year ago

1.0.70

1 year ago

1.0.75

1 year ago

1.0.66

1 year ago

1.0.65

1 year ago

1.0.64

1 year ago

1.0.63

1 year ago

1.0.69

1 year ago

1.0.68

1 year ago

1.0.67

1 year ago

1.0.62

1 year ago

1.0.61

1 year ago

1.0.60

2 years ago

1.0.55

2 years ago

1.0.59

2 years ago

1.0.58

2 years ago

1.0.57

2 years ago

1.0.56

2 years ago

1.0.53

2 years ago

1.0.48

2 years ago

1.0.49

2 years ago

1.0.51

2 years ago

1.0.50

2 years ago

1.0.52

2 years ago

1.0.39

2 years ago

1.0.40

2 years ago

1.0.44

2 years ago

1.0.43

2 years ago

1.0.42

2 years ago

1.0.41

2 years ago

1.0.47

2 years ago

1.0.46

2 years ago

1.0.45

2 years ago

1.0.38

2 years ago

1.0.26

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.35

2 years ago

1.0.34

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.10

2 years ago

1.0.12

2 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.3

3 years ago

1.0.0

3 years ago