Skip to content
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

add lua-mqtt #46

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions types/lua-mqtt/mqtt311.d.tl
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
--
-- https://luarocks.org/modules/fperrad/lua-mqtt
--

local record MQTT
_NAME: string
_VERSION: string
_DESCRIPTION: string
_COPYRIGHT: string
PORT: string
PORT_TLS: string

record Client
record Packet
enum Type
"CONNACK"
"PUBLISH"
"PUBACK"
"PUBREL"
"PUBREC"
"PUBCOMP"
"SUBACK"
"UNSUBACK"
"PINGRESP"
end

dup: boolean
id: integer
payload: string|{integer}
qos: integer
retain: boolean
rc: integer
sp: boolean
topic: string
type: Type
end

record Connect
record Will
{string}
qos: integer
retain: boolean
end

clean: boolean
keep_alive: integer
id: string
will: Will
username: string
password: string
end

record Publish
qos: integer
retain: boolean
end

connect: function(self: Client, options: Connect)
reconnect: function(self: Client, socket: any)
publish: function(self: Client, topic: string, payload: string, options: Publish)
subscribe: function(self: Client, list: {integer|string})
unsubscribe: function(self: Client, list: {string})
ping: function(self: Client)
disconnect: function(self: Client)
read: function(self: Client): Packet, string
end

record Params
logger: any
max_packet_size: integer
on_connect: function(reason_code: integer, session_present: boolean)
on_error: function(): boolean, string
on_message: function(topic: string, payload: string)
socket: any
end

match: function(name: string, filter: string): boolean

metamethod __call: function(_: MQTT, t: Params): Client
end

return MQTT
120 changes: 120 additions & 0 deletions types/lua-mqtt/mqtt5.d.tl
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
--
-- https://luarocks.org/modules/fperrad/lua-mqtt
--

local record MQTT
_NAME: string
_VERSION: string
_DESCRIPTION: string
_COPYRIGHT: string
PORT: string
PORT_TLS: string

enum Prop
"PAYLOAD_FORMAT_INDICATOR"
"MESSAGE_EXPIRY_INTERVAL"
"CONTENT_TYPE"
"RESPONSE_TOPIC"
"CORRELATION_DATA"
"SUBSCRIPTION_IDENTIFIER"
"SESSION_EXPIRY_INTERVAL"
"ASSIGNED_CLIENT_IDENTIFIER"
"SERVER_KEEP_ALIVE"
"AUTHENTICATION_METHOD"
"AUTHENTICATION_DATA"
"REQUEST_PROBLEM_INFORMATION"
"WILL_DELAY_INTERVAL"
"REQUEST_RESPONSE_INFORMATION"
"RESPONSE_INFORMATION"
"SERVER_REFERENCE"
"REASON_STRING"
"RECEIVE_MAXIMUM"
"TOPIC_ALIAS_MAXIMUM"
"TOPIC_ALIAS"
"MAXIMUM_QOS"
"RETAIN_AVAILABLE"
"USER_PROPERTY"
"MAXIMUM_PACKET_SIZE"
"WILDCARD_SUB_AVAILABLE"
"SUBSCRIPTION_ID_AVAILABLE"
"SHARED_SUB_AVAILABLE"
end
PROP: {Prop:integer}

type Properties = {integer|string|table}

record Client
record Packet
enum Type
"CONNACK"
"PUBLISH"
"PUBACK"
"PUBREL"
"PUBREC"
"PUBCOMP"
"SUBACK"
"UNSUBACK"
"PINGRESP"
"DISCONNECT"
"AUTH"
end

dup: boolean
id: integer
payload: string|{integer}
props: Properties
qos: integer
retain: boolean
rc: integer
sp: boolean
topic: string
type: Type
end

record Connect
record Will
{string}
qos: integer
retain: boolean
props: Properties
end

clean: boolean
keep_alive: integer
id: string
will: Will
username: string
password: string
end

record Publish
qos: integer
retain: boolean
end

connect: function(self: Client, options: Connect, props: Properties)
reconnect: function(self: Client, socket: any)
publish: function(self: Client, topic: string, payload: string, options: Publish, props: Properties)
subscribe: function(self: Client, list: {integer|string}, props: Properties)
unsubscribe: function(self: Client, list: {string}, props: Properties)
ping: function(self: Client)
disconnect: function(self: Client, reason_code: integer, props: Properties)
auth: function(self: Client, reason_code: integer, props: Properties)
read: function(self: Client): Packet, string
end

record Params
logger: any
on_connect: function(reason_code: integer, session_present: boolean, props: Properties)
on_message: function(topic: string, payload: string, props: Properties)
on_disconnect: function(reason_code: integer, props: Properties)
on_error: function(): boolean, string
socket: any
end

match: function(name: string, filter: string): boolean

metamethod __call: function(_: MQTT, t: Params): Client
end

return MQTT