@e22m4u/js-repository 0.8.5 → 0.8.6
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/README.md +27 -23
- package/dist/cjs/index.cjs +746 -325
- package/eslint.config.js +1 -0
- package/package.json +14 -13
- package/src/adapter/adapter-loader.js +9 -4
- package/src/adapter/adapter-registry.js +3 -1
- package/src/adapter/builtin/memory-adapter.js +29 -13
- package/src/adapter/decorator/data-sanitizing-decorator.js +2 -1
- package/src/adapter/decorator/default-values-decorator.js +2 -1
- package/src/adapter/decorator/fields-filtering-decorator.js +14 -7
- package/src/adapter/decorator/inclusion-decorator.js +14 -7
- package/src/adapter/decorator/property-uniqueness-decorator.js +2 -1
- package/src/adapter/decorator/required-property-decorator.js +2 -1
- package/src/definition/datasource/datasource-definition-validator.js +6 -3
- package/src/definition/definition-registry.js +8 -4
- package/src/definition/model/model-data-sanitizer.js +4 -2
- package/src/definition/model/model-definition-utils.js +68 -26
- package/src/definition/model/model-definition-validator.js +10 -5
- package/src/definition/model/properties/primary-keys-definition-validator.js +4 -2
- package/src/definition/model/properties/properties-definition-validator.js +36 -18
- package/src/definition/model/properties/property-uniqueness-validator.js +26 -10
- package/src/definition/model/properties/property-uniqueness-validator.spec.js +500 -38
- package/src/definition/model/relations/relations-definition-validator.js +70 -33
- package/src/filter/fields-clause-tool.js +31 -12
- package/src/filter/include-clause-tool.js +38 -15
- package/src/filter/operator-clause-tool.js +55 -23
- package/src/filter/order-clause-tool.js +36 -13
- package/src/filter/slice-clause-tool.js +16 -7
- package/src/filter/where-clause-tool.js +24 -10
- package/src/relations/belongs-to-resolver.js +44 -20
- package/src/relations/has-many-resolver.js +52 -25
- package/src/relations/has-one-resolver.js +58 -27
- package/src/relations/references-many-resolver.js +24 -11
- package/src/repository/repository-registry.js +3 -1
- package/src/repository/repository.js +2 -1
- package/src/utils/capitalize.js +3 -1
- package/src/utils/clone-deep.js +6 -2
- package/src/utils/exclude-object-keys.js +2 -1
- package/src/utils/get-value-by-path.js +6 -2
- package/src/utils/is-deep-equal.js +21 -7
- package/src/utils/is-promise.js +6 -2
- package/src/utils/model-name-to-model-key.js +2 -1
- package/src/utils/select-object-keys.js +9 -4
- package/src/utils/singularize.js +3 -1
|
@@ -429,11 +429,12 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
429
429
|
const idValue = 1;
|
|
430
430
|
const modelData = {foo: 'bar'};
|
|
431
431
|
const countMethod = where => {
|
|
432
|
-
if (invoked === 0)
|
|
432
|
+
if (invoked === 0) {
|
|
433
433
|
expect(where).to.be.eql({
|
|
434
434
|
myId: {neq: idValue},
|
|
435
435
|
foo: 'bar',
|
|
436
436
|
});
|
|
437
|
+
}
|
|
437
438
|
invoked++;
|
|
438
439
|
return 0;
|
|
439
440
|
};
|
|
@@ -837,7 +838,9 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
837
838
|
let invoked = 0;
|
|
838
839
|
const modelData = {foo: 'val1', bar: 'val2'};
|
|
839
840
|
const countMethod = where => {
|
|
840
|
-
if (invoked === 0)
|
|
841
|
+
if (invoked === 0) {
|
|
842
|
+
expect(where).to.be.eql({foo: 'val1'});
|
|
843
|
+
}
|
|
841
844
|
invoked++;
|
|
842
845
|
return 0;
|
|
843
846
|
};
|
|
@@ -936,11 +939,12 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
936
939
|
const idValue = 1;
|
|
937
940
|
const modelData = {foo: 'val1', bar: 'val2'};
|
|
938
941
|
const countMethod = where => {
|
|
939
|
-
if (invoked === 0)
|
|
942
|
+
if (invoked === 0) {
|
|
940
943
|
expect(where).to.be.eql({
|
|
941
944
|
[DEF_PK]: {neq: idValue},
|
|
942
945
|
foo: 'val1',
|
|
943
946
|
});
|
|
947
|
+
}
|
|
944
948
|
invoked++;
|
|
945
949
|
return 0;
|
|
946
950
|
};
|
|
@@ -999,11 +1003,12 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
999
1003
|
const idValue = 1;
|
|
1000
1004
|
const modelData = {foo: 'bar'};
|
|
1001
1005
|
const countMethod = where => {
|
|
1002
|
-
if (invoked === 0)
|
|
1006
|
+
if (invoked === 0) {
|
|
1003
1007
|
expect(where).to.be.eql({
|
|
1004
1008
|
myId: {neq: idValue},
|
|
1005
1009
|
foo: 'bar',
|
|
1006
1010
|
});
|
|
1011
|
+
}
|
|
1007
1012
|
invoked++;
|
|
1008
1013
|
return 0;
|
|
1009
1014
|
};
|
|
@@ -1202,11 +1207,12 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
1202
1207
|
const idValue = 1;
|
|
1203
1208
|
const modelData = {foo: 'bar'};
|
|
1204
1209
|
const countMethod = where => {
|
|
1205
|
-
if (invoked === 0)
|
|
1210
|
+
if (invoked === 0) {
|
|
1206
1211
|
expect(where).to.be.eql({
|
|
1207
1212
|
myId: {neq: idValue},
|
|
1208
1213
|
foo: 'bar',
|
|
1209
1214
|
});
|
|
1215
|
+
}
|
|
1210
1216
|
invoked++;
|
|
1211
1217
|
return 0;
|
|
1212
1218
|
};
|
|
@@ -1610,7 +1616,9 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
1610
1616
|
let invoked = 0;
|
|
1611
1617
|
const modelData = {foo: 'val1', bar: 'val2'};
|
|
1612
1618
|
const countMethod = where => {
|
|
1613
|
-
if (invoked === 0)
|
|
1619
|
+
if (invoked === 0) {
|
|
1620
|
+
expect(where).to.be.eql({foo: 'val1'});
|
|
1621
|
+
}
|
|
1614
1622
|
invoked++;
|
|
1615
1623
|
return 0;
|
|
1616
1624
|
};
|
|
@@ -1709,11 +1717,12 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
1709
1717
|
const idValue = 1;
|
|
1710
1718
|
const modelData = {foo: 'val1', bar: 'val2'};
|
|
1711
1719
|
const countMethod = where => {
|
|
1712
|
-
if (invoked === 0)
|
|
1720
|
+
if (invoked === 0) {
|
|
1713
1721
|
expect(where).to.be.eql({
|
|
1714
1722
|
[DEF_PK]: {neq: idValue},
|
|
1715
1723
|
foo: 'val1',
|
|
1716
1724
|
});
|
|
1725
|
+
}
|
|
1717
1726
|
invoked++;
|
|
1718
1727
|
return 0;
|
|
1719
1728
|
};
|
|
@@ -1772,11 +1781,12 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
1772
1781
|
const idValue = 1;
|
|
1773
1782
|
const modelData = {foo: 'bar'};
|
|
1774
1783
|
const countMethod = where => {
|
|
1775
|
-
if (invoked === 0)
|
|
1784
|
+
if (invoked === 0) {
|
|
1776
1785
|
expect(where).to.be.eql({
|
|
1777
1786
|
myId: {neq: idValue},
|
|
1778
1787
|
foo: 'bar',
|
|
1779
1788
|
});
|
|
1789
|
+
}
|
|
1780
1790
|
invoked++;
|
|
1781
1791
|
return 0;
|
|
1782
1792
|
};
|
|
@@ -1853,7 +1863,9 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
1853
1863
|
let invoked = 0;
|
|
1854
1864
|
const modelData = {foo: 'val1', bar: 'val2'};
|
|
1855
1865
|
const countMethod = where => {
|
|
1856
|
-
if (invoked === 0)
|
|
1866
|
+
if (invoked === 0) {
|
|
1867
|
+
expect(where).to.be.eql({foo: 'val1'});
|
|
1868
|
+
}
|
|
1857
1869
|
invoked++;
|
|
1858
1870
|
return 0;
|
|
1859
1871
|
};
|
|
@@ -1861,7 +1873,7 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
1861
1873
|
expect(invoked).to.be.eq(1);
|
|
1862
1874
|
});
|
|
1863
1875
|
|
|
1864
|
-
it('skips uniqueness checking for undefined value', async function () {
|
|
1876
|
+
it('skips uniqueness checking for an undefined value', async function () {
|
|
1865
1877
|
const dbs = new DatabaseSchema();
|
|
1866
1878
|
dbs.defineModel({
|
|
1867
1879
|
name: 'model',
|
|
@@ -1880,7 +1892,9 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
1880
1892
|
let invoked = 0;
|
|
1881
1893
|
const modelData = {foo: 'val1', bar: undefined};
|
|
1882
1894
|
const countMethod = where => {
|
|
1883
|
-
if (invoked === 0)
|
|
1895
|
+
if (invoked === 0) {
|
|
1896
|
+
expect(where).to.be.eql({foo: modelData.foo});
|
|
1897
|
+
}
|
|
1884
1898
|
invoked++;
|
|
1885
1899
|
return 0;
|
|
1886
1900
|
};
|
|
@@ -1907,7 +1921,67 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
1907
1921
|
let invoked = 0;
|
|
1908
1922
|
const modelData = {foo: 'val1', bar: ''};
|
|
1909
1923
|
const countMethod = where => {
|
|
1910
|
-
if (invoked === 0)
|
|
1924
|
+
if (invoked === 0) {
|
|
1925
|
+
expect(where).to.be.eql({foo: modelData.foo});
|
|
1926
|
+
}
|
|
1927
|
+
invoked++;
|
|
1928
|
+
return 0;
|
|
1929
|
+
};
|
|
1930
|
+
await puv.validate(countMethod, 'create', 'model', modelData);
|
|
1931
|
+
expect(invoked).to.be.eql(1);
|
|
1932
|
+
});
|
|
1933
|
+
|
|
1934
|
+
it('skips uniqueness checking for a zero number', async function () {
|
|
1935
|
+
const dbs = new DatabaseSchema();
|
|
1936
|
+
dbs.defineModel({
|
|
1937
|
+
name: 'model',
|
|
1938
|
+
properties: {
|
|
1939
|
+
foo: {
|
|
1940
|
+
type: DataType.NUMBER,
|
|
1941
|
+
unique: PropertyUniqueness.SPARSE,
|
|
1942
|
+
},
|
|
1943
|
+
bar: {
|
|
1944
|
+
type: DataType.NUMBER,
|
|
1945
|
+
unique: PropertyUniqueness.SPARSE,
|
|
1946
|
+
},
|
|
1947
|
+
},
|
|
1948
|
+
});
|
|
1949
|
+
const puv = dbs.getService(PropertyUniquenessValidator);
|
|
1950
|
+
let invoked = 0;
|
|
1951
|
+
const modelData = {foo: 10, bar: 0};
|
|
1952
|
+
const countMethod = where => {
|
|
1953
|
+
if (invoked === 0) {
|
|
1954
|
+
expect(where).to.be.eql({foo: modelData.foo});
|
|
1955
|
+
}
|
|
1956
|
+
invoked++;
|
|
1957
|
+
return 0;
|
|
1958
|
+
};
|
|
1959
|
+
await puv.validate(countMethod, 'create', 'model', modelData);
|
|
1960
|
+
expect(invoked).to.be.eql(1);
|
|
1961
|
+
});
|
|
1962
|
+
|
|
1963
|
+
it('skips uniqueness checking for a false value', async function () {
|
|
1964
|
+
const dbs = new DatabaseSchema();
|
|
1965
|
+
dbs.defineModel({
|
|
1966
|
+
name: 'model',
|
|
1967
|
+
properties: {
|
|
1968
|
+
foo: {
|
|
1969
|
+
type: DataType.BOOLEAN,
|
|
1970
|
+
unique: PropertyUniqueness.SPARSE,
|
|
1971
|
+
},
|
|
1972
|
+
bar: {
|
|
1973
|
+
type: DataType.BOOLEAN,
|
|
1974
|
+
unique: PropertyUniqueness.SPARSE,
|
|
1975
|
+
},
|
|
1976
|
+
},
|
|
1977
|
+
});
|
|
1978
|
+
const puv = dbs.getService(PropertyUniquenessValidator);
|
|
1979
|
+
let invoked = 0;
|
|
1980
|
+
const modelData = {foo: true, bar: false};
|
|
1981
|
+
const countMethod = where => {
|
|
1982
|
+
if (invoked === 0) {
|
|
1983
|
+
expect(where).to.be.eql({foo: modelData.foo});
|
|
1984
|
+
}
|
|
1911
1985
|
invoked++;
|
|
1912
1986
|
return 0;
|
|
1913
1987
|
};
|
|
@@ -1981,11 +2055,12 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
1981
2055
|
const idValue = 1;
|
|
1982
2056
|
const modelData = {foo: 'val1', bar: 'val2'};
|
|
1983
2057
|
const countMethod = where => {
|
|
1984
|
-
if (invoked === 0)
|
|
2058
|
+
if (invoked === 0) {
|
|
1985
2059
|
expect(where).to.be.eql({
|
|
1986
2060
|
[DEF_PK]: {neq: idValue},
|
|
1987
2061
|
foo: 'val1',
|
|
1988
2062
|
});
|
|
2063
|
+
}
|
|
1989
2064
|
invoked++;
|
|
1990
2065
|
return 0;
|
|
1991
2066
|
};
|
|
@@ -1999,7 +2074,7 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
1999
2074
|
expect(invoked).to.be.eq(1);
|
|
2000
2075
|
});
|
|
2001
2076
|
|
|
2002
|
-
it('skips uniqueness checking for undefined value', async function () {
|
|
2077
|
+
it('skips uniqueness checking for an undefined value', async function () {
|
|
2003
2078
|
const dbs = new DatabaseSchema();
|
|
2004
2079
|
dbs.defineModel({
|
|
2005
2080
|
name: 'model',
|
|
@@ -2019,11 +2094,12 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
2019
2094
|
const idValue = 1;
|
|
2020
2095
|
const modelData = {foo: 'val1', bar: undefined};
|
|
2021
2096
|
const countMethod = where => {
|
|
2022
|
-
if (invoked === 0)
|
|
2097
|
+
if (invoked === 0) {
|
|
2023
2098
|
expect(where).to.be.eql({
|
|
2024
2099
|
[DEF_PK]: {neq: idValue},
|
|
2025
|
-
foo:
|
|
2100
|
+
foo: modelData.foo,
|
|
2026
2101
|
});
|
|
2102
|
+
}
|
|
2027
2103
|
invoked++;
|
|
2028
2104
|
return 0;
|
|
2029
2105
|
};
|
|
@@ -2057,11 +2133,90 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
2057
2133
|
const idValue = 1;
|
|
2058
2134
|
const modelData = {foo: 'val1', bar: ''};
|
|
2059
2135
|
const countMethod = where => {
|
|
2060
|
-
if (invoked === 0)
|
|
2136
|
+
if (invoked === 0) {
|
|
2061
2137
|
expect(where).to.be.eql({
|
|
2062
2138
|
[DEF_PK]: {neq: idValue},
|
|
2063
|
-
foo:
|
|
2139
|
+
foo: modelData.foo,
|
|
2140
|
+
});
|
|
2141
|
+
}
|
|
2142
|
+
invoked++;
|
|
2143
|
+
return 0;
|
|
2144
|
+
};
|
|
2145
|
+
await puv.validate(
|
|
2146
|
+
countMethod,
|
|
2147
|
+
'replaceById',
|
|
2148
|
+
'model',
|
|
2149
|
+
modelData,
|
|
2150
|
+
idValue,
|
|
2151
|
+
);
|
|
2152
|
+
expect(invoked).to.be.eql(1);
|
|
2153
|
+
});
|
|
2154
|
+
|
|
2155
|
+
it('skips uniqueness checking for a zero number', async function () {
|
|
2156
|
+
const dbs = new DatabaseSchema();
|
|
2157
|
+
dbs.defineModel({
|
|
2158
|
+
name: 'model',
|
|
2159
|
+
properties: {
|
|
2160
|
+
foo: {
|
|
2161
|
+
type: DataType.NUMBER,
|
|
2162
|
+
unique: PropertyUniqueness.SPARSE,
|
|
2163
|
+
},
|
|
2164
|
+
bar: {
|
|
2165
|
+
type: DataType.NUMBER,
|
|
2166
|
+
unique: PropertyUniqueness.SPARSE,
|
|
2167
|
+
},
|
|
2168
|
+
},
|
|
2169
|
+
});
|
|
2170
|
+
const puv = dbs.getService(PropertyUniquenessValidator);
|
|
2171
|
+
let invoked = 0;
|
|
2172
|
+
const idValue = 1;
|
|
2173
|
+
const modelData = {foo: 10, bar: 0};
|
|
2174
|
+
const countMethod = where => {
|
|
2175
|
+
if (invoked === 0) {
|
|
2176
|
+
expect(where).to.be.eql({
|
|
2177
|
+
[DEF_PK]: {neq: idValue},
|
|
2178
|
+
foo: modelData.foo,
|
|
2064
2179
|
});
|
|
2180
|
+
}
|
|
2181
|
+
invoked++;
|
|
2182
|
+
return 0;
|
|
2183
|
+
};
|
|
2184
|
+
await puv.validate(
|
|
2185
|
+
countMethod,
|
|
2186
|
+
'replaceById',
|
|
2187
|
+
'model',
|
|
2188
|
+
modelData,
|
|
2189
|
+
idValue,
|
|
2190
|
+
);
|
|
2191
|
+
expect(invoked).to.be.eql(1);
|
|
2192
|
+
});
|
|
2193
|
+
|
|
2194
|
+
it('skips uniqueness checking for a false value', async function () {
|
|
2195
|
+
const dbs = new DatabaseSchema();
|
|
2196
|
+
dbs.defineModel({
|
|
2197
|
+
name: 'model',
|
|
2198
|
+
properties: {
|
|
2199
|
+
foo: {
|
|
2200
|
+
type: DataType.BOOLEAN,
|
|
2201
|
+
unique: PropertyUniqueness.SPARSE,
|
|
2202
|
+
},
|
|
2203
|
+
bar: {
|
|
2204
|
+
type: DataType.BOOLEAN,
|
|
2205
|
+
unique: PropertyUniqueness.SPARSE,
|
|
2206
|
+
},
|
|
2207
|
+
},
|
|
2208
|
+
});
|
|
2209
|
+
const puv = dbs.getService(PropertyUniquenessValidator);
|
|
2210
|
+
let invoked = 0;
|
|
2211
|
+
const idValue = 1;
|
|
2212
|
+
const modelData = {foo: true, bar: false};
|
|
2213
|
+
const countMethod = where => {
|
|
2214
|
+
if (invoked === 0) {
|
|
2215
|
+
expect(where).to.be.eql({
|
|
2216
|
+
[DEF_PK]: {neq: idValue},
|
|
2217
|
+
foo: modelData.foo,
|
|
2218
|
+
});
|
|
2219
|
+
}
|
|
2065
2220
|
invoked++;
|
|
2066
2221
|
return 0;
|
|
2067
2222
|
};
|
|
@@ -2095,11 +2250,12 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
2095
2250
|
const idValue = 1;
|
|
2096
2251
|
const modelData = {foo: 'bar'};
|
|
2097
2252
|
const countMethod = where => {
|
|
2098
|
-
if (invoked === 0)
|
|
2253
|
+
if (invoked === 0) {
|
|
2099
2254
|
expect(where).to.be.eql({
|
|
2100
2255
|
myId: {neq: idValue},
|
|
2101
2256
|
foo: 'bar',
|
|
2102
2257
|
});
|
|
2258
|
+
}
|
|
2103
2259
|
invoked++;
|
|
2104
2260
|
return 0;
|
|
2105
2261
|
};
|
|
@@ -2174,7 +2330,9 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
2174
2330
|
let invoked = 0;
|
|
2175
2331
|
const modelData = {foo: 'val1', bar: 'val2'};
|
|
2176
2332
|
const countMethod = where => {
|
|
2177
|
-
if (invoked === 0)
|
|
2333
|
+
if (invoked === 0) {
|
|
2334
|
+
expect(where).to.be.eql({foo: 'val1'});
|
|
2335
|
+
}
|
|
2178
2336
|
invoked++;
|
|
2179
2337
|
return 0;
|
|
2180
2338
|
};
|
|
@@ -2299,7 +2457,7 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
2299
2457
|
expect(invoked).to.be.eq(3);
|
|
2300
2458
|
});
|
|
2301
2459
|
|
|
2302
|
-
it('skips uniqueness checking for undefined value', async function () {
|
|
2460
|
+
it('skips uniqueness checking for an undefined value', async function () {
|
|
2303
2461
|
const dbs = new DatabaseSchema();
|
|
2304
2462
|
dbs.defineModel({
|
|
2305
2463
|
name: 'model',
|
|
@@ -2326,7 +2484,7 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
2326
2484
|
if (invoked === 0) {
|
|
2327
2485
|
expect(where).to.be.eql({[DEF_PK]: idValue});
|
|
2328
2486
|
} else if (invoked === 1) {
|
|
2329
|
-
expect(where).to.be.eql({foo:
|
|
2487
|
+
expect(where).to.be.eql({foo: modelData.foo});
|
|
2330
2488
|
}
|
|
2331
2489
|
invoked++;
|
|
2332
2490
|
return 0;
|
|
@@ -2361,13 +2519,95 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
2361
2519
|
const modelData = {
|
|
2362
2520
|
[DEF_PK]: idValue,
|
|
2363
2521
|
foo: 'val1',
|
|
2364
|
-
bar:
|
|
2522
|
+
bar: '',
|
|
2365
2523
|
};
|
|
2366
2524
|
const countMethod = where => {
|
|
2367
2525
|
if (invoked === 0) {
|
|
2368
2526
|
expect(where).to.be.eql({[DEF_PK]: idValue});
|
|
2369
2527
|
} else if (invoked === 1) {
|
|
2370
|
-
expect(where).to.be.eql({foo:
|
|
2528
|
+
expect(where).to.be.eql({foo: modelData.foo});
|
|
2529
|
+
}
|
|
2530
|
+
invoked++;
|
|
2531
|
+
return 0;
|
|
2532
|
+
};
|
|
2533
|
+
await puv.validate(
|
|
2534
|
+
countMethod,
|
|
2535
|
+
'replaceOrCreate',
|
|
2536
|
+
'model',
|
|
2537
|
+
modelData,
|
|
2538
|
+
);
|
|
2539
|
+
expect(invoked).to.be.eql(2);
|
|
2540
|
+
});
|
|
2541
|
+
|
|
2542
|
+
it('skips uniqueness checking for a zero number', async function () {
|
|
2543
|
+
const dbs = new DatabaseSchema();
|
|
2544
|
+
dbs.defineModel({
|
|
2545
|
+
name: 'model',
|
|
2546
|
+
properties: {
|
|
2547
|
+
foo: {
|
|
2548
|
+
type: DataType.NUMBER,
|
|
2549
|
+
unique: PropertyUniqueness.SPARSE,
|
|
2550
|
+
},
|
|
2551
|
+
bar: {
|
|
2552
|
+
type: DataType.NUMBER,
|
|
2553
|
+
unique: PropertyUniqueness.SPARSE,
|
|
2554
|
+
},
|
|
2555
|
+
},
|
|
2556
|
+
});
|
|
2557
|
+
const puv = dbs.getService(PropertyUniquenessValidator);
|
|
2558
|
+
let invoked = 0;
|
|
2559
|
+
const idValue = 1;
|
|
2560
|
+
const modelData = {
|
|
2561
|
+
[DEF_PK]: idValue,
|
|
2562
|
+
foo: 10,
|
|
2563
|
+
bar: 0,
|
|
2564
|
+
};
|
|
2565
|
+
const countMethod = where => {
|
|
2566
|
+
if (invoked === 0) {
|
|
2567
|
+
expect(where).to.be.eql({[DEF_PK]: idValue});
|
|
2568
|
+
} else if (invoked === 1) {
|
|
2569
|
+
expect(where).to.be.eql({foo: modelData.foo});
|
|
2570
|
+
}
|
|
2571
|
+
invoked++;
|
|
2572
|
+
return 0;
|
|
2573
|
+
};
|
|
2574
|
+
await puv.validate(
|
|
2575
|
+
countMethod,
|
|
2576
|
+
'replaceOrCreate',
|
|
2577
|
+
'model',
|
|
2578
|
+
modelData,
|
|
2579
|
+
);
|
|
2580
|
+
expect(invoked).to.be.eql(2);
|
|
2581
|
+
});
|
|
2582
|
+
|
|
2583
|
+
it('skips uniqueness checking for a false value', async function () {
|
|
2584
|
+
const dbs = new DatabaseSchema();
|
|
2585
|
+
dbs.defineModel({
|
|
2586
|
+
name: 'model',
|
|
2587
|
+
properties: {
|
|
2588
|
+
foo: {
|
|
2589
|
+
type: DataType.BOOLEAN,
|
|
2590
|
+
unique: PropertyUniqueness.SPARSE,
|
|
2591
|
+
},
|
|
2592
|
+
bar: {
|
|
2593
|
+
type: DataType.BOOLEAN,
|
|
2594
|
+
unique: PropertyUniqueness.SPARSE,
|
|
2595
|
+
},
|
|
2596
|
+
},
|
|
2597
|
+
});
|
|
2598
|
+
const puv = dbs.getService(PropertyUniquenessValidator);
|
|
2599
|
+
let invoked = 0;
|
|
2600
|
+
const idValue = 1;
|
|
2601
|
+
const modelData = {
|
|
2602
|
+
[DEF_PK]: idValue,
|
|
2603
|
+
foo: true,
|
|
2604
|
+
bar: false,
|
|
2605
|
+
};
|
|
2606
|
+
const countMethod = where => {
|
|
2607
|
+
if (invoked === 0) {
|
|
2608
|
+
expect(where).to.be.eql({[DEF_PK]: idValue});
|
|
2609
|
+
} else if (invoked === 1) {
|
|
2610
|
+
expect(where).to.be.eql({foo: modelData.foo});
|
|
2371
2611
|
}
|
|
2372
2612
|
invoked++;
|
|
2373
2613
|
return 0;
|
|
@@ -2520,7 +2760,7 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
2520
2760
|
expect(invoked).to.be.eq(3);
|
|
2521
2761
|
});
|
|
2522
2762
|
|
|
2523
|
-
it('skips uniqueness checking for undefined value', async function () {
|
|
2763
|
+
it('skips uniqueness checking for an undefined value', async function () {
|
|
2524
2764
|
const dbs = new DatabaseSchema();
|
|
2525
2765
|
dbs.defineModel({
|
|
2526
2766
|
name: 'model',
|
|
@@ -2551,7 +2791,7 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
2551
2791
|
} else if (invoked === 2) {
|
|
2552
2792
|
expect(where).to.be.eql({
|
|
2553
2793
|
[DEF_PK]: {neq: idValue},
|
|
2554
|
-
foo:
|
|
2794
|
+
foo: modelData.foo,
|
|
2555
2795
|
});
|
|
2556
2796
|
return 0;
|
|
2557
2797
|
}
|
|
@@ -2596,7 +2836,97 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
2596
2836
|
} else if (invoked === 2) {
|
|
2597
2837
|
expect(where).to.be.eql({
|
|
2598
2838
|
[DEF_PK]: {neq: idValue},
|
|
2599
|
-
foo:
|
|
2839
|
+
foo: modelData.foo,
|
|
2840
|
+
});
|
|
2841
|
+
return 0;
|
|
2842
|
+
}
|
|
2843
|
+
};
|
|
2844
|
+
await puv.validate(
|
|
2845
|
+
countMethod,
|
|
2846
|
+
'replaceOrCreate',
|
|
2847
|
+
'model',
|
|
2848
|
+
modelData,
|
|
2849
|
+
);
|
|
2850
|
+
expect(invoked).to.be.eql(2);
|
|
2851
|
+
});
|
|
2852
|
+
|
|
2853
|
+
it('skips uniqueness checking for a zero number', async function () {
|
|
2854
|
+
const dbs = new DatabaseSchema();
|
|
2855
|
+
dbs.defineModel({
|
|
2856
|
+
name: 'model',
|
|
2857
|
+
properties: {
|
|
2858
|
+
foo: {
|
|
2859
|
+
type: DataType.NUMBER,
|
|
2860
|
+
unique: PropertyUniqueness.SPARSE,
|
|
2861
|
+
},
|
|
2862
|
+
bar: {
|
|
2863
|
+
type: DataType.NUMBER,
|
|
2864
|
+
unique: PropertyUniqueness.SPARSE,
|
|
2865
|
+
},
|
|
2866
|
+
},
|
|
2867
|
+
});
|
|
2868
|
+
const puv = dbs.getService(PropertyUniquenessValidator);
|
|
2869
|
+
let invoked = 0;
|
|
2870
|
+
const idValue = 1;
|
|
2871
|
+
const modelData = {
|
|
2872
|
+
[DEF_PK]: idValue,
|
|
2873
|
+
foo: 10,
|
|
2874
|
+
bar: 0,
|
|
2875
|
+
};
|
|
2876
|
+
const countMethod = where => {
|
|
2877
|
+
invoked++;
|
|
2878
|
+
if (invoked === 1) {
|
|
2879
|
+
expect(where).to.be.eql({[DEF_PK]: idValue});
|
|
2880
|
+
return 1;
|
|
2881
|
+
} else if (invoked === 2) {
|
|
2882
|
+
expect(where).to.be.eql({
|
|
2883
|
+
[DEF_PK]: {neq: idValue},
|
|
2884
|
+
foo: modelData.foo,
|
|
2885
|
+
});
|
|
2886
|
+
return 0;
|
|
2887
|
+
}
|
|
2888
|
+
};
|
|
2889
|
+
await puv.validate(
|
|
2890
|
+
countMethod,
|
|
2891
|
+
'replaceOrCreate',
|
|
2892
|
+
'model',
|
|
2893
|
+
modelData,
|
|
2894
|
+
);
|
|
2895
|
+
expect(invoked).to.be.eql(2);
|
|
2896
|
+
});
|
|
2897
|
+
|
|
2898
|
+
it('skips uniqueness checking for a false value', async function () {
|
|
2899
|
+
const dbs = new DatabaseSchema();
|
|
2900
|
+
dbs.defineModel({
|
|
2901
|
+
name: 'model',
|
|
2902
|
+
properties: {
|
|
2903
|
+
foo: {
|
|
2904
|
+
type: DataType.BOOLEAN,
|
|
2905
|
+
unique: PropertyUniqueness.SPARSE,
|
|
2906
|
+
},
|
|
2907
|
+
bar: {
|
|
2908
|
+
type: DataType.BOOLEAN,
|
|
2909
|
+
unique: PropertyUniqueness.SPARSE,
|
|
2910
|
+
},
|
|
2911
|
+
},
|
|
2912
|
+
});
|
|
2913
|
+
const puv = dbs.getService(PropertyUniquenessValidator);
|
|
2914
|
+
let invoked = 0;
|
|
2915
|
+
const idValue = 1;
|
|
2916
|
+
const modelData = {
|
|
2917
|
+
[DEF_PK]: idValue,
|
|
2918
|
+
foo: true,
|
|
2919
|
+
bar: false,
|
|
2920
|
+
};
|
|
2921
|
+
const countMethod = where => {
|
|
2922
|
+
invoked++;
|
|
2923
|
+
if (invoked === 1) {
|
|
2924
|
+
expect(where).to.be.eql({[DEF_PK]: idValue});
|
|
2925
|
+
return 1;
|
|
2926
|
+
} else if (invoked === 2) {
|
|
2927
|
+
expect(where).to.be.eql({
|
|
2928
|
+
[DEF_PK]: {neq: idValue},
|
|
2929
|
+
foo: modelData.foo,
|
|
2600
2930
|
});
|
|
2601
2931
|
return 0;
|
|
2602
2932
|
}
|
|
@@ -2671,7 +3001,9 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
2671
3001
|
let invoked = 0;
|
|
2672
3002
|
const modelData = {foo: 'val1', bar: 'val2'};
|
|
2673
3003
|
const countMethod = where => {
|
|
2674
|
-
if (invoked === 0)
|
|
3004
|
+
if (invoked === 0) {
|
|
3005
|
+
expect(where).to.be.eql({foo: 'val1'});
|
|
3006
|
+
}
|
|
2675
3007
|
invoked++;
|
|
2676
3008
|
return 0;
|
|
2677
3009
|
};
|
|
@@ -2704,7 +3036,7 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
2704
3036
|
await expect(promise2).not.to.be.rejected;
|
|
2705
3037
|
});
|
|
2706
3038
|
|
|
2707
|
-
it('skips uniqueness checking for undefined value', async function () {
|
|
3039
|
+
it('skips uniqueness checking for an undefined value', async function () {
|
|
2708
3040
|
const dbs = new DatabaseSchema();
|
|
2709
3041
|
dbs.defineModel({
|
|
2710
3042
|
name: 'model',
|
|
@@ -2723,7 +3055,9 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
2723
3055
|
let invoked = 0;
|
|
2724
3056
|
const modelData = {foo: 'val1', bar: undefined};
|
|
2725
3057
|
const countMethod = where => {
|
|
2726
|
-
if (invoked === 0)
|
|
3058
|
+
if (invoked === 0) {
|
|
3059
|
+
expect(where).to.be.eql({foo: modelData.foo});
|
|
3060
|
+
}
|
|
2727
3061
|
invoked++;
|
|
2728
3062
|
return 0;
|
|
2729
3063
|
};
|
|
@@ -2750,7 +3084,67 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
2750
3084
|
let invoked = 0;
|
|
2751
3085
|
const modelData = {foo: 'val1', bar: ''};
|
|
2752
3086
|
const countMethod = where => {
|
|
2753
|
-
if (invoked === 0)
|
|
3087
|
+
if (invoked === 0) {
|
|
3088
|
+
expect(where).to.be.eql({foo: modelData.foo});
|
|
3089
|
+
}
|
|
3090
|
+
invoked++;
|
|
3091
|
+
return 0;
|
|
3092
|
+
};
|
|
3093
|
+
await puv.validate(countMethod, 'patch', 'model', modelData);
|
|
3094
|
+
expect(invoked).to.be.eql(1);
|
|
3095
|
+
});
|
|
3096
|
+
|
|
3097
|
+
it('skips uniqueness checking for a zero number', async function () {
|
|
3098
|
+
const dbs = new DatabaseSchema();
|
|
3099
|
+
dbs.defineModel({
|
|
3100
|
+
name: 'model',
|
|
3101
|
+
properties: {
|
|
3102
|
+
foo: {
|
|
3103
|
+
type: DataType.NUMBER,
|
|
3104
|
+
unique: PropertyUniqueness.SPARSE,
|
|
3105
|
+
},
|
|
3106
|
+
bar: {
|
|
3107
|
+
type: DataType.NUMBER,
|
|
3108
|
+
unique: PropertyUniqueness.SPARSE,
|
|
3109
|
+
},
|
|
3110
|
+
},
|
|
3111
|
+
});
|
|
3112
|
+
const puv = dbs.getService(PropertyUniquenessValidator);
|
|
3113
|
+
let invoked = 0;
|
|
3114
|
+
const modelData = {foo: 10, bar: 0};
|
|
3115
|
+
const countMethod = where => {
|
|
3116
|
+
if (invoked === 0) {
|
|
3117
|
+
expect(where).to.be.eql({foo: modelData.foo});
|
|
3118
|
+
}
|
|
3119
|
+
invoked++;
|
|
3120
|
+
return 0;
|
|
3121
|
+
};
|
|
3122
|
+
await puv.validate(countMethod, 'patch', 'model', modelData);
|
|
3123
|
+
expect(invoked).to.be.eql(1);
|
|
3124
|
+
});
|
|
3125
|
+
|
|
3126
|
+
it('skips uniqueness checking for a false value', async function () {
|
|
3127
|
+
const dbs = new DatabaseSchema();
|
|
3128
|
+
dbs.defineModel({
|
|
3129
|
+
name: 'model',
|
|
3130
|
+
properties: {
|
|
3131
|
+
foo: {
|
|
3132
|
+
type: DataType.BOOLEAN,
|
|
3133
|
+
unique: PropertyUniqueness.SPARSE,
|
|
3134
|
+
},
|
|
3135
|
+
bar: {
|
|
3136
|
+
type: DataType.BOOLEAN,
|
|
3137
|
+
unique: PropertyUniqueness.SPARSE,
|
|
3138
|
+
},
|
|
3139
|
+
},
|
|
3140
|
+
});
|
|
3141
|
+
const puv = dbs.getService(PropertyUniquenessValidator);
|
|
3142
|
+
let invoked = 0;
|
|
3143
|
+
const modelData = {foo: true, bar: false};
|
|
3144
|
+
const countMethod = where => {
|
|
3145
|
+
if (invoked === 0) {
|
|
3146
|
+
expect(where).to.be.eql({foo: modelData.foo});
|
|
3147
|
+
}
|
|
2754
3148
|
invoked++;
|
|
2755
3149
|
return 0;
|
|
2756
3150
|
};
|
|
@@ -2824,11 +3218,12 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
2824
3218
|
const idValue = 1;
|
|
2825
3219
|
const modelData = {foo: 'val1', bar: 'val2'};
|
|
2826
3220
|
const countMethod = where => {
|
|
2827
|
-
if (invoked === 0)
|
|
3221
|
+
if (invoked === 0) {
|
|
2828
3222
|
expect(where).to.be.eql({
|
|
2829
3223
|
[DEF_PK]: {neq: idValue},
|
|
2830
3224
|
foo: 'val1',
|
|
2831
3225
|
});
|
|
3226
|
+
}
|
|
2832
3227
|
invoked++;
|
|
2833
3228
|
return 0;
|
|
2834
3229
|
};
|
|
@@ -2867,7 +3262,7 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
2867
3262
|
await expect(promise2).not.to.be.rejected;
|
|
2868
3263
|
});
|
|
2869
3264
|
|
|
2870
|
-
it('skips uniqueness checking for undefined value', async function () {
|
|
3265
|
+
it('skips uniqueness checking for an undefined value', async function () {
|
|
2871
3266
|
const dbs = new DatabaseSchema();
|
|
2872
3267
|
dbs.defineModel({
|
|
2873
3268
|
name: 'model',
|
|
@@ -2886,11 +3281,12 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
2886
3281
|
let invoked = 0;
|
|
2887
3282
|
const modelData = {foo: 'val1', bar: undefined};
|
|
2888
3283
|
const countMethod = where => {
|
|
2889
|
-
if (invoked === 0)
|
|
3284
|
+
if (invoked === 0) {
|
|
2890
3285
|
expect(where).to.be.eql({
|
|
2891
3286
|
[DEF_PK]: {neq: 1},
|
|
2892
|
-
foo:
|
|
3287
|
+
foo: modelData.foo,
|
|
2893
3288
|
});
|
|
3289
|
+
}
|
|
2894
3290
|
invoked++;
|
|
2895
3291
|
return 0;
|
|
2896
3292
|
};
|
|
@@ -2917,11 +3313,76 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
2917
3313
|
let invoked = 0;
|
|
2918
3314
|
const modelData = {foo: 'val1', bar: ''};
|
|
2919
3315
|
const countMethod = where => {
|
|
2920
|
-
if (invoked === 0)
|
|
3316
|
+
if (invoked === 0) {
|
|
2921
3317
|
expect(where).to.be.eql({
|
|
2922
3318
|
[DEF_PK]: {neq: 1},
|
|
2923
|
-
foo:
|
|
3319
|
+
foo: modelData.foo,
|
|
2924
3320
|
});
|
|
3321
|
+
}
|
|
3322
|
+
invoked++;
|
|
3323
|
+
return 0;
|
|
3324
|
+
};
|
|
3325
|
+
await puv.validate(countMethod, 'patchById', 'model', modelData, 1);
|
|
3326
|
+
expect(invoked).to.be.eql(1);
|
|
3327
|
+
});
|
|
3328
|
+
|
|
3329
|
+
it('skips uniqueness checking for a zero number', async function () {
|
|
3330
|
+
const dbs = new DatabaseSchema();
|
|
3331
|
+
dbs.defineModel({
|
|
3332
|
+
name: 'model',
|
|
3333
|
+
properties: {
|
|
3334
|
+
foo: {
|
|
3335
|
+
type: DataType.NUMBER,
|
|
3336
|
+
unique: PropertyUniqueness.SPARSE,
|
|
3337
|
+
},
|
|
3338
|
+
bar: {
|
|
3339
|
+
type: DataType.NUMBER,
|
|
3340
|
+
unique: PropertyUniqueness.SPARSE,
|
|
3341
|
+
},
|
|
3342
|
+
},
|
|
3343
|
+
});
|
|
3344
|
+
const puv = dbs.getService(PropertyUniquenessValidator);
|
|
3345
|
+
let invoked = 0;
|
|
3346
|
+
const modelData = {foo: 10, bar: 0};
|
|
3347
|
+
const countMethod = where => {
|
|
3348
|
+
if (invoked === 0) {
|
|
3349
|
+
expect(where).to.be.eql({
|
|
3350
|
+
[DEF_PK]: {neq: 1},
|
|
3351
|
+
foo: modelData.foo,
|
|
3352
|
+
});
|
|
3353
|
+
}
|
|
3354
|
+
invoked++;
|
|
3355
|
+
return 0;
|
|
3356
|
+
};
|
|
3357
|
+
await puv.validate(countMethod, 'patchById', 'model', modelData, 1);
|
|
3358
|
+
expect(invoked).to.be.eql(1);
|
|
3359
|
+
});
|
|
3360
|
+
|
|
3361
|
+
it('skips uniqueness checking for a false value', async function () {
|
|
3362
|
+
const dbs = new DatabaseSchema();
|
|
3363
|
+
dbs.defineModel({
|
|
3364
|
+
name: 'model',
|
|
3365
|
+
properties: {
|
|
3366
|
+
foo: {
|
|
3367
|
+
type: DataType.BOOLEAN,
|
|
3368
|
+
unique: PropertyUniqueness.SPARSE,
|
|
3369
|
+
},
|
|
3370
|
+
bar: {
|
|
3371
|
+
type: DataType.BOOLEAN,
|
|
3372
|
+
unique: PropertyUniqueness.SPARSE,
|
|
3373
|
+
},
|
|
3374
|
+
},
|
|
3375
|
+
});
|
|
3376
|
+
const puv = dbs.getService(PropertyUniquenessValidator);
|
|
3377
|
+
let invoked = 0;
|
|
3378
|
+
const modelData = {foo: true, bar: false};
|
|
3379
|
+
const countMethod = where => {
|
|
3380
|
+
if (invoked === 0) {
|
|
3381
|
+
expect(where).to.be.eql({
|
|
3382
|
+
[DEF_PK]: {neq: 1},
|
|
3383
|
+
foo: modelData.foo,
|
|
3384
|
+
});
|
|
3385
|
+
}
|
|
2925
3386
|
invoked++;
|
|
2926
3387
|
return 0;
|
|
2927
3388
|
};
|
|
@@ -2949,11 +3410,12 @@ describe('PropertyUniquenessValidator', function () {
|
|
|
2949
3410
|
const idValue = 1;
|
|
2950
3411
|
const modelData = {foo: 'bar'};
|
|
2951
3412
|
const countMethod = where => {
|
|
2952
|
-
if (invoked === 0)
|
|
3413
|
+
if (invoked === 0) {
|
|
2953
3414
|
expect(where).to.be.eql({
|
|
2954
3415
|
myId: {neq: idValue},
|
|
2955
3416
|
foo: 'bar',
|
|
2956
3417
|
});
|
|
3418
|
+
}
|
|
2957
3419
|
invoked++;
|
|
2958
3420
|
return 0;
|
|
2959
3421
|
};
|