@e22m4u/js-repository 0.6.5 → 0.8.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/.mocharc.json +2 -3
- package/README.md +128 -695
- package/dist/cjs/index.cjs +141 -1262
- package/eslint.config.js +29 -58
- package/jsconfig.json +7 -0
- package/package.json +12 -20
- package/src/adapter/adapter-loader.js +3 -4
- package/src/adapter/adapter.js +10 -11
- package/src/adapter/adapter.spec.js +13 -24
- package/src/adapter/builtin/memory-adapter.js +49 -19
- package/src/adapter/builtin/memory-adapter.spec.js +52 -2
- package/src/adapter/decorator/default-values-decorator.spec.js +1 -2
- package/src/adapter/decorator/index.js +0 -2
- package/src/database-schema.js +1 -2
- package/src/{database-schema.spec.ts → database-schema.spec.js} +5 -17
- package/src/definition/model/index.js +0 -3
- package/src/definition/model/model-definition-utils.js +1 -2
- package/src/definition/model/model-definition-utils.spec.js +5 -2
- package/src/definition/model/properties/index.js +0 -3
- package/src/definition/model/properties/properties-definition-validator.js +0 -169
- package/src/definition/model/properties/properties-definition-validator.spec.js +0 -162
- package/src/definition/model/relations/index.js +0 -1
- package/src/definition/model/relations/relations-definition-validator.js +4 -5
- package/src/filter/include-clause-tool.js +8 -6
- package/src/index.js +0 -1
- package/src/relations/belongs-to-resolver.js +1 -2
- package/src/relations/belongs-to-resolver.spec.js +6 -3
- package/src/relations/has-many-resolver.js +1 -2
- package/src/relations/has-many-resolver.spec.js +6 -3
- package/src/relations/has-one-resolver.js +1 -2
- package/src/relations/has-one-resolver.spec.js +6 -3
- package/src/relations/references-many-resolver.js +1 -2
- package/src/relations/references-many-resolver.spec.js +6 -3
- package/src/repository/repository.js +1 -2
- package/src/utils/index.js +0 -4
- package/src/utils/is-plain-object.js +4 -4
- package/src/utils/model-name-to-model-key.js +0 -4
- package/src/utils/model-name-to-model-key.spec.js +0 -23
- package/src/adapter/adapter-loader.d.ts +0 -16
- package/src/adapter/adapter-registry.d.ts +0 -14
- package/src/adapter/adapter.d.ts +0 -155
- package/src/adapter/builtin/memory-adapter.d.ts +0 -148
- package/src/adapter/decorator/data-sanitizing-decorator.d.ts +0 -14
- package/src/adapter/decorator/data-transformation-decorator.d.ts +0 -14
- package/src/adapter/decorator/data-transformation-decorator.js +0 -54
- package/src/adapter/decorator/data-transformation-decorator.spec.js +0 -193
- package/src/adapter/decorator/data-validation-decorator.d.ts +0 -14
- package/src/adapter/decorator/data-validation-decorator.js +0 -54
- package/src/adapter/decorator/data-validation-decorator.spec.js +0 -105
- package/src/adapter/decorator/default-values-decorator.d.ts +0 -14
- package/src/adapter/decorator/fields-filtering-decorator.d.ts +0 -14
- package/src/adapter/decorator/inclusion-decorator.d.ts +0 -14
- package/src/adapter/decorator/index.d.ts +0 -7
- package/src/adapter/decorator/property-uniqueness-decorator.d.ts +0 -14
- package/src/adapter/index.d.ts +0 -3
- package/src/database-schema.d.ts +0 -37
- package/src/definition/datasource/datasource-definition-validator.d.ts +0 -14
- package/src/definition/datasource/datasource-definition.d.ts +0 -8
- package/src/definition/datasource/index.d.ts +0 -2
- package/src/definition/definition-registry.d.ts +0 -50
- package/src/definition/index.d.ts +0 -3
- package/src/definition/model/index.d.ts +0 -8
- package/src/definition/model/model-data-sanitizer.d.ts +0 -15
- package/src/definition/model/model-data-transformer.d.ts +0 -16
- package/src/definition/model/model-data-transformer.js +0 -170
- package/src/definition/model/model-data-transformer.spec.js +0 -2312
- package/src/definition/model/model-data-validator.d.ts +0 -16
- package/src/definition/model/model-data-validator.js +0 -318
- package/src/definition/model/model-data-validator.spec.js +0 -4528
- package/src/definition/model/model-definition-utils.d.ts +0 -180
- package/src/definition/model/model-definition-validator.d.ts +0 -14
- package/src/definition/model/model-definition.d.ts +0 -28
- package/src/definition/model/model-definition.js +0 -1
- package/src/definition/model/properties/data-type.d.ts +0 -16
- package/src/definition/model/properties/index.d.ts +0 -8
- package/src/definition/model/properties/primary-keys-definition-validator.d.ts +0 -15
- package/src/definition/model/properties/properties-definition-validator.d.ts +0 -15
- package/src/definition/model/properties/property-definition.d.ts +0 -27
- package/src/definition/model/properties/property-definition.js +0 -1
- package/src/definition/model/properties/property-transformer/builtin/index.d.ts +0 -3
- package/src/definition/model/properties/property-transformer/builtin/index.js +0 -3
- package/src/definition/model/properties/property-transformer/builtin/to-lower-case-transformer.d.ts +0 -6
- package/src/definition/model/properties/property-transformer/builtin/to-lower-case-transformer.js +0 -19
- package/src/definition/model/properties/property-transformer/builtin/to-lower-case-transformer.spec.js +0 -39
- package/src/definition/model/properties/property-transformer/builtin/to-upper-case-transformer.d.ts +0 -6
- package/src/definition/model/properties/property-transformer/builtin/to-upper-case-transformer.js +0 -19
- package/src/definition/model/properties/property-transformer/builtin/to-upper-case-transformer.spec.js +0 -39
- package/src/definition/model/properties/property-transformer/builtin/trim-transformer.d.ts +0 -6
- package/src/definition/model/properties/property-transformer/builtin/trim-transformer.js +0 -19
- package/src/definition/model/properties/property-transformer/builtin/trim-transformer.spec.js +0 -39
- package/src/definition/model/properties/property-transformer/index.d.ts +0 -2
- package/src/definition/model/properties/property-transformer/index.js +0 -2
- package/src/definition/model/properties/property-transformer/property-transformer-registry.d.ts +0 -29
- package/src/definition/model/properties/property-transformer/property-transformer-registry.js +0 -76
- package/src/definition/model/properties/property-transformer/property-transformer-registry.spec.js +0 -133
- package/src/definition/model/properties/property-transformer/property-transformer.d.ts +0 -27
- package/src/definition/model/properties/property-transformer/property-transformer.js +0 -1
- package/src/definition/model/properties/property-uniqueness-validator.d.ts +0 -31
- package/src/definition/model/properties/property-uniqueness.d.ts +0 -14
- package/src/definition/model/properties/property-validator/builtin/index.d.ts +0 -3
- package/src/definition/model/properties/property-validator/builtin/index.js +0 -3
- package/src/definition/model/properties/property-validator/builtin/max-length-validator.d.ts +0 -6
- package/src/definition/model/properties/property-validator/builtin/max-length-validator.js +0 -28
- package/src/definition/model/properties/property-validator/builtin/max-length-validator.spec.js +0 -100
- package/src/definition/model/properties/property-validator/builtin/min-length-validator.d.ts +0 -6
- package/src/definition/model/properties/property-validator/builtin/min-length-validator.js +0 -28
- package/src/definition/model/properties/property-validator/builtin/min-length-validator.spec.js +0 -100
- package/src/definition/model/properties/property-validator/builtin/regexp-validator.d.ts +0 -6
- package/src/definition/model/properties/property-validator/builtin/regexp-validator.js +0 -30
- package/src/definition/model/properties/property-validator/builtin/regexp-validator.spec.js +0 -102
- package/src/definition/model/properties/property-validator/index.d.ts +0 -2
- package/src/definition/model/properties/property-validator/index.js +0 -2
- package/src/definition/model/properties/property-validator/property-validator-registry.d.ts +0 -29
- package/src/definition/model/properties/property-validator/property-validator-registry.js +0 -76
- package/src/definition/model/properties/property-validator/property-validator-registry.spec.js +0 -132
- package/src/definition/model/properties/property-validator/property-validator.d.ts +0 -25
- package/src/definition/model/properties/property-validator/property-validator.js +0 -1
- package/src/definition/model/relations/index.d.ts +0 -3
- package/src/definition/model/relations/relation-definition.d.ts +0 -236
- package/src/definition/model/relations/relation-definition.js +0 -1
- package/src/definition/model/relations/relation-type.d.ts +0 -14
- package/src/definition/model/relations/relations-definition-validator.d.ts +0 -15
- package/src/errors/index.d.ts +0 -3
- package/src/errors/invalid-argument-error.d.ts +0 -6
- package/src/errors/invalid-operator-value-error.d.ts +0 -13
- package/src/errors/not-implemented-error.d.ts +0 -6
- package/src/filter/fields-clause-tool.d.ts +0 -38
- package/src/filter/filter-clause.d.ts +0 -348
- package/src/filter/include-clause-tool.d.ts +0 -55
- package/src/filter/index.d.ts +0 -7
- package/src/filter/operator-clause-tool.d.ts +0 -224
- package/src/filter/order-clause-tool.d.ts +0 -32
- package/src/filter/slice-clause-tool.d.ts +0 -30
- package/src/filter/where-clause-tool.d.ts +0 -23
- package/src/index.d.ts +0 -9
- package/src/relations/belongs-to-resolver.d.ts +0 -46
- package/src/relations/has-many-resolver.d.ts +0 -67
- package/src/relations/has-one-resolver.d.ts +0 -67
- package/src/relations/index.d.ts +0 -4
- package/src/relations/references-many-resolver.d.ts +0 -27
- package/src/repository/index.d.ts +0 -2
- package/src/repository/repository-registry.d.ts +0 -29
- package/src/repository/repository.d.ts +0 -183
- package/src/types.d.ts +0 -43
- package/src/types.js +0 -1
- package/src/utils/capitalize.d.ts +0 -6
- package/src/utils/clone-deep.d.ts +0 -6
- package/src/utils/exclude-object-keys.d.ts +0 -10
- package/src/utils/get-ctor-name.d.ts +0 -6
- package/src/utils/get-ctor-name.js +0 -11
- package/src/utils/get-ctor-name.spec.js +0 -17
- package/src/utils/get-decorator-target-type.d.ts +0 -27
- package/src/utils/get-decorator-target-type.js +0 -63
- package/src/utils/get-decorator-target-type.spec.js +0 -80
- package/src/utils/get-value-by-path.d.ts +0 -12
- package/src/utils/index.d.ts +0 -16
- package/src/utils/is-ctor.d.ts +0 -8
- package/src/utils/is-ctor.js +0 -11
- package/src/utils/is-ctor.spec.js +0 -26
- package/src/utils/is-deep-equal.d.ts +0 -10
- package/src/utils/is-plain-object.d.ts +0 -6
- package/src/utils/is-promise.d.ts +0 -10
- package/src/utils/like-to-regexp.d.ts +0 -14
- package/src/utils/model-name-to-model-key.d.ts +0 -6
- package/src/utils/select-object-keys.d.ts +0 -10
- package/src/utils/singularize.d.ts +0 -6
- package/src/utils/string-to-regexp.d.ts +0 -10
- package/src/utils/transform-promise.d.ts +0 -13
- package/src/utils/transform-promise.js +0 -15
- package/src/utils/transform-promise.spec.js +0 -19
- package/tsconfig.json +0 -11
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import {Service} from '@e22m4u/js-service';
|
|
2
|
-
import {regexpValidator} from './builtin/index.js';
|
|
3
|
-
import {maxLengthValidator} from './builtin/index.js';
|
|
4
|
-
import {minLengthValidator} from './builtin/index.js';
|
|
5
|
-
import {InvalidArgumentError} from '../../../../errors/index.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Property validator registry.
|
|
9
|
-
*/
|
|
10
|
-
export class PropertyValidatorRegistry extends Service {
|
|
11
|
-
/**
|
|
12
|
-
* Validators.
|
|
13
|
-
*
|
|
14
|
-
* @type {object}
|
|
15
|
-
*/
|
|
16
|
-
_validators = {
|
|
17
|
-
maxLength: maxLengthValidator,
|
|
18
|
-
minLength: minLengthValidator,
|
|
19
|
-
regexp: regexpValidator,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Add validator.
|
|
24
|
-
*
|
|
25
|
-
* @param {string} name
|
|
26
|
-
* @param {Function} validator
|
|
27
|
-
* @returns {PropertyValidatorRegistry}
|
|
28
|
-
*/
|
|
29
|
-
addValidator(name, validator) {
|
|
30
|
-
if (!name || typeof name !== 'string')
|
|
31
|
-
throw new InvalidArgumentError(
|
|
32
|
-
'A name of the property validator must ' +
|
|
33
|
-
'be a non-empty String, but %v was given.',
|
|
34
|
-
name,
|
|
35
|
-
);
|
|
36
|
-
if (name in this._validators)
|
|
37
|
-
throw new InvalidArgumentError(
|
|
38
|
-
'The property validator %v is already defined.',
|
|
39
|
-
name,
|
|
40
|
-
);
|
|
41
|
-
if (typeof validator !== 'function')
|
|
42
|
-
throw new InvalidArgumentError(
|
|
43
|
-
'The property validator %v must be a Function, but %v was given.',
|
|
44
|
-
name,
|
|
45
|
-
validator,
|
|
46
|
-
);
|
|
47
|
-
this._validators[name] = validator;
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Has validator.
|
|
53
|
-
*
|
|
54
|
-
* @param {string} name
|
|
55
|
-
* @returns {boolean}
|
|
56
|
-
*/
|
|
57
|
-
hasValidator(name) {
|
|
58
|
-
return Boolean(this._validators[name]);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Get validator.
|
|
63
|
-
*
|
|
64
|
-
* @param {string} name
|
|
65
|
-
* @returns {Function}
|
|
66
|
-
*/
|
|
67
|
-
getValidator(name) {
|
|
68
|
-
const validator = this._validators[name];
|
|
69
|
-
if (!validator)
|
|
70
|
-
throw new InvalidArgumentError(
|
|
71
|
-
'The property validator %v is not defined.',
|
|
72
|
-
name,
|
|
73
|
-
);
|
|
74
|
-
return validator;
|
|
75
|
-
}
|
|
76
|
-
}
|
package/src/definition/model/properties/property-validator/property-validator-registry.spec.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import {expect} from 'chai';
|
|
2
|
-
import {format} from '@e22m4u/js-format';
|
|
3
|
-
import {regexpValidator} from './builtin/index.js';
|
|
4
|
-
import {maxLengthValidator} from './builtin/index.js';
|
|
5
|
-
import {minLengthValidator} from './builtin/index.js';
|
|
6
|
-
import {PropertyValidatorRegistry} from './property-validator-registry.js';
|
|
7
|
-
|
|
8
|
-
describe('PropertyValidatorRegistry', function () {
|
|
9
|
-
it('has builtin validators', function () {
|
|
10
|
-
const pvr = new PropertyValidatorRegistry();
|
|
11
|
-
expect(pvr['_validators']).to.be.eql({
|
|
12
|
-
maxLength: maxLengthValidator,
|
|
13
|
-
minLength: minLengthValidator,
|
|
14
|
-
regexp: regexpValidator,
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe('addValidator', function () {
|
|
19
|
-
it('adds a given validator with the name', function () {
|
|
20
|
-
const pvr = new PropertyValidatorRegistry();
|
|
21
|
-
const myValidator = () => undefined;
|
|
22
|
-
const res = pvr.addValidator('myValidator', myValidator);
|
|
23
|
-
expect(res).to.be.eq(pvr);
|
|
24
|
-
expect(pvr['_validators']['myValidator']).to.be.eq(myValidator);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('requires the given name to be a non-empty string', function () {
|
|
28
|
-
const pvr = new PropertyValidatorRegistry();
|
|
29
|
-
const throwable = v => () => pvr.addValidator(v, () => undefined);
|
|
30
|
-
const error = v =>
|
|
31
|
-
format(
|
|
32
|
-
'A name of the property validator must ' +
|
|
33
|
-
'be a non-empty String, but %s was given.',
|
|
34
|
-
v,
|
|
35
|
-
);
|
|
36
|
-
expect(throwable('')).to.throw(error('""'));
|
|
37
|
-
expect(throwable(10)).to.throw(error('10'));
|
|
38
|
-
expect(throwable(0)).to.throw(error('0'));
|
|
39
|
-
expect(throwable(false)).to.throw(error('false'));
|
|
40
|
-
expect(throwable(undefined)).to.throw(error('undefined'));
|
|
41
|
-
expect(throwable(null)).to.throw(error('null'));
|
|
42
|
-
expect(throwable({})).to.throw(error('Object'));
|
|
43
|
-
expect(throwable([])).to.throw(error('Array'));
|
|
44
|
-
expect(throwable(() => undefined)).to.throw(error('Function'));
|
|
45
|
-
throwable('str')();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('throws an error if the given name already exists', function () {
|
|
49
|
-
const pvr = new PropertyValidatorRegistry();
|
|
50
|
-
pvr.addValidator('test', () => undefined);
|
|
51
|
-
const throwable = () => pvr.addValidator('test', () => undefined);
|
|
52
|
-
expect(throwable).to.throw(
|
|
53
|
-
'The property validator "test" is already defined.',
|
|
54
|
-
);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('requires the given validator to be a function', function () {
|
|
58
|
-
const pvr = new PropertyValidatorRegistry();
|
|
59
|
-
const throwable = v => () => pvr.addValidator('test', v);
|
|
60
|
-
const error = v =>
|
|
61
|
-
format(
|
|
62
|
-
'The property validator "test" must be a Function, but %s was given.',
|
|
63
|
-
v,
|
|
64
|
-
);
|
|
65
|
-
expect(throwable('str')).to.throw(error('"str"'));
|
|
66
|
-
expect(throwable('')).to.throw(error('""'));
|
|
67
|
-
expect(throwable(10)).to.throw(error('10'));
|
|
68
|
-
expect(throwable(0)).to.throw(error('0'));
|
|
69
|
-
expect(throwable(false)).to.throw(error('false'));
|
|
70
|
-
expect(throwable(undefined)).to.throw(error('undefined'));
|
|
71
|
-
expect(throwable(null)).to.throw(error('null'));
|
|
72
|
-
expect(throwable({})).to.throw(error('Object'));
|
|
73
|
-
expect(throwable([])).to.throw(error('Array'));
|
|
74
|
-
throwable(() => undefined)();
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe('hasValidator', function () {
|
|
79
|
-
it('returns false for a not existing name', function () {
|
|
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
|
-
});
|
|
93
|
-
|
|
94
|
-
it('returns true for an existing name', function () {
|
|
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
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe('getValidator', function () {
|
|
103
|
-
it('returns validator by its name', function () {
|
|
104
|
-
const pvr = new PropertyValidatorRegistry();
|
|
105
|
-
const myValidator1 = () => undefined;
|
|
106
|
-
const myValidator2 = () => undefined;
|
|
107
|
-
pvr.addValidator('foo', myValidator1);
|
|
108
|
-
pvr.addValidator('bar', myValidator2);
|
|
109
|
-
const res1 = pvr.getValidator('foo');
|
|
110
|
-
const res2 = pvr.getValidator('bar');
|
|
111
|
-
expect(res1).to.be.eq(myValidator1);
|
|
112
|
-
expect(res2).to.be.eq(myValidator2);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('throws an error for a not existed name', function () {
|
|
116
|
-
const pvr = new PropertyValidatorRegistry();
|
|
117
|
-
const throwable = v => () => pvr.getValidator(v);
|
|
118
|
-
const error = v => format('The property validator %s is not defined.', v);
|
|
119
|
-
expect(throwable('str')).to.throw(error('"str"'));
|
|
120
|
-
expect(throwable('')).to.throw(error('""'));
|
|
121
|
-
expect(throwable(10)).to.throw(error('10'));
|
|
122
|
-
expect(throwable(0)).to.throw(error('0'));
|
|
123
|
-
expect(throwable(true)).to.throw(error('true'));
|
|
124
|
-
expect(throwable(false)).to.throw(error('false'));
|
|
125
|
-
expect(throwable(null)).to.throw(error('null'));
|
|
126
|
-
expect(throwable(undefined)).to.throw(error('undefined'));
|
|
127
|
-
expect(throwable({})).to.throw(error('Object'));
|
|
128
|
-
expect(throwable([])).to.throw(error('Array'));
|
|
129
|
-
expect(throwable(() => undefined)).to.throw(error('Function'));
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Property validator context.
|
|
3
|
-
*/
|
|
4
|
-
export type PropertyValidatorContext = {
|
|
5
|
-
validatorName: string,
|
|
6
|
-
modelName: string,
|
|
7
|
-
propName: string,
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Property validator.
|
|
12
|
-
*/
|
|
13
|
-
export type PropertyValidator = (
|
|
14
|
-
value: unknown,
|
|
15
|
-
options: unknown,
|
|
16
|
-
context: PropertyValidatorContext,
|
|
17
|
-
) => boolean;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Property validate options.
|
|
21
|
-
*/
|
|
22
|
-
export type PropertyValidateOptions =
|
|
23
|
-
| (string | PropertyValidator)
|
|
24
|
-
| (string | PropertyValidator)[]
|
|
25
|
-
| {[key: string]: unknown};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import {RelationType} from './relation-type.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Relation definition.
|
|
5
|
-
*
|
|
6
|
-
* @example Available options.
|
|
7
|
-
* ```ts
|
|
8
|
-
* {
|
|
9
|
-
* type: RelationType;
|
|
10
|
-
* model?: string;
|
|
11
|
-
* foreignKey?: string;
|
|
12
|
-
* polymorphic?: boolean | string;
|
|
13
|
-
* discriminator?: string;
|
|
14
|
-
* }
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export declare type RelationDefinition =
|
|
18
|
-
// belongsTo
|
|
19
|
-
| BelongsToDefinition
|
|
20
|
-
| PolyBelongsToDefinition
|
|
21
|
-
// hasOne
|
|
22
|
-
| HasOneDefinition
|
|
23
|
-
| PolyHasOneDefinitionWithTargetRelationName
|
|
24
|
-
| PolyHasOneDefinitionWithTargetKeys
|
|
25
|
-
// hasMany
|
|
26
|
-
| HasManyDefinition
|
|
27
|
-
| PolyHasManyDefinitionWithTargetRelationName
|
|
28
|
-
| PolyHasManyDefinitionWithTargetKeys
|
|
29
|
-
// referencesMany
|
|
30
|
-
| ReferencesManyDefinition;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* The regular "belongsTo" relation.
|
|
34
|
-
*
|
|
35
|
-
* @example Required options only.
|
|
36
|
-
* ```
|
|
37
|
-
* {
|
|
38
|
-
* type: 'belongsTo',
|
|
39
|
-
* model: 'model',
|
|
40
|
-
* }
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
* @example Verbose definition.
|
|
44
|
-
* ```
|
|
45
|
-
* {
|
|
46
|
-
* type: 'belongsTo',
|
|
47
|
-
* model: 'model',
|
|
48
|
-
* foreignKey: 'modelId',
|
|
49
|
-
* }
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
export declare type BelongsToDefinition = {
|
|
53
|
-
type: typeof RelationType.BELONGS_TO;
|
|
54
|
-
polymorphic?: false;
|
|
55
|
-
model: string;
|
|
56
|
-
foreignKey?: string;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* The polymorphic "belongsTo" relation.
|
|
61
|
-
*
|
|
62
|
-
* @example Required fields only.
|
|
63
|
-
* ```
|
|
64
|
-
* {
|
|
65
|
-
* type: 'belongsTo',
|
|
66
|
-
* polymorphic: true,
|
|
67
|
-
* }
|
|
68
|
-
* ```
|
|
69
|
-
*
|
|
70
|
-
* @example Verbose definition.
|
|
71
|
-
* ```
|
|
72
|
-
* {
|
|
73
|
-
* type: 'belongsTo',
|
|
74
|
-
* polymorphic: true,
|
|
75
|
-
* foreignKey: 'referenceId',
|
|
76
|
-
* discriminator: 'referenceType',
|
|
77
|
-
* }
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
export declare type PolyBelongsToDefinition = {
|
|
81
|
-
type: typeof RelationType.BELONGS_TO;
|
|
82
|
-
polymorphic: true;
|
|
83
|
-
foreignKey?: string;
|
|
84
|
-
discriminator?: string;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* The regular "hasOne" relation.
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```ts
|
|
92
|
-
* {
|
|
93
|
-
* type: 'hasOne',
|
|
94
|
-
* model: 'model',
|
|
95
|
-
* foreignKey: 'modelId',
|
|
96
|
-
* }
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
export declare type HasOneDefinition = {
|
|
100
|
-
type: typeof RelationType.HAS_ONE;
|
|
101
|
-
model: string;
|
|
102
|
-
foreignKey: string;
|
|
103
|
-
polymorphic?: false;
|
|
104
|
-
discriminator?: undefined;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* The polymorphic "hasOne" relation with a target relation name.
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* ```ts
|
|
112
|
-
* {
|
|
113
|
-
* type: 'hasOne',
|
|
114
|
-
* model: 'model',
|
|
115
|
-
* polymorphic: 'reference',
|
|
116
|
-
* }
|
|
117
|
-
* ```
|
|
118
|
-
*/
|
|
119
|
-
export declare type PolyHasOneDefinitionWithTargetRelationName = {
|
|
120
|
-
type: typeof RelationType.HAS_ONE;
|
|
121
|
-
model: string;
|
|
122
|
-
polymorphic: string;
|
|
123
|
-
foreignKey?: undefined;
|
|
124
|
-
discriminator?: undefined;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* The polymorphic "hasOne" relation with target relation keys.
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* ```
|
|
132
|
-
* {
|
|
133
|
-
* type: 'hasOne',
|
|
134
|
-
* model: 'model',
|
|
135
|
-
* polymorphic: true,
|
|
136
|
-
* foreignKey: 'referenceId',
|
|
137
|
-
* discriminator: 'referenceType',
|
|
138
|
-
* }
|
|
139
|
-
* ```
|
|
140
|
-
*/
|
|
141
|
-
export declare type PolyHasOneDefinitionWithTargetKeys = {
|
|
142
|
-
type: typeof RelationType.HAS_ONE;
|
|
143
|
-
model: string;
|
|
144
|
-
polymorphic: true;
|
|
145
|
-
foreignKey: string;
|
|
146
|
-
discriminator: string;
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* The regular "hasMany" relation.
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* ```ts
|
|
154
|
-
* {
|
|
155
|
-
* type: 'hasMany',
|
|
156
|
-
* model: 'model',
|
|
157
|
-
* foreignKey: 'modelId',
|
|
158
|
-
* }
|
|
159
|
-
* ```
|
|
160
|
-
*/
|
|
161
|
-
export declare type HasManyDefinition = {
|
|
162
|
-
type: typeof RelationType.HAS_MANY;
|
|
163
|
-
model: string;
|
|
164
|
-
foreignKey: string;
|
|
165
|
-
polymorphic?: false;
|
|
166
|
-
discriminator?: undefined;
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* The polymorphic "hasMany" relation with a target relation name.
|
|
171
|
-
*
|
|
172
|
-
* @example
|
|
173
|
-
* ```ts
|
|
174
|
-
* {
|
|
175
|
-
* type: 'hasMany',
|
|
176
|
-
* model: 'model',
|
|
177
|
-
* polymorphic: 'reference',
|
|
178
|
-
* }
|
|
179
|
-
* ```
|
|
180
|
-
*/
|
|
181
|
-
export declare type PolyHasManyDefinitionWithTargetRelationName = {
|
|
182
|
-
type: typeof RelationType.HAS_MANY;
|
|
183
|
-
model: string;
|
|
184
|
-
polymorphic: string;
|
|
185
|
-
foreignKey?: undefined;
|
|
186
|
-
discriminator?: undefined;
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* The polymorphic "hasMany" relation with target relation keys.
|
|
191
|
-
*
|
|
192
|
-
* @example
|
|
193
|
-
* ```
|
|
194
|
-
* {
|
|
195
|
-
* type: 'hasMany',
|
|
196
|
-
* model: 'model',
|
|
197
|
-
* polymorphic: true,
|
|
198
|
-
* foreignKey: 'referenceId',
|
|
199
|
-
* discriminator: 'referenceType',
|
|
200
|
-
* }
|
|
201
|
-
* ```
|
|
202
|
-
*/
|
|
203
|
-
export declare type PolyHasManyDefinitionWithTargetKeys = {
|
|
204
|
-
type: typeof RelationType.HAS_MANY;
|
|
205
|
-
model: string;
|
|
206
|
-
polymorphic: true;
|
|
207
|
-
foreignKey: string;
|
|
208
|
-
discriminator: string;
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* The regular "referencesMany" relation.
|
|
213
|
-
*
|
|
214
|
-
* @example Required options only.
|
|
215
|
-
* ```
|
|
216
|
-
* {
|
|
217
|
-
* type: 'referencesMany',
|
|
218
|
-
* model: 'model',
|
|
219
|
-
* }
|
|
220
|
-
* ```
|
|
221
|
-
*
|
|
222
|
-
* @example Verbose definition.
|
|
223
|
-
* ```
|
|
224
|
-
* {
|
|
225
|
-
* type: 'referencesMany',
|
|
226
|
-
* model: 'model',
|
|
227
|
-
* foreignKey: 'modelIds',
|
|
228
|
-
* }
|
|
229
|
-
* ```
|
|
230
|
-
*/
|
|
231
|
-
export declare type ReferencesManyDefinition = {
|
|
232
|
-
type: typeof RelationType.REFERENCES_MANY;
|
|
233
|
-
model: string;
|
|
234
|
-
foreignKey?: string;
|
|
235
|
-
discriminator?: undefined;
|
|
236
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Relation type.
|
|
3
|
-
*/
|
|
4
|
-
export declare const RelationType: {
|
|
5
|
-
BELONGS_TO: 'belongsTo';
|
|
6
|
-
HAS_ONE: 'hasOne';
|
|
7
|
-
HAS_MANY: 'hasMany';
|
|
8
|
-
REFERENCES_MANY: 'referencesMany';
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Type of RelationType.
|
|
13
|
-
*/
|
|
14
|
-
export type RelationType = (typeof RelationType)[keyof typeof RelationType];
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import {Service} from '@e22m4u/js-service';
|
|
2
|
-
import {RelationDefinitionMap} from '../model-definition.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Relations definition validator.
|
|
6
|
-
*/
|
|
7
|
-
export declare class RelationsDefinitionValidator extends Service {
|
|
8
|
-
/**
|
|
9
|
-
* Validate.
|
|
10
|
-
*
|
|
11
|
-
* @param modelName
|
|
12
|
-
* @param relDefs
|
|
13
|
-
*/
|
|
14
|
-
validate(modelName: string, relDefs: RelationDefinitionMap): void;
|
|
15
|
-
}
|
package/src/errors/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Invalid operator value error.
|
|
3
|
-
*/
|
|
4
|
-
export declare class InvalidOperatorValueError extends Error {
|
|
5
|
-
/**
|
|
6
|
-
* Constructor.
|
|
7
|
-
*
|
|
8
|
-
* @param operator
|
|
9
|
-
* @param expects
|
|
10
|
-
* @param value
|
|
11
|
-
*/
|
|
12
|
-
constructor(operator: string, expects: string, value: unknown);
|
|
13
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import {ModelData} from '../types.js';
|
|
2
|
-
import {Service} from '@e22m4u/js-service';
|
|
3
|
-
import {FieldsClause} from './filter-clause.js';
|
|
4
|
-
import {NormalizedFieldsClause} from './filter-clause.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Field clause tool.
|
|
8
|
-
*/
|
|
9
|
-
export declare class FieldsClauseTool extends Service {
|
|
10
|
-
/**
|
|
11
|
-
* Filter.
|
|
12
|
-
*
|
|
13
|
-
* @param input
|
|
14
|
-
* @param modelName
|
|
15
|
-
* @param clause
|
|
16
|
-
*/
|
|
17
|
-
filter<T extends ModelData | ModelData[]>(
|
|
18
|
-
input: T,
|
|
19
|
-
modelName: string,
|
|
20
|
-
clause: FieldsClause | undefined,
|
|
21
|
-
): T;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Validate fields clause.
|
|
25
|
-
*
|
|
26
|
-
* @param clause
|
|
27
|
-
*/
|
|
28
|
-
static validateFieldsClause(clause: FieldsClause | undefined): void;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Normalize fields clause.
|
|
32
|
-
*
|
|
33
|
-
* @param clause
|
|
34
|
-
*/
|
|
35
|
-
static normalizeFieldsClause(
|
|
36
|
-
clause: FieldsClause | undefined,
|
|
37
|
-
): NormalizedFieldsClause | undefined;
|
|
38
|
-
}
|