@nestwork/chevron 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +82 -0
  3. package/dist/chevron-core.module.d.ts +37 -0
  4. package/dist/chevron-core.module.d.ts.map +1 -0
  5. package/dist/chevron-core.module.js +296 -0
  6. package/dist/chevron-core.module.js.map +1 -0
  7. package/dist/chevron.constants.d.ts +3 -0
  8. package/dist/chevron.constants.d.ts.map +1 -0
  9. package/dist/chevron.constants.js +6 -0
  10. package/dist/chevron.constants.js.map +1 -0
  11. package/dist/chevron.module-definition.d.ts +5 -0
  12. package/dist/chevron.module-definition.d.ts.map +1 -0
  13. package/dist/chevron.module-definition.js +12 -0
  14. package/dist/chevron.module-definition.js.map +1 -0
  15. package/dist/chevron.module.d.ts +8 -0
  16. package/dist/chevron.module.d.ts.map +1 -0
  17. package/dist/chevron.module.js +36 -0
  18. package/dist/chevron.module.js.map +1 -0
  19. package/dist/chevron.registry.d.ts +32 -0
  20. package/dist/chevron.registry.d.ts.map +1 -0
  21. package/dist/chevron.registry.js +171 -0
  22. package/dist/chevron.registry.js.map +1 -0
  23. package/dist/chevron.service.d.ts +16 -0
  24. package/dist/chevron.service.d.ts.map +1 -0
  25. package/dist/chevron.service.js +53 -0
  26. package/dist/chevron.service.js.map +1 -0
  27. package/dist/index.d.ts +7 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +15 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/interfaces/chevron-driver-options.interface.d.ts +15 -0
  32. package/dist/interfaces/chevron-driver-options.interface.d.ts.map +1 -0
  33. package/dist/interfaces/chevron-driver-options.interface.js +3 -0
  34. package/dist/interfaces/chevron-driver-options.interface.js.map +1 -0
  35. package/dist/interfaces/chevron-options.interface.d.ts +31 -0
  36. package/dist/interfaces/chevron-options.interface.d.ts.map +1 -0
  37. package/dist/interfaces/chevron-options.interface.js +3 -0
  38. package/dist/interfaces/chevron-options.interface.js.map +1 -0
  39. package/dist/interfaces/chevron-resolver.type.d.ts +4 -0
  40. package/dist/interfaces/chevron-resolver.type.d.ts.map +1 -0
  41. package/dist/interfaces/chevron-resolver.type.js +3 -0
  42. package/dist/interfaces/chevron-resolver.type.js.map +1 -0
  43. package/dist/interfaces/chevron-storage.interface.d.ts +10 -0
  44. package/dist/interfaces/chevron-storage.interface.d.ts.map +1 -0
  45. package/dist/interfaces/chevron-storage.interface.js +3 -0
  46. package/dist/interfaces/chevron-storage.interface.js.map +1 -0
  47. package/dist/interfaces/index.d.ts +5 -0
  48. package/dist/interfaces/index.d.ts.map +1 -0
  49. package/dist/interfaces/index.js +3 -0
  50. package/dist/interfaces/index.js.map +1 -0
  51. package/dist/storage/create-chevron-storage.d.ts +4 -0
  52. package/dist/storage/create-chevron-storage.d.ts.map +1 -0
  53. package/dist/storage/create-chevron-storage.js +40 -0
  54. package/dist/storage/create-chevron-storage.js.map +1 -0
  55. package/dist/storage/in-memory-chevron.storage.d.ts +11 -0
  56. package/dist/storage/in-memory-chevron.storage.d.ts.map +1 -0
  57. package/dist/storage/in-memory-chevron.storage.js +35 -0
  58. package/dist/storage/in-memory-chevron.storage.js.map +1 -0
  59. package/dist/tsconfig.tsbuildinfo +1 -0
  60. package/dist/utils/chevron-process-state.d.ts +8 -0
  61. package/dist/utils/chevron-process-state.d.ts.map +1 -0
  62. package/dist/utils/chevron-process-state.js +38 -0
  63. package/dist/utils/chevron-process-state.js.map +1 -0
  64. package/dist/utils/chevron.utils.d.ts +17 -0
  65. package/dist/utils/chevron.utils.d.ts.map +1 -0
  66. package/dist/utils/chevron.utils.js +76 -0
  67. package/dist/utils/chevron.utils.js.map +1 -0
  68. package/package.json +86 -0
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChevronRegistry = void 0;
4
+ const chevron_constants_1 = require("./chevron.constants");
5
+ class ChevronRegistry {
6
+ storage;
7
+ definitions = new Map();
8
+ cache = new Map();
9
+ pendingLookups = new Map();
10
+ featureGenerations = new Map();
11
+ globalGeneration = 0;
12
+ constructor(storage) {
13
+ this.storage = storage;
14
+ }
15
+ define(feature, resolver) {
16
+ this.definitions.set(feature, resolver);
17
+ this.invalidateFeature(feature);
18
+ }
19
+ defined() {
20
+ return [...this.definitions.keys()];
21
+ }
22
+ async value(feature) {
23
+ return this.resolveValue(feature);
24
+ }
25
+ async active(feature) {
26
+ const resolved = await this.resolveValue(feature);
27
+ return resolved !== false;
28
+ }
29
+ async inactive(feature) {
30
+ const resolved = await this.resolveValue(feature);
31
+ return resolved === false;
32
+ }
33
+ async activate(feature, featureValue = true) {
34
+ const cacheKey = this.cacheKey(feature);
35
+ await this.storage.set(feature, chevron_constants_1.GLOBAL_NULL_SCOPE, featureValue);
36
+ this.bumpGeneration(cacheKey);
37
+ this.cache.set(cacheKey, featureValue);
38
+ }
39
+ async deactivate(feature) {
40
+ await this.activate(feature, false);
41
+ }
42
+ async forget(feature) {
43
+ const cacheKey = this.cacheKey(feature);
44
+ await this.storage.delete(feature, chevron_constants_1.GLOBAL_NULL_SCOPE);
45
+ this.bumpGeneration(cacheKey);
46
+ this.cache.delete(cacheKey);
47
+ }
48
+ async purge(features) {
49
+ await this.storage.purge(features);
50
+ this.clearCache(features);
51
+ }
52
+ bootstrapFeatures(features) {
53
+ for (const [feature, resolver] of Object.entries(features)) {
54
+ this.define(feature, resolver);
55
+ }
56
+ }
57
+ async resolveValue(feature) {
58
+ const cacheKey = this.cacheKey(feature);
59
+ if (this.cache.has(cacheKey)) {
60
+ return this.cache.get(cacheKey);
61
+ }
62
+ const pendingLookup = this.pendingLookups.get(cacheKey);
63
+ if (pendingLookup !== undefined) {
64
+ return pendingLookup;
65
+ }
66
+ const lookup = this.lookupValue(feature, cacheKey);
67
+ this.pendingLookups.set(cacheKey, lookup);
68
+ try {
69
+ return await lookup;
70
+ }
71
+ finally {
72
+ if (this.pendingLookups.get(cacheKey) === lookup) {
73
+ this.pendingLookups.delete(cacheKey);
74
+ }
75
+ }
76
+ }
77
+ async lookupValue(feature, cacheKey) {
78
+ const generation = this.snapshotGeneration(cacheKey);
79
+ const stored = await this.storage.get(feature, chevron_constants_1.GLOBAL_NULL_SCOPE);
80
+ if (this.cache.has(cacheKey)) {
81
+ return this.cache.get(cacheKey);
82
+ }
83
+ if (stored !== undefined) {
84
+ if (this.isCurrentGeneration(cacheKey, generation)) {
85
+ this.cache.set(cacheKey, stored);
86
+ }
87
+ return stored;
88
+ }
89
+ const resolver = this.definitions.get(feature);
90
+ if (resolver === undefined) {
91
+ return false;
92
+ }
93
+ const resolved = await this.resolveDefinition(resolver);
94
+ if (this.cache.has(cacheKey)) {
95
+ return this.cache.get(cacheKey);
96
+ }
97
+ if (this.isCurrentGeneration(cacheKey, generation)) {
98
+ await this.storage.set(feature, chevron_constants_1.GLOBAL_NULL_SCOPE, resolved);
99
+ if (this.isCurrentGeneration(cacheKey, generation)) {
100
+ this.cache.set(cacheKey, resolved);
101
+ }
102
+ else {
103
+ await this.healStaleWrite(feature, cacheKey);
104
+ }
105
+ }
106
+ return resolved;
107
+ }
108
+ async resolveDefinition(resolver) {
109
+ if (this.isFeatureResolverFn(resolver)) {
110
+ return resolver();
111
+ }
112
+ return resolver;
113
+ }
114
+ isFeatureResolverFn(resolver) {
115
+ return typeof resolver === 'function';
116
+ }
117
+ cacheKey(feature) {
118
+ return `${feature}:${chevron_constants_1.GLOBAL_NULL_SCOPE}`;
119
+ }
120
+ invalidateFeature(feature) {
121
+ const cacheKey = this.cacheKey(feature);
122
+ this.bumpGeneration(cacheKey);
123
+ this.cache.delete(cacheKey);
124
+ const deleted = this.storage.delete(feature, chevron_constants_1.GLOBAL_NULL_SCOPE);
125
+ if (deleted instanceof Promise) {
126
+ void deleted.then(() => {
127
+ this.bumpGeneration(cacheKey);
128
+ this.cache.delete(cacheKey);
129
+ }, () => { });
130
+ }
131
+ }
132
+ clearCache(features) {
133
+ if (features === undefined) {
134
+ this.globalGeneration += 1;
135
+ this.cache.clear();
136
+ return;
137
+ }
138
+ for (const feature of features) {
139
+ this.bumpGeneration(this.cacheKey(feature));
140
+ this.cache.delete(this.cacheKey(feature));
141
+ }
142
+ }
143
+ async healStaleWrite(feature, cacheKey) {
144
+ for (;;) {
145
+ const generation = this.snapshotGeneration(cacheKey);
146
+ const hasCacheValue = this.cache.has(cacheKey);
147
+ const cacheValue = this.cache.get(cacheKey);
148
+ if (hasCacheValue) {
149
+ await this.storage.set(feature, chevron_constants_1.GLOBAL_NULL_SCOPE, cacheValue);
150
+ }
151
+ else {
152
+ await this.storage.delete(feature, chevron_constants_1.GLOBAL_NULL_SCOPE);
153
+ }
154
+ if (this.isCurrentGeneration(cacheKey, generation)) {
155
+ return;
156
+ }
157
+ }
158
+ }
159
+ bumpGeneration(cacheKey) {
160
+ this.featureGenerations.set(cacheKey, (this.featureGenerations.get(cacheKey) ?? 0) + 1);
161
+ }
162
+ snapshotGeneration(cacheKey) {
163
+ return [this.globalGeneration, this.featureGenerations.get(cacheKey) ?? 0];
164
+ }
165
+ isCurrentGeneration(cacheKey, snapshot) {
166
+ const [snapshotGlobal, snapshotFeature] = snapshot;
167
+ return (this.globalGeneration === snapshotGlobal && (this.featureGenerations.get(cacheKey) ?? 0) === snapshotFeature);
168
+ }
169
+ }
170
+ exports.ChevronRegistry = ChevronRegistry;
171
+ //# sourceMappingURL=chevron.registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chevron.registry.js","sourceRoot":"","sources":["../src/chevron.registry.ts"],"names":[],"mappings":";;;AAAA,2DAAwD;AAGxD,MAAa,eAAe;IAWK;IAVZ,WAAW,GAAG,IAAI,GAAG,EAA2B,CAAC;IAEjD,KAAK,GAAG,IAAI,GAAG,EAAwB,CAAC;IAExC,cAAc,GAAG,IAAI,GAAG,EAAyC,CAAC;IAElE,kBAAkB,GAAG,IAAI,GAAG,EAAkB,CAAC;IAExD,gBAAgB,GAAG,CAA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BAAmB,CAAC,QAAQ,EAAE,UAAU,CAAC,EAAE,CAAC;gBACjD,OAAO;YACX,CAAC;QACL,CAAC;IACL,CAAC;IAKO,cAAc,CAAC,QAAgB;QACnC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5F,CAAC;IAEO,kBAAkB,CAAC,QAAgB;QACvC,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/E,CAAC;IAEO,mBAAmB,CAAC,QAAgB,EAAE,QAAmC;QAC7E,MAAM,CAAC,cAAc,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC;QAEnD,OAAO,CACH,IAAI,CAAC,gBAAgB,KAAK,cAAc,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,eAAe,CAC/G,CAAC;IACN,CAAC;CACJ;AA/OD,0CA+OC"}
@@ -0,0 +1,16 @@
1
+ import { ChevronRegistry } from './chevron.registry';
2
+ import { FeatureResolver, FeatureValue } from './interfaces';
3
+ export declare class ChevronService {
4
+ private readonly registry;
5
+ constructor(registry: ChevronRegistry);
6
+ define(feature: string, resolver: FeatureResolver): void;
7
+ defined(): string[];
8
+ value(feature: string): Promise<FeatureValue | false>;
9
+ active(feature: string): Promise<boolean>;
10
+ inactive(feature: string): Promise<boolean>;
11
+ activate(feature: string, featureValue?: FeatureValue): Promise<void>;
12
+ deactivate(feature: string): Promise<void>;
13
+ forget(feature: string): Promise<void>;
14
+ purge(features?: string[]): Promise<void>;
15
+ }
16
+ //# sourceMappingURL=chevron.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chevron.service.d.ts","sourceRoot":"","sources":["../src/chevron.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE7D,qBACa,cAAc;IACX,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,eAAe;IAEtD,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,GAAG,IAAI;IAIxD,OAAO,IAAI,MAAM,EAAE;IAInB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,KAAK,CAAC;IAIrD,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIzC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI3C,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,GAAE,YAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAI3E,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1C,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAItC,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAG5C"}
@@ -0,0 +1,53 @@
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
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ChevronService = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const chevron_registry_1 = require("./chevron.registry");
15
+ let ChevronService = class ChevronService {
16
+ registry;
17
+ constructor(registry) {
18
+ this.registry = registry;
19
+ }
20
+ define(feature, resolver) {
21
+ this.registry.define(feature, resolver);
22
+ }
23
+ defined() {
24
+ return this.registry.defined();
25
+ }
26
+ value(feature) {
27
+ return this.registry.value(feature);
28
+ }
29
+ active(feature) {
30
+ return this.registry.active(feature);
31
+ }
32
+ inactive(feature) {
33
+ return this.registry.inactive(feature);
34
+ }
35
+ activate(feature, featureValue = true) {
36
+ return this.registry.activate(feature, featureValue);
37
+ }
38
+ deactivate(feature) {
39
+ return this.registry.deactivate(feature);
40
+ }
41
+ forget(feature) {
42
+ return this.registry.forget(feature);
43
+ }
44
+ purge(features) {
45
+ return this.registry.purge(features);
46
+ }
47
+ };
48
+ exports.ChevronService = ChevronService;
49
+ exports.ChevronService = ChevronService = __decorate([
50
+ (0, common_1.Injectable)(),
51
+ __metadata("design:paramtypes", [chevron_registry_1.ChevronRegistry])
52
+ ], ChevronService);
53
+ //# sourceMappingURL=chevron.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chevron.service.js","sourceRoot":"","sources":["../src/chevron.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,yDAAqD;AAI9C,IAAM,cAAc,GAApB,MAAM,cAAc;IACM;IAA7B,YAA6B,QAAyB;QAAzB,aAAQ,GAAR,QAAQ,CAAiB;IAAG,CAAC;IAE1D,MAAM,CAAC,OAAe,EAAE,QAAyB;QAC7C,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO;QACH,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,OAAe;QACjB,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,CAAC,OAAe;QAClB,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IAED,QAAQ,CAAC,OAAe;QACpB,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED,QAAQ,CAAC,OAAe,EAAE,eAA6B,IAAI;QACvD,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACzD,CAAC;IAED,UAAU,CAAC,OAAe;QACtB,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;IAED,MAAM,CAAC,OAAe;QAClB,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,QAAmB;QACrB,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC;CACJ,CAAA;AAtCY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;qCAE8B,kCAAe;GAD7C,cAAc,CAsC1B"}
@@ -0,0 +1,7 @@
1
+ export { ChevronModule } from './chevron.module';
2
+ export { ChevronService } from './chevron.service';
3
+ export { InMemoryChevronStorage } from './storage/in-memory-chevron.storage';
4
+ export { DEFAULT_CHEVRON_NAME } from './chevron.constants';
5
+ export { InjectChevron, getChevronToken } from './utils/chevron.utils';
6
+ export type { ChevronDatabaseDriverOptions, ChevronEnvDriverOptions, ChevronMemoryDriverOptions, ChevronModuleAsyncOptions, ChevronModuleOptions, ChevronOptionsFactory, ChevronStorage, ChevronStorageDriverOptions, ChevronStorageFactory, FeatureResolver, FeatureResolverFn, FeatureValue, } from './interfaces';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACvE,YAAY,EACR,4BAA4B,EAC5B,uBAAuB,EACvB,0BAA0B,EAC1B,yBAAyB,EACzB,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,EACd,2BAA2B,EAC3B,qBAAqB,EACrB,eAAe,EACf,iBAAiB,EACjB,YAAY,GACf,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getChevronToken = exports.InjectChevron = exports.DEFAULT_CHEVRON_NAME = exports.InMemoryChevronStorage = exports.ChevronService = exports.ChevronModule = void 0;
4
+ var chevron_module_1 = require("./chevron.module");
5
+ Object.defineProperty(exports, "ChevronModule", { enumerable: true, get: function () { return chevron_module_1.ChevronModule; } });
6
+ var chevron_service_1 = require("./chevron.service");
7
+ Object.defineProperty(exports, "ChevronService", { enumerable: true, get: function () { return chevron_service_1.ChevronService; } });
8
+ var in_memory_chevron_storage_1 = require("./storage/in-memory-chevron.storage");
9
+ Object.defineProperty(exports, "InMemoryChevronStorage", { enumerable: true, get: function () { return in_memory_chevron_storage_1.InMemoryChevronStorage; } });
10
+ var chevron_constants_1 = require("./chevron.constants");
11
+ Object.defineProperty(exports, "DEFAULT_CHEVRON_NAME", { enumerable: true, get: function () { return chevron_constants_1.DEFAULT_CHEVRON_NAME; } });
12
+ var chevron_utils_1 = require("./utils/chevron.utils");
13
+ Object.defineProperty(exports, "InjectChevron", { enumerable: true, get: function () { return chevron_utils_1.InjectChevron; } });
14
+ Object.defineProperty(exports, "getChevronToken", { enumerable: true, get: function () { return chevron_utils_1.getChevronToken; } });
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AACtB,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AACvB,iFAA6E;AAApE,mIAAA,sBAAsB,OAAA;AAC/B,yDAA2D;AAAlD,yHAAA,oBAAoB,OAAA;AAC7B,uDAAuE;AAA9D,8GAAA,aAAa,OAAA;AAAE,gHAAA,eAAe,OAAA"}
@@ -0,0 +1,15 @@
1
+ export type ChevronMemoryDriverOptions = {
2
+ driver?: 'memory';
3
+ };
4
+ export type ChevronEnvDriverOptions = {
5
+ driver: 'env';
6
+ prefix: string;
7
+ overlay?: boolean;
8
+ nameTransform?: 'camelCase';
9
+ env?: Readonly<Record<string, string | undefined>>;
10
+ };
11
+ export type ChevronDatabaseDriverOptions = {
12
+ driver: 'database';
13
+ };
14
+ export type ChevronStorageDriverOptions = ChevronMemoryDriverOptions | ChevronEnvDriverOptions | ChevronDatabaseDriverOptions;
15
+ //# sourceMappingURL=chevron-driver-options.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chevron-driver-options.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/chevron-driver-options.interface.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,0BAA0B,GAAG;IACrC,MAAM,CAAC,EAAE,QAAQ,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IAClC,MAAM,EAAE,KAAK,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,aAAa,CAAC,EAAE,WAAW,CAAC;IAC5B,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;CACtD,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACvC,MAAM,EAAE,UAAU,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,2BAA2B,GACnC,0BAA0B,GAAG,uBAAuB,GAAG,4BAA4B,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=chevron-driver-options.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chevron-driver-options.interface.js","sourceRoot":"","sources":["../../src/interfaces/chevron-driver-options.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,31 @@
1
+ import { ConfigurableModuleAsyncOptions, FactoryProvider, ModuleMetadata, Provider, Type } from '@nestjs/common';
2
+ import { ChevronStorage } from './chevron-storage.interface';
3
+ import { FeatureResolver } from './chevron-resolver.type';
4
+ import { ChevronStorageDriverOptions } from './chevron-driver-options.interface';
5
+ export type { ChevronDatabaseDriverOptions, ChevronEnvDriverOptions, ChevronMemoryDriverOptions, ChevronStorageDriverOptions, } from './chevron-driver-options.interface';
6
+ export type ChevronStorageProviderShorthand = {
7
+ useClass: Type<ChevronStorage>;
8
+ } | {
9
+ useFactory: (...args: unknown[]) => ChevronStorage | Promise<ChevronStorage>;
10
+ inject?: FactoryProvider['inject'];
11
+ } | {
12
+ useExisting: Type<ChevronStorage> | symbol | string;
13
+ };
14
+ export type ChevronStorageRegistration = Type<ChevronStorage> | ChevronStorageProviderShorthand | Provider<ChevronStorage> | ChevronStorageDriverOptions;
15
+ export interface ChevronModuleOptions {
16
+ storage?: ChevronStorageRegistration;
17
+ name?: string | symbol;
18
+ features?: Record<string, FeatureResolver>;
19
+ isGlobal?: boolean;
20
+ }
21
+ export type ChevronStorageFactory = (options: ChevronModuleOptions) => ChevronStorage | Promise<ChevronStorage>;
22
+ export interface ChevronModuleAsyncOptions extends ConfigurableModuleAsyncOptions<ChevronModuleOptions, 'createChevronOptions'>, Pick<ModuleMetadata, 'imports'> {
23
+ name?: string | symbol;
24
+ isGlobal?: boolean;
25
+ storageFactory?: ChevronStorageFactory;
26
+ extraProviders?: Provider[];
27
+ }
28
+ export interface ChevronOptionsFactory {
29
+ createChevronOptions(name?: string | symbol): Promise<ChevronModuleOptions> | ChevronModuleOptions;
30
+ }
31
+ //# sourceMappingURL=chevron-options.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chevron-options.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/chevron-options.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,eAAe,EAAE,cAAc,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACjH,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAEjF,YAAY,EACR,4BAA4B,EAC5B,uBAAuB,EACvB,0BAA0B,EAC1B,2BAA2B,GAC9B,MAAM,oCAAoC,CAAC;AAE5C,MAAM,MAAM,+BAA+B,GACrC;IAAE,QAAQ,EAAE,IAAI,CAAC,cAAc,CAAC,CAAA;CAAE,GAClC;IACI,UAAU,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAC7E,MAAM,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;CACtC,GACD;IAAE,WAAW,EAAE,IAAI,CAAC,cAAc,CAAC,GAAG,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAE9D,MAAM,MAAM,0BAA0B,GAClC,IAAI,CAAC,cAAc,CAAC,GAAG,+BAA+B,GAAG,QAAQ,CAAC,cAAc,CAAC,GAAG,2BAA2B,CAAC;AAEpH,MAAM,WAAW,oBAAoB;IACjC,OAAO,CAAC,EAAE,0BAA0B,CAAC;IACrC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC3C,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,EAAE,oBAAoB,KAAK,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAEhH,MAAM,WAAW,yBACb,SACI,8BAA8B,CAAC,oBAAoB,EAAE,sBAAsB,CAAC,EAC5E,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC;IACnC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,cAAc,CAAC,EAAE,qBAAqB,CAAC;IACvC,cAAc,CAAC,EAAE,QAAQ,EAAE,CAAC;CAC/B;AAED,MAAM,WAAW,qBAAqB;IAClC,oBAAoB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,GAAG,oBAAoB,CAAC;CACtG"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=chevron-options.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chevron-options.interface.js","sourceRoot":"","sources":["../../src/interfaces/chevron-options.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export type FeatureValue = boolean | string | number | null;
2
+ export type FeatureResolverFn = () => FeatureValue | Promise<FeatureValue>;
3
+ export type FeatureResolver = FeatureValue | FeatureResolverFn;
4
+ //# sourceMappingURL=chevron-resolver.type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chevron-resolver.type.d.ts","sourceRoot":"","sources":["../../src/interfaces/chevron-resolver.type.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAE5D,MAAM,MAAM,iBAAiB,GAAG,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAE3E,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG,iBAAiB,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=chevron-resolver.type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chevron-resolver.type.js","sourceRoot":"","sources":["../../src/interfaces/chevron-resolver.type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import { FeatureValue } from './chevron-resolver.type';
2
+ export interface ChevronStorage {
3
+ get(feature: string, scope: string): FeatureValue | undefined | Promise<FeatureValue | undefined>;
4
+ set(feature: string, scope: string, value: FeatureValue): void | Promise<void>;
5
+ delete(feature: string, scope: string): void | Promise<void>;
6
+ purge(features?: string[]): void | Promise<void>;
7
+ destroy?(): void | Promise<void>;
8
+ onModuleDestroy?(): void | Promise<void>;
9
+ }
10
+ //# sourceMappingURL=chevron-storage.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chevron-storage.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/chevron-storage.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,MAAM,WAAW,cAAc;IAC3B,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAAC;IAElG,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/E,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7D,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjD,OAAO,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjC,eAAe,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5C"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=chevron-storage.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chevron-storage.interface.js","sourceRoot":"","sources":["../../src/interfaces/chevron-storage.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ export type { ChevronModuleAsyncOptions, ChevronModuleOptions, ChevronOptionsFactory, ChevronStorageFactory, ChevronStorageProviderShorthand, ChevronStorageRegistration, } from './chevron-options.interface';
2
+ export type { FeatureResolver, FeatureResolverFn, FeatureValue } from './chevron-resolver.type';
3
+ export type { ChevronStorage } from './chevron-storage.interface';
4
+ export type { ChevronDatabaseDriverOptions, ChevronEnvDriverOptions, ChevronMemoryDriverOptions, ChevronStorageDriverOptions, } from './chevron-driver-options.interface';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACR,yBAAyB,EACzB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,+BAA+B,EAC/B,0BAA0B,GAC7B,MAAM,6BAA6B,CAAC;AAErC,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEhG,YAAY,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAElE,YAAY,EACR,4BAA4B,EAC5B,uBAAuB,EACvB,0BAA0B,EAC1B,2BAA2B,GAC9B,MAAM,oCAAoC,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { ChevronStorage, ChevronStorageDriverOptions } from '../interfaces';
2
+ export declare function isChevronStorageDriverOptions(registration: unknown): registration is ChevronStorageDriverOptions;
3
+ export declare function createChevronStorageFromDriver(options: ChevronStorageDriverOptions): ChevronStorage;
4
+ //# sourceMappingURL=create-chevron-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-chevron-storage.d.ts","sourceRoot":"","sources":["../../src/storage/create-chevron-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAG5E,wBAAgB,6BAA6B,CAAC,YAAY,EAAE,OAAO,GAAG,YAAY,IAAI,2BAA2B,CAUhH;AAED,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,2BAA2B,GAAG,cAAc,CAkBnG"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isChevronStorageDriverOptions = isChevronStorageDriverOptions;
4
+ exports.createChevronStorageFromDriver = createChevronStorageFromDriver;
5
+ const in_memory_chevron_storage_1 = require("./in-memory-chevron.storage");
6
+ function isChevronStorageDriverOptions(registration) {
7
+ return (typeof registration === 'object' &&
8
+ registration !== null &&
9
+ 'driver' in registration &&
10
+ !('provide' in registration) &&
11
+ !('useClass' in registration) &&
12
+ !('useFactory' in registration) &&
13
+ !('useExisting' in registration));
14
+ }
15
+ function createChevronStorageFromDriver(options) {
16
+ const driver = options.driver ?? 'memory';
17
+ if (driver === 'memory') {
18
+ assertMemoryDriverOptions(options);
19
+ return new in_memory_chevron_storage_1.InMemoryChevronStorage();
20
+ }
21
+ if (driver === 'env') {
22
+ throw new TypeError('Env storage driver is not implemented yet.');
23
+ }
24
+ if (driver === 'database') {
25
+ throw new TypeError('Database storage driver is not implemented yet.');
26
+ }
27
+ throw new TypeError(`Unknown chevron storage driver "${String(driver)}".`);
28
+ }
29
+ function assertMemoryDriverOptions(options) {
30
+ if (options.driver !== undefined && options.driver !== 'memory') {
31
+ return;
32
+ }
33
+ const forbiddenKeys = ['prefix', 'overlay', 'nameTransform', 'env'];
34
+ for (const key of forbiddenKeys) {
35
+ if (key in options) {
36
+ throw new TypeError(`Memory storage driver does not accept "${key}".`);
37
+ }
38
+ }
39
+ }
40
+ //# sourceMappingURL=create-chevron-storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-chevron-storage.js","sourceRoot":"","sources":["../../src/storage/create-chevron-storage.ts"],"names":[],"mappings":";;AAGA,sEAUC;AAED,wEAkBC;AAhCD,2EAAqE;AAErE,SAAgB,6BAA6B,CAAC,YAAqB;IAC/D,OAAO,CACH,OAAO,YAAY,KAAK,QAAQ;QAChC,YAAY,KAAK,IAAI;QACrB,QAAQ,IAAI,YAAY;QACxB,CAAC,CAAC,SAAS,IAAI,YAAY,CAAC;QAC5B,CAAC,CAAC,UAAU,IAAI,YAAY,CAAC;QAC7B,CAAC,CAAC,YAAY,IAAI,YAAY,CAAC;QAC/B,CAAC,CAAC,aAAa,IAAI,YAAY,CAAC,CACnC,CAAC;AACN,CAAC;AAED,SAAgB,8BAA8B,CAAC,OAAoC;IAC/E,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,QAAQ,CAAC;IAE1C,IAAI,MAAM,KAAK,QAAQ,EAAE,CAAC;QACtB,yBAAyB,CAAC,OAAO,CAAC,CAAC;QAEnC,OAAO,IAAI,kDAAsB,EAAE,CAAC;IACxC,CAAC;IAED,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QACnB,MAAM,IAAI,SAAS,CAAC,4CAA4C,CAAC,CAAC;IACtE,CAAC;IAED,IAAI,MAAM,KAAK,UAAU,EAAE,CAAC;QACxB,MAAM,IAAI,SAAS,CAAC,iDAAiD,CAAC,CAAC;IAC3E,CAAC;IAED,MAAM,IAAI,SAAS,CAAC,mCAAmC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC/E,CAAC;AAED,SAAS,yBAAyB,CAAC,OAAoC;IACnE,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS,IAAI,OAAO,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC9D,OAAO;IACX,CAAC;IAED,MAAM,aAAa,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,KAAK,CAAU,CAAC;IAE7E,KAAK,MAAM,GAAG,IAAI,aAAa,EAAE,CAAC;QAC9B,IAAI,GAAG,IAAI,OAAO,EAAE,CAAC;YACjB,MAAM,IAAI,SAAS,CAAC,0CAA0C,GAAG,IAAI,CAAC,CAAC;QAC3E,CAAC;IACL,CAAC;AACL,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { FeatureValue, ChevronStorage } from '../interfaces';
2
+ export declare class InMemoryChevronStorage implements ChevronStorage {
3
+ private readonly values;
4
+ get(feature: string, scope: string): FeatureValue | undefined;
5
+ set(feature: string, scope: string, value: FeatureValue): void;
6
+ delete(feature: string, scope: string): void;
7
+ purge(features?: string[]): void;
8
+ private featureFromKey;
9
+ private key;
10
+ }
11
+ //# sourceMappingURL=in-memory-chevron.storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory-chevron.storage.d.ts","sourceRoot":"","sources":["../../src/storage/in-memory-chevron.storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE7D,qBAAa,sBAAuB,YAAW,cAAc;IACzD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmC;IAE1D,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAI7D,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI;IAI9D,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAI5C,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI;IAchC,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,GAAG;CAGd"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InMemoryChevronStorage = void 0;
4
+ class InMemoryChevronStorage {
5
+ values = new Map();
6
+ get(feature, scope) {
7
+ return this.values.get(this.key(feature, scope));
8
+ }
9
+ set(feature, scope, value) {
10
+ this.values.set(this.key(feature, scope), value);
11
+ }
12
+ delete(feature, scope) {
13
+ this.values.delete(this.key(feature, scope));
14
+ }
15
+ purge(features) {
16
+ if (features === undefined) {
17
+ this.values.clear();
18
+ return;
19
+ }
20
+ for (const key of [...this.values.keys()]) {
21
+ if (features.includes(this.featureFromKey(key))) {
22
+ this.values.delete(key);
23
+ }
24
+ }
25
+ }
26
+ featureFromKey(key) {
27
+ const separatorIndex = key.lastIndexOf(':');
28
+ return key.slice(0, separatorIndex);
29
+ }
30
+ key(feature, scope) {
31
+ return `${feature}:${scope}`;
32
+ }
33
+ }
34
+ exports.InMemoryChevronStorage = InMemoryChevronStorage;
35
+ //# sourceMappingURL=in-memory-chevron.storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory-chevron.storage.js","sourceRoot":"","sources":["../../src/storage/in-memory-chevron.storage.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