Skip to content

Commit

Permalink
fix(db-dynamodb): cloning array by wrong reference
Browse files Browse the repository at this point in the history
  • Loading branch information
brunozoric committed Dec 16, 2024
1 parent f9de254 commit 313c901
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ module.exports = () => {
});
});

createOrRefreshIndexSubscription.name =
"headlessCmsDdbEs.context.createOrRefreshIndexSubscription";

return {
storageOperations: createStorageOperations({
documentClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ContextPlugin } from "@webiny/api";
import { CmsContext } from "@webiny/api-headless-cms/types";

export const createDummyLocales = () => {
return new ContextPlugin<CmsContext>(async context => {
const plugin = new ContextPlugin<CmsContext>(async context => {
const { i18n, security } = context;

await security.withoutAuthorization(async () => {
Expand All @@ -23,4 +23,7 @@ export const createDummyLocales = () => {
});
});
});

plugin.name = "headlessCmsDdbEs.context.createDummyLocales";
return plugin;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -240,7 +240,7 @@ export class LocalesStorageOperations implements I18NLocalesStorageOperations {
* Use the common db-dynamodb method to create the required response.
*/
return createListResponse<I18NLocaleData>({
items: cleanupItems(this.entity.entity, sortedFiles),
items: sortedFiles,
after,
totalCount,
limit
Expand Down
8 changes: 4 additions & 4 deletions packages/db-dynamodb/src/utils/batch/EntityReadBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<T = GenericRecord>() {
return await batchReadAll<T>({
table: this.entity.table as TableDef,
items: this.items
items: this._items
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/db-dynamodb/src/utils/batch/EntityWriteBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 313c901

Please sign in to comment.