@naanlang/naan 1.5.0 → 1.6.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.
Files changed (44) hide show
  1. package/LICENSE.md +2 -2
  2. package/README.md +2 -2
  3. package/bin/index.js +7 -3
  4. package/dist/env_web.js +162 -20
  5. package/dist/naan.min.js +5 -5
  6. package/frameworks/browser/https_request.nlg +2 -2
  7. package/frameworks/browser/sworker.js +28 -26
  8. package/frameworks/browser/terminals.nlg +329 -693
  9. package/frameworks/browser/worker.nlg +255 -0
  10. package/frameworks/browser/workers.nlg +5 -5
  11. package/frameworks/browser/ws_client.nlg +15 -10
  12. package/frameworks/client/apiclient.nlg +181 -9
  13. package/frameworks/client/relaycon.nlg +87 -161
  14. package/frameworks/common/events.nlg +101 -0
  15. package/frameworks/common/repltools.nlg +80 -1
  16. package/frameworks/node/apiserver.nlg +39 -246
  17. package/frameworks/node/filesystem.nlg +31 -6
  18. package/frameworks/node/http_request.nlg +34 -13
  19. package/frameworks/node/https_request.nlg +8 -3
  20. package/frameworks/node/node.nlg +2 -0
  21. package/frameworks/node/pty.nlg +346 -0
  22. package/frameworks/node/worker.nlg +409 -539
  23. package/frameworks/node/ws_client.nlg +2 -2
  24. package/frameworks/project/build.nlg +1 -1
  25. package/frameworks/project/projects.nlg +1 -1
  26. package/frameworks/running/debugnub.nlg +17 -4
  27. package/frameworks/running/executors.nlg +27 -274
  28. package/frameworks/running/instances.nlg +393 -0
  29. package/frameworks/running/remote_req.nlg +143 -0
  30. package/frameworks/running/remote_res.nlg +89 -0
  31. package/frameworks/running/taskexec.nlg +2 -2
  32. package/frameworks/service/imp.nlg +736 -0
  33. package/frameworks/service/model.nlg +71 -0
  34. package/frameworks/service/nubnode.nlg +105 -0
  35. package/frameworks/service/nubweb.nlg +106 -0
  36. package/frameworks/service/service.nlg +28 -0
  37. package/lib/browser/env_web.js +169 -27
  38. package/lib/browser/env_webworker.js +91 -4
  39. package/lib/core/naanlib.js +5 -5
  40. package/lib/env_node.js +184 -8
  41. package/lib/env_nodeworker.js +74 -1
  42. package/package.json +1 -1
  43. package/plugins/serviceNexara/speechrec.nlg +10 -6
  44. package/test/test_02_context.nlg +24 -1
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * column positioning: // // !
8
8
  *
9
- * Copyright (c) 2019-2025 by Richard C. Zulch
9
+ * Copyright (c) 2019-2026 by Richard C. Zulch
10
10
  *
11
11
  */
12
12
 
