@antelopejs/interface-core 0.0.14 → 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 +13 -2
- package/dist/config.js.map +1 -1
- package/docs/7.configuration.md +11 -8
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
|
@@ -40,14 +40,25 @@ export interface ModuleSourceLocalFolder extends ModuleSource {
|
|
|
40
40
|
*/
|
|
41
41
|
export type ConfigVarValue = string | number | boolean;
|
|
42
42
|
/**
|
|
43
|
-
* The config variables a module publishes from its `
|
|
43
|
+
* The config variables a module publishes from its `provide` callback.
|
|
44
44
|
*
|
|
45
45
|
* The keys must match the names the module declares in its `package.json`
|
|
46
46
|
* under `antelopeJs.configVars`. Consumers reference them from their own
|
|
47
47
|
* configuration with `${@<moduleName>.<VAR_NAME>}`, and the core substitutes
|
|
48
|
-
* the values before
|
|
48
|
+
* the values before any module constructs.
|
|
49
49
|
*/
|
|
50
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;
|
|
51
62
|
export interface AntelopeTestConfig {
|
|
52
63
|
folder?: string;
|
|
53
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
|
@@ -176,7 +176,7 @@ Logging configuration within the project config.
|
|
|
176
176
|
|
|
177
177
|
## Config variables
|
|
178
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 `
|
|
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
180
|
|
|
181
181
|
```json
|
|
182
182
|
{
|
|
@@ -190,12 +190,14 @@ A module can publish named values other modules reference from their own configu
|
|
|
190
190
|
```ts
|
|
191
191
|
import type { ConfigVars } from "@antelopejs/interface-core/config";
|
|
192
192
|
|
|
193
|
-
export async function
|
|
194
|
-
const port = await
|
|
193
|
+
export async function provide(config: unknown): Promise<ConfigVars> {
|
|
194
|
+
const port = await reservePort(config);
|
|
195
195
|
return { API_PORT: port };
|
|
196
196
|
}
|
|
197
197
|
```
|
|
198
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
|
+
|
|
199
201
|
A consumer references the value with `${@<moduleName>.<VAR_NAME>}`, where `<moduleName>` is the module key used in the project configuration:
|
|
200
202
|
|
|
201
203
|
```ts
|
|
@@ -211,12 +213,13 @@ export default defineConfig({
|
|
|
211
213
|
});
|
|
212
214
|
```
|
|
213
215
|
|
|
214
|
-
| Type
|
|
215
|
-
|
|
|
216
|
-
| `ConfigVarValue`
|
|
217
|
-
| `ConfigVars`
|
|
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 |
|
|
218
221
|
|
|
219
|
-
Values are resolved once,
|
|
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.
|
|
220
223
|
|
|
221
224
|
## `AntelopeTestConfig`
|
|
222
225
|
|