con un clic
nestjs-context
nestjs-context contiene 5 skills recopiladas de DavideCarvalho, con cobertura ocupacional por repositorio y páginas de detalle dentro del sitio.
Skills en este repositorio
Wire @dudousxd/nestjs-context into a NestJS app. Covers ContextModule.forRoot and ContextModule.forRootAsync (useFactory/useClass/useExisting), the global module, the ContextMiddleware that seeds traceId/requestId from the W3C traceparent header via enterWith, and the autoMiddleware/forRoutes/exclude options. Load when setting up the module, choosing forRoot vs forRootAsync, reading Context.traceId/tenantId/userRef, or establishing context outside HTTP (GraphQL/gRPC/queue) with Context.run / Context.enterWith.
Carry @dudousxd/nestjs-context across boundaries AsyncLocalStorage does not follow: queues, durable workers, sub-processes, setTimeout, and EventEmitter callbacks. Covers Context.serialize/deserialize with the plain ContextCarrier, Context.bind for snapshot-and-re-enter, the carrier config option, W3C baggage via Context.toBaggage/fromBaggage with BaggageKeyMap, and the traceparent helpers parseTraceparent/extractTraceparent/toTraceparent/randomTraceId. Also covers the process-global config and Context.resetConfig. Load when propagating context to a BullMQ job, durable workflow, timer, or another service.
Extend the @dudousxd/nestjs-context store with your own typed fields and populate them. Covers ContextStore module augmentation (declare module to add locale/impersonatorId/etc.), the forRoot initialize hook that merges fields at request start, eager enrichers (ContextEnricher) run by the middleware after entering the context plus Context.runEnrichers for non-HTTP entrypoints, and Context.lazy for memoized on-first-access derived values. Load when adding a custom field, deciding between initialize/enrichers/lazy, or typing a new store property so Context.get()/set() stay type-safe.
Read and mutate the per-request store of @dudousxd/nestjs-context. Covers Context.get/traceId/tenantId/userRef, Context.set to fill userRef/tenantId from an auth guard, the one-shot warning when Context.set runs outside an active context, the UserRef { type, id } shape, and how consumer libraries inject the read-only ContextAccessor via @Optional() @Inject(CONTEXT_ACCESSOR). Load when reading or writing context fields, wiring an auth guard, or building a library that degrades cleanly when nestjs-context is absent.
Test code that reads @dudousxd/nestjs-context by running it inside a fake store. Covers @dudousxd/nestjs-context-testing's runWithContext(partial, fn) which scopes a fake ContextStore around fn (auto-filling a random traceId), and enterContext(partial) which uses enterWith so the fake store survives past the setup call (for code that reads context after an await). Covers PartialContextStore and resetting the process-global singleton with Context.resetConfig between tests. Load when writing vitest/jest tests that assert on Context.traceId, tenantId, or userRef.