@axpecter/lync 2.2.0 → 2.2.1
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.
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/api/Packet.luau +27 -18
- package/src/api/Query.luau +27 -16
- package/src/init.luau +15 -0
package/README.md
CHANGED
package/package.json
CHANGED
package/src/api/Packet.luau
CHANGED
|
@@ -39,24 +39,30 @@ end
|
|
|
39
39
|
|
|
40
40
|
-- Public types -----------------------------------------------------------
|
|
41
41
|
|
|
42
|
-
export type PacketHandle = {
|
|
43
|
-
send: (self: PacketHandle
|
|
44
|
-
on: (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
export type PacketHandle<T> = {
|
|
43
|
+
send: (self: PacketHandle<T>, data: T, target: any?) -> (),
|
|
44
|
+
on: (
|
|
45
|
+
self: PacketHandle<T>,
|
|
46
|
+
fn: (data: T, sender: Player?, timestamp: number?) -> ()
|
|
47
|
+
) -> Types.Connection,
|
|
48
|
+
once: (
|
|
49
|
+
self: PacketHandle<T>,
|
|
50
|
+
fn: (data: T, sender: Player?, timestamp: number?) -> ()
|
|
51
|
+
) -> Types.Connection,
|
|
52
|
+
wait: (self: PacketHandle<T>) -> (T, Player?, number?),
|
|
53
|
+
name: (self: PacketHandle<T>) -> string,
|
|
54
|
+
stats: (self: PacketHandle<T>) -> Types.PacketStats,
|
|
49
55
|
}
|
|
50
56
|
|
|
51
57
|
-- Public -----------------------------------------------------------------
|
|
52
58
|
|
|
53
59
|
local Packet = {}
|
|
54
60
|
|
|
55
|
-
function Packet.define(
|
|
61
|
+
function Packet.define<T>(
|
|
56
62
|
name: string,
|
|
57
|
-
codec: Types.InternalCodec<
|
|
63
|
+
codec: Types.InternalCodec<T>,
|
|
58
64
|
options: Types.PacketOptions?
|
|
59
|
-
): PacketHandle
|
|
65
|
+
): PacketHandle<T>
|
|
60
66
|
local opts = options or ({} :: Types.PacketOptions)
|
|
61
67
|
local isUnreliable = opts.unreliable or false
|
|
62
68
|
|
|
@@ -189,8 +195,11 @@ function Packet.define(
|
|
|
189
195
|
bumpFires()
|
|
190
196
|
end
|
|
191
197
|
|
|
198
|
+
type Self = PacketHandle<T>
|
|
199
|
+
type Listener = (data: T, sender: Player?, timestamp: number?) -> ()
|
|
200
|
+
|
|
192
201
|
local handle = {
|
|
193
|
-
send = function(_self:
|
|
202
|
+
send = function(_self: Self, data: T, target: any?): ()
|
|
194
203
|
if IS_SERVER then
|
|
195
204
|
sendFromServer(data, target)
|
|
196
205
|
else
|
|
@@ -198,11 +207,11 @@ function Packet.define(
|
|
|
198
207
|
end
|
|
199
208
|
end,
|
|
200
209
|
|
|
201
|
-
on = function(_self:
|
|
202
|
-
return reg.signal:connect(fn)
|
|
210
|
+
on = function(_self: Self, fn: Listener): Types.Connection
|
|
211
|
+
return reg.signal:connect(fn :: any)
|
|
203
212
|
end,
|
|
204
213
|
|
|
205
|
-
once = function(_self:
|
|
214
|
+
once = function(_self: Self, fn: Listener): Types.Connection
|
|
206
215
|
local conn: Types.Connection
|
|
207
216
|
conn = reg.signal:connect(function(...: any)
|
|
208
217
|
conn:disconnect()
|
|
@@ -211,15 +220,15 @@ function Packet.define(
|
|
|
211
220
|
return conn
|
|
212
221
|
end,
|
|
213
222
|
|
|
214
|
-
wait = function(_self:
|
|
223
|
+
wait = function(_self: Self): (T, Player?, number?)
|
|
215
224
|
return reg.signal:wait()
|
|
216
225
|
end,
|
|
217
226
|
|
|
218
|
-
name = function(_self:
|
|
227
|
+
name = function(_self: Self): string
|
|
219
228
|
return reg.name
|
|
220
229
|
end,
|
|
221
230
|
|
|
222
|
-
stats = function(_self:
|
|
231
|
+
stats = function(_self: Self): Types.PacketStats
|
|
223
232
|
return {
|
|
224
233
|
bytesSent = reg.bytesSent,
|
|
225
234
|
bytesReceived = reg.bytesReceived,
|
|
@@ -230,7 +239,7 @@ function Packet.define(
|
|
|
230
239
|
end,
|
|
231
240
|
}
|
|
232
241
|
|
|
233
|
-
return table.freeze(handle) :: PacketHandle
|
|
242
|
+
return table.freeze(handle) :: PacketHandle<T>
|
|
234
243
|
end
|
|
235
244
|
|
|
236
245
|
return table.freeze(Packet)
|
package/src/api/Query.luau
CHANGED
|
@@ -33,23 +33,32 @@ end
|
|
|
33
33
|
|
|
34
34
|
-- Public types -----------------------------------------------------------
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
--[[
|
|
37
|
+
Server `request(data, target)` returns `Resp?` for a Player target and
|
|
38
|
+
`{ [Player]: Resp? }` for a multi-target table; Luau doesn't support
|
|
39
|
+
overloads on table fields, so the type advertises `Resp?` (the common
|
|
40
|
+
single-target case). Multi-target callers must cast the return.
|
|
41
|
+
]]
|
|
42
|
+
export type QueryHandle<Req, Resp> = {
|
|
43
|
+
handle: (
|
|
44
|
+
self: QueryHandle<Req, Resp>,
|
|
45
|
+
fn: (request: Req, player: Player?) -> Resp?
|
|
46
|
+
) -> Types.Connection,
|
|
47
|
+
request: (self: QueryHandle<Req, Resp>, data: Req, target: any?) -> Resp?,
|
|
48
|
+
name: (self: QueryHandle<Req, Resp>) -> string,
|
|
49
|
+
stats: (self: QueryHandle<Req, Resp>) -> Types.PacketStats,
|
|
41
50
|
}
|
|
42
51
|
|
|
43
52
|
-- Public -----------------------------------------------------------------
|
|
44
53
|
|
|
45
54
|
local Query = {}
|
|
46
55
|
|
|
47
|
-
function Query.define(
|
|
56
|
+
function Query.define<Req, Resp>(
|
|
48
57
|
name: string,
|
|
49
|
-
requestCodec: Types.InternalCodec<
|
|
50
|
-
responseCodec: Types.InternalCodec<
|
|
58
|
+
requestCodec: Types.InternalCodec<Req>,
|
|
59
|
+
responseCodec: Types.InternalCodec<Resp>,
|
|
51
60
|
options: Types.QueryOptions?
|
|
52
|
-
): QueryHandle
|
|
61
|
+
): QueryHandle<Req, Resp>
|
|
53
62
|
local opts = options or ({} :: Types.QueryOptions)
|
|
54
63
|
local timeout = opts.timeout or DEFAULT_TIMEOUT
|
|
55
64
|
|
|
@@ -228,14 +237,16 @@ function Query.define(
|
|
|
228
237
|
return coroutine.yield()
|
|
229
238
|
end
|
|
230
239
|
|
|
240
|
+
type Self = QueryHandle<Req, Resp>
|
|
241
|
+
|
|
231
242
|
local handle = {
|
|
232
243
|
handle = function(
|
|
233
|
-
_self:
|
|
234
|
-
fn: (request:
|
|
244
|
+
_self: Self,
|
|
245
|
+
fn: (request: Req, player: Player?) -> Resp?
|
|
235
246
|
): Types.Connection
|
|
236
247
|
handlerToken += 1
|
|
237
248
|
local myToken = handlerToken
|
|
238
|
-
activeHandler = fn
|
|
249
|
+
activeHandler = fn :: any
|
|
239
250
|
|
|
240
251
|
local conn = { connected = true }
|
|
241
252
|
function conn.disconnect(self): ()
|
|
@@ -250,18 +261,18 @@ function Query.define(
|
|
|
250
261
|
return conn :: Types.Connection
|
|
251
262
|
end,
|
|
252
263
|
|
|
253
|
-
request = function(_self:
|
|
264
|
+
request = function(_self: Self, data: Req, target: any?): Resp?
|
|
254
265
|
if IS_SERVER then
|
|
255
266
|
return requestFromServer(data, target)
|
|
256
267
|
end
|
|
257
268
|
return requestFromClient(data)
|
|
258
269
|
end,
|
|
259
270
|
|
|
260
|
-
name = function(_self:
|
|
271
|
+
name = function(_self: Self): string
|
|
261
272
|
return name
|
|
262
273
|
end,
|
|
263
274
|
|
|
264
|
-
stats = function(_self:
|
|
275
|
+
stats = function(_self: Self): Types.PacketStats
|
|
265
276
|
return {
|
|
266
277
|
bytesSent = reqReg.bytesSent + respReg.bytesSent,
|
|
267
278
|
bytesReceived = reqReg.bytesReceived + respReg.bytesReceived,
|
|
@@ -272,7 +283,7 @@ function Query.define(
|
|
|
272
283
|
end,
|
|
273
284
|
}
|
|
274
285
|
|
|
275
|
-
return table.freeze(handle) :: QueryHandle
|
|
286
|
+
return table.freeze(handle) :: QueryHandle<Req, Resp>
|
|
276
287
|
end
|
|
277
288
|
|
|
278
289
|
function Query.pendingCount(): number
|
package/src/init.luau
CHANGED
|
@@ -48,6 +48,21 @@ local UDimC = require(script.codec.datatype.UDim)
|
|
|
48
48
|
local UnknownC = require(script.codec.meta.Unknown)
|
|
49
49
|
local VectorC = require(script.codec.datatype.Vector)
|
|
50
50
|
|
|
51
|
+
-- Public types (re-exported so users can write `Lync.Packet<MyData>`) ---
|
|
52
|
+
|
|
53
|
+
export type Codec<T> = Types.Codec<T>
|
|
54
|
+
export type Connection = Types.Connection
|
|
55
|
+
export type Packet<T> = Packet.PacketHandle<T>
|
|
56
|
+
export type Query<Req, Resp> = Query.QueryHandle<Req, Resp>
|
|
57
|
+
export type Group = Group.GroupHandle
|
|
58
|
+
export type Scope = Scope.ScopeHandle
|
|
59
|
+
export type PacketOptions = Types.PacketOptions
|
|
60
|
+
export type QueryOptions = Types.QueryOptions
|
|
61
|
+
export type ConfigureOptions = Types.ConfigureOptions
|
|
62
|
+
export type RateLimitConfig = Types.RateLimitConfig
|
|
63
|
+
export type PacketStats = Types.PacketStats
|
|
64
|
+
export type PlayerStats = Types.PlayerStats
|
|
65
|
+
|
|
51
66
|
-- Constants --------------------------------------------------------------
|
|
52
67
|
|
|
53
68
|
local IS_SERVER = RunService:IsServer()
|