total5 0.0.1-9 → 0.0.2
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/api.js +18 -10
- package/bin/flow5 +142 -0
- package/bin/total5 +166 -905
- package/builders.js +90 -35
- package/changelog.txt +3 -1
- package/cluster.js +1 -1
- package/cms.js +185 -51
- package/controller.js +233 -70
- package/cron.js +1 -1
- package/debug.js +12 -5
- package/edit.js +26 -33
- package/filestorage.js +38 -17
- package/flow-flowstream.js +199 -68
- package/flow.js +16 -10
- package/flowstream.js +4 -3
- package/global.js +84 -1
- package/htmlparser.js +41 -29
- package/http.js +3 -1
- package/image.js +4 -0
- package/images.js +1 -1
- package/index.js +246 -117
- package/jsonschema.js +21 -17
- package/macros.js +222 -0
- package/mail.js +11 -27
- package/markdown.js +21 -11
- package/minificators.js +1 -1
- package/nosql-querybuilder.js +4 -0
- package/nosql.js +8 -0
- package/openclient.js +1 -1
- package/package.json +4 -3
- package/pause.html +1 -1
- package/release.js +1 -1
- package/routing.js +118 -35
- package/sourcemap.js +6 -3
- package/test.js +9 -2
- package/tms.js +11 -14
- package/uibuilder.js +59 -23
- package/utils.js +147 -102
- package/viewengine.js +19 -8
- package/websocket.js +10 -6
- package/503.html +0 -65
- package/CONTRIBUTING.md +0 -55
- package/helpers/index.js +0 -32
- package/templates.json +0 -74
- package/tests/bundles/index.js +0 -25
- package/tests/cron.js +0 -0
- package/tests/htmlparser.js +0 -0
- package/tests/minifactors.js +0 -17
- package/tests/nosql.js +0 -18
- package/tests/proxy/index.js +0 -21
- package/tests/routing/index.js +0 -27
- package/tests/schemas.js +0 -17
- package/tests/server/index.js +0 -24
- package/tests/staticfiles/index.js +0 -24
- package/tests/utils.js +0 -17
- package/tmsclient.js +0 -125
- package/todo.txt +0 -11
- package/tools/beta.sh +0 -6
- package/tools/release.sh +0 -6
package/503.html
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<title>@(Please wait)</title>
|
|
5
|
-
<meta charset="utf-8" />
|
|
6
|
-
<meta name="format-detection" content="telephone=no" />
|
|
7
|
-
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
|
|
8
|
-
<meta name="robots" content="all,follow" />
|
|
9
|
-
<style type="text/css">
|
|
10
|
-
/*auto*/
|
|
11
|
-
html,body { font: normal normal 14px Arial; background-color: white; height: 100%; margin: 0; padding: 0; font-smoothing: antialiased; }
|
|
12
|
-
.table { display: table; width: 100%; height: 100%}
|
|
13
|
-
.cell { display:table-cell;vertical-align:middle;text-align:center}
|
|
14
|
-
table { max-width: 300px; margin: 20px auto; width: 100%; border:1px solid #E0E0E0; border-collapse: collapse; font-size: 12px; }
|
|
15
|
-
table td { border: 1px solid #E0E0E0; padding: 6px 8px; text-align: center; }
|
|
16
|
-
table td:first-child { text-align: left; width: 85%; }
|
|
17
|
-
.anim { animation: anim 2s infinite; }
|
|
18
|
-
.text { color: #A0A0A0; font-size: 10px; margin-bottom: 3px; text-transform: uppercase; }
|
|
19
|
-
#time { font-size: 60px; font-weight: bold; margin-bottom: 10px; background-color: black; color: white; padding: 3px 10px; min-width: 70px; text-align: center; border-radius: 2px; position: relative; display: inline-block; }
|
|
20
|
-
|
|
21
|
-
@keyframes anim {
|
|
22
|
-
0% { transform:scale(1); }
|
|
23
|
-
50%{ transform:scale(1.5) rotate(180deg); color:gray }
|
|
24
|
-
100%{ transform:scale(1); }
|
|
25
|
-
}
|
|
26
|
-
</style>
|
|
27
|
-
</head>
|
|
28
|
-
<body>
|
|
29
|
-
|
|
30
|
-
<div class="table">
|
|
31
|
-
<div class="cell">
|
|
32
|
-
<div id="time" style="">10</div>
|
|
33
|
-
<div class="text">@(Please wait)</div>
|
|
34
|
-
<div>
|
|
35
|
-
<b>@(Application is starting …)</b>
|
|
36
|
-
</div>
|
|
37
|
-
<table>
|
|
38
|
-
@{foreach m in model}
|
|
39
|
-
<tr>
|
|
40
|
-
<td>@{m.key}</td>
|
|
41
|
-
<td class="anim">⧗</td>
|
|
42
|
-
</tr>
|
|
43
|
-
@{end}
|
|
44
|
-
</table>
|
|
45
|
-
</div>
|
|
46
|
-
</div>
|
|
47
|
-
|
|
48
|
-
<script>
|
|
49
|
-
var i = 10;
|
|
50
|
-
setInterval(function() {
|
|
51
|
-
i--;
|
|
52
|
-
if (i >= 0) {
|
|
53
|
-
var el = document.getElementById('time');
|
|
54
|
-
!i && (el.style.fontSize = '40px');
|
|
55
|
-
el.innerHTML = (i === 0 ? '@(REFRESHING)' : i);
|
|
56
|
-
} else if (i === -1) {
|
|
57
|
-
setTimeout(function() {
|
|
58
|
-
window.location.reload();
|
|
59
|
-
}, 1000);
|
|
60
|
-
}
|
|
61
|
-
}, 1000);
|
|
62
|
-
</script>
|
|
63
|
-
|
|
64
|
-
</body>
|
|
65
|
-
</html>
|
package/CONTRIBUTING.md
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
# Contributing to total.js framework
|
|
2
|
-
|
|
3
|
-
We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's:
|
|
4
|
-
|
|
5
|
-
- Reporting a bug
|
|
6
|
-
- Discussing the current state of the code
|
|
7
|
-
- Submitting a fix
|
|
8
|
-
- Proposing new features
|
|
9
|
-
|
|
10
|
-
## We Develop with Github
|
|
11
|
-
|
|
12
|
-
We use github to host code, to track issues and feature requests, as well as accept pull requests.
|
|
13
|
-
|
|
14
|
-
## We Use [Github Flow](https://docs.github.com/en/get-started/quickstart/github-flow), So All Code Changes Happen Through Pull Requests
|
|
15
|
-
|
|
16
|
-
Pull requests are the best way to propose changes to the codebase (we use [Github Flow](https://docs.github.com/en/get-started/quickstart/github-flow)). We actively welcome your pull requests:
|
|
17
|
-
|
|
18
|
-
1. Fork the repo and create your branch from `master`.
|
|
19
|
-
2. If you've added code that should be tested, add tests.
|
|
20
|
-
3. If you've changed APIs, update the documentation.
|
|
21
|
-
4. Ensure the test suite passes.
|
|
22
|
-
5. Make sure your code lints.
|
|
23
|
-
6. Issue that pull request!
|
|
24
|
-
|
|
25
|
-
## Any contributions you make will be under the MIT Software License
|
|
26
|
-
|
|
27
|
-
In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if that's a concern.
|
|
28
|
-
|
|
29
|
-
## Report bugs using Github's [issues](https://github.com/totaljs/framework5/issues)
|
|
30
|
-
|
|
31
|
-
We use GitHub issues to track public bugs. Report a bug by [opening a new issue](https://github.com/totaljs/framework4/issues); it's that easy!
|
|
32
|
-
|
|
33
|
-
## Write bug reports with detail, background, and sample code
|
|
34
|
-
|
|
35
|
-
**Great Bug Reports** tend to have:
|
|
36
|
-
|
|
37
|
-
- A quick summary and/or background
|
|
38
|
-
- Steps to reproduce - be specific!
|
|
39
|
-
- What you expected would happen
|
|
40
|
-
- What actually happens
|
|
41
|
-
- Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)
|
|
42
|
-
|
|
43
|
-
People *love* thorough bug reports. I'm not even kidding.
|
|
44
|
-
|
|
45
|
-
## Use a Consistent Coding Style
|
|
46
|
-
|
|
47
|
-
We use coding styel as described here (https://docs.totaljs.com/welcome/67b47001ty51c/)
|
|
48
|
-
|
|
49
|
-
## License
|
|
50
|
-
|
|
51
|
-
By contributing, you agree that your contributions will be licensed under its MIT License.
|
|
52
|
-
|
|
53
|
-
## References
|
|
54
|
-
|
|
55
|
-
This document was adapted from (https://gist.github.com/briandk/3d2e8b3ec8daf5a27a62)
|
package/helpers/index.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// ===================================================
|
|
2
|
-
// Total.js v5 start script
|
|
3
|
-
// https://www.totaljs.com
|
|
4
|
-
// ===================================================
|
|
5
|
-
|
|
6
|
-
require('total5');
|
|
7
|
-
|
|
8
|
-
const options = {};
|
|
9
|
-
|
|
10
|
-
// options.ip = '127.0.0.1';
|
|
11
|
-
// options.port = parseInt(process.argv[2]);
|
|
12
|
-
// options.unixsocket = PATH.join(F.tmpdir, 'app_name.socket');
|
|
13
|
-
// options.unixsocket777 = true;
|
|
14
|
-
// options.config = { name: 'Total.js' };
|
|
15
|
-
// options.sleep = 3000;
|
|
16
|
-
// options.inspector = 9229;
|
|
17
|
-
// options.watch = ['private'];
|
|
18
|
-
// options.livereload = 'https://yourhostname';
|
|
19
|
-
// options.watcher = true; // enables watcher for the release mode only controlled by the app `F.restart()`
|
|
20
|
-
// options.edit = 'wss://www.yourcodeinstance.com/?id=projectname'
|
|
21
|
-
options.release = process.argv.includes('--release');
|
|
22
|
-
|
|
23
|
-
// Service mode:
|
|
24
|
-
options.servicemode = process.argv.includes('--service') || process.argv.includes('--servicemode');
|
|
25
|
-
// options.servicemode = 'definitions,modules,config';
|
|
26
|
-
|
|
27
|
-
// Cluster:
|
|
28
|
-
// options.tz = 'utc';
|
|
29
|
-
// options.cluster = 'auto';
|
|
30
|
-
// options.limit = 10; // max 10. threads (works only with "auto" scaling)
|
|
31
|
-
|
|
32
|
-
F.run(options);
|
package/templates.json
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"empty": {
|
|
3
|
-
"id": "emptyproject",
|
|
4
|
-
"name": "Empty",
|
|
5
|
-
"total": 4,
|
|
6
|
-
"description": "Empty project without any special setup"
|
|
7
|
-
},
|
|
8
|
-
"typescript": {
|
|
9
|
-
"id": "emptyproject-typescript",
|
|
10
|
-
"name": "Typescript",
|
|
11
|
-
"total": 4,
|
|
12
|
-
"description": "Total.js with typescript"
|
|
13
|
-
},
|
|
14
|
-
"website": {
|
|
15
|
-
"id": "emptyproject-website",
|
|
16
|
-
"name": "Website",
|
|
17
|
-
"total": 4,
|
|
18
|
-
"description": "Website example"
|
|
19
|
-
},
|
|
20
|
-
"postgres": {
|
|
21
|
-
"id": "emptyproject-postgresql",
|
|
22
|
-
"name": "Postgres template",
|
|
23
|
-
"total": 4,
|
|
24
|
-
"description": "Empty project ready to be used with PostgreSQL"
|
|
25
|
-
},
|
|
26
|
-
"app-builder": {
|
|
27
|
-
"id": "emptyproject-builder",
|
|
28
|
-
"name": "App Builder",
|
|
29
|
-
"total": 4,
|
|
30
|
-
"description": "Tool for creating Total.js server-side applications"
|
|
31
|
-
},
|
|
32
|
-
"empty-spa": {
|
|
33
|
-
"id": "emptyproject-emptyspa",
|
|
34
|
-
"name": "Empty SPA",
|
|
35
|
-
"total": 4,
|
|
36
|
-
"description": "Empty single page application project"
|
|
37
|
-
},
|
|
38
|
-
"spa": {
|
|
39
|
-
"id": "emptyproject-spa",
|
|
40
|
-
"name": "SPA",
|
|
41
|
-
"total": 4,
|
|
42
|
-
"description": "Single page application template"
|
|
43
|
-
},
|
|
44
|
-
"pwa": {
|
|
45
|
-
"id": "emptyproject-emptyspa",
|
|
46
|
-
"name": "PWA",
|
|
47
|
-
"total": 4,
|
|
48
|
-
"description": "Progressive web application template"
|
|
49
|
-
},
|
|
50
|
-
"flow": {
|
|
51
|
-
"id": "emptyproject-flow",
|
|
52
|
-
"name": "Flow",
|
|
53
|
-
"total": 4,
|
|
54
|
-
"description": "Visual programming interface for IoT"
|
|
55
|
-
},
|
|
56
|
-
"flowstream": {
|
|
57
|
-
"id": "flowstream",
|
|
58
|
-
"name": "FlowStream",
|
|
59
|
-
"total": 4,
|
|
60
|
-
"description": "Total.js FlowStream"
|
|
61
|
-
},
|
|
62
|
-
"tms": {
|
|
63
|
-
"id": "tms",
|
|
64
|
-
"name": "TMS",
|
|
65
|
-
"total": 4,
|
|
66
|
-
"description": "Total.js Message Service integrator"
|
|
67
|
-
},
|
|
68
|
-
"cms": {
|
|
69
|
-
"id": "cmsbundle",
|
|
70
|
-
"name": "CMS",
|
|
71
|
-
"total": 4,
|
|
72
|
-
"description": "Total.js CMS"
|
|
73
|
-
}
|
|
74
|
-
}
|
package/tests/bundles/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
|
|
3
|
-
require('../../index');
|
|
4
|
-
require('../../test');
|
|
5
|
-
|
|
6
|
-
// Unpack bundle in bundles directory + download bundles from URL (we can add a test bundle to our CDN)
|
|
7
|
-
// Merging files
|
|
8
|
-
// Removing files
|
|
9
|
-
|
|
10
|
-
// load web server and test app
|
|
11
|
-
F.http();
|
|
12
|
-
|
|
13
|
-
ON('ready', function() {
|
|
14
|
-
|
|
15
|
-
Test.push('A test name', function(next) {
|
|
16
|
-
// Test.print('String.slug()', [error]);
|
|
17
|
-
Test.print('String.slug()');
|
|
18
|
-
next();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
Test.run(function() {
|
|
22
|
-
process.exit(0);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
});
|
package/tests/cron.js
DELETED
|
File without changes
|
package/tests/htmlparser.js
DELETED
|
File without changes
|
package/tests/minifactors.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
|
|
3
|
-
require('../index');
|
|
4
|
-
require('../test');
|
|
5
|
-
|
|
6
|
-
// .js
|
|
7
|
-
// .css
|
|
8
|
-
// .html
|
|
9
|
-
// with and without comments
|
|
10
|
-
|
|
11
|
-
Test.push('Group', function(next) {
|
|
12
|
-
// Test.print('String.slug()', [error]);
|
|
13
|
-
Test.print('Test');
|
|
14
|
-
next();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
Test.run();
|
package/tests/nosql.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
|
|
3
|
-
require('../index');
|
|
4
|
-
require('../test');
|
|
5
|
-
|
|
6
|
-
// .insert()
|
|
7
|
-
// .find() + .autoquery()
|
|
8
|
-
// .read()
|
|
9
|
-
// .update()
|
|
10
|
-
// .remove()
|
|
11
|
-
|
|
12
|
-
Test.push('Group', function(next) {
|
|
13
|
-
// Test.print('String.slug()', [error]);
|
|
14
|
-
Test.print('Test');
|
|
15
|
-
next();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
Test.run();
|
package/tests/proxy/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
|
|
3
|
-
require('../../index');
|
|
4
|
-
require('../../test');
|
|
5
|
-
|
|
6
|
-
// load web server and test app
|
|
7
|
-
F.http();
|
|
8
|
-
|
|
9
|
-
ON('ready', function() {
|
|
10
|
-
|
|
11
|
-
Test.push('A test name', function(next) {
|
|
12
|
-
// Test.print('String.slug()', [error]);
|
|
13
|
-
Test.print('String.slug()');
|
|
14
|
-
next();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
Test.run(function() {
|
|
18
|
-
process.exit(0);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
});
|
package/tests/routing/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
|
|
3
|
-
require('../../index');
|
|
4
|
-
require('../../test');
|
|
5
|
-
|
|
6
|
-
// HTTP routing
|
|
7
|
-
// API routing
|
|
8
|
-
// WebSocket routing + WebSocketClient (text, json and binary communication)
|
|
9
|
-
// File routing
|
|
10
|
-
// Removing routess
|
|
11
|
-
|
|
12
|
-
// load web server and test app
|
|
13
|
-
F.http();
|
|
14
|
-
|
|
15
|
-
ON('ready', function() {
|
|
16
|
-
|
|
17
|
-
Test.push('A test name', function(next) {
|
|
18
|
-
// Test.print('String.slug()', [error]);
|
|
19
|
-
Test.print('String.slug()');
|
|
20
|
-
next();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
Test.run(function() {
|
|
24
|
-
process.exit(0);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
});
|
package/tests/schemas.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
|
|
3
|
-
require('../index');
|
|
4
|
-
require('../test');
|
|
5
|
-
|
|
6
|
-
// NEWACTION()
|
|
7
|
-
// NEWSCHEMA()
|
|
8
|
-
// ACTION()
|
|
9
|
-
// JSON schema types defined in the ACTIONS
|
|
10
|
-
|
|
11
|
-
Test.push('Group', function(next) {
|
|
12
|
-
// Test.print('String.slug()', [error]);
|
|
13
|
-
Test.print('Test');
|
|
14
|
-
next();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
Test.run();
|
package/tests/server/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
|
|
3
|
-
require('../../index');
|
|
4
|
-
require('../../test');
|
|
5
|
-
|
|
6
|
-
// unixsocket
|
|
7
|
-
// ip + port
|
|
8
|
-
|
|
9
|
-
// load web server and test app
|
|
10
|
-
F.http();
|
|
11
|
-
|
|
12
|
-
ON('ready', function() {
|
|
13
|
-
|
|
14
|
-
Test.push('A test name', function(next) {
|
|
15
|
-
// Test.print('String.slug()', [error]);
|
|
16
|
-
Test.print('String.slug()');
|
|
17
|
-
next();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
Test.run(function() {
|
|
21
|
-
process.exit(0);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
|
|
3
|
-
require('../../index');
|
|
4
|
-
require('../../test');
|
|
5
|
-
|
|
6
|
-
// merging files
|
|
7
|
-
// localization
|
|
8
|
-
|
|
9
|
-
// load web server and test app
|
|
10
|
-
F.http();
|
|
11
|
-
|
|
12
|
-
ON('ready', function() {
|
|
13
|
-
|
|
14
|
-
Test.push('A test name', function(next) {
|
|
15
|
-
// Test.print('String.slug()', [error]);
|
|
16
|
-
Test.print('String.slug()');
|
|
17
|
-
next();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
Test.run(function() {
|
|
21
|
-
process.exit(0);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
});
|
package/tests/utils.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
|
|
3
|
-
require('../index');
|
|
4
|
-
require('../test');
|
|
5
|
-
|
|
6
|
-
Test.push('String.prototypes', function(next) {
|
|
7
|
-
// Test.print('String.slug()', [error]);
|
|
8
|
-
Test.print('String.slug()');
|
|
9
|
-
next();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
Test.push('Number.prototypes', function(next) {
|
|
13
|
-
Test.print('Number.currency');
|
|
14
|
-
next();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
Test.run();
|
package/tmsclient.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
exports.create = function(url, token, callback) {
|
|
2
|
-
|
|
3
|
-
if (typeof(token) === 'function') {
|
|
4
|
-
callback = token;
|
|
5
|
-
token = undefined;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
var client = F.TWebSocket.createclient();
|
|
9
|
-
|
|
10
|
-
var publishers = {};
|
|
11
|
-
var subscribers = {};
|
|
12
|
-
var callbacks = {};
|
|
13
|
-
var isopen = false;
|
|
14
|
-
var callbackid = 0;
|
|
15
|
-
var timeout;
|
|
16
|
-
|
|
17
|
-
if (token)
|
|
18
|
-
client.headers['x-token'] = token;
|
|
19
|
-
|
|
20
|
-
client.options.reconnectserver = true;
|
|
21
|
-
client.connect(url.replace(/^http/, 'ws'));
|
|
22
|
-
client.ready = false;
|
|
23
|
-
|
|
24
|
-
client.on('destroy', function() {
|
|
25
|
-
publishers = null;
|
|
26
|
-
subscribers = null;
|
|
27
|
-
|
|
28
|
-
for (var key in callbacks) {
|
|
29
|
-
var item = callbacks[key];
|
|
30
|
-
clearTimeout(item.timeout);
|
|
31
|
-
item.callback && item.callback('TMS has been destroyed');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
callbacks = null;
|
|
35
|
-
|
|
36
|
-
timeout && clearTimeout(timeout);
|
|
37
|
-
timeout = null;
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
client.on('close', function() {
|
|
41
|
-
isopen = false;
|
|
42
|
-
client.ready = false;
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
client.on('message', function(msg) {
|
|
46
|
-
|
|
47
|
-
if (msg.type === 'call') {
|
|
48
|
-
if (callbacks[msg.callbackid]) {
|
|
49
|
-
var tmp = callbacks[msg.callbackid];
|
|
50
|
-
tmp.callback(msg.error ? ErrorBuilder.assign(msg.data) : null, msg.success ? msg.data : null);
|
|
51
|
-
tmp.timeout && clearTimeout(tmp.timeout);
|
|
52
|
-
delete callbacks[msg.callbackid];
|
|
53
|
-
}
|
|
54
|
-
} else if (msg.type === 'publish' && subscribers[msg.id] && publishers[msg.id]) {
|
|
55
|
-
var err = new ErrorBuilder();
|
|
56
|
-
var data = framework_jsonschema.transform(publishers[msg.id], err, msg.data, true);
|
|
57
|
-
if (data) {
|
|
58
|
-
for (var fn of subscribers[msg.id])
|
|
59
|
-
fn(data);
|
|
60
|
-
}
|
|
61
|
-
} else if (msg.type === 'meta') {
|
|
62
|
-
publishers = {};
|
|
63
|
-
for (var item of msg.publish)
|
|
64
|
-
publishers[item.id] = item.schema;
|
|
65
|
-
sync_subscribers();
|
|
66
|
-
isopen = true;
|
|
67
|
-
client.ready = true;
|
|
68
|
-
client.meta = msg;
|
|
69
|
-
if (callback) {
|
|
70
|
-
setImmediate(callback, null, client, client.meta);
|
|
71
|
-
callback = null;
|
|
72
|
-
}
|
|
73
|
-
client.emit('meta', msg);
|
|
74
|
-
client.emit('ready');
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
var timeouthandler = function(id) {
|
|
79
|
-
var obj = callbacks[id];
|
|
80
|
-
obj.callback && obj.callback('408: Timeout');
|
|
81
|
-
delete callbacks[id];
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
client.call = function(name, data, callback, timeout) {
|
|
85
|
-
if (callback)
|
|
86
|
-
client._call(name, data, callback, timeout);
|
|
87
|
-
else
|
|
88
|
-
return new Promise((resolve, reject) => client._call(name, data, (err, res) => err ? reject(err) : resolve(res), timeout));
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
client._call = function(name, data, callback, timeout) {
|
|
92
|
-
if (isopen) {
|
|
93
|
-
var key = (callbackid++) + '';
|
|
94
|
-
var obj = {};
|
|
95
|
-
obj.callback = callback;
|
|
96
|
-
obj.timeout = setTimeout(timeouthandler, timeout || 10000, key);
|
|
97
|
-
callbacks[key] = obj;
|
|
98
|
-
client.send({ type: 'call', id: name, data: data, callbackid: key });
|
|
99
|
-
} else
|
|
100
|
-
callback('TMS is offline');
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
client.subscribe = function(name, callback) {
|
|
104
|
-
timeout && clearTimeout(timeout);
|
|
105
|
-
timeout = setTimeout(sync_subscribers, 50, true);
|
|
106
|
-
if (subscribers[name])
|
|
107
|
-
subscribers[name].push(callback);
|
|
108
|
-
else
|
|
109
|
-
subscribers[name] = [callback];
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
client.publish = function(name, data) {
|
|
113
|
-
isopen && client.send({ type: 'subscribe', id: name, data: data });
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
var sync_subscribers = function(force) {
|
|
117
|
-
timeout && clearTimeout(timeout);
|
|
118
|
-
timeout = null;
|
|
119
|
-
var keys = Object.keys(subscribers);
|
|
120
|
-
if (force || keys.length)
|
|
121
|
-
client.send({ type: 'subscribers', subscribers: keys });
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
return client;
|
|
125
|
-
};
|
package/todo.txt
DELETED
package/tools/beta.sh
DELETED