typeorm 0.3.26-dev.01dddfe → 0.3.26-dev.1ea3a5e

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.
@@ -14,40 +14,66 @@ export interface SapConnectionOptions extends BaseDataSourceOptions, SapConnecti
14
14
  readonly schema?: string;
15
15
  /**
16
16
  * The driver objects
17
- * This defaults to require("hdb-pool")
17
+ * This defaults to require("@sap/hana-client")
18
18
  */
19
19
  readonly driver?: any;
20
20
  /**
21
- * The driver objects
22
- * This defaults to require("@sap/hana-client")
21
+ * @deprecated Use {@link driver} instead.
23
22
  */
24
23
  readonly hanaClientDriver?: any;
25
24
  /**
26
25
  * Pool options.
27
26
  */
28
27
  readonly pool?: {
28
+ /**
29
+ * Maximum number of open connections created by the pool, each of which
30
+ * may be in the pool waiting to be reused or may no longer be in the
31
+ * pool and actively being used (default: 10).
32
+ */
33
+ readonly maxConnectedOrPooled?: number;
34
+ /**
35
+ * Defines the maximum time, in seconds, that connections are allowed to
36
+ * remain in the pool before being marked for eviction (default: 30).
37
+ */
38
+ readonly maxPooledIdleTime?: number;
39
+ /**
40
+ * Determines whether or not the pooled connection should be tested for
41
+ * viability before being reused (default: false).
42
+ */
43
+ readonly pingCheck?: boolean;
44
+ /**
45
+ * Maximum number of connections allowed to be in the pool, waiting to
46
+ * be reused (default: 0, no limit).
47
+ */
48
+ readonly poolCapacity?: number;
29
49
  /**
30
50
  * Max number of connections.
51
+ * @deprecated Use {@link maxConnectedOrPooled} instead.
31
52
  */
32
53
  readonly max?: number;
33
54
  /**
34
55
  * Minimum number of connections.
56
+ * @deprecated Obsolete, no alternative exists.
35
57
  */
36
58
  readonly min?: number;
37
59
  /**
38
- * Maximum number of waiting requests allowed. (default=0, no limit).
60
+ * Maximum number of waiting requests allowed.
61
+ * @deprecated Obsolete, no alternative exists.
39
62
  */
40
63
  readonly maxWaitingRequests?: number;
41
64
  /**
42
- * Max milliseconds a request will wait for a resource before timing out. (default=5000)
65
+ * Max milliseconds a request will wait for a resource before timing out.
66
+ * @deprecated Obsolete, no alternative exists.
43
67
  */
44
68
  readonly requestTimeout?: number;
45
69
  /**
46
- * How often to run resource timeout checks. (default=0, disabled)
70
+ * How often to run resource timeout checks.
71
+ * @deprecated Obsolete, no alternative exists.
47
72
  */
48
73
  readonly checkInterval?: number;
49
74
  /**
50
- * Idle timeout
75
+ * Idle timeout (in milliseconds).
76
+ * @deprecated Use {@link maxPooledIdleTime} (in seconds) instead .
51
77
  */
52
78
  readonly idleTimeout?: number;
53
79
  /**
@@ -56,5 +82,4 @@ export interface SapConnectionOptions extends BaseDataSourceOptions, SapConnecti
56
82
  */
57
83
  readonly poolErrorHandler?: (err: any) => any;
58
84
  };
