oracledb 3.1.2 → 4.2.0

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.
Files changed (53) hide show
  1. package/CHANGELOG.md +277 -4
  2. package/LICENSE.md +5906 -360
  3. package/README.md +7 -8
  4. package/build/Release/oracledb-4.2.0-darwin-x64.node +0 -0
  5. package/build/Release/oracledb-4.2.0-darwin-x64.node-buildinfo.txt +1 -0
  6. package/build/Release/oracledb-4.2.0-linux-x64.node +0 -0
  7. package/build/Release/oracledb-4.2.0-linux-x64.node-buildinfo.txt +1 -0
  8. package/build/Release/oracledb-4.2.0-win32-x64.node +0 -0
  9. package/build/Release/oracledb-4.2.0-win32-x64.node-buildinfo.txt +1 -0
  10. package/lib/aqDeqOptions.js +29 -0
  11. package/lib/aqEnqOptions.js +29 -0
  12. package/lib/aqMessage.js +29 -0
  13. package/lib/aqQueue.js +84 -0
  14. package/lib/connection.js +294 -326
  15. package/lib/dbObject.js +144 -0
  16. package/lib/lob.js +125 -132
  17. package/lib/oracledb.js +162 -483
  18. package/lib/pool.js +95 -109
  19. package/lib/{querystream.js → queryStream.js} +31 -30
  20. package/lib/resultset.js +75 -125
  21. package/lib/sodaCollection.js +99 -165
  22. package/lib/sodaDatabase.js +58 -133
  23. package/lib/sodaDocCursor.js +27 -70
  24. package/lib/sodaDocument.js +35 -65
  25. package/lib/sodaOperation.js +96 -252
  26. package/lib/util.js +78 -71
  27. package/package/README.md +41 -36
  28. package/package/install.js +30 -24
  29. package/package.json +2 -2
  30. package/build/Release/oracledb-abi48-darwin-x64.node +0 -0
  31. package/build/Release/oracledb-abi48-darwin-x64.node-buildinfo.txt +0 -1
  32. package/build/Release/oracledb-abi48-linux-x64.node +0 -0
  33. package/build/Release/oracledb-abi48-linux-x64.node-buildinfo.txt +0 -1
  34. package/build/Release/oracledb-abi48-win32-x64.node +0 -0
  35. package/build/Release/oracledb-abi48-win32-x64.node-buildinfo.txt +0 -1
  36. package/build/Release/oracledb-abi57-darwin-x64.node +0 -0
  37. package/build/Release/oracledb-abi57-darwin-x64.node-buildinfo.txt +0 -1
  38. package/build/Release/oracledb-abi57-linux-x64.node +0 -0
  39. package/build/Release/oracledb-abi57-linux-x64.node-buildinfo.txt +0 -1
  40. package/build/Release/oracledb-abi57-win32-x64.node +0 -0
  41. package/build/Release/oracledb-abi57-win32-x64.node-buildinfo.txt +0 -1
  42. package/build/Release/oracledb-abi64-darwin-x64.node +0 -0
  43. package/build/Release/oracledb-abi64-darwin-x64.node-buildinfo.txt +0 -1
  44. package/build/Release/oracledb-abi64-linux-x64.node +0 -0
  45. package/build/Release/oracledb-abi64-linux-x64.node-buildinfo.txt +0 -1
  46. package/build/Release/oracledb-abi64-win32-x64.node +0 -0
  47. package/build/Release/oracledb-abi64-win32-x64.node-buildinfo.txt +0 -1
  48. package/build/Release/oracledb-abi67-darwin-x64.node +0 -0
  49. package/build/Release/oracledb-abi67-darwin-x64.node-buildinfo.txt +0 -1
  50. package/build/Release/oracledb-abi67-linux-x64.node +0 -0
  51. package/build/Release/oracledb-abi67-linux-x64.node-buildinfo.txt +0 -1
  52. package/build/Release/oracledb-abi67-win32-x64.node +0 -0
  53. package/build/Release/oracledb-abi67-win32-x64.node-buildinfo.txt +0 -1
