From 5196d250a1aaa68fcb534d7d94613772829ff710 Mon Sep 17 00:00:00 2001 From: "Tyler W. Walch" Date: Tue, 30 Jul 2024 10:54:52 -0400 Subject: [PATCH] Issue/412 (#413) * fixes issue 412 * Bumps version * adds gratitude * Adds gratitude --- CHANGELOG.md | 6 ++++- package.json | 2 +- src/entity.js | 12 +++++++-- test/ts_connected.entity.spec.ts | 45 ++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f847287a..8e9387e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -527,4 +527,8 @@ All notable changes to this project will be documented in this file. Breaking ch ## [2.14.2] - 2024-07-07 ### Fixed -- Raised via [Issue #196](https://github.com/tywalch/electrodb/issues/196) and [Issue #390](https://github.com/tywalch/electrodb/issues/398), a breaking change was made to the project's dependency `@aws-sdk/lib-dynamodb`. The change resulted in the error `Error: Cannot find module '@aws-sdk/lib-dynamodb/dist-cjs/commands/utils'`. This change updates ElectroDB's dependency version to the static version `3.395.0`, a version known to be compadible. Thank you github users @miyamonz, @kevinlonigro, @srodriki, @pablote, @sargisshahinyan, and @arpadgabor! \ No newline at end of file +- Raised via [Issue #196](https://github.com/tywalch/electrodb/issues/196) and [Issue #390](https://github.com/tywalch/electrodb/issues/398), a breaking change was made to the project's dependency `@aws-sdk/lib-dynamodb`. The change resulted in the error `Error: Cannot find module '@aws-sdk/lib-dynamodb/dist-cjs/commands/utils'`. This change updates ElectroDB's dependency version to the static version `3.395.0`, a version known to be compadible. Thank you github users @miyamonz, @kevinlonigro, @srodriki, @pablote, @sargisshahinyan, and @arpadgabor! + +## [2.14.3] - 2024-07-29 +### Fixed +- Raised via [Issue #196](https://github.com/tywalch/electrodb/issues/412) and [Discussion 361](https://github.com/tywalch/electrodb/discussions/361); When using a clustered index with an empty composite array, `update` and `patch` methods would not correctly form the complete sort key value for the index. This would prevent impacted items from being queried via an Entity, though they could be queried via a collection on a Service. Thank you to github users @daniel7byte and @santiagomera for raising this issue! \ No newline at end of file diff --git a/package.json b/package.json index 5a57b191..479b3e29 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "electrodb", - "version": "2.14.2", + "version": "2.14.3", "description": "A library to more easily create and interact with multiple entities and heretical relationships in dynamodb", "main": "index.js", "scripts": { diff --git a/src/entity.js b/src/entity.js index 242cb1f7..15a51d3f 100644 --- a/src/entity.js +++ b/src/entity.js @@ -3121,8 +3121,16 @@ class Entity { indexHasSk && this.model.facets.byIndex[index].sk.length === 0; let hasPrefix = indexHasSk && this.model.prefixes[index].sk.prefix !== undefined; - if (noImpactSk && noAttributeSk && hasPrefix) { - keys.sk.push(this.model.prefixes[index].sk.prefix); + let hasPostfix = + indexHasSk && this.model.prefixes[index].sk.prefix !== undefined; + if (noImpactSk && noAttributeSk) { + let key = hasPrefix ? this.model.prefixes[index].sk.prefix : ''; + if (hasPostfix) { + key = `${key}${this.model.prefixes[index].sk.postfix}`; + } + if (key) { + keys.sk.push(key); + } } } diff --git a/test/ts_connected.entity.spec.ts b/test/ts_connected.entity.spec.ts index f8cab081..8ef11edd 100644 --- a/test/ts_connected.entity.spec.ts +++ b/test/ts_connected.entity.spec.ts @@ -4025,6 +4025,51 @@ describe("index condition", () => { }); } + describe('github issue 412', () => { + const MyEntity = new Entity({ + model: { + version: '1', + service: 'app', + entity: 'myEntity', + }, + attributes: { + id: { type: 'string' , required: true }, + name: { type: 'string' , required: true }, + date: { type: 'string' , required: true }, + }, + indexes: { + primary: { + pk: { field: 'pk', composite: ['id'] }, + sk: { field: 'sk', composite: [] } + }, + byName: { + collection: 'names', + type: 'clustered', + index: 'gsic1', + pk: { field: 'gsic1pk', composite: ['name'] }, + sk: { field: 'gsic1sk', composite: [] } + } + } + }, { table }); + + it('should correctly format a clustered index sort key without composite attributes when updating', () => { + const params = MyEntity.update({ id: '1' }).set({ name: 'qwerty', date: '2024-07-25' }).params(); + expect(params.ExpressionAttributeValues[':gsic1sk_u0']).to.be.equal("$names#myentity_1"); + + }); + + it('should correctly format a clustered index sort key without composite attributes when patching', () => { + const params = MyEntity.patch({ id: '1' }).set({ name: 'qwerty', date: '2024-07-25' }).params(); + expect(params.ExpressionAttributeValues[':gsic1sk_u0']).to.be.equal("$names#myentity_1"); + + }); + + it('should correctly format a clustered index sort key without composite attributes when upserting', () => { + const params = MyEntity.upsert({ id: '1' }).set({ name: 'qwerty', date: '2024-07-25' }).params(); + expect(params.ExpressionAttributeValues[':gsic1sk_u0']).to.be.equal("$names#myentity_1"); + }); + }); + describe('github issue 366', () => { it('should recreate exact model from issue but as an upsert', async () => {