Skip to content

Instantly share code, notes, and snippets.

@kyeotic
Last active February 12, 2021 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyeotic/f31633c4d10bf329a42348801cd48c81 to your computer and use it in GitHub Desktop.
Save kyeotic/f31633c4d10bf329a42348801cd48c81 to your computer and use it in GitHub Desktop.
DyanmoDB native types
import { marshall } from '@aws-sdk/util-dynamodb'
export { unmarshall } from '@aws-sdk/util-dynamodb'
import type {
NativeAttributeValue,
marshallOptions,
} from '@aws-sdk/util-dynamodb'
import type { AttributeValue } from '@aws-sdk/client-dynamodb'
import type {
QueryInput,
QueryOutput,
ScanInput,
ScanOutput,
GetItemInput,
GetItemOutput,
PutItemInput,
PutItemOutput,
UpdateItemInput,
UpdateItemOutput,
AttributeValueUpdate,
ExpectedAttributeValue,
DeleteItemInput,
DeleteItemOutput,
BatchGetItemInput,
BatchGetItemOutput,
BatchWriteItemInput,
BatchWriteItemOutput,
KeysAndAttributes,
} from '@aws-sdk/client-dynamodb'
export interface MarshalledItem {
[key: string]: AttributeValue
}
export interface NativeItem {
[key: string]: NativeAttributeValue
}
export { marshall }
export function marshalKeys<T, K>(
params: any,
keys: string[],
options?: marshallOptions
): T {
return keys.reduce(
(output: any, key: string) => {
output[key] = params[key] && marshall(params[key], options)
return output
},
{ ...params }
) as T
}
// Re-Marshalled Types
//
export interface QueryInputNative
extends Omit<QueryInput, 'ExpressionAttributeValues' | 'ExclusiveStartKey'> {
ExpressionAttributeValues?: NativeItem
ExclusiveStartKey?: NativeItem
}
export interface QueryOutputNative
extends Omit<QueryOutput, 'Items' | 'LastEvaluatedKey'> {
Items?: NativeItem[]
LastEvaluatedKey?: NativeItem
}
export interface ScanInputNative
extends Omit<ScanInput, 'ExpressionAttributeValues' | 'ExclusiveStartKey'> {
ExpressionAttributeValues?: NativeItem
ExclusiveStartKey?: NativeItem
}
export interface ScanOutputNative
extends Omit<ScanOutput, 'Items' | 'LastEvaluatedKey'> {
Items?: NativeItem[]
LastEvaluatedKey?: NativeItem
}
export interface GetItemInputNative extends Omit<GetItemInput, 'Key'> {
Key?: NativeItem
}
export interface GetItemOutputNative extends Omit<GetItemOutput, 'Item'> {
Item?: NativeItem
}
export interface PutItemInputNative
extends Omit<PutItemInput, 'Item' | 'ExpressionAttributeValues'> {
Item?: NativeItem
ExpressionAttributeValues?: NativeItem
}
export interface PutItemOutputNative extends Omit<PutItemOutput, 'Attributes'> {
Attributes?: NativeItem
}
export interface AttributeValueUpdateNative
extends Omit<AttributeValueUpdate, 'Value'> {
Value?: NativeAttributeValue
}
export interface ExpectedAttributeValueNative
extends Omit<ExpectedAttributeValue, 'Value' | 'AttributeValueList'> {
Value?: NativeAttributeValue
AttributeValueList?: NativeAttributeValue[]
}
export interface UpdateItemInputNative
extends Omit<
UpdateItemInput,
'Key' | 'ExpressionAttributeValues' | 'AttributeUpdates'
> {
Key?: NativeItem
ExpressionAttributeValues?: NativeItem
AttributeUpdates?: AttributeValueUpdateNative
}
export interface UpdateItemOutputNative
extends Omit<UpdateItemOutput, 'Attributes'> {
Attributes?: NativeItem
}
export interface DeleteItemInputNative
extends Omit<
DeleteItemInput,
'Key' | 'Expected' | 'ExpressionAttributeValues'
> {
Key?: NativeItem
Expected?: ExpectedAttributeValueNative
ExpressionAttributeValues?: NativeItem
}
export interface DeleteItemOutputNative
extends Omit<DeleteItemOutput, 'Attributes'> {
Attributes?: NativeItem
}
export interface KeysAndAttributesNative
extends Omit<KeysAndAttributes, 'Keys'> {
Keys?: NativeItem[]
}
export interface BatchGetItemInputNative
extends Omit<BatchGetItemInput, 'RequestItems'> {
RequestItems?: KeysAndAttributesNative
}
export interface BatchGetItemOutputNative
extends Omit<BatchGetItemOutput, 'Responses' | 'UnprocessedKeys'> {
Responses?: {
[key: string]: NativeItem[]
}
UnprocessedKeys?: KeysAndAttributesNative
}
export interface PutRequestNative {
Item?: NativeItem
}
export interface DeleteRequestNative {
Key?: NativeItem
}
export interface WriteRequestNative {
PutRequest?: PutRequestNative
DeleteRequest?: DeleteRequestNative
}
export interface BatchWriteItemInputNative
extends Omit<BatchWriteItemInput, 'RequestItems'> {
RequestItems?: {
[key: string]: WriteRequestNative[]
}
}
export interface BatchWriteItemOutputNative
extends Omit<BatchWriteItemOutput, 'UnprocessedItems'> {
UnprocessedItems?: {
[key: string]: WriteRequestNative[]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment