@@ -73,24 +73,21 @@ function execute(sql, a2, a3, a4) {
73
73
let executeCb ;
74
74
let custExecuteCb ;
75
75
76
- nodbUtil . assert ( arguments . length > 1 && arguments . length < 5 , 'NJS-009' ) ;
76
+ nodbUtil . checkAsyncArgs ( arguments , 2 , 4 ) ;
77
77
nodbUtil . assert ( typeof sql === 'string' , 'NJS-005' , 1 ) ;
78
78
79
79
switch ( arguments . length ) {
80
80
case 2 :
81
- nodbUtil . assert ( typeof a2 === 'function' , 'NJS-005' , 2 ) ;
82
81
executeCb = a2 ;
83
82
break ;
84
83
case 3 :
85
84
nodbUtil . assert ( nodbUtil . isObjectOrArray ( a2 ) , 'NJS-005' , 2 ) ;
86
- nodbUtil . assert ( typeof a3 === 'function' , 'NJS-005' , 3 ) ;
87
85
binds = a2 ;
88
86
executeCb = a3 ;
89
87
break ;
90
88
case 4 :
91
89
nodbUtil . assert ( nodbUtil . isObjectOrArray ( a2 ) , 'NJS-005' , 2 ) ;
92
90
nodbUtil . assert ( nodbUtil . isObject ( a3 ) , 'NJS-005' , 3 ) ;
93
- nodbUtil . assert ( typeof a4 === 'function' , 'NJS-005' , 4 ) ;
94
91
binds = a2 ;
95
92
executeOpts = a3 ;
96
93
executeCb = a4 ;
@@ -177,7 +174,7 @@ function executeMany(sql, bindsOrNumIters, a3, a4) {
177
174
let executeCb ;
178
175
let okBinds ;
179
176
180
- nodbUtil . assert ( arguments . length > 2 && arguments . length < 5 , 'NJS-009' ) ;
177
+ nodbUtil . checkAsyncArgs ( arguments , 3 , 4 ) ;
181
178
nodbUtil . assert ( typeof sql === 'string' , 'NJS-005' , 1 ) ;
182
179
if ( typeof bindsOrNumIters === 'number' ) {
183
180
nodbUtil . assert ( Number . isInteger ( bindsOrNumIters ) , 'NJS-005' , 2 ) ;
@@ -189,12 +186,10 @@ function executeMany(sql, bindsOrNumIters, a3, a4) {
189
186
190
187
switch ( arguments . length ) {
191
188
case 3 :
192
- nodbUtil . assert ( typeof a3 === 'function' , 'NJS-005' , 3 ) ;
193
189
executeCb = a3 ;
194
190
break ;
195
191
case 4 :
196
192
nodbUtil . assert ( nodbUtil . isObject ( a3 ) , 'NJS-005' , 3 ) ;
197
- nodbUtil . assert ( typeof a4 === 'function' , 'NJS-005' , 4 ) ;
198
193
options = a3 ;
199
194
executeCb = a4 ;
200
195
break ;
@@ -211,9 +206,8 @@ function executeMany(sql, bindsOrNumIters, a3, a4) {
211
206
// first, but if not found, the database is queried and the result is cached
212
207
// using the fully qualified name
213
208
function getDbObjectClass ( name , cb ) {
214
- nodbUtil . assert ( arguments . length === 2 , 'NJS-009' ) ;
209
+ nodbUtil . checkAsyncArgs ( arguments , 2 , 2 ) ;
215
210
nodbUtil . assert ( typeof name === 'string' , 'NJS-005' , 1 ) ;
216
- nodbUtil . assert ( typeof cb === 'function' , 'NJS-005' , 2 ) ;
217
211
218
212
// check the cache; if the class is found there, nothing further to do
219
213
let cls = this . _dbObjectClasses [ name ] ;
@@ -231,8 +225,7 @@ function getDbObjectClass(name, cb) {
231
225
function getStatementInfo ( sql , getStatementInfoCb ) {
232
226
const self = this ;
233
227
234
- nodbUtil . assert ( arguments . length === 2 , 'NJS-009' ) ;
235
- nodbUtil . assert ( typeof getStatementInfoCb === 'function' , 'NJS-005' , 1 ) ;
228
+ nodbUtil . checkAsyncArgs ( arguments , 2 , 2 ) ;
236
229
237
230
self . _getStatementInfo . apply ( self , arguments ) ;
238
231
}
@@ -241,18 +234,15 @@ function getStatementInfo(sql, getStatementInfoCb) {
241
234
function commit ( commitCb ) {
242
235
const self = this ;
243
236
244
- nodbUtil . assert ( arguments . length === 1 , 'NJS-009' ) ;
245
- nodbUtil . assert ( typeof commitCb === 'function' , 'NJS-005' , 1 ) ;
246
-
237
+ nodbUtil . checkAsyncArgs ( arguments , 1 , 1 ) ;
247
238
self . _commit . apply ( self , arguments ) ;
248
239
}
249
240
250
241
// This createLob function is just a place holder to allow for easier extension later.
251
242
function createLob ( type , createLobCb ) {
252
243
const self = this ;
253
244
254
- nodbUtil . assert ( arguments . length === 2 , 'NJS-009' ) ;
255
- nodbUtil . assert ( typeof createLobCb === 'function' , 'NJS-005' , 2 ) ;
245
+ nodbUtil . checkAsyncArgs ( arguments , 2 , 2 ) ;
256
246
257
247
self . _createLob . apply ( self , arguments ) ;
258
248
}
@@ -261,8 +251,7 @@ function createLob(type, createLobCb) {
261
251
function rollback ( rollbackCb ) {
262
252
const self = this ;
263
253
264
- nodbUtil . assert ( arguments . length === 1 , 'NJS-009' ) ;
265
- nodbUtil . assert ( typeof rollbackCb === 'function' , 'NJS-005' , 1 ) ;
254
+ nodbUtil . checkAsyncArgs ( arguments , 1 , 1 ) ;
266
255
267
256
self . _rollback . apply ( self , arguments ) ;
268
257
}
@@ -274,16 +263,14 @@ function close(a1, a2) {
274
263
let options = { } ;
275
264
let closeCb ;
276
265
277
- nodbUtil . assert ( arguments . length >= 1 && arguments . length <= 2 , 'NJS-009' ) ;
266
+ nodbUtil . checkAsyncArgs ( arguments , 1 , 2 ) ;
278
267
279
268
switch ( arguments . length ) {
280
269
case 1 :
281
- nodbUtil . assert ( typeof a1 === 'function' , 'NJS-005' , 1 ) ;
282
270
closeCb = a1 ;
283
271
break ;
284
272
case 2 :
285
273
nodbUtil . assert ( nodbUtil . isObject ( a1 ) , 'NJS-005' , 1 ) ;
286
- nodbUtil . assert ( typeof a2 === 'function' , 'NJS-005' , 2 ) ;
287
274
options = a1 ;
288
275
closeCb = a2 ;
289
276
break ;
@@ -307,8 +294,7 @@ function close(a1, a2) {
307
294
module . break = function ( breakCb ) {
308
295
const self = this ;
309
296
310
- nodbUtil . assert ( arguments . length === 1 , 'NJS-009' ) ;
311
- nodbUtil . assert ( typeof breakCb === 'function' , 'NJS-005' , 1 ) ;
297
+ nodbUtil . checkAsyncArgs ( arguments , 1 , 1 ) ;
312
298
313
299
self . _break . apply ( self , arguments ) ;
314
300
} ;
@@ -317,7 +303,7 @@ module.break = function(breakCb) {
317
303
function changePassword ( user , password , newPassword , changePasswordCb ) {
318
304
const self = this ;
319
305
320
- nodbUtil . assert ( arguments . length === 4 , 'NJS-009' ) ;
306
+ nodbUtil . checkAsyncArgs ( arguments , 4 , 4 ) ;
321
307
nodbUtil . assert ( typeof user === 'string' , 'NJS-005' , 1 ) ;
322
308
nodbUtil . assert ( typeof password === 'string' , 'NJS-005' , 2 ) ;
323
309
nodbUtil . assert ( typeof newPassword === 'string' , 'NJS-005' , 3 ) ;
@@ -330,16 +316,15 @@ function changePassword(user, password, newPassword, changePasswordCb) {
330
316
function getQueue ( name , a2 , a3 ) {
331
317
let options = { } ;
332
318
let queueCb ;
333
- nodbUtil . assert ( arguments . length >= 2 && arguments . length <= 3 , 'NJS-009' ) ;
319
+
320
+ nodbUtil . checkAsyncArgs ( arguments , 2 , 3 ) ;
334
321
nodbUtil . assert ( typeof name === 'string' , 'NJS-005' , 1 ) ;
335
322
switch ( arguments . length ) {
336
323
case 2 :
337
- nodbUtil . assert ( typeof a2 === 'function' , 'NJS-005' , 2 ) ;
338
324
queueCb = a2 ;
339
325
break ;
340
326
case 3 :
341
327
nodbUtil . assert ( nodbUtil . isObject ( a2 ) , 'NJS-005' , 2 ) ;
342
- nodbUtil . assert ( typeof a3 === 'function' , 'NJS-005' , 3 ) ;
343
328
options = a2 ;
344
329
queueCb = a3 ;
345
330
break ;
@@ -351,9 +336,7 @@ function getQueue(name, a2, a3) {
351
336
function ping ( pingCb ) {
352
337
const self = this ;
353
338
354
- nodbUtil . assert ( arguments . length === 1 , 'NJS-009' ) ;
355
- nodbUtil . assert ( typeof pingCb === 'function' , 'NJS-005' , 1 ) ;
356
-
339
+ nodbUtil . checkAsyncArgs ( arguments , 1 , 1 ) ;
357
340
self . _ping . apply ( self , arguments ) ;
358
341
}
359
342
@@ -362,20 +345,18 @@ function ping(pingCb) {
362
345
function subscribe ( name , options , subscribeCb ) {
363
346
const self = this ;
364
347
365
- nodbUtil . assert ( arguments . length == 3 , 'NJS-009' ) ;
348
+ nodbUtil . checkAsyncArgs ( arguments , 3 , 3 ) ;
366
349
nodbUtil . assert ( typeof name === 'string' , 'NJS-005' , 1 ) ;
367
350
nodbUtil . assert ( nodbUtil . isObject ( options ) , 'NJS-005' , 2 ) ;
368
- nodbUtil . assert ( typeof subscribeCb === 'function' , 'NJS-005' , 3 ) ;
369
351
self . _subscribe . call ( self , name , options , subscribeCb ) ;
370
352
}
371
353
372
354
// destroy a subscription which was earlier created using subscribe()
373
355
function unsubscribe ( name , cb ) {
374
356
const self = this ;
375
357
376
- nodbUtil . assert ( arguments . length == 2 , 'NJS-009' ) ;
358
+ nodbUtil . checkAsyncArgs ( arguments , 2 , 2 ) ;
377
359
nodbUtil . assert ( typeof name === 'string' , 'NJS-005' , 1 ) ;
378
- nodbUtil . assert ( typeof cb === 'function' , 'NJS-005' , 2 ) ;
379
360
380
361
self . _unsubscribe . call ( self , name , cb ) ;
381
362
}
@@ -447,7 +428,7 @@ class Connection extends EventEmitter {
447
428
// To obtain a SodaDatabase object (high-level SODA object associated with
448
429
// current connection)
449
430
getSodaDatabase ( ) {
450
- nodbUtil . assert ( arguments . length === 0 , 'NJS-009' ) ;
431
+ nodbUtil . checkArgCount ( arguments , 0 , 0 ) ;
451
432
return this . _getSodaDatabase ( ) ;
452
433
}
453
434
@@ -457,7 +438,7 @@ class Connection extends EventEmitter {
457
438
const self = this ;
458
439
let stream ;
459
440
460
- nodbUtil . assert ( arguments . length > 0 && arguments . length < 4 , 'NJS-009' ) ;
441
+ nodbUtil . checkArgCount ( arguments , 1 , 3 ) ;
461
442
nodbUtil . assert ( typeof sql === 'string' , 'NJS-005' , 1 ) ;
462
443
463
444
if ( binding ) {
0 commit comments