@basthon/kernel-base 0.73.1 → 0.73.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.
package/lib/commons.js CHANGED
@@ -68,23 +68,22 @@ const mockFetch = (legacy) => {
68
68
  const trueFetch = self.fetch;
69
69
  const assetsURL = self._assetsURL;
70
70
  async function mockedFetch(request, init) {
71
- // force all params to init object
72
- if (request instanceof Request)
73
- init = { ...request, ...init };
74
- const url = request.url ?? request.toString();
71
+ // build new request from init
72
+ request = new Request(request, init);
73
+ const url = request.url;
75
74
  const localfsScheme = "filesystem:/";
76
75
  // in legacy mode, only local FS is mocked
77
76
  if (legacy) {
78
77
  if (url.startsWith(localfsScheme))
79
78
  return await fetchFromLocalFS(localfsScheme, url);
80
- return await trueFetch(url, init);
79
+ return await trueFetch(request);
81
80
  }
82
81
  // not a true worker? -> error
83
82
  if (self.importScripts == null || assetsURL == null)
84
83
  return Response.error();
85
84
  // non-legacy mode (true isolated secure worker)
86
85
  // ensure credentials are not sent
87
- init = { ...init, ...{ credentials: "omit" } };
86
+ request = new Request(request, { credentials: "omit" });
88
87
  try {
89
88
  // requests towards localfs
90
89
  if (url.startsWith(localfsScheme)) {
@@ -95,12 +94,12 @@ const mockFetch = (legacy) => {
95
94
  // only url under the assets folder are proxyied
96
95
  if (parent(url).startsWith(assetsURL)) {
97
96
  const proxy = self._remoteProxy;
98
- const { body, options } = await proxy.fetch(url, init);
97
+ const { body, options } = await proxy.fetch(request);
99
98
  return new Response(body, options);
100
99
  }
101
100
  throw new Error("Ressource is outside the proxy' scope");
102
101
  }
103
- return await trueFetch(url, init);
102
+ return await trueFetch(request);
104
103
  }
105
104
  catch (e) {
106
105
  console.error(`security proxy: request to ${url} throw error: ${e.toString()}`);
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.73.1";
1
+ export declare const VERSION = "0.73.3";
package/lib/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.73.1";
1
+ export const VERSION = "0.73.3";
@@ -183,5 +183,10 @@ declare class KernelWorkerBase {
183
183
  * Ask main thread to go to the next breakpoint.
184
184
  */
185
185
  breakpointMoveOn(): void;
186
+ /**
187
+ * Create the message channel between kernel and iframe,
188
+ * send one port and the iframe to main thread and return the other one.
189
+ */
190
+ displayKernelIFrame(iframeHTML: string): MessagePort;
186
191
  }
187
192
  export { ExecuteResult, KernelWorkerBase };
@@ -416,5 +416,17 @@ class KernelWorkerBase {
416
416
  const data = this.clone(this.__eval_data__);
417
417
  this.postMessage?.({ type: "breakpoint-move-on", content: { data } });
418
418
  }
419
+ /**
420
+ * Create the message channel between kernel and iframe,
421
+ * send one port and the iframe to main thread and return the other one.
422
+ */
423
+ displayKernelIFrame(iframeHTML) {
424
+ const { port1, port2 } = new MessageChannel();
425
+ const content = { html: iframeHTML, port: port1 };
426
+ const display_type = "kernel-iframe";
427
+ const data = { ...this.clone(this.__eval_data__), content, display_type };
428
+ this.postMessage?.({ data, type: "display" }, [port1]);
429
+ return port2;
430
+ }
419
431
  }
420
432
  export { KernelWorkerBase };
@@ -3,7 +3,7 @@
3
3
  * to fetch assets.
4
4
  */
5
5
  export declare class ProxyFetch {
6
- fetch(url: string, init: RequestInit | undefined): Promise<{
6
+ fetch(request: string | URL | Request, init?: RequestInit): Promise<{
7
7
  body: any;
8
8
  options: any | undefined;
9
9
  }>;
@@ -4,16 +4,18 @@ import { transfer } from "comlink";
4
4
  * to fetch assets.
5
5
  */
6
6
  export class ProxyFetch {
7
- async fetch(url, init) {
7
+ async fetch(request, init) {
8
+ request = new Request(request, init);
9
+ const url = request.url;
8
10
  const parentURL = (s) => s.substring(0, s.lastIndexOf("/"));
9
11
  const assetsURL = parentURL(new URL(globalThis.location.toString()).href);
10
12
  const baseURL = parentURL(new URL(url).href);
11
13
  if (!baseURL.startsWith(assetsURL))
12
14
  throw new Error(`URL ${url} is outside of proxy' scope`);
13
15
  // force credentials omition
14
- if (init?.credentials !== "omit")
16
+ if (request.credentials !== "omit")
15
17
  throw new Error("Request tries to use credentials");
16
- const response = await globalThis.fetch(url, init);
18
+ const response = await globalThis.fetch(request);
17
19
  const buffer = await response.arrayBuffer();
18
20
  return {
19
21
  body: transfer(buffer, [buffer]),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basthon/kernel-base",
3
- "version": "0.73.1",
3
+ "version": "0.73.3",
4
4
  "description": "Basthon - Base Kernel",
5
5
  "homepage": "https://basthon.fr",
6
6
  "bugs": {
@@ -47,5 +47,5 @@
47
47
  "publishConfig": {
48
48
  "access": "public"
49
49
  },
50
- "gitHead": "79b1f0a19e523c150945b7ad1a6a5148d193af33"
50
+ "gitHead": "68894e4db137b9cd8ec8676a2ed9c76752120a8f"
51
51
  }