@artenc/nest-orm 1.3.0 → 2.0.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.
@@ -17,91 +17,62 @@ function AbstractOrmService(entity) {
17
17
  class AbstractOrmServiceHost {
18
18
  repository;
19
19
  async create(props, enforceEntityManager) {
20
- const entityManager = this.getEntityManager(enforceEntityManager);
21
- const model = entityManager ? entityManager.create(entity, props) : this.repository.create(props);
22
- if (entityManager) {
23
- await entityManager.save(model);
24
- }
25
- else {
26
- await this.repository.save(model);
27
- }
28
- if (enforceEntityManager) {
29
- model.setEntityManager(enforceEntityManager);
30
- }
31
- else {
32
- model.setRepository(this.repository);
33
- }
20
+ const repository = this.getRepository(enforceEntityManager);
21
+ const model = repository.create(props);
22
+ await repository.save(model);
23
+ this.pinModels([model], enforceEntityManager);
34
24
  return model;
35
25
  }
36
- async exists(condition, enforceEntityManager) {
37
- const entityManager = this.getEntityManager(enforceEntityManager);
38
- if (entityManager) {
39
- return Boolean(await entityManager.findOne(entity, condition));
40
- }
41
- return Boolean(await this.repository.findOne(condition));
26
+ exists(condition, enforceEntityManager) {
27
+ return this.getRepository(enforceEntityManager).exists(condition);
42
28
  }
43
29
  async find(conditions, enforceEntityManager) {
44
- const entityManager = this.getEntityManager(enforceEntityManager);
45
- const models = await (entityManager
46
- ? entityManager.find(entity, conditions)
47
- : this.repository.find(conditions));
48
- if (enforceEntityManager) {
49
- models.forEach((m) => m.setEntityManager(enforceEntityManager));
50
- }
51
- else {
52
- models.forEach((m) => m.setRepository(this.repository));
53
- }
30
+ const models = await this.getRepository(enforceEntityManager).find(conditions);
31
+ this.pinModels(models, enforceEntityManager);
54
32
  return models;
55
33
  }
56
34
  async findOne(conditions, enforceEntityManager) {
57
- const entityManager = this.getEntityManager(enforceEntityManager);
58
- const model = await (entityManager
59
- ? entityManager.findOne(entity, conditions)
60
- : this.repository.findOne(conditions));
35
+ const model = await this.getRepository(enforceEntityManager).findOne(conditions);
61
36
  if (!model) {
62
37
  return null;
63
38
  }
64
- if (enforceEntityManager) {
65
- model.setEntityManager(enforceEntityManager);
66
- }
67
- else {
68
- model.setRepository(this.repository);
69
- }
39
+ this.pinModels([model], enforceEntityManager);
70
40
  return model;
71
41
  }
72
42
  count(conditions, enforceEntityManager) {
73
- const entityManager = this.getEntityManager(enforceEntityManager);
74
- if (entityManager) {
75
- return entityManager.count(entity, conditions);
76
- }
77
- return this.repository.count(conditions);
43
+ return this.getRepository(enforceEntityManager).count(conditions);
78
44
  }
79
45
  update(criteria, props, enforceEntityManager) {
80
- const entityManager = this.getEntityManager(enforceEntityManager);
81
- if (entityManager) {
82
- return entityManager.update(entity, criteria, props);
83
- }
84
- return this.repository.update(criteria, props);
46
+ return this.getRepository(enforceEntityManager).update(criteria, props);
85
47
  }
86
- remove(id, enforceEntityManager) {
87
- const entityManager = this.getEntityManager(enforceEntityManager);
88
- if (entityManager) {
89
- return entityManager.delete(entity, id);
90
- }
91
- return this.repository.delete(id);
48
+ remove(conditions, enforceEntityManager) {
49
+ return this.getRepository(enforceEntityManager).delete(conditions);
92
50
  }
93
51
  createQueryBuilder(alias, enforceEntityManager) {
94
- const entityManager = this.getEntityManager(enforceEntityManager);
95
- if (entityManager) {
96
- return entityManager.createQueryBuilder(entity, alias);
52
+ return this.getRepository(enforceEntityManager).createQueryBuilder(alias);
53
+ }
54
+ pinModels(models, enforceEntityManager) {
55
+ // The repository is always pinned, even when an entityManager is also enforced below.
56
+ // An ambient transaction's manager expires once the transaction ends, but this pin is
57
+ // permanent, so it's what keeps an ambient-created entity usable afterward — while the
58
+ // transaction is still active, AbstractOrmEntity's own live ambient check already routes
59
+ // .save() through it correctly, so nothing is lost. For the enforced case specifically,
60
+ // this doesn't change resolution yet (the enforced manager still takes priority whenever
61
+ // it's set) — it just makes a safe fallback available for later.
62
+ models.forEach((m) => m.setRepository(this.repository));
63
+ if (enforceEntityManager) {
64
+ models.forEach((m) => m.setEntityManager(enforceEntityManager));
97
65
  }
98
- return this.repository.createQueryBuilder(alias);
66
+ }
67
+ getRepository(enforceEntityManager) {
68
+ const entityManager = this.getEntityManager(enforceEntityManager);
69
+ return entityManager ? entityManager.getRepository(entity) : this.repository;
99
70
  }
100
71
  getEntityManager(enforceEntityManager) {
101
72
  return enforceEntityManager ?? this.contextEntityManager;
102
73
  }
103
74
  get contextEntityManager() {
104
- return transaction_context_1.txStorage.getStore()?.manager;
75
+ return transaction_context_1.txStorage.getStore()?.get(this.repository.manager.connection);
105
76
  }
106
77
  }
107
78
  __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"abstract-orm.service.js","sourceRoot":"","sources":["../../src/services/abstract-orm.service.ts"],"names":[],"mappings":";;;;;;;;;;;AAqCA,gDA2HC;AAhKD,qCAUgB;AAGhB,6CAAkD;AAElD,oEAAsD;AAsBtD,SAAgB,kBAAkB,CAA8B,MAAsB;IAClF,MAAM,sBAAsB;QAExB,UAAU,CAAgB;QAEnB,KAAK,CAAC,MAAM,CAAC,KAAqB,EAAE,oBAAoC;YAC3E,MAAM,aAAa,GAAG,IAAI,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,CAAA;YAEjE,MAAM,KAAK,GAAG,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YAEjG,IAAI,aAAa,EAAE,CAAC;gBAChB,MAAM,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YACnC,CAAC;iBAAM,CAAC;gBACJ,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YACrC,CAAC;YAED,IAAI,oBAAoB,EAAE,CAAC;gBACvB,KAAK,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,CAAA;YAChD,CAAC;iBAAM,CAAC;gBACJ,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,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6 +1,6 @@
1
- import { DataSource } from 'typeorm';
1
+ import { DataSource, EntityManager } from 'typeorm';
2
2
  export declare class TransactionService {
3
3
  private readonly dataSource;
4
4
  constructor(dataSource: DataSource);
5
- transaction<T>(fn: () => Promise<T>): Promise<T>;
5
+ transaction<T>(fn: (manager: EntityManager) => Promise<T>): Promise<T>;
6
6
  }
@@ -19,12 +19,15 @@ let TransactionService = class TransactionService {
19
19
  this.dataSource = dataSource;
20
20
  }
21
21
  async transaction(fn) {
22
- const existing = transaction_context_1.txStorage.getStore()?.manager;
23
- if (existing) {
24
- return fn();
25
- }
26
- return this.dataSource.transaction(async (manager) => {
27
- return transaction_context_1.txStorage.run({ manager }, fn);
22
+ const currentStore = transaction_context_1.txStorage.getStore();
23
+ const manager = currentStore?.get(this.dataSource) ?? this.dataSource.manager;
24
+ return manager.transaction(async (txManager) => {
25
+ // Copy rather than mutate: the current store may still be referenced by sibling
26
+ // async branches (concurrent code that forked from the same ambient context before
27
+ // this call), which must not see this DataSource's entry appear underneath them.
28
+ const nextStore = new Map(currentStore);
29
+ nextStore.set(this.dataSource, txManager);
30
+ return transaction_context_1.txStorage.run(nextStore, () => fn(txManager));
28
31
  });
29
32
  }
30
33
  };
@@ -1 +1 @@
1
- {"version":3,"file":"transaction.service.js","sourceRoot":"","sources":["../../src/services/transaction.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAmD;AACnD,2CAA2C;AAC3C,oEAAsD;AAG/C,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IACE;IAA7B,YAA6B,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;IAAG,CAAC;IAEhD,KAAK,CAAC,WAAW,CAAI,EAAoB;QAC5C,MAAM,QAAQ,GAAG,+BAAS,CAAC,QAAQ,EAAE,EAAE,OAAO,CAAA;QAC9C,IAAI,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,EAAE,CAAA;QACf,CAAC;QAED,OAAO,IAAI,CAAC,UAAU,CAAC,WAA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@@
1
+ import { Constructor } from '../lib/constructor';
2
+ export declare const GENERATED_COLUMNS: unique symbol;
3
+ export declare function addGeneratedColumn(constructor: Constructor, column: GeneratedColumnMetadata): void;
4
+ export declare function getGeneratedColumns(constructor: Constructor): GeneratedColumnMetadata[];
5
+ type GeneratedColumnMetadata = {
6
+ propertyKey: string;
7
+ generator: (() => unknown) | null;
8
+ };
9
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GENERATED_COLUMNS = void 0;
4
+ exports.addGeneratedColumn = addGeneratedColumn;
5
+ exports.getGeneratedColumns = getGeneratedColumns;
6
+ exports.GENERATED_COLUMNS = Symbol('GENERATED_COLUMNS');
7
+ // Recorded per-class as OWN metadata only (never merged with an ancestor's at write time), so a
8
+ // subclass redeclaring a column always shadows its parent's entry for that property instead of
9
+ // stacking alongside it. `generator: null` explicitly opts a property out of an ancestor's
10
+ // auto-generation, distinct from a subclass saying nothing about the property at all.
11
+ function addGeneratedColumn(constructor, column) {
12
+ const existing = (Reflect.getOwnMetadata(exports.GENERATED_COLUMNS, constructor) ?? []);
13
+ Reflect.defineMetadata(exports.GENERATED_COLUMNS, [...existing, column], constructor);
14
+ }
15
+ // Walks the prototype chain from the topmost ancestor down to `constructor`, merging each class's
16
+ // OWN entries by propertyKey so a more-derived class's declaration always wins over an inherited one.
17
+ function getGeneratedColumns(constructor) {
18
+ const chain = [];
19
+ for (let current = constructor; current; current = Object.getPrototypeOf(current)) {
20
+ chain.unshift(current);
21
+ }
22
+ const byPropertyKey = new Map();
23
+ for (const ctor of chain) {
24
+ const ownColumns = (Reflect.getOwnMetadata(exports.GENERATED_COLUMNS, ctor) ?? []);
25
+ for (const column of ownColumns) {
26
+ byPropertyKey.set(column.propertyKey, column);
27
+ }
28
+ }
29
+ return [...byPropertyKey.values()];
30
+ }
31
+ //# sourceMappingURL=generated-column.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated-column.util.js","sourceRoot":"","sources":["../../src/utils/generated-column.util.ts"],"names":[],"mappings":";;;AAQA,gDAGC;AAID,kDAmBC;AAhCY,QAAA,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAA;AAE5D,gGAAgG;AAChG,+FAA+F;AAC/F,2FAA2F;AAC3F,sFAAsF;AACtF,SAAgB,kBAAkB,CAAC,WAAwB,EAAE,MAA+B;IACxF,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,yBAAiB,EAAE,WAAW,CAAC,IAAI,EAAE,CAA8B,CAAA;IAC5G,OAAO,CAAC,cAAc,CAAC,yBAAiB,EAAE,CAAC,GAAG,QAAQ,EAAE,MAAM,CAAC,EAAE,WAAW,CAAC,CAAA;AACjF,CAAC;AAED,kGAAkG;AAClG,sGAAsG;AACtG,SAAgB,mBAAmB,CAAC,WAAwB;IACxD,MAAM,KAAK,GAAkB,EAAE,CAAA;IAC/B,KACI,IAAI,OAAO,GAAuB,WAAW,EAC7C,OAAO,EACP,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAuB,EAChE,CAAC;QACC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC1B,CAAC;IAED,MAAM,aAAa,GAAG,IAAI,GAAG,EAAmC,CAAA;IAChE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,MAAM,UAAU,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,yBAAiB,EAAE,IAAI,CAAC,IAAI,EAAE,CAA8B,CAAA;QACvG,KAAK,MAAM,MAAM,IAAI,UAAU,EAAE,CAAC;YAC9B,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;QACjD,CAAC;IACL,CAAC;IAED,OAAO,CAAC,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC,CAAA;AACtC,CAAC"}
package/package.json CHANGED
@@ -1,36 +1,100 @@
1
1
  {
2
2
  "name": "@artenc/nest-orm",
3
- "version": "1.3.0",
3
+ "version": "2.0.0",
4
4
  "description": "Helper utility to work with TypeORM",
5
+ "keywords": [
6
+ "nestjs",
7
+ "nest",
8
+ "typeorm",
9
+ "orm",
10
+ "typescript",
11
+ "transaction",
12
+ "transactions",
13
+ "savepoint",
14
+ "async-local-storage",
15
+ "uuid",
16
+ "crud",
17
+ "repository"
18
+ ],
5
19
  "author": "artenc",
6
20
  "license": "MIT",
7
21
  "private": false,
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://gitlab.com/nestjs-utility-modules/nest-orm.git"
25
+ },
26
+ "homepage": "https://gitlab.com/nestjs-utility-modules/nest-orm#readme",
27
+ "bugs": {
28
+ "url": "https://gitlab.com/nestjs-utility-modules/nest-orm/-/issues"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
8
33
  "main": "dist/index.js",
9
- "module": "dist/index.js",
10
34
  "types": "dist/index.d.ts",
35
+ "exports": {
36
+ ".": {
37
+ "types": "./dist/index.d.ts",
38
+ "require": "./dist/index.js",
39
+ "import": "./dist/index.js"
40
+ }
41
+ },
42
+ "sideEffects": false,
11
43
  "files": [
12
44
  "dist"
13
45
  ],
14
46
  "scripts": {
15
47
  "build": "nest build",
48
+ "prepack": "npm test && npm run build",
16
49
  "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
17
- "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
50
+ "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
51
+ "test": "jest",
52
+ "test:watch": "jest --watch",
53
+ "test:cov": "jest --coverage"
54
+ },
55
+ "jest": {
56
+ "roots": [
57
+ "<rootDir>/test"
58
+ ],
59
+ "testRegex": ".*\\.spec\\.ts$",
60
+ "transform": {
61
+ "^.+\\.ts$": "ts-jest"
62
+ },
63
+ "setupFiles": [
64
+ "reflect-metadata"
65
+ ],
66
+ "testEnvironment": "node",
67
+ "collectCoverageFrom": [
68
+ "src/**/*.ts"
69
+ ],
70
+ "coverageDirectory": "coverage"
18
71
  },
19
72
  "dependencies": {
20
- "@nestjs/typeorm": "^11.0.0",
21
73
  "class-transformer": "^0.5.1",
22
- "typeorm": "^0.3.1"
74
+ "uuid": "^11.1.0"
75
+ },
76
+ "peerDependencies": {
77
+ "@nestjs/common": "^10.0.0 || ^11.0.0",
78
+ "@nestjs/typeorm": "^10.0.0 || ^11.0.0",
79
+ "typeorm": "^0.3.31"
23
80
  },
24
81
  "devDependencies": {
25
82
  "@eslint/js": "^9.18.0",
26
83
  "@nestjs/cli": "^11.0.0",
84
+ "@nestjs/common": "^11.0.0",
27
85
  "@nestjs/schematics": "^11.0.0",
86
+ "@nestjs/typeorm": "^11.0.0",
87
+ "@types/jest": "^30.0.0",
28
88
  "@types/node": "^22.10.7",
29
89
  "eslint": "^9.18.0",
30
90
  "eslint-config-prettier": "^10.0.1",
31
91
  "eslint-plugin-prettier": "^5.2.2",
32
92
  "globals": "^16.0.0",
93
+ "jest": "^30.5.0",
33
94
  "prettier": "^3.4.2",
95
+ "reflect-metadata": "^0.2.2",
96
+ "ts-jest": "^29.4.12",
97
+ "typeorm": "^0.3.31",
34
98
  "typescript": "^5.7.3",
35
99
  "typescript-eslint": "^8.20.0"
36
100
  }