import Operation from '../Operation'; // EXTERNAL to ENTITIES_MANAGER export interface EntityDefinition { [propKey: string]: Required|ParentId|ParentIds|CreatedAt|UpdatedAt|Count|Sum|DuplicateChildren; }; export interface EntitiesDefinition { [entityType: string]: EntityDefinition }; export interface Options { fetchItemTimeout: number } export type ConditionFunc = (beforeItem: any, afterItem: any) => boolean; // IN STORE export interface EntityItemCommon { id: string, }; export interface Entity { byId: { [id: string]: EntityItemCommon }, allIds: Array, orderedList: { [orderBy: string]: Array }, queriedList: { [queryName: string]: Array } }; export interface Entities { [entityType: string]: Entity, }; // CONSTRAINTS export interface Constraints { unSettableOnAdd?: boolean, // add시에 값이 없어야 한다. unSettableOnUpdate?: boolean, // update시에 값이 없어야 한다. requiredOnAdd?: boolean, // add시에 값이 있어야 한다. notNull?: boolean, // update시에 null을 assign할 수 없다. }; // FOR COMMUNICATION BETWEEN 'EntitiesManager' & 'EntityManager' export interface ItemSelector { entityType: string, id: string }; export interface HandlerSetter { handlerHolder: 'SELF'|string, // entityType (compile시에 handler를 집어넣을 entityType) onAdd: Array, onUpdate: Array, onDelete: Array }; export interface EntityHandler { checkNeedUpdatingParents?: ( childOperation: Operation, beforeParentItemSelectors: ItemSelector[], afterParentItemSelectors: ItemSelector[] ) => boolean, updatingParentType: string | null, // entityType of parents operationModifier: ( selfOperation: Operation, beforeParentOperations: Array, afterParentOperations: Array ) => void }; export interface BakedEntityHandler { childItemSelector: ItemSelector, beforeParentItemSelectors: Array, afterParentItemSelectors: Array, operationModifier: ( selfOperation: Operation, beforeParentOperations: Array, afterParentOperations: Array ) => void }; // PROP VALUE export interface PropValueCommon { constraints: Constraints, }; // constraints only export interface Required extends PropValueCommon { type: 'REQUIRED', }; // relations only export interface ParentId extends PropValueCommon { type: 'PARENT_ID', parentEntityType: string, }; export interface ParentIds extends PropValueCommon { type: 'PARENT_IDS', parentEntityType: string, } // self handlers export interface CreatedAt extends PropValueCommon { type: 'CREATED_AT', }; export interface UpdatedAt extends PropValueCommon { type: 'UPDATED_AT', }; // child handlers export type AggregationCondition = [string, '==' | '!=' | '<' | '<=' | '>' | '>=', any] export interface Count extends PropValueCommon { type: 'COUNT', childEntityType: string, conditions: Array, }; export interface Sum extends PropValueCommon { type: 'SUM', childEntityType: string, childPropKey: string, conditions: Array, }; export interface DuplicateChildren extends PropValueCommon { type: 'DUPLICATE_CHILDREN', childEntityType: string, mapFunc: (entityItem:Object) => Object, limit: number, conditions: Array };