59
- readonly poolSize?: never;
60
85
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/driver/sap/SapConnectionOptions.ts"],"names":[],"mappings":"","file":"SapConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\nimport { SapConnectionCredentialsOptions } from \"./SapConnectionCredentialsOptions\"\n\n/**\n * SAP Hana specific connection options.\n */\nexport interface SapConnectionOptions\n extends BaseDataSourceOptions,\n SapConnectionCredentialsOptions {\n /**\n * Database type.\n */\n readonly type: \"sap\"\n\n /**\n * Database schema.\n */\n readonly schema?: string\n\n /**\n * The driver objects\n * This defaults to require(\"hdb-pool\")\n */\n readonly driver?: any\n\n /**\n * The driver objects\n * This defaults to require(\"@sap/hana-client\")\n */\n readonly hanaClientDriver?: any\n\n /**\n * Pool options.\n */\n readonly pool?: {\n /**\n * Max number of connections.\n */\n readonly max?: number\n\n /**\n * Minimum number of connections.\n */\n readonly min?: number\n\n /**\n * Maximum number of waiting requests allowed. (default=0, no limit).\n */\n readonly maxWaitingRequests?: number\n /**\n * Max milliseconds a request will wait for a resource before timing out. (default=5000)\n */\n readonly requestTimeout?: number\n /**\n * How often to run resource timeout checks. (default=0, disabled)\n */\n readonly checkInterval?: number\n /**\n * Idle timeout\n */\n readonly idleTimeout?: number\n\n /**\n * Function handling errors thrown by drivers pool.\n * Defaults to logging error with `warn` level.\n */\n readonly poolErrorHandler?: (err: any) => any\n }\n\n readonly poolSize?: never\n}\n"],"sourceRoot":"../.."}
1
+ {"version":3,"sources":["../../src/driver/sap/SapConnectionOptions.ts"],"names":[],"mappings":"","file":"SapConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\nimport { SapConnectionCredentialsOptions } from \"./SapConnectionCredentialsOptions\"\n\n/**\n * SAP Hana specific connection options.\n */\nexport interface SapConnectionOptions\n extends BaseDataSourceOptions,\n SapConnectionCredentialsOptions {\n /**\n * Database type.\n */\n readonly type: \"sap\"\n\n /**\n * Database schema.\n */\n readonly schema?: string\n\n /**\n * The driver objects\n * This defaults to require(\"@sap/hana-client\")\n */\n readonly driver?: any\n\n /**\n * @deprecated Use {@link driver} instead.\n */\n readonly hanaClientDriver?: any\n\n /**\n * Pool options.\n */\n readonly pool?: {\n /**\n * Maximum number of open connections created by the pool, each of which\n * may be in the pool waiting to be reused or may no longer be in the\n * pool and actively being used (default: 10).\n */\n readonly maxConnectedOrPooled?: number\n\n /**\n * Defines the maximum time, in seconds, that connections are allowed to\n * remain in the pool before being marked for eviction (default: 30).\n */\n readonly maxPooledIdleTime?: number\n\n /**\n * Determines whether or not the pooled connection should be tested for\n * viability before being reused (default: false).\n */\n readonly pingCheck?: boolean\n\n /**\n * Maximum number of connections allowed to be in the pool, waiting to\n * be reused (default: 0, no limit).\n */\n readonly poolCapacity?: number\n\n /**\n * Max number of connections.\n * @deprecated Use {@link maxConnectedOrPooled} instead.\n */\n readonly max?: number\n\n /**\n * Minimum number of connections.\n * @deprecated Obsolete, no alternative exists.\n */\n readonly min?: number\n\n /**\n * Maximum number of waiting requests allowed.\n * @deprecated Obsolete, no alternative exists.\n */\n readonly maxWaitingRequests?: number\n\n /**\n * Max milliseconds a request will wait for a resource before timing out.\n * @deprecated Obsolete, no alternative exists.\n */\n readonly requestTimeout?: number\n\n /**\n * How often to run resource timeout checks.\n * @deprecated Obsolete, no alternative exists.\n */\n readonly checkInterval?: number\n\n /**\n * Idle timeout (in milliseconds).\n * @deprecated Use {@link maxPooledIdleTime} (in seconds) instead .\n */\n readonly idleTimeout?: number\n\n /**\n * Function handling errors thrown by drivers pool.\n * Defaults to logging error with `warn` level.\n */\n readonly poolErrorHandler?: (err: any) => any\n }\n}\n"],"sourceRoot":"../.."}
@@ -1,15 +1,15 @@
1
1
  import { ColumnType, DataSource, EntityMetadata, ObjectLiteral, Table, TableColumn, TableForeignKey } from "../..";
2
2
  import { ColumnMetadata } from "../../metadata/ColumnMetadata";
3
3
  import { RdbmsSchemaBuilder } from "../../schema-builder/RdbmsSchemaBuilder";
4
+ import { View } from "../../schema-builder/view/View";
4
5
  import { Driver } from "../Driver";
5
6
  import { CteCapabilities } from "../types/CteCapabilities";
6
7
  import { DataTypeDefaults } from "../types/DataTypeDefaults";
7
8
  import { MappedColumnTypes } from "../types/MappedColumnTypes";
8
- import { SapConnectionOptions } from "./SapConnectionOptions";
9
- import { SapQueryRunner } from "./SapQueryRunner";
10
9
  import { ReplicationMode } from "../types/ReplicationMode";
11
- import { View } from "../../schema-builder/view/View";
12
10
  import { UpsertType } from "../types/UpsertType";
