nodo 1.6.5 → 1.7.1
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.
- checksums.yaml +4 -4
- data/lib/nodo/core.rb +42 -41
- data/lib/nodo/{nodo.js → nodo.cjs} +10 -10
- data/lib/nodo/version.rb +1 -1
- metadata +6 -62
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c0c3cef7af9cd8352a7470125eda15d01a56f795a5ce3fd2b1474b47f77f171
|
4
|
+
data.tar.gz: 759f66869c24cc8511fae1adf0a633fc73dd45d340ff9f16186570c5aefccbab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 010242af2332f9eb6ac1b136ae13ab570ae63212f61fb4b056a20407cc4209d52774dec9bcb87c44c9b9f87d13f3145bc468b0e96bd4b3fd7635815035381288
|
7
|
+
data.tar.gz: 0363c67c93b8015f45028625d3c3e76a5be084f087f5f34286a47fa9bbd5227d27267cbbbfaf133fe46bc325a4e46de4178946cdfe84c9d401950e30e2bc6897
|
data/lib/nodo/core.rb
CHANGED
@@ -9,48 +9,48 @@ module Nodo
|
|
9
9
|
ARRAY_CLASS_ATTRIBUTES = %i[dependencies constants scripts].freeze
|
10
10
|
HASH_CLASS_ATTRIBUTES = %i[functions].freeze
|
11
11
|
CLASS_ATTRIBUTES = (ARRAY_CLASS_ATTRIBUTES + HASH_CLASS_ATTRIBUTES).freeze
|
12
|
-
|
12
|
+
|
13
13
|
@@node_pid = nil
|
14
14
|
@@tmpdir = nil
|
15
15
|
@@mutex = Mutex.new
|
16
16
|
@@exiting = nil
|
17
|
-
|
17
|
+
|
18
18
|
class << self
|
19
19
|
extend Forwardable
|
20
|
-
|
20
|
+
|
21
21
|
attr_accessor :class_defined
|
22
|
-
|
22
|
+
|
23
23
|
def inherited(subclass)
|
24
24
|
CLASS_ATTRIBUTES.each do |attr|
|
25
25
|
subclass.send "#{attr}=", send(attr).dup
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def instance
|
30
30
|
@instance ||= new
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def class_defined?
|
34
34
|
!!class_defined
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def clsid
|
38
38
|
name || "Class:0x#{object_id.to_s(0x10)}"
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
CLASS_ATTRIBUTES.each do |attr|
|
42
42
|
define_method "#{attr}=" do |value|
|
43
43
|
instance_variable_set :"@#{attr}", value
|
44
44
|
end
|
45
45
|
protected "#{attr}="
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
ARRAY_CLASS_ATTRIBUTES.each do |attr|
|
49
49
|
define_method "#{attr}" do
|
50
50
|
instance_variable_get(:"@#{attr}") || instance_variable_set(:"@#{attr}", [])
|
51
51
|
end
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
HASH_CLASS_ATTRIBUTES.each do |attr|
|
55
55
|
define_method "#{attr}" do
|
56
56
|
instance_variable_get(:"@#{attr}") || instance_variable_set(:"@#{attr}", {})
|
@@ -60,15 +60,15 @@ module Nodo
|
|
60
60
|
def generate_core_code
|
61
61
|
<<~JS
|
62
62
|
global.nodo = require(#{nodo_js});
|
63
|
-
|
63
|
+
|
64
64
|
const socket = process.argv[1];
|
65
65
|
if (!socket) {
|
66
66
|
process.stderr.write('Socket path is required\\n');
|
67
67
|
process.exit(1);
|
68
68
|
}
|
69
|
-
|
69
|
+
|
70
70
|
process.title = `nodo-core ${socket}`;
|
71
|
-
|
71
|
+
|
72
72
|
const shutdown = () => {
|
73
73
|
nodo.core.close(() => { process.exit(0) });
|
74
74
|
};
|
@@ -92,19 +92,20 @@ module Nodo
|
|
92
92
|
})()
|
93
93
|
JS
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
protected
|
97
|
-
|
97
|
+
|
98
98
|
def finalize_context(context_id)
|
99
99
|
proc do
|
100
|
-
if not @@exiting and core =
|
100
|
+
if not @@exiting and core = @instance
|
101
|
+
puts "finalize_context #{context_id}"
|
101
102
|
core.send(:call_js_method, GC_METHOD, context_id)
|
102
103
|
end
|
103
104
|
end
|
104
105
|
end
|
105
|
-
|
106
|
+
|
106
107
|
private
|
107
|
-
|
108
|
+
|
108
109
|
def require(*mods)
|
109
110
|
deps = mods.last.is_a?(Hash) ? mods.pop : {}
|
110
111
|
mods = mods.map { |m| [m, m] }.to_h
|
@@ -118,7 +119,7 @@ module Nodo
|
|
118
119
|
self.functions = functions.merge(name => Function.new(name, _code || code, source_location, timeout, &block))
|
119
120
|
define_method(name) { |*args| call_js_method(name, args) }
|
120
121
|
end
|
121
|
-
|
122
|
+
|
122
123
|
def class_function(*methods)
|
123
124
|
singleton_class.def_delegators(:instance, *methods)
|
124
125
|
end
|
@@ -126,20 +127,20 @@ module Nodo
|
|
126
127
|
def const(name, value)
|
127
128
|
self.constants = constants + [Constant.new(name, value)]
|
128
129
|
end
|
129
|
-
|
130
|
+
|
130
131
|
def script(code = nil, &block)
|
131
132
|
self.scripts = scripts + [Script.new(code, &block)]
|
132
133
|
end
|
133
|
-
|
134
|
+
|
134
135
|
def nodo_js
|
135
|
-
Pathname.new(__FILE__).dirname.join('nodo.
|
136
|
+
Pathname.new(__FILE__).dirname.join('nodo.cjs').to_s.to_json
|
136
137
|
end
|
137
|
-
|
138
|
+
|
138
139
|
def reserved_method_name?(name)
|
139
140
|
Nodo::Core.method_defined?(name, false) || Nodo::Core.private_method_defined?(name, false) || name.to_s == DEFINE_METHOD
|
140
141
|
end
|
141
142
|
end
|
142
|
-
|
143
|
+
|
143
144
|
def initialize
|
144
145
|
raise ClassError, :new if self.class == Nodo::Core
|
145
146
|
@@mutex.synchronize do
|
@@ -148,18 +149,18 @@ module Nodo
|
|
148
149
|
ensure_class_is_defined
|
149
150
|
end
|
150
151
|
end
|
151
|
-
|
152
|
+
|
152
153
|
def evaluate(code)
|
153
154
|
ensure_context_is_defined
|
154
155
|
call_js_method(EVALUATE_METHOD, code)
|
155
156
|
end
|
156
|
-
|
157
|
+
|
157
158
|
private
|
158
|
-
|
159
|
+
|
159
160
|
def node_pid
|
160
161
|
@@node_pid
|
161
162
|
end
|
162
|
-
|
163
|
+
|
163
164
|
def tmpdir
|
164
165
|
@@tmpdir
|
165
166
|
end
|
@@ -167,33 +168,33 @@ module Nodo
|
|
167
168
|
def socket_path
|
168
169
|
tmpdir && tmpdir.join(SOCKET_NAME)
|
169
170
|
end
|
170
|
-
|
171
|
+
|
171
172
|
def clsid
|
172
173
|
self.class.clsid
|
173
174
|
end
|
174
|
-
|
175
|
+
|
175
176
|
def context_defined?
|
176
177
|
@context_defined
|
177
178
|
end
|
178
|
-
|
179
|
+
|
179
180
|
def log_exception(e)
|
180
181
|
return unless logger = Nodo.logger
|
181
182
|
message = "\n#{e.class} (#{e.message})"
|
182
183
|
message << ":\n\n#{e.backtrace.join("\n")}" if e.backtrace
|
183
184
|
logger.error message
|
184
185
|
end
|
185
|
-
|
186
|
+
|
186
187
|
def ensure_process_is_spawned
|
187
188
|
return if node_pid
|
188
189
|
spawn_process
|
189
190
|
end
|
190
|
-
|
191
|
+
|
191
192
|
def ensure_class_is_defined
|
192
193
|
return if self.class.class_defined?
|
193
194
|
call_js_method(DEFINE_METHOD, self.class.generate_class_code)
|
194
195
|
self.class.class_defined = true
|
195
196
|
end
|
196
|
-
|
197
|
+
|
197
198
|
def ensure_context_is_defined
|
198
199
|
return if context_defined?
|
199
200
|
@@mutex.synchronize do
|
@@ -202,7 +203,7 @@ module Nodo
|
|
202
203
|
@context_defined = true
|
203
204
|
end
|
204
205
|
end
|
205
|
-
|
206
|
+
|
206
207
|
def spawn_process
|
207
208
|
@@tmpdir = Pathname.new(Dir.mktmpdir('nodo'))
|
208
209
|
env = Nodo.env.merge('NODE_PATH' => Nodo.modules_root.to_s)
|
@@ -215,7 +216,7 @@ module Nodo
|
|
215
216
|
FileUtils.remove_entry(tmpdir) if File.directory?(tmpdir)
|
216
217
|
end
|
217
218
|
end
|
218
|
-
|
219
|
+
|
219
220
|
def wait_for_socket
|
220
221
|
start = Time.now
|
221
222
|
socket = nil
|
@@ -237,7 +238,7 @@ module Nodo
|
|
237
238
|
raise NameError, "undefined function `#{method}' for #{self.class}" unless function || INTERNAL_METHODS.include?(method)
|
238
239
|
context_id = case method
|
239
240
|
when DEFINE_METHOD then 0
|
240
|
-
when GC_METHOD then args
|
241
|
+
when GC_METHOD then args
|
241
242
|
else
|
242
243
|
object_id
|
243
244
|
end
|
@@ -257,7 +258,7 @@ module Nodo
|
|
257
258
|
# TODO: restart or something? If this happens the process is completely broken
|
258
259
|
raise Error, 'Node process failed'
|
259
260
|
end
|
260
|
-
|
261
|
+
|
261
262
|
def handle_error(response, function)
|
262
263
|
if response.body
|
263
264
|
result = parse_response(response)
|
@@ -270,12 +271,12 @@ module Nodo
|
|
270
271
|
log_exception(error)
|
271
272
|
raise error
|
272
273
|
end
|
273
|
-
|
274
|
+
|
274
275
|
def parse_response(response)
|
275
276
|
data = response.body.force_encoding('UTF-8')
|
276
277
|
JSON.parse(data) unless data == ''
|
277
278
|
end
|
278
|
-
|
279
|
+
|
279
280
|
def with_tempfile(name)
|
280
281
|
ext = File.extname(name)
|
281
282
|
result = nil
|
@@ -284,6 +285,6 @@ module Nodo
|
|
284
285
|
end
|
285
286
|
result
|
286
287
|
end
|
287
|
-
|
288
|
+
|
288
289
|
end
|
289
290
|
end
|
@@ -13,7 +13,7 @@ module.exports = (function() {
|
|
13
13
|
let server, closing;
|
14
14
|
const classes = {};
|
15
15
|
const contexts = {};
|
16
|
-
|
16
|
+
|
17
17
|
function render_error(e) {
|
18
18
|
let errInfo = {};
|
19
19
|
if (e instanceof Error) {
|
@@ -31,7 +31,7 @@ module.exports = (function() {
|
|
31
31
|
debug(`Error ${code} ${rendered}`);
|
32
32
|
res.end(rendered, 'utf8');
|
33
33
|
}
|
34
|
-
|
34
|
+
|
35
35
|
function respond_with_data(res, data, start) {
|
36
36
|
let timing;
|
37
37
|
res.statusCode = 200;
|
@@ -58,18 +58,18 @@ module.exports = (function() {
|
|
58
58
|
debug('Starting up...');
|
59
59
|
server = http.createServer((req, res) => {
|
60
60
|
const start = performance.now();
|
61
|
-
|
61
|
+
|
62
62
|
res.setHeader('Content-Type', 'application/json');
|
63
63
|
debug(`${req.method} ${req.url}`);
|
64
64
|
|
65
65
|
if (req.method !== 'POST' || !req.url.startsWith('/')) {
|
66
66
|
return respond_with_error(res, 405, 'Method Not Allowed');
|
67
67
|
}
|
68
|
-
|
68
|
+
|
69
69
|
const url = req.url.substring(1);
|
70
70
|
const [class_name, object_id, method] = url.split('/');
|
71
71
|
let klass, context;
|
72
|
-
|
72
|
+
|
73
73
|
if (classes.hasOwnProperty(class_name)) {
|
74
74
|
klass = classes[class_name];
|
75
75
|
if (EVALUATE_METHOD == method) {
|
@@ -83,9 +83,9 @@ module.exports = (function() {
|
|
83
83
|
} else if (DEFINE_METHOD != method) {
|
84
84
|
return respond_with_error(res, 404, `Class ${class_name} not defined`);
|
85
85
|
}
|
86
|
-
|
86
|
+
|
87
87
|
let body = '';
|
88
|
-
|
88
|
+
|
89
89
|
req.on('data', (data) => { body += data; });
|
90
90
|
|
91
91
|
req.on('end', () => {
|
@@ -120,7 +120,7 @@ module.exports = (function() {
|
|
120
120
|
} catch(error) {
|
121
121
|
return respond_with_error(res, 500, error);
|
122
122
|
}
|
123
|
-
|
123
|
+
|
124
124
|
});
|
125
125
|
});
|
126
126
|
|
@@ -129,7 +129,7 @@ module.exports = (function() {
|
|
129
129
|
debug(`server ready, listening on ${socket} (max connections: ${server.maxConnections})`);
|
130
130
|
});
|
131
131
|
},
|
132
|
-
|
132
|
+
|
133
133
|
close: (finalizer) => {
|
134
134
|
debug("Shutting down");
|
135
135
|
if (!closing) {
|
@@ -138,6 +138,6 @@ module.exports = (function() {
|
|
138
138
|
}
|
139
139
|
}
|
140
140
|
};
|
141
|
-
|
141
|
+
|
142
142
|
return { core: core, debug: debug, import: import_module };
|
143
143
|
})();
|
data/lib/nodo/version.rb
CHANGED
metadata
CHANGED
@@ -1,71 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nodo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthias Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
requirement: !ruby/object:Gem::Requirement
|
15
|
-
requirements:
|
16
|
-
- - ">="
|
17
|
-
- !ruby/object:Gem::Version
|
18
|
-
version: '0'
|
19
|
-
name: bundler
|
20
|
-
prerelease: false
|
21
|
-
type: :development
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
requirement: !ruby/object:Gem::Requirement
|
29
|
-
requirements:
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '0'
|
33
|
-
name: rake
|
34
|
-
prerelease: false
|
35
|
-
type: :development
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
requirement: !ruby/object:Gem::Requirement
|
43
|
-
requirements:
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '0'
|
47
|
-
name: byebug
|
48
|
-
prerelease: false
|
49
|
-
type: :development
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
requirement: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '0'
|
61
|
-
name: minitest
|
62
|
-
prerelease: false
|
63
|
-
type: :development
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
11
|
+
date: 2024-10-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
69
13
|
description: Fast Ruby bridge to run JavaScript inside a Node process
|
70
14
|
email:
|
71
15
|
- mtgrosser@gmx.net
|
@@ -82,7 +26,7 @@ files:
|
|
82
26
|
- lib/nodo/dependency.rb
|
83
27
|
- lib/nodo/errors.rb
|
84
28
|
- lib/nodo/function.rb
|
85
|
-
- lib/nodo/nodo.
|
29
|
+
- lib/nodo/nodo.cjs
|
86
30
|
- lib/nodo/railtie.rb
|
87
31
|
- lib/nodo/script.rb
|
88
32
|
- lib/nodo/version.rb
|
@@ -98,14 +42,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
42
|
requirements:
|
99
43
|
- - ">="
|
100
44
|
- !ruby/object:Gem::Version
|
101
|
-
version: 2.
|
45
|
+
version: 2.7.0
|
102
46
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
47
|
requirements:
|
104
48
|
- - ">="
|
105
49
|
- !ruby/object:Gem::Version
|
106
50
|
version: '0'
|
107
51
|
requirements: []
|
108
|
-
rubygems_version: 3.
|
52
|
+
rubygems_version: 3.5.11
|
109
53
|
signing_key:
|
110
54
|
specification_version: 4
|
111
55
|
summary: Call Node.js from Ruby
|