/
attribute.type.ts
94 lines (81 loc) · 2.42 KB
/
attribute.type.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* @module mapper
*/
export type Attribute =
| StringAttribute
| NumberAttribute
| BinaryAttribute
| StringSetAttribute
| NumberSetAttribute
| BinarySetAttribute
| MapAttribute
| ListAttribute<any>
| NullAttribute
| BooleanAttribute
/**
* the key is either a key of the object T or any string to support for custom property
* names @Property({name: 'myOtherName'}) and the value is one of Attribute
* (we can't narrow the type of Attribute)
*/
export type Attributes<T = {}> = Record<keyof T | string, Attribute>
/**
* An attribute of type String. For example: "S": "Hello"
*/
export interface StringAttribute {
S: string
}
/**
* An attribute of type Number. For example: "N": "123.45" Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and libraries. However, DynamoDB treats them as number type attributes for mathematical operations.
*/
export interface NumberAttribute {
N: string
}
/**
* An attribute of type Binary. For example: "B": "dGhpcyB0ZXh0IGlzIGJhc2U2NC1lbmNvZGVk"
* TODO ENHANCEMENT:BINARY check for all possible types
*/
export interface BinaryAttribute {
B: Buffer | Uint8Array | {} | string
}
/**
* An attribute of type String Set. For example: "SS": ["Giraffe", "Hippo" ,"Zebra"]
*/
export interface StringSetAttribute {
SS: string[]
}
/**
* An attribute of type Number Set. For example: "NS": ["42.2", "-19", "7.5", "3.14"] Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and libraries. However, DynamoDB treats them as number type attributes for mathematical operations.
*/
export interface NumberSetAttribute {
NS: string[]
}
/**
* An attribute of type Binary Set. For example: "BS": ["U3Vubnk=", "UmFpbnk=", "U25vd3k="]
*/
export interface BinarySetAttribute {
BS: Array<Buffer | Uint8Array | {} | string>
}
/**
* An attribute of type Map. For example: "M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}}
*/
export interface MapAttribute<T = {}> {
M: Attributes<T>
}
/**
* An attribute of type List. For example: "L": ["Cookies", "Coffee", 3.14159]
*/
export interface ListAttribute<T extends Attribute = Attribute> {
L: T[]
}
/**
* An attribute of type Null. For example: "NULL": true
*/
export interface NullAttribute {
NULL: boolean
}
/**
* An attribute of type Boolean. For example: "BOOL": true
*/
export interface BooleanAttribute {
BOOL: boolean
}