@nestwork/chevron 1.0.0 → 1.1.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.
- package/README.md +18 -1
- package/dist/chevron.constants.d.ts +0 -1
- package/dist/chevron.constants.d.ts.map +1 -1
- package/dist/chevron.constants.js +1 -2
- package/dist/chevron.constants.js.map +1 -1
- package/dist/chevron.registry.d.ts +1 -1
- package/dist/chevron.registry.d.ts.map +1 -1
- package/dist/chevron.registry.js +54 -55
- package/dist/chevron.registry.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/chevron-driver-options.interface.d.ts +4 -7
- package/dist/interfaces/chevron-driver-options.interface.d.ts.map +1 -1
- package/dist/interfaces/chevron-options.interface.d.ts +1 -1
- package/dist/interfaces/chevron-options.interface.d.ts.map +1 -1
- package/dist/interfaces/chevron-storage.interface.d.ts +3 -3
- package/dist/interfaces/chevron-storage.interface.d.ts.map +1 -1
- package/dist/interfaces/index.d.ts +1 -1
- package/dist/interfaces/index.d.ts.map +1 -1
- package/dist/storage/assert-storage-option-keys.d.ts +2 -0
- package/dist/storage/assert-storage-option-keys.d.ts.map +1 -0
- package/dist/storage/assert-storage-option-keys.js +12 -0
- package/dist/storage/assert-storage-option-keys.js.map +1 -0
- package/dist/storage/create-chevron-storage.d.ts.map +1 -1
- package/dist/storage/create-chevron-storage.js +9 -17
- package/dist/storage/create-chevron-storage.js.map +1 -1
- package/dist/storage/env-chevron.storage.d.ts +11 -0
- package/dist/storage/env-chevron.storage.d.ts.map +1 -0
- package/dist/storage/env-chevron.storage.js +77 -0
- package/dist/storage/env-chevron.storage.js.map +1 -0
- package/dist/storage/in-memory-chevron.storage.d.ts +3 -5
- package/dist/storage/in-memory-chevron.storage.d.ts.map +1 -1
- package/dist/storage/in-memory-chevron.storage.js +8 -17
- package/dist/storage/in-memory-chevron.storage.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ pnpm test:all # lib + sample tests
|
|
|
26
26
|
pnpm lint
|
|
27
27
|
pnpm check-types
|
|
28
28
|
pnpm dev:sample # lib watch + sample/000-in-memory-app
|
|
29
|
+
pnpm dev:sample:env # lib watch + sample/001-env-storage-sample
|
|
29
30
|
```
|
|
30
31
|
|
|
31
32
|
## Quick start
|
|
@@ -57,7 +58,7 @@ export class CheckoutService {
|
|
|
57
58
|
}
|
|
58
59
|
```
|
|
59
60
|
|
|
60
|
-
See `sample/000-in-memory-app` for default + async named gates
|
|
61
|
+
See `sample/000-in-memory-app` for default + async named gates, and `sample/001-env-storage-sample` for `{ driver: 'env' }`.
|
|
61
62
|
|
|
62
63
|
## Named gates and injection scope
|
|
63
64
|
|
|
@@ -69,6 +70,22 @@ See `sample/000-in-memory-app` for default + async named gates.
|
|
|
69
70
|
|
|
70
71
|
Default storage is in-memory (`{ driver: 'memory' }`). Class-token and `useClass` registrations use Nest `ModuleRef.create()` for constructor DI.
|
|
71
72
|
|
|
73
|
+
Env storage (`{ driver: 'env', prefix: 'FEATURE_' }`) scans matching keys once at construct (`FEATURE_USE_NEW_API` → `useNewApi`) and keeps them in the same in-memory map. Put those variables on `process.env` before the gate is created (`node --env-file=.env` or `process.loadEnvFile()`). Restart the process to pick up env changes. A stored value wins over a `features` map entry and over the first `define()` of that name; a later `define()` of the same name clears storage like a redefine.
|
|
74
|
+
|
|
75
|
+
Coercion of env strings: `true` / `1` / `yes` / `on` → `true`; `false` / `0` / `no` / `off` / `''` → `false`; an integer or decimal → `number`; anything else stays a string.
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
ChevronModule.forRoot({
|
|
79
|
+
storage: { driver: 'env', prefix: 'FEATURE_' },
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Storage options are validated synchronously when the module is built, not on first use — an invalid `env` prefix, or two env keys that collapse to the same camelCase feature name (e.g. `FEATURE_LANG` and `FEATURE_Lang`), throws during Nest's DI bootstrap and fails app startup.
|
|
84
|
+
|
|
85
|
+
## Concurrency
|
|
86
|
+
|
|
87
|
+
`ChevronService` caches each feature's resolved value and de-duplicates concurrent lookups, so a resolver runs at most once even under parallel `active()`/`value()` calls for the same feature. `activate()`, `deactivate()`, `forget()`, `define()`, and `purge()` invalidate that cache immediately; a lookup already in flight when one of these runs never re-caches a stale result, even if its own storage write physically lands afterward. Safe to call from concurrent requests without external locking.
|
|
88
|
+
|
|
72
89
|
## Release
|
|
73
90
|
|
|
74
91
|
```sh
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chevron.constants.d.ts","sourceRoot":"","sources":["../src/chevron.constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,YAAY,CAAC
|
|
1
|
+
{"version":3,"file":"chevron.constants.d.ts","sourceRoot":"","sources":["../src/chevron.constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,YAAY,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.DEFAULT_CHEVRON_NAME = void 0;
|
|
4
4
|
exports.DEFAULT_CHEVRON_NAME = 'default';
|
|
5
|
-
exports.GLOBAL_NULL_SCOPE = '__chevron_null__';
|
|
6
5
|
//# sourceMappingURL=chevron.constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chevron.constants.js","sourceRoot":"","sources":["../src/chevron.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,SAAS,CAAC
|
|
1
|
+
{"version":3,"file":"chevron.constants.js","sourceRoot":"","sources":["../src/chevron.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,SAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chevron.registry.d.ts","sourceRoot":"","sources":["../src/chevron.registry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"chevron.registry.d.ts","sourceRoot":"","sources":["../src/chevron.registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAqB,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEhG,qBAAa,eAAe;IAWZ,OAAO,CAAC,QAAQ,CAAC,OAAO;IAVpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAsC;IAElE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAmC;IAEzD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAoD;IAEnF,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA6B;IAEhE,OAAO,CAAC,gBAAgB,CAAK;gBAEA,OAAO,EAAE,cAAc;IAEpD,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,GAAG,IAAI;IAaxD,OAAO,IAAI,MAAM,EAAE;IAIb,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,KAAK,CAAC;IAIrD,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAMzC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAM3C,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,GAAE,YAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAM3E,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1C,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMtC,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAK/C,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,IAAI;YAMpD,YAAY;YAuBZ,WAAW;YA6CX,iBAAiB;IAQ/B,OAAO,CAAC,mBAAmB;IAI3B,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,iBAAiB;IAqBzB,OAAO,CAAC,UAAU;YAuBJ,cAAc;IAqB5B,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,mBAAmB;CAO9B"}
|
package/dist/chevron.registry.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ChevronRegistry = void 0;
|
|
4
|
-
const chevron_constants_1 = require("./chevron.constants");
|
|
5
4
|
class ChevronRegistry {
|
|
6
5
|
storage;
|
|
7
6
|
definitions = new Map();
|
|
@@ -13,8 +12,13 @@ class ChevronRegistry {
|
|
|
13
12
|
this.storage = storage;
|
|
14
13
|
}
|
|
15
14
|
define(feature, resolver) {
|
|
15
|
+
const wasDefined = this.definitions.has(feature);
|
|
16
16
|
this.definitions.set(feature, resolver);
|
|
17
|
-
|
|
17
|
+
if (wasDefined) {
|
|
18
|
+
this.invalidateFeature(feature);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
this.invalidateCache(feature);
|
|
18
22
|
}
|
|
19
23
|
defined() {
|
|
20
24
|
return [...this.definitions.keys()];
|
|
@@ -31,19 +35,17 @@ class ChevronRegistry {
|
|
|
31
35
|
return resolved === false;
|
|
32
36
|
}
|
|
33
37
|
async activate(feature, featureValue = true) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.
|
|
37
|
-
this.cache.set(cacheKey, featureValue);
|
|
38
|
+
await this.storage.set(feature, featureValue);
|
|
39
|
+
this.bumpGeneration(feature);
|
|
40
|
+
this.cache.set(feature, featureValue);
|
|
38
41
|
}
|
|
39
42
|
async deactivate(feature) {
|
|
40
43
|
await this.activate(feature, false);
|
|
41
44
|
}
|
|
42
45
|
async forget(feature) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.
|
|
46
|
-
this.cache.delete(cacheKey);
|
|
46
|
+
await this.storage.delete(feature);
|
|
47
|
+
this.bumpGeneration(feature);
|
|
48
|
+
this.cache.delete(feature);
|
|
47
49
|
}
|
|
48
50
|
async purge(features) {
|
|
49
51
|
await this.storage.purge(features);
|
|
@@ -55,34 +57,33 @@ class ChevronRegistry {
|
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
59
|
async resolveValue(feature) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return this.cache.get(cacheKey);
|
|
60
|
+
if (this.cache.has(feature)) {
|
|
61
|
+
return this.cache.get(feature);
|
|
61
62
|
}
|
|
62
|
-
const pendingLookup = this.pendingLookups.get(
|
|
63
|
+
const pendingLookup = this.pendingLookups.get(feature);
|
|
63
64
|
if (pendingLookup !== undefined) {
|
|
64
65
|
return pendingLookup;
|
|
65
66
|
}
|
|
66
|
-
const lookup = this.lookupValue(feature
|
|
67
|
-
this.pendingLookups.set(
|
|
67
|
+
const lookup = this.lookupValue(feature);
|
|
68
|
+
this.pendingLookups.set(feature, lookup);
|
|
68
69
|
try {
|
|
69
70
|
return await lookup;
|
|
70
71
|
}
|
|
71
72
|
finally {
|
|
72
|
-
if (this.pendingLookups.get(
|
|
73
|
-
this.pendingLookups.delete(
|
|
73
|
+
if (this.pendingLookups.get(feature) === lookup) {
|
|
74
|
+
this.pendingLookups.delete(feature);
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
|
-
async lookupValue(feature
|
|
78
|
-
const generation = this.snapshotGeneration(
|
|
79
|
-
const stored = await this.storage.get(feature
|
|
80
|
-
if (this.cache.has(
|
|
81
|
-
return this.cache.get(
|
|
78
|
+
async lookupValue(feature) {
|
|
79
|
+
const generation = this.snapshotGeneration(feature);
|
|
80
|
+
const stored = await this.storage.get(feature);
|
|
81
|
+
if (this.cache.has(feature)) {
|
|
82
|
+
return this.cache.get(feature);
|
|
82
83
|
}
|
|
83
84
|
if (stored !== undefined) {
|
|
84
|
-
if (this.isCurrentGeneration(
|
|
85
|
-
this.cache.set(
|
|
85
|
+
if (this.isCurrentGeneration(feature, generation)) {
|
|
86
|
+
this.cache.set(feature, stored);
|
|
86
87
|
}
|
|
87
88
|
return stored;
|
|
88
89
|
}
|
|
@@ -91,16 +92,16 @@ class ChevronRegistry {
|
|
|
91
92
|
return false;
|
|
92
93
|
}
|
|
93
94
|
const resolved = await this.resolveDefinition(resolver);
|
|
94
|
-
if (this.cache.has(
|
|
95
|
-
return this.cache.get(
|
|
95
|
+
if (this.cache.has(feature)) {
|
|
96
|
+
return this.cache.get(feature);
|
|
96
97
|
}
|
|
97
|
-
if (this.isCurrentGeneration(
|
|
98
|
-
await this.storage.set(feature,
|
|
99
|
-
if (this.isCurrentGeneration(
|
|
100
|
-
this.cache.set(
|
|
98
|
+
if (this.isCurrentGeneration(feature, generation)) {
|
|
99
|
+
await this.storage.set(feature, resolved);
|
|
100
|
+
if (this.isCurrentGeneration(feature, generation)) {
|
|
101
|
+
this.cache.set(feature, resolved);
|
|
101
102
|
}
|
|
102
103
|
else {
|
|
103
|
-
await this.healStaleWrite(feature
|
|
104
|
+
await this.healStaleWrite(feature);
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
return resolved;
|
|
@@ -114,18 +115,16 @@ class ChevronRegistry {
|
|
|
114
115
|
isFeatureResolverFn(resolver) {
|
|
115
116
|
return typeof resolver === 'function';
|
|
116
117
|
}
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
invalidateCache(feature) {
|
|
119
|
+
this.bumpGeneration(feature);
|
|
120
|
+
this.cache.delete(feature);
|
|
119
121
|
}
|
|
120
122
|
invalidateFeature(feature) {
|
|
121
|
-
|
|
122
|
-
this.
|
|
123
|
-
this.cache.delete(cacheKey);
|
|
124
|
-
const deleted = this.storage.delete(feature, chevron_constants_1.GLOBAL_NULL_SCOPE);
|
|
123
|
+
this.invalidateCache(feature);
|
|
124
|
+
const deleted = this.storage.delete(feature);
|
|
125
125
|
if (deleted instanceof Promise) {
|
|
126
126
|
void deleted.then(() => {
|
|
127
|
-
this.
|
|
128
|
-
this.cache.delete(cacheKey);
|
|
127
|
+
this.invalidateCache(feature);
|
|
129
128
|
}, () => { });
|
|
130
129
|
}
|
|
131
130
|
}
|
|
@@ -136,35 +135,35 @@ class ChevronRegistry {
|
|
|
136
135
|
return;
|
|
137
136
|
}
|
|
138
137
|
for (const feature of features) {
|
|
139
|
-
this.bumpGeneration(
|
|
140
|
-
this.cache.delete(
|
|
138
|
+
this.bumpGeneration(feature);
|
|
139
|
+
this.cache.delete(feature);
|
|
141
140
|
}
|
|
142
141
|
}
|
|
143
|
-
async healStaleWrite(feature
|
|
142
|
+
async healStaleWrite(feature) {
|
|
144
143
|
for (;;) {
|
|
145
|
-
const generation = this.snapshotGeneration(
|
|
146
|
-
const hasCacheValue = this.cache.has(
|
|
147
|
-
const cacheValue = this.cache.get(
|
|
144
|
+
const generation = this.snapshotGeneration(feature);
|
|
145
|
+
const hasCacheValue = this.cache.has(feature);
|
|
146
|
+
const cacheValue = this.cache.get(feature);
|
|
148
147
|
if (hasCacheValue) {
|
|
149
|
-
await this.storage.set(feature,
|
|
148
|
+
await this.storage.set(feature, cacheValue);
|
|
150
149
|
}
|
|
151
150
|
else {
|
|
152
|
-
await this.storage.delete(feature
|
|
151
|
+
await this.storage.delete(feature);
|
|
153
152
|
}
|
|
154
|
-
if (this.isCurrentGeneration(
|
|
153
|
+
if (this.isCurrentGeneration(feature, generation)) {
|
|
155
154
|
return;
|
|
156
155
|
}
|
|
157
156
|
}
|
|
158
157
|
}
|
|
159
|
-
bumpGeneration(
|
|
160
|
-
this.featureGenerations.set(
|
|
158
|
+
bumpGeneration(feature) {
|
|
159
|
+
this.featureGenerations.set(feature, (this.featureGenerations.get(feature) ?? 0) + 1);
|
|
161
160
|
}
|
|
162
|
-
snapshotGeneration(
|
|
163
|
-
return [this.globalGeneration, this.featureGenerations.get(
|
|
161
|
+
snapshotGeneration(feature) {
|
|
162
|
+
return [this.globalGeneration, this.featureGenerations.get(feature) ?? 0];
|
|
164
163
|
}
|
|
165
|
-
isCurrentGeneration(
|
|
164
|
+
isCurrentGeneration(feature, snapshot) {
|
|
166
165
|
const [snapshotGlobal, snapshotFeature] = snapshot;
|
|
167
|
-
return (this.globalGeneration === snapshotGlobal && (this.featureGenerations.get(
|
|
166
|
+
return (this.globalGeneration === snapshotGlobal && (this.featureGenerations.get(feature) ?? 0) === snapshotFeature);
|
|
168
167
|
}
|
|
169
168
|
}
|
|
170
169
|
exports.ChevronRegistry = ChevronRegistry;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chevron.registry.js","sourceRoot":"","sources":["../src/chevron.registry.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"chevron.registry.js","sourceRoot":"","sources":["../src/chevron.registry.ts"],"names":[],"mappings":";;;AAEA,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,CAAC,CAAC;IAE7B,YAA6B,OAAuB;QAAvB,YAAO,GAAP,OAAO,CAAgB;IAAG,CAAC;IAExD,MAAM,CAAC,OAAe,EAAE,QAAyB;QAC7C,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACjD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAExC,IAAI,UAAU,EAAE,CAAC;YACb,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;YAEhC,OAAO;QACX,CAAC;QAED,IAAI,CAAC,eAAe,CAAC,O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ronModule } from './chevron.module';
|
|
2
2
|
export { ChevronService } from './chevron.service';
|
|
3
3
|
export { InMemoryChevronStorage } from './storage/in-memory-chevron.storage';
|
|
4
|
+
export { EnvChevronStorage } from './storage/env-chevron.storage';
|
|
4
5
|
export { DEFAULT_CHEVRON_NAME } from './chevron.constants';
|
|
5
6
|
export { InjectChevron, getChevronToken } from './utils/chevron.utils';
|
|
6
|
-
export type {
|
|
7
|
+
export type { ChevronEnvDriverOptions, ChevronMemoryDriverOptions, EnvChevronStorageOptions, ChevronModuleAsyncOptions, ChevronModuleOptions, ChevronOptionsFactory, ChevronStorage, ChevronStorageDriverOptions, ChevronStorageFactory, FeatureResolver, FeatureResolverFn, FeatureValue, } from './interfaces';
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
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,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACvE,YAAY,EACR,uBAAuB,EACvB,0BAA0B,EAC1B,wBAAwB,EACxB,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
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getChevronToken = exports.InjectChevron = exports.DEFAULT_CHEVRON_NAME = exports.InMemoryChevronStorage = exports.ChevronService = exports.ChevronModule = void 0;
|
|
3
|
+
exports.getChevronToken = exports.InjectChevron = exports.DEFAULT_CHEVRON_NAME = exports.EnvChevronStorage = exports.InMemoryChevronStorage = exports.ChevronService = exports.ChevronModule = void 0;
|
|
4
4
|
var chevron_module_1 = require("./chevron.module");
|
|
5
5
|
Object.defineProperty(exports, "ChevronModule", { enumerable: true, get: function () { return chevron_module_1.ChevronModule; } });
|
|
6
6
|
var chevron_service_1 = require("./chevron.service");
|
|
7
7
|
Object.defineProperty(exports, "ChevronService", { enumerable: true, get: function () { return chevron_service_1.ChevronService; } });
|
|
8
8
|
var in_memory_chevron_storage_1 = require("./storage/in-memory-chevron.storage");
|
|
9
9
|
Object.defineProperty(exports, "InMemoryChevronStorage", { enumerable: true, get: function () { return in_memory_chevron_storage_1.InMemoryChevronStorage; } });
|
|
10
|
+
var env_chevron_storage_1 = require("./storage/env-chevron.storage");
|
|
11
|
+
Object.defineProperty(exports, "EnvChevronStorage", { enumerable: true, get: function () { return env_chevron_storage_1.EnvChevronStorage; } });
|
|
10
12
|
var chevron_constants_1 = require("./chevron.constants");
|
|
11
13
|
Object.defineProperty(exports, "DEFAULT_CHEVRON_NAME", { enumerable: true, get: function () { return chevron_constants_1.DEFAULT_CHEVRON_NAME; } });
|
|
12
14
|
var chevron_utils_1 = require("./utils/chevron.utils");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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"}
|
|
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,qEAAkE;AAAzD,wHAAA,iBAAiB,OAAA;AAC1B,yDAA2D;AAAlD,yHAAA,oBAAoB,OAAA;AAC7B,uDAAuE;AAA9D,8GAAA,aAAa,OAAA;AAAE,gHAAA,eAAe,OAAA"}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
export type ChevronMemoryDriverOptions = {
|
|
2
2
|
driver?: 'memory';
|
|
3
3
|
};
|
|
4
|
-
export type
|
|
5
|
-
driver: 'env';
|
|
4
|
+
export type EnvChevronStorageOptions = {
|
|
6
5
|
prefix: string;
|
|
7
|
-
overlay?: boolean;
|
|
8
|
-
nameTransform?: 'camelCase';
|
|
9
6
|
env?: Readonly<Record<string, string | undefined>>;
|
|
10
7
|
};
|
|
11
|
-
export type
|
|
12
|
-
driver: '
|
|
8
|
+
export type ChevronEnvDriverOptions = EnvChevronStorageOptions & {
|
|
9
|
+
driver: 'env';
|
|
13
10
|
};
|
|
14
|
-
export type ChevronStorageDriverOptions = ChevronMemoryDriverOptions | ChevronEnvDriverOptions
|
|
11
|
+
export type ChevronStorageDriverOptions = ChevronMemoryDriverOptions | ChevronEnvDriverOptions;
|
|
15
12
|
//# sourceMappingURL=chevron-driver-options.interface.d.ts.map
|
|
@@ -1 +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,
|
|
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,wBAAwB,GAAG;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;CACtD,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,wBAAwB,GAAG;IAC7D,MAAM,EAAE,KAAK,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG,0BAA0B,GAAG,uBAAuB,CAAC"}
|
|
@@ -2,7 +2,7 @@ import { ConfigurableModuleAsyncOptions, FactoryProvider, ModuleMetadata, Provid
|
|
|
2
2
|
import { ChevronStorage } from './chevron-storage.interface';
|
|
3
3
|
import { FeatureResolver } from './chevron-resolver.type';
|
|
4
4
|
import { ChevronStorageDriverOptions } from './chevron-driver-options.interface';
|
|
5
|
-
export type {
|
|
5
|
+
export type { ChevronEnvDriverOptions, ChevronMemoryDriverOptions, ChevronStorageDriverOptions, } from './chevron-driver-options.interface';
|
|
6
6
|
export type ChevronStorageProviderShorthand = {
|
|
7
7
|
useClass: Type<ChevronStorage>;
|
|
8
8
|
} | {
|
|
@@ -1 +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,
|
|
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,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"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { FeatureValue } from './chevron-resolver.type';
|
|
2
2
|
export interface ChevronStorage {
|
|
3
|
-
get(feature: string
|
|
4
|
-
set(feature: string,
|
|
5
|
-
delete(feature: string
|
|
3
|
+
get(feature: string): FeatureValue | undefined | Promise<FeatureValue | undefined>;
|
|
4
|
+
set(feature: string, value: FeatureValue): void | Promise<void>;
|
|
5
|
+
delete(feature: string): void | Promise<void>;
|
|
6
6
|
purge(features?: string[]): void | Promise<void>;
|
|
7
7
|
destroy?(): void | Promise<void>;
|
|
8
8
|
onModuleDestroy?(): void | Promise<void>;
|
|
@@ -1 +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,
|
|
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,GAAG,YAAY,GAAG,SAAS,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAAC;IAEnF,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhE,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9C,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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { ChevronModuleAsyncOptions, ChevronModuleOptions, ChevronOptionsFactory, ChevronStorageFactory, ChevronStorageProviderShorthand, ChevronStorageRegistration, } from './chevron-options.interface';
|
|
2
2
|
export type { FeatureResolver, FeatureResolverFn, FeatureValue } from './chevron-resolver.type';
|
|
3
3
|
export type { ChevronStorage } from './chevron-storage.interface';
|
|
4
|
-
export type {
|
|
4
|
+
export type { ChevronEnvDriverOptions, ChevronMemoryDriverOptions, ChevronStorageDriverOptions, EnvChevronStorageOptions, } from './chevron-driver-options.interface';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +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,
|
|
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,uBAAuB,EACvB,0BAA0B,EAC1B,2BAA2B,EAC3B,wBAAwB,GAC3B,MAAM,oCAAoC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert-storage-option-keys.d.ts","sourceRoot":"","sources":["../../src/storage/assert-storage-option-keys.ts"],"names":[],"mappings":"AAAA,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAQ5G"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertStorageOptionKeys = assertStorageOptionKeys;
|
|
4
|
+
function assertStorageOptionKeys(options, allowedKeys, label) {
|
|
5
|
+
const allowed = new Set(allowedKeys);
|
|
6
|
+
for (const key of Object.keys(options)) {
|
|
7
|
+
if (!allowed.has(key)) {
|
|
8
|
+
throw new TypeError(`${label} does not accept "${key}".`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=assert-storage-option-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert-storage-option-keys.js","sourceRoot":"","sources":["../../src/storage/assert-storage-option-keys.ts"],"names":[],"mappings":";;AAAA,0DAQC;AARD,SAAgB,uBAAuB,CAAC,OAAe,EAAE,WAA8B,EAAE,KAAa;IAClG,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC;IAErC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACrC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACpB,MAAM,IAAI,SAAS,CAAC,GAAG,KAAK,qBAAqB,GAAG,IAAI,CAAC,CAAC;QAC9D,CAAC;IACL,CAAC;AACL,CAAC"}
|
|
@@ -1 +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;
|
|
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;AAK5E,wBAAgB,6BAA6B,CAAC,YAAY,EAAE,OAAO,GAAG,YAAY,IAAI,2BAA2B,CAUhH;AAED,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,2BAA2B,GAAG,cAAc,CAmBnG"}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isChevronStorageDriverOptions = isChevronStorageDriverOptions;
|
|
4
4
|
exports.createChevronStorageFromDriver = createChevronStorageFromDriver;
|
|
5
|
+
const assert_storage_option_keys_1 = require("./assert-storage-option-keys");
|
|
6
|
+
const env_chevron_storage_1 = require("./env-chevron.storage");
|
|
5
7
|
const in_memory_chevron_storage_1 = require("./in-memory-chevron.storage");
|
|
6
8
|
function isChevronStorageDriverOptions(registration) {
|
|
7
9
|
return (typeof registration === 'object' &&
|
|
@@ -15,26 +17,16 @@ function isChevronStorageDriverOptions(registration) {
|
|
|
15
17
|
function createChevronStorageFromDriver(options) {
|
|
16
18
|
const driver = options.driver ?? 'memory';
|
|
17
19
|
if (driver === 'memory') {
|
|
18
|
-
|
|
20
|
+
(0, assert_storage_option_keys_1.assertStorageOptionKeys)(options, ['driver'], 'Memory storage driver');
|
|
19
21
|
return new in_memory_chevron_storage_1.InMemoryChevronStorage();
|
|
20
22
|
}
|
|
21
|
-
if (driver === 'env') {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
if (options.driver === 'env') {
|
|
24
|
+
(0, assert_storage_option_keys_1.assertStorageOptionKeys)(options, ['driver', 'prefix', 'env'], 'Env storage driver');
|
|
25
|
+
return new env_chevron_storage_1.EnvChevronStorage({
|
|
26
|
+
prefix: options.prefix,
|
|
27
|
+
env: options.env,
|
|
28
|
+
});
|
|
26
29
|
}
|
|
27
30
|
throw new TypeError(`Unknown chevron storage driver "${String(driver)}".`);
|
|
28
31
|
}
|
|
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
32
|
//# sourceMappingURL=create-chevron-storage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-chevron-storage.js","sourceRoot":"","sources":["../../src/storage/create-chevron-storage.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"create-chevron-storage.js","sourceRoot":"","sources":["../../src/storage/create-chevron-storage.ts"],"names":[],"mappings":";;AAKA,sEAUC;AAED,wEAmBC;AAnCD,6EAAuE;AACvE,+DAA0D;AAC1D,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,IAAA,oDAAuB,EAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,EAAE,uBAAuB,CAAC,CAAC;QAEtE,OAAO,IAAI,kDAAsB,EAAE,CAAC;IACxC,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC;QAC3B,IAAA,oDAAuB,EAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,oBAAoB,CAAC,CAAC;QAEpF,OAAO,IAAI,uCAAiB,CAAC;YACzB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,GAAG,EAAE,OAAO,CAAC,GAAG;SACnB,CAAC,CAAC;IACP,CAAC;IAED,MAAM,IAAI,SAAS,CAAC,mCAAmC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC/E,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ChevronStorage, EnvChevronStorageOptions, FeatureValue } from '../interfaces';
|
|
2
|
+
export declare class EnvChevronStorage implements ChevronStorage {
|
|
3
|
+
private readonly memory;
|
|
4
|
+
constructor(options: EnvChevronStorageOptions);
|
|
5
|
+
get(feature: string): FeatureValue | undefined;
|
|
6
|
+
set(feature: string, value: FeatureValue): void;
|
|
7
|
+
delete(feature: string): void;
|
|
8
|
+
purge(features?: string[]): void;
|
|
9
|
+
private fillFromEnv;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=env-chevron.storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-chevron.storage.d.ts","sourceRoot":"","sources":["../../src/storage/env-chevron.storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAMvF,qBAAa,iBAAkB,YAAW,cAAc;IACpD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgC;gBAE3C,OAAO,EAAE,wBAAwB;IAU7C,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAI9C,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI;IAI/C,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAI7B,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI;IAIhC,OAAO,CAAC,WAAW;CA0BtB"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnvChevronStorage = void 0;
|
|
4
|
+
const assert_storage_option_keys_1 = require("./assert-storage-option-keys");
|
|
5
|
+
const in_memory_chevron_storage_1 = require("./in-memory-chevron.storage");
|
|
6
|
+
const NUMERIC_ENV_VALUE = /^-?\d+(?:\.\d+)?$/;
|
|
7
|
+
class EnvChevronStorage {
|
|
8
|
+
memory = new in_memory_chevron_storage_1.InMemoryChevronStorage();
|
|
9
|
+
constructor(options) {
|
|
10
|
+
(0, assert_storage_option_keys_1.assertStorageOptionKeys)(options, ['prefix', 'env'], 'Env storage driver');
|
|
11
|
+
if (typeof options.prefix !== 'string' || options.prefix === '') {
|
|
12
|
+
throw new TypeError('Env storage driver requires a non-empty prefix.');
|
|
13
|
+
}
|
|
14
|
+
this.fillFromEnv(options.prefix, options.env ?? process.env);
|
|
15
|
+
}
|
|
16
|
+
get(feature) {
|
|
17
|
+
return this.memory.get(feature);
|
|
18
|
+
}
|
|
19
|
+
set(feature, value) {
|
|
20
|
+
this.memory.set(feature, value);
|
|
21
|
+
}
|
|
22
|
+
delete(feature) {
|
|
23
|
+
this.memory.delete(feature);
|
|
24
|
+
}
|
|
25
|
+
purge(features) {
|
|
26
|
+
this.memory.purge(features);
|
|
27
|
+
}
|
|
28
|
+
fillFromEnv(prefix, env) {
|
|
29
|
+
const sourceKeys = new Map();
|
|
30
|
+
for (const [key, value] of Object.entries(env)) {
|
|
31
|
+
if (!key.startsWith(prefix) || value === undefined) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const featureName = toCamelCaseFeatureName(key.slice(prefix.length));
|
|
35
|
+
if (featureName === '') {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const existingKey = sourceKeys.get(featureName);
|
|
39
|
+
if (existingKey !== undefined) {
|
|
40
|
+
throw new TypeError(`Env keys "${existingKey}" and "${key}" map to the same feature name "${featureName}".`);
|
|
41
|
+
}
|
|
42
|
+
sourceKeys.set(featureName, key);
|
|
43
|
+
this.memory.set(featureName, coerceEnvValue(value));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.EnvChevronStorage = EnvChevronStorage;
|
|
48
|
+
function toCamelCaseFeatureName(suffix) {
|
|
49
|
+
const segments = suffix.split('_').filter((segment) => segment.length > 0);
|
|
50
|
+
return segments
|
|
51
|
+
.map((segment, index) => {
|
|
52
|
+
const lower = segment.toLowerCase();
|
|
53
|
+
if (index === 0) {
|
|
54
|
+
return lower;
|
|
55
|
+
}
|
|
56
|
+
return lower.slice(0, 1).toUpperCase() + lower.slice(1);
|
|
57
|
+
})
|
|
58
|
+
.join('');
|
|
59
|
+
}
|
|
60
|
+
function coerceEnvValue(value) {
|
|
61
|
+
const trimmed = value.trim();
|
|
62
|
+
if (trimmed === '') {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const token = trimmed.toLowerCase();
|
|
66
|
+
if (token === 'true' || token === '1' || token === 'yes' || token === 'on') {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
if (token === 'false' || token === '0' || token === 'no' || token === 'off') {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
if (NUMERIC_ENV_VALUE.test(trimmed)) {
|
|
73
|
+
return Number(trimmed);
|
|
74
|
+
}
|
|
75
|
+
return trimmed;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=env-chevron.storage.js.map
|