neo.mjs 4.0.8 → 4.0.9
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "neo.mjs",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.9",
|
|
4
4
|
"description": "The webworkers driven UI framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@fortawesome/fontawesome-free": "^6.1.1",
|
|
38
38
|
"@material/mwc-button": "^0.25.3",
|
|
39
39
|
"@material/mwc-textfield": "^0.25.3",
|
|
40
|
-
"autoprefixer": "^10.4.
|
|
40
|
+
"autoprefixer": "^10.4.5",
|
|
41
41
|
"chalk": "^5.0.1",
|
|
42
42
|
"clean-webpack-plugin": "^4.0.0",
|
|
43
43
|
"commander": "^9.2.0",
|
|
@@ -15,6 +15,15 @@ class Socket extends Base {
|
|
|
15
15
|
* @member {Number} maxReconnectAttempts=5
|
|
16
16
|
*/
|
|
17
17
|
maxReconnectAttempts = 5
|
|
18
|
+
/**
|
|
19
|
+
* @member {Object} messageCallbacks={}
|
|
20
|
+
*/
|
|
21
|
+
messageCallbacks = {}
|
|
22
|
+
/**
|
|
23
|
+
* @member {Number} messageId=1
|
|
24
|
+
* @protected
|
|
25
|
+
*/
|
|
26
|
+
messageId = 1
|
|
18
27
|
/**
|
|
19
28
|
* @member {Number} reconnectAttempts=0
|
|
20
29
|
* @protected
|
|
@@ -177,9 +186,15 @@ class Socket extends Base {
|
|
|
177
186
|
* @param {MessageEvent} event
|
|
178
187
|
*/
|
|
179
188
|
onMessage(event) {
|
|
180
|
-
let
|
|
189
|
+
let me = this,
|
|
190
|
+
data = JSON.parse(event.data);
|
|
181
191
|
|
|
182
192
|
console.log('onMessage', data);
|
|
193
|
+
|
|
194
|
+
if (data.mId) {
|
|
195
|
+
me.messageCallbacks[data.mId].resolve(data.data);
|
|
196
|
+
delete me.messageCallbacks[data.mId];
|
|
197
|
+
}
|
|
183
198
|
}
|
|
184
199
|
|
|
185
200
|
/**
|
|
@@ -189,6 +204,21 @@ class Socket extends Base {
|
|
|
189
204
|
this.fire('open', {scope: this});
|
|
190
205
|
}
|
|
191
206
|
|
|
207
|
+
/**
|
|
208
|
+
* @param {Object} data
|
|
209
|
+
* @returns {Promise<any>}
|
|
210
|
+
*/
|
|
211
|
+
promiseMessage(data) {
|
|
212
|
+
let me = this;
|
|
213
|
+
|
|
214
|
+
return new Promise((resolve, reject) => {
|
|
215
|
+
me.messageCallbacks[me.messageId] = {reject, resolve};
|
|
216
|
+
|
|
217
|
+
me.sendMessage({data, mId: me.messageId});
|
|
218
|
+
me.messageId++;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
192
222
|
/**
|
|
193
223
|
* @param {Object} data
|
|
194
224
|
*/
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import Base from '
|
|
1
|
+
import Base from '../Base.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @class Neo.manager.
|
|
4
|
+
* @class Neo.manager.rpc.Api
|
|
5
5
|
* @extends Neo.manager.Base
|
|
6
6
|
* @singleton
|
|
7
7
|
*/
|
|
8
|
-
class
|
|
8
|
+
class Api extends Base {
|
|
9
9
|
static getConfig() {return {
|
|
10
10
|
/**
|
|
11
|
-
* @member {String} className='Neo.manager.
|
|
11
|
+
* @member {String} className='Neo.manager.rpc.Api'
|
|
12
12
|
* @protected
|
|
13
13
|
*/
|
|
14
|
-
className: 'Neo.manager.
|
|
14
|
+
className: 'Neo.manager.rpc.Api',
|
|
15
15
|
/**
|
|
16
16
|
* @member {Boolean} singleton=true
|
|
17
17
|
* @protected
|
|
@@ -27,19 +27,20 @@ class RpcApi extends Base {
|
|
|
27
27
|
Object.entries(api.services).forEach(([service, serviceValue]) => {
|
|
28
28
|
Object.entries(serviceValue.methods).forEach(([method, methodValue]) => {
|
|
29
29
|
this.register({
|
|
30
|
-
id
|
|
30
|
+
id : `${service}.${method}`,
|
|
31
31
|
method,
|
|
32
32
|
service,
|
|
33
|
-
|
|
33
|
+
type: methodValue.type || serviceValue.type || api.type || 'ajax',
|
|
34
|
+
url : methodValue.url || serviceValue.url || api.url
|
|
34
35
|
})
|
|
35
36
|
})
|
|
36
37
|
})
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
Neo.applyClassConfig(
|
|
41
|
+
Neo.applyClassConfig(Api);
|
|
41
42
|
|
|
42
|
-
let instance = Neo.create(
|
|
43
|
+
let instance = Neo.create(Api);
|
|
43
44
|
|
|
44
45
|
Neo.applyToGlobalNs(instance);
|
|
45
46
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import Base from '
|
|
2
|
-
import NeoArray from '
|
|
1
|
+
import Base from '../Base.mjs';
|
|
2
|
+
import NeoArray from '../../util/Array.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* @class Neo.manager.
|
|
5
|
+
* @class Neo.manager.rpc.Message
|
|
6
6
|
* @extends Neo.manager.Base
|
|
7
7
|
* @singleton
|
|
8
8
|
*/
|
|
9
|
-
class
|
|
9
|
+
class Message extends Base {
|
|
10
10
|
/**
|
|
11
11
|
* Stores the urls of endpoints for which a setTimeout() call is in progress
|
|
12
12
|
* @member {String[]} endPointTimeouts=[]
|
|
@@ -23,6 +23,10 @@ class RpcMessage extends Base {
|
|
|
23
23
|
* @member {Number} requestBuffer=20
|
|
24
24
|
*/
|
|
25
25
|
requestBuffer = 20
|
|
26
|
+
/**
|
|
27
|
+
* @member {Object} socketConnections={}
|
|
28
|
+
*/
|
|
29
|
+
socketConnections = {}
|
|
26
30
|
/**
|
|
27
31
|
* internal incrementing flag
|
|
28
32
|
* @member {Number} transactionId=1
|
|
@@ -32,10 +36,10 @@ class RpcMessage extends Base {
|
|
|
32
36
|
|
|
33
37
|
static getConfig() {return {
|
|
34
38
|
/**
|
|
35
|
-
* @member {String} className='Neo.manager.
|
|
39
|
+
* @member {String} className='Neo.manager.rpc.Message'
|
|
36
40
|
* @protected
|
|
37
41
|
*/
|
|
38
|
-
className: 'Neo.manager.
|
|
42
|
+
className: 'Neo.manager.rpc.Message',
|
|
39
43
|
/**
|
|
40
44
|
* @member {Boolean} singleton=true
|
|
41
45
|
* @protected
|
|
@@ -56,10 +60,22 @@ class RpcMessage extends Base {
|
|
|
56
60
|
* @returns {Promise<any>}
|
|
57
61
|
*/
|
|
58
62
|
onMessage(msg) {
|
|
63
|
+
let api = Neo.manager.rpc.Api.get(`${msg.service}.${msg.method}`);
|
|
64
|
+
|
|
65
|
+
return this[`onMessage${Neo.capitalize(method.type)}`](msg, api);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
*
|
|
70
|
+
* @param {Object} msg
|
|
71
|
+
* @param {Object} api
|
|
72
|
+
* @protected
|
|
73
|
+
* @returns {Promise<any>}
|
|
74
|
+
*/
|
|
75
|
+
onMessageAjax(msg, api) {
|
|
59
76
|
return new Promise((resolve, reject) => {
|
|
60
|
-
let me
|
|
61
|
-
|
|
62
|
-
url = method.url;
|
|
77
|
+
let me = this,
|
|
78
|
+
url = api.url;
|
|
63
79
|
|
|
64
80
|
me.register({
|
|
65
81
|
id : me.messageId,
|
|
@@ -84,6 +100,33 @@ class RpcMessage extends Base {
|
|
|
84
100
|
});
|
|
85
101
|
}
|
|
86
102
|
|
|
103
|
+
/**
|
|
104
|
+
*
|
|
105
|
+
* @param {Object} msg
|
|
106
|
+
* @param {Object} api
|
|
107
|
+
* @protected
|
|
108
|
+
* @returns {Promise<any>}
|
|
109
|
+
*/
|
|
110
|
+
async onMessageWebsocket(msg, api) {
|
|
111
|
+
console.log('onMessageWebsocket', msg, api);
|
|
112
|
+
|
|
113
|
+
let me = this,
|
|
114
|
+
url = api.url,
|
|
115
|
+
connection = me.socketConnections[url];
|
|
116
|
+
|
|
117
|
+
if (!connection) {
|
|
118
|
+
let module = await import('../../data/connection/WebSocket.mjs');
|
|
119
|
+
|
|
120
|
+
me.socketConnections[url] = connection = Neo.create(module.default, {serverAddress: url});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return await connection.promiseMessage({
|
|
124
|
+
data : msg,
|
|
125
|
+
method : api.method,
|
|
126
|
+
service: api.service
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
|
|
87
130
|
/**
|
|
88
131
|
* @param {String} url
|
|
89
132
|
*/
|
|
@@ -126,9 +169,9 @@ class RpcMessage extends Base {
|
|
|
126
169
|
}
|
|
127
170
|
}
|
|
128
171
|
|
|
129
|
-
Neo.applyClassConfig(
|
|
172
|
+
Neo.applyClassConfig(Message);
|
|
130
173
|
|
|
131
|
-
let instance = Neo.create(
|
|
174
|
+
let instance = Neo.create(Message);
|
|
132
175
|
|
|
133
176
|
Neo.applyToGlobalNs(instance);
|
|
134
177
|
|
package/src/worker/Data.mjs
CHANGED
|
@@ -70,7 +70,7 @@ class Data extends Base {
|
|
|
70
70
|
* @param {Object} msg.data the API content
|
|
71
71
|
*/
|
|
72
72
|
onRegisterApi(msg) {
|
|
73
|
-
import('../manager/
|
|
73
|
+
import('../manager/rpc/Api.mjs').then(module => {
|
|
74
74
|
module.default.registerApi(msg.data);
|
|
75
75
|
this.rpcApiManagerLoaded = true
|
|
76
76
|
})
|
|
@@ -82,7 +82,7 @@ class Data extends Base {
|
|
|
82
82
|
onRegisterNeoConfig(msg) {
|
|
83
83
|
super.onRegisterNeoConfig(msg);
|
|
84
84
|
|
|
85
|
-
Neo.config.remotesApiUrl && import('../manager/
|
|
85
|
+
Neo.config.remotesApiUrl && import('../manager/rpc/Message.mjs').then(module => {
|
|
86
86
|
this.rpcMessageManagerLoaded = true
|
|
87
87
|
})
|
|
88
88
|
}
|
|
@@ -102,7 +102,7 @@ class Data extends Base {
|
|
|
102
102
|
|
|
103
103
|
me.reject(msg);
|
|
104
104
|
} else {
|
|
105
|
-
response = await Neo.manager.
|
|
105
|
+
response = await Neo.manager.rpc.Message.onMessage(msg);
|
|
106
106
|
|
|
107
107
|
me.resolve(msg, response);
|
|
108
108
|
}
|