@pi-r/oracle 0.3.0 → 0.3.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 Studio Trigger
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 Aina
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
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DB_SOURCE_TYPE = exports.DB_SOURCE_CLIENT = exports.checkTimeout = exports.executeBatchQuery = exports.executeQuery = exports.setCredential = void 0;
4
+ const oracledb = require("oracledb");
4
5
  const util_1 = require("@e-mc/db/util");
5
6
  const types_1 = require("@e-mc/types");
6
7
  const Db = require("@e-mc/db");
@@ -17,18 +18,29 @@ class OraclePool extends DbPool {
17
18
  return this.closed || connectionsInUse === 0 && currentQueueLength === 0;
18
19
  }
19
20
  get closeable() {
20
- return super.closeable || this.client.status === 6001 /* POOL_STATUS.DRAINING */;
21
+ return super.closeable || this.client.status === 6001;
21
22
  }
22
23
  get closed() {
23
- return this.client.status === 6002 /* POOL_STATUS.CLOSED */;
24
+ return this.client.status === 6002;
24
25
  }
25
26
  }
26
27
  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 };
28
+ const POOL_UNUSED = ['poolMax', 'poolMin', 'poolIncrement', 'poolTimeout', 'poolPingInterval', 'poolMaxPerShard', 'queueMax', 'queueRequests', 'queueTimeout'];
29
+ function removePoolProperties(credential) {
30
+ if (!credential.uuidKey) {
31
+ let result;
32
+ for (let i = 0, length = POOL_UNUSED.length; i < length; ++i) {
33
+ const attr = POOL_UNUSED[i];
34
+ if (attr in credential) {
35
+ result || (result = { ...credential });
36
+ delete result[attr];
37
+ }
38
+ }
39
+ if (result) {
40
+ return result;
41
+ }
30
42
  }
31
- return options;
43
+ return credential;
32
44
  }
