import { OnModuleInit } from '@nestjs/common'; import { AssignCollectionsToChannelInput, ConfigurableOperationDefinition, CreateCollectionInput, DeletionResponse, LanguageCode, MoveCollectionInput, PreviewCollectionVariantsInput, RemoveCollectionsFromChannelInput, UpdateCollectionInput } from '@vendure/common/lib/generated-types'; import { ID, PaginatedList } from '@vendure/common/lib/shared-types'; import { RequestContext } from '../../api/common/request-context'; import { RelationPaths } from '../../api/decorators/relations.decorator'; import { ListQueryOptions } from '../../common/types/common-types'; import { Translated } from '../../common/types/locale-types'; import { ConfigService } from '../../config/config.service'; import { TransactionalConnection } from '../../connection/transactional-connection'; import { Collection } from '../../entity/collection/collection.entity'; import { ProductVariant } from '../../entity/product-variant/product-variant.entity'; import { EventBus } from '../../event-bus/event-bus'; import { JobQueueService } from '../../job-queue/job-queue.service'; import { ConfigArgService } from '../helpers/config-arg/config-arg.service'; import { CustomFieldRelationService } from '../helpers/custom-field-relation/custom-field-relation.service'; import { ListQueryBuilder } from '../helpers/list-query-builder/list-query-builder'; import { RequestContextService } from '../helpers/request-context/request-context.service'; import { SlugValidator } from '../helpers/slug-validator/slug-validator'; import { TranslatableSaver } from '../helpers/translatable-saver/translatable-saver'; import { TranslatorService } from '../helpers/translator/translator.service'; import { AssetService } from './asset.service'; import { ChannelService } from './channel.service'; import { RoleService } from './role.service'; export type ApplyCollectionFiltersJobData = { ctx: { channelToken: string; languageCode: LanguageCode; }; collectionIds: ID[]; applyToChangedVariantsOnly?: boolean; }; /** * @description * Contains methods relating to {@link Collection} entities. * * @docsCategory services */ export declare class CollectionService implements OnModuleInit { private connection; private channelService; private assetService; private listQueryBuilder; private translatableSaver; private eventBus; private jobQueueService; private configService; private slugValidator; private configArgService; private customFieldRelationService; private translator; private roleService; private requestContextService; private rootCollection; private applyFiltersQueue; private applyAllFiltersOnProductUpdates; constructor(connection: TransactionalConnection, channelService: ChannelService, assetService: AssetService, listQueryBuilder: ListQueryBuilder, translatableSaver: TranslatableSaver, eventBus: EventBus, jobQueueService: JobQueueService, configService: ConfigService, slugValidator: SlugValidator, configArgService: ConfigArgService, customFieldRelationService: CustomFieldRelationService, translator: TranslatorService, roleService: RoleService, requestContextService: RequestContextService); /** * @internal */ onModuleInit(): Promise; findAll(ctx: RequestContext, options?: ListQueryOptions & { topLevelOnly?: boolean; }, relations?: RelationPaths): Promise>>; findOne(ctx: RequestContext, collectionId: ID, relations?: RelationPaths): Promise | undefined>; findByIds(ctx: RequestContext, ids: ID[], relations?: RelationPaths): Promise>>; findOneBySlug(ctx: RequestContext, slug: string, relations?: RelationPaths): Promise | undefined>; /** * @description * Returns all configured CollectionFilters, as specified by the {@link CatalogOptions}. */ getAvailableFilters(ctx: RequestContext): ConfigurableOperationDefinition[]; getParent(ctx: RequestContext, collectionId: ID): Promise; /** * @description * Returns all child Collections of the Collection with the given id. */ getChildren(ctx: RequestContext, collectionId: ID): Promise; /** * @description * Returns a Map of collection IDs to their product variant counts. * This performs a single bulk query to get counts for all provided collection IDs, * avoiding N+1 query issues when resolving productVariantCount on multiple collections. */ getProductVariantCounts(ctx: RequestContext, collectionIds: ID[]): Promise>; /** * @description * Returns an array of name/id pairs representing all ancestor Collections up * to the Root Collection. */ getBreadcrumbs(ctx: RequestContext, collection: Collection): Promise>; /** * @description * Returns all Collections which are associated with the given Product ID. */ getCollectionsByProductId(ctx: RequestContext, productId: ID, publicOnly: boolean): Promise>>; /** * @description * Returns the descendants of a Collection as a flat array. The depth of the traversal can be limited * with the maxDepth argument. So to get only the immediate children, set maxDepth = 1. */ getDescendants(ctx: RequestContext, rootId: ID, maxDepth?: number): Promise>>; /** * @description * Gets the ancestors of a given collection. Note that since ProductCategories are implemented as an adjacency list, this method * will produce more queries the deeper the collection is in the tree. */ getAncestors(collectionId: ID): Promise; getAncestors(collectionId: ID, ctx: RequestContext): Promise>>; previewCollectionVariants(ctx: RequestContext, input: PreviewCollectionVariantsInput, options?: ListQueryOptions, relations?: RelationPaths): Promise>; create(ctx: RequestContext, input: CreateCollectionInput): Promise>; update(ctx: RequestContext, input: UpdateCollectionInput): Promise>; delete(ctx: RequestContext, id: ID): Promise; /** * @description * Moves a Collection by specifying the parent Collection ID, and an index representing the order amongst * its siblings. */ move(ctx: RequestContext, input: MoveCollectionInput): Promise>; /** * @description * By default, whenever product data is updated (as determined by subscribing to the * {@link ProductEvent} and {@link ProductVariantEvent} events), the CollectionFilters are re-applied * to all Collections. * * In certain scenarios, such as when a large number of products are updated at once due to * bulk data import, this can be inefficient. In such cases, you can disable this behaviour * for the duration of the import process by calling this method with `false`, and then * re-enable it by calling with `true`. * * Afterward, you can call the `triggerApplyFiltersJob` method to manually re-apply the filters. * * @since 3.1.3 */ setApplyAllFiltersOnProductUpdates(applyAllFiltersOnProductUpdates: boolean): void; /** * @description * Triggers the creation of an `apply-collection-filters` job which will cause the contents * of the specified collections to be re-evaluated against their filters. * * If no `collectionIds` option is passed, then all collections will be re-evaluated. * * @since 3.1.3 */ triggerApplyFiltersJob(ctx: RequestContext, options?: { collectionIds?: ID[]; applyToChangedVariantsOnly?: boolean; }): Promise; private getCollectionFiltersFromInput; private chunkArray; /** * Applies the CollectionFilters and returns the IDs of ProductVariants that need to be added or removed. */ private applyCollectionFiltersInternal; /** * Gets all filters of ancestor Collections while respecting the `inheritFilters` setting of each. * As soon as `inheritFilters === false` is encountered, the collected filters are returned. */ private getAncestorFilters; /** * Returns the IDs of the Collection's ProductVariants. */ getCollectionProductVariantIds(collection: Collection, ctx?: RequestContext): Promise; /** * Returns the next position value in the given parent collection. */ private getNextPositionInParent; private getParentCollection; private getRootCollection; /** * @description * Assigns Collections to the specified Channel */ assignCollectionsToChannel(ctx: RequestContext, input: AssignCollectionsToChannelInput): Promise>>; /** * @description * Remove Collections from the specified Channel */ removeCollectionsFromChannel(ctx: RequestContext, input: RemoveCollectionsFromChannelInput): Promise>>; }