From 7b9862fcf446137732627d249f3c757caf869e03 Mon Sep 17 00:00:00 2001 From: Max Polsky Date: Thu, 21 Mar 2024 16:32:11 +0200 Subject: [PATCH] Refactor index API response structure --- .../test/drivers/index_api_rest_matchers.ts | 10 ++++++---- .../test/drivers/index_api_rest_test_support.ts | 2 +- libs/velo-external-db-core/src/router.ts | 4 ++-- libs/velo-external-db-core/src/spi-model/indexing.ts | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/apps/velo-external-db/test/drivers/index_api_rest_matchers.ts b/apps/velo-external-db/test/drivers/index_api_rest_matchers.ts index 2df60bd28..64a423d38 100644 --- a/apps/velo-external-db/test/drivers/index_api_rest_matchers.ts +++ b/apps/velo-external-db/test/drivers/index_api_rest_matchers.ts @@ -16,13 +16,15 @@ export const failedIndexCreationResponse = (index: indexSpi.Index) => ({ }) -export const listIndexResponseWithDefaultIndex = () => - expect.arrayContaining([toHaveDefaultIndex()]) +export const listIndexResponseWithDefaultIndex = () => ({ + indexes: expect.arrayContaining([toHaveDefaultIndex()]) +}) -export const listIndexResponseWith = (indexes: indexSpi.Index[]) => - expect.arrayContaining( +export const listIndexResponseWith = (indexes: indexSpi.Index[]) => ({ + indexes: expect.arrayContaining( [...indexes.map((index: indexSpi.Index) => indexWith(index, { status: IndexStatus.ACTIVE }))] ) +}) export const toHaveDefaultIndex = () => ({ name: expect.any(String), diff --git a/apps/velo-external-db/test/drivers/index_api_rest_test_support.ts b/apps/velo-external-db/test/drivers/index_api_rest_test_support.ts index 9a7b939b2..2e67a0b08 100644 --- a/apps/velo-external-db/test/drivers/index_api_rest_test_support.ts +++ b/apps/velo-external-db/test/drivers/index_api_rest_test_support.ts @@ -15,7 +15,7 @@ export const givenIndexes = async(collectionName: string, indexes: indexSpi.Inde const indexCreated = async(collectionName: string, indexName: string, auth: any) => { await waitUntil(async() => { - const indexes = await retrieveIndexesFor(collectionName, auth) as indexSpi.Index[] + const { indexes } = await retrieveIndexesFor(collectionName, auth) as indexSpi.ListIndexesResponse return indexes.some(index => index.name === indexName) }) } diff --git a/libs/velo-external-db-core/src/router.ts b/libs/velo-external-db-core/src/router.ts index 74d90b6d1..7471426e5 100644 --- a/libs/velo-external-db-core/src/router.ts +++ b/libs/velo-external-db-core/src/router.ts @@ -333,13 +333,13 @@ export const createRouter = () => { } }) - // *************** Indexes API ********************** + // *************** Indexes API ********************** router.post('/v3/indexes/list', async(req, res, next) => { try { const { collectionId } = req.body as ListIndexesRequest const indexes = await indexService.list(collectionId) - res.json(indexes) + res.json({ indexes }) } catch (e) { next(e) } diff --git a/libs/velo-external-db-core/src/spi-model/indexing.ts b/libs/velo-external-db-core/src/spi-model/indexing.ts index 57c7657d6..350309591 100644 --- a/libs/velo-external-db-core/src/spi-model/indexing.ts +++ b/libs/velo-external-db-core/src/spi-model/indexing.ts @@ -53,8 +53,8 @@ export interface ListIndexesRequest { collectionId: string; } -export interface ListIndexesResponse { - index: Index[]; +export type ListIndexesResponse = { + indexes: Index[]; } export interface CreateIndexRequest {