gremlin 3.5.2 → 3.5.3

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 (88) hide show
  1. package/.eslintrc.js +154 -0
  2. package/.prettierrc.js +29 -0
  3. package/Gruntfile.js +15 -16
  4. package/doc/AnonymousTraversalSource.html +4 -4
  5. package/doc/Authenticator.html +1 -1
  6. package/doc/Bytecode.html +6 -6
  7. package/doc/Client.html +137 -63
  8. package/doc/Connection.html +88 -4
  9. package/doc/DriverRemoteConnection.html +10 -10
  10. package/doc/EdgeLabelVerificationStrategy.html +1 -1
  11. package/doc/Graph.html +1 -1
  12. package/doc/GraphSON2Reader.html +3 -3
  13. package/doc/GraphSON2Writer.html +2 -2
  14. package/doc/GraphSON3Reader.html +2 -2
  15. package/doc/GraphSON3Writer.html +2 -2
  16. package/doc/GraphTraversal.html +106 -106
  17. package/doc/GraphTraversalSource.html +18 -18
  18. package/doc/HaltedTraverserStrategy.html +2 -2
  19. package/doc/MatchAlgorithmStrategy.html +2 -2
  20. package/doc/P.html +12 -12
  21. package/doc/PartitionStrategy.html +2 -2
  22. package/doc/Path.html +1 -1
  23. package/doc/PlainTextSaslAuthenticator.html +1 -1
  24. package/doc/ProductiveByStrategy.html +1 -1
  25. package/doc/RemoteConnection.html +9 -9
  26. package/doc/RemoteStrategy.html +3 -3
  27. package/doc/RemoteTraversal.html +2 -2
  28. package/doc/ReservedKeysVerificationStrategy.html +2 -2
  29. package/doc/ResponseError.html +1 -1
  30. package/doc/ResultSet.html +6 -6
  31. package/doc/SaslAuthenticator.html +1 -1
  32. package/doc/SaslMechanismBase.html +1 -1
  33. package/doc/SaslMechanismPlain.html +5 -5
  34. package/doc/SeedStrategy.html +2 -2
  35. package/doc/SubgraphStrategy.html +2 -2
  36. package/doc/TextP.html +9 -9
  37. package/doc/Transaction.html +5 -5
  38. package/doc/Translator.html +1 -1
  39. package/doc/TraversalStrategies.html +4 -4
  40. package/doc/TraversalStrategy.html +2 -2
  41. package/doc/TypeSerializer.html +1 -1
  42. package/doc/driver_auth_authenticator.js.html +3 -3
  43. package/doc/driver_auth_mechanisms_sasl-mechanism-base.js.html +2 -2
  44. package/doc/driver_auth_mechanisms_sasl-mechanism-plain.js.html +25 -16
  45. package/doc/driver_auth_plain-text-sasl-authenticator.js.html +6 -6
  46. package/doc/driver_auth_sasl-authenticator.js.html +2 -2
  47. package/doc/driver_client.js.html +69 -23
  48. package/doc/driver_connection.js.html +107 -88
  49. package/doc/driver_driver-remote-connection.js.html +11 -10
  50. package/doc/driver_remote-connection.js.html +3 -4
  51. package/doc/driver_response-error.js.html +4 -3
  52. package/doc/driver_result-set.js.html +3 -3
  53. package/doc/global.html +199 -2
  54. package/doc/index.html +1 -1
  55. package/doc/process_anonymous-traversal.js.html +3 -3
  56. package/doc/process_bytecode.js.html +10 -8
  57. package/doc/process_graph-traversal.js.html +193 -142
  58. package/doc/process_transaction.js.html +15 -8
  59. package/doc/process_translator.js.html +13 -10
  60. package/doc/process_traversal-strategy.js.html +59 -53
  61. package/doc/process_traversal.js.html +100 -107
  62. package/doc/structure_graph.js.html +6 -6
  63. package/doc/structure_io_graph-serializer.js.html +64 -17
  64. package/doc/structure_io_type-serializers.js.html +85 -88
  65. package/index.js +5 -5
  66. package/lib/driver/auth/authenticator.js +2 -2
  67. package/lib/driver/auth/mechanisms/sasl-mechanism-base.js +1 -1
  68. package/lib/driver/auth/mechanisms/sasl-mechanism-plain.js +24 -15
  69. package/lib/driver/auth/plain-text-sasl-authenticator.js +5 -5
  70. package/lib/driver/auth/sasl-authenticator.js +1 -1
  71. package/lib/driver/client.js +68 -22
  72. package/lib/driver/connection.js +106 -87
  73. package/lib/driver/driver-remote-connection.js +10 -9
  74. package/lib/driver/remote-connection.js +2 -3
  75. package/lib/driver/response-error.js +2 -2
  76. package/lib/driver/result-set.js +1 -2
  77. package/lib/process/anonymous-traversal.js +1 -2
  78. package/lib/process/bytecode.js +9 -7
  79. package/lib/process/graph-traversal.js +191 -141
  80. package/lib/process/transaction.js +13 -7
  81. package/lib/process/translator.js +11 -9
  82. package/lib/process/traversal-strategy.js +57 -52
  83. package/lib/process/traversal.js +99 -106
  84. package/lib/structure/graph.js +5 -5
  85. package/lib/structure/io/graph-serializer.js +62 -16
  86. package/lib/structure/io/type-serializers.js +84 -87
  87. package/lib/utils.js +15 -10
  88. package/package.json +10 -5