11
+ import { SapConnectionOptions } from "./SapConnectionOptions";
12
+ import { SapQueryRunner } from "./SapQueryRunner";
13
13
  /**
14
14
  * Organizes communication with SAP Hana DBMS.
15
15
  *
@@ -21,11 +21,11 @@ export declare class SapDriver implements Driver {
21
21
  */
22
22
  connection: DataSource;
23
23
  /**
24
- * Hana Pool instance.
24
+ * SAP HANA Client Pool instance.
25
25
  */
26
26
  client: any;
27
27
  /**
28
- * Hana Client streaming extension.
28
+ * SAP HANA Client streaming extension.
29
29
  */
30
30
  streamClient: any;
31
31
  /**
@@ -33,10 +33,9 @@ export declare class SapDriver implements Driver {
33
33
  */
34
34
  master: any;
35
35
  /**
36
- * Pool for slave databases.
37
- * Used in replication.
36
+ * Function handling errors thrown by drivers pool.
38
37
  */
39
- slaves: any[];
38
+ poolErrorHandler: (error: any) => void;
40
39
  /**
41
40
  * Connection options.
42
41
  */
@@ -104,7 +103,7 @@ export declare class SapDriver implements Driver {
104
103
  dataTypeDefaults: DataTypeDefaults;
105
104
  /**
106
105
  * Max length allowed by SAP HANA for aliases (identifiers).
107
- * @see https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.03/en-US/20a760537519101497e3cfe07b348f3c.html
106
+ * @see https://help.sap.com/docs/hana-cloud-database/sap-hana-cloud-sap-hana-database-sql-reference-guide/system-limitations
108
107
  */
109
108
  maxAliasLength: number;
110
109
  cteCapabilities: CteCapabilities;
@@ -124,6 +123,18 @@ export declare class SapDriver implements Driver {
124
123
  * Closes connection with the database.
125
124
  */
126
125
  disconnect(): Promise<void>;
126
+ /**
127
+ * Obtains a new database connection to a master server.
128
+ * Used for replication.
129
+ * If replication is not setup then returns default connection's database connection.
130
+ */
131
+ obtainMasterConnection(): Promise<any>;
132
+ /**
133
+ * Obtains a new database connection to a slave server.
134
+ * Used for replication.
135
+ * If replication is not setup then returns master (default) connection's database connection.
136
+ */
137
+ obtainSlaveConnection(): Promise<any>;
127
138
  /**
128
139
  * Creates a schema builder used to build and sync a schema.
129
140
  */
@@ -187,18 +198,6 @@ export declare class SapDriver implements Driver {
187
198
  * Creates column type definition including length, precision and scale
188
199
  */
189
200
  createFullType(column: TableColumn): string;
190
- /**
191
- * Obtains a new database connection to a master server.
192
- * Used for replication.
193
- * If replication is not setup then returns default connection's database connection.
194
- */
195
- obtainMasterConnection(): Promise<any>;
196
- /**
197
- * Obtains a new database connection to a slave server.
198
- * Used for replication.
199
- * If replication is not setup then returns master (default) connection's database connection.
200
- */
201
- obtainSlaveConnection(): Promise<any>;
202
201
  /**
203
202
  * Creates generated map of values generated or returned by database after INSERT query.
204
203
  */
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SapDriver = void 0;
4
+ const node_util_1 = require("node:util");
4
5
  const __1 = require("../..");
5
6
  const DriverPackageNotInstalledError_1 = require("../../error/DriverPackageNotInstalledError");
6
7
  const TypeORMError_1 = require("../../error/TypeORMError");
@@ -8,10 +9,10 @@ const PlatformTools_1 = require("../../platform/PlatformTools");
8
9
  const RdbmsSchemaBuilder_1 = require("../../schema-builder/RdbmsSchemaBuilder");
9
10
  const ApplyValueTransformers_1 = require("../../util/ApplyValueTransformers");
10
11
  const DateUtils_1 = require("../../util/DateUtils");
12
+ const InstanceChecker_1 = require("../../util/InstanceChecker");
11
13
  const OrmUtils_1 = require("../../util/OrmUtils");
12
- const SapQueryRunner_1 = require("./SapQueryRunner");
13
14
  const DriverUtils_1 = require("../DriverUtils");
14
- const InstanceChecker_1 = require("../../util/InstanceChecker");
15
+ const SapQueryRunner_1 = require("./SapQueryRunner");
15
16
  /**
16
17
  * Organizes communication with SAP Hana DBMS.
17
18
  *
@@ -22,11 +23,6 @@ class SapDriver {
22
23
  // Constructor
23
24
  // -------------------------------------------------------------------------
24
25
  constructor(connection) {
25
- /**
26
- * Pool for slave databases.
27
- * Used in replication.
28
- */
29
- this.slaves = [];
30
26
  /**
31
27
  * Indicates if replication is enabled.
32
28
  */
@@ -154,7 +150,7 @@ class SapDriver {
154
150
  };
155
151
  /**
156
152
  * Max length allowed by SAP HANA for aliases (identifiers).
157
- * @see https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.03/en-US/20a760537519101497e3cfe07b348f3c.html
153
+ * @see https://help.sap.com/docs/hana-cloud-database/sap-hana-cloud-sap-hana-database-sql-reference-guide/system-limitations
158
154
  */
159
155
  this.maxAliasLength = 128;
160
156
  this.cteCapabilities = {
@@ -177,50 +173,55 @@ class SapDriver {
177
173
  */
178
174
  async connect() {
179
175
  // HANA connection info
180
- const dbParams = {
181
- hostName: this.options.host,
176
+ const connectionOptions = {
177
+ host: this.options.host,
182
178
  port: this.options.port,
183
- userName: this.options.username,
179
+ user: this.options.username,
184
180
  password: this.options.password,
185
- ...this.options.extra,
181
+ database: this.options.database,
182
+ currentSchema: this.options.schema,
183
+ encrypt: this.options.encrypt,
184
+ sslValidateCertificate: this.options.sslValidateCertificate,
185
+ key: this.options.key,
186
+ cert: this.options.cert,
187
+ ca: this.options.ca,
186
188
  };
187
- if (this.options.database)
188
- dbParams.databaseName = this.options.database;
189
- if (this.options.schema)
190
- dbParams.currentSchema = this.options.schema;
191
- if (this.options.encrypt)
192
- dbParams.encrypt = this.options.encrypt;
193
- if (this.options.sslValidateCertificate)
194
- dbParams.validateCertificate = this.options.sslValidateCertificate;
195
- if (this.options.key)
196
- dbParams.key = this.options.key;
197
- if (this.options.cert)
198
- dbParams.cert = this.options.cert;
199
- if (this.options.ca)
200
- dbParams.ca = this.options.ca;
189
+ Object.keys(connectionOptions).forEach((key) => {
190
+ if (connectionOptions[key] === undefined) {
191
+ delete connectionOptions[key];
192
+ }
193
+ });
194
+ Object.assign(connectionOptions, this.options.extra ?? {});
201
195
  // pool options
202
- const options = {
203
- min: this.options.pool && this.options.pool.min
204
- ? this.options.pool.min
205
- : 1,
206
- max: this.options.pool && this.options.pool.max
207
- ? this.options.pool.max
208
- : 10,
196
+ const poolOptions = {
197
+ maxConnectedOrPooled: this.options.pool?.maxConnectedOrPooled ??
198
+ this.options.pool?.max ??
199
+ this.options.poolSize ??
200
+ 10,
201
+ maxPooledIdleTime: this.options.pool?.maxPooledIdleTime ??
202
+ (this.options.pool?.idleTimeout
203
+ ? this.options.pool.idleTimeout / 1000
204
+ : 30),
209
205
  };
210
- if (this.options.pool && this.options.pool.checkInterval)
211
- options.checkInterval = this.options.pool.checkInterval;
212
- if (this.options.pool && this.options.pool.maxWaitingRequests)
213
- options.maxWaitingRequests = this.options.pool.maxWaitingRequests;
214
- if (this.options.pool && this.options.pool.requestTimeout)
215
- options.requestTimeout = this.options.pool.requestTimeout;
216
- if (this.options.pool && this.options.pool.idleTimeout)
217
- options.idleTimeout = this.options.pool.idleTimeout;
218
- const { logger } = this.connection;
219
- const poolErrorHandler = options.poolErrorHandler ||
220
- ((error) => logger.log("warn", `SAP Hana pool raised an error. ${error}`));
221
- this.client.eventEmitter.on("poolError", poolErrorHandler);
206
+ if (this.options.pool?.pingCheck) {
207
+ poolOptions.pingCheck = this.options.pool.pingCheck;
208
+ }
209
+ if (this.options.pool?.poolCapacity) {
210
+ poolOptions.poolCapacity = this.options.pool.poolCapacity;
211
+ }
212
+ this.poolErrorHandler =
213
+ this.options.pool?.poolErrorHandler ??
214
+ ((error) => {
215
+ this.connection.logger.log("warn", `SAP HANA pool raised an error: ${error}`);
216
+ });
222
217
  // create the pool
223
- this.master = this.client.createPool(dbParams, options);
218
+ try {
219
+ this.master = this.client.createPool(connectionOptions, poolOptions);
220
+ }
221
+ catch (error) {
222
+ this.poolErrorHandler(error);
223
+ throw error;
224
+ }
224
225
  const queryRunner = this.createQueryRunner("master");
225
226
  const { version, database } = await queryRunner.getDatabaseAndVersion();
226
227
  this.version = version;
@@ -245,7 +246,39 @@ class SapDriver {
245
246
  throw new __1.ConnectionIsNotSetError("sap");
246
247
  }
247
248
  this.master = undefined;
248
- await pool.clear();
249
+ try {
250
+ await (0, node_util_1.promisify)(pool.clear).call(pool);
251
+ }
252
+ catch (error) {
253
+ this.poolErrorHandler(error);
254
+ throw error;
255
+ }
256
+ }
257
+ /**
258
+ * Obtains a new database connection to a master server.
259
+ * Used for replication.
260
+ * If replication is not setup then returns default connection's database connection.
261
+ */
262
+ async obtainMasterConnection() {
263
+ const pool = this.master;
264
+ if (!pool) {
265
+ throw new TypeORMError_1.TypeORMError("Driver not Connected");
266
+ }
267
+ try {
268
+ return await (0, node_util_1.promisify)(pool.getConnection).call(pool);
269
+ }
270
+ catch (error) {
271
+ this.poolErrorHandler(error);
272
+ throw error;
273
+ }
274
+ }
275
+ /**
276
+ * Obtains a new database connection to a slave server.
277
+ * Used for replication.
278
+ * If replication is not setup then returns master (default) connection's database connection.
279
+ */
280
+ async obtainSlaveConnection() {
281
+ return this.obtainMasterConnection();
249
282
  }
250
283
  /**
251
284
  * Creates a schema builder used to build and sync a schema.
@@ -556,25 +589,6 @@ class SapDriver {
556
589
  type += " array";
557
590
  return type;
558
591
  }
559
- /**
560
- * Obtains a new database connection to a master server.
561
- * Used for replication.
562
- * If replication is not setup then returns default connection's database connection.
563
- */
564
- obtainMasterConnection() {
565
- if (!this.master) {
566
- throw new TypeORMError_1.TypeORMError("Driver not Connected");
567
- }
568
- return this.master.getConnection();
569
- }
570
- /**
571
- * Obtains a new database connection to a slave server.
572
- * Used for replication.
573
- * If replication is not setup then returns master (default) connection's database connection.
574
- */
575
- obtainSlaveConnection() {
576
- return this.obtainMasterConnection();
577
- }
578
592
  /**
579
593
  * Creates generated map of values generated or returned by database after INSERT query.
580
594
  */
@@ -654,21 +668,16 @@ class SapDriver {
654
668
  * If driver dependency is not given explicitly, then try to load it via "require".
655
669
  */
656
670
  loadDependencies() {
657
- try {
658
- const client = this.options.driver || PlatformTools_1.PlatformTools.load("hdb-pool");
671
+ const client = this.options.driver ?? this.options.hanaClientDriver;
672
+ if (client) {
659
673
  this.client = client;
660
- }
661
- catch (e) {
662
- // todo: better error for browser env
663
- throw new DriverPackageNotInstalledError_1.DriverPackageNotInstalledError("SAP Hana", "hdb-pool");
674
+ return;
664
675
  }
665
676
  try {
666
- if (!this.options.hanaClientDriver) {
667
- PlatformTools_1.PlatformTools.load("@sap/hana-client");
668
- this.streamClient = PlatformTools_1.PlatformTools.load("@sap/hana-client/extension/Stream");
669
- }
677
+ this.client = PlatformTools_1.PlatformTools.load("@sap/hana-client");
678
+ this.streamClient = PlatformTools_1.PlatformTools.load("@sap/hana-client/extension/Stream");
670
679
  }
671
- catch (e) {
680
+ catch {
672
681
  // todo: better error for browser env
673
682
  throw new DriverPackageNotInstalledError_1.DriverPackageNotInstalledError("SAP Hana", "@sap/hana-client");
674
683
  }