@moddable/typings 9.5.0 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/DS18X20.d.ts +40 -0
  2. package/{embedded_io/system.d.ts → ResourceIterator.d.ts} +4 -9
  3. package/ble/bleclient.d.ts +1 -0
  4. package/ble/bleserver.d.ts +1 -0
  5. package/ble/btutils.d.ts +3 -0
  6. package/ble/connection.d.ts +1 -0
  7. package/ble/gap.d.ts +2 -0
  8. package/ble/gatt.d.ts +4 -0
  9. package/ble/hidclient.d.ts +5 -0
  10. package/ble/sm.d.ts +3 -0
  11. package/captiveportal.d.ts +5 -5
  12. package/commodetto/Poco.d.ts +10 -2
  13. package/commodetto/ReadGIF.d.ts +1 -1
  14. package/commodetto/outline.d.ts +4 -1
  15. package/commodetto/parseRLE.d.ts +1 -1
  16. package/commodetto/readJPEG.d.ts +1 -1
  17. package/config/analog.d.ts +31 -0
  18. package/config/digital.d.ts +32 -0
  19. package/config/dns.d.ts +33 -0
  20. package/config/dnssd.d.ts +31 -0
  21. package/config/files.d.ts +27 -0
  22. package/config/flash.d.ts +27 -0
  23. package/config/httpclient.d.ts +34 -0
  24. package/config/httpsclient.d.ts +34 -0
  25. package/config/httpserver.d.ts +33 -0
  26. package/config/i2c.d.ts +33 -0
  27. package/config/mqtt.d.ts +27 -0
  28. package/config/mqttclient.d.ts +31 -0
  29. package/config/mqttsclient.d.ts +32 -0
  30. package/config/ntp.d.ts +34 -0
  31. package/config/pulsecount.d.ts +30 -0
  32. package/config/pwm.d.ts +30 -0
  33. package/config/serial.d.ts +31 -0
  34. package/config/socket.d.ts +34 -0
  35. package/config/spi.d.ts +31 -0
  36. package/config/storage.d.ts +27 -0
  37. package/config/system.d.ts +27 -0
  38. package/config/tls.d.ts +30 -0
  39. package/config/update.d.ts +27 -0
  40. package/config/wsclient.d.ts +31 -0
  41. package/config/wssclient.d.ts +32 -0
  42. package/crc.d.ts +1 -1
  43. package/dns/server.d.ts +1 -0
  44. package/embedded/RTC/zephyr-builtin.d.ts +48 -0
  45. package/embedded/RTC.d.ts +18 -7
  46. package/embedded/display.d.ts +8 -3
  47. package/embedded/storage/files.d.ts +10 -7
  48. package/embedded/storage/flash.d.ts +2 -2
  49. package/embedded/storage/key-value.d.ts +27 -6
  50. package/embedded/system.d.ts +49 -0
  51. package/embedded_io/_common.d.ts +42 -3
  52. package/embedded_io/analog.d.ts +7 -7
  53. package/embedded_io/audio/in.d.ts +3 -2
  54. package/embedded_io/audio/out.d.ts +12 -4
  55. package/embedded_io/ble/central.d.ts +5 -4
  56. package/embedded_io/ble/peripheral.d.ts +6 -5
  57. package/embedded_io/crypt/digest.d.ts +2 -2
  58. package/embedded_io/digital.d.ts +4 -3
  59. package/embedded_io/digitalbank.d.ts +9 -5
  60. package/embedded_io/i2c.d.ts +9 -6
  61. package/embedded_io/image/in/camera.d.ts +82 -0
  62. package/embedded_io/pulsecount.d.ts +7 -5
  63. package/embedded_io/pwm.d.ts +11 -5
  64. package/embedded_io/serial.d.ts +33 -16
  65. package/embedded_io/socket/listener.d.ts +3 -2
  66. package/embedded_io/socket/tcp/tls.d.ts +41 -12
  67. package/embedded_io/socket/tcp.d.ts +26 -12
  68. package/embedded_io/socket/udp.d.ts +17 -12
  69. package/embedded_io/spi.d.ts +8 -6
  70. package/embedded_network/dns/resolver/udp.d.ts +13 -6
  71. package/embedded_network/dns/server/udp.d.ts +39 -0
  72. package/embedded_network/dnssd.d.ts +9 -7
  73. package/embedded_network/http/client.d.ts +21 -7
  74. package/embedded_network/http/server/route/serversentevents.d.ts +48 -0
  75. package/embedded_network/http/server/route/static.d.ts +41 -0
  76. package/embedded_network/http/server/route/webdav.d.ts +42 -0
  77. package/embedded_network/http/server/route/ws/handshake.d.ts +28 -0
  78. package/embedded_network/http/server.d.ts +27 -6
  79. package/embedded_network/interface/ethernet.d.ts +3 -3
  80. package/embedded_network/interface/wifi/accesspoint.d.ts +2 -2
  81. package/embedded_network/interface/wifi.d.ts +21 -12
  82. package/embedded_network/mdns.d.ts +2 -2
  83. package/embedded_network/mqtt/client.d.ts +55 -16
  84. package/embedded_network/ntp/client.d.ts +16 -8
  85. package/embedded_network/websocket/client.d.ts +47 -28
  86. package/embedded_provider/builtin.d.ts +40 -34
  87. package/file.d.ts +4 -0
  88. package/flash.d.ts +1 -0
  89. package/global.d.ts +0 -3
  90. package/host/default.d.ts +31 -0
  91. package/host/esp32/moddable_six.d.ts +50 -0
  92. package/host/esp32/moddable_two.d.ts +55 -0
  93. package/host/generic.d.ts +47 -0
  94. package/host/index.d.ts +24 -0
  95. package/host/lin.d.ts +30 -0
  96. package/host/mac.d.ts +30 -0
  97. package/host/pebble.d.ts +70 -0
  98. package/host/win.d.ts +30 -0
  99. package/http.d.ts +2 -0
  100. package/mcpack.d.ts +20 -0
  101. package/mdns.d.ts +1 -0
  102. package/modules.d.ts +1 -1
  103. package/mqtt/js.d.ts +22 -4
  104. package/neopixel.d.ts +2 -2
  105. package/onewire.d.ts +31 -0
  106. package/package.json +14 -4
  107. package/pebble/accelerometer.d.ts +5 -5
  108. package/pebble/battery.d.ts +3 -3
  109. package/pebble/button.d.ts +2 -2
  110. package/pebble/compass.d.ts +3 -3
  111. package/pebble/dictation.d.ts +2 -2
  112. package/pebble/global.d.ts +37 -3
  113. package/pebble/health.d.ts +2 -2
  114. package/pebble/location.d.ts +2 -2
  115. package/pebble/message.d.ts +5 -5
  116. package/pebble/piu.d.ts +2 -57
  117. package/pebble/poco.d.ts +2 -2
  118. package/pebble/texture.d.ts +33 -0
  119. package/pebble/touch.d.ts +47 -0
  120. package/ping.d.ts +1 -0
  121. package/pins/analog.d.ts +1 -0
  122. package/pins/audioin.d.ts +1 -0
  123. package/pins/digital.d.ts +1 -0
  124. package/pins/i2c.d.ts +1 -0
  125. package/pins/pwm.d.ts +1 -0
  126. package/pins/rmt.d.ts +1 -0
  127. package/pins/servo.d.ts +1 -0
  128. package/pins/smbus.d.ts +1 -0
  129. package/piu/MC-types.d.ts +231 -97
  130. package/piu/MC.d.ts +2 -1
  131. package/piu/QRCode.d.ts +5 -0
  132. package/piu/RoundRect.d.ts +53 -0
  133. package/piu/SVGImage.d.ts +62 -0
  134. package/piu/Timeline.d.ts +17 -21
  135. package/pococolorcell.d.ts +25 -0
  136. package/pocoqrcode.d.ts +25 -0
  137. package/pocostatic.d.ts +25 -0
  138. package/preference.d.ts +1 -0
  139. package/securesocket.d.ts +1 -0
  140. package/sntp.d.ts +1 -0
  141. package/socket.d.ts +6 -0
  142. package/ssl/session.d.ts +60 -0
  143. package/time.d.ts +1 -1
  144. package/tsconfig.es2024.json +0 -1
  145. package/tsconfig.es2025.json +1 -1
  146. package/web/bluetooth.d.ts +112 -0
  147. package/web/decompressionstream.d.ts +1 -1
  148. package/web/eventsource.d.ts +12 -7
  149. package/web/fetch-streams.d.ts +57 -0
  150. package/web/fetch.d.ts +1 -1
  151. package/web/serial.d.ts +58 -0
  152. package/web/websocket.d.ts +18 -13
  153. package/web/webstorage.d.ts +3 -0
  154. package/web/worker.d.ts +2 -0
  155. package/websocket.d.ts +2 -0
  156. package/wifi.d.ts +1 -0
  157. package/xs.d.ts +52 -5
  158. package/data/location/nmea.d.ts +0 -103
  159. package/data/location/ubx.d.ts +0 -78
  160. package/display.d.ts +0 -68
  161. package/embedded/sensor/Barometer-Humidity-Temperature/BME280.d.ts +0 -102
  162. package/embedded/sensor/Location/GPS.d.ts +0 -96
  163. package/embedded/sensor/Location/IP.d.ts +0 -67
  164. package/pebble/device.d.ts +0 -51
