1
1
//
2
- // HookFunction .swift
2
+ // ParseHookFunction+Vapor .swift
3
3
//
4
4
//
5
5
// Created by Corey Baker on 6/23/22.
@@ -9,29 +9,18 @@ import Foundation
9
9
import ParseSwift
10
10
import Vapor
11
11
12
- /**
13
- Parse Hook Functions can be created by conforming to
14
- `ParseHookFunctionable`.
15
- */
16
- public struct HookFunction : ParseHookFunctionable {
17
- public var functionName : String ?
18
- public var url : URL ?
19
-
20
- public init ( ) { }
21
- }
22
-
23
12
// MARK: HookFunction - Internal
24
- extension HookFunction {
13
+ extension ParseHookFunction {
25
14
26
15
@discardableResult
27
16
static func method( _ method: HTTPMethod ,
28
17
_ path: [ PathComponent ] ,
29
18
name: String ,
30
- parseServerURLStrings: [ String ] ) async throws -> [ String : HookFunction ] {
19
+ parseServerURLStrings: [ String ] ) async throws -> [ String : Self ] {
31
20
let url = try buildServerPathname ( path)
32
- let hookFunction = HookFunction ( name: name,
33
- url: url)
34
- var hookFunctions = [ String: HookFunction ] ( )
21
+ let hookFunction = Self ( name: name,
22
+ url: url)
23
+ var hookFunctions = [ String: Self ] ( )
35
24
36
25
for parseServerURLString in parseServerURLStrings {
37
26
do {
@@ -79,7 +68,7 @@ extension HookFunction {
79
68
}
80
69
81
70
// MARK: HookFunction - Fetch
82
- public extension HookFunction {
71
+ public extension ParseHookFunction {
83
72
84
73
/**
85
74
Fetches a Parse Cloud Code hook function.
@@ -93,7 +82,7 @@ public extension HookFunction {
93
82
*/
94
83
static func fetch( _ path: PathComponent ... ,
95
84
name: String ,
96
- parseServerURLStrings: [ String ] ) async throws -> [ String : HookFunction ] {
85
+ parseServerURLStrings: [ String ] ) async throws -> [ String : Self ] {
97
86
try await fetch ( path, name: name, parseServerURLStrings: parseServerURLStrings)
98
87
}
99
88
@@ -109,7 +98,7 @@ public extension HookFunction {
109
98
*/
110
99
static func fetch( _ path: [ PathComponent ] ,
111
100
name: String ,
112
- parseServerURLStrings: [ String ] ) async throws -> [ String : HookFunction ] {
101
+ parseServerURLStrings: [ String ] ) async throws -> [ String : Self ] {
113
102
try await method ( . PUT, path, name: name, parseServerURLStrings: parseServerURLStrings)
114
103
}
115
104
@@ -125,7 +114,7 @@ public extension HookFunction {
125
114
*/
126
115
static func fetchAll( _ path: PathComponent ... ,
127
116
name: String ,
128
- parseServerURLStrings: [ String ] ) async throws -> [ String : [ HookFunction ] ] {
117
+ parseServerURLStrings: [ String ] ) async throws -> [ String : [ Self ] ] {
129
118
try await fetchAll ( path, name: name, parseServerURLStrings: parseServerURLStrings)
130
119
}
131
120
@@ -141,11 +130,11 @@ public extension HookFunction {
141
130
*/
142
131
static func fetchAll( _ path: [ PathComponent ] ,
143
132
name: String ,
144
- parseServerURLStrings: [ String ] ) async throws -> [ String : [ HookFunction ] ] {
133
+ parseServerURLStrings: [ String ] ) async throws -> [ String : [ Self ] ] {
145
134
let url = try buildServerPathname ( path)
146
- let hookFunction = HookFunction ( name: name,
135
+ let hookFunction = Self ( name: name,
147
136
url: url)
148
- var hookFunctions = [ String: [ HookFunction ] ] ( )
137
+ var hookFunctions = [ String: [ Self ] ] ( )
149
138
150
139
for parseServerURLString in parseServerURLStrings {
151
140
do {
@@ -161,7 +150,7 @@ public extension HookFunction {
161
150
}
162
151
163
152
// MARK: HookFunction - Create
164
- public extension HookFunction {
153
+ public extension ParseHookFunction {
165
154
166
155
/**
167
156
Creates a Parse Cloud Code hook function.
@@ -177,7 +166,7 @@ public extension HookFunction {
177
166
static func create( _ path: PathComponent ... ,
178
167
name: String ,
179
168
// swiftlint:disable:next line_length
180
- parseServerURLStrings: [ String ] = ParseServerSwift . configuration. parseServerURLStrings) async throws -> [ String : HookFunction ] {
169
+ parseServerURLStrings: [ String ] = ParseServerSwift . configuration. parseServerURLStrings) async throws -> [ String : Self ] {
181
170
try await create ( path, name: name, parseServerURLStrings: parseServerURLStrings)
182
171
}
183
172
@@ -195,13 +184,13 @@ public extension HookFunction {
195
184
static func create( _ path: [ PathComponent ] ,
196
185
name: String ,
197
186
// swiftlint:disable:next line_length
198
- parseServerURLStrings: [ String ] = ParseServerSwift . configuration. parseServerURLStrings) async throws -> [ String : HookFunction ] {
187
+ parseServerURLStrings: [ String ] = ParseServerSwift . configuration. parseServerURLStrings) async throws -> [ String : Self ] {
199
188
try await method ( . POST, path, name: name, parseServerURLStrings: parseServerURLStrings)
200
189
}
201
190
}
202
191
203
192
// MARK: HookFunction - Update
204
- public extension HookFunction {
193
+ public extension ParseHookFunction {
205
194
206
195
/**
207
196
Updates a Parse Cloud Code hook function.
@@ -217,7 +206,7 @@ public extension HookFunction {
217
206
static func update( _ path: PathComponent ... ,
218
207
name: String ,
219
208
// swiftlint:disable:next line_length
220
- parseServerURLStrings: [ String ] = ParseServerSwift . configuration. parseServerURLStrings) async throws -> [ String : HookFunction ] {
209
+ parseServerURLStrings: [ String ] = ParseServerSwift . configuration. parseServerURLStrings) async throws -> [ String : Self ] {
221
210
try await update ( path, name: name, parseServerURLStrings: parseServerURLStrings)
222
211
}
223
212
@@ -235,13 +224,13 @@ public extension HookFunction {
235
224
static func update( _ path: [ PathComponent ] ,
236
225
name: String ,
237
226
// swiftlint:disable:next line_length
238
- parseServerURLStrings: [ String ] = ParseServerSwift . configuration. parseServerURLStrings) async throws -> [ String : HookFunction ] {
227
+ parseServerURLStrings: [ String ] = ParseServerSwift . configuration. parseServerURLStrings) async throws -> [ String : Self ] {
239
228
try await method ( . PUT, path, name: name, parseServerURLStrings: parseServerURLStrings)
240
229
}
241
230
}
242
231
243
232
// MARK: HookFunction - Delete
244
- public extension HookFunction {
233
+ public extension ParseHookFunction {
245
234
246
235
/**
247
236
Removes a Parse Cloud Code hook function.
@@ -359,8 +348,8 @@ public extension RoutesBuilder {
359
348
let route = self . on ( . POST, path, body: body, use: closure)
360
349
Task {
361
350
do {
362
- await configuration. hooks. updateFunctions ( try await HookFunction . create ( route. path,
363
- name: name) )
351
+ await configuration. hooks. updateFunctions ( try await ParseHookFunction . create ( route. path,
352
+ name: name) )
364
353
} catch {
365
354
// swiftlint:disable:next line_length
366
355
configuration. logger. error ( " Could not create HookFunction route for path: \( path) ; name: \( name) on servers: \( configuration. parseServerURLStrings) because of error: \( error) " )
0 commit comments