import * as Immutable from 'immutable'; import * as utils from '../utils'; export class ValueToStringError extends utils.SiError {} export class ValueFromStringError extends utils.SiError {} export interface ISiFieldValue { field: ISiDataType; value: T; toString: () => string; } export type ISiStorageData = Immutable.List; export interface ISiDataType { isValueValid: (value: T) => boolean; typeSpecificIsValueValid: (value: T) => boolean; valueToString: (value: T) => string|ValueToStringError; typeSpecificValueToString: (value: T) => string|ValueToStringError; valueFromString: (string: string) => T|ValueFromStringError; typeSpecificValueFromString: (string: string) => T|ValueFromStringError; extractFromData: (data: ISiStorageData) => ISiFieldValue|undefined; typeSpecificExtractFromData: (data: ISiStorageData) => T|undefined; updateData: (data: ISiStorageData, newValue: T|ISiFieldValue) => ISiStorageData; typeSpecificUpdateData: (data: ISiStorageData, newValue: T) => ISiStorageData; } export type ISiStorageLocations = { [id in keyof Fields]: ISiDataType }; /** Consists of locations and size */ export type ISiStorageDefinition = ( initArg?: Immutable.List|Array ) => ISiStorage; export interface ISiStorage { size: number; locations: ISiStorageLocations; data: ISiStorageData; get: ( fieldName: U, ) => ISiFieldValue|undefined; set: ( fieldName: U, newValue: ISiFieldValue|T[U], ) => void; splice: ( index: number, removeNum: number, ...values: number[] ) => void; }