@e22m4u/js-repository 0.8.1 → 0.8.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/.mocharc.json +2 -1
- package/README.md +16 -16
- package/dist/cjs/index.cjs +2 -2
- package/mocha.setup.js +6 -0
- package/package.json +10 -11
- package/src/adapter/adapter.spec.js +2 -2
- package/src/adapter/decorator/data-sanitizing-decorator.spec.js +7 -7
- package/src/adapter/decorator/default-values-decorator.spec.js +2 -2
- package/src/adapter/decorator/fields-filtering-decorator.spec.js +7 -27
- package/src/adapter/decorator/inclusion-decorator.spec.js +2 -2
- package/src/adapter/decorator/property-uniqueness-decorator.spec.js +2 -2
- package/src/definition/definition-registry.spec.js +4 -4
- package/src/definition/model/model-definition-utils.js +1 -1
- package/src/definition/model/model-definition-utils.spec.js +2 -2
- package/src/definition/model/model-definition-validator.spec.js +4 -4
- package/src/definition/model/properties/properties-definition-validator.spec.js +3 -3
- package/src/definition/model/properties/property-uniqueness-validator.js +1 -1
- package/src/chai.js +0 -9
package/.mocharc.json
CHANGED
package/README.md
CHANGED
|
@@ -483,14 +483,14 @@ dbs.defineModel({
|
|
|
483
483
|
наоборот допускает дублирование пустых значений уникального свойства,
|
|
484
484
|
поскольку они не участвуют в проверке.
|
|
485
485
|
|
|
486
|
-
| тип | пустые значения
|
|
487
|
-
|
|
488
|
-
| `
|
|
489
|
-
| `
|
|
490
|
-
| `
|
|
491
|
-
| `
|
|
492
|
-
| `
|
|
493
|
-
| `
|
|
486
|
+
| константа | тип | пустые значения |
|
|
487
|
+
|--------------------|-------------|------------------------------|
|
|
488
|
+
| `DataType.ANY` | `"any"` | *пустые значения всех типов* |
|
|
489
|
+
| `DataType.STRING` | `"string"` | `undefined`, `null`, `""` |
|
|
490
|
+
| `DataType.NUMBER` | `"number"` | `undefined`, `null`, `0` |
|
|
491
|
+
| `DataType.BOOLEAN` | `"boolean"` | `undefined`, `null` |
|
|
492
|
+
| `DataType.ARRAY` | `"array"` | `undefined`, `null`, `[]` |
|
|
493
|
+
| `DataType.OBJECT` | `"object"` | `undefined`, `null`, `{}` |
|
|
494
494
|
|
|
495
495
|
### Переопределение пустых значений
|
|
496
496
|
|
|
@@ -526,9 +526,9 @@ class EmptyValuesService {
|
|
|
526
526
|
|
|
527
527
|
**Пример**
|
|
528
528
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
значений только `undefined` и `null`.
|
|
529
|
+
Если свойство с типом `string` является обязательным, то попытка записи пустой
|
|
530
|
+
строки приведет к ошибке. Следующий пример демонстрирует, как изменить данное
|
|
531
|
+
поведение, оставив в качестве пустых значений только `undefined` и `null`.
|
|
532
532
|
|
|
533
533
|
```js
|
|
534
534
|
import {DataType} from '@e22m4u/js-repository';
|
|
@@ -540,13 +540,13 @@ const dbs = new DatabaseSchema();
|
|
|
540
540
|
// получение сервиса для работы с пустыми значениями
|
|
541
541
|
const emptyValuesService = dbs.getService(EmptyValuesService);
|
|
542
542
|
|
|
543
|
-
// переопределение пустых значений для типа DataType.
|
|
544
|
-
emptyValuesService.setEmptyValuesOf(DataType.
|
|
543
|
+
// переопределение пустых значений для типа DataType.STRING
|
|
544
|
+
emptyValuesService.setEmptyValuesOf(DataType.STRING, [undefined, null]);
|
|
545
545
|
```
|
|
546
546
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
547
|
+
Теперь пустая строка будет успешно проходить проверку для обязательных свойств
|
|
548
|
+
с типом `string`, а также не будет заменяться на значение по умолчанию
|
|
549
|
+
для необязательных свойств модели.
|
|
550
550
|
|
|
551
551
|
## Репозиторий
|
|
552
552
|
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1881,7 +1881,7 @@ var init_model_definition_utils = __esm({
|
|
|
1881
1881
|
const propDef = propDefs[propName];
|
|
1882
1882
|
const propValue = extendedData[propName];
|
|
1883
1883
|
const propType = propDef != null ? this.getDataTypeFromPropertyDefinition(propDef) : DataType.ANY;
|
|
1884
|
-
const isEmpty = emptyValuesService.
|
|
1884
|
+
const isEmpty = emptyValuesService.isEmptyOf(propType, propValue);
|
|
1885
1885
|
if (!isEmpty) return;
|
|
1886
1886
|
if (propDef && typeof propDef === "object" && propDef.default !== void 0) {
|
|
1887
1887
|
extendedData[propName] = this.getDefaultPropertyValue(
|
|
@@ -2239,7 +2239,7 @@ var init_property_uniqueness_validator = __esm({
|
|
|
2239
2239
|
const propValue = modelData[propName];
|
|
2240
2240
|
if (propDef.unique === PropertyUniqueness.SPARSE) {
|
|
2241
2241
|
const propType = propDef.type || DataType.ANY;
|
|
2242
|
-
const isEmpty = emptyValuesService.
|
|
2242
|
+
const isEmpty = emptyValuesService.isEmptyOf(propType, propValue);
|
|
2243
2243
|
if (isEmpty) continue;
|
|
2244
2244
|
}
|
|
2245
2245
|
if (methodName === "create") {
|
package/mocha.setup.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e22m4u/js-repository",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"description": "Реализация репозитория для работы с базами данных",
|
|
5
5
|
"author": "Mikhail Evstropov <e22m4u@yandex.ru>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,27 +39,26 @@
|
|
|
39
39
|
"prepare": "husky"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@e22m4u/js-empty-values": "~0.2
|
|
43
|
-
"@e22m4u/js-format": "~0.3.
|
|
42
|
+
"@e22m4u/js-empty-values": "~0.3.2",
|
|
43
|
+
"@e22m4u/js-format": "~0.3.2",
|
|
44
44
|
"@e22m4u/js-service": "~0.5.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@commitlint/cli": "~20.
|
|
48
|
-
"@commitlint/config-conventional": "~20.
|
|
47
|
+
"@commitlint/cli": "~20.2.0",
|
|
48
|
+
"@commitlint/config-conventional": "~20.2.0",
|
|
49
|
+
"@e22m4u/js-spy": "~0.3.5",
|
|
49
50
|
"@types/chai": "~5.2.3",
|
|
50
51
|
"@types/chai-as-promised": "~8.0.2",
|
|
51
|
-
"@types/chai-spies": "~1.0.6",
|
|
52
52
|
"@types/mocha": "~10.0.10",
|
|
53
53
|
"c8": "~10.1.3",
|
|
54
|
-
"chai": "~6.2.
|
|
54
|
+
"chai": "~6.2.2",
|
|
55
55
|
"chai-as-promised": "~8.0.2",
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"eslint": "~9.39.1",
|
|
56
|
+
"esbuild": "~0.27.2",
|
|
57
|
+
"eslint": "~9.39.2",
|
|
59
58
|
"eslint-config-prettier": "~10.1.8",
|
|
60
59
|
"eslint-plugin-chai-expect": "~3.1.0",
|
|
61
60
|
"eslint-plugin-import": "~2.32.0",
|
|
62
|
-
"eslint-plugin-jsdoc": "~61.
|
|
61
|
+
"eslint-plugin-jsdoc": "~61.5.0",
|
|
63
62
|
"eslint-plugin-mocha": "~11.2.0",
|
|
64
63
|
"husky": "~9.1.7",
|
|
65
64
|
"mocha": "~11.7.5",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
|
-
import {
|
|
2
|
+
import {createSandbox} from '@e22m4u/js-spy';
|
|
3
3
|
import {DatabaseSchema} from '../database-schema.js';
|
|
4
4
|
import {Adapter, ADAPTER_CLASS_NAME} from './adapter.js';
|
|
5
5
|
import {Service, ServiceContainer} from '@e22m4u/js-service';
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
PropertyUniquenessDecorator,
|
|
13
13
|
} from './decorator/index.js';
|
|
14
14
|
|
|
15
|
-
const sandbox =
|
|
15
|
+
const sandbox = createSandbox();
|
|
16
16
|
|
|
17
17
|
describe('Adapter', function () {
|
|
18
18
|
it('exposes static property "kinds"', function () {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
|
-
import {chai} from '../../chai.js';
|
|
3
2
|
import {Adapter} from '../adapter.js';
|
|
3
|
+
import {createSandbox} from '@e22m4u/js-spy';
|
|
4
4
|
import {DatabaseSchema} from '../../database-schema.js';
|
|
5
5
|
import {ModelDataSanitizer} from '../../definition/index.js';
|
|
6
6
|
|
|
@@ -36,7 +36,7 @@ class TestAdapter extends Adapter {
|
|
|
36
36
|
|
|
37
37
|
const A = dbs.getService(TestAdapter);
|
|
38
38
|
const V = dbs.getService(ModelDataSanitizer);
|
|
39
|
-
const sandbox =
|
|
39
|
+
const sandbox = createSandbox();
|
|
40
40
|
|
|
41
41
|
describe('DataSanitizingDecorator', function () {
|
|
42
42
|
afterEach(function () {
|
|
@@ -48,7 +48,7 @@ describe('DataSanitizingDecorator', function () {
|
|
|
48
48
|
const data = {};
|
|
49
49
|
await A.create('model', data);
|
|
50
50
|
expect(V.sanitize).to.be.called.once;
|
|
51
|
-
expect(V.sanitize).to.be.called.with
|
|
51
|
+
expect(V.sanitize).to.be.called.with('model', data);
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
it('overrides the "replaceById" method and sanitizes a given data', async function () {
|
|
@@ -56,7 +56,7 @@ describe('DataSanitizingDecorator', function () {
|
|
|
56
56
|
const data = {};
|
|
57
57
|
await A.replaceById('model', 1, data);
|
|
58
58
|
expect(V.sanitize).to.be.called.once;
|
|
59
|
-
expect(V.sanitize).to.be.called.with
|
|
59
|
+
expect(V.sanitize).to.be.called.with('model', data);
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
it('overrides the "replaceOrCreate" method and sanitizes a given data', async function () {
|
|
@@ -64,7 +64,7 @@ describe('DataSanitizingDecorator', function () {
|
|
|
64
64
|
const data = {};
|
|
65
65
|
await A.replaceOrCreate('model', data);
|
|
66
66
|
expect(V.sanitize).to.be.called.once;
|
|
67
|
-
expect(V.sanitize).to.be.called.with
|
|
67
|
+
expect(V.sanitize).to.be.called.with('model', data);
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
it('overrides the "patch" method and sanitizes a given data', async function () {
|
|
@@ -72,7 +72,7 @@ describe('DataSanitizingDecorator', function () {
|
|
|
72
72
|
const data = {};
|
|
73
73
|
await A.patch('model', data);
|
|
74
74
|
expect(V.sanitize).to.be.called.once;
|
|
75
|
-
expect(V.sanitize).to.be.called.with
|
|
75
|
+
expect(V.sanitize).to.be.called.with('model', data);
|
|
76
76
|
});
|
|
77
77
|
|
|
78
78
|
it('overrides the "patchById" method and sanitizes a given data', async function () {
|
|
@@ -80,6 +80,6 @@ describe('DataSanitizingDecorator', function () {
|
|
|
80
80
|
const data = {};
|
|
81
81
|
await A.patchById('model', 1, data);
|
|
82
82
|
expect(V.sanitize).to.be.called.once;
|
|
83
|
-
expect(V.sanitize).to.be.called.with
|
|
83
|
+
expect(V.sanitize).to.be.called.with('model', data);
|
|
84
84
|
});
|
|
85
85
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
|
-
import {chai} from '../../chai.js';
|
|
3
2
|
import {Adapter} from '../adapter.js';
|
|
3
|
+
import {createSandbox} from '@e22m4u/js-spy';
|
|
4
4
|
import {DatabaseSchema} from '../../database-schema.js';
|
|
5
5
|
import {DataType, ModelDefinitionUtils} from '../../definition/index.js';
|
|
6
6
|
|
|
@@ -57,7 +57,7 @@ class TestAdapter extends Adapter {
|
|
|
57
57
|
|
|
58
58
|
const A = dbs.getService(TestAdapter);
|
|
59
59
|
const U = dbs.getService(ModelDefinitionUtils);
|
|
60
|
-
const sandbox =
|
|
60
|
+
const sandbox = createSandbox();
|
|
61
61
|
|
|
62
62
|
describe('DefaultValuesDecorator', function () {
|
|
63
63
|
afterEach(function () {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
|
-
import {chai} from '../../chai.js';
|
|
3
2
|
import {Adapter} from '../adapter.js';
|
|
3
|
+
import {createSandbox} from '@e22m4u/js-spy';
|
|
4
4
|
import {FieldsClauseTool} from '../../filter/index.js';
|
|
5
5
|
import {DatabaseSchema} from '../../database-schema.js';
|
|
6
6
|
|
|
@@ -55,7 +55,7 @@ class TestAdapter extends Adapter {
|
|
|
55
55
|
|
|
56
56
|
const A = dbs.getService(TestAdapter);
|
|
57
57
|
const T = dbs.getService(FieldsClauseTool);
|
|
58
|
-
const sandbox =
|
|
58
|
+
const sandbox = createSandbox();
|
|
59
59
|
|
|
60
60
|
describe('FieldsFilteringDecorator', function () {
|
|
61
61
|
afterEach(function () {
|
|
@@ -67,11 +67,7 @@ describe('FieldsFilteringDecorator', function () {
|
|
|
67
67
|
const retval = await A.create(MODEL_NAME, {}, FILTER);
|
|
68
68
|
expect(retval).to.be.eql(RETVAL_DATA);
|
|
69
69
|
expect(T.filter).to.be.called.once;
|
|
70
|
-
expect(T.filter).to.be.called.with.
|
|
71
|
-
MODEL_DATA,
|
|
72
|
-
MODEL_NAME,
|
|
73
|
-
FILTER.fields,
|
|
74
|
-
);
|
|
70
|
+
expect(T.filter).to.be.called.with(MODEL_DATA, MODEL_NAME, FILTER.fields);
|
|
75
71
|
});
|
|
76
72
|
|
|
77
73
|
it('overrides the "replaceById" method and filtering output fields', async function () {
|
|
@@ -79,11 +75,7 @@ describe('FieldsFilteringDecorator', function () {
|
|
|
79
75
|
const retval = await A.replaceById(MODEL_NAME, 1, {}, FILTER);
|
|
80
76
|
expect(retval).to.be.eql(RETVAL_DATA);
|
|
81
77
|
expect(T.filter).to.be.called.once;
|
|
82
|
-
expect(T.filter).to.be.called.with.
|
|
83
|
-
MODEL_DATA,
|
|
84
|
-
MODEL_NAME,
|
|
85
|
-
FILTER.fields,
|
|
86
|
-
);
|
|
78
|
+
expect(T.filter).to.be.called.with(MODEL_DATA, MODEL_NAME, FILTER.fields);
|
|
87
79
|
});
|
|
88
80
|
|
|
89
81
|
it('overrides the "replaceOrCreate" method and filtering output fields', async function () {
|
|
@@ -91,11 +83,7 @@ describe('FieldsFilteringDecorator', function () {
|
|
|
91
83
|
const retval = await A.replaceOrCreate(MODEL_NAME, {}, FILTER);
|
|
92
84
|
expect(retval).to.be.eql(RETVAL_DATA);
|
|
93
85
|
expect(T.filter).to.be.called.once;
|
|
94
|
-
expect(T.filter).to.be.called.with.
|
|
95
|
-
MODEL_DATA,
|
|
96
|
-
MODEL_NAME,
|
|
97
|
-
FILTER.fields,
|
|
98
|
-
);
|
|
86
|
+
expect(T.filter).to.be.called.with(MODEL_DATA, MODEL_NAME, FILTER.fields);
|
|
99
87
|
});
|
|
100
88
|
|
|
101
89
|
it('overrides the "patchById" method and filtering output fields', async function () {
|
|
@@ -103,11 +91,7 @@ describe('FieldsFilteringDecorator', function () {
|
|
|
103
91
|
const retval = await A.patchById(MODEL_NAME, 1, {}, FILTER);
|
|
104
92
|
expect(retval).to.be.eql(RETVAL_DATA);
|
|
105
93
|
expect(T.filter).to.be.called.once;
|
|
106
|
-
expect(T.filter).to.be.called.with.
|
|
107
|
-
MODEL_DATA,
|
|
108
|
-
MODEL_NAME,
|
|
109
|
-
FILTER.fields,
|
|
110
|
-
);
|
|
94
|
+
expect(T.filter).to.be.called.with(MODEL_DATA, MODEL_NAME, FILTER.fields);
|
|
111
95
|
});
|
|
112
96
|
|
|
113
97
|
it('overrides the "find" method and filtering output fields', async function () {
|
|
@@ -127,10 +111,6 @@ describe('FieldsFilteringDecorator', function () {
|
|
|
127
111
|
const retval = await A.findById(MODEL_NAME, 1, FILTER);
|
|
128
112
|
expect(retval).to.be.eql(RETVAL_DATA);
|
|
129
113
|
expect(T.filter).to.be.called.once;
|
|
130
|
-
expect(T.filter).to.be.called.with.
|
|
131
|
-
MODEL_DATA,
|
|
132
|
-
MODEL_NAME,
|
|
133
|
-
FILTER.fields,
|
|
134
|
-
);
|
|
114
|
+
expect(T.filter).to.be.called.with(MODEL_DATA, MODEL_NAME, FILTER.fields);
|
|
135
115
|
});
|
|
136
116
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
|
-
import {chai} from '../../chai.js';
|
|
3
2
|
import {Adapter} from '../adapter.js';
|
|
3
|
+
import {createSandbox} from '@e22m4u/js-spy';
|
|
4
4
|
import {DatabaseSchema} from '../../database-schema.js';
|
|
5
5
|
import {IncludeClauseTool} from '../../filter/index.js';
|
|
6
6
|
|
|
@@ -53,7 +53,7 @@ class TestAdapter extends Adapter {
|
|
|
53
53
|
|
|
54
54
|
const A = dbs.getService(TestAdapter);
|
|
55
55
|
const T = dbs.getService(IncludeClauseTool);
|
|
56
|
-
const sandbox =
|
|
56
|
+
const sandbox = createSandbox();
|
|
57
57
|
|
|
58
58
|
describe('InclusionDecorator', function () {
|
|
59
59
|
afterEach(function () {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
|
-
import {chai} from '../../chai.js';
|
|
3
2
|
import {Adapter} from '../adapter.js';
|
|
3
|
+
import {createSandbox} from '@e22m4u/js-spy';
|
|
4
4
|
import {DatabaseSchema} from '../../database-schema.js';
|
|
5
5
|
import {PropertyUniquenessValidator} from '../../definition/index.js';
|
|
6
6
|
|
|
@@ -36,7 +36,7 @@ class TestAdapter extends Adapter {
|
|
|
36
36
|
|
|
37
37
|
const A = dbs.getService(TestAdapter);
|
|
38
38
|
const V = dbs.getService(PropertyUniquenessValidator);
|
|
39
|
-
const sandbox =
|
|
39
|
+
const sandbox = createSandbox();
|
|
40
40
|
|
|
41
41
|
describe('PropertyUniquenessDecorator', function () {
|
|
42
42
|
afterEach(function () {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
|
-
import {
|
|
2
|
+
import {createSandbox} from '@e22m4u/js-spy';
|
|
3
3
|
import {ModelDefinitionValidator} from './model/index.js';
|
|
4
4
|
import {DefinitionRegistry} from './definition-registry.js';
|
|
5
5
|
import {DatasourceDefinitionValidator} from '../definition/index.js';
|
|
6
6
|
|
|
7
|
-
const sandbox =
|
|
7
|
+
const sandbox = createSandbox();
|
|
8
8
|
|
|
9
9
|
describe('DefinitionRegistry', function () {
|
|
10
10
|
let S;
|
|
@@ -31,7 +31,7 @@ describe('DefinitionRegistry', function () {
|
|
|
31
31
|
const datasource = {name: 'datasource', adapter: 'adapter'};
|
|
32
32
|
S.addDatasource(datasource);
|
|
33
33
|
expect(V.validate).to.have.been.called.once;
|
|
34
|
-
expect(V.validate).to.have.been.called.with
|
|
34
|
+
expect(V.validate).to.have.been.called.with(datasource);
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
it('throws an error if a given datasource is already defined', function () {
|
|
@@ -82,7 +82,7 @@ describe('DefinitionRegistry', function () {
|
|
|
82
82
|
const model = {name: 'model'};
|
|
83
83
|
S.addModel(model);
|
|
84
84
|
expect(V.validate).to.have.been.called.once;
|
|
85
|
-
expect(V.validate).to.have.been.called.with
|
|
85
|
+
expect(V.validate).to.have.been.called.with(model);
|
|
86
86
|
});
|
|
87
87
|
|
|
88
88
|
it('throws an error if a given model is already defined', function () {
|
|
@@ -147,7 +147,7 @@ export class ModelDefinitionUtils extends Service {
|
|
|
147
147
|
propDef != null
|
|
148
148
|
? this.getDataTypeFromPropertyDefinition(propDef)
|
|
149
149
|
: DataType.ANY;
|
|
150
|
-
const isEmpty = emptyValuesService.
|
|
150
|
+
const isEmpty = emptyValuesService.isEmptyOf(propType, propValue);
|
|
151
151
|
if (!isEmpty) return;
|
|
152
152
|
if (
|
|
153
153
|
propDef &&
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
|
-
import {chai} from '../../chai.js';
|
|
3
2
|
import {format} from '@e22m4u/js-format';
|
|
3
|
+
import {createSandbox} from '@e22m4u/js-spy';
|
|
4
4
|
import {DataType} from './properties/index.js';
|
|
5
5
|
import {RelationType} from './relations/index.js';
|
|
6
6
|
import {DatabaseSchema} from '../../database-schema.js';
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
DEFAULT_PRIMARY_KEY_PROPERTY_NAME as DEF_PK,
|
|
13
13
|
} from './model-definition-utils.js';
|
|
14
14
|
|
|
15
|
-
const sandbox =
|
|
15
|
+
const sandbox = createSandbox();
|
|
16
16
|
|
|
17
17
|
describe('ModelDefinitionUtils', function () {
|
|
18
18
|
afterEach(function () {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
|
-
import {chai} from '../../chai.js';
|
|
3
2
|
import {format} from '@e22m4u/js-format';
|
|
3
|
+
import {createSandbox} from '@e22m4u/js-spy';
|
|
4
4
|
import {RelationsDefinitionValidator} from './relations/index.js';
|
|
5
5
|
import {PropertiesDefinitionValidator} from './properties/index.js';
|
|
6
6
|
import {ModelDefinitionValidator} from './model-definition-validator.js';
|
|
7
7
|
|
|
8
8
|
const S = new ModelDefinitionValidator();
|
|
9
|
-
const sandbox =
|
|
9
|
+
const sandbox = createSandbox();
|
|
10
10
|
|
|
11
11
|
describe('ModelDefinitionValidator', function () {
|
|
12
12
|
afterEach(function () {
|
|
@@ -131,7 +131,7 @@ describe('ModelDefinitionValidator', function () {
|
|
|
131
131
|
const properties = {};
|
|
132
132
|
S.validate({name: 'model', properties});
|
|
133
133
|
expect(V.validate).to.have.been.called.once;
|
|
134
|
-
expect(V.validate).to.have.been.called.with
|
|
134
|
+
expect(V.validate).to.have.been.called.with('model', properties);
|
|
135
135
|
});
|
|
136
136
|
|
|
137
137
|
it('uses RelationsDefinitionValidator service to validate model relations', function () {
|
|
@@ -140,7 +140,7 @@ describe('ModelDefinitionValidator', function () {
|
|
|
140
140
|
const relations = {};
|
|
141
141
|
S.validate({name: 'model', relations});
|
|
142
142
|
expect(V.validate).to.have.been.called.once;
|
|
143
|
-
expect(V.validate).to.have.been.called.with
|
|
143
|
+
expect(V.validate).to.have.been.called.with('model', relations);
|
|
144
144
|
});
|
|
145
145
|
});
|
|
146
146
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
|
-
import {chai} from '../../../chai.js';
|
|
3
2
|
import {DataType} from './data-type.js';
|
|
4
3
|
import {format} from '@e22m4u/js-format';
|
|
4
|
+
import {createSandbox} from '@e22m4u/js-spy';
|
|
5
5
|
import {PropertyUniqueness} from './property-uniqueness.js';
|
|
6
6
|
import {PropertiesDefinitionValidator} from './properties-definition-validator.js';
|
|
7
7
|
import {PrimaryKeysDefinitionValidator} from './primary-keys-definition-validator.js';
|
|
8
8
|
|
|
9
9
|
const S = new PropertiesDefinitionValidator();
|
|
10
|
-
const sandbox =
|
|
10
|
+
const sandbox = createSandbox();
|
|
11
11
|
|
|
12
12
|
describe('PropertiesDefinitionValidator', function () {
|
|
13
13
|
afterEach(function () {
|
|
@@ -415,7 +415,7 @@ describe('PropertiesDefinitionValidator', function () {
|
|
|
415
415
|
const propDefs = {};
|
|
416
416
|
S.validate('model', propDefs);
|
|
417
417
|
expect(V.validate).to.have.been.called.once;
|
|
418
|
-
expect(V.validate).to.have.been.called.with
|
|
418
|
+
expect(V.validate).to.have.been.called.with('model', propDefs);
|
|
419
419
|
});
|
|
420
420
|
|
|
421
421
|
it('expects the provided option "unique" to be a Boolean or the PropertyUniqueness', function () {
|
|
@@ -85,7 +85,7 @@ export class PropertyUniquenessValidator extends Service {
|
|
|
85
85
|
const propValue = modelData[propName];
|
|
86
86
|
if (propDef.unique === PropertyUniqueness.SPARSE) {
|
|
87
87
|
const propType = propDef.type || DataType.ANY;
|
|
88
|
-
const isEmpty = emptyValuesService.
|
|
88
|
+
const isEmpty = emptyValuesService.isEmptyOf(propType, propValue);
|
|
89
89
|
if (isEmpty) continue;
|
|
90
90
|
}
|
|
91
91
|
// create
|
package/src/chai.js
DELETED