@naanlang/naan 1.0.0 → 1.0.3

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 (37) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +37 -8
  3. package/bin/index.js +148 -0
  4. package/dist/env_web.js +145 -16
  5. package/dist/naan.min.js +5 -5
  6. package/frameworks/browser/sworker.js +309 -91
  7. package/frameworks/browser/terminals.nlg +22 -9
  8. package/frameworks/browser/workers.nlg +19 -11
  9. package/frameworks/client/apiclient.nlg +17 -4
  10. package/frameworks/client/psm_client.nlg +116 -53
  11. package/frameworks/common/common.nlg +12 -2
  12. package/frameworks/node/apiserver.nlg +25 -13
  13. package/frameworks/node/filesystem.nlg +173 -30
  14. package/frameworks/node/psm_server.nlg +95 -32
  15. package/frameworks/project/build.nlg +40 -23
  16. package/frameworks/project/projects.nlg +47 -26
  17. package/frameworks/running/debugnub.nlg +2 -5
  18. package/frameworks/storage/csv.nlg +120 -0
  19. package/frameworks/storage/dbt_pouch.nlg +41 -25
  20. package/frameworks/storage/psm.nlg +108 -28
  21. package/frameworks/storage/psm_dbtables.nlg +7 -3
  22. package/frameworks/storage/resources.nlg +30 -2
  23. package/lib/browser/env_web.js +147 -18
  24. package/lib/browser/env_webworker.js +1 -1
  25. package/lib/browser/require.js +1 -1
  26. package/lib/core/naanlib.js +5 -5
  27. package/lib/env_node.js +14 -2
  28. package/lib/node_repl.js +2 -2
  29. package/package.json +4 -1
  30. package/plugins/serviceAws/aws_cloudwatchlogs.nlg +1 -1
  31. package/plugins/serviceAws/aws_dynamo.nlg +625 -141
  32. package/plugins/serviceAws/aws_dynextra.nlg +294 -0
  33. package/plugins/serviceAws/dbt_aws.nlg +31 -11
  34. package/plugins/serviceAws/psm_aws.nlg +42 -26
  35. package/plugins/serviceAws/serviceAws.nlg +1 -0
  36. package/plugins/serviceGitHub/psm_github.nlg +41 -25
  37. package/plugins/serviceGitLab/psm_gitlab.nlg +41 -25
package/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Naan for NPM version 1.0.0-1 is released under the MIT License:
1
+ Naan for NPM version 1.0.3-1 is released under the MIT License:
2
2
 
3
3
  Copyright (c) 2017-2022 Zulch Laboratories, Inc.
4
4
 
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  Naan is an async-first software platform for rapid development.
5
5
 
6
6
  #### Release:
7
-      Naan for NPM version 1.0.0-1
7
+      Naan for NPM version 1.0.3-1
8
8
       Copyright (c) 2017-2022 Zulch Laboratories, Inc.
9
9
 
10
10
  #### Features
@@ -17,7 +17,7 @@ Naan is an async-first software platform for rapid development.
17
17
  - Preserves referential integrity when communicating among workers or hosts
18
18
  - Plugin architecture enables alternate languages and functionality
19
19
  - Custom language syntax can be added through simplified dialect extensions
20
- - Integrates transparently with all exising JavaScript libraries
20
+ - Integrates transparently with all existing JavaScript libraries
21
21
  - Can save and reload running program state across page loads or lambda invocations
22
22
  - Lightweight and efficient
23
23
 
