@antelopejs/interface-core 0.0.13 → 0.1.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/dist/config.d.ts +27 -0
- package/dist/config.js.map +1 -1
- package/docs/7.configuration.md +47 -0
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
|
@@ -32,6 +32,33 @@ export interface ModuleSourceLocalFolder extends ModuleSource {
|
|
|
32
32
|
installCommand?: ModuleInstallCommand;
|
|
33
33
|
reloadCommand?: ModuleInstallCommand;
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* A value a module may publish as a config variable.
|
|
37
|
+
*
|
|
38
|
+
* Only primitives travel between modules: the value is substituted into
|
|
39
|
+
* another module's configuration before that module constructs.
|
|
40
|
+
*/
|
|
41
|
+
export type ConfigVarValue = string | number | boolean;
|
|
42
|
+
/**
|
|
43
|
+
* The config variables a module publishes from its `provide` callback.
|
|
44
|
+
*
|
|
45
|
+
* The keys must match the names the module declares in its `package.json`
|
|
46
|
+
* under `antelopeJs.configVars`. Consumers reference them from their own
|
|
47
|
+
* configuration with `${@<moduleName>.<VAR_NAME>}`, and the core substitutes
|
|
48
|
+
* the values before any module constructs.
|
|
49
|
+
*/
|
|
50
|
+
export type ConfigVars = Record<string, ConfigVarValue>;
|
|
51
|
+
/**
|
|
52
|
+
* The `provide` lifecycle callback a provider module exports.
|
|
53
|
+
*
|
|
54
|
+
* It runs before every `construct`, which is what makes the published values
|
|
55
|
+
* available to consumers whatever the order of the interface graph. A provider
|
|
56
|
+
* must therefore compute its values on its own: no other module has
|
|
57
|
+
* constructed yet, so awaiting another module's interface from `provide`
|
|
58
|
+
* deadlocks the startup. The core interfaces registered before the module
|
|
59
|
+
* lifecycle starts, `GetRuntimeInfo()` among them, remain available.
|
|
60
|
+
*/
|
|
61
|
+
export type ConfigVarProvider = (config: unknown) => Promise<ConfigVars | void> | ConfigVars | void;
|
|
35
62
|
export interface AntelopeTestConfig {
|
|
36
63
|
folder?: string;
|
|
37
64
|
setup?: () => undefined | Partial<AntelopeConfig> | Promise<undefined | Partial<AntelopeConfig>>;
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AAAA,sBAAsB;;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AAAA,sBAAsB;;AAyItB,oCAEC;AAFD,SAAgB,YAAY,CAAC,KAAkB;IAC7C,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/docs/7.configuration.md
CHANGED
|
@@ -174,6 +174,53 @@ Logging configuration within the project config.
|
|
|
174
174
|
| `formatter` | `Record<string, string>` | Custom formatters per channel |
|
|
175
175
|
| `dateFormat` | `string` | Date format string for log timestamps |
|
|
176
176
|
|
|
177
|
+
## Config variables
|
|
178
|
+
|
|
179
|
+
A module can publish named values other modules reference from their own configuration. The provider declares the names it publishes in its `package.json`, returns them from its `provide` callback, and the core substitutes them into every consumer before any module constructs.
|
|
180
|
+
|
|
181
|
+
```json
|
|
182
|
+
{
|
|
183
|
+
"name": "api",
|
|
184
|
+
"antelopeJs": {
|
|
185
|
+
"configVars": ["API_PORT"]
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
import type { ConfigVars } from "@antelopejs/interface-core/config";
|
|
192
|
+
|
|
193
|
+
export async function provide(config: unknown): Promise<ConfigVars> {
|
|
194
|
+
const port = await reservePort(config);
|
|
195
|
+
return { API_PORT: port };
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
`provide` is optional and only providers implement it. It runs before every `construct`, so a provider cannot await another module's interface from it: nothing has constructed yet. The core interfaces registered before the module lifecycle starts — `GetRuntimeInfo()` among them — stay available, which is enough to compute a port, a base URL or a generated secret.
|
|
200
|
+
|
|
201
|
+
A consumer references the value with `${@<moduleName>.<VAR_NAME>}`, where `<moduleName>` is the module key used in the project configuration:
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
export default defineConfig({
|
|
205
|
+
name: "my-project",
|
|
206
|
+
modules: {
|
|
207
|
+
api: { version: "1.0.0" },
|
|
208
|
+
dms: {
|
|
209
|
+
version: "1.0.0",
|
|
210
|
+
config: { apiBaseUrl: "http://127.0.0.1:${@api.API_PORT}" },
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
| Type | Definition | Description |
|
|
217
|
+
| ------------------- | ------------------------------------------------------------------------ | --------------------------------------- |
|
|
218
|
+
| `ConfigVarValue` | `string \| number \| boolean` | A single published value |
|
|
219
|
+
| `ConfigVars` | `Record<string, ConfigVarValue>` | The record `provide` returns |
|
|
220
|
+
| `ConfigVarProvider` | `(config: unknown) => Promise<ConfigVars \| void> \| ConfigVars \| void` | The signature of the `provide` callback |
|
|
221
|
+
|
|
222
|
+
Values are resolved once, before construction, and never re-resolved afterwards. `construct` cannot publish config variables: its return value is ignored. See the core documentation for the resolution order and the failure modes.
|
|
223
|
+
|
|
177
224
|
## `AntelopeTestConfig`
|
|
178
225
|
|
|
179
226
|
Test configuration for the project.
|