@@ -81,38 +81,36 @@ class NumberSerializer extends TypeSerializer {
81
81
  if (isNaN(item)) {
82
82
  return {
83
83
  [typeKey]: 'g:Double',
84
- [valueKey]: 'NaN'
84
+ [valueKey]: 'NaN',
85
85
  };
86
86
  } else if (item === Number.POSITIVE_INFINITY) {
87
87
  return {
88
88
  [typeKey]: 'g:Double',
89
- [valueKey]: 'Infinity'
89
+ [valueKey]: 'Infinity',
90
90
  };
91
91
  } else if (item === Number.NEGATIVE_INFINITY) {
92
92
  return {
93
93
  [typeKey]: 'g:Double',
94
- [valueKey]: '-Infinity'
94
+ [valueKey]: '-Infinity',
95
95
  };
96
- } else {
97
- return item;
98
96
  }
97
+ return item;
99
98
  }
100
99
 
101
100
  deserialize(obj) {
102
- var val = obj[valueKey];
101
+ const val = obj[valueKey];
103
102
  if (val === 'NaN') {
104
103
  return NaN;
105
104
  } else if (val === 'Infinity') {
106
105
  return Number.POSITIVE_INFINITY;
107
106
  } else if (val === '-Infinity') {
108
107
  return Number.NEGATIVE_INFINITY;
109
- } else {
110
- return parseFloat(val);
111
108
  }
109
+ return parseFloat(val);
112
110
  }
113
111
 
114
112
  canBeUsedFor(value) {
115
- return (typeof value === 'number');
113
+ return typeof value === 'number';
116
114
  }
117
115
  }
118
116
 
@@ -120,7 +118,7 @@ class DateSerializer extends TypeSerializer {
120
118
  serialize(item) {
121
119
  return {
122
120
  [typeKey]: 'g:Date',
123
- [valueKey]: item.getTime()
121
+ [valueKey]: item.getTime(),
124
122
  };
125
123
  }
126
124
 
@@ -129,7 +127,7 @@ class DateSerializer extends TypeSerializer {
129
127
  }
130
128
 
131
129
  canBeUsedFor(value) {
132
- return (value instanceof Date);
130
+ return value instanceof Date;
133
131
  }
134
132
  }
135
133
 
@@ -137,12 +135,12 @@ class LongSerializer extends TypeSerializer {
137
135
  serialize(item) {
138
136
  return {
139
137
  [typeKey]: 'g:Int64',
140
- [valueKey]: item.value
138
+ [valueKey]: item.value,
141
139
  };
142
140
  }
143
141
 
144
142
  canBeUsedFor(value) {
145
- return (value instanceof utils.Long);
143
+ return value instanceof utils.Long;
146
144
  }
147
145
  }
