Skip to content

Commit

Permalink
Docs markup
Browse files Browse the repository at this point in the history
  • Loading branch information
SalehAlbuga committed Jun 7, 2020
1 parent ec402ff commit 319ced1
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 33 deletions.
13 changes: 13 additions & 0 deletions Sources/AzureFunctions/AzureFunction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,64 @@ public typealias callback = (Any) -> Void

open class Function {

/// Function name, has to match class and file names.
public var name: String!

public var id: String!

internal var inputBindingsDic: [String: Binding] = [:]
internal var outputBindingsDic: [String: Binding] = [:]

/// Function input bindings (Classic and HTTP modes)
public var inputBindings: [Binding] = []
/// Function output bindings (Classic and HTTP modes)
public var outputBindings: [Binding] = []
public var isDisabled: Bool = false

/// Function trigger (Classic and HTTP modes)
public var trigger: Binding!

/// function.json bindings dictionary (HTTP Worker mode only)
public var functionJsonBindings: [[String: Any]] = []
/// Vapor app, to add the function route (HTTP Worker mode only)
public var app: Application = HandlerHTTPServer.shared.app


public required init() {

}

/// Function handler for HTTP trigger (Classic mode only)
open func exec(request: HttpRequest, context: inout Context, callback: @escaping callback) throws {
throw FunctionError.FunctionTypeNotImplementedException("Please override the right exec function for your trigger")
}

/// Function handler for Timer trigger (Classic mode only)
open func exec(timer: TimerTrigger, context: inout Context, callback: @escaping callback) throws {
throw FunctionError.FunctionTypeNotImplementedException("Please override the right exec function for your trigger")
}

/// Function handler for various triggers that has values of type Data (Classic mode only)
open func exec(data: Data, context: inout Context, callback: @escaping callback) throws {
throw FunctionError.FunctionTypeNotImplementedException("Please override the right exec function for your trigger")
}

/// Function handler for various triggers that has values of type String (Classic mode only)
open func exec(string: String, context: inout Context, callback: @escaping callback) throws {
throw FunctionError.FunctionTypeNotImplementedException("Please override the right exec function for your trigger")
}

/// Function handler for various triggers that has values of type Dictionary (Classic mode only)
open func exec(dictionary: [String: Any], context: inout Context, callback: @escaping callback) throws {
throw FunctionError.FunctionTypeNotImplementedException("Please override the right exec function for your trigger")
}

/// Function handler for Blob trigger (Classic mode only)
open func exec(blob: Blob, context: inout Context, callback: @escaping callback) throws {
throw FunctionError.FunctionTypeNotImplementedException("Please override the right exec function for your trigger")
}

/// Function handler for ServiceBus trigger (Classic mode only)
open func exec(sbMessage: ServiceBusMessage, context: inout Context, callback: @escaping callback) throws {
throw FunctionError.FunctionTypeNotImplementedException("Please override the right exec function for your trigger")
}
Expand Down
6 changes: 6 additions & 0 deletions Sources/AzureFunctions/AzureFunctionsWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public final class AzureFunctionsWorker {

internal var worker: WorkerChannel!

/// Starts the worker
/// given element.
///
/// - Parameter registery: The functions registery
/// - Parameter mode: Worker mode, can be set to .HTTP (for Azure Functions Custom Handler, HTTP worker mode) or .Classic. Defaults to .Classic
///
public func main(registry: FunctionRegistry, mode: WorkerMode = .Classic) {

#if !os(Linux)
Expand Down
12 changes: 6 additions & 6 deletions Sources/AzureFunctions/Bindings/ServiceBusMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ServiceBusMessage: Binding {
public var connection: String = ""
public var message: Any?

internal init() {
internal init() {

}

Expand All @@ -42,15 +42,15 @@ public class ServiceBusMessage: Binding {

extension ServiceBusMessage: BindingCapability {

var isInput: Bool {
var isInput: Bool {
return false
}

var isOutput: Bool {
var isOutput: Bool {
return true
}

var isTrigger: Bool {
var isTrigger: Bool {
return true
}

Expand Down Expand Up @@ -94,7 +94,7 @@ extension ServiceBusMessage: BindingCapability {
}

func stringJsonDescription(direction: BindingDirection) throws -> String {
return try jsonDescription(direction: direction).toJsonString()
}
return try jsonDescription(direction: direction).toJsonString()
}

}
20 changes: 11 additions & 9 deletions Sources/AzureFunctions/Bindings/models/InvocationRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,27 @@ import Vapor

public struct InvocationRequest: Content {

public var Data: [String:AnyCodable]?
public var Metadata: [String:AnyCodable]?
/// Trigger/Bindings data (values).
public var data: [String:AnyCodable]?
/// Trigger/Bindings metadata.
public var metadata: [String:AnyCodable]?

public enum CodingKeys: String, CodingKey {

public enum CodingKeys: String, CodingKey {
case data = "Data"
case metadata = "Metadata"
}

public init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
Data = try values.decode([String:AnyCodable].self, forKey: .data)
Metadata = try values.decode([String:AnyCodable].self, forKey: .metadata)
data = try values.decode([String:AnyCodable].self, forKey: .data)
metadata = try values.decode([String:AnyCodable].self, forKey: .metadata)
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(Data, forKey: .data)
try container.encode(Metadata, forKey: .metadata)
try container.encode(data, forKey: .data)
try container.encode(metadata, forKey: .metadata)
}

}
38 changes: 20 additions & 18 deletions Sources/AzureFunctions/Bindings/models/InvocationResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,38 @@ import Vapor

public struct InvocationResponse: Content {

var Outputs: [String:AnyCodable]?
var Logs: [String] = []
var ReturnValue: AnyCodable?
/// Output bindings values dictionary
var outputs: [String:AnyCodable]?
/// Functions logs array. These will be logged when the Function is executed
var logs: [String] = []
/// The $return binding value
var returnValue: AnyCodable?

enum CodingKeys: String, CodingKey {

case Output = "Outputs"
case Logs = "Logs"
case ReturnValue = "ReturnValue"
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
Outputs = try container.decode([String:AnyCodable].self, forKey: .Output)
Logs = try container.decode([String].self, forKey: .Logs)
ReturnValue = try container.decode(AnyCodable.self, forKey: .ReturnValue)
outputs = try container.decode([String:AnyCodable].self, forKey: .Output)
logs = try container.decode([String].self, forKey: .Logs)
returnValue = try container.decode(AnyCodable.self, forKey: .ReturnValue)
}

public init() { }

public init(outputs: [String:AnyCodable], logs: [String] = [], returnValue: AnyCodable? = nil) {
self.Outputs = outputs
Logs = logs
ReturnValue = returnValue
self.outputs = outputs
self.logs = logs
self.returnValue = returnValue
}

public init(logs: [String] = [], returnValue: AnyCodable? = nil) {
self.Outputs = nil
Logs = logs
ReturnValue = returnValue
self.outputs = nil
self.logs = logs
self.returnValue = returnValue
}

public static func response(with outputs: [String:AnyCodable], logs: [String] = [], returnValue: AnyCodable? = nil) -> Data {
Expand All @@ -50,21 +52,21 @@ public struct InvocationResponse: Content {

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(Outputs, forKey: .Output)
try container.encode(Logs, forKey: .Logs)
try container.encode(ReturnValue, forKey: .ReturnValue)
try container.encode(outputs, forKey: .Output)
try container.encode(logs, forKey: .Logs)
try container.encode(returnValue, forKey: .ReturnValue)
}

}

public extension InvocationResponse {

mutating func appendLog(_ log: String) {
Logs.append(log)
logs.append(log)
}

mutating func removeLastLog() {
Logs.removeLast()
logs.removeLast()
}

}
5 changes: 5 additions & 0 deletions Sources/AzureFunctions/FunctionRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ public final class FunctionRegistry {
private var functionsById: [String: Function] = [:]
private var functionsInfo: [String: FunctionInfo] = [:]

/// Default Azure Function storage
public var AzureWebJobsStorage: String?
/// Environment variables dictionary
public var EnvironmentVariables: [String: String]?

/// Extensions Bundle id (do not change unless needed, defaults to Microsoft.Azure.Functions.ExtensionBundle)
public var ExtensionBundleId: String?
/// Extensions Bundle version (do not change unless needed, defaults to [1.*, 2.0.0))
public var ExtensionBundleVersion: String?

public init() { }
Expand All @@ -30,6 +34,7 @@ public final class FunctionRegistry {
self.EnvironmentVariables = EnvironmentVariables
}

/// Registers a Function
public func register(_ function: Function.Type) {
let fun = function.init()
self.functionsByName[fun.name] = fun
Expand Down

0 comments on commit 319ced1

Please sign in to comment.