@quenty/valuebaseutils 13.17.0 → 13.17.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [13.17.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/valuebaseutils@13.17.0...@quenty/valuebaseutils@13.17.1) (2025-04-05)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Add types to packages ([2374fb2](https://github.com/Quenty/NevermoreEngine/commit/2374fb2b043cfbe0e9b507b3316eec46a4e353a0))
12
+
13
+
14
+
15
+
16
+
6
17
  # [13.17.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/valuebaseutils@13.16.2...@quenty/valuebaseutils@13.17.0) (2025-04-02)
7
18
 
8
19
  **Note:** Version bump only for package @quenty/valuebaseutils
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/valuebaseutils",
3
- "version": "13.17.0",
3
+ "version": "13.17.1",
4
4
  "description": "Provides utilities for working with valuesbase objects, like IntValue or ObjectValue in Roblox.",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -25,15 +25,15 @@
25
25
  "Quenty"
26
26
  ],
27
27
  "dependencies": {
28
- "@quenty/brio": "^14.17.0",
29
- "@quenty/instanceutils": "^13.17.0",
30
- "@quenty/loader": "^10.8.0",
31
- "@quenty/promise": "^10.10.1",
32
- "@quenty/rx": "^13.17.0",
33
- "@quenty/rxsignal": "^7.17.0"
28
+ "@quenty/brio": "^14.17.1",
29
+ "@quenty/instanceutils": "^13.17.1",
30
+ "@quenty/loader": "^10.8.1",
31
+ "@quenty/promise": "^10.10.2",
32
+ "@quenty/rx": "^13.17.1",
33
+ "@quenty/rxsignal": "^7.17.1"
34
34
  },
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "e8ea56930e65322fcffc05a1556d5df988068f0b"
38
+ "gitHead": "78c3ac0ab08dd18085b6e6e6e4f745e76ed99f68"
39
39
  }
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  @class RxValueBaseUtils
3
4
  ]=]
@@ -6,6 +7,8 @@ local require = require(script.Parent.loader).load(script)
6
7
 
7
8
  local RxInstanceUtils = require("RxInstanceUtils")
8
9
  local RxBrioUtils = require("RxBrioUtils")
10
+ local _Observable = require("Observable")
11
+ local _Brio = require("Brio")
9
12
 
10
13
  local RxValueBaseUtils = {}
11
14
 
@@ -18,19 +21,21 @@ local RxValueBaseUtils = {}
18
21
  @param predicate callback -- Optional callback
19
22
  @return Observable<Brio<any>>
20
23
  ]=]
21
- function RxValueBaseUtils.observeBrio(parent, className, name, predicate)
24
+ function RxValueBaseUtils.observeBrio(
25
+ parent: Instance,
26
+ className: string,
27
+ name: string,
28
+ predicate: ((any) -> boolean)?
29
+ ): _Observable.Observable<_Brio.Brio<any>>
22
30
  assert(typeof(parent) == "Instance", "Bad parent")
23
31
  assert(type(className) == "string", "Bad className")
24
32
  assert(type(name) == "string", "Bad naem")
25
33
 
26
- return RxInstanceUtils.observeLastNamedChildBrio(parent, className, name)
27
- :Pipe({
28
- RxBrioUtils.switchMapBrio(function(valueObject)
29
- return RxValueBaseUtils.observeValue(valueObject)
30
- end),
31
- RxBrioUtils.onlyLastBrioSurvives(),
32
- predicate and RxBrioUtils.where(predicate) or nil;
33
- })
34
+ return RxInstanceUtils.observeLastNamedChildBrio(parent, className, name):Pipe({
35
+ RxBrioUtils.switchMapBrio(RxValueBaseUtils.observeValue) :: any,
36
+ RxBrioUtils.onlyLastBrioSurvives() :: any,
37
+ if predicate then RxBrioUtils.where(predicate) else nil :: never,
38
+ }) :: any
34
39
  end
35
40
 
36
41
  --[=[
@@ -42,15 +47,19 @@ end
42
47
  @param defaultValue any
43
48
  @return Observable<any>
44
49
  ]=]
45
- function RxValueBaseUtils.observe(parent, className, name, defaultValue)
50
+ function RxValueBaseUtils.observe(
51
+ parent: Instance,
52
+ className: string,
53
+ name: string,
54
+ defaultValue: any?
55
+ ): _Observable.Observable<any>
46
56
  assert(typeof(parent) == "Instance", "Bad parent")
47
57
  assert(type(className) == "string", "Bad className")
48
58
  assert(type(name) == "string", "Bad name")
49
59
 
