UNPKG

dynamodb-toolbox

Version:

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

47 lines (46 loc) 1.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Parser = void 0; const index_js_1 = require("../../../errors/index.js"); const index_js_2 = require("../../../schema/index.js"); const item_js_1 = require("./item.js"); const schema_js_1 = require("./schema.js"); class Parser extends index_js_2.SchemaAction { start(inputValue, options = {}) { if (this.schema.type === 'item') { return (0, item_js_1.itemParser)(this.schema, inputValue, options); } else { return (0, schema_js_1.schemaParser)(this.schema, inputValue, options); } } parse(inputValue, options = {}) { const parser = this.start(inputValue, options); let done = false; let value; do { const nextProps = parser.next(); done = Boolean(nextProps.done); // TODO: Not cast value = nextProps.value; } while (!done); return value; } reparse(inputValue, options = {}) { return this.parse(inputValue, options); } validate(inputValue, options = {}) { try { this.parse(inputValue, { ...options, fill: false, transform: false }); } catch (error) { if (error instanceof index_js_1.DynamoDBToolboxError && index_js_1.DynamoDBToolboxError.match(error, 'parsing.')) { return false; } throw error; } return true; } } exports.Parser = Parser; Parser.actionName = 'parse';