-
Notifications
You must be signed in to change notification settings - Fork 243
Typing improvements for io
and fixes for websocketclient
, and a few others
#1429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: public
Are you sure you want to change the base?
Changes from 18 commits
6bc4f6a
f3c862b
e42b93c
2fe80d7
65d177e
201906a
9a3aa33
afeb566
04a118f
b6e275e
365854b
72b162a
2d935cb
e002eab
a0c86df
f88cff5
b318fce
629663f
47168b1
876f4e0
08e1cee
1c711f2
ae61e2d
37055ec
188fc24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about this change. It must fix a problem you see. But, it also would require the caller to set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch - on review I see I misunderstood what it was doing. I'll fix... |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
* 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 <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
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; | ||
read(buffer: Buffer): void; | ||
write(value: number | Buffer): void; | ||
close(): void; | ||
get format(): "number" | "buffer"; | ||
set format(value: "number" | "buffer"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for filling this in. The change is good. I don't want even more copies of the HTTP status code map in the repo. I'll make a module for those so it can be shared. But that doesn't need to hold this up.