@onivoro/server-typeorm-postgres 22.0.9 → 22.0.11

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,4 +1,4 @@
1
- import { EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere } from 'typeorm';
1
+ import { EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere, ObjectLiteral, Repository } 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';
@@ -6,9 +6,9 @@ import { TTableMeta } from '../types/table-meta.type';
6
6
  export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEntity, FindOneOptions<TEntity>, FindManyOptions<TEntity>, FindOptionsWhere<TEntity>, QueryDeepPartialEntity<TEntity>> {
7
7
  entityType: any;
8
8
  entityManager: EntityManager;
9
- protected columns: TKeysOf<TEntity, TTableMeta>;
10
- protected table: string;
11
- protected schema: string;
9
+ columns: TKeysOf<TEntity, TTableMeta>;
10
+ table: string;
11
+ schema: string;
12
12
  debug: boolean;
13
13
  constructor(entityType: any, entityManager: EntityManager);
14
14
  forTransaction(entityManager: EntityManager): TypeOrmRepository<TEntity>;
@@ -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(): import("typeorm").Repository<import("typeorm").ObjectLiteral>;
24
+ get repo(): Repository<ObjectLiteral>;
25
25
  protected insertAndReturn(entityToInsert: TEntity): Promise<TEntity>;
26
26
  protected insertAndReturnMany(entitiesToInsert: TEntity[]): Promise<TEntity[]>;
27
27
  protected getSchemaPrefix(): string;
@@ -11,13 +11,17 @@ class TypeOrmRepository {
11
11
  constructor(entityType, entityManager) {
12
12
  this.entityType = entityType;
13
13
  this.entityManager = entityManager;
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
- });
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
+ }
21
25
  }
22
26
  forTransaction(entityManager) {
23
27
  return new this.constructor(this.entityType, entityManager);
@@ -54,7 +58,13 @@ class TypeOrmRepository {
54
58
  await this.repo.update(options, body);
55
59
  }
56
60
  get repo() {
57
- return this.entityManager.getRepository(this.entityType);
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
+ }
58
68
  }
59
69
  async insertAndReturn(entityToInsert) {
60
70
  return (await this.insertAndReturnMany([entityToInsert]))[0];
@@ -1,4 +1,4 @@
1
- import { EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere } from 'typeorm';
1
+ import { EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere, ObjectLiteral, Repository } 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';
@@ -6,9 +6,9 @@ import { TTableMeta } from '../types/table-meta.type';
6
6
  export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEntity, FindOneOptions<TEntity>, FindManyOptions<TEntity>, FindOptionsWhere<TEntity>, QueryDeepPartialEntity<TEntity>> {
7
7
  entityType: any;
8
8
  entityManager: EntityManager;
9
- protected columns: TKeysOf<TEntity, TTableMeta>;
10
- protected table: string;
11
- protected schema: string;
9
+ columns: TKeysOf<TEntity, TTableMeta>;
10
+ table: string;
11
+ schema: string;
12
12
  debug: boolean;
13
13
  constructor(entityType: any, entityManager: EntityManager);
14
14
  forTransaction(entityManager: EntityManager): TypeOrmRepository<TEntity>;
@@ -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(): import("typeorm").Repository<import("typeorm").ObjectLiteral>;
24
+ get repo(): Repository<ObjectLiteral>;
25
25
  protected insertAndReturn(entityToInsert: TEntity): Promise<TEntity>;
26
26
  protected insertAndReturnMany(entitiesToInsert: TEntity[]): Promise<TEntity[]>;
27
27
  protected getSchemaPrefix(): string;
@@ -11,13 +11,17 @@ class TypeOrmRepository {
11
11
  constructor(entityType, entityManager) {
12
12
  this.entityType = entityType;
13
13
  this.entityManager = entityManager;
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
- });
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
+ }
21
25
  }
22
26
  forTransaction(entityManager) {
23
27
  return new this.constructor(this.entityType, entityManager);
@@ -54,7 +58,13 @@ class TypeOrmRepository {
54
58
  await this.repo.update(options, body);
55
59
  }
56
60
  get repo() {
57
- return this.entityManager.getRepository(this.entityType);
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
+ }
58
68
  }
59
69
  async insertAndReturn(entityToInsert) {
60
70
  return (await this.insertAndReturnMany([entityToInsert]))[0];
@@ -1,4 +1,4 @@
1
- import { EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere } from 'typeorm';
1
+ import { EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere, ObjectLiteral, Repository } 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';
@@ -6,9 +6,9 @@ import { TTableMeta } from '../types/table-meta.type';
6
6
  export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEntity, FindOneOptions<TEntity>, FindManyOptions<TEntity>, FindOptionsWhere<TEntity>, QueryDeepPartialEntity<TEntity>> {
7
7
  entityType: any;
8
8
  entityManager: EntityManager;
9
- protected columns: TKeysOf<TEntity, TTableMeta>;
10
- protected table: string;
11
- protected schema: string;
9
+ columns: TKeysOf<TEntity, TTableMeta>;
10
+ table: string;
11
+ schema: string;
12
12
  debug: boolean;
13
13
  constructor(entityType: any, entityManager: EntityManager);
14
14
  forTransaction(entityManager: EntityManager): TypeOrmRepository<TEntity>;
@@ -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(): import("typeorm").Repository<import("typeorm").ObjectLiteral>;
24
+ get repo(): Repository<ObjectLiteral>;
25
25
  protected insertAndReturn(entityToInsert: TEntity): Promise<TEntity>;
26
26
  protected insertAndReturnMany(entitiesToInsert: TEntity[]): Promise<TEntity[]>;
27
27
  protected getSchemaPrefix(): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onivoro/server-typeorm-postgres",
3
- "version": "22.0.9",
3
+ "version": "22.0.11",
4
4
  "repository": {
5
5
  "url": "git+https://github.com/onivoro/server-typeorm-postgres.git"
6
6
  },