npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@beardyman/fixture-interface-dynamodb

v1.0.4

Published

DynamoDB interface implementation extending the fixture-interface library

Downloads

8

Readme

@beardyman/fixture-interface-dynamodb

A DynamoDB implementation of the fixture-interface library for test data management. This package provides a simple, consistent API for setting up and tearing down DynamoDB test data using the fixture pattern.

Features

  • AWS SDK v3 - Built with modern AWS SDK v3 for DynamoDB operations
  • Fixture Pattern - Extends fixture-interface for consistent test data management
  • Dual Module Support - Works with both CommonJS and ES modules
  • TypeScript Support - Complete TypeScript declarations included
  • Flexible Key Handling - Works with both single keys (id) and composite keys (partitionKey/sortKey)
  • Smart Key Extraction - Automatically extracts keys from full item objects
  • Comprehensive Testing - Full unit and functional test coverage

Installation

npm install @beardyman/fixture-interface-dynamodb

Quick Start

Basic Usage

const DynamoFx = require('@beardyman/fixture-interface-dynamodb');

// Create a fixture for your DynamoDB table
const userFixture = new DynamoFx({
  region: 'us-east-1',
  endpoint: 'http://localhost:8000' // For DynamoDB Local
}, 'users');

// Test data
const testUsers = [
  { id: 'user1', name: 'John Doe', email: '[email protected]' },
  { id: 'user2', name: 'Jane Smith', email: '[email protected]' }
];

// In your test setup
async function setupTest() {
  // Provision test data
  await userFixture.provision(testUsers);
}

// In your test teardown
async function cleanupTest() {
  // Remove all test data
  await userFixture.cleanup();
}

Using with Mocha

describe('User Service Tests', () => {
  let userFixture;

  before(async () => {
    userFixture = new DynamoFx({
      region: 'us-east-1',
      endpoint: 'http://localhost:8000'
    }, 'users');
  });

  beforeEach(async () => {
    const testData = [
      { id: 'test-user', name: 'Test User', email: '[email protected]' }
    ];
    await userFixture.provision(testData);
  });

  afterEach(async () => {
    await userFixture.cleanup();
  });

  it('should find user by id', async () => {
    const result = await userFixture.get({ id: 'test-user' });
    expect(result.Item.name).to.equal('Test User');
  });
});

Composite Key Tables

const orderFixture = new DynamoFx({
  region: 'us-east-1'
}, 'orders');

// Working with composite keys
const testOrders = [
  { 
    partitionKey: 'user#123', 
    sortKey: 'order#001',
    amount: 99.99,
    status: 'pending'
  }
];

await orderFixture.provision(testOrders);

// Get specific order
const result = await orderFixture.get({
  partitionKey: 'user#123',
  sortKey: 'order#001'
});

API Reference

Constructor

new DynamoFx(connConfig, tableName)
  • connConfig - AWS DynamoDB client configuration object
  • tableName - Name of the DynamoDB table

Methods

insert(item)

Insert a single item into the table.

  • Returns: Promise<PutCommandOutput>

remove(keyOrItem)

Remove an item from the table. Accepts either a key object or full item.

  • Returns: Promise<DeleteCommandOutput>

get(keyOrItem)

Retrieve an item from the table. Accepts either a key object or full item.

  • Returns: Promise<GetCommandOutput>

provision(items)

Insert multiple items and track them for cleanup (inherited from fixture-interface).

  • Returns: Promise<Array>

cleanup()

Remove all tracked items (inherited from fixture-interface).

  • Returns: Promise<void>

addData(item)

Add an item to the cleanup tracking list (inherited from fixture-interface).

  • Returns: number

getKey(keyOrItem)

Extract key attributes from a full item or return key if already a key object.

  • Returns: Key object suitable for DynamoDB operations

Configuration

AWS Configuration

The connConfig parameter accepts standard AWS DynamoDB client configuration:

const config = {
  region: 'us-east-1',
  credentials: {
    accessKeyId: 'your-access-key',
    secretAccessKey: 'your-secret-key'
  },
  endpoint: 'http://localhost:8000' // For DynamoDB Local
};

Testing with DynamoDB Local

For local testing, you can use DynamoDB Local:

# Install DynamoDB Local
npm install --save-dev dynamodb-local

# Configure for local testing
const config = {
  region: 'us-east-1',
  endpoint: 'http://localhost:8000',
  credentials: {
    accessKeyId: 'fakeKey',
    secretAccessKey: 'fakeSecret'
  }
};

Key Handling

The library automatically handles key extraction for both simple and composite key tables:

  • Single Key: { id: 'value' }
  • Composite Key: { partitionKey: 'pk-value', sortKey: 'sk-value' }

You can pass either full items or just keys to remove() and get() methods:

// These are equivalent for single key tables
await fixture.remove({ id: 'user1' });
await fixture.remove({ id: 'user1', name: 'John', email: '[email protected]' });

// These are equivalent for composite key tables  
await fixture.remove({ partitionKey: 'user#123', sortKey: 'order#001' });
await fixture.remove({ 
  partitionKey: 'user#123', 
  sortKey: 'order#001',
  amount: 99.99,
  status: 'pending'
});

Development

Building

npm run build        # Full build (ESM, CJS, TypeScript declarations)
npm run clean        # Clean build artifacts

Testing

npm test             # Run all tests
npm run test:unit    # Run unit tests only
npm run test:functional  # Run functional tests only (requires DynamoDB Local)

Test Coverage

npm run open:cov     # Open combined coverage report
npm run open:cov:unit      # Open unit test coverage
npm run open:cov:functional # Open functional test coverage

License

MIT

Contributing

This package follows the fixture-interface pattern for consistent test data management across different data stores. Contributions are welcome!