import { CudOperation, InfoOption, IfOption, DbSelector, PotentialUpdateOption, PotentialInsertOption, TimestampOption } from './dbDefinitions'; import { ComplexTypesOption } from 'ziron-worker'; declare type CommitFunction = (operations: CudOperation[], options: InfoOption & TimestampOption & ComplexTypesOption) => void; /** * Saves all commands for execute later. */ export default class DbTransaction { private operations; private readonly commitFunction; constructor(commitFunc: CommitFunction); /** * Insert a new value in the Databox. * The function is part of the performance transaction API. * In most cases, it is highly recommended to use the type-safe and more readable content API. * Insert behavior: * 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. * Head (with selector [] or '') -> Inserts the value. * 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. * Object -> Insert the value with the key. * 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 selector * The selector describes which key-value pairs should be * deleted updated or where a value should be inserted. * It can be a string array key path, but it also can contain * filter queries (they work with the queric library). * You can filter by value ($value or property value) by key ($key or property key) or * select all keys with {} (For better readability use the constant $all). * In the case of insertions, most times, the selector should end with * a new key instead of a query. * @param value * @param ifContains * @param potentialUpdate */ insert(selector: DbSelector, value: any, { if: ifOption, potentialUpdate }?: IfOption & PotentialUpdateOption): DbTransaction; /** * Update a value in the Databox. * The function is part of the performance transaction API. * In most cases, it is highly recommended to use the type-safe and more readable content API. * Update behavior: * 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. * Head (with selector [] or '') -> Updates the complete structure. * KeyArray -> Updates the specific value. * Object -> Updates the specific value. * Array -> Updates the value at the specified numeric * index or the last item in the array with the key "$lastIndex". * @param selector * The selector describes which key-value pairs should be * deleted updated or where a value should be inserted. * It can be a string array key path, but it also can contain * filter queries (they work with the queric library). * You can filter by value ($value or property value) by key ($key or property key) or * select all keys with {} (For better readability use the constant $all). * In the case of insertions, most times, the selector should end with * a new key instead of a query. * @param value * @param ifContains * @param potentialInsert */ update(selector: DbSelector, value: any, { if: ifOption, potentialInsert }?: IfOption & PotentialInsertOption): DbTransaction; /** * Delete a value in the Databox. * The function is part of the performance transaction API. * In most cases, it is highly recommended to use the type-safe and more readable content API. * Delete behavior: * 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. * Head (with selector [] or '') -> Deletes the complete structure. * 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 selector * The selector describes which key-value pairs should be * deleted updated or where a value should be inserted. * It can be a string array key path, but it also can contain * filter queries (they work with the queric library). * You can filter by value ($value or property value) by key ($key or property key) or * select all keys with {} (For better readability use the constant $all). * In the case of insertions, most times, the selector should end with * a new key instead of a query. * @param ifContains */ delete(selector: DbSelector, { if: ifOption }?: IfOption): DbTransaction; /** * @description * Returns if the sequence has uncommitted changes. */ hasUncommittedChanges(): boolean; /** * @description * Apply all changes on the Databox. * Don't forget to update your database before updating the databox. */ commit(options?: TimestampOption & ComplexTypesOption & InfoOption): void; } export {};