@enyo-energy/energy-app-sdk 0.0.132 → 0.0.133
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/README.md +44 -0
- package/dist/cjs/energy-app.cjs +10 -0
- package/dist/cjs/energy-app.d.cts +9 -0
- package/dist/cjs/enyo-energy-app-sdk.d.cts +3 -0
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.d.cts +2 -0
- package/dist/cjs/packages/energy-app-configuration-manager.cjs +2 -0
- package/dist/cjs/packages/energy-app-configuration-manager.d.cts +56 -0
- package/dist/cjs/types/enyo-configuration-manager.cjs +2 -0
- package/dist/cjs/types/enyo-configuration-manager.d.cts +84 -0
- package/dist/cjs/version.cjs +1 -1
- package/dist/cjs/version.d.cts +1 -1
- package/dist/energy-app.d.ts +9 -0
- package/dist/energy-app.js +10 -0
- package/dist/enyo-energy-app-sdk.d.ts +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/packages/energy-app-configuration-manager.d.ts +56 -0
- package/dist/packages/energy-app-configuration-manager.js +1 -0
- package/dist/types/enyo-configuration-manager.d.ts +84 -0
- package/dist/types/enyo-configuration-manager.js +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -616,6 +616,50 @@ settings.listenForSettingsChanges((settingName, newValue) => {
|
|
|
616
616
|
const allSettings = await settings.getSettingsConfig();
|
|
617
617
|
```
|
|
618
618
|
|
|
619
|
+
#### `useConfigurationManager(): EnergyAppConfigurationManager`
|
|
620
|
+
|
|
621
|
+
Register **internal**, non user-facing configurations for your package and react to value changes. Unlike `useSettings()`, configurations registered here are NOT rendered in the Energy App UI — they are intended for values the package itself reads and writes at runtime (e.g. internal feature toggles, tuning parameters, calibration values) and need to be persisted across restarts.
|
|
622
|
+
|
|
623
|
+
Each configuration is addressed by a unique `key` and is either of type `number` (with optional `minValue` / `maxValue` / `step` constraints) or `select` (with a fixed list of allowed `selectOptions`).
|
|
624
|
+
|
|
625
|
+
```typescript
|
|
626
|
+
const configManager = energyApp.useConfigurationManager();
|
|
627
|
+
|
|
628
|
+
// Register the full set of internal configurations in a single call
|
|
629
|
+
await configManager.registerConfigurations([
|
|
630
|
+
{
|
|
631
|
+
key: 'pollIntervalMs',
|
|
632
|
+
type: 'number',
|
|
633
|
+
defaultValue: 5000,
|
|
634
|
+
numberOptions: { minValue: 1000, maxValue: 60000, step: 1000 }
|
|
635
|
+
},
|
|
636
|
+
{
|
|
637
|
+
key: 'logLevel',
|
|
638
|
+
type: 'select',
|
|
639
|
+
defaultValue: 'info',
|
|
640
|
+
selectOptions: [
|
|
641
|
+
{ value: 'debug' },
|
|
642
|
+
{ value: 'info' },
|
|
643
|
+
{ value: 'warn' },
|
|
644
|
+
{ value: 'error' }
|
|
645
|
+
]
|
|
646
|
+
}
|
|
647
|
+
]);
|
|
648
|
+
|
|
649
|
+
// Read the current (or default) value for a configuration
|
|
650
|
+
const pollInterval = await configManager.getConfiguration('pollIntervalMs');
|
|
651
|
+
|
|
652
|
+
// React to value changes
|
|
653
|
+
configManager.onConfigurationChanged(event => {
|
|
654
|
+
console.log(
|
|
655
|
+
`Configuration ${event.key} changed from ${event.previousValue} to ${event.newValue}`
|
|
656
|
+
);
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
// Remove configurations (e.g. on cleanup or after a migration)
|
|
660
|
+
await configManager.unregisterConfigurations(['logLevel']);
|
|
661
|
+
```
|
|
662
|
+
|
|
619
663
|
#### `useElectricityPrices(): EnergyAppElectricityPrices`
|
|
620
664
|
|
|
621
665
|
Access electricity pricing information:
|
package/dist/cjs/energy-app.cjs
CHANGED
|
@@ -288,6 +288,16 @@ class EnergyApp {
|
|
|
288
288
|
useGridConnectionPoint() {
|
|
289
289
|
return this.energyAppSdk.useGridConnectionPoint();
|
|
290
290
|
}
|
|
291
|
+
/**
|
|
292
|
+
* Gets the Configuration Manager API for registering internal (non user-facing)
|
|
293
|
+
* package configurations. Configurations are typed as either `number` or
|
|
294
|
+
* `select`, addressed by a unique key, and emit change events when their
|
|
295
|
+
* persisted value is updated.
|
|
296
|
+
* @returns The Configuration Manager API instance
|
|
297
|
+
*/
|
|
298
|
+
useConfigurationManager() {
|
|
299
|
+
return this.energyAppSdk.useConfigurationManager();
|
|
300
|
+
}
|
|
291
301
|
/**
|
|
292
302
|
* Gets the current SDK version.
|
|
293
303
|
* @returns The semantic version string of the SDK
|
|
@@ -34,6 +34,7 @@ import { EnergyAppLearningPhase } from "./packages/energy-app-learning-phase.cjs
|
|
|
34
34
|
import { EnergyAppWifi } from "./packages/energy-app-wifi.cjs";
|
|
35
35
|
import { EnergyAppUdp } from "./packages/energy-app-udp.cjs";
|
|
36
36
|
import { EnergyAppGridConnectionPoint } from "./packages/energy-app-grid-connection-point.cjs";
|
|
37
|
+
import { EnergyAppConfigurationManager } from "./packages/energy-app-configuration-manager.cjs";
|
|
37
38
|
/**
|
|
38
39
|
* Concrete implementation of {@link EnyoEnergyAppSdk} that delegates every call
|
|
39
40
|
* to the runtime-provided `energyAppSdkInstance` global.
|
|
@@ -223,6 +224,14 @@ export declare class EnergyApp implements EnyoEnergyAppSdk {
|
|
|
223
224
|
* @returns The Grid Connection Point API instance
|
|
224
225
|
*/
|
|
225
226
|
useGridConnectionPoint(): EnergyAppGridConnectionPoint;
|
|
227
|
+
/**
|
|
228
|
+
* Gets the Configuration Manager API for registering internal (non user-facing)
|
|
229
|
+
* package configurations. Configurations are typed as either `number` or
|
|
230
|
+
* `select`, addressed by a unique key, and emit change events when their
|
|
231
|
+
* persisted value is updated.
|
|
232
|
+
* @returns The Configuration Manager API instance
|
|
233
|
+
*/
|
|
234
|
+
useConfigurationManager(): EnergyAppConfigurationManager;
|
|
226
235
|
/**
|
|
227
236
|
* Gets the current SDK version.
|
|
228
237
|
* @returns The semantic version string of the SDK
|
|
@@ -33,6 +33,7 @@ import { EnergyAppLearningPhase } from "./packages/energy-app-learning-phase.cjs
|
|
|
33
33
|
import { EnergyAppWifi } from "./packages/energy-app-wifi.cjs";
|
|
34
34
|
import { EnergyAppUdp } from "./packages/energy-app-udp.cjs";
|
|
35
35
|
import { EnergyAppGridConnectionPoint } from "./packages/energy-app-grid-connection-point.cjs";
|
|
36
|
+
import { EnergyAppConfigurationManager } from "./packages/energy-app-configuration-manager.cjs";
|
|
36
37
|
export declare enum EnergyAppStateEnum {
|
|
37
38
|
Launching = "launching",
|
|
38
39
|
Running = "running",
|
|
@@ -127,4 +128,6 @@ export interface EnyoEnergyAppSdk {
|
|
|
127
128
|
useUdp: () => EnergyAppUdp;
|
|
128
129
|
/** Get the Grid Connection Point API for retrieving fuse rating, phase count, and power limit of the site's grid connection */
|
|
129
130
|
useGridConnectionPoint: () => EnergyAppGridConnectionPoint;
|
|
131
|
+
/** Get the Configuration Manager API for registering internal (non user-facing) package configurations with change notifications */
|
|
132
|
+
useConfigurationManager: () => EnergyAppConfigurationManager;
|
|
130
133
|
}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -66,6 +66,8 @@ __exportStar(require("./packages/energy-app-wifi.cjs"), exports);
|
|
|
66
66
|
__exportStar(require("./packages/energy-app-udp.cjs"), exports);
|
|
67
67
|
__exportStar(require("./types/enyo-grid-connection-point.cjs"), exports);
|
|
68
68
|
__exportStar(require("./packages/energy-app-grid-connection-point.cjs"), exports);
|
|
69
|
+
__exportStar(require("./types/enyo-configuration-manager.cjs"), exports);
|
|
70
|
+
__exportStar(require("./packages/energy-app-configuration-manager.cjs"), exports);
|
|
69
71
|
__exportStar(require("./types/enyo-air-conditioning-appliance.cjs"), exports);
|
|
70
72
|
__exportStar(require("./types/enyo-onboarding.cjs"), exports);
|
|
71
73
|
__exportStar(require("./packages/energy-app-onboarding.cjs"), exports);
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -50,6 +50,8 @@ export * from './packages/energy-app-wifi.cjs';
|
|
|
50
50
|
export * from './packages/energy-app-udp.cjs';
|
|
51
51
|
export * from './types/enyo-grid-connection-point.cjs';
|
|
52
52
|
export * from './packages/energy-app-grid-connection-point.cjs';
|
|
53
|
+
export * from './types/enyo-configuration-manager.cjs';
|
|
54
|
+
export * from './packages/energy-app-configuration-manager.cjs';
|
|
53
55
|
export * from './types/enyo-air-conditioning-appliance.cjs';
|
|
54
56
|
export * from './types/enyo-onboarding.cjs';
|
|
55
57
|
export * from './packages/energy-app-onboarding.cjs';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { EnyoConfiguration, EnyoConfigurationChangeListener } from "../types/enyo-configuration-manager.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* Internal configuration manager for an Energy App package.
|
|
4
|
+
*
|
|
5
|
+
* Unlike {@link import('./energy-app-settings.js').EnergyAppSettings}, configurations
|
|
6
|
+
* registered here are NOT user-facing and are not rendered in the Energy App UI.
|
|
7
|
+
* They are intended for values that the package itself reads and writes at runtime
|
|
8
|
+
* (e.g. internal feature toggles, tuning parameters, calibration values) and need
|
|
9
|
+
* to be persisted across restarts.
|
|
10
|
+
*
|
|
11
|
+
* Each configuration is identified by a unique `key` within the package and is
|
|
12
|
+
* either a numeric value (`number`) or a value picked from a fixed list (`select`).
|
|
13
|
+
* Consumers can react to value changes by registering a change listener.
|
|
14
|
+
*/
|
|
15
|
+
export interface EnergyAppConfigurationManager {
|
|
16
|
+
/**
|
|
17
|
+
* Registers the full set of internal configurations for the package in a
|
|
18
|
+
* single call. This method is intended to be called once per package start
|
|
19
|
+
* with every configuration the package needs.
|
|
20
|
+
*
|
|
21
|
+
* Each configuration must have a unique `key` within the supplied array.
|
|
22
|
+
* Re-registering an existing key is treated as an update of that
|
|
23
|
+
* configuration's definition; the currently stored value is preserved if
|
|
24
|
+
* it still satisfies the new constraints.
|
|
25
|
+
*
|
|
26
|
+
* @param configurations - The complete list of configuration definitions to register
|
|
27
|
+
* @returns Promise that resolves once all configurations are registered
|
|
28
|
+
*/
|
|
29
|
+
registerConfigurations(configurations: EnyoConfiguration[]): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Removes the configurations identified by the given keys along with any
|
|
32
|
+
* values stored for them. Unknown keys are ignored.
|
|
33
|
+
*
|
|
34
|
+
* @param keys - The unique keys of the configurations to remove
|
|
35
|
+
* @returns Promise that resolves once all configurations are removed
|
|
36
|
+
*/
|
|
37
|
+
unregisterConfigurations(keys: string[]): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Retrieves the current value for a registered configuration.
|
|
40
|
+
*
|
|
41
|
+
* Returns the persisted value if one has been set, otherwise the
|
|
42
|
+
* configuration's `defaultValue` if defined, otherwise `undefined`.
|
|
43
|
+
*
|
|
44
|
+
* @param key - The unique key of the configuration
|
|
45
|
+
* @returns Promise resolving to the current value, or `undefined` if no
|
|
46
|
+
* value and no default has been defined
|
|
47
|
+
*/
|
|
48
|
+
getConfiguration(key: string): Promise<string | number | undefined>;
|
|
49
|
+
/**
|
|
50
|
+
* Registers a listener that is invoked whenever the value of any
|
|
51
|
+
* configuration managed by this package changes.
|
|
52
|
+
*
|
|
53
|
+
* @param listener - Callback invoked with the change event
|
|
54
|
+
*/
|
|
55
|
+
onConfigurationChanged(listener: EnyoConfigurationChangeListener): void;
|
|
56
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discriminator for the type of an internal configuration.
|
|
3
|
+
* - `number`: a numeric value with optional min/max/step constraints
|
|
4
|
+
* - `select`: a string value picked from a fixed list of allowed options
|
|
5
|
+
*/
|
|
6
|
+
export type EnyoConfigurationType = 'number' | 'select';
|
|
7
|
+
/**
|
|
8
|
+
* Defines an allowed option for a select-type configuration.
|
|
9
|
+
*/
|
|
10
|
+
export interface EnyoConfigurationSelectOption {
|
|
11
|
+
/** The underlying value stored for this option. Must be unique within the configuration. */
|
|
12
|
+
value: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Constraints for a number-type configuration.
|
|
16
|
+
* All bounds are inclusive when provided.
|
|
17
|
+
*/
|
|
18
|
+
export interface EnyoConfigurationNumberOptions {
|
|
19
|
+
/** Optional inclusive minimum value */
|
|
20
|
+
minValue?: number;
|
|
21
|
+
/** Optional inclusive maximum value */
|
|
22
|
+
maxValue?: number;
|
|
23
|
+
/** Optional step increment between valid values */
|
|
24
|
+
step?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Base properties shared by every configuration registration.
|
|
28
|
+
*/
|
|
29
|
+
interface EnyoConfigurationBase {
|
|
30
|
+
/**
|
|
31
|
+
* Unique key identifying this configuration within the package.
|
|
32
|
+
* The same key is used for retrieval, change notifications, and removal.
|
|
33
|
+
*/
|
|
34
|
+
key: string;
|
|
35
|
+
/**
|
|
36
|
+
* Optional default value applied when the configuration has not been
|
|
37
|
+
* set yet. For `select` configurations this must match one of the
|
|
38
|
+
* defined option values. For `number` configurations this must satisfy
|
|
39
|
+
* the configured min/max/step constraints.
|
|
40
|
+
*/
|
|
41
|
+
defaultValue?: string | number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Registration payload for a number-type internal configuration.
|
|
45
|
+
*/
|
|
46
|
+
export interface EnyoNumberConfiguration extends EnyoConfigurationBase {
|
|
47
|
+
type: 'number';
|
|
48
|
+
/** Optional numeric constraints */
|
|
49
|
+
numberOptions?: EnyoConfigurationNumberOptions;
|
|
50
|
+
/** Default value must be a number when provided */
|
|
51
|
+
defaultValue?: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Registration payload for a select-type internal configuration.
|
|
55
|
+
*/
|
|
56
|
+
export interface EnyoSelectConfiguration extends EnyoConfigurationBase {
|
|
57
|
+
type: 'select';
|
|
58
|
+
/** The list of allowed options - must contain at least one entry */
|
|
59
|
+
selectOptions: EnyoConfigurationSelectOption[];
|
|
60
|
+
/** Default value must match one of the {@link selectOptions} values when provided */
|
|
61
|
+
defaultValue?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Discriminated union of all configuration registration payloads.
|
|
65
|
+
* Use the `type` field to narrow to the concrete configuration shape.
|
|
66
|
+
*/
|
|
67
|
+
export type EnyoConfiguration = EnyoNumberConfiguration | EnyoSelectConfiguration;
|
|
68
|
+
/**
|
|
69
|
+
* Event emitted when the value of a registered configuration changes.
|
|
70
|
+
* `previousValue` is omitted when the configuration is being set for the first time.
|
|
71
|
+
*/
|
|
72
|
+
export interface EnyoConfigurationChangeEvent {
|
|
73
|
+
/** The key of the configuration that changed */
|
|
74
|
+
key: string;
|
|
75
|
+
/** The new value of the configuration */
|
|
76
|
+
newValue: string | number;
|
|
77
|
+
/** The previous value of the configuration, if one existed */
|
|
78
|
+
previousValue?: string | number;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Callback signature for listeners notified on configuration value changes.
|
|
82
|
+
*/
|
|
83
|
+
export type EnyoConfigurationChangeListener = (event: EnyoConfigurationChangeEvent) => Promise<void> | void;
|
|
84
|
+
export {};
|
package/dist/cjs/version.cjs
CHANGED
|
@@ -9,7 +9,7 @@ exports.getSdkVersion = getSdkVersion;
|
|
|
9
9
|
/**
|
|
10
10
|
* Current version of the enyo Energy App SDK.
|
|
11
11
|
*/
|
|
12
|
-
exports.SDK_VERSION = '0.0.
|
|
12
|
+
exports.SDK_VERSION = '0.0.133';
|
|
13
13
|
/**
|
|
14
14
|
* Gets the current SDK version.
|
|
15
15
|
* @returns The semantic version string of the SDK
|
package/dist/cjs/version.d.cts
CHANGED
package/dist/energy-app.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ import { EnergyAppLearningPhase } from "./packages/energy-app-learning-phase.js"
|
|
|
34
34
|
import { EnergyAppWifi } from "./packages/energy-app-wifi.js";
|
|
35
35
|
import { EnergyAppUdp } from "./packages/energy-app-udp.js";
|
|
36
36
|
import { EnergyAppGridConnectionPoint } from "./packages/energy-app-grid-connection-point.js";
|
|
37
|
+
import { EnergyAppConfigurationManager } from "./packages/energy-app-configuration-manager.js";
|
|
37
38
|
/**
|
|
38
39
|
* Concrete implementation of {@link EnyoEnergyAppSdk} that delegates every call
|
|
39
40
|
* to the runtime-provided `energyAppSdkInstance` global.
|
|
@@ -223,6 +224,14 @@ export declare class EnergyApp implements EnyoEnergyAppSdk {
|
|
|
223
224
|
* @returns The Grid Connection Point API instance
|
|
224
225
|
*/
|
|
225
226
|
useGridConnectionPoint(): EnergyAppGridConnectionPoint;
|
|
227
|
+
/**
|
|
228
|
+
* Gets the Configuration Manager API for registering internal (non user-facing)
|
|
229
|
+
* package configurations. Configurations are typed as either `number` or
|
|
230
|
+
* `select`, addressed by a unique key, and emit change events when their
|
|
231
|
+
* persisted value is updated.
|
|
232
|
+
* @returns The Configuration Manager API instance
|
|
233
|
+
*/
|
|
234
|
+
useConfigurationManager(): EnergyAppConfigurationManager;
|
|
226
235
|
/**
|
|
227
236
|
* Gets the current SDK version.
|
|
228
237
|
* @returns The semantic version string of the SDK
|
package/dist/energy-app.js
CHANGED
|
@@ -285,6 +285,16 @@ export class EnergyApp {
|
|
|
285
285
|
useGridConnectionPoint() {
|
|
286
286
|
return this.energyAppSdk.useGridConnectionPoint();
|
|
287
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* Gets the Configuration Manager API for registering internal (non user-facing)
|
|
290
|
+
* package configurations. Configurations are typed as either `number` or
|
|
291
|
+
* `select`, addressed by a unique key, and emit change events when their
|
|
292
|
+
* persisted value is updated.
|
|
293
|
+
* @returns The Configuration Manager API instance
|
|
294
|
+
*/
|
|
295
|
+
useConfigurationManager() {
|
|
296
|
+
return this.energyAppSdk.useConfigurationManager();
|
|
297
|
+
}
|
|
288
298
|
/**
|
|
289
299
|
* Gets the current SDK version.
|
|
290
300
|
* @returns The semantic version string of the SDK
|
|
@@ -33,6 +33,7 @@ import { EnergyAppLearningPhase } from "./packages/energy-app-learning-phase.js"
|
|
|
33
33
|
import { EnergyAppWifi } from "./packages/energy-app-wifi.js";
|
|
34
34
|
import { EnergyAppUdp } from "./packages/energy-app-udp.js";
|
|
35
35
|
import { EnergyAppGridConnectionPoint } from "./packages/energy-app-grid-connection-point.js";
|
|
36
|
+
import { EnergyAppConfigurationManager } from "./packages/energy-app-configuration-manager.js";
|
|
36
37
|
export declare enum EnergyAppStateEnum {
|
|
37
38
|
Launching = "launching",
|
|
38
39
|
Running = "running",
|
|
@@ -127,4 +128,6 @@ export interface EnyoEnergyAppSdk {
|
|
|
127
128
|
useUdp: () => EnergyAppUdp;
|
|
128
129
|
/** Get the Grid Connection Point API for retrieving fuse rating, phase count, and power limit of the site's grid connection */
|
|
129
130
|
useGridConnectionPoint: () => EnergyAppGridConnectionPoint;
|
|
131
|
+
/** Get the Configuration Manager API for registering internal (non user-facing) package configurations with change notifications */
|
|
132
|
+
useConfigurationManager: () => EnergyAppConfigurationManager;
|
|
130
133
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -50,6 +50,8 @@ export * from './packages/energy-app-wifi.js';
|
|
|
50
50
|
export * from './packages/energy-app-udp.js';
|
|
51
51
|
export * from './types/enyo-grid-connection-point.js';
|
|
52
52
|
export * from './packages/energy-app-grid-connection-point.js';
|
|
53
|
+
export * from './types/enyo-configuration-manager.js';
|
|
54
|
+
export * from './packages/energy-app-configuration-manager.js';
|
|
53
55
|
export * from './types/enyo-air-conditioning-appliance.js';
|
|
54
56
|
export * from './types/enyo-onboarding.js';
|
|
55
57
|
export * from './packages/energy-app-onboarding.js';
|
package/dist/index.js
CHANGED
|
@@ -50,6 +50,8 @@ export * from './packages/energy-app-wifi.js';
|
|
|
50
50
|
export * from './packages/energy-app-udp.js';
|
|
51
51
|
export * from './types/enyo-grid-connection-point.js';
|
|
52
52
|
export * from './packages/energy-app-grid-connection-point.js';
|
|
53
|
+
export * from './types/enyo-configuration-manager.js';
|
|
54
|
+
export * from './packages/energy-app-configuration-manager.js';
|
|
53
55
|
export * from './types/enyo-air-conditioning-appliance.js';
|
|
54
56
|
export * from './types/enyo-onboarding.js';
|
|
55
57
|
export * from './packages/energy-app-onboarding.js';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { EnyoConfiguration, EnyoConfigurationChangeListener } from "../types/enyo-configuration-manager.js";
|
|
2
|
+
/**
|
|
3
|
+
* Internal configuration manager for an Energy App package.
|
|
4
|
+
*
|
|
5
|
+
* Unlike {@link import('./energy-app-settings.js').EnergyAppSettings}, configurations
|
|
6
|
+
* registered here are NOT user-facing and are not rendered in the Energy App UI.
|
|
7
|
+
* They are intended for values that the package itself reads and writes at runtime
|
|
8
|
+
* (e.g. internal feature toggles, tuning parameters, calibration values) and need
|
|
9
|
+
* to be persisted across restarts.
|
|
10
|
+
*
|
|
11
|
+
* Each configuration is identified by a unique `key` within the package and is
|
|
12
|
+
* either a numeric value (`number`) or a value picked from a fixed list (`select`).
|
|
13
|
+
* Consumers can react to value changes by registering a change listener.
|
|
14
|
+
*/
|
|
15
|
+
export interface EnergyAppConfigurationManager {
|
|
16
|
+
/**
|
|
17
|
+
* Registers the full set of internal configurations for the package in a
|
|
18
|
+
* single call. This method is intended to be called once per package start
|
|
19
|
+
* with every configuration the package needs.
|
|
20
|
+
*
|
|
21
|
+
* Each configuration must have a unique `key` within the supplied array.
|
|
22
|
+
* Re-registering an existing key is treated as an update of that
|
|
23
|
+
* configuration's definition; the currently stored value is preserved if
|
|
24
|
+
* it still satisfies the new constraints.
|
|
25
|
+
*
|
|
26
|
+
* @param configurations - The complete list of configuration definitions to register
|
|
27
|
+
* @returns Promise that resolves once all configurations are registered
|
|
28
|
+
*/
|
|
29
|
+
registerConfigurations(configurations: EnyoConfiguration[]): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Removes the configurations identified by the given keys along with any
|
|
32
|
+
* values stored for them. Unknown keys are ignored.
|
|
33
|
+
*
|
|
34
|
+
* @param keys - The unique keys of the configurations to remove
|
|
35
|
+
* @returns Promise that resolves once all configurations are removed
|
|
36
|
+
*/
|
|
37
|
+
unregisterConfigurations(keys: string[]): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Retrieves the current value for a registered configuration.
|
|
40
|
+
*
|
|
41
|
+
* Returns the persisted value if one has been set, otherwise the
|
|
42
|
+
* configuration's `defaultValue` if defined, otherwise `undefined`.
|
|
43
|
+
*
|
|
44
|
+
* @param key - The unique key of the configuration
|
|
45
|
+
* @returns Promise resolving to the current value, or `undefined` if no
|
|
46
|
+
* value and no default has been defined
|
|
47
|
+
*/
|
|
48
|
+
getConfiguration(key: string): Promise<string | number | undefined>;
|
|
49
|
+
/**
|
|
50
|
+
* Registers a listener that is invoked whenever the value of any
|
|
51
|
+
* configuration managed by this package changes.
|
|
52
|
+
*
|
|
53
|
+
* @param listener - Callback invoked with the change event
|
|
54
|
+
*/
|
|
55
|
+
onConfigurationChanged(listener: EnyoConfigurationChangeListener): void;
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discriminator for the type of an internal configuration.
|
|
3
|
+
* - `number`: a numeric value with optional min/max/step constraints
|
|
4
|
+
* - `select`: a string value picked from a fixed list of allowed options
|
|
5
|
+
*/
|
|
6
|
+
export type EnyoConfigurationType = 'number' | 'select';
|
|
7
|
+
/**
|
|
8
|
+
* Defines an allowed option for a select-type configuration.
|
|
9
|
+
*/
|
|
10
|
+
export interface EnyoConfigurationSelectOption {
|
|
11
|
+
/** The underlying value stored for this option. Must be unique within the configuration. */
|
|
12
|
+
value: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Constraints for a number-type configuration.
|
|
16
|
+
* All bounds are inclusive when provided.
|
|
17
|
+
*/
|
|
18
|
+
export interface EnyoConfigurationNumberOptions {
|
|
19
|
+
/** Optional inclusive minimum value */
|
|
20
|
+
minValue?: number;
|
|
21
|
+
/** Optional inclusive maximum value */
|
|
22
|
+
maxValue?: number;
|
|
23
|
+
/** Optional step increment between valid values */
|
|
24
|
+
step?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Base properties shared by every configuration registration.
|
|
28
|
+
*/
|
|
29
|
+
interface EnyoConfigurationBase {
|
|
30
|
+
/**
|
|
31
|
+
* Unique key identifying this configuration within the package.
|
|
32
|
+
* The same key is used for retrieval, change notifications, and removal.
|
|
33
|
+
*/
|
|
34
|
+
key: string;
|
|
35
|
+
/**
|
|
36
|
+
* Optional default value applied when the configuration has not been
|
|
37
|
+
* set yet. For `select` configurations this must match one of the
|
|
38
|
+
* defined option values. For `number` configurations this must satisfy
|
|
39
|
+
* the configured min/max/step constraints.
|
|
40
|
+
*/
|
|
41
|
+
defaultValue?: string | number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Registration payload for a number-type internal configuration.
|
|
45
|
+
*/
|
|
46
|
+
export interface EnyoNumberConfiguration extends EnyoConfigurationBase {
|
|
47
|
+
type: 'number';
|
|
48
|
+
/** Optional numeric constraints */
|
|
49
|
+
numberOptions?: EnyoConfigurationNumberOptions;
|
|
50
|
+
/** Default value must be a number when provided */
|
|
51
|
+
defaultValue?: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Registration payload for a select-type internal configuration.
|
|
55
|
+
*/
|
|
56
|
+
export interface EnyoSelectConfiguration extends EnyoConfigurationBase {
|
|
57
|
+
type: 'select';
|
|
58
|
+
/** The list of allowed options - must contain at least one entry */
|
|
59
|
+
selectOptions: EnyoConfigurationSelectOption[];
|
|
60
|
+
/** Default value must match one of the {@link selectOptions} values when provided */
|
|
61
|
+
defaultValue?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Discriminated union of all configuration registration payloads.
|
|
65
|
+
* Use the `type` field to narrow to the concrete configuration shape.
|
|
66
|
+
*/
|
|
67
|
+
export type EnyoConfiguration = EnyoNumberConfiguration | EnyoSelectConfiguration;
|
|
68
|
+
/**
|
|
69
|
+
* Event emitted when the value of a registered configuration changes.
|
|
70
|
+
* `previousValue` is omitted when the configuration is being set for the first time.
|
|
71
|
+
*/
|
|
72
|
+
export interface EnyoConfigurationChangeEvent {
|
|
73
|
+
/** The key of the configuration that changed */
|
|
74
|
+
key: string;
|
|
75
|
+
/** The new value of the configuration */
|
|
76
|
+
newValue: string | number;
|
|
77
|
+
/** The previous value of the configuration, if one existed */
|
|
78
|
+
previousValue?: string | number;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Callback signature for listeners notified on configuration value changes.
|
|
82
|
+
*/
|
|
83
|
+
export type EnyoConfigurationChangeListener = (event: EnyoConfigurationChangeEvent) => Promise<void> | void;
|
|
84
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED