@rbxts/scribe 2.5.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 (56) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +21 -0
  3. package/README.md +100 -0
  4. package/Scribe-source-map.json +1 -0
  5. package/licenses/ProfileStore-Apache-2.0.txt +201 -0
  6. package/package.json +32 -0
  7. package/src/Client/DebugHook.luau +457 -0
  8. package/src/Client/init.luau +1607 -0
  9. package/src/Internal/Addons.luau +68 -0
  10. package/src/Internal/Big.luau +582 -0
  11. package/src/Internal/Budget.luau +377 -0
  12. package/src/Internal/Clock.luau +75 -0
  13. package/src/Internal/Config.luau +17 -0
  14. package/src/Internal/Conform.luau +400 -0
  15. package/src/Internal/Datatypes.luau +653 -0
  16. package/src/Internal/Defaults.luau +12 -0
  17. package/src/Internal/Derived.luau +428 -0
  18. package/src/Internal/Exchange.luau +556 -0
  19. package/src/Internal/ExchangeLeg.luau +1368 -0
  20. package/src/Internal/ExchangeVerdict.luau +179 -0
  21. package/src/Internal/Failure.luau +148 -0
  22. package/src/Internal/Health.luau +320 -0
  23. package/src/Internal/LeaderboardDiagnostics.luau +36 -0
  24. package/src/Internal/Log.luau +378 -0
  25. package/src/Internal/Marker.luau +76 -0
  26. package/src/Internal/Metrics.luau +152 -0
  27. package/src/Internal/Node.luau +3954 -0
  28. package/src/Internal/Profile.luau +69 -0
  29. package/src/Internal/Rng.luau +83 -0
  30. package/src/Internal/Sched.luau +56 -0
  31. package/src/Internal/Signal.luau +199 -0
  32. package/src/Internal/Store/ProfileStore.luau +3019 -0
  33. package/src/Internal/Store/init.luau +18 -0
  34. package/src/Internal/StudioCodec.luau +155 -0
  35. package/src/Internal/Template.luau +1848 -0
  36. package/src/Internal/Transport.luau +169 -0
  37. package/src/Internal/Util.luau +517 -0
  38. package/src/Internal/Version.luau +4 -0
  39. package/src/Internal/Wire.luau +1283 -0
  40. package/src/Server/Analytics.luau +223 -0
  41. package/src/Server/Commands.luau +728 -0
  42. package/src/Server/DebugHook.luau +1490 -0
  43. package/src/Server/Exchanges.luau +737 -0
  44. package/src/Server/Leaderboards.luau +2143 -0
  45. package/src/Server/Monetization.luau +3212 -0
  46. package/src/Server/Persistence.luau +3775 -0
  47. package/src/Server/Replication.luau +1253 -0
  48. package/src/Server/ServerStore.luau +81 -0
  49. package/src/Server/Timed.luau +579 -0
  50. package/src/Server/init.luau +672 -0
  51. package/src/Types.luau +480 -0
  52. package/src/init.luau +2231 -0
  53. package/types/api.d.ts +252 -0
  54. package/types/common.d.ts +355 -0
  55. package/types/index.d.ts +226 -0
  56. package/types/schema.d.ts +276 -0
