@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
|
@@ -1,152 +1,165 @@
|
|
|
1
|
-
import type { EnvScopeConfigure, EnvScopeRuntime } from "../scope";
|
|
1
|
+
import type { EnvScopeConfigure, EnvScopeRuntime, EnvVariation, EnvVariationValue } from "../scope";
|
|
2
2
|
import type { EnvBase } from "../core";
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import type { EnumLiteral, EnumMap, KeyValue } from "@leyyo/common";
|
|
4
|
+
import type { AssertBasicFn, ToLambda } from "@leyyo/type";
|
|
5
|
+
/**
|
|
6
|
+
* Field types
|
|
7
|
+
* */
|
|
7
8
|
export type EnvFieldType = 'string' | 'text' | 'float' | 'integer' | 'boolean' | 'literal' | 'enumeration';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
max?: number;
|
|
12
|
-
unique?: boolean;
|
|
13
|
-
}
|
|
14
|
-
export interface EnvFieldSecret {
|
|
15
|
-
type?: EnvFieldSecretType;
|
|
16
|
-
}
|
|
17
|
-
export type EnvFieldSecretType = 'password' | 'token' | 'private-key' | 'public-key' | 'api-key' | 'host';
|
|
18
|
-
export interface EnvFieldString {
|
|
19
|
-
min?: number;
|
|
20
|
-
max?: number;
|
|
21
|
-
pattern?: string | RegExp;
|
|
22
|
-
}
|
|
23
|
-
export interface EnvFieldFloat {
|
|
24
|
-
min?: number;
|
|
25
|
-
max?: number;
|
|
26
|
-
}
|
|
27
|
-
export interface EnvFieldInteger {
|
|
28
|
-
min?: number;
|
|
29
|
-
max?: number;
|
|
30
|
-
modulus?: number;
|
|
31
|
-
}
|
|
32
|
-
export interface EnvFieldBoolean {
|
|
33
|
-
yes?: string[];
|
|
34
|
-
no?: string[];
|
|
35
|
-
}
|
|
9
|
+
/**
|
|
10
|
+
* Printable field object
|
|
11
|
+
* */
|
|
36
12
|
export interface EnvFieldPrint {
|
|
13
|
+
/**
|
|
14
|
+
* Name of scope
|
|
15
|
+
* */
|
|
37
16
|
scope: string;
|
|
17
|
+
/**
|
|
18
|
+
* Key of field
|
|
19
|
+
* */
|
|
38
20
|
key: string;
|
|
21
|
+
/**
|
|
22
|
+
* Value of field
|
|
23
|
+
* */
|
|
39
24
|
value?: any;
|
|
25
|
+
/**
|
|
26
|
+
* Type of field
|
|
27
|
+
* */
|
|
40
28
|
type: EnvFieldType;
|
|
29
|
+
/**
|
|
30
|
+
* Other info about field
|
|
31
|
+
* */
|
|
41
32
|
opt?: Record<string, unknown>;
|
|
42
33
|
}
|
|
43
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Environment field, configuration mode
|
|
36
|
+
*
|
|
37
|
+
* Generics:
|
|
38
|
+
* - C: Environment interface
|
|
39
|
+
* - P: Prefix for environment
|
|
40
|
+
* - A: Variation
|
|
41
|
+
* - Z: field name
|
|
42
|
+
* */
|
|
43
|
+
export interface EnvFieldConfigure<C extends EnvBase, P extends string, A extends string, Z extends keyof C = keyof C> {
|
|
44
44
|
/**
|
|
45
45
|
* Shift to runtime mode
|
|
46
46
|
* */
|
|
47
|
-
get runtime(): EnvFieldRuntime<
|
|
47
|
+
get runtime(): EnvFieldRuntime<C, P, A, Z>;
|
|
48
48
|
/**
|
|
49
49
|
* Key is required
|
|
50
50
|
* */
|
|
51
|
-
required(): EnvFieldConfigure<
|
|
51
|
+
required(): EnvFieldConfigure<C, P, A, Z>;
|
|
52
52
|
/**
|
|
53
53
|
* Key is required or not
|
|
54
54
|
* */
|
|
55
|
-
required(flag: boolean): EnvFieldConfigure<
|
|
55
|
+
required(flag: boolean): EnvFieldConfigure<C, P, A, Z>;
|
|
56
56
|
/**
|
|
57
57
|
* Key is required by given condition
|
|
58
58
|
* */
|
|
59
|
-
required(fn: EnvFieldOnLambda<
|
|
59
|
+
required(fn: EnvFieldOnLambda<C, P, A, Z, boolean>): EnvFieldConfigure<C, P, A, Z>;
|
|
60
60
|
/**
|
|
61
61
|
* Key is array, so value is split by char
|
|
62
62
|
* */
|
|
63
|
-
array(
|
|
63
|
+
array(): EnvFieldConfigure<C, P, A, Z>;
|
|
64
64
|
/**
|
|
65
65
|
* Key is secret value
|
|
66
66
|
* */
|
|
67
|
-
secret(
|
|
67
|
+
secret(): EnvFieldConfigure<C, P, A, Z>;
|
|
68
68
|
/**
|
|
69
69
|
* Cloned key
|
|
70
70
|
* */
|
|
71
|
-
clone(name: string): EnvFieldConfigure<
|
|
71
|
+
clone(name: string): EnvFieldConfigure<C, P, A, Z>;
|
|
72
72
|
/**
|
|
73
73
|
* Set default value
|
|
74
74
|
* */
|
|
75
|
-
def(value:
|
|
75
|
+
def(value: C[Z] | EnvFieldOnLambda<C, P, A, Z, C[Z]>): EnvFieldConfigure<C, P, A, Z>;
|
|
76
76
|
/**
|
|
77
77
|
* Value may have another aliases
|
|
78
78
|
* */
|
|
79
|
-
alias(...keys: string[]): EnvFieldConfigure<
|
|
79
|
+
alias(...keys: string[]): EnvFieldConfigure<C, P, A, Z>;
|
|
80
80
|
/**
|
|
81
81
|
* Value is string (can be empty)
|
|
82
82
|
* */
|
|
83
|
-
string(
|
|
83
|
+
string(): EnvFieldConfigure<C, P, A, Z>;
|
|
84
84
|
/**
|
|
85
85
|
* Value is text (can not be empty)
|
|
86
86
|
* */
|
|
87
|
-
text(
|
|
87
|
+
text(): EnvFieldConfigure<C, P, A, Z>;
|
|
88
88
|
/**
|
|
89
89
|
* Value is float
|
|
90
90
|
* */
|
|
91
|
-
float(
|
|
91
|
+
float(): EnvFieldConfigure<C, P, A, Z>;
|
|
92
92
|
/**
|
|
93
93
|
* Value is integer
|
|
94
94
|
* */
|
|
95
|
-
integer(
|
|
95
|
+
integer(): EnvFieldConfigure<C, P, A, Z>;
|
|
96
96
|
/**
|
|
97
97
|
* Value is boolean
|
|
98
98
|
* */
|
|
99
|
-
boolean(
|
|
99
|
+
boolean(): EnvFieldConfigure<C, P, A, Z>;
|
|
100
100
|
/**
|
|
101
101
|
* Value is literal
|
|
102
102
|
* */
|
|
103
|
-
literal<L extends KeyValue = string>(keys: EnumLiteral<L>): EnvFieldConfigure<
|
|
103
|
+
literal<L extends KeyValue = string>(keys: EnumLiteral<L>): EnvFieldConfigure<C, P, A, Z>;
|
|
104
104
|
/**
|
|
105
105
|
* Value is enumeration
|
|
106
106
|
* */
|
|
107
|
-
enumeration<L extends KeyValue = string>(map: EnumMap<L>): EnvFieldConfigure<
|
|
107
|
+
enumeration<L extends KeyValue = string>(map: EnumMap<L>): EnvFieldConfigure<C, P, A, Z>;
|
|
108
108
|
/**
|
|
109
109
|
* Emit an event when ota is occurred
|
|
110
110
|
* */
|
|
111
|
-
onOta(fn?: EnvFieldOnLambda<
|
|
111
|
+
onOta(fn?: EnvFieldOnLambda<C, P, A, Z, void>): EnvFieldConfigure<C, P, A, Z>;
|
|
112
112
|
/**
|
|
113
113
|
* Emit an event when value is changed
|
|
114
114
|
* */
|
|
115
|
-
onChange(fn: EnvFieldOnLambda<
|
|
115
|
+
onChange(fn: EnvFieldOnLambda<C, P, A, Z, void>): EnvFieldConfigure<C, P, A, Z>;
|
|
116
116
|
/**
|
|
117
117
|
* Emit an event when value is set
|
|
118
118
|
* */
|
|
119
|
-
onSet(fn: EnvFieldOnLambda<
|
|
119
|
+
onSet(fn: EnvFieldOnLambda<C, P, A, Z, void>): EnvFieldConfigure<C, P, A, Z>;
|
|
120
120
|
/**
|
|
121
121
|
* Set cast function, please take attention
|
|
122
122
|
* */
|
|
123
|
-
cast(fn:
|
|
123
|
+
cast(fn: ToLambda<C[Z]>): EnvFieldConfigure<C, P, A, Z>;
|
|
124
124
|
/**
|
|
125
125
|
* Set asset function, please take attention
|
|
126
126
|
* */
|
|
127
|
-
assert(fn:
|
|
127
|
+
assert(fn: AssertBasicFn): EnvFieldConfigure<C, P, A, Z>;
|
|
128
128
|
/**
|
|
129
129
|
* Go back to scope
|
|
130
130
|
* */
|
|
131
|
-
|
|
131
|
+
end(): EnvScopeConfigure<C, P, A>;
|
|
132
132
|
}
|
|
133
|
-
|
|
133
|
+
/**
|
|
134
|
+
* Environment field, runtime mode
|
|
135
|
+
*
|
|
136
|
+
* Generics:
|
|
137
|
+
* - C: Environment interface
|
|
138
|
+
* - P: Prefix for environment
|
|
139
|
+
* - A: Variation
|
|
140
|
+
* - Z: field name
|
|
141
|
+
* */
|
|
142
|
+
export interface EnvFieldRuntime<C extends EnvBase, P extends string, A extends string, Z extends keyof C = keyof C> {
|
|
134
143
|
/**
|
|
135
144
|
* Scope
|
|
136
145
|
* */
|
|
137
|
-
readonly scope: EnvScopeRuntime<
|
|
146
|
+
readonly scope: EnvScopeRuntime<C, P, A>;
|
|
138
147
|
/**
|
|
139
148
|
* Name of field
|
|
140
149
|
* */
|
|
141
150
|
readonly name: Z;
|
|
151
|
+
/**
|
|
152
|
+
* Full name of field
|
|
153
|
+
* */
|
|
154
|
+
readonly full: keyof EnvVariation<C, P, A>;
|
|
142
155
|
/**
|
|
143
156
|
* Shift to configure mode
|
|
144
157
|
* */
|
|
145
|
-
get configure(): EnvFieldConfigure<
|
|
158
|
+
get configure(): EnvFieldConfigure<C, P, A, Z>;
|
|
146
159
|
/**
|
|
147
160
|
* Shift to secure mode
|
|
148
161
|
* */
|
|
149
|
-
get $secure(): EnvFieldSecure<
|
|
162
|
+
get $secure(): EnvFieldSecure<C, P, A, Z>;
|
|
150
163
|
/**
|
|
151
164
|
* Read value, and call cast (if defined), assert (if defined), onChanged (if changed), onSet (if exists)
|
|
152
165
|
* */
|
|
@@ -156,9 +169,9 @@ export interface EnvFieldRuntime<E extends EnvBase = EnvBase, Z extends keyof E
|
|
|
156
169
|
* */
|
|
157
170
|
print(): EnvFieldPrint;
|
|
158
171
|
/**
|
|
159
|
-
* Return
|
|
172
|
+
* Return value
|
|
160
173
|
* */
|
|
161
|
-
get
|
|
174
|
+
get value(): EnvVariationValue<C, P, A, Z> | undefined;
|
|
162
175
|
/**
|
|
163
176
|
* Value is being set from ota
|
|
164
177
|
* */
|
|
@@ -166,13 +179,22 @@ export interface EnvFieldRuntime<E extends EnvBase = EnvBase, Z extends keyof E
|
|
|
166
179
|
/**
|
|
167
180
|
* Set value with all controls
|
|
168
181
|
* */
|
|
169
|
-
set(value:
|
|
182
|
+
set(value: C[Z]): void;
|
|
170
183
|
}
|
|
171
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Environment field, secure mode
|
|
186
|
+
*
|
|
187
|
+
* Generics:
|
|
188
|
+
* - C: Environment interface
|
|
189
|
+
* - P: Prefix for environment
|
|
190
|
+
* - A: Variation
|
|
191
|
+
* - Z: field name
|
|
192
|
+
* */
|
|
193
|
+
export interface EnvFieldSecure<C extends EnvBase, P extends string, A extends string, Z extends keyof C = keyof C> {
|
|
172
194
|
/**
|
|
173
195
|
* Shift to runtime mode
|
|
174
196
|
* */
|
|
175
|
-
get runtime(): EnvFieldRuntime<
|
|
197
|
+
get runtime(): EnvFieldRuntime<C, P, A, Z>;
|
|
176
198
|
/**
|
|
177
199
|
* Set value without any control
|
|
178
200
|
* */
|
|
@@ -180,23 +202,33 @@ export interface EnvFieldSecure<E extends EnvBase = EnvBase, Z extends keyof E =
|
|
|
180
202
|
/**
|
|
181
203
|
* Set cast function without any control
|
|
182
204
|
* */
|
|
183
|
-
$cast(fn:
|
|
205
|
+
$cast(fn: ToLambda<C[Z]>): void;
|
|
184
206
|
/**
|
|
185
207
|
* Set asset function without any control
|
|
186
208
|
* */
|
|
187
|
-
$assert(fn:
|
|
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> {
|
|
209
|
+
$assert(fn: AssertBasicFn): void;
|
|
190
210
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
enumeration: EnvFieldCastEnumLambda<KeyValue>;
|
|
211
|
+
/**
|
|
212
|
+
* Environment field, all modes
|
|
213
|
+
*
|
|
214
|
+
* Generics:
|
|
215
|
+
* - C: Environment interface
|
|
216
|
+
* - P: Prefix for environment
|
|
217
|
+
* - A: Variation
|
|
218
|
+
* - Z: field name
|
|
219
|
+
* */
|
|
220
|
+
export interface EnvField<C extends EnvBase, P extends string, A extends string, Z extends keyof C = keyof C> extends EnvFieldConfigure<C, P, A, Z>, EnvFieldRuntime<C, P, A, Z>, EnvFieldSecure<C, P, A, Z> {
|
|
202
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Environment field on lambda
|
|
224
|
+
*
|
|
225
|
+
* Generics:
|
|
226
|
+
* - C: Environment interface
|
|
227
|
+
* - P: Prefix for environment
|
|
228
|
+
* - A: Variation
|
|
229
|
+
* - Z: field name
|
|
230
|
+
*
|
|
231
|
+
* @param {EnvFieldRuntime} field
|
|
232
|
+
* @return {any}
|
|
233
|
+
* */
|
|
234
|
+
export type EnvFieldOnLambda<C extends EnvBase, P extends string, A extends string, Z extends keyof C = keyof C, R = unknown> = (field?: EnvFieldRuntime<C, P, A, Z>) => R;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type EnvBase, type EnvCoreRuntime } from "../core";
|
|
2
2
|
import type { EnvFieldConfigure, EnvFieldRuntime } from "../field";
|
|
3
|
-
import { EnvScope, EnvScopeConfigure, EnvScopeOnLambda, EnvScopePrint, EnvScopeRuntime, EnvScopeSecure } from "./index.types";
|
|
4
|
-
export declare class EnvScopeImpl<
|
|
3
|
+
import type { EnvScope, EnvScopeConfigure, EnvScopeOnLambda, EnvScopePrint, EnvScopeRuntime, EnvScopeSecure, EnvVariation } from "./index.types";
|
|
4
|
+
export declare class EnvScopeImpl<C extends EnvBase = EnvBase, P extends string = string, A extends string = undefined> implements EnvScope<C, P, A> {
|
|
5
5
|
readonly core: EnvCoreRuntime;
|
|
6
6
|
readonly name: string;
|
|
7
|
-
|
|
7
|
+
readonly prefix: P;
|
|
8
|
+
readonly variation: A | undefined;
|
|
9
|
+
private _valueFull;
|
|
10
|
+
private _valueShort;
|
|
8
11
|
private _run;
|
|
9
12
|
private readonly _fields;
|
|
10
13
|
private readonly _otaList;
|
|
@@ -13,29 +16,34 @@ export declare class EnvScopeImpl<E extends EnvBase = EnvBase> implements EnvSco
|
|
|
13
16
|
private _onChangeList;
|
|
14
17
|
private _onSet;
|
|
15
18
|
private _state;
|
|
16
|
-
constructor(core: EnvCoreRuntime, name: string);
|
|
17
|
-
field<Z extends keyof
|
|
18
|
-
uses<
|
|
19
|
-
onChange(fn: EnvScopeOnLambda<
|
|
20
|
-
onSet(fn: EnvScopeOnLambda<
|
|
21
|
-
onOta(fn: EnvScopeOnLambda<
|
|
22
|
-
getField<Z extends keyof
|
|
23
|
-
hasField<Z extends keyof
|
|
19
|
+
constructor(core: EnvCoreRuntime, name: string, prefix: P, variation: A | undefined);
|
|
20
|
+
field<Z extends keyof C = keyof C>(name: Z): EnvFieldConfigure<C, P, A, Z>;
|
|
21
|
+
uses<C2 extends EnvBase = EnvBase, P2 extends string = string, A2 extends string = undefined>(p1: string | EnvScopeRuntime<C2, P2, A2>): EnvScopeConfigure<C, P, A>;
|
|
22
|
+
onChange(fn: EnvScopeOnLambda<C, P, A, void>): EnvScopeConfigure<C, P, A>;
|
|
23
|
+
onSet(fn: EnvScopeOnLambda<C, P, A, void>): EnvScopeConfigure<C, P, A>;
|
|
24
|
+
onOta(fn: EnvScopeOnLambda<C, P, A, void>): EnvScopeConfigure<C, P, A>;
|
|
25
|
+
getField<Z extends keyof C = keyof C>(name: Z): EnvFieldRuntime<C, P, A, Z>;
|
|
26
|
+
hasField<Z extends keyof C = keyof C>(name: Z): boolean;
|
|
24
27
|
hasUse(name: string): boolean;
|
|
25
28
|
validUse(name: string): boolean;
|
|
26
29
|
read(): void;
|
|
27
30
|
print(asObject?: boolean): string | EnvScopePrint[];
|
|
28
|
-
|
|
31
|
+
private _readAgain;
|
|
32
|
+
get valueFull(): EnvVariation<C, P, A>;
|
|
33
|
+
get valueShort(): C;
|
|
29
34
|
refresh(): void;
|
|
30
35
|
clear(): void;
|
|
31
36
|
get useList(): Record<string, boolean>;
|
|
32
|
-
fromOta(values: Partial<
|
|
37
|
+
fromOta(values: Partial<EnvVariation<C, P, A>>): void;
|
|
33
38
|
$read(): void;
|
|
34
39
|
$print(): EnvScopePrint;
|
|
35
|
-
$addOta(name: keyof
|
|
36
|
-
get runtime(): EnvScopeRuntime<
|
|
37
|
-
get configure(): EnvScopeConfigure<
|
|
38
|
-
get $secure(): EnvScopeSecure<
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
$addOta(name: keyof C): void;
|
|
41
|
+
get runtime(): EnvScopeRuntime<C, P, A>;
|
|
42
|
+
get configure(): EnvScopeConfigure<C, P, A>;
|
|
43
|
+
get $secure(): EnvScopeSecure<C, P, A>;
|
|
44
|
+
private _getVariationName;
|
|
45
|
+
newVariation<A2 extends string = undefined>(variation: A2): EnvScopeConfigure<C, P, A2>;
|
|
46
|
+
getVariation<A2 extends string = undefined>(variation: A2): EnvScopeRuntime<C, P, A2>;
|
|
47
|
+
finish(): EnvScopeRuntime<C, P, A>;
|
|
48
|
+
start(): EnvScopeConfigure<C, P, A>;
|
|
41
49
|
}
|
|
@@ -5,12 +5,16 @@ 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
7
|
const error_enveloper_1 = require("@leyyo/error-enveloper");
|
|
8
|
+
const core_1 = require("../core");
|
|
9
|
+
const type_1 = require("@leyyo/type");
|
|
8
10
|
const WHERE = `${internal_1.FQN}.EnvScopeImpl`;
|
|
9
11
|
class EnvScopeImpl {
|
|
10
12
|
// endregion property
|
|
11
|
-
constructor(core, name) {
|
|
13
|
+
constructor(core, name, prefix, variation) {
|
|
12
14
|
this.core = core;
|
|
13
15
|
this.name = name;
|
|
16
|
+
this.prefix = prefix;
|
|
17
|
+
this.variation = variation;
|
|
14
18
|
this._fields = common_1.$repo.newMap(WHERE, 'fields'); // field name x field instance
|
|
15
19
|
this._otaList = common_1.$repo.newArray(WHERE, 'otaList'); // field name
|
|
16
20
|
this._uses = common_1.$repo.newMap(WHERE, 'uses'); // scope name x scope instance
|
|
@@ -18,11 +22,12 @@ class EnvScopeImpl {
|
|
|
18
22
|
}
|
|
19
23
|
// region configure
|
|
20
24
|
field(name) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
25
|
+
if (this.variation) {
|
|
26
|
+
throw new core_1.EnvironmentError('varied.scope.does.not.support', `Scope[${this.name}] does not support to create new field`, { scope: this.name, where: WHERE, method: 'finish' });
|
|
27
|
+
}
|
|
28
|
+
(0, type_1.assertText)(name, () => common_1.$opt.fn({ where: WHERE, scope: this.name, method: 'field' }));
|
|
24
29
|
if (this._fields.has(name)) {
|
|
25
|
-
throw
|
|
30
|
+
throw new core_1.EnvironmentError('field.duplicated', `Field[${name}] is duplicated`, { where: WHERE, scope: this.name, method: 'field', field: name });
|
|
26
31
|
}
|
|
27
32
|
const ins = new env_field_impl_1.EnvFieldImpl(this, name);
|
|
28
33
|
this._fields.set(name, ins);
|
|
@@ -40,20 +45,20 @@ class EnvScopeImpl {
|
|
|
40
45
|
scope.$secure.$read();
|
|
41
46
|
}
|
|
42
47
|
else {
|
|
43
|
-
|
|
48
|
+
logger.warn('Not found scope', { given: name, where: WHERE, scope: this.name });
|
|
44
49
|
}
|
|
45
50
|
if (this._uses.has(name)) {
|
|
46
|
-
|
|
51
|
+
logger.warn('Duplicated used scope', { given: name, where: WHERE, scope: this.name });
|
|
47
52
|
}
|
|
48
53
|
else {
|
|
49
54
|
this._uses.set(name, scope);
|
|
50
55
|
}
|
|
51
56
|
}
|
|
52
|
-
else if (
|
|
57
|
+
else if ((0, type_1.isObjectValid)(p1) && p1 instanceof EnvScopeImpl) {
|
|
53
58
|
scope = p1;
|
|
54
59
|
name = scope.name;
|
|
55
60
|
if (this._uses.has(name)) {
|
|
56
|
-
|
|
61
|
+
logger.warn('Duplicated used scope', { given: name, where: WHERE, scope: this.name });
|
|
57
62
|
}
|
|
58
63
|
else {
|
|
59
64
|
this._uses.set(name, scope);
|
|
@@ -61,12 +66,12 @@ class EnvScopeImpl {
|
|
|
61
66
|
}
|
|
62
67
|
}
|
|
63
68
|
else {
|
|
64
|
-
|
|
69
|
+
logger.warn('Invalid used scope', { type: typeof p1, clazz: (_a = p1 === null || p1 === void 0 ? void 0 : p1.constructor) === null || _a === void 0 ? void 0 : _a.name, where: WHERE, scope: this.name });
|
|
65
70
|
}
|
|
66
71
|
return this;
|
|
67
72
|
}
|
|
68
73
|
onChange(fn) {
|
|
69
|
-
|
|
74
|
+
(0, type_1.assertFunction)(fn, () => common_1.$opt.fn({ where: WHERE, scope: this.name, method: 'onChange' }));
|
|
70
75
|
if (!Array.isArray(this._onChangeList)) {
|
|
71
76
|
this._onChangeList = [];
|
|
72
77
|
}
|
|
@@ -74,36 +79,30 @@ class EnvScopeImpl {
|
|
|
74
79
|
return this;
|
|
75
80
|
}
|
|
76
81
|
onSet(fn) {
|
|
77
|
-
|
|
82
|
+
(0, type_1.assertFunction)(fn, () => common_1.$opt.fn({ where: WHERE, scope: this.name, method: 'onSet' }));
|
|
78
83
|
this._onSet = fn;
|
|
79
84
|
return this;
|
|
80
85
|
}
|
|
81
86
|
onOta(fn) {
|
|
82
|
-
|
|
87
|
+
(0, type_1.assertFunction)(fn, () => common_1.$opt.fn({ where: WHERE, scope: this.name, method: 'onOta' }));
|
|
83
88
|
this._onOta = fn;
|
|
84
89
|
return this;
|
|
85
90
|
}
|
|
86
91
|
// endregion configure
|
|
87
92
|
// region runtime
|
|
88
93
|
getField(name) {
|
|
89
|
-
|
|
90
|
-
return { where: WHERE, scope: this.name, method: 'getField' };
|
|
91
|
-
});
|
|
94
|
+
(0, type_1.assertText)(name, () => common_1.$opt.fn({ where: WHERE, scope: this.name, method: 'getField' }));
|
|
92
95
|
if (!this._fields.has(name)) {
|
|
93
|
-
throw
|
|
96
|
+
throw new core_1.EnvironmentError('field.not.found', `Field[${name}] could not found`, { where: WHERE, scope: this.name, method: 'getField', field: name });
|
|
94
97
|
}
|
|
95
98
|
return this._fields.get(name);
|
|
96
99
|
}
|
|
97
100
|
hasField(name) {
|
|
98
|
-
|
|
99
|
-
return { where: WHERE, scope: this.name, method: 'hasField' };
|
|
100
|
-
});
|
|
101
|
+
(0, type_1.assertText)(name, () => common_1.$opt.fn({ where: WHERE, scope: this.name, method: 'hasField' }));
|
|
101
102
|
return this._fields.has(name);
|
|
102
103
|
}
|
|
103
104
|
hasUse(name) {
|
|
104
|
-
|
|
105
|
-
return { where: WHERE, scope: this.name, method: 'hasUse' };
|
|
106
|
-
});
|
|
105
|
+
(0, type_1.assertText)(name, () => common_1.$opt.fn({ where: WHERE, scope: this.name, method: 'hasUse' }));
|
|
107
106
|
return this._uses.has(name);
|
|
108
107
|
}
|
|
109
108
|
validUse(name) {
|
|
@@ -118,23 +117,38 @@ class EnvScopeImpl {
|
|
|
118
117
|
print(asObject) {
|
|
119
118
|
return this.core.print(asObject);
|
|
120
119
|
}
|
|
121
|
-
|
|
122
|
-
if (this._raw !== undefined) {
|
|
123
|
-
return this._raw;
|
|
124
|
-
}
|
|
120
|
+
_readAgain() {
|
|
125
121
|
this.read();
|
|
126
|
-
this.
|
|
127
|
-
|
|
128
|
-
|
|
122
|
+
this._valueFull = {};
|
|
123
|
+
this._valueShort = {};
|
|
124
|
+
Array.from(this._fields.values())
|
|
125
|
+
.forEach(field => {
|
|
126
|
+
this._valueFull[field.full] = field.value;
|
|
127
|
+
this._valueShort[field.name] = field.value;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
get valueFull() {
|
|
131
|
+
if (this._valueFull !== undefined) {
|
|
132
|
+
return this._valueFull;
|
|
133
|
+
}
|
|
134
|
+
this._readAgain();
|
|
135
|
+
return this._valueFull;
|
|
136
|
+
}
|
|
137
|
+
get valueShort() {
|
|
138
|
+
if (this._valueShort !== undefined) {
|
|
139
|
+
return this._valueShort;
|
|
129
140
|
}
|
|
130
|
-
|
|
141
|
+
this._readAgain();
|
|
142
|
+
return this._valueShort;
|
|
131
143
|
}
|
|
132
144
|
refresh() {
|
|
133
145
|
this._run = false;
|
|
134
|
-
this.
|
|
146
|
+
this._valueFull = undefined;
|
|
147
|
+
this._valueShort = undefined;
|
|
135
148
|
}
|
|
136
149
|
clear() {
|
|
137
|
-
this.
|
|
150
|
+
this._valueFull = undefined;
|
|
151
|
+
this._valueShort = undefined;
|
|
138
152
|
}
|
|
139
153
|
get useList() {
|
|
140
154
|
const rec = {};
|
|
@@ -145,9 +159,13 @@ class EnvScopeImpl {
|
|
|
145
159
|
}
|
|
146
160
|
fromOta(values) {
|
|
147
161
|
this.refresh();
|
|
148
|
-
if (
|
|
162
|
+
if ((0, type_1.isObjectBare)(values)) {
|
|
149
163
|
let changedAny = false;
|
|
150
|
-
for (const [
|
|
164
|
+
for (const [full, value] of Object.entries(values)) {
|
|
165
|
+
let name = full.substring(this.prefix.length);
|
|
166
|
+
if (this.variation) {
|
|
167
|
+
name = name.substring(this.variation.length);
|
|
168
|
+
}
|
|
151
169
|
const ins = this._fields.get(name);
|
|
152
170
|
if (ins) {
|
|
153
171
|
if (ins.fromOta(value)) {
|
|
@@ -156,7 +174,11 @@ class EnvScopeImpl {
|
|
|
156
174
|
}
|
|
157
175
|
}
|
|
158
176
|
if (changedAny && this._onOta) {
|
|
159
|
-
error_enveloper_1.errorEnveloper.handle(() => this._onOta(this), (e) =>
|
|
177
|
+
error_enveloper_1.errorEnveloper.handle(() => this._onOta(this), (e) => logger.warn('OnOta Error', {
|
|
178
|
+
caused: { name: e.name, message: e.message },
|
|
179
|
+
where: WHERE,
|
|
180
|
+
scope: this.name
|
|
181
|
+
}));
|
|
160
182
|
}
|
|
161
183
|
}
|
|
162
184
|
}
|
|
@@ -176,11 +198,20 @@ class EnvScopeImpl {
|
|
|
176
198
|
});
|
|
177
199
|
if (changedAny && this._onChangeList) {
|
|
178
200
|
this._onChangeList.forEach((fn, index) => {
|
|
179
|
-
error_enveloper_1.errorEnveloper.handle(() => fn(this), (e) =>
|
|
201
|
+
error_enveloper_1.errorEnveloper.handle(() => fn(this), (e) => logger.warn('OnChange Error', {
|
|
202
|
+
caused: { name: e.name, message: e.message },
|
|
203
|
+
where: WHERE,
|
|
204
|
+
scope: this.name,
|
|
205
|
+
index
|
|
206
|
+
}));
|
|
180
207
|
});
|
|
181
208
|
}
|
|
182
209
|
if (this._onSet) {
|
|
183
|
-
error_enveloper_1.errorEnveloper.handle(() => this._onSet(this), (e) =>
|
|
210
|
+
error_enveloper_1.errorEnveloper.handle(() => this._onSet(this), (e) => logger.warn('OnSet Error', {
|
|
211
|
+
caused: { name: e.name, message: e.message },
|
|
212
|
+
where: WHERE,
|
|
213
|
+
scope: this.name
|
|
214
|
+
}));
|
|
184
215
|
}
|
|
185
216
|
}
|
|
186
217
|
$print() {
|
|
@@ -208,25 +239,61 @@ class EnvScopeImpl {
|
|
|
208
239
|
get $secure() {
|
|
209
240
|
return this;
|
|
210
241
|
}
|
|
211
|
-
|
|
212
|
-
if (this.
|
|
213
|
-
this.
|
|
242
|
+
_getVariationName(variation) {
|
|
243
|
+
if (this.variation) {
|
|
244
|
+
throw new core_1.EnvironmentError('scope.already.varied', `Scope is already varied`, { value: this.name, where: WHERE, method: 'newVariation', variation });
|
|
214
245
|
}
|
|
215
|
-
|
|
216
|
-
|
|
246
|
+
(0, type_1.assertText)(variation, () => common_1.$opt.fn({ where: WHERE, scope: this.name, method: 'newVariation', field: 'variation' }));
|
|
247
|
+
return `${this.name}#${variation}`;
|
|
248
|
+
}
|
|
249
|
+
newVariation(variation) {
|
|
250
|
+
const name = this._getVariationName(variation);
|
|
251
|
+
if (this.core.hasScope(name)) {
|
|
252
|
+
throw new core_1.EnvironmentError('scope.duplicated', `Scope[${name}] is duplicated`, { value: name, where: WHERE, method: 'newVariation' });
|
|
217
253
|
}
|
|
218
|
-
return this;
|
|
254
|
+
return new EnvScopeImpl(this.core, name, this.prefix, variation);
|
|
255
|
+
}
|
|
256
|
+
getVariation(variation) {
|
|
257
|
+
const name = this._getVariationName(variation);
|
|
258
|
+
if (this.core.hasScope(name)) {
|
|
259
|
+
return this.core.getScope(name);
|
|
260
|
+
}
|
|
261
|
+
return new EnvScopeImpl(this.core, name, this.prefix, variation);
|
|
219
262
|
}
|
|
220
|
-
|
|
263
|
+
finish() {
|
|
264
|
+
if (this.variation) {
|
|
265
|
+
throw new core_1.EnvironmentError('varied.scope.does.not.support', `Scope[${this.name}] does not support finish operation`, { scope: this.name, where: WHERE, method: 'finish' });
|
|
266
|
+
}
|
|
221
267
|
if (this._state === 'started') {
|
|
222
268
|
this.read();
|
|
223
269
|
this._state = 'completed';
|
|
224
270
|
}
|
|
225
271
|
else {
|
|
226
|
-
|
|
272
|
+
logger.warn('Unexpected end of configure', {
|
|
273
|
+
state: this._state,
|
|
274
|
+
scope: this.name,
|
|
275
|
+
where: WHERE
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
return this;
|
|
279
|
+
}
|
|
280
|
+
start() {
|
|
281
|
+
if (this.variation) {
|
|
282
|
+
throw new core_1.EnvironmentError('varied.scope.does.not.support', `Scope[${this.name}] does not support start operation`, { scope: this.name, where: WHERE, method: 'finish' });
|
|
283
|
+
}
|
|
284
|
+
if (this._state === 'pending') {
|
|
285
|
+
this._state = 'started';
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
logger.warn('Unexpected begin of configure', {
|
|
289
|
+
state: this._state,
|
|
290
|
+
scope: this.name,
|
|
291
|
+
where: WHERE
|
|
292
|
+
});
|
|
227
293
|
}
|
|
228
294
|
return this;
|
|
229
295
|
}
|
|
230
296
|
}
|
|
231
297
|
exports.EnvScopeImpl = EnvScopeImpl;
|
|
298
|
+
const logger = common_1.$log.create(EnvScopeImpl);
|
|
232
299
|
//# sourceMappingURL=env-scope.impl.js.map
|