148
146
 
@@ -154,7 +152,7 @@ class BytecodeSerializer extends TypeSerializer {
154
152
  }
155
153
  const result = {};
156
154
  result[typeKey] = 'g:Bytecode';
157
- const resultValue = result[valueKey] = {};
155
+ const resultValue = (result[valueKey] = {});
158
156
  const sources = this._serializeInstructions(bytecode.sourceInstructions);
159
157
  if (sources) {
160
158
  resultValue['source'] = sources;
@@ -173,13 +171,13 @@ class BytecodeSerializer extends TypeSerializer {
173
171
  const result = new Array(instructions.length);
174
172
  result[0] = instructions[0];
175
173
  for (let i = 0; i < instructions.length; i++) {
176
- result[i] = instructions[i].map(item => this.writer.adaptObject(item));
174
+ result[i] = instructions[i].map((item) => this.writer.adaptObject(item));
177
175
  }
178
176
  return result;
179
177
  }
180
178
 
181
179
  canBeUsedFor(value) {
182
- return (value instanceof Bytecode) || (value instanceof t.Traversal);
180
+ return value instanceof Bytecode || value instanceof t.Traversal;
183
181
  }
184
182
  }
185
183
 
@@ -188,20 +186,19 @@ class PSerializer extends TypeSerializer {
188
186
  serialize(item) {
189
187
  const result = {};
190
188
  result[typeKey] = 'g:P';
191
- const resultValue = result[valueKey] = {
192
- 'predicate': item.operator
193
- };
189
+ const resultValue = (result[valueKey] = {
190
+ predicate: item.operator,
191
+ });
194
192
  if (item.other === undefined || item.other === null) {
195
193
  resultValue['value'] = this.writer.adaptObject(item.value);
196
- }
197
- else {
198
- resultValue['value'] = [ this.writer.adaptObject(item.value), this.writer.adaptObject(item.other) ];
194
+ } else {
195
+ resultValue['value'] = [this.writer.adaptObject(item.value), this.writer.adaptObject(item.other)];
199
196
  }
200
197
  return result;
201
198
  }
202
199
 
203
200
  canBeUsedFor(value) {
204
- return (value instanceof t.P);
201
+ return value instanceof t.P;
205
202
  }
206
203
  }
207
204
 
@@ -210,20 +207,19 @@ class TextPSerializer extends TypeSerializer {
210
207
  serialize(item) {
211
208
  const result = {};
212
209
  result[typeKey] = 'g:TextP';
213
- const resultValue = result[valueKey] = {
214
- 'predicate': item.operator
215
- };
210
+ const resultValue = (result[valueKey] = {
211
+ predicate: item.operator,
212
+ });
216
213
  if (item.other === undefined || item.other === null) {
217
214
  resultValue['value'] = this.writer.adaptObject(item.value);
218
- }
219
- else {
220
- resultValue['value'] = [ this.writer.adaptObject(item.value), this.writer.adaptObject(item.other) ];
215
+ } else {
216
+ resultValue['value'] = [this.writer.adaptObject(item.value), this.writer.adaptObject(item.other)];
221
217
  }
222
218
  return result;
223
219
  }
224
220
 
225
221
  canBeUsedFor(value) {
226
- return (value instanceof t.TextP);
222
+ return value instanceof t.TextP;
227
223
  }
228
224
  }
229
225
 
@@ -233,27 +229,30 @@ class LambdaSerializer extends TypeSerializer {
233
229
  const lambdaDef = item();
234
230
 
235
231
  // check if the language is specified otherwise assume gremlin-groovy.
236
- const returnIsString = typeof(lambdaDef) === 'string';
232
+ const returnIsString = typeof lambdaDef === 'string';
237
233
  const script = returnIsString ? lambdaDef : lambdaDef[0];
238
- const lang = returnIsString ? "gremlin-groovy" : lambdaDef[1];
234
+ const lang = returnIsString ? 'gremlin-groovy' : lambdaDef[1];
239
235
 
240
236
  // detect argument count
241
- const argCount = lang === "gremlin-groovy" && script.includes("->") ?
242
- (script.substring(0, script.indexOf("->")).includes(",") ? 2 : 1) :
243
- -1;
237
+ const argCount =
238
+ lang === 'gremlin-groovy' && script.includes('->')
239
+ ? script.substring(0, script.indexOf('->')).includes(',')
240
+ ? 2
241
+ : 1
242
+ : -1;
244
243
 
245
244
  return {
246
245
  [typeKey]: 'g:Lambda',
247
246
  [valueKey]: {
248
- 'arguments': argCount,
249
- 'language': lang,
250
- 'script': script
251
- }
247
+ arguments: argCount,
248
+ language: lang,
249
+ script: script,
250
+ },
252
251
  };
