dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
36 lines (35 loc) • 1.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.fromZodLiteral = void 0;
const index_js_1 = require("../../../errors/index.js");
const index_js_2 = require("../../../schema/boolean/index.js");
const index_js_3 = require("../../../schema/null/index.js");
const index_js_4 = require("../../../schema/number/index.js");
const index_js_5 = require("../../../schema/string/index.js");
const isBigInt_js_1 = require("../../../utils/validation/isBigInt.js");
const isBoolean_js_1 = require("../../../utils/validation/isBoolean.js");
const isNull_js_1 = require("../../../utils/validation/isNull.js");
const isNumber_js_1 = require("../../../utils/validation/isNumber.js");
const isString_js_1 = require("../../../utils/validation/isString.js");
const fromZodLiteral = (zodLiteral) => {
if ((0, isNull_js_1.isNull)(zodLiteral.value)) {
return (0, index_js_3.nul)().const(null);
}
if ((0, isBoolean_js_1.isBoolean)(zodLiteral.value)) {
return (0, index_js_2.boolean)().const(zodLiteral.value);
}
if ((0, isNumber_js_1.isNumber)(zodLiteral.value)) {
return (0, index_js_4.number)().const(zodLiteral.value);
}
if ((0, isBigInt_js_1.isBigInt)(zodLiteral.value)) {
return (0, index_js_4.number)().big().const(zodLiteral.value);
}
if ((0, isString_js_1.isString)(zodLiteral.value)) {
return (0, index_js_5.string)().const(zodLiteral.value);
}
throw new index_js_1.DynamoDBToolboxError('fromZodSchema.unrecognizedLiteral', {
message: 'ZodLiteral schema cannot be represented within DynamoDB-Toolbox',
payload: { received: zodLiteral.value }
});
};
exports.fromZodLiteral = fromZodLiteral;