UNPKG

@danielbiegler/vendure-plugin-blurry-image-lazy-loading

Version:

Generates image hashes for displaying blurry previews when loading images on the frontend.

82 lines (81 loc) 4.36 kB
import { OnModuleInit } from "@nestjs/common"; import { Asset, AssetService, CollectionService, ConfigService, EventBus, JobQueueService, ProductService, ProductVariantService, RelationPaths, RequestContext, SerializedRequestContext, TransactionalConnection } from "@vendure/core"; import { PluginPreviewImageHashCreateInput, PluginPreviewImageHashCreateResult, PluginPreviewImageHashForAllAssetsInput, PluginPreviewImageHashForCollectionInput, PluginPreviewImageHashForProductInput, PluginPreviewImageHashResult } from "../generated-admin-types"; import { PluginPreviewImageHashOptions } from "../types"; /** * The PreviewImageHashService provides methods for managing the creation of image hashes. * * @category Services */ export declare class PreviewImageHashService implements OnModuleInit { private assetService; private collectionService; private productService; private productVariantService; private configService; private eventBus; private jobQueueService; private connection; private options; /** @internal */ constructor(assetService: AssetService, collectionService: CollectionService, productService: ProductService, productVariantService: ProductVariantService, configService: ConfigService, eventBus: EventBus, jobQueueService: JobQueueService, connection: TransactionalConnection, options: PluginPreviewImageHashOptions); private jobQueue; /** * Adds the hashing to the dedicated job queue */ addToJobQueue(ctx: RequestContext, input: PluginPreviewImageHashCreateInput): Promise<import("@vendure/core/dist/job-queue/subscribable-job").SubscribableJob<{ ctx: SerializedRequestContext; input: PluginPreviewImageHashCreateInput; }>>; /** * Convenience method to make the processing code more concise */ private result; /** * Bootstrapping the plugin */ onModuleInit(): Promise<void>; /** * Depending on `input.runSynchronously` will either generate the hash and persist it to the asset, * or will add this task to the dedicated job queue. * * If being run synchronously will return the asset so you can query the custom field directly */ create(ctx: RequestContext, input: PluginPreviewImageHashCreateInput, relations?: RelationPaths<Asset>): Promise<PluginPreviewImageHashCreateResult>; /** * Enqueues hashing jobs for each asset inside this product. * Includes the product itself and all of its variants. * * Deduplicates the asset IDs. */ createForProduct(ctx: RequestContext, input: PluginPreviewImageHashForProductInput): Promise<PluginPreviewImageHashResult>; /** * Helper for determining whether or not we should skip hash generation for a given asset. * Useful for keeping the logging DRY. * * @param shouldRegenerate Whether or not you want to regenerate existing hashes * @param asset The asset for which you would like to check * @returns Whether or not you should skip this asset */ private shouldSkipGeneratingHash; /** * Enqueues hashing jobs for each asset inside a collection. This includes the collection itself, * the contained products and all of their variants. * * Due to how large collections can become, you may want to disable the deduplication of asset ids. * * If deduplication is enabled, jobs will be created only after gathering all assets first. * If disabled, jobs will be created as the assets are being read. * * No deduplication may result in assets being hashed multiple times, but the tradeoff is not having * to hold potentially millions of records in memory and just letting the worker take care of them eventually. */ createForCollection(ctx: RequestContext, input: PluginPreviewImageHashForCollectionInput): Promise<PluginPreviewImageHashResult>; /** * Create preview image hashes for all assets. * * This mutation should be handled with extra care since an installation may hold hundreds of thousands of images. * This is mainly useful as a one-time-use utility to initialize all of the assets with hashes after installing the plugin. */ createForAllAssets(ctx: RequestContext, input?: PluginPreviewImageHashForAllAssetsInput): Promise<PluginPreviewImageHashResult>; }