@naanlang/naan 1.0.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 (98) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +46 -0
  3. package/dist/env_web.js +431 -0
  4. package/dist/naan.min.js +73 -0
  5. package/frameworks/browser/browser.nlg +30 -0
  6. package/frameworks/browser/pouchdb/pouchdb.min.js +7 -0
  7. package/frameworks/browser/spark-md5/spark-md5.min.js +1 -0
  8. package/frameworks/browser/sworker.js +192 -0
  9. package/frameworks/browser/terminals.nlg +787 -0
  10. package/frameworks/browser/workers.nlg +386 -0
  11. package/frameworks/client/apiclient.nlg +183 -0
  12. package/frameworks/client/client.nlg +29 -0
  13. package/frameworks/client/psm_client.nlg +572 -0
  14. package/frameworks/common/common.nlg +464 -0
  15. package/frameworks/common/preferences.nlg +131 -0
  16. package/frameworks/common/repltools.nlg +100 -0
  17. package/frameworks/common/watching.nlg +97 -0
  18. package/frameworks/node/apiserver.nlg +399 -0
  19. package/frameworks/node/filesystem.nlg +1012 -0
  20. package/frameworks/node/gitter.nlg +234 -0
  21. package/frameworks/node/node.nlg +81 -0
  22. package/frameworks/node/psm_server.nlg +465 -0
  23. package/frameworks/node/worker.nlg +560 -0
  24. package/frameworks/project/build.nlg +1229 -0
  25. package/frameworks/project/jszip.js +30 -0
  26. package/frameworks/project/jszip.nlg +87 -0
  27. package/frameworks/project/proj_cliser.nlg +139 -0
  28. package/frameworks/project/proj_console.nlg +137 -0
  29. package/frameworks/project/proj_folder.nlg +143 -0
  30. package/frameworks/project/proj_lambda.nlg +137 -0
  31. package/frameworks/project/proj_static.nlg +138 -0
  32. package/frameworks/project/project.nlg +29 -0
  33. package/frameworks/project/projects.nlg +587 -0
  34. package/frameworks/project/uglifyjs.js +1 -0
  35. package/frameworks/project/uglifyjs.nlg +79 -0
  36. package/frameworks/running/debugcom.nlg +163 -0
  37. package/frameworks/running/debugnub.nlg +565 -0
  38. package/frameworks/running/debugutil.nlg +510 -0
  39. package/frameworks/running/executors.nlg +767 -0
  40. package/frameworks/running/running.nlg +151 -0
  41. package/frameworks/running/sourcecode.nlg +346 -0
  42. package/frameworks/running/taskexec.nlg +196 -0
  43. package/frameworks/storage/dbt_pouch.nlg +773 -0
  44. package/frameworks/storage/file_manager.nlg +772 -0
  45. package/frameworks/storage/psm.nlg +326 -0
  46. package/frameworks/storage/psm_dbtables.nlg +814 -0
  47. package/frameworks/storage/resources.nlg +445 -0
  48. package/frameworks/storage/storage.nlg +52 -0
  49. package/lib/browser/env_web.js +431 -0
  50. package/lib/browser/env_webworker.js +146 -0
  51. package/lib/browser/require.js +1653 -0
  52. package/lib/core/naanlib.js +73 -0
  53. package/lib/env_node.js +282 -0
  54. package/lib/env_nodeworker.js +165 -0
  55. package/lib/node_repl.js +25 -0
  56. package/lib/node_repl_init.nlg +52 -0
  57. package/package.json +13 -0
  58. package/plugins/gitClient/clientops.nlg +317 -0
  59. package/plugins/gitClient/gitClient.nlg +63 -0
  60. package/plugins/gitClient/gitutils.nlg +1331 -0
  61. package/plugins/gitClient/minimatch.js +945 -0
  62. package/plugins/gitClient/minimatch_license.txt +15 -0
  63. package/plugins/gitClient/minimatch_readme.md +208 -0
  64. package/plugins/nodeLib/nodeLib.nlg +26 -0
  65. package/plugins/nodeLib/node_cp.nlg +65 -0
  66. package/plugins/nodeLib/node_fs.nlg +137 -0
  67. package/plugins/nodeLib/node_https.nlg +172 -0
  68. package/plugins/nodeLib/node_util.nlg +180 -0
  69. package/plugins/serviceAws/aws/aws-sdk.min.js +88 -0
  70. package/plugins/serviceAws/aws/lambda_rest_index.js +122 -0
  71. package/plugins/serviceAws/aws/lambda_rest_init.nlg +58 -0
  72. package/plugins/serviceAws/aws/lambda_ws_index.js +498 -0
  73. package/plugins/serviceAws/aws/lambda_ws_init.nlg +49 -0
  74. package/plugins/serviceAws/aws_cloudwatchlogs.nlg +122 -0
  75. package/plugins/serviceAws/aws_cognito.nlg +76 -0
  76. package/plugins/serviceAws/aws_dynamo.nlg +509 -0
  77. package/plugins/serviceAws/aws_lambda.nlg +95 -0
  78. package/plugins/serviceAws/aws_s3.nlg +134 -0
  79. package/plugins/serviceAws/aws_utils.nlg +86 -0
  80. package/plugins/serviceAws/dbt_aws.nlg +769 -0
  81. package/plugins/serviceAws/lambda_naan_control.nlg +175 -0
  82. package/plugins/serviceAws/psm_aws.nlg +258 -0
  83. package/plugins/serviceAws/serviceAws.nlg +38 -0
  84. package/plugins/serviceGitHub/gitops.nlg +522 -0
  85. package/plugins/serviceGitHub/psm_github.nlg +205 -0
  86. package/plugins/serviceGitHub/serviceGitHub.nlg +65 -0
  87. package/plugins/serviceGitLab/gitops.nlg +528 -0
  88. package/plugins/serviceGitLab/psm_gitlab.nlg +205 -0
  89. package/plugins/serviceGitLab/serviceGitLab.nlg +65 -0
  90. package/test/harness.nlg +312 -0
  91. package/test/node_test.js +33 -0
  92. package/test/test_01_core.nlg +768 -0
  93. package/test/test_02_context.nlg +269 -0
  94. package/test/test_03_jsinterop.nlg +137 -0
  95. package/test/test_04_numerics.nlg +450 -0
  96. package/test/test_05_strings.nlg +63 -0
  97. package/test/test_06_lingoparse.nlg +500 -0
  98. package/test/test_07_lingo.nlg +623 -0
