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