@naanlang/naan 1.5.0 → 1.7.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.md +2 -2
- package/README.md +2 -2
- package/bin/index.js +7 -3
- package/dist/env_web.js +162 -48
- package/dist/naan.min.js +11 -11
- package/frameworks/browser/https_request.nlg +2 -2
- package/frameworks/browser/sworker.js +28 -26
- package/frameworks/browser/terminals.nlg +295 -737
- package/frameworks/browser/worker.nlg +295 -0
- package/frameworks/browser/workers.nlg +6 -6
- package/frameworks/browser/ws_client.nlg +15 -10
- package/frameworks/client/apiclient.nlg +211 -9
- package/frameworks/client/psm_client.nlg +10 -14
- package/frameworks/client/relaycon.nlg +87 -161
- package/frameworks/common/common.nlg +2 -0
- package/frameworks/common/events.nlg +101 -0
- package/frameworks/common/repltools.nlg +80 -1
- package/frameworks/node/apiserver.nlg +38 -246
- package/frameworks/node/filesystem.nlg +31 -6
- package/frameworks/node/http_request.nlg +34 -13
- package/frameworks/node/https_request.nlg +8 -3
- package/frameworks/node/node.nlg +3 -0
- package/frameworks/node/pty.nlg +346 -0
- package/frameworks/node/shell.nlg +26 -3
- package/frameworks/node/worker.nlg +504 -560
- package/frameworks/node/ws_client.nlg +2 -2
- package/frameworks/project/build.nlg +56 -14
- package/frameworks/project/projects.nlg +1 -1
- package/frameworks/running/debugcom.nlg +20 -3
- package/frameworks/running/debugnub.nlg +33 -11
- package/frameworks/running/executors.nlg +40 -285
- package/frameworks/running/instances.nlg +394 -0
- package/frameworks/running/remote_req.nlg +139 -0
- package/frameworks/running/remote_res.nlg +89 -0
- package/frameworks/running/sourcecode.nlg +3 -2
- package/frameworks/running/taskexec.nlg +16 -59
- package/frameworks/service/imp.nlg +751 -0
- package/frameworks/service/model.nlg +71 -0
- package/frameworks/service/nubnode.nlg +136 -0
- package/frameworks/service/nubweb.nlg +124 -0
- package/frameworks/service/service.nlg +28 -0
- package/frameworks/storage/file_manager.nlg +3 -2
- package/lib/browser/env_web.js +169 -55
- package/lib/browser/env_webworker.js +89 -31
- package/lib/core/naanlib.js +11 -11
- package/lib/env_node.js +186 -27
- package/lib/env_nodeworker.js +82 -44
- package/lib/node_server_init.nlg +149 -0
- package/lib/node_worker.js +36 -0
- package/lib/node_worker_init.nlg +43 -0
- package/package.json +1 -1
- package/plugins/openSearch/openSearch.nlg +3 -2
- package/plugins/openSearch/os_dynamo.nlg +3 -2
- package/plugins/serviceAws/aws_cloudwatchlogs.nlg +44 -2
- package/plugins/serviceAws/aws_dynamo.nlg +144 -63
- package/plugins/serviceAws/aws_utils.nlg +6 -11
- package/plugins/serviceAws/serviceAws.nlg +3 -2
- package/plugins/serviceNexara/speechrec.nlg +10 -6
- package/test/test_01_core.nlg +2 -2
- package/test/test_02_context.nlg +32 -9
- package/test/test_03_jsinterop.nlg +3 -3
- package/test/test_07_lingo.nlg +1 -1
package/lib/env_node.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* column positioning: // // !
|
|
8
8
|
*
|
|
9
|
-
* Copyright (c) 2017-
|
|
9
|
+
* Copyright (c) 2017-2026 by Richard C. Zulch
|
|
10
10
|
*
|
|
11
11
|
*/
|
|
12
12
|
|
|
@@ -49,6 +49,7 @@ exports.NaanNodeREPL = function NaanNodeREPL(options) {
|
|
|
49
49
|
if (typeof(options) != 'object')
|
|
50
50
|
options = { };
|
|
51
51
|
var repl = require('repl');
|
|
52
|
+
const { Transform } = require('node:stream');
|
|
52
53
|
var replServer;
|
|
53
54
|
var process = require('process');
|
|
54
55
|
var Naan = require('./core/naanlib');
|
|
@@ -62,8 +63,16 @@ exports.NaanNodeREPL = function NaanNodeREPL(options) {
|
|
|
62
63
|
if (outEnable && process.env["RUNKIT_ENDPOINT_URL"])
|
|
63
64
|
useConsoleOut = true; // use console.log for output in RunKit
|
|
64
65
|
var dontSaveUntilWorking; // true when state loaded, must be reset to save state again
|
|
66
|
+
var dontSave; // true to avoid saving, i.e. in debugger
|
|
65
67
|
var prefs = { };
|
|
66
68
|
|
|
69
|
+
// kpMode
|
|
70
|
+
// 0: normal (readline & echo)
|
|
71
|
+
// 1: readline, but echo CR only
|
|
72
|
+
// 2: readline, but don't echo
|
|
73
|
+
// 3: raw, no echo or readline, but key-events
|
|
74
|
+
var kpMode = 0;
|
|
75
|
+
|
|
67
76
|
//==========================================================================
|
|
68
77
|
// API
|
|
69
78
|
//--------------------------------------------------------------------------
|
|
@@ -112,7 +121,27 @@ exports.NaanNodeREPL = function NaanNodeREPL(options) {
|
|
|
112
121
|
|
|
113
122
|
if (process.stdin.isTTY)
|
|
114
123
|
{ // must have TTY for local REPL
|
|
115
|
-
|
|
124
|
+
const replOutputStream = new Transform({
|
|
125
|
+
writableObjectMode: true,
|
|
126
|
+
readableObjectMode: true,
|
|
127
|
+
transform(chunk, encoding, callback) {
|
|
128
|
+
if (kpMode > 0) {
|
|
129
|
+
const str = chunk.toString();
|
|
130
|
+
if (kpMode != 1 || str != "\r\n")
|
|
131
|
+
return callback(); // output goes to the bit bucket
|
|
132
|
+
}
|
|
133
|
+
return callback(null, chunk); // normal output
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
replOutputStream.pipe(process.stdout); // output filter for raw and no-echo
|
|
137
|
+
|
|
138
|
+
replServer = repl.start({
|
|
139
|
+
prompt: '',
|
|
140
|
+
eval: myEval,
|
|
141
|
+
input: process.stdin,
|
|
142
|
+
output: replOutputStream,
|
|
143
|
+
terminal: true
|
|
144
|
+
});
|
|
116
145
|
|
|
117
146
|
replServer.on('line', function(cmd) { // process raw command line
|
|
118
147
|
if (options.replDisable)
|
|
@@ -122,7 +151,21 @@ exports.NaanNodeREPL = function NaanNodeREPL(options) {
|
|
|
122
151
|
naanlib.textLine(cmd + "\n");
|
|
123
152
|
}
|
|
124
153
|
});
|
|
125
|
-
|
|
154
|
+
|
|
155
|
+
const origListenersData = process.stdin.listeners('data');
|
|
156
|
+
process.stdin.removeAllListeners('data');
|
|
157
|
+
|
|
158
|
+
process.stdin.on('data', (data) => {
|
|
159
|
+
if (kpMode == 3) {
|
|
160
|
+
servSelf.ioctl_event("raw-key", { // raw mode
|
|
161
|
+
key: data.toString(),
|
|
162
|
+
origin: 0 // assume keystroke
|
|
163
|
+
});
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
origListenersData.forEach(listener => listener(data));
|
|
167
|
+
});
|
|
168
|
+
|
|
126
169
|
//
|
|
127
170
|
// Hook the ^C interrupt
|
|
128
171
|
//
|
|
@@ -131,8 +174,10 @@ exports.NaanNodeREPL = function NaanNodeREPL(options) {
|
|
|
131
174
|
if (options.replDisable) {
|
|
132
175
|
console.log("^C");
|
|
133
176
|
process.exit();
|
|
134
|
-
} else
|
|
177
|
+
} else {
|
|
178
|
+
setKpMode(0);
|
|
135
179
|
naanlib.escape();
|
|
180
|
+
}
|
|
136
181
|
};
|
|
137
182
|
|
|
138
183
|
//
|
|
@@ -142,6 +187,17 @@ exports.NaanNodeREPL = function NaanNodeREPL(options) {
|
|
|
142
187
|
replServer.on('exit', function() {
|
|
143
188
|
process.exit();
|
|
144
189
|
});
|
|
190
|
+
|
|
191
|
+
//
|
|
192
|
+
// Process resize notifications
|
|
193
|
+
//
|
|
194
|
+
|
|
195
|
+
process.stdout.on('resize', () => {
|
|
196
|
+
servSelf.ioctl_event("term-resize", {
|
|
197
|
+
cols: process.stdout.columns,
|
|
198
|
+
rows: process.stdout.rows
|
|
199
|
+
});
|
|
200
|
+
});
|
|
145
201
|
}
|
|
146
202
|
|
|
147
203
|
//
|
|
@@ -177,6 +233,43 @@ exports.NaanNodeREPL = function NaanNodeREPL(options) {
|
|
|
177
233
|
textToRemoteTerm(text);
|
|
178
234
|
}
|
|
179
235
|
});
|
|
236
|
+
|
|
237
|
+
//
|
|
238
|
+
// setKpMode
|
|
239
|
+
//
|
|
240
|
+
|
|
241
|
+
function setKpMode(mode) {
|
|
242
|
+
if (!replServer)
|
|
243
|
+
return;
|
|
244
|
+
kpMode = mode;
|
|
245
|
+
process.stdin.resume();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
//
|
|
249
|
+
// repl_keystroke
|
|
250
|
+
//
|
|
251
|
+
|
|
252
|
+
function repl_keystroke(str) {
|
|
253
|
+
if (replServer)
|
|
254
|
+
replServer.write(str, null);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
//
|
|
258
|
+
// repl_ioctl
|
|
259
|
+
//
|
|
260
|
+
|
|
261
|
+
this.repl_ioctl = function repl_ioctl(op, arg) {
|
|
262
|
+
if (op == "sane")
|
|
263
|
+
setKpMode(0);
|
|
264
|
+
else if (op == "raw")
|
|
265
|
+
setKpMode(arg ? 3 : 0);
|
|
266
|
+
else if (op == "keystroke")
|
|
267
|
+
repl_keystroke(arg);
|
|
268
|
+
else if (op == "echo") {
|
|
269
|
+
if (arg >= 0 && arg <= 2)
|
|
270
|
+
setKpMode(arg);
|
|
271
|
+
}
|
|
272
|
+
};
|
|
180
273
|
|
|
181
274
|
|
|
182
275
|
//==========================================================================
|
|
@@ -196,7 +289,7 @@ exports.NaanNodeREPL = function NaanNodeREPL(options) {
|
|
|
196
289
|
//
|
|
197
290
|
// Detach
|
|
198
291
|
//
|
|
199
|
-
// Detach the terminal from
|
|
292
|
+
// Detach the terminal from our interpreter.
|
|
200
293
|
//
|
|
201
294
|
|
|
202
295
|
this.Detach = function(tops) {
|
|
@@ -211,26 +304,6 @@ exports.NaanNodeREPL = function NaanNodeREPL(options) {
|
|
|
211
304
|
// messages are originating from the interpreter itself, so that it does not call itself back
|
|
212
305
|
// recursively. That would be Very Bad™.
|
|
213
306
|
//
|
|
214
|
-
|
|
215
|
-
var replyHook;
|
|
216
|
-
this.OnReplyHook = function OnReplyHook(proc) {
|
|
217
|
-
replyHook = proc;
|
|
218
|
-
return (proc);
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
this.ReplyMessage = function ReplyMessage(data) {
|
|
222
|
-
if (replyHook)
|
|
223
|
-
setTimeout(function() {
|
|
224
|
-
replyHook(data);
|
|
225
|
-
}, 1);
|
|
226
|
-
if (termops)
|
|
227
|
-
{
|
|
228
|
-
setTimeout(function () {
|
|
229
|
-
termops.messageout(data);
|
|
230
|
-
}, 1);
|
|
231
|
-
}
|
|
232
|
-
return (data);
|
|
233
|
-
};
|
|
234
307
|
|
|
235
308
|
var nodeListener;
|
|
236
309
|
this.OnMessage = function OnMessage(proc) {
|
|
@@ -242,7 +315,8 @@ exports.NaanNodeREPL = function NaanNodeREPL(options) {
|
|
|
242
315
|
if (termops)
|
|
243
316
|
{
|
|
244
317
|
setTimeout(function () {
|
|
245
|
-
termops
|
|
318
|
+
if (termops)
|
|
319
|
+
termops.debugout(data);
|
|
246
320
|
}, 1);
|
|
247
321
|
}
|
|
248
322
|
return (data);
|
|
@@ -277,6 +351,10 @@ exports.NaanNodeREPL = function NaanNodeREPL(options) {
|
|
|
277
351
|
naanlib.textLine(msg.text); // keyboard text from terminal
|
|
278
352
|
}, 1);
|
|
279
353
|
}
|
|
354
|
+
else if (msg.id == "typed")
|
|
355
|
+
{
|
|
356
|
+
echoTyped(msg.text);
|
|
357
|
+
}
|
|
280
358
|
else if (msg.id == "targetin")
|
|
281
359
|
{
|
|
282
360
|
setTimeout(function () {
|
|
@@ -291,6 +369,12 @@ exports.NaanNodeREPL = function NaanNodeREPL(options) {
|
|
|
291
369
|
debugListener(msg.data); // received a debugger message
|
|
292
370
|
}, 1);
|
|
293
371
|
}
|
|
372
|
+
else if (msg.id == "attached")
|
|
373
|
+
servSelf.ioctl_event("term-attach", msg.guid);
|
|
374
|
+
else if (msg.id == "detached")
|
|
375
|
+
servSelf.ioctl_event("term-detach", msg.guid);
|
|
376
|
+
else if (msg.id == "ioctl-event")
|
|
377
|
+
servSelf.ioctl_event(msg.msg, msg.arg);
|
|
294
378
|
};
|
|
295
379
|
|
|
296
380
|
// textToRemoteTerm
|
|
@@ -301,7 +385,8 @@ exports.NaanNodeREPL = function NaanNodeREPL(options) {
|
|
|
301
385
|
if (termops)
|
|
302
386
|
{
|
|
303
387
|
setTimeout(function () {
|
|
304
|
-
termops
|
|
388
|
+
if (termops)
|
|
389
|
+
termops.textout(text);
|
|
305
390
|
}, 1);
|
|
306
391
|
}
|
|
307
392
|
}
|
|
@@ -323,6 +408,68 @@ exports.NaanNodeREPL = function NaanNodeREPL(options) {
|
|
|
323
408
|
}
|
|
324
409
|
}, 1000);
|
|
325
410
|
|
|
411
|
+
//==========================================================================
|
|
412
|
+
// ioctl terminal control
|
|
413
|
+
//--------------------------------------------------------------------------
|
|
414
|
+
|
|
415
|
+
//
|
|
416
|
+
// ioctl_event
|
|
417
|
+
//
|
|
418
|
+
// Events incoming from terminal.
|
|
419
|
+
//
|
|
420
|
+
|
|
421
|
+
this.ioctl_event = function ioctl_event(msg, arg) {
|
|
422
|
+
if (listeners[msg])
|
|
423
|
+
listeners[msg].forEach(function(proc) {
|
|
424
|
+
setTimeout(function () {
|
|
425
|
+
proc(msg, arg);
|
|
426
|
+
}, 1);
|
|
427
|
+
});
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
//
|
|
431
|
+
// ioctl_add_listener
|
|
432
|
+
// ioctl_remove_listener
|
|
433
|
+
//
|
|
434
|
+
// Add a listener for a terminal event.
|
|
435
|
+
//
|
|
436
|
+
|
|
437
|
+
var listeners = { };
|
|
438
|
+
|
|
439
|
+
this.ioctl_add_listener = function ioctl_add_listener(msg, proc) {
|
|
440
|
+
if (typeof(msg) != "string" || typeof(proc) != "function")
|
|
441
|
+
return (false);
|
|
442
|
+
this.ioctl_remove_listener(msg, proc);
|
|
443
|
+
if (!listeners[msg])
|
|
444
|
+
listeners[msg] = [];
|
|
445
|
+
listeners[msg].push(proc);
|
|
446
|
+
return (true);
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
this.ioctl_remove_listener = function ioctl_remove_listener(msg, proc) {
|
|
450
|
+
if (typeof(msg) != "string" || typeof(proc) != "function")
|
|
451
|
+
return (false);
|
|
452
|
+
if (listeners[msg]) {
|
|
453
|
+
var index = listeners[msg].indexOf(proc);
|
|
454
|
+
if (index >= 0)
|
|
455
|
+
listeners[msg].splice(index, 1);
|
|
456
|
+
}
|
|
457
|
+
return (true);
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
//
|
|
461
|
+
// ioctl
|
|
462
|
+
//
|
|
463
|
+
// Control of terminals (and their controller.)
|
|
464
|
+
//
|
|
465
|
+
|
|
466
|
+
this.ioctl = function ioctl(op, arg) {
|
|
467
|
+
setTimeout(function () {
|
|
468
|
+
servSelf.repl_ioctl(op, arg);
|
|
469
|
+
if (termops)
|
|
470
|
+
termops.ioctl(op, arg);
|
|
471
|
+
}, 1);
|
|
472
|
+
};
|
|
326
473
|
|
|
327
474
|
//==========================================================================
|
|
328
475
|
// State load/save
|
|
@@ -352,6 +499,16 @@ exports.NaanNodeREPL = function NaanNodeREPL(options) {
|
|
|
352
499
|
dontSaveUntilWorking = false;
|
|
353
500
|
};
|
|
354
501
|
|
|
502
|
+
//
|
|
503
|
+
// Saving
|
|
504
|
+
//
|
|
505
|
+
// Turn state saving on or off; on by default.
|
|
506
|
+
//
|
|
507
|
+
|
|
508
|
+
this.Saving = function Saving(onOff) {
|
|
509
|
+
dontSave = !onOff;
|
|
510
|
+
};
|
|
511
|
+
|
|
355
512
|
// MakeState
|
|
356
513
|
//
|
|
357
514
|
// Save our state into a new object.
|
|
@@ -359,6 +516,8 @@ exports.NaanNodeREPL = function NaanNodeREPL(options) {
|
|
|
359
516
|
this.MakeState = function MakeState() {
|
|
360
517
|
if (dontSaveUntilWorking)
|
|
361
518
|
return (false); // didn't get far enough to call Working()
|
|
519
|
+
if (dontSave)
|
|
520
|
+
return (false); // not saving right now
|
|
362
521
|
var statedoc = {};
|
|
363
522
|
statedoc.curversion = kStateCurrentVersion;
|
|
364
523
|
statedoc.firstver = kStateFirstVersion;
|
package/lib/env_nodeworker.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* column positioning: // // !
|
|
8
8
|
*
|
|
9
|
-
* Copyright (c) 2019-
|
|
9
|
+
* Copyright (c) 2019-2026 by Richard C. Zulch
|
|
10
10
|
*
|
|
11
11
|
*/
|
|
12
12
|
|
|
@@ -63,6 +63,7 @@ exports.NaanWorkerActivate = function NaanWorkerActivate(cbReady) {
|
|
|
63
63
|
workSelf.anaan = naanlib.js.n;
|
|
64
64
|
naanlib.js.t = workSelf;
|
|
65
65
|
naanlib.js.k = threads;
|
|
66
|
+
var workerMetadata = { };
|
|
66
67
|
|
|
67
68
|
|
|
68
69
|
//==========================================================================
|
|
@@ -84,12 +85,79 @@ exports.NaanWorkerActivate = function NaanWorkerActivate(cbReady) {
|
|
|
84
85
|
this.textCommand = function textCommand(cmd) { // send a command
|
|
85
86
|
naanlib.textLine(cmd);
|
|
86
87
|
};
|
|
88
|
+
|
|
89
|
+
this.metadata = function metadata() { // our creation metadata
|
|
90
|
+
return (workerMetadata);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
this.msgPort = msgPort; // our msgPort
|
|
94
|
+
|
|
95
|
+
//==========================================================================
|
|
96
|
+
// ioctl terminal control
|
|
97
|
+
//--------------------------------------------------------------------------
|
|
98
|
+
|
|
99
|
+
//
|
|
100
|
+
// ioctl_event
|
|
101
|
+
//
|
|
102
|
+
// Events incoming from terminal.
|
|
103
|
+
//
|
|
104
|
+
|
|
105
|
+
workSelf.ioctl_event = function ioctl_event(msg, arg) {
|
|
106
|
+
if (listeners[msg])
|
|
107
|
+
listeners[msg].forEach(function(proc) {
|
|
108
|
+
proc(msg, arg);
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
//
|
|
113
|
+
// ioctl_add_listener
|
|
114
|
+
// ioctl_remove_listener
|
|
115
|
+
//
|
|
116
|
+
// Add a listener for a terminal event.
|
|
117
|
+
//
|
|
118
|
+
|
|
119
|
+
var listeners = { };
|
|
120
|
+
|
|
121
|
+
workSelf.ioctl_add_listener = function ioctl_add_listener(msg, proc) {
|
|
122
|
+
if (typeof(msg) != "string" || typeof(proc) != "function")
|
|
123
|
+
return (false);
|
|
124
|
+
workSelf.ioctl_remove_listener(msg, proc);
|
|
125
|
+
if (!listeners[msg])
|
|
126
|
+
listeners[msg] = [];
|
|
127
|
+
listeners[msg].push(proc);
|
|
128
|
+
return (true);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
workSelf.ioctl_remove_listener = function ioctl_remove_listener(msg, proc) {
|
|
132
|
+
if (typeof(msg) != "string" || typeof(proc) != "function")
|
|
133
|
+
return (false);
|
|
134
|
+
if (listeners[msg]) {
|
|
135
|
+
var index = listeners[msg].indexOf(proc);
|
|
136
|
+
if (index >= 0)
|
|
137
|
+
listeners[msg].splice(index, 1);
|
|
138
|
+
}
|
|
139
|
+
return (true);
|
|
140
|
+
};
|
|
87
141
|
|
|
142
|
+
//
|
|
143
|
+
// ioctl
|
|
144
|
+
//
|
|
145
|
+
// Control of terminals (and their controller.)
|
|
146
|
+
//
|
|
147
|
+
|
|
148
|
+
workSelf.ioctl = function ioctl(op, arg) {
|
|
149
|
+
msgPort.postMessage({
|
|
150
|
+
id: "ioctl",
|
|
151
|
+
op: op,
|
|
152
|
+
arg: arg
|
|
153
|
+
});
|
|
154
|
+
return (undefined);
|
|
155
|
+
};
|
|
88
156
|
|
|
89
157
|
//==========================================================================
|
|
90
158
|
// NodeJS Worker Terminal Interface
|
|
91
159
|
//--------------------------------------------------------------------------
|
|
92
|
-
|
|
160
|
+
|
|
93
161
|
naanlib.onText(function(text, level) {
|
|
94
162
|
if (level)
|
|
95
163
|
msgPort.postMessage({
|
|
@@ -103,7 +171,7 @@ exports.NaanWorkerActivate = function NaanWorkerActivate(cbReady) {
|
|
|
103
171
|
text: text
|
|
104
172
|
});
|
|
105
173
|
});
|
|
106
|
-
|
|
174
|
+
|
|
107
175
|
setInterval(function() {
|
|
108
176
|
var samples = naanlib.status(1);
|
|
109
177
|
if (samples.length > 0)
|
|
@@ -114,34 +182,6 @@ exports.NaanWorkerActivate = function NaanWorkerActivate(cbReady) {
|
|
|
114
182
|
}
|
|
115
183
|
});
|
|
116
184
|
}, 1000);
|
|
117
|
-
|
|
118
|
-
workSelf.ReplyMessage = function ReplyMessage(data) {
|
|
119
|
-
msgPort.postMessage({ // worker is sending a message
|
|
120
|
-
id: "targetout",
|
|
121
|
-
data: data
|
|
122
|
-
});
|
|
123
|
-
return (data);
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
var workerListener;
|
|
127
|
-
workSelf.OnMessage = function OnMessage(proc) {
|
|
128
|
-
workerListener = proc;
|
|
129
|
-
return (proc);
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
workSelf.DispatchMessage = function DispatchMessage(data) {
|
|
133
|
-
msgPort.postMessage({ // target is sending a message
|
|
134
|
-
id: "targetsend",
|
|
135
|
-
data: data
|
|
136
|
-
});
|
|
137
|
-
return (data);
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
var targetReceiver;
|
|
141
|
-
workSelf.OnReceive = function OnReceive(proc) {
|
|
142
|
-
targetReceiver = proc;
|
|
143
|
-
return (proc);
|
|
144
|
-
};
|
|
145
185
|
|
|
146
186
|
workSelf.ReplyDebugger = function ReplyDebugger(data) {
|
|
147
187
|
msgPort.postMessage({ // target is sending debug data
|
|
@@ -150,22 +190,24 @@ exports.NaanWorkerActivate = function NaanWorkerActivate(cbReady) {
|
|
|
150
190
|
});
|
|
151
191
|
return (data);
|
|
152
192
|
};
|
|
153
|
-
|
|
193
|
+
|
|
154
194
|
var debugListener;
|
|
155
195
|
workSelf.OnDebugger = function OnDebugger(proc) {
|
|
156
196
|
debugListener = proc;
|
|
157
197
|
return (proc);
|
|
158
198
|
};
|
|
159
|
-
|
|
199
|
+
|
|
160
200
|
msgPort.on("message", function(msg) {
|
|
161
201
|
if (msg.id == "interrupt")
|
|
162
202
|
naanlib.escape(); // interrupt request from terminal
|
|
163
203
|
else if (msg.id == "keyline")
|
|
164
204
|
naanlib.textLine(msg.text); // keyboard text from terminal
|
|
205
|
+
else if (msg.id == "typed")
|
|
206
|
+
echoTyped(msg.text);
|
|
165
207
|
else if (msg.id == "start")
|
|
166
208
|
{ // start execution with optional state
|
|
167
209
|
workSelf.workerID = msg.workerID;
|
|
168
|
-
|
|
210
|
+
workerMetadata = msg.metadata || { };
|
|
169
211
|
if (typeof(__dirname) !== "undefined")
|
|
170
212
|
naanlib.js.h = naanlib.js.d; // set host directory path
|
|
171
213
|
if (msg.dirpath)
|
|
@@ -182,21 +224,17 @@ exports.NaanWorkerActivate = function NaanWorkerActivate(cbReady) {
|
|
|
182
224
|
}
|
|
183
225
|
else if (msg.id == "import")
|
|
184
226
|
importScripts(msg.script); // load a JavaScript
|
|
185
|
-
else if (msg.id == "targetin")
|
|
186
|
-
{
|
|
187
|
-
if (workerListener)
|
|
188
|
-
workerListener(msg.data); // worker received a message
|
|
189
|
-
}
|
|
190
227
|
else if (msg.id == "debugin")
|
|
191
228
|
{
|
|
192
229
|
if (debugListener)
|
|
193
230
|
debugListener(msg.data); // target received a message
|
|
194
231
|
}
|
|
195
|
-
else if (msg.id == "
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
232
|
+
else if (msg.id == "attached")
|
|
233
|
+
workSelf.ioctl_event("term-attach", msg.guid);
|
|
234
|
+
else if (msg.id == "detached")
|
|
235
|
+
workSelf.ioctl_event("term-detach", msg.guid);
|
|
236
|
+
else if (msg.id == "ioctl-event")
|
|
237
|
+
workSelf.ioctl_event(msg.msg, msg.arg);
|
|
200
238
|
});
|
|
201
239
|
|
|
202
240
|
naanlib.banner();
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* node_server_init.nlg
|
|
3
|
+
* Naanide
|
|
4
|
+
*
|
|
5
|
+
* Loaded automatically for Node.js before REPL turned over to the user.
|
|
6
|
+
*
|
|
7
|
+
* column positioning: // // !
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) 2020-2026 by Richard C. Zulch
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
loglevel(3);
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
* Debugging & Tools
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
if !module.owner.list.running.components.debugnub {
|
|
22
|
+
require("naanlib:frameworks/common/repltools.nlg").ImportReplTools()
|
|
23
|
+
require("naanlib:frameworks/running/debugnub.nlg").DebugNub()
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
App.shell = require("naanlib:frameworks/node/shell.nlg").ShellConnect({
|
|
27
|
+
cwd: js.d
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
/*
|
|
32
|
+
* versionCheck
|
|
33
|
+
*
|
|
34
|
+
* Ensure that Node is at least as new as the specified version.
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
function versionCheck(minver, local rxver, curver) {
|
|
39
|
+
rxver = RegExp("([0-9]+)[.]([0-9]+)[.]([0-9]+)")
|
|
40
|
+
minver = minver.match(rxver).map(function(x){Number.parseInt(x)})
|
|
41
|
+
curver = js.g.process.version.match(rxver).map(function(x){Number.parseInt(x)})
|
|
42
|
+
minver[1] < curver[1] || minver[1] == curver[1] && (minver[2] < curver[2] || minver[2] == curver[2] && minver[3] <= curver[3])
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
/*
|
|
47
|
+
* saveState
|
|
48
|
+
*
|
|
49
|
+
* Save our state soon. This saves in a future to avoid stack problems. Returns a nonce.
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
function saveState() {
|
|
54
|
+
future(function() {
|
|
55
|
+
js.t.Working()
|
|
56
|
+
js.save()
|
|
57
|
+
}, 0)
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
/*
|
|
62
|
+
* startup
|
|
63
|
+
*
|
|
64
|
+
* This is the normal NaanIDE startup code. The scenarios are as follows:
|
|
65
|
+
* 1. Start new server at available port and launch browser tab // default behavior
|
|
66
|
+
* 2. Start new server with intialization file that launches browser
|
|
67
|
+
* 3. Start new server at fixed port and launch browser tab
|
|
68
|
+
* 4. Start new server at fixed port with initialization file
|
|
69
|
+
* 5. Connect to existing server at fixed port and evaluate remote expression, then quit
|
|
70
|
+
*
|
|
71
|
+
* This uses the Naan symbol NaanStartParams as:
|
|
72
|
+
* {
|
|
73
|
+
* naanpath: <string> // path to the naan library
|
|
74
|
+
* serverPort: <integer> // defined if the command line specified a port
|
|
75
|
+
* guid: <string> // server secret
|
|
76
|
+
* cmd_mod: <string> // name of a command to execute
|
|
77
|
+
* cmd_path: <string> // path to command's module
|
|
78
|
+
* cmd_args: [<string>] // arguments to the command
|
|
79
|
+
* }
|
|
80
|
+
*
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
closure startup(local error, api, exists, oururl) {
|
|
84
|
+
if !versionCheck("16.20.2") {
|
|
85
|
+
debuglog("NaanIDE: NodeJS too old; version 16.20.2 required.")
|
|
86
|
+
js.g.process.exit(2)
|
|
87
|
+
}
|
|
88
|
+
if !dictionary(NaanStartParams) {
|
|
89
|
+
debuglog("NaanIDE: startup parameters missing.")
|
|
90
|
+
js.g.process.exit(3)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
App.imp = require("naanlib:frameworks/service/imp.nlg").Imp({
|
|
94
|
+
name: "NaanIDE Server"
|
|
95
|
+
type: "Server IMP"
|
|
96
|
+
})
|
|
97
|
+
require("naanlib:frameworks/running/remote_res.nlg")
|
|
98
|
+
.RemoteResponder(App.imp.us.instanceID, { // make our server remotable
|
|
99
|
+
name: "NaanIDE Server"
|
|
100
|
+
type: "Node Remote"
|
|
101
|
+
})
|
|
102
|
+
App.exec = require("naanlib:frameworks/node/worker.nlg").CurBot({
|
|
103
|
+
name: "NaanIDE Server"
|
|
104
|
+
type: "NaaN Server"
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
App.api = undefined
|
|
108
|
+
App.naanpath = NaanStartParams.naanpath
|
|
109
|
+
App.nidecon = require("lib/nidecon").NideCon({
|
|
110
|
+
fixedPort: NaanStartParams.serverPort
|
|
111
|
+
guid: NaanStartParams.guid
|
|
112
|
+
statics: [
|
|
113
|
+
list("", NaanStartParams.naanpath)
|
|
114
|
+
]
|
|
115
|
+
})
|
|
116
|
+
if NaanStartParams.cmd_mod {
|
|
117
|
+
`(error) = App.nidecon.runCommand(NaanStartParams.cmd_mod, NaanStartParams.cmd_path, NaanStartParams.cmd_args)
|
|
118
|
+
saveState().wait() // wait so we don't exit too soon
|
|
119
|
+
if error {
|
|
120
|
+
if error.memo != ""
|
|
121
|
+
ErrorDebuglog("NaanIDE: command failed", error)
|
|
122
|
+
if error.exit
|
|
123
|
+
js.g.process.exit(error.exit) // fatal error
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else if js.expr
|
|
127
|
+
saveState().wait()
|
|
128
|
+
else {
|
|
129
|
+
`(error, api, exists) = App.nidecon.startServer()
|
|
130
|
+
if exists {
|
|
131
|
+
`(error, oururl) = App.nidecon.connectServer()
|
|
132
|
+
if error {
|
|
133
|
+
ErrorDebuglog("NaanIDE: server at port ${NaanStartParams.serverPort} not responding", error)
|
|
134
|
+
js.g.process.exit(1)
|
|
135
|
+
}
|
|
136
|
+
debuglog("existing server access:", oururl)
|
|
137
|
+
return
|
|
138
|
+
} else if error {
|
|
139
|
+
ErrorDebuglog("NaanIDE: can't start server:", error)
|
|
140
|
+
js.g.process.exit(1)
|
|
141
|
+
}
|
|
142
|
+
debuglog("server access:", api.oururl)
|
|
143
|
+
Naan.runtimelib.curdriver().setOptions({prompt:true})
|
|
144
|
+
saveState()
|
|
145
|
+
`(error) = App.nidecon.launchBrowser()
|
|
146
|
+
if error
|
|
147
|
+
ErrorDebuglog("NaanIDE: can't launch browser:", error)
|
|
148
|
+
}
|
|
149
|
+
}();
|