253
252
  }
254
253
 
255
254
  canBeUsedFor(value) {
256
- return (typeof value === 'function');
255
+ return typeof value === 'function';
257
256
  }
258
257
  }
259
258
 
@@ -262,7 +261,7 @@ class EnumSerializer extends TypeSerializer {
262
261
  serialize(item) {
263
262
  return {
264
263
  [typeKey]: 'g:' + item.typeName,
265
- [valueKey]: item.elementName
264
+ [valueKey]: item.elementName,
266
265
  };
267
266
  }
268
267
 
@@ -277,9 +276,9 @@ class TraverserSerializer extends TypeSerializer {
277
276
  return {
278
277
  [typeKey]: 'g:Traverser',
279
278
  [valueKey]: {
280
- 'value': this.writer.adaptObject(item.object),
281
- 'bulk': this.writer.adaptObject(item.bulk)
282
- }
279
+ value: this.writer.adaptObject(item.object),
280
+ bulk: this.writer.adaptObject(item.bulk),
281
+ },
283
282
  };
284
283
  }
285
284
 
@@ -289,7 +288,7 @@ class TraverserSerializer extends TypeSerializer {
289
288
  }
290
289
 
291
290
  canBeUsedFor(value) {
292
- return (value instanceof t.Traverser);
291
+ return value instanceof t.Traverser;
293
292
  }
294
293
  }
295
294
 
@@ -297,7 +296,7 @@ class TraversalStrategySerializer extends TypeSerializer {
297
296
  /** @param {TraversalStrategy} item */
298
297
  serialize(item) {
299
298
  const conf = {};
300
- for (let k in item.configuration) {
299
+ for (const k in item.configuration) {
301
300
  if (item.configuration.hasOwnProperty(k)) {
302
301
  conf[k] = this.writer.adaptObject(item.configuration[k]);
303
302
  }
@@ -305,12 +304,12 @@ class TraversalStrategySerializer extends TypeSerializer {
305
304
 
306
305
  return {
307
306
  [typeKey]: 'g:' + item.constructor.name,
308
- [valueKey]: conf
307
+ [valueKey]: conf,
309
308
  };
310
309
  }
311
310
 
312
311
  canBeUsedFor(value) {
313
- return (value instanceof ts.TraversalStrategy);
312
+ return value instanceof ts.TraversalStrategy;
314
313
  }
315
314
  }
316
315
 
@@ -325,14 +324,14 @@ class VertexSerializer extends TypeSerializer {
325
324
  return {
326
325
  [typeKey]: 'g:Vertex',
327
326
  [valueKey]: {
328
- 'id': this.writer.adaptObject(item.id),
329
- 'label': item.label
330
- }
327
+ id: this.writer.adaptObject(item.id),
328
+ label: item.label,
329
+ },
331
330
  };
332
331
  }
333
332
 
334
333
  canBeUsedFor(value) {
335
- return (value instanceof g.Vertex);
334
+ return value instanceof g.Vertex;
336
335
  }
337
336
  }
338
337
 
@@ -343,7 +342,7 @@ class VertexPropertySerializer extends TypeSerializer {
343
342
  this.reader.read(value['id']),
344
343
  value['label'],
345
344
  this.reader.read(value['value']),
346
- this.reader.read(value['properties'])
345
+ this.reader.read(value['properties']),
347
346
  );
348
347
  }
349
348
  }
