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);
}
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.
fixEnsure 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.
fixCheck 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.
fixEnsure all required fields (defined by Zod schema) are provided in the data object.
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