Skip to content

Commit

Permalink
Export a PackageSpec type vs repeating it
Browse files Browse the repository at this point in the history
  • Loading branch information
John Schulz committed Dec 7, 2020
1 parent efc73f9 commit 5f2c4a5
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions x-pack/plugins/fleet/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RegistryPackage, 'readme' | 'assets' | 'data_streams' | 'internal'>;

export type RegistryPackage = PackageSpecManifest &
Partial<RegistryOverridesToOptional> &
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<PackageSpecManifest, 'title' | 'release'>;

// 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[];
Expand All @@ -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<RegistryPackage, 'readme' | 'assets' | 'data_streams' | 'internal'>;

export type RegistryPackage = PackageSpecManifest &
Partial<RegistryOverridesToOptional> &
RegistryAdditionalProperties &
RegistryOverridePropertyValue;

export type RegistryRelease = PackageSpecManifest['release'];
export interface RegistryImage {
src: string;
path: string;
Expand Down

0 comments on commit 5f2c4a5

Please sign in to comment.