@@ -18,6 +18,9 @@
18
18
  *
19
19
  */
20
20
 
21
+ // the manifest that supplies this module includes the manifests of these configurations
22
+ /// <reference path="../../config/httpserver.d.ts" />
23
+
21
24
  declare module "embedded:network/http/server" {
22
25
  import type Listener from "embedded:io/socket/listener";
23
26
  import type TCP from "embedded:io/socket/tcp";
@@ -40,8 +43,12 @@ declare module "embedded:network/http/server" {
40
43
  onResponse?(this: HTTPConnection, response: HTTPResponse): void;
41
44
  onWritable?(this: HTTPConnection, count: number): void;
42
45
  onDone?(this: HTTPConnection): void;
43
- onError?(this: HTTPConnection): void;
46
+ onError?(this: HTTPConnection, error: string): void;
47
+ }
48
+
49
+ export interface HTTPRouteTypes {
44
50
  }
51
+ export type HTTPRoute = HTTPConnectionHandlers | HTTPRouteTypes[keyof HTTPRouteTypes];
45
52
 
46
53
  export interface HTTPConnection extends Disposable {
47
54
  close(): void;
@@ -50,21 +57,35 @@ declare module "embedded:network/http/server" {
50
57
  respond(options: HTTPResponse): void;
51
58
  read(count?: number): ArrayBuffer | undefined;
52
59
  write(bytes?: ByteBuffer): number;
53
- route: HTTPConnectionHandlers;
60
+ route: HTTPRoute;
54
61
  format: "buffer";
62
+ protocol?: string;
55
63
  }
56
64
 
57
- export interface HTTPServerOptions {
65
+ export interface HTTPServerSocketProvider {
58
66
  io: typeof Listener;
67
+ }
68
+
69
+ export interface HTTPServerProvider {
70
+ io: typeof HTTPServer;
71
+ socket: HTTPServerSocketProvider;
72
+ }
73
+
74
+ export interface HTTPServerOptions extends Partial<HTTPServerProvider> {
75
+ socket: HTTPServerSocketProvider;
59
76
  port?: number;
60
- onConnect(this: HTTPServer, connection: HTTPConnection): void;
77
+ keepAlive?: number;
78
+ onConnect?(this: HTTPServer, connection: HTTPConnection): void;
79
+ target?: any;
80
+ onRoute?(this: HTTPServer, request: HTTPRequest): HTTPRoute | undefined | null | false | void;
61
81
  }
62
82
 
63
- class HTTPServer {
83
+ class HTTPServer implements Disposable {
84
+ target?: any;
64
85
  constructor(options: HTTPServerOptions);
65
86
  close(): void;
66
87
  readonly port: number;
88
+ [Symbol.dispose](): void;
67
89
  }
68
- interface HTTPServer extends Disposable {}
69
90
  export default HTTPServer;
70
91
  }
@@ -25,7 +25,7 @@ declare module "embedded:network/interface/ethernet" {
25
25
 
26
26
  export interface EthernetConstructorOptions {
27
27
  port?: PortSpecifier;
28
- onChanged?: (property: EthernetChangedProperty) => void;
28
+ onChanged?: (this: Ethernet, property: EthernetChangedProperty) => void;
29
29
  }
30
30
 
31
31
  export interface EthernetStaticAddress {
@@ -39,7 +39,7 @@ declare module "embedded:network/interface/ethernet" {
39
39
  static?: EthernetStaticAddress | false;
40
40
  }
41
41
 
42
- class Ethernet {
42
+ class Ethernet implements Disposable {
43
43
  constructor(options: EthernetConstructorOptions);
44
44
 
45
45
  close(): void;
@@ -50,8 +50,8 @@ declare module "embedded:network/interface/ethernet" {
50
50
  readonly connection: number;
51
51
  readonly address: string | undefined;
52
52
  readonly MAC: string | undefined;
53
+ [Symbol.dispose](): void;
53
54
  }
54
- interface Ethernet extends Disposable {}
55
55
 
56
56
  export default Ethernet;
57
57
  }
@@ -47,7 +47,7 @@ declare module "embedded:network/interface/wifi/accesspoint" {
47
47
  portal?: string;
48
48
  }
49
49
 
50
- class WiFiAccessPoint {
50
+ class WiFiAccessPoint implements Disposable {
51
51
  constructor(options: WiFiAccessPointConstructorOptions);
52
52
 
53
53
  close(): void;
@@ -58,8 +58,8 @@ declare module "embedded:network/interface/wifi/accesspoint" {
58
58
  readonly MAC: string | undefined;
59
59
  readonly SSID: string | undefined;
60
60
  readonly channel: number | undefined;
61
+ [Symbol.dispose](): void;
61
62
  }
62
- interface WiFiAccessPoint extends Disposable {}
63
63
 
64
64
  export default WiFiAccessPoint;
65
65
  }
@@ -23,28 +23,34 @@ declare module "embedded:network/interface/wifi" {
23
23
 
24
24
  export type WiFiChangedProperty = "connection" | "address";
25
25
 
26
+ export type WiFiSecurity = "none" | "wep" | "wpa_psk" | "wpa2_psk" | "wpa_wpa2_psk" | "wpa3_psk" | "wpa2_wpa3_psk" | "wpa2_enterprise" | "unknown" | (string & {});
27
+
26
28
  export interface WiFiConstructorOptions {
27
29
  port?: PortSpecifier;
28
- onChanged?: (property: WiFiChangedProperty) => void;
30
+ onChanged?: (this: WiFi, property: WiFiChangedProperty) => void;
29
31
  }
30
32
 
31
33
  export interface WiFiScanResult {
32
34
  SSID: string;
33
- channel: number;
35
+ BSSID: string;
34
36
  RSSI: number;
35
- BSSID?: string;
37
+ channel: number;
38
+ security: WiFiSecurity;
36
39
  }
37
40
 
38
41
  export interface WiFiScanOptions {
39
- onFound?: (result: WiFiScanResult) => void;
40
- onComplete?: () => void;
42
+ onFound: (this: WiFi, result: WiFiScanResult) => void;
43
+ onComplete?: (this: WiFi) => void;
44
+ channel?: number;
45
+ frequency?: 2.4 | 5;
46
+ secure?: boolean;
41
47
  }
42
48
 
43
- export interface WiFiConnectOptions {
44
- SSID: string;
49
+ export type WiFiConnectOptions = ({ SSID: string; BSSID?: string } | { SSID?: string; BSSID: string }) & {
45
50
  password?: string;
46
- secure?: boolean;
47
- }
51
+ secure?: boolean; // true to disallow connecting to an open access point
52
+ channel?: number;
53
+ };
48
54
 
49
55
  export interface WiFiStaticAddress {
50
56
  address: string;
@@ -52,27 +58,30 @@ declare module "embedded:network/interface/wifi" {
52
58
  gateway: string;
53
59
  }
54
60
 
61
+ // Moddable SDK extension
55
62
  export interface WiFiConfigureOptions {
56
63
  hostname?: string;
57
64
  static?: WiFiStaticAddress | false;
58
65
  }
59
66
 
60
- class WiFi {
67
+ class WiFi implements Disposable {
61
68
  constructor(options: WiFiConstructorOptions);
62
69
 
63
70
  close(): void;
64
71
  scan(options: WiFiScanOptions): void;
65
72
  connect(options: WiFiConnectOptions): void;
66
73
  disconnect(): void;
67
- configure(options: WiFiConfigureOptions): void;
74
+ configure(options: WiFiConfigureOptions): void; // Moddable SDK extension
68
75
 
69
76
  readonly connection: number;
70
77
  readonly address: string | undefined;
71
78
  readonly MAC: string | undefined;
72
79
  readonly SSID: string | undefined;
80
+ readonly BSSID: string | undefined;
73
81
  readonly RSSI: number | undefined;
82
+ readonly channel: number | undefined;
83
+ [Symbol.dispose](): void;
74
84
  }
75
- interface WiFi extends Disposable {}
76
85
 
77
86
  export default WiFi;
78
87
  }
@@ -70,13 +70,13 @@ declare module "embedded:network/mdns" {
70
70
  close(): void;
71
71
  }
72
72
 
73
- class DNSSD {
73
+ class DNSSD implements Disposable {
74
74
  constructor(options: DNSSDOptions);
75
75
  close(): void;
76
76
  claim(options: ClaimOptions): ClaimInstance;
77
77
  advertise(options: AdvertiseOptions): AdvertiseInstance;
78
78
  discover(options: DiscoverOptions): DiscoverInstance;
79
+ [Symbol.dispose](): void;
79
80
  }
80
- interface DNSSD extends Disposable {}
81
81
  export default DNSSD;
82
82
  }
@@ -1,4 +1,18 @@
1
+ // the manifest that supplies this module includes the manifests of these configurations
2
+ /// <reference path="../../config/mqttclient.d.ts" />
3
+
1
4
  declare module "embedded:network/mqtt/client" {
5
+ import type TCP from "embedded:io/socket/tcp";
6
+ import type TLS from "embedded:io/socket/tcp/tls";
7
+ import type { ClientSocket } from "embedded:io/socket/tcp/tls";
8
+ import type { DNSResolverProvider } from "embedded:network/dns/resolver/udp";
9
+
10
+ export interface MQTTClientProvider {
11
+ io: typeof MQTTClient,
12
+ dns: DNSResolverProvider,
13
+ socket: ClientSocket,
14
+ }
15
+
2
16
  interface onReadableOptions {
3
17
  more: boolean,
4
18
  topic?: string,
@@ -26,33 +40,58 @@ declare module "embedded:network/mqtt/client" {
26
40
  password?: string,
27
41
  id?: string,
28
42
  clean?: boolean,
29
- will?: any,
43
+ will?: Will,
30
44
  keepAlive?: number, // milliseconds
31
- onReadable?: (count: number, options: onReadableOptions) => void,
32
- onWritable?: (count: number) => void,
33
- onControl?: (opcode: number, message: onControlMessage) => void,
34
- onClose?: () => void,
35
- onError?: (error: any) => void,
36
- dns: Record<string, any>,
37
- socket: Record<string, any>,
45
+ onReadable?: (this: MQTTClient, count: number, options: onReadableOptions) => void,
46
+ onWritable?: (this: MQTTClient, count: number) => void,
47
+ onControl?: (this: MQTTClient, opcode: number, message: onControlMessage) => void,
48
+ onClose?: (this: MQTTClient) => void,
49
+ onError?: (this: MQTTClient, error: any) => void,
50
+ target?: any,
51
+ dns: DNSResolverProvider,
52
+ socket: ClientSocket,
38
53
  }
39
54
 
40
- interface WriteOptions {
41
- operation?: number,
55
+ interface PublishOptions {
56
+ operation?: typeof MQTTClient.PUBLISH,
42
57
  id?: number,
43
58
  topic: string,
44
59
  QoS?: number,
45
60
  retain?: boolean,
46
61
  duplicate?: boolean,
47
- byteLength?: number,
48
- items?: any[], // being lazy here
62
+ byteLength?: number, // total payload, when larger than this first fragment
63
+ }
64
+
65
+ interface SubscribeOptions {
66
+ operation: typeof MQTTClient.SUBSCRIBE,
67
+ id?: number,
68
+ items: { topic: string, QoS?: number }[],
49
69
  }
50
70
 
51
- class MQTTClient {
71
+ interface UnsubscribeOptions {
72
+ operation: typeof MQTTClient.UNSUBSCRIBE,
73
+ id?: number,
74
+ items: { topic: string }[],
75
+ }
76
+
77
+ interface AcknowledgeOptions {
78
+ operation: typeof MQTTClient.PUBACK | typeof MQTTClient.PUBREC | typeof MQTTClient.PUBREL | typeof MQTTClient.PUBCOMP,
79
+ id: number,
80
+ }
81
+
82
+ interface SessionOptions {
83
+ operation: typeof MQTTClient.PINGREQ | typeof MQTTClient.DISCONNECT,
84
+ }
85
+
86
+ type WriteOptions = PublishOptions | SubscribeOptions | UnsubscribeOptions | AcknowledgeOptions | SessionOptions;
87
+
88
+ class MQTTClient implements Disposable {
89
+ target?: any
52
90
  constructor(options: Options)
53
- read(count: number): ArrayBuffer
91
+ read(count?: number): ArrayBuffer
54
92
  read(buffer: ByteBuffer): number
55
- write(data: ByteBuffer, options: WriteOptions): number
93
+ write(data: ByteBuffer): number // continues the publish in progress
94
+ write(data: ByteBuffer | null, options: WriteOptions): number
56
95
  close(): void
57
96
 
58
97
  static CONNECT: 1
@@ -69,7 +108,7 @@ declare module "embedded:network/mqtt/client" {
69
108
  static PINGREQ: 12
70
109
  static PINGRESP: 13
71
110
  static DISCONNECT: 14
111
+ [Symbol.dispose](): void
72
112
  }
73
- interface MQTTClient extends Disposable {}
74
113
  export default MQTTClient;
75
114
  }
@@ -18,10 +18,21 @@
18
18
  *
19
19
  */
20
20
 
21
+ // the manifest that supplies this module includes the manifests of these configurations
22
+ /// <reference path="../../config/ntp.d.ts" />
23
+
21
24
  declare module "embedded:network/ntp/client" {
22
25
  import type UDP from "embedded:io/socket/udp";
23
26
  import type Resolver from "embedded:network/dns/resolver/udp";
24
-
27
+ import type { DNSResolverProvider } from "embedded:network/dns/resolver/udp";
28
+
29
+ export interface NTPClientProvider {
30
+ io: typeof NTP;
31
+ dns: DNSResolverProvider;
32
+ socket: { io: typeof UDP; [option: string]: unknown };
33
+ servers: string[];
34
+ }
35
+
25
36
  export interface NTPOptions<T = any> {
26
37
  servers: string[];
27
38
  socket: { io: typeof UDP };
@@ -29,17 +40,14 @@ declare module "embedded:network/ntp/client" {
29
40
  target?: T;
30
41
  }
31
42
 
32
- export interface NTPCallback {
33
- (error: null, time: number): void;
34
- (error: Error): void;
35
- }
43
+ export type NTPCallback<T = any> = (this: NTP<T>, error: Error | null, time: number) => void;
36
44
 
37
- class NTP<T = any> {
45
+ class NTP<T = any> implements Disposable {
38
46
  target?: T;
39
47
  constructor(options: NTPOptions<T>);
40
48
  close(): void;
41
- getTime(callback: NTPCallback): void;
49
+ getTime(callback: NTPCallback<T>): void;
50
+ [Symbol.dispose](): void;
42
51
  }
43
- interface NTP<T = any> extends Disposable {}
44
52
  export default NTP;
45
53
  }
@@ -21,56 +21,75 @@
21
21
  // websocketclient.d.ts
22
22
 
23
23
  declare module "embedded:network/websocket/client" {
24
- interface WebSocketClientOptions {
25
- onReadable?: (this: WebSocketClient, count: number, options: { more: boolean; binary: boolean }) => void;
26
- onWritable?: (this: WebSocketClient, count: number) => void;
27
- onControl?: (this: WebSocketClient, opcode: number, data: ArrayBuffer) => void;
28
- onClose?: (this: WebSocketClient) => void;
29
- onError?: (this: WebSocketClient) => void;
30
- format?: "buffer" | "number";
24
+ import type TCP from "embedded:io/socket/tcp";
25
+ import type TLS from "embedded:io/socket/tcp/tls";
26
+ import type { ClientSocket } from "embedded:io/socket/tcp/tls";
27
+ import type { DNSResolverProvider } from "embedded:network/dns/resolver/udp";
28
+
29
+ export interface WebSocketClientProvider {
30
+ io: typeof WebSocketClient;
31
+ dns: DNSResolverProvider;
32
+ socket: ClientSocket;
33
+ }
34
+
35
+ export type Format = "buffer" | "number";
36
+
37
+ export interface WebSocketClientOptions<F extends Format = Format> {
38
+ onReadable?: (this: WebSocketClient<F>, count: number, options: { more: boolean; binary: boolean }) => void;
39
+ onWritable?: (this: WebSocketClient<F>, count: number) => void;
40
+ onControl?: (this: WebSocketClient<F>, opcode: number, data: ArrayBuffer) => void;
41
+ onClose?: (this: WebSocketClient<F>) => void;
42
+ onError?: (this: WebSocketClient<F>) => void;
43
+ format?: F;
31
44
  target?: any;
32
- attach?: {
33
- constructor: new (options: any) => any;
34
- };
45
+ attach?: TCP;
35
46
  host?: string;
36
47
  path?: string;
37
48
  port?: number;
38
49
  protocol?: string;
39
50
  headers?: Map<string, string>;
40
- dns?: {
41
- io: new (options: any) => any;
42
- };
43
- socket?: {
44
- io: new (options: any) => any;
45
- };
51
+ dns?: DNSResolverProvider;
52
+ socket?: ClientSocket;
46
53
  }
47
54
 
48
- interface WebSocketWriteOptions {
55
+ export interface WebSocketWriteOptions {
49
56
  opcode?: number;
50
57
  binary?: boolean;
51
58
  more?: boolean;
52
59
  }
53
60
 
54
- class WebSocketClient {
55
- constructor(options: WebSocketClientOptions);
56
-
61
+ /*
62
+ F is the format named in the options when the client is created. Naming it there
63
+ (format: "buffer") fixes the type read() with no argument returns:
64
+ a byte for "number", an ArrayBuffer for "buffer".
65
+ When the options name no format, read() is typed as returning either, because the
66
+ format can be changed later through the format property.
67
+ */
68
+ interface WebSocketClient<F extends Format = Format> extends Disposable {
57
69
  close(): void;
58
70
  write(data: ByteBuffer, options?: WebSocketWriteOptions): number;
59
- read(): number | ArrayBuffer;
71
+ read(): F extends "number" ? number : ArrayBuffer;
60
72
  read(count: number): ArrayBuffer;
61
73
  read(buffer: ByteBuffer): number;
62
74
 
63
- format: "buffer" | "number";
75
+ get format(): F;
76
+ set format(value: Format);
64
77
  protocol: string | undefined;
65
78
  target?: any;
66
79
 
67
- static readonly text: 1;
68
- static readonly binary: 2;
69
- static readonly close: 8;
70
- static readonly ping: 9;
71
- static readonly pong: 10;
80
+ [Symbol.dispose](): void;
81
+ }
82
+ interface WebSocketClientConstructor {
83
+ new <F extends Format = Format>(options: WebSocketClientOptions<F>): WebSocketClient<F>;
84
+ readonly prototype: WebSocketClient;
85
+
86
+ readonly text: 1;
87
+ readonly binary: 2;
88
+ readonly close: 8;
89
+ readonly ping: 9;
90
+ readonly pong: 10;
72
91
  }
73
- interface WebSocketClient extends Disposable {}
92
+ const WebSocketClient: WebSocketClientConstructor;
74
93
 
75
94
  export default WebSocketClient;
76
95
  }
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2022 Shinya Ishikawa
2
+ * Copyright (c) 2026 Moddable Tech, Inc.
3
3
  *
4
4
  * This file is part of the Moddable SDK Tools.
5
5
  *
@@ -20,38 +20,44 @@
20
20
 
21
21
 
22
22
  declare module "embedded:provider/builtin" {
23
- import Digital from "embedded:io/digital";
24
- import DigitalBank from "embedded:io/digitalbank";
25
- import Analog from "embedded:io/analog";
26
- import PWM from "embedded:io/pwm";
27
- import PulseCount from "embedded:io/pulsecount";
28
- import I2C from "embedded:io/i2c";
29
- import SMBus from "embedded:io/smbus";
30
- import SPI from "embedded:io/spi";
31
- import Serial from "embedded:io/serial";
32
- import type { PinSpecifier } from "embedded:io/_common";
33
- const device: {
34
- io: {
35
- Digital: typeof Digital;
36
- DigitalBank: typeof DigitalBank;
37
- Analog: typeof Analog;
38
- PWM: typeof PWM;
39
- PulseCount: typeof PulseCount;
40
- I2C: typeof I2C;
41
- SMBus: typeof SMBus;
42
- SPI: typeof SPI;
43
- Serial: typeof Serial;
44
- };
45
- Digital: { default: ConstructorParameters<typeof Digital>[0] };
46
- DigitalBank: { default: ConstructorParameters<typeof DigitalBank>[0] };
47
- Analog: { default: ConstructorParameters<typeof Analog>[0] };
48
- PWM: { default: ConstructorParameters<typeof PWM>[0] };
49
- PulseCount: { default: ConstructorParameters<typeof PulseCount>[0] };
50
- I2C: { default: ConstructorParameters<typeof I2C>[0] };
51
- SMBus: { default: ConstructorParameters<typeof SMBus>[0] };
52
- SPI: { default: ConstructorParameters<typeof SPI>[0] };
53
- Serial: { default: ConstructorParameters<typeof Serial>[0] };
54
- pin: { [name: string]: PinSpecifier };
55
- };
23
+ export interface Device {
24
+ }
25
+ export interface DeviceIO {
26
+ }
27
+ // the host typing of a target with a network attaches DeviceNetwork to Device; the network configurations
28
+ // in the build (config/dns, config/httpclient, ...) add their providers to it
29
+ export interface DeviceNetwork {
30
+ }
31
+
32
+ export interface DeviceAnalog {
33
+ }
34
+ export interface DeviceI2C {
35
+ }
36
+ export interface DeviceSPI {
37
+ }
38
+ export interface DeviceSerial {
39
+ }
40
+
41
+ type Speed<T, K extends keyof T> = T extends unknown ? Omit<T, K> & Partial<Pick<T, K>> : never;
42
+ export type AnalogBus = ConstructorParameters<typeof import("embedded:io/analog").default>[0] & { io: typeof import("embedded:io/analog").default };
43
+ export type I2CBus = Speed<Omit<ConstructorParameters<typeof import("embedded:io/i2c").default>[0], "address">, "hz"> & { io: typeof import("embedded:io/i2c").default };
44
+ export type SPIBus = Speed<ConstructorParameters<typeof import("embedded:io/spi").default>[0], "hz"> & { io: typeof import("embedded:io/spi").default };
45
+ export type SerialBus = Speed<ConstructorParameters<typeof import("embedded:io/serial").default>[0], "baud"> & { io: typeof import("embedded:io/serial").default };
46
+
47
+ // any function or class
48
+ type Callable = ((...args: never) => unknown) | (abstract new (...args: never) => unknown);
49
+ // values that are not remapped: functions, classes, arrays, and byte buffers
50
+ type Leaf = Callable | readonly unknown[] | ArrayBufferLike | ArrayBufferView;
51
+
52
+ // device after lockdown: frozen with every io resolved to a constructor
53
+ type Frozen<T> = T extends Leaf ? T : T extends object ? { readonly [K in keyof T]: Frozen<T[K]> } : T;
54
+
55
+ // device before lockdown (during preload)
56
+ type Provider = { io: Callable };
57
+ type IOName<C> = { [N in keyof DeviceIO]: DeviceIO[N] extends C ? N : never }[keyof DeviceIO];
58
+ type ProviderConfig<T> = T extends Leaf ? T : T extends object ? { -readonly [K in keyof T]: K extends "io" ? T[K] | IOName<T[K]> : ProviderConfig<T[K]> } : T;
59
+ export type DeviceConfig<T = Device> = T extends Leaf ? T : T extends Provider ? ProviderConfig<T> : T extends object ? { -readonly [K in keyof T]?: DeviceConfig<T[K]> } : T;
60
+
61
+ const device: Frozen<Device>;
56
62
  export default device;
57
63
  }
package/file.d.ts CHANGED
@@ -22,6 +22,7 @@ declare module "file" {
22
22
  /**
23
23
  * The `File` class provides access to files.
24
24
  */
25
+ /** @deprecated Use the ECMA-419 files API, embedded:storage/files */
25
26
  export class File {
26
27
  constructor(path: string, write?: boolean);
27
28
  /**
@@ -50,16 +51,19 @@ declare module "file" {
50
51
  }
51
52
  type IteratorDirectoryEntry = {name: string, length: undefined};
52
53
  type IteratorFileEntry = {name: string, length: number};
54
+ /** @deprecated Use the ECMA-419 files API, embedded:storage/files */
53
55
  class Iterator {
54
56
  constructor(path: string);
55
57
  next(): IteratorDirectoryEntry | IteratorFileEntry | undefined;
56
58
  }
57
59
 
60
+ /** @deprecated Use the ECMA-419 files API, embedded:storage/files */
58
61
  class Directory {
59
62
  static create(path: string): void;
60
63
  static delete(path: string): void;
61
64
  }
62
65
 
66
+ /** @deprecated Use the ECMA-419 files API, embedded:storage/files */
63
67
  class System {
64
68
  static config(): {maxPathLength: number}
65
69
  static info(): {used: number, total: number};
package/flash.d.ts CHANGED
@@ -19,6 +19,7 @@
19
19
  */
20
20
 
21
21
  declare module "flash" {
22
+ /** @deprecated Use the ECMA-419 flash API, embedded:storage/flash */
22
23
  class Flash {
23
24
  constructor(partition?: string);
24
25
  constructor(offset: number, byteLength: number);
package/global.d.ts CHANGED
@@ -1,12 +1,9 @@
1
1
  declare module "global" {
2
2
 
3
- import System_ from "embedded:io/system"
4
3
  import Device from "embedded:provider/builtin"
5
4
 
6
5
  export {}
7
6
  global {
8
- // NOTE: `System` is non-standard and temporary to support the IO examples. Breaking changes are possible.
9
- var System: typeof System_;
10
7
  var device: typeof Device;
11
8
  }
12
9
  }
@@ -0,0 +1,31 @@
1
+ /*
2
+ * Copyright (c) 2026 Moddable Tech, Inc.
3
+ *
4
+ * This file is part of the Moddable SDK Tools.
5
+ *
6
+ * The Moddable SDK Tools is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * The Moddable SDK Tools is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with the Moddable SDK Tools. If not, see <http://www.gnu.org/licenses/>.
18
+ *
19
+ */
20
+
21
+ // the host provider typing when no target is named: the generic host plus every standard IO class,
22
+ // since without a manifest there is no way to know which are in the build
23
+ /// <reference path="./generic.d.ts" />
24
+ /// <reference path="../config/analog.d.ts" />
25
+ /// <reference path="../config/digital.d.ts" />
26
+ /// <reference path="../config/i2c.d.ts" />
27
+ /// <reference path="../config/pulsecount.d.ts" />
28
+ /// <reference path="../config/pwm.d.ts" />
29
+ /// <reference path="../config/serial.d.ts" />
30
+ /// <reference path="../config/socket.d.ts" />
31
+ /// <reference path="../config/spi.d.ts" />