@quenty/datastore 13.51.1 → 13.52.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.
@@ -0,0 +1,57 @@
1
+ --!strict
2
+ --[=[
3
+ Shared plumbing for the datastore Cmdr commands. Runs on both realms, so nothing here may reach
4
+ for a store -- those live on the server.
5
+
6
+ @class DataStoreCmdrUtils
7
+ ]=]
8
+
9
+ local DataStoreCmdrUtils = {}
10
+
11
+ --[=[
12
+ Splits a slash-delimited sub-store path into its segments, dropping empty ones so a stray or
13
+ trailing slash is forgiving rather than an error. An empty path means the root store.
14
+
15
+ @param text string
16
+ @return { string }
17
+ ]=]
18
+ function DataStoreCmdrUtils.parsePath(text: string): { string }
19
+ assert(type(text) == "string", "Bad text")
20
+
21
+ local path = {}
22
+ for segment in string.gmatch(text, "[^/]+") do
23
+ table.insert(path, segment)
24
+ end
25
+
26
+ return path
27
+ end
28
+
29
+ --[=[
30
+ Registers the sub-store path type.
31
+
32
+ Cmdr resolves types against the executor, who cannot see another player's stores, so a path is
33
+ accepted as typed rather than completed against anything.
34
+
35
+ @param cmdr Cmdr
36
+ ]=]
37
+ function DataStoreCmdrUtils.registerSubStoreType(cmdr: any): ()
38
+ local subStore = {
39
+ Transform = function(text: string)
40
+ if text ~= "" then
41
+ return { text }
42
+ end
43
+
44
+ return {}
45
+ end,
46
+ Validate = function(keys: { string })
47
+ return #keys > 0, "Not a sub-store path."
48
+ end,
49
+ Parse = function(keys: { string })
50
+ return DataStoreCmdrUtils.parsePath(keys[1])
51
+ end,
52
+ }
53
+
54
+ cmdr.Registry:RegisterType("dataStoreSubStore", subStore)
55
+ end
56
+
57
+ return DataStoreCmdrUtils