Improve dependent and preload typings

Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2020-02-19 09:36:02 +07:00
parent c21da8f3db
commit cf76875f64
No known key found for this signature in database
GPG Key ID: 49690ED87032539F
3 changed files with 18 additions and 11 deletions

View File

@ -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);
}
}

View File

@ -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

View File

@ -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>;
};
}