@e22m4u/js-repository 0.7.0 → 0.8.1

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,5 +1,4 @@
1
1
  {
2
- "extension": ["js", "ts"],
3
- "spec": "src/**/*.spec.{js,ts}",
4
- "require": ["ts-node/register"]
2
+ "extension": ["js"],
3
+ "spec": "src/**/*.spec.js"
5
4
  }
@@ -1225,7 +1225,6 @@ var init_relations_definition_validator = __esm({
1225
1225
  "use strict";
1226
1226
  import_js_service5 = require("@e22m4u/js-service");
1227
1227
  init_relation_type();
1228
- init_relation_type();
1229
1228
  init_errors();
1230
1229
  _RelationsDefinitionValidator = class _RelationsDefinitionValidator extends import_js_service5.Service {
1231
1230
  /**
@@ -1765,11 +1764,10 @@ var init_model_definition_utils = __esm({
1765
1764
  "use strict";
1766
1765
  import_js_service7 = require("@e22m4u/js-service");
1767
1766
  init_properties();
1768
- init_utils();
1769
- init_utils();
1770
1767
  import_js_empty_values = require("@e22m4u/js-empty-values");
1771
1768
  init_errors();
1772
1769
  init_definition_registry();
1770
+ init_utils();
1773
1771
  DEFAULT_PRIMARY_KEY_PROPERTY_NAME = "id";
1774
1772
  _ModelDefinitionUtils = class _ModelDefinitionUtils extends import_js_service7.Service {
1775
1773
  /**
@@ -3251,10 +3249,6 @@ var init_adapter = __esm({
3251
3249
  import_js_service20 = require("@e22m4u/js-service");
3252
3250
  init_errors();
3253
3251
  init_decorator();
3254
- init_decorator();
3255
- init_decorator();
3256
- init_decorator();
3257
- init_decorator();
3258
3252
  ADAPTER_CLASS_NAME = "Adapter";
3259
3253
  _Adapter = class _Adapter extends import_js_service20.Service {
3260
3254
  /**
@@ -3461,14 +3455,10 @@ var init_memory_adapter = __esm({
3461
3455
  "src/adapter/builtin/memory-adapter.js"() {
3462
3456
  "use strict";
3463
3457
  init_adapter();
3464
- init_utils();
3458
+ init_errors();
3465
3459
  init_utils();
3466
3460
  init_definition();
3467
3461
  init_filter();
3468
- init_filter();
3469
- init_filter();
3470
- init_errors();
3471
- init_definition();
3472
3462
  _MemoryAdapter = class _MemoryAdapter extends Adapter {
3473
3463
  /**
3474
3464
  * Tables.
@@ -3880,10 +3870,9 @@ var import_js_service21, _AdapterLoader, AdapterLoader;
3880
3870
  var init_adapter_loader = __esm({
3881
3871
  "src/adapter/adapter-loader.js"() {
3882
3872
  "use strict";
3883
- init_adapter();
3884
3873
  import_js_service21 = require("@e22m4u/js-service");
3885
- init_adapter();
3886
3874
  init_errors();
3875
+ init_adapter();
3887
3876
  init_();
3888
3877
  _AdapterLoader = class _AdapterLoader extends import_js_service21.Service {
3889
3878
  /**
@@ -3903,13 +3892,13 @@ var init_adapter_loader = __esm({
3903
3892
  try {
3904
3893
  const module2 = await globImport_builtin_adapter_js(`./builtin/${adapterName}-adapter.js`);
3905
3894
  adapterCtor = findAdapterCtorInModule(module2);
3906
- } catch (e) {
3895
+ } catch {
3907
3896
  }
3908
3897
  if (!adapterCtor)
3909
3898
  try {
3910
3899
  const module2 = await Promise.resolve().then(() => __toESM(require(`@e22m4u/js-repository-${adapterName}-adapter`)));
3911
3900
  adapterCtor = findAdapterCtorInModule(module2);
3912
- } catch (e) {
3901
+ } catch {
3913
3902
  }
3914
3903
  if (!adapterCtor)
3915
3904
  throw new InvalidArgumentError(
@@ -3981,10 +3970,9 @@ var init_repository = __esm({
3981
3970
  "src/repository/repository.js"() {
3982
3971
  "use strict";
3983
3972
  import_js_service23 = require("@e22m4u/js-service");
3984
- init_adapter2();
3985
- init_adapter2();
3986
3973
  init_errors();
3987
3974
  init_definition();
3975
+ init_adapter2();
3988
3976
  _Repository = class _Repository extends import_js_service23.Service {
3989
3977
  /**
3990
3978
  * Model name.
@@ -4251,7 +4239,6 @@ var init_has_one_resolver = __esm({
4251
4239
  "use strict";
4252
4240
  import_js_service25 = require("@e22m4u/js-service");
4253
4241
  init_utils();
4254
- init_definition();
4255
4242
  init_errors();
4256
4243
  init_repository2();
4257
4244
  init_definition();
@@ -4506,7 +4493,6 @@ var init_has_many_resolver = __esm({
4506
4493
  "use strict";
4507
4494
  import_js_service26 = require("@e22m4u/js-service");
4508
4495
  init_utils();
4509
- init_definition();
4510
4496
  init_errors();
4511
4497
  init_repository2();
4512
4498
  init_definition();
@@ -4770,9 +4756,8 @@ var init_belongs_to_resolver = __esm({
4770
4756
  "src/relations/belongs-to-resolver.js"() {
4771
4757
  "use strict";
4772
4758
  import_js_service27 = require("@e22m4u/js-service");
4773
- init_utils();
4774
- init_utils();
4775
4759
  init_errors();
4760
+ init_utils();
4776
4761
  init_repository2();
4777
4762
  init_definition();
4778
4763
  _BelongsToResolver = class _BelongsToResolver extends import_js_service27.Service {
@@ -4978,9 +4963,8 @@ var init_references_many_resolver = __esm({
4978
4963
  "src/relations/references-many-resolver.js"() {
4979
4964
  "use strict";
4980
4965
  import_js_service28 = require("@e22m4u/js-service");
4981
- init_utils();
4982
- init_utils();
4983
4966
  init_errors();
4967
+ init_utils();
4984
4968
  init_repository2();
4985
4969
  init_definition();
4986
4970
  _ReferencesManyResolver = class _ReferencesManyResolver extends import_js_service28.Service {
@@ -5090,14 +5074,10 @@ var init_include_clause_tool = __esm({
5090
5074
  "src/filter/include-clause-tool.js"() {
5091
5075
  "use strict";
5092
5076
  import_js_service29 = require("@e22m4u/js-service");
5093
- init_definition();
5094
- init_relations2();
5095
- init_relations2();
5096
5077
  init_where_clause_tool();
5097
5078
  init_order_clause_tool();
5098
5079
  init_slice_clause_tool();
5099
5080
  init_errors();
5100
- init_relations2();
5101
5081
  init_fields_clause_tool();
5102
5082
  init_definition();
5103
5083
  init_relations2();
@@ -5494,7 +5474,6 @@ init_adapter2();
5494
5474
 
5495
5475
  // src/database-schema.js
5496
5476
  var import_js_service30 = require("@e22m4u/js-service");
5497
- init_repository2();
5498
5477
  init_definition();
5499
5478
  init_repository2();
5500
5479
  var _DatabaseSchema = class _DatabaseSchema extends import_js_service30.Service {
package/eslint.config.js CHANGED
@@ -1,68 +1,40 @@
1
1
  import globals from 'globals';
2
2
  import eslintJs from '@eslint/js';
3
- import eslintTypescript from 'typescript-eslint';
4
3
  import eslintJsdocPlugin from 'eslint-plugin-jsdoc';
5
4
  import eslintMochaPlugin from 'eslint-plugin-mocha';
5
+ import eslintImportPlugin from 'eslint-plugin-import';
6
6
  import eslintPrettierConfig from 'eslint-config-prettier';
7
7
  import eslintChaiExpectPlugin from 'eslint-plugin-chai-expect';
8
8
 
9
- export default [
10
- {
11
- files: ['src/**/*.js'],
12
- languageOptions: {
13
- globals: {
14
- ...globals.node,
15
- ...globals.es2021,
16
- ...globals.mocha,
17
- },
18
- },
19
- plugins: {
20
- 'jsdoc': eslintJsdocPlugin,
21
- 'mocha': eslintMochaPlugin,
22
- 'chai-expect': eslintChaiExpectPlugin,
23
- },
24
- rules: {
25
- ...eslintJs.configs.recommended.rules,
26
- ...eslintPrettierConfig.rules,
27
- ...eslintMochaPlugin.configs.recommended.rules,
28
- ...eslintChaiExpectPlugin.configs['recommended-flat'].rules,
29
- ...eslintJsdocPlugin.configs['flat/recommended-error'].rules,
30
- 'no-unused-vars': ['error', {'caughtErrors': 'none'}],
31
- 'jsdoc/reject-any-type': 0,
32
- 'jsdoc/reject-function-type': 0,
33
- 'jsdoc/require-param-description': 0,
34
- 'jsdoc/require-returns-description': 0,
35
- 'jsdoc/require-property-description': 0,
36
- 'jsdoc/tag-lines': ['error', 'any', {startLines: 1}],
9
+ export default [{
10
+ files: ['src/**/*.js'],
11
+ languageOptions: {
12
+ globals: {
13
+ ...globals.node,
14
+ ...globals.es2021,
15
+ ...globals.mocha,
37
16
  },
38
17
  },
39
- {
40
- files: ['src/**/*.ts'],
41
- ignores: ['src/**/*.d.ts'],
42
- languageOptions: {
43
- globals: {
44
- ...globals.node,
45
- ...globals.es2021,
46
- ...globals.mocha,
47
- },
48
- parser: eslintTypescript.parser,
49
- parserOptions: {
50
- projectService: true,
51
- tsconfigRootDir: import.meta.dirname,
52
- },
53
- },
54
- plugins: {
55
- '@typescript-eslint': eslintTypescript.plugin,
56
- 'mocha': eslintMochaPlugin,
57
- 'chai-expect': eslintChaiExpectPlugin,
58
- },
59
- rules: {
60
- ...eslintJs.configs.recommended.rules,
61
- ...eslintPrettierConfig.rules,
62
- ...eslintTypescript.configs.recommended.rules,
63
- '@typescript-eslint/no-namespace': 0,
64
- '@typescript-eslint/no-var-requires': 0,
65
- '@typescript-eslint/no-unnecessary-type-constraint': 0,
66
- },
18
+ plugins: {
19
+ 'jsdoc': eslintJsdocPlugin,
20
+ 'mocha': eslintMochaPlugin,
21
+ 'import': eslintImportPlugin,
22
+ 'chai-expect': eslintChaiExpectPlugin,
23
+ },
24
+ rules: {
25
+ ...eslintJs.configs.recommended.rules,
26
+ ...eslintPrettierConfig.rules,
27
+ ...eslintImportPlugin.flatConfigs.recommended.rules,
28
+ ...eslintMochaPlugin.configs.recommended.rules,
29
+ ...eslintChaiExpectPlugin.configs['recommended-flat'].rules,
30
+ ...eslintJsdocPlugin.configs['flat/recommended-error'].rules,
31
+ 'no-duplicate-imports': 'error',
32
+ 'import/export': 0,
33
+ 'jsdoc/reject-any-type': 0,
34
+ 'jsdoc/reject-function-type': 0,
35
+ 'jsdoc/require-param-description': 0,
36
+ 'jsdoc/require-returns-description': 0,
37
+ 'jsdoc/require-property-description': 0,
38
+ 'jsdoc/tag-lines': ['error', 'any', {startLines: 1}],
67
39
  },
68
- ];
40
+ }];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e22m4u/js-repository",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "description": "Реализация репозитория для работы с базами данных",
5
5
  "author": "Mikhail Evstropov <e22m4u@yandex.ru>",
6
6
  "license": "MIT",
@@ -12,10 +12,10 @@
12
12
  "Datasource",
13
13
  "Relations"
14
14
  ],
15
- "homepage": "https://github.com/e22m4u/js-repository",
15
+ "homepage": "https://gitrepos.ru/e22m4u/js-repository",
16
16
  "repository": {
17
17
  "type": "git",
18
- "url": "git+https://github.com/e22m4u/js-repository.git"
18
+ "url": "git+https://gitrepos.ru/e22m4u/js-repository.git"
19
19
  },
20
20
  "type": "module",
21
21
  "types": "./src/index.d.ts",
@@ -35,13 +35,13 @@
35
35
  "format": "prettier --write \"./src/**/*.js\"",
36
36
  "test": "npm run lint && c8 --reporter=text-summary mocha --bail",
37
37
  "test:coverage": "npm run lint && c8 --reporter=text mocha --bail",
38
- "build:cjs": "rimraf ./dist/cjs && node --no-warnings=ExperimentalWarning build-cjs.js",
38
+ "build:cjs": "rimraf ./dist/cjs && node build-cjs.js",
39
39
  "prepare": "husky"
40
40
  },
41
41
  "dependencies": {
42
- "@e22m4u/js-empty-values": "~0.1.3",
43
- "@e22m4u/js-format": "~0.2.1",
44
- "@e22m4u/js-service": "~0.4.6"
42
+ "@e22m4u/js-empty-values": "~0.2.1",
43
+ "@e22m4u/js-format": "~0.3.1",
44
+ "@e22m4u/js-service": "~0.5.1"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@commitlint/cli": "~20.1.0",
@@ -58,14 +58,13 @@
58
58
  "eslint": "~9.39.1",
59
59
  "eslint-config-prettier": "~10.1.8",
60
60
  "eslint-plugin-chai-expect": "~3.1.0",
61
+ "eslint-plugin-import": "~2.32.0",
61
62
  "eslint-plugin-jsdoc": "~61.4.1",
62
63
  "eslint-plugin-mocha": "~11.2.0",
63
64
  "husky": "~9.1.7",
64
65
  "mocha": "~11.7.5",
65
- "prettier": "~3.6.2",
66
+ "prettier": "~3.7.4",
66
67
  "rimraf": "~6.1.2",
67
- "ts-node": "~10.9.2",
68
- "typescript": "~5.9.3",
69
- "typescript-eslint": "~8.48.0"
68
+ "typescript": "~5.9.3"
70
69
  }
71
70
  }
@@ -1,7 +1,6 @@
1
- import {Adapter} from './adapter.js';
2
1
  import {Service} from '@e22m4u/js-service';
3
- import {ADAPTER_CLASS_NAME} from './adapter.js';
4
2
  import {InvalidArgumentError} from '../errors/index.js';
3
+ import {Adapter, ADAPTER_CLASS_NAME} from './adapter.js';
5
4
 
6
5
  /**
7
6
  * Adapter loader.
@@ -24,7 +23,7 @@ export class AdapterLoader extends Service {
24
23
  try {
25
24
  const module = await import(`./builtin/${adapterName}-adapter.js`);
26
25
  adapterCtor = findAdapterCtorInModule(module);
27
- } catch (e) {
26
+ } catch {
28
27
  /**/
29
28
  }
