@quenty/datastore 3.6.0 → 4.0.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,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
|
+
# [4.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@3.6.0...@quenty/datastore@4.0.0) (2022-03-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Can add removing promises to datastore before save ([653bef8](https://github.com/Quenty/NevermoreEngine/commit/653bef8717e4470cf94340e67ff69eab1b7269f6))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [3.6.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@3.5.1...@quenty/datastore@3.6.0) (2022-01-17)
|
|
7
18
|
|
|
8
19
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/datastore",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Quenty's Datastore implementation for Roblox",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"Quenty"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@quenty/baseobject": "^
|
|
30
|
-
"@quenty/loader": "^
|
|
29
|
+
"@quenty/baseobject": "^4.0.0",
|
|
30
|
+
"@quenty/loader": "^4.0.0",
|
|
31
31
|
"@quenty/maid": "^2.1.0",
|
|
32
|
-
"@quenty/promise": "^
|
|
32
|
+
"@quenty/promise": "^4.0.0",
|
|
33
33
|
"@quenty/signal": "^2.1.0",
|
|
34
34
|
"@quenty/symbol": "^2.0.1",
|
|
35
35
|
"@quenty/table": "^2.1.1"
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "dd428cab58282c975a4c082957dc8f58e3186905"
|
|
41
41
|
}
|
package/src/Server/DataStore.lua
CHANGED
|
@@ -131,15 +131,24 @@ function DataStore:Save()
|
|
|
131
131
|
return Promise.rejected("Load not successful, not saving")
|
|
132
132
|
end
|
|
133
133
|
|
|
134
|
-
if
|
|
135
|
-
|
|
136
|
-
if DEBUG_WRITING then
|
|
137
|
-
print("[DataStore.Save] - Not saving, nothing staged")
|
|
138
|
-
end
|
|
139
|
-
return Promise.resolved(nil)
|
|
134
|
+
if DEBUG_WRITING then
|
|
135
|
+
print("[DataStore.Save] - Starting save routine")
|
|
140
136
|
end
|
|
141
137
|
|
|
142
|
-
|
|
138
|
+
-- Avoid constructing promises for every callback down the datastore
|
|
139
|
+
-- upon save.
|
|
140
|
+
return (self:_promiseInvokeSavingCallbacks() or Promise.resolved())
|
|
141
|
+
:Then(function()
|
|
142
|
+
if not self:HasWritableData() then
|
|
143
|
+
-- Nothing to save, don't update anything
|
|
144
|
+
if DEBUG_WRITING then
|
|
145
|
+
print("[DataStore.Save] - Not saving, nothing staged")
|
|
146
|
+
end
|
|
147
|
+
return nil
|
|
148
|
+
else
|
|
149
|
+
return self:_saveData(self:GetNewWriter())
|
|
150
|
+
end
|
|
151
|
+
end)
|
|
143
152
|
end
|
|
144
153
|
|
|
145
154
|
--[=[
|
|
@@ -16,6 +16,7 @@ local DataStoreWriter = require("DataStoreWriter")
|
|
|
16
16
|
local Promise = require("Promise")
|
|
17
17
|
local Table = require("Table")
|
|
18
18
|
local Signal = require("Signal")
|
|
19
|
+
local PromiseUtils = require("PromiseUtils")
|
|
19
20
|
|
|
20
21
|
local DataStoreStage = setmetatable({}, BaseObject)
|
|
21
22
|
DataStoreStage.ClassName = "DataStoreStage"
|
|
@@ -35,12 +36,65 @@ function DataStoreStage.new(loadName, loadParent)
|
|
|
35
36
|
self._loadName = loadName
|
|
36
37
|
self._loadParent = loadParent
|
|
37
38
|
|
|
39
|
+
self._savingCallbacks = {} -- [func, ...]
|
|
38
40
|
self._takenKeys = {} -- [name] = true
|
|
39
41
|
self._stores = {} -- [name] = dataSubStore
|
|
40
42
|
|
|
41
43
|
return self
|
|
42
44
|
end
|
|
43
45
|
|
|
46
|
+
-- Also returns nil for speedyness
|
|
47
|
+
function DataStoreStage:_promiseInvokeSavingCallbacks()
|
|
48
|
+
if not next(self._savingCallbacks) then
|
|
49
|
+
return nil
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
local removingPromises = {}
|
|
53
|
+
for _, func in pairs(self._savingCallbacks) do
|
|
54
|
+
local result = func()
|
|
55
|
+
if Promise.isPromise(result) then
|
|
56
|
+
table.insert(removingPromises, result)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
for _, substore in pairs(self._stores) do
|
|
61
|
+
local promise = substore:_promiseInvokeSavingCallbacks()
|
|
62
|
+
if promise then
|
|
63
|
+
table.insert(removingPromises, promise)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
return PromiseUtils.all(removingPromises)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
--[=[
|
|
71
|
+
Adds a callback to be called before save. This may return a promise.
|
|
72
|
+
@param callback function -- May return a promise
|
|
73
|
+
@return function -- Call to remove
|
|
74
|
+
]=]
|
|
75
|
+
function DataStoreStage:AddSavingCallback(callback)
|
|
76
|
+
assert(type(callback) == "function", "Bad callback")
|
|
77
|
+
|
|
78
|
+
table.insert(self._savingCallbacks, callback)
|
|
79
|
+
|
|
80
|
+
return function()
|
|
81
|
+
self:RemoveSavingCallback(callback)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
--[=[
|
|
86
|
+
Removes a saving callback from the data store stage
|
|
87
|
+
@param callback function
|
|
88
|
+
]=]
|
|
89
|
+
function DataStoreStage:RemoveSavingCallback(callback)
|
|
90
|
+
assert(type(callback) == "function", "Bad callback")
|
|
91
|
+
|
|
92
|
+
local index = table.find(self._savingCallbacks, callback)
|
|
93
|
+
if index then
|
|
94
|
+
table.remove(self._savingCallbacks, index)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
44
98
|
--[=[
|
|
45
99
|
Gets an event that will fire off whenever something is stored at this level
|
|
46
100
|
@return Signal
|
|
@@ -15,6 +15,7 @@ local DataStore = require("DataStore")
|
|
|
15
15
|
local PromiseUtils = require("PromiseUtils")
|
|
16
16
|
local PendingPromiseTracker = require("PendingPromiseTracker")
|
|
17
17
|
local Maid = require("Maid")
|
|
18
|
+
local Promise = require("Promise")
|
|
18
19
|
|
|
19
20
|
local PlayerDataStoreManager = setmetatable({}, BaseObject)
|
|
20
21
|
PlayerDataStoreManager.ClassName = "PlayerDataStoreManager"
|
|
@@ -69,7 +70,7 @@ end
|
|
|
69
70
|
|
|
70
71
|
--[=[
|
|
71
72
|
Adds a callback to be called before save on removal
|
|
72
|
-
@param callback function
|
|
73
|
+
@param callback function -- May return a promise
|
|
73
74
|
]=]
|
|
74
75
|
function PlayerDataStoreManager:AddRemovingCallback(callback)
|
|
75
76
|
table.insert(self._removingCallbacks, callback)
|
|
@@ -142,14 +143,22 @@ function PlayerDataStoreManager:_removePlayerDataStore(player)
|
|
|
142
143
|
|
|
143
144
|
self._removing[player] = true
|
|
144
145
|
|
|
146
|
+
local removingPromises = {}
|
|
145
147
|
for _, func in pairs(self._removingCallbacks) do
|
|
146
|
-
func(player)
|
|
148
|
+
local result = func(player)
|
|
149
|
+
if Promise.isPromise(result) then
|
|
150
|
+
table.insert(removingPromises, result)
|
|
151
|
+
end
|
|
147
152
|
end
|
|
148
153
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
154
|
+
PromiseUtils.all(removingPromises)
|
|
155
|
+
:Then(function()
|
|
156
|
+
return datastore:Save()
|
|
157
|
+
end)
|
|
158
|
+
:Finally(function()
|
|
159
|
+
datastore:Destroy()
|
|
160
|
+
self._removing[player] = nil
|
|
161
|
+
end)
|
|
153
162
|
|
|
154
163
|
-- Prevent double removal or additional issues
|
|
155
164
|
self._datastores[player] = nil
|