Skip to content

Commit

Permalink
Issue/412 (#413)
Browse files Browse the repository at this point in the history
* fixes issue 412

* Bumps version

* adds gratitude

* Adds gratitude
  • Loading branch information
tywalch authored Jul 30, 2024
1 parent 7de5b06 commit 5196d25
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
- 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!
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
12 changes: 10 additions & 2 deletions src/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
45 changes: 45 additions & 0 deletions test/ts_connected.entity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {

Expand Down

0 comments on commit 5196d25

Please sign in to comment.