cluaupp 1.5.0 → 1.5.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.
Files changed (323) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +10 -5
  3. package/api/CHANGELOG.md +3 -0
  4. package/api/chat.js +74 -0
  5. package/api/fixtures/roblox/README.md +6 -0
  6. package/api/fixtures/roblox/aux/sample.d.luau +6 -0
  7. package/api/fixtures/roblox/mini/Mini-API-Dump.json +72 -0
  8. package/api/generated/bench-latest.json +39 -0
  9. package/api/generated/capability-profile.json +76 -0
  10. package/api/generated/lsp-index.json +1 -0
  11. package/api/generated/luau/classes.d.luau +11221 -0
  12. package/api/generated/luau/datatypes.d.luau +327 -0
  13. package/api/generated/luau/enums.d.luau +4918 -0
  14. package/api/generated/luau/globals.d.luau +12 -0
  15. package/api/manifests/roblox-target.manifest.json +22 -0
  16. package/api/normalized/roblox-target.profile.json +237461 -0
  17. package/api/overrides/classes.json +8 -0
  18. package/api/overrides/compatibility.json +9 -0
  19. package/api/overrides/datatypes.json +1579 -0
  20. package/api/overrides/enums.json +8 -0
  21. package/api/overrides/globals.json +8 -0
  22. package/api/overrides/type-mappings.json +9 -0
  23. package/api/roblox-api.lock.json +9 -0
  24. package/data/Mini-API-Dump.json +1 -0
  25. package/editors/vscode/README.md +12 -10
  26. package/editors/vscode/extension.js +82 -0
  27. package/editors/vscode/icons/axiom.svg +4 -0
  28. package/editors/vscode/icons/bloom.svg +5 -0
  29. package/editors/vscode/icons/helm.svg +4 -0
  30. package/editors/vscode/icons/hive.svg +5 -0
  31. package/editors/vscode/icons/mint.svg +4 -0
  32. package/editors/vscode/icons/shift.svg +6 -0
  33. package/editors/vscode/language-configuration-schema.json +24 -0
  34. package/editors/vscode/package.json +172 -12
  35. package/editors/vscode/snippets/axiom.json +12 -0
  36. package/editors/vscode/snippets/bloom.json +12 -0
  37. package/editors/vscode/snippets/helm.json +12 -0
  38. package/editors/vscode/snippets/hive.json +12 -0
  39. package/editors/vscode/snippets/mint.json +12 -0
  40. package/editors/vscode/snippets/shift.json +17 -0
  41. package/editors/vscode/syntaxes/axiom.tmLanguage.json +5 -0
  42. package/editors/vscode/syntaxes/bloom.tmLanguage.json +5 -0
  43. package/editors/vscode/syntaxes/helm.tmLanguage.json +5 -0
  44. package/editors/vscode/syntaxes/hive.tmLanguage.json +5 -0
  45. package/editors/vscode/syntaxes/mint.tmLanguage.json +5 -0
  46. package/editors/vscode/syntaxes/schema.tmLanguage.json +89 -0
  47. package/editors/vscode/syntaxes/shift.tmLanguage.json +5 -0
  48. package/examples/game/.cluaupp/compile-cache/ReplicatedStorage__Shared__Constants__Datas__TemplateData.clh.json +1 -0
  49. package/examples/game/.cluaupp/compile-cache/ServerScriptService__Boot__DataBoot.server.clpp.json +1 -0
  50. package/examples/game/.cluaupp/compile-cache/ServerScriptService__Configuration__ServerConfig.clp.json +1 -0
  51. package/examples/game/.cluaupp/compile-cache/ServerScriptService__Handlers__Guard.server.clpp.json +1 -0
  52. package/examples/game/.cluaupp/compile-cache/ServerScriptService__Handlers__PlayerHandler.server.clpp.json +1 -0
  53. package/examples/game/.cluaupp/compile-cache/StarterPlayer__StarterCharacterScripts__Character__CharacterReady.client.clpp.json +1 -0
  54. package/examples/game/.cluaupp/compile-cache/StarterPlayer__StarterPlayerScripts__Controllers__DataController.client.clpp.json +1 -0
  55. package/examples/game/.cluaupp/compile-cache/index.json +12 -0
  56. package/examples/game/.cluaupp/datamodel-profile.json +94 -0
  57. package/examples/game/.vscode/settings.json +12 -1
  58. package/examples/game/include/clpp/datatypes.clh +337 -373
  59. package/examples/game/include/clpp/generated/datamodel.clh +25 -0
  60. package/examples/game/include/clpp/generated/enums.clh +1 -1
  61. package/examples/game/include/clpp/generated/instances.clh +41135 -41064
  62. package/examples/game/include/clpp/libs/axiom.clh +1 -1
  63. package/examples/game/include/clpp/libs/math.clh +14 -0
  64. package/examples/game/include/clpp/libs/spring.clh +17 -0
  65. package/examples/game/include/clpp/libs/ward.clh +1 -0
  66. package/examples/game/include/clpp/roblox.clh +3 -4
  67. package/examples/game/libs/ArrayIndexer/init.luau +209 -0
  68. package/examples/game/libs/Axiom/init.luau +608 -0
  69. package/examples/game/libs/Bloom/init.luau +433 -0
  70. package/examples/game/libs/Coil/init.luau +215 -0
  71. package/examples/game/libs/Crest/init.luau +426 -0
  72. package/examples/game/libs/Echo/init.luau +417 -0
  73. package/examples/game/libs/Ember/init.luau +365 -0
  74. package/examples/game/libs/Flare/init.luau +717 -0
  75. package/examples/game/libs/Gleam/init.luau +729 -0
  76. package/examples/game/libs/Guide/init.luau +215 -0
  77. package/examples/game/libs/Helm/init.luau +377 -0
  78. package/examples/game/libs/Hive/init.luau +241 -0
  79. package/examples/game/libs/Keep/Client.luau +114 -0
  80. package/examples/game/libs/Keep/Data.luau +883 -0
  81. package/examples/game/libs/Keep/Engine.luau +211 -0
  82. package/examples/game/libs/Keep/Enum.luau +6 -0
  83. package/examples/game/libs/Keep/Enums.luau +10 -0
  84. package/examples/game/libs/Keep/Path.luau +236 -0
  85. package/examples/game/libs/Keep/Replicator.luau +298 -0
  86. package/examples/game/libs/Keep/Server.luau +251 -0
  87. package/examples/game/libs/Keep/Store.luau +652 -0
  88. package/examples/game/libs/Keep/Trade.luau +455 -0
  89. package/examples/game/libs/Keep/init.luau +205 -0
  90. package/examples/game/libs/Lens/init.luau +609 -0
  91. package/examples/game/libs/Mint/init.luau +279 -0
  92. package/examples/game/libs/Net/init.luau +156 -0
  93. package/examples/game/libs/Net/src/codec.luau +224 -0
  94. package/examples/game/libs/Occlude/init.luau +117 -0
  95. package/examples/game/libs/Pin/init.luau +309 -0
  96. package/examples/game/libs/Promise/LICENSE +21 -0
  97. package/examples/game/libs/Promise/_impl/LICENSE +21 -0
  98. package/examples/game/libs/Promise/_impl/init.lua +1991 -0
  99. package/examples/game/libs/Promise/init.lua +1990 -0
  100. package/examples/game/libs/Promise/init.luau +13 -0
  101. package/examples/game/libs/Promise/types.luau +46 -0
  102. package/examples/game/libs/Roster/init.luau +686 -0
  103. package/examples/game/libs/SOURCES.md +31 -0
  104. package/examples/game/libs/Shift/init.luau +238 -0
  105. package/examples/game/libs/Spark/init.luau +487 -0
  106. package/examples/game/libs/Stage/init.luau +178 -0
  107. package/examples/game/libs/Sweep/init.luau +259 -0
  108. package/examples/game/libs/Trace/init.luau +213 -0
  109. package/examples/game/libs/Ward/init.luau +211 -0
  110. package/examples/game/out/ReplicatedStorage/Shared/Constants/Datas/TemplateData.luau +29 -0
  111. package/examples/game/out/ReplicatedStorage/Shared/Constants/Datas/TemplateData.luau.map.json +13 -0
  112. package/examples/game/out/ReplicatedStorage/Shared/Net/Net.luau +83 -0
  113. package/examples/game/out/ReplicatedStorage/Shared/Net/Net.luau.map.json +13 -0
  114. package/examples/game/out/ServerScriptService/Boot/DataBoot.server.luau +18 -0
  115. package/examples/game/out/ServerScriptService/Boot/DataBoot.server.luau.map.json +13 -0
  116. package/examples/game/out/ServerScriptService/Configuration/ServerConfig.luau +14 -0
  117. package/examples/game/out/ServerScriptService/Configuration/ServerConfig.luau.map.json +13 -0
  118. package/examples/game/out/ServerScriptService/Handlers/Guard.server.luau +15 -0
  119. package/examples/game/out/ServerScriptService/Handlers/Guard.server.luau.map.json +13 -0
  120. package/examples/game/out/ServerScriptService/Handlers/PlayerHandler.server.luau +50 -0
  121. package/examples/game/out/ServerScriptService/Handlers/PlayerHandler.server.luau.map.json +13 -0
  122. package/examples/game/out/StarterPlayer/StarterCharacterScripts/Character/CharacterReady.client.luau +12 -0
  123. package/examples/game/out/StarterPlayer/StarterCharacterScripts/Character/CharacterReady.client.luau.map.json +13 -0
  124. package/examples/game/out/StarterPlayer/StarterPlayerScripts/Controllers/DataController.client.luau +16 -0
  125. package/examples/game/out/StarterPlayer/StarterPlayerScripts/Controllers/DataController.client.luau.map.json +13 -0
  126. package/examples/game/src/ReplicatedStorage/Shared/Net/Net.clh +26 -0
  127. package/examples/game/src/ServerScriptService/Boot/DataBoot.server.clpp +1 -1
  128. package/examples/game/src/ServerScriptService/Handlers/PlayerHandler.server.clpp +1 -1
  129. package/examples/game/stylua.toml +9 -0
  130. package/generated/api/build-profile.js +115 -0
  131. package/generated/api/cache.js +44 -0
  132. package/generated/api/coverage.js +32 -0
  133. package/generated/api/diff.js +125 -0
  134. package/generated/api/generators/clpp-headers.js +353 -0
  135. package/generated/api/generators/docs-reference.js +7 -0
  136. package/generated/api/generators/lsp-index.js +81 -0
  137. package/generated/api/generators/luau-defs.js +94 -0
  138. package/generated/api/ide.js +76 -0
  139. package/generated/api/identifier.js +47 -0
  140. package/generated/api/index.js +324 -0
  141. package/generated/api/loader.js +57 -0
  142. package/generated/api/merge.js +88 -0
  143. package/generated/api/model.js +5 -0
  144. package/generated/api/normalize.js +231 -0
  145. package/generated/api/overrides-validate.js +58 -0
  146. package/generated/api/perf.js +12 -0
  147. package/generated/api/registry.js +136 -0
  148. package/generated/api/release.js +44 -0
  149. package/generated/api/resolver.js +250 -0
  150. package/generated/api/sources/aux-types-diff.js +75 -0
  151. package/generated/api/sources/client-tracker.js +11 -0
  152. package/generated/api/sources/creator-docs.js +42 -0
  153. package/generated/api/sources/luau-types.js +34 -0
  154. package/generated/api/sources/mini-dump.js +17 -0
  155. package/generated/api/sources/studio-api.js +8 -0
  156. package/generated/api/sources/studio-apiv2.js +11 -0
  157. package/generated/api/sources/studio-full-api.js +8 -0
  158. package/generated/api/studio-smoke.js +80 -0
  159. package/generated/api/type-parse.js +49 -0
  160. package/generated/api/understander.js +51 -0
  161. package/generated/api/validate.js +135 -0
  162. package/generated/api-cli.js +421 -0
  163. package/generated/cli.js +16 -5
  164. package/generated/clpp/contract.js +3 -3
  165. package/generated/clpp/format-luau.js +236 -0
  166. package/generated/clpp/index.js +13 -1
  167. package/generated/clpp/modules.js +227 -0
  168. package/generated/clpp/postprocess.js +86 -5
  169. package/generated/clpp/rewrite-janitor.js +145 -0
  170. package/generated/clpp/runner.js +14 -2
  171. package/generated/compile.js +82 -0
  172. package/generated/flare/parse.js +12 -1
  173. package/generated/intellisense.js +57 -1
  174. package/generated/native/index.js +217 -16
  175. package/generated/target/authority-check.js +136 -0
  176. package/generated/target/authority-graph.js +74 -0
  177. package/generated/target/build-cache.js +112 -0
  178. package/generated/target/capabilities.js +89 -0
  179. package/generated/target/capability-profile.js +30 -0
  180. package/generated/target/component-contracts.js +60 -0
  181. package/generated/target/context-check.js +160 -0
  182. package/generated/target/datamodel-check.js +170 -0
  183. package/generated/target/datamodel-generate.js +74 -0
  184. package/generated/target/datamodel.js +233 -0
  185. package/generated/target/diagnostics.js +63 -0
  186. package/generated/target/doctor.js +152 -0
  187. package/generated/target/flare-version.js +58 -0
  188. package/generated/target/get-service.js +69 -0
  189. package/generated/target/lifetime-check.js +47 -0
  190. package/generated/target/luau-stamp.js +39 -0
  191. package/generated/target/optimizer-advise.js +88 -0
  192. package/generated/target/optimizer-apply.js +44 -0
  193. package/generated/target/optimizer-soa.js +254 -0
  194. package/generated/target/parallel-check.js +136 -0
  195. package/generated/target/pgo.js +148 -0
  196. package/generated/target/project-docs.js +69 -0
  197. package/generated/target/project-graph.js +71 -0
  198. package/generated/target/roblox.js +63 -0
  199. package/generated/target/security-check.js +41 -0
  200. package/generated/target/source-map.js +25 -0
  201. package/generated/target/studio-bridge.js +112 -0
  202. package/generated/utils/project.js +178 -8
  203. package/generated/utils/rojo-mapper.js +11 -3
  204. package/include/clpp/datatypes.clh +337 -373
  205. package/include/clpp/generated/enums.clh +1 -1
  206. package/include/clpp/generated/instances.clh +41135 -41064
  207. package/include/clpp/libs/axiom.clh +1 -1
  208. package/include/clpp/libs/hive.clh +1 -0
  209. package/include/clpp/libs/keep.clh +2 -0
  210. package/include/clpp/libs/math.clh +14 -0
  211. package/include/clpp/libs/spring.clh +17 -0
  212. package/include/clpp/libs/ward.clh +1 -0
  213. package/include/clpp/roblox.clh +3 -4
  214. package/package.json +10 -3
  215. package/plugins/CluauppNav/Plugin.luau +207 -0
  216. package/plugins/CluauppNav/ProfileLogger.luau +27 -0
  217. package/plugins/CluauppNav/README.md +24 -0
  218. package/runtime/Axiom/init.luau +10 -7
  219. package/runtime/Coil/init.luau +8 -2
  220. package/runtime/Crest/init.luau +1 -0
  221. package/runtime/Flare/init.luau +2 -1
  222. package/runtime/Gleam/init.luau +15 -4
  223. package/runtime/Hive/init.luau +36 -14
  224. package/runtime/Pin/init.luau +5 -2
  225. package/runtime/Roster/init.luau +2 -0
  226. package/runtime/Spark/init.luau +3 -0
  227. package/runtime/Sweep/init.luau +2 -0
  228. package/runtime/Trace/init.luau +3 -0
  229. package/runtime/Ward/init.luau +38 -5
  230. package/scripts/postinstall-editor.js +17 -0
  231. package/skills/README.md +13 -0
  232. package/skills/clpp-hive-flare/SKILL.md +79 -0
  233. package/skills/clpp-language/SKILL.md +123 -0
  234. package/skills/clpp-language/compiler.md +89 -0
  235. package/skills/clpp-style/SKILL.md +95 -0
  236. package/src/api/build-profile.ts +138 -0
  237. package/src/api/cache.ts +45 -0
  238. package/src/api/coverage.ts +46 -0
  239. package/src/api/diff.ts +143 -0
  240. package/src/api/generators/clpp-headers.ts +377 -0
  241. package/src/api/generators/docs-reference.ts +11 -0
  242. package/src/api/generators/lsp-index.ts +106 -0
  243. package/src/api/generators/luau-defs.ts +98 -0
  244. package/src/api/ide.ts +87 -0
  245. package/src/api/identifier.ts +47 -0
  246. package/src/api/index.ts +269 -0
  247. package/src/api/loader.ts +60 -0
  248. package/src/api/merge.ts +126 -0
  249. package/src/api/model.ts +283 -0
  250. package/src/api/normalize.ts +257 -0
  251. package/src/api/overrides-validate.ts +58 -0
  252. package/src/api/perf.ts +15 -0
  253. package/src/api/registry.ts +162 -0
  254. package/src/api/release.ts +47 -0
  255. package/src/api/resolver.ts +255 -0
  256. package/src/api/sources/aux-types-diff.ts +81 -0
  257. package/src/api/sources/client-tracker.ts +10 -0
  258. package/src/api/sources/creator-docs.ts +37 -0
  259. package/src/api/sources/luau-types.ts +30 -0
  260. package/src/api/sources/mini-dump.ts +50 -0
  261. package/src/api/sources/studio-api.ts +7 -0
  262. package/src/api/sources/studio-apiv2.ts +10 -0
  263. package/src/api/sources/studio-full-api.ts +7 -0
  264. package/src/api/studio-smoke.ts +82 -0
  265. package/src/api/type-parse.ts +48 -0
  266. package/src/api/understander.ts +72 -0
  267. package/src/api/validate.ts +160 -0
  268. package/src/api-cli.ts +493 -0
  269. package/src/api.generated.js +37 -22
  270. package/src/cli.ts +21 -6
  271. package/src/clpp/contract.ts +34 -3
  272. package/src/clpp/format-luau.ts +262 -0
  273. package/src/clpp/index.ts +13 -2
  274. package/src/clpp/modules.ts +252 -0
  275. package/src/clpp/postprocess.ts +100 -5
  276. package/src/clpp/rewrite-janitor.ts +156 -0
  277. package/src/clpp/runner.ts +14 -2
  278. package/src/compile.ts +87 -0
  279. package/src/flare/parse.ts +14 -1
  280. package/src/flare/types.ts +2 -0
  281. package/src/intellisense.ts +58 -1
  282. package/src/native/index.ts +225 -16
  283. package/src/target/authority-check.ts +162 -0
  284. package/src/target/authority-graph.ts +80 -0
  285. package/src/target/build-cache.ts +129 -0
  286. package/src/target/capabilities.ts +115 -0
  287. package/src/target/capability-profile.ts +25 -0
  288. package/src/target/component-contracts.ts +64 -0
  289. package/src/target/context-check.ts +177 -0
  290. package/src/target/datamodel-check.ts +188 -0
  291. package/src/target/datamodel-generate.ts +78 -0
  292. package/src/target/datamodel.ts +261 -0
  293. package/src/target/diagnostics.ts +67 -0
  294. package/src/target/doctor.ts +171 -0
  295. package/src/target/flare-version.ts +61 -0
  296. package/src/target/get-service.ts +85 -0
  297. package/src/target/lifetime-check.ts +45 -0
  298. package/src/target/luau-stamp.ts +33 -0
  299. package/src/target/optimizer-advise.ts +93 -0
  300. package/src/target/optimizer-apply.ts +63 -0
  301. package/src/target/optimizer-soa.ts +270 -0
  302. package/src/target/parallel-check.ts +135 -0
  303. package/src/target/pgo.ts +157 -0
  304. package/src/target/project-docs.ts +68 -0
  305. package/src/target/project-graph.ts +75 -0
  306. package/src/target/roblox.ts +78 -0
  307. package/src/target/security-check.ts +40 -0
  308. package/src/target/source-map.ts +36 -0
  309. package/src/target/studio-bridge.ts +140 -0
  310. package/src/types.ts +14 -0
  311. package/src/utils/project.ts +183 -9
  312. package/src/utils/rojo-mapper.ts +12 -3
  313. package/stylua.toml +9 -0
  314. package/templates/game/.vscode/settings.json +7 -1
  315. package/templates/game/include/clpp/datatypes.clh +337 -373
  316. package/templates/game/include/clpp/generated/enums.clh +1 -1
  317. package/templates/game/include/clpp/generated/instances.clh +41135 -41064
  318. package/templates/game/include/clpp/libs/axiom.clh +1 -1
  319. package/templates/game/include/clpp/libs/ward.clh +1 -0
  320. package/templates/game/include/clpp/roblox.clh +3 -4
  321. package/templates/game/src/ServerScriptService/Boot/DataBoot.server.clpp +1 -1
  322. package/templates/game/src/ServerScriptService/Handlers/PlayerHandler.server.clpp +1 -1
  323. package/templates/game/stylua.toml +9 -0