30
29
  if (!adapterCtor)
@@ -33,7 +32,7 @@ export class AdapterLoader extends Service {
33
32
  `@e22m4u/js-repository-${adapterName}-adapter`
34
33
  );
35
34
  adapterCtor = findAdapterCtorInModule(module);
36
- } catch (e) {
35
+ } catch {
37
36
  /**/
38
37
  }
39
38
  if (!adapterCtor)
@@ -2,11 +2,14 @@
2
2
  /* eslint jsdoc/require-returns-check: 0 */
3
3
  import {Service} from '@e22m4u/js-service';
4
4
  import {NotImplementedError} from '../errors/index.js';
5
- import {InclusionDecorator} from './decorator/index.js';
6
- import {DefaultValuesDecorator} from './decorator/index.js';
7
- import {DataSanitizingDecorator} from './decorator/index.js';
8
- import {FieldsFilteringDecorator} from './decorator/index.js';
9
- import {PropertyUniquenessDecorator} from './decorator/index.js';
5
+
6
+ import {
7
+ InclusionDecorator,
8
+ DefaultValuesDecorator,
9
+ DataSanitizingDecorator,
10
+ FieldsFilteringDecorator,
11
+ PropertyUniquenessDecorator,
12
+ } from './decorator/index.js';
10
13
 
