Explorar el Código

chore(core): Remove deprecated ORM utils

Michael Bromley hace 4 años
padre
commit
bd797f3b75

+ 0 - 66
packages/core/src/service/helpers/utils/channel-aware-orm-utils.ts

@@ -1,66 +0,0 @@
-import { ID, Type } from '@vendure/common/lib/shared-types';
-import { FindManyOptions, FindOptionsUtils } from 'typeorm';
-
-import { ChannelAware } from '../../../common/types/common-types';
-import { VendureEntity } from '../../../entity';
-import { TransactionalConnection } from '../../transaction/transactional-connection';
-
-/**
- * Like the TypeOrm `Repository.findByIds()` method, but limits the results to
- * the given Channel.
- *
- * @deprecated
- */
-export function findByIdsInChannel<T extends ChannelAware | VendureEntity>(
-    connection: TransactionalConnection,
-    entity: Type<T>,
-    ids: ID[],
-    channelId: ID,
-    findOptions?: FindManyOptions<T>,
-    eager = true,
-) {
-    // the syntax described in https://github.com/typeorm/typeorm/issues/1239#issuecomment-366955628
-    // breaks if the array is empty
-    if (ids.length === 0) {
-        return Promise.resolve([]);
-    }
-
-    const qb = connection.getRepository(entity).createQueryBuilder('product');
-    FindOptionsUtils.applyFindManyOptionsOrConditionsToQueryBuilder(qb, findOptions);
-    if (eager) {
-        // tslint:disable-next-line:no-non-null-assertion
-        FindOptionsUtils.joinEagerRelations(qb, qb.alias, qb.expressionMap.mainAlias!.metadata);
-    }
-    return qb
-        .leftJoin('product.channels', 'channel')
-        .andWhere('product.id IN (:...ids)', { ids })
-        .andWhere('channel.id = :channelId', { channelId })
-        .getMany();
-}
-
-/**
- * Like the TypeOrm `Repository.findOne()` method, but limits the results to
- * the given Channel.
- *
- * @deprecated Use {@link TransactionalConnection}.findOneInChannel() instead.
- */
-export function findOneInChannel<T extends ChannelAware | VendureEntity>(
-    connection: TransactionalConnection,
-    entity: Type<T>,
-    id: ID,
-    channelId: ID,
-    findOptions?: FindManyOptions<T>,
-    eager = true,
-) {
-    const qb = connection.getRepository(entity).createQueryBuilder('product');
-    FindOptionsUtils.applyFindManyOptionsOrConditionsToQueryBuilder(qb, findOptions);
-    if (eager) {
-        // tslint:disable-next-line:no-non-null-assertion
-        FindOptionsUtils.joinEagerRelations(qb, qb.alias, qb.expressionMap.mainAlias!.metadata);
-    }
-    return qb
-        .leftJoin('product.channels', 'channel')
-        .andWhere('product.id = :id', { id })
-        .andWhere('channel.id = :channelId', { channelId })
-        .getOne();
-}

+ 0 - 61
packages/core/src/service/helpers/utils/get-entity-or-throw.ts

@@ -1,61 +0,0 @@
-import { ID, Type } from '@vendure/common/lib/shared-types';
-import { FindOneOptions } from 'typeorm';
-
-import { EntityNotFoundError } from '../../../common/error/errors';
-import { ChannelAware, SoftDeletable } from '../../../common/types/common-types';
-import { VendureEntity } from '../../../entity/base/base.entity';
-import { TransactionalConnection } from '../../transaction/transactional-connection';
-
-import { findOneInChannel } from './channel-aware-orm-utils';
-
-/**
- * Attempts to find an entity of the given type and id, and throws an error if not found.
- * If the entity is a ChannelAware type, then the `channelId` must be supplied or else
- * the function will "fail" by resolving to the `never` type.
- *
- * @deprecated Use {@link TransactionalConnection}.getEntityOrThrow() instead.
- */
-export async function getEntityOrThrow<T extends VendureEntity>(
-    connection: TransactionalConnection,
-    entityType: Type<T>,
-    id: ID,
-    findOptions?: FindOneOptions<T>,
-): Promise<T extends ChannelAware ? never : T>;
-export async function getEntityOrThrow<T extends VendureEntity | ChannelAware>(
-    connection: TransactionalConnection,
-    entityType: Type<T>,
-    id: ID,
-    channelId: ID,
-    findOptions?: FindOneOptions<T>,
-    eager?: boolean,
-): Promise<T>;
-export async function getEntityOrThrow<T extends VendureEntity>(
-    connection: TransactionalConnection,
-    entityType: Type<T>,
-    id: ID,
-    findOptionsOrChannelId?: FindOneOptions<T> | ID,
-    maybeFindOptions?: FindOneOptions<T>,
-    eager?: boolean,
-): Promise<T> {
-    let entity: T | undefined;
-    if (isId(findOptionsOrChannelId)) {
-        entity = await findOneInChannel(
-            connection,
-            entityType,
-            id,
-            findOptionsOrChannelId,
-            maybeFindOptions,
-            eager,
-        );
-    } else {
-        entity = await connection.getRepository(entityType).findOne(id, findOptionsOrChannelId);
-    }
-    if (!entity || (entity.hasOwnProperty('deletedAt') && (entity as T & SoftDeletable).deletedAt !== null)) {
-        throw new EntityNotFoundError(entityType.name as any, id);
-    }
-    return entity;
-}
-
-function isId(value: unknown): value is ID {
-    return typeof value === 'string' || typeof value === 'number';
-}

+ 0 - 2
packages/core/src/service/index.ts

@@ -1,7 +1,5 @@
 export * from './helpers/utils/translate-entity';
 export * from './helpers/utils/patch-entity';
-export * from './helpers/utils/channel-aware-orm-utils';
-export * from './helpers/utils/get-entity-or-throw';
 export * from './helpers/active-order/active-order.service';
 export * from './helpers/list-query-builder/list-query-builder';
 export * from './helpers/locale-string-hydrator/locale-string-hydrator';