@lorion-org/runtime-config-node 1.0.0-beta.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 +21 -0
- package/README.md +200 -0
- package/dist/index.cjs +586 -0
- package/dist/index.d.cts +174 -0
- package/dist/index.d.ts +174 -0
- package/dist/index.js +526 -0
- package/examples/env-assignments.ts +21 -0
- package/examples/load-runtime-config-tree.ts +17 -0
- package/examples/query-runtime-config-tree.ts +53 -0
- package/examples/source-and-scope-files.ts +24 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
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
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# @lorion-org/runtime-config-node
|
|
2
|
+
|
|
3
|
+
Node-side runtime-config loaders and path conventions.
|
|
4
|
+
|
|
5
|
+
It stays generic: directories are scopes, files are fragments, and loaded values
|
|
6
|
+
use the contracts from `@lorion-org/runtime-config`.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```shell
|
|
11
|
+
pnpm add @lorion-org/runtime-config-node @lorion-org/runtime-config
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## What it is
|
|
15
|
+
|
|
16
|
+
- path helpers for runtime-config directories
|
|
17
|
+
- a JSON fragment loader for one scope
|
|
18
|
+
- a tree loader for all scope directories below one `runtime-config` root
|
|
19
|
+
- pattern-source helpers for adapters that do not use the default tree shape
|
|
20
|
+
- tree-query helpers for list/show/project/get/scope flows
|
|
21
|
+
- env-var and shell-assignment rendering from a loaded tree
|
|
22
|
+
- JSON and text file read/write helpers for adapter layers
|
|
23
|
+
- source, scope-file, and public-file path helpers for thin integrations
|
|
24
|
+
- schema validation for runtime-config targets
|
|
25
|
+
|
|
26
|
+
## What it is not
|
|
27
|
+
|
|
28
|
+
- not a framework module
|
|
29
|
+
- not a config-file parser beyond JSON
|
|
30
|
+
- not an application-specific directory convention
|
|
31
|
+
|
|
32
|
+
## Directory shape
|
|
33
|
+
|
|
34
|
+
```text
|
|
35
|
+
var/
|
|
36
|
+
runtime-config/
|
|
37
|
+
billing/
|
|
38
|
+
runtime.config.json
|
|
39
|
+
mail/
|
|
40
|
+
runtime.config.json
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Basic example
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { loadRuntimeConfigTree } from '@lorion-org/runtime-config-node';
|
|
47
|
+
import { projectSectionedRuntimeConfig } from '@lorion-org/runtime-config';
|
|
48
|
+
|
|
49
|
+
const fragments = loadRuntimeConfigTree('./var');
|
|
50
|
+
const runtimeConfig = projectSectionedRuntimeConfig(fragments);
|
|
51
|
+
|
|
52
|
+
runtimeConfig.public.billingApiBase;
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Single fragment example
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { loadRuntimeConfigFragment } from '@lorion-org/runtime-config-node';
|
|
59
|
+
|
|
60
|
+
const billing = loadRuntimeConfigFragment('./var', 'billing');
|
|
61
|
+
|
|
62
|
+
billing?.public?.apiBase;
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Source and scope file example
|
|
66
|
+
|
|
67
|
+
Adapters often need one shared source convention and a few non-fragment files
|
|
68
|
+
inside a scope directory. Keep the source generic and pass application-specific
|
|
69
|
+
file names from the adapter.
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import {
|
|
73
|
+
readRuntimeConfigScopeJson,
|
|
74
|
+
resolveRuntimeConfigPublicFilePath,
|
|
75
|
+
resolveRuntimeConfigSource,
|
|
76
|
+
} from '@lorion-org/runtime-config-node';
|
|
77
|
+
|
|
78
|
+
const source = resolveRuntimeConfigSource({
|
|
79
|
+
defaultVarDir: './var',
|
|
80
|
+
env: process.env,
|
|
81
|
+
envKey: 'APP_VAR_DIR',
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
readRuntimeConfigScopeJson(source, 'billing', 'settings.json');
|
|
85
|
+
// => { apiBase: '/api/billing' }
|
|
86
|
+
|
|
87
|
+
resolveRuntimeConfigPublicFilePath(source, 'billing/logo.svg');
|
|
88
|
+
// => '/absolute/project/path/var/runtime-config/public/billing/logo.svg'
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Pattern source example
|
|
92
|
+
|
|
93
|
+
Adapters can load fragments from path patterns when the directory convention is
|
|
94
|
+
owned by the host application. Pattern sources use exactly one `*` wildcard; the
|
|
95
|
+
matched segment becomes the scope id.
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import {
|
|
99
|
+
loadRuntimeConfigSourceTree,
|
|
100
|
+
resolveRuntimeConfigSourceFiles,
|
|
101
|
+
validateRuntimeConfigSourceScopes,
|
|
102
|
+
} from '@lorion-org/runtime-config-node';
|
|
103
|
+
|
|
104
|
+
const source = {
|
|
105
|
+
paths: ['.runtimeconfig/runtime-config/*/runtime.config.json'],
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
resolveRuntimeConfigSourceFiles(source);
|
|
109
|
+
// => [{ scopeId: 'billing', configPath: '/project/.runtimeconfig/runtime-config/billing/runtime.config.json', ... }]
|
|
110
|
+
|
|
111
|
+
loadRuntimeConfigSourceTree(source).get('billing')?.public?.apiBase;
|
|
112
|
+
// => '/api/billing'
|
|
113
|
+
|
|
114
|
+
validateRuntimeConfigSourceScopes(source, [{ scopeId: 'billing', cwd: './extensions/billing' }]);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Write fragment example
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import { writeRuntimeConfigFragment } from '@lorion-org/runtime-config-node';
|
|
121
|
+
|
|
122
|
+
writeRuntimeConfigFragment('./var', 'billing', {
|
|
123
|
+
public: {
|
|
124
|
+
apiBase: '/api/billing',
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Env assignment example
|
|
130
|
+
|
|
131
|
+
Runtime-config env rendering delegates projection rules to
|
|
132
|
+
`@lorion-org/runtime-config` and keeps file-system loading in this package.
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
import { loadRuntimeConfigShellAssignments } from '@lorion-org/runtime-config-node';
|
|
136
|
+
|
|
137
|
+
loadRuntimeConfigShellAssignments('./var', {
|
|
138
|
+
prefix: 'APP',
|
|
139
|
+
});
|
|
140
|
+
// => APP_PUBLIC_BILLING_API_BASE='"/api/billing"'
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Tree query example
|
|
144
|
+
|
|
145
|
+
These helpers are useful for CLIs, local tooling, and lightweight adapters that
|
|
146
|
+
need to inspect runtime-config trees without reimplementing projection rules.
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
import {
|
|
150
|
+
getRuntimeConfigScopeView,
|
|
151
|
+
getRuntimeConfigValue,
|
|
152
|
+
listRuntimeConfigFragments,
|
|
153
|
+
projectRuntimeConfigTree,
|
|
154
|
+
} from '@lorion-org/runtime-config-node';
|
|
155
|
+
|
|
156
|
+
listRuntimeConfigFragments('./var');
|
|
157
|
+
// => { scopes: [{ scopeId: 'billing', ... }] }
|
|
158
|
+
|
|
159
|
+
projectRuntimeConfigTree('./var').runtimeConfig.public.billingApiBase;
|
|
160
|
+
// => '/api/billing'
|
|
161
|
+
|
|
162
|
+
getRuntimeConfigValue('./var', 'billing', 'apiBase').value;
|
|
163
|
+
// => '/api/billing'
|
|
164
|
+
|
|
165
|
+
getRuntimeConfigScopeView('./var', 'billing').config;
|
|
166
|
+
// => { apiBase: '/api/billing' }
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Schema validation example
|
|
170
|
+
|
|
171
|
+
Schema validation applies to the fragment file on disk. Projection into a flat
|
|
172
|
+
runtime object happens afterwards in `@lorion-org/runtime-config`.
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
import { validateRuntimeConfigSchemaTargets } from '@lorion-org/runtime-config-node';
|
|
176
|
+
|
|
177
|
+
validateRuntimeConfigSchemaTargets([
|
|
178
|
+
{
|
|
179
|
+
scopeId: 'billing',
|
|
180
|
+
schemaPath: './schemas/billing.schema.json',
|
|
181
|
+
configPath: './var/runtime-config/billing/runtime.config.json',
|
|
182
|
+
},
|
|
183
|
+
]);
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
For adapters that resolve schema locations from scope directories, use
|
|
187
|
+
`validateRuntimeConfigScopes(...)` to collect `validated` and `skipped`
|
|
188
|
+
targets before the AJV validation runs.
|
|
189
|
+
|
|
190
|
+
Runnable example files live in [`examples/`](./examples).
|
|
191
|
+
|
|
192
|
+
## Local commands
|
|
193
|
+
|
|
194
|
+
```shell
|
|
195
|
+
cd packages/runtime-config-node
|
|
196
|
+
pnpm build
|
|
197
|
+
pnpm test
|
|
198
|
+
pnpm typecheck
|
|
199
|
+
pnpm package:check
|
|
200
|
+
```
|