Skip to content

Commit

Permalink
Change schema definition (#21)
Browse files Browse the repository at this point in the history
* Swtich to full joi schema to allow for more control
* Overriding tables does not fully work as an unknown field is treated as `Joi.any()` so may not serialize to the correct type.
  • Loading branch information
tgandrews committed Oct 31, 2020
1 parent 77a208f commit 881325a
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 121 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Omanyd

A simple but production ready dynamodb mapper.
A simple and experimental dynamodb data mapper.

[![Coverage Status](https://coveralls.io/repos/github/tgandrews/omanyd/badge.svg?branch=main)](https://coveralls.io/github/tgandrews/omanyd?branch=main)

Expand All @@ -12,16 +12,15 @@ A simple but production ready dynamodb mapper.
- Complete typescript typings
- Basic global indexes
- Range key
- Lists

### Missing features

- Parallel scans
- Paging
- Complex querying
- Number and binary sets
- Boolean types
- Date types
- Lists
- Local indexes

## Installation
Expand Down Expand Up @@ -78,10 +77,10 @@ interface Tweet {
const TweetStore = Omanyd.define<Tweet>({
name: "Tweet",
hashKey: "id",
schema: {
schema: Joi.object({
id: Omanyd.types.id(),
content: Joi.string(),
},
}),
});
```

Expand Down Expand Up @@ -210,11 +209,11 @@ interface Document {
const DocumentStore = Omanyd.define<User>({
name: "Documents",
hashKey: "id",
schema: {
schema: Joi.object({
id: Omanyd.types.id(),
version: Joi.string().required(),
email: Joi.string().required(),
},
}),
});

// Assuming table has been created separately
Expand Down Expand Up @@ -255,10 +254,10 @@ interface User {
const UserStore = Omanyd.define<User>({
name: "Users",
hashKey: "id",
schema: {
schema: Joi.object({
id: Omanyd.types.id(),
email: Joi.string().required(),
},
}),
indexes: [
{
name: "EmailIndex",
Expand Down
4 changes: 1 addition & 3 deletions src/deserializer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { PlainObject, Schema } from "./types";
import { PlainObject } from "./types";

type DynamoType = keyof AWS.DynamoDB.AttributeValue;

class Deserializer {
constructor(private schema: Schema) {}

fromDynamoValue(attributeValue: AWS.DynamoDB.AttributeValue): any {
const [dynamoType, dynamoValue] = Object.entries(attributeValue)[0] as [
DynamoType,
Expand Down
Loading

0 comments on commit 881325a

Please sign in to comment.