preload: Improve the typings

Change-type: patch
Depends-on: https://github.com/balena-io/balena-sdk/pull/980
See: https://github.com/balena-io/balena-cli/pull/2007#discussion_r478330624
Signed-off-by: Thodoris Greasidis <thodoris@balena.io>
This commit is contained in:
Thodoris Greasidis 2020-08-27 14:05:04 +03:00
parent c647989054
commit 2e1570149d
2 changed files with 38 additions and 35 deletions

View File

@ -30,13 +30,12 @@ import type {
Application,
BalenaSDK,
DeviceTypeJson,
PineOptions,
PineExpand,
Release,
} from 'balena-sdk';
import type { Preloader } from 'balena-preload';
import { parseAsInteger } from '../utils/validation';
import { ExpectedError } from '../errors';
import type { ResourceExpand } from 'pinejs-client-core';
interface FlagsDef extends DockerConnectionCliFlags {
app?: string;
@ -278,7 +277,7 @@ Can be repeated to add multiple certificates.\
}
}
readonly applicationExpandOptions: ResourceExpand = {
readonly applicationExpandOptions: PineExpand<Application> = {
owns__release: {
$select: ['id', 'commit', 'end_timestamp', 'composition'],
$orderby: [{ end_timestamp: 'desc' }, { id: 'desc' }],
@ -340,38 +339,43 @@ Can be repeated to add multiple certificates.\
return this.getDeviceTypesWithSameArch(deviceTypeSlug).then(
(deviceTypes) => {
const options: PineOptions<
ApplicationWithDeviceType & { should_be_running__release: [Release?] }
> = {
$filter: {
is_for__device_type: {
$any: {
$alias: 'dt',
$expr: {
dt: {
slug: { $in: deviceTypes },
},
},
},
},
owns__release: {
$any: {
$alias: 'r',
$expr: {
r: {
status: 'success',
},
},
},
},
},
$expand: this.applicationExpandOptions,
$select: ['id', 'app_name', 'should_track_latest_release'],
$orderby: 'app_name asc',
};
return balena.pine.get({
// TODO: remove the explicit types once https://github.com/balena-io/balena-sdk/pull/889 gets merged
return balena.pine.get<
Application,
Array<
ApplicationWithDeviceType & {
should_be_running__release: [Release?];
}
>
>({
resource: 'my_application',
options,
options: {
$filter: {
is_for__device_type: {
$any: {
$alias: 'dt',
$expr: {
dt: {
slug: { $in: deviceTypes },
},
},
},
},
owns__release: {
$any: {
$alias: 'r',
$expr: {
r: {
status: 'success',
},
},
},
},
},
$expand: this.applicationExpandOptions,
$select: ['id', 'app_name', 'should_track_latest_release'],
$orderby: 'app_name asc',
},
});
},
);

View File

@ -180,7 +180,6 @@
"mock-require": "^3.0.3",
"nock": "^12.0.3",
"parse-link-header": "~1.0.1",
"pinejs-client-core": "^6.7.3",
"pkg": "^4.4.9",
"publish-release": "^1.6.1",
"rewire": "^4.0.1",