Skip to content

Commit

Permalink
Add initial structure for context and reference (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
keelerm84 authored May 25, 2022
1 parent e2abc45 commit a3a0e8a
Show file tree
Hide file tree
Showing 14 changed files with 966 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ContractTests/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ let package = Package(
.product(name: "LaunchDarkly", package: "LaunchDarkly"),
.product(name: "Vapor", package: "vapor")
],
path: "Source"),
path: "Source")
],
swiftLanguageVersions: [.v5])
2 changes: 1 addition & 1 deletion ContractTests/Source/app.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Vapor

extension String: Error {}

public func app(_ env: Environment) throws -> Application {
func app(_ env: Environment) throws -> Application {
var config = Config.default()
var env = env
var services = Services.default()
Expand Down
2 changes: 1 addition & 1 deletion ContractTests/Source/boot.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Vapor

/// Called after your application has initialized.
public func boot(_ app: Application) throws {
func boot(_ app: Application) throws {
// Your code here
}
2 changes: 1 addition & 1 deletion ContractTests/Source/configure.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Vapor

/// Called before your application initializes.
public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
// Register routes to the router
let router = EngineRouter.default()
try routes(router)
Expand Down
2 changes: 1 addition & 1 deletion ContractTests/Source/routes.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Vapor

public func routes(_ router: Router) throws {
func routes(_ router: Router) throws {
let sdkController = SdkController()
router.get("/", use: sdkController.status)
router.post("/", use: sdkController.createClient)
Expand Down
58 changes: 58 additions & 0 deletions LaunchDarkly.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,21 @@
83F0A5641FB5F33800550A95 /* LDConfigSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83F0A5631FB5F33800550A95 /* LDConfigSpec.swift */; };
83FEF8DD1F266742001CF12C /* FlagSynchronizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83FEF8DC1F266742001CF12C /* FlagSynchronizer.swift */; };
83FEF8DF1F2667E4001CF12C /* EventReporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83FEF8DE1F2667E4001CF12C /* EventReporter.swift */; };
A31088172837DC0400184942 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = A31088142837DC0400184942 /* Reference.swift */; };
A31088182837DC0400184942 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = A31088142837DC0400184942 /* Reference.swift */; };
A31088192837DC0400184942 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = A31088142837DC0400184942 /* Reference.swift */; };
A310881A2837DC0400184942 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = A31088142837DC0400184942 /* Reference.swift */; };
A310881B2837DC0400184942 /* Kind.swift in Sources */ = {isa = PBXBuildFile; fileRef = A31088152837DC0400184942 /* Kind.swift */; };
A310881C2837DC0400184942 /* Kind.swift in Sources */ = {isa = PBXBuildFile; fileRef = A31088152837DC0400184942 /* Kind.swift */; };
A310881D2837DC0400184942 /* Kind.swift in Sources */ = {isa = PBXBuildFile; fileRef = A31088152837DC0400184942 /* Kind.swift */; };
A310881E2837DC0400184942 /* Kind.swift in Sources */ = {isa = PBXBuildFile; fileRef = A31088152837DC0400184942 /* Kind.swift */; };
A310881F2837DC0400184942 /* LDContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = A31088162837DC0400184942 /* LDContext.swift */; };
A31088202837DC0400184942 /* LDContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = A31088162837DC0400184942 /* LDContext.swift */; };
A31088212837DC0400184942 /* LDContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = A31088162837DC0400184942 /* LDContext.swift */; };
A31088222837DC0400184942 /* LDContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = A31088162837DC0400184942 /* LDContext.swift */; };
A31088272837DCA900184942 /* LDContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = A31088242837DCA900184942 /* LDContextSpec.swift */; };
A31088282837DCA900184942 /* ReferenceSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = A31088252837DCA900184942 /* ReferenceSpec.swift */; };
A31088292837DCA900184942 /* KindSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = A31088262837DCA900184942 /* KindSpec.swift */; };
B40B419C249ADA6B00CD0726 /* DiagnosticCacheSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B40B419B249ADA6B00CD0726 /* DiagnosticCacheSpec.swift */; };
B4265EB124E7390C001CFD2C /* TestUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4265EB024E7390C001CFD2C /* TestUtil.swift */; };
B467791324D8AEEC00897F00 /* LDSwiftEventSourceStatic in Frameworks */ = {isa = PBXBuildFile; productRef = B467791224D8AEEC00897F00 /* LDSwiftEventSourceStatic */; };
Expand Down Expand Up @@ -393,6 +408,12 @@
83F0A5631FB5F33800550A95 /* LDConfigSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LDConfigSpec.swift; sourceTree = "<group>"; };
83FEF8DC1F266742001CF12C /* FlagSynchronizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlagSynchronizer.swift; sourceTree = "<group>"; };
83FEF8DE1F2667E4001CF12C /* EventReporter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventReporter.swift; sourceTree = "<group>"; };
A31088142837DC0400184942 /* Reference.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Reference.swift; sourceTree = "<group>"; };
A31088152837DC0400184942 /* Kind.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Kind.swift; sourceTree = "<group>"; };
A31088162837DC0400184942 /* LDContext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LDContext.swift; sourceTree = "<group>"; };
A31088242837DCA900184942 /* LDContextSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LDContextSpec.swift; sourceTree = "<group>"; };
A31088252837DCA900184942 /* ReferenceSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReferenceSpec.swift; sourceTree = "<group>"; };
A31088262837DCA900184942 /* KindSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KindSpec.swift; sourceTree = "<group>"; };
B40B419B249ADA6B00CD0726 /* DiagnosticCacheSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiagnosticCacheSpec.swift; sourceTree = "<group>"; };
B4265EB024E7390C001CFD2C /* TestUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestUtil.swift; sourceTree = "<group>"; };
B468E70F24B3C3AC00E0C883 /* ObjcLDEvaluationDetail.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjcLDEvaluationDetail.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -596,6 +617,7 @@
8354EFE61F263E4200C05156 /* Models */ = {
isa = PBXGroup;
children = (
A31088132837DC0400184942 /* Context */,
C408884823033B7500420721 /* ConnectionInformation.swift */,
B4C9D42D2489B5FF004A9B03 /* DiagnosticEvent.swift */,
8354EFDE1F26380700C05156 /* Event.swift */,
Expand Down Expand Up @@ -722,6 +744,7 @@
83EF67911F9945CE00403126 /* Models */ = {
isa = PBXGroup;
children = (
A31088232837DCA900184942 /* Context */,
83F0A5631FB5F33800550A95 /* LDConfigSpec.swift */,
83EBCBA620D9A23E003A7142 /* User */,
83EBCBA720D9A251003A7142 /* FeatureFlag */,
Expand Down Expand Up @@ -751,6 +774,26 @@
path = ServiceObjects;
sourceTree = "<group>";
};
A31088132837DC0400184942 /* Context */ = {
isa = PBXGroup;
children = (
A31088142837DC0400184942 /* Reference.swift */,
A31088152837DC0400184942 /* Kind.swift */,
A31088162837DC0400184942 /* LDContext.swift */,
);
path = Context;
sourceTree = "<group>";
};
A31088232837DCA900184942 /* Context */ = {
isa = PBXGroup;
children = (
A31088242837DCA900184942 /* LDContextSpec.swift */,
A31088252837DCA900184942 /* ReferenceSpec.swift */,
A31088262837DCA900184942 /* KindSpec.swift */,
);
path = Context;
sourceTree = "<group>";
};
B467790E24D8AECA00897F00 /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1106,10 +1149,13 @@
8311885F2113AE2D00D77CB5 /* HTTPURLRequest.swift in Sources */,
B4C9D4362489C8FD004A9B03 /* DiagnosticCache.swift in Sources */,
831188452113ADC500D77CB5 /* LDClient.swift in Sources */,
A310881E2837DC0400184942 /* Kind.swift in Sources */,
A310881A2837DC0400184942 /* Reference.swift in Sources */,
831188522113ADF700D77CB5 /* KeyedValueCache.swift in Sources */,
831188582113AE0F00D77CB5 /* EventReporter.swift in Sources */,
8311885D2113AE2500D77CB5 /* DarklyService.swift in Sources */,
831188692113AE5900D77CB5 /* ObjcLDConfig.swift in Sources */,
A31088222837DC0400184942 /* LDContext.swift in Sources */,
8311886C2113AE6400D77CB5 /* ObjcLDChangedFlag.swift in Sources */,
C43C37E8238DF22D003C1624 /* LDEvaluationDetail.swift in Sources */,
8311884C2113ADDE00D77CB5 /* FlagChangeObserver.swift in Sources */,
Expand Down Expand Up @@ -1155,6 +1201,7 @@
B468E71224B3C3AC00E0C883 /* ObjcLDEvaluationDetail.swift in Sources */,
831EF34320655E730001C643 /* LDCommon.swift in Sources */,
831EF34420655E730001C643 /* LDConfig.swift in Sources */,
A31088212837DC0400184942 /* LDContext.swift in Sources */,
831EF34520655E730001C643 /* LDClient.swift in Sources */,
831EF34620655E730001C643 /* LDUser.swift in Sources */,
830DB3B02239B54900D65D25 /* URLResponse.swift in Sources */,
Expand All @@ -1163,10 +1210,12 @@
C443A40C2315AA4D00145710 /* NetworkReporter.swift in Sources */,
831EF34B20655E730001C643 /* LDChangedFlag.swift in Sources */,
8354AC722243166900CDE602 /* FeatureFlagCache.swift in Sources */,
A310881D2837DC0400184942 /* Kind.swift in Sources */,
C443A40423145FBE00145710 /* ConnectionInformation.swift in Sources */,
832D68A4224A38FC005F052A /* CacheConverter.swift in Sources */,
831EF34C20655E730001C643 /* FlagChangeObserver.swift in Sources */,
831EF34D20655E730001C643 /* FlagsUnchangedObserver.swift in Sources */,
A31088192837DC0400184942 /* Reference.swift in Sources */,
831EF34E20655E730001C643 /* Event.swift in Sources */,
C443A41123186A4F00145710 /* ConnectionModeChangeObserver.swift in Sources */,
831EF35020655E730001C643 /* ClientServiceFactory.swift in Sources */,
Expand Down Expand Up @@ -1217,10 +1266,13 @@
B4C9D4332489C8FD004A9B03 /* DiagnosticCache.swift in Sources */,
8354EFE51F263DAC00C05156 /* FeatureFlag.swift in Sources */,
8372668C20D4439600BD1088 /* DateFormatter.swift in Sources */,
A310881B2837DC0400184942 /* Kind.swift in Sources */,
A31088172837DC0400184942 /* Reference.swift in Sources */,
83A2D6241F51CD7A00EA3BD4 /* LDUser.swift in Sources */,
8354EFE21F26380700C05156 /* Event.swift in Sources */,
C408884923033B7500420721 /* ConnectionInformation.swift in Sources */,
831D8B721F71D3E700ED65E8 /* DarklyService.swift in Sources */,
A310881F2837DC0400184942 /* LDContext.swift in Sources */,
835E1D431F685AC900184DB4 /* ObjcLDChangedFlag.swift in Sources */,
8358F25E1F474E5900ECE1AF /* LDChangedFlag.swift in Sources */,
83D559741FD87CC9002D10C8 /* KeyedValueCache.swift in Sources */,
Expand Down Expand Up @@ -1263,6 +1315,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A31088272837DCA900184942 /* LDContextSpec.swift in Sources */,
83CFE7CE1F7AD81D0010544E /* EventReporterSpec.swift in Sources */,
8392FFA32033565700320914 /* HTTPURLResponse.swift in Sources */,
83411A5F1FABDA8700E5CF39 /* mocks.generated.swift in Sources */,
Expand All @@ -1278,6 +1331,7 @@
838F96741FB9F024009CFC45 /* LDClientSpec.swift in Sources */,
83E2E2061F9E7AC7007514E9 /* LDUserSpec.swift in Sources */,
83A0E6B1203B557F00224298 /* FeatureFlagSpec.swift in Sources */,
A31088282837DCA900184942 /* ReferenceSpec.swift in Sources */,
83EBCBB720DABE93003A7142 /* FlagRequestTrackerSpec.swift in Sources */,
B4265EB124E7390C001CFD2C /* TestUtil.swift in Sources */,
B46F344125E6DB7D0078D45F /* DiagnosticReporterSpec.swift in Sources */,
Expand All @@ -1299,6 +1353,7 @@
832307A61F7D8D720029815A /* URLRequestSpec.swift in Sources */,
832307A81F7DA61B0029815A /* LDEventSourceMock.swift in Sources */,
838F967A1FBA551A009CFC45 /* ClientServiceMockFactory.swift in Sources */,
A31088292837DCA900184942 /* KindSpec.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -1315,10 +1370,13 @@
83D9EC7C2062DEAB004D7FA6 /* FeatureFlag.swift in Sources */,
8372668D20D4439600BD1088 /* DateFormatter.swift in Sources */,
83D9EC7D2062DEAB004D7FA6 /* LDChangedFlag.swift in Sources */,
A310881C2837DC0400184942 /* Kind.swift in Sources */,
A31088182837DC0400184942 /* Reference.swift in Sources */,
83D9EC7E2062DEAB004D7FA6 /* FlagChangeObserver.swift in Sources */,
83D9EC7F2062DEAB004D7FA6 /* FlagsUnchangedObserver.swift in Sources */,
83D9EC802062DEAB004D7FA6 /* Event.swift in Sources */,
83D9EC822062DEAB004D7FA6 /* ClientServiceFactory.swift in Sources */,
A31088202837DC0400184942 /* LDContext.swift in Sources */,
83D9EC832062DEAB004D7FA6 /* KeyedValueCache.swift in Sources */,
831AAE2D20A9E4F600B46DBA /* Throttler.swift in Sources */,
C43C37E6238DF22B003C1624 /* LDEvaluationDetail.swift in Sources */,
Expand Down
79 changes: 79 additions & 0 deletions LaunchDarkly/LaunchDarkly/Models/Context/Kind.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import Foundation

public enum Kind: Codable, Equatable, Hashable {
case user
case multi
case custom(String)

public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()

switch try container.decode(String.self) {
case "user":
self = .user
case "multi":
self = .multi
case let custom:
self = .custom(custom)
}
}

public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(self.description)
}

public func isMulti() -> Bool {
self == .multi || self == .custom("multi")
}

public func isUser() -> Bool {
self == .user || self == .custom("user") || self == .custom("")
}

private static func isValid(_ description: String) -> Bool {
description.onlyContainsCharset(Util.validKindCharacterSet)
}
}

extension Kind: Comparable {
public static func < (lhs: Kind, rhs: Kind) -> Bool {
lhs.description < rhs.description
}

public static func == (lhs: Kind, rhs: Kind) -> Bool {
lhs.description == rhs.description
}
}

extension Kind: LosslessStringConvertible {
public init?(_ description: String) {
switch description {
case "kind":
return nil
case "multi":
self = .multi
case "", "user":
self = .user
default:
if !Kind.isValid(description) {
return nil
}

self = .custom(description)
}
}
}

extension Kind: CustomStringConvertible {
public var description: String {
switch self {
case .user:
return "user"
case .multi:
return "multi"
case let .custom(val):
return val
}
}
}
Loading

0 comments on commit a3a0e8a

Please sign in to comment.