@leyyo/env 1.0.7 → 1.0.9
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.d.ts +2 -2
- package/dist/core/env-core.impl.js +59 -32
- package/dist/core/env-core.impl.js.map +1 -1
- package/dist/core/index.types.d.ts +27 -11
- package/dist/field/env-field.impl.d.ts +61 -31
- package/dist/field/env-field.impl.js +306 -101
- package/dist/field/env-field.impl.js.map +1 -1
- package/dist/field/index.types.d.ts +108 -29
- package/dist/scope/env-scope.impl.d.ts +23 -13
- package/dist/scope/env-scope.impl.js +99 -41
- package/dist/scope/env-scope.impl.js.map +1 -1
- package/dist/scope/index.types.d.ts +29 -14
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/package.json +3 -2
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EnvScopeConfigure, EnvScopeRuntime } from "../scope";
|
|
2
2
|
import type { EnvBase } from "../core";
|
|
3
|
-
import { DevOpt, EnumMap, KeyValue } from "@leyyo/common";
|
|
4
|
-
import { EnumLiteral } from "@leyyo/common/dist/shared/index.types";
|
|
3
|
+
import type { DevOpt, EnumMap, KeyValue } from "@leyyo/common";
|
|
4
|
+
import type { EnumLiteral } from "@leyyo/common/dist/shared/index.types";
|
|
5
5
|
export type EnvFieldCastLambda<E extends EnvBase = EnvBase, Z extends keyof E = keyof E> = (v: unknown) => E[Z];
|
|
6
6
|
export type EnvFieldAssertLambda = (v: unknown) => void;
|
|
7
7
|
export type EnvFieldType = 'string' | 'text' | 'float' | 'integer' | 'boolean' | 'literal' | 'enumeration';
|
|
8
|
-
export type EnvFieldOtaLambda<E extends EnvBase = EnvBase, Z extends keyof E = keyof E> = (field: Z, data: E) => void;
|
|
9
8
|
export interface EnvFieldArray {
|
|
10
9
|
char?: ',' | ';' | '/' | '|' | string;
|
|
11
10
|
min?: number;
|
|
@@ -34,84 +33,164 @@ export interface EnvFieldBoolean {
|
|
|
34
33
|
yes?: string[];
|
|
35
34
|
no?: string[];
|
|
36
35
|
}
|
|
37
|
-
export type EnvFieldPrintTag = 'required' | 'array' | 'secret' | 'ota';
|
|
38
36
|
export interface EnvFieldPrint {
|
|
39
37
|
scope: string;
|
|
40
38
|
key: string;
|
|
41
39
|
value?: any;
|
|
42
40
|
type: EnvFieldType;
|
|
43
|
-
|
|
44
|
-
aliases?: string[];
|
|
41
|
+
opt?: Record<string, unknown>;
|
|
45
42
|
}
|
|
46
|
-
export interface
|
|
43
|
+
export interface EnvFieldConfigure<E extends EnvBase = EnvBase, Z extends keyof E = keyof E> {
|
|
44
|
+
/**
|
|
45
|
+
* Shift to runtime mode
|
|
46
|
+
* */
|
|
47
|
+
get runtime(): EnvFieldRuntime<E, Z>;
|
|
47
48
|
/**
|
|
48
49
|
* Key is required
|
|
49
50
|
* */
|
|
50
|
-
required():
|
|
51
|
+
required(): EnvFieldConfigure<E, Z>;
|
|
52
|
+
/**
|
|
53
|
+
* Key is required or not
|
|
54
|
+
* */
|
|
55
|
+
required(flag: boolean): EnvFieldConfigure<E, Z>;
|
|
56
|
+
/**
|
|
57
|
+
* Key is required by given condition
|
|
58
|
+
* */
|
|
59
|
+
required(fn: EnvFieldOnLambda<E, Z, boolean>): EnvFieldConfigure<E, Z>;
|
|
51
60
|
/**
|
|
52
61
|
* Key is array, so value is split by char
|
|
53
62
|
* */
|
|
54
|
-
array(opt?: EnvFieldArray):
|
|
63
|
+
array(opt?: EnvFieldArray): EnvFieldConfigure<E, Z>;
|
|
55
64
|
/**
|
|
56
65
|
* Key is secret value
|
|
57
66
|
* */
|
|
58
|
-
secret(opt?: EnvFieldSecret):
|
|
67
|
+
secret(opt?: EnvFieldSecret): EnvFieldConfigure<E, Z>;
|
|
68
|
+
/**
|
|
69
|
+
* Cloned key
|
|
70
|
+
* */
|
|
71
|
+
clone(name: string): EnvFieldConfigure<E, Z>;
|
|
59
72
|
/**
|
|
60
73
|
* Set default value
|
|
61
74
|
* */
|
|
62
|
-
def(value: E[Z]):
|
|
75
|
+
def(value: E[Z]): EnvFieldConfigure<E, Z>;
|
|
63
76
|
/**
|
|
64
77
|
* Value may have another aliases
|
|
65
78
|
* */
|
|
66
|
-
alias(...keys: string[]):
|
|
79
|
+
alias(...keys: string[]): EnvFieldConfigure<E, Z>;
|
|
67
80
|
/**
|
|
68
81
|
* Value is string (can be empty)
|
|
69
82
|
* */
|
|
70
|
-
string(opt?: EnvFieldString):
|
|
83
|
+
string(opt?: EnvFieldString): EnvFieldConfigure<E, Z>;
|
|
71
84
|
/**
|
|
72
85
|
* Value is text (can not be empty)
|
|
73
86
|
* */
|
|
74
|
-
text(opt?: EnvFieldString):
|
|
87
|
+
text(opt?: EnvFieldString): EnvFieldConfigure<E, Z>;
|
|
75
88
|
/**
|
|
76
89
|
* Value is float
|
|
77
90
|
* */
|
|
78
|
-
float(opt?: EnvFieldFloat):
|
|
91
|
+
float(opt?: EnvFieldFloat): EnvFieldConfigure<E, Z>;
|
|
79
92
|
/**
|
|
80
93
|
* Value is integer
|
|
81
94
|
* */
|
|
82
|
-
integer(opt?: EnvFieldInteger):
|
|
95
|
+
integer(opt?: EnvFieldInteger): EnvFieldConfigure<E, Z>;
|
|
83
96
|
/**
|
|
84
97
|
* Value is boolean
|
|
85
98
|
* */
|
|
86
|
-
boolean(opt?: EnvFieldBoolean):
|
|
99
|
+
boolean(opt?: EnvFieldBoolean): EnvFieldConfigure<E, Z>;
|
|
87
100
|
/**
|
|
88
101
|
* Value is literal
|
|
89
102
|
* */
|
|
90
|
-
literal<L extends KeyValue = string>(keys: EnumLiteral<L>):
|
|
103
|
+
literal<L extends KeyValue = string>(keys: EnumLiteral<L>): EnvFieldConfigure<E, Z>;
|
|
91
104
|
/**
|
|
92
105
|
* Value is enumeration
|
|
93
106
|
* */
|
|
94
|
-
enumeration<L extends KeyValue = string>(map: EnumMap<L>):
|
|
107
|
+
enumeration<L extends KeyValue = string>(map: EnumMap<L>): EnvFieldConfigure<E, Z>;
|
|
108
|
+
/**
|
|
109
|
+
* Emit an event when ota is occurred
|
|
110
|
+
* */
|
|
111
|
+
onOta(fn?: EnvFieldOnLambda<E, Z, void>): EnvFieldConfigure<E, Z>;
|
|
112
|
+
/**
|
|
113
|
+
* Emit an event when value is changed
|
|
114
|
+
* */
|
|
115
|
+
onChange(fn: EnvFieldOnLambda<E, Z, void>): EnvFieldConfigure<E, Z>;
|
|
116
|
+
/**
|
|
117
|
+
* Emit an event when value is set
|
|
118
|
+
* */
|
|
119
|
+
onSet(fn: EnvFieldOnLambda<E, Z, void>): EnvFieldConfigure<E, Z>;
|
|
95
120
|
/**
|
|
96
|
-
*
|
|
121
|
+
* Set cast function, please take attention
|
|
97
122
|
* */
|
|
98
|
-
|
|
123
|
+
cast(fn: EnvFieldCastLambda<E, Z>): EnvFieldConfigure<E, Z>;
|
|
124
|
+
/**
|
|
125
|
+
* Set asset function, please take attention
|
|
126
|
+
* */
|
|
127
|
+
assert(fn: EnvFieldAssertLambda): EnvFieldConfigure<E, Z>;
|
|
99
128
|
/**
|
|
100
129
|
* Go back to scope
|
|
101
130
|
* */
|
|
102
|
-
end():
|
|
131
|
+
get end(): EnvScopeConfigure<E>;
|
|
132
|
+
}
|
|
133
|
+
export interface EnvFieldRuntime<E extends EnvBase = EnvBase, Z extends keyof E = keyof E> {
|
|
103
134
|
/**
|
|
104
135
|
* Scope
|
|
105
136
|
* */
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
137
|
+
readonly scope: EnvScopeRuntime<E>;
|
|
138
|
+
/**
|
|
139
|
+
* Name of field
|
|
140
|
+
* */
|
|
141
|
+
readonly name: Z;
|
|
142
|
+
/**
|
|
143
|
+
* Shift to configure mode
|
|
144
|
+
* */
|
|
145
|
+
get configure(): EnvFieldConfigure<E, Z>;
|
|
146
|
+
/**
|
|
147
|
+
* Shift to secure mode
|
|
148
|
+
* */
|
|
149
|
+
get $secure(): EnvFieldSecure<E, Z>;
|
|
150
|
+
/**
|
|
151
|
+
* Read value, and call cast (if defined), assert (if defined), onChanged (if changed), onSet (if exists)
|
|
152
|
+
* */
|
|
153
|
+
read(): boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Print value and other settings
|
|
156
|
+
* */
|
|
157
|
+
print(): EnvFieldPrint;
|
|
158
|
+
/**
|
|
159
|
+
* Return raw value
|
|
160
|
+
* */
|
|
161
|
+
get raw(): E[Z] | undefined;
|
|
162
|
+
/**
|
|
163
|
+
* Value is being set from ota
|
|
164
|
+
* */
|
|
165
|
+
fromOta(value: unknown): boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Set value with all controls
|
|
168
|
+
* */
|
|
169
|
+
set(value: E[Z]): void;
|
|
170
|
+
}
|
|
171
|
+
export interface EnvFieldSecure<E extends EnvBase = EnvBase, Z extends keyof E = keyof E> {
|
|
172
|
+
/**
|
|
173
|
+
* Shift to runtime mode
|
|
174
|
+
* */
|
|
175
|
+
get runtime(): EnvFieldRuntime<E, Z>;
|
|
176
|
+
/**
|
|
177
|
+
* Set value without any control
|
|
178
|
+
* */
|
|
179
|
+
$set(value: unknown): void;
|
|
180
|
+
/**
|
|
181
|
+
* Set cast function without any control
|
|
182
|
+
* */
|
|
183
|
+
$cast(fn: EnvFieldCastLambda<E, Z>): void;
|
|
184
|
+
/**
|
|
185
|
+
* Set asset function without any control
|
|
186
|
+
* */
|
|
187
|
+
$assert(fn: EnvFieldAssertLambda): void;
|
|
188
|
+
}
|
|
189
|
+
export interface EnvField<E extends EnvBase = EnvBase, Z extends keyof E = keyof E> extends EnvFieldConfigure<E, Z>, EnvFieldRuntime<E, Z>, EnvFieldSecure<E, Z> {
|
|
112
190
|
}
|
|
113
191
|
export type EnvFieldCastBasicLambda<T> = (value: unknown, opt: DevOpt, required: boolean) => T | undefined;
|
|
114
192
|
export type EnvFieldCastEnumLambda<T extends KeyValue> = (value: unknown, keys: unknown, opt: DevOpt, required: boolean) => T | undefined;
|
|
193
|
+
export type EnvFieldOnLambda<E extends EnvBase = EnvBase, Z extends keyof E = keyof E, R = unknown> = (field: EnvFieldRuntime<E, Z>) => R;
|
|
115
194
|
export interface EnvFieldLambdaItem {
|
|
116
195
|
string: EnvFieldCastBasicLambda<string>;
|
|
117
196
|
text: EnvFieldCastBasicLambda<string>;
|
|
@@ -1,24 +1,34 @@
|
|
|
1
|
-
import type { EnvBase,
|
|
2
|
-
import type {
|
|
3
|
-
import
|
|
1
|
+
import type { EnvBase, EnvCoreRuntime } from "../core";
|
|
2
|
+
import type { EnvFieldConfigure, EnvFieldPrint, EnvFieldRuntime } from "../field";
|
|
3
|
+
import { EnvScope, EnvScopeConfigure, EnvScopeOnLambda, EnvScopeRuntime, EnvScopeSecure } from "./index.types";
|
|
4
4
|
export declare class EnvScopeImpl<E extends EnvBase = EnvBase> implements EnvScope<E> {
|
|
5
|
-
readonly core:
|
|
5
|
+
readonly core: EnvCoreRuntime;
|
|
6
6
|
readonly name: string;
|
|
7
7
|
private _raw;
|
|
8
8
|
private _run;
|
|
9
9
|
private readonly _fields;
|
|
10
10
|
private readonly _otaList;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
private _onOta;
|
|
12
|
+
private _onChangeList;
|
|
13
|
+
private _onSet;
|
|
14
|
+
constructor(core: EnvCoreRuntime, name: string);
|
|
15
|
+
field<Z extends keyof E = keyof E>(name: Z): EnvFieldConfigure<E, Z>;
|
|
16
|
+
uses<E2 extends EnvBase = EnvBase>(scope: string | EnvScopeRuntime<E2>): EnvScopeConfigure<E>;
|
|
17
|
+
onChange(fn: EnvScopeOnLambda<E, void>): EnvScopeConfigure<E>;
|
|
18
|
+
onSet(fn: EnvScopeOnLambda<E, void>): EnvScopeConfigure<E>;
|
|
19
|
+
onOta(fn: EnvScopeOnLambda<E, void>): EnvScopeConfigure<E>;
|
|
20
|
+
get<Z extends keyof E = keyof E>(name: Z): EnvFieldRuntime<E, Z>;
|
|
21
|
+
has<Z extends keyof E = keyof E>(name: Z): boolean;
|
|
22
|
+
read(): void;
|
|
17
23
|
print(): EnvFieldPrint[];
|
|
18
24
|
get raw(): E;
|
|
25
|
+
refresh(): void;
|
|
26
|
+
clear(): void;
|
|
27
|
+
fromOta(values: Partial<E>): void;
|
|
28
|
+
$read(): void;
|
|
19
29
|
$print(): EnvFieldPrint[];
|
|
20
|
-
$run(): void;
|
|
21
|
-
$refresh(): void;
|
|
22
30
|
$addOta(name: keyof E): void;
|
|
23
|
-
|
|
31
|
+
get runtime(): EnvScopeRuntime<E>;
|
|
32
|
+
get configure(): EnvScopeConfigure<E>;
|
|
33
|
+
get $secure(): EnvScopeSecure<E>;
|
|
24
34
|
}
|
|
@@ -4,60 +4,83 @@ exports.EnvScopeImpl = void 0;
|
|
|
4
4
|
const internal_1 = require("../internal");
|
|
5
5
|
const common_1 = require("@leyyo/common");
|
|
6
6
|
const env_field_impl_1 = require("../field/env-field.impl");
|
|
7
|
+
const error_enveloper_1 = require("@leyyo/error-enveloper");
|
|
7
8
|
const WHERE = `${internal_1.FQN}.EnvScopeImpl`;
|
|
8
9
|
class EnvScopeImpl {
|
|
10
|
+
// endregion property
|
|
9
11
|
constructor(core, name) {
|
|
10
12
|
this.core = core;
|
|
11
13
|
this.name = name;
|
|
12
14
|
this._fields = common_1.$repo.newMap(WHERE, 'fields'); // field name x field instance
|
|
13
15
|
this._otaList = common_1.$repo.newArray(WHERE, 'otaList'); // field name
|
|
14
16
|
}
|
|
17
|
+
// region configure
|
|
15
18
|
field(name) {
|
|
16
19
|
common_1.$assert.text(name, () => {
|
|
17
|
-
return {
|
|
20
|
+
return { where: WHERE, scope: this.name, method: 'field' };
|
|
18
21
|
});
|
|
19
22
|
if (this._fields.has(name)) {
|
|
20
|
-
throw common_1.$dev.developerError2(internal_1.FQN, 701, { message: 'Field is duplicated',
|
|
23
|
+
throw common_1.$dev.developerError2(internal_1.FQN, 701, { message: 'Field is duplicated', where: WHERE, scope: this.name, method: 'field', field: name });
|
|
21
24
|
}
|
|
22
25
|
const ins = new env_field_impl_1.EnvFieldImpl(this, name);
|
|
23
26
|
this._fields.set(name, ins);
|
|
24
|
-
this.core.$addKey(name,
|
|
27
|
+
this.core.$secure.$addKey(name, ins);
|
|
25
28
|
return ins;
|
|
26
29
|
}
|
|
27
|
-
get(name) {
|
|
28
|
-
common_1.$assert.text(name, () => {
|
|
29
|
-
return { field: 'name', where: WHERE, scope: this.name };
|
|
30
|
-
});
|
|
31
|
-
if (!this._fields.has(name)) {
|
|
32
|
-
throw common_1.$dev.developerError2(internal_1.FQN, 701, { message: 'Field could not found', field: name, scope: this.name, where: WHERE });
|
|
33
|
-
}
|
|
34
|
-
return this._fields.get(name);
|
|
35
|
-
}
|
|
36
|
-
has(field) {
|
|
37
|
-
common_1.$assert.text(field, () => {
|
|
38
|
-
return { field: 'name', where: WHERE, scope: this.name };
|
|
39
|
-
});
|
|
40
|
-
return this._fields.has(field);
|
|
41
|
-
}
|
|
42
30
|
uses(scope) {
|
|
43
31
|
if (typeof scope === 'string') {
|
|
44
|
-
if (this.core.
|
|
45
|
-
this.core.
|
|
32
|
+
if (this.core.hasScope(scope)) {
|
|
33
|
+
this.core.getScope(scope).$secure.$read();
|
|
46
34
|
}
|
|
47
35
|
else {
|
|
48
36
|
console.warn(`Not found scope: ${scope}`);
|
|
49
37
|
}
|
|
50
38
|
}
|
|
51
39
|
else if (common_1.$is.object(scope) && scope instanceof env_field_impl_1.EnvFieldImpl) {
|
|
52
|
-
scope.$
|
|
40
|
+
scope.$secure.$read();
|
|
53
41
|
}
|
|
54
42
|
else {
|
|
55
43
|
console.warn(`Invalid scope type: ${typeof scope}`);
|
|
56
44
|
}
|
|
57
45
|
return this;
|
|
58
46
|
}
|
|
59
|
-
|
|
60
|
-
this.
|
|
47
|
+
onChange(fn) {
|
|
48
|
+
common_1.$assert.func(fn, { where: WHERE, scope: this.name, method: 'onChange' });
|
|
49
|
+
if (!Array.isArray(this._onChangeList)) {
|
|
50
|
+
this._onChangeList = [];
|
|
51
|
+
}
|
|
52
|
+
this._onChangeList.push(fn);
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
onSet(fn) {
|
|
56
|
+
common_1.$assert.func(fn, { where: WHERE, scope: this.name, method: 'onSet' });
|
|
57
|
+
this._onSet = fn;
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
onOta(fn) {
|
|
61
|
+
common_1.$assert.func(fn, { where: WHERE, scope: this.name, method: 'onOta' });
|
|
62
|
+
this._onOta = fn;
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
// endregion configure
|
|
66
|
+
// region runtime
|
|
67
|
+
get(name) {
|
|
68
|
+
common_1.$assert.text(name, () => {
|
|
69
|
+
return { where: WHERE, scope: this.name, method: 'get' };
|
|
70
|
+
});
|
|
71
|
+
if (!this._fields.has(name)) {
|
|
72
|
+
throw common_1.$dev.developerError2(internal_1.FQN, 701, { message: 'Field could not found', where: WHERE, scope: this.name, method: 'get', field: name });
|
|
73
|
+
}
|
|
74
|
+
return this._fields.get(name);
|
|
75
|
+
}
|
|
76
|
+
has(name) {
|
|
77
|
+
common_1.$assert.text(name, () => {
|
|
78
|
+
return { where: WHERE, scope: this.name, method: 'has' };
|
|
79
|
+
});
|
|
80
|
+
return this._fields.has(name);
|
|
81
|
+
}
|
|
82
|
+
read() {
|
|
83
|
+
this.core.read();
|
|
61
84
|
}
|
|
62
85
|
print() {
|
|
63
86
|
return this.core.print();
|
|
@@ -73,37 +96,72 @@ class EnvScopeImpl {
|
|
|
73
96
|
});
|
|
74
97
|
return this._raw;
|
|
75
98
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
99
|
+
refresh() {
|
|
100
|
+
this._run = false;
|
|
101
|
+
this._raw = undefined;
|
|
79
102
|
}
|
|
80
|
-
|
|
103
|
+
clear() {
|
|
104
|
+
this._raw = undefined;
|
|
105
|
+
}
|
|
106
|
+
fromOta(values) {
|
|
107
|
+
this.refresh();
|
|
108
|
+
if (common_1.$is.bareObject(values)) {
|
|
109
|
+
let changedAny = false;
|
|
110
|
+
for (const [name, value] of Object.entries(values)) {
|
|
111
|
+
const ins = this._fields.get(name);
|
|
112
|
+
if (ins) {
|
|
113
|
+
if (ins.fromOta(value)) {
|
|
114
|
+
changedAny = true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (changedAny && this._onOta) {
|
|
119
|
+
error_enveloper_1.errorEnveloper.handle(() => this._onOta(this), (e) => console.log(`OnOta Error: ${e.message}, where: ${WHERE}, scope: ${this.name}`));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// endregion runtime
|
|
124
|
+
// region secure
|
|
125
|
+
$read() {
|
|
81
126
|
if (this._run) {
|
|
82
127
|
return;
|
|
83
128
|
}
|
|
84
129
|
this._run = true;
|
|
130
|
+
let changedAny = false;
|
|
85
131
|
Array.from(this._fields.values())
|
|
86
|
-
.forEach(ins =>
|
|
132
|
+
.forEach(ins => {
|
|
133
|
+
if (ins.read()) {
|
|
134
|
+
changedAny = true;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
if (changedAny && this._onChangeList) {
|
|
138
|
+
this._onChangeList.forEach(fn => {
|
|
139
|
+
error_enveloper_1.errorEnveloper.handle(() => fn(this), (e) => console.log(`OnChange Error: ${e.message}, where: ${WHERE}, scope: ${this.name}`));
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if (this._onSet) {
|
|
143
|
+
error_enveloper_1.errorEnveloper.handle(() => this._onSet(this), (e) => console.log(`OnSet Error: ${e.message}, where: ${WHERE}, scope: ${this.name}`));
|
|
144
|
+
}
|
|
87
145
|
}
|
|
88
|
-
$
|
|
89
|
-
this.
|
|
90
|
-
|
|
146
|
+
$print() {
|
|
147
|
+
return Array.from(this._fields.values())
|
|
148
|
+
.map(field => field.print());
|
|
91
149
|
}
|
|
92
150
|
$addOta(name) {
|
|
93
151
|
if (!this._otaList.includes(name)) {
|
|
94
152
|
this._otaList.push(name);
|
|
95
153
|
}
|
|
96
154
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
155
|
+
// endregion secure
|
|
156
|
+
// region mode
|
|
157
|
+
get runtime() {
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
get configure() {
|
|
161
|
+
return this;
|
|
162
|
+
}
|
|
163
|
+
get $secure() {
|
|
164
|
+
return this;
|
|
107
165
|
}
|
|
108
166
|
}
|
|
109
167
|
exports.EnvScopeImpl = EnvScopeImpl;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env-scope.impl.js","sourceRoot":"","sources":["../../src/scope/env-scope.impl.ts"],"names":[],"mappings":";;;AAAA,0CAAgC;AAChC,0CAAwD;AACxD,4DAAqD;
|
|
1
|
+
{"version":3,"file":"env-scope.impl.js","sourceRoot":"","sources":["../../src/scope/env-scope.impl.ts"],"names":[],"mappings":";;;AAAA,0CAAgC;AAChC,0CAAwD;AACxD,4DAAqD;AACrD,4DAAsD;AAMtD,MAAM,KAAK,GAAG,GAAG,cAAG,eAAe,CAAC;AAEpC,MAAa,YAAY;IASrB,qBAAqB;IAErB,YAAqB,IAAoB,EAAW,IAAY;QAA3C,SAAI,GAAJ,IAAI,CAAgB;QAAW,SAAI,GAAJ,IAAI,CAAQ;QAP/C,YAAO,GAAG,cAAK,CAAC,MAAM,CAA8B,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,8BAA8B;QACpG,aAAQ,GAAG,cAAK,CAAC,QAAQ,CAAU,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,aAAa;IAOpF,CAAC;IAED,mBAAmB;IACnB,KAAK,CAA8B,IAAO;QACtC,gBAAO,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EA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AEnB,cAAc;IACd,IAAI,OAAO;QACP,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,IAAI,SAAS;QACT,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,IAAI,OAAO;QACP,OAAO,IAAI,CAAC;IAChB,CAAC;CAGJ;AA3LD,oCA2LC"}
|
|
@@ -1,19 +1,34 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { EnvBase,
|
|
3
|
-
export interface
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
uses(scope:
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import type { EnvFieldConfigure, EnvFieldPrint, EnvFieldRuntime } from "../field";
|
|
2
|
+
import type { EnvBase, EnvCoreRuntime } from "../core";
|
|
3
|
+
export interface EnvScopeConfigure<E extends EnvBase = EnvBase> {
|
|
4
|
+
get runtime(): EnvScopeRuntime<E>;
|
|
5
|
+
field<Z extends keyof E = keyof E>(name: Z): EnvFieldConfigure<E, Z>;
|
|
6
|
+
uses(scope: string): EnvScopeConfigure<E>;
|
|
7
|
+
uses<E2 extends EnvBase = EnvBase>(scope: EnvScopeRuntime<E2>): EnvScopeConfigure<E>;
|
|
8
|
+
onChange(fn: EnvScopeOnLambda<E, void>): EnvScopeConfigure<E>;
|
|
9
|
+
onSet(fn: EnvScopeOnLambda<E, void>): EnvScopeConfigure<E>;
|
|
10
|
+
onOta(fn: EnvScopeOnLambda<E, void>): EnvScopeConfigure<E>;
|
|
11
|
+
}
|
|
12
|
+
export interface EnvScopeRuntime<E extends EnvBase = EnvBase> {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly core: EnvCoreRuntime;
|
|
15
|
+
get configure(): EnvScopeConfigure<E>;
|
|
16
|
+
get $secure(): EnvScopeSecure<E>;
|
|
17
|
+
get<Z extends keyof E = keyof E>(name: Z): EnvFieldRuntime<E, Z>;
|
|
18
|
+
has<Z extends keyof E = keyof E>(name: Z): boolean;
|
|
19
|
+
read(): void;
|
|
10
20
|
print(): EnvFieldPrint[];
|
|
11
21
|
get raw(): E;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
22
|
+
refresh(): void;
|
|
23
|
+
clear(): void;
|
|
24
|
+
fromOta(values: Partial<E>): void;
|
|
25
|
+
}
|
|
26
|
+
export interface EnvScopeSecure<E extends EnvBase = EnvBase> {
|
|
27
|
+
get runtime(): EnvScopeRuntime<E>;
|
|
28
|
+
$read(): void;
|
|
15
29
|
$print(): EnvFieldPrint[];
|
|
16
|
-
$refresh(): void;
|
|
17
|
-
$fromOta(values: Partial<E>): void;
|
|
18
30
|
$addOta(name: keyof E): void;
|
|
19
31
|
}
|
|
32
|
+
export interface EnvScope<E extends EnvBase = EnvBase> extends EnvScopeConfigure<E>, EnvScopeRuntime<E>, EnvScopeSecure<E> {
|
|
33
|
+
}
|
|
34
|
+
export type EnvScopeOnLambda<E extends EnvBase = EnvBase, R = unknown> = (scope: EnvScopeRuntime<E>) => R;
|
package/dist/server.js
CHANGED
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;AAAA,iCAA+B;AAE/B,cAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;AAAA,iCAA+B;AAE/B,cAAO,CAAC,IAAI,EAAE,CAAC;AACf,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leyyo/env",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "Environment library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"env",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"typescript": "^5.7.3"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@leyyo/common": "^1.0.13"
|
|
54
|
+
"@leyyo/common": "^1.0.13",
|
|
55
|
+
"@leyyo/error-enveloper": "^1.0.3"
|
|
55
56
|
}
|
|
56
57
|
}
|