1 | "use strict";
|
2 | var CacheModule_1;
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | exports.CacheModule = void 0;
|
5 | const tslib_1 = require("tslib");
|
6 | const decorators_1 = require("../decorators");
|
7 | const cache_constants_1 = require("./cache.constants");
|
8 | const cache_providers_1 = require("./cache.providers");
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | let CacheModule = CacheModule_1 = class CacheModule {
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | static register(options = {}) {
|
25 | return {
|
26 | module: CacheModule_1,
|
27 | global: options.isGlobal,
|
28 | providers: [{ provide: cache_constants_1.CACHE_MODULE_OPTIONS, useValue: options }],
|
29 | };
|
30 | }
|
31 | |
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | static registerAsync(options) {
|
40 | return {
|
41 | module: CacheModule_1,
|
42 | global: options.isGlobal,
|
43 | imports: options.imports,
|
44 | providers: [
|
45 | ...this.createAsyncProviders(options),
|
46 | ...(options.extraProviders || []),
|
47 | ],
|
48 | };
|
49 | }
|
50 | static createAsyncProviders(options) {
|
51 | if (options.useExisting || options.useFactory) {
|
52 | return [this.createAsyncOptionsProvider(options)];
|
53 | }
|
54 | return [
|
55 | this.createAsyncOptionsProvider(options),
|
56 | {
|
57 | provide: options.useClass,
|
58 | useClass: options.useClass,
|
59 | },
|
60 | ];
|
61 | }
|
62 | static createAsyncOptionsProvider(options) {
|
63 | if (options.useFactory) {
|
64 | return {
|
65 | provide: cache_constants_1.CACHE_MODULE_OPTIONS,
|
66 | useFactory: options.useFactory,
|
67 | inject: options.inject || [],
|
68 | };
|
69 | }
|
70 | return {
|
71 | provide: cache_constants_1.CACHE_MODULE_OPTIONS,
|
72 | useFactory: async (optionsFactory) => optionsFactory.createCacheOptions(),
|
73 | inject: [options.useExisting || options.useClass],
|
74 | };
|
75 | }
|
76 | };
|
77 | CacheModule = CacheModule_1 = tslib_1.__decorate([
|
78 | (0, decorators_1.Module)({
|
79 | providers: [(0, cache_providers_1.createCacheManager)()],
|
80 | exports: [cache_constants_1.CACHE_MANAGER],
|
81 | })
|
82 | ], CacheModule);
|
83 | exports.CacheModule = CacheModule;
|