dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
32 lines (31 loc) • 1.34 kB
JavaScript
import { DynamoDBToolboxError } from '../../../errors/index.js';
import { boolean } from '../../../schema/boolean/index.js';
import { nul } from '../../../schema/null/index.js';
import { number } from '../../../schema/number/index.js';
import { string } from '../../../schema/string/index.js';
import { isBigInt } from '../../../utils/validation/isBigInt.js';
import { isBoolean } from '../../../utils/validation/isBoolean.js';
import { isNull } from '../../../utils/validation/isNull.js';
import { isNumber } from '../../../utils/validation/isNumber.js';
import { isString } from '../../../utils/validation/isString.js';
export const fromZodLiteral = (zodLiteral) => {
if (isNull(zodLiteral.value)) {
return nul().const(null);
}
if (isBoolean(zodLiteral.value)) {
return boolean().const(zodLiteral.value);
}
if (isNumber(zodLiteral.value)) {
return number().const(zodLiteral.value);
}
if (isBigInt(zodLiteral.value)) {
return number().big().const(zodLiteral.value);
}
if (isString(zodLiteral.value)) {
return string().const(zodLiteral.value);
}
throw new DynamoDBToolboxError('fromZodSchema.unrecognizedLiteral', {
message: 'ZodLiteral schema cannot be represented within DynamoDB-Toolbox',
payload: { received: zodLiteral.value }
});
};