@axpecter/lync 2.3.2 → 3.0.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.
Files changed (135) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +302 -299
  3. package/Types.luau +215 -0
  4. package/api/Define.luau +154 -0
  5. package/api/Lifecycle.luau +119 -0
  6. package/api/Packet.luau +108 -0
  7. package/api/Query.luau +149 -0
  8. package/api/Set.luau +189 -0
  9. package/channel/Blocks.luau +124 -0
  10. package/channel/Group.luau +118 -0
  11. package/channel/Link.luau +135 -0
  12. package/channel/Outbox.luau +261 -0
  13. package/channel/Recipients.luau +129 -0
  14. package/channel/Transport.luau +138 -0
  15. package/codec/Base.luau +236 -0
  16. package/codec/Composites.luau +128 -0
  17. package/codec/Datatypes.luau +162 -0
  18. package/codec/Legality.luau +61 -0
  19. package/codec/Scalars.luau +72 -0
  20. package/codec/Text.luau +89 -0
  21. package/codec/init.luau +39 -0
  22. package/index.d.ts +285 -0
  23. package/init.luau +91 -0
  24. package/kernel/Bits.luau +16 -0
  25. package/kernel/Catalog.luau +121 -0
  26. package/kernel/Heap.luau +80 -0
  27. package/kernel/Listeners.luau +95 -0
  28. package/kernel/Log.luau +197 -0
  29. package/kernel/Tally.luau +128 -0
  30. package/kernel/Threads.luau +44 -0
  31. package/kernel/Wide.luau +267 -0
  32. package/package.json +15 -32
  33. package/runtime/Boundary.luau +180 -0
  34. package/runtime/Dispatch.luau +91 -0
  35. package/runtime/Handles.luau +114 -0
  36. package/runtime/Handshake.luau +90 -0
  37. package/runtime/Pending.luau +196 -0
  38. package/runtime/Router.luau +379 -0
  39. package/runtime/Session.luau +731 -0
  40. package/shape/Compile.luau +340 -0
  41. package/shape/Folds.luau +332 -0
  42. package/shape/Frames.luau +170 -0
  43. package/shape/Grid.luau +169 -0
  44. package/shape/Ir.luau +540 -0
  45. package/shape/Joins.luau +125 -0
  46. package/shape/Legality.luau +273 -0
  47. package/shape/Lower.luau +419 -0
  48. package/shape/Order.luau +64 -0
  49. package/shape/Regions.luau +113 -0
  50. package/shape/Rotation.luau +472 -0
  51. package/shape/Serial.luau +258 -0
  52. package/shape/Words.luau +89 -0
  53. package/shape/emit/Block.luau +453 -0
  54. package/shape/emit/Column.luau +338 -0
  55. package/shape/emit/Leaf.luau +462 -0
  56. package/shape/emit/Word.luau +234 -0
  57. package/shape/emit/init.luau +222 -0
  58. package/shape/init.luau +78 -0
  59. package/state/Apply.luau +330 -0
  60. package/state/Audience.luau +126 -0
  61. package/state/Catchup.luau +218 -0
  62. package/state/Coalesce.luau +43 -0
  63. package/state/Fieldset.luau +177 -0
  64. package/state/Newest.luau +339 -0
  65. package/state/Plan.luau +441 -0
  66. package/state/Sections.luau +468 -0
  67. package/state/Store.luau +188 -0
  68. package/state/Sync.luau +762 -0
  69. package/wire/Bytes.luau +118 -0
  70. package/wire/Clock.luau +37 -0
  71. package/wire/Protocol.luau +110 -0
  72. package/wire/Sequence.luau +40 -0
  73. package/wire/Varint.luau +124 -0
  74. package/src/Types.luau +0 -180
  75. package/src/api/Group.luau +0 -156
  76. package/src/api/Packet.luau +0 -319
  77. package/src/api/Query.luau +0 -338
  78. package/src/api/Scope.luau +0 -90
  79. package/src/api/Signal.luau +0 -188
  80. package/src/codec/Base.luau +0 -136
  81. package/src/codec/composite/Array.luau +0 -456
  82. package/src/codec/composite/Map.luau +0 -469
  83. package/src/codec/composite/Optional.luau +0 -54
  84. package/src/codec/composite/Shared.luau +0 -291
  85. package/src/codec/composite/Struct.luau +0 -494
  86. package/src/codec/composite/Tagged.luau +0 -103
  87. package/src/codec/composite/Tuple.luau +0 -143
  88. package/src/codec/datatype/Buffer.luau +0 -66
  89. package/src/codec/datatype/CFrame.luau +0 -109
  90. package/src/codec/datatype/Color.luau +0 -32
  91. package/src/codec/datatype/Instance.luau +0 -52
  92. package/src/codec/datatype/IntVector.luau +0 -39
  93. package/src/codec/datatype/NumberRange.luau +0 -39
  94. package/src/codec/datatype/Ray.luau +0 -36
  95. package/src/codec/datatype/Rect.luau +0 -31
  96. package/src/codec/datatype/Region.luau +0 -62
  97. package/src/codec/datatype/Sequence.luau +0 -184
  98. package/src/codec/datatype/String.luau +0 -94
  99. package/src/codec/datatype/UDim.luau +0 -46
  100. package/src/codec/datatype/Vector.luau +0 -130
  101. package/src/codec/meta/Auto.luau +0 -318
  102. package/src/codec/meta/Bitfield.luau +0 -147
  103. package/src/codec/meta/Custom.luau +0 -33
  104. package/src/codec/meta/DeltaScalar.luau +0 -390
  105. package/src/codec/meta/Enum.luau +0 -50
  106. package/src/codec/meta/Float.luau +0 -38
  107. package/src/codec/meta/Nothing.luau +0 -13
  108. package/src/codec/meta/Unknown.luau +0 -41
  109. package/src/codec/primitive/Bool.luau +0 -26
  110. package/src/codec/primitive/Float16.luau +0 -99
  111. package/src/codec/primitive/Int.luau +0 -59
  112. package/src/codec/primitive/Number.luau +0 -24
  113. package/src/codec/primitive/Signed.luau +0 -32
  114. package/src/codec/primitive/Varint.luau +0 -165
  115. package/src/codec/primitive/Zint.luau +0 -99
  116. package/src/index.d.ts +0 -423
  117. package/src/init.luau +0 -362
  118. package/src/internal/Baseline.luau +0 -57
  119. package/src/internal/Channel.luau +0 -390
  120. package/src/internal/Middleware.luau +0 -100
  121. package/src/internal/Pool.luau +0 -65
  122. package/src/internal/Registry.luau +0 -119
  123. package/src/internal/Transport.luau +0 -28
  124. package/src/transport/Bridge.luau +0 -110
  125. package/src/transport/Client.luau +0 -97
  126. package/src/transport/Gate.luau +0 -488
  127. package/src/transport/Reader.luau +0 -331
  128. package/src/transport/Server.luau +0 -211
  129. package/src/util/Array.luau +0 -18
  130. package/src/util/Buffer.luau +0 -90
  131. package/src/util/Constants.luau +0 -30
  132. package/src/util/Log.luau +0 -68
  133. package/src/util/Player.luau +0 -14
  134. package/src/util/Quantize.luau +0 -84
  135. package/src/util/Quat.luau +0 -124
