/** Functions retrival, querying, and conversion of items from a local collection to/from a server collection * @since 2016-3-11 */ interface DtoFuncs { /** an optional function that copies a model, if none is provided, implementations should fall back on a default clone function */ copyFunc: (obj: E) => E; /** Convert a server data model to a client data model */ toLocalObject?: ((item: S) => E) | null; /** Convert a client data model to a server data model */ toSvcObject?: ((item: E) => S) | null; } /** A DataCollection containing syncable DTOs * @template E the type of data stored in this collection * @template K the primary keys/required fields, this is a sub-set of required fields from type 'E' * @template S the server data type stored in this collection */ interface DtoCollection extends DataCollection { /** Get data model helper functions associated with this collection/data model */ getDataModelFuncs(): DtoFuncs; } /** Represents meta-data about the items in a collection * @since 2015-12-15 */ interface DataCollectionModel { /** all the top level property names of the model */ fieldNames: (keyof E & string)[]; /** the names of all the properties which together uniquely represent each model instance */ primaryKeys: (keyof E & string)[]; /** the names of the properties which are auto generated (i.e. auto-increment ID keys) */ autoGeneratedKeys: (keyof E & string)[]; } /** ModelDefinitions - defines a set of data model meta-definitions */ interface ModelDefinitions { /** model names in the order they should be read/generated */ modelNames: string[]; /** Add a data model to this set of definitions, the data model consists of two parts: * - A model (containing the properties) * - A set of functions for working with that model (functions for copying, converting to/from service DTOs, etc.) */ addModel(modelName: string, model: DtoModel, modelFuncs?: DtoFuncs): { modelDef: DataCollectionModel, modelFuncs: DtoFuncs }; getPrimaryKeys(modelName: string): string[]; getAutoGeneratedKeys(modelName: string): string[]; getFields(modelName: string): string[]; getModel(modelName: string): DataCollectionModel; getCopyFunc(modelName: string): (obj: any) => any; /** May return null if the model has no associated functions */ getDataModelFuncs(modelName: string): DtoFuncs; } /** ModelKeys - helper for ModelDefinitions * For managing the primary and auto-generated keys from data models */ interface ModelKeys { /** add missing IDs that should be auto-generated * @param autoGenKeys in the format { name: "...", largestKey: 45678 } */ addGeneratedIds(autoGenKeys: { name: string; largestKey: number }[], doc: any): void; /** track auto-generated IDs * @param autoGenKeys in the format { name: "...", largestKey: 45678 } */ trackGeneratedIds(autoGenKeys: { name: string; largestKey: number }[], doc: any): void; /** Given a query object, check its validity based on these constraints */ validateQuery(collectionName: string, query: any, obj: any): any; }