Skip to content

Commit

Permalink
4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdeem committed Jun 13, 2024
2 parents 3d8e9dc + 220a283 commit 3a6acca
Show file tree
Hide file tree
Showing 26 changed files with 595 additions and 233 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ updates:
day: "friday"
timezone: "Australia/Sydney"
target-branch: "develop"

- package-ecosystem: "swift"
directory: "/"
schedule:
interval: "weekly"
day: "friday"
timezone: "Australia/Sydney"
target-branch: "develop"
20 changes: 4 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Build
Expand All @@ -20,21 +20,9 @@ jobs:
- name: Prepare coverage file
run: xcrun llvm-cov export -format="lcov" .build/debug/ScreamURITemplatePackageTests.xctest/Contents/MacOS/ScreamURITemplatePackageTests -instr-profile .build/debug/codecov/default.profdata > info.lcov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
fail_ci_if_error: true
verbose: true

build-5_4_2:
runs-on: macos-11
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Check Swift version
run: |
sudo xcode-select -s /Applications/Xcode_12.5.1.app/
export TOOLCHAINS=swift
swift --version
- name: Run tests
run: swift test
8 changes: 4 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ on:

jobs:
SwiftLint:
runs-on: ubuntu-latest
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: irgaly/setup-mint@v1
- name: SwiftLint
run: mint run swiftlint --strict
SwiftFormat:
runs-on: ubuntu-latest
runs-on: macos-latest
needs: SwiftLint
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: irgaly/setup-mint@v1
- name: SwiftFormat Lint
run: mint run swiftformat --lint .
4 changes: 4 additions & 0 deletions .spi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: 1
builder:
configs:
- documentation_targets: [ScreamURITemplate]
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.9
1 change: 0 additions & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
--swiftversion 5.7
--exclude .build

# rules
Expand Down
7 changes: 6 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
disabled_rules:
- line_length
- trailing_comma
- redundant_optional_initialization

opt_in_rules:
- missing_docs

included:

excluded:
.build

trailing_comma:
mandatory_comma: true

vertical_whitespace:
max_empty_lines: 2
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file.

<a name="4.0.0"></a>
# [4.0.0](https://github.com/SwiftScream/URITemplate/compare/3.1.0...4.0.0) (2024-06-13)

- Refine interface for specifying variables
- Add docc documentation
- Move to swift 5.9 as minimum supported version


<a name="3.1.0"></a>
# [3.1.0](https://github.com/SwiftScream/URITemplate/compare/3.0.1...3.1.0) (2023-01-20)

Expand Down
4 changes: 2 additions & 2 deletions Mintfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
realm/SwiftLint
nicklockwood/SwiftFormat
realm/SwiftLint@0.55.1
nicklockwood/SwiftFormat@0.53.10
25 changes: 25 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"object": {
"pins": [
{
"package": "SwiftDocCPlugin",
"repositoryURL": "https://github.com/apple/swift-docc-plugin",
"state": {
"branch": null,
"revision": "26ac5758409154cc448d7ab82389c520fa8a8247",
"version": "1.3.0"
}
},
{
"package": "SymbolKit",
"repositoryURL": "https://github.com/apple/swift-docc-symbolkit",
"state": {
"branch": null,
"revision": "b45d1f2ed151d057b54504d653e0da5552844e34",
"version": "1.0.0"
}
}
]
},
"version": 1
}
20 changes: 11 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.4
// swift-tools-version: 5.9

import PackageDescription

Expand All @@ -10,6 +10,7 @@ let package = Package(
targets: ["ScreamURITemplate"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
],
targets: [
.target(
Expand All @@ -18,20 +19,21 @@ let package = Package(
.testTarget(
name: "ScreamURITemplateTests",
dependencies: ["ScreamURITemplate"],
exclude: [
"data/uritemplate-test/json2xml.xslt",
"data/uritemplate-test/LICENSE",
"data/uritemplate-test/README.md",
"data/uritemplate-test/transform-json-tests.xslt",
],
resources: [
.process("data/tests.json"),
.process("data/uritemplate-test/spec-examples.json"),
.process("data/uritemplate-test/spec-examples-by-section.json"),
.process("data/uritemplate-test/extended-tests.json"),
.process("data/uritemplate-test/negative-tests.json"),
]),
],
swiftLanguageVersions: [.v5])

#if swift(>=5.6) || os(macOS) || os(Linux)
package.targets.append(
.executableTarget(
name: "ScreamURITemplateExample",
dependencies: ["ScreamURITemplate"])
)
#endif
dependencies: ["ScreamURITemplate"]),
],
swiftLanguageVersions: [.v5])
22 changes: 11 additions & 11 deletions Sources/ScreamURITemplate/Internal/CharacterSets.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018-2023 Alex Deem
// Copyright 2018-2024 Alex Deem
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -14,15 +14,15 @@

import Foundation

