@e22m4u/js-repository 0.3.0 → 0.3.2

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,5 @@
1
1
  {
2
2
  "extension": ["js", "ts"],
3
3
  "spec": "src/**/*.spec.{js,ts}",
4
- "require": ["tsx"]
4
+ "require": ["ts-node/register"]
5
5
  }
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 e22m4u@yandex.ru
3
+ Copyright (c) 2023-2025 Mikhail Evstropov <e22m4u@yandex.ru>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  - [Импорт](#импорт)
7
7
  - [Описание](#описание)
8
8
  - [Пример](#пример)
9
- - [Схема баз данных](#схема-баз-данных)
9
+ - [Схема базы данных](#схема-базы-данных)
10
10
  - [Источник данных](#источник-данных)
11
11
  - [Модель](#модель)
12
12
  - [Свойства](#свойства)
@@ -147,9 +147,10 @@ console.log(country);
147
147
  // }
148
148
  ```
149
149
 
150
- ## Схема баз данных
150
+ ## Схема базы данных
151
151
 
152
- Экземпляр класса `DatabaseSchema` хранит определения источников данных и моделей.
152
+ Экземпляр класса `DatabaseSchema` хранит определения источников и моделей
153
+ данных.
153
154
 
154
155
  **Методы**
155
156
 
@@ -2415,25 +2415,25 @@ var init_model_definition_utils = __esm({
2415
2415
  * @returns {object}
2416
2416
  */
2417
2417
  getPropertiesDefinitionInBaseModelHierarchy(modelName) {
2418
- let result = {};
2419
2418
  let pkPropDefs = {};
2419
+ let regularPropDefs = {};
2420
2420
  const recursion = /* @__PURE__ */ __name((currModelName, prevModelName = void 0) => {
2421
2421
  if (currModelName === prevModelName)
2422
2422
  throw new InvalidArgumentError(
2423
2423
  "The model %v has a circular inheritance.",
2424
2424
  currModelName
2425
2425
  );
2426
- if (Object.keys(pkPropDefs).length === 0) {
2426
+ if (Object.keys(pkPropDefs).length === 0)
2427
2427
  pkPropDefs = this.getOwnPropertiesDefinitionOfPrimaryKeys(currModelName);
2428
- result = { ...result, ...pkPropDefs };
2429
- }
2430
- const regularPropDefs = this.getOwnPropertiesDefinitionWithoutPrimaryKeys(currModelName);
2431
- result = { ...regularPropDefs, ...result };
2428
+ regularPropDefs = {
2429
+ ...this.getOwnPropertiesDefinitionWithoutPrimaryKeys(currModelName),
2430
+ ...regularPropDefs
2431
+ };
2432
2432
  const modelDef = this.getService(DefinitionRegistry).getModel(currModelName);
2433
2433
  if (modelDef.base) recursion(modelDef.base, currModelName);
2434
2434
  }, "recursion");
2435
2435
  recursion(modelName);
2436
- return result;
2436
+ return { ...pkPropDefs, ...regularPropDefs };
2437
2437
  }
2438
2438
  /**
2439
2439
  * Get own relations definition.
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@e22m4u/js-repository",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Реализация репозитория для работы с базами данных в Node.js",
5
- "author": "e22m4u <e22m4u@yandex.ru>",
5
+ "author": "Mikhail Evstropov <e22m4u@yandex.ru>",
6
6
  "license": "MIT",
7
7
  "keywords": [
8
8
  "Repository",
@@ -39,11 +39,9 @@
39
39
  "prepare": "husky"
40
40
  },
41
41
  "dependencies": {
42
- "@e22m4u/js-empty-values": "~0.0.1"
43
- },
44
- "peerDependencies": {
45
- "@e22m4u/js-format": "~0.1.0",
46
- "@e22m4u/js-service": "~0.2.0"
42
+ "@e22m4u/js-empty-values": "~0.0.2",
43
+ "@e22m4u/js-format": "~0.1.8",
44
+ "@e22m4u/js-service": "~0.3.3"
47
45
  },
48
46
  "devDependencies": {
49
47
  "@commitlint/cli": "~19.8.1",
@@ -53,21 +51,21 @@
53
51
  "@types/chai-spies": "~1.0.6",
54
52
  "@types/mocha": "~10.0.10",
55
53
  "c8": "~10.1.3",
56
- "chai": "~5.2.0",
54
+ "chai": "~5.2.1",
57
55
  "chai-as-promised": "~8.0.1",
58
56
  "chai-spies": "~1.1.0",
59
- "esbuild": "~0.25.5",
60
- "eslint": "~9.28.0",
61
- "eslint-config-prettier": "~10.1.5",
57
+ "esbuild": "~0.25.8",
58
+ "eslint": "~9.32.0",
59
+ "eslint-config-prettier": "~10.1.8",
62
60
  "eslint-plugin-chai-expect": "~3.1.0",
63
- "eslint-plugin-jsdoc": "~50.8.0",
61
+ "eslint-plugin-jsdoc": "~52.0.2",
64
62
  "eslint-plugin-mocha": "~11.1.0",
65
63
  "husky": "~9.1.7",
66
- "mocha": "~11.6.0",
67
- "prettier": "~3.5.3",
64
+ "mocha": "~11.7.1",
65
+ "prettier": "~3.6.2",
68
66
  "rimraf": "~6.0.1",
69
- "tsx": "~4.20.2",
67
+ "ts-node": "~10.9.2",
70
68
  "typescript": "~5.8.3",
71
- "typescript-eslint": "~8.34.0"
69
+ "typescript-eslint": "~8.39.0"
72
70
  }
73
71
  }
@@ -372,28 +372,27 @@ export class ModelDefinitionUtils extends Service {
372
372
  * @returns {object}
373
373
  */
374
374
  getPropertiesDefinitionInBaseModelHierarchy(modelName) {
375
- let result = {};
376
375
  let pkPropDefs = {};
376
+ let regularPropDefs = {};
377
377
  const recursion = (currModelName, prevModelName = undefined) => {
378
378
  if (currModelName === prevModelName)
379
379
  throw new InvalidArgumentError(
380
380
  'The model %v has a circular inheritance.',
381
381
  currModelName,
382
382
  );
383
- if (Object.keys(pkPropDefs).length === 0) {
383
+ if (Object.keys(pkPropDefs).length === 0)
384
384
  pkPropDefs =
385
385
  this.getOwnPropertiesDefinitionOfPrimaryKeys(currModelName);
386
- result = {...result, ...pkPropDefs};
387
- }
388
- const regularPropDefs =
389
- this.getOwnPropertiesDefinitionWithoutPrimaryKeys(currModelName);
390
- result = {...regularPropDefs, ...result};
386
+ regularPropDefs = {
387
+ ...this.getOwnPropertiesDefinitionWithoutPrimaryKeys(currModelName),
388
+ ...regularPropDefs,
389
+ };
391
390
  const modelDef =
392
391
  this.getService(DefinitionRegistry).getModel(currModelName);
393
392
  if (modelDef.base) recursion(modelDef.base, currModelName);
394
393
  };
395
394
  recursion(modelName);
396
- return result;
395
+ return {...pkPropDefs, ...regularPropDefs};
397
396
  }
398
397
 
399
398
  /**
@@ -1567,6 +1567,25 @@ describe('ModelDefinitionUtils', function () {
1567
1567
  'The model "model" has a circular inheritance.',
1568
1568
  );
1569
1569
  });
1570
+
1571
+ it('places a primary key definition at the start of the result', function () {
1572
+ const dbs = new DatabaseSchema();
1573
+ dbs.defineModel({
1574
+ name: 'model',
1575
+ properties: {
1576
+ foo: DataType.STRING,
1577
+ id: {
1578
+ type: DataType.STRING,
1579
+ primaryKey: true,
1580
+ },
1581
+ bar: DataType.NUMBER,
1582
+ },
1583
+ });
1584
+ const result = dbs
1585
+ .getService(ModelDefinitionUtils)
1586
+ .getPropertiesDefinitionInBaseModelHierarchy('model');
1587
+ expect(Object.keys(result)).to.be.eql(['id', 'foo', 'bar']);
1588
+ });
1570
1589
  });
1571
1590
 
1572
1591
  describe('getOwnRelationsDefinition', function () {