@leyyo/env 1.0.13 → 1.2.1
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/dist/core/env-core.impl.js +50 -26
- package/dist/core/env-core.impl.js.map +1 -1
- package/dist/core/environment.error.d.ts +12 -0
- package/dist/core/environment.error.js +19 -0
- package/dist/core/environment.error.js.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.types.d.ts +120 -10
- package/dist/field/env-field.impl.d.ts +34 -38
- package/dist/field/env-field.impl.js +112 -151
- package/dist/field/env-field.impl.js.map +1 -1
- package/dist/field/index.types.d.ts +112 -80
- package/dist/scope/env-scope.impl.d.ts +28 -20
- package/dist/scope/env-scope.impl.js +113 -46
- package/dist/scope/env-scope.impl.js.map +1 -1
- package/dist/scope/index.types.d.ts +317 -21
- package/package.json +4 -3
|
@@ -38,61 +38,77 @@ const internal_1 = require("../internal");
|
|
|
38
38
|
const env_scope_impl_1 = require("../scope/env-scope.impl");
|
|
39
39
|
const common_1 = require("@leyyo/common");
|
|
40
40
|
const util = __importStar(require("node:util"));
|
|
41
|
+
const environment_error_1 = require("./environment.error");
|
|
42
|
+
const type_1 = require("@leyyo/type");
|
|
41
43
|
const WHERE = `${internal_1.FQN}.EnvCore`;
|
|
44
|
+
/**
|
|
45
|
+
* Environment core class
|
|
46
|
+
* */
|
|
42
47
|
class EnvCoreImpl {
|
|
43
48
|
// endregion property
|
|
44
49
|
constructor() {
|
|
45
50
|
// region property
|
|
51
|
+
/**
|
|
52
|
+
* Stores scopes with name
|
|
53
|
+
* */
|
|
46
54
|
this._scopes = common_1.$repo.newMap(internal_1.FQN, 'scopes'); // scope name x scope instance
|
|
55
|
+
/**
|
|
56
|
+
* Stores fields with full name
|
|
57
|
+
* */
|
|
47
58
|
this._keys = common_1.$repo.newMap(internal_1.FQN, 'keys'); // field name x scope name[]
|
|
48
59
|
}
|
|
49
60
|
// region configure
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
});
|
|
61
|
+
/** @inheritDoc */
|
|
62
|
+
scope(name, prefix) {
|
|
63
|
+
(0, type_1.assertText)(name, () => common_1.$opt.fn({ field: 'name', where: WHERE, method: 'scope' }));
|
|
54
64
|
if (this._scopes.has(name)) {
|
|
55
|
-
throw
|
|
65
|
+
throw new environment_error_1.EnvironmentError('scope.duplicated', `Scope[${name}] is duplicated`, { value: name, where: WHERE, method: 'scope' });
|
|
66
|
+
}
|
|
67
|
+
if (prefix) {
|
|
68
|
+
(0, type_1.assertText)(prefix, () => common_1.$opt.fn({ where: WHERE, scope: name, method: 'scope', field: 'prefix' }));
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
prefix = undefined;
|
|
56
72
|
}
|
|
57
|
-
const ins = new env_scope_impl_1.EnvScopeImpl(this, name);
|
|
73
|
+
const ins = new env_scope_impl_1.EnvScopeImpl(this, name, prefix, undefined);
|
|
58
74
|
this._scopes.set(name, ins);
|
|
59
75
|
return ins;
|
|
60
76
|
}
|
|
61
77
|
// endregion configure
|
|
62
78
|
// region runtime
|
|
79
|
+
/** @inheritDoc */
|
|
63
80
|
getScope(name) {
|
|
64
|
-
|
|
65
|
-
return { where: WHERE, method: 'getScope' };
|
|
66
|
-
});
|
|
81
|
+
(0, type_1.assertText)(name, () => common_1.$opt.fn({ field: 'scope', where: WHERE, method: 'getScope' }));
|
|
67
82
|
if (!this._scopes.has(name)) {
|
|
68
|
-
throw
|
|
83
|
+
throw new environment_error_1.EnvironmentError('scope.not.found', `Scope[${name}] could not found`, { value: name, where: WHERE, method: 'getScope' });
|
|
69
84
|
}
|
|
70
85
|
return this._scopes.get(name);
|
|
71
86
|
}
|
|
87
|
+
/** @inheritDoc */
|
|
72
88
|
hasScope(name) {
|
|
73
|
-
|
|
74
|
-
return { where: WHERE, method: 'hasScope' };
|
|
75
|
-
});
|
|
89
|
+
(0, type_1.assertText)(name, () => common_1.$opt.fn({ field: 'scope', where: WHERE, method: 'hasScope' }));
|
|
76
90
|
return this._scopes.has(name);
|
|
77
91
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
throw common_1.$dev.developerError2(internal_1.FQN, 701, { message: 'Key could not found', key: name, where: WHERE });
|
|
92
|
+
/** @inheritDoc */
|
|
93
|
+
getKey(key) {
|
|
94
|
+
(0, type_1.assertText)(key, () => common_1.$opt.fn({ field: 'key', where: WHERE, method: 'getKey' }));
|
|
95
|
+
if (!this._keys.has(key)) {
|
|
96
|
+
throw new environment_error_1.EnvironmentError('field.not.found', `Key[${key}] could not found`, { value: key, where: WHERE, method: 'getKey' });
|
|
84
97
|
}
|
|
85
|
-
return this._keys.get(
|
|
98
|
+
return this._keys.get(key);
|
|
86
99
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
100
|
+
/** @inheritDoc */
|
|
101
|
+
hasKey(key) {
|
|
102
|
+
(0, type_1.assertText)(key, () => {
|
|
103
|
+
return { field: key, where: WHERE, method: 'hasKey' };
|
|
90
104
|
});
|
|
91
|
-
return this._keys.has(
|
|
105
|
+
return this._keys.has(key);
|
|
92
106
|
}
|
|
93
|
-
|
|
107
|
+
/** @inheritDoc */
|
|
108
|
+
get allValues() {
|
|
94
109
|
return JSON.parse(JSON.stringify(process.env));
|
|
95
110
|
}
|
|
111
|
+
/** @inheritDoc */
|
|
96
112
|
get keys() {
|
|
97
113
|
const doc = {};
|
|
98
114
|
for (const [key, value] of this._keys.entries()) {
|
|
@@ -100,13 +116,16 @@ class EnvCoreImpl {
|
|
|
100
116
|
}
|
|
101
117
|
return doc;
|
|
102
118
|
}
|
|
119
|
+
/** @inheritDoc */
|
|
103
120
|
get scopes() {
|
|
104
121
|
return Array.from(this._scopes.values());
|
|
105
122
|
}
|
|
123
|
+
/** @inheritDoc */
|
|
106
124
|
read() {
|
|
107
125
|
Array.from(this._scopes.values())
|
|
108
126
|
.forEach(ins => ins.$secure.$read());
|
|
109
127
|
}
|
|
128
|
+
/** @inheritDoc */
|
|
110
129
|
print(asObject) {
|
|
111
130
|
const result = [];
|
|
112
131
|
Array.from(this._scopes.values())
|
|
@@ -116,8 +135,9 @@ class EnvCoreImpl {
|
|
|
116
135
|
}
|
|
117
136
|
return util.inspect(result, { showHidden: false, depth: null, colors: true });
|
|
118
137
|
}
|
|
138
|
+
/** @inheritDoc */
|
|
119
139
|
fromOta(values) {
|
|
120
|
-
if (
|
|
140
|
+
if ((0, type_1.isObjectBare)(values)) {
|
|
121
141
|
const scopeMap = {};
|
|
122
142
|
for (const [key, value] of Object.entries(values)) {
|
|
123
143
|
if (this._keys.has(key)) {
|
|
@@ -141,6 +161,7 @@ class EnvCoreImpl {
|
|
|
141
161
|
}
|
|
142
162
|
// endregion runtime
|
|
143
163
|
// region secure
|
|
164
|
+
/** @inheritDoc */
|
|
144
165
|
$addKey(key, field, alternative) {
|
|
145
166
|
var _a;
|
|
146
167
|
if (this._keys.has(key)) {
|
|
@@ -151,12 +172,15 @@ class EnvCoreImpl {
|
|
|
151
172
|
}
|
|
152
173
|
// endregion secure
|
|
153
174
|
// region mode
|
|
175
|
+
/** @inheritDoc */
|
|
154
176
|
get runtime() {
|
|
155
177
|
return this;
|
|
156
178
|
}
|
|
179
|
+
/** @inheritDoc */
|
|
157
180
|
get configure() {
|
|
158
181
|
return this;
|
|
159
182
|
}
|
|
183
|
+
/** @inheritDoc */
|
|
160
184
|
get $secure() {
|
|
161
185
|
return this;
|
|
162
186
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env-core.impl.js","sourceRoot":"","sources":["../../src/core/env-core.impl.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAAgC;AAChC,4DAAqD;AACrD,
|
|
1
|
+
{"version":3,"file":"env-core.impl.js","sourceRoot":"","sources":["../../src/core/env-core.impl.ts"],"names":[],"mappings":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;IAChB,CAAC;IAED,kBAAkB;IAClB,IAAI,SAAS;QACT,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,kBAAkB;IAClB,IAAI,OAAO;QACP,OAAO,IAAI,CAAC;IAChB,CAAC;CAEJ;AAEY,QAAA,OAAO,GAAmB,IAAI,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LeyyoError, type Opt } from "@leyyo/common";
|
|
2
|
+
/**
|
|
3
|
+
* Environment error
|
|
4
|
+
* */
|
|
5
|
+
export declare class EnvironmentError extends LeyyoError {
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} issue - error code or issue code
|
|
8
|
+
* @param {string} message - error message
|
|
9
|
+
* @param {Opt} params - error parameters
|
|
10
|
+
* */
|
|
11
|
+
constructor(issue: string, message?: string, params?: Opt);
|
|
12
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnvironmentError = void 0;
|
|
4
|
+
const common_1 = require("@leyyo/common");
|
|
5
|
+
/**
|
|
6
|
+
* Environment error
|
|
7
|
+
* */
|
|
8
|
+
class EnvironmentError extends common_1.LeyyoError {
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} issue - error code or issue code
|
|
11
|
+
* @param {string} message - error message
|
|
12
|
+
* @param {Opt} params - error parameters
|
|
13
|
+
* */
|
|
14
|
+
constructor(issue, message, params) {
|
|
15
|
+
super(message !== null && message !== void 0 ? message : issue, Object.assign(Object.assign({}, params), { issue }));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.EnvironmentError = EnvironmentError;
|
|
19
|
+
//# sourceMappingURL=environment.error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.error.js","sourceRoot":"","sources":["../../src/core/environment.error.ts"],"names":[],"mappings":";;;AAAA,0CAAmD;AAEnD;;KAEK;AACL,MAAa,gBAAiB,SAAQ,mBAAU;IAE5C;;;;SAIK;IACL,YAAY,KAAa,EAAE,OAAgB,EAAE,MAAY;QACrD,KAAK,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,KAAK,kCAAM,MAAM,KAAE,KAAK,IAAE,CAAC;IAChD,CAAC;CACJ;AAVD,4CAUC"}
|
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.js
CHANGED
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./index.types"), exports);
|
|
18
18
|
__exportStar(require("./env-core.impl"), exports);
|
|
19
|
+
__exportStar(require("./environment.error"), exports);
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,kDAAgC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,kDAAgC;AAChC,sDAAoC"}
|
|
@@ -1,31 +1,141 @@
|
|
|
1
|
-
import { EnvScopeConfigure, EnvScopePrint, EnvScopeRuntime } from "../scope";
|
|
1
|
+
import type { EnvScopeConfigure, EnvScopePrint, EnvScopeRuntime } from "../scope";
|
|
2
2
|
import type { EnvFieldRuntime } from "../field";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Environment base object
|
|
5
|
+
* */
|
|
6
|
+
export type EnvBase = {};
|
|
7
|
+
/**
|
|
8
|
+
* Environment core, configure mode
|
|
9
|
+
* */
|
|
4
10
|
export interface EnvCoreConfigure {
|
|
11
|
+
/**
|
|
12
|
+
* Shift to runtime mode
|
|
13
|
+
*
|
|
14
|
+
* @return {EnvCoreRuntime} - runtime mode
|
|
15
|
+
* */
|
|
5
16
|
get runtime(): EnvCoreRuntime;
|
|
6
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Create new scope
|
|
19
|
+
*
|
|
20
|
+
* @param {string} name - name of scope
|
|
21
|
+
* @param {string} prefix - prefix of scope
|
|
22
|
+
* @return {EnvScopeConfigure} - created scope instance
|
|
23
|
+
* */
|
|
24
|
+
scope<C extends EnvBase, P extends string>(name: string, prefix?: P): EnvScopeConfigure<C, P>;
|
|
7
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Environment core, runtime mode
|
|
28
|
+
* */
|
|
8
29
|
export interface EnvCoreRuntime {
|
|
30
|
+
/**
|
|
31
|
+
* Shift to `configure` mode
|
|
32
|
+
* */
|
|
9
33
|
get configure(): EnvCoreConfigure;
|
|
34
|
+
/**
|
|
35
|
+
* Shift to `secure` mode
|
|
36
|
+
* */
|
|
10
37
|
get $secure(): EnvCoreSecure;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Get scope
|
|
40
|
+
*
|
|
41
|
+
* @param {string} scope - scope name
|
|
42
|
+
* @return {EnvScopeRuntime}
|
|
43
|
+
* */
|
|
44
|
+
getScope<C extends EnvBase = EnvBase, P extends string = string, A extends string = undefined>(scope: string): EnvScopeRuntime<C, P, A>;
|
|
45
|
+
/**
|
|
46
|
+
* Has scope?
|
|
47
|
+
*
|
|
48
|
+
* @param {string} scope - scope name
|
|
49
|
+
* @return {boolean}
|
|
50
|
+
* */
|
|
51
|
+
hasScope(scope: string): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Get key
|
|
54
|
+
*
|
|
55
|
+
* @param {string} key - key name in dot-env
|
|
56
|
+
* @return {EnvCoreKeyRec}
|
|
57
|
+
* */
|
|
58
|
+
getKey(key: string): EnvCoreKeyRec;
|
|
59
|
+
/**
|
|
60
|
+
* Has key?
|
|
61
|
+
*
|
|
62
|
+
* @param {string} key - key name
|
|
63
|
+
* @return {boolean}
|
|
64
|
+
* */
|
|
65
|
+
hasKey(key: string): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Return all values
|
|
68
|
+
*
|
|
69
|
+
* @return {EnvBase}
|
|
70
|
+
* */
|
|
71
|
+
get allValues(): EnvBase;
|
|
72
|
+
/**
|
|
73
|
+
* Return keys
|
|
74
|
+
*
|
|
75
|
+
* @return {Record}
|
|
76
|
+
* */
|
|
16
77
|
get keys(): Record<string, EnvCoreKeyRec>;
|
|
78
|
+
/**
|
|
79
|
+
* Return scopes
|
|
80
|
+
*
|
|
81
|
+
* @return {EnvScopeRuntime[]}
|
|
82
|
+
* */
|
|
17
83
|
get scopes(): EnvScopeRuntime[];
|
|
84
|
+
/**
|
|
85
|
+
* Read values from dot-env
|
|
86
|
+
*
|
|
87
|
+
* @return {EnvScopeRuntime[]}
|
|
88
|
+
* */
|
|
18
89
|
read(): void;
|
|
90
|
+
/**
|
|
91
|
+
* Print all environments
|
|
92
|
+
*
|
|
93
|
+
* @return {(string|EnvScopePrint[])}
|
|
94
|
+
* */
|
|
19
95
|
print(asObject?: boolean): string | EnvScopePrint[];
|
|
96
|
+
/**
|
|
97
|
+
* Read from OTA
|
|
98
|
+
*
|
|
99
|
+
* @param {EnvBase} values - incoming env data
|
|
100
|
+
* */
|
|
20
101
|
fromOta(values: EnvBase): void;
|
|
21
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Environment core, secure mode
|
|
105
|
+
* */
|
|
22
106
|
export interface EnvCoreSecure {
|
|
107
|
+
/**
|
|
108
|
+
* Return runtime value
|
|
109
|
+
* */
|
|
23
110
|
get runtime(): EnvCoreRuntime;
|
|
24
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Add key into repository
|
|
113
|
+
*
|
|
114
|
+
* @param {string} key - key name
|
|
115
|
+
* @param {EnvFieldRuntime} field - field structure
|
|
116
|
+
* @param {string?} alternative - alternative name
|
|
117
|
+
* */
|
|
118
|
+
$addKey(key: string, field: EnvFieldRuntime<EnvBase, string, undefined>, alternative?: string): void;
|
|
25
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Environment core, all modes
|
|
122
|
+
* */
|
|
26
123
|
export interface EnvCore extends EnvCoreConfigure, EnvCoreRuntime, EnvCoreSecure {
|
|
27
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Basic record for any field
|
|
127
|
+
* */
|
|
28
128
|
export interface EnvCoreKeyRec {
|
|
29
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Key instance
|
|
131
|
+
*
|
|
132
|
+
* @type {EnvFieldRuntime}
|
|
133
|
+
* */
|
|
134
|
+
field: EnvFieldRuntime<EnvBase, string, undefined>;
|
|
135
|
+
/**
|
|
136
|
+
* Alternative name
|
|
137
|
+
*
|
|
138
|
+
* @type {string?}
|
|
139
|
+
* */
|
|
30
140
|
alternative?: string;
|
|
31
141
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { EnvField,
|
|
2
|
-
import
|
|
1
|
+
import type { EnvField, EnvFieldConfigure, EnvFieldOnLambda, EnvFieldPrint, EnvFieldRuntime, EnvFieldSecure } from "./index.types";
|
|
2
|
+
import { EnvScopeConfigure, EnvScopeRuntime, EnvVariation, EnvVariationValue } from "../scope";
|
|
3
3
|
import type { EnvBase } from "../core";
|
|
4
|
-
import type { EnumMap, KeyValue
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import type { EnumLiteral, EnumMap, KeyValue } from "@leyyo/common";
|
|
5
|
+
import { type AssertBasicFn, type ToLambda } from "@leyyo/type";
|
|
6
|
+
export declare class EnvFieldImpl<C extends EnvBase = EnvBase, P extends string = string, A extends string = undefined, Z extends keyof C = keyof C> implements EnvField<C, P, A, Z> {
|
|
7
|
+
readonly scope: EnvScopeRuntime<C, P, A>;
|
|
7
8
|
readonly name: Z;
|
|
8
9
|
private _required;
|
|
9
10
|
private _requiredFn;
|
|
@@ -12,10 +13,8 @@ export declare class EnvFieldImpl<E extends EnvBase = EnvBase, Z extends keyof E
|
|
|
12
13
|
private _def;
|
|
13
14
|
private _clone;
|
|
14
15
|
private _secret;
|
|
15
|
-
private _secretOpt;
|
|
16
16
|
private _aliases;
|
|
17
17
|
private _array;
|
|
18
|
-
private _arrayOpt;
|
|
19
18
|
private _initialized;
|
|
20
19
|
private _type;
|
|
21
20
|
private _typeOpt;
|
|
@@ -23,56 +22,53 @@ export declare class EnvFieldImpl<E extends EnvBase = EnvBase, Z extends keyof E
|
|
|
23
22
|
private _onChangeList;
|
|
24
23
|
private _onSet;
|
|
25
24
|
private _value;
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
readonly full: keyof EnvVariation<C, P, A>;
|
|
26
|
+
constructor(scope: EnvScopeRuntime<C, P, A>, name: Z);
|
|
28
27
|
private get _f();
|
|
29
|
-
private _removeOpt;
|
|
30
|
-
private _setOrRemoveOpt;
|
|
31
28
|
private get _devOne();
|
|
32
|
-
private _devMore;
|
|
33
29
|
private get _findRequired();
|
|
34
30
|
private _initialize;
|
|
35
31
|
private get _fromDef();
|
|
36
32
|
private get _plainValue();
|
|
37
33
|
/** {@inheritDoc} */
|
|
38
|
-
required(p1?: boolean | EnvFieldOnLambda<
|
|
34
|
+
required(p1?: boolean | EnvFieldOnLambda<C, P, A, Z, boolean>): EnvFieldConfigure<C, P, A, Z>;
|
|
39
35
|
/** {@inheritDoc} */
|
|
40
|
-
array(
|
|
36
|
+
array(): EnvFieldConfigure<C, P, A, Z>;
|
|
41
37
|
/** {@inheritDoc} */
|
|
42
|
-
secret(
|
|
43
|
-
clone(name: string): EnvFieldConfigure<
|
|
38
|
+
secret(): EnvFieldConfigure<C, P, A, Z>;
|
|
39
|
+
clone(name: string): EnvFieldConfigure<C, P, A, Z>;
|
|
44
40
|
/** {@inheritDoc} */
|
|
45
|
-
def(value:
|
|
41
|
+
def(value: C[Z] | EnvFieldOnLambda<C, P, A, Z, C[Z]>): EnvFieldConfigure<C, P, A, Z>;
|
|
46
42
|
/** {@inheritDoc} */
|
|
47
|
-
alias(...keys: string[]): EnvFieldConfigure<
|
|
43
|
+
alias(...keys: string[]): EnvFieldConfigure<C, P, A, Z>;
|
|
48
44
|
/** {@inheritDoc} */
|
|
49
|
-
string(
|
|
45
|
+
string(): EnvFieldConfigure<C, P, A, Z>;
|
|
50
46
|
/** {@inheritDoc} */
|
|
51
|
-
text(
|
|
47
|
+
text(): EnvFieldConfigure<C, P, A, Z>;
|
|
52
48
|
/** {@inheritDoc} */
|
|
53
|
-
float(
|
|
49
|
+
float(): EnvFieldConfigure<C, P, A, Z>;
|
|
54
50
|
/** {@inheritDoc} */
|
|
55
|
-
integer(
|
|
51
|
+
integer(): EnvFieldConfigure<C, P, A, Z>;
|
|
56
52
|
/** {@inheritDoc} */
|
|
57
|
-
boolean(
|
|
53
|
+
boolean(): EnvFieldConfigure<C, P, A, Z>;
|
|
58
54
|
/** {@inheritDoc} */
|
|
59
|
-
literal<L extends KeyValue = string>(keys: EnumLiteral<L>): EnvFieldConfigure<
|
|
55
|
+
literal<L extends KeyValue = string>(keys: EnumLiteral<L>): EnvFieldConfigure<C, P, A, Z>;
|
|
60
56
|
/** {@inheritDoc} */
|
|
61
|
-
enumeration<L extends KeyValue = string>(map: EnumMap<L>): EnvFieldConfigure<
|
|
57
|
+
enumeration<L extends KeyValue = string>(map: EnumMap<L>): EnvFieldConfigure<C, P, A, Z>;
|
|
62
58
|
/** {@inheritDoc} */
|
|
63
|
-
onOta(fn?: EnvFieldOnLambda<
|
|
59
|
+
onOta(fn?: EnvFieldOnLambda<C, P, A, Z, void>): EnvFieldConfigure<C, P, A, Z>;
|
|
64
60
|
/** {@inheritDoc} */
|
|
65
|
-
onChange(fn: EnvFieldOnLambda<
|
|
61
|
+
onChange(fn: EnvFieldOnLambda<C, P, A, Z, void>): EnvFieldConfigure<C, P, A, Z>;
|
|
66
62
|
/** {@inheritDoc} */
|
|
67
|
-
onSet(fn: EnvFieldOnLambda<
|
|
63
|
+
onSet(fn: EnvFieldOnLambda<C, P, A, Z, void>): EnvFieldConfigure<C, P, A, Z>;
|
|
68
64
|
/** {@inheritDoc} */
|
|
69
|
-
cast(fn:
|
|
65
|
+
cast(fn: ToLambda<C[Z]>): EnvFieldConfigure<C, P, A, Z>;
|
|
70
66
|
/** {@inheritDoc} */
|
|
71
|
-
assert(fn:
|
|
67
|
+
assert(fn: AssertBasicFn): EnvFieldConfigure<C, P, A, Z>;
|
|
72
68
|
/** {@inheritDoc} */
|
|
73
|
-
|
|
69
|
+
end(): EnvScopeConfigure<C, P, A>;
|
|
74
70
|
/** {@inheritDoc} */
|
|
75
|
-
set(value:
|
|
71
|
+
set(value: C[Z]): void;
|
|
76
72
|
private _printValue;
|
|
77
73
|
/** {@inheritDoc} */
|
|
78
74
|
print(): EnvFieldPrint;
|
|
@@ -81,13 +77,13 @@ export declare class EnvFieldImpl<E extends EnvBase = EnvBase, Z extends keyof E
|
|
|
81
77
|
/** {@inheritDoc} */
|
|
82
78
|
fromOta(value: unknown): boolean;
|
|
83
79
|
/** {@inheritDoc} */
|
|
84
|
-
get
|
|
80
|
+
get value(): EnvVariationValue<C, P, A, Z> | undefined;
|
|
85
81
|
$set(value: unknown): void;
|
|
86
|
-
$cast(fn:
|
|
87
|
-
$assert(fn:
|
|
82
|
+
$cast(fn: ToLambda<C[Z]>): void;
|
|
83
|
+
$assert(fn: AssertBasicFn): void;
|
|
88
84
|
/** {@inheritDoc} */
|
|
89
|
-
get configure(): EnvFieldConfigure<
|
|
85
|
+
get configure(): EnvFieldConfigure<C, P, A, Z>;
|
|
90
86
|
/** {@inheritDoc} */
|
|
91
|
-
get runtime(): EnvFieldRuntime<
|
|
92
|
-
get $secure(): EnvFieldSecure<
|
|
87
|
+
get runtime(): EnvFieldRuntime<C, P, A, Z>;
|
|
88
|
+
get $secure(): EnvFieldSecure<C, P, A, Z>;
|
|
93
89
|
}
|