UNPKG

integreat

Version:
34 lines 1.22 kB
import expandShape from './expandShape.js'; import createCast from './createCast.js'; import accessForAction from './accessForAction.js'; import { isShape } from '../utils/is.js'; const expandField = (val) => typeof val === 'string' ? { $type: val } : isShape(val) ? expandFields(val) : val; const expandFields = (vals) => Object.entries(vals).reduce((newVals, [key, def]) => def ? { ...newVals, [key]: expandField(def) } : newVals, {}); const expandAccess = (access) => typeof access === 'string' ? { allow: access } : access; export default class Schema { id; plural; service; internal; shape; access; castFn; constructor(def, schemas = new Map()) { this.id = def.id; this.plural = def.plural || `${def.id}s`; this.service = def.service; this.internal = def.internal ?? false; this.shape = expandShape(def.shape || {}); this.access = expandAccess(def.access); const castFn = createCast(this.shape, def.id, schemas, def.generateId); this.castFn = castFn; } accessForAction(actionType) { return accessForAction(this.access, actionType); } } //# sourceMappingURL=Schema.js.map