diff --git a/attw.json b/attw.json index 639018244df1ef..1cf80f10a88de1 100644 --- a/attw.json +++ b/attw.json @@ -3,7 +3,8 @@ "no-resolution", "cjs-only-exports-default", "unexpected-module-syntax", - "cjs-resolves-to-esm" + "cjs-resolves-to-esm", + "named-exports" ], "failingPackages": [ "af-utils__react-table", @@ -14,7 +15,6 @@ "amqplib", "angular-gridster", "apca-w3", - "app-module-path", "architect", "axios-cancel", "babel-plugin-syntax-jsx", @@ -37,7 +37,6 @@ "cloudfour__simple-svg-placeholder", "collectionsjs", "combine-reducers", - "conditional", "cornerstone-core", "country-flag-icons", "critters-webpack-plugin", @@ -249,7 +248,6 @@ "react-native-signature-capture", "react-native-svg-animated-linear-gradient", "react-paginate", - "react-paginate/v5", "react-payment-inputs", "react-plyr", "react-recaptcha-v3", diff --git a/types/espruino/espruino-tests.ts b/types/espruino/espruino-tests.ts index 56b64e55db88e7..c46359a4c622bc 100644 --- a/types/espruino/espruino-tests.ts +++ b/types/espruino/espruino-tests.ts @@ -1,15 +1,86 @@ import * as wifi from "Wifi"; -wifi.connect("ssid", { password: "pass", authMode: "wpa_wpa2" }, err => { - if (err) throw err; - console.log("connected"); +// minimum +wifi.connect("Test", {}); + +wifi.connect("Test", { + password: "Test1234", + authMode: "wpa_wpa2", + channel: 6, + bssid: "aa:bb:cc:dd:ee:ff", + dnsServers: ["8.8.8.8", "1.1.1.1"], +}); + +wifi.connect("Test", { password: "pw" }, err => { + if (err === null) { + console.log("connected"); + } else { + const reason: string = err; + console.log("failed:", reason); + } +}); + +// test all types of auth +(["open", "wpa", "wpa2", "wpa_wpa2"] as const).forEach(authMode => { + wifi.connect("Test", { authMode }); }); -wifi.startAP("ssid", { password: "pass", authMode: "wpa_wpa2" }, err => { +// @ts-expect-error -- "wep" is not a valid WifiAuth +wifi.connect("Test", { authMode: "wep" }); + +// @ts-expect-error -- ssid must be a string +wifi.connect(12345, {}); + +// @ts-expect-error -- options is required (not optional in current d.ts) +wifi.connect("Test"); + +// ALLOWED +wifi.connect("Test", { dnsServers: ["8.8.8.8", "1.1.1.1"] }); + +// @ts-expect-error -- dnsServers is a 2-tuple, not a 3-tuple +wifi.connect("Test", { dnsServers: ["8.8.8.8", "1.1.1.1", "9.9.9.9"] }); + +// @ts-expect-error -- unknown option +wifi.connect("Test", { encryption: "wpa2" }); + +// @ts-expect-error -- callback err parameter is string|null, not Error +wifi.connect("Test", {}, (err: Error | null) => {}); + +// AP STUFF +wifi.startAP("Test", { + password: "Test1234", + authMode: "wpa_wpa2", + channel: 11, + hidden: true, +}, err => { if (err) throw err; - console.log("created"); + console.log("AP up"); +}); +wifi.stopAP(() => {}); + +// minimum +wifi.startAP("MyAP", {}, () => {}); +wifi.stopAP(() => {}); + +// @ts-expect-error -- callback is required +wifi.startAP("MyAP", { password: "pw" }); + +// @ts-expect-error -- hidden must be boolean +wifi.startAP("MyAP", { hidden: "yes" }, () => {}); + +// @ts-expect-error -- channel must be number +wifi.startAP("MyAP", { channel: "6" }, () => {}); + +wifi.disconnect(() => { + console.log("disconnected"); }); +// @ts-expect-error -- callback is required +wifi.disconnect(); + +// @ts-expect-error -- callback takes no arguments +wifi.disconnect((err: string) => {}); + digitalWrite(D2, false); digitalWrite(D2, true); diff --git a/types/espruino/index.d.ts b/types/espruino/index.d.ts index 815eb4db087236..290c8af4edd54c 100644 --- a/types/espruino/index.d.ts +++ b/types/espruino/index.d.ts @@ -3,8 +3,98 @@ declare interface Object { } declare module "Wifi" { - function connect(ssid: string, options: any, callback: (err: any) => any): any; - function startAP(ssid: string, options: any, callback: (err: any) => any): any; + type status = "off" | "connecting" | "wrong_password" | "no_ap_found" | "connect_fail" | "connected"; + type WifiAuth = "open" | "wpa2" | "wpa" | "wpa_wpa2"; + interface APOptions { + authMode?: WifiAuth; + password?: string; + channel?: number; + hidden?: boolean; + } + + interface connectionOptions { + password?: string; + dnsServers?: [string, string]; // Max 2 DNS servers + channel?: number; + bssid?: string; + authMode?: WifiAuth; + } + + function connect(ssid: string, options: connectionOptions, callback?: (err: string | null) => void): void; + function startAP(ssid: string, options: APOptions, callback: (err: string | null) => void): void; + function disconnect(callback: () => void): void; + + function getAPDetails(callback?: (details: any) => void): { + status: "enabled" | "disabled"; + stations: { ip: any }[]; + ssid: string; + password: string; + authMode: WifiAuth; + hidden: boolean; + maxConn: number; + savedSsid: string | null; + }; + + interface IPInfo { + ip: string; + netmask: string; + gw: string; + mac: string; + } + function getAPIP(callback?: (err: any, ipinfo: IPInfo) => void): IPInfo; + + interface details { + status: status; + rssi: any; + ssid: string; + password: string; + authMode: WifiAuth; + savedSsid: string; + } + function getDetails(callback?: (details: any) => void): details; + + function getHostByName(hostname: string, callback: (ip: string) => void): string; + function getHostname(callback?: (hostname: string) => void): string; + function getIP(callback?: (err: any, ipinfo: IPInfo) => void): IPInfo; + + interface StatusCallback { + status: status; + ap: "enabled" | "disabled"; + mode: "off" | "sta" | "ap" | "sta+ap"; + phy: "11b" | "11g" | "11n"; + powersave: "none" | "ps-poll"; + savedMode: "off" | "sta" | "ap" | "sta+ap"; + } + function getStatus(callback?: (status: StatusCallback) => void): StatusCallback; + + function ping(hostname: string, callback: (time: string | number) => void): void; + function restore(): void; + function save(what: "clear" | "sta+ap"): void; + function scan( + callback: ( + err: string | null, + ap_list: { ssid: string; mac: string; authMode: WifiAuth; channel: number; rssi: number | string }[], + ) => void, + ): void; + function setAPIP(settings: { ip: string; gw: string; netmask: string }, callback: (err: string) => void): void; + function setConfig(settings: { phy: "11b" | "11g" | "11n"; powersave: "none" | "ps-poll" }): void; + function setHostname(hostname: string, callback?: () => void): void; + function setIP(settings: { ip: string; gw: string; netmask: string }, callback: (err: string) => void): void; + function setSNTP(server: string, tz_offset: number): void; + function stopAP(callback: () => void): void; + function turbo(enable: boolean | number, callback: () => void): void; + + // EVENTS + type events = + | "connected" + | "dhcp_timeout" + | "disconnected" + | "probe_recv" + | "sta_joined" + | "sta_left" + | "associated" + | "auth_change"; + function on(event: events, callback: (details: any) => void): void; } declare module "InfluxDB" { @@ -2105,8 +2195,10 @@ declare namespace ESP8266 { */ declare function http(): void; +type HTTPRequestMethod = "GET" | "POST" | "PUT" | "DELETE"; + /** */ -declare namespace http { +declare module "http" { /** *

Create an HTTP Server

*

When a request to the server is made, the callback is called. In the callback you can use the methods on the response (httpSRs) to send data. You can also add request.on('data',function() { ... }) to listen for POSTed data

@@ -2116,6 +2208,36 @@ declare namespace http { * @url http://www.espruino.com/Reference#l_http_createServer */ function createServer(callback: any): httpSrv; + + /** + *

Retrieve Data from a Remote Server

+ * + * @param options + * @param callback + * @return + * @url https://www.espruino.com/Reference#t_l_http_get + */ + function get(options: string, callback: (data: httpCRs) => void): httpCRq; + + /** + *

Retrieve/Put Data to a Server

+ * + * @param options + * @param callback + * @return + * @url https://www.espruino.com/Reference#t_l_http_request + */ + function request( + options: { + host: string; + port: number; + path: string; + method: HTTPRequestMethod; + protocol: "https:" | "http:"; + headers: Record; + }, + callback: (data: httpCRs) => void, + ): httpCRq; } /** @@ -2150,12 +2272,17 @@ declare interface httpSrv { * * @url http://www.espruino.com/Reference#httpSRq */ +type httpSRqEvent = "close" | "drain"; declare interface httpSRq { /** * @return */ new(): httpSRq; + url: string; + headers: Record; + method: HTTPRequestMethod; + /** *

Return how many bytes are available to read. If there is already a listener for data, this will always return 0.

* @@ -2181,6 +2308,13 @@ declare interface httpSRq { * @url http://www.espruino.com/Reference#l_httpSRq_pipe */ pipe(destination: any, options: any): void; + + /** + *

Event Listener

+ * @param event + * @param callback + */ + on(event: httpSRqEvent, callback: (data: any) => void): void; } /** @@ -2188,12 +2322,16 @@ declare interface httpSRq { * * @url http://www.espruino.com/Reference#httpSRs */ +type httpSRsEvent = "close" | "data"; declare interface httpSRs { /** * @return */ new(): httpSRs; + headers: Record; + setHeader(key: string, value: string): void; + /** *

This function writes the data argument as a string. Data that is passed in * (including arrays) will be converted to a string with the normal JavaScript @@ -2218,7 +2356,14 @@ declare interface httpSRs { * @param headers * @url http://www.espruino.com/Reference#l_httpSRs_writeHead */ - writeHead(statusCode: number, headers: any): void; + writeHead(statusCode: number | string, headers: Record): void; + + /** + *

Event Listener

+ * @param event + * @param callback + */ + on(event: httpSRsEvent, callback: (data: any) => void): void; } /** @@ -2226,6 +2371,7 @@ declare interface httpSRs { * * @url http://www.espruino.com/Reference#httpCRq */ +type httpCRqEvent = "drain" | "error"; declare interface httpCRq { /** * @return @@ -2251,6 +2397,13 @@ declare interface httpCRq { * @url http://www.espruino.com/Reference#l_httpCRq_end */ end(data: any): void; + + /** + *

Event Listener

+ * @param event + * @param callback + */ + on(event: httpCRqEvent, callback: (data: any) => void): void; } /** @@ -2258,12 +2411,18 @@ declare interface httpCRq { * * @url http://www.espruino.com/Reference#httpCRs */ +type httpCRsEvent = "close" | "data" | "error"; declare interface httpCRs { /** * @return */ new(): httpCRs; + headers: Record; + httpVersion: string; + statusCode: string; + statusMessage: string; + /** *

Return how many bytes are available to read. If there is a 'data' event handler, this will always return 0.

* @@ -2289,6 +2448,13 @@ declare interface httpCRs { * @url http://www.espruino.com/Reference#l_httpCRs_pipe */ pipe(destination: any, options: any): void; + + /** + *

Event Listener

+ * @param event + * @param callback + */ + on(event: httpCRsEvent, callback: (data: any) => void): void; } /** diff --git a/types/espruino/package.json b/types/espruino/package.json index 15e1c4da39551b..7b0b4646768d9c 100644 --- a/types/espruino/package.json +++ b/types/espruino/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@types/espruino", - "version": "1.94.9999", + "version": "1.95.9999", "projects": [ "http://www.espruino.com/", "https://github.com/espruino/espruinotools" diff --git a/types/gorilla-engine/components/LevelMeter.d.ts b/types/gorilla-engine/components/LevelMeter.d.ts index 31c1d8318e7294..db42633d54df29 100755 --- a/types/gorilla-engine/components/LevelMeter.d.ts +++ b/types/gorilla-engine/components/LevelMeter.d.ts @@ -78,6 +78,10 @@ declare namespace GorillaEngine.UI { * The current value of the level meter. */ value: any; + /** + * Select which channel to show. + */ + channelOffset: number; } // tslint:disable-next-line:no-empty-interface diff --git a/types/gorilla-engine/gorilla-engine-tests.ts b/types/gorilla-engine/gorilla-engine-tests.ts index afa7cfae0225b8..81b1a455923f1d 100644 --- a/types/gorilla-engine/gorilla-engine-tests.ts +++ b/types/gorilla-engine/gorilla-engine-tests.ts @@ -15,3 +15,5 @@ const label = new GorillaEngine.UI.Label({ margin: 5 }); const slider = new GorillaEngine.UI.Slider({ id: "slider", x: 0, y: 2 }); const mappingEditor = new GorillaEngine.UI.MappingEditor({ id: "myNewMappingEditor", x: 3, y: 2 }); + +const levelMeter = new GorillaEngine.UI.LevelMeter({ id: "myLevelMeter", x: 0, y: 2 }); diff --git a/types/puppeteer-har/index.d.ts b/types/puppeteer-har/index.d.ts index 90a1276819a2c8..40103dc5660510 100644 --- a/types/puppeteer-har/index.d.ts +++ b/types/puppeteer-har/index.d.ts @@ -1,4 +1,4 @@ -import type { Frame, Page } from "puppeteer"; +import type { Frame, Page } from "puppeteer" with { "resolution-mode": "import" }; declare namespace PuppeteerHar { interface PuppeteerHarOptions { diff --git a/types/puppeteer-har/puppeteer-har-tests.ts b/types/puppeteer-har/puppeteer-har-tests.ts index 91a43869b4bca8..df29191dd76708 100644 --- a/types/puppeteer-har/puppeteer-har-tests.ts +++ b/types/puppeteer-har/puppeteer-har-tests.ts @@ -1,7 +1,7 @@ /// // Import only for type-checking purposes -import { Frame, Page } from "puppeteer"; +import type { Frame, Page } from "puppeteer" with { "resolution-mode": "import" }; import PuppeteerHar from "puppeteer-har"; // Define a mock Page interface just for type-checking diff --git a/types/puppeteer-screenshot-tester/index.d.ts b/types/puppeteer-screenshot-tester/index.d.ts index a0f4f0e0b6bfd7..b4d9dd7b5bd827 100644 --- a/types/puppeteer-screenshot-tester/index.d.ts +++ b/types/puppeteer-screenshot-tester/index.d.ts @@ -1,5 +1,7 @@ -import { Page, ScreenshotOptions as PuppeteerScreenshotOptions } from "puppeteer"; -import { JpegOptions, PngOptions, WebpOptions } from "sharp"; +import type { Page, ScreenshotOptions as PuppeteerScreenshotOptions } from "puppeteer" with { + "resolution-mode": "import", +}; +import type { JpegOptions, PngOptions, WebpOptions } from "sharp" with { "resolution-mode": "import" }; interface PngOutputSettings { /**