package/src/index.d.ts DELETED
@@ -1,423 +0,0 @@
1
- /// <reference types="@rbxts/types" />
2
-
3
- declare namespace Lync {
4
- // ── Core types ──────────────────────────────────────────────────────
5
-
6
- /**
7
- * Opaque codec brand. The `_nominal_codec` field never exists at
8
- * runtime; it ties the generic parameter to a unique nominal type so
9
- * `Codec<number>` and `Codec<string>` can't be assigned to each other.
10
- */
11
- interface Codec<T> {
12
- /** @hidden */ readonly _nominal_codec: T;
13
- }
14
-
15
- interface Connection {
16
- connected: boolean;
17
- disconnect(): void;
18
- }
19
-
20
- interface PacketStats {
21
- bytesSent: number;
22
- bytesReceived: number;
23
- fires: number;
24
- recvFires: number;
25
- drops: number;
26
- }
27
-
28
- interface PlayerStats {
29
- bytesSent: number;
30
- bytesReceived: number;
31
- }
32
-
33
- type RateLimitConfig =
34
- | { maxPerSecond: number; burst?: number }
35
- | { cooldown: number };
36
-
37
- // ── Packet ──────────────────────────────────────────────────────────
38
-
39
- interface PacketOptions<T> {
40
- unreliable?: boolean;
41
- rateLimit?: RateLimitConfig;
42
- validate?: (data: T, player: Player) => LuaTuple<[boolean, string?]>;
43
- maxPayloadBytes?: number;
44
- timestamp?: "frame" | "offset" | "full";
45
- }
46
-
47
- interface Packet<T> {
48
- /**
49
- * Server: target is required (single Player, array, Group, or sentinel).
50
- * Client: target is omitted; the second arg is ignored at runtime.
51
- * The signature unions both forms.
52
- */
53
- send(this: Packet<T>, data: T, target?: Target): void;
54
- on(this: Packet<T>, fn: (data: T, sender?: Player, timestamp?: number) => void): Connection;
55
- once(this: Packet<T>, fn: (data: T, sender?: Player, timestamp?: number) => void): Connection;
56
- wait(this: Packet<T>): LuaTuple<[T, Player?, number?]>;
57
- name(this: Packet<T>): string;
58
- stats(this: Packet<T>): PacketStats;
59
- }
60
-
61
- // ── Query ───────────────────────────────────────────────────────────
62
-
63
- interface QueryOptions<Req> {
64
- timeout?: number;
65
- rateLimit?: RateLimitConfig;
66
- validate?: (data: Req, player: Player) => LuaTuple<[boolean, string?]>;
67
- }
68
-
69
- interface Query<Req, Resp> {
70
- handle(
71
- this: Query<Req, Resp>,
72
- fn: (request: Req, player?: Player) => Resp | undefined,
73
- ): Connection;
74
-
75
- /** Client: yields until reply or timeout; nil on timeout. */
76
- request(this: Query<Req, Resp>, data: Req): Resp | undefined;
77
- /** Server, single-Player target. */
78
- request(this: Query<Req, Resp>, data: Req, target: Player): Resp | undefined;
79
- /** Server, multi-target (Group, array, all, except). */
80
- request(this: Query<Req, Resp>, data: Req, target: Target): Map<Player, Resp | undefined>;
81
-
82
- name(this: Query<Req, Resp>): string;
83
- stats(this: Query<Req, Resp>): PacketStats;
84
- }
85
-
86
- // ── Group ───────────────────────────────────────────────────────────
87
-
88
- interface Group extends Iterable<Player> {
89
- /** Returns true if membership changed (idempotent). */
90
- add(this: Group, player: Player): boolean;
91
- remove(this: Group, player: Player): boolean;
92
- has(this: Group, player: Player): boolean;
93
- count(this: Group): number;
94
- /** Clear members and free the name. */
95
- destroy(this: Group): void;
96
- }
97
-
98
- // ── Scope ───────────────────────────────────────────────────────────
99
-
100
- interface Scope {
101
- on<T>(
102
- this: Scope,
103
- source: Packet<T>,
104
- fn: (data: T, sender?: Player, timestamp?: number) => void,
105
- ): Connection;
106
- once<T>(
107
- this: Scope,
108
- source: Packet<T>,
109
- fn: (data: T, sender?: Player, timestamp?: number) => void,
110
- ): Connection;
111
- add(this: Scope, connection: Connection | RBXScriptConnection): void;
112
- destroy(this: Scope): void;
113
- }
114
-
115
- // ── Targets ─────────────────────────────────────────────────────────
116
-
117
- type Target = Player | Player[] | Group | AllTarget | ExceptTarget;
118
-
119
- /** Branded sentinel returned by `Lync.all`. */
120
- interface AllTarget {
121
- /** @hidden */ readonly _lyncKind: "all";
122
- }
123
-
124
- /** Branded sentinel returned by `Lync.except(...)`. */
125
- interface ExceptTarget {
126
- /** @hidden */ readonly _lyncKind: "except";
127
- }
128
-
129
- /** Branded sentinel exposed as `Lync.DROP`. Return from `onSend` to discard. */
130
- interface DropSentinel {
131
- /** @hidden */ readonly _lyncKind: "drop";
132
- }
133
-
134
- // ── Codec inference ─────────────────────────────────────────────────
135
-
136
- type InferCodec<C> = C extends Codec<infer T> ? T : never;
137
-
138
- type InferSchema<S extends Record<string, Codec<unknown>>> = {
139
- [K in keyof S]: InferCodec<S[K]>;
140
- };
141
-
142
- // ── Callable codec brands (function-call form for variants) ─────────
143
-
144
- interface StringCodec extends Codec<string> {
145
- /** Bounded variant; rejects on read if length exceeds maxLength. */
146
- (maxLength: number): Codec<string>;
147
- }
148
-
149
- interface Vec2Codec extends Codec<Vector2> {
150
- /** Quantized per-component variant. 2/4/8 bytes. */
151
- (min: number, max: number, precision: number): Codec<Vector2>;
152
- }
153
-
154
- interface Vec3Codec extends Codec<Vector3> {
155
- /** Quantized per-component variant. 3/6/12 bytes. */
156
- (min: number, max: number, precision: number): Codec<Vector3>;
157
- }
158
-
159
- interface CFrameCodec extends Codec<CFrame> {
160
- /** Smallest-three-quaternion variant. 16 bytes; ≤ 0.16° rotation error. */
161
- (): Codec<CFrame>;
162
- }
163
-
164
- // ── Bitfield schema ─────────────────────────────────────────────────
165
-
166
- type BitfieldField =
167
- | { type: "bool" }
168
- | { type: "uint"; width: number }
169
- | { type: "int"; width: number };
170
-
171
- // ── Configure ───────────────────────────────────────────────────────
172
-
173
- interface ConfigureOptions {
174
- channelMaxSize?: number;
175
- validationDepth?: number;
176
- poolSize?: number;
177
- bandwidthLimit?: { softLimit: number; maxStrikes: number };
178
- globalRateLimit?: { maxPerSecond: number };
179
- stats?: boolean;
180
- }
181
-
182
- // ── Registration debug shape ────────────────────────────────────────
183
-
184
- interface RegistrationInfo {
185
- name: string;
186
- id: number;
187
- kind: number;
188
- isUnreliable: boolean;
189
- }
190
- }
191
-
192
- interface LyncModule {
193
- // ── Lifecycle ───────────────────────────────────────────────────────
194
-
195
- configure(this: void, options: Lync.ConfigureOptions): void;
196
- start(this: void): void;
197
- isStarted(this: void): boolean;
198
- flush(this: void): void;
199
- flushRate(this: void, hz: number): void;
200
- /** Restore module state to post-require defaults. For tests / hot reload. */
201
- reset(this: void): void;
202
-
203
- // ── Definitions ─────────────────────────────────────────────────────
204
-
205
- packet<T>(
206
- this: void,
207
- name: string,
208
- codec: Lync.Codec<T>,
209
- options?: Lync.PacketOptions<T>,
210
- ): Lync.Packet<T>;
211
-
212
- query<Req, Resp>(
213
- this: void,
214
- name: string,
215
- requestCodec: Lync.Codec<Req>,
216
- responseCodec: Lync.Codec<Resp>,
217
- options?: Lync.QueryOptions<Req>,
218
- ): Lync.Query<Req, Resp>;
219
-
220
- group(this: void, name: string): Lync.Group;
221
- scope(this: void): Lync.Scope;
222
-
223
- // ── Targeting ───────────────────────────────────────────────────────
224
-
225
- readonly all: Lync.AllTarget;
226
- except(this: void, ...args: Array<Player | Lync.Group>): Lync.ExceptTarget;
227
- readonly DROP: Lync.DropSentinel;
228
-
229
- // ── Middleware ──────────────────────────────────────────────────────
230
-
231
- onSend(
232
- this: void,
233
- fn: (data: unknown, name: string, player?: Player) => unknown,
234
- ): Lync.Connection;
235
- onReceive(
236
- this: void,
237
- fn: (data: unknown, name: string, player?: Player) => unknown,
238
- ): Lync.Connection;
239
- onDrop(
240
- this: void,
241
- fn: (player: Player, reason: string, name: string, data?: unknown) => void,
242
- ): Lync.Connection;
243
-
244
- // ── Stats ───────────────────────────────────────────────────────────
245
-
246
- readonly stats: {
247
- /** Server-only; returns undefined on client or before stats=true. */
248
- player(this: void, player: Player): Lync.PlayerStats | undefined;
249
- reset(this: void): void;
250
- };
251
-
252
- // ── Debug ───────────────────────────────────────────────────────────
253
-
254
- readonly debug: {
255
- /** Reserved no-op for capture/replay tooling. */
256
- capture(this: void, label?: string): void;
257
- /** Reserved no-op for capture/replay tooling. */
258
- stop(this: void): void;
259
- /** Reserved no-op for capture/replay tooling. */
260
- dump(this: void): void;
261
- pending(this: void): number;
262
- registrations(this: void): ReadonlyArray<Lync.RegistrationInfo>;
263
- };
264
-
265
- // ── Number codecs ───────────────────────────────────────────────────
266
-
267
- int(this: void, min: number, max: number): Lync.Codec<number>;
268
- /**
269
- * Variable-length signed int via zigzag varint. 1 byte for values in
270
- * [-96, 95]; up to 5 bytes for full i32. Optional bounds gate input.
271
- */
272
- zint(this: void, min?: number, max?: number): Lync.Codec<number>;
273
- float(this: void, min: number, max: number, precision: number): Lync.Codec<number>;
274
- readonly f16: Lync.Codec<number>;
275
- readonly f32: Lync.Codec<number>;
276
- readonly f64: Lync.Codec<number>;
277
- readonly bool: Lync.Codec<boolean>;
278
-
279
- // ── Delta scalars (reliable transport only) ─────────────────────────
280
-
281
- /**
282
- * Integer that emits zigzag varint of (current - previous). Reliable
283
- * transport only; a dropped frame desyncs the receiver. Best for ints
284
- * mutating slowly across a wide range (saves vs fixed u16/u24/u32).
285
- */
286
- deltaInt(this: void, min: number, max: number): Lync.Codec<number>;
287
- /**
288
- * Quantized float with per-frame diff in integer wire space (no drift).
289
- * Same wire-size profile as deltaInt. Reliable transport only.
290
- */
291
- deltaFloat(
292
- this: void,
293
- min: number,
294
- max: number,
295
- precision: number,
296
- ): Lync.Codec<number>;
297
- /**
298
- * Quantized Vector3 with per-axis zigzag varint diffs. ~3 bytes for
299
- * unchanged, 3-15 bytes for typical motion vs 12 bytes baseline.
300
- * Reliable transport only.
301
- */
302
- deltaVec3(
303
- this: void,
304
- min: number,
305
- max: number,
306
- precision: number,
307
- ): Lync.Codec<Vector3>;
308
- /**
309
- * Quantized position + smallest-three quaternion rotation. 1 byte for
310
- * fully static; 4-7 bytes for position-only motion; up to 13 bytes
311
- * for full pose changes vs 24 bytes baseline. Reliable transport only.
312
- */
313
- deltaCFrame(
314
- this: void,
315
- posMin: number,
316
- posMax: number,
317
- posPrecision: number,
318
- ): Lync.Codec<CFrame>;
319
-
320
- // ── String & buffer ─────────────────────────────────────────────────
321
-
322
- readonly string: Lync.StringCodec;
323
- readonly buff: Lync.Codec<buffer>;
324
-
325
- // ── Vectors & spatial ───────────────────────────────────────────────
326
-
327
- readonly vec2: Lync.Vec2Codec;
328
- readonly vec3: Lync.Vec3Codec;
329
- readonly cframe: Lync.CFrameCodec;
330
- readonly ray: Lync.Codec<Ray>;
331
- readonly rect: Lync.Codec<Rect>;
332
- readonly region3: Lync.Codec<Region3>;
333
- readonly region3int16: Lync.Codec<Region3int16>;
334
- readonly vec2int16: Lync.Codec<Vector2int16>;
335
- readonly vec3int16: Lync.Codec<Vector3int16>;
336
-
337
- // ── Roblox types ────────────────────────────────────────────────────
338
-
339
- readonly color3: Lync.Codec<Color3>;
340
- readonly inst: Lync.Codec<Instance>;
341
- readonly udim: Lync.Codec<UDim>;
342
- readonly udim2: Lync.Codec<UDim2>;
343
- readonly numberRange: Lync.Codec<NumberRange>;
344
- readonly numberSequence: Lync.Codec<NumberSequence>;
345
- readonly colorSequence: Lync.Codec<ColorSequence>;
346
-
347
- // ── Composites ──────────────────────────────────────────────────────
348
-
349
- struct<S extends Record<string, Lync.Codec<unknown>>>(
350
- this: void,
351
- schema: S,
352
- ): Lync.Codec<Lync.InferSchema<S>>;
353
-
354
- /** Reliable transport only; rejected at definition time on `unreliable`. */
355
- deltaStruct<S extends Record<string, Lync.Codec<unknown>>>(
356
- this: void,
357
- schema: S,
358
- ): Lync.Codec<Lync.InferSchema<S>>;
359
-
360
- array<T>(this: void, element: Lync.Codec<T>, maxCount?: number): Lync.Codec<T[]>;
361
- /** Reliable transport only. */
362
- deltaArray<T>(this: void, element: Lync.Codec<T>, maxCount?: number): Lync.Codec<T[]>;
363
-
364
- map<K, V>(
365
- this: void,
366
- keyCodec: Lync.Codec<K>,
367
- valueCodec: Lync.Codec<V>,
368
- maxCount?: number,
369
- ): Lync.Codec<Map<K, V>>;
370
- /** Reliable transport only. */
371
- deltaMap<K, V>(
372
- this: void,
373
- keyCodec: Lync.Codec<K>,
374
- valueCodec: Lync.Codec<V>,
375
- maxCount?: number,
376
- ): Lync.Codec<Map<K, V>>;
377
-
378
- optional<T>(this: void, codec: Lync.Codec<T>): Lync.Codec<T | undefined>;
379
-
380
- tuple<T extends Lync.Codec<unknown>[]>(
381
- this: void,
382
- ...codecs: T
383
- ): Lync.Codec<{ [K in keyof T]: Lync.InferCodec<T[K]> }>;
384
-
385
- /**
386
- * Discriminated union with a string tag field. Up to 256 variants;
387
- * each variant is a struct codec keyed by name.
388
- */
389
- tagged<Tag extends string, V extends Record<string, Lync.Codec<unknown>>>(
390
- this: void,
391
- tagField: Tag,
392
- variants: V,
393
- ): Lync.Codec<
394
- { [K in keyof V & string]: { [F in Tag]: K } & Lync.InferCodec<V[K]> }[keyof V & string]
395
- >;
396
-
397
- // ── Meta ────────────────────────────────────────────────────────────
398
-
399
- enum<T extends string[]>(this: void, ...values: T): Lync.Codec<T[number]>;
400
-
401
- bitfield(
402
- this: void,
403
- schema: Record<string, Lync.BitfieldField>,
404
- ): Lync.Codec<Record<string, boolean | number>>;
405
-
406
- custom<T>(
407
- this: void,
408
- size: number,
409
- write: (b: buffer, offset: number, value: T) => void,
410
- read: (b: buffer, offset: number) => T,
411
- typeCheck?: string,
412
- ): Lync.Codec<T>;
413
-
414
- /** 0-byte codec; reads `undefined`. Use for fire-and-forget signals. */
415
- readonly nothing: Lync.Codec<undefined>;
416
- /** Bypasses serialization through the channel sidecar. Pair with `validate`. */
417
- readonly unknown: Lync.Codec<unknown>;
418
- /** Self-describing; nil/bool/numbers/strings/buffers/Roblox datatypes. */
419
- readonly auto: Lync.Codec<unknown>;
420
- }
421
-
422
- declare const Lync: LyncModule;
423
- export = Lync;