Skip to content

Commit

Permalink
Added missing types - fixes #1374
Browse files Browse the repository at this point in the history
  • Loading branch information
klein0r committed Jan 2, 2024
1 parent a32206d commit 014d655
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Since v5.5.0 of the JavaScript adapter the following locations (relative to the
### **WORK IN PROGRESS**

* (klein0r) Added missing console.info()
* (klein0r) Added missing type hints

### 7.6.0 (2023-12-26)

Expand Down
4 changes: 2 additions & 2 deletions docs/en/javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ createState(
const list = getSchedules(true);
```
Returns the list of all CRON jobs and schedules (except astro).
Argument must be `true` if you want to get the list for **every running script**. Else only schedules in the current script will be returned.
Argument must be `true` if you want to get the list for **every running script**. Otherwise only schedules in the current script will be returned.

```js
const list = getSchedules(true);
Expand Down Expand Up @@ -939,7 +939,7 @@ You should use it to **modify** an existing object you read beforehand, e.g.:
```js
const obj = getObject('adapter.N.objectName');
obj.native.settings = 1;
setObject('adapter.N.objectName', obj, function (err) {
setObject('adapter.N.objectName', obj, (err) => {
if (err) log('Cannot write object: ' + err);
});
```
Expand Down
59 changes: 58 additions & 1 deletion lib/javascript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,7 @@ declare global {
type SetStatePromise = Promise<NonNullCallbackReturnTypeOf<SetStateCallback>>;

type StateChangeHandler<TOld extends StateValue = any, TNew extends TOld = any> = (obj: ChangedStateObject<TOld, TNew>) => void | Promise<void>;
type ObjectChangeHandler = (id: string, obj: iobJS.Object) => void | Promise<void>;

type FileChangeHandler<WithFile extends boolean> =
// Variant 1: WithFile is false, data/mimeType is definitely not there
Expand Down Expand Up @@ -1191,6 +1192,13 @@ declare global {
rule: ScheduleRule | Date | string | number;
}

interface ScheduleStatus {
type: string;
pattern?: string;
scriptName: string;
id: string;
}

interface LogMessage {
severity: LogLevel; // severity
ts: number; // timestamp as Date.now()
Expand Down Expand Up @@ -1366,10 +1374,15 @@ declare global {
function subscribe(id1: string, id2: string, value2: any): any;

/**
* Returns the list of all currently active subscriptions
* Returns the list of all active subscriptions
*/
function getSubscriptions(): { [id: string]: iobJS.Subscription[] };

/**
* Returns the list of all active file subscriptions
*/
function getFileSubscriptions(): { [id: string]: iobJS.Subscription[] };

/**
* Unsubscribe from changes of the given object ID(s) or handler(s)
*/
Expand All @@ -1387,6 +1400,13 @@ declare global {
function schedule(date: Date, callback: EmptyCallback): any;
function schedule(astro: iobJS.AstroSchedule, callback: EmptyCallback): any;

/**
* [{"type":"cron","pattern":"0 15 13 * * *","scriptName":"script.js.scheduleById","id":"cron_1704187467197_22756"}]
*
* @param allScripts Return all registered schedules of all running scripts
*/
function getSchedules(allScripts?: boolean): Array<iobJS.ScheduleStatus>;

/**
* Creates a schedule based on the state value (e.g. 12:53:09)
* Schedule will be updated if the state value changes
Expand Down Expand Up @@ -1460,6 +1480,8 @@ declare global {
* @param id The ID of the state to be set
* @param state binary data as buffer
* @param callback called when the operation finished
*
* @deprecated Use @see writeFile
*/
function setBinaryState(id: string, state: Buffer, callback?: iobJS.SetStateCallback): void;
function setBinaryStateAsync(id: string, state: Buffer): iobJS.SetStatePromise;
Expand All @@ -1479,6 +1501,8 @@ declare global {
* If the adapter is configured to subscribe to all states on start,
* this can be called synchronously and immediately returns the state.
* Otherwise, you need to provide a callback.
*
* @deprecated Use @see readFile
*/
function getBinaryState(id: string, callback: iobJS.GetStateCallback): void;
function getBinaryState(id: string): Buffer;
Expand Down Expand Up @@ -1595,6 +1619,12 @@ declare global {
function sendToHost(host: string, command: string, message: string | object, callback?: iobJS.MessageCallback | iobJS.MessageCallbackInfo): void;
function sendToHostAsync(host: string, command: string, message: string | object): Promise<iobJS.MessageCallback | iobJS.MessageCallbackInfo>;

function setTimeout(callback: (args: void) => void, ms?: number): NodeJS.Timeout;
function clearTimeout(timeoutId: NodeJS.Timeout | string | number | undefined): void;
function setInterval(callback: (args: void) => void, ms?: number): NodeJS.Timeout;
function clearInterval(intervalId: NodeJS.Timeout | string | number | undefined): void;
function setImmediate(callback: (args: void) => void): NodeJS.Immediate;

type CompareTimeOperations =
"between" | "not between" |
">" | ">=" | "<" | "<=" | "==" | "<>"
Expand Down Expand Up @@ -1660,6 +1690,26 @@ declare global {
function delFile(id: string, name: string, callback: ErrorCallback): void;
function delFileAsync(id: string, name: string): Promise<void>;

/**
* Renames a file.
* @param id Name of the root directory. This should be the adapter instance, e.g. "admin.0"
* @param oldName Current file name
* @param newName New file name
* @param callback Is called when the operation has finished (successfully or not)
*/
function rename(id: string, oldName: string, newName: string, callback: ErrorCallback);
function renameAsync(id: string, oldName: string, newName: string);

/**
* Renames a file.
* @param id Name of the root directory. This should be the adapter instance, e.g. "admin.0"
* @param oldName Current file name
* @param newName New file name
* @param callback Is called when the operation has finished (successfully or not)
*/
function renameFile(id: string, oldName: string, newName: string, callback: ErrorCallback);
function renameFileAsync(id: string, oldName: string, newName: string);

function getHistory(instance: any, options: any, callback: any): any;
function getHistoryAsync(instance: any, options: any): Promise<any>;

Expand Down Expand Up @@ -1733,6 +1783,13 @@ declare global {
*/
function onMessageUnregister(id: iobJS.MessageSubscribeID | string): boolean;

function jsonataExpression(data: any, expression: string): Promise<any>;

function onObject(pattern: string, callback: iobJS.ObjectChangeHandler);
function subscribeObject(pattern: string, callback: iobJS.ObjectChangeHandler);

function unsubscribeObject(id: string);

/**
* Receives logs of specified severity level in a script.
* @param severity Severity level
Expand Down

0 comments on commit 014d655

Please sign in to comment.