11
14
  /**
12
15
  * Adapter class name.
@@ -1,15 +1,16 @@
1
1
  import {expect} from 'chai';
2
2
  import {chai} from '../chai.js';
3
- import {Adapter} from './adapter.js';
4
- import {Service} from '@e22m4u/js-service';
5
- import {ADAPTER_CLASS_NAME} from './adapter.js';
6
- import {ServiceContainer} from '@e22m4u/js-service';
7
3
  import {DatabaseSchema} from '../database-schema.js';
8
- import {InclusionDecorator} from './decorator/index.js';
9
- import {DefaultValuesDecorator} from './decorator/index.js';
10
- import {DataSanitizingDecorator} from './decorator/index.js';
11
- import {FieldsFilteringDecorator} from './decorator/index.js';
12
- import {PropertyUniquenessDecorator} from './decorator/index.js';
4
+ import {Adapter, ADAPTER_CLASS_NAME} from './adapter.js';
5
+ import {Service, ServiceContainer} from '@e22m4u/js-service';
6
+
7
+ import {
8
+ InclusionDecorator,
9
+ DefaultValuesDecorator,
10
+ DataSanitizingDecorator,
11
+ FieldsFilteringDecorator,
12
+ PropertyUniquenessDecorator,
13
+ } from './decorator/index.js';
13
14
 
14
15
  const sandbox = chai.spy.sandbox();
15
16
 
@@ -1,12 +1,13 @@
1
1
  import {Adapter} from '../adapter.js';
2
- import {cloneDeep} from '../../utils/index.js';
3
- import {capitalize} from '../../utils/index.js';
4
- import {DataType} from '../../definition/index.js';
5
- import {SliceClauseTool} from '../../filter/index.js';
6
- import {WhereClauseTool} from '../../filter/index.js';
7
- import {OrderClauseTool} from '../../filter/index.js';
8
2
  import {InvalidArgumentError} from '../../errors/index.js';
9
- import {ModelDefinitionUtils} from '../../definition/index.js';
3
+ import {cloneDeep, capitalize} from '../../utils/index.js';
4
+ import {DataType, ModelDefinitionUtils} from '../../definition/index.js';
5
+
6
+ import {
7
+ SliceClauseTool,
8
+ WhereClauseTool,
9
+ OrderClauseTool,
10
+ } from '../../filter/index.js';
10
11
 
11
12
  /**
12
13
  * Memory adapter.
@@ -1,9 +1,12 @@
1
1
  import {expect} from 'chai';
2
2
  import {format} from '@e22m4u/js-format';
3
3
  import {MemoryAdapter} from './memory-adapter.js';
4
- import {DataType} from '../../definition/index.js';
5
4
  import {DatabaseSchema} from '../../database-schema.js';
6
- import {DEFAULT_PRIMARY_KEY_PROPERTY_NAME as DEF_PK} from '../../definition/index.js';
5
+
6
+ import {
7
+ DataType,
8
+ DEFAULT_PRIMARY_KEY_PROPERTY_NAME as DEF_PK,
9
+ } from '../../definition/index.js';
7
10
 
8
11
  describe('MemoryAdapter', function () {
9
12
  describe('_getTableOrCreate', function () {
@@ -1,9 +1,8 @@
1
1
  import {expect} from 'chai';
2
2
  import {chai} from '../../chai.js';
3
3
  import {Adapter} from '../adapter.js';
4
- import {DataType} from '../../definition/index.js';
5
4
  import {DatabaseSchema} from '../../database-schema.js';
6
- import {ModelDefinitionUtils} from '../../definition/index.js';
5
+ import {DataType, ModelDefinitionUtils} from '../../definition/index.js';
7
6
 
8
7
  const dbs = new DatabaseSchema();
9
8
  dbs.defineModel({
@@ -1,7 +1,6 @@
1
1
  import {Service} from '@e22m4u/js-service';
2
- import {Repository} from './repository/index.js';
3
2
  import {DefinitionRegistry} from './definition/index.js';
4
- import {RepositoryRegistry} from './repository/index.js';
3
+ import {Repository, RepositoryRegistry} from './repository/index.js';
5
4
 
6
5
  /**
7
6
  * Database schema.
@@ -17,16 +17,17 @@ describe('DatabaseSchema', function () {
17
17
  it('sets the datasource definition', function () {
18
18
  const dbs = new DatabaseSchema();
19
19
  dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
20
- const res =
21
- dbs.getService(DefinitionRegistry).getDatasource('datasource');
20
+ const res = dbs
21
+ .getService(DefinitionRegistry)
22
+ .getDatasource('datasource');
22
23
  expect(res).to.be.eql({name: 'datasource', adapter: 'memory'});
23
24
  });
24
25
 
25
26
  it('throws an error if the datasource name already defined', function () {
26
27
  const dbs = new DatabaseSchema();
27
28
  dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
28
- const throwable =
29
- () => dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
29
+ const throwable = () =>
30
+ dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
30
31
  expect(throwable).to.throw(
31
32
  'The datasource "datasource" is already defined.',
32
33
  );
@@ -69,18 +70,5 @@ describe('DatabaseSchema', function () {
69
70
  const throwable = () => dbs.getRepository('model');
70
71
  expect(throwable).to.throw('The model "model" is not defined.');
71
72
  });
72
-
73
- it('uses generic types to define the repository type', function () {
74
- const dbs = new DatabaseSchema();
75
- dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
76
- dbs.defineModel({name: 'model', datasource: 'datasource'});
77
- interface MyModel {
78
- myId: number;
79
- }
80
- const res1: Repository = dbs.getRepository('model');
81
- const res2: Repository<MyModel, number, 'myId'> =
82
- dbs.getRepository<MyModel, number, 'myId'>('model');
83
- expect(res1).to.be.eq(res2);
84
- });
85
73
  });
86
74
  });
@@ -1,10 +1,9 @@
1
1
  import {Service} from '@e22m4u/js-service';
2
2
  import {DataType} from './properties/index.js';
3
- import {cloneDeep} from '../../utils/index.js';
4
- import {excludeObjectKeys} from '../../utils/index.js';
5
3
  import {EmptyValuesService} from '@e22m4u/js-empty-values';
6
4
  import {InvalidArgumentError} from '../../errors/index.js';
7
5
  import {DefinitionRegistry} from '../definition-registry.js';
6
+ import {cloneDeep, excludeObjectKeys} from '../../utils/index.js';
8
7
 
9
8
  /**
10
9
  * Default primary key property name.
@@ -6,8 +6,11 @@ import {RelationType} from './relations/index.js';
6
6
  import {DatabaseSchema} from '../../database-schema.js';
7
7
  import {EmptyValuesService} from '@e22m4u/js-empty-values';
8
8
  import {InvalidArgumentError} from '../../errors/index.js';
9
- import {ModelDefinitionUtils} from './model-definition-utils.js';
10
- import {DEFAULT_PRIMARY_KEY_PROPERTY_NAME as DEF_PK} from './model-definition-utils.js';
9
+
10
+ import {
11
+ ModelDefinitionUtils,
12
+ DEFAULT_PRIMARY_KEY_PROPERTY_NAME as DEF_PK,
13
+ } from './model-definition-utils.js';
11
14
 
12
15
  const sandbox = chai.spy.sandbox();
13
16
 
@@ -1,6 +1,5 @@
1
1
  import {Service} from '@e22m4u/js-service';
2
2
  import {RelationType} from './relation-type.js';
3
- import {RelationType as Type} from './relation-type.js';
4
3
  import {InvalidArgumentError} from '../../../errors/index.js';
5
4
 
6
5
  /**
@@ -62,13 +61,13 @@ export class RelationsDefinitionValidator extends Service {
62
61
  modelName,
63
62
  relDef,
64
63
  );
65
- if (!relDef.type || !Object.values(Type).includes(relDef.type))
64
+ if (!relDef.type || !Object.values(RelationType).includes(relDef.type))
66
65
  throw new InvalidArgumentError(
67
66
  'The relation %v of the model %v requires the option "type" ' +
68
67
  'to have one of relation types: %l, but %v was given.',
69
68
  relName,
70
69
  modelName,
71
- Object.values(Type),
70
+ Object.values(RelationType),
72
71
  relDef.type,
73
72
  );
74
73
  this._validateBelongsTo(modelName, relName, relDef);
@@ -105,7 +104,7 @@ export class RelationsDefinitionValidator extends Service {
105
104
  * @private
106
105
  */
