Curated facade over
@concepta/nestjs-*plus a handful of small utilities every other Rockets package shares.
Status: stable.
@bitwild/rockets-common is the shared facade over upstream motors (@concepta/nestjs-hook, nestjs-common, nestjs-authentication, nestjs-swagger-ui) plus six small local helpers. It is not a Nest module and does not replace those packages — it centralises imports for the rest of Rockets.
The package has no module. It is a pure import surface: re-exports plus six local utilities.
- A re-export of
@concepta/nestjs-hook(HookModule,Spec,Specification,UseHooks, …). - A re-export of
@concepta/nestjs-common(RuntimeException,AuditDto,CommonEntityDto,AppContextHost,Operationenum,DomainFactory, …). - The relocated
AuthUserdecorator from@concepta/nestjs-authentication. - A re-export of
@concepta/nestjs-swagger-ui(SwaggerUiModule,SwaggerUiService). - Six local utilities listed in Reference.
- You are building another Rockets package (or an internal app library) and want one stable import path for the shared primitives.
- You need any of the six local helpers (
deriveEntityKey,whitelistedFromDto,stripUndefined, …).
- You are writing an end-user app on top of
@bitwild/rocketsor@bitwild/rockets-auth. Both already depend on this package transitively and re-export what they need. - You only want one symbol — import it directly from its source
@concepta/nestjs-*package instead.
yarn add @bitwild/rockets-common \
@nestjs/common class-transformer class-validator reflect-metadata rxjs@nestjs/common, class-transformer, class-validator, reflect-metadata, and rxjs are peer dependencies — bring them from your app.
import {
AuditDto,
RuntimeException,
Operation,
deriveEntityKey,
whitelistedFromDto,
} from '@bitwild/rockets-common';
class PetEntity {}
deriveEntityKey(PetEntity); // 'pet'
throw new RuntimeException({
message: 'Pet not found',
httpStatus: 404,
});No module to register, no providers to inject — it is just imports.
Same algorithm the Rockets resource planner uses: strip a trailing Entity suffix and lowercase the first character. Use this when you want the same string everywhere (dynamic repository key, hook scope, swagger tag).
import { deriveEntityKey } from '@bitwild/rockets-common';
deriveEntityKey(UserEntity); // 'user'
deriveEntityKey(PetTagEntity); // 'petTag'
deriveEntityKey(Order); // 'order' (no `Entity` suffix to strip)For namespaced or ambiguous classes, pass an explicit string key everywhere instead.
Most Rockets APIs accept both 'pet' and PetEntity. resolveEntityKey is the canonical implementation of that contract.
import { resolveEntityKey } from '@bitwild/rockets-common';
resolveEntityKey('pet'); // 'pet'
resolveEntityKey(PetEntity); // 'pet' (via deriveEntityKey)whitelistedFromDto runs class-transformer + class-validator with whitelist: true and throws BadRequestException on validation errors. Used by handlers that receive a loose object and need to coerce it to a known DTO shape.
import { whitelistedFromDto } from '@bitwild/rockets-common';
import { UpdateUserMetadataDto } from './dto/update-user-metadata.dto';
const clean = await whitelistedFromDto<UpdateUserMetadataDto>(
UpdateUserMetadataDto,
rawInput,
);PATCH handlers typically only set the keys the client sent. Spreading them straight into a repository update would wipe untouched fields back to undefined. stripUndefined keeps only the defined keys.
import { stripUndefined } from '@bitwild/rockets-common';
await this.repo.update(id, stripUndefined(dto));Upstream commands like UpdateUserCommand expect a RepositoryContextInterface as their first argument. createRepositoryContext is the minimal shape.
import { createRepositoryContext } from '@bitwild/rockets-common';
await this.commandBus.execute(
new UpdateUserCommand(createRepositoryContext('user'), id, dto),
);logAndGetErrorDetails standardises the error-handling pattern used across Rockets handlers: log with a custom message + context, then return { errorMessage, errorStack } for re-throw.
import { Logger } from '@nestjs/common';
import { logAndGetErrorDetails } from '@bitwild/rockets-common';
const logger = new Logger('PetService');
try {
await this.pets.delete(id);
} catch (err) {
const { errorMessage } = logAndGetErrorDetails(
err,
logger,
'failed to delete pet',
{ petId: id },
);
throw new Error(errorMessage);
}| Motor | Re-exported from this package |
|---|---|
@concepta/nestjs-hook |
HookModule, Spec, UseHooks, specifications |
@concepta/nestjs-common |
exceptions, audit DTOs, AppContextHost, Operation |
@concepta/nestjs-authentication |
AuthUser decorator |
@concepta/nestjs-swagger-ui |
SwaggerUiModule, SwaggerUiService |
Local only: deriveEntityKey, whitelistedFromDto, stripUndefined, createRepositoryContext, getErrorDetails, logAndGetErrorDetails.
| Symbol | Purpose |
|---|---|
deriveEntityKey(cls) |
Class → camelCase key (strip Entity, lowercase first char). |
resolveEntityKey(keyOrClass) |
Accept either form, return the string key. |
whitelistedFromDto(dtoClass, data) |
class-validator whitelist → plain object; throws BadRequestException on errors. |
stripUndefined(input) |
Return a new object without keys whose value is undefined. |
createRepositoryContext(entityKey) |
Build the minimal { entity } object for upstream CQRS commands. |
getErrorDetails(err) / logAndGetErrorDetails(err, logger, msg, ctx?) |
Normalise unknown errors into { errorMessage, errorStack }. |
HookModule, HookResolverService, Hook, UseHooks, Specification, createHookMethodDecorator, Spec, CompositeSpecification, AlwaysSpecification, NeverSpecification, AndSpecification, OrSpecification, NotSpecification. Types: HookTypeInterface, HookMethodMetadataInterface, HookMethodKeyType.
- Settings:
createSettingsProvider. - Exceptions:
RuntimeException,NotAnErrorException,OverlayNotDefinedException,ModelQueryException,ModelMutateException,ModelValidationException,ModelIdNoMatchException. - DTOs:
AuditDto,CommonEntityDto,ReferenceIdDto. - Context:
AppContextHost,getAppContext,Ctx,OverlayRef,ContextOverlayInterceptor,RefsToMethods. - Events:
EventContextHost. - Enums:
ActionEnum,Operation,ReadOperations,WriteOperations,MutateOperations. - Domain:
DomainFactory. - Utilities:
mapNonErrorToException,mapHttpStatus,toMilliseconds. - Interfaces (type-only): all
Reference*Interface,Audit*Interface,By{Email,Id,Subject,Username}Interface,{Create,Remove,Replace,Update}OneInterface, plusLiteralObject,DeepPartial,AppContextInterface,HookContextInterface,EventContextInterface,SpecificationInterface,HookOption,HookWithSpec.
@concepta/nestjs-authentication:AuthUserdecorator (relocated upstream in v8).@concepta/nestjs-swagger-ui:SwaggerUiModule,SwaggerUiService,SwaggerUiOptionsInterface.
BSD-3-Clause