vrpc 3.14.0 → 3.15.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/LICENSE +1 -1
- package/README.md +100 -77
- package/browser/vrpc.js +2 -2
- package/index.js +7 -7
- package/package.json +23 -15
- package/vrpc/Registrations.js +850 -0
- package/vrpc/SubscribeRetrier.js +33 -0
- package/vrpc/VrpcAdapter.js +552 -294
- package/vrpc/VrpcAgent.js +230 -153
- package/vrpc/VrpcBrowserAdapter.js +417 -285
- package/vrpc/VrpcBrowserAgent.js +239 -128
- package/vrpc/VrpcClient.js +1108 -213
- package/vrpc/VrpcNative.js +10 -5
- package/vrpc/VrpcPersistor.js +1 -1
- package/vrpc/adapter.hpp +1 -1
- package/vrpc/addon.cpp +1 -1
- package/vrpc/comment-parser/parser.js +23 -0
- package/vrpc/namePattern.js +86 -0
- package/vrpc/vrpc-agent-js +3 -11
package/vrpc/VrpcNative.js
CHANGED
|
@@ -16,7 +16,7 @@ Author: Dr. Burkhard C. Heisen (https://github.com/heisenware/vrpc)
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
|
19
|
-
Copyright (c) 2018
|
|
19
|
+
Copyright (c) 2018 Dr. Burkhard C. Heisen <burkhard.heisen@heisenware.com>.
|
|
20
20
|
|
|
21
21
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
22
22
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -57,10 +57,15 @@ class VrpcNative {
|
|
|
57
57
|
|
|
58
58
|
// register callback handler
|
|
59
59
|
this._adapter.onCallback(data => {
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
// the native adapter hands over a string (crossing language
|
|
61
|
+
// boundaries): a callback or an event `{ a, i }`, or the second answer
|
|
62
|
+
// of a promise `{ r | e, i }`, which goes on as a whole
|
|
63
|
+
const json = JSON.parse(data)
|
|
64
|
+
const { i } = json
|
|
65
|
+
this._eventEmitter.emit(
|
|
66
|
+
i,
|
|
67
|
+
typeof i === 'string' && i.startsWith('__p__') ? json : json.a
|
|
68
|
+
)
|
|
64
69
|
})
|
|
65
70
|
}
|
|
66
71
|
|
package/vrpc/VrpcPersistor.js
CHANGED
|
@@ -14,7 +14,7 @@ procedure calls (RPC).
|
|
|
14
14
|
Author: Dr. Burkhard C. Heisen (https://github.com/heisenware/vrpc)
|
|
15
15
|
|
|
16
16
|
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
|
17
|
-
Copyright (c) 2018
|
|
17
|
+
Copyright (c) 2018 Dr. Burkhard C. Heisen <burkhard.heisen@heisenware.com>.
|
|
18
18
|
|
|
19
19
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
20
20
|
of this software and associated documentation files (the "Software"), to deal
|
package/vrpc/adapter.hpp
CHANGED
|
@@ -16,7 +16,7 @@ Author: Dr. Burkhard C. Heisen (https://github.com/heisenware/vrpc-hpp)
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
|
19
|
-
Copyright (c) 2018
|
|
19
|
+
Copyright (c) 2018 Dr. Burkhard C. Heisen
|
|
20
20
|
<burkhard.heisen@heisenware.com>.
|
|
21
21
|
|
|
22
22
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
package/vrpc/addon.cpp
CHANGED
|
@@ -15,7 +15,7 @@ Author: Dr. Burkhard C. Heisen (https://github.com/heisenware/vrpc)
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
|
18
|
-
Copyright (c) 2018
|
|
18
|
+
Copyright (c) 2018 Dr. Burkhard C. Heisen
|
|
19
19
|
<burkhard.heisen@heisenware.com>.
|
|
20
20
|
|
|
21
21
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
@@ -189,11 +189,19 @@ function parse_block (source, opts) {
|
|
|
189
189
|
/**
|
|
190
190
|
* Produces `extract` function with internal state initialized
|
|
191
191
|
*/
|
|
192
|
+
// A class declaration: `class Name`, also exported or assigned to module.exports
|
|
193
|
+
const CLASS_DECLARATION = /^(\s*)(?:export\s+(?:default\s+)?)?(?:module\.exports\s*=\s*)?class\s+([\w$]+)/
|
|
194
|
+
|
|
192
195
|
function mkextract (opts) {
|
|
193
196
|
let chunk = null
|
|
194
197
|
let indent = 0
|
|
195
198
|
let number = 0
|
|
196
199
|
let findMethod = false
|
|
200
|
+
// the class whose body the lines are in: its name and the indentation of
|
|
201
|
+
// its declaration; a function indented deeper belongs to it
|
|
202
|
+
let scope = null
|
|
203
|
+
// whether the lines are inside a /** ... */ block
|
|
204
|
+
let commentOpen = false
|
|
197
205
|
|
|
198
206
|
opts = Object.assign({}, {
|
|
199
207
|
trim: true,
|
|
@@ -217,6 +225,14 @@ function mkextract (opts) {
|
|
|
217
225
|
const startPos = line.indexOf(MARKER_START)
|
|
218
226
|
const endPos = line.indexOf(MARKER_END)
|
|
219
227
|
|
|
228
|
+
// in the code: where a class begins, and where its body ends
|
|
229
|
+
if (!commentOpen && startPos === -1) {
|
|
230
|
+
const declared = line.match(CLASS_DECLARATION)
|
|
231
|
+
const closing = scope && line.match(/^(\s*)\}/)
|
|
232
|
+
if (declared) scope = { name: declared[2], indent: declared[1].length }
|
|
233
|
+
else if (closing && closing[1].length === scope.indent) scope = null
|
|
234
|
+
}
|
|
235
|
+
|
|
220
236
|
// if open marker detected and it's not, skip one
|
|
221
237
|
if (startPos !== -1 && line.indexOf(MARKER_START_SKIP) !== startPos) {
|
|
222
238
|
// A block still waiting for its function is followed by another
|
|
@@ -247,6 +263,9 @@ function mkextract (opts) {
|
|
|
247
263
|
if (ret) {
|
|
248
264
|
result = parse_block(chunk, opts)
|
|
249
265
|
result.functionName = ret[1]
|
|
266
|
+
result.isStatic = /^\s*static\s/.test(line)
|
|
267
|
+
const depth = line.match(/^\s*/)[0].length
|
|
268
|
+
result.className = scope && depth > scope.indent ? scope.name : null
|
|
250
269
|
findMethod = false
|
|
251
270
|
}
|
|
252
271
|
}
|
|
@@ -292,6 +311,9 @@ function mkextract (opts) {
|
|
|
292
311
|
}
|
|
293
312
|
}
|
|
294
313
|
|
|
314
|
+
if (startPos !== -1) commentOpen = true
|
|
315
|
+
if (endPos !== -1) commentOpen = false
|
|
316
|
+
|
|
295
317
|
number += 1
|
|
296
318
|
return result
|
|
297
319
|
}
|
|
@@ -316,3 +338,4 @@ module.exports = function parse (source, opts) {
|
|
|
316
338
|
|
|
317
339
|
module.exports.PARSERS = PARSERS
|
|
318
340
|
module.exports.mkextract = mkextract
|
|
341
|
+
module.exports.CLASS_DECLARATION = CLASS_DECLARATION
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Name patterns and selections (docs/spec/protocol.md, section 11).
|
|
5
|
+
*
|
|
6
|
+
* In a pattern, `*` matches any run of characters, none included; every
|
|
7
|
+
* other character matches itself, case counts, and nothing else is special.
|
|
8
|
+
* A selection is a pattern or a non-empty list of them; it selects a name
|
|
9
|
+
* one of them matches.
|
|
10
|
+
*
|
|
11
|
+
* Matching takes time in proportion to the lengths of pattern and name,
|
|
12
|
+
* whatever they hold: no backtracking a name could make explode.
|
|
13
|
+
*
|
|
14
|
+
* @private
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Whether a pattern matches a name
|
|
19
|
+
*
|
|
20
|
+
* @param {String} pattern
|
|
21
|
+
* @param {String} name
|
|
22
|
+
* @returns {Boolean}
|
|
23
|
+
*/
|
|
24
|
+
function matches (pattern, name) {
|
|
25
|
+
let p = 0
|
|
26
|
+
let n = 0
|
|
27
|
+
// the last `*` seen, and the position in the name it stands at
|
|
28
|
+
let star = -1
|
|
29
|
+
let mark = 0
|
|
30
|
+
while (n < name.length) {
|
|
31
|
+
if (p < pattern.length && pattern[p] === '*') {
|
|
32
|
+
star = p++
|
|
33
|
+
mark = n
|
|
34
|
+
} else if (p < pattern.length && pattern[p] === name[n]) {
|
|
35
|
+
p++
|
|
36
|
+
n++
|
|
37
|
+
} else if (star !== -1) {
|
|
38
|
+
// the last `*` takes one more character
|
|
39
|
+
p = star + 1
|
|
40
|
+
n = ++mark
|
|
41
|
+
} else {
|
|
42
|
+
return false
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
while (p < pattern.length && pattern[p] === '*') p++
|
|
46
|
+
return p === pattern.length
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Whether a value is a selection: a non-empty string, or a non-empty list
|
|
51
|
+
* of them
|
|
52
|
+
*
|
|
53
|
+
* @param {Any} selection
|
|
54
|
+
* @returns {Boolean}
|
|
55
|
+
*/
|
|
56
|
+
function isSelection (selection) {
|
|
57
|
+
const isPattern = x => typeof x === 'string' && x.length > 0
|
|
58
|
+
return Array.isArray(selection)
|
|
59
|
+
? selection.length > 0 && selection.every(isPattern)
|
|
60
|
+
: isPattern(selection)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Whether a selection selects a name
|
|
65
|
+
*
|
|
66
|
+
* @param {String|Array.<String>} selection
|
|
67
|
+
* @param {String} name
|
|
68
|
+
* @returns {Boolean}
|
|
69
|
+
*/
|
|
70
|
+
function selects (selection, name) {
|
|
71
|
+
return Array.isArray(selection)
|
|
72
|
+
? selection.some(pattern => matches(pattern, name))
|
|
73
|
+
: matches(selection, name)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Whether a selection is everything: `*`, alone or in its list
|
|
78
|
+
*
|
|
79
|
+
* @param {String|Array.<String>} selection
|
|
80
|
+
* @returns {Boolean}
|
|
81
|
+
*/
|
|
82
|
+
function selectsAll (selection) {
|
|
83
|
+
return Array.isArray(selection) ? selection.includes('*') : selection === '*'
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
module.exports = { matches, isSelection, selects, selectsAll }
|
package/vrpc/vrpc-agent-js
CHANGED
|
@@ -3,17 +3,9 @@
|
|
|
3
3
|
'use strict'
|
|
4
4
|
|
|
5
5
|
const { ArgumentParser } = require('argparse')
|
|
6
|
-
const crypto = require('crypto')
|
|
7
|
-
const os = require('os')
|
|
8
6
|
const VrpcAgent = require('./VrpcAgent')
|
|
9
7
|
const path = require('path')
|
|
10
8
|
|
|
11
|
-
function generateAgentName () {
|
|
12
|
-
const { username } = os.userInfo()
|
|
13
|
-
const pathId = crypto.createHash('md5').update(path.resolve()).digest('hex').substr(0, 4)
|
|
14
|
-
return `${username}-${pathId}@${os.hostname()}-${os.platform()}-js`
|
|
15
|
-
}
|
|
16
|
-
|
|
17
9
|
const parser = new ArgumentParser({
|
|
18
10
|
add_help: true,
|
|
19
11
|
description: 'Starts a vrpc agent for node.js'
|
|
@@ -29,9 +21,9 @@ parser.add_argument(
|
|
|
29
21
|
parser.add_argument(
|
|
30
22
|
['-a', '--agent'],
|
|
31
23
|
{
|
|
32
|
-
help: 'Name of the agent for remote addressing',
|
|
24
|
+
help: 'Name of the agent for remote addressing (default: stable for this installation)',
|
|
33
25
|
type: 'string',
|
|
34
|
-
default:
|
|
26
|
+
default: VrpcAgent._generateAgentName()
|
|
35
27
|
}
|
|
36
28
|
)
|
|
37
29
|
parser.add_argument(
|
|
@@ -71,7 +63,7 @@ parser.add_argument(
|
|
|
71
63
|
{
|
|
72
64
|
help: 'Returns the VRPC version this client was built with.',
|
|
73
65
|
action: 'version',
|
|
74
|
-
version: '
|
|
66
|
+
version: `v${require('../package.json').version}`
|
|
75
67
|
}
|
|
76
68
|
)
|
|
77
69
|
|