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 | providers: [{ provide: cache_constants_1.CACHE_MODULE_OPTIONS, useValue: options }],
|
28 | };
|
29 | }
|
30 | |
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | static registerAsync(options) {
|
39 | return {
|
40 | module: CacheModule_1,
|
41 | imports: options.imports,
|
42 | providers: [
|
43 | ...this.createAsyncProviders(options),
|
44 | ...(options.extraProviders || []),
|
45 | ],
|
46 | };
|
47 | }
|
48 | static createAsyncProviders(options) {
|
49 | if (options.useExisting || options.useFactory) {
|
50 | return [this.createAsyncOptionsProvider(options)];
|
51 | }
|
52 | return [
|
53 | this.createAsyncOptionsProvider(options),
|
54 | {
|
55 | provide: options.useClass,
|
56 | useClass: options.useClass,
|
57 | },
|
58 | ];
|
59 | }
|
60 | static createAsyncOptionsProvider(options) {
|
61 | if (options.useFactory) {
|
62 | return {
|
63 | provide: cache_constants_1.CACHE_MODULE_OPTIONS,
|
64 | useFactory: options.useFactory,
|
65 | inject: options.inject || [],
|
66 | };
|
67 | }
|
68 | return {
|
69 | provide: cache_constants_1.CACHE_MODULE_OPTIONS,
|
70 | useFactory: async (optionsFactory) => optionsFactory.createCacheOptions(),
|
71 | inject: [options.useExisting || options.useClass],
|
72 | };
|
73 | }
|
74 | };
|
75 | CacheModule = CacheModule_1 = tslib_1.__decorate([
|
76 | decorators_1.Module({
|
77 | providers: [cache_providers_1.createCacheManager()],
|
78 | exports: [cache_constants_1.CACHE_MANAGER],
|
79 | })
|
80 | ], CacheModule);
|
81 | exports.CacheModule = CacheModule;
|