@flamework-experimental/networking 2.0.0-alpha.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.
- package/README.md +66 -0
- package/flamework.build +7 -0
- package/out/event/createEvent.d.ts +59 -0
- package/out/event/createEvent.luau +114 -0
- package/out/event/createRemoteInstance.d.ts +1 -0
- package/out/event/createRemoteInstance.luau +58 -0
- package/out/events/createClientMethod.d.ts +5 -0
- package/out/events/createClientMethod.luau +30 -0
- package/out/events/createGenericHandler.d.ts +5 -0
- package/out/events/createGenericHandler.luau +102 -0
- package/out/events/createNetworkingEvent.d.ts +2 -0
- package/out/events/createNetworkingEvent.luau +60 -0
- package/out/events/createServerMethod.d.ts +13 -0
- package/out/events/createServerMethod.luau +63 -0
- package/out/events/types.d.ts +220 -0
- package/out/function/createFunctionReceiver.d.ts +52 -0
- package/out/function/createFunctionReceiver.luau +118 -0
- package/out/function/createFunctionSender.d.ts +45 -0
- package/out/function/createFunctionSender.luau +135 -0
- package/out/function/errors.d.ts +10 -0
- package/out/function/errors.luau +25 -0
- package/out/functions/createClientMethod.d.ts +15 -0
- package/out/functions/createClientMethod.luau +52 -0
- package/out/functions/createGenericHandler.d.ts +7 -0
- package/out/functions/createGenericHandler.luau +140 -0
- package/out/functions/createNetworkingFunction.d.ts +2 -0
- package/out/functions/createNetworkingFunction.luau +68 -0
- package/out/functions/createServerMethod.d.ts +15 -0
- package/out/functions/createServerMethod.luau +52 -0
- package/out/functions/types.d.ts +289 -0
- package/out/handlers.d.ts +36 -0
- package/out/index.d.ts +55 -0
- package/out/init.luau +78 -0
- package/out/middleware/createGuardMiddleware.d.ts +6 -0
- package/out/middleware/createGuardMiddleware.luau +44 -0
- package/out/middleware/createMiddlewareProcessor.d.ts +3 -0
- package/out/middleware/createMiddlewareProcessor.luau +24 -0
- package/out/middleware/skip.d.ts +8 -0
- package/out/middleware/skip.luau +22 -0
- package/out/middleware/types.d.ts +15 -0
- package/out/types.d.ts +78 -0
- package/out/util/createSignalContainer.d.ts +5 -0
- package/out/util/createSignalContainer.luau +30 -0
- package/out/util/getNamespaceConfig.d.ts +10 -0
- package/out/util/getNamespaceConfig.luau +15 -0
- package/out/util/timeoutPromise.d.ts +1 -0
- package/out/util/timeoutPromise.luau +10 -0
- package/package.json +32 -0
package/out/init.luau
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local NetworkingSkip = TS.import(script, script, "middleware", "skip").Skip
|
|
4
|
+
local NetworkingFunctionError = TS.import(script, script, "function", "errors").NetworkingFunctionError
|
|
5
|
+
local createNetworkingEvent = TS.import(script, script, "events", "createNetworkingEvent").createNetworkingEvent
|
|
6
|
+
local createNetworkingFunction = TS.import(script, script, "functions", "createNetworkingFunction").createNetworkingFunction
|
|
7
|
+
local Networking = {}
|
|
8
|
+
do
|
|
9
|
+
local _container = Networking
|
|
10
|
+
--[[
|
|
11
|
+
*
|
|
12
|
+
* Creates a new event based off the supplied types.
|
|
13
|
+
* @param serverMiddleware Middleware for server events
|
|
14
|
+
* @param clientMiddleware Middleware for client events
|
|
15
|
+
* @metadata macro
|
|
16
|
+
|
|
17
|
+
]]
|
|
18
|
+
local function createEvent(name)
|
|
19
|
+
return createNetworkingEvent(name)
|
|
20
|
+
end
|
|
21
|
+
_container.createEvent = createEvent
|
|
22
|
+
--[[
|
|
23
|
+
*
|
|
24
|
+
* Creates a new function event based off the supplied types.
|
|
25
|
+
* @param serverMiddleware Middleware for server events
|
|
26
|
+
* @param clientMiddleware Middleware for client events
|
|
27
|
+
* @metadata macro
|
|
28
|
+
|
|
29
|
+
]]
|
|
30
|
+
local function createFunction(name)
|
|
31
|
+
return createNetworkingFunction(name)
|
|
32
|
+
end
|
|
33
|
+
_container.createFunction = createFunction
|
|
34
|
+
--[[
|
|
35
|
+
*
|
|
36
|
+
* Stops networking function middleware.
|
|
37
|
+
|
|
38
|
+
]]
|
|
39
|
+
local Skip = NetworkingSkip
|
|
40
|
+
_container.Skip = Skip
|
|
41
|
+
--[[
|
|
42
|
+
*
|
|
43
|
+
* Specifies that this event is unreliable.
|
|
44
|
+
*
|
|
45
|
+
* This will only work on remote events.
|
|
46
|
+
|
|
47
|
+
]]
|
|
48
|
+
--[[
|
|
49
|
+
*
|
|
50
|
+
* Sends this event's arguments as they are, bypassing `networking.serialization` for this event
|
|
51
|
+
* alone. The generated guards still run on what arrives.
|
|
52
|
+
|
|
53
|
+
]]
|
|
54
|
+
--[[
|
|
55
|
+
*
|
|
56
|
+
* An unreliable event whose arguments bypass serialization; see {@link RawReliable}.
|
|
57
|
+
|
|
58
|
+
]]
|
|
59
|
+
--[[
|
|
60
|
+
*
|
|
61
|
+
* A function whose requests and results bypass serialization; see {@link RawReliable}.
|
|
62
|
+
|
|
63
|
+
]]
|
|
64
|
+
--[[
|
|
65
|
+
*
|
|
66
|
+
* A function that generates an event middleware.
|
|
67
|
+
|
|
68
|
+
]]
|
|
69
|
+
--[[
|
|
70
|
+
*
|
|
71
|
+
* A function that generates an event middleware.
|
|
72
|
+
|
|
73
|
+
]]
|
|
74
|
+
end
|
|
75
|
+
return {
|
|
76
|
+
Networking = Networking,
|
|
77
|
+
NetworkingFunctionError = NetworkingFunctionError,
|
|
78
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { t } from "@rbxts/t";
|
|
2
|
+
import { MiddlewareFactory } from "./types";
|
|
3
|
+
import { SignalContainer } from "../util/createSignalContainer";
|
|
4
|
+
import { EventNetworkingEvents } from "../handlers";
|
|
5
|
+
import { NetworkInfo } from "../types";
|
|
6
|
+
export declare function createGuardMiddleware<I extends unknown[], O>(name: string, fixedParameters: t.check<unknown>[], restParameter: t.check<unknown> | undefined, networkInfo: NetworkInfo, warnOnInvalid: boolean, signals: SignalContainer<EventNetworkingEvents>, failureValue?: O): MiddlewareFactory<I, O>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local Players = TS.import(script, TS.getModule(script, "@rbxts", "services")).Players
|
|
4
|
+
local function createGuardMiddleware(name, fixedParameters, restParameter, networkInfo, warnOnInvalid, signals, failureValue)
|
|
5
|
+
return function(processNext)
|
|
6
|
+
return function(player, ...)
|
|
7
|
+
local args = { ... }
|
|
8
|
+
do
|
|
9
|
+
local i = 0
|
|
10
|
+
local _shouldIncrement = false
|
|
11
|
+
while true do
|
|
12
|
+
if _shouldIncrement then
|
|
13
|
+
i += 1
|
|
14
|
+
else
|
|
15
|
+
_shouldIncrement = true
|
|
16
|
+
end
|
|
17
|
+
if not (i < math.max(#fixedParameters, #args)) then
|
|
18
|
+
break
|
|
19
|
+
end
|
|
20
|
+
local guard = fixedParameters[i + 1] or restParameter
|
|
21
|
+
if guard and not guard(args[i + 1]) then
|
|
22
|
+
if warnOnInvalid then
|
|
23
|
+
if player then
|
|
24
|
+
warn(`'{player}' sent invalid arguments for event '{name}' (arg #{i}):`, args[i + 1])
|
|
25
|
+
else
|
|
26
|
+
warn(`Server sent invalid arguments for event '{name}' (arg #{i}):`, args[i + 1])
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
signals:fire("onBadRequest", player or Players.LocalPlayer, {
|
|
30
|
+
networkInfo = networkInfo,
|
|
31
|
+
argIndex = i,
|
|
32
|
+
argValue = args[i + 1],
|
|
33
|
+
})
|
|
34
|
+
return failureValue
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
return processNext(player, unpack(args))
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
return {
|
|
43
|
+
createGuardMiddleware = createGuardMiddleware,
|
|
44
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { NetworkInfo } from "../types";
|
|
2
|
+
import { Middleware, MiddlewareFactory, MiddlewareProcessor } from "./types";
|
|
3
|
+
export declare function createMiddlewareProcessor<I extends readonly unknown[], O>(middlewareFactories: MiddlewareFactory<I, O>[] | undefined, networkInfo: NetworkInfo, finalize: Middleware<I, O>): MiddlewareProcessor<I, O>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local function createMiddlewareProcessor(middlewareFactories, networkInfo, finalize)
|
|
4
|
+
local middleware = {}
|
|
5
|
+
if not middlewareFactories or #middlewareFactories == 0 then
|
|
6
|
+
middleware[1] = finalize
|
|
7
|
+
else
|
|
8
|
+
for i = #middlewareFactories - 1, 0, -1 do
|
|
9
|
+
local factory = middlewareFactories[i + 1]
|
|
10
|
+
local processNext = middleware[i + 2] or finalize
|
|
11
|
+
middleware[i + 1] = factory(TS.async(function(player, ...)
|
|
12
|
+
local args = { ... }
|
|
13
|
+
return processNext(player, unpack(args))
|
|
14
|
+
end), networkInfo)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
return TS.async(function(player, ...)
|
|
18
|
+
local args = { ... }
|
|
19
|
+
return middleware[1](player, unpack(args))
|
|
20
|
+
end)
|
|
21
|
+
end
|
|
22
|
+
return {
|
|
23
|
+
createMiddlewareProcessor = createMiddlewareProcessor,
|
|
24
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local Skip = {
|
|
3
|
+
__index = function()
|
|
4
|
+
return nil
|
|
5
|
+
end,
|
|
6
|
+
__newindex = function()
|
|
7
|
+
return nil
|
|
8
|
+
end,
|
|
9
|
+
__tostring = function()
|
|
10
|
+
return `Networking.Skip`
|
|
11
|
+
end,
|
|
12
|
+
}
|
|
13
|
+
setmetatable(Skip, Skip)
|
|
14
|
+
-- This is a special skip type used to instruct Flamework to reject with a value of "BadRequest"
|
|
15
|
+
-- This does affect equality, though, so it can only be returned from the very first middleware
|
|
16
|
+
-- to avoid other middleware from being able to inspect it.
|
|
17
|
+
local SkipBadRequest = {}
|
|
18
|
+
setmetatable(SkipBadRequest, Skip)
|
|
19
|
+
return {
|
|
20
|
+
Skip = Skip,
|
|
21
|
+
SkipBadRequest = SkipBadRequest,
|
|
22
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NetworkInfo } from "../types";
|
|
2
|
+
import { Skip } from "./skip";
|
|
3
|
+
|
|
4
|
+
export type MiddlewareProcessor<I extends readonly unknown[], O> = (player?: Player, ...args: I) => Promise<O>;
|
|
5
|
+
export type Middleware<I extends readonly unknown[] = unknown[], O = void> = (
|
|
6
|
+
player?: Player,
|
|
7
|
+
...args: I
|
|
8
|
+
) => O | Promise<O>;
|
|
9
|
+
export type MiddlewareFactory<I extends readonly unknown[] = [], O = void> = (
|
|
10
|
+
processNext: MiddlewareProcessor<I, O>,
|
|
11
|
+
event: NetworkInfo,
|
|
12
|
+
) => Middleware<I, O>;
|
|
13
|
+
|
|
14
|
+
export type EventMiddleware<I extends readonly unknown[] = unknown[]> = MiddlewareFactory<I, void>;
|
|
15
|
+
export type FunctionMiddleware<I extends readonly unknown[] = unknown[], O = void> = MiddlewareFactory<I, O | Skip>;
|
package/out/types.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Modding, Serialization } from "@flamework-experimental/core";
|
|
2
|
+
import { t } from "@rbxts/t";
|
|
3
|
+
|
|
4
|
+
export interface NetworkInfo {
|
|
5
|
+
/**
|
|
6
|
+
* The name provided for this event.
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The (generated) global name used for distinguishing different createEvent calls.
|
|
12
|
+
*/
|
|
13
|
+
globalName: string;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Whether this remote is an event or function.
|
|
17
|
+
*/
|
|
18
|
+
eventType: "Event" | "Function";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type NetworkUnreliable<T> = T & { _flamework_unreliable: never };
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Marks an event or function whose values travel as they are, outside serialization: the transformer
|
|
25
|
+
* leaves its call sites alone and the metadata carries no decoder for it.
|
|
26
|
+
*/
|
|
27
|
+
export type NetworkRaw<T> = T & { _flamework_raw: never };
|
|
28
|
+
|
|
29
|
+
export interface NetworkingObfuscationMarker {
|
|
30
|
+
/**
|
|
31
|
+
* An internal marker type used to signify to Flamework to obfuscate access expressions.
|
|
32
|
+
* @hidden
|
|
33
|
+
* @deprecated
|
|
34
|
+
*/
|
|
35
|
+
readonly _flamework_key_obfuscation: "remotes";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type FunctionParameters<T> = T extends (...args: infer P) => unknown ? P : never;
|
|
39
|
+
export type FunctionReturn<T> = T extends (...args: never[]) => infer R ? R : never;
|
|
40
|
+
|
|
41
|
+
export type ObfuscateNames<T> = IntrinsicObfuscateArray<
|
|
42
|
+
(T extends T ? Modding.Target.Obfuscate<T & string, "remotes"> : never)[],
|
|
43
|
+
string[]
|
|
44
|
+
>;
|
|
45
|
+
|
|
46
|
+
/** @hidden Intrinsic feature not intended for users */
|
|
47
|
+
export type IntrinsicObfuscate<T> = Modding.Intrinsic<"obfuscate-obj", [T, "remotes"], Record<string, T[keyof T]>>;
|
|
48
|
+
|
|
49
|
+
/** @hidden Intrinsic feature not intended for users */
|
|
50
|
+
export type IntrinsicObfuscateArray<T, V = T> = Modding.Intrinsic<"shuffle-array", [T], V>;
|
|
51
|
+
|
|
52
|
+
/** @hidden Intrinsic feature not intended for users */
|
|
53
|
+
export type IntrinsicTupleGuards<T> = Modding.Intrinsic<"tuple-guards", [T], GuardType>;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Decode code for the argument list `T`, generated only when the project's flamework.config.json
|
|
57
|
+
* enables `networking.serialization`; `undefined` otherwise, which passes values through as they
|
|
58
|
+
* are. The matching encoding is generated inline at every call site, so no encoder exists at runtime.
|
|
59
|
+
* @hidden Intrinsic feature not intended for users
|
|
60
|
+
*/
|
|
61
|
+
export type IntrinsicNetworkDecoder<T extends Array<unknown>> = Modding.Intrinsic<
|
|
62
|
+
"network-decoder",
|
|
63
|
+
[T],
|
|
64
|
+
Serialization.Decoder<T> | undefined
|
|
65
|
+
>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Decode code for the result of the function type `F`, carried as a one-element list. Takes the
|
|
69
|
+
* function type rather than its return type so that the return type as declared is known.
|
|
70
|
+
* @hidden Intrinsic feature not intended for users
|
|
71
|
+
*/
|
|
72
|
+
export type IntrinsicNetworkResultDecoder<F> = Modding.Intrinsic<
|
|
73
|
+
"network-result-decoder",
|
|
74
|
+
[F],
|
|
75
|
+
Serialization.Decoder | undefined
|
|
76
|
+
>;
|
|
77
|
+
|
|
78
|
+
type GuardType = [t.check<unknown>[], t.check<unknown> | undefined];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local Signal = TS.import(script, TS.getModule(script, "@rbxts", "signal"))
|
|
4
|
+
local function createSignalContainer()
|
|
5
|
+
local signals = {}
|
|
6
|
+
return {
|
|
7
|
+
fire = function(self, name, ...)
|
|
8
|
+
local args = { ... }
|
|
9
|
+
local _name = name
|
|
10
|
+
local signal = signals[_name]
|
|
11
|
+
if signal then
|
|
12
|
+
signal:Fire(unpack(args))
|
|
13
|
+
end
|
|
14
|
+
end,
|
|
15
|
+
connect = function(self, name, callback)
|
|
16
|
+
local _name = name
|
|
17
|
+
local signal = signals[_name]
|
|
18
|
+
if not signal then
|
|
19
|
+
local _exp = name
|
|
20
|
+
signal = Signal.new()
|
|
21
|
+
local _signal = signal
|
|
22
|
+
signals[_exp] = _signal
|
|
23
|
+
end
|
|
24
|
+
return signal:Connect(callback)
|
|
25
|
+
end,
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
return {
|
|
29
|
+
createSignalContainer = createSignalContainer,
|
|
30
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EventCreateConfiguration } from "../events/types";
|
|
2
|
+
import { FunctionCreateConfiguration } from "../functions/types";
|
|
3
|
+
type ConfigType = EventCreateConfiguration<unknown> | FunctionCreateConfiguration<unknown>;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new config with the namespace's middleware at the top level.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getNamespaceConfig<T extends ConfigType>(config: T, namespaceId: string): T & {
|
|
8
|
+
middleware: never;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
--[[
|
|
3
|
+
*
|
|
4
|
+
* Creates a new config with the namespace's middleware at the top level.
|
|
5
|
+
|
|
6
|
+
]]
|
|
7
|
+
local function getNamespaceConfig(config, namespaceId)
|
|
8
|
+
local _object = table.clone(config)
|
|
9
|
+
setmetatable(_object, nil)
|
|
10
|
+
_object.middleware = config.middleware[namespaceId] or {}
|
|
11
|
+
return _object
|
|
12
|
+
end
|
|
13
|
+
return {
|
|
14
|
+
getNamespaceConfig = getNamespaceConfig,
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function timeoutPromise(timeout: number, rejectValue: unknown): Promise<unknown>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local function timeoutPromise(timeout, rejectValue)
|
|
4
|
+
return TS.Promise.delay(timeout):andThen(function()
|
|
5
|
+
return TS.Promise.reject(rejectValue)
|
|
6
|
+
end)
|
|
7
|
+
end
|
|
8
|
+
return {
|
|
9
|
+
timeoutPromise = timeoutPromise,
|
|
10
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flamework-experimental/networking",
|
|
3
|
+
"version": "2.0.0-alpha.0",
|
|
4
|
+
"main": "out/init.luau",
|
|
5
|
+
"types": "out/index.d.ts",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "rbxtsc",
|
|
8
|
+
"watch": "rbxtsc -w"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"out",
|
|
12
|
+
"flamework.build"
|
|
13
|
+
],
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"@flamework-experimental/core": "*"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@flamework-experimental/core": "2.0.0-alpha.0",
|
|
22
|
+
"@rbxts/compiler-types": "^3.0.0-types.0",
|
|
23
|
+
"@rbxts/types": "^1.0.948",
|
|
24
|
+
"roblox-ts": "^3.0.0"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@rbxts/object-utils": "^1.0.4",
|
|
28
|
+
"@rbxts/services": "^1.1.5",
|
|
29
|
+
"@rbxts/signal": "^1.0.3",
|
|
30
|
+
"@rbxts/t": "^3.1.0"
|
|
31
|
+
}
|
|
32
|
+
}
|