@@ -0,0 +1,883 @@
1
+ local Path = require(script.Parent.Path)
2
+ const Enums = require(script.Parent.Enums)
3
+ const PackageEnum = require(script.Parent.Enum)
4
+ const Signal = require(script.Parent.Parent.Spark)
5
+
6
+ type SignalT = typeof(Signal.new())
7
+ type AnyConnection = RBXScriptConnection
8
+ type TypedSignal<T...> = {
9
+ Connect: (self: TypedSignal<T...>, fn: (T...) -> ()) -> AnyConnection,
10
+ Once: (self: TypedSignal<T...>, fn: (T...) -> ()) -> AnyConnection,
11
+ Wait: (self: TypedSignal<T...>) -> T...,
12
+ }
13
+
14
+ const Data = {}
15
+
16
+ --[=[
17
+ @class Data
18
+ Per-player data instance. Writable on the server, read-only on the client.
19
+ Use `Get()` for merged reads and `GetPersisted()` for saved ProfileStore values.
20
+ ]=]
21
+ const ROOT_KEY = {}
22
+ const WRITABLE_KEY = {}
23
+ const STRICT_PATHS_KEY = {}
24
+ const AUTO_CREATE_KEY = {}
25
+ const CHANGED_MAP_KEY = {}
26
+ const INDEX_CHANGED_MAP_KEY = {}
27
+ const ARRAY_INSERTED_MAP_KEY = {}
28
+ const ARRAY_REMOVED_MAP_KEY = {}
29
+ const TRANSIENT_KEY = {}
30
+
31
+ export type DataPath = Path.Path
32
+ export type DataPathLike = Path.Path | Path.PathToken<never>
33
+ export type DataOptions<T = never> = {
34
+ StrictPaths: boolean?,
35
+ AutoCreateMissingTables: boolean?,
36
+ Template: T?,
37
+ }
38
+ export type OrderedListOrder = typeof(PackageEnum.OrderList.Asc) | typeof(PackageEnum.OrderList.Desc) | "asc" | "desc"
39
+ export type OrderedListOptions = {
40
+ key: string,
41
+ order: OrderedListOrder?,
42
+ limit: number?,
43
+ }
44
+ export type OrderedListEntry<V> = {
45
+ index: number,
46
+ value: V,
47
+ priority: any,
48
+ }
49
+ type TypedPath<V> = Path.PathToken<V>
50
+ type ChangedSignal<V> = TypedSignal<V, V>
51
+ type IndexChangedSignal<V> = TypedSignal<string | number, V, V>
52
+ type ArrayInsertedSignal<V> = TypedSignal<number, V>
53
+ type ArrayRemovedSignal<V> = TypedSignal<number, V>
54
+ type DataCore<T> = {
55
+ Changed: SignalT,
56
+ Destroyed: boolean,
57
+ Typed: <V>(self: DataCore<T>, path: DataPathLike) -> TypedPath<V>,
58
+ Get: <V>(self: DataCore<T>, path: TypedPath<V> | DataPathLike?) -> V,
59
+ GetPersisted: <V>(self: DataCore<T>, path: TypedPath<V> | DataPathLike?) -> V,
60
+ GetTransient: <V>(self: DataCore<T>, path: TypedPath<V> | DataPathLike?) -> V?,
61
+ HasTransient: (self: DataCore<T>, path: DataPathLike?) -> boolean,
62
+ Set: <V>(self: DataCore<T>, path: TypedPath<V> | DataPathLike, value: V) -> (),
63
+ SetTransient: <V>(self: DataCore<T>, path: TypedPath<V> | DataPathLike, value: V) -> (),
64
+ Update: <V>(self: DataCore<T>, path: TypedPath<V> | DataPathLike, fn: (V) -> V) -> V,
65
+ UpdateTransient: <V>(self: DataCore<T>, path: TypedPath<V> | DataPathLike, fn: (V) -> V) -> V,
66
+ ClearTransient: (self: DataCore<T>, path: DataPathLike?) -> (),
67
+ ArrayInsert: <V>(self: DataCore<T>, path: TypedPath<{ V }> | DataPathLike, value: V, index: number?) -> (),
68
+ ArrayInsertTransient: <V>(self: DataCore<T>, path: TypedPath<{ V }> | DataPathLike, value: V, index: number?) -> (),
69
+ ArrayRemove: <V>(self: DataCore<T>, path: TypedPath<{ V }> | DataPathLike, index: number) -> V,
70
+ ArrayRemoveTransient: <V>(self: DataCore<T>, path: TypedPath<{ V }> | DataPathLike, index: number) -> V,
71
+ GetOrderedList: <V>(self: DataCore<T>, path: TypedPath<{ V }> | DataPathLike, options: OrderedListOptions) -> { OrderedListEntry<V> },
72
+ GetOrderedListWithPriority: <V>(
73
+ self: DataCore<T>,
74
+ path: TypedPath<{ V }> | DataPathLike,
75
+ key: string,
76
+ order: OrderedListOrder?
77
+ ) -> { OrderedListEntry<V> },
78
+ GetChangedSignal: <V>(self: DataCore<T>, path: TypedPath<V> | DataPathLike) -> ChangedSignal<V>,
79
+ GetPathChangedSignal: <V>(self: DataCore<T>, path: TypedPath<V> | DataPathLike) -> ChangedSignal<V>,
80
+ GetIndexChangedSignal: <V>(self: DataCore<T>, path: TypedPath<V> | DataPathLike) -> IndexChangedSignal<V>,
81
+ GetArrayInsertedSignal: <V>(self: DataCore<T>, path: TypedPath<{ V }> | DataPathLike) -> ArrayInsertedSignal<V>,
82
+ GetArrayRemovedSignal: <V>(self: DataCore<T>, path: TypedPath<{ V }> | DataPathLike) -> ArrayRemovedSignal<V>,
83
+ Destroy: (self: DataCore<T>) -> (),
84
+ }
85
+ export type Data<T> = DataCore<T>
86
+
87
+ const READ_ONLY_ERROR = "DataService: Data on the client is read-only. Mutations are server-driven."
88
+ const INVALID_PATH_ERROR = "DataService: invalid data path %q"
89
+
90
+ const pathToString = function(path: DataPath): string
91
+ if #path == 0 then
92
+ return "<root>"
93
+ end
94
+ local parts = table.create(#path)
95
+ for i, segment in path do
96
+ parts[i] = tostring(segment)
97
+ end
98
+ return table.concat(parts, ".")
99
+ end
100
+
101
+ const normalizePath = function(pathLike: DataPathLike?, allowNil: boolean?): DataPath?
102
+ local resolved = Path.toArray(pathLike)
103
+ if resolved == nil then
104
+ if allowNil then
105
+ return nil
106
+ end
107
+ error("DataService: path is required")
108
+ end
109
+ if not Path.validate(resolved) then
110
+ error(string.format(INVALID_PATH_ERROR, pathToString(resolved)))
111
+ end
112
+ return resolved
113
+ end
114
+
115
+ const pathFromKey = function(key: string): DataPath
116
+ if key == "" then
117
+ return {}
118
+ end
119
+ local path = table.create(4)
120
+ for part in string.gmatch(key, "[^\0]+") do
121
+ local kind = string.sub(part, 1, 1)
122
+ local value = string.sub(part, 3)
123
+ if kind == "s" then
124
+ path[#path + 1] = value
125
+ elseif kind == "n" then
126
+ path[#path + 1] = tonumber(value)
127
+ end
128
+ end
129
+ return path
130
+ end
131
+
132
+ const isDescendantPath = function(childKey: string, parentKey: string): boolean
133
+ if parentKey == "" then
134
+ return childKey ~= ""
135
+ end
136
+ return childKey == parentKey or string.sub(childKey, 1, #parentKey + 1) == parentKey .. "\0"
137
+ end
138
+
139
+ local function deepCopyTable(value: any): any
140
+ if type(value) ~= "table" then
141
+ return value
142
+ end
143
+ local out = {}
144
+ for k, v in value do
145
+ out[k] = deepCopyTable(v)
146
+ end
147
+ return out
148
+ end
149
+
150
+ const setAtPath = function(root: any, path: DataPath, value: any)
151
+ if #path == 0 then
152
+ return
153
+ end
154
+ local parent = root
155
+ for i = 1, #path - 1 do
156
+ local k = path[i]
157
+ local nextValue = rawget(parent, k)
158
+ if type(nextValue) ~= "table" then
159
+ nextValue = {}
160
+ rawset(parent, k, nextValue)
161
+ end
162
+ parent = nextValue
163
+ end
164
+ rawset(parent, path[#path], value)
165
+ end
166
+
167
+ const getPersistedAt = function(root: any, path: DataPath?): any
168
+ if not path or #path == 0 then
169
+ return root
170
+ end
171
+ local cur: any = root
172
+ for _, k in path do
173
+ if type(cur) ~= "table" then
174
+ return nil
175
+ end
176
+ cur = rawget(cur, k)
177
+ end
178
+ return cur
179
+ end
180
+
181
+ const getMergedValue = function(self: any, path: DataPath): any
182
+ local transient = self[TRANSIENT_KEY]
183
+ local key = Path.toKey(path)
184
+ local direct = transient[key]
185
+ if direct ~= nil then
186
+ return direct
187
+ end
188
+
189
+ if #path == 0 then
190
+ local persisted = self[ROOT_KEY]
191
+ local out = if type(persisted) == "table" then deepCopyTable(persisted) else {}
192
+ for tKey, tVal in transient do
193
+ setAtPath(out, pathFromKey(tKey), tVal)
194
+ end
195
+ return out
196
+ end
197
+
198
+ local persisted = getPersistedAt(self[ROOT_KEY], path)
199
+ local hasDescendant = false
200
+ for tKey in transient do
201
+ if isDescendantPath(tKey, key) then
202
+ hasDescendant = true
203
+ break
204
+ end
205
+ end
206
+ if not hasDescendant then
207
+ return persisted
208
+ end
209
+
210
+ local out = if type(persisted) == "table" then deepCopyTable(persisted) else {}
211
+ for tKey, tVal in transient do
212
+ if isDescendantPath(tKey, key) then
213
+ local tPath = pathFromKey(tKey)
214
+ local relative = table.create(math.max(#tPath - #path, 0))
215
+ for i = #path + 1, #tPath do
216
+ relative[#relative + 1] = tPath[i]
217
+ end
218
+ if #relative > 0 then
219
+ setAtPath(out, relative, tVal)
220
+ end
221
+ end
222
+ end
223
+ return out
224
+ end
225
+
226
+ const copyArray = function(value: any): { any }
227
+ local out = table.create(#value)
228
+ for index, item in value do
229
+ out[index] = if type(item) == "table" then deepCopyTable(item) else item
230
+ end
231
+ return out
232
+ end
233
+
234
+ function Data.new<T>(initial: T, writable: boolean?, options: DataOptions<T>?): Data<T>
235
+ local self: any
236
+ self = {
237
+ Get = function(a, b)
238
+ local path = if a == self then b else a
239
+ return Data.Get(self, path)
240
+ end,
241
+ GetPersisted = function(a, b)
242
+ local path = if a == self then b else a
243
+ return Data.GetPersisted(self, path)
244
+ end,
245
+ GetTransient = function(a, b)
246
+ local path = if a == self then b else a
247
+ return Data.GetTransient(self, path)
248
+ end,
249
+ HasTransient = function(a, b)
250
+ local path = if a == self then b else a
251
+ return Data.HasTransient(self, path)
252
+ end,
253
+ Set = function(a, b, c)
254
+ local path = if a == self then b else a
255
+ local value = if a == self then c else b
256
+ return Data.Set(self, path, value)
257
+ end,
258
+ SetTransient = function(a, b, c)
259
+ local path = if a == self then b else a
260
+ local value = if a == self then c else b
261
+ return Data.SetTransient(self, path, value)
262
+ end,
263
+ Update = function(a, b, c)
264
+ local path = if a == self then b else a
265
+ local fn = if a == self then c else b
266
+ return Data.Update(self, path, fn)
267
+ end,
268
+ UpdateTransient = function(a, b, c)
269
+ local path = if a == self then b else a
270
+ local fn = if a == self then c else b
271
+ return Data.UpdateTransient(self, path, fn)
272
+ end,
273
+ ClearTransient = function(a, b)
274
+ local path = if a == self then b else a
275
+ return Data.ClearTransient(self, path)
276
+ end,
277
+ ArrayInsert = function(a, b, c, d)
278
+ local path = if a == self then b else a
279
+ local value = if a == self then c else b
280
+ local index = if a == self then d else c
281
+ return Data.ArrayInsert(self, path, value, index)
282
+ end,
283
+ ArrayInsertTransient = function(a, b, c, d)
284
+ local path = if a == self then b else a
285
+ local value = if a == self then c else b
286
+ local index = if a == self then d else c
287
+ return Data.ArrayInsertTransient(self, path, value, index)
288
+ end,
289
+ ArrayRemove = function(a, b, c)
290
+ local path = if a == self then b else a
291
+ local index = if a == self then c else b
292
+ return Data.ArrayRemove(self, path, index)
293
+ end,
294
+ ArrayRemoveTransient = function(a, b, c)
295
+ local path = if a == self then b else a
296
+ local index = if a == self then c else b
297
+ return Data.ArrayRemoveTransient(self, path, index)
298
+ end,
299
+ GetOrderedList = function(a, b, c)
300
+ local path = if a == self then b else a
301
+ local options = if a == self then c else b
302
+ return Data.GetOrderedList(self, path, options)
303
+ end,
304
+ GetOrderedListWithPriority = function(a, b, c, d)
305
+ local path = if a == self then b else a
306
+ local key = if a == self then c else b
307
+ local order = if a == self then d else c
308
+ return Data.GetOrderedListWithPriority(self, path, key, order)
309
+ end,
310
+ GetChangedSignal = function(a, b)
311
+ local path = if a == self then b else a
312
+ return Data.GetChangedSignal(self, path)
313
+ end,
314
+ GetPathChangedSignal = function(a, b)
315
+ local path = if a == self then b else a
316
+ return Data.GetPathChangedSignal(self, path)
317
+ end,
318
+ GetIndexChangedSignal = function(a, b)
319
+ local path = if a == self then b else a
320
+ return Data.GetIndexChangedSignal(self, path)
321
+ end,
322
+ GetArrayInsertedSignal = function(a, b)
323
+ local path = if a == self then b else a
324
+ return Data.GetArrayInsertedSignal(self, path)
325
+ end,
326
+ GetArrayRemovedSignal = function(a, b)
327
+ local path = if a == self then b else a
328
+ return Data.GetArrayRemovedSignal(self, path)
329
+ end,
330
+ Typed = function(a, b)
331
+ local path = if a == self then b else a
332
+ return Data.Typed(self, path)
333
+ end,
334
+ Destroy = function()
335
+ return Data.Destroy(self)
336
+ end,
337
+ [ROOT_KEY] = initial,
338
+ [WRITABLE_KEY] = writable ~= false,
339
+ [STRICT_PATHS_KEY] = if options and options.StrictPaths ~= nil then options.StrictPaths else true,
340
+ [AUTO_CREATE_KEY] = if options and options.AutoCreateMissingTables ~= nil then options.AutoCreateMissingTables else false,
341
+ [CHANGED_MAP_KEY] = {} :: { [string]: SignalT },
342
+ [INDEX_CHANGED_MAP_KEY] = {} :: { [string]: SignalT },
343
+ [ARRAY_INSERTED_MAP_KEY] = {} :: { [string]: SignalT },
344
+ [ARRAY_REMOVED_MAP_KEY] = {} :: { [string]: SignalT },
345
+ [TRANSIENT_KEY] = {} :: { [string]: any },
346
+ Changed = Signal.new(),
347
+ Destroyed = false,
348
+ }
349
+
350
+ return (self :: any) :: Data<T>
351
+ end
352
+
353
+ const descend = function(root: any, path: DataPath?, ensureLeaf: boolean): (any?, any?)
354
+ if not path or #path == 0 then
355
+ return nil, nil
356
+ end
357
+ local parent = root
358
+ for i = 1, #path - 1 do
359
+ local k = path[i]
360
+ local nextValue = rawget(parent, k)
361
+ if type(nextValue) ~= "table" then
362
+ if ensureLeaf then
363
+ rawset(parent, k, {})
364
+ nextValue = rawget(parent, k)
365
+ else
366
+ return nil, nil
367
+ end
368
+ end
369
+ parent = nextValue
370
+ end
371
+ return parent, path[#path]
372
+ end
373
+
374
+ --[=[
375
+ @method Get
376
+ @within Data
377
+ @param path PathToken? -- Typed path or legacy array. Omit for the merged root.
378
+ @return any
379
+ Reads the merged value (persisted + transient overlay). Omit path for the full root.
380
+ ]=]
381
+ function Data:Get(path: DataPathLike?): any
382
+ local normalized = normalizePath(path, true) or {}
383
+ return getMergedValue(self, normalized)
384
+ end
385
+
386
+ --[=[
387
+ @method GetPersisted
388
+ @within Data
389
+ @tag Query
390
+ @param path PathToken?
391
+ @return any
392
+ Reads the saved ProfileStore value only (ignores transient overlay).
393
+ ]=]
394
+ function Data:GetPersisted(path: DataPathLike?): any
395
+ local normalized = normalizePath(path, true)
396
+ if not normalized or #normalized == 0 then
397
+ return self[ROOT_KEY]
398
+ end
399
+ return getPersistedAt(self[ROOT_KEY], normalized)
400
+ end
401
+
402
+ --[=[
403
+ @method GetTransient
404
+ @within Data
405
+ @tag Query
406
+ @param path PathToken?
407
+ @return any?
408
+ Reads the transient overlay at path, if present.
409
+ ]=]
410
+ function Data:GetTransient(path: DataPathLike?): any
411
+ local normalized = normalizePath(path, true) or {}
412
+ return self[TRANSIENT_KEY][Path.toKey(normalized)]
413
+ end
414
+
415
+ --[=[
416
+ @method HasTransient
417
+ @within Data
418
+ @tag Query
419
+ @param path PathToken?
420
+ @return boolean
421
+ Returns whether a transient overlay exists at or below the path.
422
+ ]=]
423
+ function Data:HasTransient(path: DataPathLike?): boolean
424
+ local normalized = normalizePath(path, true) or {}
425
+ local key = Path.toKey(normalized)
426
+ local transient = self[TRANSIENT_KEY]
427
+ if transient[key] ~= nil then
428
+ return true
429
+ end
430
+ for tKey in transient do
431
+ if isDescendantPath(tKey, key) then
432
+ return true
433
+ end
434
+ end
435
+ return false
436
+ end
437
+
438
+ --[=[
439
+ @method Typed
440
+ @within Data
441
+ @param path PathToken
442
+ @return PathToken
443
+ Type helper for stronger inference in signals and read/write calls.
444
+ ]=]
445
+ function Data:Typed(path: DataPathLike): any
446
+ return path :: any
447
+ end
448
+
449
+ function Data:_fireChanged(path: DataPath, newValue: any, oldValue: any)
450
+ if newValue == oldValue then
451
+ return
452
+ end
453
+ local key = Path.toKey(path)
454
+ local sig = self[CHANGED_MAP_KEY][key]
455
+ if sig then
456
+ sig:Fire(newValue, oldValue)
457
+ end
458
+ if #path > 0 then
459
+ local parentKey = Path.toKey(Path.parent(path))
460
+ local idx = self[INDEX_CHANGED_MAP_KEY][parentKey]
461
+ if idx then
462
+ idx:Fire(path[#path], newValue, oldValue)
463
+ end
464
+ end
465
+ end
466
+
467
+ function Data:_applySet(path: DataPath, value: any)
468
+ assert(path and #path > 0, "Data: path must be non-empty")
469
+ local parent, key = descend(self[ROOT_KEY], path, self[AUTO_CREATE_KEY])
470
+ assert(parent ~= nil and key ~= nil, string.format(INVALID_PATH_ERROR, pathToString(path)))
471
+ local old = rawget(parent, key)
472
+ if self[STRICT_PATHS_KEY] and not self[AUTO_CREATE_KEY] and old == nil and type(key) ~= "number" then
473
+ error(string.format(INVALID_PATH_ERROR, pathToString(path)))
474
+ end
475
+ rawset(parent, key, value)
476
+ Data._fireChanged(self, path, value, old)
477
+ end
478
+
479
+ function Data._applyTransientSet(self: any, path: DataPath, value: any)
480
+ local oldMerged = Data.Get(self, path)
481
+ self[TRANSIENT_KEY][Path.toKey(path)] = value
482
+ local newMerged = Data.Get(self, path)
483
+ Data._fireChanged(self, path, newMerged, oldMerged)
484
+ end
485
+
486
+ function Data._applyTransientArrayInsert(self: any, path: DataPath, value: any, index: number?)
487
+ local current = Data.Get(self, path)
488
+ local arr = if type(current) == "table" then copyArray(current) else {}
489
+ if index then
490
+ table.insert(arr, index, value)
491
+ else
492
+ table.insert(arr, value)
493
+ index = #arr
494
+ end
495
+ Data._applyTransientSet(self, path, arr)
496
+ local sig = self[ARRAY_INSERTED_MAP_KEY][Path.toKey(path)]
497
+ if sig then
498
+ sig:Fire(index, value)
499
+ end
500
+ end
501
+
502
+ function Data._applyTransientArrayRemove(self: any, path: DataPath, index: number): any
503
+ local current = Data.Get(self, path)
504
+ local arr = if type(current) == "table" then copyArray(current) else {}
505
+ local removed = table.remove(arr, index)
506
+ Data._applyTransientSet(self, path, arr)
507
+ local sig = self[ARRAY_REMOVED_MAP_KEY][Path.toKey(path)]
508
+ if sig then
509
+ sig:Fire(index, removed)
510
+ end
511
+ return removed
512
+ end
513
+
514
+ function Data._applyTransientClear(self: any, path: DataPath?)
515
+ if path then
516
+ local key = Path.toKey(path)
517
+ if self[TRANSIENT_KEY][key] == nil then
518
+ return
519
+ end
520
+ local oldMerged = Data.Get(self, path)
521
+ self[TRANSIENT_KEY][key] = nil
522
+ local newMerged = Data.Get(self, path)
523
+ Data._fireChanged(self, path, newMerged, oldMerged)
524
+ return
525
+ end
526
+
527
+ if next(self[TRANSIENT_KEY]) == nil then
528
+ return
529
+ end
530
+ table.clear(self[TRANSIENT_KEY])
531
+ end
532
+
533
+ function Data:_applyArrayInsert(path: DataPath, value: any, index: number?)
534
+ local arr = getPersistedAt(self[ROOT_KEY], path)
535
+ assert(type(arr) == "table", "Data: ArrayInsert requires an array path")
536
+ if index then
537
+ table.insert(arr, index, value)
538
+ else
539
+ table.insert(arr, value)
540
+ index = #arr
541
+ end
542
+ local sig = self[ARRAY_INSERTED_MAP_KEY][Path.toKey(path)]
543
+ if sig then
544
+ sig:Fire(index, value)
545
+ end
546
+ end
547
+
548
+ function Data:_applyArrayRemove(path: DataPath, index: number): any
549
+ local arr = getPersistedAt(self[ROOT_KEY], path)
550
+ assert(type(arr) == "table", "Data: ArrayRemove requires an array path")
551
+ local removed = table.remove(arr, index)
552
+ local sig = self[ARRAY_REMOVED_MAP_KEY][Path.toKey(path)]
553
+ if sig then
554
+ sig:Fire(index, removed)
555
+ end
556
+ return removed
557
+ end
558
+
559
+ --[=[
560
+ @method Set
561
+ @within Data
562
+ @tag Mutation
563
+ @param path PathToken
564
+ @param value any
565
+ Writes and persists to ProfileStore. **Server only.**
566
+ ]=]
567
+ function Data:Set(path: DataPathLike, value: any)
568
+ assert(self[WRITABLE_KEY], READ_ONLY_ERROR)
569
+ local normalized = normalizePath(path, false) :: DataPath
570
+ Data._applySet(self, normalized, value)
571
+ self.Changed:Fire(Enums.Set, normalized, value)
572
+ end
573
+
574
+ --[=[
575
+ @method SetTransient
576
+ @within Data
577
+ @tag Mutation
578
+ @param path PathToken
579
+ @param value any
580
+ Writes a transient overlay visible in `Get()` but **not saved**. **Server only.**
581
+ ]=]
582
+ function Data:SetTransient(path: DataPathLike, value: any)
583
+ assert(self[WRITABLE_KEY], READ_ONLY_ERROR)
584
+ local normalized = normalizePath(path, false) :: DataPath
585
+ Data._applyTransientSet(self, normalized, value)
586
+ self.Changed:Fire(Enums.SetTransient, normalized, value)
587
+ end
588
+
589
+ --[=[
590
+ @method Update
591
+ @within Data
592
+ @tag Mutation
593
+ @param path PathToken
594
+ @param fn (any) -> any
595
+ Updates the persisted value using a callback. **Server only.**
596
+ ]=]
597
+ function Data:Update(path: DataPathLike, fn: (any) -> any): any
598
+ assert(self[WRITABLE_KEY], READ_ONLY_ERROR)
599
+ local normalized = normalizePath(path, false) :: DataPath
600
+ local current = self:GetPersisted(normalized)
601
+ local new = fn(current)
602
+ self:Set(normalized, new)
603
+ return new
604
+ end
605
+
606
+ --[=[
607
+ @method UpdateTransient
608
+ @within Data
609
+ @tag Mutation
610
+ @param path PathToken
611
+ @param fn (any) -> any
612
+ Updates the merged value through a transient overlay. **Server only.**
613
+ ]=]
614
+ function Data:UpdateTransient(path: DataPathLike, fn: (any) -> any): any
615
+ assert(self[WRITABLE_KEY], READ_ONLY_ERROR)
616
+ local normalized = normalizePath(path, false) :: DataPath
617
+ local current = self:Get(normalized)
618
+ local new = fn(current)
619
+ self:SetTransient(normalized, new)
620
+ return new
621
+ end
622
+
623
+ --[=[
624
+ @method ClearTransient
625
+ @within Data
626
+ @tag Mutation
627
+ @param path PathToken?
628
+ Clears transient overlay at path, or all overlays when `path` is omitted. **Server only.**
629
+ ]=]
630
+ function Data:ClearTransient(path: DataPathLike?)
631
+ assert(self[WRITABLE_KEY], READ_ONLY_ERROR)
632
+ if path ~= nil then
633
+ local normalized = normalizePath(path, false) :: DataPath
634
+ Data._applyTransientClear(self, normalized)
635
+ self.Changed:Fire(Enums.ClearTransient, normalized)
636
+ return
637
+ end
638
+ Data._applyTransientClear(self, nil)
639
+ self.Changed:Fire(Enums.ClearTransient, nil)
640
+ end
641
+
642
+ --[=[
643
+ @method ArrayInsert
644
+ @within Data
645
+ @tag Mutation
646
+ @param path PathToken
647
+ @param value any
648
+ @param index number?
649
+ Inserts into a persisted array. **Server only.**
650
+ ]=]
651
+ function Data:ArrayInsert(path: DataPathLike, value: any, index: number?)
652
+ assert(self[WRITABLE_KEY], READ_ONLY_ERROR)
653
+ local normalized = normalizePath(path, false) :: DataPath
654
+ local arr = getPersistedAt(self[ROOT_KEY], normalized)
655
+ assert(type(arr) == "table", "Data:ArrayInsert requires an array path")
656
+ if index then
657
+ table.insert(arr, index, value)
658
+ else
659
+ table.insert(arr, value)
660
+ index = #arr
661
+ end
662
+ local sig = self[ARRAY_INSERTED_MAP_KEY][Path.toKey(normalized)]
663
+ if sig then
664
+ sig:Fire(index, value)
665
+ end
666
+ self.Changed:Fire(Enums.ArrayInsert, normalized, value, index)
667
+ end
668
+
669
+ --[=[
670
+ @method ArrayInsertTransient
671
+ @within Data
672
+ @tag Mutation
673
+ Inserts into an array through transient overlay. **Server only.**
674
+ ]=]
675
+ function Data:ArrayInsertTransient(path: DataPathLike, value: any, index: number?)
676
+ assert(self[WRITABLE_KEY], READ_ONLY_ERROR)
677
+ local normalized = normalizePath(path, false) :: DataPath
678
+ Data._applyTransientArrayInsert(self, normalized, value, index)
679
+ self.Changed:Fire(Enums.ArrayInsertTransient, normalized, value, index)
680
+ end
681
+
682
+ --[=[
683
+ @method ArrayRemove
684
+ @within Data
685
+ @tag Mutation
686
+ @param path PathToken
687
+ @param index number
688
+ Removes from a persisted array and returns the removed value. **Server only.**
689
+ ]=]
690
+ function Data:ArrayRemove(path: DataPathLike, index: number): any
691
+ assert(self[WRITABLE_KEY], READ_ONLY_ERROR)
692
+ local normalized = normalizePath(path, false) :: DataPath
693
+ local arr = getPersistedAt(self[ROOT_KEY], normalized)
694
+ assert(type(arr) == "table", "Data:ArrayRemove requires an array path")
695
+ local removed = table.remove(arr, index)
696
+ local sig = self[ARRAY_REMOVED_MAP_KEY][Path.toKey(normalized)]
697
+ if sig then
698
+ sig:Fire(index, removed)
699
+ end
700
+ self.Changed:Fire(Enums.ArrayRemove, normalized, index)
701
+ return removed
702
+ end
703
+
704
+ --[=[
705
+ @method ArrayRemoveTransient
706
+ @within Data
707
+ @tag Mutation
708
+ Removes from an array through transient overlay. **Server only.**
709
+ ]=]
710
+ function Data:ArrayRemoveTransient(path: DataPathLike, index: number): any
711
+ assert(self[WRITABLE_KEY], READ_ONLY_ERROR)
712
+ local normalized = normalizePath(path, false) :: DataPath
713
+ local removed = Data._applyTransientArrayRemove(self, normalized, index)
714
+ self.Changed:Fire(Enums.ArrayRemoveTransient, normalized, index)
715
+ return removed
716
+ end
717
+
718
+ const normalizeOrder = function(order: OrderedListOrder?): string
719
+ if order == nil then
720
+ return PackageEnum.OrderList.Desc
721
+ end
722
+ if order == PackageEnum.OrderList.Asc or order == "asc" then
723
+ return PackageEnum.OrderList.Asc
724
+ end
725
+ return PackageEnum.OrderList.Desc
726
+ end
727
+
728
+ --[=[
729
+ @method GetOrderedList
730
+ @within Data
731
+ @tag Query
732
+ @param path PathToken
733
+ @param options OrderedListOptions
734
+ @return { OrderedListEntry }
735
+ Collects and sorts table entries by `options.key`. Supports `order` and `limit`.
736
+ ]=]
737
+ function Data:GetOrderedList(path: DataPathLike, options: OrderedListOptions): { OrderedListEntry<any> }
738
+ local normalized = normalizePath(path, false) :: DataPath
739
+ local list = self:Get(normalized)
740
+ assert(type(list) == "table", "Data:GetOrderedList requires a table path")
741
+
742
+ local key = options.key
743
+ local order = normalizeOrder(options.order)
744
+ local entries = table.create(#list)
745
+
746
+ for index, item in list do
747
+ if type(item) == "table" then
748
+ entries[#entries + 1] = {
749
+ index = index,
750
+ value = item,
751
+ priority = item[key],
752
+ }
753
+ end
754
+ end
755
+
756
+ table.sort(entries, function(a, b)
757
+ local left = a.priority
758
+ local right = b.priority
759
+ if order == PackageEnum.OrderList.Desc then
760
+ return (left or 0) > (right or 0)
761
+ end
762
+ return (left or 0) < (right or 0)
763
+ end)
764
+
765
+ local limit = options.limit
766
+ if limit and limit < #entries then
767
+ local trimmed = table.create(limit)
768
+ for i = 1, limit do
769
+ trimmed[i] = entries[i]
770
+ end
771
+ return trimmed
772
+ end
773
+
774
+ return entries
775
+ end
776
+
777
+ --[=[
778
+ @method GetOrderedListWithPriority
779
+ @within Data
780
+ @tag Query
781
+ @param path PathToken
782
+ @param key string
783
+ @param order OrderedListOrder?
784
+ Shortcut for `GetOrderedList` sorted by one field. Default order: `Enum.OrderList.Desc`.
785
+ ]=]
786
+ function Data:GetOrderedListWithPriority(path: DataPathLike, key: string, order: OrderedListOrder?): { OrderedListEntry<any> }
787
+ return self:GetOrderedList(path, {
788
+ key = key,
789
+ order = order or PackageEnum.OrderList.Desc,
790
+ })
791
+ end
792
+
793
+ const ensureSignal = function(map: { [string]: SignalT }, key: string): SignalT
794
+ if not map[key] then
795
+ map[key] = Signal.new()
796
+ end
797
+ return map[key]
798
+ end
799
+
800
+ --[=[
801
+ @method GetChangedSignal
802
+ @within Data
803
+ @tag Signals
804
+ @param path PathToken
805
+ @return Signal
806
+ Fires when the merged value at path changes `(newValue, oldValue)`.
807
+ ]=]
808
+ function Data:GetChangedSignal<V>(path: TypedPath<V> | DataPathLike): ChangedSignal<V>
809
+ local normalized = normalizePath(path, false) :: DataPath
810
+ return ensureSignal(self[CHANGED_MAP_KEY], Path.toKey(normalized)) :: ChangedSignal<V>
811
+ end
812
+
813
+ --[=[
814
+ @method GetPathChangedSignal
815
+ @within Data
816
+ @tag Signals
817
+ Alias of `GetChangedSignal`.
818
+ ]=]
819
+ function Data:GetPathChangedSignal<V>(path: TypedPath<V> | DataPathLike): ChangedSignal<V>
820
+ return self:GetChangedSignal(path)
821
+ end
822
+
823
+ --[=[
824
+ @method GetIndexChangedSignal
825
+ @within Data
826
+ @tag Signals
827
+ Fires when a direct child changes `(key, newValue, oldValue)`.
828
+ ]=]
829
+ function Data:GetIndexChangedSignal<V>(path: TypedPath<V> | DataPathLike): IndexChangedSignal<V>
830
+ local normalized = normalizePath(path, false) :: DataPath
831
+ return ensureSignal(self[INDEX_CHANGED_MAP_KEY], Path.toKey(normalized)) :: IndexChangedSignal<V>
832
+ end
833
+
834
+ --[=[
835
+ @method GetArrayInsertedSignal
836
+ @within Data
837
+ @tag Signals
838
+ Fires when an item is inserted `(index, value)`.
839
+ ]=]
840
+ function Data:GetArrayInsertedSignal<V>(path: TypedPath<{ V }> | DataPathLike): ArrayInsertedSignal<V>
841
+ local normalized = normalizePath(path, false) :: DataPath
842
+ return ensureSignal(self[ARRAY_INSERTED_MAP_KEY], Path.toKey(normalized)) :: ArrayInsertedSignal<V>
843
+ end
844
+
845
+ --[=[
846
+ @method GetArrayRemovedSignal
847
+ @within Data
848
+ @tag Signals
849
+ Fires when an item is removed `(index, removedValue)`.
850
+ ]=]
851
+ function Data:GetArrayRemovedSignal<V>(path: TypedPath<{ V }> | DataPathLike): ArrayRemovedSignal<V>
852
+ local normalized = normalizePath(path, false) :: DataPath
853
+ return ensureSignal(self[ARRAY_REMOVED_MAP_KEY], Path.toKey(normalized)) :: ArrayRemovedSignal<V>
854
+ end
855
+
856
+ --[=[
857
+ @method Destroy
858
+ @within Data
859
+ @tag Lifecycle
860
+ Destroys internal signals and clears transient state.
861
+ ]=]
862
+ function Data:Destroy()
863
+ if self.Destroyed then
864
+ return
865
+ end
866
+ self.Destroyed = true
867
+ table.clear(self[TRANSIENT_KEY])
868
+ for _, s in self[CHANGED_MAP_KEY] do
869
+ s:Destroy()
870
+ end
871
+ for _, s in self[INDEX_CHANGED_MAP_KEY] do
872
+ s:Destroy()
873
+ end
874
+ for _, s in self[ARRAY_INSERTED_MAP_KEY] do
875
+ s:Destroy()
876
+ end
877
+ for _, s in self[ARRAY_REMOVED_MAP_KEY] do
878
+ s:Destroy()
879
+ end
880
+ self.Changed:Destroy()
881
+ end
882
+
883
+ return Data