@@ -1,330 +1,174 @@
1
- /* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved */
2
-
3
- /**************************************************************************
4
- *
5
- * You may not use the identified files except in compliance with the Apache
6
- * License, Version 2.0 (the "License.")
7
- *
8
- * You may obtain a copy of the License at
9
- * http://www.apache.org/licenses/LICENSE-2.0.
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- *
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- *
18
- *****************************************************************************/
1
+ // Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved
2
+
3
+ //-----------------------------------------------------------------------------
4
+ //
5
+ // You may not use the identified files except in compliance with the Apache
6
+ // License, Version 2.0 (the "License.")
7
+ //
8
+ // You may obtain a copy of the License at
9
+ // http://www.apache.org/licenses/LICENSE-2.0.
10
+ //
11
+ // Unless required by applicable law or agreed to in writing, software
12
+ // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ //
15
+ // See the License for the specific language governing permissions and
16
+ // limitations under the License.
17
+ //
18
+ //-----------------------------------------------------------------------------
19
19
 
20
20
  'use strict';
21
21
 
22
22
  const nodbUtil = require('./util.js');
23
- const sodaDocument = require('./sodaDocument.js');
24
- const sodaDocCursor = require('./sodaDocCursor.js');
25
-
26
- var countPromisified;
27
- var getOnePromisified;
28
- var replaceOnePromisified;
29
- var replaceOneAndGetPromisified;
30
- var removePromisified;
31
- var getCursorPromisified;
32
- var getDocumentsPromisified;
33
-
34
23
 
35
24
  // to obtain count of documents from find() result
36
25
  // This is a terminal function (no further chaining possible)
37
26
  function count(cb) {
38
- var self = this;
39
- nodbUtil.assert(arguments.length === 1, 'NJS-009');
40
- nodbUtil.assert(typeof cb === 'function', 'NJS-006', 1);
27
+ nodbUtil.checkAsyncArgs(arguments, 1, 1);
41
28
 
42
- self._count(this._options, cb);
29
+ this._count(this._options, cb);
43
30
  }
44
31
 
45
- countPromisified = nodbUtil.promisify(count);
46
32
 
47
33
  // To obtain first document object from find() result
48
34
  // This is a terminal function (no further chaining possible)
49
35
  function getOne(cb) {
50
- var self = this;
51
-
52
- nodbUtil.assert(arguments.length === 1, 'NJS-009');
53
- nodbUtil.assert(typeof cb === 'function', 'NJS-006', 1);
36
+ nodbUtil.checkAsyncArgs(arguments, 1, 1);
54
37
 
55
- self._getOne(this._options, function(err, doc) {
56
- if (doc) {
57
- sodaDocument.extend(doc);
58
- }
59
- cb(err, doc);
60
- });
38
+ this._getOne(this._options, cb);
61
39
  }
62
40
 
63
- getOnePromisified = nodbUtil.promisify(getOne);
64
-
65
41
 
66
42
  // To replace one document by a given document based from find() result
67
43
  // This is a terminal function (no further chaining possible)
68
44
  function replaceOne(content, cb) {
69
- var self = this;
70
-
71
- nodbUtil.assert(arguments.length === 2, 'NJS-009');
45
+ nodbUtil.checkAsyncArgs(arguments, 2, 2);
72
46
  nodbUtil.assert(nodbUtil.isObject(content) ||
73
- nodbUtil.isSodaDocument(content), 'NJS-006', 1);
74
- nodbUtil.assert(typeof cb === 'function', 'NJS-006', 2);
47
+ nodbUtil.isSodaDocument(content), 'NJS-005', 1);
75
48
 
76
49
  if (!nodbUtil.isSodaDocument(content)) {
77
50
  content = Buffer.from(JSON.stringify(content));
78
51
  }
79
52
 
80
- self._replaceOne(this._options, content, cb);
53
+ this._replaceOne(this._options, content, cb);
81
54
  }
82
55
 
83
- replaceOnePromisified = nodbUtil.promisify(replaceOne);
84
-
85
56
 
86
57
  // To replace one document by a given document based from find() result
87
58
  // This is a terminal function (no further chaining possible)
88
59
  function replaceOneAndGet(content, cb) {
89
- var self = this;
90
-
91
- nodbUtil.assert(arguments.length === 2, 'NJS-009');
60
+ nodbUtil.checkAsyncArgs(arguments, 2, 2);
92
61
  nodbUtil.assert(nodbUtil.isObject(content) ||
93
- nodbUtil.isSodaDocument(content), 'NJS-006', 1);
94
- nodbUtil.assert(typeof cb === 'function', 'NJS-006', 2);
62
+ nodbUtil.isSodaDocument(content), 'NJS-005', 1);
95
63
 
