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,438 @@
1
+ /*###############################################################
2
+ # #
3
+ # Copyright (c) 2025-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 Server {
17
+ hostName = ''
18
+ mindVersion = ''
19
+ ydbVersion = ''
20
+ platform = ''
21
+ architecture = ''
22
+
23
+ pinfo = function (pid = 0) {
24
+ const that = this
25
+ const RESP3 = that.objRoot.RESP3
26
+
27
+ return new Promise(function (resolve, reject) {
28
+ if (that.connected === false || that.loggedIn === false) {
29
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
30
+ }
31
+
32
+
33
+
34
+ if (utils.validateTypeOfField(pid, 'number') === false) {
35
+ reject(new Error(errors.PARAM_NOT_NUMBER + 'Parameter pid must be a number'))
36
+
37
+ return
38
+ }
39
+
40
+ // send command
41
+ const opCode = 'server.pinfo'
42
+ that.writer("*2" + RESP3.CRLF +
43
+ RESP3.build.blob(opCode) +
44
+ RESP3.build.blob(pid.toString())
45
+ );
46
+
47
+ that.reader(data => {
48
+ if (data.charAt(0) === '-') {
49
+ reject(new Error(RESP3.parse.simpleError(data)))
50
+
51
+ return
52
+ }
53
+
54
+ data = data.slice(2 + data.indexOf(RESP3.CRLF), -2).split(RESP3.CRLF)
55
+ const res = {}
56
+
57
+ for (let ix = 0; ix < data.length; ix += 2) {
58
+ res[data[ix].slice(1)] = parseInt(data[ix + 1].slice(1))
59
+ }
60
+
61
+ resolve(res)
62
+ })
63
+ })
64
+ }
65
+
66
+ SIG_INT = 2
67
+ SIG_KIL = 9
68
+
69
+ kill = function (pid, sigNumber = 2) {
70
+ const that = this
71
+ const RESP3 = that.objRoot.RESP3
72
+
73
+ return new Promise(function (resolve, reject) {
74
+ if (that.connected === false || that.loggedIn === false) {
75
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
76
+
77
+ return
78
+ }
79
+
80
+ if (utils.validateTypeOfField(pid, 'number') === false) {
81
+ reject(new Error(errors.PARAM_NOT_NUMBER + 'Parameter pid must be a number'))
82
+
83
+ return
84
+ }
85
+
86
+ if (pid === 0) {
87
+ reject(new Error(errors.PATH_NOT_PROVIDED + 'the path has not been provided'))
88
+
89
+ return
90
+ }
91
+
92
+ if (utils.validateTypeOfField(sigNumber, 'number') === false) {
93
+ reject(new Error(errors.PARAM_NOT_NUMBER + 'Parameter sigNumber must be a number'))
94
+
95
+ return
96
+ }
97
+
98
+ // send command
99
+ const opCode = 'server.kill'
100
+ that.writer("*3" + RESP3.CRLF +
101
+ RESP3.build.blob(opCode) +
102
+ RESP3.build.blob(pid.toString()) +
103
+ RESP3.build.blob(sigNumber.toString())
104
+ );
105
+
106
+ that.reader(data => {
107
+ if (data.charAt(0) === '-') {
108
+ reject(new Error(RESP3.parse.simpleError(data)))
109
+
110
+ return
111
+ }
112
+
113
+ that.reader(data => {
114
+ if (data.charAt(0) === '-') {
115
+ reject(new Error(RESP3.parse.simpleError(data)))
116
+
117
+ return
118
+ }
119
+
120
+ resolve()
121
+ })
122
+ })
123
+ })
124
+ }
125
+
126
+ GUID = function (dashed = true, braced = false) {
127
+ const that = this
128
+ const RESP3 = that.objRoot.RESP3
129
+
130
+ return new Promise(function (resolve, reject) {
131
+ if (that.connected === false || that.loggedIn === false) {
132
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
133
+
134
+ return
135
+ }
136
+
137
+ if (typeof dashed !== 'boolean' || typeof braced !== 'boolean') {
138
+ reject(new Error(errors.PARAM_NOT_BOOLEAN + 'Parameter must be a boolean'))
139
+ }
140
+
141
+ // send command
142
+ const opCode = 'server.GUID'
143
+ that.writer("*2" + RESP3.CRLF +
144
+ RESP3.build.blob(opCode) +
145
+ RESP3.build.blob((dashed === true ? 'D' : '') + (braced === true ? 'B' : ''))
146
+ );
147
+
148
+ that.reader(data => {
149
+ if (data.charAt(0) === '-') {
150
+ reject(new Error(RESP3.parse.simpleError(data)))
151
+
152
+ return
153
+ }
154
+
155
+
156
+ resolve(RESP3.parse.simpleString(data))
157
+ })
158
+ })
159
+ }
160
+
161
+ stats = function () {
162
+ const that = this
163
+ const RESP3 = that.objRoot.RESP3
164
+
165
+ return new Promise(function (resolve, reject) {
166
+ if (that.connected === false || that.loggedIn === false) {
167
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
168
+
169
+ return
170
+ }
171
+
172
+ // send command
173
+ const opCode = 'server.stats'
174
+ that.writer("*1" + RESP3.CRLF +
175
+ RESP3.build.blob(opCode)
176
+ );
177
+
178
+ that.reader(data => {
179
+ if (data.charAt(0) === '-') {
180
+ reject(new Error(RESP3.parse.simpleError(data)))
181
+
182
+ return
183
+ }
184
+
185
+ if (data.indexOf('+no data') > -1) {
186
+ resolve({})
187
+
188
+ return
189
+ }
190
+
191
+ resolve(JSON.parse(RESP3.parse.blob(data)))
192
+ })
193
+ })
194
+ }
195
+
196
+ listSessions = function () {
197
+ const that = this
198
+ const RESP3 = that.objRoot.RESP3
199
+
200
+ return new Promise(function (resolve, reject) {
201
+ if (that.connected === false || that.loggedIn === false) {
202
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
203
+
204
+ return
205
+ }
206
+
207
+ // send command
208
+ const opCode = 'server.listSessions'
209
+ that.writer("*1" + RESP3.CRLF +
210
+ RESP3.build.blob(opCode)
211
+ );
212
+
213
+ that.reader(data => {
214
+ if (data.charAt(0) === '-') {
215
+ reject(new Error(RESP3.parse.simpleError(data)))
216
+
217
+ return
218
+ }
219
+
220
+ if (data.indexOf('+no data') > -1) {
221
+ reject(new Error('No stats enabled on server'))
222
+
223
+ return
224
+ }
225
+
226
+ resolve(JSON.parse(RESP3.parse.blob(data)))
227
+ })
228
+ })
229
+ }
230
+
231
+ plist = function () {
232
+ const that = this
233
+ const RESP3 = that.objRoot.RESP3
234
+
235
+ return new Promise(function (resolve, reject) {
236
+ if (that.connected === false || that.loggedIn === false) {
237
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
238
+
239
+ return
240
+ }
241
+
242
+ // send command
243
+ const opCode = 'server.plist'
244
+ that.writer("*1" + RESP3.CRLF +
245
+ RESP3.build.blob(opCode)
246
+ );
247
+
248
+ that.reader(data => {
249
+ if (data.charAt(0) === '-') {
250
+ reject(new Error(RESP3.parse.simpleError(data)))
251
+
252
+ return
253
+ }
254
+
255
+ resolve(JSON.parse(RESP3.parse.blob(data)))
256
+ })
257
+ })
258
+ }
259
+
260
+ unixtime = function () {
261
+ const that = this
262
+ const RESP3 = that.objRoot.RESP3
263
+
264
+ return new Promise(function (resolve, reject) {
265
+ if (that.connected === false || that.loggedIn === false) {
266
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
267
+
268
+ return
269
+ }
270
+
271
+ // send command
272
+ const opCode = 'server.unixtime'
273
+ that.writer("*1" + RESP3.CRLF +
274
+ RESP3.build.blob(opCode)
275
+ );
276
+
277
+ that.reader(data => {
278
+ if (data.charAt(0) === '-') {
279
+ reject(new Error(RESP3.parse.simpleError(data)))
280
+
281
+ return
282
+ }
283
+
284
+ resolve(parseInt(RESP3.parse.simpleString(data)))
285
+ })
286
+ })
287
+ }
288
+
289
+ now = function (resolution = 'ms') {
290
+ const that = this
291
+ const RESP3 = that.objRoot.RESP3
292
+
293
+ return new Promise(function (resolve, reject) {
294
+ if (that.connected === false || that.loggedIn === false) {
295
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
296
+
297
+ return
298
+ }
299
+
300
+ if (resolution !== 'ms' && resolution !== 'us') {
301
+ reject(new Error('Resolution can be either ms (milliseconds) or us (microseconds)'))
302
+
303
+ return
304
+ }
305
+
306
+ // send command
307
+ const opCode = 'server.now'
308
+ that.writer("*2" + RESP3.CRLF +
309
+ RESP3.build.blob(opCode) +
310
+ RESP3.build.blob(resolution)
311
+ );
312
+
313
+ that.reader(data => {
314
+ if (data.charAt(0) === '-') {
315
+ reject(new Error(RESP3.parse.simpleError(data)))
316
+
317
+ return
318
+ }
319
+
320
+ resolve(parseInt(RESP3.parse.simpleString(data)))
321
+ })
322
+ })
323
+ }
324
+
325
+ datetime = function () {
326
+ const that = this
327
+ const RESP3 = that.objRoot.RESP3
328
+
329
+ return new Promise(function (resolve, reject) {
330
+ if (that.connected === false || that.loggedIn === false) {
331
+ reject(new Error('Not logged in'))
332
+
333
+ return
334
+ }
335
+
336
+ // send command
337
+ const opCode = 'server.datetime'
338
+ that.writer("*1" + RESP3.CRLF +
339
+ RESP3.build.blob(opCode)
340
+ );
341
+
342
+ that.reader(data => {
343
+ if (data.charAt(0) === '-') {
344
+ reject(new Error(RESP3.parse.simpleError(data)))
345
+
346
+ return
347
+ }
348
+
349
+ data = data.slice(2 + data.indexOf(RESP3.CRLF), -2).split(RESP3.CRLF)
350
+ const res = {}
351
+
352
+ for (let ix = 0; ix < data.length; ix += 2) {
353
+ res[data[ix].slice(1)] = parseInt(data[ix + 1].slice(1))
354
+ }
355
+
356
+ resolve(res)
357
+ })
358
+ })
359
+ }
360
+
361
+ horolog = function () {
362
+ const that = this
363
+ const RESP3 = that.objRoot.RESP3
364
+
365
+ return new Promise(function (resolve, reject) {
366
+ if (that.connected === false || that.loggedIn === false) {
367
+ reject(new Error('Not logged in'))
368
+
369
+ return
370
+ }
371
+
372
+ // send command
373
+ const opCode = 'server.horolog'
374
+ that.writer("*1" + RESP3.CRLF +
375
+ RESP3.build.blob(opCode)
376
+ );
377
+
378
+ that.reader(data => {
379
+ if (data.charAt(0) === '-') {
380
+ reject(new Error(RESP3.parse.simpleError(data)))
381
+
382
+ return
383
+ }
384
+
385
+ data = data.slice(2 + data.indexOf(RESP3.CRLF), -2).split(RESP3.CRLF)
386
+ const res = {}
387
+
388
+ for (let ix = 0; ix < data.length; ix += 2) {
389
+ res[data[ix].slice(1)] = data[ix + 1].slice(1)
390
+ }
391
+
392
+ resolve(res)
393
+ })
394
+ })
395
+ }
396
+
397
+ _init = function (obj) {
398
+ Object.defineProperties(obj, {
399
+ SIG_INT: {
400
+ value: 2,
401
+ enumerable: true,
402
+ configurable: false,
403
+ writable: false
404
+ }
405
+
406
+ })
407
+
408
+ Object.defineProperties(obj, {
409
+ SIG_KIL: {
410
+ value: 9,
411
+ enumerable: true,
412
+ configurable: false,
413
+ writable: false
414
+ }
415
+
416
+ })
417
+
418
+ Object.defineProperties(obj, {
419
+ SIG_USR1: {
420
+ value: 10,
421
+ enumerable: true,
422
+ configurable: false,
423
+ writable: false
424
+ }
425
+
426
+ })
427
+
428
+ Object.defineProperties(obj, {
429
+ _init: {
430
+ enumerable: false,
431
+ }
432
+
433
+ })
434
+ }
435
+ }
436
+
437
+ module.exports = Server
438
+