@@ -351,9 +350,7 @@ class VertexPropertySerializer extends TypeSerializer {
351
350
  class PropertySerializer extends TypeSerializer {
352
351
  deserialize(obj) {
353
352
  const value = obj[valueKey];
354
- return new g.Property(
355
- value['key'],
356
- this.reader.read(value['value']));
353
+ return new g.Property(value['key'], this.reader.read(value['value']));
357
354
  }
358
355
  }
359
356
 
@@ -365,7 +362,7 @@ class EdgeSerializer extends TypeSerializer {
365
362
  new g.Vertex(this.reader.read(value['outV']), this.reader.read(value['outVLabel'])),
366
363
  value['label'],
367
364
  new g.Vertex(this.reader.read(value['inV']), this.reader.read(value['inVLabel'])),
368
- this.reader.read(value['properties'])
365
+ this.reader.read(value['properties']),
369
366
  );
370
367
  }
371
368
 
@@ -374,25 +371,25 @@ class EdgeSerializer extends TypeSerializer {
374
371
  return {
375
372
  [typeKey]: 'g:Edge',
376
373
  [valueKey]: {
377
- 'id': this.writer.adaptObject(item.id),
378
- 'label': item.label,
379
- 'outV': this.writer.adaptObject(item.outV.id),
380
- 'outVLabel': item.outV.label,
381
- 'inV': this.writer.adaptObject(item.inV.id),
382
- 'inVLabel': item.inV.label
383
- }
374
+ id: this.writer.adaptObject(item.id),
375
+ label: item.label,
376
+ outV: this.writer.adaptObject(item.outV.id),
377
+ outVLabel: item.outV.label,
378
+ inV: this.writer.adaptObject(item.inV.id),
379
+ inVLabel: item.inV.label,
380
+ },
384
381
  };
385
382
  }
386
383
 
387
384
  canBeUsedFor(value) {
388
- return (value instanceof g.Edge);
385
+ return value instanceof g.Edge;
389
386
  }
390
387
  }
391
388
 
392
389
  class PathSerializer extends TypeSerializer {
393
390
  deserialize(obj) {
394
391
  const value = obj[valueKey];
395
- const objects = value['objects'].map(o => this.reader.read(o));
392
+ const objects = value['objects'].map((o) => this.reader.read(o));
396
393
  return new g.Path(this.reader.read(value['labels']), objects);
397
394
  }
398
395
  }
@@ -411,9 +408,9 @@ class TSerializer extends TypeSerializer {
411
408
  }
412
409
 
413
410
  class DirectionSerializer extends TypeSerializer {
414
- deserialize(obj) {
415
- return t.direction[obj[valueKey].toLowerCase()];
416
- }
411
+ deserialize(obj) {
412
+ return t.direction[obj[valueKey].toLowerCase()];
413
+ }
417
414
  }
418
415
 
