UNPKG

chrono-forge

Version:

A comprehensive framework for building resilient Temporal workflows, advanced state management, and real-time streaming activities in TypeScript. Designed for a seamless developer experience with powerful abstractions, dynamic orchestration, and full cont

145 lines (144 loc) 7.06 kB
import type { EntitiesState, EntityState } from './entities'; import { EnhancedEntity } from '../store/SchemaManager'; /** * Action type for entity operations * @typedef {Object} EntityAction * @property {string} type - The action type * @property {EntitiesState} entities - The entities state * @property {EntityStrategy} [strategy] - The update strategy to apply */ export type EntityAction = { type: string; entities: EntitiesState; strategy?: EntityStrategy; }; /** * Strategy types for entity operations * @typedef {string} EntityStrategy * @property {'$replace'} $replace - Replace the entire entity * @property {'$set'} $set - Set specific properties * @property {'$merge'} $merge - Merge with existing properties * @property {'$unset'} $unset - Remove specific properties * @property {'$push'} $push - Add items to the end of an array * @property {'$unshift'} $unshift - Add items to the beginning of an array * @property {'$splice'} $splice - Remove/replace items in an array * @property {'$apply'} $apply - Apply a function to transform a value * @property {'$toggle'} $toggle - Toggle boolean values * @property {'$add'} $add - Add items to a collection * @property {'$remove'} $remove - Remove items from a collection */ export type EntityStrategy = '$replace' | '$set' | '$merge' | '$unset' | '$push' | '$unshift' | '$splice' | '$apply' | '$toggle' | '$add' | '$remove'; /** Action type for upserting multiple entities */ export declare const UPDATE_ENTITIES = "entities.upsertEntities"; /** Action type for partially updating entities */ export declare const UPDATE_ENTITIES_PARTIAL = "entities.partialUpdates"; /** Action type for deleting multiple entities */ export declare const DELETE_ENTITIES = "entities.deleteEntities"; /** Action type for setting the entire entities state */ export declare const SET_STATE = "entities.setState"; export declare const actionNames: { UPDATE_ENTITIES: string; UPDATE_ENTITIES_PARTIAL: string; DELETE_ENTITIES: string; SET_STATE: string; }; /** * Creates an action to update a single entity * @param {EntityState} entity - The entity to update * @param {string} entityName - The entity type/name * @returns {EntityAction} An action object for updating the entity */ export declare const updateEntity: (entity: EntityState, entityName: string) => EntityAction; /** * Creates an action to partially update an entity * @param {EntityState} entity - The entity to update * @param {string} entityName - The entity type/name * @param {EntityStrategy} [strategy='$merge'] - The update strategy to apply * @returns {EntityAction} An action object for partially updating the entity */ export declare const updateEntityPartial: (entity: EntityState, entityName: string, strategy?: EntityStrategy) => EntityAction; /** * Creates an action to update multiple entities * @param {EntityState[]} entities - Array of entities to update * @param {string} entityName - The entity type/name * @returns {EntityAction} An action object for updating multiple entities */ export declare const updateEntities: (entities: EntityState[], entityName: string) => EntityAction; /** * Creates an action to partially update multiple entities * @param {EntityState[]} entities - Array of entities to update * @param {string} entityName - The entity type/name * @param {EntityStrategy} [strategy='$merge'] - The update strategy to apply * @returns {EntityAction} An action object for partially updating multiple entities */ export declare const updateEntitiesPartial: (entities: EntityState[], entityName: string, strategy?: EntityStrategy) => EntityAction; /** * Creates an action to delete a single entity * @param {EntityState} entity - The entity to delete * @param {string} entityName - The entity type/name * @returns {EntityAction} An action object for deleting the entity */ export declare const deleteEntity: (entity: EntityState, entityName: string) => EntityAction; /** * Creates an action to delete multiple entities * @param {any[]} entities - Array of entities to delete * @param {string} entityName - The entity type/name * @returns {EntityAction} An action object for deleting multiple entities */ export declare const deleteEntities: (entities: any[], entityName: string) => EntityAction; /** * Creates an action to update multiple normalized entities * @param {EntitiesState} entities - The normalized entities to update * @param {EntityStrategy} [strategy='$merge'] - The update strategy to apply * @returns {EntityAction} An action object for updating normalized entities */ export declare const updateNormalizedEntities: (entities: EntitiesState, strategy?: EntityStrategy) => EntityAction; /** * Creates an action to delete multiple normalized entities * @param {EntitiesState} entities - The normalized entities to delete * @returns {EntityAction} An action object for deleting normalized entities */ export declare const deleteNormalizedEntities: (entities: EntitiesState) => EntityAction; /** * Creates an action to clear all entities * @param {EntitiesState} [entities={...defaultState}] - Optional entities state to set after clearing * @returns {EntityAction} An action object for clearing all entities */ export declare const clearEntities: (entities?: { [x: string]: Record<string, EntityState>; }) => EntityAction; /** * Creates an action to set the entire entities state * @param {EntitiesState} [entities={}] - The entities state to set * @returns {EntityAction} An action object for setting the entire entities state */ export declare const setState: (entities?: EntitiesState) => EntityAction; /** * Gets a schema by entity name from the SchemaManager * @param {string} entityName - The entity type/name * @returns {EnhancedEntity} The schema for the entity * @throws {Error} If the schema is not found */ export declare function getSchema(entityName: string): EnhancedEntity; declare const _default: { actionNames: { UPDATE_ENTITIES: string; UPDATE_ENTITIES_PARTIAL: string; DELETE_ENTITIES: string; SET_STATE: string; }; getSchema: typeof getSchema; setState: (entities?: EntitiesState) => EntityAction; updateEntity: (entity: EntityState, entityName: string) => EntityAction; updateEntities: (entities: EntityState[], entityName: string) => EntityAction; deleteEntity: (entity: EntityState, entityName: string) => EntityAction; deleteEntities: (entities: any[], entityName: string) => EntityAction; clearEntities: (entities?: { [x: string]: Record<string, EntityState>; }) => EntityAction; updateEntityPartial: (entity: EntityState, entityName: string, strategy?: EntityStrategy) => EntityAction; updateEntitiesPartial: (entities: EntityState[], entityName: string, strategy?: EntityStrategy) => EntityAction; updateNormalizedEntities: (entities: EntitiesState, strategy?: EntityStrategy) => EntityAction; deleteNormalizedEntities: (entities: EntitiesState) => EntityAction; }; export default _default;