Skip to content

Commit 89737ca

Browse files
committed
add typings for graal-js builtins Polyglot and console
1 parent 6c87da7 commit 89737ca

File tree

3 files changed

+195
-1
lines changed

3 files changed

+195
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ npm install mle-js-plsqltypes
2323
```
2424

2525
Alternatively, you can also download `mle-js` which is a single bundled ambient file for all these module declarations in one.
26+
In addition, this bundle also contains declarations for GraalVM JavaScript builtins, concretely `Polyglot` and `console`.
2627
You can conveniently install it from NPM and then reference it in the beginning of your JavaScript code using the `<reference>` tag:
2728
```
2829
npm install mle-js

declarations/mle-js/mle-js.d.ts

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,3 +2149,196 @@ export class IOracleDate {
21492149
isValid(): boolean;
21502150
}
21512151
}
2152+
2153+
/* Copyright (c) 2022, 2022, Oracle and/or its affiliates. */
2154+
2155+
/*
2156+
* TypeScript declarations for JavaScript builtins in Oracle Database
2157+
* Multilingual Engine, see the following links for more information:
2158+
* - https://www.graalvm.org/latest/reference-manual/js/JavaScriptCompatibility
2159+
* - https://oracle-samples.github.io/mle-modules
2160+
*/
2161+
2162+
/**
2163+
* Type for programming languages that can be evaluated. Currently, it's
2164+
* JavaScript only.
2165+
*/
2166+
type Language = 'js';
2167+
2168+
/**
2169+
* Interface for Polyglot object. The functions of the Polyglot object allow to
2170+
* interact with values from other polyglot languages.
2171+
*/
2172+
interface IPolyglot {
2173+
2174+
/**
2175+
* Exports the JavaScript value under the given key to the polyglot bindings.
2176+
* If the polyglot bindings already had a value identified by key, it is
2177+
* overwritten with the new value. The value may be any valid Polyglot
2178+
* value.
2179+
*
2180+
* @param key identifier of polyglot binding that should be written.
2181+
* @param value content of polyglot binding that should be written.
2182+
* @throws TypeError if key is not a String.
2183+
*/
2184+
export(key: string, value: any): undefined;
2185+
2186+
/**
2187+
* Imports the value identified by key from the polyglot bindings and
2188+
* returns it. If no language has exported a value identified by key,
2189+
* undefined is returned.
2190+
*
2191+
* @param key identifier of polyglot binding that should be read.
2192+
* @returns the value of the polyglot binding or undefinied if it does not
2193+
* exist.
2194+
* @throws TypeError if key is not a String.
2195+
*/
2196+
import(key: string): any;
2197+
2198+
/**
2199+
* Parses and evaluates sourceCode with the interpreter identified by
2200+
* languageId. The value of sourceCode is expected to be a String (or
2201+
* convertable to one). Returns the evaluation result.
2202+
*
2203+
* @param languageId identifies the language.
2204+
* @param sourceCode contains the source code to be evaluated.
2205+
* @returns the evaluation result, depending on the sourceCode and/or the
2206+
* semantics of the language evaluated.
2207+
* @throws Exceptions can occur when an invalid languageId is passed, when
2208+
* sourceCode cannot be evaluated by the language, or when the executed
2209+
* program throws an exception itself.
2210+
*/
2211+
eval(languageId: Language, sourceCode: string): any;
2212+
}
2213+
declare const Polyglot: IPolyglot;
2214+
2215+
/**
2216+
* Interface for console object.
2217+
*/
2218+
interface IConsole {
2219+
2220+
/**
2221+
* Prints the arguments to stdout, providing a best-effort human readable
2222+
* output. By default, stdout is redirected to DBMS_OUTPUT and can be
2223+
* redirected using the appropriate procedures in DBMS_MLE.
2224+
*
2225+
* @param args arguments to be printed to stdout.
2226+
*/
2227+
log(...args: any[] ): undefined;
2228+
2229+
/**
2230+
* Alias of {@link log}:
2231+
* Prints the arguments to stdout, providing a best-effort human readable
2232+
* output. By default, stdout is redirected to DBMS_OUTPUT and can be
2233+
* redirected using the appropriate procedures in DBMS_MLE.
2234+
*
2235+
* @param args arguments to be printed to stdout.
2236+
*/
2237+
info(...args: any[] ): undefined;
2238+
2239+
/**
2240+
* Alias of {@link log}:
2241+
* Prints the arguments to stdout, providing a best-effort human readable
2242+
* output. By default, stdout is redirected to DBMS_OUTPUT and can be
2243+
* redirected using the appropriate procedures in DBMS_MLE.
2244+
*
2245+
* @param args arguments to be printed to stdout.
2246+
*/
2247+
debug(...args: any[] ): undefined;
2248+
2249+
/**
2250+
* Prints the arguments to stderr, providing a best-effort human readable
2251+
* output. By default, stderr is redirected to DBMS_OUTPUT and can be
2252+
* redirected using the appropriate procedures in DBMS_MLE.
2253+
*
2254+
* @param args arguments to be printed to stderr.
2255+
*/
2256+
error(...args: any[] ): undefined;
2257+
2258+
/**
2259+
* Alias of {@link error}:
2260+
* Prints the arguments to stderr, providing a best-effort human readable
2261+
* output. By default, stderr is redirected to DBMS_OUTPUT and can be
2262+
* redirected using the appropriate procedures in DBMS_MLE.
2263+
*
2264+
* @param args arguments to be printed to stderr.
2265+
*/
2266+
warn(...args: any[] ): undefined;
2267+
2268+
/**
2269+
* Prints message when check is falsy.
2270+
*
2271+
* @param check boolean condition that should be checked.
2272+
* @param message message that should be printed if check fails.
2273+
*/
2274+
asserts(check: boolean, message: string): undefined;
2275+
2276+
/**
2277+
* Clears the console window if possible. In Oracle Database, this function
2278+
* does not do anything useful, but prints some additional special
2279+
* characters.
2280+
*/
2281+
clear(): undefined;
2282+
2283+
/**
2284+
* Increases the given counter and prints how many times it has been called.
2285+
* The counter is identified by its label.
2286+
*
2287+
* @param label name of the counter to be increased. If no name is
2288+
* provided, the default counter is used.
2289+
*/
2290+
count(label?: string): undefined;
2291+
2292+
/**
2293+
* Resets the given counter to 0. The counter is identified by its label.
2294+
*
2295+
* @param label name of the counter to be reset. If no name is
2296+
* provided, the default counter is used.
2297+
*/
2298+
countReset(label?: string): undefined;
2299+
2300+
/**
2301+
* Increases the indentation for succeeding outputs to the console until
2302+
* {@link groupEnd} is called.
2303+
*
2304+
* @param labels if provided, the labels get printed before the indentation
2305+
* is increased.
2306+
*/
2307+
group(...labels: string[]): undefined;
2308+
2309+
/**
2310+
* Decreases the indentation for succeeding outputs to the console that was
2311+
* prevsiously increased with {@link group}. If identation is already at the
2312+
* lowest (outermost) level, this has no effect.
2313+
*/
2314+
groupEnd(): undefined;
2315+
2316+
/**
2317+
* Starts a timer. The timer is identified by its label.
2318+
*
2319+
* @param label name of the timer to be started. If no name is
2320+
* provided, the default timer is used.
2321+
*/
2322+
time(label?: string): undefined;
2323+
2324+
/**
2325+
* Logs, i.e. prints the duration of a timer (in milliseconds). The timer is
2326+
* identified by its label. If the timer has already been stopped, this has
2327+
* no effect.
2328+
*
2329+
* @param label name of the timer to be logged. If no name is
2330+
* provided, the default timer is used.
2331+
*/
2332+
timeLog(label?: string): undefined;
2333+
2334+
/**
2335+
* Stops the timer and prints its duration (in milliseconds). The timer is
2336+
* identified by its label. After this call, further calls to this function
2337+
* or to {@link timeLog} have no effect.
2338+
*
2339+
* @param label name of the timer to be stopped. If no name is
2340+
* provided, the default timer is used.
2341+
*/
2342+
timeEnd(label?: string): undefined;
2343+
}
2344+
declare const console: IConsole;

declarations/mle-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mle-js",
3-
"version": "21.3.0",
3+
"version": "21.3.1",
44
"description": "Bundle of all declarations of pre-defined JavaScript modules that ship with Oracle Database",
55
"types": "mle-js.d.ts",
66
"author": "Oracle",

0 commit comments

Comments
 (0)