@onivoro/server-typeorm-postgres 22.0.11 → 22.0.13

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.
@@ -1,6 +1,8 @@
1
- import { EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere } from 'typeorm';
1
+ import { DataSource, EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere } from 'typeorm';
2
2
  import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
3
3
  import { TypeOrmRepository } from './type-orm-repository.class';
4
+ import { TTableMeta } from '../types/table-meta.type';
5
+ import { TKeysOf } from '@onivoro/isomorphic-common';
4
6
  export declare class RedshiftRepository<TEntity> extends TypeOrmRepository<TEntity> {
5
7
  entityType: any;
6
8
  entityManager: EntityManager;
@@ -19,4 +21,9 @@ export declare class RedshiftRepository<TEntity> extends TypeOrmRepository<TEnti
19
21
  postManyWithoutReturn(entities: Partial<TEntity>[]): Promise<void>;
20
22
  private throwNotImplemented;
21
23
  protected mapPlaceholderExpression(length: number, index: number, column: string): string;
24
+ static buildFromMetadata<TGenericEntity>(dataSource: DataSource, _: {
25
+ schema: string;
26
+ table: string;
27
+ columns: TKeysOf<TGenericEntity, TTableMeta>;
28
+ }): RedshiftRepository<TGenericEntity>;
22
29
  }
@@ -8,12 +8,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
+ var RedshiftRepository_1;
11
12
  Object.defineProperty(exports, "__esModule", { value: true });
12
13
  exports.RedshiftRepository = void 0;
13
14
  const common_1 = require("@nestjs/common");
14
15
  const typeorm_1 = require("typeorm");
15
16
  const type_orm_repository_class_1 = require("./type-orm-repository.class");
