@moicky/dynamodb 2.3.3 → 2.3.5
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/lib/fixes.d.ts +1 -1
- package/dist/operations/get.d.ts +3 -3
- package/dist/operations/put.d.ts +1 -1
- package/dist/operations/query.d.ts +5 -5
- package/dist/operations/query.js +2 -2
- package/dist/operations/transactGetItems.d.ts +2 -2
- package/dist/operations/update.d.ts +2 -2
- package/dist/operations/update.js +4 -2
- package/package.json +1 -1
- package/readme.md +1 -1
package/dist/lib/fixes.d.ts
CHANGED
|
@@ -63,4 +63,4 @@ export declare const marshallWithOptions: (input: Parameters<typeof marshall>[0]
|
|
|
63
63
|
* @returns The unmarshalled input
|
|
64
64
|
* @private
|
|
65
65
|
*/
|
|
66
|
-
export declare const unmarshallWithOptions: (input: Parameters<typeof unmarshall>[0]) =>
|
|
66
|
+
export declare const unmarshallWithOptions: <T extends Record<string, any> = Record<string, any>>(input: Parameters<typeof unmarshall>[0]) => T;
|
package/dist/operations/get.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ import { BatchGetItemCommandInput, GetItemCommandInput, ScanCommandInput } from
|
|
|
25
25
|
* );
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
export declare function getItem(key: Record<string, any>, args?: Partial<GetItemCommandInput>): Promise<
|
|
28
|
+
export declare function getItem<T extends Record<string, any> = Record<string, any>>(key: Record<string, any>, args?: Partial<GetItemCommandInput>): Promise<T | undefined>;
|
|
29
29
|
type GetItemsArgs = Partial<BatchGetItemCommandInput & {
|
|
30
30
|
TableName?: string;
|
|
31
31
|
}>;
|
|
@@ -58,7 +58,7 @@ type GetItemsArgs = Partial<BatchGetItemCommandInput & {
|
|
|
58
58
|
* );
|
|
59
59
|
* ```
|
|
60
60
|
*/
|
|
61
|
-
export declare function getItems(keys: Record<string, any>[], args?: GetItemsArgs, retry?: number): Promise<
|
|
61
|
+
export declare function getItems<T extends Record<string, any> = Record<string, any>>(keys: Record<string, any>[], args?: GetItemsArgs, retry?: number): Promise<Array<T | undefined>>;
|
|
62
62
|
/**
|
|
63
63
|
* Retrieves all items from the DynamoDB table.
|
|
64
64
|
* @param args - The additional arguments to override or specify for {@link ScanCommandInput}
|
|
@@ -77,5 +77,5 @@ export declare function getItems(keys: Record<string, any>[], args?: GetItemsArg
|
|
|
77
77
|
* );
|
|
78
78
|
* ```
|
|
79
79
|
*/
|
|
80
|
-
export declare function getAllItems(args?: Partial<ScanCommandInput>): Promise<
|
|
80
|
+
export declare function getAllItems<T extends Record<string, any> = Record<string, any>>(args?: Partial<ScanCommandInput>): Promise<T[]>;
|
|
81
81
|
export {};
|
package/dist/operations/put.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { BatchWriteItemCommandInput, BatchWriteItemCommandOutput, PutItemCommand
|
|
|
17
17
|
* });
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
export declare function putItem(item: Record<string, any>, args?: Partial<PutItemCommandInput>): Promise<PutItemCommandOutput |
|
|
20
|
+
export declare function putItem<T extends Record<string, any> = Record<string, any>>(item: Record<string, any>, args?: Partial<PutItemCommandInput>): Promise<PutItemCommandOutput | T>;
|
|
21
21
|
type PutItemsArgs = Partial<BatchWriteItemCommandInput & {
|
|
22
22
|
TableName?: string;
|
|
23
23
|
}>;
|
|
@@ -32,7 +32,7 @@ export declare function query(keyCondition: string, key: Record<string, any>, ar
|
|
|
32
32
|
* });
|
|
33
33
|
* ```
|
|
34
34
|
*/
|
|
35
|
-
export declare function queryItems(keyCondition: string, key: Record<string, any>, args?: Partial<QueryCommandInput>): Promise<
|
|
35
|
+
export declare function queryItems<T extends Record<string, any> = Record<string, any>>(keyCondition: string, key: Record<string, any>, args?: Partial<QueryCommandInput>): Promise<Array<T>>;
|
|
36
36
|
/**
|
|
37
37
|
* Query all items from the DynamoDB table using a key condition and unmarshalls the result.
|
|
38
38
|
* This function retries until all items are retrieved due to the AWS limit of 1MB per query.
|
|
@@ -62,7 +62,7 @@ export declare function queryItems(keyCondition: string, key: Record<string, any
|
|
|
62
62
|
* );
|
|
63
63
|
* ```
|
|
64
64
|
*/
|
|
65
|
-
export declare function queryAllItems(keyCondition: string, key: Record<string, any>, args?: Partial<QueryCommandInput>): Promise<
|
|
65
|
+
export declare function queryAllItems<T = Record<string, any>>(keyCondition: string, key: Record<string, any>, args?: Partial<QueryCommandInput>): Promise<Array<T>>;
|
|
66
66
|
/**
|
|
67
67
|
* The structure for the PaginationPage type.
|
|
68
68
|
* @property number - The page number. Cannot be set manually.
|
|
@@ -81,8 +81,8 @@ export type PaginationPage = {
|
|
|
81
81
|
* @property hasNextPage - Whether there is a next page.
|
|
82
82
|
* @property currentPage - The current page.
|
|
83
83
|
*/
|
|
84
|
-
export type PaginationResult = {
|
|
85
|
-
items:
|
|
84
|
+
export type PaginationResult<T> = {
|
|
85
|
+
items: T[];
|
|
86
86
|
hasPreviousPage: boolean;
|
|
87
87
|
hasNextPage: boolean;
|
|
88
88
|
currentPage: PaginationPage;
|
|
@@ -125,4 +125,4 @@ export interface PaginationArgs extends Partial<Omit<QueryCommandInput, "Limit">
|
|
|
125
125
|
* // currentPage: { number: 2, firstKey: { ... }, lastKey: { ... } }
|
|
126
126
|
* ```
|
|
127
127
|
*/
|
|
128
|
-
export declare function queryPaginatedItems(keyCondition: string, key: Record<string, any>, args: PaginationArgs): Promise<PaginationResult
|
|
128
|
+
export declare function queryPaginatedItems<T extends Record<string, any> = Record<string, any>>(keyCondition: string, key: Record<string, any>, args: PaginationArgs): Promise<PaginationResult<T>>;
|
package/dist/operations/query.js
CHANGED
|
@@ -66,8 +66,8 @@ exports.query = query;
|
|
|
66
66
|
async function queryItems(keyCondition, key, args = {}) {
|
|
67
67
|
args = (0, lib_1.withDefaults)(args, "queryItems");
|
|
68
68
|
return _query(keyCondition, key, args).then((res) => (res?.Items || [])
|
|
69
|
-
.map((item) =>
|
|
70
|
-
.filter(
|
|
69
|
+
.map((item) => (0, lib_1.unmarshallWithOptions)(item))
|
|
70
|
+
.filter(Boolean));
|
|
71
71
|
}
|
|
72
72
|
exports.queryItems = queryItems;
|
|
73
73
|
/**
|
|
@@ -34,9 +34,9 @@ import { Get, TransactGetItemsCommandInput } from "@aws-sdk/client-dynamodb";
|
|
|
34
34
|
* );
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
|
-
export declare function transactGetItems(keys: Array<Omit<Get, "TableName" | "Key"> & {
|
|
37
|
+
export declare function transactGetItems<T extends Record<string, any> = Array<Record<string, any> | undefined>>(keys: Array<Omit<Get, "TableName" | "Key"> & {
|
|
38
38
|
key: Record<string, any>;
|
|
39
39
|
TableName?: string;
|
|
40
40
|
}>, args?: Partial<TransactGetItemsCommandInput & {
|
|
41
41
|
TableName?: string;
|
|
42
|
-
}>): Promise<
|
|
42
|
+
}>): Promise<T[]>;
|
|
@@ -31,7 +31,7 @@ import { UpdateItemCommandInput, UpdateItemCommandOutput } from "@aws-sdk/client
|
|
|
31
31
|
* console.log(newItem); // { "PK": "User/1", "SK": "Book/1", "released": 2000 }
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
|
-
export declare function updateItem(key: Record<string, any>, data: Record<string, any>, args?: Partial<UpdateItemCommandInput>): Promise<undefined |
|
|
34
|
+
export declare function updateItem<T extends Record<string, any> = Record<string, any>>(key: Record<string, any>, data: Record<string, any>, args?: Partial<UpdateItemCommandInput>): Promise<undefined | T>;
|
|
35
35
|
/**
|
|
36
36
|
* Removes specified attributes from an item in DynamoDB.
|
|
37
37
|
*
|
|
@@ -46,4 +46,4 @@ export declare function updateItem(key: Record<string, any>, data: Record<string
|
|
|
46
46
|
* await removeAttributes({ PK: "User/1", SK: "Book/1" }, ["description"]);
|
|
47
47
|
* ```
|
|
48
48
|
*/
|
|
49
|
-
export declare function removeAttributes(key: Record<string, any>, attributes: string[], args?: Partial<UpdateItemCommandInput>): Promise<UpdateItemCommandOutput>;
|
|
49
|
+
export declare function removeAttributes<T extends Record<string, any> = Record<string, any>>(key: Record<string, any>, attributes: string[], args?: Partial<UpdateItemCommandInput>): Promise<UpdateItemCommandOutput | T>;
|
|
@@ -79,7 +79,8 @@ exports.updateItem = updateItem;
|
|
|
79
79
|
async function removeAttributes(key, attributes, args = {}) {
|
|
80
80
|
args = (0, lib_1.withDefaults)(args, "removeAttributes");
|
|
81
81
|
const UpdateExpression = "REMOVE " + attributes.map((att) => `#${att}`).join(", ");
|
|
82
|
-
return (0, lib_1.getClient)()
|
|
82
|
+
return (0, lib_1.getClient)()
|
|
83
|
+
.send(new client_dynamodb_1.UpdateItemCommand({
|
|
83
84
|
Key: (0, lib_1.stripKey)(key, args),
|
|
84
85
|
UpdateExpression,
|
|
85
86
|
ExpressionAttributeNames: (0, lib_1.getAttributeNames)(attributes.reduce((acc, att) => {
|
|
@@ -88,6 +89,7 @@ async function removeAttributes(key, attributes, args = {}) {
|
|
|
88
89
|
}, {})),
|
|
89
90
|
...args,
|
|
90
91
|
TableName: args?.TableName || (0, lib_1.getDefaultTable)(),
|
|
91
|
-
}))
|
|
92
|
+
}))
|
|
93
|
+
.then((res) => args?.ReturnValues ? (0, lib_1.unmarshallWithOptions)(res.Attributes) : undefined);
|
|
92
94
|
}
|
|
93
95
|
exports.removeAttributes = removeAttributes;
|
package/package.json
CHANGED