@@ -0,0 +1,18 @@
1
+ --!strict
2
+ -- Scribe's session/profile store: a vendored fork of ProfileStore v1.0.3, additive only.
3
+ -- The lock (ForceLoadSession, the steal ladder, ASSUME_DEAD, the MessagingService
4
+ -- release, the record shape) and the stored key are byte-identical to upstream, so a
5
+ -- fleet can run mixed versions and roll back without a migration.
6
+ --
7
+ -- Added: `Profile:SaveAwait()`, an answer for one call where upstream Save() is
8
+ -- fire-and-forget (Saved is the only outcome meaning the data is on disk; NotOwned is a
9
+ -- round trip whose transform declined to write); `UpdateOfflineAsync`, a compare-and-set
10
+ -- for an absent player; and `BeginClose`/`AwaitClose`, so the owner drives shutdown order.
11
+
12
+ export type SaveOutcome = "Saved" | "NotOwned" | "Failed"
13
+
14
+ -- The vendored body is `--!nocheck` and untyped; this is the one place that casts,
15
+ -- so callers get the type above rather than `any`.
16
+ local Store = require(script.ProfileStore) :: any
17
+
18
+ return Store
@@ -0,0 +1,155 @@
1
+ --!strict
2
+ -- Studio debug-hook codec: a self-describing, length-prefixed text encoding for
3
+ -- arbitrary Luau data tables crossing the plugin/game VM boundary. Carries
4
+ -- string/number/boolean/nil/buffer values under string/number keys, including the
5
+ -- mixed and sparse tables neither JSON nor cross-VM reflection can carry.
6
+ --
7
+ -- Shared by Server/DebugHook.luau and Client/DebugHook.luau, byte-compatible with the
8
+ -- Studio plugin's copy (src/Codec.luau) and versioned by the hooks'
9
+ -- PROTOCOL_VERSIONs; change together.
10
+
11
+ local StudioCodec = {}
12
+
13
+ local function encodeNumber(n: number): string
14
+ if n ~= n then
15
+ return "N!"
16
+ elseif n == math.huge then
17
+ return "N+"
18
+ elseif n == -math.huge then
19
+ -- A "-" sentinel would collide with negative number literals.
20
+ return "N~"
21
+ elseif n % 1 == 0 and math.abs(n) < 2 ^ 53 then
22
+ return `I{n};`
23
+ end
24
+ return `N{string.format("%.17g", n)};`
25
+ end
26
+
27
+ local function encodeValue(out: { string }, value: any, depth: number)
28
+ if depth > 32 then
29
+ error("Scribe: value too deep to encode")
30
+ end
31
+ local t = type(value)
32
+ if value == nil then
33
+ table.insert(out, "z")
34
+ elseif t == "boolean" then
35
+ table.insert(out, if value then "T" else "F")
36
+ elseif t == "number" then
37
+ table.insert(out, encodeNumber(value))
38
+ elseif t == "string" then
39
+ table.insert(out, `S{#value}:`)
40
+ table.insert(out, value)
41
+ elseif t == "buffer" then
42
+ local bytes = buffer.tostring(value)
43
+ table.insert(out, `B{#bytes}:`)
44
+ table.insert(out, bytes)
45
+ elseif t == "table" then
46
+ local count = 0
47
+ for _ in value do
48
+ count += 1
49
+ end
50
+ table.insert(out, `t{count}:`)
51
+ for k, v in value do
52
+ local kt = type(k)
53
+ if kt == "string" then
54
+ table.insert(out, `S{#k}:`)
55
+ table.insert(out, k)
56
+ elseif kt == "number" then
57
+ table.insert(out, encodeNumber(k))
58
+ else
59
+ table.insert(out, "S9:<badkey?>")
60
+ end
61
+ encodeValue(out, v, depth + 1)
62
+ end
63
+ else
64
+ local s = tostring(value)
65
+ table.insert(out, `S{#s}:`)
66
+ table.insert(out, s)
67
+ end
68
+ end
69
+
70
+ function StudioCodec.Encode(value: any): string
71
+ local out: { string } = {}
72
+ encodeValue(out, value, 0)
73
+ return table.concat(out)
74
+ end
75
+
76
+ type Cursor = { s: string, pos: number }
77
+
78
+ local function decodeValue(cur: Cursor, depth: number): any
79
+ if depth > 34 then
80
+ error("Scribe: encoded value too deep")
81
+ end
82
+ local s = cur.s
83
+ local tag = string.sub(s, cur.pos, cur.pos)
84
+ cur.pos += 1
85
+ if tag == "z" then
86
+ return nil
87
+ elseif tag == "T" then
88
+ return true
89
+ elseif tag == "F" then
90
+ return false
91
+ elseif tag == "N" or tag == "I" then
92
+ local head = string.sub(s, cur.pos, cur.pos)
93
+ if tag == "N" and head == "!" then
94
+ cur.pos += 1
95
+ return 0 / 0
96
+ elseif tag == "N" and head == "+" then
97
+ cur.pos += 1
98
+ return math.huge
99
+ elseif tag == "N" and head == "~" then
100
+ cur.pos += 1
101
+ return -math.huge
102
+ end
103
+ local stop = string.find(s, ";", cur.pos, true)
104
+ if not stop then
105
+ error("Scribe: malformed number")
106
+ end
107
+ local n = tonumber(string.sub(s, cur.pos, stop - 1))
108
+ if n == nil then
109
+ error("Scribe: malformed number")
110
+ end
111
+ cur.pos = stop + 1
112
+ return n
113
+ elseif tag == "S" or tag == "B" then
114
+ local stop = string.find(s, ":", cur.pos, true)
115
+ if not stop then
116
+ error("Scribe: malformed string")
117
+ end
118
+ local len = tonumber(string.sub(s, cur.pos, stop - 1))
119
+ if len == nil or len < 0 then
120
+ error("Scribe: malformed string length")
121
+ end
122
+ local value = string.sub(s, stop + 1, stop + len)
123
+ cur.pos = stop + 1 + len
124
+ if tag == "B" then
125
+ return buffer.fromstring(value)
126
+ end
127
+ return value
128
+ elseif tag == "t" then
129
+ local stop = string.find(s, ":", cur.pos, true)
130
+ if not stop then
131
+ error("Scribe: malformed table")
132
+ end
133
+ local count = tonumber(string.sub(s, cur.pos, stop - 1))
134
+ if count == nil then
135
+ error("Scribe: malformed table count")
136
+ end
137
+ cur.pos = stop + 1
138
+ local out = {}
139
+ for _ = 1, count do
140
+ local key = decodeValue(cur, depth + 1)
141
+ local value = decodeValue(cur, depth + 1)
142
+ if key ~= nil then
143
+ out[key] = value
144
+ end
145
+ end
146
+ return out
147
+ end
148
+ error(`Scribe: unknown codec tag "{tag}"`)
149
+ end
150
+
151
+ function StudioCodec.Decode(encoded: string): any
152
+ return decodeValue({ s = encoded, pos = 1 }, 0)
153
+ end
154
+
155
+ return StudioCodec