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
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: RecordReturn 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: RecordThis function writes the Event Listener Event Listener Return how many bytes are available to read. If there is a 'data' event handler, this will always return 0. Event Listenerdata 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