419
416
  class ArraySerializer extends TypeSerializer {
@@ -427,14 +424,14 @@ class ArraySerializer extends TypeSerializer {
427
424
  if (!Array.isArray(value)) {
428
425
  throw new Error('Expected Array, obtained: ' + value);
429
426
  }
430
- return value.map(x => this.reader.read(x));
427
+ return value.map((x) => this.reader.read(x));
431
428
  }
432
429
 
433
430
  /** @param {Array} item */
434
431
  serialize(item) {
435
432
  return {
436
433
  [typeKey]: this.typeKey,
437
- [valueKey]: item.map(x => this.writer.adaptObject(x))
434
+ [valueKey]: item.map((x) => this.writer.adaptObject(x)),
438
435
  };
439
436
  }
440
437
 
@@ -445,22 +442,22 @@ class ArraySerializer extends TypeSerializer {
445
442
 
446
443
  class BulkSetSerializer extends TypeSerializer {
447
444
  deserialize(obj) {
448
- const value = obj[valueKey];
449
- if (!Array.isArray(value)) {
450
- throw new Error('Expected Array, obtained: ' + value);
451
- }
445
+ const value = obj[valueKey];
446
+ if (!Array.isArray(value)) {
447
+ throw new Error('Expected Array, obtained: ' + value);
448
+ }
452
449
 
453
- // coerce the BulkSet to List. if the bulk exceeds the int space then we can't coerce to List anyway,
454
- // so this query will be trouble. we'd need a legit BulkSet implementation here in js. this current
455
- // implementation is here to replicate the previous functionality that existed on the server side in
456
- // previous versions.
457
- let result = [];
458
- for (let ix = 0, iy = value.length; ix < iy; ix += 2) {
459
- const pair = value.slice(ix, ix + 2);
460
- result = result.concat(Array(this.reader.read(pair[1])).fill(this.reader.read(pair[0])));
461
- }
450
+ // coerce the BulkSet to List. if the bulk exceeds the int space then we can't coerce to List anyway,
451
+ // so this query will be trouble. we'd need a legit BulkSet implementation here in js. this current
452
+ // implementation is here to replicate the previous functionality that existed on the server side in
453
+ // previous versions.
454
+ let result = [];
455
+ for (let ix = 0, iy = value.length; ix < iy; ix += 2) {
456
+ const pair = value.slice(ix, ix + 2);
457
+ result = result.concat(Array(this.reader.read(pair[1])).fill(this.reader.read(pair[0])));
458
+ }
462
459
 
463
- return result;
460
+ return result;
464
461
  }
465
462
  }
466
463
 
@@ -486,7 +483,7 @@ class MapSerializer extends TypeSerializer {
486
483
  });
487
484
  return {
488
485
  [typeKey]: 'g:Map',
489
- [valueKey]: arr
486
+ [valueKey]: arr,
490
487
  };
491
488
  }
492
489
 
@@ -531,7 +528,7 @@ module.exports = {
531
528
  typeKey,
532
529
  valueKey,
533
530
  VertexPropertySerializer,
534
- VertexSerializer
531
+ VertexSerializer,
535
532
  };
536
533
  </code></pre>
537
534
  </article>
@@ -549,7 +546,7 @@ module.exports = {
549
546
  <br class="clear">
550
547
 
551
548
  <footer>
552
- Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Fri Jan 14 2022 09:04:29 GMT-0500 (Eastern Standard Time)
549
+ Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Mon Apr 11 2022 07:21:14 GMT-0400 (Eastern Daylight Time)
553
550
  </footer>
554
551
 
555
552
  <script> prettyPrint(); </script>
package/index.js CHANGED
@@ -50,8 +50,8 @@ module.exports = {
50
50
  ResultSet,
51
51
  auth: {
52
52
  Authenticator,
53
- PlainTextSaslAuthenticator
54
- }
53
+ PlainTextSaslAuthenticator,
54
+ },
55
55
  },
56
56
  process: {
57
57
  Bytecode,
@@ -79,7 +79,7 @@ module.exports = {
79
79
  Translator,
80
80
  traversal: AnonymousTraversalSource.traversal,
81
81
  AnonymousTraversalSource,
82
- withOptions: t.withOptions
82
+ withOptions: t.withOptions,
83
83
  },
84
84
  structure: {
85
85
  io: gs,
@@ -89,6 +89,6 @@ module.exports = {
89
89
  Property: graph.Property,
90
90
  Vertex: graph.Vertex,
91
91
  VertexProperty: graph.VertexProperty,
92
- toLong: utils.toLong
93
- }
92
+ toLong: utils.toLong,
93
+ },
94
94
  };
@@ -24,14 +24,14 @@ class Authenticator {
24
24
  constructor(options) {
25
25
  this._options = options;
26
26
  }
27
-
27
+
28
28
  /**
29
29
  * @abstract
30
30
  * Evaluates the challenge from the server and returns appropriate response.
31
31
  * @param {String} challenge Challenge string presented by the server.
32
32
  */
33
33
  evaluateChallenge(challenge) {
34
- throw new Error("evaluateChallenge should be implemented");
34
+ throw new Error('evaluateChallenge should be implemented');
35
35
  }
36
36
  }
37
37
 
@@ -45,7 +45,7 @@ class SaslMechanismBase {
45
45
  * @param {String} challenge Challenge string presented by the server
46
46
  */
47
47
  evaluateChallenge(challenge) {
48
- throw new Error("evaluateChallenge should be implemented");
48
+ throw new Error('evaluateChallenge should be implemented');
49
49
  }
50
50
  }
