Registry / aws / nestjs-dynamoose

nestjs-dynamoose

JSON →
library0.6.0jsnpmunverified

nestjs-dynamoose is a module designed to seamlessly integrate the Dynamoose ODM (Object Document Mapper) for DynamoDB into NestJS applications. It provides NestJS-specific modules and decorators that leverage NestJS's robust dependency injection system, allowing developers to define DynamoDB schemas and models in a structured, modular way. The current stable version is 0.6.0, with releases occurring frequently to maintain compatibility with new versions of NestJS and Dynamoose. Key differentiators include its adherence to NestJS architectural patterns (e.g., `forRoot`, `forFeature`), simplifying the setup and management of DynamoDB connections and models compared to integrating Dynamoose directly without the NestJS wrapper, and enabling easy configuration of AWS credentials and local DynamoDB instances.

npm install nestjs-dynamoose
INSTALL
IMPORT
SIG · NESTJS-DYNAMOOSE
N
nestjs-dynamoose
awsjavascriptv0.6.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DynamooseModule
import { DynamooseModule } from 'nestjs-dynamoose';
const { DynamooseModule } = require('nestjs-dynamoose');
nestjs-dynamoose is designed for modern NestJS projects primarily using ES Modules.
Schema
import { Schema } from 'dynamoose';
import { Schema } from 'nestjs-dynamoose';
The Dynamoose Schema class is imported directly from the `dynamoose` package, not the wrapper.
Model type
import { Model } from 'dynamoose';
import { Model } from 'nestjs-dynamoose';
Type definitions for Dynamoose models are exported by the underlying `dynamoose` library.

This quickstart demonstrates how to configure Dynamoose at the root of a NestJS application, define a Dynamoose schema, register it with a feature module, and inject the Dynamoose model into a service for data operations.

import { Module } from '@nestjs/common'; import { DynamooseModule } from 'nestjs-dynamoose'; import { Schema } from 'dynamoose'; // user/user.schema.ts export const UserSchema = new Schema({ id: { type: String, hashKey: true }, name: { type: String }, email: { type: String } }); // user/user.service.ts (simplified) import { Injectable } from '@nestjs/common'; import { Model } from 'dynamoose'; import { InjectModel } from 'nestjs-dynamoose'; interface UserKey { id: string; } interface User extends UserKey { name: string; email?: string; } @Injectable() export class UserService { constructor(@InjectModel('User') private userModel: Model<User, UserKey>) {} async create(user: User): Promise<User> { return this.userModel.create(user); } } // user/user.module.ts @Module({ imports: [ DynamooseModule.forFeature([{ name: 'User', schema: UserSchema, options: { tableName: 'user-table-name' // Explicit table name } }]) ], providers: [UserService], exports: [UserService] }) export class UserModule {} // app.module.ts @Module({ imports: [ DynamooseModule.forRoot({ aws: { region: process.env.AWS_REGION ?? 'us-east-1', accessKeyId: process.env.AWS_ACCESS_KEY_ID ?? '', secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ?? '' }, local: process.env.DYNAMODB_ENDPOINT ?? false // Set to true or 'http://localhost:8000' for local DynamoDB }), UserModule ] }) export class AppModule {}
Debug
Known issues
breakingThe peer dependency for NestJS has been updated multiple times, requiring users to upgrade their NestJS versions. Specifically, v0.6.0 requires NestJS 11, v0.5.5 required NestJS 10, and older versions required 8 or 9.
fix
Ensure your NestJS monorepo dependencies (`@nestjs/common`, `@nestjs/core`) match the peer dependency range specified for the installed `nestjs-dynamoose` version.
affects: >=0.5.5
breakingThe `tableName` property, previously configurable directly within the schema definition, was moved to the `options` object within `DynamooseModule.forFeature()`.
fix
Refactor your `DynamooseModule.forFeature()` configuration. Instead of `schema: { tableName: 'my-table', ... }`, use `options: { tableName: 'my-table' }` as a sibling to `schema`.
affects: >=0.5.4
breakingThe terminology `document` was renamed to `item` to align with Dynamoose v3 conventions and prevent confusion with MongoDB documents.
fix
Update all occurrences where you previously referred to 'document' in your code (e.g., interface names, variable names) to 'item'.
affects: >=0.5.3
breakingThe peer dependency for `dynamoose` has been updated, requiring users to upgrade their `dynamoose` library. Version 0.5.6 introduced support for Dynamoose v4, and v0.5.4 added support for Dynamoose v3.2.0.
fix
Upgrade your `dynamoose` package to a version compatible with your `nestjs-dynamoose` installation, typically `^3.2.0` or `^4.0.0` depending on the `nestjs-dynamoose` version.
affects: >=0.5.4
gotchaWhen using `DynamooseModule.forRootAsync()`, the `useFactory` callback's first parameter is reserved for future use and should be ignored (e.g., by using `_`).
fix
If defining `forRootAsync` with `useFactory`, ensure your factory function signature includes an ignored first parameter, e.g., `useFactory: async (_, configService: ConfigService) => ({ /* ... */ })`.
affects: >=0.1.0
Errors
Common errors & fixes
Nest can't resolve dependencies of the XService (?, YRepository)
The Dynamoose model was not correctly injected or the feature module was not imported.
fix
Ensure `DynamooseModule.forFeature()` is imported in the relevant feature module and that `InjectModel('YourModelName')` is used correctly in the service constructor, matching the name provided in `forFeature`.
No provider for DynamooseModuleOptions! (or similar DI error related to DynamooseModule)
The `DynamooseModule.forRoot()` or `DynamooseModule.forRootAsync()` was not called or configured in the root `AppModule`.
fix
Add `DynamooseModule.forRoot()` (or `forRootAsync()`) to the `imports` array of your main `AppModule` to initialize the Dynamoose connection.
Type 'Schema<any, any>' is not assignable to type 'Schema<any, any>'
Inconsistent versions of `dynamoose` or `@types/dynamoose` in your project dependencies, often caused by transitive dependencies or different peer dependency requirements.
fix
Check your `package.json` and `package-lock.json` for multiple versions of `dynamoose` or its types. Try `npm dedupe` or manually adjust versions to a single, compatible one.
Invalid table options: Table name must be a string
The `tableName` option is missing or incorrectly specified in `DynamooseModule.forFeature()`'s options, or is still located in the old schema definition after v0.5.4.
fix
Move `tableName` from the schema definition to the `options` property within the object passed to `DynamooseModule.forFeature()`, ensuring it's a string.
Upgrade
Version history
0.6.0latest on npm
Audit
Dependencies
@aws-sdk/client-dynamodbrequiredUnderlying AWS SDK for DynamoDB operations, required by Dynamoose.
@nestjs/commonrequiredCore NestJS framework peer dependency for common utilities and decorators.
@nestjs/corerequiredCore NestJS framework peer dependency for module and application bootstrap.
dynamooserequiredThe Object Document Mapper (ODM) for DynamoDB that this package wraps.
reflect-metadatarequiredRequired by NestJS for TypeScript decorators and metadata reflection.
rxjsrequiredReactive programming library, a standard peer dependency for NestJS.
Agent activity
8 hits · last 30 days
node
8
Resources
nestjs-dynamoose — npm install nestjs-dynamoose · libregistry