From 5f2c4a5547fc9a70b2696ca34c7caff64f3ed674 Mon Sep 17 00:00:00 2001 From: John Schulz Date: Sun, 6 Dec 2020 19:41:49 -0500 Subject: [PATCH] Export a PackageSpec type vs repeating it --- .../plugins/fleet/common/types/models/epm.ts | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/x-pack/plugins/fleet/common/types/models/epm.ts b/x-pack/plugins/fleet/common/types/models/epm.ts index 7b20439c464078..c99ad71a2df6eb 100644 --- a/x-pack/plugins/fleet/common/types/models/epm.ts +++ b/x-pack/plugins/fleet/common/types/models/epm.ts @@ -68,16 +68,25 @@ export enum ElasticsearchAssetType { export type DataType = typeof dataTypes; -export type RegistryRelease = 'ga' | 'beta' | 'experimental'; +export type InstallablePackage = RegistryPackage | ArchivePackage; + +export type ArchivePackage = PackageSpecManifest & + // should an uploaded package be able to specify `internal`? + Pick; + +export type RegistryPackage = PackageSpecManifest & + Partial & + RegistryAdditionalProperties & + RegistryOverridePropertyValue; // Registry packages do have extra fields. // cf. type Package struct at https://github.com/elastic/package-registry/blob/master/util/package.go type RegistryOverridesToOptional = Pick; -// our current types have these as all required, buy they're are all optional (have `omitempty`) according to +// our current types have `download`, & `path` as required but they're are optional (have `omitempty`) according to // https://github.com/elastic/package-registry/blob/master/util/package.go#L57 // & https://github.com/elastic/package-registry/blob/master/util/package.go#L80-L81 -// However, are always present in every registry response I checked. Chose to keep types unchanged for now +// However, they are always present in every registry response I checked. Chose to keep types unchanged for now // and confirm with Registry if they are really optional. Can update types and ~4 places in code later if neccessary interface RegistryAdditionalProperties { assets?: string[]; @@ -87,23 +96,12 @@ interface RegistryAdditionalProperties { internal?: boolean; // Registry addition[0] and EPM uses it[1] [0]: https://github.com/elastic/package-registry/blob/dd7b021893aa8d66a5a5fde963d8ff2792a9b8fa/util/package.go#L63 [1] data_streams?: RegistryDataStream[]; // Registry addition [0] [0]: https://github.com/elastic/package-registry/blob/dd7b021893aa8d66a5a5fde963d8ff2792a9b8fa/util/package.go#L65 } - interface RegistryOverridePropertyValue { icons?: RegistryImage[]; screenshots?: RegistryImage[]; } -export type InstallablePackage = RegistryPackage | ArchivePackage; - -export type ArchivePackage = PackageSpecManifest & - // should an uploaded package be able to specify `internal`? - Pick; - -export type RegistryPackage = PackageSpecManifest & - Partial & - RegistryAdditionalProperties & - RegistryOverridePropertyValue; - +export type RegistryRelease = PackageSpecManifest['release']; export interface RegistryImage { src: string; path: string;