mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-06-06 09:31:40 +00:00
Improve dependent and preload typings
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
parent
c21da8f3db
commit
cf76875f64
@ -70,12 +70,16 @@ function validateState(state: any): asserts state is TargetState {
|
|||||||
if (!_.isObject(state)) {
|
if (!_.isObject(state)) {
|
||||||
throw new Error('State must be an object');
|
throw new Error('State must be an object');
|
||||||
}
|
}
|
||||||
if (!_.isObject(state.local)) {
|
// these any typings seem unnecessary but the `isObject`
|
||||||
|
// call above tells typescript that state is of type
|
||||||
|
// `object` - which apparently does not allow any fields
|
||||||
|
// to be accessed
|
||||||
|
if (!_.isObject((state as any).local)) {
|
||||||
throw new Error('Local state must be an object');
|
throw new Error('Local state must be an object');
|
||||||
}
|
}
|
||||||
validateLocalState(state.local);
|
validateLocalState((state as any).local);
|
||||||
if (state.dependent != null) {
|
if ((state as any).dependent != null) {
|
||||||
return validateDependentState(state.dependent);
|
return validateDependentState((state as any).dependent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ export async function loadTargetFromFile(
|
|||||||
|
|
||||||
if (_.isArray(stateFromFile)) {
|
if (_.isArray(stateFromFile)) {
|
||||||
log.debug('Detected a legacy apps.json, converting...');
|
log.debug('Detected a legacy apps.json, converting...');
|
||||||
stateFromFile = convertLegacyAppsJson(stateFromFile);
|
stateFromFile = convertLegacyAppsJson(stateFromFile as any[]);
|
||||||
}
|
}
|
||||||
const preloadState = stateFromFile as AppsJsonFormat;
|
const preloadState = stateFromFile as AppsJsonFormat;
|
||||||
|
|
||||||
@ -80,12 +80,15 @@ export async function loadTargetFromFile(
|
|||||||
preloadState.config,
|
preloadState.config,
|
||||||
);
|
);
|
||||||
preloadState.config = { ...formattedConf, ...deviceConf };
|
preloadState.config = { ...formattedConf, ...deviceConf };
|
||||||
const localState = { local: { name: '', ...preloadState } };
|
const localState = {
|
||||||
|
local: { name: '', ...preloadState },
|
||||||
|
dependent: { apps: [], devices: [] },
|
||||||
|
};
|
||||||
|
|
||||||
await deviceState.setTarget(localState);
|
await deviceState.setTarget(localState);
|
||||||
|
|
||||||
log.success('Preloading complete');
|
log.success('Preloading complete');
|
||||||
if (stateFromFile.pinDevice) {
|
if (preloadState.pinDevice) {
|
||||||
// Multi-app warning!
|
// Multi-app warning!
|
||||||
// The following will need to be changed once running
|
// The following will need to be changed once running
|
||||||
// multiple applications is possible
|
// multiple applications is possible
|
||||||
|
@ -72,14 +72,14 @@ export interface TargetState {
|
|||||||
// TODO: Correctly type this once dependent devices are
|
// TODO: Correctly type this once dependent devices are
|
||||||
// actually properly supported
|
// actually properly supported
|
||||||
dependent: {
|
dependent: {
|
||||||
apps: Dictionary<{
|
apps: Array<{
|
||||||
name?: string;
|
name?: string;
|
||||||
image?: string;
|
image?: string;
|
||||||
commit?: string;
|
commit?: string;
|
||||||
config?: EnvVarObject;
|
config?: EnvVarObject;
|
||||||
environment?: EnvVarObject;
|
environment?: EnvVarObject;
|
||||||
}>;
|
}>;
|
||||||
devices: Dictionary<{
|
devices: Array<{
|
||||||
name?: string;
|
name?: string;
|
||||||
apps?: Dictionary<{
|
apps?: Dictionary<{
|
||||||
config?: EnvVarObject;
|
config?: EnvVarObject;
|
||||||
@ -118,8 +118,8 @@ export interface InstancedAppState {
|
|||||||
releaseId: number;
|
releaseId: number;
|
||||||
name: string;
|
name: string;
|
||||||
services: Service[];
|
services: Service[];
|
||||||
volumes: { [name: string]: Volume };
|
volumes: Dictionary<Volume>;
|
||||||
networks: { [name: string]: Network };
|
networks: Dictionary<Network>;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user