@pyscript/core 0.2.2 → 0.2.4
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/dist/core.js +2 -2
- package/dist/core.js.map +1 -1
- package/dist/error-e4fe78fd.js.map +1 -1
- package/package.json +5 -4
- package/src/all-done.js +62 -0
- package/src/config.js +15 -5
- package/src/core.js +10 -27
- package/src/exceptions.js +25 -0
- package/src/hooks.js +21 -0
- package/src/plugins/error.js +5 -0
- package/src/sync.js +4 -0
- package/types/all-done.d.ts +1 -0
- package/types/core.d.ts +2 -12
- package/types/exceptions.d.ts +48 -5
- package/types/hooks.d.ts +12 -0
- package/types/plugins/error.d.ts +5 -1
- package/types/sync.d.ts +5 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"error-e4fe78fd.js","sources":["../src/plugins/error.js"],"sourcesContent":["// PyScript Error Plugin\nimport { hooks } from \"../core.js\";\n\nhooks.onInterpreterReady.add(function override(pyScript) {\n // be sure this override happens only once\n hooks.onInterpreterReady.delete(override);\n\n // trap generic `stderr` to propagate to it regardless\n const { stderr } = pyScript.io;\n\n // override it with our own logic\n pyScript.io.stderr = (error, ...rest) => {\n notify(error.message || error);\n // let other plugins or stderr hook, if any, do the rest\n return stderr(error, ...rest);\n };\n\n // be sure uncaught Python errors are also visible\n addEventListener(\"error\", ({ message }) => {\n if (message.startsWith(\"Uncaught PythonError\")) notify(message);\n });\n});\n\n// Error hook utilities\n\n// Custom function to show notifications\nexport function notify(message) {\n const div = document.createElement(\"div\");\n div.className = \"py-error\";\n div.textContent = message;\n div.style.cssText = `\n border: 1px solid red;\n background: #ffdddd;\n color: black;\n font-family: courier, monospace;\n white-space: pre;\n overflow-x: auto;\n padding: 8px;\n margin-top: 8px;\n `;\n document.body.append(div);\n}\n"],"names":["notify","message","div","document","createElement","className","textContent","style","cssText","body","append","hooks","onInterpreterReady","add","override","pyScript","delete","stderr","io","error","rest","addEventListener","startsWith"],"mappings":"
|
1
|
+
{"version":3,"file":"error-e4fe78fd.js","sources":["../src/plugins/error.js"],"sourcesContent":["// PyScript Error Plugin\nimport { hooks } from \"../core.js\";\n\nhooks.onInterpreterReady.add(function override(pyScript) {\n // be sure this override happens only once\n hooks.onInterpreterReady.delete(override);\n\n // trap generic `stderr` to propagate to it regardless\n const { stderr } = pyScript.io;\n\n // override it with our own logic\n pyScript.io.stderr = (error, ...rest) => {\n notify(error.message || error);\n // let other plugins or stderr hook, if any, do the rest\n return stderr(error, ...rest);\n };\n\n // be sure uncaught Python errors are also visible\n addEventListener(\"error\", ({ message }) => {\n if (message.startsWith(\"Uncaught PythonError\")) notify(message);\n });\n});\n\n// Error hook utilities\n\n// Custom function to show notifications\n\n/**\n * Add a banner to the top of the page, notifying the user of an error\n * @param {string} message\n */\nexport function notify(message) {\n const div = document.createElement(\"div\");\n div.className = \"py-error\";\n div.textContent = message;\n div.style.cssText = `\n border: 1px solid red;\n background: #ffdddd;\n color: black;\n font-family: courier, monospace;\n white-space: pre;\n overflow-x: auto;\n padding: 8px;\n margin-top: 8px;\n `;\n document.body.append(div);\n}\n"],"names":["notify","message","div","document","createElement","className","textContent","style","cssText","body","append","hooks","onInterpreterReady","add","override","pyScript","delete","stderr","io","error","rest","addEventListener","startsWith"],"mappings":"kCA+BO,SAASA,EAAOC,GACnB,MAAMC,EAAMC,SAASC,cAAc,OACnCF,EAAIG,UAAY,WAChBH,EAAII,YAAcL,EAClBC,EAAIK,MAAMC,QAAU,6MAUpBL,SAASM,KAAKC,OAAOR,EACzB,CA3CAS,EAAMC,mBAAmBC,KAAI,SAASC,EAASC,GAE3CJ,EAAMC,mBAAmBI,OAAOF,GAGhC,MAAMG,OAAEA,GAAWF,EAASG,GAG5BH,EAASG,GAAGD,OAAS,CAACE,KAAUC,KAC5BpB,EAAOmB,EAAMlB,SAAWkB,GAEjBF,EAAOE,KAAUC,IAI5BC,iBAAiB,SAAS,EAAGpB,cACrBA,EAAQqB,WAAW,yBAAyBtB,EAAOC,EAAQ,GAEvE"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pyscript/core",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.4",
|
4
4
|
"type": "module",
|
5
5
|
"description": "PyScript",
|
6
6
|
"module": "./index.js",
|
@@ -20,7 +20,7 @@
|
|
20
20
|
},
|
21
21
|
"scripts": {
|
22
22
|
"server": "npx static-handler --cors --coep --coop --corp .",
|
23
|
-
"build": "node rollup/stdlib.cjs && node rollup/plugins.cjs && rm -rf dist && rollup --config rollup/core.config.js && npm run ts",
|
23
|
+
"build": "node rollup/stdlib.cjs && node rollup/plugins.cjs && rm -rf dist && rollup --config rollup/core.config.js && eslint src/ && npm run ts",
|
24
24
|
"size": "echo -e \"\\033[1mdist/*.js file size\\033[0m\"; for js in $(ls dist/*.js); do echo -e \"\\033[2m$js:\\033[0m $(cat $js | brotli | wc -c) bytes\"; done",
|
25
25
|
"ts": "tsc -p ."
|
26
26
|
},
|
@@ -33,12 +33,13 @@
|
|
33
33
|
"dependencies": {
|
34
34
|
"@ungap/with-resolvers": "^0.1.0",
|
35
35
|
"basic-devtools": "^0.1.6",
|
36
|
-
"polyscript": "^0.4.
|
36
|
+
"polyscript": "^0.4.6"
|
37
37
|
},
|
38
38
|
"devDependencies": {
|
39
39
|
"@rollup/plugin-node-resolve": "^15.2.1",
|
40
40
|
"@rollup/plugin-terser": "^0.4.3",
|
41
|
-
"
|
41
|
+
"eslint": "^8.50.0",
|
42
|
+
"rollup": "^3.29.3",
|
42
43
|
"rollup-plugin-postcss": "^4.0.2",
|
43
44
|
"rollup-plugin-string": "^3.0.0",
|
44
45
|
"static-handler": "^0.4.2",
|
package/src/all-done.js
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
import TYPES from "./types.js";
|
2
|
+
import hooks from "./hooks.js";
|
3
|
+
|
4
|
+
const DONE = "py:all-done";
|
5
|
+
|
6
|
+
const {
|
7
|
+
onAfterRun,
|
8
|
+
onAfterRunAsync,
|
9
|
+
codeAfterRunWorker,
|
10
|
+
codeAfterRunWorkerAsync,
|
11
|
+
} = hooks;
|
12
|
+
|
13
|
+
const waitForIt = [];
|
14
|
+
const codes = [];
|
15
|
+
|
16
|
+
const codeFor = (element) => {
|
17
|
+
const isAsync = element.hasAttribute("async");
|
18
|
+
const { promise, resolve } = Promise.withResolvers();
|
19
|
+
const type = `${DONE}:${waitForIt.push(promise)}`;
|
20
|
+
|
21
|
+
// resolve each promise once notified
|
22
|
+
addEventListener(type, resolve, { once: true });
|
23
|
+
|
24
|
+
if (element.hasAttribute("worker")) {
|
25
|
+
const code = `
|
26
|
+
from pyscript import window as _w
|
27
|
+
_w.dispatchEvent(_w.Event.new("${type}"))
|
28
|
+
`;
|
29
|
+
if (isAsync) codeAfterRunWorkerAsync.add(code);
|
30
|
+
else codeAfterRunWorker.add(code);
|
31
|
+
return code;
|
32
|
+
}
|
33
|
+
|
34
|
+
// dispatch only once the ready element is the same
|
35
|
+
const code = (_, el) => {
|
36
|
+
if (el === element) dispatchEvent(new Event(type));
|
37
|
+
};
|
38
|
+
|
39
|
+
if (isAsync) onAfterRunAsync.add(code);
|
40
|
+
else onAfterRun.add(code);
|
41
|
+
return code;
|
42
|
+
};
|
43
|
+
|
44
|
+
const selector = [];
|
45
|
+
for (const [TYPE] of TYPES)
|
46
|
+
selector.push(`script[type="${TYPE}"]`, `${TYPE}-script`);
|
47
|
+
|
48
|
+
// loop over all known scripts and elements
|
49
|
+
for (const element of document.querySelectorAll(selector.join(",")))
|
50
|
+
codes.push(codeFor(element));
|
51
|
+
|
52
|
+
// wait for all the things then cleanup
|
53
|
+
Promise.all(waitForIt).then(() => {
|
54
|
+
// cleanup unnecessary hooks
|
55
|
+
for (const code of codes) {
|
56
|
+
onAfterRun.delete(code);
|
57
|
+
onAfterRunAsync.delete(code);
|
58
|
+
codeAfterRunWorker.delete(code);
|
59
|
+
codeAfterRunWorkerAsync.delete(code);
|
60
|
+
}
|
61
|
+
dispatchEvent(new Event(DONE));
|
62
|
+
});
|
package/src/config.js
CHANGED
@@ -20,9 +20,10 @@ const badURL = (url, expected = "") => {
|
|
20
20
|
* Given a string, returns its trimmed content as text,
|
21
21
|
* fetching it from a file if the content is a URL.
|
22
22
|
* @param {string} config either JSON, TOML, or a file to fetch
|
23
|
+
* @param {string?} type the optional type to enforce
|
23
24
|
* @returns {{json: boolean, toml: boolean, text: string}}
|
24
25
|
*/
|
25
|
-
const configDetails = async (config) => {
|
26
|
+
const configDetails = async (config, type) => {
|
26
27
|
let text = config?.trim();
|
27
28
|
// we only support an object as root config
|
28
29
|
let url = "",
|
@@ -49,9 +50,18 @@ const syntaxError = (type, url, { message }) => {
|
|
49
50
|
const configs = new Map();
|
50
51
|
|
51
52
|
for (const [TYPE] of TYPES) {
|
52
|
-
|
53
|
-
let
|
54
|
-
|
53
|
+
/** @type {Promise<any> | undefined} A Promise wrapping any plugins which should be loaded. */
|
54
|
+
let plugins;
|
55
|
+
|
56
|
+
/** @type {any} The PyScript configuration parsed from the JSON or TOML object*. May be any of the return types of JSON.parse() or toml-j0.4's parse() ( {number | string | boolean | null | object | Array} ) */
|
57
|
+
let parsed;
|
58
|
+
|
59
|
+
/** @type {SyntaxError | undefined} The error thrown when parsing the PyScript config, if any.*/
|
60
|
+
let error;
|
61
|
+
|
62
|
+
let config,
|
63
|
+
type,
|
64
|
+
pyConfig = $(`${TYPE}-config`);
|
55
65
|
if (pyConfig) {
|
56
66
|
config = pyConfig.getAttribute("src") || pyConfig.textContent;
|
57
67
|
type = pyConfig.getAttribute("type");
|
@@ -68,7 +78,7 @@ for (const [TYPE] of TYPES) {
|
|
68
78
|
// catch possible fetch errors
|
69
79
|
if (config) {
|
70
80
|
try {
|
71
|
-
const { json, toml, text, url } = await configDetails(config);
|
81
|
+
const { json, toml, text, url } = await configDetails(config, type);
|
72
82
|
config = text;
|
73
83
|
if (json || type === "json") {
|
74
84
|
try {
|
package/src/core.js
CHANGED
@@ -1,16 +1,21 @@
|
|
1
1
|
/*! (c) PyScript Development Team */
|
2
2
|
|
3
3
|
import "@ungap/with-resolvers";
|
4
|
-
import { INVALID_CONTENT, define, XWorker } from "polyscript";
|
5
4
|
|
6
|
-
//
|
7
|
-
|
5
|
+
// These imports can hook more than usual and help debugging possible polyscript issues
|
6
|
+
import {
|
7
|
+
INVALID_CONTENT,
|
8
|
+
define,
|
9
|
+
XWorker,
|
10
|
+
} from "../node_modules/polyscript/esm/index.js";
|
8
11
|
import { queryTarget } from "../node_modules/polyscript/esm/script-handler.js";
|
9
12
|
import { dedent, dispatch } from "../node_modules/polyscript/esm/utils.js";
|
10
13
|
import { Hook } from "../node_modules/polyscript/esm/worker/hooks.js";
|
11
14
|
|
15
|
+
import "./all-done.js";
|
12
16
|
import TYPES from "./types.js";
|
13
17
|
import configs from "./config.js";
|
18
|
+
import hooks from "./hooks.js";
|
14
19
|
import sync from "./sync.js";
|
15
20
|
import stdlib from "./stdlib.js";
|
16
21
|
import { ErrorCode } from "./exceptions.js";
|
@@ -66,28 +71,6 @@ const registerModule = ({ XWorker: $XWorker, interpreter, io }) => {
|
|
66
71
|
interpreter.runPython(stdlib, { globals: interpreter.runPython("{}") });
|
67
72
|
};
|
68
73
|
|
69
|
-
export const hooks = {
|
70
|
-
/** @type {Set<function>} */
|
71
|
-
onBeforeRun: new Set(),
|
72
|
-
/** @type {Set<function>} */
|
73
|
-
onBeforeRunAsync: new Set(),
|
74
|
-
/** @type {Set<function>} */
|
75
|
-
onAfterRun: new Set(),
|
76
|
-
/** @type {Set<function>} */
|
77
|
-
onAfterRunAsync: new Set(),
|
78
|
-
/** @type {Set<function>} */
|
79
|
-
onInterpreterReady: new Set(),
|
80
|
-
|
81
|
-
/** @type {Set<string>} */
|
82
|
-
codeBeforeRunWorker: new Set(),
|
83
|
-
/** @type {Set<string>} */
|
84
|
-
codeBeforeRunWorkerAsync: new Set(),
|
85
|
-
/** @type {Set<string>} */
|
86
|
-
codeAfterRunWorker: new Set(),
|
87
|
-
/** @type {Set<string>} */
|
88
|
-
codeAfterRunWorkerAsync: new Set(),
|
89
|
-
};
|
90
|
-
|
91
74
|
const workerHooks = {
|
92
75
|
codeBeforeRunWorker: () =>
|
93
76
|
[stdlib, ...hooks.codeBeforeRunWorker].map(dedent).join("\n"),
|
@@ -100,7 +83,7 @@ const workerHooks = {
|
|
100
83
|
};
|
101
84
|
|
102
85
|
const exportedConfig = {};
|
103
|
-
export { exportedConfig as config };
|
86
|
+
export { exportedConfig as config, hooks };
|
104
87
|
|
105
88
|
for (const [TYPE, interpreter] of TYPES) {
|
106
89
|
const { config, plugins, error } = configs.get(TYPE);
|
@@ -206,7 +189,7 @@ for (const [TYPE, interpreter] of TYPES) {
|
|
206
189
|
} = element;
|
207
190
|
const hasTarget = !!target?.value;
|
208
191
|
const show = hasTarget
|
209
|
-
? queryTarget(target.value)
|
192
|
+
? queryTarget(element, target.value)
|
210
193
|
: document.createElement("script-py");
|
211
194
|
|
212
195
|
if (!hasTarget) {
|
package/src/exceptions.js
CHANGED
@@ -23,7 +23,17 @@ export const ErrorCode = {
|
|
23
23
|
FETCH_UNAVAILABLE_ERROR: "PY0503",
|
24
24
|
};
|
25
25
|
|
26
|
+
/**
|
27
|
+
* Keys of the ErrorCode object
|
28
|
+
* @typedef {keyof ErrorCode} ErrorCodes
|
29
|
+
* */
|
30
|
+
|
26
31
|
export class UserError extends Error {
|
32
|
+
/**
|
33
|
+
* @param {ErrorCodes} errorCode
|
34
|
+
* @param {string} message
|
35
|
+
* @param {string} messageType
|
36
|
+
* */
|
27
37
|
constructor(errorCode, message = "", messageType = "text") {
|
28
38
|
super(`(${errorCode}): ${message}`);
|
29
39
|
this.errorCode = errorCode;
|
@@ -33,6 +43,10 @@ export class UserError extends Error {
|
|
33
43
|
}
|
34
44
|
|
35
45
|
export class FetchError extends UserError {
|
46
|
+
/**
|
47
|
+
* @param {ErrorCodes} errorCode
|
48
|
+
* @param {string} message
|
49
|
+
* */
|
36
50
|
constructor(errorCode, message) {
|
37
51
|
super(errorCode, message);
|
38
52
|
this.name = "FetchError";
|
@@ -40,12 +54,23 @@ export class FetchError extends UserError {
|
|
40
54
|
}
|
41
55
|
|
42
56
|
export class InstallError extends UserError {
|
57
|
+
/**
|
58
|
+
* @param {ErrorCodes} errorCode
|
59
|
+
* @param {string} message
|
60
|
+
* */
|
43
61
|
constructor(errorCode, message) {
|
44
62
|
super(errorCode, message);
|
45
63
|
this.name = "InstallError";
|
46
64
|
}
|
47
65
|
}
|
48
66
|
|
67
|
+
/**
|
68
|
+
* Internal function for creating alert banners on the page
|
69
|
+
* @param {string} message The message to be displayed to the user
|
70
|
+
* @param {string} level The alert level of the message. Can be any string; 'error' or 'warning' cause matching messages to be emitted to the console
|
71
|
+
* @param {string} [messageType="text"] If set to "html", the message content will be assigned to the banner's innerHTML directly, instead of its textContent
|
72
|
+
* @param {any} [logMessage=true] An additional flag for whether the message should be sent to the console log.
|
73
|
+
*/
|
49
74
|
export function _createAlertBanner(
|
50
75
|
message,
|
51
76
|
level,
|
package/src/hooks.js
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
export default {
|
2
|
+
/** @type {Set<function>} */
|
3
|
+
onBeforeRun: new Set(),
|
4
|
+
/** @type {Set<function>} */
|
5
|
+
onBeforeRunAsync: new Set(),
|
6
|
+
/** @type {Set<function>} */
|
7
|
+
onAfterRun: new Set(),
|
8
|
+
/** @type {Set<function>} */
|
9
|
+
onAfterRunAsync: new Set(),
|
10
|
+
/** @type {Set<function>} */
|
11
|
+
onInterpreterReady: new Set(),
|
12
|
+
|
13
|
+
/** @type {Set<string>} */
|
14
|
+
codeBeforeRunWorker: new Set(),
|
15
|
+
/** @type {Set<string>} */
|
16
|
+
codeBeforeRunWorkerAsync: new Set(),
|
17
|
+
/** @type {Set<string>} */
|
18
|
+
codeAfterRunWorker: new Set(),
|
19
|
+
/** @type {Set<string>} */
|
20
|
+
codeAfterRunWorkerAsync: new Set(),
|
21
|
+
};
|
package/src/plugins/error.js
CHANGED
@@ -24,6 +24,11 @@ hooks.onInterpreterReady.add(function override(pyScript) {
|
|
24
24
|
// Error hook utilities
|
25
25
|
|
26
26
|
// Custom function to show notifications
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Add a banner to the top of the page, notifying the user of an error
|
30
|
+
* @param {string} message
|
31
|
+
*/
|
27
32
|
export function notify(message) {
|
28
33
|
const div = document.createElement("div");
|
29
34
|
div.className = "py-error";
|
package/src/sync.js
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
export default {
|
2
|
+
/**
|
3
|
+
* 'Sleep' for the given number of seconds. Used to implement Python's time.sleep in Worker threads.
|
4
|
+
* @param {number} seconds The number of seconds to sleep.
|
5
|
+
*/
|
2
6
|
sleep(seconds) {
|
3
7
|
return new Promise(($) => setTimeout($, seconds * 1000));
|
4
8
|
},
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/types/core.d.ts
CHANGED
@@ -10,17 +10,7 @@ export function PyWorker(file: string, options?: {
|
|
10
10
|
}): Worker & {
|
11
11
|
sync: ProxyHandler<object>;
|
12
12
|
};
|
13
|
-
export namespace hooks {
|
14
|
-
let onBeforeRun: Set<Function>;
|
15
|
-
let onBeforeRunAsync: Set<Function>;
|
16
|
-
let onAfterRun: Set<Function>;
|
17
|
-
let onAfterRunAsync: Set<Function>;
|
18
|
-
let onInterpreterReady: Set<Function>;
|
19
|
-
let codeBeforeRunWorker: Set<string>;
|
20
|
-
let codeBeforeRunWorkerAsync: Set<string>;
|
21
|
-
let codeAfterRunWorker: Set<string>;
|
22
|
-
let codeAfterRunWorkerAsync: Set<string>;
|
23
|
-
}
|
24
|
-
export { exportedConfig as config };
|
25
13
|
import sync from "./sync.js";
|
26
14
|
declare const exportedConfig: {};
|
15
|
+
import hooks from "./hooks.js";
|
16
|
+
export { exportedConfig as config, hooks };
|
package/types/exceptions.d.ts
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
|
1
|
+
/**
|
2
|
+
* Internal function for creating alert banners on the page
|
3
|
+
* @param {string} message The message to be displayed to the user
|
4
|
+
* @param {string} level The alert level of the message. Can be any string; 'error' or 'warning' cause matching messages to be emitted to the console
|
5
|
+
* @param {string} [messageType="text"] If set to "html", the message content will be assigned to the banner's innerHTML directly, instead of its textContent
|
6
|
+
* @param {any} [logMessage=true] An additional flag for whether the message should be sent to the console log.
|
7
|
+
*/
|
8
|
+
export function _createAlertBanner(message: string, level: string, messageType?: string, logMessage?: any): void;
|
2
9
|
export namespace ErrorCode {
|
3
10
|
let GENERIC: string;
|
4
11
|
let CONFLICTING_CODE: string;
|
@@ -15,14 +22,50 @@ export namespace ErrorCode {
|
|
15
22
|
let FETCH_SERVER_ERROR: string;
|
16
23
|
let FETCH_UNAVAILABLE_ERROR: string;
|
17
24
|
}
|
25
|
+
/**
|
26
|
+
* Keys of the ErrorCode object
|
27
|
+
* @typedef {keyof ErrorCode} ErrorCodes
|
28
|
+
* */
|
18
29
|
export class UserError extends Error {
|
19
|
-
|
20
|
-
|
30
|
+
/**
|
31
|
+
* @param {ErrorCodes} errorCode
|
32
|
+
* @param {string} message
|
33
|
+
* @param {string} messageType
|
34
|
+
* */
|
35
|
+
constructor(errorCode: ErrorCodes, message?: string, messageType?: string);
|
36
|
+
errorCode: "GENERIC" | "CONFLICTING_CODE" | "BAD_CONFIG" | "MICROPIP_INSTALL_ERROR" | "BAD_PLUGIN_FILE_EXTENSION" | "NO_DEFAULT_EXPORT" | "TOP_LEVEL_AWAIT" | "FETCH_ERROR" | "FETCH_NAME_ERROR" | "FETCH_UNAUTHORIZED_ERROR" | "FETCH_FORBIDDEN_ERROR" | "FETCH_NOT_FOUND_ERROR" | "FETCH_SERVER_ERROR" | "FETCH_UNAVAILABLE_ERROR";
|
21
37
|
messageType: string;
|
22
38
|
}
|
23
39
|
export class FetchError extends UserError {
|
24
|
-
|
40
|
+
/**
|
41
|
+
* @param {ErrorCodes} errorCode
|
42
|
+
* @param {string} message
|
43
|
+
* */
|
44
|
+
constructor(errorCode: ErrorCodes, message: string);
|
25
45
|
}
|
26
46
|
export class InstallError extends UserError {
|
27
|
-
|
47
|
+
/**
|
48
|
+
* @param {ErrorCodes} errorCode
|
49
|
+
* @param {string} message
|
50
|
+
* */
|
51
|
+
constructor(errorCode: ErrorCodes, message: string);
|
28
52
|
}
|
53
|
+
/**
|
54
|
+
* Keys of the ErrorCode object
|
55
|
+
*/
|
56
|
+
export type ErrorCodes = keyof {
|
57
|
+
GENERIC: string;
|
58
|
+
CONFLICTING_CODE: string;
|
59
|
+
BAD_CONFIG: string;
|
60
|
+
MICROPIP_INSTALL_ERROR: string;
|
61
|
+
BAD_PLUGIN_FILE_EXTENSION: string;
|
62
|
+
NO_DEFAULT_EXPORT: string;
|
63
|
+
TOP_LEVEL_AWAIT: string;
|
64
|
+
FETCH_ERROR: string;
|
65
|
+
FETCH_NAME_ERROR: string;
|
66
|
+
FETCH_UNAUTHORIZED_ERROR: string;
|
67
|
+
FETCH_FORBIDDEN_ERROR: string;
|
68
|
+
FETCH_NOT_FOUND_ERROR: string;
|
69
|
+
FETCH_SERVER_ERROR: string;
|
70
|
+
FETCH_UNAVAILABLE_ERROR: string;
|
71
|
+
};
|
package/types/hooks.d.ts
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
declare namespace _default {
|
2
|
+
let onBeforeRun: Set<Function>;
|
3
|
+
let onBeforeRunAsync: Set<Function>;
|
4
|
+
let onAfterRun: Set<Function>;
|
5
|
+
let onAfterRunAsync: Set<Function>;
|
6
|
+
let onInterpreterReady: Set<Function>;
|
7
|
+
let codeBeforeRunWorker: Set<string>;
|
8
|
+
let codeBeforeRunWorkerAsync: Set<string>;
|
9
|
+
let codeAfterRunWorker: Set<string>;
|
10
|
+
let codeAfterRunWorkerAsync: Set<string>;
|
11
|
+
}
|
12
|
+
export default _default;
|
package/types/plugins/error.d.ts
CHANGED
package/types/sync.d.ts
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
declare namespace _default {
|
2
|
-
|
2
|
+
/**
|
3
|
+
* 'Sleep' for the given number of seconds. Used to implement Python's time.sleep in Worker threads.
|
4
|
+
* @param {number} seconds The number of seconds to sleep.
|
5
|
+
*/
|
6
|
+
function sleep(seconds: number): Promise<any>;
|
3
7
|
}
|
4
8
|
export default _default;
|