UNPKG

@backland/schema

Version:

TypeScript schema declaration and validation library with static type inference

54 lines (53 loc) 1.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AliasField = void 0; var _utils = require("@backland/utils"); var _CircularDeps = require("../CircularDeps"); var _FieldType = require("./FieldType"); class AliasField extends _FieldType.FieldType { static is(input) { return (input === null || input === void 0 ? void 0 : input.__isFieldType) && (input === null || input === void 0 ? void 0 : input.type) === 'alias'; } static assert(input) { (0, _utils.assertEqual)(this.is(input), true, 'NOT_ALIAS_FIELD'); } constructor(def) { super({ def, name: 'alias' }); const type = _CircularDeps.CircularDeps.createType(typeof def === 'string' ? 'any' : def.type); this.utils = { fieldType: type.__lazyGetter.field }; this.composer = { compose: parent => { if (typeof this.def === 'string') { return (0, _utils.getByPath)(parent, this.def); } if (this.def.from) { parent = (0, _utils.getByPath)(parent, this.def.from); if (!this.def.aggregate) return parent; } (0, _utils.nonNullValues)({ aggregate: this.def.aggregate }); return (0, _utils.aggio)([parent], this.def.aggregate); }, def: this.utils.fieldType.asFinalFieldDef, validate: value => { return this.utils.fieldType.validate(value); } }; this.parse = input => { return this.utils.fieldType.parse(input); }; } static create = def => { return new AliasField(def); }; } exports.AliasField = AliasField; //# sourceMappingURL=AliasField.js.map