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,157 @@
|
|
|
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
|
+
const funct = module.exports = {
|
|
17
|
+
method: function (that, reader, writer, fn, namespace, args) {
|
|
18
|
+
const RESP3 = that.RESP3
|
|
19
|
+
const package = []
|
|
20
|
+
|
|
21
|
+
return new Promise(function (resolve, reject) {
|
|
22
|
+
if (that.connected === false || that.loggedIn === false) {
|
|
23
|
+
reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
|
|
24
|
+
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// validate parameters
|
|
29
|
+
try {
|
|
30
|
+
parseParams(fn, args, that)
|
|
31
|
+
|
|
32
|
+
} catch (err) {
|
|
33
|
+
reject(err)
|
|
34
|
+
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// prepare parameters
|
|
39
|
+
args.forEach((arg, ix) => {
|
|
40
|
+
switch (typeof arg) {
|
|
41
|
+
case 'undefined':
|
|
42
|
+
args[ix] = '___'
|
|
43
|
+
|
|
44
|
+
break
|
|
45
|
+
case 'boolean':
|
|
46
|
+
args[ix] = arg === true ? '1' : '0'
|
|
47
|
+
|
|
48
|
+
break
|
|
49
|
+
case 'number':
|
|
50
|
+
args[ix] = arg.toString()
|
|
51
|
+
|
|
52
|
+
break
|
|
53
|
+
case 'object':
|
|
54
|
+
args[ix] = JSON.stringify(arg)
|
|
55
|
+
|
|
56
|
+
break
|
|
57
|
+
default:
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
// prepare package
|
|
62
|
+
package.push(RESP3.build.blob(namespace + '.' + fn.name))
|
|
63
|
+
args.forEach(arg => {
|
|
64
|
+
package.push(RESP3.build.blob(arg))
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
// send package
|
|
68
|
+
writer('*' + (package.length) + RESP3.CRLF + package.join(''))
|
|
69
|
+
|
|
70
|
+
reader(data => {
|
|
71
|
+
if (data.charAt(0) === '-') {
|
|
72
|
+
// process eventual simple error
|
|
73
|
+
reject(new Error(RESP3.parse.simpleError(data)))
|
|
74
|
+
|
|
75
|
+
return
|
|
76
|
+
|
|
77
|
+
} else if (data.charAt(0) === '!') {
|
|
78
|
+
// process eventual blob error
|
|
79
|
+
reject(new Error(RESP3.build.blobError(data)))
|
|
80
|
+
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// check whether it needs to return a value or just resolve()
|
|
85
|
+
if (fn.returns && typeof fn.returns === 'string') {
|
|
86
|
+
resolve(RESP3.parse.returns(data, fn.returns))
|
|
87
|
+
|
|
88
|
+
} else resolve()
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const parseParams = function (fn, args, that) {
|
|
95
|
+
if (fn.parameters && fn.parameters.length > 0) {
|
|
96
|
+
// when # of params is < that requested
|
|
97
|
+
if (fn.parameters.length !== args.length) {
|
|
98
|
+
throw new Error(errors.METHOD_BAD_ARGS_NUMBER + 'Expected ' + fn.parameters.length + ' parameters, got ' + args.length + '.')
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// validate datatype of each parameter
|
|
102
|
+
fn.parameters.forEach(function (param, ix) {
|
|
103
|
+
switch (param.datatype) {
|
|
104
|
+
case 'int':
|
|
105
|
+
case 'float': {
|
|
106
|
+
if (typeof args[ix] !== 'number' && typeof args[ix] !== 'undefined') {
|
|
107
|
+
throw new Error(errors.PARAM_NOT_NUMBER + 'Parameter ' + (ix + 1) + ': "' + param.name + '" must be a number.')
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (args[ix].toString().indexOf('.') > -1 && param.datatype === 'int') {
|
|
111
|
+
throw new Error(errors.PARAM_NOT_INT + 'Parameter ' + (ix + 1) + ': "' + param.name + '" must be an int.')
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
break
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
case 'varByRef': {
|
|
118
|
+
if (typeof args[ix] !== 'string' && typeof args[ix] !== 'undefined') {
|
|
119
|
+
throw new Error(errors.PARAM_NOT_STRING + 'Parameter ' + (ix + 1) + ': "' + param.name + '" must be a string populated with the var name.')
|
|
120
|
+
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
let found = false
|
|
124
|
+
Object.keys(that.db.vars).forEach(function (varName) {
|
|
125
|
+
if (varName === args[ix]) found = true;
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
if (found === false) {
|
|
129
|
+
throw new Error(errors.PARAM_NOT_EXISTING + 'Parameter ' + (ix + 1) + ': "' + param.name + '" var: "' + args[ix] + '" was not declared.')
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
break
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
case 'json': {
|
|
136
|
+
if (typeof args[ix] !== 'string' && typeof args[ix] !== 'undefined') {
|
|
137
|
+
throw new Error(errors.PARAM_NOT_STRING + 'Parameter ' + (ix + 1) + ': "' + param.name + '" must be a string.')
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
break
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
default: {
|
|
144
|
+
if (typeof args[ix] !== param.datatype && typeof args[ix] !== 'undefined') {
|
|
145
|
+
throw new Error(errors.PARAM_BAD_DATA_TYPE + 'Parameter ' + (ix + 1) + ': "' + param.name + '" must be a ' + param.datatype + '.')
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
break
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
// when args are passed, but not needed
|
|
154
|
+
} else if ((!fn.parameters || fn.parameters.length === 0) && args.length > 0) {
|
|
155
|
+
throw (new Error('This method has no parameters'))
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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 Vars extends GlvnManagement {
|
|
16
|
+
_type = 'vars'
|
|
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
|
+
addName: {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: false,
|
|
31
|
+
writable: false
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
Object.defineProperties(obj, {
|
|
36
|
+
removeName: {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
configurable: false,
|
|
39
|
+
writable: false
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
Object.defineProperties(obj, {
|
|
44
|
+
_init: {
|
|
45
|
+
enumerable: false,
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = Vars
|