@moicky/dynamodb 2.0.1 → 2.2.0

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.
@@ -1,3 +1,11 @@
1
1
  import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
2
+ /**
3
+ * Initializes the {@link DynamoDBClient} to use for all operations.
4
+ * @param newClient - The new {@link DynamoDBClient} to use
5
+ */
2
6
  export declare const initClient: (newClient: DynamoDBClient) => void;
7
+ /**
8
+ * Returns the current {@link DynamoDBClient} used for all operations.
9
+ * @returns The current {@link DynamoDBClient}
10
+ */
3
11
  export declare const getClient: () => DynamoDBClient;
@@ -10,9 +10,17 @@ const defaultTable = process.env.DYNAMODB_TABLE;
10
10
  if (defaultTable) {
11
11
  (0, schemas_1.initSchema)({ [defaultTable]: (0, schemas_1.getDefaultTableSchema)() });
12
12
  }
13
+ /**
14
+ * Initializes the {@link DynamoDBClient} to use for all operations.
15
+ * @param newClient - The new {@link DynamoDBClient} to use
16
+ */
13
17
  const initClient = (newClient) => {
14
18
  client = newClient;
15
19
  };
16
20
  exports.initClient = initClient;
21
+ /**
22
+ * Returns the current {@link DynamoDBClient} used for all operations.
23
+ * @returns The current {@link DynamoDBClient}
24
+ */
17
25
  const getClient = () => client;
18
26
  exports.getClient = getClient;
