electrodb 3.4.3 → 3.4.5
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 +1 -1
- package/src/entity.js +9 -3
- package/src/schema.js +73 -58
- package/src/util.js +7 -10
package/package.json
CHANGED
package/src/entity.js
CHANGED
|
@@ -2012,7 +2012,10 @@ class Entity {
|
|
|
2012
2012
|
);
|
|
2013
2013
|
break;
|
|
2014
2014
|
case MethodTypes.scan:
|
|
2015
|
-
params = this._makeScanParam(
|
|
2015
|
+
params = this._makeScanParam(
|
|
2016
|
+
filter[ExpressionTypes.FilterExpression],
|
|
2017
|
+
config,
|
|
2018
|
+
);
|
|
2016
2019
|
break;
|
|
2017
2020
|
/* istanbul ignore next */
|
|
2018
2021
|
default:
|
|
@@ -2228,7 +2231,7 @@ class Entity {
|
|
|
2228
2231
|
}
|
|
2229
2232
|
|
|
2230
2233
|
/* istanbul ignore next */
|
|
2231
|
-
_makeScanParam(filter = {}) {
|
|
2234
|
+
_makeScanParam(filter = {}, options = {}) {
|
|
2232
2235
|
let indexBase = TableIndex;
|
|
2233
2236
|
let hasSortKey = this.model.lookup.indexHasSortKeys[indexBase];
|
|
2234
2237
|
let accessPattern =
|
|
@@ -2291,7 +2294,10 @@ class Entity {
|
|
|
2291
2294
|
params.FilterExpression = filterExpressions.join(" AND ");
|
|
2292
2295
|
}
|
|
2293
2296
|
|
|
2294
|
-
return
|
|
2297
|
+
return this._applyProjectionExpressions({
|
|
2298
|
+
parameters: params,
|
|
2299
|
+
config: options,
|
|
2300
|
+
});
|
|
2295
2301
|
}
|
|
2296
2302
|
|
|
2297
2303
|
_makeSimpleIndexParams(partition, sort) {
|
package/src/schema.js
CHANGED
|
@@ -268,19 +268,23 @@ class Attribute {
|
|
|
268
268
|
|
|
269
269
|
_makeGet(get) {
|
|
270
270
|
this._checkGetSet(get, "get");
|
|
271
|
-
const getter = get
|
|
272
|
-
|
|
271
|
+
const getter = get
|
|
272
|
+
? (value, getSiblings) => get(value, getSiblings())
|
|
273
|
+
: (attr) => attr;
|
|
274
|
+
return (value, getSiblings) => {
|
|
273
275
|
if (this.hidden) {
|
|
274
276
|
return;
|
|
275
277
|
}
|
|
276
278
|
value = this.unformat(value);
|
|
277
|
-
return getter(value,
|
|
279
|
+
return getter(value, getSiblings);
|
|
278
280
|
};
|
|
279
281
|
}
|
|
280
282
|
|
|
281
283
|
_makeSet(set) {
|
|
282
284
|
this._checkGetSet(set, "set");
|
|
283
|
-
return set
|
|
285
|
+
return set
|
|
286
|
+
? (value, getSiblings) => set(value, getSiblings())
|
|
287
|
+
: (attr) => attr;
|
|
284
288
|
}
|
|
285
289
|
|
|
286
290
|
_makeApplyFixings({
|
|
@@ -664,19 +668,19 @@ class MapAttribute extends Attribute {
|
|
|
664
668
|
|
|
665
669
|
_makeGet(get, properties) {
|
|
666
670
|
this._checkGetSet(get, "get");
|
|
667
|
-
const getter =
|
|
668
|
-
get
|
|
669
|
-
(
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
return (values,
|
|
671
|
+
const getter = get
|
|
672
|
+
? (value, getSiblings) => get(value, getSiblings())
|
|
673
|
+
: (val) => {
|
|
674
|
+
const isEmpty = !val || Object.keys(val).length === 0;
|
|
675
|
+
const isNotRequired = !this.required;
|
|
676
|
+
const doesNotHaveDefault = this.default === undefined;
|
|
677
|
+
const isRoot = this.isRoot;
|
|
678
|
+
if (isEmpty && isRoot && isNotRequired && doesNotHaveDefault) {
|
|
679
|
+
return undefined;
|
|
680
|
+
}
|
|
681
|
+
return val;
|
|
682
|
+
};
|
|
683
|
+
return (values, getSiblings) => {
|
|
680
684
|
const data = {};
|
|
681
685
|
|
|
682
686
|
if (this.hidden) {
|
|
@@ -687,60 +691,62 @@ class MapAttribute extends Attribute {
|
|
|
687
691
|
if (!get) {
|
|
688
692
|
return undefined;
|
|
689
693
|
}
|
|
690
|
-
return getter(data,
|
|
694
|
+
return getter(data, getSiblings);
|
|
691
695
|
}
|
|
692
696
|
|
|
693
697
|
for (const name of Object.keys(properties.attributes)) {
|
|
694
698
|
const attribute = properties.attributes[name];
|
|
695
699
|
if (values[attribute.field] !== undefined) {
|
|
696
|
-
let results = attribute.get(values[attribute.field],
|
|
700
|
+
let results = attribute.get(values[attribute.field], () => ({
|
|
701
|
+
...values,
|
|
702
|
+
}));
|
|
697
703
|
if (results !== undefined) {
|
|
698
704
|
data[name] = results;
|
|
699
705
|
}
|
|
700
706
|
}
|
|
701
707
|
}
|
|
702
708
|
|
|
703
|
-
return getter(data,
|
|
709
|
+
return getter(data, getSiblings);
|
|
704
710
|
};
|
|
705
711
|
}
|
|
706
712
|
|
|
707
713
|
_makeSet(set, properties) {
|
|
708
714
|
this._checkGetSet(set, "set");
|
|
709
|
-
const setter =
|
|
710
|
-
set
|
|
711
|
-
(
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
715
|
+
const setter = set
|
|
716
|
+
? (val, getSiblings) => set(val, getSiblings())
|
|
717
|
+
: (val) => {
|
|
718
|
+
const isEmpty = !val || Object.keys(val).length === 0;
|
|
719
|
+
const isNotRequired = !this.required;
|
|
720
|
+
const doesNotHaveDefault = this.default === undefined;
|
|
721
|
+
const defaultIsValue = this.default === val;
|
|
722
|
+
const isRoot = this.isRoot;
|
|
723
|
+
if (defaultIsValue) {
|
|
724
|
+
return val;
|
|
725
|
+
} else if (isEmpty && isRoot && isNotRequired && doesNotHaveDefault) {
|
|
726
|
+
return undefined;
|
|
727
|
+
} else {
|
|
728
|
+
return val;
|
|
729
|
+
}
|
|
730
|
+
};
|
|
725
731
|
|
|
726
|
-
return (values,
|
|
732
|
+
return (values, getSiblings) => {
|
|
727
733
|
const data = {};
|
|
728
734
|
if (values === undefined) {
|
|
729
735
|
if (!set) {
|
|
730
736
|
return undefined;
|
|
731
737
|
}
|
|
732
|
-
return setter(values,
|
|
738
|
+
return setter(values, getSiblings);
|
|
733
739
|
}
|
|
734
740
|
for (const name of Object.keys(properties.attributes)) {
|
|
735
741
|
const attribute = properties.attributes[name];
|
|
736
742
|
if (values[name] !== undefined) {
|
|
737
|
-
const results = attribute.set(values[name], { ...values });
|
|
743
|
+
const results = attribute.set(values[name], () => ({ ...values }));
|
|
738
744
|
if (results !== undefined) {
|
|
739
745
|
data[attribute.field] = results;
|
|
740
746
|
}
|
|
741
747
|
}
|
|
742
748
|
}
|
|
743
|
-
return setter(data,
|
|
749
|
+
return setter(data, getSiblings);
|
|
744
750
|
};
|
|
745
751
|
}
|
|
746
752
|
|
|
@@ -876,9 +882,11 @@ class ListAttribute extends Attribute {
|
|
|
876
882
|
_makeGet(get, items) {
|
|
877
883
|
this._checkGetSet(get, "get");
|
|
878
884
|
|
|
879
|
-
const getter = get
|
|
885
|
+
const getter = get
|
|
886
|
+
? (value, getSiblings) => get(value, getSiblings())
|
|
887
|
+
: (attr) => attr;
|
|
880
888
|
|
|
881
|
-
return (values,
|
|
889
|
+
return (values, getSiblings) => {
|
|
882
890
|
const data = [];
|
|
883
891
|
|
|
884
892
|
if (this.hidden) {
|
|
@@ -886,38 +894,40 @@ class ListAttribute extends Attribute {
|
|
|
886
894
|
}
|
|
887
895
|
|
|
888
896
|
if (values === undefined) {
|
|
889
|
-
return getter(data,
|
|
897
|
+
return getter(data, getSiblings);
|
|
890
898
|
}
|
|
891
899
|
|
|
892
900
|
for (let value of values) {
|
|
893
|
-
const results = items.get(value, [...values]);
|
|
901
|
+
const results = items.get(value, () => [...values]);
|
|
894
902
|
if (results !== undefined) {
|
|
895
903
|
data.push(results);
|
|
896
904
|
}
|
|
897
905
|
}
|
|
898
906
|
|
|
899
|
-
return getter(data,
|
|
907
|
+
return getter(data, getSiblings);
|
|
900
908
|
};
|
|
901
909
|
}
|
|
902
910
|
|
|
903
911
|
_makeSet(set, items) {
|
|
904
912
|
this._checkGetSet(set, "set");
|
|
905
|
-
const setter = set
|
|
906
|
-
|
|
913
|
+
const setter = set
|
|
914
|
+
? (value, getSiblings) => set(value, getSiblings())
|
|
915
|
+
: (attr) => attr;
|
|
916
|
+
return (values, getSiblings) => {
|
|
907
917
|
const data = [];
|
|
908
918
|
|
|
909
919
|
if (values === undefined) {
|
|
910
|
-
return setter(values,
|
|
920
|
+
return setter(values, getSiblings);
|
|
911
921
|
}
|
|
912
922
|
|
|
913
923
|
for (const value of values) {
|
|
914
|
-
const results = items.set(value, [...values]);
|
|
924
|
+
const results = items.set(value, () => [...values]);
|
|
915
925
|
if (results !== undefined) {
|
|
916
926
|
data.push(results);
|
|
917
927
|
}
|
|
918
928
|
}
|
|
919
929
|
|
|
920
|
-
return setter(data,
|
|
930
|
+
return setter(data, getSiblings);
|
|
921
931
|
};
|
|
922
932
|
}
|
|
923
933
|
|
|
@@ -1111,14 +1121,16 @@ class SetAttribute extends Attribute {
|
|
|
1111
1121
|
|
|
1112
1122
|
_makeGet(get, items) {
|
|
1113
1123
|
this._checkGetSet(get, "get");
|
|
1114
|
-
const getter = get
|
|
1115
|
-
|
|
1124
|
+
const getter = get
|
|
1125
|
+
? (value, getSiblings) => get(value, getSiblings())
|
|
1126
|
+
: (attr) => attr;
|
|
1127
|
+
return (values, getSiblings) => {
|
|
1116
1128
|
if (values !== undefined) {
|
|
1117
1129
|
const data = this.fromDDBSet(values);
|
|
1118
|
-
return getter(data,
|
|
1130
|
+
return getter(data, getSiblings);
|
|
1119
1131
|
}
|
|
1120
1132
|
const data = this.fromDDBSet(values);
|
|
1121
|
-
const results = getter(data,
|
|
1133
|
+
const results = getter(data, getSiblings);
|
|
1122
1134
|
if (results !== undefined) {
|
|
1123
1135
|
// if not undefined, try to convert, else no need to return
|
|
1124
1136
|
return this.fromDDBSet(results);
|
|
@@ -1128,9 +1140,11 @@ class SetAttribute extends Attribute {
|
|
|
1128
1140
|
|
|
1129
1141
|
_makeSet(set, items) {
|
|
1130
1142
|
this._checkGetSet(set, "set");
|
|
1131
|
-
const setter = set
|
|
1132
|
-
|
|
1133
|
-
|
|
1143
|
+
const setter = set
|
|
1144
|
+
? (value, getSiblings) => set(value, getSiblings())
|
|
1145
|
+
: (attr) => attr;
|
|
1146
|
+
return (values, getSiblings) => {
|
|
1147
|
+
const results = setter(this.fromDDBSet(values), getSiblings);
|
|
1134
1148
|
if (results !== undefined) {
|
|
1135
1149
|
return this.toDDBSet(results);
|
|
1136
1150
|
}
|
|
@@ -1616,12 +1630,13 @@ class Schema {
|
|
|
1616
1630
|
|
|
1617
1631
|
_applyAttributeMutation(method, include, avoid, payload) {
|
|
1618
1632
|
let data = { ...payload };
|
|
1633
|
+
const getSiblings = () => ({ ...payload });
|
|
1619
1634
|
for (let path of Object.keys(include)) {
|
|
1620
1635
|
// this.attributes[attribute] !== undefined | Attribute exists as actual attribute. If `includeKeys` is turned on for example this will include values that do not have a presence in the model and therefore will not have a `.get()` method
|
|
1621
1636
|
// avoid[attribute] === undefined | Attribute shouldn't be in the avoided
|
|
1622
1637
|
const attribute = this.getAttribute(path);
|
|
1623
1638
|
if (attribute !== undefined && avoid[path] === undefined) {
|
|
1624
|
-
data[path] = attribute[method](payload[path],
|
|
1639
|
+
data[path] = attribute[method](payload[path], getSiblings);
|
|
1625
1640
|
}
|
|
1626
1641
|
}
|
|
1627
1642
|
return data;
|
package/src/util.js
CHANGED
|
@@ -209,19 +209,16 @@ const cursorFormatter = {
|
|
|
209
209
|
};
|
|
210
210
|
|
|
211
211
|
function removeFixings({ prefix = "", postfix = "", value = "" } = {}) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
212
|
+
if (prefix === "" && postfix === "") return value;
|
|
213
|
+
|
|
214
|
+
const valueLower = value.toLowerCase();
|
|
215
|
+
|
|
216
|
+
const start = valueLower.startsWith(prefix.toLowerCase()) ? prefix.length : 0;
|
|
215
217
|
const end =
|
|
216
218
|
value.length -
|
|
217
|
-
(
|
|
218
|
-
|
|
219
|
-
let formatted = "";
|
|
220
|
-
for (let i = start; i < end; i++) {
|
|
221
|
-
formatted += value[i];
|
|
222
|
-
}
|
|
219
|
+
(valueLower.endsWith(postfix.toLowerCase()) ? postfix.length : 0);
|
|
223
220
|
|
|
224
|
-
return
|
|
221
|
+
return value.slice(start, end);
|
|
225
222
|
}
|
|
226
223
|
|
|
227
224
|
function addPadding({ padding = {}, value = "" } = {}) {
|