51
51
 
@@ -32,12 +32,13 @@ class SaslMechanismPlain extends SaslMechanismBase {
32
32
  constructor(options) {
33
33
  super(options);
34
34
 
35
- if (this._options.username === undefined
36
- || this._options.username === null
37
- || this._options.username.length == 0
38
- || this._options.password === undefined
39
- || this._options.password === null
40
- || this._options.password.length == 0
35
+ if (
36
+ this._options.username === undefined ||
37
+ this._options.username === null ||
38
+ this._options.username.length === 0 ||
39
+ this._options.password === undefined ||
40
+ this._options.password === null ||
41
+ this._options.password.length === 0
41
42
  ) {
42
43
  throw new Error('Missing credentials for SASL PLAIN mechanism');
43
44
  }
@@ -49,7 +50,7 @@ class SaslMechanismPlain extends SaslMechanismBase {
49
50
  get name() {
50
51
  return 'PLAIN';
51
52
  }
52
-
53
+
53
54
  /**
54
55
  * Evaluates the challenge from the server and returns appropriate response.
55
56
  * @param {String} challenge Challenge string presented by the server.
@@ -58,12 +59,14 @@ class SaslMechanismPlain extends SaslMechanismBase {
58
59
  evaluateChallenge(challenge) {
59
60
  if (this._hasInitialResponse(challenge)) {
60
61
  return Promise.resolve({
61
- 'saslMechanism': this.name,
62
- 'sasl': this._saslArgument(this._options.authzid, this._options.username, this._options.password)
62
+ saslMechanism: this.name,
63
+ sasl: this._saslArgument(this._options.authzid, this._options.username, this._options.password),
63
64
  });
64
65
  }
65
-
66
- return Promise.resolve({ 'sasl': this._saslArgument(this._options.authzid, this._options.username, this._options.password) });
66
+
67
+ return Promise.resolve({
68
+ sasl: this._saslArgument(this._options.authzid, this._options.username, this._options.password),
69
+ });
67
70
  }
68
71
 
69
72
  /**
@@ -73,11 +76,17 @@ class SaslMechanismPlain extends SaslMechanismBase {
73
76
  * @param {String} password The password of user with access to server.
74
77
  */
75
78
  _saslArgument(authzid, username, password) {
76
- if (authzid === undefined || authzid === null) authzid = '';
77
- if (username === undefined || username === null) username = '';
78
- if (password === undefined || password.length === null) password = '';
79
+ if (authzid === undefined || authzid === null) {
80
+ authzid = '';
81
+ }
82
+ if (username === undefined || username === null) {
83
+ username = '';
84
+ }
85
+ if (password === undefined || password.length === null) {
86
+ password = '';
87
+ }
79
88
 
80
- return new Buffer(`${authzid}\0${username}\0${password}`).toString('base64');
89
+ return Buffer.from(`${authzid}\0${username}\0${password}`).toString('base64');
81
90
  }
82
91
 
83
92
  /**
@@ -33,15 +33,15 @@ class PlainTextSaslAuthenticator extends Authenticator {
33
33
  constructor(username, password, authzid) {
34
34
  const options = {
35
35
  mechanism: new SaslMechanismPlain({
36
- 'username': username,
37
- 'password': password,
38
- 'authzid': authzid
39
- })
36
+ username: username,
37
+ password: password,
38
+ authzid: authzid,
39
+ }),
40
40
  };
41
41
 
42
42
  super(options);
43
43
  }
44
-
44
+
45
45
  /**
46
46
  * Evaluates the challenge from the server and returns appropriate response.
47
47
  * @param {String} challenge Challenge string presented by the server.
@@ -35,7 +35,7 @@ class SaslAuthenticator extends Authenticator {
35
35
  throw new Error('No Sasl Mechanism Specified');
36
36
  }
37
37
  }
38
-
38
+
39
39
  /**
40
40
  * Evaluates the challenge from the server and returns appropriate response.
41
41
  * @param {String} challenge Challenge string presented by the server.