@@ -1,10 +1,11 @@
1
- import { deleteItem, deleteItems, getAllItems, getItem, getItems, itemExists, putItem, putItems, query, queryAllItems, queryItems, removeAttributes, updateItem } from "../operations";
1
+ import { deleteItem, deleteItems, getAllItems, getItem, getItems, itemExists, putItem, putItems, query, queryAllItems, queryItems, queryPaginatedItems, removeAttributes, updateItem } from "../operations";
2
2
  export interface OperationArguments {
3
3
  deleteItem?: Parameters<typeof deleteItem>[1];
4
4
  deleteItems?: Parameters<typeof deleteItems>[1];
5
5
  getItem?: Parameters<typeof getItem>[1];
6
6
  getItems?: Parameters<typeof getItems>[1];
7
7
  getAllItems?: Parameters<typeof getAllItems>[0];
8
+ queryPaginatedItems?: Parameters<typeof queryPaginatedItems>[2];
8
9
  itemExists?: Parameters<typeof itemExists>[1];
9
10
  putItem?: Parameters<typeof putItem>[1];
10
11
  putItems?: Parameters<typeof putItems>[1];
@@ -14,6 +15,37 @@ export interface OperationArguments {
14
15
  updateItem?: Parameters<typeof updateItem>[2];
15
16
  removeAttributes?: Parameters<typeof removeAttributes>[2];
16
17
  }
18
+ /**
19
+ * Initializes the default arguments to use for all operations.
20
+ * @param args - The new default arguments to use for all operations {@link OperationArguments}
21
+ * @returns void
22
+ * @example
23
+ * Enable consistent reads for all operations which support it:
24
+ * ```javascript
25
+ * initDefaultArguments({
26
+ * getItem: { ConsistentRead: true },
27
+ * getAllItems: { ConsistentRead: true },
28
+ * queryPaginatedItems: { ConsistentRead: true, pageSize: 100 },
29
+ *
30
+ * itemExists: { ConsistentRead: true },
31
+ *
32
+ * query: { ConsistentRead: true },
33
+ * queryItems: { ConsistentRead: true },
34
+ * queryAllItems: { ConsistentRead: true },
35
+ * });
36
+ * ```
37
+ */
17
38
  export declare const initDefaultArguments: (args: OperationArguments) => void;
39
+ /**
40
+ * Returns the current default arguments used for all operations.
41
+ * @returns The current default arguments {@link OperationArguments}
42
+ */
18
43
  export declare const getDefaultArguments: () => OperationArguments;
44
+ /**
45
+ * Returns the current default arguments used for all operations.
46
+ * @param args - The arguments to override the default arguments with
47
+ * @param operation - The operation to get the default arguments for
48
+ * @returns The merged arguments
49
+ * @private
50
+ */
19
51
  export declare const withDefaults: <T extends keyof OperationArguments>(args: Partial<OperationArguments[T]>, operation: T) => OperationArguments[T];
@@ -2,12 +2,43 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.withDefaults = exports.getDefaultArguments = exports.initDefaultArguments = void 0;
4
4
  let defaultArguments = {};
5
+ /**
6
+ * Initializes the default arguments to use for all operations.
7
+ * @param args - The new default arguments to use for all operations {@link OperationArguments}
8
+ * @returns void
9
+ * @example
10
+ * Enable consistent reads for all operations which support it:
11
+ * ```javascript
12
+ * initDefaultArguments({
13
+ * getItem: { ConsistentRead: true },
14
+ * getAllItems: { ConsistentRead: true },
15
+ * queryPaginatedItems: { ConsistentRead: true, pageSize: 100 },
16
+ *
17
+ * itemExists: { ConsistentRead: true },
18
+ *
19
+ * query: { ConsistentRead: true },
20
+ * queryItems: { ConsistentRead: true },
21
+ * queryAllItems: { ConsistentRead: true },
22
+ * });
23
+ * ```
24
+ */
5
25
  const initDefaultArguments = (args) => {
6
26
  defaultArguments = args;
7
27
  };
8
28
  exports.initDefaultArguments = initDefaultArguments;
29
+ /**
30
+ * Returns the current default arguments used for all operations.
31
+ * @returns The current default arguments {@link OperationArguments}
32
+ */
9
33
  const getDefaultArguments = () => defaultArguments;
10
34
  exports.getDefaultArguments = getDefaultArguments;
35
+ /**
36
+ * Returns the current default arguments used for all operations.
37
+ * @param args - The arguments to override the default arguments with
38
+ * @param operation - The operation to get the default arguments for
39
+ * @returns The merged arguments
40
+ * @private
41
+ */
11
42
  const withDefaults = (args, operation) => {
12
43
  return {
13
44
  ...defaultArguments[operation],
@@ -1,5 +1,22 @@
1
1
  import { QueryCommandInput, ScanCommandInput } from "@aws-sdk/client-dynamodb";
2
2
  import { marshall, marshallOptions, unmarshall, unmarshallOptions } from "@aws-sdk/util-dynamodb";
3
+ /**
4
+ * DynamoDBFixes is a collection of fixes for DynamoDB.
5
+ * @property disableConsistantReadWhenUsingIndexes - Disables ConsistentRead when using indexes.
6
+ * @property marshallOptions - Options to pass to the [marshall](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/interfaces/_aws_sdk_util_dynamodb.marshallOptions.html) function.
7
+ * @property unmarshallOptions - Options to pass to the [unmarshall](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/interfaces/_aws_sdk_util_dynamodb.unmarshallOptions.html) function.
8
+ * @example
9
+ * ```javascript
10
+ * initFixes({
11
+ * disableConsistantReadWhenUsingIndexes: {
12
+ * enabled: true, // default,
13
+ *
14
+ * // Won't disable ConsistantRead if IndexName is specified here.
15
+ * stillUseOnLocalIndexes: ["localIndexName1", "localIndexName1"],
16
+ * },
17
+ * });
18
+ * ```
19
+ */
3
20
  export declare interface DynamoDBFixes {
4
21
  disableConsistantReadWhenUsingIndexes?: {
5
22
  enabled: boolean;
@@ -8,9 +25,42 @@ export declare interface DynamoDBFixes {
8
25
  marshallOptions?: marshallOptions;
9
26
  unmarshallOptions?: unmarshallOptions;
10
27
  }
28
+ /**
29
+ * Initializes the {@link DynamoDBFixes} to use for all operations.
30
+ * @param fixesConfig - The new {@link DynamoDBFixes} to use
31
+ * @returns void
32
+ */
11
33
  export declare const initFixes: (fixesConfig: DynamoDBFixes) => void;
34
+ /**
35
+ * Returns the current {@link DynamoDBFixes} used for all operations.
36
+ * @returns The current {@link DynamoDBFixes}
37
+ * @private
38
+ */
12
39
  export declare const getFixes: () => DynamoDBFixes;
40
+ /**
41
+ * Returns the current {@link DynamoDBFixes} used for all operations.
42
+ * @param args - The arguments to override the default arguments with
43
+ * @returns The merged arguments
44
+ * @private
45
+ */
13
46
  export declare const withFixes: (args: Partial<QueryCommandInput> | Partial<ScanCommandInput>) => Partial<QueryCommandInput> | Partial<ScanCommandInput>;
47
+ /**
48
+ * Returns the current {@link DynamoDBFixes} used for all operations.
49
+ * @returns The current {@link DynamoDBFixes}
50
+ * @private
51
+ */
14
52
  export declare const getDefaultFixes: () => DynamoDBFixes;
53
+ /**
54
+ * Returns the current {@link DynamoDBFixes} used for all operations.
55
+ * @param input - The input to marshall
56
+ * @returns The marshalled input
57
+ * @private
58
+ */
15
59
  export declare const marshallWithOptions: (input: Parameters<typeof marshall>[0]) => Record<string, import("@aws-sdk/client-dynamodb").AttributeValue>;
60
+ /**
61
+ * Returns the current {@link DynamoDBFixes} used for all operations.
62
+ * @param input - The input to unmarshall
63
+ * @returns The unmarshalled input
64
+ * @private
65
+ */
16
66
  export declare const unmarshallWithOptions: (input: Parameters<typeof unmarshall>[0]) => Record<string, any>;
package/dist/lib/fixes.js CHANGED
@@ -8,10 +8,20 @@ const defaults = Object.freeze({
8
8
  },
9
9
  });
10
10
  let fixes = defaults;
11
+ /**
12
+ * Initializes the {@link DynamoDBFixes} to use for all operations.
13
+ * @param fixesConfig - The new {@link DynamoDBFixes} to use
14
+ * @returns void
15
+ */
11
16
  const initFixes = (fixesConfig) => {
12
17
  fixes = fixesConfig;
13
18
  };
14
19
  exports.initFixes = initFixes;
20
+ /**
21
+ * Returns the current {@link DynamoDBFixes} used for all operations.
22
+ * @returns The current {@link DynamoDBFixes}
23
+ * @private
24
+ */
15
25
  const getFixes = () => fixes;
16
26
  exports.getFixes = getFixes;
17
27
  const handleIndex = (args) => {
@@ -22,14 +32,37 @@ const handleIndex = (args) => {
22
32
  args.ConsistentRead = false;
23
33
  }
24
34
  };
35
+ /**
36
+ * Returns the current {@link DynamoDBFixes} used for all operations.
37
+ * @param args - The arguments to override the default arguments with
38
+ * @returns The merged arguments
39
+ * @private
40
+ */
25
41
  const withFixes = (args) => {
26
42
  handleIndex(args);
27
43
  return args;
28
44
  };
29
45
  exports.withFixes = withFixes;
46
+ /**
47
+ * Returns the current {@link DynamoDBFixes} used for all operations.
48
+ * @returns The current {@link DynamoDBFixes}
49
+ * @private
50
+ */
30
51
  const getDefaultFixes = () => defaults;
31
52
  exports.getDefaultFixes = getDefaultFixes;
53
+ /**
54
+ * Returns the current {@link DynamoDBFixes} used for all operations.
55
+ * @param input - The input to marshall
56
+ * @returns The marshalled input
57
+ * @private
58
+ */
32
59
  const marshallWithOptions = (input) => (0, util_dynamodb_1.marshall)(input, fixes.marshallOptions);
33
60
  exports.marshallWithOptions = marshallWithOptions;
61
+ /**
62
+ * Returns the current {@link DynamoDBFixes} used for all operations.
63
+ * @param input - The input to unmarshall
64
+ * @returns The unmarshalled input
65
+ * @private
66
+ */
34
67
  const unmarshallWithOptions = (input) => (0, util_dynamodb_1.unmarshall)(input, fixes.unmarshallOptions);
35
68
  exports.unmarshallWithOptions = unmarshallWithOptions;
@@ -1,13 +1,44 @@
1
+ /**
2
+ * @property {string} hash - The name of the hash key.
3
+ * @property {string} [range] - The name of the range key. Only required if the table has a range key.
4
+ */
1
5
  export declare interface KeySchema {
2
6
  hash: string;
3
7
  range?: string;
4
8
  }
9
+ /**
10
+ * @property {string} tableName - The name of the table.
11
+ */
5
12
  export declare interface KeySchemaCollection {
6
13
  [tableName: string]: KeySchema;
7
14
  }
15
+ /**
16
+ * Initializes the {@link KeySchemaCollection} to use for all operations.
17
+ * @param schema - The new {@link KeySchemaCollection} to use
18
+ * @returns The new {@link KeySchemaCollection}
19
+ */
8
20
  export declare const initSchema: (schema: KeySchemaCollection) => KeySchemaCollection;
21
+ /**
22
+ * Validates the {@link KeySchemaCollection} to use for all operations.
23
+ * @param schema - The {@link KeySchemaCollection} to validate
24
+ * @returns true if the schema is valid
25
+ */
9
26
  export declare const validateSchema: (schema: KeySchemaCollection) => boolean;
27
+ /**
28
+ * Returns the first table name from the {@link KeySchemaCollection}.
29
+ */
10
30
  export declare const getDefaultTable: () => string;
31
+ /**
32
+ * Returns the {@link KeySchema} for the given or default table.
33
+ */
11
34
  export declare const getTableSchema: (tableName?: string) => KeySchema;
35
+ /**
36
+ * Returns the default {@link KeySchema}.
37
+ * @returns The default {@link KeySchema}
38
+ */
12
39
  export declare const getDefaultTableSchema: () => KeySchema;
40
+ /**
41
+ * Returns whether the {@link KeySchemaCollection} has been initialized.
42
+ * @returns true if the {@link KeySchemaCollection} has been initialized
43
+ */
13
44
  export declare const isInitialized: () => boolean;
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isInitialized = exports.getDefaultTableSchema = exports.getTableSchema = exports.getDefaultTable = exports.validateSchema = exports.initSchema = void 0;
4
4
  let initialized = false;
5
5
  let tablesSchema = {};
6
+ /**
7
+ * Initializes the {@link KeySchemaCollection} to use for all operations.
8
+ * @param schema - The new {@link KeySchemaCollection} to use
9
+ * @returns The new {@link KeySchemaCollection}
10
+ */
6
11
  const initSchema = (schema) => {
7
12
  if (!(0, exports.validateSchema)(schema)) {
8
13
  throw new Error("[@moicky/dynamodb]: Invalid schema");
@@ -19,6 +24,11 @@ const initSchema = (schema) => {
19
24
  return tablesSchema;
20
25
  };
21
26
  exports.initSchema = initSchema;
27
+ /**
28
+ * Validates the {@link KeySchemaCollection} to use for all operations.
29
+ * @param schema - The {@link KeySchemaCollection} to validate
30
+ * @returns true if the schema is valid
31
+ */
22
32
  const validateSchema = (schema) => {
23
33
  const tables = Object.keys(schema);
24
34
  if (tables.length === 0) {
@@ -40,6 +50,9 @@ const validateSchema = (schema) => {
40
50
  return true;
41
51
  };
42
52
  exports.validateSchema = validateSchema;
53
+ /**
54
+ * Returns the first table name from the {@link KeySchemaCollection}.
55
+ */
43
56
  const getDefaultTable = () => {
44
57
  if (!initialized) {
45
58
  throw new Error("[@moicky/dynamodb]: Schema not initialized");
@@ -47,6 +60,9 @@ const getDefaultTable = () => {
47
60
  return Object.keys(tablesSchema)[0];
48
61
  };
49
62
  exports.getDefaultTable = getDefaultTable;
63
+ /**
64
+ * Returns the {@link KeySchema} for the given or default table.
65
+ */
50
66
  const getTableSchema = (tableName) => {
51
67
  if (!initialized) {
52
68
  throw new Error("[@moicky/dynamodb]: Schema not initialized");
@@ -55,9 +71,17 @@ const getTableSchema = (tableName) => {
55
71
  return tablesSchema[table] || (0, exports.getDefaultTableSchema)();
56
72
  };
57
73
  exports.getTableSchema = getTableSchema;
74
+ /**
75
+ * Returns the default {@link KeySchema}.
76
+ * @returns The default {@link KeySchema}
77
+ */
58
78
  const getDefaultTableSchema = () => {
59
79
  return { hash: "PK", range: "SK" };
60
80
  };
61
81
  exports.getDefaultTableSchema = getDefaultTableSchema;
82
+ /**
83
+ * Returns whether the {@link KeySchemaCollection} has been initialized.
84
+ * @returns true if the {@link KeySchemaCollection} has been initialized
85
+ */
62
86
  const isInitialized = () => initialized;
63
87
  exports.isInitialized = isInitialized;
@@ -1,5 +1,66 @@
1
1
  import { BatchWriteItemCommandInput, DeleteItemCommandInput, DeleteItemCommandOutput } from "@aws-sdk/client-dynamodb";
2
+ /**
3
+ * Deletes an item from the DynamoDB table using its key schema.
4
+ * @param key - The item with at least the partition key and the sort key (if applicable) of the item to delete.
5
+ * @param args - The additional arguments to override or specify for {@link DeleteItemCommandInput}
6
+ * @returns A promise that resolves to the output of {@link DeleteItemCommandOutput}
7
+ *
8
+ * @example
9
+ * Delete a single item in default table
10
+ * ```javascript
11
+ * await deleteItem({
12
+ * PK: "User/1",
13
+ * SK: "Book/1",
14
+ * // fields which are not part of the key schema will be removed
15
+ * title: "The Great Gatsby",
16
+ * author: "F. Scott Fitzgerald",
17
+ * released: 1925,
18
+ * });
19
+ * ```
20
+ * @example
21
+ * Delete a single item in a different table
22
+ * ```javascript
23
+ * await deleteItem(
24
+ * { PK: "User/1", SK: "Book/1" },
25
+ * { TableName: "AnotherTable" }
26
+ * );
27
+ * ```
28
+ */
2
29
  export declare function deleteItem(key: any, args?: Partial<DeleteItemCommandInput>): Promise<DeleteItemCommandOutput>;
3
- export declare function deleteItems(keys: any[], args?: Partial<BatchWriteItemCommandInput & {
30
+ type DeleteItemsArgs = Partial<BatchWriteItemCommandInput & {
4
31
  TableName?: string;
5
- }>, retry?: number): Promise<void>;
32
+ }>;
33
+ /**
34
+ * Deletes unlimited items from the DynamoDB table using their key schema.
35
+ * @param keys - The items with at least the partition key and the sort key (if applicable) of the items to delete.
36
+ * @param args - The additional arguments to override or specify for {@link DeleteItemsArgs}
37
+ * @returns A promise that resolves to void
38
+ *
39
+ * @example
40
+ * Delete items in default table
41
+ * ```javascript
42
+ * await deleteItems([
43
+ * // fields which are not part of the key schema will be removed
44
+ * { PK: "User/1", SK: "Book/1", title: "The Great Gatsby", released: 1925 },
45
+ * { PK: "User/1", SK: "Book/2" },
46
+ * { PK: "User/1", SK: "Book/3" },
47
+ * // ... infinite more items (will be grouped into batches of 25 due to aws limit)
48
+ * // and retried up to 3 times
49
+ * ]);
50
+ * ```
51
+ * @example
52
+ * Delete items in a different table
53
+ * ```javascript
54
+ * await deleteItems(
55
+ * [
56
+ * // fields which are not part of the key schema will be removed
57
+ * { PK: "User/1", SK: "Book/1", title: "The Great Gatsby", released: 1925 },
58
+ * { PK: "User/1", SK: "Book/2" },
59
+ * { PK: "User/1", SK: "Book/3" },
60
+ * ],
61
+ * { TableName: "AnotherTable" }
62
+ * );
63
+ * ```
64
+ */
65
+ export declare function deleteItems(keys: any[], args?: DeleteItemsArgs, retry?: number): Promise<void>;
66
+ export {};
@@ -3,6 +3,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deleteItems = exports.deleteItem = void 0;
4
4
  const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
5
5
  const lib_1 = require("../lib");
6
+ /**
7
+ * Deletes an item from the DynamoDB table using its key schema.
8
+ * @param key - The item with at least the partition key and the sort key (if applicable) of the item to delete.
9
+ * @param args - The additional arguments to override or specify for {@link DeleteItemCommandInput}
10
+ * @returns A promise that resolves to the output of {@link DeleteItemCommandOutput}
11
+ *
12
+ * @example
13
+ * Delete a single item in default table
14
+ * ```javascript
15
+ * await deleteItem({
16
+ * PK: "User/1",
17
+ * SK: "Book/1",
18
+ * // fields which are not part of the key schema will be removed
19
+ * title: "The Great Gatsby",
20
+ * author: "F. Scott Fitzgerald",
21
+ * released: 1925,
22
+ * });
23
+ * ```
24
+ * @example
25
+ * Delete a single item in a different table
26
+ * ```javascript
27
+ * await deleteItem(
28
+ * { PK: "User/1", SK: "Book/1" },
29
+ * { TableName: "AnotherTable" }
30
+ * );
31
+ * ```
32
+ */
6
33
  async function deleteItem(key, args = {}) {
7
34
  return (0, lib_1.getClient)().send(new client_dynamodb_1.DeleteItemCommand({
8
35
  Key: (0, lib_1.stripKey)(key, args),
@@ -11,6 +38,38 @@ async function deleteItem(key, args = {}) {
11
38
  }));
12
39
  }
13
40
  exports.deleteItem = deleteItem;
41
+ /**
42
+ * Deletes unlimited items from the DynamoDB table using their key schema.
43
+ * @param keys - The items with at least the partition key and the sort key (if applicable) of the items to delete.
44
+ * @param args - The additional arguments to override or specify for {@link DeleteItemsArgs}
45
+ * @returns A promise that resolves to void
46
+ *
47
+ * @example
48
+ * Delete items in default table
49
+ * ```javascript
50
+ * await deleteItems([
51
+ * // fields which are not part of the key schema will be removed
52
+ * { PK: "User/1", SK: "Book/1", title: "The Great Gatsby", released: 1925 },
53
+ * { PK: "User/1", SK: "Book/2" },
54
+ * { PK: "User/1", SK: "Book/3" },
55
+ * // ... infinite more items (will be grouped into batches of 25 due to aws limit)
56
+ * // and retried up to 3 times
57
+ * ]);
58
+ * ```
59
+ * @example
60
+ * Delete items in a different table
61
+ * ```javascript
62
+ * await deleteItems(
63
+ * [
64
+ * // fields which are not part of the key schema will be removed
65
+ * { PK: "User/1", SK: "Book/1", title: "The Great Gatsby", released: 1925 },
66
+ * { PK: "User/1", SK: "Book/2" },
67
+ * { PK: "User/1", SK: "Book/3" },
68
+ * ],
69
+ * { TableName: "AnotherTable" }
70
+ * );
71
+ * ```
72
+ */
14
73
  async function deleteItems(keys, args = {}, retry = 0) {
15
74
  args = (0, lib_1.withDefaults)(args, "deleteItems");
16
75
  const uniqueKeys = Object.values(keys.reduce((acc, key) => {
@@ -1,6 +1,81 @@
1
1
  import { BatchGetItemCommandInput, GetItemCommandInput, ScanCommandInput } from "@aws-sdk/client-dynamodb";
2
+ /**
3
+ * Retrieves an item from the DynamoDB table using its key schema.
4
+ * @param key - The item with at least the partition key and the sort key (if applicable) of the item to get.
5
+ * @param args - The additional arguments to override or specify for {@link GetItemCommandInput}
6
+ * @returns A promise that resolves to the unmarshalled item
7
+ *
8
+ * @example
9
+ * Get a single item
10
+ * ```javascript
11
+ * await getItem({
12
+ * PK: "User/1",
13
+ * SK: "Book/1",
14
+ * title: "The Great Gatsby",
15
+ * author: "F. Scott Fitzgerald",
16
+ * released: 1925,
17
+ * });
18
+ * ```
19
+ * @example
20
+ * Get a single item in a different table
21
+ * ```javascript
22
+ * await getItem(
23
+ * { PK: "User/1", SK: "Book/1" },
24
+ * { TableName: "AnotherTable" }
25
+ * );
26
+ * ```
27
+ */
2
28
  export declare function getItem(key: any, args?: Partial<GetItemCommandInput>): Promise<Record<string, any> | undefined>;
3
- export declare function getItems(keys: any[], args?: Partial<BatchGetItemCommandInput & {
29
+ type GetItemsArgs = Partial<BatchGetItemCommandInput & {
4
30
  TableName?: string;
5
- }>, retry?: number): Promise<Record<string, any>[]>;
31
+ }>;
32
+ /**
33
+ * Retrieves multiple items from the DynamoDB table using their key schema.
34
+ * @param keys - The items with at least the partition key and the sort key (if applicable) of the items to get.
35
+ * @param args - The additional arguments to override or specify for {@link GetItemsArgs}
36
+ * @returns A promise that resolves to an array of unmarshalled items
37
+ *
38
+ * @example
39
+ * Get items in default table
40
+ * ```javascript
41
+ * await getItems([
42
+ * { PK: "User/1", SK: "Book/1", title: "The Great Gatsby", released: 1925 },
43
+ * { PK: "User/1", SK: "Book/2" },
44
+ * { PK: "User/1", SK: "Book/3" },
45
+ * // ... infinite more items (will be grouped into batches of 100 due to aws limit) and retried up to 3 times
46
+ * ]);
47
+ * ```
48
+ * @example
49
+ * Get items in a different table
50
+ * ```javascript
51
+ * await getItems(
52
+ * [
53
+ * { PK: "User/1", SK: "Book/1", title: "The Great Gatsby", released: 1925 },
54
+ * { PK: "User/1", SK: "Book/2" },
55
+ * { PK: "User/1", SK: "Book/3" },
56
+ * ],
57
+ * { TableName: "AnotherTable" }
58
+ * );
59
+ * ```
60
+ */
61
+ export declare function getItems(keys: any[], args?: GetItemsArgs, retry?: number): Promise<Record<string, any>[]>;
62
+ /**
63
+ * Retrieves all items from the DynamoDB table.
64
+ * @param args - The additional arguments to override or specify for {@link ScanCommandInput}
65
+ * @returns A promise that resolves to an array of unmarshalled items
66
+ *
67
+ * @example
68
+ * Retrieve all items in default table
69
+ * ```javascript
70
+ * await getAllItems();
71
+ * ```
72
+ * @example
73
+ * Retrieve all items in a different table
74
+ * ```javascript
75
+ * await getAllItems(
76
+ * { TableName: "AnotherTable" }
77
+ * );
78
+ * ```
79
+ */
6
80
  export declare function getAllItems(args?: Partial<ScanCommandInput>): Promise<Record<string, any>[]>;
81
+ export {};
@@ -3,6 +3,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAllItems = exports.getItems = exports.getItem = void 0;
4
4
  const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
5
5
  const lib_1 = require("../lib");
6
+ /**
7
+ * Retrieves an item from the DynamoDB table using its key schema.
8
+ * @param key - The item with at least the partition key and the sort key (if applicable) of the item to get.
9
+ * @param args - The additional arguments to override or specify for {@link GetItemCommandInput}
10
+ * @returns A promise that resolves to the unmarshalled item
11
+ *
12
+ * @example
13
+ * Get a single item
14
+ * ```javascript
15
+ * await getItem({
16
+ * PK: "User/1",
17
+ * SK: "Book/1",
18
+ * title: "The Great Gatsby",
19
+ * author: "F. Scott Fitzgerald",
20
+ * released: 1925,
21
+ * });
22
+ * ```
23
+ * @example
24
+ * Get a single item in a different table
25
+ * ```javascript
26
+ * await getItem(
27
+ * { PK: "User/1", SK: "Book/1" },
28
+ * { TableName: "AnotherTable" }
29
+ * );
30
+ * ```
31
+ */
6
32
  async function getItem(key, args = {}) {
7
33
  args = (0, lib_1.withDefaults)(args, "getItem");
8
34
  return (0, lib_1.getClient)()
@@ -14,6 +40,35 @@ async function getItem(key, args = {}) {
14
40
  .then((res) => res?.Item && (0, lib_1.unmarshallWithOptions)(res.Item));
15
41
  }
16
42
  exports.getItem = getItem;
43
+ /**
44
+ * Retrieves multiple items from the DynamoDB table using their key schema.
45
+ * @param keys - The items with at least the partition key and the sort key (if applicable) of the items to get.
46
+ * @param args - The additional arguments to override or specify for {@link GetItemsArgs}
47
+ * @returns A promise that resolves to an array of unmarshalled items
48
+ *
49
+ * @example
50
+ * Get items in default table
51
+ * ```javascript
52
+ * await getItems([
53
+ * { PK: "User/1", SK: "Book/1", title: "The Great Gatsby", released: 1925 },
54
+ * { PK: "User/1", SK: "Book/2" },
55
+ * { PK: "User/1", SK: "Book/3" },
56
+ * // ... infinite more items (will be grouped into batches of 100 due to aws limit) and retried up to 3 times
57
+ * ]);
58
+ * ```
59
+ * @example
60
+ * Get items in a different table
61
+ * ```javascript
62
+ * await getItems(
63
+ * [
64
+ * { PK: "User/1", SK: "Book/1", title: "The Great Gatsby", released: 1925 },
65
+ * { PK: "User/1", SK: "Book/2" },
66
+ * { PK: "User/1", SK: "Book/3" },
67
+ * ],
68
+ * { TableName: "AnotherTable" }
69
+ * );
70
+ * ```
71
+ */
17
72
  async function getItems(keys, args = {}, retry = 0) {
18
73
  args = (0, lib_1.withDefaults)(args, "getItems");
19
74
  // creates batches of 100 items each and performs batchGet on every batch.
@@ -68,6 +123,24 @@ async function getItems(keys, args = {}, retry = 0) {
68
123
  return keys.map((key) => resultItems[JSON.stringify((0, lib_1.stripKey)(key, { TableName }))] || undefined);
69
124
  }
70
125
  exports.getItems = getItems;
126
+ /**
127
+ * Retrieves all items from the DynamoDB table.
128
+ * @param args - The additional arguments to override or specify for {@link ScanCommandInput}
129
+ * @returns A promise that resolves to an array of unmarshalled items
130
+ *
131
+ * @example
132
+ * Retrieve all items in default table
133
+ * ```javascript
134
+ * await getAllItems();
135
+ * ```
136
+ * @example
137
+ * Retrieve all items in a different table
138
+ * ```javascript
139
+ * await getAllItems(
140
+ * { TableName: "AnotherTable" }
141
+ * );
142
+ * ```
143
+ */
71
144
  async function getAllItems(args = {}) {
72
145
  args = (0, lib_1.withFixes)((0, lib_1.withDefaults)(args, "getAllItems"));
73
146
  return (0, lib_1.getClient)()