@naanlang/naan 1.0.4 → 1.0.5

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 (39) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +8 -6
  3. package/bin/index.js +2 -2
  4. package/dist/env_web.js +25 -5
  5. package/dist/naan.min.js +4 -4
  6. package/frameworks/browser/https_request.nlg +120 -0
  7. package/frameworks/browser/sworker.js +19 -19
  8. package/frameworks/browser/terminals.nlg +5 -3
  9. package/frameworks/browser/workers.nlg +1 -0
  10. package/frameworks/client/psm_client.nlg +7 -1
  11. package/frameworks/common/common.nlg +95 -25
  12. package/frameworks/common/preferences.nlg +1 -0
  13. package/frameworks/common/watching.nlg +1 -0
  14. package/frameworks/node/https_request.nlg +119 -0
  15. package/frameworks/node/node.nlg +1 -0
  16. package/frameworks/project/proj_cliser.nlg +11 -3
  17. package/frameworks/project/proj_console.nlg +13 -4
  18. package/frameworks/project/proj_folder.nlg +10 -1
  19. package/frameworks/project/proj_lambda.nlg +13 -4
  20. package/frameworks/project/proj_static.nlg +11 -3
  21. package/frameworks/project/projects.nlg +80 -15
  22. package/frameworks/running/executors.nlg +1 -0
  23. package/lib/browser/env_web.js +27 -7
  24. package/lib/core/naanlib.js +4 -4
  25. package/package.json +1 -1
  26. package/plugins/serviceAws/aws/aws-sdk-node.min.js +2 -0
  27. package/plugins/serviceAws/aws/aws-sdk.min.js +2 -88
  28. package/plugins/serviceAws/aws_cloudwatchlogs.nlg +7 -6
  29. package/plugins/serviceAws/aws_dynamo.nlg +127 -44
  30. package/plugins/serviceAws/aws_lambda.nlg +11 -4
  31. package/plugins/serviceAws/aws_s3.nlg +44 -14
  32. package/plugins/serviceAws/dbt_aws.nlg +29 -36
  33. package/plugins/serviceAws/psm_aws.nlg +21 -16
  34. package/plugins/serviceAws/serviceAws.nlg +6 -4
  35. package/test/harness.nlg +3 -1
  36. package/test/test_01_core.nlg +5 -5
  37. package/test/test_02_context.nlg +4 -4
  38. package/test/test_03_jsinterop.nlg +9 -3
  39. package/plugins/serviceAws/aws_cognito.nlg +0 -76
