
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
This package provides a lightweight, type-safe client for Amazon DynamoDB, simplifying common operations with a schema-first approach. By leveraging Zod for schema validation, it ensures your data conforms to a defined structure before interacting with the database. The library abstracts away the complexities of the AWS SDK, such as marshaling and unmarshaling data, and provides a fluent API for building queries.
defineSchema function.query() API for intuitive read operations.batchWrite, batchGet, transactWrite, and transactGet operations.npm install dynaorm zod @aws-sdk/client-dynamodb
First, define the structure of your data using Zod. This library uses Zod to validate the data before it's sent to DynamoDB. You then use the defineSchema function to specify your DynamoDB table's primary keys and any secondary indexes.
import { defineSchema } from "dynaorm";
import { z } from "zod";
const userSchema = z.object({
userId: z.string().uuid(),
email: z.string().email(),
username: z.string().min(3),
createdAt: z.string().datetime(),
status: z.enum(["active", "inactive", "suspended"]),
});
const userTableSchema = defineSchema({
tableName: "UsersTable",
fields: userSchema,
partitionKey: "userId",
globalSecondaryIndexes: {
byEmail: { partitionKey: "email", projection: { type: "ALL" } },
byStatus: {
partitionKey: "status",
sortKey: "createdAt",
projection: { type: "KEYS_ONLY" },
},
},
});
The createClient function is the entry point for your application. It takes a record of your schemas and an AWS SDK client configuration. It returns a type-safe client with a model for each schema you defined.
import { DynamoDBClientConfig } from "@aws-sdk/client-dynamodb";
import { createClient } from "dynaorm";
const config: DynamoDBClientConfig = {
region: "us-east-1",
};
const client = createClient(
{ users: userTableSchema },
{
config,
modelOptions: {
throttle: { limit: 100, interval: 1000 },
},
},
);
const userModel = client.users;
const newUser = {
userId: "some-uuid-1",
email: "test@example.com",
username: "testuser",
createdAt: new Date().toISOString(),
status: "active",
};
await userModel.create(newUser);
const updatedUser = { ...newUser, status: "inactive" };
await userModel.upsert(updatedUser);
const user = await userModel.findOne({ userId: "some-uuid-1" });
console.log(user);
const activeUsers = await userModel.findByIndex(
"byStatus",
{ status: "active" },
{ limit: 10 },
);
console.log(activeUsers);
const recentActiveUsers = await userModel
.query()
.onIndex("byStatus")
.wherePK("active")
.whereSK("begins_with", "2023-10")
.execAll();
console.log(recentActiveUsers);
await userModel.update({ userId: "some-uuid-1" }, { status: "suspended" });
await userModel.delete({ userId: "some-uuid-1" });
await userModel.batchWrite([
{
type: "put",
item: {
userId: "uuid-2",
email: "a@b.com",
username: "userA",
createdAt: new Date().toISOString(),
status: "active",
},
},
{ type: "delete", item: { userId: "uuid-3" } },
]);
const items = await userModel.batchGet([{ userId: "uuid-2" }]);
console.log(items);
await userModel.transactWrite([
{
type: "put",
item: {
userId: "uuid-4",
email: "c@d.com",
username: "userC",
createdAt: new Date().toISOString(),
status: "active",
},
},
{
type: "update",
key: { userId: "uuid-2" },
updates: { username: "userA-updated" },
},
]);
createClient(schemas, options)Initializes the DynamoDB client and attaches models for each schema.
config (DynamoDBClientConfig), optional modelOptions, and optional perModelOptions.defineSchema(schema)Defines a new DynamoDB table schema with strong typing.
Model<S>Provides methods for interacting with a DynamoDB table.
create(item)upsert(item, options?)update(key, updates, options?)delete(key, options?)findOne(key, options?)query()findMany(partitionKeyValue, sortKeyCondition?, options?)findByIndex(indexName, keyValues, options?)scanAll(options?)getItemCount(options?)batchWrite(items)batchGet(keys)transactWrite(items)transactGet(keys)upsertMany(items)updateMany(items)deleteMany(partitionKeyValue, sortKeyCondition?)QueryBuilder<S>Fluent API for building DynamoDB Query operations.
wherePK(value)whereSK(operator, value)filter(key, operator, value, join?)limit(count)orderBy(asc)startKey(key)project(attrs)onIndex(index)consistentRead()exec()paginate()execAll()FAQs
A type-safe DynamoDB ORM
The npm package dynaorm receives a total of 26 weekly downloads. As such, dynaorm popularity was classified as not popular.
We found that dynaorm demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.