@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.
Files changed (44) hide show
  1. package/README.md +79 -80
  2. package/dist/cjs/index.cjs +2023 -2093
  3. package/eslint.config.js +1 -1
  4. package/package.json +15 -12
  5. package/src/adapter/adapter-registry.spec.js +7 -7
  6. package/src/adapter/adapter.spec.js +11 -11
  7. package/src/adapter/builtin/memory-adapter.spec.js +537 -537
  8. package/src/adapter/decorator/data-sanitizing-decorator.spec.js +5 -5
  9. package/src/adapter/decorator/data-transformation-decorator.spec.js +5 -5
  10. package/src/adapter/decorator/data-validation-decorator.spec.js +5 -5
  11. package/src/adapter/decorator/default-values-decorator.spec.js +5 -5
  12. package/src/adapter/decorator/fields-filtering-decorator.spec.js +5 -5
  13. package/src/adapter/decorator/inclusion-decorator.spec.js +5 -5
  14. package/src/adapter/decorator/property-uniqueness-decorator.spec.js +5 -5
  15. package/src/{schema.d.ts → database-schema.d.ts} +2 -2
  16. package/src/{schema.js → database-schema.js} +2 -2
  17. package/src/database-schema.spec.ts +86 -0
  18. package/src/definition/model/model-data-transformer.js +3 -3
  19. package/src/definition/model/model-data-transformer.spec.js +93 -93
  20. package/src/definition/model/model-data-validator.js +2 -2
  21. package/src/definition/model/model-data-validator.spec.js +517 -531
  22. package/src/definition/model/model-definition-utils.js +3 -3
  23. package/src/definition/model/model-definition-utils.spec.js +345 -343
  24. package/src/definition/model/properties/index.d.ts +0 -1
  25. package/src/definition/model/properties/index.js +0 -1
  26. package/src/definition/model/properties/property-transformer/property-transformer-registry.spec.js +36 -36
  27. package/src/definition/model/properties/property-uniqueness-validator.js +3 -3
  28. package/src/definition/model/properties/property-uniqueness-validator.spec.js +417 -384
  29. package/src/definition/model/properties/property-validator/property-validator-registry.spec.js +36 -36
  30. package/src/filter/fields-clause-tool.spec.js +4 -4
  31. package/src/index.d.ts +1 -1
  32. package/src/index.js +1 -1
  33. package/src/relations/belongs-to-resolver.spec.js +166 -166
  34. package/src/relations/has-many-resolver.spec.js +281 -281
  35. package/src/relations/has-one-resolver.spec.js +281 -281
  36. package/src/relations/references-many-resolver.spec.js +92 -92
  37. package/src/repository/repository-registry.spec.js +10 -10
  38. package/src/repository/repository.spec.js +73 -73
  39. package/src/utils/is-promise.spec.js +1 -2
  40. package/src/utils/transform-promise.spec.js +0 -1
  41. package/src/definition/model/properties/empty-values-definer.d.ts +0 -23
  42. package/src/definition/model/properties/empty-values-definer.js +0 -66
  43. package/src/definition/model/properties/empty-values-definer.spec.js +0 -96
  44. package/src/schema.spec.ts +0 -86
@@ -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 S = new PropertyValidatorRegistry();
11
- expect(S['_validators']).to.be.eql({
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 S = new PropertyValidatorRegistry();
20
+ const pvr = new PropertyValidatorRegistry();
21
21
  const myValidator = () => undefined;
22
- const res = S.addValidator('myValidator', myValidator);
23
- expect(res).to.be.eq(S);
24
- expect(S['_validators']['myValidator']).to.be.eq(myValidator);
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 S = new PropertyValidatorRegistry();
29
- const throwable = v => () => S.addValidator(v, () => undefined);
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 S = new PropertyValidatorRegistry();
50
- S.addValidator('test', () => undefined);
51
- const throwable = () => S.addValidator('test', () => undefined);
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 S = new PropertyValidatorRegistry();
59
- const throwable = v => () => S.addValidator('test', 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 S = new PropertyValidatorRegistry();
81
- expect(S.hasValidator('str')).to.be.false;
82
- expect(S.hasValidator('')).to.be.false;
83
- expect(S.hasValidator(10)).to.be.false;
84
- expect(S.hasValidator(0)).to.be.false;
85
- expect(S.hasValidator(true)).to.be.false;
86
- expect(S.hasValidator(false)).to.be.false;
87
- expect(S.hasValidator(null)).to.be.false;
88
- expect(S.hasValidator(undefined)).to.be.false;
89
- expect(S.hasValidator({})).to.be.false;
90
- expect(S.hasValidator([])).to.be.false;
91
- expect(S.hasValidator(() => undefined)).to.be.false;
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 S = new PropertyValidatorRegistry();
96
- expect(S.hasValidator('test')).to.be.false;
97
- S.addValidator('test', () => undefined);
98
- expect(S.hasValidator('test')).to.be.true;
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 S = new PropertyValidatorRegistry();
104
+ const pvr = new PropertyValidatorRegistry();
105
105
  const myValidator1 = () => undefined;
106
106
  const myValidator2 = () => undefined;
107
- S.addValidator('foo', myValidator1);
108
- S.addValidator('bar', myValidator2);
109
- const res1 = S.getValidator('foo');
110
- const res2 = S.getValidator('bar');
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 S = new PropertyValidatorRegistry();
117
- const throwable = v => () => S.getValidator(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 S = new Schema();
7
+ const dbs = new DatabaseSchema();
8
8
  const MODEL_NAME = 'model';
9
- S.defineModel({name: MODEL_NAME});
10
- const T = S.getService(FieldsClauseTool);
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';