@@ -27,7 +27,7 @@ closure proj_cliserInstance(projman, where, projID, local project) {
27
27
  project.name = where.name
28
28
  project.where = where
29
29
  project.projID = projID
30
- project.config = projConfig(projman, where)
30
+ project.config = projConfig(projman, where, projID)
31
31
 
32
32
  // create
33
33
  //
@@ -63,8 +63,16 @@ closure proj_cliserInstance(projman, where, projID, local project) {
63
63
  //
64
64
  // Run the project by building and then launching.
65
65
  //
66
- project.run = closure run(buildonly) {
67
- project.config.run(buildonly)
66
+ project.run = closure run(stage, buildonly) {
67
+ project.config.run(stage, buildonly)
68
+ }
69
+
70
+ // publish
71
+ //
72
+ // Publish the project according to the stage.
73
+ //
74
+ project.publish = closure publish(stage) {
75
+ project.config.publish(stage)
68
76
  }
69
77
 
70
78
  // close()
@@ -27,7 +27,7 @@ closure proj_consoleInstance(projman, where, projID, local project) {
27
27
  project.name = where.name
28
28
  project.where = where
29
29
  project.projID = projID
30
- project.config = projConfig(projman, where)
30
+ project.config = projConfig(projman, where, projID)
31
31
  project.runPageDebug = true // switch to Debug page on run
32
32
 
33
33
  // create
@@ -60,9 +60,18 @@ closure proj_consoleInstance(projman, where, projID, local project) {
60
60
 
61
61
  // run
62
62
  //
63
- // Run the project by building and then launching.
64
- project.run = closure run(buildonly) {
65
- project.config.run(buildonly)
63
+ // Run the project by building and then launching.
64
+ //
65
+ project.run = closure run(stage, buildonly) {
66
+ project.config.run(stage, buildonly)
67
+ }
68
+
69
+ // publish
70
+ //
71
+ // Publish the project according to the stage.
72
+ //
73
+ project.publish = closure publish(stage) {
74
+ project.config.publish(stage)
66
75
  }
67
76
 
68
77
  // close
@@ -61,11 +61,20 @@ closure proj_folderInstance(projman, where, projID, local project) {
61
61
  // run
62
62
  //
63
63
  // Run the project by building and then launching.
64
- project.run = closure run(buildonly) {
64
+ project.run = closure run(stage, buildonly) {
65
65
  debuglog("folder run project stub")
66
66
  list(false, { ok: true })
67
67
  }
68
68
 
69
+ // publish
70
+ //
71
+ // Publish the project according to the stage.
72
+ //
73
+ project.publish = closure publish(stage) {
74
+ debuglog("folder publish project stub")
75
+ list(false, { ok: true })
76
+ }
77
+
69
78
  // close
70
79
  //
71
80
  // Close the project, releasing resources.
@@ -27,7 +27,7 @@ closure proj_lambdaInstance(projman, where, projID, local project) {
27
27
  project.name = where.name
28
28
  project.where = where
29
29
  project.projID = projID
30
- project.config = projConfig(projman, where)
30
+ project.config = projConfig(projman, where, projID)
31
31
  project.runPageDebug = true // switch to Debug page on run
32
32
 
33
33
  // create
@@ -60,9 +60,18 @@ closure proj_lambdaInstance(projman, where, projID, local project) {
60
60
 
61
61
  // run
62
62
  //
63
- // Run the project by building and then launching.
64
- project.run = closure run(buildonly) {
65
- project.config.run(buildonly)
63
+ // Run the project by building and then launching.
64
+ //
65
+ project.run = closure run(stage, buildonly) {
66
+ project.config.run(stage, buildonly)
67
+ }
68
+
69
+ // publish
70
+ //
71
+ // Publish the project according to the stage.
72
+ //
73
+ project.publish = closure publish(stage) {
74
+ project.config.publish(stage)
66
75
  }
67
76
 
68
77
  // close
@@ -26,7 +26,7 @@ closure proj_staticInstance(projman, where, projID, local project) {
26
26
  project.name = where.name
27
27
  project.where = where
28
28
  project.projID = projID
29
- project.config = projConfig(projman, where)
29
+ project.config = projConfig(projman, where, projID)
30
30
 
31
31
  // create
32
32
  //
@@ -62,8 +62,16 @@ closure proj_staticInstance(projman, where, projID, local project) {
62
62
  //
63
63
  // Run the project by building and then launching.
64
64
  //
65
- project.run = closure run(buildonly) {
66
- project.config.run(buildonly)
65
+ project.run = closure run(stage, buildonly) {
66
+ project.config.run(stage, buildonly)
67
+ }
68
+
69
+ // publish
70
+ //
71
+ // Publish the project according to the stage.
72
+ //
73
+ project.publish = closure publish(stage) {
74
+ project.config.publish(stage)
67
75
  }
68
76
 
69
77
  // close()
@@ -23,6 +23,7 @@ closure ProjectManager(locate, track, dbname, local error, proj) {
23
23
  `(error, proj) = storageResources.ResourceManager(dbname, "Projects/")
24
24
  if error
25
25
  return(list(error))
26
+ proj.configLocal = proj.vault("configlocal") // local config storage
26
27
  proj.locate = locate // storage locations
27
28
  proj.track = track // execution tracking
28
29
  proj.types = []
@@ -226,7 +227,9 @@ closure projConnector(projman, projtype, local connector, watch) {
226
227
  // deleteResource
227
228
  //
228
229
  // Delete information for a project. The return value is (error, result) tuple.
229
- connector.deleteResource = function deleteResource(resID) {
230
+ connector.deleteResource = function deleteResource(resID, local localID) {
231
+ localID = resID.concat("-data")
232
+ projman.configLocal.deleteResource(localID) // remove local storage if there is any
230
233
  connector.vault.deleteResource(resID)
231
234
  watch.notify(projtype.classID, { deleted: [resID] })
232
235
  list(false, { ok: true})
@@ -293,7 +296,7 @@ closure projConnector(projman, projtype, local connector, watch) {
293
296
  *
294
297
  * Nide.proj/
295
298
  * nide_cliser.cfg - JSON definition of the project (see below)
296
- * NaanIDE_version.txt - [default] substitution file defining 1.0.4-1 etc.
299
+ * NaanIDE_version.txt - [default] substitution file defining 1.0.5-1 etc.
297
300
  * NaanIDE_version_builds.txt - [default] contains current build number as decimal string
298
301
  * build/ - [optional] default build output location
299
302
  * NaanIDE.lic - [optional] defines Zulch Laboratories, Inc. and other license info
@@ -306,6 +309,10 @@ closure projConnector(projman, projtype, local connector, watch) {
306
309
  * build: <build instructions dictionary>
307
310
  * }
308
311
  *
312
+ * A project configuration also stores local data that is not in any file, which is useful for
313
+ * items like accounts & locations, or credentials that should not be "on disk". Project data from
314
+ * the .cfg file is available in config.configDict, while local data is in config.localDict.
315
+ *
309
316
  * Given a new projConfig instance, you can either load (which fails of the project is not valid)
310
317
  * or create (which fails if the project already exists.) The load operation will update the where
311
318
  * argument with the actual name and type found. Unless other noted the methods all return standard
@@ -316,9 +323,11 @@ closure projConnector(projman, projtype, local connector, watch) {
316
323
  proj_configDataFolder = "Nide.proj/";
317
324
  proj_cliserConfigFile = "nide_cliser.cfg";
318
325
 
319
- closure projConfig(projman, where, local procon, fs, configpath) {
326
+ closure projConfig(projman, where, projID, local procon, fs, configpath) {
320
327
  procon = new(object, this)
321
328
  procon.name = where.name
329
+ if projID
330
+ procon.localID = projID.concat("-data")
322
331
 
323
332
  // validate
324
333
  //
@@ -376,6 +385,15 @@ closure projConfig(projman, where, local procon, fs, configpath) {
376
385
  return (list(Error("can't parse project configuration", where.path, exception))) }
377
386
  procon.where_name = where.name // copy name to config
378
387
  procon.where_typeID = where.typeID // copy typeID to config
388
+ if procon.localID {
389
+ `(error, data) = projman.configLocal.accessResource(procon.localID)
390
+ if data
391
+ procon.localDict = data
392
+ else {
393
+ procon.localDict = { }
394
+ projman.configLocal.addResource(procon.localID, procon.localDict)
395
+ }
396
+ }
379
397
  list(false, procon.configDict)
380
398
  }
381
399
 
@@ -384,6 +402,11 @@ closure projConfig(projman, where, local procon, fs, configpath) {
384
402
  // Write procon.configDict to our configuration file, returning a result tuple.
385
403
  //
386
404
  closure writeConfig(local error, info, data) {
405
+ if procon.localID {
406
+ `(error, data) = projman.configLocal.updateResource(procon.localID, procon.localDict)
407
+ if error
408
+ debuglog("projConfig.writeConfig cannot write local storage:", ErrorString(error))
409
+ }
387
410
  `(error, data) = fs.writeFile(configpath, JSONstringify(procon.configDict))
388
411
  if !error {
389
412
  procon.configMD5 = data
@@ -402,6 +425,8 @@ closure projConfig(projman, where, local procon, fs, configpath) {
402
425
  // not already be loaded. The provided name overrides any name in the where argument above, but
403
426
  // path and locationID must be specified. Returns a standard result tuple.
404
427
  //
428
+ // ### we need to update this for optional multiple-configuraiton builds
429
+ //
405
430
  procon.create = closure create(name, local error, data, configpath) {
406
431
  if procon.loaded
407
432
  return (list(Error("Project.create: project already loaded")))
@@ -498,15 +523,52 @@ closure projConfig(projman, where, local procon, fs, configpath) {
498
523
  procon.configDict = newconfig
499
524
  `(error, data) = writeConfig()
500
525
  }
501
-
526
+
527
+ // stages
528
+ //
529
+ // Return a tuple of stages in the project configuration.
530
+ //
531
+ procon.stages = function stages() {
532
+ procon.configDict."build-rules".*
533
+ }
534
+
535
+ // currentStage
536
+ //
537
+ // Validate and return the current stage of the project, or the first one if there isn't a
538
+ // previous selection, or false if no valid stages exist.
539
+ //
540
+ procon.currentStage = function currentStage(local stage, stagelist) {
541
+ stage = procon.localDict.currentStage
542
+ stagelist = stages()
543
+ if stage && !member(stage, stagelist)
544
+ stage = false
545
+ if stagelist && !stage
546
+ stage = stagelist.0
547
+ stage
548
+ }
549
+
502
550
  // buildrules
503
551
  //
504
- // Get the current build rules.
552
+ // Get the build rules for the named stage.
505
553
  //
506
- function buildrules(local rules) {
507
- rules = procon.configDict."build-rules".default // "default" will be switchable later
554
+ function buildrules(stage, local rules, common, rule, key) {
555
+ rules = procon.configDict."build-rules"[stage]
508
556
  if !rules
509
557
  rules = procon.configDict.build // fallback to old config structure
558
+ rules = new(rules)
559
+ common = procon.configDict."build-common"
560
+ if common {
561
+ for rule in common
562
+ if !rules[rule]
563
+ rules[rule] = common[rule] // common rule was not overridden
564
+ else if array(common[rule], rules[rule])
565
+ rules[rule] = common[rule].concat(rules[rule]) // merge common array with rule
566
+ else if dictionary(common[rule], rules[rule]) {
567
+ for key in common[rule] // merge common dictionary with rule
568
+ if !rules[rule][key]
569
+ rules[rule][key] = common[rule][key]
570
+ }
571
+ }
510
572
  rules
511
573
  }
512
574
 
@@ -514,16 +576,18 @@ closure projConfig(projman, where, local procon, fs, configpath) {
514
576
  //
515
577
  // Run the project by building and then launching.
516
578
  //
517
- procon.run = closure run(buildonly, local rules, builder, buildpath, error, buildnum) {
579
+ procon.run = closure run(stage, buildonly, local rules, builder, buildpath, error, buildnum) {
518
580
  if !procon.loaded
519
581
  return (list(Error("project not loaded")))
520
- rules = buildrules()
582
+ rules = buildrules(stage)
521
583
  if !rules || !rules.products
522
584
  return (list(Error("build rules missing or incomplete")))
523
585
  buildpath = fs.path.join(proj_configDataFolder, rules.products)
524
586
  rules.name = procon.where_name
525
587
  rules.typeID = procon.where_typeID
526
- `(error, builder) = Builder(rules, "debug", fs, "", buildpath)
588
+ if !rules.operation
589
+ rules.operation = "debug"
590
+ `(error, builder) = Builder(rules, rules.operation, fs, "", buildpath)
527
591
  if error
528
592
  return (list(error))
529
593
  `(error, buildnum) = builder.increment()
@@ -549,12 +613,13 @@ closure projConfig(projman, where, local procon, fs, configpath) {
549
613
  //
550
614
  // Publish the project to its configured location.
551
615
  //
552
- procon.publish = closure publish(local rules, publish, error, outfs, inpath) {
553
- rules = buildrules()
554
- publish = procon.configDict.publish
555
- if !rules || !publish.where
616
+ procon.publish = closure publish(stage, local rules, where, publish, error, outfs, inpath) {
617
+ rules = buildrules(stage)
618
+ publish = rules.publish
619
+ where = procon.localDict.publish[stage].where
620
+ if !rules || !where
556
621
  return (list(Error("no project publish location configured")))
557
- `(error, outfs) = projman.locate.connect(publish.where.locationID, "NideFS", publish.where.path)
622
+ `(error, outfs) = projman.locate.connect(where.locationID, "NideFS", where.path)
558
623
  if error
559
624
  return (list(Error("can't access publishing filesystem", error)))
560
625
  inpath = fs.path.join(proj_configDataFolder, rules.products, publish.input)
@@ -438,6 +438,7 @@ closure ExecutorTracker(local xtrak) {
438
438
  // Notify watchers of an update on an execution instance.
439
439
 
440
440
  xtrak.update = closure update(executor) {
441
+ debuglog("xtrack.update", executor.title)
441
442
  notify({ updated: [executor] })
442
443
  }
443
444
 
@@ -74,10 +74,12 @@ exports.NaanControllerWeb = function() {
74
74
  //
75
75
 
76
76
  var naanlib = new exports.Naanlib();
77
+ var dontSaveUntilWorking; // true when state loaded, must be reset to save state again
77
78
  var contSelf = this; // this is us, for access within nested functions
78
79
  exports.naancon = this; // access to this instance
79
80
  contSelf.anaan = naanlib.js.n;
80
81
  naanlib.js.t = contSelf;
82
+ naanlib.js.q = querystrings;
81
83
  var replstate; // latest known state of the REPL
82
84
  var naanstate; // desired state for the interpreter
83
85
  var replqueue; // text destined for terminal when opened
@@ -412,6 +414,16 @@ exports.NaanControllerWeb = function() {
412
414
  this.LoadPref = function LoadPref(key) {
413
415
  return (prefs[key]);
414
416
  };
417
+
418
+ //
419
+ // Working
420
+ //
421
+ // The application is working, so it is safe to save state.
422
+ //
423
+
424
+ this.Working = function Working() {
425
+ dontSaveUntilWorking = false;
426
+ };
415
427
 
416
428
  var saveEvent = new Event("NaanSave");
417
429
 
@@ -443,7 +455,7 @@ exports.NaanControllerWeb = function() {
443
455
  statedoc.curversion = kStateCurrentVersion;
444
456
  statedoc.firstver = kStateFirstVersion;
445
457
  statedoc.licensee = "MIT-License";
446
- statedoc.verstring = "1.0.4-1";
458
+ statedoc.verstring = "1.0.5-1";
447
459
  statedoc.date = new Date().toISOString();
448
460
  statedoc.prefs = prefs;
449
461
  statedoc.naan = naanlib.saveState(false); // true to optimize, which is a bit slower
@@ -461,7 +473,7 @@ exports.NaanControllerWeb = function() {
461
473
  || statedoc.firstver > kStateCurrentVersion
462
474
  || statedoc.curversion < kStateFirstVersion
463
475
  || statedoc.licensee != "MIT-License"
464
- || statedoc.verstring != "1.0.4-1")
476
+ || statedoc.verstring != "1.0.5-1")
465
477
  {
466
478
  localStorage.removeItem("NaanState_Hosted");
467
479
  return (false);
@@ -475,6 +487,10 @@ exports.NaanControllerWeb = function() {
475
487
 
476
488
  function saveLocal() {
477
489
  /*jshint sub:true */
490
+ if (dontSaveUntilWorking) { // saved state is problematic
491
+ localStorage.removeItem("NaanState_Hosted");
492
+ return (false);
493
+ }
478
494
  if (querystrings["nosave"])
479
495
  return (false);
480
496
  var statedoc = makeState();
@@ -498,6 +514,7 @@ exports.NaanControllerWeb = function() {
498
514
  if ("localStorage" in window && window["localStorage"] !== null)
499
515
  {
500
516
  var statestr = localStorage.getItem("NaanState_Hosted");
517
+ dontSaveUntilWorking = true;
501
518
  if (statestr)
502
519
  return (loadState(JSON.parse(statestr)));
503
520
  }
@@ -513,7 +530,8 @@ exports.NaanControllerWeb = function() {
513
530
  window.opener.Naanlang.naancon.DispatchMessage({
514
531
  op: "VsiteOpen",
515
532
  name: vsiteName,
516
- naancont: contSelf
533
+ naancont: contSelf,
534
+ title: vsiteName + " 1.0.5-1"
517
535
  });
518
536
  }
519
537
 
@@ -522,7 +540,8 @@ exports.NaanControllerWeb = function() {
522
540
  window.opener.Naanlang.naancon.DispatchMessage({
523
541
  op: "VsiteClose",
524
542
  name: vsiteName,
525
- naancont: contSelf
543
+ naancont: contSelf,
544
+ title: vsiteName + " 1.0.5-1"
526
545
  });
527
546
  termTextOut("\x1b[90m\x1b[3m".concat("\nwindow closed", "\x1b[0m\n"));
528
547
  }
@@ -541,9 +560,10 @@ exports.NaanControllerWeb = function() {
541
560
  naanlib.banner();
542
561
  naanlib.textLine("print();;\n");
543
562
  }
544
- naanlib.start({
545
- state: naanstate
546
- });
563
+ if (!naanlib.start({ state: naanstate })) { // state loading failed
564
+ localStorage.removeItem("NaanState_Hosted");
565
+ window.location.reload();
566
+ }
547
567
  }
548
568
 
549
569
  if (window.opener) {