@quenty/datastore 8.0.0-canary.331.7eefa75.0 → 8.0.0-canary.367.e9fdcbc.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.
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,95 @@
|
|
|
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
|
-
# [8.0.0-canary.
|
|
6
|
+
# [8.0.0-canary.367.e9fdcbc.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@7.15.0...@quenty/datastore@8.0.0-canary.367.e9fdcbc.0) (2023-06-05)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @quenty/datastore
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [7.15.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@7.14.0...@quenty/datastore@7.15.0) (2023-05-26)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @quenty/datastore
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# [7.14.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@7.13.0...@quenty/datastore@7.14.0) (2023-05-08)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @quenty/datastore
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# [7.13.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@7.12.1...@quenty/datastore@7.13.0) (2023-04-10)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @quenty/datastore
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## [7.12.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@7.12.0...@quenty/datastore@7.12.1) (2023-04-07)
|
|
39
|
+
|
|
40
|
+
**Note:** Version bump only for package @quenty/datastore
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# [7.12.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@7.11.0...@quenty/datastore@7.12.0) (2023-04-06)
|
|
47
|
+
|
|
48
|
+
**Note:** Version bump only for package @quenty/datastore
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
# [7.11.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@7.10.0...@quenty/datastore@7.11.0) (2023-04-03)
|
|
55
|
+
|
|
56
|
+
**Note:** Version bump only for package @quenty/datastore
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
# [7.10.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@7.9.0...@quenty/datastore@7.10.0) (2023-03-31)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
### Bug Fixes
|
|
66
|
+
|
|
67
|
+
* Fix removing callback from DataStore when it would previously error ([fae393c](https://github.com/Quenty/NevermoreEngine/commit/fae393c6984de2fb5961e5047894a782721d772d))
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
### Features
|
|
71
|
+
|
|
72
|
+
* Add DataStoreStage:Observe(), DataStoreStage:PromiseKeyList(), DataStoreStage:PromiseKeySet(), DataStoreStage:LoadAll() API surfaces ([2969478](https://github.com/Quenty/NevermoreEngine/commit/29694788ce765fc30cfd8c80571e7d7172176051))
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# [7.9.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@7.8.0...@quenty/datastore@7.9.0) (2023-03-06)
|
|
79
|
+
|
|
80
|
+
**Note:** Version bump only for package @quenty/datastore
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# [7.8.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@7.7.0...@quenty/datastore@7.8.0) (2023-03-05)
|
|
87
|
+
|
|
88
|
+
**Note:** Version bump only for package @quenty/datastore
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
# [7.7.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@7.6.0...@quenty/datastore@7.7.0) (2023-02-27)
|
|
7
95
|
|
|
8
96
|
**Note:** Version bump only for package @quenty/datastore
|
|
9
97
|
|
package/LICENSE.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/datastore",
|
|
3
|
-
"version": "8.0.0-canary.
|
|
3
|
+
"version": "8.0.0-canary.367.e9fdcbc.0",
|
|
4
4
|
"description": "Quenty's Datastore implementation for Roblox",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -26,17 +26,18 @@
|
|
|
26
26
|
"Quenty"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@quenty/baseobject": "6.1
|
|
30
|
-
"@quenty/bindtocloseservice": "3.0.0-canary.
|
|
31
|
-
"@quenty/loader": "6.1
|
|
32
|
-
"@quenty/maid": "2.
|
|
33
|
-
"@quenty/promise": "
|
|
34
|
-
"@quenty/
|
|
29
|
+
"@quenty/baseobject": "6.2.1",
|
|
30
|
+
"@quenty/bindtocloseservice": "3.0.0-canary.367.e9fdcbc.0",
|
|
31
|
+
"@quenty/loader": "6.2.1",
|
|
32
|
+
"@quenty/maid": "2.5.0",
|
|
33
|
+
"@quenty/promise": "6.5.0",
|
|
34
|
+
"@quenty/rx": "7.11.0",
|
|
35
|
+
"@quenty/signal": "2.4.0",
|
|
35
36
|
"@quenty/symbol": "2.2.0",
|
|
36
37
|
"@quenty/table": "3.2.0"
|
|
37
38
|
},
|
|
38
39
|
"publishConfig": {
|
|
39
40
|
"access": "public"
|
|
40
41
|
},
|
|
41
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "e9fdcbc6ea1d46e068bf42a08b833099e9005259"
|
|
42
43
|
}
|
|
@@ -18,6 +18,8 @@ local Promise = require("Promise")
|
|
|
18
18
|
local PromiseUtils = require("PromiseUtils")
|
|
19
19
|
local Signal = require("Signal")
|
|
20
20
|
local Table = require("Table")
|
|
21
|
+
local Observable = require("Observable")
|
|
22
|
+
local ObservableSubscriptionTable = require("ObservableSubscriptionTable")
|
|
21
23
|
|
|
22
24
|
local DataStoreStage = setmetatable({}, BaseObject)
|
|
23
25
|
DataStoreStage.ClassName = "DataStoreStage"
|
|
@@ -41,6 +43,9 @@ function DataStoreStage.new(loadName, loadParent)
|
|
|
41
43
|
self._takenKeys = {} -- [name] = true
|
|
42
44
|
self._stores = {} -- [name] = dataSubStore
|
|
43
45
|
|
|
46
|
+
self._subsTable = ObservableSubscriptionTable.new()
|
|
47
|
+
self._maid:GiveTask(self._subsTable)
|
|
48
|
+
|
|
44
49
|
return self
|
|
45
50
|
end
|
|
46
51
|
|
|
@@ -79,7 +84,9 @@ function DataStoreStage:AddSavingCallback(callback)
|
|
|
79
84
|
table.insert(self._savingCallbacks, callback)
|
|
80
85
|
|
|
81
86
|
return function()
|
|
82
|
-
self
|
|
87
|
+
if self.Destroy then
|
|
88
|
+
self:RemoveSavingCallback(callback)
|
|
89
|
+
end
|
|
83
90
|
end
|
|
84
91
|
end
|
|
85
92
|
|
|
@@ -124,17 +131,13 @@ end
|
|
|
124
131
|
|
|
125
132
|
--[=[
|
|
126
133
|
Loads the data at the `name`.
|
|
127
|
-
|
|
134
|
+
|
|
135
|
+
@param name string | number
|
|
128
136
|
@param defaultValue T?
|
|
129
137
|
@return Promise<T>
|
|
130
138
|
]=]
|
|
131
139
|
function DataStoreStage:Load(name, defaultValue)
|
|
132
|
-
|
|
133
|
-
error("[DataStoreStage.Load] - Failed to load, no loadParent!")
|
|
134
|
-
end
|
|
135
|
-
if not self._loadName then
|
|
136
|
-
error("[DataStoreStage.Load] - Failed to load, no loadName!")
|
|
137
|
-
end
|
|
140
|
+
assert(type(name) == "string" or type(name) == "number", "Bad name")
|
|
138
141
|
|
|
139
142
|
if self._dataToSave and self._dataToSave[name] ~= nil then
|
|
140
143
|
if self._dataToSave[name] == DataStoreDeleteToken then
|
|
@@ -144,13 +147,42 @@ function DataStoreStage:Load(name, defaultValue)
|
|
|
144
147
|
end
|
|
145
148
|
end
|
|
146
149
|
|
|
147
|
-
return self
|
|
150
|
+
return self:_promiseLoadParentContent():Then(function(data)
|
|
148
151
|
return self:_afterLoadGetAndApplyStagedData(name, data, defaultValue)
|
|
149
152
|
end)
|
|
150
153
|
end
|
|
151
154
|
|
|
155
|
+
--[=[
|
|
156
|
+
Observes the current value for the stage itself
|
|
157
|
+
|
|
158
|
+
@param name string | number
|
|
159
|
+
@param defaultValue T?
|
|
160
|
+
@return Observable<T>
|
|
161
|
+
]=]
|
|
162
|
+
function DataStoreStage:Observe(name, defaultValue)
|
|
163
|
+
assert(type(name) == "string" or type(name) == "number", "Bad name")
|
|
164
|
+
|
|
165
|
+
return Observable.new(function(sub)
|
|
166
|
+
local maid = Maid.new()
|
|
167
|
+
|
|
168
|
+
maid:GiveTask(self._subsTable:Observe(name):Subscribe(sub:GetFireFailComplete()))
|
|
169
|
+
|
|
170
|
+
-- Load initially
|
|
171
|
+
maid:GivePromise(self:Load(name, defaultValue))
|
|
172
|
+
:Then(function(value)
|
|
173
|
+
sub:Fire(value)
|
|
174
|
+
end, function(...)
|
|
175
|
+
sub:Fail(...)
|
|
176
|
+
end)
|
|
177
|
+
|
|
178
|
+
return maid
|
|
179
|
+
end)
|
|
180
|
+
end
|
|
181
|
+
|
|
152
182
|
-- Protected!
|
|
153
183
|
function DataStoreStage:_afterLoadGetAndApplyStagedData(name, data, defaultValue)
|
|
184
|
+
assert(type(name) == "string" or type(name) == "number", "Bad name")
|
|
185
|
+
|
|
154
186
|
if self._dataToSave and self._dataToSave[name] ~= nil then
|
|
155
187
|
if self._dataToSave[name] == DataStoreDeleteToken then
|
|
156
188
|
return defaultValue
|
|
@@ -175,9 +207,12 @@ end
|
|
|
175
207
|
|
|
176
208
|
--[=[
|
|
177
209
|
Explicitely deletes data at the key
|
|
178
|
-
|
|
210
|
+
|
|
211
|
+
@param name string | number
|
|
179
212
|
]=]
|
|
180
213
|
function DataStoreStage:Delete(name)
|
|
214
|
+
assert(type(name) == "string", "Bad name")
|
|
215
|
+
|
|
181
216
|
if self._takenKeys[name] then
|
|
182
217
|
error(("[DataStoreStage] - Already have a writer for %q"):format(name))
|
|
183
218
|
end
|
|
@@ -201,7 +236,120 @@ function DataStoreStage:Wipe()
|
|
|
201
236
|
end)
|
|
202
237
|
end
|
|
203
238
|
|
|
239
|
+
--[=[
|
|
240
|
+
Promises a list of keys in the data store stage
|
|
241
|
+
|
|
242
|
+
@return Promise<{ string }>
|
|
243
|
+
]=]
|
|
244
|
+
function DataStoreStage:PromiseKeyList()
|
|
245
|
+
return self:PromiseKeySet()
|
|
246
|
+
:Then(function(keys)
|
|
247
|
+
local list = {}
|
|
248
|
+
for key, _ in pairs(keys) do
|
|
249
|
+
table.insert(list, key)
|
|
250
|
+
end
|
|
251
|
+
return list
|
|
252
|
+
end)
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
--[=[
|
|
256
|
+
Promises a set of keys in the data store stage
|
|
257
|
+
|
|
258
|
+
@return Promise<{ [string]: true }>
|
|
259
|
+
]=]
|
|
260
|
+
function DataStoreStage:PromiseKeySet()
|
|
261
|
+
return self:_promiseLoadParentContent():Then(function(data)
|
|
262
|
+
local keySet = {}
|
|
263
|
+
|
|
264
|
+
for key, value in pairs(data) do
|
|
265
|
+
if value ~= DataStoreDeleteToken then
|
|
266
|
+
keySet[key] = true
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
if self._dataToSave then
|
|
271
|
+
for key, value in pairs(self._dataToSave) do
|
|
272
|
+
if value ~= DataStoreDeleteToken then
|
|
273
|
+
keySet[key] = true
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
-- Otherwise we assume previous data would have it
|
|
279
|
+
for key, store in pairs(self._stores) do
|
|
280
|
+
if store:HasWritableData() then
|
|
281
|
+
keySet[key] = true
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
return keySet
|
|
286
|
+
end)
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
--[=[
|
|
290
|
+
Promises the full content for the datastore
|
|
291
|
+
|
|
292
|
+
@return Promise<any>
|
|
293
|
+
]=]
|
|
294
|
+
function DataStoreStage:LoadAll()
|
|
295
|
+
return self:_promiseLoadParentContent():Then(function(data)
|
|
296
|
+
local result = {}
|
|
297
|
+
|
|
298
|
+
for key, value in pairs(data) do
|
|
299
|
+
if value == DataStoreDeleteToken then
|
|
300
|
+
result[key] = nil
|
|
301
|
+
elseif type(value) == "table" then
|
|
302
|
+
result[key] = Table.deepCopy(value)
|
|
303
|
+
else
|
|
304
|
+
result[key] = value
|
|
305
|
+
end
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
if self._dataToSave then
|
|
309
|
+
for key, value in pairs(self._dataToSave) do
|
|
310
|
+
if value == DataStoreDeleteToken then
|
|
311
|
+
result[key] = nil
|
|
312
|
+
elseif type(value) == "table" then
|
|
313
|
+
result[key] = Table.deepCopy(value)
|
|
314
|
+
else
|
|
315
|
+
result[key] = value
|
|
316
|
+
end
|
|
317
|
+
end
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
for key, store in pairs(self._stores) do
|
|
321
|
+
if store:HasWritableData() then
|
|
322
|
+
local writer = store:GetNewWriter()
|
|
323
|
+
local original = Table.deepCopy(result[key] or {})
|
|
324
|
+
writer:WriteMerge(original)
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
return result
|
|
329
|
+
end)
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
function DataStoreStage:_promiseLoadParentContent()
|
|
333
|
+
if not self._loadParent then
|
|
334
|
+
error("[DataStoreStage.Load] - Failed to load, no loadParent!")
|
|
335
|
+
end
|
|
336
|
+
if not self._loadName then
|
|
337
|
+
error("[DataStoreStage.Load] - Failed to load, no loadName!")
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
return self._loadParent:Load(self._loadName, {})
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
--[=[
|
|
344
|
+
Stores the value, firing off events and queuing the item
|
|
345
|
+
for save.
|
|
346
|
+
|
|
347
|
+
@param name string | number
|
|
348
|
+
@param value string
|
|
349
|
+
]=]
|
|
204
350
|
function DataStoreStage:Store(name, value)
|
|
351
|
+
assert(type(name) == "string", "Bad name")
|
|
352
|
+
|
|
205
353
|
if self._takenKeys[name] then
|
|
206
354
|
error(("[DataStoreStage] - Already have a writer for %q"):format(name))
|
|
207
355
|
end
|
|
@@ -215,11 +363,12 @@ end
|
|
|
215
363
|
|
|
216
364
|
--[=[
|
|
217
365
|
Gets a sub-datastore that will write at the given name point
|
|
218
|
-
|
|
366
|
+
|
|
367
|
+
@param name string | number
|
|
219
368
|
@return DataStoreStage
|
|
220
369
|
]=]
|
|
221
370
|
function DataStoreStage:GetSubStore(name)
|
|
222
|
-
assert(type(name) == "string", "Bad name")
|
|
371
|
+
assert(type(name) == "string" or type(name) == "number", "Bad name")
|
|
223
372
|
|
|
224
373
|
if self._stores[name] then
|
|
225
374
|
return self._stores[name]
|
|
@@ -240,12 +389,13 @@ end
|
|
|
240
389
|
|
|
241
390
|
--[=[
|
|
242
391
|
Whenever the ValueObject changes, stores the resulting value in that entry.
|
|
243
|
-
|
|
392
|
+
|
|
393
|
+
@param name string | number
|
|
244
394
|
@param valueObj Instance -- ValueBase object to store on
|
|
245
395
|
@return MaidTask -- Cleanup to remove this writer and free the key.
|
|
246
396
|
]=]
|
|
247
397
|
function DataStoreStage:StoreOnValueChange(name, valueObj)
|
|
248
|
-
assert(type(name) == "string", "Bad name")
|
|
398
|
+
assert(type(name) == "string" or type(name) == "number", "Bad name")
|
|
249
399
|
assert(typeof(valueObj) == "Instance" or (type(valueObj) == "table" and valueObj.Changed), "Bad valueObj")
|
|
250
400
|
|
|
251
401
|
if self._takenKeys[name] then
|
|
@@ -268,6 +418,7 @@ end
|
|
|
268
418
|
|
|
269
419
|
--[=[
|
|
270
420
|
If these is data not yet written then this will return true
|
|
421
|
+
|
|
271
422
|
@return boolean
|
|
272
423
|
]=]
|
|
273
424
|
function DataStoreStage:HasWritableData()
|
|
@@ -291,6 +442,7 @@ end
|
|
|
291
442
|
|
|
292
443
|
--[=[
|
|
293
444
|
Constructs a writer which provides a snapshot of the current data state to write
|
|
445
|
+
|
|
294
446
|
@return DataStoreWriter
|
|
295
447
|
]=]
|
|
296
448
|
function DataStoreStage:GetNewWriter()
|
|
@@ -335,6 +487,12 @@ function DataStoreStage:_doStore(name, value)
|
|
|
335
487
|
if self._topLevelStoreSignal then
|
|
336
488
|
self._topLevelStoreSignal:Fire()
|
|
337
489
|
end
|
|
490
|
+
|
|
491
|
+
if newValue == DataStoreDeleteToken then
|
|
492
|
+
self._subsTable:Fire(name, nil)
|
|
493
|
+
else
|
|
494
|
+
self._subsTable:Fire(name, newValue)
|
|
495
|
+
end
|
|
338
496
|
end
|
|
339
497
|
|
|
340
498
|
|