import { ActionAttribute } from '../actions/types' import { VarDataType } from '../types' import { createAttributeGlobalId } from './attribute' /** * System produced attributes * @returns */ export const provideSystemProducedAttribute = ( data: Pick & { relId: string } ): ActionAttribute => { const { name, datatype, label, description, relId } = data const attr = { globalId: '', id: '', name, datatype, label, description, required: false, value: '', } const id = createAttributeGlobalId({ relId: '', name: attr.name, datatype: attr.datatype, }) const globalId = createAttributeGlobalId({ relId, name: attr.name, datatype: attr.datatype, }) return { ...attr, globalId, id } } export const EMPTY_ATTR_GLOBAL_ID = createAttributeGlobalId({ relId: '$empty', name: 'empty', datatype: VarDataType.null, }) export const emptyAttribute = provideSystemProducedAttribute({ name: 'empty', label: '$Empty Value', datatype: VarDataType.null, description: '$Empty value', relId: '$empty', }) export const serialize = (obj = {}) => Object.entries(obj) .map(([key, val]) => `${key}=${val}`) .join(';') export const deserialize = (str = '') => Object.fromEntries(str.split(';').map(equalStr => equalStr.split('=')))