UNPKG

@typeheim/orm-on-fire

Version:
44 lines 2.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Factory = void 0; const Collection_1 = require("./Collection"); const EntityPersister_1 = require("./EntityPersister"); const QueryFactory_1 = require("../Persistence/QueryFactory"); const EntityManager_1 = require("../Persistence/EntityManager"); const CollectionReference_1 = require("../Persistence/CollectionReference"); const NullCollection_1 = require("./NullCollection"); class Factory { constructor(connection, metadata) { this.connection = connection; this.metadata = metadata; } createNullCollection() { return new NullCollection_1.NullCollection(); } createGroupFor(entity) { const metadata = this.metadata.entity(entity).get(); // @ts-ignore return this.create(entity, this.connection.collectionGroupRef(metadata.collection), metadata); } createFor(entity) { const metadata = this.metadata.entity(entity).get(); return this.create(entity, this.connection.collectionRef(metadata.collection), metadata); } createWithRef(entity, docReference) { const metadata = this.metadata.entity(entity).get(); let collectionRef = new CollectionReference_1.CollectionReference(this.connection, `${docReference.path}/${metadata.collection}`); return this.create(entity, collectionRef, metadata); } createFromBasePath(entity, path) { const metadata = this.metadata.entity(entity).get(); let collectionRef = new CollectionReference_1.CollectionReference(this.connection, `${path}/${metadata.collection}`); return this.create(entity, collectionRef, metadata); } create(entity, collectionRef, metadata) { let entityManager = new EntityManager_1.EntityManager(metadata, entity, collectionRef); let queryFactory = new QueryFactory_1.QueryFactory(collectionRef, entityManager, metadata); return new Collection_1.Collection(queryFactory, new EntityPersister_1.EntityPersister(entityManager)); } } exports.Factory = Factory; //# sourceMappingURL=CollectionFactory.js.map