UNPKG

dynamodb-toolbox

Version:

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

28 lines (27 loc) 962 B
import { DynamoDBToolboxError } from '../../errors/index.js'; import { isBoolean } from '../../utils/validation/isBoolean.js'; import { checkPrimitiveSchema } from '../primitive/check.js'; export class NumberSchema { constructor(props) { this.type = 'number'; this.props = props; } get checked() { return Object.isFrozen(this.props); } check(path) { if (this.checked) { return; } checkPrimitiveSchema(this, path); const { big } = this.props; if (big !== undefined && !isBoolean(big)) { throw new DynamoDBToolboxError('schema.invalidProp', { message: `Invalid property type${path !== undefined ? ` at path '${path}'` : ''}. Property: 'big'. Expected: boolean. Received: ${String(big)}.`, path, payload: { propName: 'big', received: big } }); } Object.freeze(this.props); } }