Skip to content

Commit b5a4620

Browse files
committed
missed on, only note return types
1 parent 1116f2c commit b5a4620

File tree

1 file changed

+76
-23
lines changed

1 file changed

+76
-23
lines changed

src/Neo4jDFG/services/CGStructure.jl

Lines changed: 76 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
function isValidLabel(abstractNode::N)::Bool where N <: AbstractCGNode
1+
# return ::Bool
2+
function isValidLabel(abstractNode::N) where N <: AbstractCGNode
23
id = String(abstractNode.id)
34
return all(t -> t != uppercase(id), _invalidIds) && match(_validLabelRegex, id) !== nothing
45
end
56

67
# Fastest way I can think to convert the data into a dict
78
#TODO: Probably should be made more efficient...definitely should be made more efficient
8-
function _convertNodeToDict(abstractNode::N)::Dict{String, Any} where N <: AbstractCGNode
9+
# return ::Dict{String, Any}
10+
function _convertNodeToDict(abstractNode::N) where N <: AbstractCGNode
911
cp = deepcopy(abstractNode)
1012
data = length(cp.data) != 0 ? JSON2.write(cp.data) : "{}"
1113
ser = JSON2.read(JSON2.write(abstractNode), Dict{String, Any})
@@ -15,7 +17,8 @@ function _convertNodeToDict(abstractNode::N)::Dict{String, Any} where N <: Abstr
1517
end
1618

