import { Query } from "queric"; import { IfOption, InfoOption, PotentialInsertOption, PotentialUpdateOption, TimestampOption } from './dbDefinitions'; import { ComplexTypesOption } from 'ziron-worker'; import { IsStrictlyAny, ObjectValues, OptionalObjectKeys, RequiredValue } from '../utils/typeUtils'; import Databox from '../../api/databox/Databox'; import StaticDatabox from '../../api/databox/StaticDatabox'; interface FilterFunctions { /** * @description * Function to filter the items by value with a queric query. */ filterByValue(query: Query): R; /** * @description * Function to filter the items by key with a queric query. * @param query */ filterByKey(query: Query): R; /** * @description * Function to filter the items by pair with queric queries. * @param keyQuery * @param valueQuery */ filterByPair(keyQuery: Query, valueQuery: Query): R; /** * @description * Function to select all items. */ all(): R; } interface DeleteFunction { /** * @description * Deletes the selected value/s. * Don't forget to update your database before updating the databox. * If you want to do multiple operations in one transaction, you should look at the bundle option. * Notice that in every case, the delete only happens when the key * on the client does exist. * Otherwise, the client will ignore it. * Other conditions are that the timeout is newer than the existing * timeout and all if conditions are true. * KeyArray -> Deletes the specific value. * Object -> Deletes the specific value. * Array -> Deletes the value at the specified numeric * index or the last item in the array with the key "$lastIndex". * To delete the last item, you can use the $lastIndex string as a key. * @param options */ delete(options?: IfOption & InfoOption & TimestampOption): R; } interface UpdateFunction { /** * @description * Updates the selected value/s. * Don't forget to update your database before updating the databox. * If you want to do multiple operations in one transaction, you should look at the bundle option. * Update behaviour: * Notice that in every case, the update only happens when the key * on the client does exist. * Otherwise, the client will ignore or convert it to an * insert when potentiallyInsert is active. * Other conditions are that the timeout is newer than the existing * timeout and all if conditions are true. * @param value * @param options */ update(value: V, options?: IfOption & PotentialInsertOption & InfoOption & TimestampOption & ComplexTypesOption): R; } interface ArrInsertFunction { /** * Inserts a new value in the selected array or keyArray. * Don't forget to update your database before updating the databox. * If you want to do multiple operations in one transaction, you should look at the bundle option. * Notice that in every case, the insert only happens when the key * does not exist on the client. * Otherwise, the client will ignore or convert it to an * update when potentiallyUpdate is active. * Other conditions are that the timeout is newer than the existing * timeout and all if conditions are true. * KeyArray -> Inserts the value at the end with the key. * But if you are using a compare function, it will insert the value in the correct position. * Array -> Key will be parsed to int if it is a number, then it will be inserted at the index. * Otherwise, it is possible to insert at the end with the key "$nextIndex". * @param key * @param value * @param options */ insert(key: string | number | '$nextIndex', value: V, options?: IfOption & PotentialUpdateOption & InfoOption & TimestampOption & ComplexTypesOption): R; } interface ObjInsertFunction { /** * Inserts a new value in the object. * Don't forget to update your database before updating the databox. * If you want to do multiple operations in one transaction, you should look at the bundle option. * Notice that in every case, the insert only happens when the key * does not exist on the client. * Otherwise, the client will ignore or convert it to an * update when potentiallyUpdate is active. * Other conditions are that the timeout is newer than the existing * timeout and all if conditions are true. * @param property * @param value * @param options */ insert>(property: K, value: O[K], options?: IfOption & PotentialUpdateOption & InfoOption & TimestampOption & ComplexTypesOption): R; } interface BundleDeleteFunction { /** * @description * Deletes the selected value/s. * Don't forget to update your database before updating the databox. * Notice that in every case, the delete only happens when the key * on the client does exist. * Otherwise, the client will ignore it. * Other conditions are that the timeout is newer than the existing * timeout and all if conditions are true. * KeyArray -> Deletes the specific value. * Object -> Deletes the specific value. * Array -> Deletes the value at the specified numeric * index or the last item in the array with the key "$lastIndex". * To delete the last item, you can use the $lastIndex string as a key. * @param options */ delete(options?: IfOption): R; } interface BundleUpdateFunction { /** * @description * Updates the selected value/s. * Don't forget to update your database before updating the databox. * Update behaviour: * Notice that in every case, the update only happens when the key * on the client does exist. * Otherwise, the client will ignore or convert it to an * insert when potentiallyInsert is active. * Other conditions are that the timeout is newer than the existing * timeout and all if conditions are true. * @param value * @param options */ update(value: V, options?: IfOption & PotentialInsertOption): R; } interface BundleObjPartialUpdateFunction { /** * @description * Updates all given properties of the object. * Notice that internally multiple updates for each given property are built. * That's why this method is only available when constructing a bundle. * Don't forget to update your database before updating the databox. * Update behaviour: * Notice that in every case, the update only happens when the key * on the client does exist. * Otherwise, the client will ignore or convert it to an * insert when potentiallyInsert is active. * Other conditions are that the timeout is newer than the existing * timeout and all if conditions are true. * @param properties * @param options */ partialUpdate(properties: Partial, options?: IfOption & PotentialInsertOption): R; } interface BundleArrInsertFunction { /** * Inserts a new value in the selected array or keyArray. * Don't forget to update your database before updating the databox. * Notice that in every case, the insert only happens when the key * does not exist on the client. * Otherwise, the client will ignore or convert it to an * update when potentiallyUpdate is active. * Other conditions are that the timeout is newer than the existing * timeout and all if conditions are true. * KeyArray -> Inserts the value at the end with the key. * But if you are using a compare function, it will insert the value in the correct position. * Array -> Key will be parsed to int if it is a number, then it will be inserted at the index. * Otherwise, it is possible to insert at the end with the key "$nextIndex". * @param key * @param value * @param options */ insert(key: string | number | '$nextIndex', value: V, options?: IfOption & PotentialUpdateOption): R; } interface BundleObjInsertFunction { /** * Inserts a new value in the object. * Don't forget to update your database before updating the databox. * Notice that in every case, the insert only happens when the key * does not exist on the client. * Otherwise, the client will ignore or convert it to an * update when potentiallyUpdate is active. * Other conditions are that the timeout is newer than the existing * timeout and all if conditions are true. * @param property * @param value * @param options */ insert>(property: K, value: O[K], options?: IfOption & PotentialUpdateOption): R; } interface CommitFunction { /** * @description * Apply all changes on the Databox. * Don't forget to update your database before updating the databox. */ commit(options?: TimestampOption & ComplexTypesOption & InfoOption): R; } export declare type ContentPrimitive = null | boolean | string | number | Function; declare type ContentBody = (true extends DE ? DeleteFunction> : {}) & (IsStrictlyAny extends true ? UpdateFunction> & ObjInsertFunction> & FilterFunctions> & { [p: string]: ContentBody; } : [ D ] extends [ContentPrimitive] ? UpdateFunction> : D extends Array ? Omit<{ [Index in keyof D]: ContentBody; }, keyof typeof Array['prototype']> & Record> & UpdateFunction> & ArrInsertFunction> & FilterFunctions> : D extends object ? { [K in keyof D]-?: ContentBody, undefined extends D[K] ? true : false>; } & UpdateFunction> & ObjInsertFunction> & FilterFunctions, ContentBody, false>> : {}); declare type ContentHead = ContentBody, undefined extends T ? true : false>; declare type BundleContentBody = (true extends DE ? BundleDeleteFunction & CommitFunction>> : {}) & (IsStrictlyAny extends true ? BundleUpdateFunction & CommitFunction>> & BundleObjInsertFunction & CommitFunction>> & BundleObjPartialUpdateFunction & CommitFunction>> & FilterFunctions> & { [p: string]: BundleContentBody; } : [ D ] extends [ContentPrimitive] ? BundleUpdateFunction & CommitFunction>> : D extends Array ? Omit<{ [Index in keyof D]: BundleContentBody; }, keyof typeof Array['prototype']> & Record> & BundleUpdateFunction & CommitFunction>> & BundleArrInsertFunction & CommitFunction>> & FilterFunctions> : D extends object ? { [K in keyof D]-?: BundleContentBody, undefined extends D[K] ? true : false>; } & BundleUpdateFunction & CommitFunction>> & BundleObjInsertFunction & CommitFunction>> & BundleObjPartialUpdateFunction & CommitFunction>> & FilterFunctions, BundleContentBody, false>> : {}); declare type BundleContentHead = CommitFunction> & BundleContentBody, undefined extends T ? true : false>; export declare type Content = true extends B ? BundleContentHead : ContentHead; export declare type DbContent = T extends Databox ? ContentHead : T extends StaticDatabox ? ContentHead : never; export declare type DbContentBundle = T extends Databox ? BundleContentHead : T extends StaticDatabox ? BundleContentHead : never; export declare type StaticDbContentAPI = (bundle?: B) => Content; export declare type DbContentAPI = (member: M, bundle?: B) => Content; export interface DataboxContentCompatible { } export interface StaticDataboxContentCompatible { } export declare function buildStaticDbContentAPI(databox: StaticDataboxContentCompatible): StaticDbContentAPI; export declare function buildDbContentAPI(databox: DataboxContentCompatible): DbContentAPI; export {};