@@ -45,20 +45,27 @@ exports.NaanControllerWebWorker = function NaanControllerWebWorker() {
45
45
  var targSelf = this; // this is us, for access within nested functions
46
46
  targSelf.anaan = naanlib.js.n;
47
47
  naanlib.js.t = targSelf;
48
-
48
+ var workerMetadata = { };
49
+
49
50
  //
50
51
  // Communications
51
52
  //
52
53
 
54
+ targSelf.metadata = function metadata() { // our creation metadata
55
+ return (workerMetadata);
56
+ };
57
+
53
58
  naanlib.onText(function(text, level) {
54
59
  if (level)
55
60
  postMessage({
61
+ scope: "naan-env-web",
56
62
  id: "debugtext",
57
63
  text: text,
58
64
  level: level
59
65
  });
60
66
  else
61
67
  postMessage({
68
+ scope: "naan-env-web",
62
69
  id: "textout",
63
70
  text: text
64
71
  });
@@ -68,6 +75,7 @@ exports.NaanControllerWebWorker = function NaanControllerWebWorker() {
68
75
  var samples = naanlib.status(1);
69
76
  if (samples.length > 0)
70
77
  postMessage({ // periodic worker status
78
+ scope: "naan-env-web",
71
79
  id: "status",
72
80
  status: {
73
81
  sample: samples[0]
@@ -77,6 +85,7 @@ exports.NaanControllerWebWorker = function NaanControllerWebWorker() {
77
85
 
78
86
  targSelf.ReplyMessage = function ReplyMessage(data) {
79
87
  postMessage({ // target is sending a message
88
+ scope: "naan-env-web",
80
89
  id: "targetout",
81
90
  data: data
82
91
  });
@@ -91,6 +100,7 @@ exports.NaanControllerWebWorker = function NaanControllerWebWorker() {
91
100
 
92
101
  this.DispatchMessage = function DispatchMessage(data) {
93
102
  postMessage({ // target is sending a message
103
+ scope: "naan-env-web",
94
104
  id: "targetsend",
95
105
  data: data
96
106
  });
@@ -105,6 +115,7 @@ exports.NaanControllerWebWorker = function NaanControllerWebWorker() {
105
115
 
106
116
  targSelf.ReplyDebugger = function ReplyDebugger(data) {
107
117
  postMessage({ // target is sending debug data
118
+ scope: "naan-env-web",
108
119
  id: "debugout",
109
120
  data: data
110
121
  });
@@ -119,6 +130,7 @@ exports.NaanControllerWebWorker = function NaanControllerWebWorker() {
119
130
 
120
131
  targSelf.Download = function Download(bits, name, options) {
121
132
  postMessage({ // tell browser host to download a file
133
+ scope: "naan-env-web",
122
134
  id: "download",
123
135
  bits: bits,
124
136
  name: name,
@@ -129,6 +141,7 @@ exports.NaanControllerWebWorker = function NaanControllerWebWorker() {
129
141
 
130
142
  targSelf.Terminate = function Terminate(result) {
131
143
  postMessage({ // terminate this worker from worker
144
+ scope: "naan-env-web",
132
145
  id: "termination",
133
146
  result: result
134
147
  });
@@ -136,16 +149,21 @@ exports.NaanControllerWebWorker = function NaanControllerWebWorker() {
136
149
  return (result);
137
150
  };
138
151
 
139
- onmessage = function(e) {
152
+ addEventListener("message", function(e) {
140
153
  var msg = e.data;
154
+ if (msg.scope != "naan-env-web")
155
+ return;
141
156
  if (msg.id == "interrupt")
142
157
  naanlib.escape();
143
158
  else if (msg.id == "keyline")
144
159
  naanlib.textLine(msg.text); // keyboard text from terminal
160
+ else if (msg.id == "typed")
161
+ echoTyped(msg.text);
145
162
  else if (msg.id == "start")
146
163
  { // start execution with optional state
147
164
  targSelf.workerID = msg.workerID;
148
165
  targSelf.workerGUID = msg.workerGUID;
166
+ workerMetadata = msg.metadata || { };
149
167
  naanlib.banner();
150
168
  naanlib.start({
151
169
  state: msg.state,
@@ -169,13 +187,82 @@ exports.NaanControllerWebWorker = function NaanControllerWebWorker() {
169
187
  if (targetReceiver)
170
188
  targetReceiver(msg.data);
171
189
  }
190
+ else if (msg.id == "attached")
191
+ targSelf.ioctl_event("term-attach", msg.guid);
192
+ else if (msg.id == "detached")
193
+ targSelf.ioctl_event("term-detach", msg.guid);
194
+ else if (msg.id == "ioctl-event")
195
+ targSelf.ioctl_event(msg.msg, msg.arg);
196
+ });
197
+
198
+ //==========================================================================
199
+ // ioctl terminal control
200
+ //--------------------------------------------------------------------------
201
+
202
+ var listeners = { };
203
+
204
+ //
205
+ // ioctl_event
206
+ //
207
+ // Events incoming from terminal.
208
+ //
209
+
210
+ targSelf.ioctl_event = function ioctl_event(msg, arg) {
211
+ if (listeners[msg])
212
+ listeners[msg].forEach(function(proc) {
213
+ proc(msg, arg);
214
+ });
172
215
  };
173
-
216
+
217
+ //
218
+ // ioctl_add_listener
219
+ // ioctl_remove_listener
220
+ //
221
+ // Add a listener for a terminal event.
222
+ //
223
+
224
+ targSelf.ioctl_add_listener = function ioctl_add_listener(msg, proc) {
225
+ if (typeof(msg) != "string" || typeof(proc) != "function")
226
+ return (false);
227
+ targSelf.ioctl_remove_listener(msg, proc);
228
+ if (!listeners[msg])
229
+ listeners[msg] = [];
230
+ listeners[msg].push(proc);
231
+ return (true);
232
+ };
233
+
234
+ targSelf.ioctl_remove_listener = function ioctl_remove_listener(msg, proc) {
235
+ if (typeof(msg) != "string" || typeof(proc) != "function")
236
+ return (false);
237
+ if (listeners[msg]) {
238
+ var index = listeners[msg].indexOf(proc);
239
+ if (index >= 0)
240
+ listeners[msg].splice(index, 1);
241
+ }
242
+ return (true);
243
+ };
244
+
245
+ //
246
+ // ioctl
247
+ //
248
+ // Control of terminals (and their controller.)
249
+ //
250
+
251
+ targSelf.ioctl = function ioctl(op, arg) {
252
+ postMessage({
253
+ scope: "naan-env-web",
254
+ id: "ioctl",
255
+ op: op,
256
+ arg: arg
257
+ });
258
+ };
259
+
174
260
  //
175
261
  // Initialization complete
176
262
  //
177
263
 
178
264
  postMessage({
265
+ scope: "naan-env-web",
179
266
  id: "loaded"
180
267
  });
181
268
  };