@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
package/eslint.config.js
CHANGED
|
@@ -1,68 +1,39 @@
|
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
globals
|
|
14
|
-
|
|
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
|
+
languageOptions: {
|
|
11
|
+
globals: {
|
|
12
|
+
...globals.node,
|
|
13
|
+
...globals.es2021,
|
|
14
|
+
...globals.mocha,
|
|
37
15
|
},
|
|
38
16
|
},
|
|
39
|
-
{
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
},
|
|
17
|
+
plugins: {
|
|
18
|
+
'jsdoc': eslintJsdocPlugin,
|
|
19
|
+
'mocha': eslintMochaPlugin,
|
|
20
|
+
'import': eslintImportPlugin,
|
|
21
|
+
'chai-expect': eslintChaiExpectPlugin,
|
|
22
|
+
},
|
|
23
|
+
rules: {
|
|
24
|
+
...eslintJs.configs.recommended.rules,
|
|
25
|
+
...eslintPrettierConfig.rules,
|
|
26
|
+
...eslintImportPlugin.flatConfigs.recommended.rules,
|
|
27
|
+
...eslintMochaPlugin.configs.recommended.rules,
|
|
28
|
+
...eslintChaiExpectPlugin.configs['recommended-flat'].rules,
|
|
29
|
+
...eslintJsdocPlugin.configs['flat/recommended-error'].rules,
|
|
30
|
+
'no-duplicate-imports': 'error',
|
|
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}],
|
|
67
37
|
},
|
|
68
|
-
]
|
|
38
|
+
files: ['src/**/*.js'],
|
|
39
|
+
}];
|
package/jsconfig.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e22m4u/js-repository",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Реализация репозитория для работы с базами данных",
|
|
5
5
|
"author": "Mikhail Evstropov <e22m4u@yandex.ru>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,17 +12,15 @@
|
|
|
12
12
|
"Datasource",
|
|
13
13
|
"Relations"
|
|
14
14
|
],
|
|
15
|
-
"homepage": "https://
|
|
15
|
+
"homepage": "https://gitrepos.ru/e22m4u/js-repository",
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
18
|
-
"url": "git+https://
|
|
18
|
+
"url": "git+https://gitrepos.ru/e22m4u/js-repository.git"
|
|
19
19
|
},
|
|
20
20
|
"type": "module",
|
|
21
|
-
"types": "./src/index.d.ts",
|
|
22
21
|
"module": "./src/index.js",
|
|
23
22
|
"main": "./dist/cjs/index.cjs",
|
|
24
23
|
"exports": {
|
|
25
|
-
"types": "./src/index.d.ts",
|
|
26
24
|
"import": "./src/index.js",
|
|
27
25
|
"require": "./dist/cjs/index.cjs"
|
|
28
26
|
},
|
|
@@ -30,26 +28,22 @@
|
|
|
30
28
|
"node": ">=12"
|
|
31
29
|
},
|
|
32
30
|
"scripts": {
|
|
33
|
-
"lint": "
|
|
34
|
-
"lint:fix": "
|
|
31
|
+
"lint": "eslint ./src",
|
|
32
|
+
"lint:fix": "eslint ./src --fix",
|
|
35
33
|
"format": "prettier --write \"./src/**/*.js\"",
|
|
36
34
|
"test": "npm run lint && c8 --reporter=text-summary mocha --bail",
|
|
37
35
|
"test:coverage": "npm run lint && c8 --reporter=text mocha --bail",
|
|
38
|
-
"build:cjs": "rimraf ./dist/cjs && node
|
|
36
|
+
"build:cjs": "rimraf ./dist/cjs && node build-cjs.js",
|
|
39
37
|
"prepare": "husky"
|
|
40
38
|
},
|
|
41
39
|
"dependencies": {
|
|
42
|
-
"@e22m4u/js-empty-values": "~0.
|
|
43
|
-
"@e22m4u/js-format": "~0.
|
|
40
|
+
"@e22m4u/js-empty-values": "~0.2.0",
|
|
41
|
+
"@e22m4u/js-format": "~0.3.0",
|
|
44
42
|
"@e22m4u/js-service": "~0.4.6"
|
|
45
43
|
},
|
|
46
44
|
"devDependencies": {
|
|
47
45
|
"@commitlint/cli": "~20.1.0",
|
|
48
46
|
"@commitlint/config-conventional": "~20.0.0",
|
|
49
|
-
"@types/chai": "~5.2.3",
|
|
50
|
-
"@types/chai-as-promised": "~8.0.2",
|
|
51
|
-
"@types/chai-spies": "~1.0.6",
|
|
52
|
-
"@types/mocha": "~10.0.10",
|
|
53
47
|
"c8": "~10.1.3",
|
|
54
48
|
"chai": "~6.2.1",
|
|
55
49
|
"chai-as-promised": "~8.0.2",
|
|
@@ -58,14 +52,12 @@
|
|
|
58
52
|
"eslint": "~9.39.1",
|
|
59
53
|
"eslint-config-prettier": "~10.1.8",
|
|
60
54
|
"eslint-plugin-chai-expect": "~3.1.0",
|
|
61
|
-
"eslint-plugin-
|
|
55
|
+
"eslint-plugin-import": "~2.32.0",
|
|
56
|
+
"eslint-plugin-jsdoc": "~61.4.1",
|
|
62
57
|
"eslint-plugin-mocha": "~11.2.0",
|
|
63
58
|
"husky": "~9.1.7",
|
|
64
59
|
"mocha": "~11.7.5",
|
|
65
|
-
"prettier": "~3.
|
|
66
|
-
"rimraf": "~6.1.
|
|
67
|
-
"ts-node": "~10.9.2",
|
|
68
|
-
"typescript": "~5.9.3",
|
|
69
|
-
"typescript-eslint": "~8.46.4"
|
|
60
|
+
"prettier": "~3.7.3",
|
|
61
|
+
"rimraf": "~6.1.2"
|
|
70
62
|
}
|
|
71
63
|
}
|
|
@@ -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
|
|
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
|
|
35
|
+
} catch {
|
|
37
36
|
/**/
|
|
38
37
|
}
|
|
39
38
|
if (!adapterCtor)
|
package/src/adapter/adapter.js
CHANGED
|
@@ -2,13 +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
|
-
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
InclusionDecorator,
|
|
8
|
+
DefaultValuesDecorator,
|
|
9
|
+
DataSanitizingDecorator,
|
|
10
|
+
FieldsFilteringDecorator,
|
|
11
|
+
PropertyUniquenessDecorator,
|
|
12
|
+
} from './decorator/index.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Adapter class name.
|
|
@@ -22,9 +23,9 @@ export const ADAPTER_CLASS_NAME = 'Adapter';
|
|
|
22
23
|
*/
|
|
23
24
|
export class Adapter extends Service {
|
|
24
25
|
/**
|
|
25
|
-
*
|
|
26
|
+
* Kinds.
|
|
26
27
|
*
|
|
27
|
-
* @type {string}
|
|
28
|
+
* @type {string[]}
|
|
28
29
|
*/
|
|
29
30
|
static kinds = [...Service.kinds, ADAPTER_CLASS_NAME];
|
|
30
31
|
|
|
@@ -57,8 +58,6 @@ export class Adapter extends Service {
|
|
|
57
58
|
if (this.constructor !== Adapter) {
|
|
58
59
|
this.getService(DataSanitizingDecorator).decorate(this);
|
|
59
60
|
this.getService(DefaultValuesDecorator).decorate(this);
|
|
60
|
-
this.getService(DataTransformationDecorator).decorate(this);
|
|
61
|
-
this.getService(DataValidationDecorator).decorate(this);
|
|
62
61
|
this.getService(PropertyUniquenessDecorator).decorate(this);
|
|
63
62
|
this.getService(FieldsFilteringDecorator).decorate(this);
|
|
64
63
|
this.getService(InclusionDecorator).decorate(this);
|
|
@@ -1,17 +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 {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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';
|
|
15
14
|
|
|
16
15
|
const sandbox = chai.spy.sandbox();
|
|
17
16
|
|
|
@@ -45,11 +44,9 @@ describe('Adapter', function () {
|
|
|
45
44
|
const dbs = new DatabaseSchema();
|
|
46
45
|
const dec1 = dbs.getService(DataSanitizingDecorator);
|
|
47
46
|
const dec2 = dbs.getService(DefaultValuesDecorator);
|
|
48
|
-
const dec3 = dbs.getService(
|
|
49
|
-
const dec4 = dbs.getService(
|
|
50
|
-
const dec5 = dbs.getService(
|
|
51
|
-
const dec6 = dbs.getService(FieldsFilteringDecorator);
|
|
52
|
-
const dec7 = dbs.getService(InclusionDecorator);
|
|
47
|
+
const dec3 = dbs.getService(PropertyUniquenessDecorator);
|
|
48
|
+
const dec4 = dbs.getService(FieldsFilteringDecorator);
|
|
49
|
+
const dec5 = dbs.getService(InclusionDecorator);
|
|
53
50
|
const order = [];
|
|
54
51
|
const decorate = function (ctx) {
|
|
55
52
|
expect(ctx).to.be.instanceof(Adapter);
|
|
@@ -60,8 +57,6 @@ describe('Adapter', function () {
|
|
|
60
57
|
sandbox.on(dec3, 'decorate', decorate);
|
|
61
58
|
sandbox.on(dec4, 'decorate', decorate);
|
|
62
59
|
sandbox.on(dec5, 'decorate', decorate);
|
|
63
|
-
sandbox.on(dec6, 'decorate', decorate);
|
|
64
|
-
sandbox.on(dec7, 'decorate', decorate);
|
|
65
60
|
new Adapter(dbs.container);
|
|
66
61
|
expect(order).to.be.empty;
|
|
67
62
|
expect(dec1.decorate).to.be.not.called;
|
|
@@ -69,8 +64,6 @@ describe('Adapter', function () {
|
|
|
69
64
|
expect(dec3.decorate).to.be.not.called;
|
|
70
65
|
expect(dec4.decorate).to.be.not.called;
|
|
71
66
|
expect(dec5.decorate).to.be.not.called;
|
|
72
|
-
expect(dec6.decorate).to.be.not.called;
|
|
73
|
-
expect(dec7.decorate).to.be.not.called;
|
|
74
67
|
class ExtendedAdapter extends Adapter {}
|
|
75
68
|
new ExtendedAdapter(dbs.container);
|
|
76
69
|
expect(order[0]).to.be.eql(dec1);
|
|
@@ -78,15 +71,11 @@ describe('Adapter', function () {
|
|
|
78
71
|
expect(order[2]).to.be.eql(dec3);
|
|
79
72
|
expect(order[3]).to.be.eql(dec4);
|
|
80
73
|
expect(order[4]).to.be.eql(dec5);
|
|
81
|
-
expect(order[5]).to.be.eql(dec6);
|
|
82
|
-
expect(order[6]).to.be.eql(dec7);
|
|
83
74
|
expect(dec1.decorate).to.be.called.once;
|
|
84
75
|
expect(dec2.decorate).to.be.called.once;
|
|
85
76
|
expect(dec3.decorate).to.be.called.once;
|
|
86
77
|
expect(dec4.decorate).to.be.called.once;
|
|
87
78
|
expect(dec5.decorate).to.be.called.once;
|
|
88
|
-
expect(dec6.decorate).to.be.called.once;
|
|
89
|
-
expect(dec7.decorate).to.be.called.once;
|
|
90
79
|
});
|
|
91
80
|
});
|
|
92
81
|
|
|
@@ -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';
|
|
2
|
+
import {cloneDeep, capitalize} from '../../utils/index.js';
|
|
8
3
|
import {InvalidArgumentError} from '../../errors/index.js';
|
|
9
|
-
import {ModelDefinitionUtils} from '../../definition/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.
|
|
@@ -50,10 +51,9 @@ export class MemoryAdapter extends Adapter {
|
|
|
50
51
|
* @returns {number}
|
|
51
52
|
*/
|
|
52
53
|
_genNextIdValue(modelName, propName) {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (propType !== DataType.ANY && propType !== DataType.NUMBER)
|
|
54
|
+
const modelUtils = this.getService(ModelDefinitionUtils);
|
|
55
|
+
const propType = modelUtils.getDataTypeByPropertyName(modelName, propName);
|
|
56
|
+
if (propType !== DataType.ANY && propType !== DataType.NUMBER) {
|
|
57
57
|
throw new InvalidArgumentError(
|
|
58
58
|
'The memory adapter able to generate only Number identifiers, ' +
|
|
59
59
|
'but the primary key %v of the model %v is defined as %s. ' +
|
|
@@ -65,18 +65,36 @@ export class MemoryAdapter extends Adapter {
|
|
|
65
65
|
capitalize(propType),
|
|
66
66
|
propName,
|
|
67
67
|
);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const lastId = this._lastIds.get(tableName) ?? 0;
|
|
71
|
-
const nextId = lastId + 1;
|
|
72
|
-
this._lastIds.set(tableName, nextId);
|
|
68
|
+
}
|
|
69
|
+
const tableName = modelUtils.getTableNameByModelName(modelName);
|
|
73
70
|
const table = this._getTableOrCreate(modelName);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
let nextId = this._lastIds.get(tableName) ?? 0;
|
|
72
|
+
do {
|
|
73
|
+
nextId++;
|
|
74
|
+
} while (table.has(nextId));
|
|
75
|
+
this._lastIds.set(tableName, nextId);
|
|
77
76
|
return nextId;
|
|
78
77
|
}
|
|
79
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Update last id value if needed.
|
|
81
|
+
*
|
|
82
|
+
* Если переданное значение последнего использованного
|
|
83
|
+
* идентификатора больше текущего, то текущее значение
|
|
84
|
+
* перезаписывается полученным.
|
|
85
|
+
*
|
|
86
|
+
* @param {string} modelName
|
|
87
|
+
* @param {number} idValue
|
|
88
|
+
*/
|
|
89
|
+
_updateLastIdValueIfNeeded(modelName, idValue) {
|
|
90
|
+
const tableName =
|
|
91
|
+
this.getService(ModelDefinitionUtils).getTableNameByModelName(modelName);
|
|
92
|
+
const currentLastId = this._lastIds.get(tableName) ?? 0;
|
|
93
|
+
if (idValue > currentLastId) {
|
|
94
|
+
this._lastIds.set(tableName, idValue);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
80
98
|
/**
|
|
81
99
|
* Create
|
|
82
100
|
*
|
|
@@ -95,6 +113,12 @@ export class MemoryAdapter extends Adapter {
|
|
|
95
113
|
if (idValue == null || idValue === '' || idValue === 0) {
|
|
96
114
|
idValue = this._genNextIdValue(modelName, pkPropName);
|
|
97
115
|
}
|
|
116
|
+
// если идентификатор передан вручную и является числом,
|
|
117
|
+
// то значение последнего использованного идентификатора
|
|
118
|
+
// обновляется на полученное
|
|
119
|
+
else if (typeof idValue === 'number') {
|
|
120
|
+
this._updateLastIdValueIfNeeded(modelName, idValue);
|
|
121
|
+
}
|
|
98
122
|
|
|
99
123
|
const table = this._getTableOrCreate(modelName);
|
|
100
124
|
if (table.has(idValue))
|
|
@@ -174,6 +198,12 @@ export class MemoryAdapter extends Adapter {
|
|
|
174
198
|
if (idValue == null || idValue === '' || idValue === 0) {
|
|
175
199
|
idValue = this._genNextIdValue(modelName, pkPropName);
|
|
176
200
|
}
|
|
201
|
+
// если идентификатор передан вручную и является числом,
|
|
202
|
+
// то значение последнего использованного идентификатора
|
|
203
|
+
// обновляется на полученное
|
|
204
|
+
else if (typeof idValue === 'number') {
|
|
205
|
+
this._updateLastIdValueIfNeeded(modelName, idValue);
|
|
206
|
+
}
|
|
177
207
|
|
|
178
208
|
const table = this._getTableOrCreate(modelName);
|
|
179
209
|
modelData = cloneDeep(modelData);
|
|
@@ -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
|
-
|
|
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 () {
|
|
@@ -56,6 +59,53 @@ describe('MemoryAdapter', function () {
|
|
|
56
59
|
expect(id2).to.be.eq(2);
|
|
57
60
|
expect(id3).to.be.eq(3);
|
|
58
61
|
});
|
|
62
|
+
|
|
63
|
+
it('increments from the the last known identifier', function () {
|
|
64
|
+
const dbs = new DatabaseSchema();
|
|
65
|
+
dbs.defineModel({name: 'model'});
|
|
66
|
+
const A = dbs.getService(MemoryAdapter);
|
|
67
|
+
A._lastIds.set('model', 10);
|
|
68
|
+
const id1 = A._genNextIdValue('model', DEF_PK);
|
|
69
|
+
const id2 = A._genNextIdValue('model', DEF_PK);
|
|
70
|
+
const id3 = A._genNextIdValue('model', DEF_PK);
|
|
71
|
+
expect(id1).to.be.eq(11);
|
|
72
|
+
expect(id2).to.be.eq(12);
|
|
73
|
+
expect(id3).to.be.eq(13);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('_updateLastIdValueIfNeeded', function () {
|
|
78
|
+
it('does nothing when the given identifier is lower or equal', function () {
|
|
79
|
+
const dbs = new DatabaseSchema();
|
|
80
|
+
dbs.defineModel({name: 'model'});
|
|
81
|
+
const A = dbs.getService(MemoryAdapter);
|
|
82
|
+
A._lastIds.set('model', 10);
|
|
83
|
+
A._updateLastIdValueIfNeeded('model', 9);
|
|
84
|
+
A._updateLastIdValueIfNeeded('model', 10);
|
|
85
|
+
const res = A._lastIds.get('model');
|
|
86
|
+
expect(res).to.be.eq(10);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('updates the last known identifier if the given identifier is greater', function () {
|
|
90
|
+
const dbs = new DatabaseSchema();
|
|
91
|
+
dbs.defineModel({name: 'model'});
|
|
92
|
+
const A = dbs.getService(MemoryAdapter);
|
|
93
|
+
A._lastIds.set('model', 10);
|
|
94
|
+
A._updateLastIdValueIfNeeded('model', 15);
|
|
95
|
+
const res = A._lastIds.get('model');
|
|
96
|
+
expect(res).to.be.eq(15);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('correctly resolves table name from model name', function () {
|
|
100
|
+
const dbs = new DatabaseSchema();
|
|
101
|
+
dbs.defineModel({name: 'MyModel', tableName: 'custom_table_name'});
|
|
102
|
+
const A = dbs.getService(MemoryAdapter);
|
|
103
|
+
A._lastIds.set('custom_table_name', 10);
|
|
104
|
+
A._updateLastIdValueIfNeeded('MyModel', 20);
|
|
105
|
+
const res = A._lastIds.get('custom_table_name');
|
|
106
|
+
expect(res).to.be.eq(20);
|
|
107
|
+
expect(A._lastIds.has('MyModel')).to.be.false;
|
|
108
|
+
});
|
|
59
109
|
});
|
|
60
110
|
|
|
61
111
|
describe('create', 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,5 @@
|
|
|
1
1
|
export * from './inclusion-decorator.js';
|
|
2
2
|
export * from './default-values-decorator.js';
|
|
3
3
|
export * from './data-sanitizing-decorator.js';
|
|
4
|
-
export * from './data-validation-decorator.js';
|
|
5
4
|
export * from './fields-filtering-decorator.js';
|
|
6
|
-
export * from './data-transformation-decorator.js';
|
|
7
5
|
export * from './property-uniqueness-decorator.js';
|
package/src/database-schema.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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,8 +1,5 @@
|
|
|
1
1
|
export * from './relations/index.js';
|
|
2
2
|
export * from './properties/index.js';
|
|
3
|
-
export * from './model-definition.js';
|
|
4
|
-
export * from './model-data-validator.js';
|
|
5
3
|
export * from './model-data-sanitizer.js';
|
|
6
|
-
export * from './model-data-transformer.js';
|
|
7
4
|
export * from './model-definition-utils.js';
|
|
8
5
|
export * from './model-definition-validator.js';
|
|
@@ -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
|
-
|
|
10
|
-
import {
|
|
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,8 +1,5 @@
|
|
|
1
1
|
export * from './data-type.js';
|
|
2
|
-
export * from './property-definition.js';
|
|
3
2
|
export * from './property-uniqueness.js';
|
|
4
|
-
export * from './property-validator/index.js';
|
|
5
|
-
export * from './property-transformer/index.js';
|
|
6
3
|
export * from './property-uniqueness-validator.js';
|
|
7
4
|
export * from './properties-definition-validator.js';
|
|
8
5
|
export * from './primary-keys-definition-validator.js';
|