@@ -19,25 +19,25 @@ struct TrieRouter: OpenAPILambdaRouter {
1919 private let uriPath : URIPathCollection = URIPath ( )
2020
2121 /// add a route for a given HTTP method and path and associate a handler
22- func add( method: HTTPRequest . Method , path: String , handler: @escaping OpenAPIHandler ) async throws {
23- try await uriPath. add ( method: method, path: path, handler: handler)
22+ func add( method: HTTPRequest . Method , path: String , handler: @escaping OpenAPIHandler ) throws {
23+ try uriPath. add ( method: method, path: path, handler: handler)
2424 }
2525
2626 /// Retrieve the handler and path parameter for a given HTTP method and path
27- func route( method: HTTPRequest . Method , path: String ) async throws -> (
27+ func route( method: HTTPRequest . Method , path: String ) throws -> (
2828 OpenAPIHandler , OpenAPILambdaRequestParameters
29- ) { try await uriPath. find ( method: method, path: path) }
29+ ) { try uriPath. find ( method: method, path: path) }
3030}
3131
3232enum URIPathCollectionError : Error {
3333 case canNotAddChildToHandlerNode
3434 case canNotHaveMultipleParamChilds
3535}
3636
37- protocol URIPathCollection : Sendable {
37+ protocol URIPathCollection {
3838 func root( ) -> Node
39- func add( method: HTTPRequest . Method , path: String , handler: @escaping OpenAPIHandler ) async throws
40- func find( method: HTTPRequest . Method , path: String ) async throws -> ( OpenAPIHandler , OpenAPILambdaRequestParameters )
39+ func add( method: HTTPRequest . Method , path: String , handler: @escaping OpenAPIHandler ) throws
40+ func find( method: HTTPRequest . Method , path: String ) throws -> ( OpenAPIHandler , OpenAPILambdaRequestParameters )
4141}
4242
4343/// A Trie graph representation of an URI path + its handler
@@ -56,10 +56,10 @@ struct URIPath: URIPathCollection {
5656 /// - method: the HTTP method to use as first node
5757 /// - path: the full path as received from OpenAPI registration (including parameters encoded as {param name}
5858 /// - handler: the OpenAPI handler to invoke for such path
59- func add( method: HTTPRequest . Method , path: String , handler: @escaping OpenAPIHandler ) async throws {
59+ func add( method: HTTPRequest . Method , path: String , handler: @escaping OpenAPIHandler ) throws {
6060
6161 // add or retrieve the HTTP method node
62- var node = try await root ( ) . add ( httpMethod: method)
62+ var node = try root ( ) . add ( httpMethod: method)
6363
6464 // add each path element as child nodes
6565 let pathComponents = path. split ( separator: " / " )
@@ -68,15 +68,15 @@ struct URIPath: URIPathCollection {
6868 var comp = component
6969 comp. removeFirst ( )
7070 comp. removeLast ( )
71- node = try await node. add ( parameter: String ( comp) )
71+ node = try node. add ( parameter: String ( comp) )
7272 }
7373 else {
74- node = try await node. add ( pathElement: String ( component) )
74+ node = try node. add ( pathElement: String ( component) )
7575 }
7676 }
7777
7878 // finally add the handler
79- _ = try await node. add ( handler: handler)
79+ _ = try node. add ( handler: handler)
8080 }
8181
8282 /// Navigate the tree to find the handler
@@ -91,13 +91,13 @@ struct URIPath: URIPathCollection {
9191 /// - OpenAPILambdaRouterError.noRouteForPath when there is no handler in the graph for the given combination of HTTP method and path
9292 /// - OpenAPILambdaRouterError.noRouteForMethod when there is no handler for that HTTP method
9393 /// - OpenAPILambdaRouterError.noHandlerForPath when there is no handler as leaf node of the tree. This is a programming error and should not happen
94- func find( method: HTTPRequest . Method , path: String ) async throws -> ( OpenAPIHandler , OpenAPILambdaRequestParameters )
94+ func find( method: HTTPRequest . Method , path: String ) throws -> ( OpenAPIHandler , OpenAPILambdaRequestParameters )
9595 {
9696 var parameters : OpenAPILambdaRequestParameters = [ : ]
9797 let root : Node = root ( )
9898
9999 // first node is the HTTP Method
100- guard let nodeHTTP = await root. children [ method. rawValue] else {
100+ guard let nodeHTTP = root. children [ method. rawValue] else {
101101 throw OpenAPILambdaRouterError . noRouteForMethod ( method)
102102 }
103103
@@ -106,14 +106,14 @@ struct URIPath: URIPathCollection {
106106 let pathComponents = path. prefix ( while: { $0 != " ? " } ) . split ( separator: " / " )
107107 var currentNode = nodeHTTP
108108 for component in pathComponents {
109- if let child = await currentNode. child ( with: component) {
109+ if let child = currentNode. child ( with: component) {
110110 // found a node with path element, continue to explore
111111 currentNode = child
112112 }
113113 else {
114114 // no path element for this component, maybe this component is a parameter value
115115 // let's see if we have a child param node
116- if let child = await currentNode. parameterChild ( ) {
116+ if let child = currentNode. parameterChild ( ) {
117117 let paramName = child. value. asString!
118118
119119 //TODO: do not collect param when another child is a path with matching name ?
@@ -133,7 +133,7 @@ struct URIPath: URIPathCollection {
133133 }
134134
135135 //at this stage, current node must have a handler child
136- guard let handlerNode = await currentNode. handlerChild ( ) else {
136+ guard let handlerNode = currentNode. handlerChild ( ) else {
137137 throw OpenAPILambdaRouterError . noHandlerForPath ( path)
138138 }
139139
0 commit comments