@webda/core
Version:
Expose API with Lambda
150 lines (149 loc) • 3.71 kB
TypeScript
import { CoreModel } from "../models/coremodel.js";
import { Service, ServiceParameters } from "../services/service.js";
import { Store } from "./store.js";
export type MapUpdates = "created" | "deleted" | {
[key: string]: any;
};
export interface Mapper {
uuid: string;
[key: string]: any;
}
/**
* Mapper configuration
*/
export declare class MapperParameters extends ServiceParameters {
/**
* Field to duplicate
*/
fields: string[];
/**
* Source service
*/
source: string;
/**
* Target store
*/
target: string;
/**
* Async
*
* @default false
*/
async: boolean;
/**
* Attribute to use for link
*
* Depending on the type
* - string[]: will consider each string as id
* - string: will be consider as id
* - Object: each keys will be consider as id
*/
attribute: string;
/**
* The object will contain a Mapper
*/
targetAttribute: string;
/**
* Delete source if target object is deleted
*/
cascade: boolean;
constructor(params: any);
}
/**
* Map object to another object
* @WebdaModda Mapper
*/
export default class MapperService<T extends MapperParameters = MapperParameters> extends Service<T> {
targetStore: Store<CoreModel & {
[key: string]: any[];
}>;
sourceService: Store;
/**
* @override
*/
loadParameters(params: any): MapperParameters;
/**
* @override
*/
resolve(): this;
/**
* Get index of the mapper for an object
* @param map
* @param uuid
* @returns
*/
getMapper(map: any[], uuid: string): number;
/**
* Create an object mapper
*
* @param map map to create mapper for
* @param object for the mapper to represent
* @param updates to the object being made
* @returns mapper object and found = true if updates will impact the mapper
*/
createMapper(object: CoreModel, updates: any): [mapper: Mapper, found: boolean];
/**
* Update a mapper after source object was modified
*
* @param source
* @param target
* @param mapper
* @returns
*/
_handleUpdatedMap(source: CoreModel, target: CoreModel, updates: any): Promise<Date>;
/**
* Update a mapper after source object was modified without change in target
*
* @param source
* @param target
* @param mapper
* @returns
*/
_handleUpdatedMapMapper(source: CoreModel, target: CoreModel, mapper: Mapper): Promise<Date>;
/**
* Remove the mapper for a deleted object
*
* @param source
* @param target
* @returns
*/
_handleDeletedMap(source: CoreModel, target: CoreModel): Promise<Date>;
/**
* Add the mapper for a newly created object
*
* @param source
* @param target
* @returns
*/
_handleCreatedMap(source: CoreModel, target: CoreModel): Promise<Date>;
/**
* Return true if property belongs to the mapped properties
*
* @param property
* @returns
*/
isMapped(property: string): boolean;
/**
* Handle the map from a partial update
*
* @param uid
* @param updateDate
* @param prop
*/
_handleMapFromPartial(uid: string, updateDate: Date, property?: string | string[]): Promise<void>;
/**
* Manage one mapping update
*
* @param store
* @param object
* @param map
* @param updates
* @returns
*/
handleMap(object: CoreModel, updates: MapUpdates): Promise<void>;
/**
* Recompute the whole mappers
*/
recompute(): Promise<void>;
}
export { MapperService };