@rbxts/netweave 0.1.0 → 0.1.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/index.d.ts +58 -12
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -53,11 +53,41 @@ type DeepReadonly<T> = T extends Primitive | Datatype | undefined
|
|
|
53
53
|
Refuses keys outside `K`, even through a variable, where TypeScript's own excess-property check does
|
|
54
54
|
not look. `S` is inferred backwards through a homomorphic mapped type rather than intersected in:
|
|
55
55
|
intersecting turns `maxBytes: "4"` into "not assignable to never", and this keeps "to number".
|
|
56
|
+
|
|
57
|
+
The message is the original's (Channel.luau `permit`): the key, the keys the class takes in `Takes`,
|
|
58
|
+
which is a tuple so that their order is the one written and not a union's, and the key of `Takes`
|
|
59
|
+
the written one is but for case, when there is one. A key of `K` that is not in `Takes` is one the
|
|
60
|
+
spec forbids with its own message.
|
|
56
61
|
*/
|
|
57
|
-
type OnlyKeys<S, K, Where extends string> = {
|
|
58
|
-
readonly [P in keyof S]: P extends K
|
|
62
|
+
type OnlyKeys<S, K, Where extends string, Takes extends readonly string[]> = {
|
|
63
|
+
readonly [P in keyof S]: P extends K
|
|
64
|
+
? unknown
|
|
65
|
+
: Forbidden<`${Where} has no \`${P & string}\`.${CaseHint<P & string, Takes>} It takes ${Joined<Takes>} — check the spelling, because a key that is ignored looks exactly like one that worked.`>;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/* The same for nw.configure, in the words of the original's (Config.luau `refuse`): `Known` is sorted as those are. */
|
|
69
|
+
type KnownKeys<S, Known extends readonly string[], Field extends string> = {
|
|
70
|
+
readonly [P in keyof S]: P extends Known[number]
|
|
71
|
+
? unknown
|
|
72
|
+
: Forbidden<`nw.configure: no such ${Field} \`${P & string}\`.${CaseHint<P & string, Known>} Known ${Field}s: ${Joined<Known>}`>;
|
|
59
73
|
};
|
|
60
74
|
|
|
75
|
+
/* `a, b, c`. */
|
|
76
|
+
type Joined<L extends readonly string[]> = L extends readonly [infer H extends string, ...infer R extends readonly string[]]
|
|
77
|
+
? R extends readonly []
|
|
78
|
+
? H
|
|
79
|
+
: `${H}, ${Joined<R>}`
|
|
80
|
+
: "";
|
|
81
|
+
|
|
82
|
+
/* The first of `L` that is `P` but for case, or never: `timeout` for `timeOut`, `maxBytes` for `maxbytes`. */
|
|
83
|
+
type SameButCase<P extends string, L extends readonly string[]> = L extends readonly [infer H extends string, ...infer R extends readonly string[]]
|
|
84
|
+
? Lowercase<H> extends Lowercase<P>
|
|
85
|
+
? H
|
|
86
|
+
: SameButCase<P, R>
|
|
87
|
+
: never;
|
|
88
|
+
|
|
89
|
+
type CaseHint<P extends string, L extends readonly string[]> = [SameButCase<P, L>] extends [never] ? "" : ` Did you mean \`${SameButCase<P, L>}\`?`;
|
|
90
|
+
|
|
61
91
|
type NonEmpty<R, M extends string> = [keyof R] extends [never] ? Forbidden<M> : R;
|
|
62
92
|
|
|
63
93
|
type NotUntrusted<V> = V extends { readonly [untrusted]: true }
|
|
@@ -188,6 +218,22 @@ type QueryKeys = keyof QuerySpec<AnyType, AnyType>;
|
|
|
188
218
|
type PublishKeys = keyof PublishSpec<AnyType, nw.Scope>;
|
|
189
219
|
type ReplicateKeys = keyof ReplicateSpec<AnyType, AnyType, nw.Scope>;
|
|
190
220
|
|
|
221
|
+
/*
|
|
222
|
+
The keys each class takes, which its refusal of any other lists, in the order of the original's
|
|
223
|
+
`permit`. Written by hand, because a union has no order to print, and so held against the spec in
|
|
224
|
+
tests/types/extra_ok.ts: every key of it that is not forbidden, and no other.
|
|
225
|
+
*/
|
|
226
|
+
type CommandTakes = ["data", "rate", "burst", "maxBytes", "authorize"];
|
|
227
|
+
type LooseTakes = ["data", "rate", "burst", "maxBytes", "unreliable"];
|
|
228
|
+
type QueryTakes = ["args", "returns", "rate", "burst", "maxBytes", "timeout", "authorize"];
|
|
229
|
+
type PublishTakes = ["data", "audience", "unreliable"];
|
|
230
|
+
type ReplicateTakes = ["subject", "data", "audience", "store"];
|
|
231
|
+
|
|
232
|
+
/* What nw.configure knows, sorted as the original sorts them, and held against `nw.Settings`, `nw.Rules` and `nw.Limits` there too. */
|
|
233
|
+
type SettingNames = ["contextGuard", "limits", "rules"];
|
|
234
|
+
type RuleNames = ["authorize", "budget", "direction", "handler", "parse", "protocol", "query", "queue", "rateUnbounded", "replicate", "send"];
|
|
235
|
+
type LimitNames = ["baselinesPerClient", "callsInFlight", "pendingPerBatch", "queueCapacity", "repeatsPerDiagnostic", "resyncTicks", "unreliableBytes"];
|
|
236
|
+
|
|
191
237
|
type Published<C extends nw.Class, S extends nw.Scope, T> = nw.Channel<
|
|
192
238
|
C,
|
|
193
239
|
[S] extends ["everyone"] ? nw.Broadcaster<T> : nw.Publisher<T>,
|
|
@@ -935,7 +981,7 @@ declare namespace nw {
|
|
|
935
981
|
* inside the declared rate, and approved.
|
|
936
982
|
*/
|
|
937
983
|
function command<D extends AnyType, K = unknown>(
|
|
938
|
-
spec: CommandSpec<D> & OnlyKeys<K, CommandKeys, "nw.command">,
|
|
984
|
+
spec: CommandSpec<D> & OnlyKeys<K, CommandKeys, "nw.command", CommandTakes>,
|
|
939
985
|
): Channel<"command", Inbound<Trusted<PayloadOf<D>>>, Sender<PayloadOf<D>>>;
|
|
940
986
|
|
|
941
987
|
/**
|
|
@@ -944,7 +990,7 @@ declare namespace nw {
|
|
|
944
990
|
* however often `send` is called.
|
|
945
991
|
*/
|
|
946
992
|
function intent<D extends AnyType, K = unknown>(
|
|
947
|
-
spec: LooseSpec<D> & OnlyKeys<K, LooseKeys, "nw.intent">,
|
|
993
|
+
spec: LooseSpec<D> & OnlyKeys<K, LooseKeys, "nw.intent", LooseTakes>,
|
|
948
994
|
): Channel<"intent", Inbound<PayloadOf<D>>, Sender<PayloadOf<D>>>;
|
|
949
995
|
|
|
950
996
|
/**
|
|
@@ -952,22 +998,22 @@ declare namespace nw {
|
|
|
952
998
|
* not fit a function that wants `Trusted<T>`.
|
|
953
999
|
*/
|
|
954
1000
|
function signal<D extends AnyType, K = unknown>(
|
|
955
|
-
spec: LooseSpec<D> & OnlyKeys<K, LooseKeys, "nw.signal">,
|
|
1001
|
+
spec: LooseSpec<D> & OnlyKeys<K, LooseKeys, "nw.signal", LooseTakes>,
|
|
956
1002
|
): Channel<"signal", Inbound<Untrusted<PayloadOf<D>>>, Sender<PayloadOf<D>>>;
|
|
957
1003
|
|
|
958
1004
|
/** A request that expects an answer, authorized like a command. */
|
|
959
1005
|
function query<A extends AnyType, R extends AnyType, K = unknown>(
|
|
960
|
-
spec: QuerySpec<A, R> & OnlyKeys<K, QueryKeys, "nw.query">,
|
|
1006
|
+
spec: QuerySpec<A, R> & OnlyKeys<K, QueryKeys, "nw.query", QueryTakes>,
|
|
961
1007
|
): Channel<"query", Handling<Trusted<PayloadOf<A>>, PayloadOf<R>>, Invoker<PayloadOf<A>, PayloadOf<R>>>;
|
|
962
1008
|
|
|
963
1009
|
/** Server to client, the current value of a subject, every time you publish it. */
|
|
964
1010
|
function state<D extends AnyType, S extends Scope, K = unknown>(
|
|
965
|
-
spec: PublishSpec<D, S> & OnlyKeys<K, PublishKeys, "nw.state">,
|
|
1011
|
+
spec: PublishSpec<D, S> & OnlyKeys<K, PublishKeys, "nw.state", PublishTakes>,
|
|
966
1012
|
): Published<"state", S, PayloadOf<D>>;
|
|
967
1013
|
|
|
968
1014
|
/** Server to client, something that happened once. */
|
|
969
1015
|
function event<D extends AnyType, S extends Scope, K = unknown>(
|
|
970
|
-
spec: PublishSpec<D, S> & OnlyKeys<K, PublishKeys, "nw.event">,
|
|
1016
|
+
spec: PublishSpec<D, S> & OnlyKeys<K, PublishKeys, "nw.event", PublishTakes>,
|
|
971
1017
|
): Published<"event", S, PayloadOf<D>>;
|
|
972
1018
|
|
|
973
1019
|
/**
|
|
@@ -975,7 +1021,7 @@ declare namespace nw {
|
|
|
975
1021
|
* it: `store` is read once a tick, and each client is sent what it is missing.
|
|
976
1022
|
*/
|
|
977
1023
|
function replicate<U extends AnyType, D extends AnyType, S extends Scope, K = unknown>(
|
|
978
|
-
spec: ReplicateSpec<U, D, S> & OnlyKeys<K, ReplicateKeys, "nw.replicate">,
|
|
1024
|
+
spec: ReplicateSpec<U, D, S> & OnlyKeys<K, ReplicateKeys, "nw.replicate", ReplicateTakes>,
|
|
979
1025
|
): Channel<"replicate", Nothing, Mirror<PayloadOf<U>, PayloadOf<D>>>;
|
|
980
1026
|
|
|
981
1027
|
// Views -------------------------------------------------------------------------------------
|
|
@@ -1183,10 +1229,10 @@ declare namespace nw {
|
|
|
1183
1229
|
/** Sets severities and limits. Call it before declaring channels: limits are read when they are built. */
|
|
1184
1230
|
function configure<K = unknown, R = unknown, L = unknown>(
|
|
1185
1231
|
settings: {
|
|
1186
|
-
readonly rules?: Rules &
|
|
1187
|
-
readonly limits?: Limits &
|
|
1232
|
+
readonly rules?: Rules & KnownKeys<R, RuleNames, "rule">;
|
|
1233
|
+
readonly limits?: Limits & KnownKeys<L, LimitNames, "limit">;
|
|
1188
1234
|
readonly contextGuard?: boolean;
|
|
1189
|
-
} &
|
|
1235
|
+
} & KnownKeys<K, SettingNames, "setting">,
|
|
1190
1236
|
): Snapshot;
|
|
1191
1237
|
|
|
1192
1238
|
const config: {
|