aws-v3-sdk 1.0.13 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/clients/dynamo/DocumentClientAsync.js +131 -0
- package/clients/dynamoDB.js +2 -0
- package/clients/lambda.js +22 -0
- package/package.json +1 -1
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
const { DynamoDB, DynamoDBClient } = require('@aws-sdk/client-dynamodb')
|
|
2
|
+
const { DynamoDBDocument, DynamoDBDocumentClient, GetCommand, BatchWriteCommand, PutCommand, QueryCommand, ScanCommand, DeleteCommand } = require('@aws-sdk/lib-dynamodb')
|
|
3
|
+
const ddb = new DynamoDBClient()
|
|
4
|
+
const documentClient = DynamoDBDocumentClient.from(ddb)
|
|
5
|
+
|
|
6
|
+
class DocumentClientAsync {
|
|
7
|
+
get (params, callback) {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
const getCommand = new GetCommand(params)
|
|
10
|
+
documentClient.send(getCommand, (err, response) => {
|
|
11
|
+
if (err || !response) {
|
|
12
|
+
return reject(err)
|
|
13
|
+
}
|
|
14
|
+
if (response.Item) {
|
|
15
|
+
return resolve(response)
|
|
16
|
+
} else if (!response.Item) {
|
|
17
|
+
return resolve({})
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
}).then(result => {
|
|
21
|
+
if (callback && typeof callback === 'function') {
|
|
22
|
+
callback(null, result)
|
|
23
|
+
}
|
|
24
|
+
return result
|
|
25
|
+
}).catch(error => {
|
|
26
|
+
if (callback && typeof callback === 'function') {
|
|
27
|
+
callback(error, null)
|
|
28
|
+
}
|
|
29
|
+
return Promise.reject(error)
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
query (params, callback) {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const getCommand = new QueryCommand(params)
|
|
36
|
+
documentClient.send(getCommand, (err, response) => {
|
|
37
|
+
if (err || !response) {
|
|
38
|
+
return resolve(err)
|
|
39
|
+
}
|
|
40
|
+
return resolve(response)
|
|
41
|
+
})
|
|
42
|
+
}).then(result => {
|
|
43
|
+
if (callback && typeof callback === 'function') {
|
|
44
|
+
callback(null, result)
|
|
45
|
+
}
|
|
46
|
+
return result
|
|
47
|
+
}).catch(error => {
|
|
48
|
+
if (callback && typeof callback === 'function') {
|
|
49
|
+
callback(error, null)
|
|
50
|
+
}
|
|
51
|
+
return Promise.reject(error)
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
put (params, callback) {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
let item = params.Item
|
|
58
|
+
try {
|
|
59
|
+
item = Object.fromEntries(Object.entries(item).filter(([key, value]) => value !== undefined))
|
|
60
|
+
} catch (error) {
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
params.Item = item
|
|
64
|
+
const putCommand = new PutCommand(params)
|
|
65
|
+
documentClient.send(putCommand, (err, response) => {
|
|
66
|
+
if (err || !response) {
|
|
67
|
+
return resolve(err)
|
|
68
|
+
}
|
|
69
|
+
return resolve(response)
|
|
70
|
+
})
|
|
71
|
+
}).then(result => {
|
|
72
|
+
if (callback && typeof callback === 'function') {
|
|
73
|
+
callback(null, result)
|
|
74
|
+
}
|
|
75
|
+
return result
|
|
76
|
+
}).catch(error => {
|
|
77
|
+
if (callback && typeof callback === 'function') {
|
|
78
|
+
callback(error, null)
|
|
79
|
+
}
|
|
80
|
+
return Promise.reject(error)
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
delete (params, callback) {
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
|
+
const docClient = DynamoDBDocument.from(new DynamoDB())
|
|
87
|
+
docClient.delete(params, (err, response) => {
|
|
88
|
+
if (err) {
|
|
89
|
+
return resolve(err)
|
|
90
|
+
} else {
|
|
91
|
+
return resolve(response)
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
}).then(result => {
|
|
95
|
+
if (callback && typeof callback === 'function') {
|
|
96
|
+
callback(null, result)
|
|
97
|
+
}
|
|
98
|
+
return result
|
|
99
|
+
}).catch(error => {
|
|
100
|
+
if (callback && typeof callback === 'function') {
|
|
101
|
+
callback(error, null)
|
|
102
|
+
}
|
|
103
|
+
return Promise.reject(error)
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
update (params, callback) {
|
|
108
|
+
return new Promise((resolve, reject) => {
|
|
109
|
+
const docClient = DynamoDBDocument.from(new DynamoDB())
|
|
110
|
+
docClient.update(params, (err, response) => {
|
|
111
|
+
if (err) {
|
|
112
|
+
return resolve(err)
|
|
113
|
+
} else {
|
|
114
|
+
return resolve(response)
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
}).then(result => {
|
|
118
|
+
if (callback && typeof callback === 'function') {
|
|
119
|
+
callback(null, result)
|
|
120
|
+
}
|
|
121
|
+
return result
|
|
122
|
+
}).catch(error => {
|
|
123
|
+
if (callback && typeof callback === 'function') {
|
|
124
|
+
callback(error, null)
|
|
125
|
+
}
|
|
126
|
+
return Promise.reject(error)
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
module.exports = DocumentClientAsync
|
package/clients/dynamoDB.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
const DocumentClient = require('./dynamo/DocumentClient')
|
|
2
|
+
const DocumentClientAsync = require('./dynamo/DocumentClientAsync')
|
|
2
3
|
|
|
3
4
|
class DynamoDB {
|
|
4
5
|
constructor () {
|
|
5
6
|
this.DocumentClient = DocumentClient
|
|
7
|
+
this.DocumentClientAsync = DocumentClientAsync
|
|
6
8
|
}
|
|
7
9
|
}
|
|
8
10
|
|
package/clients/lambda.js
CHANGED
|
@@ -19,6 +19,28 @@ class Lambda {
|
|
|
19
19
|
callback(err)
|
|
20
20
|
})
|
|
21
21
|
}
|
|
22
|
+
|
|
23
|
+
invokeAsync (params, callback) {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const command = new InvokeCommand(params)
|
|
26
|
+
this.client.send(command).then(response => {
|
|
27
|
+
response.Payload = toUtf8(response.Payload)
|
|
28
|
+
resolve(response)
|
|
29
|
+
}).catch(err => {
|
|
30
|
+
resolve(err)
|
|
31
|
+
})
|
|
32
|
+
}).then(result => {
|
|
33
|
+
if (callback && typeof callback === 'function') {
|
|
34
|
+
callback(null, result)
|
|
35
|
+
}
|
|
36
|
+
return result
|
|
37
|
+
}).catch(error => {
|
|
38
|
+
if (callback && typeof callback === 'function') {
|
|
39
|
+
callback(error, null)
|
|
40
|
+
}
|
|
41
|
+
return Promise.reject(error)
|
|
42
|
+
})
|
|
43
|
+
}
|
|
22
44
|
}
|
|
23
45
|
|
|
24
46
|
module.exports = Lambda
|