import { TDMModel, TDMCollection, TargetMetadata, MapperFactory } from '@tdm/core/tdm'; import { ActionMetadata } from '../metadata'; import { IdentityValueType } from '../fw'; /** * */ export interface ExecuteParams { /** * Data object supplied by the creator of this execution. * This is a placeholder for an object that the creator of the execution can pass. * * For example, in: * ```ts * DAO.of(SomeAdapter, SomeTarget, { a: 'b' }).findById(12, 'abc'); * ``` * * `factoryArgs` will be { a: 'b' } * */ factoryArgs?: T; /** * Arguments used when calling the action. * These are the arguments that the user passed in runtime. * * For example, in: * ```ts * DAO.of(SomeAdapter, SomeTarget).findById(12, 'abc'); * ``` * * `args` will be [12, 'abc'] */ args?: any[]; } export declare class ExecuteContext { private readonly meta; readonly action: T; /** * Optional data, usually an action pre hook will use this to pass information to the adapter. */ data?: any; readonly targetMeta: TargetMetadata; /** * The instance representing this execution context. * * The instance not set, to set the instance use the setInstance() method. * Note that calling any method in ExecuteContext that requires the instance (setIdentity, deserialize, * serialize etc...) will automatically init a new instance. * * This also mean that the instance can be set from an action's "pre" handler. * An instance set must be an instance of the target or an instance of ActiveRecordCollection. * (i.e. return true from the call to ExecuteContext#instanceOf) */ readonly instance: any; private readonly safeInstance; private _instance; private mapper; constructor(meta: TargetMetadata, action: T, mapper?: MapperFactory); /** * The the instance for this execution context. * If no value supplied the instance set is a new instance or a new TDMCollection (based on the action) * @param value */ setInstance(value?: TDMModel | TDMCollection): void; /** * Returns true if an object is an instance of the target type of this execution context. * The target type is ActionRecordCollection when the action of this execution context * is true (ActionMetadata#isCollection) otherwise it is the target. * @param obj */ instanceOf(obj: any): boolean; getIdentity(): IdentityValueType; setIdentity(identity: IdentityValueType): void; /** * Serialize the instance in this execution context. */ serialize(): any; /** * Deserialize an object into the instance of the current execution context. * If an instance does not exist, it will be created on the fly. * @param data */ deserialize(data: any): void; /** * Returns a context-free copy of the current execution context. * The returned execution context does not contain the instance and/or data that existed in the source execution * context. */ clone(instance?: TDMModel | TDMCollection): ExecuteContext; }