33
45
  function getPoolKey(credential) {
34
46
  if (credential.connectString && (credential.user && credential.password || credential.externalAuth)) {
@@ -84,7 +96,7 @@ async function setCredential(item) {
84
96
  errors.push('connectString');
85
97
  }
86
98
  if (errors.length) {
87
- throw (0, types_1.errorMessage)("oracle" /* STRINGS.MODULE_NAME */, 'Not defined - ' + errors.join(' | '));
99
+ throw (0, types_1.errorMessage)("oracle", 'Not defined - ' + errors.join(' | '));
88
100
  }
89
101
  }
90
102
  const usePool = item.usePool;
@@ -114,8 +126,7 @@ async function setCredential(item) {
114
126
  const poolKey = getPoolKey(credential);
115
127
  if (poolKey) {
116
128
  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);
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) {
@@ -134,7 +145,7 @@ async function setCredential(item) {
134
145
  credential.queueTimeout ?? (credential.queueTimeout = queue_idle);
135
146
  }
136
147
  }
137
- new OraclePool(await createPool(credential), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
148
+ new OraclePool(await oracledb.createPool(credential), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
138
149
  }
139
150
  else {
140
151
  pool.add(item);
@@ -155,7 +166,6 @@ async function executeBatchQuery(batch, options = '', outResult) {
155
166
  if (length === 0) {
156
167
  return [];
157
168
  }
158
- const db = require("oracledb" /* STRINGS.PACKAGE_NAME */);
159
169
  let parallel, connectOnce, errorQuery, sessionKey, outCacheMiss;
160
170
  if ((0, types_1.isPlainObject)(options)) {
161
171
  ({ parallel, connectOnce, errorQuery, sessionKey } = options);
@@ -176,16 +186,16 @@ async function executeBatchQuery(batch, options = '', outResult) {
176
186
  if (!parallel) {
177
187
  outResult || (outResult = new Array(length));
178
188
  }
179
- const caching = this.hasCache("oracle" /* STRINGS.MODULE_NAME */, sessionKey);
189
+ const caching = this.hasCache("oracle", sessionKey);
180
190
  const tasks = new Array(length);
181
191
  const clients = [];
182
192
  let oraclePool, oracleClient, oracleCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
183
193
  const getConnection = async (item, credential) => {
184
- item.transactionState = 64 /* DB_TRANSACTION.AUTH */;
194
+ item.transactionState = 64;
185
195
  let client;
186
196
  if (oraclePool) {
187
197
  clients.push(client = await oraclePool.getConnection());
188
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
198
+ item.transactionState &= ~64;
189
199
  return client;
190
200
  }
191
201
  const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
@@ -216,21 +226,21 @@ async function executeBatchQuery(batch, options = '', outResult) {
216
226
  pool.connected = false;
217
227
  }
218
228
  }
219
- clients.push(client || (client = await db.getConnection((oracleCredential || credential))));
229
+ clients.push(client || (client = await oracledb.getConnection((oracleCredential || credential))));
220
230
  if (connectOnce) {
221
231
  if (!parallel) {
222
232
  oracleClient = client;
223
233
  }
224
234
  oracleCredential = credential;
225
235
  }
226
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
236
+ item.transactionState &= ~64;
227
237
  return client;
228
238
  };
229
239
  for (let i = 0; i < length; ++i) {
230
240
  const item = batch[i];
231
241
  const { source, query, params, ignoreCache, options: clientOptions } = item;
232
242
  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 */))) {
243
+ 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
244
  if (this.handleFail(error, item, { errorQuery })) {
235
245
  if (!parallel) {
236
246
  tasks.length = 0;
@@ -246,8 +256,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
246
256
  }
247
257
  continue;
248
258
  }
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;
259
+ item.transactionState = 1;
260
+ const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("oracle", 'options', null, credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
251
261
  const renewCache = ignoreCache === 0;
252
262
  const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
253
263
  let queryString = '';
@@ -262,7 +272,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
262
272
  else {
263
273
  outResult[i] = result;
264
274
  }
265
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */ | 128 /* DB_TRANSACTION.CACHE */);
275
+ this.add(item, 4 | 128);
266
276
  continue;
267
277
  }
268
278
  if (!ignoreCache && outCacheMiss) {
@@ -287,7 +297,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
287
297
  if (oracleClient && parallel) {
288
298
  oracleClient = undefined;
289
299
  }
290
- const executeOptions = { outFormat: db.OUT_FORMAT_OBJECT, ...clientOptions, resultSet: false, autoCommit: true };
300
+ const executeOptions = { outFormat: oracledb.OUT_FORMAT_OBJECT, ...clientOptions, resultSet: false, autoCommit: true };
291
301
  commandType = this.commandType.SELECT;
292
302
  if (streamRow) {
293
303
  const rows = [];
@@ -313,7 +323,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
313
323
  reject(error);
314
324
  }
315
325
  else {
316
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
326
+ this.add(item, 4);
317
327
  resolve(!error ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : rows);
318
328
  }
319
329
  })
@@ -321,7 +331,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
321
331
  }
322
332
  else {
323
333
  const { rows } = await client.execute(query, params || [], executeOptions);
324
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
334
+ this.add(item, 4);
325
335
  resolve(rows ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : null);
326
336
  }
327
337
  }
@@ -345,7 +355,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
345
355
  }
346
356
  }
347
357
  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 }))),
358
+ disconnect: () => clients.forEach(item => item.close(err => err && this.writeFail(["Unable to close connnection", "oracle"], err, { type: 65536, fatal: false }))),
349
359
  parallel
350
360
  }, outResult);
351
361
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/oracle",
3
- "version": "0.3.0",
3
+ "version": "0.3.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.5.3",
25
- "@e-mc/types": "^0.5.3",
26
- "oracledb": "^6.0.0"
24
+ "@e-mc/db": "^0.6.1",
25
+ "@e-mc/types": "^0.6.1",
26
+ "oracledb": "^6.3.0"
27
27
  }
28
28
  }