@e22m4u/js-repository 0.2.6 → 0.3.0
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 +79 -80
- package/dist/cjs/index.cjs +2023 -2093
- package/eslint.config.js +1 -1
- package/package.json +15 -12
- package/src/adapter/adapter-registry.spec.js +7 -7
- package/src/adapter/adapter.spec.js +11 -11
- package/src/adapter/builtin/memory-adapter.spec.js +537 -537
- package/src/adapter/decorator/data-sanitizing-decorator.spec.js +5 -5
- package/src/adapter/decorator/data-transformation-decorator.spec.js +5 -5
- package/src/adapter/decorator/data-validation-decorator.spec.js +5 -5
- package/src/adapter/decorator/default-values-decorator.spec.js +5 -5
- package/src/adapter/decorator/fields-filtering-decorator.spec.js +5 -5
- package/src/adapter/decorator/inclusion-decorator.spec.js +5 -5
- package/src/adapter/decorator/property-uniqueness-decorator.spec.js +5 -5
- package/src/{schema.d.ts → database-schema.d.ts} +2 -2
- package/src/{schema.js → database-schema.js} +2 -2
- package/src/database-schema.spec.ts +86 -0
- package/src/definition/model/model-data-transformer.js +3 -3
- package/src/definition/model/model-data-transformer.spec.js +93 -93
- package/src/definition/model/model-data-validator.js +2 -2
- package/src/definition/model/model-data-validator.spec.js +517 -531
- package/src/definition/model/model-definition-utils.js +3 -3
- package/src/definition/model/model-definition-utils.spec.js +345 -343
- package/src/definition/model/properties/index.d.ts +0 -1
- package/src/definition/model/properties/index.js +0 -1
- package/src/definition/model/properties/property-transformer/property-transformer-registry.spec.js +36 -36
- package/src/definition/model/properties/property-uniqueness-validator.js +3 -3
- package/src/definition/model/properties/property-uniqueness-validator.spec.js +417 -384
- package/src/definition/model/properties/property-validator/property-validator-registry.spec.js +36 -36
- package/src/filter/fields-clause-tool.spec.js +4 -4
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/src/relations/belongs-to-resolver.spec.js +166 -166
- package/src/relations/has-many-resolver.spec.js +281 -281
- package/src/relations/has-one-resolver.spec.js +281 -281
- package/src/relations/references-many-resolver.spec.js +92 -92
- package/src/repository/repository-registry.spec.js +10 -10
- package/src/repository/repository.spec.js +73 -73
- package/src/utils/is-promise.spec.js +1 -2
- package/src/utils/transform-promise.spec.js +0 -1
- package/src/definition/model/properties/empty-values-definer.d.ts +0 -23
- package/src/definition/model/properties/empty-values-definer.js +0 -66
- package/src/definition/model/properties/empty-values-definer.spec.js +0 -96
- package/src/schema.spec.ts +0 -86
package/src/definition/model/properties/property-validator/property-validator-registry.spec.js
CHANGED
|
@@ -7,8 +7,8 @@ import {PropertyValidatorRegistry} from './property-validator-registry.js';
|
|
|
7
7
|
|
|
8
8
|
describe('PropertyValidatorRegistry', function () {
|
|
9
9
|
it('has builtin validators', function () {
|
|
10
|
-
const
|
|
11
|
-
expect(
|
|
10
|
+
const pvr = new PropertyValidatorRegistry();
|
|
11
|
+
expect(pvr['_validators']).to.be.eql({
|
|
12
12
|
maxLength: maxLengthValidator,
|
|
13
13
|
minLength: minLengthValidator,
|
|
14
14
|
regexp: regexpValidator,
|
|
@@ -17,16 +17,16 @@ describe('PropertyValidatorRegistry', function () {
|
|
|
17
17
|
|
|
18
18
|
describe('addValidator', function () {
|
|
19
19
|
it('adds a given validator with the name', function () {
|
|
20
|
-
const
|
|
20
|
+
const pvr = new PropertyValidatorRegistry();
|
|
21
21
|
const myValidator = () => undefined;
|
|
22
|
-
const res =
|
|
23
|
-
expect(res).to.be.eq(
|
|
24
|
-
expect(
|
|
22
|
+
const res = pvr.addValidator('myValidator', myValidator);
|
|
23
|
+
expect(res).to.be.eq(pvr);
|
|
24
|
+
expect(pvr['_validators']['myValidator']).to.be.eq(myValidator);
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
it('requires the given name to be a non-empty string', function () {
|
|
28
|
-
const
|
|
29
|
-
const throwable = v => () =>
|
|
28
|
+
const pvr = new PropertyValidatorRegistry();
|
|
29
|
+
const throwable = v => () => pvr.addValidator(v, () => undefined);
|
|
30
30
|
const error = v =>
|
|
31
31
|
format(
|
|
32
32
|
'A name of the property validator must ' +
|
|
@@ -46,17 +46,17 @@ describe('PropertyValidatorRegistry', function () {
|
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
it('throws an error if the given name already exists', function () {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
const throwable = () =>
|
|
49
|
+
const pvr = new PropertyValidatorRegistry();
|
|
50
|
+
pvr.addValidator('test', () => undefined);
|
|
51
|
+
const throwable = () => pvr.addValidator('test', () => undefined);
|
|
52
52
|
expect(throwable).to.throw(
|
|
53
53
|
'The property validator "test" is already defined.',
|
|
54
54
|
);
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
it('requires the given validator to be a function', function () {
|
|
58
|
-
const
|
|
59
|
-
const throwable = v => () =>
|
|
58
|
+
const pvr = new PropertyValidatorRegistry();
|
|
59
|
+
const throwable = v => () => pvr.addValidator('test', v);
|
|
60
60
|
const error = v =>
|
|
61
61
|
format(
|
|
62
62
|
'The property validator "test" must be a Function, but %s given.',
|
|
@@ -77,44 +77,44 @@ describe('PropertyValidatorRegistry', function () {
|
|
|
77
77
|
|
|
78
78
|
describe('hasValidator', function () {
|
|
79
79
|
it('returns false for a not existing name', function () {
|
|
80
|
-
const
|
|
81
|
-
expect(
|
|
82
|
-
expect(
|
|
83
|
-
expect(
|
|
84
|
-
expect(
|
|
85
|
-
expect(
|
|
86
|
-
expect(
|
|
87
|
-
expect(
|
|
88
|
-
expect(
|
|
89
|
-
expect(
|
|
90
|
-
expect(
|
|
91
|
-
expect(
|
|
80
|
+
const pvr = new PropertyValidatorRegistry();
|
|
81
|
+
expect(pvr.hasValidator('str')).to.be.false;
|
|
82
|
+
expect(pvr.hasValidator('')).to.be.false;
|
|
83
|
+
expect(pvr.hasValidator(10)).to.be.false;
|
|
84
|
+
expect(pvr.hasValidator(0)).to.be.false;
|
|
85
|
+
expect(pvr.hasValidator(true)).to.be.false;
|
|
86
|
+
expect(pvr.hasValidator(false)).to.be.false;
|
|
87
|
+
expect(pvr.hasValidator(null)).to.be.false;
|
|
88
|
+
expect(pvr.hasValidator(undefined)).to.be.false;
|
|
89
|
+
expect(pvr.hasValidator({})).to.be.false;
|
|
90
|
+
expect(pvr.hasValidator([])).to.be.false;
|
|
91
|
+
expect(pvr.hasValidator(() => undefined)).to.be.false;
|
|
92
92
|
});
|
|
93
93
|
|
|
94
94
|
it('returns true for an existing name', function () {
|
|
95
|
-
const
|
|
96
|
-
expect(
|
|
97
|
-
|
|
98
|
-
expect(
|
|
95
|
+
const pvr = new PropertyValidatorRegistry();
|
|
96
|
+
expect(pvr.hasValidator('test')).to.be.false;
|
|
97
|
+
pvr.addValidator('test', () => undefined);
|
|
98
|
+
expect(pvr.hasValidator('test')).to.be.true;
|
|
99
99
|
});
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
describe('getValidator', function () {
|
|
103
103
|
it('returns validator by its name', function () {
|
|
104
|
-
const
|
|
104
|
+
const pvr = new PropertyValidatorRegistry();
|
|
105
105
|
const myValidator1 = () => undefined;
|
|
106
106
|
const myValidator2 = () => undefined;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const res1 =
|
|
110
|
-
const res2 =
|
|
107
|
+
pvr.addValidator('foo', myValidator1);
|
|
108
|
+
pvr.addValidator('bar', myValidator2);
|
|
109
|
+
const res1 = pvr.getValidator('foo');
|
|
110
|
+
const res2 = pvr.getValidator('bar');
|
|
111
111
|
expect(res1).to.be.eq(myValidator1);
|
|
112
112
|
expect(res2).to.be.eq(myValidator2);
|
|
113
113
|
});
|
|
114
114
|
|
|
115
115
|
it('throws an error for a not existed name', function () {
|
|
116
|
-
const
|
|
117
|
-
const throwable = v => () =>
|
|
116
|
+
const pvr = new PropertyValidatorRegistry();
|
|
117
|
+
const throwable = v => () => pvr.getValidator(v);
|
|
118
118
|
const error = v => format('The property validator %s is not defined.', v);
|
|
119
119
|
expect(throwable('str')).to.throw(error('"str"'));
|
|
120
120
|
expect(throwable('')).to.throw(error('""'));
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
|
-
import {Schema} from '../schema.js';
|
|
3
2
|
import {format} from '@e22m4u/js-format';
|
|
3
|
+
import {DatabaseSchema} from '../database-schema.js';
|
|
4
4
|
import {FieldsClauseTool} from './fields-clause-tool.js';
|
|
5
5
|
import {DEFAULT_PRIMARY_KEY_PROPERTY_NAME as DEF_PK} from '../definition/index.js';
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const dbs = new DatabaseSchema();
|
|
8
8
|
const MODEL_NAME = 'model';
|
|
9
|
-
|
|
10
|
-
const T =
|
|
9
|
+
dbs.defineModel({name: MODEL_NAME});
|
|
10
|
+
const T = dbs.getService(FieldsClauseTool);
|
|
11
11
|
|
|
12
12
|
describe('FieldsClauseTool', function () {
|
|
13
13
|
describe('filter', function () {
|
package/src/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export * from './types.js';
|
|
2
|
-
export * from './schema.js';
|
|
3
2
|
export * from './utils/index.js';
|
|
4
3
|
export * from './errors/index.js';
|
|
5
4
|
export * from './filter/index.js';
|
|
6
5
|
export * from './adapter/index.js';
|
|
6
|
+
export * from './database-schema.js';
|
|
7
7
|
export * from './relations/index.js';
|
|
8
8
|
export * from './definition/index.js';
|
|
9
9
|
export * from './repository/index.js';
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export * from './types.js';
|
|
2
|
-
export * from './schema.js';
|
|
3
2
|
export * from './utils/index.js';
|
|
4
3
|
export * from './errors/index.js';
|
|
5
4
|
export * from './filter/index.js';
|
|
6
5
|
export * from './adapter/index.js';
|
|
6
|
+
export * from './database-schema.js';
|
|
7
7
|
export * from './relations/index.js';
|
|
8
8
|
export * from './definition/index.js';
|
|
9
9
|
export * from './repository/index.js';
|