diff --git a/packages/spacecat-shared-dynamo/src/utils/guards.js b/packages/spacecat-shared-dynamo/src/utils/guards.js index 90668b1d..62b39272 100644 --- a/packages/spacecat-shared-dynamo/src/utils/guards.js +++ b/packages/spacecat-shared-dynamo/src/utils/guards.js @@ -12,18 +12,36 @@ import { hasText, isObject } from '@adobe/spacecat-shared-utils'; +/** + * Validates that the provided table name is a non-empty string. + * + * @param {string} tableName - The name of the table to validate. + * @throws {Error} If the table name is empty or not a string. + */ const guardTableName = (tableName) => { if (!hasText(tableName)) { throw new Error('Table name is required.'); } }; +/** + * Validates that the provided key is an object and contains a partitionKey. + * + * @param {object} key - The key object to validate. + * @throws {Error} If the key is not an object or does not contain a partitionKey. + */ const guardKey = (key) => { if (!isObject(key) || !key.partitionKey) { throw new Error('Key must be an object with a partitionKey.'); } }; +/** + * Validates that the provided parameters object contains the required query parameters. + * + * @param {object} params - The parameters object to validate. + * @throws {Error} If the parameters object is not an object or is missing required properties. + */ const guardQueryParameters = (params) => { if (!isObject(params)) { throw new Error('Query parameters must be an object.');