@pi-r/oracle 0.4.0 → 0.5.2

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 2023 Wit Studio
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,5 +1,7 @@
1
- ### @pi-r/oracle
1
+ # @pi-r/oracle
2
2
 
3
- ### LICENSE
3
+ PEP 402 - Forever Vivy
4
+
5
+ ## LICENSE
4
6
 
5
7
  MIT
package/client/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { OracleDataSource } from '@e-mc/types/lib/db';
2
-
3
1
  import type { IDbSourceClient } from '@e-mc/db/types';
4
2
 
3
+ import type { OracleDataSource } from '../types';
4
+
5
5
  declare const Oracle: IDbSourceClient<OracleDataSource>;
6
6
 
7
7
  export = Oracle;
package/client/index.js CHANGED
@@ -18,14 +18,14 @@ class OraclePool extends DbPool {
18
18
  return this.closed || connectionsInUse === 0 && currentQueueLength === 0;
19
19
  }
20
20
  get closeable() {
21
- return super.closeable || this.client.status === 6001 /* POOL_STATUS.DRAINING */;
21
+ return super.closeable || this.client.status === 6001;
22
22
  }
23
23
  get closed() {
24
- return this.client.status === 6002 /* POOL_STATUS.CLOSED */;
24
+ return this.client.status === 6002;
25
25
  }
26
26
  }
27
27
  const POOL_STATE = {};
28
- const POOL_UNUSED = ['poolMax', 'poolMin', 'poolIncrement', 'poolTimeout', 'poolPingInterval', 'poolMaxPerShard', 'queueMax', 'queueRequests', 'queueTimeout'];
28
+ const POOL_UNUSED = ['poolMax', 'poolMin', 'poolIncrement', 'poolTimeout', 'poolPingInterval', 'poolMaxPerShard', 'connectTimeout', 'queueMax', 'queueRequests', 'queueTimeout'];
29
29
  function removePoolProperties(credential) {
30
30
  if (!credential.uuidKey) {
31
31
  let result;
@@ -96,7 +96,7 @@ async function setCredential(item) {
96
96
  errors.push('connectString');
97
97
  }
98
98
  if (errors.length) {
99
- throw (0, types_1.errorMessage)("oracle" /* STRINGS.MODULE_NAME */, 'Not defined - ' + errors.join(' | '));
99
+ throw (0, types_1.errorMessage)("oracle", 'Not defined - ' + errors.join(' | '));
100
100
  }
101
101
  }
102
102
  const usePool = item.usePool;
@@ -126,9 +126,9 @@ async function setCredential(item) {
126
126
  const poolKey = getPoolKey(credential);
127
127
  if (poolKey) {
128
128
  if (!(pool = POOL_STATE[poolKey]) || pool.closed) {
129
- const config = this.getPoolConfig("oracle" /* STRINGS.MODULE_NAME */, password);
129
+ const config = this.getPoolConfig("oracle", password);
130
130
  if (config) {
131
- const { min, max, idle, queue_max, queue_idle } = config;
131
+ const { min, max, idle, queue_max, queue_idle, timeout } = config;
132
132
  if (min >= 0) {
133
133
  credential.poolMin ?? (credential.poolMin = min);
134
134
  }
@@ -144,6 +144,9 @@ async function setCredential(item) {
144
144
  if (queue_idle >= 0) {
145
145
  credential.queueTimeout ?? (credential.queueTimeout = queue_idle);
146
146
  }
147
+ if (timeout >= 0) {
148
+ credential.connectTimeout ?? (credential.connectTimeout = idle / 1000);
149
+ }
147
150
  }
148
151
  new OraclePool(await oracledb.createPool(credential), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
149
152
  }
@@ -186,16 +189,16 @@ async function executeBatchQuery(batch, options = '', outResult) {
186
189
  if (!parallel) {
187
190
  outResult || (outResult = new Array(length));
188
191
  }
189
- const caching = this.hasCache("oracle" /* STRINGS.MODULE_NAME */, sessionKey);
192
+ const caching = this.hasCache("oracle", sessionKey);
190
193
  const tasks = new Array(length);
191
194
  const clients = [];
192
195
  let oraclePool, oracleClient, oracleCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
193
196
  const getConnection = async (item, credential) => {
194
- item.transactionState = 64 /* DB_TRANSACTION.AUTH */;
197
+ item.transactionState = 64;
195
198
  let client;
196
199
  if (oraclePool) {
197
200
  clients.push(client = await oraclePool.getConnection());
198
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
201
+ item.transactionState &= ~64;
199
202
  return client;
200
203
  }
201
204
  const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
@@ -233,14 +236,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
233
236
  }
234
237
  oracleCredential = credential;
235
238
  }
236
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
239
+ item.transactionState &= ~64;
237
240
  return client;
238
241
  };
239
242
  for (let i = 0; i < length; ++i) {
240
243
  const item = batch[i];
241
244
  const { source, query, params, ignoreCache, options: clientOptions } = item;
242
245
  let credential = oracleCredential || onceCredential, error;
243
- 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 */))) {
246
+ 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"))) {
244
247
  if (this.handleFail(error, item, { errorQuery })) {
245
248
  if (!parallel) {
246
249
  tasks.length = 0;
@@ -256,8 +259,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
256
259
  }
257
260
  continue;
258
261
  }
259
- item.transactionState = 1 /* DB_TRANSACTION.ACTIVE */;
260
- const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("oracle" /* STRINGS.MODULE_NAME */, 'options', null, credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
262
+ item.transactionState = 1;
263
+ const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("oracle", 'options', null, credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
261
264
  const renewCache = ignoreCache === 0;
262
265
  const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
263
266
  let queryString = '';
@@ -272,7 +275,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
272
275
  else {
273
276
  outResult[i] = result;
274
277
  }
275
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */ | 128 /* DB_TRANSACTION.CACHE */);
278
+ this.add(item, 4 | 128);
276
279
  continue;
277
280
  }
278
281
  if (!ignoreCache && outCacheMiss) {
@@ -323,7 +326,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
323
326
  reject(error);
324
327
  }
325
328
  else {
326
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
329
+ this.add(item, 4);
327
330
  resolve(!error ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : rows);
328
331
  }
329
332
  })
@@ -331,7 +334,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
331
334
  }
332
335
  else {
333
336
  const { rows } = await client.execute(query, params || [], executeOptions);
334
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
337
+ this.add(item, 4);
335
338
  resolve(rows ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : null);
336
339
  }
337
340
  }
@@ -355,7 +358,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
355
358
  }
356
359
  }
357
360
  return this.processRows(batch, tasks, {
358
- 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 }))),
361
+ disconnect: () => clients.forEach(item => item.close(err => err && this.writeFail(["Unable to close connnection", "oracle"], err, { type: 65536, fatal: false }))),
359
362
  parallel
360
363
  }, outResult);
361
364
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/oracle",
3
- "version": "0.4.0",
3
+ "version": "0.5.2",
4
4
  "description": "Oracle client driver for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "https://github.com/anpham6/pi-r.git",
12
+ "url": "git+https://github.com/anpham6/pi-r.git",
13
13
  "directory": "src/db/oracle"
14
14
  },
15
15
  "keywords": [
@@ -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.6.0",
25
- "@e-mc/types": "^0.6.0",
26
- "oracledb": "^6.0.3"
24
+ "@e-mc/db": "^0.7.2",
25
+ "@e-mc/types": "^0.7.2",
26
+ "oracledb": "^6.3.0"
27
27
  }
28
28
  }