UNPKG

@statezero/core

Version:

The type-safe frontend client for StateZero - connect directly to your backend models with zero boilerplate

102 lines (101 loc) 3.31 kB
export const operationEvents: import("mitt").Emitter<Record<import("mitt").EventType, unknown>>; export namespace Status { let CREATED: string; let UPDATED: string; let CONFIRMED: string; let REJECTED: string; let CLEAR: string; let MUTATED: string; } export namespace Type { let CREATE: string; let BULK_CREATE: string; let UPDATE: string; let DELETE: string; let UPDATE_INSTANCE: string; let DELETE_INSTANCE: string; let GET_OR_CREATE: string; let UPDATE_OR_CREATE: string; let CHECKPOINT: string; let COUNT: string; let MIN: string; let MAX: string; let AVG: string; let SUM: string; let AGGREGATE: string; } export class Operation { constructor(data: any, restore?: boolean); operationId: any; type: any; status: any; queryset: any; args: any; timestamp: any; doNotPropagate: any; localOnly: any; /** * Setter for instances */ set instances(value: any); /** * Getter for instances that replaces any temporary PKs with real PKs */ get instances(): any; /** * Setter for frozenInstances */ set frozenInstances(value: any); /** * Getter for frozenInstances that replaces any temporary PKs with real PKs */ get frozenInstances(): any; /** * Get primary keys of all instances in this operation * Returns primary keys as simple values (not objects) */ get instancePks(): any; /** * Update this operation's status and emit an event * @param {string} status - New status ('confirmed', 'rejected', etc.) * @param {Array|Object|null} [instances=null] - New instances for the operation */ updateStatus(status: string, instances?: any[] | Object | null): void; /** * Updates this operation with new data and emits the appropriate event * @param {Object} newData - New data to update the operation with * @returns {Operation} - Returns this operation instance for chaining */ mutate(newData: Object): Operation; #private; } export const operationRegistry: OperationRegistry; declare class OperationRegistry { _operations: Map<any, any>; /** * Registers a pre-constructed Operation instance in the registry. * Ensures the operationId is unique within the registry. * Throws an Error if the operationId already exists. * * @param {Operation} operation - The fully instantiated Operation object to register. * @throws {Error} If the input is not a valid operation object or if an operation with the same operationId already exists. */ register(operation: Operation): void; /** * Retrieves an operation by its ID. * @param {string} operationId - The ID of the operation. * @returns {Operation | undefined} The operation instance or undefined if not found. */ get(operationId: string): Operation | undefined; /** * Checks if an operation with the given ID exists in the registry. * @param {string} operationId - The ID of the operation to check. * @returns {boolean} True if the operation exists, false otherwise. */ has(operationId: string): boolean; /** * Clears all operations from the registry. */ clear(): void; } export {};