mind-client-js 0.20.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.
@@ -0,0 +1,940 @@
1
+ /*###############################################################
2
+ # #
3
+ # Copyright (c) 2026 DnaSoft BV and/or its subsidiaries. #
4
+ # All rights reserved. #
5
+ # #
6
+ # This source code contains the intellectual property #
7
+ # of its copyright holder(s), and is made available #
8
+ # under a license. If you do not know the terms of #
9
+ # the license, please stop and do not read further. #
10
+ # #
11
+ ###############################################################*/
12
+
13
+ const utils = require("../utils");
14
+ const errors = require('../errors.js')
15
+
16
+ class Glvn {
17
+ _path = ''
18
+
19
+ _ = function (...path) {
20
+
21
+ try {
22
+ utils.validateGlvnPath(path)
23
+ } catch (err) {
24
+ throw err
25
+ }
26
+
27
+ this._path = utils.convertPathTo$Name(path)
28
+
29
+ return this
30
+ }
31
+
32
+ hasValue = function () {
33
+ const that = this
34
+ const RESP3 = that.objRoot.RESP3
35
+
36
+ return new Promise(function (resolve, reject) {
37
+ if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
38
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
39
+
40
+ return
41
+ }
42
+
43
+ // send command
44
+ const opCode = 'glvn.hasValue'
45
+
46
+ that.writer("*2" + RESP3.CRLF +
47
+ RESP3.build.blob(opCode) +
48
+ RESP3.build.blob(utils.generateGlvn(that))
49
+ );
50
+
51
+ that._path = ''
52
+
53
+ that.reader(data => {
54
+ if (data.charAt(0) === '-') {
55
+ reject(new Error(RESP3.parse.simpleError(data)))
56
+
57
+ return
58
+ }
59
+
60
+ if (data.charAt(0) !== '#') {
61
+ reject(new Error(RESP3.parse.simpleError(data)))
62
+
63
+ return
64
+ }
65
+
66
+ resolve(data.slice(0, -2) === RESP3.true)
67
+ })
68
+ })
69
+ }
70
+
71
+ hasNodes = function () {
72
+ const that = this
73
+ const RESP3 = that.objRoot.RESP3
74
+
75
+ return new Promise(function (resolve, reject) {
76
+ if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
77
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
78
+
79
+ return
80
+ }
81
+
82
+ // send command
83
+ const opCode = 'glvn.hasNodes'
84
+
85
+ that.writer("*2" + RESP3.CRLF +
86
+ RESP3.build.blob(opCode) +
87
+ RESP3.build.blob(utils.generateGlvn(that))
88
+ );
89
+
90
+ that._path = ''
91
+
92
+ that.reader(data => {
93
+ if (data.charAt(0) === '-') {
94
+ reject(new Error(RESP3.parse.simpleError(data)))
95
+
96
+ return
97
+ }
98
+
99
+ if (data.charAt(0) !== '#') {
100
+ reject(new Error(RESP3.parse.simpleError(data)))
101
+
102
+ return
103
+ }
104
+
105
+ resolve(data.slice(0, -2) === RESP3.true)
106
+ })
107
+ })
108
+ }
109
+
110
+ datatype = function () {
111
+ const that = this
112
+ const RESP3 = that.objRoot.RESP3
113
+
114
+ return new Promise(function (resolve, reject) {
115
+ if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
116
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
117
+
118
+ return
119
+ }
120
+
121
+ // send command
122
+ const opCode = 'glvn.datatype'
123
+
124
+ that.writer("*2" + RESP3.CRLF +
125
+ RESP3.build.blob(opCode) +
126
+ RESP3.build.blob(utils.generateGlvn(that))
127
+ );
128
+
129
+ that._path = ''
130
+
131
+ that.reader(data => {
132
+ if (data.charAt(0) === '-') {
133
+ reject(new Error(RESP3.parse.simpleError(data)))
134
+
135
+ return
136
+ }
137
+
138
+ resolve(RESP3.parse.simpleString(data))
139
+ })
140
+ })
141
+ }
142
+
143
+ getValue = function () {
144
+ const that = this
145
+ const RESP3 = that.objRoot.RESP3
146
+
147
+ return new Promise(function (resolve, reject) {
148
+ if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
149
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
150
+
151
+ return
152
+ }
153
+
154
+ // send command
155
+ const opCode = 'glvn.getValue'
156
+
157
+ that.writer("*2" + RESP3.CRLF +
158
+ RESP3.build.blob(opCode) +
159
+ RESP3.build.blob(utils.generateGlvn(that))
160
+ );
161
+
162
+ that._path = ''
163
+
164
+ that.reader(data => {
165
+ if (data.charAt(0) === '-') {
166
+ reject(new Error(RESP3.parse.simpleError(data)))
167
+ }
168
+
169
+ if (data.charAt(0) === '(') {
170
+ resolve(parseFloat(data.slice(1, -2)))
171
+
172
+ } else if (data.charAt(0) === '$') {
173
+ resolve(RESP3.parse.blob(data))
174
+
175
+ } else {
176
+ reject(new Error(RESP3.parse.simpleError(data)))
177
+ }
178
+ })
179
+ })
180
+ }
181
+
182
+ readValue = function () {
183
+ const that = this
184
+ const RESP3 = that.objRoot.RESP3
185
+
186
+ return new Promise(function (resolve, reject) {
187
+ if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
188
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
189
+
190
+ return
191
+ }
192
+
193
+ // send command
194
+ const opCode = 'glvn.readValue'
195
+
196
+ that.writer("*2" + RESP3.CRLF +
197
+ RESP3.build.blob(opCode) +
198
+ RESP3.build.blob(utils.generateGlvn(that))
199
+ );
200
+
201
+ that._path = ''
202
+
203
+ that.reader(data => {
204
+ if (data.charAt(0) === '-') {
205
+ reject(new Error(RESP3.parse.simpleError(data)))
206
+ }
207
+
208
+ if (data.charAt(0) === '(') {
209
+ resolve(parseFloat(data.slice(1, -2)))
210
+
211
+ } else if (data.charAt(0) === '$') {
212
+ resolve(RESP3.parse.blob(data.slice(1)))
213
+
214
+ } else {
215
+ reject(new Error(RESP3.parse.simpleError(data)))
216
+ }
217
+ })
218
+ })
219
+ }
220
+
221
+ killValue = function () {
222
+ const that = this
223
+ const RESP3 = that.objRoot.RESP3
224
+
225
+ return new Promise(function (resolve, reject) {
226
+ if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
227
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
228
+
229
+ return
230
+ }
231
+
232
+ // send command
233
+ const opCode = 'glvn.killValue'
234
+
235
+ that.writer("*2" + RESP3.CRLF +
236
+ RESP3.build.blob(opCode) +
237
+ RESP3.build.blob(utils.generateGlvn(that))
238
+ );
239
+
240
+ that._path = ''
241
+
242
+ that.reader(data => {
243
+ if (data.charAt(0) === '-' || data.indexOf('+ok') === -1) {
244
+ reject(new Error(RESP3.parse.simpleError(data)))
245
+
246
+ return
247
+ }
248
+
249
+ resolve()
250
+ })
251
+ })
252
+ }
253
+
254
+ killTree = function () {
255
+ const that = this
256
+ const RESP3 = that.objRoot.RESP3
257
+
258
+ return new Promise(function (resolve, reject) {
259
+ if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
260
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
261
+
262
+ return
263
+ }
264
+
265
+ // send command
266
+ const opCode = 'glvn.killTree'
267
+
268
+ that.writer("*2" + RESP3.CRLF +
269
+ RESP3.build.blob(opCode) +
270
+ RESP3.build.blob(utils.generateGlvn(that))
271
+ );
272
+
273
+ that._path = ''
274
+
275
+ that.reader(data => {
276
+ if (data.charAt(0) === '-' || data.indexOf('+ok') === -1) {
277
+ reject(new Error(RESP3.parse.simpleError(data)))
278
+
279
+ return
280
+ }
281
+
282
+ resolve()
283
+ })
284
+ })
285
+ }
286
+
287
+ getPiece = function (pieceChar = '^', start = 1, end) {
288
+ const that = this
289
+ const RESP3 = that.objRoot.RESP3
290
+
291
+ return new Promise(function (resolve, reject) {
292
+ if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
293
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
294
+
295
+ return
296
+ }
297
+
298
+ if (typeof pieceChar !== 'string') {
299
+ reject(new Error(errors.PARAM_NOT_STRING + 'pieceChar must be a string'))
300
+
301
+ return
302
+ }
303
+
304
+ if (typeof start !== 'number') {
305
+ reject(new Error(errors.PARAM_NOT_NUMBER + 'start must be a number'))
306
+
307
+ return
308
+ }
309
+
310
+ if (start < 1) {
311
+ reject(new Error('start must be greater than 0'))
312
+
313
+ return
314
+ }
315
+
316
+ if (typeof end === 'undefined') {
317
+ end = start
318
+
319
+ } else if (typeof end !== 'number') {
320
+ reject(new Error(errors.PARAM_NOT_NUMBER + 'end must be a number'))
321
+
322
+ return
323
+
324
+ } else if (end < 1) {
325
+ reject(new Error('start must be greater than 0'))
326
+
327
+ return
328
+ }
329
+
330
+ // send command
331
+ const opCode = 'glvn.getPiece'
332
+
333
+ that.writer("*5" + RESP3.CRLF +
334
+ RESP3.build.blob(opCode) +
335
+ RESP3.build.blob(utils.generateGlvn(that)) +
336
+ RESP3.build.blob(pieceChar) +
337
+ RESP3.build.blob(start) +
338
+ RESP3.build.blob(end)
339
+ );
340
+
341
+ that._path = ''
342
+
343
+ that.reader(data => {
344
+ if (data.charAt(0) === '-') {
345
+ reject(new Error(RESP3.parse.simpleError(data)))
346
+ }
347
+
348
+ if (data.charAt(0) === '(') {
349
+ resolve(parseFloat(data.slice(1, -2)))
350
+
351
+ } else if (data.charAt(0) === '$') {
352
+ resolve(RESP3.parse.blob(data.slice(1)))
353
+
354
+ } else {
355
+ reject(new Error(data.slice(1, -2)))
356
+ }
357
+ })
358
+ })
359
+ }
360
+
361
+ setValue = function (data = '') {
362
+ const that = this
363
+ const RESP3 = that.objRoot.RESP3
364
+
365
+ return new Promise(function (resolve, reject) {
366
+ if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
367
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
368
+
369
+ return
370
+ }
371
+
372
+ if (typeof data !== 'string' && typeof data !== 'number') {
373
+ reject(new Error(errors.PARAM_NOT_STRING_OR_NUMBER + 'data must be either a string or a number'))
374
+
375
+ return
376
+ }
377
+
378
+ // send command
379
+ const opCode = 'glvn.setValue'
380
+ let newData = ''
381
+
382
+ if (typeof data === 'string') {
383
+ newData = RESP3.build.blob(data.toString())
384
+ } else newData = '(' + data.toString() + RESP3.CRLF
385
+
386
+ that.writer("*3" + RESP3.CRLF +
387
+ RESP3.build.blob(opCode) +
388
+ RESP3.build.blob(utils.generateGlvn(that)) +
389
+ RESP3.build.blob(newData)
390
+ );
391
+
392
+ that._path = ''
393
+
394
+ that.reader(data => {
395
+ if (data.charAt(0) === '-' || data.indexOf('+ok') === -1) {
396
+ reject(new Error(RESP3.parse.simpleError(data)))
397
+
398
+ return
399
+ }
400
+
401
+ resolve()
402
+ })
403
+ })
404
+ }
405
+
406
+ setPiece = function (data, pieceChar = '^', start = 1, end) {
407
+ const that = this
408
+ const RESP3 = that.objRoot.RESP3
409
+
410
+ return new Promise(function (resolve, reject) {
411
+ if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
412
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
413
+
414
+ return
415
+ }
416
+
417
+ if (typeof data !== 'string' && typeof data !== 'number') {
418
+ reject(new Error('data must be either a string or a number'))
419
+
420
+ return
421
+
422
+ }
423
+
424
+ if (typeof pieceChar !== 'string') {
425
+ reject(new Error('pieceChar must be a string'))
426
+
427
+ return
428
+ }
429
+
430
+ if (typeof start !== 'number') {
431
+ reject(new Error('start must be a number'))
432
+
433
+ return
434
+ }
435
+
436
+ if (start < 1) {
437
+ reject(new Error('start must be greater than 0'))
438
+
439
+ return
440
+ }
441
+
442
+ if (typeof end === 'undefined') {
443
+ end = start
444
+
445
+ } else if (typeof end !== 'number') {
446
+ reject(new Error('end must be a number'))
447
+
448
+ return
449
+
450
+ } else if (end < 1) {
451
+ reject(new Error('start must be greater than 0'))
452
+
453
+ return
454
+ }
455
+
456
+ // send command
457
+ const opCode = 'glvn.setPiece'
458
+
459
+ that.writer("*6" + RESP3.CRLF +
460
+ RESP3.build.blob(opCode) +
461
+ RESP3.build.blob(utils.generateGlvn(that)) +
462
+ RESP3.build.blob(data.toString()) +
463
+ RESP3.build.blob(pieceChar) +
464
+ RESP3.build.blob(start) +
465
+ RESP3.build.blob(end)
466
+ );
467
+
468
+ that._path = ''
469
+
470
+ that.reader(data => {
471
+ if (data.charAt(0) === '-' || data.indexOf('+ok') === -1) {
472
+ reject(new Error(RESP3.parse.simpleError(data)))
473
+
474
+ return
475
+ }
476
+
477
+ resolve()
478
+ })
479
+ })
480
+ }
481
+
482
+ setJSON = function (json = '') {
483
+ const that = this
484
+ const RESP3 = that.objRoot.RESP3
485
+
486
+ return new Promise(function (resolve, reject) {
487
+ if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
488
+ reject(new Error('Not logged in'))
489
+
490
+ return
491
+ }
492
+
493
+ if (typeof json !== 'string') {
494
+ reject(new Error('JSON must be a string'))
495
+
496
+ return
497
+ }
498
+
499
+ // send command
500
+ const opCode = 'glvn.setJSON'
501
+ let newData = ''
502
+
503
+ that.writer("*3" + RESP3.CRLF +
504
+ RESP3.build.blob(opCode) +
505
+ RESP3.build.blob(utils.generateGlvn(that)) +
506
+ RESP3.build.blob(json)
507
+ );
508
+
509
+ that._path = ''
510
+
511
+ that.reader(data => {
512
+ if (data.charAt(0) === '-' || data.indexOf('+ok') === -1) {
513
+ reject(new Error(RESP3.parse.simpleError(data)))
514
+
515
+ return
516
+ }
517
+
518
+ resolve()
519
+ })
520
+ })
521
+ }
522
+
523
+ setObject = function (obj = {}) {
524
+ const that = this
525
+ const RESP3 = that.objRoot.RESP3
526
+ let json
527
+
528
+ return new Promise(function (resolve, reject) {
529
+ if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
530
+ reject(new Error('Not logged in'))
531
+
532
+ return
533
+ }
534
+
535
+ if (typeof obj !== 'object' || obj === null) {
536
+ reject(new Error('obj must be an object'))
537
+
538
+ return
539
+ }
540
+
541
+ try {
542
+ json = JSON.stringify(obj)
543
+
544
+ } catch (err) {
545
+ reject(new Error('error parsing object: ' + err.message))
546
+
547
+ return
548
+ }
549
+
550
+ // send command
551
+ const opCode = 'glvn.setJSON'
552
+ let newData = ''
553
+
554
+ that.writer("*3" + RESP3.CRLF +
555
+ RESP3.build.blob(opCode) +
556
+ RESP3.build.blob(utils.generateGlvn(that)) +
557
+ RESP3.build.blob(json)
558
+ );
559
+
560
+ that._path = ''
561
+
562
+ that.reader(data => {
563
+ if (data.charAt(0) === '-' || data.indexOf('+ok') === -1) {
564
+ reject(new Error(RESP3.parse.simpleError(data)))
565
+
566
+ return
567
+ }
568
+
569
+ resolve()
570
+ })
571
+ })
572
+ }
573
+
574
+ getJSON = function () {
575
+ const that = this
576
+ const RESP3 = that.objRoot.RESP3
577
+
578
+ return new Promise(function (resolve, reject) {
579
+ if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
580
+ reject(new Error('Not logged in'))
581
+
582
+ return
583
+ }
584
+
585
+ // send command
586
+ const opCode = 'glvn.getJSON'
587
+ let newData = ''
588
+
589
+ that.writer("*2" + RESP3.CRLF +
590
+ RESP3.build.blob(opCode) +
591
+ RESP3.build.blob(utils.generateGlvn(that))
592
+ );
593
+
594
+ that._path = ''
595
+
596
+ that.reader(data => {
597
+ if (data.charAt(0) === '-') {
598
+ reject(new Error(RESP3.parse.simpleError(data)))
599
+
600
+ return
601
+ }
602
+
603
+ resolve(RESP3.parse.blob(data))
604
+ })
605
+ })
606
+ }
607
+
608
+ getObject = function () {
609
+ const that = this
610
+ const RESP3 = that.objRoot.RESP3
611
+
612
+ return new Promise(function (resolve, reject) {
613
+ if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
614
+ reject(new Error('Not logged in'))
615
+
616
+ return
617
+ }
618
+
619
+ // send command
620
+ const opCode = 'glvn.getJSON'
621
+ let newData = ''
622
+
623
+ that.writer("*2" + RESP3.CRLF +
624
+ RESP3.build.blob(opCode) +
625
+ RESP3.build.blob(utils.generateGlvn(that))
626
+ );
627
+
628
+ that._path = ''
629
+
630
+ that.reader(data => {
631
+ if (data.charAt(0) === '-') {
632
+ reject(new Error(RESP3.parse.simpleError(data)))
633
+
634
+ return
635
+ }
636
+
637
+ resolve(JSON.parse(RESP3.parse.blob(data)))
638
+ })
639
+ })
640
+ }
641
+
642
+ increment = function (incrementBy = 1) {
643
+ const that = this
644
+ const RESP3 = that.objRoot.RESP3
645
+
646
+ return new Promise(function (resolve, reject) {
647
+ if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
648
+ reject(new Error('Not logged in'))
649
+
650
+ return
651
+ }
652
+
653
+ if (typeof incrementBy !== 'number') {
654
+ reject(new Error('incrementBy must be a number'))
655
+
656
+ return
657
+ }
658
+
659
+ if (incrementBy === 0 || incrementBy < 0) {
660
+ reject(new Error('incrementBy must be a positive number'))
661
+
662
+ return
663
+ }
664
+
665
+ // send command
666
+ const opCode = 'glvn.increment'
667
+
668
+ that.writer("*3" + RESP3.CRLF +
669
+ RESP3.build.blob(opCode) +
670
+ RESP3.build.blob(utils.generateGlvn(that)) +
671
+ RESP3.build.blob(incrementBy)
672
+ );
673
+
674
+ that._path = ''
675
+
676
+ that.reader(data => {
677
+ if (data.charAt(0) === '-') {
678
+ reject(new Error(RESP3.parse.simpleError(data)))
679
+
680
+ return
681
+ }
682
+
683
+ if (data.charAt(0) !== ',' && data.charAt(0) !== ':') {
684
+ reject(new Error(RESP3.parse.simpleError(data)))
685
+
686
+ return
687
+ }
688
+
689
+ resolve(parseFloat(data.slice(1, -2)))
690
+ })
691
+ })
692
+ }
693
+
694
+ decrement = function (decrementBy = 1) {
695
+ const that = this
696
+ const RESP3 = that.objRoot.RESP3
697
+
698
+ return new Promise(function (resolve, reject) {
699
+ if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
700
+ reject(new Error('Not logged in'))
701
+
702
+ return
703
+ }
704
+
705
+ if (typeof decrementBy !== 'number') {
706
+ reject(new Error('decrementBy must be a number'))
707
+
708
+ return
709
+ }
710
+
711
+ if (decrementBy === 0 || decrementBy < 0) {
712
+ reject(new Error('decrementBy must be a positive number'))
713
+
714
+ return
715
+ }
716
+
717
+ // send command
718
+ const opCode = 'glvn.decrement'
719
+
720
+ that.writer("*3" + RESP3.CRLF +
721
+ RESP3.build.blob(opCode) +
722
+ RESP3.build.blob(utils.generateGlvn(that)) +
723
+ RESP3.build.blob(decrementBy)
724
+ );
725
+
726
+ that._path = ''
727
+
728
+ that.reader(data => {
729
+ if (data.charAt(0) === '-') {
730
+ reject(new Error(RESP3.parse.simpleError(data)))
731
+
732
+ return
733
+ }
734
+
735
+ if (data.charAt(0) !== ',' && data.charAt(0) !== ':') {
736
+ reject(new Error(RESP3.parse.simpleError(data)))
737
+
738
+ return
739
+ }
740
+
741
+ resolve(parseFloat(data.slice(1, -2)))
742
+ })
743
+ })
744
+ }
745
+
746
+ findNext = function (findValue = '') {
747
+ const that = this
748
+ const RESP3 = that.objRoot.RESP3
749
+
750
+ return new Promise(function (resolve, reject) {
751
+ if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
752
+ reject(new Error('Not logged in'))
753
+
754
+ return
755
+ }
756
+
757
+ if (typeof findValue !== 'number' && typeof findValue !== 'string') {
758
+ reject(new Error('findValue must be a number or a string'))
759
+
760
+ return
761
+ }
762
+
763
+ // send command
764
+ const opCode = 'glvn.findNext'
765
+
766
+ that.writer("*3" + RESP3.CRLF +
767
+ RESP3.build.blob(opCode) +
768
+ RESP3.build.blob(utils.generateGlvn(that)) +
769
+ RESP3.build.blob(findValue)
770
+ );
771
+
772
+ that._path = ''
773
+
774
+ that.reader(data => {
775
+ if (data.charAt(0) === '-') {
776
+ reject(new Error(RESP3.parse.simpleError(data)))
777
+ }
778
+
779
+ if (data.charAt(0) === '(') {
780
+ resolve(parseFloat(data.slice(1, -2)))
781
+
782
+ } else if (data.charAt(0) === '$') {
783
+ resolve(RESP3.parse.blob(data))
784
+
785
+ } else {
786
+ reject(new Error(data.slice(1, -2)))
787
+ }
788
+ })
789
+ })
790
+ }
791
+
792
+ findPrev = function (findValue = '') {
793
+ const that = this
794
+ const RESP3 = that.objRoot.RESP3
795
+
796
+ return new Promise(function (resolve, reject) {
797
+ if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
798
+ reject(new Error('Not logged in'))
799
+
800
+ return
801
+ }
802
+
803
+ if (typeof findValue !== 'number' && typeof findValue !== 'string') {
804
+ reject(new Error('findValue must be a number or a string'))
805
+
806
+ return
807
+ }
808
+
809
+ // send command
810
+ const opCode = 'glvn.findPrev'
811
+
812
+ that.writer("*3" + RESP3.CRLF +
813
+ RESP3.build.blob(opCode) +
814
+ RESP3.build.blob(utils.generateGlvn(that)) +
815
+ RESP3.build.blob(findValue)
816
+ );
817
+
818
+ that._path = ''
819
+
820
+ that.reader(data => {
821
+ if (data.charAt(0) === '-') {
822
+ reject(new Error(RESP3.parse.simpleError(data)))
823
+ }
824
+
825
+ if (data.charAt(0) === '(') {
826
+ resolve(parseFloat(data.slice(1, -2)))
827
+
828
+ } else if (data.charAt(0) === '$') {
829
+ resolve(RESP3.parse.blob(data))
830
+
831
+ } else {
832
+ reject(new Error(data.slice(1, -2)))
833
+ }
834
+ })
835
+ })
836
+ }
837
+
838
+ query = function (glvn = undefined) {
839
+ const that = this
840
+ const RESP3 = that.objRoot.RESP3
841
+
842
+ return new Promise(function (resolve, reject) {
843
+ if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
844
+ reject(new Error('Not logged in'))
845
+
846
+ return
847
+ }
848
+
849
+ if (glvn && typeof glvn !== 'string') {
850
+ reject(new Error('glvn must be a string'))
851
+
852
+ return
853
+ }
854
+
855
+ // send command
856
+ const opCode = 'glvn.query'
857
+
858
+ that.writer("*3" + RESP3.CRLF +
859
+ RESP3.build.blob(opCode) +
860
+ RESP3.build.blob(utils.generateGlvn(that)) +
861
+ RESP3.build.blob(glvn || '')
862
+ );
863
+
864
+ that._path = ''
865
+
866
+ that.reader(data => {
867
+ if (data.charAt(0) === '-') {
868
+ reject(new Error(RESP3.parse.simpleError(data)))
869
+ }
870
+
871
+ if (data.charAt(0) === '$') {
872
+ resolve(RESP3.parse.blob(data))
873
+
874
+ } else {
875
+ reject(new Error(data.slice(1, -2)))
876
+ }
877
+ })
878
+ })
879
+ }
880
+
881
+ merge = function (glvn = undefined) {
882
+ const that = this
883
+ const RESP3 = that.objRoot.RESP3
884
+
885
+ return new Promise(function (resolve, reject) {
886
+ if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
887
+ reject(new Error('Not logged in'))
888
+
889
+ return
890
+ }
891
+
892
+ if (glvn && typeof glvn !== 'string') {
893
+ reject(new Error('glvn must be a string'))
894
+
895
+ return
896
+ }
897
+
898
+ // send command
899
+ const opCode = 'glvn.merge'
900
+
901
+ that.writer("*3" + RESP3.CRLF +
902
+ RESP3.build.blob(opCode) +
903
+ RESP3.build.blob(utils.generateGlvn(that)) +
904
+ RESP3.build.blob(glvn || '')
905
+ );
906
+
907
+ that._path = ''
908
+
909
+ that.reader(data => {
910
+ if (data.charAt(0) === '-') {
911
+ reject(new Error(RESP3.parse.simpleError(data)))
912
+ }
913
+
914
+ resolve()
915
+ })
916
+ })
917
+ }
918
+
919
+ toString = function () {
920
+ return utils.generateGlvn(this)
921
+ }
922
+
923
+ _init = function (obj) {
924
+ Object.defineProperties(obj, {
925
+ _path: {
926
+ enumerable: false,
927
+ configurable: false,
928
+ writable: true
929
+ },
930
+ })
931
+
932
+ Object.defineProperties(obj, {
933
+ _init: {
934
+ enumerable: false,
935
+ }
936
+ })
937
+ }
938
+ }
939
+
940
+ module.exports = Glvn