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.
- package/.gitattributes +3 -0
- package/LICENSE +674 -0
- package/README.md +1 -0
- package/js/dynamic-pool.js +145 -0
- package/js/errors.js +84 -0
- package/js/extends/global.js +134 -0
- package/js/extends/glvn.js +940 -0
- package/js/extends/glvnManagement.js +76 -0
- package/js/index.js +811 -0
- package/js/login.js +215 -0
- package/js/namespaces/RESP3.js +211 -0
- package/js/namespaces/_staticPool.js +156 -0
- package/js/namespaces/db.js +23 -0
- package/js/namespaces/dbms.js +18 -0
- package/js/namespaces/fs.js +708 -0
- package/js/namespaces/globals.js +35 -0
- package/js/namespaces/process.js +451 -0
- package/js/namespaces/server.js +438 -0
- package/js/namespaces/session.js +622 -0
- package/js/namespaces/uApi.js +157 -0
- package/js/namespaces/vars.js +51 -0
- package/js/static-pool.js +789 -0
- package/js/uapi.js +270 -0
- package/js/utils.js +174 -0
- package/package.json +34 -0
- package/sketch.txt +22 -0
|
@@ -0,0 +1,145 @@
|
|
|
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 errors = require('./errors')
|
|
14
|
+
|
|
15
|
+
module.exports = {
|
|
16
|
+
createNewSession: async function (that, classModule, timeout) {
|
|
17
|
+
return new Promise(async (resolve, reject) => {
|
|
18
|
+
const session = new classModule.exports.session
|
|
19
|
+
|
|
20
|
+
if (that.maxSize > 0 && Object.keys(that.sessions).length === that.maxSize) {
|
|
21
|
+
reject(new Error(errors.POOL_NO_MORE_SLOTS + 'you reached the maximum number of slots available for this pool'))
|
|
22
|
+
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
await session.connect(that.host, that.port, that.username, that.password, that.options)
|
|
28
|
+
|
|
29
|
+
Object.assign(that.sessions, {
|
|
30
|
+
[session.session.GUID]: {
|
|
31
|
+
session: session,
|
|
32
|
+
inUse: true
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
Object.assign(session, {
|
|
37
|
+
done: function () {
|
|
38
|
+
that.sessions[session.session.GUID].inUse = false
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
// mount handler to remove entry from sessions{} when remote disconnect occurs
|
|
43
|
+
session.on('disconnect', function () {
|
|
44
|
+
delete that.sessions[this.session.GUID]
|
|
45
|
+
|
|
46
|
+
that.stats.remoteDisconnects++
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
resolve([session, session.session.GUID])
|
|
50
|
+
|
|
51
|
+
} catch
|
|
52
|
+
(err) {
|
|
53
|
+
reject(err)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
)
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
getSessionByGUID: async function (that, classModule, GUID, timeout) {
|
|
60
|
+
return new Promise(async (resolve, reject) => {
|
|
61
|
+
try {
|
|
62
|
+
if (that.sessions[GUID] === undefined) {
|
|
63
|
+
reject(new Error(errors.POOL_GUID_NOT_FOUND + 'guid does not exist'))
|
|
64
|
+
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// TODO: this should be change in a queue with 0 ms timer
|
|
69
|
+
if (that.sessions[GUID].inUse === true) {
|
|
70
|
+
that.stats.inUseError++
|
|
71
|
+
|
|
72
|
+
reject(new Error(errors.POOL_SESSION_IN_USE + 'session in use'))
|
|
73
|
+
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
that.sessions[GUID].inUse = true
|
|
78
|
+
|
|
79
|
+
resolve(that.sessions[GUID].session)
|
|
80
|
+
|
|
81
|
+
} catch (err) {
|
|
82
|
+
reject(err)
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
terminateSession: async function (that, GUID) {
|
|
88
|
+
return new Promise(async (resolve, reject) => {
|
|
89
|
+
try {
|
|
90
|
+
if (that.sessions[GUID] === undefined) {
|
|
91
|
+
reject(new Error(errors.POOL_GUID_NOT_FOUND + 'guid does not exist'))
|
|
92
|
+
|
|
93
|
+
return
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
that.sessions[GUID].session.disconnect()
|
|
97
|
+
delete that.sessions[GUID]
|
|
98
|
+
|
|
99
|
+
resolve()
|
|
100
|
+
|
|
101
|
+
} catch (err) {
|
|
102
|
+
reject(err)
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
terminatePool: async function (that) {
|
|
108
|
+
return new Promise(async (resolve, reject) => {
|
|
109
|
+
try {
|
|
110
|
+
for (const [guid, session] of Object.entries(that.sessions)) {
|
|
111
|
+
await session.session.disconnect()
|
|
112
|
+
delete that.sessions[guid]
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
resolve()
|
|
116
|
+
|
|
117
|
+
} catch (err) {
|
|
118
|
+
reject(err)
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
getStatus: async function (that, GUID) {
|
|
124
|
+
return new Promise(async (resolve, reject) => {
|
|
125
|
+
|
|
126
|
+
})
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
verifyConnection: async function (that, classModule) {
|
|
130
|
+
return new Promise(async (resolve, reject) => {
|
|
131
|
+
const session = new classModule.exports.session
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
await session.connect(that.host, that.port, that.username, that.password, that.options)
|
|
135
|
+
|
|
136
|
+
resolve()
|
|
137
|
+
|
|
138
|
+
} catch (err) {
|
|
139
|
+
reject(err)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
session.disconnect()
|
|
143
|
+
})
|
|
144
|
+
},
|
|
145
|
+
}
|
package/js/errors.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
module.exports = {
|
|
14
|
+
NOT_LOGGED_IN: 'NOT_LOGGED_IN,',
|
|
15
|
+
|
|
16
|
+
LOG_STR_NOT_A_STRING: 'LOG_STR_NOT_A_STRING,',
|
|
17
|
+
|
|
18
|
+
NAME_ALREADY_REGISTERED: 'NAME_ALREADY_REGISTERED,',
|
|
19
|
+
NAME_NOT_FOUND: 'NAME_NOT_FOUND,',
|
|
20
|
+
NAME_EMPTY_OR_NOT_STRING: 'NAME_EMPTY_OR_NOT_STRING,',
|
|
21
|
+
ERROR_ADDING_NAME: 'ERROR_ADDING_NAME,',
|
|
22
|
+
|
|
23
|
+
POOL_SIZE_NOT_MIN_TWO: 'POOL_SIZE_NOT_MIN_TWO.',
|
|
24
|
+
|
|
25
|
+
HOST_MUST_BE_STRING: 'HOST_MUST_BE_STRING,',
|
|
26
|
+
PORT_MUST_BE_NUMBER: 'PORT_MUST_BE_NUMBER,',
|
|
27
|
+
USERNAME_MUST_BE_STRING: 'USERNAME_MUST_BE_STRING,',
|
|
28
|
+
PASSWORD_MUST_BE_STRING: 'PASSWORD_MUST_BE_STRING,',
|
|
29
|
+
TIMEOUT_MUST_BE_NUMBER: 'TIMEOUT_MUST_BE_NUMBER,',
|
|
30
|
+
TIMEOUT_NOT_POSITIVE_NUMBER: 'TIMEOUT_NOT_POSITIVE_NUMBER,',
|
|
31
|
+
|
|
32
|
+
METHOD_BAD_ARGS_NUMBER: 'METHOD_BAD_ARGS_NUMBER,',
|
|
33
|
+
METHOD_PARAM_NOT_NUMBER: 'METHOD_PARAM_NOT_NUMBER,',
|
|
34
|
+
METHOD_PARAM_NOT_STRING: 'METHOD_PARAM_NOT_STRING,',
|
|
35
|
+
METHOD_PARAM_NOT_VAR_NAME: 'METHOD_PARAM_NOT_VAR_NAME,',
|
|
36
|
+
|
|
37
|
+
PARAM_NOT_STRING: 'PARAM_NOT_STRING,',
|
|
38
|
+
PARAM_NOT_NUMBER: 'PARAM_NOT_NUMBER,',
|
|
39
|
+
PARAM_NOT_INT: 'PARAM_NOT_INT,',
|
|
40
|
+
PARAM_NOT_BOOLEAN: 'PARAM_NOT_BOOLEAN,',
|
|
41
|
+
PARAM_NOT_OBJECT: 'PARAM_NOT_OBJECT,',
|
|
42
|
+
PARAM_IS_ARRAY: 'PARAM_IS_ARRAY,',
|
|
43
|
+
PARAM_NOT_ARRAY: 'PARAM_NOT_ARRAY,',
|
|
44
|
+
PARAM_NOT_GREATER_THAN_ZERO: 'PARAM_NOT_GREATER_THAN_ZERO,',
|
|
45
|
+
PARAM_NOT_ZERO_OR_GREATER: 'PARAM_NOT_ZERO_OR_GREATER,',
|
|
46
|
+
PARAM_NOT_ZERO_OR_ONE: 'PARAM_NOT_ZERO_OR_ONE,',
|
|
47
|
+
PARAM_NOT_BETWEEN_ZERO_AND_ONE: 'PARAM_NOT_BETWEEN_ZERO_AND_ONE,',
|
|
48
|
+
PARAM_NOT_BETWEEN_ZERO_AND_THREE: 'PARAM_NOT_BETWEEN_ZERO_AND_THREE,',
|
|
49
|
+
PARAM_NOT_STRING_OR_NUMBER: 'PARAM_NOT_STRING_OR_NUMBER,',
|
|
50
|
+
PARAM_NOT_STRING_OR_EMPTY: 'PARAM_NOT_STRING_OR_EMPTY,',
|
|
51
|
+
PARAM_BAD_VALUE: 'PARAM_BAD_VALUE,',
|
|
52
|
+
INVALID_PARAM: 'INVALID_PARAM,',
|
|
53
|
+
PARAM_MISSING: 'PARAM_MISSING,',
|
|
54
|
+
PARAM_BAD_DATA_TYPE: 'PARAM_BAD_DATA_TYPE,',
|
|
55
|
+
PARAM_NOT_ALLOWED: 'PARAM_NOT_ALLOWED,',
|
|
56
|
+
PARAM_NOT_EXISTING: 'PARAM_NOT_EXISTING,',
|
|
57
|
+
PARAM_IS_EMPTY: 'PARAM_IS_EMPTY,',
|
|
58
|
+
|
|
59
|
+
BAD_SYNTAX: 'BAD_SYNTAX,',
|
|
60
|
+
STRING_IS_EMPTY: 'STRING_IS_EMPTY,',
|
|
61
|
+
|
|
62
|
+
VERBATIM_TYPE_NOT_3_CHARS: 'VERBATIM_TYPE_NOT_3_CHARS,',
|
|
63
|
+
|
|
64
|
+
FILENAME_NOT_PROVIDED: 'FILENAME_NOT_PROVIDED,',
|
|
65
|
+
FILENAME_NOT_STRING: 'FILENAME_NOT_STRING,',
|
|
66
|
+
PATH_NOT_PROVIDED: 'PATH_NOT_PROVIDED,',
|
|
67
|
+
PATH_NOT_STRING: 'PATH_NOT_STRING,',
|
|
68
|
+
|
|
69
|
+
BAD_SERVER_VERSION: 'BAD_SERVER_VERSION,',
|
|
70
|
+
ERROR_OCCURRED: 'ERROR_OCCURRED,',
|
|
71
|
+
NO_COMMAND_PROVIDED: 'NO_COMMAND_PROVIDED,`',
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
TIMEOUT_OCCURRED: 'TIMEOUT_OCCURRED,',
|
|
75
|
+
SOCKET_DISCONNECTED: 'SOCKET_DISCONNECTED,',
|
|
76
|
+
|
|
77
|
+
POOL_NO_MORE_SLOTS: 'POOL_NO_MORE_SLOTS,',
|
|
78
|
+
POOL_GUID_NOT_FOUND: 'POOL_GUID_NOT_FOUND,',
|
|
79
|
+
POOL_SESSION_IN_USE: 'POOL_SESSION_IN_USE,',
|
|
80
|
+
POOL_DEVOPS_SESSION_IN_USE: 'POOL_DEVOPS_SESSION_IN_USE,',
|
|
81
|
+
POOL_NOT_INITIALIZED: 'POOL_NOT_INITIALIZED,',
|
|
82
|
+
POOL_NEWSIZE_SAME_AS_SIZE: 'POOL_NEWSIZE_SAME_AS_SIZE,',
|
|
83
|
+
POOL_TOO_MANY_SESSIONS_IN_USE: 'POOL_TOO_MANY_SESSIONS_IN_USE,'
|
|
84
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
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 Glvn = require("./glvn")
|
|
14
|
+
const utils = require("../utils");
|
|
15
|
+
const errors = require('../errors.js')
|
|
16
|
+
|
|
17
|
+
class Global extends Glvn {
|
|
18
|
+
spaceOnDisk = function () {
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
addLock = function (timeout = 0) {
|
|
23
|
+
const that = this
|
|
24
|
+
const RESP3 = that.objRoot.RESP3
|
|
25
|
+
|
|
26
|
+
return new Promise(function (resolve, reject) {
|
|
27
|
+
if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
|
|
28
|
+
reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
|
|
29
|
+
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (typeof timeout !== 'number') {
|
|
34
|
+
reject(new Error(errors.TIMEOUT_MUST_BE_NUMBER + 'timeout must be a number'))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (timeout < 0) {
|
|
38
|
+
reject(new Error(errors.TIMEOUT_NOT_POSITIVE_NUMBER + 'timeout must be a positive number'))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (that.objRoot.process._groupLocksFlag === true) {
|
|
42
|
+
that.objRoot.process._locks.push(utils.generateGlvn(that))
|
|
43
|
+
|
|
44
|
+
resolve()
|
|
45
|
+
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// send command
|
|
50
|
+
const opCode = 'glvn.addLock'
|
|
51
|
+
|
|
52
|
+
that.writer("*3" + RESP3.CRLF +
|
|
53
|
+
RESP3.build.blob(opCode) +
|
|
54
|
+
RESP3.build.blob(utils.generateGlvn(that)) +
|
|
55
|
+
RESP3.build.blob(timeout)
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
that._path = ''
|
|
59
|
+
|
|
60
|
+
that.reader(data => {
|
|
61
|
+
if (data.charAt(0) === '-') {
|
|
62
|
+
reject(new Error(RESP3.parse.simpleError(data)))
|
|
63
|
+
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
resolve()
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
removeLock = function () {
|
|
73
|
+
const that = this
|
|
74
|
+
const RESP3 = that.objRoot.RESP3
|
|
75
|
+
|
|
76
|
+
return new Promise(function (resolve, reject) {
|
|
77
|
+
if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
|
|
78
|
+
reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
|
|
79
|
+
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (that.objRoot.process._groupLocksFlag === true) {
|
|
84
|
+
const glvn = utils.generateGlvn(that)
|
|
85
|
+
|
|
86
|
+
const ix = that.objRoot.process._locks.findIndex(lGlvn => glvn === lGlvn)
|
|
87
|
+
if (ix > -1) that.objRoot.process._locks.splice(ix, 1)
|
|
88
|
+
|
|
89
|
+
resolve()
|
|
90
|
+
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// send command
|
|
95
|
+
const opCode = 'glvn.removeLock'
|
|
96
|
+
|
|
97
|
+
that.writer("*2" + RESP3.CRLF +
|
|
98
|
+
RESP3.build.blob(opCode) +
|
|
99
|
+
RESP3.build.blob(utils.generateGlvn(that))
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
that._path = ''
|
|
103
|
+
|
|
104
|
+
that.reader(data => {
|
|
105
|
+
if (data.charAt(0) === '-') {
|
|
106
|
+
reject(new Error(RESP3.parse.simpleError(data)))
|
|
107
|
+
|
|
108
|
+
return
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
resolve()
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
_init = function (obj) {
|
|
117
|
+
Object.defineProperties(obj, {
|
|
118
|
+
_path: {
|
|
119
|
+
enumerable: false,
|
|
120
|
+
configurable: false,
|
|
121
|
+
writable: true
|
|
122
|
+
},
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
Object.defineProperties(obj, {
|
|
126
|
+
_init: {
|
|
127
|
+
enumerable: false,
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
module.exports = Global
|