@rnw-community/nestjs-enterprise
v2.17.1
Published
NestJS Enterprise is a collection of enterprise-grade modules for NestJS.
Maintainers
Readme
NestJS Enterprise
NestJS enterprise is a collection of tools and utilities to help you build enterprise-grade applications with NestJS.
Installation
Add @rnw-community/nestjs-enterprise to your project using you package manager of choice.
Peer dependencies that your project should contain:
- @nestjs/common
^11.1.28, - RxJS
^7.8.2
Some features have additional installation requirements, please refer to the feature documentation for more information.
Contents
Decorators
- Log - method call logging
- Histogram Metric - Prometheus histogram metrics
Distributed Locking
Create lock decorators bound to any injectable LockServiceInterface via NestJS DI:
const { SequentialLock, ExclusiveLock } = createPromiseLockDecorators(MyLockService, 5000);
const { SequentialLock$, ExclusiveLock$ } = createObservableLockDecorators(MyLockService, 5000);- createPromiseLockDecorators -
SequentialLock+ExclusiveLockfor async methods - createObservableLockDecorators -
SequentialLock$+ExclusiveLock$for Observable methods
Types
PreDecoratorFunction<TArgs, TResult>-(...args: TArgs) => TResult; the spread-form callback shape accepted as thepreLockargument toSequentialLock/ExclusiveLock/SequentialLock$/ExclusiveLock$(and the deprecatedLockPromise/LockObservable) — computes the lock resource key(s) from the decorated method's own arguments.import type { PreDecoratorFunction } from '@rnw-community/nestjs-enterprise'; const preLock: PreDecoratorFunction<[orderId: string], string[]> = orderId => [`order:${orderId}`];LockServiceInterface- the contractcreatePromiseLockDecorators/createObservableLockDecoratorsexpect from an injectable NestJS provider:acquire(resources, duration)resolves aLockHandle;tryAcquire(resources, duration)resolvesLockHandle | undefined, returningundefinedon contention instead of waiting or throwing.import type { LockServiceInterface } from '@rnw-community/nestjs-enterprise'; class RedlockService implements LockServiceInterface { async acquire(resources: string[], duration: number) { return { release: async () => undefined }; } async tryAcquire(resources: string[], duration: number) { return { release: async () => undefined }; } }LockHandle-{ release(): Promise<void> }; returned byLockServiceInterface.acquire/tryAcquireand released automatically once the decorated method settles.import type { LockHandle } from '@rnw-community/nestjs-enterprise'; const handle: LockHandle = { release: async () => undefined };
Deprecated
- LockPromise - use
createPromiseLockDecoratorsinstead - LockObservable - use
createObservableLockDecoratorsinstead - LockableService - use
LockServiceInterfaceinstead
License
This library is licensed under The MIT License.
