Skip to content

Commit 02a3d2d

Browse files
Fix Append On Upsert (#53)
1 parent ab79880 commit 02a3d2d

File tree

9 files changed

+26
-13
lines changed

9 files changed

+26
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Changed
1313

14-
- Fix types of not implemented repository methods
14+
### Fixed
15+
16+
- Types of not implemented repository methods
17+
- `Append` on upsert
1518

1619
### Removed

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"techmmunity-symbiosis"
2929
],
3030
"peerDependencies": {
31-
"@techmmunity/symbiosis": "^0.0.25",
31+
"@techmmunity/symbiosis": "^0.0.26",
3232
"reflect-metadata": "^0.1.13"
3333
},
3434
"dependencies": {
@@ -38,7 +38,7 @@
3838
},
3939
"devDependencies": {
4040
"@techmmunity/eslint-config": "^5.0.1",
41-
"@techmmunity/symbiosis": "^0.0.25",
41+
"@techmmunity/symbiosis": "^0.0.26",
4242
"@types/jest": "^27.0.1",
4343
"@vercel/ncc": "^0.31.1",
4444
"eslint": "^8.1.0",
@@ -56,12 +56,13 @@
5656
"ts-node": "ts-node",
5757
"test": "jest",
5858
"test:cov": "jest --coverage",
59-
"build": "ncc build src/index.ts -o dist -s -m",
59+
"build": "ncc build src/index.ts -o dist -s -m -e @aws-sdk/client-dynamodb -e @aws-sdk/util-dynamodb -e @techmmunity/utils",
60+
"build:dev": "ncc build src/index.ts -o dist -s -m",
6061
"format": "eslint . --fix --quiet",
6162
"lint": "eslint . --quiet",
6263
"update-dependencies": "yarn upgrade-interactive --latest",
6364
"husky:pre-commit": "tsc && lint-staged",
64-
"lk": "yarn build && cp package.json dist/package.json && cd dist && yarn link && cd ..",
65+
"lk": "yarn build:dev && cp package.json dist/package.json && cd dist && yarn link && cd ..",
6566
"ulk": "yarn unlink && yarn lk"
6667
}
6768
}

src/lib/repository/upsert/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const upsert = async <Entity>(
7373
code: "OPERATION_FAILED",
7474
origin: "DATABASE",
7575
message: "Operation failed",
76-
details: ["Fail to update item using the primary keys:", rawData],
76+
details: ["Fail to update item using the primary keys:", rawConditions],
7777
});
7878
}
7979

src/lib/utils/get-data-properties/get-expression-attribute-values.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const getExpressionAttributeValues = (valuesMap: ValuesMap) => {
2424
}
2525
case "append": {
2626
valuesEntriesToReturn.push([valueAlias, value.values]);
27+
valuesEntriesToReturn.push([":emptyList", []]);
2728

2829
return;
2930
}

src/lib/utils/get-data-properties/get-update-expression.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const getUpdateExpression = <Entity>({
3737

3838
case "append":
3939
expressions.set.push(
40-
`${keyAlias} = list_append(${keyAlias}, ${valueAlias})`,
40+
`${keyAlias} = list_append(if_not_exists(${keyAlias}, :emptyList), ${valueAlias})`,
4141
);
4242
break;
4343

src/tests/utils/get-data-properties/get-expression-attribute-values.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ describe("getExpressionAttributeValues", () => {
6464
expect(result).toStrictEqual({
6565
// eslint-disable-next-line @typescript-eslint/naming-convention
6666
":UPDATEbar": { L: [{ N: "1" }, { N: "2" }] },
67+
// eslint-disable-next-line @typescript-eslint/naming-convention
68+
":emptyList": { L: [] },
6769
});
6870
});
6971

src/tests/utils/get-data-properties/get-update-expression.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ describe("getUpdateExpression", () => {
117117
}
118118

119119
expect(result).toBe(
120-
"SET #UPDATEfoo = :UPDATEfoo, #UPDATEbar = :UPDATEbar, #UPDATEfoobar = :UPDATEfoobar, #UPDATEbarfoo = list_append(#UPDATEbarfoo, :UPDATEbarfoo)",
120+
"SET #UPDATEfoo = :UPDATEfoo, #UPDATEbar = :UPDATEbar, #UPDATEfoobar = :UPDATEfoobar, #UPDATEbarfoo = list_append(if_not_exists(#UPDATEbarfoo, :emptyList), :UPDATEbarfoo)",
121121
);
122122
});
123123

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"noUnusedParameters": true,
1818
"sourceMap": true,
1919
"incremental": true,
20+
"skipLibCheck": true,
2021
"types": ["node", "jest", "reflect-metadata"]
2122
},
2223
"include": ["src/**/*.ts", "jest.config.js"]

yarn.lock

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,21 +1223,26 @@
12231223
eslint-plugin-react-hooks "^4.2.1-alpha-4298ddbc5-20211023"
12241224
eslint-plugin-sonarjs "^0.10.0"
12251225

1226-
"@techmmunity/symbiosis@^0.0.25":
1227-
version "0.0.25"
1228-
resolved "https://registry.yarnpkg.com/@techmmunity/symbiosis/-/symbiosis-0.0.25.tgz#be1ad2c64a797b525dc146e0cdbb903c6b2d7b47"
1229-
integrity sha512-qGejrWxuPXBWOT4TjCds3Ie9jXiEMh19sh7eYUPS0AyalvHhCOlzZdyQA8fUg0XwLAGbfMltKUsk5KxiOvhoJQ==
1226+
"@techmmunity/symbiosis@^0.0.26":
1227+
version "0.0.26"
1228+
resolved "https://registry.yarnpkg.com/@techmmunity/symbiosis/-/symbiosis-0.0.26.tgz#1c198dc854b37d00657793ff53ce33bc5a0cf154"
1229+
integrity sha512-WEt7CXR/ahsXKkHubmI4/cnaeCcqDw2DVZ5eZRk0w8KqcjIHRl0C8KmKpA9P8veXUdxu4TKXOSFyWfau9QfzUQ==
12301230
dependencies:
12311231
"@techmmunity/utils" "^1.5.0"
12321232
change-case "^4.1.2"
12331233
dayjs "^1.10.6"
12341234
tiny-glob "^0.2.9"
12351235

1236-
"@techmmunity/utils@^1.3.0", "@techmmunity/utils@^1.5.0":
1236+
"@techmmunity/utils@^1.3.0":
12371237
version "1.5.0"
12381238
resolved "https://registry.yarnpkg.com/@techmmunity/utils/-/utils-1.5.0.tgz#2a5014536fc553206ab1a1aec11bb4b78a58a922"
12391239
integrity sha512-kZWJsXfpm+c/3SOw7C5BiEpGeuIEIfIuGSIXszOqOah8ne6uXQPlf3V20f5EY3jX9aWZfOCz7L5SV80wHdng+g==
12401240

1241+
"@techmmunity/utils@^1.5.0":
1242+
version "1.6.0"
1243+
resolved "https://registry.yarnpkg.com/@techmmunity/utils/-/utils-1.6.0.tgz#ca8e6cfa564236e7f3aac41bfdd431959a970042"
1244+
integrity sha512-u90x3wvPyIDEGgzWf9NL/8EoMdNPSPy/7gb3oY5NbXcnCLqLyoufpdEdU4OVQOzLV4OHzNhmk3Py57u+F5SRnQ==
1245+
12411246
"@tootallnate/once@1":
12421247
version "1.1.2"
12431248
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82"

0 commit comments

Comments
 (0)