@pi-r/oracle 0.6.3 → 0.6.5

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.
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 An Pham
1
+ Copyright 2024 An Pham
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
package/README.md CHANGED
@@ -1,7 +1,10 @@
1
- ### @pi-r/oracle
1
+ # @pi-r/oracle
2
2
 
3
- https://e-mc.readthedocs.io/en/latest/db/oracle.html
3
+ ## Documentation
4
4
 
5
- ### LICENSE
5
+ - [E-mc](https://e-mc.readthedocs.io/en/latest/db/oracle.html)
6
+ - [squared](https://squared.readthedocs.io)
7
+
8
+ ## LICENSE
6
9
 
7
10
  MIT
package/client/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import type { IDbSourceClient } from '@e-mc/db/types';
4
4
 
5
5
  import type { OracleDataSource } from '../types';
6
6
 
7
+ // @ts-ignore
7
8
  import type { InitialiseOptions } from 'oracledb';
8
9
 
9
10
  declare const Oracle: IDbSourceClient<OracleDataSource> & {
package/client/index.js CHANGED
@@ -30,17 +30,18 @@ class OraclePool extends DbPool {
30
30
  }
31
31
  }
32
32
  get closeable() {
33
- return super.closeable || this.client.status === 6001 /* POOL_STATUS.DRAINING */;
33
+ return super.closeable || this.client.status === 6001;
34
34
  }
35
35
  get closed() {
36
- return this.client.status === 6002 /* POOL_STATUS.CLOSED */;
36
+ return this.client.status === 6002;
37
37
  }
38
38
  }
39
39
  const DRIVER_MODE = process.env.NODE_ORACLEDB_DRIVER_MODE;
40
40
  const POOL_STATE = {};
41
41
  const POOL_UNUSED = ['poolMax', 'poolMin', 'poolIncrement', 'poolTimeout', 'poolPingInterval', 'poolMaxPerShard', 'connectTimeout', 'queueMax', 'queueRequests', 'queueTimeout'];
42
+ const POOL_ACTIVE = new WeakSet();
42
43
  function removePoolProperties(credential) {
43
- if (!credential.uuidKey) {
44
+ if (!credential.uuidKey && POOL_ACTIVE.has(credential)) {
44
45
  let result;
45
46
  for (let i = 0, length = POOL_UNUSED.length; i < length; ++i) {
46
47
  const attr = POOL_UNUSED[i];
@@ -72,7 +73,7 @@ if (DRIVER_MODE === 'thick' && oracledb.thin) {
72
73
  oracledb.initOracleClient({ libDir, configDir: process.env.NODE_ORACLEDB_CLIENT_CONFIG_DIR, driverName: process.env.NODE_ORACLEDB_CLIENT_DRIVER_NAME, errorUrl: process.env.NODE_ORACLEDB_CLIENT_ERROR_URL });
73
74
  }
74
75
  catch (err) {
75
- Db.writeFail(["Unable to configure client" /* ERR_DB.CLIENT */, 'oracledb'], err);
76
+ Db.writeFail(["Unable to configure client", 'oracledb'], err);
76
77
  }
77
78
  }
78
79
  }
@@ -89,14 +90,14 @@ function initOracleClient(credential, type) {
89
90
  this.addLog(this.statusType.WARN, err, 'oracledb', credential.libDir);
90
91
  break;
91
92
  default:
92
- this.writeFail(["Unable to configure client" /* ERR_DB.CLIENT */, 'oracledb'], err, { type: type ?? 65536 /* LOG_TYPE.DB */, fatal: false });
93
+ this.writeFail(["Unable to configure client", 'oracledb'], err, { type: type ?? 65536, fatal: false });
93
94
  break;
94
95
  }
95
96
  }
96
97
  }
97
98
  }
98
99
  else {
99
- this.writeFail(["Unable to configure client" /* ERR_DB.CLIENT */, 'oracledb'], (0, types_1.errorMessage)('oracledb', 'Environment variable "NODE_ORACLEDB_DRIVER_MODE" was not set', 'thick'), { type: type ?? 65536 /* LOG_TYPE.DB */, fatal: false });
100
+ this.writeFail(["Unable to configure client", 'oracledb'], (0, types_1.errorMessage)('oracledb', 'Environment variable "NODE_ORACLEDB_DRIVER_MODE" was not set', 'thick'), { type: type ?? 65536, fatal: false });
100
101
  }
101
102
  delete credential.libDir;
102
103
  }
@@ -151,7 +152,7 @@ async function setCredential(item) {
151
152
  errors.push('connectString');
152
153
  }
153
154
  if (errors.length) {
154
- throw (0, types_1.errorMessage)("oracle" /* STRINGS.MODULE_NAME */, 'Not defined - ' + errors.join(' | '));
155
+ throw (0, types_1.errorMessage)("oracle", 'Not defined - ' + errors.join(' | '));
155
156
  }
156
157
  }
157
158
  initOracleClient.call(this, credential);
@@ -187,7 +188,7 @@ async function setCredential(item) {
187
188
  }
188
189
  }
189
190
  }