107
106
  _validateBelongsTo(modelName, relName, relDef) {
108
- if (relDef.type !== Type.BELONGS_TO) return;
107
+ if (relDef.type !== RelationType.BELONGS_TO) return;
109
108
  if (relDef.polymorphic) {
110
109
  // A polymorphic "belongsTo" relation.
111
110
  if (typeof relDef.polymorphic !== 'boolean')
@@ -419,7 +418,7 @@ export class RelationsDefinitionValidator extends Service {
419
418
  * @private
420
419
  */
421
420
  _validateReferencesMany(modelName, relName, relDef) {
422
- if (relDef.type !== Type.REFERENCES_MANY) return;
421
+ if (relDef.type !== RelationType.REFERENCES_MANY) return;
423
422
  if (!relDef.model || typeof relDef.model !== 'string')
424
423
  throw new InvalidArgumentError(
425
424
  'The relation %v of the model %v has the type "referencesMany", ' +
@@ -1,15 +1,17 @@
1
1
  import {Service} from '@e22m4u/js-service';
2
- import {RelationType} from '../definition/index.js';
3
- import {HasOneResolver} from '../relations/index.js';
4
- import {HasManyResolver} from '../relations/index.js';
5
2
  import {WhereClauseTool} from './where-clause-tool.js';
6
3
  import {OrderClauseTool} from './order-clause-tool.js';
7
4
  import {SliceClauseTool} from './slice-clause-tool.js';
8
5
  import {InvalidArgumentError} from '../errors/index.js';
9
- import {BelongsToResolver} from '../relations/index.js';
10
6
  import {FieldsClauseTool} from './fields-clause-tool.js';
11
- import {ModelDefinitionUtils} from '../definition/index.js';
12
- import {ReferencesManyResolver} from '../relations/index.js';
7
+ import {RelationType, ModelDefinitionUtils} from '../definition/index.js';
8
+
9
+ import {
10
+ HasOneResolver,
11
+ HasManyResolver,
12
+ BelongsToResolver,
13
+ ReferencesManyResolver,
14
+ } from '../relations/index.js';
13
15
 
14
16
  /**
15
17
  * Include clause tool.
@@ -1,7 +1,6 @@
1
1
  import {Service} from '@e22m4u/js-service';
2
- import {cloneDeep} from '../utils/index.js';
3
- import {singularize} from '../utils/index.js';
4
2
  import {InvalidArgumentError} from '../errors/index.js';
3
+ import {cloneDeep, singularize} from '../utils/index.js';
5
4
  import {RepositoryRegistry} from '../repository/index.js';
6
5
  import {ModelDefinitionUtils} from '../definition/index.js';
7
6
 
@@ -1,10 +1,13 @@
1
1
  import {expect} from 'chai';
2
2
  import {format} from '@e22m4u/js-format';
3
- import {DataType} from '../definition/index.js';
4
- import {RelationType} from '../definition/index.js';
5
3
  import {DatabaseSchema} from '../database-schema.js';
6
4
  import {BelongsToResolver} from './belongs-to-resolver.js';
7
- import {DEFAULT_PRIMARY_KEY_PROPERTY_NAME as DEF_PK} from '../definition/index.js';
5
+
6
+ import {
7
+ DataType,
8
+ RelationType,
9
+ DEFAULT_PRIMARY_KEY_PROPERTY_NAME as DEF_PK,
10
+ } from '../definition/index.js';
8
11
 
9
12
  describe('BelongsToResolver', function () {
10
13
  describe('includeTo', function () {
@@ -1,9 +1,8 @@
1
1
  import {Service} from '@e22m4u/js-service';
2
2
  import {cloneDeep} from '../utils/index.js';
3
- import {RelationType} from '../definition/index.js';
4
3
  import {InvalidArgumentError} from '../errors/index.js';
5
4
  import {RepositoryRegistry} from '../repository/index.js';
6
- import {ModelDefinitionUtils} from '../definition/index.js';
5
+ import {RelationType, ModelDefinitionUtils} from '../definition/index.js';
7
6
 
8
7
  /**
9
8
  * Has many resolver.
@@ -1,10 +1,13 @@
1
1
  import {expect} from 'chai';
2
2
  import {format} from '@e22m4u/js-format';
3
- import {DataType} from '../definition/index.js';
4
- import {RelationType} from '../definition/index.js';
5
3
  import {DatabaseSchema} from '../database-schema.js';
6
4
  import {HasManyResolver} from './has-many-resolver.js';
7
- import {DEFAULT_PRIMARY_KEY_PROPERTY_NAME as DEF_PK} from '../definition/index.js';
5
+
6
+ import {
7
+ DataType,
8
+ RelationType,
9
+ DEFAULT_PRIMARY_KEY_PROPERTY_NAME as DEF_PK,
10
+ } from '../definition/index.js';
8
11
 
9
12
  describe('HasManyResolver', function () {
10
13
  describe('includeTo', function () {
@@ -1,9 +1,8 @@
1
1
  import {Service} from '@e22m4u/js-service';
2
2
  import {cloneDeep} from '../utils/index.js';
3
- import {RelationType} from '../definition/index.js';
4
3
  import {InvalidArgumentError} from '../errors/index.js';
5
4
  import {RepositoryRegistry} from '../repository/index.js';
6
- import {ModelDefinitionUtils} from '../definition/index.js';
5
+ import {RelationType, ModelDefinitionUtils} from '../definition/index.js';
7
6
 
8
7
  /**
9
8
  * Has one resolver.
@@ -1,10 +1,13 @@
1
1
  import {expect} from 'chai';
2
2
  import {format} from '@e22m4u/js-format';
3
- import {DataType} from '../definition/index.js';
4
- import {RelationType} from '../definition/index.js';
5
3
  import {HasOneResolver} from './has-one-resolver.js';
6
4
  import {DatabaseSchema} from '../database-schema.js';
7
- import {DEFAULT_PRIMARY_KEY_PROPERTY_NAME as DEF_PK} from '../definition/index.js';
5
+
6
+ import {
7
+ DataType,
8
+ RelationType,
9
+ DEFAULT_PRIMARY_KEY_PROPERTY_NAME as DEF_PK,
10
+ } from '../definition/index.js';
8
11
 
9
12
  describe('HasOneResolver', function () {
10
13
  describe('includeTo', function () {
@@ -1,7 +1,6 @@
1
1
  import {Service} from '@e22m4u/js-service';
2
- import {cloneDeep} from '../utils/index.js';
3
- import {singularize} from '../utils/index.js';
4
2
  import {InvalidArgumentError} from '../errors/index.js';
3
+ import {cloneDeep, singularize} from '../utils/index.js';
5
4
  import {RepositoryRegistry} from '../repository/index.js';
6
5
  import {ModelDefinitionUtils} from '../definition/index.js';
7
6
 
@@ -1,10 +1,13 @@
1
1
  import {expect} from 'chai';
2
2
  import {format} from '@e22m4u/js-format';
3
- import {DataType} from '../definition/index.js';
4
- import {RelationType} from '../definition/index.js';
5
3
  import {DatabaseSchema} from '../database-schema.js';
6
4
  import {ReferencesManyResolver} from './references-many-resolver.js';
7
- import {DEFAULT_PRIMARY_KEY_PROPERTY_NAME as DEF_PK} from '../definition/index.js';
5
+
6
+ import {
7
+ DataType,
8
+ RelationType,
9
+ DEFAULT_PRIMARY_KEY_PROPERTY_NAME as DEF_PK,
10
+ } from '../definition/index.js';
8
11
 
9
12
  describe('ReferencesManyResolver', function () {
10
13
  describe('includeTo', function () {
@@ -1,8 +1,7 @@
1
1
  import {Service} from '@e22m4u/js-service';
2
- import {Adapter} from '../adapter/index.js';
3
- import {AdapterRegistry} from '../adapter/index.js';
4
2
  import {InvalidArgumentError} from '../errors/index.js';
5
3
  import {DefinitionRegistry} from '../definition/index.js';
4
+ import {Adapter, AdapterRegistry} from '../adapter/index.js';
6
5
 
7
6
  /**
8
7
  * Repository.
@@ -7,9 +7,9 @@
7
7
  export function isPlainObject(value) {
8
8
  return Boolean(
9
9
  typeof value === 'object' &&
10
- value &&
11
- !Array.isArray(value) &&
12
- (!value.constructor ||
13
- (value.constructor && value.constructor.name === 'Object')),
10
+ value &&
11
+ !Array.isArray(value) &&
12
+ (!value.constructor ||
13
+ (value.constructor && value.constructor.name === 'Object')),
14
14
  );
15
15
  }
package/tsconfig.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "strict": true,
4
- "noEmit": true,
5
4
  "target": "es2022",
6
5
  "module": "NodeNext",
7
6
  "moduleResolution": "NodeNext",
8
- "strictNullChecks": true,
7
+ "noEmit": true,
9
8
  "allowJs": true
10
- }
9
+ },
10
+ "include": [
11
+ "./src/**/*.ts",
12
+ "./src/**/*.js"
13
+ ]
11
14
  }