@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
@@ -0,0 +1,339 @@
1
+ --!strict
2
+ --!optimize 2
3
+ -- The lane a newest field travels on: what has moved, how often it may say so, and in what order.
4
+
5
+ local Apply = require (script.Parent.Apply)
6
+ local Bits = require (script.Parent.Parent.kernel.Bits)
7
+ local Fieldset = require (script.Parent.Fieldset)
8
+ local Protocol = require (script.Parent.Parent.wire.Protocol)
9
+ local Sections = require (script.Parent.Sections)
10
+ local Sequence = require (script.Parent.Parent.wire.Sequence)
11
+ local Store = require (script.Parent.Store)
12
+ local Types = require (script.Parent.Parent.Types)
13
+ local Varint = require (script.Parent.Parent.wire.Varint)
14
+
15
+ local Newest = {}
16
+
17
+ -- Constants -----------------------------------------------------------
18
+
19
+ -- What one fire carries, which a section of this lane is a block of and so has to fit inside.
20
+ const CAP = Protocol.UNRELIABLE_CAP
21
+
22
+ -- The bits one group of a varint carries, which is what a slot's width comes to bytes through.
23
+ const GROUP = Protocol.VARINT_BITS
24
+
25
+ --[[
26
+ The generation a slot stands at, which is a byte a record at its widest and one bit less at its
27
+ narrowest, so an entry is bounded by the byte.
28
+ ]]
29
+ const STAMPED = 1
30
+
31
+ --[[
32
+ The least an entry can spend, which is a slot varint at its shortest and nothing else that has
33
+ to be there, and is what a count is held against before the lists it drives are walked.
34
+ ]]
35
+ const LEAST = 1
36
+
37
+ --[[
38
+ Where a stream header keeps the two fields a sender states outright, the third being the
39
+ sequence. Which slot that one is comes off the form rather than being written down here, since
40
+ the order is the wire's and its home is the frame that lays the header out.
41
+ ]]
42
+ const WHOSE = 1
43
+ const WHICH = 2
44
+
45
+ const TOO_MANY = "a newest section naming more records than its own bytes could hold"
46
+ const OUT_OF_ORDER = "a newest section naming its slots out of order"
47
+
48
+ -- Types ---------------------------------------------------------------
49
+
50
+ -- One partition's streams, one to a newest field, and the four numbers each of them keeps.
51
+ export type Streams = {
52
+ at: { number },
53
+ last: { number? },
54
+ heard: { number },
55
+ took: { boolean },
56
+ from: { number },
57
+ }
58
+
59
+ -- One set's newest lane, compiled: which fields ride it, how each is compared, and what it costs.
60
+ export type Lane = {
61
+ read layout: Sections.Layout,
62
+ read fields: { number },
63
+ read place: { [number]: number },
64
+ read hz: { number? },
65
+ read mark: { (value: any) -> any },
66
+ read spent: { number },
67
+ read opening: number,
68
+ read seqAt: number,
69
+ key: any,
70
+ read slots: { number },
71
+ read gens: { number },
72
+ read marks: { any },
73
+ read values: { any },
74
+ read head: { number },
75
+ }
76
+
77
+ -- Private -------------------------------------------------------------
78
+
79
+ -- What a field with no one index is remembered by, which is the value a caller handed over.
80
+ local function same (value: any): any return value end
81
+
82
+ -- Public --------------------------------------------------------------
83
+
84
+ -- A set's newest lane, as the closures and the scratch one partition's flush is written through.
85
+ function Newest.of (layout: Sections.Layout): Lane
86
+ local def = layout.def
87
+ local reach = #def.newestFields
88
+
89
+ local fields = table.create (reach) :: { number }
90
+ local place: { [number]: number } = {}
91
+ local hz = table.create (reach) :: { number? }
92
+ local mark = table.create (reach) :: { (value: any) -> any }
93
+ local spent = table.create (reach) :: { number }
94
+
95
+ local key = def.keyIndex
96
+ local opening = def.stream.bytes + 1 + (if key == nil then 0 else def.fieldBuilt[key].maxBytes)
97
+
98
+ local head = table.create (def.stream.fields, 0)
99
+ head[WHOSE] = def.id
100
+
101
+ for index, field in def.newestFields do
102
+ local built = def.fieldBuilt[field]
103
+ local grid = built.grid
104
+
105
+ fields[index] = field
106
+ place[field] = index
107
+ hz[index] = built.cell.newestHz
108
+ mark[index] = if grid == nil then same else grid.toIndex :: any
109
+ spent[index] = STAMPED + layout.each[field]
110
+ end
111
+
112
+ return {
113
+ layout = layout,
114
+ fields = table.freeze (fields),
115
+ place = table.freeze (place),
116
+ hz = table.freeze (hz),
117
+ mark = table.freeze (mark),
118
+ spent = table.freeze (spent),
119
+ opening = opening,
120
+ seqAt = def.stream.fields,
121
+ key = nil,
122
+ slots = {},
123
+ gens = {},
124
+ marks = {},
125
+ values = {},
126
+ head = head,
127
+ }
128
+ end
129
+
130
+ -- A partition's streams, none of them having said anything yet.
131
+ function Newest.streams (of: Lane): Streams
132
+ local reach = #of.fields
133
+ local held: Streams = { at = {}, last = {}, heard = {}, took = {}, from = {} }
134
+
135
+ for index = 1, reach do
136
+ held.at[index] = 0
137
+ held.heard[index] = 0
138
+ held.took[index] = false
139
+ held.from[index] = 0
140
+ end
141
+ return held
142
+ end
143
+
144
+ -- Every stream back to having said nothing, which a partition emptied is for all of them.
145
+ function Newest.sweep (of: Streams)
146
+ for index = 1, #of.at do
147
+ of.at[index] = 0
148
+ of.last[index] = nil
149
+ of.heard[index] = 0
150
+ of.took[index] = false
151
+ of.from[index] = 0
152
+ end
153
+ end
154
+
155
+ -- Every newest field of the listed slots, recorded as sent.
156
+ function Newest.established (of: Lane, store: Store.Store, slots: { number }, count: number)
157
+ for at = 1, #of.fields do
158
+ local field = of.fields[at]
159
+ local column = store.columns[field]
160
+ local sent = store.sent[field] :: { [number]: any }
161
+ local mark = of.mark[at]
162
+
163
+ for index = 1, count do
164
+ local slot = slots[index]
165
+ sent[slot] = mark (column[slot])
166
+ end
167
+ end
168
+ end
169
+
170
+ -- What one stream has to say this flush, gathered where a section reads it.
171
+ function Newest.changed (
172
+ of: Lane,
173
+ streams: Streams,
174
+ store: Store.Store,
175
+ at: number,
176
+ now: number
177
+ ): number
178
+ if not Sequence.opened (now, streams.last[at], of.hz[at]) then return 0 end
179
+
180
+ local field = of.fields[at]
181
+ local column = store.columns[field]
182
+ local sent = store.sent[field] :: { [number]: any }
183
+ local gens = store.gens :: { [number]: number }
184
+ local mark = of.mark[at]
185
+ local ids = store.ids
186
+
187
+ --[[
188
+ How many fit one fire, worked out here because the slot is the piece a schema cannot bound.
189
+ A partition of a hundred spells every slot in a byte and one of a million in three, and the
190
+ difference is a section three times the size for the same values.
191
+ ]]
192
+ local wide = math.max (1, math.ceil (Bits.width (store.high) / GROUP))
193
+ local reach = math.max (1, (CAP - of.opening) // (wide + of.spent[at]))
194
+ local held = 0
195
+
196
+ for slot = streams.from[at] + 1, store.high do
197
+ if ids[slot] == nil then continue end
198
+
199
+ local value = column[slot]
200
+ local one = mark (value)
201
+ if one == sent[slot] then continue end
202
+
203
+ held += 1
204
+ of.slots[held] = slot
205
+ of.values[held] = value
206
+ of.marks[held] = one
207
+ of.gens[held] = gens[slot]
208
+
209
+ if held == reach then break end
210
+ end
211
+
212
+ streams.from[at] = if held < reach then 0 else of.slots[held]
213
+ return held
214
+ end
215
+
216
+ -- One stream's section, and the stream moved on past it.
217
+ function Newest.section (
218
+ of: Lane,
219
+ streams: Streams,
220
+ store: Store.Store,
221
+ at: number,
222
+ b: buffer,
223
+ pos: number,
224
+ now: number,
225
+ count: number
226
+ ): number
227
+ local layout = of.layout
228
+ local def = layout.def
229
+ local field = of.fields[at]
230
+
231
+ local seq = Sequence.next (streams.at[at])
232
+ streams.at[at] = seq
233
+
234
+ of.head[WHICH] = field - 1
235
+ of.head[of.seqAt] = seq
236
+ def.stream.write (b, pos, of.head)
237
+
238
+ local held = pos + def.stream.bytes
239
+ local key = def.keyIndex
240
+ if key ~= nil then held = def.fieldBuilt[key].write (b, held, of.key) end
241
+
242
+ held = Varint.write (b, held, count)
243
+ for index = 1, count do
244
+ held = Varint.write (b, held, of.slots[index])
245
+ end
246
+
247
+ held = layout.generations.whole (b, held, of.gens :: any, layout.spare, count)
248
+ held = layout.fields[field].whole (b, held, of.values, layout.spare, count)
249
+
250
+ local sent = store.sent[field] :: { [number]: any }
251
+ for index = 1, count do
252
+ sent[of.slots[index] ] = of.marks[index]
253
+ end
254
+
255
+ streams.last[at] = now
256
+ return held
257
+ end
258
+
259
+ --[[
260
+ Whatever section is at this position, as the stream it is for, the sequence it carries and the
261
+ byte past it.
262
+ ]]
263
+ function Newest.taken (
264
+ of: Lane,
265
+ b: buffer,
266
+ pos: number,
267
+ ctx: Types.ValidateContext
268
+ ): (number, number, number, number)
269
+ local layout = of.layout
270
+ local def = layout.def
271
+
272
+ def.stream.read (b, pos, of.head)
273
+ local at = of.place[of.head[WHICH] + 1]
274
+ local seq = of.head[of.seqAt]
275
+
276
+ local held = pos + def.stream.bytes
277
+ local key = def.keyIndex
278
+ if key ~= nil then
279
+ held, of.key = def.fieldBuilt[key].read (b, held, ctx)
280
+ end
281
+
282
+ local count
283
+ count, held = Varint.read (b, held)
284
+ if count * LEAST > buffer.len (b) - held then Fieldset.broken (TOO_MANY) end
285
+
286
+ local last = 0
287
+ for index = 1, count do
288
+ local slot
289
+ slot, held = Varint.read (b, held)
290
+ if slot <= last then Fieldset.broken (OUT_OF_ORDER) end
291
+
292
+ of.slots[index] = slot
293
+ last = slot
294
+ end
295
+
296
+ held = layout.generations.back (b, held, of.gens :: any, layout.spare, count, ctx)
297
+ held = layout.fields[of.fields[at] ].back (b, held, of.values, layout.spare, count, ctx)
298
+
299
+ return at, seq, count, held
300
+ end
301
+
302
+ --[[
303
+ A section applied, where it is newer than what this stream has taken and where a slot's
304
+ generation is the one its keyframe stated.
305
+ ]]
306
+ function Newest.apply (
307
+ of: Lane,
308
+ streams: Streams,
309
+ store: Store.Store,
310
+ heard: Apply.Heard,
311
+ at: number,
312
+ seq: number,
313
+ count: number
314
+ )
315
+ if streams.took[at] and not Sequence.isNewer (seq, streams.heard[at]) then return end
316
+
317
+ streams.took[at] = true
318
+ streams.heard[at] = seq
319
+
320
+ local field = of.fields[at]
321
+ local gens = store.gens :: { [number]: number }
322
+ local ids = store.ids
323
+
324
+ for index = 1, count do
325
+ local slot = of.slots[index]
326
+ local id = ids[slot]
327
+ if id == nil or gens[slot] ~= of.gens[index] then continue end
328
+
329
+ -- A value the record already holds is not a change and is not written.
330
+ local value = of.values[index]
331
+ if store.columns[field][slot] == value then continue end
332
+
333
+ Apply.snapped (heard, store, id)
334
+ Store.write (store, slot, field, value)
335
+ Apply.moved (heard, id)
336
+ end
337
+ end
338
+
339
+ return table.freeze (Newest)