import { Query } from "queric"; import Socket from '../../api/Socket'; import { DeepReadonly } from '../utils/typeUtils'; export interface DataboxConnectReq { /** * databox (identifier) */ d: string; /** * member */ m?: any; /** * apiLevel */ a?: number; /** * token * If defined will be used instead of * creating a new token with options. */ t?: string; /** * options */ o?: any; } export interface DataboxConnectRes { /** * Input key */ i: string; /** * Output key */ o: string; /** * Last transaction id */ lt: string; /** * Parallel fetching */ p: boolean; /** * The max allowed fetching backpressure (if the parallel fetch is false) */ bp?: number; /** * Initial data */ id?: any; /** * Reload strategy */ rs?: [string, any?]; } export declare type UnregisterSocketFunction = (inputChannelId?: string) => void; export declare const DATABOX_START_INDICATOR = "D>"; export declare const enum CudType { Insert = 0, Update = 1, Delete = 2 } /** * A full-defined transaction package that the server can send to the clients. */ export interface TransactionPackage extends PreTransactionPackage { /** * timestamp */ t: number; } /** * A pre-defined transaction package. */ export interface PreTransactionPackage { /** * id */ i: string; /** * timestamp */ t?: number; /** * operations * If operations is undefined, the changes are unknown. * So the client should reload the complete data. */ o?: CudOperation[]; /** * code */ c?: any; /** * metadata */ m?: any; } /** * A cud operation. */ export interface CudOperation { /** * type */ t: CudType; /** * selector */ s: DbSelector; /** * value */ v?: any; /** * if conditions */ i?: IfOptionProcessedValue; /** * potential Insert/Update */ p?: 0 | 1; } /** * The package that the client can send to the server to invoke an action. */ export interface DbClientInputPackage { /** * Action */ a: DbClientInputAction; /** * Session Target */ t?: DBClientInputSessionTarget; } /** * The package that the client can send to the server to send a signal. */ export interface DbClientInputSignalPackage extends DbClientInputPackage { a: DbClientInputAction.signal; /** * signal */ s: string; /** * data */ d: any; } /** * The package that the client can send to the server to fetch data. */ export interface DbClientInputFetchPackage extends DbClientInputPackage { a: DbClientInputAction.fetch; /** * input */ i: any; } export interface DbClientInputFetchResponse { /** * counter */ c: number; /** * token */ t: string; /** * data */ d: any; /** * Timestamp */ ti: number; } /** * Events that a client can receive from the server. */ export declare enum DbClientOutputEvent { transaction = 0, close = 1, reload = 2, kickOut = 3, signal = 4 } /** * Packages that the server can send to the clients. */ export interface DbClientOutputPackage { /** * action */ a: DbClientOutputEvent; } /** * Transaction package that the server can send to the clients. * In case of inserts, updates, or deletes of data. */ export interface DbClientOutputTransactionPackage extends DbClientOutputPackage { /** * action */ a: DbClientOutputEvent.transaction; /** * payload */ p: TransactionPackage; } /** * Reload package that the server can send to the clients. */ export interface DbClientOutputReloadPackage extends DbClientOutputPackage { /** * action */ a: DbClientOutputEvent.reload; } /** * Close package that the server can send to the clients. */ export interface DbClientOutputClosePackage extends DbClientOutputPackage { /** * action */ a: DbClientOutputEvent.close; /** * code */ c?: number | string; /** * metadata */ m?: any; } /** * Kick out package that the server can send to the clients. */ export interface DbClientOutputKickOutPackage extends DbClientOutputPackage { /** * action */ a: DbClientOutputEvent.kickOut; /** * code */ c?: number | string; /** * metadata */ m?: any; } /** * Signal package that the server can send to the clients. */ export interface DbClientOutputSignalPackage extends DbClientOutputPackage { /** * action */ a: DbClientOutputEvent.signal; /** * signal */ s: string; /** * data */ d?: any; } /** * The target session that the server should use to process. */ export declare const enum DBClientInputSessionTarget { mainSession = 0, reloadSession = 1 } /** * Actions that a client can send to the server. */ export declare const enum DbClientInputAction { fetch = 0, resetSession = 1, copySession = 2, disconnect = 3, getLastTransactionId = 4, signal = 5 } /** * Actions that a server can send to another server. */ export declare const enum DbServerAction { /** * New transaction. */ transaction = 0, /** * Broadcast a client signal package. */ signal = 1, /** * Close the Databox */ close = 2, /** * Broadcast a client package. */ broadcast = 3, /** * Current transaction data request. */ transactionDataRequest = 4, /** * Current transaction data response. */ transactionDataResponse = 5, /** * Recheck member access request. */ recheckMemberAccess = 6 } /** * A package that a worker can send to the other workers. */ export interface DbServerPackage { /** * action */ 0: DbServerAction; /** * payload */ 1?: any; } /** * Transaction package that the server can send to other servers. * In case of inserts, updates, or deletes. */ export interface DbServerTransactionPackage extends DbServerPackage { /** * action */ 0: DbServerAction.transaction; /** * transaction package */ 1: TransactionPackage; } /** * Signal package that the server can send to other servers. */ export interface DbServerSignalPackage extends DbServerPackage { /** * action */ 0: DbServerAction.signal; /** * data */ 1: DbClientOutputSignalPackage; } /** * Close package that the server can send to other servers. */ export interface DbServerClosePackage extends DbServerPackage { /** * action */ 0: DbServerAction.close; /** * The client close package. */ 1: DbClientOutputClosePackage; } /** * Broadcast package that the server can send to other servers. */ export interface DbServerBroadcastPackage extends DbServerPackage { /** * action */ 0: DbServerAction.broadcast; /** * data */ 1: DbClientOutputPackage; } /** * Current transaction data request package that the server can send to other servers. */ export interface DbServerTransactionDataRequestPackage extends DbServerPackage { /** * action */ 0: DbServerAction.transactionDataRequest; } /** * Current transaction data response package that the server can send to other servers. */ export interface DbServerTransactionDataResponsePackage extends DbServerPackage { /** * action */ 0: DbServerAction.transactionDataResponse; /** * last transaction timestamp */ 1: number; /** * last transaction id */ 2: string; } /** * Recheck member access request package that the server can send to other servers. */ export interface DbServerRecheckMemberAccessPackage extends DbServerPackage { /** * action */ 0: DbServerAction.recheckMemberAccess; } /** * The Databox token. */ export interface DbToken { /** * The raw options. */ rawOptions: any; /** * The Databox sessions. */ sessions: DbSessions; } /** * All session data of a client. */ export interface DbSessions { /** * mainSession */ main: DbSession; /** * reloadSession */ reload: DbSession; } /** * One session that can be used to call the get data method. */ export interface DbSession { /** * counter */ c: number; /** * data */ d: DbSessionData; } export declare type DbSessionData = Record; export interface InfoOption { /** * @description * With the code, you can describe the type of the transaction. * That can be a string (e.g. 'NewMessage') or a number (e.g. 200,304). */ code?: string | number; /** * @description * Optional metadata that describes the transaction. * The metadata can be used in middlewares to deny or allow the transaction. */ metadata?: any; } export interface TimestampOption { /** * With the timestamp option, you can change the sequence of data. * The client, for example, will only update data that is older as incoming data. * Use this option only if you know what you are doing. */ timestamp?: number; } export declare const enum IfQueryType { search = 0, full = 1 } export declare type IfQuery = IfFullQuery | IfSearchQuery; export interface IfFullQuery { n?: boolean; t: IfQueryType.full; q: Query; } export interface IfSearchQuery { n?: boolean; t: IfQueryType.search; q: SearchQuery; } export declare type IfOptionValue = IfQuery | (IfQuery[]); export declare type IfOptionProcessedValue = IfQuery[]; export interface IfOptionProcessed { if?: IfOptionProcessedValue; } export interface IfOption { /** * @description * The if option gives you the possibility to * define conditions for the transaction operation. * All conditions must be evaluated to true; * otherwise, the client will ignore the operation. * Notice that even in the content API, the if option is not typesafe. * You can define multiple conditions with an array or only one condition. * If you have an operation that has a selector that has multiple key targets, * the if conditions will only be evaluated once for every component. * There are two helper functions to build a condition the $contains and $matches helper. * In both helper functions, you pass in queric queries. * The contains helper function will execute the queries multiple times * for each key or value. * If at least one pair, key, or value matches, the condition is evaluated to true. * It's possible to invert the result using the $not function. * That gives you the possibility to check that a specific key, value, * or pair must exist or not. * In the case of a head selector (with selector [] or ''), the key always is: '' and * the value references to the complete data structure (if the value is not undefined).) * With the $any constant, which refers to an empty query ({}), * you can check if any pair exists or not. * Some useful example would be to reinsert old data, * but only to the clients that already loaded this old data section. * Or to build a set where each element value should be unique. * The matches helper function will execute the query once for the * complete object (all key-value pairs). * It's also possible to invert the result using the $not function. * In the case of a head selector (with selector [] or ''), the value * of the head (complete data structure) will be used. * It helps to check multiple pairs in one query and makes it more readable. * @example * if: $not($contains($any)) * if: $contains($key('20')) * if: [$contains($value({name: 'luca'})),$not(contains($key('30')))] * if: $contains($pair('name','luca')) * if: $matches({name: 'luca', age: {gte: 18}, email: 'test1@test.de'}) * if: $not($matches({email: 'test1@test.de'})) */ if?: IfOptionValue; } export interface PotentialUpdateOption { /** * @description * With the potentialUpdate option, you indicate that the insert is potential an update. * For example, when the key already exists, * the client will update the value instead of insert. */ potentialUpdate?: boolean; } export interface PotentialInsertOption { /** * @description * With the potentialInsert option, you indicate that the update is potential an insert. * For example, when the key does not exist, * the client will insert the value instead of update. * Notice that the potentialInsert only works when the path selector ends on a specific key. */ potentialInsert?: boolean; } /** * The memory that Databoxes stores internally for last transaction data. */ export interface DbLastTransactionDataMemory { id: string; timestamp: number; fetchResolve?: () => void; fetchPromise?: Promise; } /** * The memory that Databoxes stores internally for each socket. */ export interface DbSocketMemory { unregisterSocket: UnregisterSocketFunction; inputChIds: Set; } /** * The memory that DataboxFamilies stores internally for each member. */ export interface DbMemberMemory { sockets: Map; lastTransactionData: DbLastTransactionDataMemory; } /** * The Databox register result. */ export interface DbRegisterResult { inputCh: string; outputCh: string; } /** * The Databox info object. */ export interface DataboxInfo { identifier: string; /** * Notice that the member is deep readonly and only given in non-static components. */ member?: any; } /** * Internal member wrapper interface. */ export interface DbMember { memberStr: string; member: DeepReadonly; } /** * queric search query. */ export declare type SearchQuery = { k?: Query; v?: Query; }; export declare type DbSelector = (string | '$nextIndex' | '$lastIndex' | SearchQuery)[];