This repository has been archived by the owner on Sep 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from spotify/transfer-codebase
Transfer codebase
- Loading branch information
Showing
50 changed files
with
3,061 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: CI | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- 'main' | ||
push: | ||
branches: | ||
- 'main' | ||
|
||
jobs: | ||
test: | ||
runs-on: macOS-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Build and Test | ||
run: swift test | ||
|
||
swiftlint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: GitHub Action for SwiftLint | ||
uses: norio-nomura/[email protected] | ||
with: | ||
args: --config .swiftlint.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/config/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc | ||
.build | ||
.mockingbird | ||
project.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"fileScopedDeclarationPrivacy" : { | ||
"accessLevel" : "private" | ||
}, | ||
"indentation" : { | ||
"spaces" : 4 | ||
}, | ||
"indentConditionalCompilationBlocks" : true, | ||
"indentSwitchCaseLabels" : false, | ||
"lineBreakAroundMultilineExpressionChainComponents" : false, | ||
"lineBreakBeforeControlFlowKeywords" : false, | ||
"lineBreakBeforeEachArgument" : false, | ||
"lineBreakBeforeEachGenericRequirement" : false, | ||
"lineLength" : 120, | ||
"maximumBlankLines" : 1, | ||
"prioritizeKeepingFunctionOutputTogether" : false, | ||
"respectsExistingLineBreaks" : true, | ||
"rules" : { | ||
"AllPublicDeclarationsHaveDocumentation" : false, | ||
"AlwaysUseLowerCamelCase" : true, | ||
"AmbiguousTrailingClosureOverload" : true, | ||
"BeginDocumentationCommentWithOneLineSummary" : false, | ||
"DoNotUseSemicolons" : true, | ||
"DontRepeatTypeInStaticProperties" : true, | ||
"FileScopedDeclarationPrivacy" : true, | ||
"FullyIndirectEnum" : true, | ||
"GroupNumericLiterals" : true, | ||
"IdentifiersMustBeASCII" : true, | ||
"NeverForceUnwrap" : false, | ||
"NeverUseForceTry" : false, | ||
"NeverUseImplicitlyUnwrappedOptionals" : false, | ||
"NoAccessLevelOnExtensionDeclaration" : true, | ||
"NoBlockComments" : true, | ||
"NoCasesWithOnlyFallthrough" : true, | ||
"NoEmptyTrailingClosureParentheses" : true, | ||
"NoLabelsInCasePatterns" : true, | ||
"NoLeadingUnderscores" : false, | ||
"NoParensAroundConditions" : true, | ||
"NoVoidReturnOnFunctionSignature" : true, | ||
"OneCasePerLine" : true, | ||
"OneVariableDeclarationPerLine" : true, | ||
"OnlyOneTrailingClosureArgument" : true, | ||
"OrderedImports" : true, | ||
"ReturnVoidInsteadOfEmptyTuple" : true, | ||
"UseEarlyExits" : false, | ||
"UseLetInEveryBoundCaseVariable" : true, | ||
"UseShorthandTypeNames" : true, | ||
"UseSingleLinePropertyGetter" : true, | ||
"UseSynthesizedInitializer" : true, | ||
"UseTripleSlashForDocumentationComments" : true, | ||
"UseWhereClausesInForLoops" : false, | ||
"ValidateDocumentationComments" : false | ||
}, | ||
"tabWidth" : 8, | ||
"version" : 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
excluded: | ||
- ${PWD}/Carthage | ||
- ${PWD}/Pods | ||
- ${PWD}/DerivedData | ||
- ${PWD}/.build | ||
- ${PWD}/Tools/.build | ||
- ${PWD}/Tests/OpenFeatureTests/MockingbirdMocks/ | ||
- ${PWD}/Sources/OpenFeature/FlagResolver | ||
|
||
disabled_rules: | ||
- discarded_notification_center_observer | ||
- notification_center_detachment | ||
- orphaned_doc_comment | ||
- todo | ||
- unused_capture_list | ||
- opening_brace | ||
|
||
analyzer_rules: | ||
- unused_import | ||
|
||
opt_in_rules: | ||
- array_init | ||
- attributes | ||
- closure_end_indentation | ||
- closure_spacing | ||
- collection_alignment | ||
- colon # promote to error | ||
- convenience_type | ||
- discouraged_object_literal | ||
- empty_collection_literal | ||
- empty_count | ||
- empty_string | ||
- enum_case_associated_values_count | ||
- fatal_error_message | ||
- first_where | ||
- force_unwrapping | ||
- implicitly_unwrapped_optional | ||
- indentation_width | ||
- last_where | ||
- legacy_random | ||
- literal_expression_end_indentation | ||
- multiline_arguments | ||
- multiline_function_chains | ||
- multiline_literal_brackets | ||
- multiline_parameters | ||
- multiline_parameters_brackets | ||
- operator_usage_whitespace | ||
- overridden_super_call | ||
- pattern_matching_keywords | ||
- prefer_self_type_over_type_of_self | ||
- redundant_nil_coalescing | ||
- redundant_type_annotation | ||
- strict_fileprivate | ||
- toggle_bool | ||
- trailing_closure | ||
- unneeded_parentheses_in_closure_argument | ||
- vertical_whitespace_closing_braces | ||
- vertical_whitespace_opening_braces | ||
- yoda_condition | ||
|
||
|
||
custom_rules: | ||
array_constructor: | ||
name: "Array/Dictionary initializer" | ||
regex: '[let,var] .+ = (\[.+\]\(\))' | ||
capture_group: 1 | ||
message: "Use explicit type annotation when initializing empty arrays and dictionaries" | ||
severity: warning | ||
|
||
|
||
attributes: | ||
always_on_same_line: | ||
- "@IBSegueAction" | ||
- "@IBAction" | ||
- "@NSManaged" | ||
- "@objc" | ||
|
||
force_cast: warning | ||
force_try: warning | ||
function_body_length: | ||
warning: 60 | ||
|
||
legacy_hashing: error | ||
|
||
identifier_name: | ||
excluded: | ||
- i | ||
- id | ||
- x | ||
- y | ||
- z | ||
|
||
indentation_width: | ||
indentation_width: 4 | ||
|
||
line_length: | ||
ignores_urls: true | ||
ignores_function_declarations: true | ||
ignores_comments: true | ||
|
||
multiline_arguments: | ||
first_argument_location: next_line | ||
only_enforce_after_first_closure_on_first_line: true | ||
|
||
private_over_fileprivate: | ||
validate_extensions: true | ||
|
||
trailing_comma: | ||
mandatory_comma: true | ||
|
||
trailing_whitespace: | ||
ignores_empty_lines: false | ||
ignores_comments: true | ||
|
||
vertical_whitespace: | ||
max_empty_lines: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// swift-tools-version: 5.5 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "OpenFeature", | ||
platforms: [ | ||
.iOS(.v14), | ||
.macOS(.v12) | ||
], | ||
products: [ | ||
.library( | ||
name: "OpenFeature", | ||
targets: ["OpenFeature"]) | ||
], | ||
dependencies: [ | ||
], | ||
targets: [ | ||
.target( | ||
name: "OpenFeature", | ||
dependencies: [] | ||
), | ||
.testTarget( | ||
name: "OpenFeatureTests", | ||
dependencies: ["OpenFeature"]) | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,58 @@ | ||
# openfeature-swift-sdk | ||
# OpenFeature | ||
|
||
Swift implementation of the OpenFeature SDK. | ||
|
||
## Usage | ||
|
||
### Adding the package dependency | ||
|
||
If you manage dependencies through Xcode go to "Add package" and enter `[email protected]:spotify/openfeature-swift-sdk.git`. | ||
|
||
If you manage dependencies through SPM, in the dependencies section of Package.swift add: | ||
```swift | ||
.package(url: "[email protected]:spotify/openfeature-swift-sdk.git", from: "0.1.0") | ||
``` | ||
|
||
and in the target dependencies section add: | ||
```swift | ||
.product(name: "OpenFeature", package: "openfeature-swift-sdk"), | ||
``` | ||
|
||
### Resolving a flag | ||
|
||
To enable the provider and start resolving flags add the following: | ||
|
||
```swift | ||
import OpenFeature | ||
|
||
// Change this to your actual provider | ||
OpenFeatureAPI.shared.provider = NoOpProvider() | ||
|
||
let client = OpenFeatureAPI.shared.getClient() | ||
let value = client.getBooleanValue(key: "flag", defaultValue: false) | ||
``` | ||
|
||
## Development | ||
|
||
Open the project in XCode and build by Product -> Build. | ||
|
||
### Linting code | ||
|
||
Code is automatically linted during build in XCode, if you need to manually lint: | ||
```shell | ||
brew install swiftlint | ||
swiftlint | ||
``` | ||
|
||
### Formatting code | ||
|
||
You can automatically format your code using: | ||
```shell | ||
./scripts/swift-format | ||
``` | ||
|
||
## Running tests from cmd-line | ||
|
||
```shell | ||
swift test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Foundation | ||
|
||
public protocol BaseEvaluation { | ||
associatedtype ValueType | ||
var value: ValueType { get } | ||
var variant: String? { get } | ||
var reason: String? { get } | ||
var errorCode: ErrorCode? { get } | ||
var errorMessage: String? { get } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Foundation | ||
|
||
/// Interface used to resolve flags of varying types. | ||
public protocol Client: Features { | ||
var metadata: Metadata { get } | ||
|
||
/// Return an optional client-level evaluation context. | ||
var evaluationContext: EvaluationContext? { get set } | ||
|
||
/// The hooks associated to this client. | ||
var hooks: [AnyHook] { get } | ||
|
||
/// Adds hooks for evaluation. | ||
/// Hooks are run in the order they're added in the before stage. They are run in reverse order for all | ||
/// other stages. | ||
func addHooks(_ hooks: AnyHook...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Foundation | ||
|
||
public protocol EvaluationContext: Structure { | ||
func getTargetingKey() -> String | ||
|
||
func setTargetingKey(targetingKey: String) | ||
|
||
func merge(overridingContext: EvaluationContext) -> EvaluationContext | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Foundation | ||
|
||
/// The interface implemented by upstream flag providers to resolve flags for their service. | ||
public protocol FeatureProvider { | ||
var hooks: [AnyHook] { get } | ||
var metadata: Metadata { get } | ||
|
||
func getBooleanEvaluation(key: String, defaultValue: Bool, ctx: EvaluationContext) throws -> ProviderEvaluation< | ||
Bool | ||
> | ||
func getStringEvaluation(key: String, defaultValue: String, ctx: EvaluationContext) throws -> ProviderEvaluation< | ||
String | ||
> | ||
func getIntegerEvaluation(key: String, defaultValue: Int64, ctx: EvaluationContext) throws -> ProviderEvaluation< | ||
Int64 | ||
> | ||
func getDoubleEvaluation(key: String, defaultValue: Double, ctx: EvaluationContext) throws -> ProviderEvaluation< | ||
Double | ||
> | ||
func getObjectEvaluation(key: String, defaultValue: Value, ctx: EvaluationContext) throws -> ProviderEvaluation< | ||
Value | ||
> | ||
} |
Oops, something went wrong.