@e22m4u/js-repository 0.8.1 → 0.8.2

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 CHANGED
@@ -1,4 +1,5 @@
1
1
  {
2
2
  "extension": ["js"],
3
- "spec": "src/**/*.spec.js"
3
+ "spec": "src/**/*.spec.js",
4
+ "require": "mocha.setup.js"
4
5
  }
package/README.md CHANGED
@@ -485,12 +485,12 @@ dbs.defineModel({
485
485
 
486
486
  | тип | пустые значения |
487
487
  |-------------|---------------------------|
488
- | `'any'` | `undefined`, `null` |
488
+ | `'any'` | `undefined`, `null`, `''` |
489
489
  | `'string'` | `undefined`, `null`, `''` |
490
- | `'number'` | `undefined`, `null`, `0` |
490
+ | `'number'` | `undefined`, `null` |
491
491
  | `'boolean'` | `undefined`, `null` |
492
- | `'array'` | `undefined`, `null`, `[]` |
493
- | `'object'` | `undefined`, `null`, `{}` |
492
+ | `'array'` | `undefined`, `null` |
493
+ | `'object'` | `undefined`, `null` |
494
494
 
495
495
  ### Переопределение пустых значений
496
496
 
@@ -526,9 +526,9 @@ class EmptyValuesService {
526
526
 
527
527
  **Пример**
528
528
 
529
- По умолчанию, для числовых свойств значение `0` считается пустым. Следующий
530
- пример демонстрирует, как изменить это поведение, оставив в качестве пустых
531
- значений только `undefined` и `null`.
529
+ Если строковое свойство является обязательным, то значение `""` (пустая строка)
530
+ приведет к ошибке. Следующий пример демонстрирует, как изменить данное
531
+ поведение, оставив в качестве пустых значений только `undefined` и `null`.
532
532
 
533
533
  ```js
534
534
  import {DataType} from '@e22m4u/js-repository';
@@ -540,13 +540,12 @@ const dbs = new DatabaseSchema();
540
540
  // получение сервиса для работы с пустыми значениями
541
541
  const emptyValuesService = dbs.getService(EmptyValuesService);
542
542
 
543
- // переопределение пустых значений для типа DataType.NUMBER
544
- emptyValuesService.setEmptyValuesOf(DataType.NUMBER, [undefined, null]);
543
+ // переопределение пустых значений для типа DataType.STRING
544
+ emptyValuesService.setEmptyValuesOf(DataType.STRING, [undefined, null]);
545
545
  ```
546
546
 
547
- После этого, значение `0` для свойств типа `DataType.NUMBER` больше не будет
548
- считаться пустым и будет проходить проверку с опцией `required`, а также
549
- не будет заменяться значением по умолчанию.
547
+ Теперь пустая строка будет успешно проходить проверку для свойств
548
+ с типом `string`, а также не будет заменяться на значение по умолчанию.
550
549
 
551
550
  ## Репозиторий
552
551
 
package/mocha.setup.js ADDED
@@ -0,0 +1,6 @@
1
+ import * as chai from 'chai';
2
+ import {chaiSpies} from '@e22m4u/js-spy';
3
+ import chaiAsPromised from 'chai-as-promised';
4
+
5
+ chai.use(chaiSpies);
6
+ chai.use(chaiAsPromised);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e22m4u/js-repository",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
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.1",
43
- "@e22m4u/js-format": "~0.3.1",
42
+ "@e22m4u/js-empty-values": "~0.3.1",
43
+ "@e22m4u/js-format": "~0.3.2",
44
44
  "@e22m4u/js-service": "~0.5.1"
45
45
  },
46
46
  "devDependencies": {
47
- "@commitlint/cli": "~20.1.0",
48
- "@commitlint/config-conventional": "~20.0.0",
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.1",
54
+ "chai": "~6.2.2",
55
55
  "chai-as-promised": "~8.0.2",
56
- "chai-spies": "~1.1.0",
57
- "esbuild": "~0.27.0",
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.4.1",
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 {chai} from '../chai.js';
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 = chai.spy.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 = chai.spy.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.exactly('model', data);
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.exactly('model', data);
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.exactly('model', data);
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.exactly('model', data);
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.exactly('model', data);
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 = chai.spy.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 = chai.spy.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.exactly(
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.exactly(
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.exactly(
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.exactly(
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.exactly(
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 = chai.spy.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 = chai.spy.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 {chai} from '../chai.js';
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 = chai.spy.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.exactly(datasource);
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.exactly(model);
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 () {
@@ -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 = chai.spy.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 = chai.spy.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.exactly('model', properties);
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.exactly('model', relations);
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 = chai.spy.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.exactly('model', propDefs);
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 () {
package/src/chai.js DELETED
@@ -1,9 +0,0 @@
1
- import * as chaiModule from 'chai';
2
- import chaiSpies from 'chai-spies';
3
- import chaiAsPromised from 'chai-as-promised';
4
- const chai = {...chaiModule};
5
-
6
- chaiSpies(chai, chai.util);
7
- chaiAsPromised(chai, chai.util);
8
-
9
- export {chai};