16
- let RedshiftRepository = class RedshiftRepository extends type_orm_repository_class_1.TypeOrmRepository {
17
+ let RedshiftRepository = RedshiftRepository_1 = class RedshiftRepository extends type_orm_repository_class_1.TypeOrmRepository {
17
18
  entityType;
18
19
  entityManager;
19
20
  constructor(entityType, entityManager) {
@@ -104,9 +105,25 @@ let RedshiftRepository = class RedshiftRepository extends type_orm_repository_cl
104
105
  const meta = this.columns[column];
105
106
  return meta.type === 'jsonb' ? `JSON_PARSE(${exp})` : exp;
106
107
  }
108
+ static buildFromMetadata(dataSource, _) {
109
+ class GenericRepository extends RedshiftRepository_1 {
110
+ constructor() {
111
+ const entityManager = dataSource.createEntityManager();
112
+ super(Object, {
113
+ ...entityManager,
114
+ getRepository: () => entityManager
115
+ });
116
+ }
117
+ }
118
+ const genericRepository = new GenericRepository();
119
+ genericRepository.schema = _.schema;
120
+ genericRepository.table = _.table;
121
+ genericRepository.columns = _.columns;
122
+ return genericRepository;
123
+ }
107
124
  };
108
125
  exports.RedshiftRepository = RedshiftRepository;
109
- exports.RedshiftRepository = RedshiftRepository = __decorate([
126
+ exports.RedshiftRepository = RedshiftRepository = RedshiftRepository_1 = __decorate([
110
127
  (0, common_1.Injectable)(),
111
128
  __metadata("design:paramtypes", [Object, typeorm_1.EntityManager])
112
129
  ], RedshiftRepository);
@@ -1,4 +1,4 @@
1
- import { EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere, ObjectLiteral, Repository } from 'typeorm';
1
+ import { DataSource, EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere } from 'typeorm';
2
2
  import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
3
3
  import { IEntityProvider } from '../types/entity-provider.interface';
4
4
  import { TKeysOf } from '@onivoro/isomorphic-common';
@@ -21,7 +21,7 @@ export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEnti
21
21
  softDelete(options: FindOptionsWhere<TEntity>): Promise<void>;
22
22
  put(options: FindOptionsWhere<TEntity>, body: QueryDeepPartialEntity<TEntity>): Promise<void>;
23
23
  patch(options: FindOptionsWhere<TEntity>, body: QueryDeepPartialEntity<TEntity>): Promise<void>;
24
- get repo(): Repository<ObjectLiteral>;
24
+ get repo(): import("typeorm").Repository<import("typeorm").ObjectLiteral>;
25
25
  protected insertAndReturn(entityToInsert: TEntity): Promise<TEntity>;
26
26
  protected insertAndReturnMany(entitiesToInsert: TEntity[]): Promise<TEntity[]>;
27
27
  protected getSchemaPrefix(): string;
@@ -54,4 +54,9 @@ export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEnti
54
54
  map(raw: any): TEntity;
55
55
  query(query: string, parameters: any[]): Promise<any[]>;
56
56
  queryAndMap(query: string, parameters: any[]): Promise<TEntity[]>;
57
+ static buildFromMetadata<TGenericEntity>(dataSource: DataSource, _: {
58
+ schema: string;
59
+ table: string;
60
+ columns: TKeysOf<TGenericEntity, TTableMeta>;
61
+ }): TypeOrmRepository<TGenericEntity>;
57
62
  }
@@ -11,17 +11,13 @@ class TypeOrmRepository {
11
11
  constructor(entityType, entityManager) {
12
12
  this.entityType = entityType;
13
13
  this.entityManager = entityManager;
14
- this.table = '';
15
- this.schema = '';
16
- if (this.repo?.metadata?.columns?.length) {
17
- const { tableName, schema } = this.repo.metadata;
18
- this.table = tableName;
19
- this.schema = schema;
20
- this.repo.metadata.columns.forEach((_) => {
21
- const { databasePath, propertyPath, type, isPrimary } = _;
22
- this.columns[propertyPath] = { databasePath, type, propertyPath, isPrimary, default: _.default };
23
- });
24
- }
14
+ const { tableName, schema } = this.repo.metadata;
15
+ this.table = tableName;
16
+ this.schema = schema;
17
+ this.repo.metadata.columns.forEach((_) => {
18
+ const { databasePath, propertyPath, type, isPrimary } = _;
19
+ this.columns[propertyPath] = { databasePath, type, propertyPath, isPrimary, default: _.default };
20
+ });
25
21
  }
26
22
  forTransaction(entityManager) {
27
23
  return new this.constructor(this.entityType, entityManager);
@@ -58,13 +54,7 @@ class TypeOrmRepository {
58
54
  await this.repo.update(options, body);
59
55
  }
60
56
  get repo() {
61
- try {
62
- return this.entityManager.getRepository(this.entityType);
63
- }
64
- catch (error) {
65
- console.error(`EntityManager.getRepository failed. Falling back to EntityManager for basic functionality.`);
66
- return this.entityManager;
67
- }
57
+ return this.entityManager.getRepository(this.entityType);
68
58
  }
69
59
  async insertAndReturn(entityToInsert) {
70
60
  return (await this.insertAndReturnMany([entityToInsert]))[0];
@@ -192,5 +182,21 @@ class TypeOrmRepository {
192
182
  const result = await this.query(query, parameters);
193
183
  return result?.map((_) => this.map(_));
194
184
  }
185
+ static buildFromMetadata(dataSource, _) {
186
+ class GenericRepository extends TypeOrmRepository {
187
+ constructor() {
188
+ const entityManager = dataSource.createEntityManager();
189
+ super(Object, {
190
+ ...entityManager,
191
+ getRepository: () => entityManager
192
+ });
193
+ }
194
+ }
195
+ const genericRepository = new GenericRepository();
196
+ genericRepository.schema = _.schema;
197
+ genericRepository.table = _.table;
198
+ genericRepository.columns = _.columns;
199
+ return genericRepository;
200
+ }
195
201
  }
196
202
  exports.TypeOrmRepository = TypeOrmRepository;
@@ -1,6 +1,8 @@
1
- import { EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere } from 'typeorm';
1
+ import { DataSource, EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere } from 'typeorm';
2
2
  import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
3
3
  import { TypeOrmRepository } from './type-orm-repository.class';
4
+ import { TTableMeta } from '../types/table-meta.type';
5
+ import { TKeysOf } from '@onivoro/isomorphic-common';
4
6
  export declare class RedshiftRepository<TEntity> extends TypeOrmRepository<TEntity> {
5
7
  entityType: any;
6
8
  entityManager: EntityManager;
@@ -19,4 +21,9 @@ export declare class RedshiftRepository<TEntity> extends TypeOrmRepository<TEnti
19
21
  postManyWithoutReturn(entities: Partial<TEntity>[]): Promise<void>;
20
22
  private throwNotImplemented;
21
23
  protected mapPlaceholderExpression(length: number, index: number, column: string): string;
24
+ static buildFromMetadata<TGenericEntity>(dataSource: DataSource, _: {
25
+ schema: string;
26
+ table: string;
27
+ columns: TKeysOf<TGenericEntity, TTableMeta>;
28
+ }): RedshiftRepository<TGenericEntity>;
22
29
  }
@@ -8,12 +8,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
+ var RedshiftRepository_1;
11
12
  Object.defineProperty(exports, "__esModule", { value: true });
12
13
  exports.RedshiftRepository = void 0;
13
14
  const common_1 = require("@nestjs/common");
14
15
  const typeorm_1 = require("typeorm");
15
16
  const type_orm_repository_class_1 = require("./type-orm-repository.class");
16
- let RedshiftRepository = class RedshiftRepository extends type_orm_repository_class_1.TypeOrmRepository {
17
+ let RedshiftRepository = RedshiftRepository_1 = class RedshiftRepository extends type_orm_repository_class_1.TypeOrmRepository {
17
18
  entityType;
18
19
  entityManager;
19
20
  constructor(entityType, entityManager) {
@@ -104,9 +105,25 @@ let RedshiftRepository = class RedshiftRepository extends type_orm_repository_cl
104
105
  const meta = this.columns[column];
105
106
  return meta.type === 'jsonb' ? `JSON_PARSE(${exp})` : exp;
106
107
  }
108
+ static buildFromMetadata(dataSource, _) {
109
+ class GenericRepository extends RedshiftRepository_1 {
110
+ constructor() {
111
+ const entityManager = dataSource.createEntityManager();
112
+ super(Object, {
113
+ ...entityManager,
114
+ getRepository: () => entityManager
115
+ });
116
+ }
117
+ }
118
+ const genericRepository = new GenericRepository();
119
+ genericRepository.schema = _.schema;
120
+ genericRepository.table = _.table;
121
+ genericRepository.columns = _.columns;
122
+ return genericRepository;
123
+ }
107
124
  };
108
125
  exports.RedshiftRepository = RedshiftRepository;
109
- exports.RedshiftRepository = RedshiftRepository = __decorate([
126
+ exports.RedshiftRepository = RedshiftRepository = RedshiftRepository_1 = __decorate([
110
127
  (0, common_1.Injectable)(),
111
128
  __metadata("design:paramtypes", [Object, typeorm_1.EntityManager])
112
129
  ], RedshiftRepository);
@@ -1,4 +1,4 @@
1
- import { EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere, ObjectLiteral, Repository } from 'typeorm';
1
+ import { DataSource, EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere } from 'typeorm';
2
2
  import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
3
3
  import { IEntityProvider } from '../types/entity-provider.interface';
4
4
  import { TKeysOf } from '@onivoro/isomorphic-common';
@@ -21,7 +21,7 @@ export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEnti
21
21
  softDelete(options: FindOptionsWhere<TEntity>): Promise<void>;
22
22
  put(options: FindOptionsWhere<TEntity>, body: QueryDeepPartialEntity<TEntity>): Promise<void>;
23
23
  patch(options: FindOptionsWhere<TEntity>, body: QueryDeepPartialEntity<TEntity>): Promise<void>;
24
- get repo(): Repository<ObjectLiteral>;
24
+ get repo(): import("typeorm").Repository<import("typeorm").ObjectLiteral>;
25
25
  protected insertAndReturn(entityToInsert: TEntity): Promise<TEntity>;
26
26
  protected insertAndReturnMany(entitiesToInsert: TEntity[]): Promise<TEntity[]>;
27
27
  protected getSchemaPrefix(): string;
@@ -54,4 +54,9 @@ export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEnti
54
54
  map(raw: any): TEntity;
55
55
  query(query: string, parameters: any[]): Promise<any[]>;
56
56
  queryAndMap(query: string, parameters: any[]): Promise<TEntity[]>;
57
+ static buildFromMetadata<TGenericEntity>(dataSource: DataSource, _: {
58
+ schema: string;
59
+ table: string;
60
+ columns: TKeysOf<TGenericEntity, TTableMeta>;
61
+ }): TypeOrmRepository<TGenericEntity>;
57
62
  }
@@ -11,17 +11,13 @@ class TypeOrmRepository {
11
11
  constructor(entityType, entityManager) {
12
12
  this.entityType = entityType;
13
13
  this.entityManager = entityManager;
14
- this.table = '';
15
- this.schema = '';
16
- if (this.repo?.metadata?.columns?.length) {
17
- const { tableName, schema } = this.repo.metadata;
18
- this.table = tableName;
19
- this.schema = schema;
20
- this.repo.metadata.columns.forEach((_) => {
21
- const { databasePath, propertyPath, type, isPrimary } = _;
22
- this.columns[propertyPath] = { databasePath, type, propertyPath, isPrimary, default: _.default };
23
- });
24
- }
14
+ const { tableName, schema } = this.repo.metadata;
15
+ this.table = tableName;
16
+ this.schema = schema;
17
+ this.repo.metadata.columns.forEach((_) => {
18
+ const { databasePath, propertyPath, type, isPrimary } = _;
19
+ this.columns[propertyPath] = { databasePath, type, propertyPath, isPrimary, default: _.default };
20
+ });
25
21
  }
26
22
  forTransaction(entityManager) {
27
23
  return new this.constructor(this.entityType, entityManager);
@@ -58,13 +54,7 @@ class TypeOrmRepository {
58
54
  await this.repo.update(options, body);
59
55
  }
60
56
  get repo() {
61
- try {
62
- return this.entityManager.getRepository(this.entityType);
63
- }
64
- catch (error) {
65
- console.error(`EntityManager.getRepository failed. Falling back to EntityManager for basic functionality.`);
66
- return this.entityManager;
67
- }
57
+ return this.entityManager.getRepository(this.entityType);
68
58
  }
69
59
  async insertAndReturn(entityToInsert) {
70
60
  return (await this.insertAndReturnMany([entityToInsert]))[0];
@@ -192,5 +182,21 @@ class TypeOrmRepository {
192
182
  const result = await this.query(query, parameters);
193
183
  return result?.map((_) => this.map(_));
194
184
  }
185
+ static buildFromMetadata(dataSource, _) {
186
+ class GenericRepository extends TypeOrmRepository {
187
+ constructor() {
188
+ const entityManager = dataSource.createEntityManager();
189
+ super(Object, {
190
+ ...entityManager,
191
+ getRepository: () => entityManager
192
+ });
193
+ }
194
+ }
195
+ const genericRepository = new GenericRepository();
196
+ genericRepository.schema = _.schema;
197
+ genericRepository.table = _.table;
198
+ genericRepository.columns = _.columns;
199
+ return genericRepository;
200
+ }
195
201
  }
196
202
  exports.TypeOrmRepository = TypeOrmRepository;
@@ -1,6 +1,8 @@
1
- import { EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere } from 'typeorm';
1
+ import { DataSource, EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere } from 'typeorm';
2
2
  import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
3
3
  import { TypeOrmRepository } from './type-orm-repository.class';
4
+ import { TTableMeta } from '../types/table-meta.type';
5
+ import { TKeysOf } from '@onivoro/isomorphic-common';
4
6
  export declare class RedshiftRepository<TEntity> extends TypeOrmRepository<TEntity> {
5
7
  entityType: any;
6
8
  entityManager: EntityManager;
@@ -19,4 +21,9 @@ export declare class RedshiftRepository<TEntity> extends TypeOrmRepository<TEnti
19
21
  postManyWithoutReturn(entities: Partial<TEntity>[]): Promise<void>;
20
22
  private throwNotImplemented;
21
23
  protected mapPlaceholderExpression(length: number, index: number, column: string): string;
24
+ static buildFromMetadata<TGenericEntity>(dataSource: DataSource, _: {
25
+ schema: string;
26
+ table: string;
27
+ columns: TKeysOf<TGenericEntity, TTableMeta>;
28
+ }): RedshiftRepository<TGenericEntity>;
22
29
  }
@@ -1,4 +1,4 @@
1
- import { EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere, ObjectLiteral, Repository } from 'typeorm';
1
+ import { DataSource, EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere } from 'typeorm';
2
2
  import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
3
3
  import { IEntityProvider } from '../types/entity-provider.interface';
4
4
  import { TKeysOf } from '@onivoro/isomorphic-common';
@@ -21,7 +21,7 @@ export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEnti
21
21
  softDelete(options: FindOptionsWhere<TEntity>): Promise<void>;
22
22
  put(options: FindOptionsWhere<TEntity>, body: QueryDeepPartialEntity<TEntity>): Promise<void>;
23
23
  patch(options: FindOptionsWhere<TEntity>, body: QueryDeepPartialEntity<TEntity>): Promise<void>;
24
- get repo(): Repository<ObjectLiteral>;
24
+ get repo(): import("typeorm").Repository<import("typeorm").ObjectLiteral>;
25
25
  protected insertAndReturn(entityToInsert: TEntity): Promise<TEntity>;
26
26
  protected insertAndReturnMany(entitiesToInsert: TEntity[]): Promise<TEntity[]>;
27
27
  protected getSchemaPrefix(): string;
@@ -54,4 +54,9 @@ export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEnti
54
54
  map(raw: any): TEntity;
55
55
  query(query: string, parameters: any[]): Promise<any[]>;
56
56
  queryAndMap(query: string, parameters: any[]): Promise<TEntity[]>;
57
+ static buildFromMetadata<TGenericEntity>(dataSource: DataSource, _: {
58
+ schema: string;
59
+ table: string;
60
+ columns: TKeysOf<TGenericEntity, TTableMeta>;
61
+ }): TypeOrmRepository<TGenericEntity>;
57
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onivoro/server-typeorm-postgres",
3
- "version": "22.0.11",
3
+ "version": "22.0.13",
4
4
  "repository": {
5
5
  "url": "git+https://github.com/onivoro/server-typeorm-postgres.git"
6
6
  },
@@ -30,9 +30,9 @@
30
30
  "module": ""
31
31
  },
32
32
  "devDependencies": {
33
- "@onivoro/cli": "^22.0.3",
33
+ "@onivoro/cli": "^22.0.8",
34
34
  "@types/jest": "*",
35
- "@types/node": "22.7.9",
35
+ "@types/node": "22.10.2",
36
36
  "typescript": "*"
37
37
  },
38
38
  "engines": {
@@ -40,9 +40,9 @@
40
40
  "npm": "10.9.0"
41
41
  },
42
42
  "dependencies": {
43
- "@nestjs/common": "^10.4.6",
44
- "@nestjs/swagger": "^7.4.2",
45
- "@onivoro/isomorphic-common": "^22.0.1",
43
+ "@nestjs/common": "^10.4.15",
44
+ "@nestjs/swagger": "^8.1.0",
45
+ "@onivoro/isomorphic-common": "^22.0.7",
46
46
  "typeorm": "^0.3.20",
47
47
  "typeorm-naming-strategies": "^4.1.0"
48
48
  }