@wisemen/nestjs-typeorm 0.0.25 → 0.0.27

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.
@@ -3,4 +3,8 @@ export declare class TypeOrmRepository<T extends ObjectLiteral> extends Reposito
3
3
  constructor(entity: EntityTarget<T>, manager: EntityManager);
4
4
  findInBatches(options: FindOneOptions<T>, batchSize: number): AsyncGenerator<T[], void, void>;
5
5
  findByInBatches(where: FindOptionsWhere<T> | FindOptionsWhere<T>[], batchSize: number): AsyncGenerator<T[], void, void>;
6
+ private addBatchingToOrder;
7
+ private addBatchingToWhere;
8
+ private addBatchConditionToWhereClause;
9
+ private getKeyCondition;
6
10
  }
@@ -1,23 +1,16 @@
1
- import { MoreThan, Repository } from 'typeorm';
1
+ import { And, Equal, FindOperator, LessThan, MoreThan, Repository } from 'typeorm';
2
2
  import { createTransactionManagerProxy } from './transaction.js';
3
3
  export class TypeOrmRepository extends Repository {
4
4
  constructor(entity, manager) {
5
5
  super(entity, createTransactionManagerProxy(manager));
6
6
  }
7
7
  async *findInBatches(options, batchSize) {
8
- if (this.metadata.primaryColumns.length !== 1) {
9
- throw new Error(`Entity ${this.metadata.name} has a composite primary key and cannot be fetched in batches`);
10
- }
11
- const primaryKey = this.metadata.primaryColumns[0].propertyName;
12
- let lastPrimaryKeyValue = undefined;
8
+ const primaryKeys = this.metadata.primaryColumns.map(column => column.propertyName);
13
9
  let entities = [];
10
+ let lastEntity = undefined;
14
11
  do {
15
- const where = lastPrimaryKeyValue !== undefined
16
- ? { ...options.where, [primaryKey]: MoreThan(lastPrimaryKeyValue) }
17
- : options.where;
18
- const order = options.order !== undefined && primaryKey in options.order
19
- ? options.order
20
- : { ...options.order, [primaryKey]: 'ASC' };
12
+ const order = this.addBatchingToOrder(options.order, primaryKeys);
13
+ const where = this.addBatchingToWhere(options.where, order, lastEntity);
21
14
  entities = await this.find({
22
15
  ...options,
23
16
  where,
@@ -27,11 +20,58 @@ export class TypeOrmRepository extends Repository {
27
20
  if (entities.length === 0)
28
21
  return;
29
22
  yield entities;
30
- lastPrimaryKeyValue = entities.at(-1)?.[primaryKey];
31
- } while (lastPrimaryKeyValue !== undefined);
23
+ lastEntity = entities.at(-1);
24
+ } while (entities.length === batchSize);
32
25
  }
33
26
  findByInBatches(where, batchSize) {
34
27
  return this.findInBatches({ where }, batchSize);
35
28
  }
29
+ addBatchingToOrder(order, keys) {
30
+ const batchOrder = Object.fromEntries(keys.map((key) => [key, order?.[key] ?? 'ASC']));
31
+ return {
32
+ ...order,
33
+ ...batchOrder
34
+ };
35
+ }
36
+ addBatchingToWhere(where, order, lastEntity) {
37
+ if (lastEntity === undefined) {
38
+ return where;
39
+ }
40
+ if (Array.isArray(where)) {
41
+ return where.flatMap(whereClause => this.addBatchConditionToWhereClause(whereClause, order, lastEntity));
42
+ }
43
+ return this.addBatchConditionToWhereClause(where, order, lastEntity);
44
+ }
45
+ addBatchConditionToWhereClause(where, order, lastEntity) {
46
+ const clauses = [];
47
+ const keys = Object.keys(order);
48
+ for (let i = keys.length - 1; i >= 0; i--) {
49
+ const key = keys[i];
50
+ const keyLastValue = lastEntity[key];
51
+ const preceedingKeys = keys.slice(0, i);
52
+ const preceedingKeysLastValues = preceedingKeys.map(k => lastEntity[k]);
53
+ const preceedingKeysWhere = Object.fromEntries(preceedingKeys.map((k, i) => [k, preceedingKeysLastValues[i]]));
54
+ const clause = {
55
+ ...where,
56
+ ...preceedingKeysWhere,
57
+ [key]: this.getKeyCondition(where, order, key, keyLastValue)
58
+ };
59
+ clauses.push(clause);
60
+ }
61
+ return clauses;
62
+ }
63
+ getKeyCondition(where, order, key, lastKeyValue) {
64
+ const existingCondition = where?.[key];
65
+ const batchCondition = order?.[key] === 'ASC' ? MoreThan(lastKeyValue) : LessThan(lastKeyValue);
66
+ if (existingCondition === undefined) {
67
+ return batchCondition;
68
+ }
69
+ else if (existingCondition instanceof FindOperator) {
70
+ return And(batchCondition, existingCondition);
71
+ }
72
+ else {
73
+ return And(batchCondition, Equal(existingCondition));
74
+ }
75
+ }
36
76
  }
37
77
  //# sourceMappingURL=repository.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"repository.js","sourceRoot":"","sources":["../../lib/extensions/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6F,QAAQ,EAAiB,UAAU,EAAE,MAAM,SAAS,CAAA;AACxJ,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAA;AAEhE,MAAM,OAAO,iBAA2C,SAAQ,UAAc;IAC5E,YAAa,MAAuB,EAAE,OAAsB;QAC1D,KAAK,CAAC,MAAM,EAAE,6BAA6B,CAAC,OAAO,CAAC,CAAC,CAAA;IACvD,CAAC;IAED,KAAK,CAAA,CAAE,aAAa,CAClB,OAA0B,EAC1B,SAAiB;QAEjB,IAAI,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC9C,MAAM,IAAI,KAAK,CAAC,UAAU,IAAI,CAAC,QAAQ,CAAC,IAAI,+DAA+D,CAAC,CAAA;QAC9G,CAAC;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,YAAY,CAAA;QAE/D,IAAI,mBAAmB,GAAY,SAAS,CAAA;QAC5C,IAAI,QAAQ,GAAQ,EAAE,CAAA;QAEtB,GAAG,CAAC;YACF,MAAM,KAAK,GAAG,mBAAmB,KAAK,SAAS;gBAC7C,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,mBAAmB,CAAC,EAAE;gBACnE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAA;YACjB,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,KAAK,SAAS,IAAI,UAAU,IAAI,OAAO,CAAC,KAAK;gBACtE,CAAC,CAAC,OAAO,CAAC,KAAK;gBACf,CAAC,CAAC,EAAE,GAAG,O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AAe,CACrB,KAAsC,EACtC,KAAsC,EACtC,GAAW,EACX,YAAqB;QAErB,MAAM,iBAAiB,GAAG,KAAK,EAAE,CAAC,GAAG,CAAC,CAAA;QACtC,MAAM,cAAc,GAAG,KAAK,EAAE,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAA;QAE/F,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;YACpC,OAAO,cAAc,CAAA;QACvB,CAAC;aAAM,IAAI,iBAAiB,YAAY,YAAY,EAAE,CAAC;YACrD,OAAO,GAAG,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAA;QAC/C,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,CAAC,cAAc,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAA;QACtD,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,90 @@
1
+ import { after, before, describe, it } from "node:test";
2
+ import { expect } from 'expect';
3
+ import { dataSource } from "./sql/datasource.js";
4
+ import { UserEntity } from "./test.entity.js";
5
+ import { TypeOrmRepository } from "../repository.js";
6
+ import { LessThan } from "typeorm";
7
+ describe('Monetary calculations', () => {
8
+ let repository;
9
+ before(async () => {
10
+ await dataSource.initialize();
11
+ await dataSource.synchronize(true);
12
+ repository = new TypeOrmRepository(UserEntity, dataSource.manager);
13
+ await repository.insert([
14
+ { id: 1, name: "Alice", age: 25 },
15
+ { id: 2, name: "Bob", age: 30 },
16
+ { id: 3, name: "Charlie", age: 28 },
17
+ { id: 4, name: "Diana", age: 22 },
18
+ { id: 5, name: "Eve", age: 35 }
19
+ ]);
20
+ });
21
+ after(async () => {
22
+ await dataSource.destroy();
23
+ });
24
+ it('finds in batches without filters or sorting', async () => {
25
+ const result = repository.findInBatches({}, 2);
26
+ let batches = [];
27
+ for await (const batch of result) {
28
+ batches.push(batch);
29
+ }
30
+ expect(batches).toHaveLength(3);
31
+ expect(batches[0]).toHaveLength(2);
32
+ expect(batches[1]).toHaveLength(2);
33
+ expect(batches[2]).toHaveLength(1);
34
+ expect(batches[0][0].name).toBe("Alice");
35
+ expect(batches[0][1].name).toBe("Bob");
36
+ expect(batches[1][0].name).toBe("Charlie");
37
+ expect(batches[1][1].name).toBe("Diana");
38
+ expect(batches[2][0].name).toBe("Eve");
39
+ });
40
+ it('finds in batches without filters with sorting', async () => {
41
+ const result = repository.findInBatches({
42
+ order: { name: 'DESC' }
43
+ }, 2);
44
+ let batches = [];
45
+ for await (const batch of result) {
46
+ batches.push(batch);
47
+ }
48
+ expect(batches).toHaveLength(3);
49
+ expect(batches[0]).toHaveLength(2);
50
+ expect(batches[1]).toHaveLength(2);
51
+ expect(batches[2]).toHaveLength(1);
52
+ expect(batches[0][0].name).toBe("Eve");
53
+ expect(batches[0][1].name).toBe("Diana");
54
+ expect(batches[1][0].name).toBe("Charlie");
55
+ expect(batches[1][1].name).toBe("Bob");
56
+ expect(batches[2][0].name).toBe("Alice");
57
+ });
58
+ it('finds in batches with filters without sorting', async () => {
59
+ const result = repository.findInBatches({
60
+ where: { age: LessThan(30) }
61
+ }, 2);
62
+ let batches = [];
63
+ for await (const batch of result) {
64
+ batches.push(batch);
65
+ }
66
+ expect(batches).toHaveLength(2);
67
+ expect(batches[0]).toHaveLength(2);
68
+ expect(batches[1]).toHaveLength(1);
69
+ expect(batches[0][0].name).toBe('Alice');
70
+ expect(batches[0][1].name).toBe('Charlie');
71
+ expect(batches[1][0].name).toBe('Diana');
72
+ });
73
+ it('finds in batches with filters with sorting', async () => {
74
+ const result = repository.findInBatches({
75
+ where: { age: LessThan(30) },
76
+ order: { age: 'ASC' }
77
+ }, 2);
78
+ let batches = [];
79
+ for await (const batch of result) {
80
+ batches.push(batch);
81
+ }
82
+ expect(batches).toHaveLength(2);
83
+ expect(batches[0]).toHaveLength(2);
84
+ expect(batches[1]).toHaveLength(1);
85
+ expect(batches[0][0].name).toBe('Diana');
86
+ expect(batches[0][1].name).toBe('Alice');
87
+ expect(batches[1][0].name).toBe('Charlie');
88
+ });
89
+ });
90
+ //# sourceMappingURL=repository-find-in-batches.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository-find-in-batches.test.js","sourceRoot":"","sources":["../../../lib/extensions/tests/repository-find-in-batches.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAElC,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,IAAI,UAAyC,CAAA;IAC7C,MAAM,CAAC,KAAK,IAAI,EAAE;QAChB,MAAM,UAAU,CAAC,UAAU,EAAE,CAAA;QAC7B,MAAM,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;QAElC,UAAU,GAAG,IAAI,iBAAiB,CAAC,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,CAAA;QAElE,MAAM,UAAU,CAAC,MAAM,CAAC;YACtB,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAI,GAAG,EAAE,EAAE,EAAE;YACnC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAM,GAAG,EAAE,EAAE,EAAE;YACnC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,EAAE,EAAE;YACnC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAI,GAAG,EAAE,EAAE,EAAE;YACnC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AC1D,MAAM,MAAM,GAAG,UAAU,CAAC,aAAa,CAAC;YACtC,KAAK,EAAE,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC,EAAE;YAC5B,KAAK,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE;SACtB,EAAE,CAAC,CAAC,CAAA;QAEL,IAAI,OAAO,GAAmB,EAAE,CAAA;QAEhC,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YACjC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACrB,CAAC;QAED,MAAM,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;QAC/B,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;QAClC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;QAClC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACxC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACxC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IAC5C,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ import { DataSource } from "typeorm";
2
+ export declare const dataSource: DataSource;
@@ -0,0 +1,16 @@
1
+ import { DataSource } from "typeorm";
2
+ import { SnakeNamingStrategy } from "../../../naming/snake-case.naming-strategy.js";
3
+ import { sslHelper } from "../../../helpers/ssl.js";
4
+ export const dataSource = new DataSource({
5
+ name: 'default',
6
+ type: 'postgres',
7
+ url: process.env.DATABASE_URI,
8
+ ssl: sslHelper(process.env.DATABASE_SSL),
9
+ extra: { max: 50 },
10
+ logging: false,
11
+ synchronize: false,
12
+ migrationsRun: true,
13
+ entities: ['dist/**/*.entity.js'],
14
+ namingStrategy: new SnakeNamingStrategy()
15
+ });
16
+ //# sourceMappingURL=datasource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datasource.js","sourceRoot":"","sources":["../../../../lib/extensions/tests/sql/datasource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,mBAAmB,EAAE,MAAM,+CAA+C,CAAC;AACpF,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC;IACvC,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,UAAU;IAChB,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY;IAC7B,GAAG,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;IACxC,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE;IAClB,OAAO,EAAE,KAAK;IACd,WAAW,EAAE,KAAK;IAClB,aAAa,EAAE,IAAI;IACnB,QAAQ,EAAE,CAAC,qBAAqB,CAAC;IACjC,cAAc,EAAE,IAAI,mBAAmB,EAAE;CAC1C,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ export declare class UserEntity {
2
+ id: number;
3
+ name: string;
4
+ age: number;
5
+ }
@@ -0,0 +1,32 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
11
+ let UserEntity = class UserEntity {
12
+ id;
13
+ name;
14
+ age;
15
+ };
16
+ __decorate([
17
+ PrimaryGeneratedColumn(),
18
+ __metadata("design:type", Number)
19
+ ], UserEntity.prototype, "id", void 0);
20
+ __decorate([
21
+ Column({ type: 'varchar' }),
22
+ __metadata("design:type", String)
23
+ ], UserEntity.prototype, "name", void 0);
24
+ __decorate([
25
+ Column({ type: 'int' }),
26
+ __metadata("design:type", Number)
27
+ ], UserEntity.prototype, "age", void 0);
28
+ UserEntity = __decorate([
29
+ Entity()
30
+ ], UserEntity);
31
+ export { UserEntity };
32
+ //# sourceMappingURL=test.entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.entity.js","sourceRoot":"","sources":["../../../lib/extensions/tests/test.entity.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAG1D,IAAM,UAAU,GAAhB,MAAM,UAAU;IAErB,EAAE,CAAQ;IAGV,IAAI,CAAQ;IAGZ,GAAG,CAAQ;CACZ,CAAA;AAPC;IADC,sBAAsB,EAAE;;sCACf;AAGV;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;wCAChB;AAGZ;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;;uCACb;AARA,UAAU;IADtB,MAAM,EAAE;GACI,UAAU,CAStB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wisemen/nestjs-typeorm",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",
@@ -13,13 +13,14 @@
13
13
  "clean": "rm -rf ./dist",
14
14
  "build": "tsc",
15
15
  "pretest": "npm run clean && npm run build",
16
- "test": "node --test",
16
+ "test": "node --env-file=.env --test",
17
17
  "prerelease": "npm run build",
18
18
  "release": "pnpx release-it"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/node": "^24.3.0",
22
22
  "eslint": "^9.33.0",
23
+ "expect": "^30.0.5",
23
24
  "typescript": "^5.9.2"
24
25
  },
25
26
  "author": "Joren Vandeweyer",