Skip to content

Commit

Permalink
Change property names to better align with other APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry350 committed May 15, 2023
1 parent ed121b5 commit a6a2cd1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/common/types/rest_spec/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ interface InstalledPackage {
export interface GetInstalledPackagesResponse {
items: InstalledPackage[];
total: number;
pageAfter?: SortResults;
searchAfter?: SortResults;
}

export interface GetEpmDataStreamsResponse {
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/fleet/server/services/epm/data_streams/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export async function getDataStreams(options: {
esClient: ElasticsearchClient;
type?: PackageDataStreamTypes;
datasetQuery?: string;
sortDirection: 'asc' | 'desc';
sortOrder: 'asc' | 'desc';
uncategorisedOnly: boolean;
}) {
const { esClient, type, datasetQuery, uncategorisedOnly, sortDirection } = options;
const { esClient, type, datasetQuery, uncategorisedOnly, sortOrder } = options;

const allDataStreams = await dataStreamService.getMatchingDataStreams(esClient, {
type: type ? type : '*',
Expand All @@ -39,7 +39,7 @@ export async function getDataStreams(options: {
return a.name.localeCompare(b.name);
});

const dataStreams = sortDirection === 'asc' ? sortedDataStreams : sortedDataStreams.reverse();
const dataStreams = sortOrder === 'asc' ? sortedDataStreams : sortedDataStreams.reverse();

return {
items: dataStreams,
Expand Down
27 changes: 14 additions & 13 deletions x-pack/plugins/fleet/server/services/epm/packages/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,23 @@ export async function getPackages(

export async function getInstalledPackages(options: {
savedObjectsClient: SavedObjectsClientContract;
type?: PackageDataStreamTypes;
dataStreamType?: PackageDataStreamTypes;
nameQuery?: string;
pageAfter?: SortResults;
pageSize: number;
sortDirection: 'asc' | 'desc';
searchAfter?: SortResults;
perPage: number;
sortOrder: 'asc' | 'desc';
}) {
const { savedObjectsClient, pageAfter, pageSize, nameQuery, sortDirection, type } = options;
const { savedObjectsClient, searchAfter, perPage, nameQuery, sortOrder, dataStreamType } =
options;

const packageSavedObjects = await savedObjectsClient.find<Installation>({
type: PACKAGES_SAVED_OBJECT_TYPE,
// Pagination
perPage: pageSize,
...(pageAfter && { searchAfter: pageAfter }),
perPage,
...(searchAfter && { searchAfter }),
// Sort
sortField: 'name',
sortOrder: sortDirection,
sortOrder,
// Name filter
...(nameQuery && { searchFields: ['name'] }),
...(nameQuery && { search: `${nameQuery}* | ${nameQuery}` }),
Expand All @@ -184,12 +185,12 @@ export async function getInstalledPackages(options: {
nodeBuilder.is('type', 'index_template')
),
// "Type" filter
...(type
...(dataStreamType
? [
buildFunctionNode(
'nested',
`${PACKAGES_SAVED_OBJECT_TYPE}.attributes.installed_es`,
nodeBuilder.is('id', buildWildcardNode(`${type}-*`))
nodeBuilder.is('id', buildWildcardNode(`${dataStreamType}-*`))
),
]
: []),
Expand All @@ -212,10 +213,10 @@ export async function getInstalledPackages(options: {
};
})
.filter((stream) => {
if (!type) {
if (!dataStreamType) {
return true;
} else {
return stream.title.startsWith(`${type}-`);
return stream.title.startsWith(`${dataStreamType}-`);
}
});

Expand All @@ -230,7 +231,7 @@ export async function getInstalledPackages(options: {
return {
items: integrations,
total: packageSavedObjects.total,
pageAfter: packageSavedObjects.saved_objects.at(-1)?.sort, // Enable ability to use searchAfter in subsequent queries
searchAfter: packageSavedObjects.saved_objects.at(-1)?.sort, // Enable ability to use searchAfter in subsequent queries
};
}

Expand Down
10 changes: 5 additions & 5 deletions x-pack/plugins/fleet/server/types/rest_spec/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const GetPackagesRequestSchema = {

export const GetInstalledPackagesRequestSchema = {
query: schema.object({
type: schema.maybe(
dataStreamType: schema.maybe(
schema.oneOf([
schema.literal('logs'),
schema.literal('metrics'),
Expand All @@ -36,9 +36,9 @@ export const GetInstalledPackagesRequestSchema = {
])
),
nameQuery: schema.maybe(schema.string()),
pageAfter: schema.maybe(schema.arrayOf(schema.oneOf([schema.string(), schema.number()]))),
pageSize: schema.number({ defaultValue: 30 }),
sortDirection: schema.oneOf([schema.literal('asc'), schema.literal('desc')], {
searchAfter: schema.maybe(schema.arrayOf(schema.oneOf([schema.string(), schema.number()]))),
perPage: schema.number({ defaultValue: 30 }),
sortOrder: schema.oneOf([schema.literal('asc'), schema.literal('desc')], {
defaultValue: 'asc',
}),
}),
Expand All @@ -56,7 +56,7 @@ export const GetDataStreamsRequestSchema = {
])
),
datasetQuery: schema.maybe(schema.string()),
sortDirection: schema.oneOf([schema.literal('asc'), schema.literal('desc')], {
sortOrder: schema.oneOf([schema.literal('asc'), schema.literal('desc')], {
defaultValue: 'asc',
}),
uncategorisedOnly: schema.boolean({ defaultValue: true }),
Expand Down

0 comments on commit a6a2cd1

Please sign in to comment.