@basthon/kernel-base 0.35.4 → 0.35.8

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/kernel.d.ts CHANGED
@@ -1,21 +1,13 @@
1
- /**
2
- * Fix window.
3
- */
4
- declare global {
5
- interface Window {
6
- BASTHON_KERNEL_SCRIPT?: string;
7
- }
8
- }
9
1
  /**
10
2
  * API that any Basthon kernel should fill to be supported
11
3
  * in console/notebook.
12
4
  */
13
5
  export declare class KernelBase {
14
- private _urlScript;
15
- private _loaded;
16
- private _pageLoad;
6
+ private _rootPath;
7
+ private readonly _loaded;
8
+ private readonly _pageLoad;
17
9
  execution_count: number;
18
- constructor();
10
+ constructor(rootPath: string);
19
11
  /**
20
12
  * Kernel version number (string).
21
13
  */
@@ -56,29 +48,21 @@ export declare class KernelBase {
56
48
  /**
57
49
  * Initialize the kernel.
58
50
  */
59
- init(): Promise<any>;
51
+ init(): Promise<void>;
60
52
  /**
61
53
  * Promise that resolve when the kernel is loaded.
62
54
  */
63
- loaded(): Promise<any>;
64
- /**
65
- * The current script URL.
66
- */
67
- urlScript(): string;
68
- /**
69
- * An URL without it's basename.
70
- */
71
- dirname(url: string): string;
55
+ loaded(): Promise<void>;
72
56
  /**
73
57
  * Root for kernel files. This is always the versnion number
74
- * directory inside the current script directory.
58
+ * directory inside the kernel directory.
75
59
  */
76
60
  basthonRoot(): string;
77
61
  /**
78
62
  * Downloading data (bytes array) as filename
79
63
  * (opening browser dialog).
80
64
  */
81
- static download(data: Uint8Array, filename: string): void;
65
+ download(data: Uint8Array, filename: string): void;
82
66
  /**
83
67
  * Dynamically load a script asynchronously.
84
68
  */
@@ -86,7 +70,7 @@ export declare class KernelBase {
86
70
  /**
87
71
  * Returns a promise that resolves when page is loaded.
88
72
  */
89
- pageLoad(): Promise<any>;
73
+ pageLoad(): Promise<void>;
90
74
  /**
91
75
  * Wraper around XMLHttpRequest.
92
76
  */
package/lib/kernel.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { PromiseDelegate } from "promise-delegate";
1
2
  import { VERSION } from './version';
2
3
  /**
3
4
  * An error thrown by not implemented API functions.
@@ -5,6 +6,7 @@ import { VERSION } from './version';
5
6
  class NotImplementedError extends Error {
6
7
  constructor(funcName) {
7
8
  super(`Function ${funcName} not implemented!`);
9
+ this.name = "NotImplementedError";
8
10
  }
9
11
  }
10
12
  /**
@@ -21,29 +23,23 @@ class BasthonEvent extends Event {
21
23
  * in console/notebook.
22
24
  */
23
25
  export class KernelBase {
24
- constructor() {
25
- this._loaded = null;
26
- this._pageLoad = null;
26
+ constructor(rootPath) {
27
+ this._loaded = new PromiseDelegate();
28
+ this._pageLoad = new PromiseDelegate();
27
29
  this.execution_count = 0;
28
- /**
29
- * Path to current script.
30
- *
31
- * Warning: this should not be postponed since
32
- * document.currentScript will be undefined.
33
- */
34
- this._urlScript = (function () {
35
- let url = window.location.origin + window.location.pathname;
36
- url = url.substring(0, url.lastIndexOf('/')) + "/";
37
- if (window.BASTHON_KERNEL_SCRIPT != null) {
38
- return url + window.BASTHON_KERNEL_SCRIPT;
39
- //} else if( module != null ) {
40
- // return url + module.uri;
41
- }
42
- else
43
- return document.currentScript.src;
44
- })();
30
+ // root path where kernel is installed
31
+ this._rootPath = rootPath;
32
+ if (document.readyState === 'complete') {
33
+ this._pageLoad.resolve();
34
+ }
35
+ else {
36
+ const callback = () => {
37
+ window.removeEventListener("load", callback);
38
+ this._pageLoad.resolve();
39
+ };
40
+ window.addEventListener("load", callback);
41
+ }
45
42
  }
46
- ;
47
43
  /**
48
44
  * Kernel version number (string).
49
45
  */
@@ -111,43 +107,30 @@ export class KernelBase {
111
107
  /**
112
108
  * Initialize the kernel.
113
109
  */
114
- init() {
115
- return this._loaded = this.launch().then(() => {
116
- // connecting eval to basthon.eval.request event.
117
- this.addEventListener("eval.request", this.evalFromEvent.bind(this));
118
- });
110
+ async init() {
111
+ await this.launch();
112
+ // connecting eval to basthon.eval.request event.
113
+ this.addEventListener("eval.request", this.evalFromEvent.bind(this));
114
+ this._loaded.resolve();
119
115
  }
120
116
  ;
121
117
  /**
122
118
  * Promise that resolve when the kernel is loaded.
123
119
  */
124
- loaded() { var _a; return (_a = this._loaded) !== null && _a !== void 0 ? _a : this.init(); }
125
- ;
126
- /**
127
- * The current script URL.
128
- */
129
- urlScript() { return this._urlScript; }
130
- ;
131
- /**
132
- * An URL without it's basename.
133
- */
134
- dirname(url) {
135
- return url.substring(0, url.lastIndexOf("/"));
136
- }
137
- ;
120
+ async loaded() { await this._loaded.promise; }
138
121
  /**
139
122
  * Root for kernel files. This is always the versnion number
140
- * directory inside the current script directory.
123
+ * directory inside the kernel directory.
141
124
  */
142
125
  basthonRoot() {
143
- return this.dirname(this.urlScript()) + "/" + this.version();
126
+ return this._rootPath + "/" + this.version();
144
127
  }
145
128
  ;
146
129
  /**
147
130
  * Downloading data (bytes array) as filename
148
131
  * (opening browser dialog).
149
132
  */
150
- static download(data, filename) {
133
+ download(data, filename) {
151
134
  let blob = new Blob([data], { type: "application/octet-stream" });
152
135
  let anchor = document.createElement("a");
153
136
  anchor.download = filename;
@@ -175,21 +158,7 @@ export class KernelBase {
175
158
  /**
176
159
  * Returns a promise that resolves when page is loaded.
177
160
  */
178
- pageLoad() {
179
- var _a;
180
- return (_a = this._pageLoad) !== null && _a !== void 0 ? _a : (this._pageLoad = new Promise(function (resolve, reject) {
181
- if (document.readyState === 'complete') {
182
- resolve();
183
- }
184
- else {
185
- const callback = () => {
186
- window.removeEventListener("load", callback);
187
- resolve();
188
- };
189
- window.addEventListener("load", callback);
190
- }
191
- }));
192
- }
161
+ async pageLoad() { await this._pageLoad.promise; }
193
162
  ;
194
163
  /**
195
164
  * Wraper around XMLHttpRequest.
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.35.4";
1
+ export declare const VERSION = "0.35.8";
package/lib/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.35.4";
1
+ export const VERSION = "0.35.8";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basthon/kernel-base",
3
- "version": "0.35.4",
3
+ "version": "0.35.8",
4
4
  "description": "Basthon - Base Kernel",
5
5
  "homepage": "https://basthon.fr",
6
6
  "bugs": {
@@ -27,11 +27,12 @@
27
27
  "devDependencies": {
28
28
  "gulp": "^4.0.2",
29
29
  "gulp-typescript": "^6.0.0-alpha.1",
30
+ "promise-delegate": "^1.0.1",
30
31
  "typescript": "~4.4.4",
31
32
  "vinyl-buffer": "^1.0.1"
32
33
  },
33
34
  "publishConfig": {
34
35
  "access": "public"
35
36
  },
36
- "gitHead": "ebf66dd4f601ad1b975d2e82b384b47a07ae4255"
37
+ "gitHead": "81d8ed255bdf30248c9c6ad761b5a820386f5e91"
37
38
  }