@e22m4u/js-repository 0.3.1 → 0.3.3

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
@@ -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.1",
3
+ "version": "0.3.3",
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.3.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.30.0",
61
- "eslint-config-prettier": "~10.1.5",
57
+ "esbuild": "~0.25.9",
58
+ "eslint": "~9.33.0",
59
+ "eslint-config-prettier": "~10.1.8",
62
60
  "eslint-plugin-chai-expect": "~3.1.0",
63
- "eslint-plugin-jsdoc": "~51.2.3",
61
+ "eslint-plugin-jsdoc": "~54.1.0",
64
62
  "eslint-plugin-mocha": "~11.1.0",
65
63
  "husky": "~9.1.7",
66
64
  "mocha": "~11.7.1",
67
65
  "prettier": "~3.6.2",
68
66
  "rimraf": "~6.0.1",
69
- "tsx": "~4.20.3",
70
- "typescript": "~5.8.3",
71
- "typescript-eslint": "~8.35.0"
67
+ "ts-node": "~10.9.2",
68
+ "typescript": "~5.9.2",
69
+ "typescript-eslint": "~8.39.1"
72
70
  }
73
71
  }
@@ -32,6 +32,6 @@ export declare class DatabaseSchema extends Service {
32
32
  getRepository<
33
33
  Data extends object = ModelData,
34
34
  IdType extends ModelId = ModelId,
35
- IdName extends string = DEFAULT_PRIMARY_KEY_PROPERTY_NAME,
35
+ IdName extends string = typeof DEFAULT_PRIMARY_KEY_PROPERTY_NAME,
36
36
  >(modelName: string): Repository<Data, IdType, IdName>;
37
37
  }
@@ -9,7 +9,7 @@ import {RelationDefinitionMap} from './model-definition.js';
9
9
  /**
10
10
  * Default primary key property name.
11
11
  */
12
- export type DEFAULT_PRIMARY_KEY_PROPERTY_NAME = 'id';
12
+ export const DEFAULT_PRIMARY_KEY_PROPERTY_NAME: 'id';
13
13
 
14
14
  /**
15
15
  * Model definition utils.
@@ -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 () {
@@ -24,6 +24,6 @@ export declare class RepositoryRegistry extends Service {
24
24
  getRepository<
25
25
  Data extends ModelData = ModelData,
26
26
  IdType extends ModelId = ModelId,
27
- IdName extends string = DEFAULT_PRIMARY_KEY_PROPERTY_NAME,
27
+ IdName extends string = typeof DEFAULT_PRIMARY_KEY_PROPERTY_NAME,
28
28
  >(modelName: string): Repository<Data, IdType, IdName>;
29
29
  }
@@ -16,7 +16,7 @@ import {DEFAULT_PRIMARY_KEY_PROPERTY_NAME} from '../definition/index.js';
16
16
  export declare class Repository<
17
17
  Data extends object = ModelData,
18
18
  IdType extends ModelId = ModelId,
19
- IdName extends string = DEFAULT_PRIMARY_KEY_PROPERTY_NAME,
19
+ IdName extends string = typeof DEFAULT_PRIMARY_KEY_PROPERTY_NAME,
20
20
  FlatData extends ModelData = Flatten<Data>,
21
21
  > extends Service {
22
22
  // it fixes unused generic bug