UNPKG

@backland/schema

Version:

TypeScript schema declaration and validation library with static type inference

84 lines 2.48 kB
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } import { CircularDeps } from '../CircularDeps'; import { FieldType } from './FieldType'; var def = { PK: { description: 'Primary Key', string: {} }, SK: { description: 'Secondary or Sort Key', optional: true, string: {} }, after: { // description: '', optional: true, string: {} }, fields: { list: true, // description: '', optional: true, string: {} }, limit: { int: {}, // description: '', optional: true }, prefix: { description: 'The prefix to search as "startsWith" in SK', optional: true, string: {} }, sep: { description: 'Composite key separator', optional: true, string: {} }, version: { description: 'The Cursor format version', string: {} } }; var cursorObject; function getCursorObject() { // circular dependency var { createObjectType } = CircularDeps.ObjectType; cursorObject = cursorObject || createObjectType('Cursor', def); return cursorObject; } export class CursorField extends FieldType { static object() { return getCursorObject(); } constructor() { super({ def: undefined, name: 'cursor' }); _defineProperty(this, "parse", void 0); _defineProperty(this, "utils", void 0); this.utils = { object: getCursorObject() }; var parser = this.utils.object.parse.bind(this.utils.object); this.parse = this.applyParser({ parse: value => { if (typeof value !== 'object') { throw new Error("Expected cursor, found ".concat(value)); } return parser(value); } }); } } _defineProperty(CursorField, "create", () => { return new CursorField(); }); //# sourceMappingURL=CursorField.js.map