190
- const config = this.getPoolConfig("oracle" /* STRINGS.MODULE_NAME */, password);
191
+ const config = this.getPoolConfig("oracle", password);
191
192
  if (config) {
192
193
  const { min, max, idle, queue_max, queue_idle, timeout } = config;
193
194
  if (min >= 0) {
@@ -246,16 +247,17 @@ async function executeBatchQuery(batch, options = '', outResult) {
246
247
  if (!parallel) {
247
248
  outResult || (outResult = new Array(length));
248
249
  }
249
- const caching = this.hasCache("oracle" /* STRINGS.MODULE_NAME */, sessionKey);
250
+ const caching = this.hasCache("oracle", sessionKey);
250
251
  const tasks = new Array(length);
251
252
  const clients = [];
252
253
  let oraclePool, oracleClient, oracleCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
253
254
  const getConnection = async (item, credential) => {
254
- item.transactionState = 64 /* DB_TRANSACTION.AUTH */;
255
+ item.transactionState = 64;
255
256
  let client;
256
257
  if (oraclePool) {
257
258
  clients.push(client = await oraclePool.getConnection());
258
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
259
+ item.transactionState &= ~64;
260
+ POOL_ACTIVE.add(credential);
259
261
  return client;
260
262
  }
261
263
  const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
@@ -266,6 +268,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
266
268
  oraclePool = pool;
267
269
  }
268
270
  pool.connected = true;
271
+ POOL_ACTIVE.add(credential);
269
272
  }
270
273
  catch (err) {
271
274
  let close;
@@ -293,7 +296,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
293
296
  }
294
297
  oracleCredential = credential;
295
298
  }
296
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
299
+ item.transactionState &= ~64;
297
300
  return client;
298
301
  };
299
302
  if (this.host?.username) {
@@ -303,7 +306,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
303
306
  const item = batch[i];
304
307
  const { source, query, params, ignoreCache, options: clientOptions } = item;
305
308
  let credential = oracleCredential || onceCredential, error;
306
- if (!credential && !(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials" /* ERR_DB.CREDENTIALS */)) || !query && (error = (0, types_1.errorMessage)(source, "Missing database query" /* ERR_DB.QUERY */))) {
309
+ if (!credential && !(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials")) || !query && (error = (0, types_1.errorMessage)(source, "Missing database query"))) {
307
310
  if (this.handleFail(error, item, { errorQuery })) {
308
311
  if (!parallel) {
309
312
  tasks.length = 0;
@@ -319,8 +322,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
319
322
  }
320
323
  continue;
321
324
  }
322
- item.transactionState = 1 /* DB_TRANSACTION.ACTIVE */;
323
- const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("oracle" /* STRINGS.MODULE_NAME */, 'options', null, credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
325
+ item.transactionState = 1;
326
+ const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("oracle", 'options', null, credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
324
327
  const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
325
328
  let queryString = '';
326
329
  if (caching && ignoreCache !== true && !streamRow) {
@@ -334,7 +337,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
334
337
  else {
335
338
  outResult[i] = result;
336
339
  }
337
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */ | 128 /* DB_TRANSACTION.CACHE */);
340
+ this.add(item, 4 | 128);
338
341
  continue;
339
342
  }
340
343
  if (!ignoreCache && outCacheMiss) {
@@ -385,7 +388,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
385
388
  reject(error);
386
389
  }
387
390
  else {
388
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
391
+ this.add(item, 4);
389
392
  resolve(!error ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : rows);
390
393
  }
391
394
  })
@@ -393,7 +396,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
393
396
  }
394
397
  else {
395
398
  const { rows } = await client.execute(query, params || [], executeOptions);
396
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
399
+ this.add(item, 4);
397
400
  resolve(rows ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : null);
398
401
  }
399
402
  }
@@ -417,7 +420,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
417
420
  }
418
421
  }
419
422
  return this.processRows(batch, tasks, {
420
- disconnect: () => clients.forEach(item => item.close(err => err && this.writeFail(["Unable to close connnection" /* ERR_DB.CONNECTION_CLOSE */, "oracle" /* STRINGS.MODULE_NAME */], err, { type: 65536 /* LOG_TYPE.DB */, fatal: false }))),
423
+ disconnect: () => clients.forEach(item => item.close(err => err && this.writeFail(["Unable to close connnection", "oracle"], err, { type: 65536, fatal: false }))),
421
424
  parallel
422
425
  }, outResult);
423
426
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/oracle",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "description": "Oracle client driver for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",
@@ -21,8 +21,8 @@
21
21
  "license": "MIT",
22
22
  "homepage": "https://github.com/anpham6/pi-r#readme",
23
23
  "dependencies": {
24
- "@e-mc/db": "^0.8.3",
25
- "@e-mc/types": "^0.8.3",
24
+ "@e-mc/db": "^0.8.6",
25
+ "@e-mc/types": "^0.8.6",
26
26
  "oracledb": "^6.3.0"
27
27
  }
28
28
  }
package/types/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import type { DbDataSource } from '@e-mc/types/lib/squared';
2
2
 
3
3
  import type { ExecuteAction, ServerAuth } from '@e-mc/types/lib/db';
4
4
 
5
+ // @ts-ignore
5
6
  import type { BindParameters, ConnectionAttributes, ExecuteOptions, InitialiseOptions, PoolAttributes } from 'oracledb';
6
7
 
7
8
  export interface OracleDataSource extends DbDataSource<string, ExecuteOptions, unknown, string | OracleCredential, string>, ExecuteAction<BindParameters> {