@zucker-framework/config 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +22 -0
- package/THIRD_PARTY_NOTICES +4 -0
- package/dist/index.d.mts +382 -0
- package/dist/index.d.ts +382 -0
- package/dist/index.js +1307 -0
- package/dist/index.mjs +1265 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Zucker Framework
|
|
2
|
+
Copyright 2026 Lind and Zucker Framework contributors
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0. See LICENSE.
|
|
5
|
+
|
|
6
|
+
The framework includes TypeScript adaptations and enhancements of concepts and
|
|
7
|
+
implementations from hsweb-framework and jetlinks-community, both distributed
|
|
8
|
+
under the Apache License, Version 2.0. Individual packages use different subsets
|
|
9
|
+
of the framework. The TypeScript adaptations and Node.js integrations were
|
|
10
|
+
modified for Zucker Framework; they are not the original upstream distribution.
|
|
11
|
+
|
|
12
|
+
hsweb-framework
|
|
13
|
+
https://github.com/hs-web/hsweb-framework
|
|
14
|
+
Copyright 2020 http://hsweb.me
|
|
15
|
+
|
|
16
|
+
jetlinks-community
|
|
17
|
+
https://github.com/jetlinks/jetlinks-community
|
|
18
|
+
|
|
19
|
+
See THIRD_PARTY_NOTICES for license texts and attribution for bundled dependencies
|
|
20
|
+
and reference implementations relevant to this package. External dependencies
|
|
21
|
+
remain subject to their own licenses. This NOTICE is informational and does not
|
|
22
|
+
modify any license or grant rights to upstream trademarks.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import { DatabaseAdapter } from '@zucker-framework/core';
|
|
2
|
+
import { EventEmitter2 } from 'eventemitter2';
|
|
3
|
+
import { DynamicModule, Type, InjectionToken, OptionalFactoryDependency, CanActivate, ExecutionContext } from '@nestjs/common';
|
|
4
|
+
import { FeatureFlagEvaluator } from '@zucker-framework/feature-flags';
|
|
5
|
+
export { FeatureFlagDecisionReason, FeatureFlagEnvironmentReader, FeatureFlagEvaluation, FeatureFlagEvaluator, FlagContext, FlagDefinition, FlagRule, FlagRuleType, defaultFeatureFlagEnvKey } from '@zucker-framework/feature-flags';
|
|
6
|
+
export { DATABASE_ADAPTER } from '@zucker-framework/crud';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* ConfigScopeCustomizer — implement to register custom config scopes.
|
|
10
|
+
*
|
|
11
|
+
* Reference: jetlinks ConfigScopeCustomizer
|
|
12
|
+
*/
|
|
13
|
+
interface ConfigScopeCustomizer {
|
|
14
|
+
custom(manager: ConfigScopeManager): void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* ConfigScopeManager — register and retrieve config scopes.
|
|
18
|
+
*
|
|
19
|
+
* Reference: jetlinks ConfigScopeManager + SimpleConfigManager
|
|
20
|
+
*/
|
|
21
|
+
declare class ConfigScopeManager {
|
|
22
|
+
private readonly logger;
|
|
23
|
+
private readonly scopes;
|
|
24
|
+
/**
|
|
25
|
+
* Register a fully defined scope.
|
|
26
|
+
*/
|
|
27
|
+
register(scope: ConfigScope): void;
|
|
28
|
+
/**
|
|
29
|
+
* Add a scope with separate property definitions — mirrors jetlinks ConfigScopeManager.addScope().
|
|
30
|
+
*
|
|
31
|
+
* Reference: jetlinks ConfigScopeManager.addScope(ConfigScope, List<ConfigPropertyDef>)
|
|
32
|
+
*/
|
|
33
|
+
addScope(scopePartial: {
|
|
34
|
+
id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
publicAccess?: boolean;
|
|
37
|
+
}, properties: ConfigPropertyDef[]): void;
|
|
38
|
+
/**
|
|
39
|
+
* Apply customizers — call during module initialization.
|
|
40
|
+
*
|
|
41
|
+
* Reference: jetlinks ConfigScopeProperties.custom()
|
|
42
|
+
*/
|
|
43
|
+
applyCustomizers(customizers: ConfigScopeCustomizer[]): void;
|
|
44
|
+
get(scopeId: string): ConfigScope | undefined;
|
|
45
|
+
getAll(): ConfigScope[];
|
|
46
|
+
has(scopeId: string): boolean;
|
|
47
|
+
unregister(scopeId: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Get all scopes marked as public access.
|
|
50
|
+
*
|
|
51
|
+
* Reference: jetlinks SystemConfigManagerController checks isPublicAccess()
|
|
52
|
+
* for unauthenticated access.
|
|
53
|
+
*/
|
|
54
|
+
getPublicScopes(): ConfigScope[];
|
|
55
|
+
getProperties(scopeId: string): ConfigPropertyDef[];
|
|
56
|
+
/**
|
|
57
|
+
* Validate a config value against its scope property definition.
|
|
58
|
+
* Returns error messages if invalid.
|
|
59
|
+
*/
|
|
60
|
+
validate(scopeId: string, key: string, value: unknown): string[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
declare const CONFIG_CHANGED_EVENT = "zucker.config-changed";
|
|
64
|
+
/**
|
|
65
|
+
* TopicEventBus topic for config changes.
|
|
66
|
+
* Uses `/` delimiter to match DefaultTopicEventBus conventions.
|
|
67
|
+
* Subscribers can use wildcards: `system/config/**`
|
|
68
|
+
*/
|
|
69
|
+
declare const CONFIG_CHANGED_TOPIC = "system/config/changed";
|
|
70
|
+
/** Optional encryption adapter for encrypting/decrypting sensitive config values */
|
|
71
|
+
declare const CONFIG_ENCRYPTOR = "CONFIG_ENCRYPTOR";
|
|
72
|
+
interface ConfigChangePayload {
|
|
73
|
+
scope: string;
|
|
74
|
+
key: string;
|
|
75
|
+
oldValue: unknown;
|
|
76
|
+
newValue: unknown;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Encryption adapter interface for config values.
|
|
80
|
+
*
|
|
81
|
+
* Reference: jetlinks stores some config values encrypted;
|
|
82
|
+
* this provides a pluggable encryption mechanism.
|
|
83
|
+
*/
|
|
84
|
+
interface ConfigEncryptor {
|
|
85
|
+
encrypt(value: string): string | Promise<string>;
|
|
86
|
+
decrypt(value: string): string | Promise<string>;
|
|
87
|
+
}
|
|
88
|
+
/** Minimal TopicEventBus interface to avoid hard dependency on @zucker-framework/event */
|
|
89
|
+
interface TopicEventBusLike$1 {
|
|
90
|
+
publish(topic: string, payload: unknown): Promise<void>;
|
|
91
|
+
}
|
|
92
|
+
declare class ConfigService {
|
|
93
|
+
private readonly db;
|
|
94
|
+
private readonly eventEmitter?;
|
|
95
|
+
private readonly scopeManager?;
|
|
96
|
+
private readonly encryptor?;
|
|
97
|
+
private readonly topicEventBus?;
|
|
98
|
+
private readonly logger;
|
|
99
|
+
private readonly cache;
|
|
100
|
+
private static readonly CACHE_MAX_SIZE;
|
|
101
|
+
constructor(db: DatabaseAdapter, eventEmitter?: EventEmitter2 | undefined, scopeManager?: ConfigScopeManager | undefined, encryptor?: ConfigEncryptor | undefined, topicEventBus?: TopicEventBusLike$1 | undefined);
|
|
102
|
+
/**
|
|
103
|
+
* 获取指定 scope 和 key 的配置值
|
|
104
|
+
* @param scope 配置域
|
|
105
|
+
* @param key 配置键
|
|
106
|
+
* @returns 配置值,不存在时返回 undefined
|
|
107
|
+
*/
|
|
108
|
+
get<T = string>(scope: string, key: string): Promise<T | undefined>;
|
|
109
|
+
/**
|
|
110
|
+
* Get a config value with a fallback default.
|
|
111
|
+
* If no stored value exists, checks the scope definition default,
|
|
112
|
+
* then falls back to the provided default.
|
|
113
|
+
*
|
|
114
|
+
* Reference: jetlinks getProperties merges defaults from ConfigPropertyDef.
|
|
115
|
+
*/
|
|
116
|
+
getOrDefault<T = string>(scope: string, key: string, defaultValue: T): Promise<T>;
|
|
117
|
+
/**
|
|
118
|
+
* 设置配置值(自动触发变更事件)
|
|
119
|
+
* @param scope 配置域
|
|
120
|
+
* @param key 配置键
|
|
121
|
+
* @param value 配置值
|
|
122
|
+
* @throws ValidationException 校验失败时
|
|
123
|
+
*/
|
|
124
|
+
set(scope: string, key: string, value: unknown): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Set multiple properties at once for a scope.
|
|
127
|
+
* Performs batch validation first, then persists all values and emits
|
|
128
|
+
* a single consolidated event — mirrors jetlinks ConfigManager.setProperties(scope, Map)
|
|
129
|
+
* which does repository.save + cache.evict instead of N individual updates.
|
|
130
|
+
*/
|
|
131
|
+
setProperties(scope: string, values: Record<string, unknown>): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* 获取指定 scope 下的所有配置
|
|
134
|
+
* @param scope 配置域
|
|
135
|
+
* @returns 键值对集合(包含默认值)
|
|
136
|
+
*/
|
|
137
|
+
getAll(scope: string): Promise<Record<string, unknown>>;
|
|
138
|
+
/**
|
|
139
|
+
* Remove a specific config property.
|
|
140
|
+
*/
|
|
141
|
+
remove(scope: string, key: string): Promise<void>;
|
|
142
|
+
/**
|
|
143
|
+
* 监听配置变更事件
|
|
144
|
+
* @param callback 变更回调
|
|
145
|
+
* @returns 订阅句柄,调用 unsubscribe() 取消监听
|
|
146
|
+
*/
|
|
147
|
+
onChange(callback: (payload: ConfigChangePayload) => void): {
|
|
148
|
+
unsubscribe: () => void;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* 监听指定 scope.key 的配置变更,每次变更时执行回调。
|
|
152
|
+
*
|
|
153
|
+
* @param scope 配置域
|
|
154
|
+
* @param key 配置键(可选,不传则监听整个 scope)
|
|
155
|
+
* @param callback 变更回调
|
|
156
|
+
* @returns 取消监听函数
|
|
157
|
+
*/
|
|
158
|
+
watch<T = unknown>(scope: string, key: string | undefined, callback: (newValue: T, oldValue: T | undefined) => void): {
|
|
159
|
+
unsubscribe: () => void;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* 清除配置缓存
|
|
163
|
+
* @param scope 可选的配置域,不传则清除所有缓存
|
|
164
|
+
*/
|
|
165
|
+
clearCache(scope?: string): void;
|
|
166
|
+
/**
|
|
167
|
+
* 记录配置变更历史(自动版本号递增)
|
|
168
|
+
* 配置版本控制
|
|
169
|
+
*/
|
|
170
|
+
private recordHistory;
|
|
171
|
+
/**
|
|
172
|
+
* 查询配置变更历史
|
|
173
|
+
* @param scope 配置域
|
|
174
|
+
* @param key 配置键(可选,不传则查询该 scope 所有变更)
|
|
175
|
+
* @param limit 返回条数(默认 20)
|
|
176
|
+
*/
|
|
177
|
+
getHistory(scope: string, key?: string, limit?: number): Promise<Array<{
|
|
178
|
+
scope: string;
|
|
179
|
+
key: string;
|
|
180
|
+
oldValue: unknown;
|
|
181
|
+
newValue: unknown;
|
|
182
|
+
changedAt: Date;
|
|
183
|
+
}>>;
|
|
184
|
+
/**
|
|
185
|
+
* 回滚配置到指定历史版本
|
|
186
|
+
* @param historyId 历史记录 ID
|
|
187
|
+
*/
|
|
188
|
+
rollback(historyId: string): Promise<void>;
|
|
189
|
+
/**
|
|
190
|
+
* Check if a property is marked as encrypted in its scope definition.
|
|
191
|
+
*/
|
|
192
|
+
private isEncryptedProperty;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
interface ZuckerConfigModuleOptions {
|
|
196
|
+
/** Optional encryption adapter for sensitive config values */
|
|
197
|
+
encryptor?: ConfigEncryptor;
|
|
198
|
+
/** Optional scope customizers to register scopes during init */
|
|
199
|
+
customizers?: ConfigScopeCustomizer[];
|
|
200
|
+
}
|
|
201
|
+
declare const CONFIG_MODULE_OPTIONS: unique symbol;
|
|
202
|
+
interface ZuckerConfigModuleAsyncOptions {
|
|
203
|
+
imports?: Array<Type | DynamicModule>;
|
|
204
|
+
useFactory?: (...args: unknown[]) => ZuckerConfigModuleOptions | Promise<ZuckerConfigModuleOptions>;
|
|
205
|
+
useClass?: Type<ZuckerConfigModuleOptionsFactory>;
|
|
206
|
+
useExisting?: Type<ZuckerConfigModuleOptionsFactory>;
|
|
207
|
+
inject?: Array<InjectionToken | OptionalFactoryDependency>;
|
|
208
|
+
}
|
|
209
|
+
interface ZuckerConfigModuleOptionsFactory {
|
|
210
|
+
createConfigOptions(): ZuckerConfigModuleOptions | Promise<ZuckerConfigModuleOptions>;
|
|
211
|
+
}
|
|
212
|
+
declare class ZuckerConfigModule {
|
|
213
|
+
static forRoot(options?: ZuckerConfigModuleOptions): DynamicModule;
|
|
214
|
+
static forRootAsync(options: ZuckerConfigModuleAsyncOptions): DynamicModule;
|
|
215
|
+
private static createAsyncProviders;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
declare const CONFIG_SCOPE_REGISTRY = "CONFIG_SCOPE_REGISTRY";
|
|
219
|
+
interface ConfigScopeEntry {
|
|
220
|
+
name: string;
|
|
221
|
+
publicAccess: boolean;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* ConfigGuard — 配置访问守卫
|
|
225
|
+
*
|
|
226
|
+
* 检查请求的 scope 是否标记为 publicAccess,
|
|
227
|
+
* 如果是公开的则跳过认证,否则要求请求已认证。
|
|
228
|
+
*/
|
|
229
|
+
declare class ConfigGuard implements CanActivate {
|
|
230
|
+
private readonly scopeRegistry;
|
|
231
|
+
private readonly logger;
|
|
232
|
+
constructor(scopeRegistry: Map<string, ConfigScopeEntry>);
|
|
233
|
+
canActivate(context: ExecutionContext): boolean;
|
|
234
|
+
private isAuthenticated;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
type ConfigLayer = 'system' | 'tenant' | 'user';
|
|
238
|
+
declare const CONFIG_LAYER_PRIORITY: Record<ConfigLayer, number>;
|
|
239
|
+
declare const LAYERED_CONFIG_CHANGED_EVENT = "zucker.layered-config-changed";
|
|
240
|
+
/**
|
|
241
|
+
* TopicEventBus topic for layered config changes.
|
|
242
|
+
* Uses `/` delimiter to match DefaultTopicEventBus conventions.
|
|
243
|
+
*/
|
|
244
|
+
declare const LAYERED_CONFIG_CHANGED_TOPIC = "system/config/layered-changed";
|
|
245
|
+
/** Minimal TopicEventBus interface to avoid hard dependency on @zucker-framework/event */
|
|
246
|
+
interface TopicEventBusLike {
|
|
247
|
+
publish(topic: string, payload: unknown): Promise<void>;
|
|
248
|
+
}
|
|
249
|
+
interface LayeredConfigChangePayload {
|
|
250
|
+
scope: string;
|
|
251
|
+
key: string;
|
|
252
|
+
layer: ConfigLayer;
|
|
253
|
+
oldValue: unknown;
|
|
254
|
+
newValue: unknown;
|
|
255
|
+
}
|
|
256
|
+
interface LayeredConfigContext {
|
|
257
|
+
tenantId?: string;
|
|
258
|
+
userId?: string;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* LayeredConfigService — config with layered inheritance: system -> tenant -> user.
|
|
262
|
+
*
|
|
263
|
+
* Higher layers override lower layers. When getting a value, the most specific
|
|
264
|
+
* layer with a value wins.
|
|
265
|
+
*/
|
|
266
|
+
declare class LayeredConfigService {
|
|
267
|
+
private readonly db;
|
|
268
|
+
private readonly scopeManager;
|
|
269
|
+
private readonly eventEmitter?;
|
|
270
|
+
private readonly topicEventBus?;
|
|
271
|
+
private readonly logger;
|
|
272
|
+
private readonly cache;
|
|
273
|
+
constructor(db: DatabaseAdapter, scopeManager: ConfigScopeManager, eventEmitter?: EventEmitter2 | undefined, topicEventBus?: TopicEventBusLike | undefined);
|
|
274
|
+
/**
|
|
275
|
+
* Get a config value, resolving through layers (user > tenant > system > default).
|
|
276
|
+
*/
|
|
277
|
+
get<T = unknown>(scope: string, key: string, context?: LayeredConfigContext): Promise<T | undefined>;
|
|
278
|
+
/**
|
|
279
|
+
* Set a config value at a specific layer.
|
|
280
|
+
*/
|
|
281
|
+
set(scope: string, key: string, value: unknown, layer: ConfigLayer, ownerId?: string): Promise<void>;
|
|
282
|
+
/**
|
|
283
|
+
* Get all values for a scope, merged across layers.
|
|
284
|
+
*/
|
|
285
|
+
getAll(scope: string, context?: LayeredConfigContext): Promise<Record<string, unknown>>;
|
|
286
|
+
/**
|
|
287
|
+
* Set multiple properties at a specific layer.
|
|
288
|
+
* Validates all entries first, then persists in batch.
|
|
289
|
+
*
|
|
290
|
+
* Reference: jetlinks ConfigManager.setProperties(scope, Map)
|
|
291
|
+
*/
|
|
292
|
+
setProperties(scope: string, values: Record<string, unknown>, layer: ConfigLayer, ownerId?: string): Promise<void>;
|
|
293
|
+
/**
|
|
294
|
+
* Remove a config value at a specific layer.
|
|
295
|
+
*/
|
|
296
|
+
remove(scope: string, key: string, layer: ConfigLayer, ownerId?: string): Promise<void>;
|
|
297
|
+
/**
|
|
298
|
+
* Clear the in-memory cache.
|
|
299
|
+
* @param scope Optional — only clear entries for this scope prefix
|
|
300
|
+
*/
|
|
301
|
+
clearCache(scope?: string): void;
|
|
302
|
+
private getLayerValue;
|
|
303
|
+
private getLayerRecords;
|
|
304
|
+
private buildLayerKey;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
declare class FeatureFlagService extends FeatureFlagEvaluator {
|
|
308
|
+
constructor();
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* 配置文件热重载监听器 — 对标 Claude Code changeDetector.ts
|
|
313
|
+
*
|
|
314
|
+
* 监听配置文件变化,带写入稳定性检测和删除宽限期。
|
|
315
|
+
*
|
|
316
|
+
* 用法:
|
|
317
|
+
* ```ts
|
|
318
|
+
* const watcher = new ConfigFileWatcher();
|
|
319
|
+
* watcher.watch('/path/to/config.json', () => {
|
|
320
|
+
* configService.clearCache();
|
|
321
|
+
* logger.log('Config reloaded');
|
|
322
|
+
* });
|
|
323
|
+
*
|
|
324
|
+
* // 停止监听
|
|
325
|
+
* watcher.close();
|
|
326
|
+
* ```
|
|
327
|
+
*/
|
|
328
|
+
interface ConfigWatcherOptions {
|
|
329
|
+
/** 写入稳定性延迟:文件修改后等待此时间无新修改才触发回调(毫秒) */
|
|
330
|
+
stabilityMs?: number;
|
|
331
|
+
/** 删除宽限期:文件删除后等待此时间,若重建则不触发删除回调 */
|
|
332
|
+
deleteGraceMs?: number;
|
|
333
|
+
}
|
|
334
|
+
declare class ConfigFileWatcher {
|
|
335
|
+
private readonly logger;
|
|
336
|
+
private readonly stabilityMs;
|
|
337
|
+
private readonly deleteGraceMs;
|
|
338
|
+
private readonly watched;
|
|
339
|
+
constructor(options?: ConfigWatcherOptions);
|
|
340
|
+
/**
|
|
341
|
+
* 开始监听文件
|
|
342
|
+
* @returns 取消监听函数
|
|
343
|
+
*/
|
|
344
|
+
watch(filePath: string, callback: () => void): () => void;
|
|
345
|
+
/**
|
|
346
|
+
* 停止监听指定文件
|
|
347
|
+
*/
|
|
348
|
+
unwatch(filePath: string): void;
|
|
349
|
+
/**
|
|
350
|
+
* 关闭所有监听
|
|
351
|
+
*/
|
|
352
|
+
close(): void;
|
|
353
|
+
/**
|
|
354
|
+
* 获取当前监听的文件列表
|
|
355
|
+
*/
|
|
356
|
+
getWatchedFiles(): string[];
|
|
357
|
+
private handleEvent;
|
|
358
|
+
private getModifiedTime;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
interface ConfigPropertyDef {
|
|
362
|
+
key: string;
|
|
363
|
+
name: string;
|
|
364
|
+
type: string;
|
|
365
|
+
defaultValue: unknown;
|
|
366
|
+
description: string;
|
|
367
|
+
readonly: boolean;
|
|
368
|
+
/** Whether this property value should be encrypted at rest */
|
|
369
|
+
encrypted?: boolean;
|
|
370
|
+
/** Sort order for display */
|
|
371
|
+
sortOrder?: number;
|
|
372
|
+
}
|
|
373
|
+
interface ConfigScope {
|
|
374
|
+
id: string;
|
|
375
|
+
name: string;
|
|
376
|
+
isPublic: boolean;
|
|
377
|
+
/** Whether public access is allowed (no auth required) */
|
|
378
|
+
publicAccess: boolean;
|
|
379
|
+
properties: ConfigPropertyDef[];
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export { CONFIG_CHANGED_EVENT, CONFIG_CHANGED_TOPIC, CONFIG_ENCRYPTOR, CONFIG_LAYER_PRIORITY, CONFIG_MODULE_OPTIONS, CONFIG_SCOPE_REGISTRY, type ConfigChangePayload, type ConfigEncryptor, ConfigFileWatcher, ConfigGuard, type ConfigLayer, type ConfigPropertyDef, type ConfigScope, type ConfigScopeCustomizer, type ConfigScopeEntry, ConfigScopeManager, ConfigService, type ConfigWatcherOptions, FeatureFlagService, LAYERED_CONFIG_CHANGED_EVENT, LAYERED_CONFIG_CHANGED_TOPIC, type LayeredConfigChangePayload, type LayeredConfigContext, LayeredConfigService, ZuckerConfigModule, type ZuckerConfigModuleAsyncOptions, type ZuckerConfigModuleOptions, type ZuckerConfigModuleOptionsFactory };
|