@grest-ts/config 0.0.5 → 0.0.7
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 +21 -21
- package/README.md +62 -57
- package/dist/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/src/GGConfig.ts +69 -69
- package/src/GGConfigKey.ts +106 -106
- package/src/GGConfigLocator.ts +112 -112
- package/src/GGConfigStore.ts +100 -100
- package/src/GG_CONFIG.ts +4 -4
- package/src/assureValidConfigPath.spec.ts +140 -140
- package/src/assureValidConfigPath.ts +33 -33
- package/src/index-node.ts +10 -10
- package/src/keys/GGResource.ts +20 -20
- package/src/keys/GGSecret.ts +20 -20
- package/src/keys/GGSetting.ts +28 -28
- package/src/stores/GGConfigStoreFile.ts +69 -69
- package/src/stores/GGConfigStoreLocal.ts +109 -109
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Grest Games OÜ
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Grest Games OÜ
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,57 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
//
|
|
38
|
-
AppConfig.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
1
|
+
<!-- GREST-TS-BANNER-START -->
|
|
2
|
+
> Part of the [grest-ts](https://github.com/grest-ts/grest-ts) framework.
|
|
3
|
+
> [Documentation](https://github.com/grest-ts/grest-ts#readme) | [All packages](https://github.com/grest-ts/grest-ts#package-reference)
|
|
4
|
+
<!-- GREST-TS-BANNER-END -->
|
|
5
|
+
|
|
6
|
+
# @grest-ts/config
|
|
7
|
+
|
|
8
|
+
Type-safe configuration management for Grest Framework.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- Type-safe configuration keys with validation
|
|
13
|
+
- Multiple key types (Settings, Secrets, Resources)
|
|
14
|
+
- Pluggable storage backends (file, environment, remote)
|
|
15
|
+
- Runtime configuration updates with watchers
|
|
16
|
+
- Centralized configuration definitions
|
|
17
|
+
- Config values are validated!
|
|
18
|
+
|
|
19
|
+
## Pattern
|
|
20
|
+
|
|
21
|
+
- Keys are defined statically, but values are resolved at runtime from async context
|
|
22
|
+
- Different key types (Setting, Secret, Resource) can use different storage backends (Strategy pattern)
|
|
23
|
+
- Supports watching for runtime configuration changes (Observer pattern)
|
|
24
|
+
|
|
25
|
+
## Quick usage example
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import {GGConfig, GGResource, GGSecret, GGSetting} from "@grest-ts/config"
|
|
29
|
+
|
|
30
|
+
// Define configuration keys
|
|
31
|
+
export const AppConfig = GGConfig.define('/app/', () => ({
|
|
32
|
+
port: new GGSetting('port', 3000, 'Server port', IsInt),
|
|
33
|
+
apiKey: new GGSecret('apiKey', '', 'External API key', IsString),
|
|
34
|
+
dbUrl: new GGResource('db/url', 'localhost:5432', 'Database URL', IsString)
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
// Usage in runtime
|
|
38
|
+
const port = AppConfig.port.get();
|
|
39
|
+
const apiKey = AppConfig.apiKey.reveal();
|
|
40
|
+
const dbUrl = AppConfig.dbUrl.get(); // if value changes, you get the new value
|
|
41
|
+
|
|
42
|
+
// Watch for changes (in case you need to) - as a simple example: you need to roll a mysql user password and start a new pool without any downtime.
|
|
43
|
+
AppConfig.dbUrl.watch(() => {
|
|
44
|
+
// Do something when dbUrl changes
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
// Where actually values come from? You define the source in the runtime compose.
|
|
48
|
+
// in example we use a file (don't really use files, use proper services for each category!)
|
|
49
|
+
// These particular stores also watch the file for updates. Most stores should allow dynamic config updates!
|
|
50
|
+
// You can also add your own stores, groups etc rather easily.
|
|
51
|
+
new GGConfigLoader(new Map<any, any>([
|
|
52
|
+
[GGSetting, new GGConfigStoreFile("./config/settings.json", import.meta.url)],
|
|
53
|
+
[GGSecret, new GGConfigStoreFile("./config/secrets.json", import.meta.url)],
|
|
54
|
+
[GGResource, new GGConfigStoreFile("./config/resources.json", import.meta.url)]
|
|
55
|
+
]));
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Documentation
|
|
60
|
+
|
|
61
|
+
- [Usage](./README-usage.md) - How to define and use configuration
|
|
62
|
+
- [Extending](./README-extending.md) - How to add custom key types and stores
|