50
- return RxValueBaseUtils.observeBrio(parent, className, name)
51
- :Pipe({
52
- RxBrioUtils.emitOnDeath(defaultValue)
53
- })
60
+ return RxValueBaseUtils.observeBrio(parent, className, name):Pipe({
61
+ RxBrioUtils.emitOnDeath(defaultValue) :: any,
62
+ }) :: any
54
63
  end
55
64
 
56
65
 
@@ -59,7 +68,7 @@ end
59
68
  @param valueObject Instance
60
69
  @return Observable<T>
61
70
  ]=]
62
- function RxValueBaseUtils.observeValue(valueObject)
71
+ function RxValueBaseUtils.observeValue(valueObject): _Observable.Observable<any>
63
72
  assert(typeof(valueObject) == "Instance", "Bad valueObject")
64
73
 
65
74
  return RxInstanceUtils.observeProperty(valueObject, "Value")
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  Provides utilities for working with ValueBase objects, like [IntValue] or [ObjectValue] in Roblox.
3
4
 
@@ -7,39 +8,51 @@
7
8
  local ValueBaseUtils = {}
8
9
 
9
10
  local TYPE_TO_CLASSNAME_LOOKUP = {
10
- ["nil"] = "ObjectValue";
11
- boolean = "BoolValue";
12
- number = "NumberValue";
13
- string = "StringValue";
14
-
15
- BrickColor = "BrickColorValue";
16
- CFrame = "CFrameValue";
17
- Color3 = "Color3Value";
18
- Instance = "ObjectValue";
19
- Ray = "RayValue";
20
- Vector3 = "Vector3Value";
11
+ ["nil"] = "ObjectValue",
12
+ boolean = "BoolValue",
13
+ number = "NumberValue",
14
+ string = "StringValue",
15
+
16
+ BrickColor = "BrickColorValue",
17
+ CFrame = "CFrameValue",
18
+ Color3 = "Color3Value",
19
+ Instance = "ObjectValue",
20
+ Ray = "RayValue",
21
+ Vector3 = "Vector3Value",
21
22
  }
22
23
 
23
24
  local VALUE_BASE_TYPE_LOOKUP = {
24
- BoolValue = "boolean";
25
- NumberValue = "number";
26
- IntValue = "number";
27
- StringValue = "string";
28
- BrickColorValue = "BrickColor";
29
- CFrameValue = "CFrame";
30
- Color3Value = "Color3";
31
- ObjectValue = "Instance";
32
- RayValue = "Ray";
33
- Vector3Value = "Vector3";
25
+ BoolValue = "boolean",
26
+ NumberValue = "number",
27
+ IntValue = "number",
28
+ StringValue = "string",
29
+ BrickColorValue = "BrickColor",
30
+ CFrameValue = "CFrame",
31
+ Color3Value = "Color3",
32
+ ObjectValue = "Instance",
33
+ RayValue = "Ray",
34
+ Vector3Value = "Vector3",
34
35
  }
35
36
 
37
+ export type ValueBaseType =
38
+ "BoolValue"
39
+ | "NumberValue"
40
+ | "IntValue"
41
+ | "StringValue"
42
+ | "BrickColorValue"
43
+ | "CFrameValue"
44
+ | "Color3Value"
45
+ | "ObjectValue"
46
+ | "RayValue"
47
+ | "Vector3Value"
48
+
36
49
  --[=[
37
50
  Returns true if the value is a ValueBase instance
38
51
 
39
52
  @param instance Instance
40
53
  @return boolean
41
54
  ]=]
42
- function ValueBaseUtils.isValueBase(instance)
55
+ function ValueBaseUtils.isValueBase(instance: Instance): boolean
43
56
  return typeof(instance) == "Instance" and instance:IsA("ValueBase")
44
57
  end
45
58
 
@@ -49,7 +62,7 @@ end
49
62
  @param valueBaseClassName string
50
63
  @return string?
51
64
  ]=]
52
- function ValueBaseUtils.getValueBaseType(valueBaseClassName)
65
+ function ValueBaseUtils.getValueBaseType(valueBaseClassName: ValueBaseType): string?
53
66
  return VALUE_BASE_TYPE_LOOKUP[valueBaseClassName]
54
67
  end
55
68
 
@@ -59,7 +72,7 @@ end
59
72
  @param luaType string
60
73
  @return string?
61
74
  ]=]
62
- function ValueBaseUtils.getClassNameFromType(luaType)
75
+ function ValueBaseUtils.getClassNameFromType(luaType: string): string?
63
76
  return TYPE_TO_CLASSNAME_LOOKUP[luaType]
64
77
  end
65
78
 
@@ -72,7 +85,12 @@ end
72
85
  @param defaultValue any?
73
86
  @return Instance
74
87
  ]=]
