triangle-utils 1.4.34 → 1.4.36
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/dist/src/UtilsDynamoDB.d.ts +1 -1
- package/dist/src/UtilsDynamoDB.js +7 -13
- package/package.json +1 -1
- package/src/UtilsDynamoDB.ts +11 -14
|
@@ -10,7 +10,7 @@ export declare class UtilsDynamoDB {
|
|
|
10
10
|
concurrency?: number;
|
|
11
11
|
}): Promise<Record<string, any>[]>;
|
|
12
12
|
get(table: string, key: Record<string, any>, consistent?: boolean): Promise<Record<string, any> | undefined>;
|
|
13
|
-
get_max(table_index_name: string, primary_key: Record<string,
|
|
13
|
+
get_max(table_index_name: string, primary_key: Record<string, string | number>): Promise<Record<string, any> | undefined>;
|
|
14
14
|
query(table_index_name: string, primary_key: Record<string, any>, options?: {
|
|
15
15
|
reverse?: boolean;
|
|
16
16
|
compile?: boolean;
|
|
@@ -158,24 +158,18 @@ export class UtilsDynamoDB {
|
|
|
158
158
|
async get_max(table_index_name, primary_key) {
|
|
159
159
|
const table_name = table_index_name.split(":")[0];
|
|
160
160
|
const index_name = table_index_name.split(":")[1];
|
|
161
|
-
if (Object.keys(primary_key).length !== 1
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
const key = Object.keys(primary_key)[0];
|
|
165
|
-
const value = convert_input(Object.values(primary_key)[0]);
|
|
166
|
-
if (value === undefined) {
|
|
161
|
+
if (index_name === undefined && Object.keys(primary_key).length !== 1 ||
|
|
162
|
+
index_name !== undefined && Object.keys(primary_key).length !== index_name.split("-").length) {
|
|
167
163
|
return undefined;
|
|
168
164
|
}
|
|
169
165
|
const request = {
|
|
170
166
|
TableName: table_name,
|
|
171
167
|
IndexName: index_name,
|
|
172
|
-
ExpressionAttributeNames:
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
},
|
|
178
|
-
KeyConditionExpression: "#a = :a",
|
|
168
|
+
ExpressionAttributeNames: Object.fromEntries(Object.keys(primary_key).map(key => ["#" + key, key])),
|
|
169
|
+
ExpressionAttributeValues: Object.fromEntries(Object.entries(primary_key)
|
|
170
|
+
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
171
|
+
.filter(([key, value]) => value !== undefined)),
|
|
172
|
+
KeyConditionExpression: Object.keys(primary_key).map(key => "#" + key + " = :" + key).join(" AND "),
|
|
179
173
|
Limit: 1,
|
|
180
174
|
ScanIndexForward: false
|
|
181
175
|
};
|
package/package.json
CHANGED
package/src/UtilsDynamoDB.ts
CHANGED
|
@@ -183,28 +183,25 @@ export class UtilsDynamoDB {
|
|
|
183
183
|
|
|
184
184
|
async get_max(
|
|
185
185
|
table_index_name : string,
|
|
186
|
-
primary_key : Record<string,
|
|
186
|
+
primary_key : Record<string, string | number>
|
|
187
187
|
) : Promise<Record<string, any> | undefined> {
|
|
188
188
|
const table_name : string = table_index_name.split(":")[0]
|
|
189
189
|
const index_name : string | undefined = table_index_name.split(":")[1]
|
|
190
|
-
if (Object.keys(primary_key).length !== 1
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const key = Object.keys(primary_key)[0]
|
|
194
|
-
const value = convert_input(Object.values(primary_key)[0])
|
|
195
|
-
if (value === undefined) {
|
|
190
|
+
if (index_name === undefined && Object.keys(primary_key).length !== 1 ||
|
|
191
|
+
index_name !== undefined && Object.keys(primary_key).length !== index_name.split("-").length
|
|
192
|
+
) {
|
|
196
193
|
return undefined
|
|
197
194
|
}
|
|
198
195
|
const request : QueryCommandInput = {
|
|
199
196
|
TableName : table_name,
|
|
200
197
|
IndexName : index_name,
|
|
201
|
-
ExpressionAttributeNames:
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
KeyConditionExpression: "#
|
|
198
|
+
ExpressionAttributeNames: Object.fromEntries(Object.keys(primary_key).map(key => ["#" + key, key])),
|
|
199
|
+
ExpressionAttributeValues: Object.fromEntries(
|
|
200
|
+
Object.entries(primary_key)
|
|
201
|
+
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
202
|
+
.filter(([key, value]) => value !== undefined)
|
|
203
|
+
),
|
|
204
|
+
KeyConditionExpression: Object.keys(primary_key).map(key => "#" + key + " = :" + key).join(" AND "),
|
|
208
205
|
Limit : 1,
|
|
209
206
|
ScanIndexForward : false
|
|
210
207
|
}
|