electrodb 1.6.2 → 1.6.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/CHANGELOG.md CHANGED
@@ -140,6 +140,10 @@ All notable changes to this project will be documented in this file. Breaking ch
140
140
  ### Fixed
141
141
  - In some cases the `find()` and `match()` methods would incorrectly select an index without a complete partition key. This would result in validation exceptions preventing the user from querying if an index definition and provided attribute object aligned improperly. This was fixed and a slightly more robust mechanism for ranking indexes was made.
142
142
 
143
- ## [1.6.2] = 2021-01-27
143
+ ## [1.6.2] - 2022-01-27
144
144
  ### Changed
145
- - The methods `create`, `patch`, and `remove` will now refer to primary table keys through parameters via ExpressionAttributeNames when using `attribute_exists()`/`attribute_not_exists()` DynamoDB conditions. Prior to this they were referenced directly which would fail in cases where key names include illegal characters. Parameter implementation change only, non-breaking.
145
+ - The methods `create`, `patch`, and `remove` will now refer to primary table keys through parameters via ExpressionAttributeNames when using `attribute_exists()`/`attribute_not_exists()` DynamoDB conditions. Prior to this they were referenced directly which would fail in cases where key names include illegal characters. Parameter implementation change only, non-breaking.
146
+
147
+ ## [1.6.3] - 2022-02-22
148
+ ### Added
149
+ - Add `data` update operation `ifNotExists` to allow for use of the UpdateExpression function "if_not_exists()".
package/README.md CHANGED
@@ -3462,7 +3462,8 @@ operation | example | result
3462
3462
  `delete` | `delete(tenant, name)` | `#tenant :tenant1` | Remove item from existing `set` attribute
3463
3463
  `del` | `del(tenant, name)` | `#tenant :tenant1` | Alias for `delete` operation
3464
3464
  `name` | `name(rent)` | `#rent` | Reference another attribute's name, can be passed to other operation that allows leveraging existing attribute values in calculating new values
3465
- `value` | `value(rent, value)` | `:rent1` | Create a reference to a particular value, can be passed to other operation that allows leveraging existing attribute values in calculating new values
3465
+ `value` | `value(rent, amount)` | `:rent1` | Create a reference to a particular value, can be passed to other operation that allows leveraging existing attribute values in calculating new values
3466
+ `ifNotExists` | `ifNotExists(rent, amount)` | `#rent = if_not_exists(#rent, :rent0)` | Update a property's value only if that property doesn't yet exist on the record
3466
3467
 
3467
3468
  ```javascript
3468
3469
  await StoreLocations
package/index.d.ts CHANGED
@@ -954,6 +954,7 @@ type DataUpdateOperations<A extends string, F extends A, C extends string, S ext
954
954
  del: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: A extends DataUpdateAttributeSymbol<infer V> ? V extends Array<any> ? V : never : never ) => any;
955
955
  value: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: DataUpdateAttributeValues<A>) => Required<DataUpdateAttributeValues<A>>;
956
956
  name: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A) => any;
957
+ ifNotExists: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: DataUpdateAttributeValues<A>) => any;
957
958
  };
958
959
 
959
960
  type WhereCallback<A extends string, F extends A, C extends string, S extends Schema<A,F,C>, I extends Item<A,F,C,S,S["attributes"]>> =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electrodb",
3
- "version": "1.6.2",
3
+ "version": "1.6.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/operations.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const {AttributeTypes, ItemOperations, AttributeProxySymbol, BuilderTypes} = require("./types");
2
2
  const e = require("./errors");
3
- const v = require("./util");
3
+ const u = require("./util");
4
4
 
5
5
  const deleteOperations = {
6
6
  canNest: false,
@@ -21,6 +21,13 @@ const deleteOperations = {
21
21
  };
22
22
 
23
23
  const UpdateOperations = {
24
+ ifNotExists: {
25
+ template: function if_not_exists(options, attr, path, value) {
26
+ const operation = ItemOperations.set;
27
+ const expression = `${path} = if_not_exists(${path}, ${value})`;
28
+ return {operation, expression};
29
+ }
30
+ },
24
31
  name: {
25
32
  canNest: true,
26
33
  template: function name(options, attr, path) {
@@ -325,7 +332,7 @@ class AttributeOperationProxy {
325
332
  fromObject(operation, record) {
326
333
  for (let path of Object.keys(record)) {
327
334
  const value = record[path];
328
- const parts = v.parseJSONPath(path);
335
+ const parts = u.parseJSONPath(path);
329
336
  let attribute = this.attributes;
330
337
  for (let part of parts) {
331
338
  attribute = attribute[part];
@@ -342,7 +349,7 @@ class AttributeOperationProxy {
342
349
 
343
350
  fromArray(operation, paths) {
344
351
  for (let path of paths) {
345
- const parts = v.parseJSONPath(path);
352
+ const parts = u.parseJSONPath(path);
346
353
  let attribute = this.attributes;
347
354
  for (let part of parts) {
348
355
  attribute = attribute[part];