75
- function ValueBaseUtils.getOrCreateValue(parent, instanceType, name, defaultValue)
88
+ function ValueBaseUtils.getOrCreateValue(
89
+ parent: Instance,
90
+ instanceType: ValueBaseType,
91
+ name: string,
92
+ defaultValue
93
+ ): Instance
76
94
  assert(typeof(parent) == "Instance", "Bad argument 'parent'")
77
95
  assert(type(instanceType) == "string", "Bad argument 'instanceType'")
78
96
  assert(type(name) == "string", "Bad argument 'name'")
@@ -80,12 +98,20 @@ function ValueBaseUtils.getOrCreateValue(parent, instanceType, name, defaultValu
80
98
  local foundChild = parent:FindFirstChild(name)
81
99
  if foundChild then
82
100
  if not foundChild:IsA(instanceType) then
83
- warn(string.format("[ValueBaseUtils.getOrCreateValue] - Value of type %q of name %q is of type %q in %s instead", instanceType, name, foundChild.ClassName, foundChild:GetFullName()))
101
+ warn(
102
+ string.format(
103
+ "[ValueBaseUtils.getOrCreateValue] - Value of type %q of name %q is of type %q in %s instead",
104
+ instanceType,
105
+ name,
106
+ foundChild.ClassName,
107
+ foundChild:GetFullName()
108
+ )
109
+ )
84
110
  end
85
111
 
86
112
  return foundChild
87
113
  else
88
- local newChild = Instance.new(instanceType)
114
+ local newChild: any = Instance.new(instanceType)
89
115
  newChild.Name = name
90
116
  newChild.Value = defaultValue
91
117
  newChild.Parent = parent
@@ -103,7 +129,7 @@ end
103
129
  @param value any
104
130
  @return any
105
131
  ]=]
106
- function ValueBaseUtils.setValue(parent, instanceType, name, value)
132
+ function ValueBaseUtils.setValue(parent: Instance, instanceType: ValueBaseType, name: string, value: any)
107
133
  assert(typeof(parent) == "Instance", "Bad argument 'parent'")
108
134
  assert(type(instanceType) == "string", "Bad argument 'instanceType'")
109
135
  assert(type(name) == "string", "Bad argument 'name'")
@@ -111,12 +137,20 @@ function ValueBaseUtils.setValue(parent, instanceType, name, value)
111
137
  local foundChild = parent:FindFirstChild(name)
112
138
  if foundChild then
113
139
  if not foundChild:IsA(instanceType) then
114
- warn(string.format("[ValueBaseUtils.setValue] - Value of type %q of name %q is of type %q in %s instead", instanceType, name, foundChild.ClassName, foundChild:GetFullName()))
140
+ warn(
141
+ string.format(
142
+ "[ValueBaseUtils.setValue] - Value of type %q of name %q is of type %q in %s instead",
143
+ instanceType,
144
+ name,
145
+ foundChild.ClassName,
146
+ foundChild:GetFullName()
147
+ )
148
+ )
115
149
  end
116
150
 
117
- foundChild.Value = value
151
+ (foundChild :: any).Value = value
118
152
  else
119
- local newChild = Instance.new(instanceType)
153
+ local newChild: any = Instance.new(instanceType)
120
154
  newChild.Name = name
121
155
  newChild.Value = value
122
156
  newChild.Parent = parent
@@ -132,7 +166,7 @@ end
132
166
  @param default any?
133
167
  @return any
134
168
  ]=]
135
- function ValueBaseUtils.getValue(parent, instanceType, name, default)
169
+ function ValueBaseUtils.getValue(parent: Instance, instanceType: ValueBaseType, name: string, default: any?)
136
170
  assert(typeof(parent) == "Instance", "Bad argument 'parent'")
137
171
  assert(type(instanceType) == "string", "Bad argument 'instanceType'")
138
172
  assert(type(name) == "string", "Bad argument 'name'")
@@ -140,9 +174,17 @@ function ValueBaseUtils.getValue(parent, instanceType, name, default)
140
174
  local foundChild = parent:FindFirstChild(name)
141
175
  if foundChild then
142
176
  if foundChild:IsA(instanceType) then
143
- return foundChild.Value
177
+ return (foundChild :: any).Value
144
178
  else
145
- warn(string.format("[ValueBaseUtils.getValue] - Value of type %q of name %q is of type %q in %s instead", instanceType, name, foundChild.ClassName, foundChild:GetFullName()))
179
+ warn(
180
+ string.format(
181
+ "[ValueBaseUtils.getValue] - Value of type %q of name %q is of type %q in %s instead",
182
+ instanceType,
183
+ name,
184
+ foundChild.ClassName,
185
+ foundChild:GetFullName()
186
+ )
187
+ )
146
188
  return nil
147
189
  end
148
190
  else
@@ -159,7 +201,7 @@ end
159
201
  @return function
