Fault tolerance tools for TypeScript
out·work
/ˈoutˌwərk/
a section of a fortification or system of defense which is in front of the main part.
As a Decorator
class SomeClass {
@retry({
maxAttempts: 3,
backOff: 100,
backOffPolicy: BackOffPolicy.CONSTANT,
shouldRetry: (e: Error) => {
return e.message === 'Error: 429'
},
})
async someFnWithConstantRateRetries(): Promise<any> {
throw new Error('Error: 404')
}
@retry({
maxAttempts: 3,
backOffPolicy: BackOffPolicy.EXPONENTIAL,
maxDelay: 1000,
minDelay: 100,
jitter: true,
})
async someFnWithExponentialBackOffRetries(): Promise<any> {
return new Promise((_, reject) => {
reject(new Error('Broke'))
})
}
}
As a HoF:
const myAsyncFunc = async (num: number, str: string): Promise<void> => {...}
const myAsyncFuncWithRetries =
withRetry(myAsyncFunc, {
maxAttempts: 3,
backOffPolicy: BackOffPolicy.EXPONENTIAL,
maxDelay: 1000,
minDelay: 100,
jitter: true
})
Tools:
- TypeScript 4.0
- ESLint
- Jest
- Prettier
- Reproducible environments with Volta
- install Volta
- .editorconfig for consistent file format
- Dependabot updates
- KodiakHQ automerges
build
- compile TSbuild:watch
- interactive watch mode to automatically transpile source filescheckcommit
- validate commit messageclean
- remove coverage data, Jest cache and transpiled files,clean-deps
- removenode_modules
clean-generated
- remove coverage and build directories and filesclean-logs
- remove log filescommit
- start commitformat
- format fileslint
- lint source files and tests,nuke
- clean everythingsort-pj
- sortpackage.json
test
- run tests,test:watch
- interactive watch mode to automatically re-run tests