neo.mjs 4.0.7 → 4.0.10
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.10",
|
|
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",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"neo-jsdoc": "^1.0.1",
|
|
50
50
|
"neo-jsdoc-x": "^1.0.4",
|
|
51
51
|
"postcss": "^8.4.12",
|
|
52
|
-
"sass": "^1.50.
|
|
52
|
+
"sass": "^1.50.1",
|
|
53
53
|
"webpack": "^5.72.0",
|
|
54
54
|
"webpack-cli": "^4.9.2",
|
|
55
55
|
"webpack-dev-server": "4.8.1",
|
package/src/data/Store.mjs
CHANGED
|
@@ -29,6 +29,10 @@ class Store extends Base {
|
|
|
29
29
|
* @protected
|
|
30
30
|
*/
|
|
31
31
|
ntype: 'store',
|
|
32
|
+
/**
|
|
33
|
+
* @member {Object|String|null} api_=null
|
|
34
|
+
*/
|
|
35
|
+
api_: null,
|
|
32
36
|
/**
|
|
33
37
|
* @member {Boolean} autoLoad=false
|
|
34
38
|
*/
|
|
@@ -187,8 +191,8 @@ class Store extends Base {
|
|
|
187
191
|
}
|
|
188
192
|
|
|
189
193
|
/**
|
|
190
|
-
* @param {Neo.data.Model} value
|
|
191
|
-
* @param {Neo.data.Model} oldValue
|
|
194
|
+
* @param {Neo.data.Model|Object} value
|
|
195
|
+
* @param {Neo.data.Model|Object} oldValue
|
|
192
196
|
* @protected
|
|
193
197
|
* @returns {Neo.data.Model}
|
|
194
198
|
*/
|
|
@@ -210,14 +214,31 @@ class Store extends Base {
|
|
|
210
214
|
load() {
|
|
211
215
|
let me = this;
|
|
212
216
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
217
|
+
if (me.api) {
|
|
218
|
+
let apiArray = me.api.create.split('.'),
|
|
219
|
+
fn = apiArray.pop(),
|
|
220
|
+
service = Neo.ns(apiArray.join('.'));
|
|
221
|
+
|
|
222
|
+
if (!service) {
|
|
223
|
+
console.log('Api is not defined', this);
|
|
224
|
+
} else {
|
|
225
|
+
// todo: add params
|
|
226
|
+
|
|
227
|
+
service[fn]().then(response => {
|
|
228
|
+
me.data = response.data;
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
} else {
|
|
233
|
+
Neo.Xhr.promiseJson({
|
|
234
|
+
url: me.url
|
|
235
|
+
}).catch(err => {
|
|
236
|
+
console.log('Error for Neo.Xhr.request', err, me.id);
|
|
237
|
+
}).then(data => {
|
|
238
|
+
me.data = Array.isArray(data.json) ? data.json : data.json.data;
|
|
239
|
+
// we do not need to fire a load event => onCollectionMutate()
|
|
240
|
+
});
|
|
241
|
+
}
|
|
221
242
|
}
|
|
222
243
|
|
|
223
244
|
/**
|
|
@@ -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
|
|
@@ -57,7 +66,7 @@ class Socket extends Base {
|
|
|
57
66
|
*/
|
|
58
67
|
construct(config) {
|
|
59
68
|
super.construct(config);
|
|
60
|
-
this.
|
|
69
|
+
this.createSocket();
|
|
61
70
|
}
|
|
62
71
|
|
|
63
72
|
/**
|
|
@@ -70,7 +79,7 @@ class Socket extends Base {
|
|
|
70
79
|
me.reconnectAttempts++;
|
|
71
80
|
|
|
72
81
|
if (me.reconnectAttempts < me.maxReconnectAttempts) {
|
|
73
|
-
me.
|
|
82
|
+
me.createSocket();
|
|
74
83
|
|
|
75
84
|
callback && me.on('open', {
|
|
76
85
|
callback,
|
|
@@ -89,7 +98,7 @@ class Socket extends Base {
|
|
|
89
98
|
let me = this,
|
|
90
99
|
channel = me.channel;
|
|
91
100
|
|
|
92
|
-
console.
|
|
101
|
+
console.log('WS: Sending message', (channel ? '\nChannel: ' + channel : ''), '\nData:', data);
|
|
93
102
|
|
|
94
103
|
return JSON.stringify(channel ? {channel, data} : data);
|
|
95
104
|
}
|
|
@@ -118,6 +127,29 @@ class Socket extends Base {
|
|
|
118
127
|
return value;
|
|
119
128
|
}
|
|
120
129
|
|
|
130
|
+
/**
|
|
131
|
+
* @param {Number} [code] defaults to 1000
|
|
132
|
+
* @param {String} [reason]
|
|
133
|
+
*/
|
|
134
|
+
close(code, reason) {
|
|
135
|
+
this.socket.close(code, reason);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
*
|
|
140
|
+
*/
|
|
141
|
+
createSocket() {
|
|
142
|
+
this.socket = new WebSocket(this.serverAddress);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
*
|
|
147
|
+
*/
|
|
148
|
+
destroy(...args) {
|
|
149
|
+
this.close();
|
|
150
|
+
super.destroy(...args);
|
|
151
|
+
}
|
|
152
|
+
|
|
121
153
|
/**
|
|
122
154
|
* @param {CloseEvent} event The Websocket generated CloseEvent
|
|
123
155
|
* @param {Number} event.code The WebSocket connection close code provided by the server
|
|
@@ -151,10 +183,18 @@ class Socket extends Base {
|
|
|
151
183
|
}
|
|
152
184
|
|
|
153
185
|
/**
|
|
154
|
-
* @param {
|
|
186
|
+
* @param {MessageEvent} event
|
|
155
187
|
*/
|
|
156
188
|
onMessage(event) {
|
|
157
|
-
|
|
189
|
+
let me = this,
|
|
190
|
+
data = JSON.parse(event.data);
|
|
191
|
+
|
|
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
|
+
}
|
|
158
198
|
}
|
|
159
199
|
|
|
160
200
|
/**
|
|
@@ -164,10 +204,25 @@ class Socket extends Base {
|
|
|
164
204
|
this.fire('open', {scope: this});
|
|
165
205
|
}
|
|
166
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
|
+
|
|
167
222
|
/**
|
|
168
223
|
* @param {Object} data
|
|
169
224
|
*/
|
|
170
|
-
|
|
225
|
+
sendMessage(data) {
|
|
171
226
|
let me = this,
|
|
172
227
|
socket = me.socket,
|
|
173
228
|
d = data;
|
|
@@ -182,12 +237,12 @@ class Socket extends Base {
|
|
|
182
237
|
case WebSocket.CLOSED:
|
|
183
238
|
case WebSocket.CLOSING:
|
|
184
239
|
me.attemptReconnect(function() {
|
|
185
|
-
me.
|
|
240
|
+
me.sendMessage(d);
|
|
186
241
|
});
|
|
187
242
|
break;
|
|
188
243
|
case WebSocket.CONNECTING:
|
|
189
244
|
me.on('open', function() {
|
|
190
|
-
me.
|
|
245
|
+
me.sendMessage(d);
|
|
191
246
|
}, me, {single: true});
|
|
192
247
|
break;
|
|
193
248
|
case WebSocket.OPEN:
|
|
@@ -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(api.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,27 @@ 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
|
+
let me = this,
|
|
112
|
+
url = api.url,
|
|
113
|
+
connection = me.socketConnections[url];
|
|
114
|
+
|
|
115
|
+
if (!connection) {
|
|
116
|
+
let module = await import('../../data/connection/WebSocket.mjs');
|
|
117
|
+
|
|
118
|
+
me.socketConnections[url] = connection = Neo.create(module.default, {serverAddress: url});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return await connection.promiseMessage(msg);
|
|
122
|
+
}
|
|
123
|
+
|
|
87
124
|
/**
|
|
88
125
|
* @param {String} url
|
|
89
126
|
*/
|
|
@@ -126,9 +163,9 @@ class RpcMessage extends Base {
|
|
|
126
163
|
}
|
|
127
164
|
}
|
|
128
165
|
|
|
129
|
-
Neo.applyClassConfig(
|
|
166
|
+
Neo.applyClassConfig(Message);
|
|
130
167
|
|
|
131
|
-
let instance = Neo.create(
|
|
168
|
+
let instance = Neo.create(Message);
|
|
132
169
|
|
|
133
170
|
Neo.applyToGlobalNs(instance);
|
|
134
171
|
|
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
|
}
|