160
202
  @return function
161
203
  ]=]
162
- function ValueBaseUtils.createGetSet(instanceType, name)
204
+ function ValueBaseUtils.createGetSet(instanceType: ValueBaseType, name: string)
163
205
  assert(type(instanceType) == "string", "Bad argument 'instanceType'")
164
206
  assert(type(name) == "string", "Bad argument 'name'")
165
207
 
@@ -12,12 +12,41 @@ local Rx = require("Rx")
12
12
  local RxSignal = require("RxSignal")
13
13
  local RxValueBaseUtils = require("RxValueBaseUtils")
14
14
  local ValueBaseUtils = require("ValueBaseUtils")
15
+ local _Observable = require("Observable")
16
+ local _Brio = require("Brio")
15
17
 
16
18
  local ValueBaseValue = {}
17
19
  ValueBaseValue.ClassName = "ValueBaseValue"
18
20
  ValueBaseValue.__index = ValueBaseValue
19
21
 
20
- function ValueBaseValue.new(parent, className, name, defaultValue)
22
+ export type ValueBaseValue = typeof(setmetatable(
23
+ {} :: {
24
+ _parent: Instance,
25
+ _className: ValueBaseUtils.ValueBaseType,
26
+ _name: string,
27
+ _defaultValue: any?,
28
+ Value: any?,
29
+ Changed: RxSignal.RxSignal<any>,
30
+ },
31
+ ValueBaseValue
32
+ ))
33
+
34
+ --[=[
35
+ Constructs a ValueBaseValue object. This is a wrapper around the value base
36
+ underneath the parent. It will create the value base if it does not exist.
37
+
38
+ @param parent Instance
39
+ @param className string
40
+ @param name string
41
+ @param defaultValue any?
42
+ @return ValueBaseValue
43
+ ]=]
44
+ function ValueBaseValue.new(
45
+ parent: Instance,
46
+ className: ValueBaseUtils.ValueBaseType,
47
+ name: string,
48
+ defaultValue: any?
49
+ ): ValueBaseValue
21
50
  assert(typeof(parent) == "Instance", "Bad argument 'parent'")
22
51
  assert(type(className) == "string", "Bad argument 'className'")
23
52
  assert(type(name) == "string", "Bad argument 'name'")
@@ -34,23 +63,38 @@ function ValueBaseValue.new(parent, className, name, defaultValue)
34
63
  ValueBaseUtils.getOrCreateValue(parent, self._className, self._name, self._defaultValue)
35
64
  end
36
65
 
37
- return setmetatable(self, ValueBaseValue)
66
+ return setmetatable(self, ValueBaseValue) :: any
38
67
  end
39
68
 
40
- function ValueBaseValue:ObserveBrio(predicate)
69
+ --[=[
70
+ Observes the value base value. This will return a brio of the value base
71
+ underneath the parent.
72
+
73
+ @param predicate ((any) -> boolean)? -- Optional callback
74
+ @return Observable<Brio<any>>
75
+ ]=]
76
+ function ValueBaseValue.ObserveBrio(
77
+ self: ValueBaseValue,
78
+ predicate: Rx.Predicate<any>?
79
+ ): _Observable.Observable<_Brio.Brio<any>>
41
80
  return RxValueBaseUtils.observeBrio(self._parent, self._className, self._name, predicate)
42
81
  end
43
82
 
44
- function ValueBaseValue:Observe()
83
+ --[=[
84
+ Observes the value base value's
85
+
86
+ @return Observable<any>
87
+ ]=]
88
+ function ValueBaseValue.Observe(self: ValueBaseValue): _Observable.Observable<any>
45
89
  return RxValueBaseUtils.observe(self._parent, self._className, self._name, self._defaultValue)
46
90
  end
47
91
 
48
- function ValueBaseValue:__index(index)
92
+ (ValueBaseValue :: any).__index = function(self: any, index)
49
93
  if index == "Value" then
50
94
  return ValueBaseUtils.getValue(self._parent, self._className, self._name, self._defaultValue)
51
95
  elseif index == "Changed" then
52
96
  return RxSignal.new(self:Observe():Pipe({
53
- Rx.skip(1)
97
+ Rx.skip(1),
54
98
  }))
55
99
  elseif ValueBaseValue[index] or index == "_defaultValue" then
56
100
  return ValueBaseValue[index]
@@ -59,7 +103,7 @@ function ValueBaseValue:__index(index)
59
103
  end
60
104
  end
61
105
 
62
- function ValueBaseValue:__newindex(index, value)
106
+ function ValueBaseValue.__newindex(self: ValueBaseValue, index, value)
63
107
  if index == "Value" then
64
108
  ValueBaseUtils.setValue(self._parent, self._className, self._name, value)
65
109
  else