diff --git a/packages/catalog-client/report.api.md b/packages/catalog-client/report.api.md index 5bb36e16fc..4175cf3a4b 100644 --- a/packages/catalog-client/report.api.md +++ b/packages/catalog-client/report.api.md @@ -335,10 +335,10 @@ export type QueryEntitiesResponse = { // @public export type StreamEntitiesRequest = Omit< - QueryEntitiesRequest, + QueryEntitiesInitialRequest, 'limit' | 'offset' > & { - batchSize?: number; + pageSize?: number; }; // @public diff --git a/packages/catalog-client/src/CatalogClient.ts b/packages/catalog-client/src/CatalogClient.ts index e83fd362da..c777c48940 100644 --- a/packages/catalog-client/src/CatalogClient.ts +++ b/packages/catalog-client/src/CatalogClient.ts @@ -49,9 +49,7 @@ import type { AnalyzeLocationRequest, AnalyzeLocationResponse, } from '@backstage/plugin-catalog-common'; - -// Number of entities to return in a single streamEntities request -const DEFAULT_STREAM_ENTITIES_LIMIT = 500; +import { DEFAULT_STREAM_ENTITIES_LIMIT } from './constants.ts'; /** * A frontend and backend compatible client for communicating with the Backstage @@ -483,7 +481,7 @@ export class CatalogClient implements CatalogApi { options?: CatalogRequestOptions, ): AsyncIterable { let cursor: string | undefined = undefined; - const limit = request?.batchSize ?? DEFAULT_STREAM_ENTITIES_LIMIT; + const limit = request?.pageSize ?? DEFAULT_STREAM_ENTITIES_LIMIT; do { const res = await this.queryEntities( cursor ? { ...request, cursor, limit } : { ...request, limit }, diff --git a/packages/catalog-client/src/constants.ts b/packages/catalog-client/src/constants.ts new file mode 100644 index 0000000000..dd8d0530df --- /dev/null +++ b/packages/catalog-client/src/constants.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2025 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export const DEFAULT_STREAM_ENTITIES_LIMIT = 500; diff --git a/packages/catalog-client/src/testUtils/InMemoryCatalogClient.ts b/packages/catalog-client/src/testUtils/InMemoryCatalogClient.ts index c033ced387..ef125d3c3a 100644 --- a/packages/catalog-client/src/testUtils/InMemoryCatalogClient.ts +++ b/packages/catalog-client/src/testUtils/InMemoryCatalogClient.ts @@ -49,6 +49,7 @@ import type { AnalyzeLocationRequest, AnalyzeLocationResponse, } from '@backstage/plugin-catalog-common'; +import { DEFAULT_STREAM_ENTITIES_LIMIT } from '../constants.ts'; function buildEntitySearch(entity: Entity) { const rows = traverse(entity); @@ -295,9 +296,10 @@ export class InMemoryCatalogClient implements CatalogApi { request?: StreamEntitiesRequest, ): AsyncIterable { let cursor: string | undefined = undefined; + const limit = request?.pageSize ?? DEFAULT_STREAM_ENTITIES_LIMIT; do { const res = await this.queryEntities( - cursor ? { ...request, cursor } : request, + cursor ? { ...request, limit, cursor } : { ...request, limit }, ); yield res.items; diff --git a/packages/catalog-client/src/types/api.ts b/packages/catalog-client/src/types/api.ts index 56872c60c8..6a83b95d6e 100644 --- a/packages/catalog-client/src/types/api.ts +++ b/packages/catalog-client/src/types/api.ts @@ -471,13 +471,13 @@ export type QueryEntitiesResponse = { * @public */ export type StreamEntitiesRequest = Omit< - QueryEntitiesRequest, + QueryEntitiesInitialRequest, 'limit' | 'offset' > & { /** - * The number of entities to fetch in each batch. Defaults to 500. + * The number of entities to fetch in each page. Defaults to 500. */ - batchSize?: number; + pageSize?: number; }; /**