96
64
  if (!nodbUtil.isSodaDocument(content)) {
97
65
  content = Buffer.from(JSON.stringify(content));
98
66
  }
99
67
 
100
- self._replaceOneAndGet(this._options, content, function(err, doc) {
101
- if (doc) {
102
- sodaDocument.extend(doc);
103
- }
104
- cb(err, doc);
105
- });
68
+ this._replaceOneAndGet(this._options, content, cb);
106
69
  }
107
70
 
108
- replaceOneAndGetPromisified = nodbUtil.promisify(replaceOneAndGet);
109
-
110
71
 
111
72
  // To remove documents obtained from find() result
112
73
  // This is a terminal function (no further chaining possible)
113
74
  function remove(cb) {
114
- var self = this;
115
-
116
- nodbUtil.assert(arguments.length === 1, 'NJS-009');
117
- nodbUtil.assert(typeof cb === 'function', 'NJS-006', 1);
75
+ nodbUtil.checkAsyncArgs(arguments, 1, 1);
118
76
 
119
- self._remove(this._options, cb);
77
+ this._remove(this._options, cb);
120
78
  }
121
79
 
122
- removePromisified = nodbUtil.promisify(remove);
123
-
124
80
 
125
81
  // To obtain document-cursor object from find() result
126
82
  // This is a terminal function (no further chaining possible)
127
83
  function getCursor(cb) {
128
- var self = this;
84
+ nodbUtil.checkAsyncArgs(arguments, 1, 1);
129
85
 
130
- nodbUtil.assert(arguments.length === 1, 'NJS-009');
131
- nodbUtil.assert(typeof cb === 'function', 'NJS-006', 1);
132
-
133
- self._getCursor(this._options, function(err, cursor) {
134
- if (cursor) {
135
- sodaDocCursor.extend(cursor, self._oracledb);
136
- }
137
- cb(err, cursor);
138
- });
86
+ this._getCursor(this._options, cb);
139
87
  }
140
88
 
141
- getCursorPromisified = nodbUtil.promisify(getCursor);
142
-
143
89
 
144
90
  // to obtain documents from find() result
145
91
  // This is a terminal function (no further chaining possible)
146
92
  function getDocuments(cb) {
147
- var self = this;
148
-
149
- nodbUtil.assert(arguments.length === 1, 'NJS-009');
150
- nodbUtil.assert(typeof cb === 'function', 'NJS-006', 1);
93
+ nodbUtil.checkAsyncArgs(arguments, 1, 1);
151
94
 
152
- self._getDocuments(this._options, function(err, docs) {
153
- if (err) {
154
- cb(err, null);
155
- return;
156
- }
157
- for (let i = 0; i < docs.length; i++) {
158
- sodaDocument.extend(docs[i]);
159
- }
160
- cb(null, docs);
161
- });
95
+ this._getDocuments(this._options, cb);
162
96
  }
163
97
 
164
- getDocumentsPromisified = nodbUtil.promisify(getDocuments);
165
98
 
166
99
 
