neo.mjs 4.0.8 → 4.0.11
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.11",
|
|
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",
|
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.read.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
|
|
@@ -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
|
*/
|
|
@@ -207,12 +237,12 @@ class Socket extends Base {
|
|
|
207
237
|
case WebSocket.CLOSED:
|
|
208
238
|
case WebSocket.CLOSING:
|
|
209
239
|
me.attemptReconnect(function() {
|
|
210
|
-
me.
|
|
240
|
+
me.sendMessage(d);
|
|
211
241
|
});
|
|
212
242
|
break;
|
|
213
243
|
case WebSocket.CONNECTING:
|
|
214
244
|
me.on('open', function() {
|
|
215
|
-
me.
|
|
245
|
+
me.sendMessage(d);
|
|
216
246
|
}, me, {single: true});
|
|
217
247
|
break;
|
|
218
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
|
}
|