@naanlang/naan 1.2.0 → 1.3.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 +1 -1
- package/README.md +1 -1
- package/bin/index.js +5 -2
- package/dist/env_web.js +11 -1
- package/dist/naan.min.js +5 -5
- package/frameworks/browser/https_request.nlg +2 -0
- package/frameworks/browser/sworker.js +23 -23
- package/frameworks/browser/terminals.nlg +132 -20
- package/frameworks/browser/workers.nlg +4 -1
- package/frameworks/browser/ws_client.nlg +9 -3
- package/frameworks/client/apiclient.nlg +8 -6
- package/frameworks/client/psm_client.nlg +4 -4
- package/frameworks/client/relaycon.nlg +5 -1
- package/frameworks/common/common.nlg +10 -4
- package/frameworks/node/apiserver.nlg +190 -4
- package/frameworks/node/worker.nlg +112 -10
- package/frameworks/node/ws_client.nlg +10 -3
- package/frameworks/project/build.nlg +13 -11
- package/frameworks/project/projects.nlg +7 -5
- package/frameworks/running/executors.nlg +124 -34
- package/frameworks/running/taskexec.nlg +5 -1
- package/lib/browser/env_web.js +17 -7
- package/lib/browser/env_webworker.js +22 -3
- package/lib/core/naanlib.js +5 -5
- package/lib/env_node.js +15 -4
- package/lib/env_nodeworker.js +21 -1
- package/package.json +8 -5
- package/plugins/serviceAws/aws/aws-sdk-node.min.js +2 -2
- package/plugins/serviceAws/aws/aws-sdk.min.js +3 -2
- package/plugins/serviceAws/aws_dynamo.nlg +19 -19
- package/plugins/serviceAws/dbt_aws.nlg +1 -1
- package/plugins/serviceYC/generic_api.yaml +36 -0
- package/plugins/serviceYC/naanide-relay-index.js +148 -0
- package/plugins/serviceYC/serviceYC.nlg +60 -0
- package/plugins/serviceYC/yc_apigateway.nlg +205 -0
- package/plugins/serviceYC/yc_function.nlg +163 -0
- package/plugins/serviceYC/yc_vm.nlg +207 -0
- package/test/test_02_context.nlg +1 -1
- package/test/test_03_jsinterop.nlg +2 -2
- package/test/test_05_strings.nlg +7 -4
- package/test/test_07_lingo.nlg +1 -1
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
* encoding: <string> // "binary" to receive binary data as arrayBuffer
|
|
25
25
|
* range: <string> // sets range header
|
|
26
26
|
* headers: [`(key, value)] // add header(s) to the request, overriding defaults
|
|
27
|
+
* keepalive: <boolean> // true to send data at unload
|
|
27
28
|
* debug: <boolean> // log errors and status results
|
|
28
29
|
* }
|
|
29
30
|
*
|
|
@@ -55,6 +56,7 @@ closure HttpsApiRequest(url, options,
|
|
|
55
56
|
headers: { }
|
|
56
57
|
redirect: 'follow'
|
|
57
58
|
referrerPolicy: 'no-referrer'
|
|
59
|
+
keepalive: options.keepalive || undefined
|
|
58
60
|
}
|
|
59
61
|
if options.method
|
|
60
62
|
fetchOptions.method = options.method
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
*
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
|
-
var CurrentCacheName = "Naanlang-1.
|
|
39
|
+
var CurrentCacheName = "Naanlang-1.3.0+1";
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
//
|
|
@@ -92,18 +92,18 @@ var terminated; // flag that this service worker
|
|
|
92
92
|
var pubVersion = event.data.hereIsMyVersion;
|
|
93
93
|
var sourceId = event.source.id; // client id of sender of message
|
|
94
94
|
msgPorts[sourceId] = msgport;
|
|
95
|
-
console.log("[1.
|
|
96
|
-
if (pubVersion != "1.
|
|
95
|
+
console.log("[1.3.0+1] received new msgport for", sourceId, pubID, "-", pubVersion);
|
|
96
|
+
if (pubVersion != "1.3.0+1") {
|
|
97
97
|
if (upgradeMsgPorts) { // if not activated
|
|
98
|
-
console.log("[1.
|
|
98
|
+
console.log("[1.3.0+1] update pending for", sourceId);
|
|
99
99
|
upgradeMsgPorts[sourceId] = msgport;
|
|
100
100
|
}
|
|
101
101
|
else {
|
|
102
102
|
msgport.postMessage({ // notify new version available
|
|
103
103
|
id: "upgrade",
|
|
104
|
-
version: "1.
|
|
104
|
+
version: "1.3.0+1"
|
|
105
105
|
});
|
|
106
|
-
console.log("[1.
|
|
106
|
+
console.log("[1.3.0+1] update sent for:", sourceId);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
Reaper(); // clean up obsolete info
|
|
@@ -134,10 +134,10 @@ var terminated; // flag that this service worker
|
|
|
134
134
|
msgport.onmessage = function(msg) {
|
|
135
135
|
msg = msg.data;
|
|
136
136
|
if (msg.id == "skipWaiting") { // try to activate this SW now
|
|
137
|
-
console.log("[1.
|
|
137
|
+
console.log("[1.3.0+1] attempting skipWaiting");
|
|
138
138
|
self.skipWaiting();
|
|
139
139
|
} else if (msg.id == "terminate") { // termiante this SW now
|
|
140
|
-
console.log("[1.
|
|
140
|
+
console.log("[1.3.0+1] terminated");
|
|
141
141
|
terminate();
|
|
142
142
|
} else if (msg.id == "abortURL") { // abort an I/O transaction
|
|
143
143
|
var href = new URL(msg.url).href;
|
|
@@ -150,7 +150,7 @@ var terminated; // flag that this service worker
|
|
|
150
150
|
} else if (msg.id == "response") // response from fetch request
|
|
151
151
|
processResponse(msg);
|
|
152
152
|
else if (msg.id == "text") // just log some text
|
|
153
|
-
console.log("[1.
|
|
153
|
+
console.log("[1.3.0+1] msg received:", msg.text);
|
|
154
154
|
};
|
|
155
155
|
|
|
156
156
|
// send text to IDE log
|
|
@@ -161,7 +161,7 @@ var terminated; // flag that this service worker
|
|
|
161
161
|
// don't clutter the log
|
|
162
162
|
msgport.postMessage({
|
|
163
163
|
id: "text",
|
|
164
|
-
text: "port received by 1.
|
|
164
|
+
text: "port received by 1.3.0+1",
|
|
165
165
|
});
|
|
166
166
|
*/
|
|
167
167
|
if (--pending === 0)
|
|
@@ -178,7 +178,7 @@ var terminated; // flag that this service worker
|
|
|
178
178
|
includeUncontrolled: true
|
|
179
179
|
}).then(function(clientList) {
|
|
180
180
|
clientList.every(function(client) {
|
|
181
|
-
console.log("[1.
|
|
181
|
+
console.log("[1.3.0+1] requesting new msgport for", client.id);
|
|
182
182
|
++pending;
|
|
183
183
|
client.postMessage({ // tell client(s) we need this fetch source
|
|
184
184
|
msg: "Naan_need_fetch_port",
|
|
@@ -224,12 +224,12 @@ function Reaper() {
|
|
|
224
224
|
clients[clientList[clidex].id] = clientList[clidex];
|
|
225
225
|
for (var sourceId in msgPorts)
|
|
226
226
|
if (!clients[sourceId]) {
|
|
227
|
-
console.log("[1.
|
|
227
|
+
console.log("[1.3.0+1] source gone:", sourceId);
|
|
228
228
|
delete msgPorts[sourceId]; // no longer a source
|
|
229
229
|
}
|
|
230
230
|
for (var clientId in fetchPorts)
|
|
231
231
|
if (!clients[clientId]) {
|
|
232
|
-
console.log("[1.
|
|
232
|
+
console.log("[1.3.0+1] client gone:", clientId);
|
|
233
233
|
delete fetchPorts[clientId]; // no longer a client
|
|
234
234
|
}
|
|
235
235
|
for (var fqdex = 0; fqdex < fetchQueue.length; ++fqdex) {
|
|
@@ -263,16 +263,16 @@ function ClearCaches() {
|
|
|
263
263
|
return (Promise.all(
|
|
264
264
|
cacheNames.map(function(cacheName) {
|
|
265
265
|
if (cacheName != CurrentCacheName) {
|
|
266
|
-
console.log('[1.
|
|
266
|
+
console.log('[1.3.0+1] deleting old cache:', cacheName);
|
|
267
267
|
return (caches.delete(cacheName));
|
|
268
268
|
}
|
|
269
269
|
})
|
|
270
270
|
));
|
|
271
271
|
}).then(function() { // claim all clients
|
|
272
|
-
console.log('[1.
|
|
272
|
+
console.log('[1.3.0+1] claiming clients');
|
|
273
273
|
return (self.clients.claim());
|
|
274
274
|
}).then(function() {
|
|
275
|
-
console.log('[1.
|
|
275
|
+
console.log('[1.3.0+1] clients claimed');
|
|
276
276
|
return (Promise.resolve(true));
|
|
277
277
|
});
|
|
278
278
|
return (promise);
|
|
@@ -315,7 +315,7 @@ function GetClientResponse(event, urlpath) {
|
|
|
315
315
|
msgport.postMessage({
|
|
316
316
|
id: "fetch",
|
|
317
317
|
seq: seqno,
|
|
318
|
-
version: "1.
|
|
318
|
+
version: "1.3.0+1",
|
|
319
319
|
request: {
|
|
320
320
|
method: event.request.method,
|
|
321
321
|
url: event.request.url
|
|
@@ -363,7 +363,7 @@ function GetClientResponse(event, urlpath) {
|
|
|
363
363
|
*/
|
|
364
364
|
|
|
365
365
|
self.addEventListener('install', function(event) {
|
|
366
|
-
console.log("[1.
|
|
366
|
+
console.log("[1.3.0+1] install");
|
|
367
367
|
self.skipWaiting();
|
|
368
368
|
});
|
|
369
369
|
|
|
@@ -376,20 +376,20 @@ self.addEventListener('install', function(event) {
|
|
|
376
376
|
*/
|
|
377
377
|
|
|
378
378
|
self.addEventListener('activate', function(event) {
|
|
379
|
-
console.log("[1.
|
|
379
|
+
console.log("[1.3.0+1] activate");
|
|
380
380
|
self.clients.matchAll({ // for debugging, list controlled clients
|
|
381
381
|
includeUncontrolled: true
|
|
382
382
|
}).then(function(clientList) {
|
|
383
383
|
var urls = clientList.map(function(client) {
|
|
384
384
|
return (client.url);
|
|
385
385
|
});
|
|
386
|
-
console.log('[1.
|
|
386
|
+
console.log('[1.3.0+1] matching clients:', urls.join(', '));
|
|
387
387
|
});
|
|
388
388
|
var promise = ClearCaches().then(function() {
|
|
389
389
|
for (var sourceId in upgradeMsgPorts) {
|
|
390
390
|
upgradeMsgPorts[sourceId].postMessage({ // notify new version available
|
|
391
391
|
id: "upgrade",
|
|
392
|
-
version: "1.
|
|
392
|
+
version: "1.3.0+1"
|
|
393
393
|
});
|
|
394
394
|
}
|
|
395
395
|
upgradeMsgPorts = false;
|
|
@@ -421,7 +421,7 @@ self.addEventListener('fetch', function(event) {
|
|
|
421
421
|
var promise;
|
|
422
422
|
var url = new URL(request.url);
|
|
423
423
|
var nocache = request.method != "GET"
|
|
424
|
-
|| url.search.length !== 0 && url.searchParams.get("naanver") !== "
|
|
424
|
+
|| url.search.length !== 0 && url.searchParams.get("naanver") !== "73538d9da7b765535859c873f6955312"
|
|
425
425
|
|| request.headers.get('range');
|
|
426
426
|
if (url.pathname.startsWith("/run/")) {
|
|
427
427
|
nocache = true;
|
|
@@ -455,7 +455,7 @@ self.addEventListener('fetch', function(event) {
|
|
|
455
455
|
statusText: "Request Cancelled"
|
|
456
456
|
}));
|
|
457
457
|
}
|
|
458
|
-
console.log("[1.
|
|
458
|
+
console.log("[1.3.0+1] fetch failed", request.url, e);
|
|
459
459
|
return (new Response(undefined, {
|
|
460
460
|
status: 404,
|
|
461
461
|
statusText: "Fetch Failed"
|
|
@@ -10,6 +10,13 @@
|
|
|
10
10
|
*
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
/*
|
|
14
|
+
* globals
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
workers;
|
|
19
|
+
|
|
13
20
|
|
|
14
21
|
/*
|
|
15
22
|
* TermHost
|
|
@@ -55,13 +62,19 @@ closure TermHost(track, api, name, options, local target, nlregex, xtarg)
|
|
|
55
62
|
|
|
56
63
|
// connect
|
|
57
64
|
// Connect with the host if not already connected.
|
|
58
|
-
closure connect(local
|
|
65
|
+
closure connect(local url, pending) {
|
|
59
66
|
if target.ws
|
|
60
67
|
return(list(false, { connected: true }))
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
try {
|
|
69
|
+
url = xnew(window.URL, api.url)
|
|
70
|
+
} catch {
|
|
71
|
+
return(list(Error("invalid URL ${api.url}", exception)))
|
|
72
|
+
}
|
|
73
|
+
if url.protocol == "https:"
|
|
74
|
+
url.protocol = "wss:"
|
|
75
|
+
else
|
|
76
|
+
url.protocol = "ws:"
|
|
77
|
+
target.ws = xnew(window.WebSocket, url.href)
|
|
65
78
|
pending = new(nonce)
|
|
66
79
|
|
|
67
80
|
// onopen
|
|
@@ -98,8 +111,10 @@ closure TermHost(track, api, name, options, local target, nlregex, xtarg)
|
|
|
98
111
|
if msg.id == "spawned" || msg.id == "workerlist" || msg.id == "termination"
|
|
99
112
|
return (hostWorkerUpdate(msg))
|
|
100
113
|
if msg.id != "targetout" {
|
|
101
|
-
if msg.id == "status"
|
|
114
|
+
if msg.id == "status" {
|
|
102
115
|
target.lastStatus = milliseconds()
|
|
116
|
+
target.execSetStatus(msg.status)
|
|
117
|
+
}
|
|
103
118
|
if target.msgQueue {
|
|
104
119
|
if msg.id != "status"
|
|
105
120
|
target.msgQueue.push(msg)
|
|
@@ -416,7 +431,9 @@ closure TermHost(track, api, name, options, local target, nlregex, xtarg)
|
|
|
416
431
|
|
|
417
432
|
closure TermLocal(track, name, options, local target, nlregex, listener)
|
|
418
433
|
{
|
|
419
|
-
global(js, window)
|
|
434
|
+
global(js, window, workers)
|
|
435
|
+
if !dictionary(workers)
|
|
436
|
+
workers = {}
|
|
420
437
|
options = merge({
|
|
421
438
|
type: "Local"
|
|
422
439
|
}, options)
|
|
@@ -444,6 +461,8 @@ closure TermLocal(track, name, options, local target, nlregex, listener)
|
|
|
444
461
|
return (list(Error("Local environment does not support workers")))
|
|
445
462
|
target.worker = xnew(window.Worker, "env_webworker.js")
|
|
446
463
|
listener = target.worker
|
|
464
|
+
target.guid = UUID()
|
|
465
|
+
workers[target.guid] = target
|
|
447
466
|
}
|
|
448
467
|
|
|
449
468
|
// onmessage
|
|
@@ -455,8 +474,10 @@ closure TermLocal(track, name, options, local target, nlregex, listener)
|
|
|
455
474
|
destroy()
|
|
456
475
|
return }
|
|
457
476
|
else if msg.id != "targetout" && msg.id != "loaded" {
|
|
458
|
-
if msg.id == "status"
|
|
477
|
+
if msg.id == "status" {
|
|
459
478
|
target.lastStatus = milliseconds()
|
|
479
|
+
target.execSetStatus(msg.status)
|
|
480
|
+
}
|
|
460
481
|
if target.msgQueue {
|
|
461
482
|
if msg.id != "status"
|
|
462
483
|
target.msgQueue.push(msg)
|
|
@@ -468,6 +489,7 @@ closure TermLocal(track, name, options, local target, nlregex, listener)
|
|
|
468
489
|
// The worker had an error.
|
|
469
490
|
|
|
470
491
|
target.worker.addEventListener("error", function(e) {
|
|
492
|
+
debuglog("TermLocal worker error:", e.message)
|
|
471
493
|
target.execClosed(Error("instance error", e.message))
|
|
472
494
|
})
|
|
473
495
|
|
|
@@ -531,8 +553,11 @@ closure TermLocal(track, name, options, local target, nlregex, listener)
|
|
|
531
553
|
altcmd: options.startup.initcmds
|
|
532
554
|
})
|
|
533
555
|
target.started = true
|
|
556
|
+
} else if msg.id == "targetsend" {
|
|
557
|
+
msg.data._guid = target.guid
|
|
558
|
+
js.t.DispatchMessage(msg.data)
|
|
534
559
|
}
|
|
535
|
-
|
|
560
|
+
}
|
|
536
561
|
|
|
537
562
|
//
|
|
538
563
|
// target.DebugCmd
|
|
@@ -642,6 +667,82 @@ closure TermLocal(track, name, options, local target, nlregex, listener)
|
|
|
642
667
|
};
|
|
643
668
|
|
|
644
669
|
|
|
670
|
+
/*
|
|
671
|
+
* termMainProxy
|
|
672
|
+
*
|
|
673
|
+
* column positioning: // // !
|
|
674
|
+
* Make a browser proxy representing the main thread. This runs inside the worker and allows it
|
|
675
|
+
* to do remote execution with Main.
|
|
676
|
+
*
|
|
677
|
+
*/
|
|
678
|
+
|
|
679
|
+
closure termMainProxy(track, name, options, local target) {
|
|
680
|
+
global(js)
|
|
681
|
+
target = require("../running/executors.nlg").ExecutorBase(track, "mainProxy", name)
|
|
682
|
+
target.name = name
|
|
683
|
+
|
|
684
|
+
//
|
|
685
|
+
// target.PostMessage
|
|
686
|
+
//
|
|
687
|
+
// Post a message to the main thread.
|
|
688
|
+
//
|
|
689
|
+
target.PostMessage = function PostMessage(data) {
|
|
690
|
+
js.t.DispatchMessage(data)
|
|
691
|
+
list(false, { posted: true })
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
//
|
|
695
|
+
// onreceive
|
|
696
|
+
//
|
|
697
|
+
// Process a received message from the main thread, typically in response.
|
|
698
|
+
//
|
|
699
|
+
function onreceive(data) {
|
|
700
|
+
target.execReceived(data)
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// destroy
|
|
704
|
+
//
|
|
705
|
+
// Destroy the execution instance.
|
|
706
|
+
//
|
|
707
|
+
target.destroy = function destroy() {
|
|
708
|
+
target.execClosed(Error("instance destroyed"))
|
|
709
|
+
track.delete(target)
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
js.t.OnReceive(onreceive.proc)
|
|
713
|
+
track.add(target)
|
|
714
|
+
|
|
715
|
+
// finis
|
|
716
|
+
|
|
717
|
+
list(false, target)
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
/*
|
|
722
|
+
* WorkerToMain
|
|
723
|
+
*
|
|
724
|
+
* Connect our worker to the main thread, returning a result tuple with an executor representing
|
|
725
|
+
* Main. Use this to create a context object for Main, allowing remote evaluation.
|
|
726
|
+
*
|
|
727
|
+
*/
|
|
728
|
+
|
|
729
|
+
closure WorkerToMain(local nideRunning, track) {
|
|
730
|
+
// mainProxy -- link tracker to main thread proxy
|
|
731
|
+
function mainProxy(track, name, options) {
|
|
732
|
+
termMainProxy(track, name, options)
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
if !js.s {
|
|
736
|
+
error = Error("WorkerToMain only available in browser workers")
|
|
737
|
+
return (list(error))
|
|
738
|
+
}
|
|
739
|
+
nideRunning = require("frameworks/running/executors.nlg")
|
|
740
|
+
track = nideRunning.ExecutorTracker()
|
|
741
|
+
track.register(mainProxy, "proxy")
|
|
742
|
+
track.spawn("proxy") // returns result tuple
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
|
|
645
746
|
/*
|
|
646
747
|
* findIDEtarget
|
|
647
748
|
*
|
|
@@ -668,7 +769,7 @@ closure findIDEtarget(track, name, workerID, naancont, local target) {
|
|
|
668
769
|
*/
|
|
669
770
|
|
|
670
771
|
closure termIDE(track, name, workerID, naancont, title, local target, connected) {
|
|
671
|
-
global()
|
|
772
|
+
global(workers)
|
|
672
773
|
target = findIDEtarget(track, name, workerID, naancont)
|
|
673
774
|
if target { // new naancont on existing target
|
|
674
775
|
target.updateController(naancont)
|
|
@@ -682,23 +783,31 @@ closure termIDE(track, name, workerID, naancont, title, local target, connected)
|
|
|
682
783
|
target.workerID = workerID
|
|
683
784
|
target.naancont = naancont
|
|
684
785
|
connected = []
|
|
685
|
-
|
|
786
|
+
|
|
787
|
+
// replyHook
|
|
686
788
|
//
|
|
789
|
+
// Intercept the ReplyMessage function to see if we should handle it.
|
|
790
|
+
//
|
|
791
|
+
function replyHook(data) {
|
|
792
|
+
if data._guid
|
|
793
|
+
workers[data._guid].worker.postMessage({
|
|
794
|
+
id: "targetreceive"
|
|
795
|
+
data: data
|
|
796
|
+
})
|
|
797
|
+
}
|
|
798
|
+
|
|
687
799
|
// target.DebugCmd
|
|
688
800
|
//
|
|
689
801
|
// Post a debug command to the target, ourselves.
|
|
690
802
|
//
|
|
691
|
-
|
|
692
803
|
target.DebugCmd = function DebugCmd(data) {
|
|
693
804
|
naancont.DispatchDebugger(data)
|
|
694
805
|
}
|
|
695
806
|
|
|
696
|
-
//
|
|
697
807
|
// target.PostMessage
|
|
698
808
|
//
|
|
699
809
|
// Post a message to the target, ourselves.
|
|
700
810
|
//
|
|
701
|
-
|
|
702
811
|
target.PostMessage = function PostMessage(data) {
|
|
703
812
|
naancont.DispatchMessage(data)
|
|
704
813
|
list(false, { posted: true })
|
|
@@ -707,7 +816,7 @@ closure termIDE(track, name, workerID, naancont, title, local target, connected)
|
|
|
707
816
|
// termAttach
|
|
708
817
|
//
|
|
709
818
|
// Create a closure for an attaching terminal.
|
|
710
|
-
|
|
819
|
+
//
|
|
711
820
|
target.termAttach = closure termAttach(term, db, statusCB, local connection, inbound) {
|
|
712
821
|
connection = new(object, this)
|
|
713
822
|
|
|
@@ -720,6 +829,7 @@ closure termIDE(track, name, workerID, naancont, title, local target, connected)
|
|
|
720
829
|
}
|
|
721
830
|
|
|
722
831
|
function onstatus(status) {
|
|
832
|
+
target.execSetStatus(status)
|
|
723
833
|
statusCB(target, status)
|
|
724
834
|
}
|
|
725
835
|
|
|
@@ -783,7 +893,7 @@ closure termIDE(track, name, workerID, naancont, title, local target, connected)
|
|
|
783
893
|
// updateController
|
|
784
894
|
//
|
|
785
895
|
// Update the naan controller on this target, which means updating for all the terminals.
|
|
786
|
-
|
|
896
|
+
//
|
|
787
897
|
target.updateController = function updateController(newnc, local conn) {
|
|
788
898
|
naancont = newnc
|
|
789
899
|
target.naancont = newnc
|
|
@@ -801,7 +911,7 @@ closure termIDE(track, name, workerID, naancont, title, local target, connected)
|
|
|
801
911
|
// vsiteRefresh
|
|
802
912
|
//
|
|
803
913
|
// The vsite upon which we are based has changed.
|
|
804
|
-
|
|
914
|
+
//
|
|
805
915
|
target.vsiteRefresh = function vsiteRefresh(url_origin) {
|
|
806
916
|
naancont.VsiteRefresh(url_origin)
|
|
807
917
|
}
|
|
@@ -809,12 +919,13 @@ closure termIDE(track, name, workerID, naancont, title, local target, connected)
|
|
|
809
919
|
// destroy
|
|
810
920
|
//
|
|
811
921
|
// Destroy the execution instance.
|
|
812
|
-
|
|
922
|
+
//
|
|
813
923
|
target.destroy = function destroy() {
|
|
814
924
|
target.execClosed(Error("instance destroyed"))
|
|
815
925
|
track.delete(target)
|
|
816
926
|
}
|
|
817
927
|
|
|
928
|
+
js.t.OnReplyHook(replyHook.proc)
|
|
818
929
|
track.add(target)
|
|
819
930
|
|
|
820
931
|
// finis
|
|
@@ -858,13 +969,14 @@ closure termInstallVirtualWatcher(track, naancont) {
|
|
|
858
969
|
*/
|
|
859
970
|
|
|
860
971
|
function termInit(local manifest) {
|
|
861
|
-
|
|
862
|
-
|
|
972
|
+
manifest = `(TermHost, TermLocal, termMainProxy, WorkerToMain, findIDEtarget, termIDE,
|
|
973
|
+
termInstallVirtualWatcher, termInit)
|
|
863
974
|
|
|
864
975
|
Naan.module.build(module.id, "terminals", function(modobj, compobj) {
|
|
865
976
|
require("./browser.nlg")
|
|
866
977
|
compobj.manifest = manifest
|
|
867
978
|
modobj.exports.TermLocal = TermLocal
|
|
868
979
|
modobj.exports.TermHost = TermHost
|
|
980
|
+
modobj.exports.WorkerToMain = WorkerToMain
|
|
869
981
|
})
|
|
870
982
|
} ();
|
|
@@ -234,7 +234,10 @@ closure ScopedServiceWorker(pubID, pubVersion, callback, local scoper, result) {
|
|
|
234
234
|
scoper = new(object, ScopedServiceWorker)
|
|
235
235
|
scoper.scopes = {}
|
|
236
236
|
scoper.serv = ServiceWorker(pubID, pubVersion)
|
|
237
|
-
|
|
237
|
+
scoper.root = js.r("path").dirname(js.w.location.pathname) // normally "/", but could be subfolder
|
|
238
|
+
if scoper.root.slice(-1) != "/"
|
|
239
|
+
scoper.root = scoper.root.concat("/") // must end in "/"
|
|
240
|
+
result = scoper.serv.register(scoper.root, closure(error, data, local response, filepath, scope) {
|
|
238
241
|
if data.message == "fetch" {
|
|
239
242
|
response = {
|
|
240
243
|
id: "response"
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* column positioning: // // !
|
|
7
7
|
*
|
|
8
|
-
* Copyright (c) 2023 by Richard C. Zulch
|
|
8
|
+
* Copyright (c) 2023-2024 by Richard C. Zulch
|
|
9
9
|
*
|
|
10
10
|
*/
|
|
11
11
|
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
* onmessage: <proc>(e, message) // message received
|
|
23
23
|
* onerror: <proc>(e) // error occurred
|
|
24
24
|
* onclose: <proc>(e) // connection has closed
|
|
25
|
+
* query: <string> // query string starting with ? for insecure connections
|
|
26
|
+
* querys: <string> // query string starting with ? for secure connections
|
|
25
27
|
* }
|
|
26
28
|
*
|
|
27
29
|
*/
|
|
@@ -37,10 +39,14 @@ closure WebSocket(options, local wsock) {
|
|
|
37
39
|
//
|
|
38
40
|
// Connect with the host if not already connected, returning a result tuple.
|
|
39
41
|
//
|
|
40
|
-
wsock.connect = closure connect(local pending) {
|
|
42
|
+
wsock.connect = closure connect(local url, pending) {
|
|
41
43
|
if wsock.ws
|
|
42
44
|
return (list(false, { open: true }))
|
|
43
|
-
|
|
45
|
+
if window.location.protocol == "https:"
|
|
46
|
+
url = "wss://${options.host}${options.querys||''}"
|
|
47
|
+
else
|
|
48
|
+
url = "ws://${options.host}${options.query||''}"
|
|
49
|
+
wsock.ws = xnew(window.WebSocket, url)
|
|
44
50
|
pending = new(nonce)
|
|
45
51
|
|
|
46
52
|
// onopen
|
|
@@ -22,7 +22,9 @@ closure NideAPIclient(url, guid, apiRequester, local client) {
|
|
|
22
22
|
global()
|
|
23
23
|
client = new(object, this)
|
|
24
24
|
if !url.match(RegExp("^https?:\/\/", "i"))
|
|
25
|
-
url = "http://${url}"
|
|
25
|
+
url = "http://${url}" // a protocol is required
|
|
26
|
+
if url.slice(-1) != "/"
|
|
27
|
+
url = url.concat("/") // must end in "/"
|
|
26
28
|
client.url = url
|
|
27
29
|
client.guid = guid
|
|
28
30
|
client.notifyAfter = 0
|
|
@@ -42,7 +44,7 @@ closure NideAPIclient(url, guid, apiRequester, local client) {
|
|
|
42
44
|
//
|
|
43
45
|
|
|
44
46
|
client.docs = closure docs(local error, content, extra) {
|
|
45
|
-
`(error, content, extra) = clientRequest(url
|
|
47
|
+
`(error, content, extra) = clientRequest(url)
|
|
46
48
|
printline(content)
|
|
47
49
|
}
|
|
48
50
|
|
|
@@ -51,7 +53,7 @@ closure NideAPIclient(url, guid, apiRequester, local client) {
|
|
|
51
53
|
//
|
|
52
54
|
|
|
53
55
|
client.status = closure status(cbStatus, timeoutms, local query, error, content, extra, queued) {
|
|
54
|
-
query = EncodeQuery("
|
|
56
|
+
query = EncodeQuery("status/?", {
|
|
55
57
|
timeout: timeoutms
|
|
56
58
|
after: client.notifyAfter
|
|
57
59
|
})
|
|
@@ -75,7 +77,7 @@ closure NideAPIclient(url, guid, apiRequester, local client) {
|
|
|
75
77
|
//
|
|
76
78
|
|
|
77
79
|
client.get = closure get(path, options, local error, content, extra) {
|
|
78
|
-
`(error, content, extra) = clientRequest(url.concat(
|
|
80
|
+
`(error, content, extra) = clientRequest(url.concat(path))
|
|
79
81
|
if !error && extra.status != 200
|
|
80
82
|
error = Error("readFile failed: ".concat(extra.status), {
|
|
81
83
|
status: extra.status
|
|
@@ -91,7 +93,7 @@ closure NideAPIclient(url, guid, apiRequester, local client) {
|
|
|
91
93
|
//
|
|
92
94
|
|
|
93
95
|
client.readFile = closure readFile(filepath, options, local query, error, content, extra) {
|
|
94
|
-
query = EncodeQuery("
|
|
96
|
+
query = EncodeQuery("readfile/?", {
|
|
95
97
|
path: filepath
|
|
96
98
|
})
|
|
97
99
|
`(error, content, extra) = clientRequest(url.concat(query), options)
|
|
@@ -112,7 +114,7 @@ closure NideAPIclient(url, guid, apiRequester, local client) {
|
|
|
112
114
|
|
|
113
115
|
client.psmRemote = closure psmRemote(options, data, callback,
|
|
114
116
|
local query, reqOptions, error, content, extra) {
|
|
115
|
-
query = EncodeQuery("
|
|
117
|
+
query = EncodeQuery("psm/?", options)
|
|
116
118
|
reqOptions = {
|
|
117
119
|
putdata: data
|
|
118
120
|
}
|
|
@@ -667,13 +667,13 @@ closure psmcFsConnector(psm, api, local connClassID, connector, watch) {
|
|
|
667
667
|
|
|
668
668
|
|
|
669
669
|
/*
|
|
670
|
-
*
|
|
670
|
+
* MakeClientPSM
|
|
671
671
|
*
|
|
672
672
|
* Return a new client PSM with our known connectors.
|
|
673
673
|
*
|
|
674
674
|
*/
|
|
675
675
|
|
|
676
|
-
function
|
|
676
|
+
function MakeClientPSM(api, dbname, local importPSM) {
|
|
677
677
|
global(App)
|
|
678
678
|
importPSM = require("../storage/psm.nlg")
|
|
679
679
|
App.psm = importPSM.MakePSM(dbname).1
|
|
@@ -694,12 +694,12 @@ function psmcMakeClientPSM(api, dbname, local importPSM) {
|
|
|
694
694
|
|
|
695
695
|
function psmcInit(local manifest) {
|
|
696
696
|
|
|
697
|
-
manifest = `(psmcFsView, psmcFsConnector,
|
|
697
|
+
manifest = `(psmcFsView, psmcFsConnector, MakeClientPSM, psmcInit)
|
|
698
698
|
|
|
699
699
|
Naan.module.build(module.id, "psm_client", function(modobj, compobj) {
|
|
700
700
|
require("./client.nlg")
|
|
701
701
|
compobj.manifest = manifest
|
|
702
|
-
modobj.exports.MakeClientPSM =
|
|
702
|
+
modobj.exports.MakeClientPSM = MakeClientPSM
|
|
703
703
|
})
|
|
704
704
|
|
|
705
705
|
} ();
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* column positioning: // // !
|
|
8
8
|
*
|
|
9
|
-
* Copyright (c) 2023 by Richard C. Zulch
|
|
9
|
+
* Copyright (c) 2023-2024 by Richard C. Zulch
|
|
10
10
|
*
|
|
11
11
|
*/
|
|
12
12
|
|
|
@@ -35,6 +35,7 @@ wsMod;; // websocket module
|
|
|
35
35
|
* workerID: <string> // worker on server (server destinations only)
|
|
36
36
|
* }
|
|
37
37
|
* startup: <dictionary> // worker spawn init (server destinations only)
|
|
38
|
+
* wss: <boolean> // true to use secure connection
|
|
38
39
|
* debug: <boolean> // debug logging
|
|
39
40
|
* }
|
|
40
41
|
*
|
|
@@ -74,10 +75,13 @@ closure RelayCon(host, secret, options, local relay, nlregex)
|
|
|
74
75
|
relay.guid = secret
|
|
75
76
|
relay.host = host // e.g. "localhost:8009"
|
|
76
77
|
relay.wscon = wsMod.WebSocket(host, {
|
|
78
|
+
wss: options.wss || undefined
|
|
77
79
|
onopen: onopen
|
|
78
80
|
onmessage: onmessage
|
|
79
81
|
onerror: onerror
|
|
80
82
|
onclose: onclose
|
|
83
|
+
query: undefined // don't put secret on unsecure connections
|
|
84
|
+
querys: secret && EncodeQuery("?", { guid: secret })
|
|
81
85
|
})
|
|
82
86
|
result = relay.wscon.connect()
|
|
83
87
|
if !result.0
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* column positioning: // // !
|
|
8
8
|
*
|
|
9
|
-
* Copyright (c) 2020-
|
|
9
|
+
* Copyright (c) 2020-2024 by Richard C. Zulch
|
|
10
10
|
*
|
|
11
11
|
*/
|
|
12
12
|
|
|
@@ -193,8 +193,14 @@ closure JsLoadScript(libpath, globalID, local scriptTag, fpath) {
|
|
|
193
193
|
else
|
|
194
194
|
fpath = "/".concat(libpath)
|
|
195
195
|
if js.s.importScripts && tostring(js.s.importScripts) == "[Function importScripts]" {
|
|
196
|
-
js.
|
|
197
|
-
|
|
196
|
+
fpath = JSpath.dirname(js.w.location.href).concat(fpath)
|
|
197
|
+
try {
|
|
198
|
+
js.s.importScripts(fpath) // load in worker context
|
|
199
|
+
jsScripts[libpath] = js.s[globalID]
|
|
200
|
+
} catch {
|
|
201
|
+
debuglog("JsLoadScript:", libpath, "failed", exception)
|
|
202
|
+
js.s.console.log("JsLoadScript:", libpath, "failed", exception) // ensure visibility in JS console
|
|
203
|
+
}
|
|
198
204
|
} else if js.w { // load in browser context
|
|
199
205
|
pending = new(nonce)
|
|
200
206
|
scriptTag = js.w.document.createElement("script")
|
|
@@ -205,7 +211,7 @@ closure JsLoadScript(libpath, globalID, local scriptTag, fpath) {
|
|
|
205
211
|
true
|
|
206
212
|
}
|
|
207
213
|
scriptTag.onerror = function (event) {
|
|
208
|
-
debuglog("
|
|
214
|
+
debuglog("JsLoadScript:", libpath, "not found")
|
|
209
215
|
pending.signal(false)
|
|
210
216
|
true
|
|
211
217
|
}
|