import * as tslib_1 from "tslib";
/**
 * Repository is supposed to work with your entity objects. Find entities, insert, update, delete, etc.
 */
export function createLiteralRepository(_a) {
    var manager = _a.manager, metadata = _a.metadata, queryRunner = _a.queryRunner;
    return {
        manager: manager,
        metadata: metadata,
        queryRunner: queryRunner,
        /**
         * Creates a new query builder that lscan be used to build a sql query.
         */
        createQueryBuilder: function (alias, queryRunner) {
            return this.manager.createQueryBuilder(this.metadata.target, alias || this.metadata.targetName, queryRunner || this.queryRunner);
        },
        /**
         * Returns object that is managed by this repository.
         * If this repository manages entity from schema,
         * then it returns a name of that schema instead.
         */
        get target() {
            return this.metadata.target;
        },
        /**
         * Checks if entity has an id.
         * If entity composite compose ids, it will check them all.
         */
        hasId: function (entity) {
            return this.manager.hasId(this.metadata.target, entity);
        },
        /**
         * Gets entity mixed id.
         */
        getId: function (entity) {
            return this.manager.getId(this.metadata.target, entity);
        },
        /**
         * Creates a new entity instance or instances.
         * Can copy properties from the given object into new entities.
         */
        create: function (plainEntityLikeOrPlainEntityLikes) {
            return this.manager.create(this.metadata.target, plainEntityLikeOrPlainEntityLikes);
        },
        /**
         * Merges multiple entities (or entity-like objects) into a given entity.
         */
        merge: function (mergeIntoEntity) {
            var entityLikes = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                entityLikes[_i - 1] = arguments[_i];
            }
            var _a;
            return (_a = this.manager).merge.apply(_a, tslib_1.__spread([this.metadata.target, mergeIntoEntity], entityLikes));
        },
        /**
         * Creates a new entity from the given plan javascript object. If entity already exist in the database, then
         * it loads it (and everything related to it), replaces all values with the new ones from the given object
         * and returns this new entity. This new entity is actually a loaded from the db entity with all properties
         * replaced from the new object.
         *
         * Note that given entity-like object must have an entity id / primary key to find entity by.
         * Returns undefined if entity with given id was not found.
         */
        preload: function (entityLike) {
            return this.manager.preload(this.metadata.target, entityLike);
        },
        /**
         * Saves one or many given entities.
         */
        save: function (entityOrEntities, options) {
            return this.manager.save(this.metadata.target, entityOrEntities, options);
        },
        /**
         * Removes one or many given entities.
         */
        remove: function (entityOrEntities, options) {
            return this.manager.remove(this.metadata.target, entityOrEntities, options);
        },
        /**
         * Inserts a given entity into the database.
         * Unlike save method executes a primitive operation without cascades, relations and other operations included.
         * Executes fast and efficient INSERT query.
         * Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.
         */
        insert: function (entity) {
            return this.manager.insert(this.metadata.target, entity);
        },
        /**
         * Updates entity partially. Entity can be found by a given conditions.
         * Unlike save method executes a primitive operation without cascades, relations and other operations included.
         * Executes fast and efficient UPDATE query.
         * Does not check if entity exist in the database.
         */
        update: function (criteria, partialEntity) {
            return this.manager.update(this.metadata.target, criteria, partialEntity);
        },
        /**
         * Deletes entities by a given criteria.
         * Unlike save method executes a primitive operation without cascades, relations and other operations included.
         * Executes fast and efficient DELETE query.
         * Does not check if entity exist in the database.
         */
        delete: function (criteria) {
            return this.manager.delete(this.metadata.target, criteria);
        },
        /**
         * Counts entities that match given find options or conditions.
         */
        count: function (optionsOrConditions) {
            return this.manager.count(this.metadata.target, optionsOrConditions);
        },
        /**
         * Finds entities that match given find options or conditions.
         */
        find: function (optionsOrConditions) {
            return this.manager.find(this.metadata.target, optionsOrConditions);
        },
        /**
         * Finds entities that match given find options or conditions.
         * Also counts all entities that match given conditions,
         * but ignores pagination settings (from and take options).
         */
        findAndCount: function (optionsOrConditions) {
            return this.manager.findAndCount(this.metadata.target, optionsOrConditions);
        },
        /**
         * Finds entities by ids.
         * Optionally find options can be applied.
         */
        findByIds: function (ids, optionsOrConditions) {
            return this.manager.findByIds(this.metadata.target, ids, optionsOrConditions);
        },
        /**
         * Finds first entity that matches given conditions.
         */
        findOne: function (optionsOrConditions, maybeOptions) {
            return this.manager.findOne(this.metadata.target, optionsOrConditions, maybeOptions);
        },
        /**
         * Finds first entity that matches given conditions.
         */
        findOneOrFail: function (optionsOrConditions, maybeOptions) {
            return this.manager.findOneOrFail(this.metadata.target, optionsOrConditions, maybeOptions);
        },
        /**
         * Finds entities that match given options and returns observable.
         * Whenever new data appears that matches given query observable emits new value.
         */
        observe: function (optionsOrConditions) {
            return this.manager.observe(this.metadata.target, optionsOrConditions);
        },
        /**
         * Finds entities and count that match given options and returns observable.
         * Whenever new data appears that matches given query observable emits new value.
         */
        observeManyAndCount: function (optionsOrConditions) {
            return this.manager.observeManyAndCount(this.metadata.target, optionsOrConditions);
        },
        /**
         * Finds entity that match given options and returns observable.
         * Whenever new data appears that matches given query observable emits new value.
         */
        observeOne: function (optionsOrConditions) {
            return this.manager.observeOne(this.metadata.target, optionsOrConditions);
        },
        /**
         * Gets the entities count match given options and returns observable.
         * Whenever new data appears that matches given query observable emits new value.
         */
        observeCount: function (optionsOrConditions) {
            return this.manager.observeCount(this.metadata.target, optionsOrConditions);
        },
        /**
         * Executes a raw SQL query and returns a raw database results.
         * Raw query execution is supported only by relational databases (MongoDB is not supported).
         */
        query: function (query, parameters) {
            return this.manager.query(query, parameters);
        },
        /**
         * Clears all the data from the given table/collection (truncates/drops it).
         *
         * Note: this method uses TRUNCATE and may not work as you expect in transactions on some platforms.
         * @see https://stackoverflow.com/a/5972738/925151
         */
        clear: function () {
            return this.manager.clear(this.metadata.target);
        },
        /**
         * Increments some column by provided value of the entities matched given conditions.
         */
        increment: function (conditions, propertyPath, value) {
            return this.manager.increment(this.metadata.target, conditions, propertyPath, value);
        },
        /**
         * Decrements some column by provided value of the entities matched given conditions.
         */
        decrement: function (conditions, propertyPath, value) {
            return this.manager.decrement(this.metadata.target, conditions, propertyPath, value);
        },
        /**
         * Extends repository with provided functions.
         */
        extend: function (factory) {
            return tslib_1.__assign({}, this, factory(this));
        }
    };
}

//# sourceMappingURL=LiteralRepository.js.map
