import {FormatType} from '../modeling'; export type ReturnType = 'objects' | 'relations' | 'pairs' | 'map' | 'keyed_objects' | 'keyed_relations' | 'keyed_pairs'; export type ValueType = 'primitive' | 'list' | 'summary'; export type ObjectType = 'specials' | 'instance'; export type DataValue = string | number | boolean | ArrayBuffer; export type JSONDataValue = string | number | boolean; export type JSONValue = | string | number | boolean | null | { [x: string]: JSONValue } | Array; export type Parameters = { [_: string]: JSONValue }; export class Mapping { protected _valueType: ValueType; protected _valueParams: { [_: string]: JSONValue }; public constructor(valueType: ValueType) { this._valueType = valueType; this._valueParams = {}; } public get valueType(): ValueType { return this._valueType; } public get parameters(): Parameters { return this._valueParams; } public change(change: 'set' | 'add'): Mapping { this.set('change', change); return this; } protected set(key: string, value: JSONValue): Mapping { this._valueParams[key] = value; return this; } public setParams(params: { [_: string]: JSONValue }) { params['mapping'] = this._valueType for (const k in this._valueParams) { params[`mp_${k}`] = this._valueParams[k] } } } export class PrimitiveMapping extends Mapping { constructor() { super('primitive'); } public change(change: 'set' | 'add'): PrimitiveMapping { return super.change(change); } } export class ListMapping extends Mapping { constructor() { super('list'); } public change(change: 'set' | 'add'): ListMapping { return super.change(change); } } export class KeyedListMapping extends Mapping { constructor(format: FormatType) { super('list'); this.set('keyFormat', format); } public change(change: 'set' | 'add'): KeyedListMapping { return super.change(change); } } export class SystemError { public constructor(public readonly code: number, public readonly message: string) { } }