import { DataboxConfig, DbAccessFunction } from '../../main/config/definitions/parts/databoxConfig'; import Bag from "../Bag"; import { buildKeyArray } from "../../main/databox/keyArrayUtils"; import { ConsumeInputFunction, ValidateInputFunction } from '../../main/input/inputClosureCreator'; import Component from '../component/Component'; /** * If you always want to present the most recent data on the client, * the Databox is the best choice. * The Databox will keep the data up to date on the client in real-time. * Also, it will handle all problematic cases, for example, * when the connection to the server is lost, * and the client did not get an update of the data. * It's also the right choice if you want to present a significant amount of data * because Databoxes support the functionality to stream the data * to the clients whenever a client needs more data. * Additionally, it keeps the network traffic low because it * only sends the changed data information, not the whole data again. */ export default abstract class DataboxCore extends Component { /** * @description * The Databox token version indicates the version of the data tokens. * You should change that version whenever you make a significant change in the session data structure. * It helps to protect your system against old tokens with different structures. * @default 0 */ protected readonly dbTokenVersion: number; private readonly _sendErrorDescription; private readonly _preparedTokenSessionKey; protected readonly parallelFetch: boolean; private readonly _optionsInputConsumer; private readonly _fetchInputConsumer; private readonly _memberInputValidator; protected constructor(identifier: string, bag: Bag, preparedData: DbPreparedData, apiLevel: number | undefined); /** * @description * This property is used for getting the configuration of this Databox. */ static readonly config: DataboxConfig; /** * **Not override this method.** * This method can be used to build a raw key array. * These arrays are useful to present data in a sequence and as a key-value map. * Later, when you use the Databox, * you easily can access the items by the key. * If you did not use a key array, the only possibility to * access the elements in an array is per index. * But this is problematical if every client has a different amount * of elements because then you are not able to change one specific item. * (Because you would change on each client a different item.) * You have more possibilities to create a key array, all are explained in the examples. * @example * // 1: From objects with a key property * // This one is useful when you have objects, * // where each of them has the same property that indicates a key. * // For example, I have 20 message objects, * // and each message object has an id property. * // Then you quickly can build the key array by invoking this * // method with an array that contains the 20 messages and the property name, * // which represents the key. * buildKeyArray([{id: '2033323',msg: 'hello'},{id: '2435435',msg: 'hi'}], 'id'); * * // 2: From objects with a key and value property * // That option is useful when you want to point with the key to only * // a single property value of the object instead of to the whole object. * // Therefore you specify in which property the value can be found. * // In the message example, we could use the msg property as a value and the id as a key. * // The fourth parameter indicates if the data should be compressed. * // By default, this is enabled. Compress will convert every object * // into a key-value pair array; this helps to remove unnecessary properties * // and makes the data that needs to be sent smaller. * buildKeyArray([{id: '2033323',msg: 'hello'}, * {id: '2435435',msg: 'hi'}], 'id', 'msg', true); * * // 3: From key-value pair arrays * // This option will build the key-array from key-value pair arrays. * // That means you specify key-value pairs with arrays. * // The first item of each array represents the key and the second item the associated value. * buildKeyArray([['2033323','hello'],['2435435','hi']]) */ protected buildKeyArray: typeof buildKeyArray; /** * Decorator for set the Databox config. * But notice that when you use the decorator * that you cannot set the config property by yourself. * @param databoxConfig * @example * @Databox.Config({}); */ static Config(databoxConfig: DataboxConfig): (target: typeof DataboxCore) => void; } export interface DbPreparedData { checkAccess: DbAccessFunction; consumeOptionsInput: ConsumeInputFunction; consumeFetchInput: ConsumeInputFunction; validateMemberInput: ValidateInputFunction; parallelFetch: boolean; maxBackpressure: number; maxSocketInputChannels: number; fetchLastTransactionData: number | false; unregisterDelay: number; maxSocketMembers: number; initialData: any; reloadStrategy: { name: string; options?: any; } | null; batch: number | null; }