mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-03-21 03:25:46 +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)) {
|
||||
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');
|
||||
}
|
||||
validateLocalState(state.local);
|
||||
if (state.dependent != null) {
|
||||
return validateDependentState(state.dependent);
|
||||
validateLocalState((state as any).local);
|
||||
if ((state as any).dependent != null) {
|
||||
return validateDependentState((state as any).dependent);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ export async function loadTargetFromFile(
|
||||
|
||||
if (_.isArray(stateFromFile)) {
|
||||
log.debug('Detected a legacy apps.json, converting...');
|
||||
stateFromFile = convertLegacyAppsJson(stateFromFile);
|
||||
stateFromFile = convertLegacyAppsJson(stateFromFile as any[]);
|
||||
}
|
||||
const preloadState = stateFromFile as AppsJsonFormat;
|
||||
|
||||
@ -80,12 +80,15 @@ export async function loadTargetFromFile(
|
||||
preloadState.config,
|
||||
);
|
||||
preloadState.config = { ...formattedConf, ...deviceConf };
|
||||
const localState = { local: { name: '', ...preloadState } };
|
||||
const localState = {
|
||||
local: { name: '', ...preloadState },
|
||||
dependent: { apps: [], devices: [] },
|
||||
};
|
||||
|
||||
await deviceState.setTarget(localState);
|
||||
|
||||
log.success('Preloading complete');
|
||||
if (stateFromFile.pinDevice) {
|
||||
if (preloadState.pinDevice) {
|
||||
// Multi-app warning!
|
||||
// The following will need to be changed once running
|
||||
// multiple applications is possible
|
||||
|
@ -72,14 +72,14 @@ export interface TargetState {
|
||||
// TODO: Correctly type this once dependent devices are
|
||||
// actually properly supported
|
||||
dependent: {
|
||||
apps: Dictionary<{
|
||||
apps: Array<{
|
||||
name?: string;
|
||||
image?: string;
|
||||
commit?: string;
|
||||
config?: EnvVarObject;
|
||||
environment?: EnvVarObject;
|
||||
}>;
|
||||
devices: Dictionary<{
|
||||
devices: Array<{
|
||||
name?: string;
|
||||
apps?: Dictionary<{
|
||||
config?: EnvVarObject;
|
||||
@ -118,8 +118,8 @@ export interface InstancedAppState {
|
||||
releaseId: number;
|
||||
name: string;
|
||||
services: Service[];
|
||||
volumes: { [name: string]: Volume };
|
||||
networks: { [name: string]: Network };
|
||||
volumes: Dictionary<Volume>;
|
||||
networks: Dictionary<Network>;
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user