electrodb 2.12.1 → 2.12.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electrodb",
3
- "version": "2.12.1",
3
+ "version": "2.12.3",
4
4
  "description": "A library to more easily create and interact with multiple entities and heretical relationships in dynamodb",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/entity.js CHANGED
@@ -343,6 +343,7 @@ class Entity {
343
343
  collection(collection = "", clauses = {}, facets = {}, options = {}) {
344
344
  const chainOptions = {
345
345
  ...options,
346
+ _isPagination: true,
346
347
  _isCollectionQuery: true,
347
348
  };
348
349
 
@@ -2211,30 +2212,61 @@ class Entity {
2211
2212
  let { pk, sk } = this._makeIndexKeys({
2212
2213
  index: indexBase,
2213
2214
  });
2215
+
2214
2216
  let keys = this._makeParameterKey(indexBase, pk, ...sk);
2217
+ // trim empty key values (this can occur when keys are defined by users)
2218
+ for (let key in keys) {
2219
+ if (keys[key] === undefined || keys[key] === '') {
2220
+ delete keys[key];
2221
+ }
2222
+ }
2223
+
2215
2224
  let keyExpressions = this._expressionAttributeBuilder(keys);
2216
- let params = {
2217
- TableName: this.getTableName(),
2218
- ExpressionAttributeNames: this._mergeExpressionsAttributes(
2225
+
2226
+ const expressionAttributeNames = this._mergeExpressionsAttributes(
2219
2227
  filter.getNames(),
2220
2228
  keyExpressions.ExpressionAttributeNames,
2221
- ),
2222
- ExpressionAttributeValues: this._mergeExpressionsAttributes(
2229
+ );
2230
+
2231
+ const expressionAttributeValues = this._mergeExpressionsAttributes(
2223
2232
  filter.getValues(),
2224
2233
  keyExpressions.ExpressionAttributeValues,
2225
- ),
2226
- FilterExpression: `begins_with(#${pkField}, :${pkField})`,
2234
+ );
2235
+
2236
+
2237
+ let params = {
2238
+ TableName: this.getTableName(),
2227
2239
  };
2228
2240
 
2241
+ if (Object.keys(expressionAttributeNames).length) {
2242
+ params['ExpressionAttributeNames'] = expressionAttributeNames;
2243
+ }
2244
+
2245
+ if (Object.keys(expressionAttributeValues).length) {
2246
+ params['ExpressionAttributeValues'] = expressionAttributeValues;
2247
+ }
2248
+
2249
+ let filterExpressions = [];
2250
+
2251
+ if (keys[pkField]) {
2252
+ filterExpressions.push(`begins_with(#${pkField}, :${pkField})`);
2253
+ }
2254
+
2229
2255
  if (hasSortKey) {
2230
2256
  let skField = this.model.indexes[accessPattern].sk.field;
2231
- params.FilterExpression = `${params.FilterExpression} AND begins_with(#${skField}, :${skField})`;
2257
+ if (keys[skField]) {
2258
+ filterExpressions.push(`begins_with(#${skField}, :${skField})`);
2259
+ }
2232
2260
  }
2261
+
2233
2262
  if (filter.build()) {
2234
- params.FilterExpression = `${
2235
- params.FilterExpression
2236
- } AND ${filter.build()}`;
2263
+ filterExpressions.push(filter.build());
2237
2264
  }
2265
+
2266
+ if (filterExpressions.length) {
2267
+ params.FilterExpression = filterExpressions.join(' AND ');
2268
+ }
2269
+
2238
2270
  return params;
2239
2271
  }
2240
2272