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

@mikecbrant/appsyncjs-dynamo

v1.0.1

Published

Dynamo library for Appsync JS runtime

Readme

@mikecbrant/appsyncjs-dynamo

Helpers for authoring AWS AppSync JavaScript (APPSYNC_JS) resolvers that target DynamoDB data sources.

This package currently exposes:

  • getItem(props) — builds a valid DynamoDBGetItemRequest object.
  • putItem(props) — builds a valid DynamoDBPutItemRequest object.
  • deleteItem(props) — builds a valid DynamoDBDeleteItemRequest object.
  • updateItem(props) — builds a valid DynamoDBUpdateItemRequest object.
  • buildProjectionExpression(fields) — builds a DynamoDB projection expression { expression, expressionNames } from a string array.

Peer dependency: @aws-appsync/utils (the request objects use the AppSync util.dynamodb helpers under the hood).

Examples

The snippets below are written for the AppSync JS runtime resolver format and show both request and response handlers.

  1. Basic GetItem
// resolvers/getUser.ts
import { getItem } from '@mikecbrant/appsyncjs-dynamo';
import { util } from '@aws-appsync/utils';

export function request(ctx) {
	return getItem({
		key: { pk: `USER#${ctx.args.id}` },
	});
}

export function response(ctx) {
	if (ctx.error) {
		// surface DynamoDB/Resolver errors via GraphQL
		util.error(ctx.error.message, ctx.error.type);
	}
	return ctx.result; // for GetItem, return the mapped item (or null)
}
  1. DeleteItem (basic)
// resolvers/deleteUser.ts
import { deleteItem } from '@mikecbrant/appsyncjs-dynamo';
import { util } from '@aws-appsync/utils';

export function request(ctx) {
	return deleteItem({
		key: { pk: `USER#${ctx.args.id}` },
		// optional: provide a condition
		// condition: { expression: 'attribute_exists(#pk)', expressionNames: { '#pk': 'pk' }, expressionValues: {} },
	});
}

export function response(ctx) {
	if (ctx.error) {
		util.error(ctx.error.message, ctx.error.type);
	}
	return ctx.result ?? null;
}

2a) DeleteItem and return deleted item

// resolvers/deleteUser.ts
import { deleteItem } from '@mikecbrant/appsyncjs-dynamo';

export function request(ctx) {
	return deleteItem({
		key: { pk: `USER#${ctx.args.id}` },
		returnDeleted: true, // adds returnValues: 'ALL_OLD' (DynamoDB API: ReturnValues)
	});
}

export function response(ctx) {
	// When returnDeleted is true, ctx.result contains the deleted item's previous attributes
	return ctx.result ?? null;
}
  1. GetItem with strongly consistent read and a projection
// resolvers/getUser.ts
import { getItem } from '@mikecbrant/appsyncjs-dynamo';
import { util } from '@aws-appsync/utils';

export function request(ctx) {
	return getItem({
		key: { pk: `USER#${ctx.args.id}` },
		consistentRead: true,
		returnedFields: ['pk', 'name', 'email'],
	});
}

export function response(ctx) {
	if (ctx.error) {
		util.error(ctx.error.message, ctx.error.type);
	}
	return ctx.result;
}
  1. Use buildProjectionExpression with your own DynamoDB request
// resolvers/listUserPosts.ts
import { buildProjectionExpression } from '@mikecbrant/appsyncjs-dynamo';
import { util } from '@aws-appsync/utils';

export function request(ctx) {
	const projection = buildProjectionExpression(['pk', 'sk', 'title', 'status']);

	return {
		operation: 'Query',
		query: {
			expression: '#pk = :pk',
			expressionNames: { '#pk': 'pk' },
			expressionValues: {
				':pk': util.dynamodb.toDynamoDB(`USER#${ctx.args.id}`),
			},
		},
		projection,
	};
}

export function response(ctx) {
	if (ctx.error) {
		util.error(ctx.error.message, ctx.error.type);
	}
	// Query results commonly return { items, nextToken, ... }
	// Return the list of items when your schema expects a list
	return ctx.result?.items ?? [];
}
  1. Basic PutItem
// resolvers/createUser.ts
import { putItem } from '@mikecbrant/appsyncjs-dynamo';
import { util } from '@aws-appsync/utils';

export function request(ctx) {
	const user = {
		pk: `USER#${ctx.args.id}`,
		name: ctx.args.name,
		email: ctx.args.email,
	};

	return putItem({
		key: { pk: user.pk },
		item: user,
	});
}

export function response(ctx) {
	if (ctx.error) {
		util.error(ctx.error.message, ctx.error.type);
	}
	// Note: PutItem only returns attributes when your resolver is configured
	// to return them; otherwise ctx.result is typically empty
	return ctx.result;
}
  1. Conditional write with condition
// resolvers/createUserIfMissing.ts
import { putItem } from '@mikecbrant/appsyncjs-dynamo';
import { util } from '@aws-appsync/utils';

export function request(ctx) {
	const pk = `USER#${ctx.args.id}`;
	return putItem({
		key: { pk },
		item: { pk, name: ctx.args.name },
		// Only create when the item does not already exist
		condition: {
			expression: 'attribute_not_exists(#pk)',
			expressionNames: { '#pk': 'pk' },
		},
	});
}

export function response(ctx) {
	if (ctx.error) {
		util.error(ctx.error.message, ctx.error.type);
	}
	return ctx.result;
}
  1. Basic UpdateItem
// resolvers/upvotePost.ts
import { updateItem } from '@mikecbrant/appsyncjs-dynamo';
import { util } from '@aws-appsync/utils';

export function request(ctx) {
	return updateItem({
		key: { pk: `POST#${ctx.args.id}` },
		update: {
			expression: 'ADD #upvotes :one',
			expressionNames: { '#upvotes': 'upvotes' },
			expressionValues: { ':one': util.dynamodb.toDynamoDB(1) },
		},
		// optional condition:
		// condition: { expression: 'attribute_exists(#pk)', expressionNames: { '#pk': 'pk' } },
	});
}

export function response(ctx) {
	if (ctx.error) {
		util.error(ctx.error.message, ctx.error.type);
	}
	return ctx.result; // UpdateItem typically returns the updated item
}

API: putItem(props)

Builds and returns a DynamoDBPutItemRequest suitable for AppSync DynamoDB resolvers. Import it as a named export:

import { putItem } from '@mikecbrant/appsyncjs-dynamo';

Parameters (PutItemProps):

  • key: DynamoKey — the primary key for the item. A map of attribute name to a string or number value, e.g. { pk: 'USER#123' }.
  • item: Record<string, unknown> — the full item attributes to write. Values are marshaled with util.dynamodb.toMapValues.
  • condition?: ConditionCheckExpression — optional conditional expression to enforce on write (for example, attribute_not_exists(#pk)).

Notes

  • condition is omitted from the request when not provided.
  • Under the hood, both key and item are converted with util.dynamodb.toMapValues from @aws-appsync/utils.

API: updateItem(props)

Builds and returns a DynamoDBUpdateItemRequest suitable for AppSync DynamoDB resolvers. Import it as a named export:

import { updateItem } from '@mikecbrant/appsyncjs-dynamo';

Parameters:

  • key: DynamoKey — the primary key for the item.
  • update: DynamoDBExpression — the update expression and its names/values.
  • condition?: ConditionCheckExpression — optional conditional expression to enforce on update.

Notes

  • condition is omitted from the request when not provided.
  • Under the hood, key is converted with util.dynamodb.toMapValues from @aws-appsync/utils.