sam-goodwin / punchcard

Type-safe AWS infrastructure.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

add an `any` type

sam-goodwin opened this issue · comments

commented

Do we want to support an any type? What would we do in the Mappers? Best-effort serialization?

it would be nice. I'm having to set manually every member of a nested JSON body, but I really wanted a punchcard.any() and just stuff the thing inside the dynamodb, as-is
EDIT: just thinking out loud, maybe a "coerce" would turn the input as a JSON serialized value, so a deep nested json object, if coerce("string"), would go from { "some": { "object": [] } } to the string representation (same would happen with a number input that would be coerced to a number string, useful for really big numbers)

commented

I think we should copy (or use) the DocumentClient for working with any in DynamoDB. It marshals based on the JS type.

The JSON mapper should just be a no-op - pass the value through to JSON.stringify

Future codecs such as Avro (#10) would likely have to throw unless the underlying protocols supported an any.

What about Glue Tables? I'm leaning towards throwing an error but we could also use string and serialize as JSON.

The most difficult change would be the DynamoDB Path and JSON Path DSLs. For example, because the types of a property isn't defined, we can't have a type-safe DynamoDB condition expression like: if: item => item.anyAttribute.some.path.equals('some string'). I think the solution is to add an as method that lets you explicitly treat a property within a nested object as some type:

const table = new HashTable(.., {
  shape: {
    anyAttribute: punchcard.any
  }
});

await table.put({
  if: item => item.anyAttribute.some.arbitrary.path.as(string()).equals('some value')
})