Registry / database / dynaorm

dynaorm

JSON →
library1.0.18jsnpmunverified

A lightweight, type-safe ORM for Amazon DynamoDB built with TypeScript. Version 1.0.18 uses Zod (v4+) for schema validation and data integrity, provides a fluent query builder, and supports bulk operations (batchWrite, batchGet, transactWrite, transactGet) with built-in request throttling. Unlike other DynamoDB ORMs, it enforces a schema-first approach with full TypeScript generics for autocompletion and compile-time error prevention. Released as of 2024, actively maintained on GitHub. Requires @aws-sdk/client-dynamodb >=3.955.0, @aws-sdk/util-dynamodb >=3.955.0, p-throttle >=8.1.0, and zod >=4.2.1 as peer dependencies.

npm install dynaorm
INSTALL
IMPORT
SIG · DYNAORM
D
dynaorm
databasejavascriptv1.0.18
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

defineSchema
import { defineSchema } from 'dynaorm'
const defineSchema = require('dynaorm').defineSchema
ESM-only import; no CommonJS support.
createClient
import { createClient } from 'dynaorm'
import createClient from 'dynaorm'
Named export; do not use default import.
Model
import type { Model } from 'dynaorm'
import { Model } from 'dynaorm'
Use type-only import as Model is a TypeScript type, not a runtime value.
QueryBuilder
import type { QueryBuilder } from 'dynaorm'
Type-only import for query builder fluent interface.

Shows how to define a Zod schema, create a DynamoDB table schema with defineSchema, initialize the client with throttling, and perform create and findOne operations.

import { defineSchema, createClient } from 'dynaorm'; import { z } from 'zod'; import { DynamoDBClientConfig } from '@aws-sdk/client-dynamodb'; 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' } }, }, }); // Example using environment variable for region, replace with actual config const config: DynamoDBClientConfig = { region: process.env.AWS_REGION ?? 'us-east-1', credentials: { accessKeyId: process.env.AWS_ACCESS_KEY_ID ?? '', secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ?? '', }, }; const client = createClient( { users: userTableSchema }, { config, modelOptions: { throttle: { limit: 100, interval: 1000 } } } ); const userModel = client.users; export async function createUser() { const newUser = { userId: 'some-uuid-1', email: 'test@example.com', username: 'testuser', createdAt: new Date().toISOString(), status: 'active', }; await userModel.create(newUser); const user = await userModel.findOne({ userId: 'some-uuid-1' }); console.log(user); }
Debug
Known issues
breakingPeer dependency zod >=4.2.1 is required; using older zod versions will cause runtime errors.
fix
Install zod version 4.2.1 or higher: npm install zod@^4.2.1
affects: >=1.0.0
breakingRequires @aws-sdk/client-dynamodb version 3.955.0 or higher. Older SDK versions may lack required features.
fix
Update AWS SDK: npm install @aws-sdk/client-dynamodb@^3.955.0
affects: >=1.0.0
deprecatedThe findByIndex method may be deprecated in future versions in favor of the query builder.
fix
Use userModel.query().onIndex('byStatus').wherePK('active').execAll() instead.
affects: >=1.0.0
gotchaThe query builder's exec() returns only the first page of results; use execAll() to fetch all items.
fix
Use .execAll() instead of .exec() to get all matching items.
affects: >=1.0.0
gotchaBatchWrite does not automatically handle unprocessed items; you must implement retry logic yourself.
fix
After calling batchWrite, check the result's UnprocessedItems and retry accordingly.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Expected object schema but got something else
Zod schema provided to defineSchema is not a z.object() or has invalid structure.
fix
Ensure the schema is created with z.object({...}) and that all field types are valid Zod types.
TypeError: Cannot read properties of undefined (reading 'create')
Client not initialized properly or model name misspelled.
fix
Check that createClient is called with correct schema names and that you access client.<schemaName>.
ValidationError: [{"code":"invalid_type","expected":"string","received":"undefined","path":["userId"],"message":"Required"}]
Missing required field in create or upsert operation.
fix
Ensure all required fields (defined by Zod schema) are provided in the data object.
Upgrade
Version history
1.0.18latest on npm
Audit
Dependencies
@aws-sdk/client-dynamodbrequiredProvides DynamoDB client for database operations
@aws-sdk/util-dynamodbrequiredUsed for marshaling/unmarshaling DynamoDB data
p-throttlerequiredEnables request throttling to manage DynamoDB throughput
zodrequiredSchema validation library for defining data structures
Agent activity
11 hits · last 30 days
node
8
Resources
dynaorm — npm install dynaorm · libregistry