1719
#TODO: Refactor, #HACK :D (but it works!)
18-
function _convertDictToSession(dict::Dict{String, Any})::Session
20+
# return ::Session
21+
function _convertDictToSession(dict::Dict{String, Any})
1922
data = JSON2.read(String(base64decode(dict["data"])), Dict{Symbol, String})
2023
session = Session(
2124
Symbol(dict["id"]),
@@ -29,7 +32,8 @@ function _convertDictToSession(dict::Dict{String, Any})::Session
2932
return session
3033
end
3134
#TODO: Refactor, #HACK :D (but it works!)
32-
function _convertDictToRobot(dict::Dict{String, Any})::Robot
35+
# returns ::Robot
36+
function _convertDictToRobot(dict::Dict{String, Any})
3337
data = JSON2.read(String(base64decode(dict["data"])), Dict{Symbol, String})
3438
robot = Robot(
3539
Symbol(dict["id"]),
@@ -42,7 +46,8 @@ function _convertDictToRobot(dict::Dict{String, Any})::Robot
4246
return robot
4347
end
4448
#TODO: Refactor, #HACK :D (but it works!)
45-
function _convertDictToUser(dict::Dict{String, Any})::User
49+
# returns ::User
50+
function _convertDictToUser(dict::Dict{String, Any})
4651
data = JSON2.read(String(base64decode(dict["data"])), Dict{Symbol, String})
4752
user = User(
4853
Symbol(dict["id"]),
@@ -54,7 +59,8 @@ function _convertDictToUser(dict::Dict{String, Any})::User
5459
return user
5560
end
5661

57-
function createUser(dfg::Neo4jDFG, user::User)::User
62+
# returns ::User
63+
function createUser(dfg::Neo4jDFG, user::User)
5864
Symbol(dfg.userId) != user.id && error("DFG user ID must match user's ID")
5965
!isValidLabel(user) && error("Node cannot have an ID '$(user.id)'.")
6066

@@ -64,7 +70,8 @@ function createUser(dfg::Neo4jDFG, user::User)::User
6470
return user
6571
end
6672

67-
function createRobot(dfg::Neo4jDFG, robot::Robot)::Robot
73+
# returns ::Robot
74+
function createRobot(dfg::Neo4jDFG, robot::Robot)
6875
Symbol(dfg.robotId) != robot.id && error("DFG robot ID must match robot's ID")
6976
Symbol(dfg.userId) != robot.userId && error("DFG user ID must match robot's user ID")
7077
!isValidLabel(robot) && error("Node cannot have an ID '$(robot.id)'.")
@@ -84,7 +91,8 @@ function createRobot(dfg::Neo4jDFG, robot::Robot)::Robot
8491
return robot
8592
end
8693

87-
function createSession(dfg::Neo4jDFG, session::Session)::Session
94+
# returns ::Session
95+
function createSession(dfg::Neo4jDFG, session::Session)
8896
Symbol(dfg.robotId) != session.robotId && error("DFG robot ID must match session's robot ID")
8997
Symbol(dfg.userId) != session.userId && error("DFG user ID must match session's->robot's->user ID")
9098
!isValidLabel(session) && error("Node cannot have an ID '$(session.id)'.")
@@ -107,8 +115,11 @@ end
107115
"""
108116
$(SIGNATURES)
109117
Shortcut method to create the user, robot, and session if it doesn't already exist.
118+
119+
Notes
120+
- return `::Session`
110121
"""
111-
function createDfgSessionIfNotExist(dfg::Neo4jDFG)::Session
122+
function createDfgSessionIfNotExist(dfg::Neo4jDFG)
112123
strip(dfg.userId) == "" && error("User ID is not populated in DFG.")
113124
strip(dfg.robotId) == "" && error("Robot ID is not populated in DFG.")
114125
strip(dfg.sessionId) == "" && error("Session ID is not populated in DFG.")
@@ -129,8 +140,11 @@ end
129140
$(SIGNATURES)
130141
List all sessions for the specified DFG's robot and user.
131142
Returns nothing if it isn't found.
143+
144+
Notes
145+
- Returns `Vector{Session}`
132146
"""
133-
function lsSessions(dfg::Neo4jDFG)::Vector{Session}
147+
function lsSessions(dfg::Neo4jDFG)
134148
sessionNodes = _getNeoNodesFromCyphonQuery(dfg.neo4jInstance, "(node:SESSION:$(dfg.robotId):$(dfg.userId))")
135149
return map(s -> _convertDictToSession(Neo4j.getnodeproperties(s)), sessionNodes)
136150
end
@@ -139,8 +153,11 @@ end
139153
$(SIGNATURES)
140154
List all robots for the specified DFG's user.
141155
Returns nothing if it isn't found.
156+
157+
Notes
158+
- Returns `::Vector{Robot}`
142159
"""
143-
function lsRobots(dfg::Neo4jDFG)::Vector{Robot}
160+
function lsRobots(dfg::Neo4jDFG)
144161
robotNodes = _getNeoNodesFromCyphonQuery(dfg.neo4jInstance, "(node:ROBOT:$(dfg.userId))")
145162
return map(s -> _convertDictToRobot(Neo4j.getnodeproperties(s)), robotNodes)
146163
end
@@ -149,8 +166,11 @@ end
149166
$(SIGNATURES)
150167
List all users.
151168
Returns nothing if it isn't found.
169+
170+
Notes
171+
- Returns `::Vector{User}`
152172
"""
153-
function lsUsers(dfg::Neo4jDFG)::Vector{User}
173+
function lsUsers(dfg::Neo4jDFG)
154174
userNodes = _getNeoNodesFromCyphonQuery(dfg.neo4jInstance, "(node:USER)")
155175
return map(s -> _convertDictToUser(Neo4j.getnodeproperties(s)), userNodes)
156176
end
@@ -159,8 +179,11 @@ end
159179
$(SIGNATURES)
160180
Get a session specified by userId:robotId:sessionId.
161181
Returns nothing if it isn't found.
182+
183+
Notes
184+
- Returns either `::Union{Session, Nothing}`
162185
"""
163-
function getSession(dfg::Neo4jDFG, userId::Symbol, robotId::Symbol, sessionId::Symbol)::Union{Session, Nothing}
186+
function getSession(dfg::Neo4jDFG, userId::Symbol, robotId::Symbol, sessionId::Symbol)
164187
!isValidLabel(userId) && error("Can't retrieve session with user ID '$(userId)'.")
165188
!isValidLabel(robotId) && error("Can't retrieve session with robot ID '$(robotId)'.")
166189
!isValidLabel(sessionId) && error("Can't retrieve session with session ID '$(sessionId)'.")
@@ -174,17 +197,23 @@ end
174197
$(SIGNATURES)
175198
Get the session specified by the DFG object.
176199
Returns nothing if it isn't found.
200+
201+
Notes
202+
- Returns either `::Union{Nothing, Session}`
177203
"""
178-
function getSession(dfg::Neo4jDFG)::Union{Nothing, Session}
204+
function getSession(dfg::Neo4jDFG)
179205
return getSession(dfg, Symbol(dfg.userId), Symbol(dfg.robotId), Symbol(dfg.sessionId))
180206
end
181207

182208
"""
183209
$(SIGNATURES)
184210
Get a robot specified by userId:robotId.
185211
Returns nothing if it isn't found.
212+
213+
Notes
214+
- Returns either `::Union{Robot, Nothing}`
186215
"""
187-
function getRobot(dfg::Neo4jDFG, userId::Symbol, robotId::Symbol)::Union{Robot, Nothing}
216+
function getRobot(dfg::Neo4jDFG, userId::Symbol, robotId::Symbol)
188217
!isValidLabel(userId) && error("Can't retrieve robot with user ID '$(userId)'.")
189218
!isValidLabel(robotId) && error("Can't retrieve robot with robot ID '$(robotId)'.")
190219
robotNode = _getNeoNodesFromCyphonQuery(dfg.neo4jInstance, "(node:ROBOT:$(robotId):$(userId))")
@@ -197,17 +226,23 @@ end
197226
$(SIGNATURES)
198227
Get the robot specified by the DFG object.
199228
Returns nothing if it isn't found.
229+
230+
Notes
231+
- Returns either `::Union{Nothing, Robot}`
200232
"""
201-
function getRobot(dfg::Neo4jDFG)::Union{Nothing, Robot}
233+
function getRobot(dfg::Neo4jDFG)
202234
return getRobot(dfg, Symbol(dfg.userId), Symbol(dfg.robotId))
203235
end
204236

205237
"""
206238
$(SIGNATURES)
207239
Get a user specified by userId.
208240
Returns nothing if it isn't found.
241+
242+
Notes
243+
- Returns either `::Union{User, Nothing}`
209244
"""
210-
function getUser(dfg::Neo4jDFG, userId::Symbol)::Union{User, Nothing}
245+
function getUser(dfg::Neo4jDFG, userId::Symbol)
211246
!isValidLabel(userId) && error("Can't retrieve user with user ID '$(userId)'.")
212247
userNode = _getNeoNodesFromCyphonQuery(dfg.neo4jInstance, "(node:USER:$(userId))")
213248
length(userNode) == 0 && return nothing
@@ -219,17 +254,23 @@ end
219254
$(SIGNATURES)
220255
Get the user specified by the DFG object.
221256
Returns nothing if it isn't found.
257+
258+
Notes
259+
- Returns either `::Union{Nothing, User}`
222260
"""
223-
function getUser(dfg::Neo4jDFG)::Union{Nothing, User}
261+
function getUser(dfg::Neo4jDFG)
224262
return getUser(dfg, Symbol(dfg.userId))
225263
end
226264

227265

228266
"""
229267
$(SIGNATURES)
230268
DANGER: Clears the whole session from the database.
269+
270+
Notes
271+
- Returns `::Nothing`
231272
"""
232-
function clearSession!!(dfg::Neo4jDFG)::Nothing
273+
function clearSession!!(dfg::Neo4jDFG)
233274
# Perform detach+deletion
234275
_queryNeo4j(dfg.neo4jInstance, "match (node:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId)) detach delete node ")
235276

@@ -241,8 +282,11 @@ end
241282
"""
242283
$(SIGNATURES)
243284
DANGER: Clears the whole robot + sessions from the database.
285+
286+
Notes
287+
- Returns `::Nothing`
244288
"""
245-
function clearRobot!!(dfg::Neo4jDFG)::Nothing
289+
function clearRobot!!(dfg::Neo4jDFG)
246290
# Perform detach+deletion
247291
_queryNeo4j(dfg.neo4jInstance, "match (node:$(dfg.userId):$(dfg.robotId)) detach delete node ")
248292

@@ -254,8 +298,11 @@ end
254298
"""
255299
$(SIGNATURES)
256300
DANGER: Clears the whole user + robot + sessions from the database.
301+
302+
Notes
303+
- Returns `::Nothing`
257304
"""
258-
function clearUser!!(dfg::Neo4jDFG)::Nothing
305+
function clearUser!!(dfg::Neo4jDFG)
259306
# Perform detach+deletion
260307
_queryNeo4j(dfg.neo4jInstance, "match (node:$(dfg.userId)) detach delete node ")
261308

@@ -268,8 +315,11 @@ end
268315
$(SIGNATURES)
269316
DANGER: Copies and overwrites the destination session.
270317
If no destination specified then it creates a unique one.
318+
319+
Notes
320+
- Returns `::Neo4jDFG `
271321
"""
272-
function copySession!(sourceDFG::Neo4jDFG, destDFG::Union{Nothing, Neo4jDFG})::Neo4jDFG
322+
function copySession!(sourceDFG::Neo4jDFG, destDFG::Union{Nothing, <:Neo4jDFG})
273323
if destDFG == nothing
274324
destDFG = _getDuplicatedEmptyDFG(sourceDFG)
275325
end
@@ -279,5 +329,8 @@ end
279329
"""
280330
$(SIGNATURES)
281331
DANGER: Copies the source to a new unique destination.
332+
333+
Notes
334+
- Returns `::Neo4jDFG`
282335
"""
283-
copySession!(sourceDFG::Neo4jDFG)::Neo4jDFG = copySession!(sourceDFG, nothing)
336+
copySession!(sourceDFG::Neo4jDFG) = copySession!(sourceDFG, nothing)

0 commit comments

Comments
 (0)