Skip to content

Commit

Permalink
Refactors to remove pinned aws-sdk version (#428)
Browse files Browse the repository at this point in the history
* Refactors to remove pinned aws-sdk version

* Updates changelog
  • Loading branch information
tywalch authored Sep 20, 2024
1 parent 219cf28 commit 57b1cf2
Show file tree
Hide file tree
Showing 7 changed files with 24,434 additions and 16,908 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -531,4 +531,9 @@ All notable changes to this project will be documented in this file. Breaking ch

## [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!
- 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.15.0] - 2024-09-19
### Updated
- Updated `@aws-sdk/lib-dynamodb` dependency from pinned version `3.395.0` to latest release `^3.654.0`. This impacts users using the v3 aws-sdk.
- Adds dependency `@aws-sdk/util-dynamodb` for unmarshalling functionality.
2 changes: 1 addition & 1 deletion buildbrowser.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
original_line_lib="const lib = require\('@aws-sdk\/lib-dynamodb'\)"
safe_line_lib="const lib = {}"
original_line_unmarshall_output="const util = require\('@aws-sdk\/lib-dynamodb\/dist-cjs\/commands\/utils'\)"
original_line_unmarshall_output="const util = require\('@aws-sdk\/util-dynamodb'\)"
safe_line_unmarshall_output="const util = {}"
filePath="./src/client.js"

Expand Down
41,291 changes: 24,401 additions & 16,890 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electrodb",
"version": "2.14.3",
"version": "2.15.0",
"description": "A library to more easily create and interact with multiple entities and heretical relationships in dynamodb",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -55,6 +55,7 @@
"@types/mocha": "^8.0.3",
"@types/node": "^15.14.9",
"@types/uuid": "^8.3.0",
"aws-cdk-lib": "^2.100.0",
"aws-sdk": "2.630.0",
"browserify": "^17.0.0",
"chai": "4.2.0",
Expand All @@ -72,8 +73,7 @@
"ts-node": "^10.9.1",
"tsd": "^0.28.1",
"typescript": "^5.2.2",
"uuid": "7.0.1",
"aws-cdk-lib": "^2.100.0"
"uuid": "7.0.1"
},
"keywords": [
"electrodb",
Expand All @@ -88,7 +88,8 @@
"directory": "test"
},
"dependencies": {
"@aws-sdk/lib-dynamodb": "3.395.0",
"@aws-sdk/lib-dynamodb": "^3.654.0",
"@aws-sdk/util-dynamodb": "^3.654.0",
"jsonschema": "1.2.7"
}
}
19 changes: 14 additions & 5 deletions src/client.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
const lib = require('@aws-sdk/lib-dynamodb')
const util = require('@aws-sdk/lib-dynamodb/dist-cjs/commands/utils')
const util = require('@aws-sdk/util-dynamodb')
const { isFunction } = require("./validations");
const { ElectroError, ErrorCodes } = require("./errors");
const DocumentClientVersions = {
v2: "v2",
v3: "v3",
electro: "electro",
};
const unmarshallOutput = util.unmarshallOutput || ((val) => val);
const unmarshallItem = (value) => {
const unmarshall = util.unmarshall || ((val) => val);
try {
value.Item = unmarshall(value.Item);
} catch(err) {
console.error('Internal Error: Failed to unmarshal input', err);
}

return value;
}

const v3Methods = ["send"];
const v2Methods = [
Expand Down Expand Up @@ -89,7 +98,7 @@ class DocumentClientV2Wrapper {
return {
canceled: cancellationReasons.map((reason) => {
if (reason.Item) {
return unmarshallOutput(reason, [{ key: "Item" }]);
return unmarshallItem(reason);
}
return reason;
}),
Expand Down Expand Up @@ -202,7 +211,7 @@ class DocumentClientV3Wrapper {
return {
canceled: err.CancellationReasons.map((reason) => {
if (reason.Item) {
return unmarshallOutput(reason, [{ key: "Item" }]);
return unmarshallItem(reason);
}
return reason;
}),
Expand All @@ -225,7 +234,7 @@ class DocumentClientV3Wrapper {
return {
canceled: err.CancellationReasons.map((reason) => {
if (reason.Item) {
return unmarshallOutput(reason, [{ key: "Item" }]);
return unmarshallItem(reason);
}
return reason;
}),
Expand Down
4 changes: 1 addition & 3 deletions test/connected.crud.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3958,8 +3958,6 @@ for (const [clientVersion, client] of [
} else {
expect(updateRecord).to.have.keys([
"$metadata",
"Attributes",
"ItemCollectionMetrics",
]);
}

Expand All @@ -3984,11 +3982,11 @@ for (const [clientVersion, client] of [
ScannedCount: 1,
});
} else {
console.log({queryRecord});
expect(queryRecord).to.have.keys([
"Items",
"Count",
"ScannedCount",
"LastEvaluatedKey",
"$metadata",
]);
}
Expand Down
10 changes: 6 additions & 4 deletions test/ts_connected.crud.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5466,6 +5466,8 @@ describe("upsert", () => {
});

it("should allow calculated field createdAt/updatedAt pattern with upsert", async () => {
let createdAt = Date.now();
let updatedAt = Date.now();
const entity = new Entity(
{
model: {
Expand All @@ -5487,15 +5489,15 @@ describe("upsert", () => {
type: "number",
readOnly: true,
required: true,
default: () => Date.now(),
set: () => Date.now(),
default: () => createdAt++,
set: () => createdAt++,
},
updatedAt: {
type: "number",
watch: "*",
required: true,
default: () => Date.now(),
set: () => Date.now(),
default: () => updatedAt++,
set: () => updatedAt++,
},
},
indexes: {
Expand Down

0 comments on commit 57b1cf2

Please sign in to comment.