@pi-r/oracle 0.2.1 → 0.2.8

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 Mile Square Park
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
4
+
5
+ ## LICENSE
4
6
 
5
7
  MIT
package/client/index.js CHANGED
@@ -17,18 +17,29 @@ class OraclePool extends DbPool {
17
17
  return this.closed || connectionsInUse === 0 && currentQueueLength === 0;
18
18
  }
19
19
  get closeable() {
20
- return super.closeable || this.client.status === 6001 /* POOL_STATUS.DRAINING */;
20
+ return super.closeable || this.client.status === 6001;
21
21
  }
22
22
  get closed() {
23
- return this.client.status === 6002 /* POOL_STATUS.CLOSED */;
23
+ return this.client.status === 6002;
24
24
  }
25
25
  }
26
26
  const POOL_STATE = {};
27
- function removePoolProperties(options) {
28
- if (!options.uuidKey && ('poolMax' in options || 'poolMin' in options || 'poolIncrement' in options || 'poolTimeout' in options || 'poolPingInterval' in options || 'poolMaxPerShard' in options || 'queueMax' in options || 'queueRequests' in options || 'queueTimeout' in options)) {
29
- return { ...options, poolMax: undefined, poolMin: undefined, poolIncrement: undefined, poolTimeout: undefined, poolPingInterval: undefined, poolMaxPerShard: undefined, queueMax: undefined, queueRequests: undefined, queueTimeout: undefined };
27
+ const POOL_UNUSED = ['poolMax', 'poolMin', 'poolIncrement', 'poolTimeout', 'poolPingInterval', 'poolMaxPerShard', 'queueMax', 'queueRequests', 'queueTimeout'];
28
+ function removePoolProperties(credential) {
29
+ if (!credential.uuidKey) {
30
+ let result;
31
+ for (let i = 0, length = POOL_UNUSED.length; i < length; ++i) {
32
+ const attr = POOL_UNUSED[i];
33
+ if (attr in credential) {
34
+ result || (result = { ...credential });
35
+ delete result[attr];
36
+ }
37
+ }
38
+ if (result) {
39
+ return result;
40
+ }
30
41
  }
31
- return options;
42
+ return credential;
32
43
  }
33
44
  function getPoolKey(credential) {
34
45
  if (credential.connectString && (credential.user && credential.password || credential.externalAuth)) {
@@ -84,7 +95,7 @@ async function setCredential(item) {
84
95
  errors.push('connectString');
85
96
  }
86
97
  if (errors.length) {
87
- throw (0, types_1.errorMessage)("oracle" /* STRINGS.MODULE_NAME */, 'Not defined - ' + errors.join(' | '));
98
+ throw (0, types_1.errorMessage)("oracle", 'Not defined - ' + errors.join(' | '));
88
99
  }
89
100
  }
90
101
  const usePool = item.usePool;
@@ -114,8 +125,8 @@ async function setCredential(item) {
114
125
  const poolKey = getPoolKey(credential);
115
126
  if (poolKey) {
116
127
  if (!(pool = POOL_STATE[poolKey]) || pool.closed) {
117
- const { createPool } = require("oracledb" /* STRINGS.PACKAGE_NAME */);
118
- const config = this.getPoolConfig("oracle" /* STRINGS.MODULE_NAME */, password);
128
+ const { createPool } = require("oracledb");
129
+ const config = this.getPoolConfig("oracle", password);
119
130
  if (config) {
120
131
  const { min, max, idle, queue_max, queue_idle } = config;
121
132
  if (min >= 0) {
@@ -155,7 +166,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
155
166
  if (length === 0) {
156
167
  return [];
157
168
  }
158
- const db = require("oracledb" /* STRINGS.PACKAGE_NAME */);
169
+ const db = require("oracledb");
159
170
  let parallel, connectOnce, errorQuery, sessionKey, outCacheMiss;
160
171
  if ((0, types_1.isPlainObject)(options)) {
161
172
  ({ parallel, connectOnce, errorQuery, sessionKey } = options);
@@ -176,16 +187,16 @@ async function executeBatchQuery(batch, options = '', outResult) {
176
187
  if (!parallel) {
177
188
  outResult || (outResult = new Array(length));
178
189
  }
179
- const caching = this.hasCache("oracle" /* STRINGS.MODULE_NAME */, sessionKey);
190
+ const caching = this.hasCache("oracle", sessionKey);
180
191
  const tasks = new Array(length);
181
192
  const clients = [];
182
193
  let oraclePool, oracleClient, oracleCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
183
194
  const getConnection = async (item, credential) => {
184
- item.transactionState = 64 /* DB_TRANSACTION.AUTH */;
195
+ item.transactionState = 64;
185
196
  let client;
186
197
  if (oraclePool) {
187
198
  clients.push(client = await oraclePool.getConnection());
188
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
199
+ item.transactionState &= ~64;
189
200
  return client;
190
201
  }
191
202
  const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
@@ -223,14 +234,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
223
234
  }
224
235
  oracleCredential = credential;
225
236
  }
226
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
237
+ item.transactionState &= ~64;
227
238
  return client;
228
239
  };
229
240
  for (let i = 0; i < length; ++i) {
230
241
  const item = batch[i];
231
242
  const { source, query, params, ignoreCache, options: clientOptions } = item;
232
243
  let credential = oracleCredential || onceCredential, error;
233
- 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 */))) {
244
+ 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"))) {
234
245
  if (this.handleFail(error, item, { errorQuery })) {
235
246
  if (!parallel) {
236
247
  tasks.length = 0;
@@ -246,8 +257,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
246
257
  }
247
258
  continue;
248
259
  }
249
- item.transactionState = 1 /* DB_TRANSACTION.ACTIVE */;
250
- const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("oracle" /* STRINGS.MODULE_NAME */, 'options', null, credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
260
+ item.transactionState = 1;
261
+ const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("oracle", 'options', null, credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
251
262
  const renewCache = ignoreCache === 0;
252
263
  const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
253
264
  let queryString = '';
@@ -262,7 +273,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
262
273
  else {
263
274
  outResult[i] = result;
264
275
  }
265
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */ | 128 /* DB_TRANSACTION.CACHE */);
276
+ this.add(item, 4 | 128);
266
277
  continue;
267
278
  }
268
279
  if (!ignoreCache && outCacheMiss) {
@@ -313,7 +324,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
313
324
  reject(error);
314
325
  }
315
326
  else {
316
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
327
+ this.add(item, 4);
317
328
  resolve(!error ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : rows);
318
329
  }
319
330
  })
@@ -321,7 +332,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
321
332
  }
322
333
  else {
323
334
  const { rows } = await client.execute(query, params || [], executeOptions);
324
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
335
+ this.add(item, 4);
325
336
  resolve(rows ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : null);
326
337
  }
327
338
  }
@@ -345,7 +356,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
345
356
  }
346
357
  }
347
358
  return this.processRows(batch, tasks, {
348
- 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 }))),
359
+ disconnect: () => clients.forEach(item => item.close(err => err && this.writeFail(["Unable to close connnection", "oracle"], err, { type: 65536, fatal: false }))),
349
360
  parallel
350
361
  }, outResult);
351
362
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/oracle",
3
- "version": "0.2.1",
3
+ "version": "0.2.8",
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.5.2",
25
- "@e-mc/types": "^0.5.2",
24
+ "@e-mc/db": "^0.5.4",
25
+ "@e-mc/types": "^0.5.4",
26
26
  "oracledb": "^5.5.0"
27
27
  }
28
28
  }