@@ -0,0 +1,431 @@
1
+ /*
2
+ * env_web.js
3
+ * Naanlib
4
+ *
5
+ * Host Naan in the Browser environment.
6
+ *
7
+ * column positioning: // // !
8
+ *
9
+ * Copyright (c) 2017-2021 by Richard C. Zulch
10
+ *
11
+ */
12
+
13
+
14
+ /*
15
+ * Initialize
16
+ *
17
+ */
18
+
19
+ (function(exports){
20
+
21
+
22
+ /*
23
+ * NaanControllerWeb
24
+ *
25
+ * This JavaScript object manages a single Naan interpreter instance with the following services:
26
+ * 1. Load persistent state on startup, if available and allowed
27
+ * 2. Interpret query strings supplied when the host window was opened
28
+ * 3. Save state before the host window is closed.
29
+ *
30
+ */
31
+
32
+ exports.NaanControllerWeb = function() {
33
+
34
+ "use strict";
35
+ /*jshint -W024 */
36
+ var undefined; // JavaScript should make this a keyword
37
+
38
+ //
39
+ // Persistent
40
+ //
41
+
42
+ var
43
+ kStateFirstVersion = 200, // increment when losing backwards compatbility
44
+ kStateCurrentVersion = 200; // increment when adding features
45
+
46
+
47
+ //
48
+ // Environment
49
+ //
50
+
51
+ var pageLoading = true; // assume we are loading the page
52
+
53
+ window.addEventListener("load", function (e) {
54
+ pageLoading = false;
55
+ });
56
+
57
+ var querystrings = (function(a) {
58
+ if (a === "") return {};
59
+ var b = {};
60
+ for (var i = 0; i < a.length; ++i)
61
+ {
62
+ var p=a[i].split('=', 2);
63
+ if (p.length == 1)
64
+ b[p[0]] = "";
65
+ else
66
+ b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
67
+ }
68
+ return b;
69
+ })(window.location.search.substr(1).split('&'));
70
+
71
+
72
+ //
73
+ // Initialization
74
+ //
75
+
76
+ var naanlib = new exports.Naanlib();
77
+ var contSelf = this; // this is us, for access within nested functions
78
+ exports.naancon = this; // access to this instance
79
+ contSelf.anaan = naanlib.js.n;
80
+ naanlib.js.t = contSelf;
81
+ var replstate; // latest known state of the REPL
82
+ var naanstate; // desired state for the interpreter
83
+ var replqueue; // text destined for terminal when opened
84
+ var termlist = []; // list of terminals currently attached
85
+ var prefs = { };
86
+
87
+ //
88
+ // termTextOut
89
+ //
90
+ // Output debug text/level to terminal.
91
+ //
92
+
93
+ naanlib.onText(termTextOut);
94
+
95
+ function termTextOut(text, level) {
96
+ if (!text)
97
+ return;
98
+ if (termlist.length === 0) {
99
+ console.log(text); // make sure we can see early errors
100
+ if (!replqueue)
101
+ replqueue = [];
102
+ replqueue.push({text:text, level:level});
103
+ }
104
+ else {
105
+ termlist.forEach(function(term) {
106
+ var msg;
107
+ if (level)
108
+ msg = {
109
+ id: "debugtext",
110
+ text: text,
111
+ level: level
112
+ };
113
+ else
114
+ msg = {
115
+ id: "textout",
116
+ text: text
117
+ };
118
+ term.OnMessage(msg);
119
+ });
120
+ }
121
+ }
122
+
123
+ //
124
+ // takePending
125
+ //
126
+ // Read any pending Naan output and send to terminal.
127
+ //
128
+
129
+ function takePending() {
130
+ var outputq = replqueue;
131
+ replqueue = false;
132
+ if (outputq)
133
+ outputq.reverse();
134
+ while (outputq && outputq.length > 0) {
135
+ var item = outputq.pop();
136
+ termTextOut(item.text, item.level);
137
+ }
138
+ }
139
+
140
+
141
+ //==========================================================================
142
+ // New Terminal Interface
143
+ //--------------------------------------------------------------------------
144
+
145
+ //
146
+ // StateGet
147
+ //
148
+ // Report the saved state we are keeping for the terminal.
149
+ //
150
+
151
+ this.StateGet = function StateGet() {
152
+ if (termlist.length > 0)
153
+ replstate = termlist[0].StateSave(); // restore current buffer state to new terminal
154
+ return (replstate);
155
+ };
156
+
157
+ //
158
+ // Attach
159
+ //
160
+ // Attach a terminal to our interpreter and immediately start sending it messages.
161
+ //
162
+
163
+ this.Attach = function Attach(terminal) {
164
+ var repdex = termlist.indexOf(terminal);
165
+ if (repdex < 0)
166
+ termlist.push(terminal);
167
+ takePending(); // output all pending terminal messages
168
+ };
169
+
170
+ //
171
+ // Detach
172
+ //
173
+ // Detach the terminal from the interpreter.
174
+ //
175
+
176
+ this.Detach = function Detach(terminal) {
177
+ var repdex = termlist.indexOf(terminal);
178
+ if (repdex >= 0)
179
+ termlist.splice(repdex, 1);
180
+ if (termlist.length === 0)
181
+ replstate = terminal.StateSave(); // save ultimate repl state
182
+ };
183
+
184
+ //
185
+ // Interrupt
186
+ //
187
+ // Interrupt the interpreter in response to a user request.
188
+ //
189
+
190
+ this.Interrupt = function Interrupt(terminal) {
191
+ window.setTimeout(function () {
192
+ naanlib.escape();
193
+ }, 1);
194
+ };
195
+
196
+ //
197
+ // Return
198
+ //
199
+ // Enter line of text to instance.
200
+ //
201
+
202
+ this.Return = function Return(text, terminal) {
203
+ termlist.forEach(function(term) {
204
+ if (term !== terminal)
205
+ term.OnMessage({ // send text to other terminals
206
+ id: "textout",
207
+ text: text + "\r\n"
208
+ });
209
+ });
210
+ window.setTimeout(function () {
211
+ naanlib.textLine(text)
212
+ }, 1);
213
+ };
214
+
215
+ this.ReplyMessage = function ReplyMessage(data) { // "remote" -> "local"
216
+ termlist.forEach(function(term) {
217
+ if (term.OnMessageOut)
218
+ term.OnMessageOut(data);
219
+ });
220
+ return (data);
221
+ };
222
+
223
+ var nideListener;
224
+ this.OnMessage = function OnMessage(proc) {
225
+ nideListener = proc;
226
+ return (proc);
227
+ };
228
+
229
+ this.DispatchMessage = function DispatchMessage(data) { // "local" -> "remote"
230
+ if (nideListener)
231
+ setTimeout(function() {
232
+ nideListener(data)
233
+ }, 1);
234
+ }
235
+
236
+ this.ReplyDebugger = function ReplyDebugger(data) { // "remote" -> "local"
237
+ termlist.forEach(function(term) {
238
+ if (term.OnDebugOut)
239
+ term.OnDebugOut(data);
240
+ });
241
+ return (data);
242
+ };
243
+
244
+ var debugListener;
245
+ this.OnDebugger = function OnDebugger(proc) {
246
+ debugListener = proc;
247
+ return (proc);
248
+ };
249
+
250
+ this.DispatchDebugger = function DispatchDebugger(data) { // "local" -> "remote"
251
+ if (debugListener)
252
+ setTimeout(function() {
253
+ debugListener(data)
254
+ }, 1);
255
+ }
256
+
257
+ //
258
+ // Status
259
+ //
260
+ // Report status to the terminal.
261
+ //
262
+
263
+ setInterval(function() {
264
+ var samples = naanlib.status(1);
265
+ if (samples.length > 0)
266
+ termlist.forEach(function(term) {
267
+ if (term.OnStatus)
268
+ term.OnStatus({ // send status dictionary without ID
269
+ sample: samples[0]
270
+ });
271
+ });
272
+ }, 1000);
273
+
274
+ //
275
+ // Keystroke
276
+ //
277
+ // Enter keystroke to instance.
278
+ //
279
+
280
+ this.Keystroke = function Keystroke(text, keycode) {
281
+ console.log("Naan keystroke mode not implemented");
282
+ };
283
+
284
+ //
285
+ // Dimensions
286
+ //
287
+ // Report terminal dimensions to instance.
288
+ //
289
+
290
+ this.Dimensions = function Dimensions(rows, cols) {
291
+ console.log("Naan terminal dimensions now (" + rows + ", " + cols + ")");
292
+ };
293
+
294
+
295
+ //==========================================================================
296
+ // Host Environment
297
+ //--------------------------------------------------------------------------
298
+
299
+ //
300
+ // SavePref
301
+ //
302
+ // Save a persistent preference objectc that can be retrieved in the future.
303
+ //
304
+
305
+ this.SavePref = function SavePref(key, value) {
306
+ return (prefs[key] = value);
307
+ };
308
+
309
+ //
310
+ // LoadPref
311
+ //
312
+ // Load a previously-saved preference object for future retrieval.
313
+ //
314
+
315
+ this.LoadPref = function LoadPref(key) {
316
+ return (prefs[key]);
317
+ };
318
+
319
+ var saveEvent = new Event("NaanSave");
320
+
321
+ window.document.addEventListener("visibilitychange", function (e) {
322
+ if (window.document.visibilityState != "hidden")
323
+ return;
324
+ window.dispatchEvent(saveEvent);
325
+ saveLocal();
326
+ });
327
+
328
+ window.addEventListener("pagehide", function (e) {
329
+ window.dispatchEvent(saveEvent);
330
+ saveLocal();
331
+ });
332
+
333
+ window.addEventListener("unload", function (e) {
334
+ window.dispatchEvent(saveEvent);
335
+ saveLocal();
336
+ });
337
+
338
+ window.addEventListener("beforeunload", function (e) {
339
+ window.dispatchEvent(saveEvent);
340
+ saveLocal();
341
+ });
342
+
343
+ function makeState() {
344
+ var statedoc = {};
345
+ statedoc.curversion = kStateCurrentVersion;
346
+ statedoc.firstver = kStateFirstVersion;
347
+ statedoc.licensee = "MIT-License";
348
+ statedoc.verstring = "1.0.0-1";
349
+ statedoc.date = new Date().toISOString();
350
+ statedoc.prefs = prefs;
351
+ statedoc.naan = naanlib.saveState(true); // true to optimize, which is a bit slower
352
+ termlist.forEach(function(term) {
353
+ if (!replstate || term.termwin)
354
+ replstate = term.StateSave(); // state with separate window, otherwise any state
355
+ })
356
+ if (replstate)
357
+ statedoc.replstate = replstate;
358
+ return (statedoc);
359
+ }
360
+
361
+ function loadState(statedoc) {
362
+ if (statedoc===undefined || statedoc.naan === undefined
363
+ || statedoc.firstver > kStateCurrentVersion
364
+ || statedoc.curversion < kStateFirstVersion
365
+ || statedoc.licensee != "MIT-License"
366
+ || statedoc.verstring != "1.0.0-1")
367
+ return (false);
368
+ naanstate = statedoc.naan;
369
+ replstate = statedoc.replstate; // get terminal state, if any
370
+ if (typeof(statedoc.prefs) == "object")
371
+ prefs = statedoc.prefs;
372
+ return (true);
373
+ }
374
+
375
+ function saveLocal() {
376
+ /*jshint sub:true */
377
+ if (querystrings["nosave"])
378
+ return (false);
379
+ var statedoc = makeState();
380
+ var statestr = JSON.stringify(statedoc);
381
+ try {
382
+ if ("localStorage" in window && window["localStorage"] !== null)
383
+ {
384
+ localStorage.removeItem("NaanState_Nide");
385
+ if (localStorage.setItem("NaanState_Nide", statestr) !== undefined)
386
+ return (true);
387
+ }
388
+ } catch(e) {
389
+ console.log("save state failed: " + "(" + e + ")");
390
+ }
391
+ return (false);
392
+ }
393
+
394
+ function loadLocal() {
395
+ try {
396
+ /*jshint sub:true */
397
+ if ("localStorage" in window && window["localStorage"] !== null)
398
+ {
399
+ var statestr = localStorage.getItem("NaanState_Nide");
400
+ if (statestr)
401
+ return (loadState(JSON.parse(statestr)));
402
+ }
403
+ } catch(e) {
404
+ termTextOut("load state failed: " + "(" + e + ")");
405
+ }
406
+ return (false);
407
+ }
408
+
409
+ /*jshint sub:true */
410
+ if (querystrings["restart"] || !loadLocal())
411
+ { // don't load state or can't load state
412
+ naanlib.banner();
413
+ var hostpath = naanlib.js.r("path").dirname(window.location.href);
414
+ naanlib.start({
415
+ cmd: 'Naan.module.webparse("naan_init.nlg", "' + hostpath + '"' + ');;\r\n'
416
+ });
417
+ } else {
418
+ if (!replstate) { // saved state but never opened a terminal
419
+ naanlib.banner();
420
+ naanlib.textLine("print();;\n");
421
+ }
422
+ naanlib.start({
423
+ state: naanstate
424
+ });
425
+ }
426
+ };
427
+
428
+ /*jshint sub:true */
429
+ })(typeof exports === 'undefined'?(this.Naanlang?this.Naanlang:this.Naanlang={}) : exports);
430
+
431
+ new Naanlang.NaanControllerWeb();
@@ -0,0 +1,146 @@
1
+ /*
2
+ * env_webworker.js
3
+ * Naanlib
4
+ *
5
+ * Host Naan in the Browser worker environment.
6
+ *
7
+ * column positioning: // // !
8
+ *
9
+ * Copyright (c) 2019-2022 by Richard C. Zulch
10
+ *
11
+ */
12
+
13
+
14
+ /*
15
+ * Initialize
16
+ *
17
+ */
18
+
19
+ importScripts(
20
+ // remove "_omit" for debugging
21
+ "lib/core/naanlib.js"
22
+ );
23
+
24
+
25
+ (function(exports){
26
+
27
+
28
+ /*
29
+ * NaanControllerNodeWorker
30
+ *
31
+ * This is the Web worker that executes Naan.
32
+ *
33
+ */
34
+
35
+ exports.NaanControllerWebWorker = function NaanControllerWebWorker() {
36
+
37
+ "use strict";
38
+ /*jshint -W024 */
39
+ var undefined; // should be a keyword
40
+
41
+ //
42
+ // Initialization
43
+ //
44
+
45
+ var naanlib = new Naanlang.Naanlib();
46
+ var targSelf = this; // this is us, for access within nested functions
47
+ targSelf.anaan = naanlib.js.n;
48
+ naanlib.js.t = targSelf;
49
+
50
+ //
51
+ // Communications
52
+ //
53
+
54
+ naanlib.onText(function(text, level) {
55
+ if (level)
56
+ postMessage({
57
+ id: "debugtext",
58
+ text: text,
59
+ level: level
60
+ });
61
+ else
62
+ postMessage({
63
+ id: "textout",
64
+ text: text
65
+ });
66
+ });
67
+
68
+ setInterval(function() {
69
+ var samples = naanlib.status(1);
70
+ if (samples.length > 0)
71
+ postMessage({ // periodic worker status
72
+ id: "status",
73
+ status: {
74
+ sample: samples[0]
75
+ }
76
+ });
77
+ }, 1000);
78
+
79
+ targSelf.ReplyMessage = function ReplyMessage(data) {
80
+ postMessage({ // target is sending a message
81
+ id: "targetout",
82
+ data: data
83
+ });
84
+ return (data);
85
+ };
86
+
87
+ var targetListener;
88
+ targSelf.OnMessage = function OnMessage(proc) {
89
+ targetListener = proc;
90
+ return (proc);
91
+ };
92
+
93
+ targSelf.ReplyDebugger = function ReplyDebugger(data) {
94
+ postMessage({ // target is sending debug data
95
+ id: "debugout",
96
+ data: data
97
+ });
98
+ return (data);
99
+ };
100
+
101
+ var debugListener;
102
+ targSelf.OnDebugger = function OnDebugger(proc) {
103
+ debugListener = proc;
104
+ return (proc);
105
+ };
106
+
107
+ onmessage = function(e) {
108
+ var msg = e.data;
109
+ if (msg.id == "interrupt")
110
+ naanlib.escape();
111
+ else if (msg.id == "keyline")
112
+ naanlib.textLine(msg.text); // keyboard text from terminal
113
+ else if (msg.id == "start")
114
+ { // start execution with optional state
115
+ naanlib.banner();
116
+ naanlib.start({
117
+ state: msg.state,
118
+ cmd: msg.altcmd
119
+ });
120
+ }
121
+ else if (msg.id == "import")
122
+ importScripts(msg.script); // load any desired script
123
+ else if (msg.id == "targetin")
124
+ {
125
+ if (targetListener)
126
+ targetListener(msg.data); // target received a message
127
+ }
128
+ else if (msg.id == "debugin")
129
+ {
130
+ if (debugListener)
131
+ debugListener(msg.data); // target received a message
132
+ }
133
+ };
134
+
135
+ //
136
+ // Initialization complete
137
+ //
138
+
139
+ postMessage({
140
+ id: "loaded"
141
+ });
142
+ };
143
+
144
+ })(typeof exports === 'undefined'?(this.Naanlang?this.Naanlang:this.Naanlang={}) : exports);
145
+
146
+ new Naanlang.NaanControllerWebWorker();