From 313c9017be5b1734a167e49d95b074a980e084ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Zori=C4=87?= Date: Mon, 16 Dec 2024 15:01:06 +0100 Subject: [PATCH] fix(db-dynamodb): cloning array by wrong reference --- .../__tests__/__api__/setupFile.js | 3 +++ .../__tests__/converters/convertersDisabled.test.ts | 2 -- .../__tests__/graphql/dummyLocales.ts | 5 ++++- .../src/operations/locales/LocalesStorageOperations.ts | 4 ++-- packages/db-dynamodb/src/utils/batch/EntityReadBatch.ts | 8 ++++---- packages/db-dynamodb/src/utils/batch/EntityWriteBatch.ts | 2 +- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/api-headless-cms-ddb-es/__tests__/__api__/setupFile.js b/packages/api-headless-cms-ddb-es/__tests__/__api__/setupFile.js index e657c72bbb3..a436a3f75d9 100644 --- a/packages/api-headless-cms-ddb-es/__tests__/__api__/setupFile.js +++ b/packages/api-headless-cms-ddb-es/__tests__/__api__/setupFile.js @@ -66,6 +66,9 @@ module.exports = () => { }); }); + createOrRefreshIndexSubscription.name = + "headlessCmsDdbEs.context.createOrRefreshIndexSubscription"; + return { storageOperations: createStorageOperations({ documentClient, diff --git a/packages/api-headless-cms-ddb-es/__tests__/converters/convertersDisabled.test.ts b/packages/api-headless-cms-ddb-es/__tests__/converters/convertersDisabled.test.ts index b3193273d49..dac86634f7c 100644 --- a/packages/api-headless-cms-ddb-es/__tests__/converters/convertersDisabled.test.ts +++ b/packages/api-headless-cms-ddb-es/__tests__/converters/convertersDisabled.test.ts @@ -7,8 +7,6 @@ import { CmsModel } from "@webiny/api-headless-cms/types"; import { get } from "@webiny/db-dynamodb"; import { createPartitionKey } from "~/operations/entry/keys"; -jest.retryTimes(0); - describe("storage field path converters disabled", () => { const { elasticsearch, entryEntity } = useHandler(); diff --git a/packages/api-headless-cms-ddb-es/__tests__/graphql/dummyLocales.ts b/packages/api-headless-cms-ddb-es/__tests__/graphql/dummyLocales.ts index 9424ee10e21..f6b763e697c 100644 --- a/packages/api-headless-cms-ddb-es/__tests__/graphql/dummyLocales.ts +++ b/packages/api-headless-cms-ddb-es/__tests__/graphql/dummyLocales.ts @@ -2,7 +2,7 @@ import { ContextPlugin } from "@webiny/api"; import { CmsContext } from "@webiny/api-headless-cms/types"; export const createDummyLocales = () => { - return new ContextPlugin(async context => { + const plugin = new ContextPlugin(async context => { const { i18n, security } = context; await security.withoutAuthorization(async () => { @@ -23,4 +23,7 @@ export const createDummyLocales = () => { }); }); }); + + plugin.name = "headlessCmsDdbEs.context.createDummyLocales"; + return plugin; }; diff --git a/packages/api-i18n-ddb/src/operations/locales/LocalesStorageOperations.ts b/packages/api-i18n-ddb/src/operations/locales/LocalesStorageOperations.ts index 8a28a945747..18e344863d6 100644 --- a/packages/api-i18n-ddb/src/operations/locales/LocalesStorageOperations.ts +++ b/packages/api-i18n-ddb/src/operations/locales/LocalesStorageOperations.ts @@ -16,7 +16,7 @@ import WebinyError from "@webiny/error"; import defineTable from "~/definitions/table"; import defineLocaleEntity from "~/definitions/localeEntity"; import type { IEntity, IEntityQueryAllParams } from "@webiny/db-dynamodb"; -import { cleanupItems, createListResponse, filterItems, sortItems } from "@webiny/db-dynamodb"; +import { createListResponse, filterItems, sortItems } from "@webiny/db-dynamodb"; import { LocaleDynamoDbFieldPlugin } from "~/plugins/LocaleDynamoDbFieldPlugin"; interface ConstructorParams { @@ -240,7 +240,7 @@ export class LocalesStorageOperations implements I18NLocalesStorageOperations { * Use the common db-dynamodb method to create the required response. */ return createListResponse({ - items: cleanupItems(this.entity.entity, sortedFiles), + items: sortedFiles, after, totalCount, limit diff --git a/packages/db-dynamodb/src/utils/batch/EntityReadBatch.ts b/packages/db-dynamodb/src/utils/batch/EntityReadBatch.ts index 4464a4f1ea3..862dcd1d315 100644 --- a/packages/db-dynamodb/src/utils/batch/EntityReadBatch.ts +++ b/packages/db-dynamodb/src/utils/batch/EntityReadBatch.ts @@ -18,7 +18,7 @@ export interface IEntityReadBatchParams { export class EntityReadBatch implements IEntityReadBatch { private readonly entity: Entity; private readonly builder: IEntityReadBatchBuilder; - private readonly items: IEntityReadBatchBuilderGetResponse[] = []; + private readonly _items: IEntityReadBatchBuilderGetResponse[] = []; public constructor(params: IEntityReadBatchParams) { if (!params.entity.name) { @@ -31,20 +31,20 @@ export class EntityReadBatch implements IEntityReadBatch { } public get(input: IEntityReadBatchKey | IEntityReadBatchKey[]): void { if (Array.isArray(input)) { - this.items.push( + this._items.push( ...input.map(item => { return this.builder.get(item); }) ); return; } - this.items.push(this.builder.get(input)); + this._items.push(this.builder.get(input)); } public async execute() { return await batchReadAll({ table: this.entity.table as TableDef, - items: this.items + items: this._items }); } } diff --git a/packages/db-dynamodb/src/utils/batch/EntityWriteBatch.ts b/packages/db-dynamodb/src/utils/batch/EntityWriteBatch.ts index 6cc19de71e9..d98fa8156ea 100644 --- a/packages/db-dynamodb/src/utils/batch/EntityWriteBatch.ts +++ b/packages/db-dynamodb/src/utils/batch/EntityWriteBatch.ts @@ -28,7 +28,7 @@ export class EntityWriteBatch implements IEntityWriteBatch { } public get items(): BatchWriteItem[] { - return Array.from(this.items); + return Array.from(this._items); } public constructor(params: IEntityWriteBatchParams) {