triangle-utils 1.0.1 → 1.0.3
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/Config.ts +0 -0
- package/config.js +0 -0
- package/dynamodb.js +14 -19
- package/index.js +11 -4
- package/package.json +5 -2
package/Config.ts
ADDED
|
File without changes
|
package/config.js
ADDED
|
File without changes
|
package/dynamodb.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import config from "../config.js"
|
|
2
|
-
import { DynamoDB } from "@aws-sdk/client-dynamodb"
|
|
3
|
-
|
|
4
|
-
var dynamodb = new DynamoDB({ region: config.region })
|
|
5
|
-
|
|
6
1
|
function convert_output(dynamoobject) {
|
|
7
2
|
if (dynamoobject.S !== undefined) {
|
|
8
3
|
return dynamoobject.S
|
|
@@ -59,7 +54,7 @@ async function paginate(request, f) {
|
|
|
59
54
|
}
|
|
60
55
|
}
|
|
61
56
|
|
|
62
|
-
export async function
|
|
57
|
+
export async function dynamodb_scan(dynamodb, table, attribute_names = [], filters = {}) {
|
|
63
58
|
const request = Object.fromEntries(Object.entries({
|
|
64
59
|
TableName : table,
|
|
65
60
|
ExpressionAttributeNames : Object.fromEntries((Object.keys(filters).concat(attribute_names)).map(attribute_name => ["#" + attribute_name, attribute_name])),
|
|
@@ -70,7 +65,7 @@ export async function scan(table, attribute_names = [], filters = {}) {
|
|
|
70
65
|
return await paginate(request, (request) => dynamodb.scan(request))
|
|
71
66
|
}
|
|
72
67
|
|
|
73
|
-
export async function
|
|
68
|
+
export async function dynamodb_get(dynamodb, table, key, consistent=false) {
|
|
74
69
|
const item = await dynamodb.getItem({
|
|
75
70
|
ConsistentRead : consistent,
|
|
76
71
|
TableName : table,
|
|
@@ -83,7 +78,7 @@ export async function get(table, key, consistent=false) {
|
|
|
83
78
|
return convert_output({ M : item })
|
|
84
79
|
}
|
|
85
80
|
|
|
86
|
-
export async function
|
|
81
|
+
export async function dynamodb_get_max(dynamodb, table, primary_key) {
|
|
87
82
|
if (Object.keys(primary_key).length !== 1) {
|
|
88
83
|
return undefined
|
|
89
84
|
}
|
|
@@ -109,7 +104,7 @@ export async function get_max(table, primary_key) {
|
|
|
109
104
|
|
|
110
105
|
|
|
111
106
|
|
|
112
|
-
export async function
|
|
107
|
+
export async function dynamodb_query(dynamodb, table, primary_key, reverse=false) {
|
|
113
108
|
if (Object.keys(primary_key).length !== 1) {
|
|
114
109
|
return undefined
|
|
115
110
|
}
|
|
@@ -127,7 +122,7 @@ export async function query(table, primary_key, reverse=false) {
|
|
|
127
122
|
return await paginate(request, (request) => dynamodb.query(request))
|
|
128
123
|
}
|
|
129
124
|
|
|
130
|
-
export async function
|
|
125
|
+
export async function dynamodb_query_prefix(dynamodb, table, primary_key, secondary_key_prefix, reverse=false) {
|
|
131
126
|
if (Object.keys(primary_key).length !== 1 || Object.keys(secondary_key_prefix).length !== 1) {
|
|
132
127
|
return undefined
|
|
133
128
|
}
|
|
@@ -147,7 +142,7 @@ export async function query_prefix(table, primary_key, secondary_key_prefix, rev
|
|
|
147
142
|
return await paginate(request, (request) => dynamodb.query(request))
|
|
148
143
|
}
|
|
149
144
|
|
|
150
|
-
export async function
|
|
145
|
+
export async function dynamodb_query_range(dynamodb, table, primary_key, secondary_key_range, reverse=false) {
|
|
151
146
|
if (Object.keys(primary_key).length !== 1 || Object.keys(secondary_key_range).length !== 1 || Object.values(secondary_key_range)[0].length !== 2) {
|
|
152
147
|
return undefined
|
|
153
148
|
}
|
|
@@ -168,7 +163,7 @@ export async function query_range(table, primary_key, secondary_key_range, rever
|
|
|
168
163
|
return await paginate(request, (request) => dynamodb.query(request))
|
|
169
164
|
}
|
|
170
165
|
|
|
171
|
-
export async function
|
|
166
|
+
export async function dynamodb_set(dynamodb, table, key, attributes) {
|
|
172
167
|
return await dynamodb.updateItem({
|
|
173
168
|
TableName : table,
|
|
174
169
|
Key : convert_input(key).M,
|
|
@@ -190,7 +185,7 @@ export async function set(table, key, attributes) {
|
|
|
190
185
|
})
|
|
191
186
|
}
|
|
192
187
|
|
|
193
|
-
export async function
|
|
188
|
+
export async function dynamodb_append(dynamodb, table, key, attributes) {
|
|
194
189
|
return await dynamodb.updateItem({
|
|
195
190
|
TableName : table,
|
|
196
191
|
Key : convert_input(key).M,
|
|
@@ -208,7 +203,7 @@ export async function append(table, key, attributes) {
|
|
|
208
203
|
})
|
|
209
204
|
}
|
|
210
205
|
|
|
211
|
-
export async function
|
|
206
|
+
export async function dynamodb_add(dynamodb, table, key, attributes) {
|
|
212
207
|
const item = await get(table, key, true)
|
|
213
208
|
const new_attributes = {}
|
|
214
209
|
for (const [attribute, values] of Object.entries(attributes)) {
|
|
@@ -226,7 +221,7 @@ export async function add(table, key, attributes) {
|
|
|
226
221
|
return await append(table, key, attributes)
|
|
227
222
|
}
|
|
228
223
|
|
|
229
|
-
export async function
|
|
224
|
+
export async function dynamodb_remove(dynamodb, table, key, attributes) {
|
|
230
225
|
return await dynamodb.updateItem({
|
|
231
226
|
TableName : table,
|
|
232
227
|
Key : convert_input(key).M,
|
|
@@ -238,7 +233,7 @@ export async function remove(table, key, attributes) {
|
|
|
238
233
|
})
|
|
239
234
|
}
|
|
240
235
|
|
|
241
|
-
export async function
|
|
236
|
+
export async function dynamodb_create(dynamodb, table, key, attributes = {}) {
|
|
242
237
|
const item = await get(table, key)
|
|
243
238
|
if (item !== undefined) {
|
|
244
239
|
return undefined
|
|
@@ -249,14 +244,14 @@ export async function create(table, key, attributes = {}) {
|
|
|
249
244
|
})
|
|
250
245
|
}
|
|
251
246
|
|
|
252
|
-
export async function
|
|
247
|
+
export async function dynamodb_delete(dynamodb, table, key) {
|
|
253
248
|
return await dynamodb.deleteItem({
|
|
254
249
|
TableName: table,
|
|
255
250
|
Key: Object.fromEntries(Object.keys(key).map(key_name => [key_name, convert_input(key[key_name])]))
|
|
256
251
|
})
|
|
257
252
|
}
|
|
258
253
|
|
|
259
|
-
export async function
|
|
254
|
+
export async function dynamodb_duplicate_attribute(dynamodb, table, attribute_name, new_attribute_name) {
|
|
260
255
|
const table_key_names = await dynamodb.describeTable({
|
|
261
256
|
TableName : table
|
|
262
257
|
}).then(metadata => metadata.Table.KeySchema.map(key => key.AttributeName))
|
|
@@ -274,7 +269,7 @@ export async function duplicate_attribute(table, attribute_name, new_attribute_n
|
|
|
274
269
|
}
|
|
275
270
|
}
|
|
276
271
|
|
|
277
|
-
export async function
|
|
272
|
+
export async function dynamodb_remove_attribute(dynamodb, table, attribute_name) {
|
|
278
273
|
const table_key_names = await dynamodb.describeTable({
|
|
279
274
|
TableName : table
|
|
280
275
|
}).then(metadata => metadata.Table.KeySchema.map(key => key.AttributeName))
|
package/index.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as utils_dynamodb from "./dynamodb.js"
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import { DynamoDB } from "@aws-sdk/client-dynamodb"
|
|
4
|
+
|
|
5
|
+
export function get_utils(config) {
|
|
6
|
+
const utils = {}
|
|
7
|
+
const dynamodb = new DynamoDB({ region : config.region })
|
|
8
|
+
for (const util of utils_dynamodb) {
|
|
9
|
+
utils[util.name] = async (...args) => await util(dynamodb, ...args)
|
|
10
|
+
}
|
|
11
|
+
return utils
|
|
12
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "triangle-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"description": "",
|
|
8
|
-
"type": "module"
|
|
8
|
+
"type": "module",
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@aws-sdk/client-dynamodb": "^3.953.0"
|
|
11
|
+
}
|
|
9
12
|
}
|