167
- // limit property - a non-terminal function and can chain further
168
- function _limit (n) {
169
- nodbUtil.assert(arguments.length === 1, 'NJS-009');
170
- nodbUtil.assert(typeof n === 'number', 'NJS-006', 1);
171
- this._options.limit = n;
172
- return this;
173
- }
100
+ class SodaOperation {
174
101
 
102
+ constructor() {
103
+ this._options = {};
104
+ }
175
105
 
176
- // skip property - a non-terminal function and can chain further
177
- function _skip(n) {
178
- nodbUtil.assert(arguments.length === 1, 'NJS-009');
179
- nodbUtil.assert(typeof n === 'number', 'NJS-006', 1);
180
- this._options.skip = n;
181
- return this;
182
- }
106
+ _extend(oracledb) {
107
+ this.count = nodbUtil.promisify(oracledb, count);
108
+ this.getCursor = nodbUtil.promisify(oracledb, getCursor);
109
+ this.getDocuments = nodbUtil.promisify(oracledb, getDocuments);
110
+ this.getOne = nodbUtil.promisify(oracledb, getOne);
111
+ this.remove = nodbUtil.promisify(oracledb, remove);
112
+ this.replaceOne = nodbUtil.promisify(oracledb, replaceOne);
113
+ this.replaceOneAndGet = nodbUtil.promisify(oracledb, replaceOneAndGet);
114
+ }
183
115
 
184
- // version property - a non-terminal function and can chain further
185
- function _version(v) {
186
- nodbUtil.assert(arguments.length === 1, 'NJS-009');
187
- nodbUtil.assert(typeof v === 'string', 'NJS-006', 1);
188
- this._options.version = v;
189
- return this;
190
- }
116
+ // filter property - a non-terminal function and can chain further
117
+ filter(f) {
118
+ nodbUtil.checkArgCount (arguments, 1, 1);
119
+ nodbUtil.assert(nodbUtil.isObject(f), 'NJS-005', 1);
120
+ this._options.filter = JSON.stringify(f);
121
+ return this;
122
+ }
191
123
 
192
- // filter property - a non-terminal function and can chain further
193
- function _filter(f) {
194
- nodbUtil.assert(arguments.length === 1, 'NJS-009');
195
- nodbUtil.assert(nodbUtil.isObject(f), 'NJS-006', 1);
196
- this._options.filter = JSON.stringify(f);
197
- return this;
198
- }
124
+ // key - a non-terminal function and can chain further
125
+ key(k) {
126
+ nodbUtil.checkArgCount(arguments, 1, 1);
127
+ nodbUtil.assert(typeof k === 'string', 'NJS-005', 1);
128
+ this._options.key = k;
129
+ this._options.keys = undefined;
130
+ return this;
131
+ }
199
132
 
200
- // key - a non-terminal function and can chain further
201
- function _key(k) {
202
- nodbUtil.assert(arguments.length === 1, 'NJS-009');
203
- nodbUtil.assert(typeof k === 'string', 'NJS-006', 1);
204
- this._options.key = k;
205
- this._options.keys = undefined;
206
- return this;
207
- }
133
+ // keys - a non-terminal function and can chain further
134
+ keys(arr) {
135
+ nodbUtil.checkArgCount(arguments, 1, 1);
136
+ nodbUtil.assert(Array.isArray(arr), 'NJS-005', 1);
208
137
 
209
- // keys - a non-terminal function and can chain further
210
- function _keys(arr) {
211
- nodbUtil.assert(arguments.length === 1, 'NJS-009');
212
- nodbUtil.assert(Array.isArray(arr), 'NJS-006', 1);
138
+ for (let i = 0; i < arr.length; i++) {
139
+ nodbUtil.assert(typeof arr[i] === 'string', 'NJS-005', 1);
140
+ }
213
141
 
214
- for (let i = 0; i < arr.length; i++) {
215
- nodbUtil.assert(typeof arr[i] === 'string', 'NJS-006', 1);
142
+ this._options.keys = arr;
143
+ this._options.key = undefined;
144
+ return this;
216
145
  }
217
146
 
218
- this._options.keys = arr;
219
- this._options.key = undefined;
220
- return this;
221
- }
147
+ // limit property - a non-terminal function and can chain further
148
+ limit (n) {
149
+ nodbUtil.checkArgCount(arguments, 1, 1);
150
+ nodbUtil.assert(typeof n === 'number', 'NJS-005', 1);
151
+ this._options.limit = n;
152
+ return this;
153
+ }
154
+
155
+ // skip property - a non-terminal function and can chain further
156
+ skip(n) {
157
+ nodbUtil.checkArgCount(arguments, 1, 1);
158
+ nodbUtil.assert(typeof n === 'number', 'NJS-005', 1);
159
+ this._options.skip = n;
160
+ return this;
161
+ }
222
162
 
163
+ // version property - a non-terminal function and can chain further
164
+ version(v) {
165
+ nodbUtil.checkArgCount(arguments, 1, 1);
166
+ nodbUtil.assert(typeof v === 'string', 'NJS-005', 1);
167
+ this._options.version = v;
168
+ return this;
169
+ }
223
170
 
224
- // The extend method is used to extend the sodaOperation istance from C Layer
225
- // with custom properties and method overrides. References to the original
226
- // methods are maintained so they can be invoked by the overriding method at
227
- // the right time
228
- function extend(sodaOp, oracledb) {
229
- // Using Object.defineProperties to add properties to the soda instance with
230
- // special properties
231
- Object.defineProperties (
232
- sodaOp,
233
- {
234
- _oracledb: {
235
- value: oracledb
236
- },
237
- limit: {
238
- value: _limit,
239
- enumerable: true,
240
- writable: true
241
- },
242
- skip: {
243
- value: _skip,
244
- enumerable: true,
245
- writable: true
246
- },
247
- version: {
248
- value: _version,
249
- enumerable: true,
250
- writable: true
251
- },
252
- filter: {
253
- value: _filter,
254
- enumerable: true,
255
- writable: true
256
- },
257
- key: {
258
- value: _key,
259
- enumerable: true,
260
- writable: true
261
- },
262
- keys: {
263
- value: _keys,
264
- enumerable: true,
265
- writable: true
266
- },
267
- _options: {
268
- value: {}
269
- },
270
- _count: {
271
- value: sodaOp.count
272
- },
273
- count: {
274
- value: countPromisified,
275
- enumerable: true,
276
- writable: true
277
- },
278
- _getOne: {
279
- value: sodaOp.getOne
280
- },
281
- getOne: {
282
- value: getOnePromisified,
283
- enumerable: true,
284
- writable: true
285
- },
286
- _replaceOne: {
287
- value: sodaOp.replaceOne
288
- },
289
- replaceOne: {
290
- value: replaceOnePromisified,
291
- enumerable: true,
292
- writable: true
293
- },
294
- _replaceOneAndGet: {
295
- value: sodaOp.replaceOneAndGet
296
- },
297
- replaceOneAndGet: {
298
- value: replaceOneAndGetPromisified,
299
- enumerable: true,
300
- writable: true
301
- },
302
- _remove: {
303
- value: sodaOp.remove
304
- },
305
- remove: {
306
- value: removePromisified,
307
- enumerable: true,
308
- writable: true
309
- },
310
- _getCursor: {
311
- value: sodaOp.getCursor
312
- },
313
- getCursor: {
314
- value: getCursorPromisified,
315
- enumerable: true,
316
- writable: true
317
- },
318
- _getDocuments: {
319
- value: sodaOp.getDocuments
320
- },
321
- getDocuments: {
322
- value: getDocumentsPromisified,
323
- enumerable: true,
324
- writable: true
325
- }
326
- }
327
- );
328
171
  }
329
172
 
330
- module.exports.extend = extend;
173
+
174
+ module.exports = SodaOperation;
package/lib/util.js CHANGED
@@ -1,64 +1,66 @@
1
- /* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. */
2
-
3
- /******************************************************************************
4
- *
5
- * You may not use the identified files except in compliance with the Apache
6
- * License, Version 2.0 (the "License.")
7
- *
8
- * You may obtain a copy of the License at
9
- * http://www.apache.org/licenses/LICENSE-2.0.
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- *
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- *
18
- *****************************************************************************/
1
+ // Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved
2
+
3
+ //-----------------------------------------------------------------------------
4
+ //
5
+ // You may not use the identified files except in compliance with the Apache
6
+ // License, Version 2.0 (the "License.")
7
+ //
8
+ // You may obtain a copy of the License at
9
+ // http://www.apache.org/licenses/LICENSE-2.0.
10
+ //
11
+ // Unless required by applicable law or agreed to in writing, software
12
+ // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ //
15
+ // See the License for the specific language governing permissions and
16
+ // limitations under the License.
17
+ //
18
+ //-----------------------------------------------------------------------------
19
19
 
20
20
  'use strict';
21
21
 
22
- var util = require('util');
22
+ const util = require('util');
23
+
24
+ // node-oracledb version number
25
+ let packageJSON;
26
+ try {
27
+ packageJSON = require('../package.json');
28
+ } catch(err) {
29
+ throw new Error('package.json is missing');
30
+ }
31
+ const PACKAGE_JSON_VERSION = packageJSON.version;
32
+ module.exports.PACKAGE_JSON_VERSION = PACKAGE_JSON_VERSION;
23
33
 
24
34
  // Directory containing the node-oracledb add-on binary
25
35
  const RELEASE_DIR = 'build/Release';
26
36
  module.exports.RELEASE_DIR = RELEASE_DIR;
27
37
 
28
38
  // The default node-oracledb add-on binary filename for this Node.js
29
- const BINARY_FILE = 'oracledb-abi' + process.versions.modules + '-' + process.platform + '-' + process.arch + '.node';
39
+ const BINARY_FILE = 'oracledb-' + PACKAGE_JSON_VERSION + '-' + process.platform + '-' + process.arch + '.node';
30
40
  module.exports.BINARY_FILE = BINARY_FILE;
31
41
 
32
42
  // Staging directory used by maintainers building the npm package
33
43
  const STAGING_DIR = 'package/Staging';
34
44
  module.exports.STAGING_DIR = STAGING_DIR;
35
45
 
36
- var EventEmitter = require('events').EventEmitter;
37
- var eventEmitterKeys = Object.keys(EventEmitter.prototype);
38
- var eventEmitterFuncKeys = eventEmitterKeys.filter(function(key) {
39
- return typeof EventEmitter.prototype[key] === 'function';
40
- });
41
-
42
46
  // errorMessages is for NJS error messages used in the JavaScript layer
43
- var errorMessages = {
47
+ const errorMessages = {
44
48
  'NJS-002': 'NJS-002: invalid pool',
45
49
  'NJS-004': 'NJS-004: invalid value for property %s',
46
50
  'NJS-005': 'NJS-005: invalid value for parameter %d',
47
- 'NJS-006': 'NJS-006: invalid type for parameter %d',
48
51
  'NJS-009': 'NJS-009: invalid number of parameters',
49
- 'NJS-014': 'NJS-014: %s is a read-only property',
50
52
  'NJS-037': 'NJS-037: incompatible type of value provided',
51
- 'NJS-040': 'NJS-040: connection request timeout',
53
+ 'NJS-040': 'NJS-040: connection request timeout. Request exceeded queueTimeout of %d',
52
54
  'NJS-041': 'NJS-041: cannot convert ResultSet to QueryStream after invoking methods',
53
55
  'NJS-042': 'NJS-042: cannot invoke ResultSet methods after converting to QueryStream',
54
56
  'NJS-043': 'NJS-043: ResultSet already converted to QueryStream',
55
57
  'NJS-045': 'NJS-045: cannot load a node-oracledb binary for Node.js ' + process.versions.node + ' (' + process.platform + ' ' + process.arch + ') %s',
56
58
  'NJS-046': 'NJS-046: poolAlias "%s" already exists in the connection pool cache',
57
59
  'NJS-047': 'NJS-047: poolAlias "%s" not found in the connection pool cache',
58
- 'NJS-054': 'NJS-054: binary build/Release/oracledb.node was not installed',
59
60
  'NJS-064': 'NJS-064: connection pool is closing',
60
61
  'NJS-065': 'NJS-065: connection pool was closed',
61
- 'NJS-067': 'NJS-067: a pre-built node-oracledb binary was not found for Node.js %s'
62
+ 'NJS-067': 'NJS-067: a pre-built node-oracledb binary was not found for %s',
63
+ 'NJS-069': 'NJS-069: node-oracledb %s requires Node.js %s or later',
62
64
  };
63
65
 
64
66
  // getInstallURL returns a string with installation URL
@@ -70,8 +72,8 @@ module.exports.getInstallURL = getInstallURL;
70
72
 
71
73
  // getInstallHelp returns a string with installation usage tips that may be helpful
72
74
  function getInstallHelp() {
73
- var arch, url;
74
- var mesg = getInstallURL() + '\n';
75
+ let arch, url;
76
+ let mesg = getInstallURL() + '\n';
75
77
  if (process.platform === 'linux') {
76
78
  if (process.arch === 'x64') {
77
79
  url = 'http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html\n';
@@ -125,35 +127,20 @@ function getInstallHelp() {
125
127
 
126
128
  module.exports.getInstallHelp = getInstallHelp;
127
129
 
128
- // makeEventEmitter is used to make class instances inherit from the EventEmitter
129
- // class. This is needed because we extend instances from the C layer and thus
130
- // don't have JavaScript constructor functions we can use for more traditional
131
- // inheritance.
132
- function makeEventEmitter(instance){
133
- eventEmitterFuncKeys.forEach(function(key) {
134
- instance[key] = EventEmitter.prototype[key];
135
- });
136
-
137
- EventEmitter.call(instance);
138
- }
139
-
140
- module.exports.makeEventEmitter = makeEventEmitter;
141
-
142
- // getErrorMessage is used to get and format error messages to make throwing errors
143
- // a little more convenient.
144
- function getErrorMessage(errorCode, messageArg1) {
145
- if (messageArg1) {
146
- return util.format(errorMessages[errorCode], messageArg1);
147
- } else {
148
- return util.format(errorMessages[errorCode]);
149
- }
130
+ // getErrorMessage is used to get and format error messages to make throwing
131
+ // errors a little more convenient.
132
+ function getErrorMessage(errorCode) {
133
+ let args = Array.prototype.slice.call(arguments);
134
+ args[0] = errorMessages[errorCode];
135
+ return util.format.apply(util, args);
150
136
  }
151
137
 
152
138
  module.exports.getErrorMessage = getErrorMessage;
153
139
 
154
- // assert it typically used in the beginning of public functions to assert preconditions
155
- // for the function to execute. Most commonly it's used to validate arguments lenght
156
- // and types and throw an error if they don't match what is expected.
140
+ // assert is typically used at the beginning of public functions to assert
141
+ // preconditions for the function to execute. Most commonly it is used to
142
+ // validate the number of arguments and their types and throw an error if they
143
+ // don't match what is expected.
157
144
  function assert(condition, errorCode, messageArg1) {
158
145
  if (!condition) {
159
146
  throw new Error(getErrorMessage(errorCode, messageArg1));
@@ -162,26 +149,46 @@ function assert(condition, errorCode, messageArg1) {
162
149
 
163
150
  module.exports.assert = assert;
164
151
 
152
+ // checkArgCount is used to validate the number of arguments, particularly with
153
+ // optional parameters (range of number of parameters). If the number of
154
+ // arguments is not within the given range, an error is thrown.
155
+ function checkArgCount(args, minArgCount, maxArgCount) {
156
+ if (args.length < minArgCount || args.length > maxArgCount)
157
+ throw new Error(getErrorMessage('NJS-009'));
158
+ }
159
+
160
+ module.exports.checkArgCount = checkArgCount;
161
+
162
+
163
+ // checkAsyncArgs is used to validate number of arguments and last parameter
164
+ // is of type 'function'. This is used by all asynchronous functions where
165
+ // the last parameter is expected to be a function.
166
+ function checkAsyncArgs (args, minArgCount, maxArgCount) {
167
+ checkArgCount(args, minArgCount, maxArgCount);
168
+ assert(typeof args[args.length - 1] === 'function', 'NJS-005', args.length);
169
+ }
170
+
171
+ module.exports.checkAsyncArgs = checkAsyncArgs;
172
+
173
+
165
174
  // The promisify function is used to wrap async methods to add optional promise
166
175
  // support. If the last parameter passed to a method is a function, then it is
167
176
  // assumed that the callback pattern is being used and the method is invoked as
168
- // usual. Otherwise a promise is returned and later resolved or rejected based on
169
- // the return of the method.
170
- function promisify(func) {
177
+ // usual. Otherwise a promise is returned and later resolved or rejected based
178
+ // on the return of the method.
179
+ function promisify(oracledb, func) {
171
180
  return function() {
172
- var self = this;
173
- var args;
181
+ const self = this;
182
+ let args;
174
183
 
175
- // This/self could refer to the base class instance, pool, connection, etc. All
176
- // class instances have a private reference to the base class for convenience.
177
- if (!self._oracledb.Promise || typeof arguments[arguments.length - 1] === 'function') {
184
+ if (!oracledb.Promise || typeof arguments[arguments.length - 1] === 'function') {
178
185
  return func.apply(self, arguments);
179
186
  } else {
180
187
  // Converting to an array so we can extend it later with a custom callback
181
188
  args = Array.prototype.slice.call(arguments);
182
189
 
183
- return new self._oracledb.Promise(function(resolve, reject) {
184
- var errorCode;
190
+ return new oracledb.Promise(function(resolve, reject) {
191
+ let errorCode;
185
192
 
186
193
  try {
187
194
  args[args.length] = function(err, result) {
@@ -194,11 +201,11 @@ function promisify(func) {
194
201
 
195
202
  func.apply(self, args);
196
203
  } catch (err) {
197
- errorCode = err.message.substr(0, 7);
204
+ errorCode = err.message.substr(0, err.message.indexOf(':'));
198
205
 
199
206
  // Check for invalid number or type of parameter(s) as they should be
200
207
  // eagerly thrown.
201
- if (errorCode === 'NJS-009' || errorCode === 'NJS-006') {
208
+ if (errorCode === 'NJS-009' || errorCode === 'NJS-005') {
202
209
  // Throwing the error outside of the promise wrapper so that its not
203
210
  // swallowed up as a rejection.
204
211
  process.nextTick(function() {