|
| 1 | +"use strict"; |
| 2 | +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { |
| 3 | + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; |
| 4 | + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); |
| 5 | + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; |
| 6 | + return c > 3 && r && Object.defineProperty(target, key, r), r; |
| 7 | +}; |
| 8 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 9 | +const decorators_1 = require("../decorators"); |
| 10 | +const cache_constants_1 = require("./cache.constants"); |
| 11 | +const cache_providers_1 = require("./cache.providers"); |
| 12 | +let CacheModule = CacheModule_1 = class CacheModule { |
| 13 | + static register(options = {}) { |
| 14 | + return { |
| 15 | + module: CacheModule_1, |
| 16 | + providers: [{ provide: cache_constants_1.CACHE_MODULE_OPTIONS, useValue: options }], |
| 17 | + }; |
| 18 | + } |
| 19 | + static registerAsync(options) { |
| 20 | + return { |
| 21 | + module: CacheModule_1, |
| 22 | + imports: options.imports, |
| 23 | + providers: this.createAsyncProviders(options), |
| 24 | + }; |
| 25 | + } |
| 26 | + static createAsyncProviders(options) { |
| 27 | + if (options.useExisting || options.useFactory) { |
| 28 | + return [this.createAsyncOptionsProvider(options)]; |
| 29 | + } |
| 30 | + return [ |
| 31 | + this.createAsyncOptionsProvider(options), |
| 32 | + { |
| 33 | + provide: options.useClass, |
| 34 | + useClass: options.useClass, |
| 35 | + }, |
| 36 | + ]; |
| 37 | + } |
| 38 | + static createAsyncOptionsProvider(options) { |
| 39 | + if (options.useFactory) { |
| 40 | + return { |
| 41 | + provide: cache_constants_1.CACHE_MODULE_OPTIONS, |
| 42 | + useFactory: options.useFactory, |
| 43 | + inject: options.inject || [], |
| 44 | + }; |
| 45 | + } |
| 46 | + return { |
| 47 | + provide: cache_constants_1.CACHE_MODULE_OPTIONS, |
| 48 | + useFactory: async (optionsFactory) => await optionsFactory.createCacheOptions(), |
| 49 | + inject: [options.useExisting || options.useClass], |
| 50 | + }; |
| 51 | + } |
| 52 | +}; |
| 53 | +CacheModule = CacheModule_1 = __decorate([ |
| 54 | + decorators_1.Module({ |
| 55 | + providers: [cache_providers_1.createCacheManager()], |
| 56 | + exports: [cache_constants_1.CACHE_MANAGER], |
| 57 | + }) |
| 58 | +], CacheModule); |
| 59 | +exports.CacheModule = CacheModule; |
| 60 | +var CacheModule_1; |
0 commit comments