internal let unreservedCharacterSet = CharacterSet.alphanumerics.union(CharacterSet(charactersIn: "-._~"))
let unreservedCharacterSet = CharacterSet.alphanumerics.union(CharacterSet(charactersIn: "-._~"))
private let genDelimsCharacterSet = CharacterSet(charactersIn: ":/?#[]@")
private let subDelimsCharacterSet = CharacterSet(charactersIn: "!$&'()*+,;=")
internal let reservedCharacterSet = genDelimsCharacterSet.union(subDelimsCharacterSet)
internal let reservedAndUnreservedCharacterSet = reservedCharacterSet.union(unreservedCharacterSet)
internal let invertedLiteralCharacterSet = CharacterSet.illegalCharacters.union(CharacterSet.controlCharacters).union(CharacterSet(charactersIn: " \"%<>\\^`{|}"))
internal let literalCharacterSet = invertedLiteralCharacterSet.inverted
internal let hexCharacterSet = CharacterSet(charactersIn: "0123456789abcdefABCDEF")
internal let varnameCharacterSet = CharacterSet.alphanumerics.union(CharacterSet(charactersIn: "_%."))
internal let invertedVarnameCharacterSet = varnameCharacterSet.inverted
internal let expressionOperatorCharacterSet = CharacterSet(charactersIn: "+#./;?&=,!@|")
internal let invertedDecimalDigitsCharacterSet = CharacterSet.decimalDigits.inverted
let reservedCharacterSet = genDelimsCharacterSet.union(subDelimsCharacterSet)
let reservedAndUnreservedCharacterSet = reservedCharacterSet.union(unreservedCharacterSet)
let invertedLiteralCharacterSet = CharacterSet.illegalCharacters.union(CharacterSet.controlCharacters).union(CharacterSet(charactersIn: " \"%<>\\^`{|}"))
let literalCharacterSet = invertedLiteralCharacterSet.inverted
let hexCharacterSet = CharacterSet(charactersIn: "0123456789abcdefABCDEF")
let varnameCharacterSet = CharacterSet.alphanumerics.union(CharacterSet(charactersIn: "_%."))
let invertedVarnameCharacterSet = varnameCharacterSet.inverted
let expressionOperatorCharacterSet = CharacterSet(charactersIn: "+#./;?&=,!@|")
let invertedDecimalDigitsCharacterSet = CharacterSet.decimalDigits.inverted
49 changes: 11 additions & 38 deletions Sources/ScreamURITemplate/Internal/Components.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018-2023 Alex Deem
// Copyright 2018-2024 Alex Deem
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -14,14 +14,10 @@

import Foundation

#if swift(>=5.5)
internal typealias ComponentBase = Sendable
#else
internal protocol ComponentBase {}
#endif
typealias ComponentBase = Sendable

internal protocol Component: ComponentBase {
func expand(variables: [String: VariableValue]) throws -> String
protocol Component: ComponentBase {
func expand(variables: TypedVariableProvider) throws -> String
var variableNames: [String] { get }
}

Expand All @@ -31,13 +27,13 @@ extension Component {
}
}

internal struct LiteralComponent: Component {
struct LiteralComponent: Component {
let literal: Substring
init(_ string: Substring) {
literal = string
}

func expand(variables _: [String: VariableValue]) throws -> String {
func expand(variables _: TypedVariableProvider) throws -> String {
let expansion = String(literal)
guard let encodedExpansion = expansion.addingPercentEncoding(withAllowedCharacters: reservedAndUnreservedCharacterSet) else {
throw URITemplate.Error.expansionFailure(position: literal.startIndex, reason: "Percent Encoding Failed")
Expand All @@ -46,18 +42,18 @@ internal struct LiteralComponent: Component {
}
}

internal struct LiteralPercentEncodedTripletComponent: Component {
struct LiteralPercentEncodedTripletComponent: Component {
let literal: Substring
init(_ string: Substring) {
literal = string
}

func expand(variables _: [String: VariableValue]) throws -> String {
func expand(variables _: TypedVariableProvider) throws -> String {
return String(literal)
}
}

internal struct ExpressionComponent: Component {
struct ExpressionComponent: Component {
let expressionOperator: ExpressionOperator
let variableList: [VariableSpec]
let templatePosition: String.Index
Expand All @@ -68,37 +64,14 @@ internal struct ExpressionComponent: Component {
self.templatePosition = templatePosition
}

// swiftlint:disable:next cyclomatic_complexity
func expand(variables: [String: VariableValue]) throws -> String {
func expand(variables: TypedVariableProvider) throws -> String {
let configuration = expressionOperator.expansionConfiguration()
let expansions = try variableList.compactMap { variableSpec -> String? in
guard let value = variables[String(variableSpec.name)] else {
return nil
}
do {
if let stringValue = value as? String {
return try stringValue.formatForTemplateExpansion(variableSpec: variableSpec, expansionConfiguration: configuration)
} else if let arrayValue = value as? [String] {
switch variableSpec.modifier {
case .prefix:
throw FormatError.failure(reason: "Prefix operator can only be applied to string")
case .explode:
return try arrayValue.explodeForTemplateExpansion(variableSpec: variableSpec, expansionConfiguration: configuration)
case .none:
return try arrayValue.formatForTemplateExpansion(variableSpec: variableSpec, expansionConfiguration: configuration)
}
} else if let dictionaryValue = value as? [String: String] {
switch variableSpec.modifier {
case .prefix:
throw FormatError.failure(reason: "Prefix operator can only be applied to string")
case .explode:
return try dictionaryValue.explodeForTemplateExpansion(variableSpec: variableSpec, expansionConfiguration: configuration)
case .none:
return try dictionaryValue.formatForTemplateExpansion(variableSpec: variableSpec, expansionConfiguration: configuration)
}
} else {
throw FormatError.failure(reason: "Invalid Value Type")
}
return try value.formatForTemplateExpansion(variableSpec: variableSpec, expansionConfiguration: configuration)
} catch let FormatError.failure(reason) {
throw URITemplate.Error.expansionFailure(position: templatePosition, reason: "Failed expanding variable \"\(variableSpec.name)\": \(reason)")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018-2023 Alex Deem
// Copyright 2018-2024 Alex Deem
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -14,11 +14,11 @@

import Foundation

internal struct ExpansionConfiguration {
struct ExpansionConfiguration {
let percentEncodingAllowedCharacterSet: CharacterSet
let allowPercentEncodedTriplets: Bool
let prefix: String?
let separator: String
let named: Bool
let omittOrphanedEquals: Bool
let omitOrphanedEquals: Bool
}
Loading

0 comments on commit 3a6acca

Please sign in to comment.