diff --git a/examples/io/listener/httpserver/httpserver.js b/examples/io/listener/httpserver/httpserver.js
index 90baafe424..0af49d2dca 100644
--- a/examples/io/listener/httpserver/httpserver.js
+++ b/examples/io/listener/httpserver/httpserver.js
@@ -20,6 +20,20 @@
import Timer from "timer";
+const statusReasons = Object.freeze({
+ 200: "OK",
+ 201: "Created",
+ 204: "No Content",
+ 301: "Moved Permanently",
+ 302: "Found",
+ 400: "Bad Request",
+ 401: "Unauthorized",
+ 403: "Forbidden",
+ 404: "Not Found",
+ 500: "Internal Server Error",
+ 503: "Service Unavailable",
+});
+
const more = Object.freeze({more: true});
class Connection {
@@ -282,7 +296,7 @@ class Connection {
switch (this.#state) {
case "sendResponse":
- this.#pendingWrite = `HTTP/1.1 ${this.#options.status} FILL_THIS_IN\r\n`;
+ this.#pendingWrite = `HTTP/1.1 ${this.#options.status} ${statusReasons[this.#options.status] ?? ""}\r\n`;
this.#pendingWrite = ArrayBuffer.fromString(this.#pendingWrite);
this.#writePosition = 0;
diff --git a/examples/io/listener/httpserver/options/webpage.js b/examples/io/listener/httpserver/options/webpage.js
index 7f6b317e7b..796a9f2e4a 100644
--- a/examples/io/listener/httpserver/options/webpage.js
+++ b/examples/io/listener/httpserver/options/webpage.js
@@ -45,6 +45,7 @@ export default {
else
throw new Error("unsupported data type");
response.headers.set("content-type", route.contentType ?? "text/html");
+ response.status = this.route.status ?? 200;
this.respond(response);
},
onWritable(count) {
diff --git a/examples/io/tcp/websocket/WebSocket.js b/examples/io/tcp/websocket/WebSocket.js
index 228b2af89d..a6364c07b2 100644
--- a/examples/io/tcp/websocket/WebSocket.js
+++ b/examples/io/tcp/websocket/WebSocket.js
@@ -310,6 +310,4 @@ class WebSocket {
}
}
-export default WebSocket;
-
-
+export default WebSocket;
\ No newline at end of file
diff --git a/examples/io/tcp/websocketclient/config.js b/examples/io/tcp/websocketclient/config.js
index 3bf2cd8583..ec2237f65a 100644
--- a/examples/io/tcp/websocketclient/config.js
+++ b/examples/io/tcp/websocketclient/config.js
@@ -28,4 +28,3 @@ globalThis.device = Object.freeze({
},
},
}, true);
-
diff --git a/examples/io/tcp/websocketclient/manifest_websocketclient.json b/examples/io/tcp/websocketclient/manifest_websocketclient.json
index 8ca27bee0a..982ec90472 100644
--- a/examples/io/tcp/websocketclient/manifest_websocketclient.json
+++ b/examples/io/tcp/websocketclient/manifest_websocketclient.json
@@ -6,13 +6,13 @@
],
"modules": {
"*": [
- "./config",
"$(MODULES)/data/logical/*"
],
+ "websocketclient/config": "./config",
"embedded:network/websocket/client": "./websocketclient"
},
"preload": [
- "config",
+ "websocketclient/config",
"embedded:network/websocket/client",
"logical"
]
diff --git a/examples/io/tcp/websocketclient/websocketclient.js b/examples/io/tcp/websocketclient/websocketclient.js
index 5297662db9..00803630ec 100644
--- a/examples/io/tcp/websocketclient/websocketclient.js
+++ b/examples/io/tcp/websocketclient/websocketclient.js
@@ -402,6 +402,9 @@ class WebSocketClient {
return;
const opcode = options.tag & 0x0F;
+ if (options.mask) {
+ Logical.xor(control.buffer, options.mask.buffer);
+ }
try {
this.#options.onControl?.call(this, opcode, control.buffer);
if (!this.#socket)
@@ -587,4 +590,4 @@ class WebSocketClient {
static pong = 10;
}
-export default WebSocketClient;
+export default WebSocketClient;
\ No newline at end of file
diff --git a/examples/io/tcp/websocketsclient/config.js b/examples/io/tcp/websocketsclient/config.js
index c8ea8951ac..c69d256c39 100644
--- a/examples/io/tcp/websocketsclient/config.js
+++ b/examples/io/tcp/websocketsclient/config.js
@@ -1,6 +1,5 @@
import "system" // system initializes globalThis.device. this ensures it runs before this module.
-import TCP from "embedded:io/socket/tcp";
import UDP from "embedded:io/socket/udp";
import Resolver from "embedded:network/dns/resolver/udp";
import TLSSocket from "embedded:io/socket/tcp/tls";
@@ -29,4 +28,4 @@ globalThis.device = Object.freeze({
}
},
},
-}, true);
+}, true);
\ No newline at end of file
diff --git a/examples/manifest_typings.json b/examples/manifest_typings.json
index 1e3e6f41f3..3160af1de1 100644
--- a/examples/manifest_typings.json
+++ b/examples/manifest_typings.json
@@ -33,17 +33,23 @@
"embedded:io/socket/*": [
"$(TYPINGS)/embedded_io/socket/*"
],
+ "embedded:io/socket/tcp/*": [
+ "$(TYPINGS)/embedded_io/socket/tcp/*"
+ ],
"embedded:network/http/*": [
"$(TYPINGS)/embedded_network/http/*"
],
+ "embedded:network/http/server/options/*": [
+ "$(TYPINGS)/embedded_network/http/server/options/*"
+ ],
"embedded:network/mqtt/*": [
"$(TYPINGS)/embedded_network/mqtt/*"
],
"embedded:network/dns/resolver/*": [
"$(TYPINGS)/embedded_network/dns/resolver/*"
],
- "embedded:network/*": [
- "$(TYPINGS)/embedded_network/*"
+ "embedded:network/websocket/*": [
+ "$(TYPINGS)/embedded_network/websocket/*"
],
"mqtt/js": [
"$(TYPINGS)/mqtt/js"
diff --git a/typings/embedded_io/socket/listener.d.ts b/typings/embedded_io/socket/listener.d.ts
index 1842a953dd..1334f304c9 100644
--- a/typings/embedded_io/socket/listener.d.ts
+++ b/typings/embedded_io/socket/listener.d.ts
@@ -19,19 +19,25 @@
*/
declare module "embedded:io/socket/listener" {
- import TCP from "embedded:io/socket/tcp"
+ import type TCP from "embedded:io/socket/tcp";
+
+ export interface ListenerOptions {
+ port?: number;
+ address?: string;
+ onReadable?: (this: Listener, bytes: number) => void;
+ format?: "socket/tcp";
+ }
+
+ export type ListenerDevice = ListenerOptions & { io: typeof Listener };
+
class Listener {
- constructor(options: {
- port?: number;
- address?: string;
- onReadable?: (this: Listener, requests: number) => void;
- format?: "socket/tcp";
- target?: any;
- })
+ constructor(options: ListenerOptions)
read(): TCP | undefined
get format(): "socket/tcp"
set format(value: "socket/tcp")
+
readonly port: number;
}
+
export default Listener;
}
diff --git a/typings/embedded_io/socket/tcp.d.ts b/typings/embedded_io/socket/tcp.d.ts
index 71b651ef32..889565b7b9 100644
--- a/typings/embedded_io/socket/tcp.d.ts
+++ b/typings/embedded_io/socket/tcp.d.ts
@@ -1,51 +1,53 @@
/*
-* Copyright (c) 2022 Shinya Ishikawa
-*
-* This file is part of the Moddable SDK Tools.
-*
-* The Moddable SDK Tools is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* The Moddable SDK Tools is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with the Moddable SDK Tools. If not, see .
-*
-*/
-
+ * Copyright (c) 2022 Shinya Ishikawa
+ *
+ * This file is part of the Moddable SDK Tools.
+ *
+ * The Moddable SDK Tools is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * The Moddable SDK Tools is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the Moddable SDK Tools. If not, see .
+ *
+ */
declare module "embedded:io/socket/tcp" {
- import type { Buffer } from "embedded:io/_common";
- export type Options = ((({
- address: string;
- } | {
- host: string;
- }) & {
- port: number;
- }) | {
- from: TCP;
- }) & {
- nodelay?: boolean;
- onReadable?: (this: TCP, bytes: number) => void;
- onWritable?: (this: TCP, bytes: number) => void;
- onError?: (this: TCP) => void;
- format?: "number" | "buffer";
- target?: any;
- };
-
- export default class TCP {
- constructor(options: Options)
- readonly remoteAddress: string | undefined;
- readonly remotePort: number | undefined;
- read(byteLength?: number): number | ArrayBuffer;
- read(buffer: Buffer): void;
- write(value: number | Buffer): void;
- close(): void;
- get format(): "number" | "buffer"
- set format(value: "number" | "buffer")
- }
+ import type { Buffer } from "embedded:io/_common";
+ import type UDP from "embedded:io/socket/udp";
+
+ export type TCPOptions = ((
+ {
+ address: string;
+ port: number;
+ } | {
+ from: TCP;
+ }) & {
+ nodelay?: boolean;
+ onReadable?: (this: TCP, bytes: number) => void;
+ onWritable?: (this: TCP, bytes: number) => void;
+ onError?: (this: TCP) => void;
+ format?: "number" | "buffer";
+ }
+ );
+
+ export type TCPDevice = TCPOptions & { io: typeof UDP };
+
+ export default class TCP {
+ constructor(options: TCPOptions);
+ readonly remoteAddress: string | undefined;
+ readonly remotePort: number | undefined;
+ read(): number;
+ read(byteLength: number): ArrayBuffer | undefined;
+ read(buffer: Buffer): void;
+ write(value: number | Buffer): void;
+ close(): void;
+ get format(): "number" | "buffer";
+ set format(value: "number" | "buffer");
+ }
}
diff --git a/typings/embedded_io/socket/tcp/tls.d.ts b/typings/embedded_io/socket/tcp/tls.d.ts
new file mode 100644
index 0000000000..fc6ab1ab89
--- /dev/null
+++ b/typings/embedded_io/socket/tcp/tls.d.ts
@@ -0,0 +1,27 @@
+declare module "embedded:io/socket/tcp/tls" {
+ import TCP, { TCPOptions } from "embedded:io/socket/tcp";
+ import UDP from "embedded:io/socket/udp";
+
+ export type SSLSessionOptions = {
+ protocolVersion?: number;
+ serverName?: string;
+ applicationLayerProtocolNegotiation?: string;
+ trace?: number;
+ cache?: boolean;
+ tls_server_name?: string;
+ client_auth?: {
+ cipherSuites: string[];
+ subjectDN: string;
+ };
+ };
+
+ export type TLSOptions = TCPOptions & {
+ host: string;
+ secure: SSLSessionOptions;
+ };
+ export type TLSDevice = TCPOptions & { io: typeof UDP };
+
+ export default class TLSSocket extends TCP {
+ constructor(options: TLSOptions);
+ }
+}
diff --git a/typings/embedded_io/socket/tls.d.ts b/typings/embedded_io/socket/tls.d.ts
deleted file mode 100644
index f4a6134d21..0000000000
--- a/typings/embedded_io/socket/tls.d.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-declare module "embedded:io/socket/tcp/tls" {
- import { Options as TCPOptions } from "embedded:io/socket/tcp"
- export type Options = TCPOptions & {
- host: string
- secure: Record // should be called "tls" according to std?
- }
- export default class TLSSocket {
- constructor(options: Options)
- close(): undefined
- read(count: number|ArrayBufferLike) : undefined|ArrayBufferLike
- write(buffer: ArrayBufferLike) : number
- set format(format: string)
- get format() : string
- }
-}
-
diff --git a/typings/embedded_io/socket/udp.d.ts b/typings/embedded_io/socket/udp.d.ts
index e9f4846ab3..60dce58cc6 100644
--- a/typings/embedded_io/socket/udp.d.ts
+++ b/typings/embedded_io/socket/udp.d.ts
@@ -20,27 +20,34 @@
declare module "embedded:io/socket/udp" {
import type { Buffer } from "embedded:io/_common";
+
+ interface UDPOptionsBase {
+ port?: number;
+ address?: string;
+ onReadable?: (this: UDP, packets: number) => void;
+ onError?: () => void;
+ format?: "buffer";
+ }
+
+ interface UDPMulticastOptions {
+ multicast: string;
+ timeToLive: number;
+ }
+
+ export type UDPOptions = UDPOptionsBase & ({} | UDPMulticastOptions);
+
+ export type UDPDevice = UDPOptions & { io: typeof UDP };
+
class UDP {
- constructor(options: {
- port?: number;
- address?: string;
- onReadable?: (this: UDP, packets: number) => void;
- onError?: () => void;
- format?: "buffer";
- target?: any;
- } & ({} | {
- multicast: string;
- timeToLive: number;
- }))
+ constructor(options: UDPOptions)
write(buffer: Buffer, address: string, port: number): void;
read(): ArrayBuffer & {
address: string;
port: number;
};
- read(buffer: Buffer);
get format(): "buffer"
set format(value: "buffer")
}
-
- export default UDP
+
+ export default UDP;
}
diff --git a/typings/embedded_network/dns/resolver/udp.d.ts b/typings/embedded_network/dns/resolver/udp.d.ts
index b77b60d992..0c0d269356 100644
--- a/typings/embedded_network/dns/resolver/udp.d.ts
+++ b/typings/embedded_network/dns/resolver/udp.d.ts
@@ -19,19 +19,27 @@
*/
declare module "embedded:network/dns/resolver/udp" {
+ import type { UDPDevice } from 'embedded:io/socket/udp';
- interface Options {
- host: string
- onResolved: ((host:string, address:any) => null)
- onError: ((host:string) => null)
+ export interface DNSUDPOptions {
+ http?: never;
+ servers: string[];
+ socket: UDPDevice;
}
- class Resolver {
- constructor(options: Record)
- close(): void
- resolve(options: Options): void
+ export interface DNSUDPResolveOptions {
+ host: string;
+ onResolved: ((host:string, address:any) => null);
+ onError: ((host:string) => null);
+ }
+ export type DNSUDPDevice = DNSUDPOptions & { io: typeof Resolver };
+
+ class Resolver {
+ constructor(options: DNSUDPOptions);
+ close(): void;
+ resolve(options: DNSUDPResolveOptions): void;
}
- export default Resolver
+ export default Resolver;
}
diff --git a/typings/embedded_network/http/client.d.ts b/typings/embedded_network/http/client.d.ts
index b928e606ad..21ab3396d9 100644
--- a/typings/embedded_network/http/client.d.ts
+++ b/typings/embedded_network/http/client.d.ts
@@ -20,12 +20,15 @@
declare module "embedded:network/http/client" {
import type { Buffer } from "embedded:io/_common"
+ import type { TCPDevice } from "embedded:io/socket/tcp";
+ import type { TLSDevice } from "embedded:io/socket/tls";
+ import type { DNSUDPDevice } from "embedded:io/socket/dns";
- export interface ClientOptions {
- socket: any
- port?:number
- host: string
- dns: any
+ export interface HTTPClientOptions {
+ socket: TCPDevice | TLSDevice;
+ port?: number;
+ host: string;
+ dns: DNSUDPDevice;
onError?: (err:any)=>void
}
@@ -39,14 +42,17 @@ declare module "embedded:network/http/client" {
onDone?: (this: HTTPRequest, error: Error|null) => void // note: error is empty Error object
}
+ export type HTTPClientDevice = HTTPClientOptions & { io: typeof HTTPClient };
+
export interface HTTPRequest {
- read(byteLength?: number): ArrayBuffer|undefined;
- read(buffer: Buffer): void;
+ read(): number;
+ read(byteLength: number): ArrayBuffer;
+ read(buffer: Buffer): void;
write(value: Buffer|undefined): void;
}
export default class HTTPClient {
- constructor(options: ClientOptions)
+ constructor(options: HTTPClientOptions)
request(options: RequestOptions): HTTPRequest
close(): void
}
diff --git a/typings/embedded_network/http/server-device.d.ts b/typings/embedded_network/http/server-device.d.ts
new file mode 100644
index 0000000000..a09fb17f78
--- /dev/null
+++ b/typings/embedded_network/http/server-device.d.ts
@@ -0,0 +1,19 @@
+import type { DNSUDPDevice } from "embedded:network/dns/resolver/udp";
+import type { TCPDevice } from 'embedded:io/socket/tcp';
+import HTTPServer from "embedded:network/http/server";
+
+
+declare global {
+ interface NetworkExtensions {
+ http: {
+ io: typeof HTTPServer;
+ dns: DNSUDPDevice;
+ socket: TCPDevice
+ };
+ }
+
+ interface Device {
+ network: NetworkExtensions;
+ }
+}
+
diff --git a/typings/embedded_network/http/server.d.ts b/typings/embedded_network/http/server.d.ts
new file mode 100644
index 0000000000..b3daae1537
--- /dev/null
+++ b/typings/embedded_network/http/server.d.ts
@@ -0,0 +1,42 @@
+declare module "embedded:network/http/server" {
+ import type Listener from "embedded:io/socket/listener";
+ import type TCP from "embedded:io/socket/tcp";
+ import "embedded:network/http/server-device";
+
+ export interface HTTPServerOptions {
+ io: typeof Listener;
+ port?: number;
+ onConnect?: (this: HTTPServer, connection: HTTPServerConnection) => void;
+ }
+
+ export interface HTTPServerRoute {
+ onRequest?: (this: HTTPServerConnection, request: { method: string, path: string, headers: Map}) => void;
+ onReadable?: (this: HTTPServerConnection, count: number) => void;
+ onResponse?: (this: HTTPServerConnection, response: HTTPServerResponseOptions) => void;
+ onWritable?: (this: HTTPServerConnection, count: number) => void;
+ onDone?: (this: HTTPServerConnection, ) => void;
+ onError?: (this: HTTPServerConnection, error?: string) => void;
+ }
+
+ export interface HTTPServerResponseOptions {
+ status: number;
+ headers: Map;
+ }
+
+ export interface HTTPServerConnection {
+ close(): void;
+ detach(): TCP;
+ accept(options: HTTPServerRoute): void;
+ respond(options: HTTPServerResponseOptions): void;
+ read(count: number): ArrayBuffer;
+ write(payload?: ArrayBuffer): number;
+ route: HTTPServerRoute;
+ }
+
+ export default class HTTPServer {
+ constructor(options: HTTPServerOptions);
+ close(): void;
+ get port(): number;
+ }
+ }
+
\ No newline at end of file
diff --git a/typings/embedded_network/http/server/options/webpage.d.ts b/typings/embedded_network/http/server/options/webpage.d.ts
new file mode 100644
index 0000000000..d197815ca0
--- /dev/null
+++ b/typings/embedded_network/http/server/options/webpage.d.ts
@@ -0,0 +1,13 @@
+declare module "embedded:network/http/server/options/webpage" {
+ import type { HTTPServerRoute } from "embedded:network/http/server";
+ import type { Buffer } from "embedded:io/_common";
+
+ export interface HTTPServerRouteWebPage extends HTTPServerRoute {
+ data: Buffer | string;
+ contentType?: string;
+ headers?: Map;
+ status?: number;
+ }
+ const route: HTTPServerRouteWebPage;
+ export default route;
+}
\ No newline at end of file
diff --git a/typings/embedded_network/http/server/options/websocket.d.ts b/typings/embedded_network/http/server/options/websocket.d.ts
new file mode 100644
index 0000000000..4ab9a49191
--- /dev/null
+++ b/typings/embedded_network/http/server/options/websocket.d.ts
@@ -0,0 +1,8 @@
+declare module "embedded:network/http/server/options/websocket" {
+ import type { HTTPServerRoute } from "embedded:network/http/server";
+
+ export interface HTTPServerRouteWebSocket extends HTTPServerRoute {}
+
+ const route: HTTPServerRouteWebSocket;
+ export default route;
+}
diff --git a/typings/embedded_network/websocket/client-device.d.ts b/typings/embedded_network/websocket/client-device.d.ts
new file mode 100644
index 0000000000..cbc68e2612
--- /dev/null
+++ b/typings/embedded_network/websocket/client-device.d.ts
@@ -0,0 +1,25 @@
+import type { DNSUDPDevice } from "embedded:network/dns/resolver/udp";
+import type { TCPDevice } from 'embedded:io/socket/tcp';
+import type { TLSDevice } from "embedded:io/socket/tcp/tls";
+import type WebSocketClient from "embedded:network/websocket/client";
+
+declare global {
+ interface NetworkExtensions {
+ ws: {
+ io: typeof WebSocketClient;
+ dns: DNSUDPDevice;
+ socket: TCPDevice
+ };
+ wss: {
+ io: typeof WebSocketClient;
+ dns: DNSUDPDevice;
+ socket: TLSDevice;
+ };
+ }
+
+ interface Device {
+ network: NetworkExtensions;
+ }
+
+}
+
diff --git a/typings/embedded_network/websocket/client.d.ts b/typings/embedded_network/websocket/client.d.ts
new file mode 100644
index 0000000000..faf2cf1224
--- /dev/null
+++ b/typings/embedded_network/websocket/client.d.ts
@@ -0,0 +1,58 @@
+declare module "embedded:network/websocket/client" {
+ import type { DNSUDPDevice } from "embedded:network/dns/resolver/udp";
+ import type { Buffer } from "embedded:io/_common";
+ import type TCP from "embedded:io/socket/tcp";
+ import type { TCPDevice } from "embedded:io/socket/tcp";
+ import type TLSSocket from "embedded:io/socket/tcp/tls";
+ import type { TLSDevice } from "embedded:io/socket/tcp/tls";
+ import "embedded:network/websocket/client-device";
+
+ interface WebSocketClientReadableOptions {
+ more: boolean;
+ binary: boolean;
+ }
+
+ export interface WebSocketClientWriteOptions {
+ binary?: boolean;
+ more?: boolean;
+ opcode?: WebSocketClientOpcode;
+ }
+
+ type WebSocketClientOpcode = 1 | 2 | 8 | 9 | 10;
+
+ type WebSocketClientOptions = ((
+ {
+ attach?: TCP | TLSSocket;
+ } | {
+ host?: string;
+ port?: number;
+ socket: TCPDevice | TLSDevice;
+ }) & {
+ protocol?: string;
+ headers?: Map;
+ dns?: DNSUDPDevice;
+ onReadable?: (this: WebSocketClient, count: number, options: WebSocketClientReadableOptions) => void;
+ onWritable?: (this: WebSocketClient, count: number) => void;
+ onControl?: (this: WebSocketClient, opcode: WebSocketClientOpcode, buffer: ArrayBuffer) => void;
+ onClose?: (this: WebSocketClient) => void;
+ onError?: (this: WebSocketClient, error?: string) => void;
+ }
+ );
+
+ export type WebSocketClientDevice = WebSocketClientOptions & { io: typeof WebSocketClient };
+
+ export default class WebSocketClient {
+ constructor(options: WebSocketClientOptions);
+ close(): void;
+ read(count?: number): ArrayBuffer | undefined;
+ write(message: Buffer, options?: WebSocketClientWriteOptions): number;
+ get format(): "number" | "buffer";
+ set format(value: "number" | "buffer");
+
+ static readonly text: 1;
+ static readonly binary: 2;
+ static readonly close: 8;
+ static readonly ping: 9;
+ static readonly pong: 10;
+ }
+}
diff --git a/typings/embedded_provider/builtin-device.d.ts b/typings/embedded_provider/builtin-device.d.ts
new file mode 100644
index 0000000000..934f53bbd4
--- /dev/null
+++ b/typings/embedded_provider/builtin-device.d.ts
@@ -0,0 +1,56 @@
+/*
+* Copyright (c) 2022 Shinya Ishikawa
+*
+* This file is part of the Moddable SDK Tools.
+*
+* The Moddable SDK Tools is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* The Moddable SDK Tools is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with the Moddable SDK Tools. If not, see .
+*
+*/
+
+import Digital from "embedded:io/digital";
+import DigitalBank from "embedded:io/digitalbank";
+import Analog from "embedded:io/analog";
+import PWM from "embedded:io/pwm";
+import PulseCount from "embedded:io/pulsecount";
+import I2C from "embedded:io/i2c";
+import SMBus from "embedded:io/smbus";
+import SPI from "embedded:io/spi";
+import Serial from "embedded:io/serial";
+import type { PinSpecifier } from "embedded:io/_common";
+
+declare global {
+ interface Device {
+ io: {
+ Digital: typeof Digital;
+ DigitalBank: typeof DigitalBank;
+ Analog: typeof Analog;
+ PWM: typeof PWM;
+ PulseCount: typeof PulseCount;
+ I2C: typeof I2C;
+ SMBus: typeof SMBus;
+ SPI: typeof SPI;
+ Serial: typeof Serial;
+ };
+ Digital: { default: ConstructorParameters[0] };
+ DigitalBank: { default: ConstructorParameters[0] };
+ Analog: { default: ConstructorParameters[0] };
+ PWM: { default: ConstructorParameters[0] };
+ PulseCount: { default: ConstructorParameters[0] };
+ I2C: { default: ConstructorParameters[0] };
+ SMBus: { default: ConstructorParameters[0] };
+ SPI: { default: ConstructorParameters[0] };
+ Serial: { default: ConstructorParameters[0] };
+ pin: { [name: string]: PinSpecifier };
+ }
+}
diff --git a/typings/embedded_provider/builtin.d.ts b/typings/embedded_provider/builtin.d.ts
index ea56a861b6..9b4a69a3ab 100644
--- a/typings/embedded_provider/builtin.d.ts
+++ b/typings/embedded_provider/builtin.d.ts
@@ -18,40 +18,6 @@
*
*/
-
declare module "embedded:provider/builtin" {
- import Digital from "embedded:io/digital";
- import DigitalBank from "embedded:io/digitalbank";
- import Analog from "embedded:io/analog";
- import PWM from "embedded:io/pwm";
- import PulseCount from "embedded:io/pulsecount";
- import I2C from "embedded:io/i2c";
- import SMBus from "embedded:io/smbus";
- import SPI from "embedded:io/spi";
- import Serial from "embedded:io/serial";
- import type { PinSpecifier } from "embedded:io/_common";
- const device: {
- io: {
- Digital: typeof Digital;
- DigitalBank: typeof DigitalBank;
- Analog: typeof Analog;
- PWM: typeof PWM;
- PulseCount: typeof PulseCount;
- I2C: typeof I2C;
- SMBus: typeof SMBus;
- SPI: typeof SPI;
- Serial: typeof Serial;
- };
- Digital: { default: ConstructorParameters[0] };
- DigitalBank: { default: ConstructorParameters[0] };
- Analog: { default: ConstructorParameters[0] };
- PWM: { default: ConstructorParameters[0] };
- PulseCount: { default: ConstructorParameters[0] };
- I2C: { default: ConstructorParameters[0] };
- SMBus: { default: ConstructorParameters[0] };
- SPI: { default: ConstructorParameters[0] };
- Serial: { default: ConstructorParameters[0] };
- pin: { [name: string]: PinSpecifier };
- };
export default device;
-}
+}
\ No newline at end of file
diff --git a/typings/global.d.ts b/typings/global.d.ts
index be64bba413..caa579d73e 100644
--- a/typings/global.d.ts
+++ b/typings/global.d.ts
@@ -1,9 +1,8 @@
import System_ from "embedded:io/system"
-import Device from "embedded:provider/builtin"
+import "embedded:provider/builtin-device"
-export {}
declare global {
// NOTE: `System` is non-standard and temporary to support the IO examples. Breaking changes are possible.
var System: typeof System_;
- var device: typeof Device;
+ var device: Device;
}