UNPKG

dynamodb-toolbox

Version:

Lightweight and type-safe query builder for DynamoDB and TypeScript.

26 lines (25 loc) 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.doesSchemaValidateTableSchema = exports.doesSchemaValidateTableSchemaKey = void 0; const doesSchemaValidateTableSchemaKey = (schema, key) => { if (key === undefined) return true; const keyAttributeEntry = [...schema.keyAttributeNames.values()] .map(attributeName => [attributeName, schema.attributes[attributeName]]) .find(([attributeName, { props }]) => props.savedAs === key.name || (props.savedAs === undefined && attributeName === key.name)); if (keyAttributeEntry === undefined) { return false; } const [, keyAttribute] = keyAttributeEntry; return (keyAttribute !== undefined && keyAttribute.type === key.type && keyAttribute.props.key === true && (keyAttribute.props.required === 'always' || keyAttribute.props.keyDefault !== undefined)); }; exports.doesSchemaValidateTableSchemaKey = doesSchemaValidateTableSchemaKey; const doesSchemaValidateTableSchema = (schema, table) => { const { partitionKey, sortKey } = table; return ((0, exports.doesSchemaValidateTableSchemaKey)(schema, partitionKey) && (0, exports.doesSchemaValidateTableSchemaKey)(schema, sortKey)); }; exports.doesSchemaValidateTableSchema = doesSchemaValidateTableSchema;