@@ -27,18 +27,47 @@ Please ensure you have a recent version of [node.js](http://nodejs.org/)
27
27
 
28
28
  For use everywhere as a command line app:
29
29
 
30
- npm install naan -g
30
+ npm install @naanlang/naan -g
31
31
 
32
32
  For use as a library in the current project:
33
33
 
34
- npm install naan
34
+ npm install @naanlang/naan
35
35
 
36
- #### Command line usage
36
+ #### Command line execution
37
37
 
38
- naan
38
+ naan [options] [source file] [arguments]
39
39
 
40
- ##### Dependencies:
41
-      We greatfully acknowlege these software packages used with Naan:
40
+ With no arguments Naan runs as an interactive REPL using the node.js terminal.
41
+ It can also evaluate an expression or execute a source file.
42
+
43
+ ##### Command line usage
44
+
45
+ -h, --help print usage information
46
+ -e <expression> evaluate an expression
47
+ -i, --interactive use REPL with -e or [source file]
48
+ -v, --version print Naan version
49
+ -vv print Naan version with build number
50
+
51
+ Naan prints the results of evaluating each expression with the REPL, but not
52
+ by default with an expression or source file. The interactive flag overrides
53
+ this to print the result of each expression in all cases.
54
+
55
+ ##### Shell scripting
56
+
57
+ When installed globally, Naan can be used for shell scripts with the [Shebang](https://en.wikipedia.org/wiki/Shebang_(Unix))
58
+ mechanism. For example, copy the following text to a file named helloworld:
59
+
60
+ #!/usr/bin/env naan
61
+ printline("Hello World")
62
+
63
+ Now make it executable with chmod:
64
+
65
+ chmod a+x helloworld
66
+
67
+
68
+
69
+ #### Dependencies:
70
+      We gratefully acknowledge these software packages used with Naan:
42
71
  - [jszip.js](http://stuartk.com/jszip) - read and write zip files
43
72
  - [NodeJS-path](https://nodejs.org/) - NodeJS path utilities
44
73
  - [PouchDB](https://pouchdb.com/) - synchronizing database
package/bin/index.js ADDED
@@ -0,0 +1,148 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ * index.js
4
+ * Naanlib
5
+ *
6
+ * Naan command line.
7
+ *
8
+ * column positioning: // // !
9
+ *
10
+ * Copyright (c) 2021-2022 by Richard C. Zulch
11
+ *
12
+ */
13
+
14
+ "use strict";
15
+
16
+ /*
17
+ * imports
18
+ *
19
+ */
20
+
21
+ var path = require("path");
22
+ var fs = require("fs");
23
+ var naanOptions;
24
+
25
+ /*
26
+ * Process command-line arguments
27
+ *
28
+ */
29
+
30
+ var cmd_file;
31
+ var eval_text;
32
+ var do_interactive;
33
+ var cmd_text = "nodeparse('node_repl_init.nlg');;\n";
34
+
35
+ process.argv.every((val, index) => {
36
+ if (index < 2)
37
+ return (true);
38
+ if (val == "-e") {
39
+ eval_text = 1;
40
+ return (true);
41
+ }
42
+ if (eval_text == 1 && val.substring(0,1) == "-")
43
+ return (false);
44
+ if (val == "-h" || val == "--help") {
45
+ console.log(
46
+ "Usage: naan [options] [source file] [arguments]\n\n" +
47
+ "Options:\n" +
48
+ " -e <expression> evaluate an expression\n" +
49
+ " -i, --interactive use REPL with -e or [source file]\n" +
50
+ " --version print the Naan version\n" +
51
+ " --buildno print the version and build\n" +
52
+ " -h, --help print this usage information\n"
53
+ );
54
+ process.exit(0);
55
+ }
56
+ if (val == "-i" || val == "--interactive") {
57
+ do_interactive = true;
58
+ return (true);
59
+ }
60
+ if (val == "--version") {
61
+ console.log("1.0.3");
62
+ process.exit(0);
63
+ }
64
+ if (val == "--buildno") {
65
+ console.log("1.0.3-1");
66
+ process.exit(0);
67
+ }
68
+ if (val.substring(0,1) == "-") {
69
+ console.log("naan: bad option: " + val);
70
+ process.exit(9);
71
+ }
72
+ if (eval_text == 1) {
73
+ eval_text = val + '\n';
74
+ return (true);
75
+ }
76
+ if (!cmd_file) {
77
+ cmd_file = val;
78
+ return (true);
79
+ }
80
+ // ignore extra arguments
81
+ return (true);
82
+ });
83
+
84
+ if (eval_text == 1) {
85
+ console.log("naan: -e requires an argument");
86
+ process.exit(9);
87
+ }
88
+ if (cmd_file) {
89
+ if (!fs.existsSync(cmd_file)) {
90
+ console.log("naan: file not found: " + cmd_file);
91
+ process.exit(1);
92
+ }
93
+ eval_text = fs.readFileSync(cmd_file, "utf8");
94
+ eval_text = eval_text.replace(/^#!.*\n/, "");
95
+ }
96
+ if (eval_text) {
97
+ if (!do_interactive)
98
+ naanOptions = { replDisable: true };
99
+ cmd_text =
100
+ "closure NodeREPL(local input, error, expr) {\n" +
101
+ (do_interactive ?
102
+ ""
103
+ :
104
+ " sudo(putproc(`exception, false))\n") +
105
+ " input = new(textstream, js.expr)\n" +
106
+ " try {\n" +
107
+ " loop {\n" +
108
+ " `(error, expr) = Dialect.parse(input)\n" +
109
+ " if error {\n" +
110
+ " printline(' ==> parse error: ', Dialect.parseErrorString(error.0))\n" +
111
+ " break\n" +
112
+ " } else\n" +
113
+ (cmd_file && !do_interactive ?
114
+ " eval(expr)\n"
115
+ :
116
+ " {\n" +
117
+ " if input.tokenlast().atom == `;;\n" +
118
+ " eval(expr)\n" +
119
+ " else if input.tokenlast().atom == `;>\n" +
120
+ " printline(eval(expr))\n" +
121
+ " else\n" +
122
+ " printline(Dialect.print(eval(expr)))\n" +
123
+ " }\n") +
124
+ " }\n" +
125
+ " } catch {\n" +
126
+ " if true {\n" +
127
+ " if exception != `(internal, 'end-of-file')\n" +
128
+ " printline(' ==> exception: ', error = exception)\n" +
129
+ " }\n" +
130
+ " } finally {\n" +
131
+ " sleep(1)\n" +
132
+ " exec(quote(js.g.process.exit(if error 1 else 0)))\n" +
133
+ " }\n" +
134
+ "}();;\n";
135
+ }
136
+
137
+
138
+ /*
139
+ * Execute Naan
140
+ *
141
+ */
142
+
143
+ var NaanNodeREPL = require('../lib/env_node.js');
144
+ var naanrepl = new NaanNodeREPL(naanOptions);
145
+ naanrepl.setDirectory(path.join(__dirname, "../lib"));
146
+ if (eval_text)
147
+ naanrepl.setGlobal("expr", eval_text + "\n");
148
+ naanrepl.textCommand(cmd_text);
package/dist/env_web.js CHANGED
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * column positioning: // // !
8
8
  *
9
- * Copyright (c) 2017-2021 by Richard C. Zulch
9
+ * Copyright (c) 2017-2022 by Richard C. Zulch
10
10
  *
11
11
  */
12
12
 
@@ -83,6 +83,7 @@ exports.NaanControllerWeb = function() {
83
83
  var replqueue; // text destined for terminal when opened
84
84
  var termlist = []; // list of terminals currently attached
85
85
  var prefs = { };
86
+ var vsiteName;
86
87
 
87
88
  //
88
89
  // termTextOut
@@ -149,8 +150,15 @@ exports.NaanControllerWeb = function() {
149
150
  //
150
151
 
151
152
  this.StateGet = function StateGet() {
152
- if (termlist.length > 0)
153
- replstate = termlist[0].StateSave(); // restore current buffer state to new terminal
153
+ termlist.every(function(term) {
154
+ var state;
155
+ if (term.StateSave && (state = term.StateSave()))
156
+ { // update the state if we can
157
+ replstate = state;
158
+ return (false);
159
+ }
160
+ return (true); // keep searching
161
+ });
154
162
  return (replstate);
155
163
  };
156
164
 
@@ -204,14 +212,14 @@ exports.NaanControllerWeb = function() {
204
212
  if (term !== terminal)
205
213
  term.OnMessage({ // send text to other terminals
206
214
  id: "textout",
207
- text: text + "\r\n"
215
+ text: "\x1b[90m\x1b[3m" + text + "\x1b[0m" + "\r\n"
208
216
  });
209
217
  });
210
218
  window.setTimeout(function () {
211
- naanlib.textLine(text)
219
+ naanlib.textLine(text);
212
220
  }, 1);
213
221
  };
214
-
222
+
215
223
  this.ReplyMessage = function ReplyMessage(data) { // "remote" -> "local"
216
224
  termlist.forEach(function(term) {
217
225
  if (term.OnMessageOut)
@@ -229,9 +237,9 @@ exports.NaanControllerWeb = function() {
229
237
  this.DispatchMessage = function DispatchMessage(data) { // "local" -> "remote"
230
238
  if (nideListener)
231
239
  setTimeout(function() {
232
- nideListener(data)
240
+ nideListener(data);
233
241
  }, 1);
234
- }
242
+ };
235
243
 
236
244
  this.ReplyDebugger = function ReplyDebugger(data) { // "remote" -> "local"
237
245
  termlist.forEach(function(term) {
@@ -250,9 +258,9 @@ exports.NaanControllerWeb = function() {
250
258
  this.DispatchDebugger = function DispatchDebugger(data) { // "local" -> "remote"
251
259
  if (debugListener)
252
260
  setTimeout(function() {
253
- debugListener(data)
261
+ debugListener(data);
254
262
  }, 1);
255
- }
263
+ };
256
264
 
257
265
  //
258
266
  // Status
@@ -290,7 +298,95 @@ exports.NaanControllerWeb = function() {
290
298
  this.Dimensions = function Dimensions(rows, cols) {
291
299
  console.log("Naan terminal dimensions now (" + rows + ", " + cols + ")");
292
300
  };
301
+
302
+ //
303
+ // VsiteRefresh
304
+ //
305
+ // Check if our underlying data has changed, and reload if needed.
306
+ //
307
+
308
+ this.VsiteRefresh = function VsiteRefresh(url_origin) {
309
+ if (window.location.href.startsWith(url_origin))
310
+ window.location.reload(); // we have changed underneath
311
+ };
312
+
293
313
 
314
+ //==========================================================================
315
+ // Clone Debug Interface
316
+ //--------------------------------------------------------------------------
317
+
318
+ function CloneDebugTerminal()
319
+ {
320
+ var termSelf = this;
321
+ //
322
+ // listen for messages
323
+ //
324
+ window.addEventListener("message", function (event) {
325
+ if (event.origin !== window.origin)
326
+ return; // only talk with our peers
327
+ var msg = event.data;
328
+ if (msg.id == "interrupt")
329
+ contSelf.Interrupt();
330
+ else if (msg.id == "keyline")
331
+ contSelf.Return(msg.text, termSelf); // keyboard text from terminal
332
+ else if (msg.id == "start")
333
+ contSelf.Attach(term); // opener is ready
334
+ else if (msg.id == "import")
335
+ { // for workers
336
+ }
337
+ else if (msg.id == "targetin")
338
+ {
339
+ if (nideListener)
340
+ nideListener(msg.data); // target received a message
341
+ }
342
+ else if (msg.id == "debugin")
343
+ {
344
+ if (debugListener)
345
+ debugListener(msg.data); // target received a message
346
+ }
347
+ });
348
+
349
+ //
350
+ // report messages back to opener
351
+ //
352
+ termSelf.OnMessage = function OnMessage(msg) {
353
+ window.opener.postMessage(msg, window.origin);
354
+ return (msg);
355
+ };
356
+
357
+ //
358
+ // report messages back to opener
359
+ //
360
+ termSelf.OnMessageOut = function OnMessageOut(data) {
361
+ var msg = { // target is sending debug data
362
+ id: "targetout",
363
+ data: data
364
+ };
365
+ return (termSelf.OnMessage(msg));
366
+ };
367
+
368
+ //
369
+ // report debug messages back to opener
370
+ //
371
+ termSelf.OnDebugOut = function OnDebugOut(data) {
372
+ var msg = { // target is sending debug data
373
+ id: "debugout",
374
+ data: data
375
+ };
376
+ return (termSelf.OnMessage(msg));
377
+ };
378
+
379
+ //
380
+ // report status back to opener
381
+ //
382
+ termSelf.OnStatus = function OnStatus(status) {
383
+ var msg = { // target is sending debug data
384
+ id: "status",
385
+ status: status
386
+ };
387
+ return (termSelf.OnMessage(msg));
388
+ };
389
+ }
294
390
 
295
391
  //==========================================================================
296
392
  // Host Environment
@@ -299,7 +395,7 @@ exports.NaanControllerWeb = function() {
299
395
  //
300
396
  // SavePref
301
397
  //
302
- // Save a persistent preference objectc that can be retrieved in the future.
398
+ // Save a persistent preference object that can be retrieved in the future.
303
399
  //
304
400
 
305
401
  this.SavePref = function SavePref(key, value) {
@@ -333,6 +429,7 @@ exports.NaanControllerWeb = function() {
333
429
  window.addEventListener("unload", function (e) {
334
430
  window.dispatchEvent(saveEvent);
335
431
  saveLocal();
432
+ virtualClose();
336
433
  });
337
434
 
338
435
  window.addEventListener("beforeunload", function (e) {
@@ -348,11 +445,11 @@ exports.NaanControllerWeb = function() {
348
445
  statedoc.verstring = "$Version$";
349
446
  statedoc.date = new Date().toISOString();
350
447
  statedoc.prefs = prefs;
351
- statedoc.naan = naanlib.saveState(true); // true to optimize, which is a bit slower
448
+ statedoc.naan = naanlib.saveState(false); // true to optimize, which is a bit slower
352
449
  termlist.forEach(function(term) {
353
450
  if (!replstate || term.termwin)
354
451
  replstate = term.StateSave(); // state with separate window, otherwise any state
355
- })
452
+ });
356
453
  if (replstate)
357
454
  statedoc.replstate = replstate;
358
455
  return (statedoc);
@@ -364,7 +461,10 @@ exports.NaanControllerWeb = function() {
364
461
  || statedoc.curversion < kStateFirstVersion
365
462
  || statedoc.licensee != "$Licensee$"
366
463
  || statedoc.verstring != "$Version$")
464
+ {
465
+ localStorage.removeItem("NaanState_Hosted");
367
466
  return (false);
467
+ }
368
468
  naanstate = statedoc.naan;
369
469
  replstate = statedoc.replstate; // get terminal state, if any
370
470
  if (typeof(statedoc.prefs) == "object")
@@ -381,8 +481,8 @@ exports.NaanControllerWeb = function() {
381
481
  try {
382
482
  if ("localStorage" in window && window["localStorage"] !== null)
383
483
  {
384
- localStorage.removeItem("NaanState_Nide");
385
- if (localStorage.setItem("NaanState_Nide", statestr) !== undefined)
484
+ localStorage.removeItem("NaanState_Hosted");
485
+ if (localStorage.setItem("NaanState_Hosted", statestr) !== undefined)
386
486
  return (true);
387
487
  }
388
488
  } catch(e) {
@@ -396,7 +496,7 @@ exports.NaanControllerWeb = function() {
396
496
  /*jshint sub:true */
397
497
  if ("localStorage" in window && window["localStorage"] !== null)
398
498
  {
399
- var statestr = localStorage.getItem("NaanState_Nide");
499
+ var statestr = localStorage.getItem("NaanState_Hosted");
400
500
  if (statestr)
401
501
  return (loadState(JSON.parse(statestr)));
402
502
  }
@@ -405,7 +505,28 @@ exports.NaanControllerWeb = function() {
405
505
  }
406
506
  return (false);
407
507
  }
508
+
509
+ function virtualOpen() {
510
+ vsiteName = window.document.title; // consistent name at open and close
511
+ if (window.opener && window.opener.Naanlang)
512
+ window.opener.Naanlang.naancon.DispatchMessage({
513
+ op: "VsiteOpen",
514
+ name: vsiteName,
515
+ naancont: contSelf
516
+ });
517
+ }
408
518
 
519
+ function virtualClose() {
520
+ if (window.opener && window.opener.Naanlang) {
521
+ window.opener.Naanlang.naancon.DispatchMessage({
522
+ op: "VsiteClose",
523
+ name: vsiteName,
524
+ naancont: contSelf
525
+ });
526
+ termTextOut("\x1b[90m\x1b[3m".concat("\nwindow closed", "\x1b[0m\n"));
527
+ }
528
+ }
529
+
409
530
  /*jshint sub:true */
410
531
  if (querystrings["restart"] || !loadLocal())
411
532
  { // don't load state or can't load state
@@ -423,6 +544,14 @@ exports.NaanControllerWeb = function() {
423
544
  state: naanstate
424
545
  });
425
546
  }
547
+
548
+ if (window.opener) {
549
+ virtualOpen();
550
+ var term = new CloneDebugTerminal();
551
+ term.OnMessage({
552
+ id: "loaded"
553
+ });
554
+ }
426
555
  };
427
556
 
428
557
  /*jshint sub:true */