Skip to content

Commit

Permalink
5.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdeem committed Jan 1, 2025
2 parents 3a6acca + a285ce1 commit 19c997e
Show file tree
Hide file tree
Showing 39 changed files with 1,116 additions and 145 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
jobs:
build:
runs-on: macos-latest
env:
DEVELOPER_DIR: /Applications/Xcode_16.1.app/Contents/Developer
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -20,9 +22,8 @@ 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@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
verbose: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store
.build
.swiftpm
.vscode
Package.resolved
2 changes: 1 addition & 1 deletion .spi.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
builder:
configs:
- documentation_targets: [ScreamURITemplate]
- documentation_targets: [ScreamURITemplate, ScreamURITemplateMacros]
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.9
6.0
3 changes: 3 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ trailing_comma:

vertical_whitespace:
max_empty_lines: 2

nesting:
type_level: 2
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

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

<a name="5.0.0"></a>
# [5.0.0](https://github.com/SwiftScream/URITemplate/compare/4.0.0...5.0.0) (2025-01-02)

- Move to swift 6.0 as minimum supported version
- Leverage typed-throws
- Add #URITemplate freestanding expression macro
- Add #URLByExpandingURITemplate freestanding expression macro
- Add @VariableProvider attached macro to provide default implementqation of `VariableProvider`
- Add TypedURITemplate enabling a type-safe process interface

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

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@0.55.1
nicklockwood/SwiftFormat@0.53.10
realm/SwiftLint@0.57.1
nicklockwood/SwiftFormat@0.55.3
25 changes: 0 additions & 25 deletions Package.resolved

This file was deleted.

30 changes: 25 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
// swift-tools-version: 5.9
// swift-tools-version: 6.0

import CompilerPluginSupport
import PackageDescription

let package = Package(
name: "ScreamURITemplate",
platforms: [.macOS(.v13)],
products: [
.library(
name: "ScreamURITemplate",
targets: ["ScreamURITemplate"]),
.library(
name: "ScreamURITemplateMacros",
targets: ["ScreamURITemplateMacros"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-syntax", from: "600.0.1"),
],
targets: [
.target(
name: "ScreamURITemplate",
dependencies: []),
resources: [.process("PrivacyInfo.xcprivacy")]),
.target(
name: "ScreamURITemplateMacros",
dependencies: ["ScreamURITemplate", "ScreamURITemplateCompilerPlugin"]),
.macro(
name: "ScreamURITemplateCompilerPlugin",
dependencies: [
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
"ScreamURITemplate",
]),
.testTarget(
name: "ScreamURITemplateTests",
dependencies: ["ScreamURITemplate"],
dependencies: [
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
"ScreamURITemplate",
"ScreamURITemplateCompilerPlugin",
],
exclude: [
"data/uritemplate-test/json2xml.xslt",
"data/uritemplate-test/LICENSE",
Expand All @@ -34,6 +54,6 @@ let package = Package(
]),
.executableTarget(
name: "ScreamURITemplateExample",
dependencies: ["ScreamURITemplate"]),
dependencies: ["ScreamURITemplate", "ScreamURITemplateMacros"]),
],
swiftLanguageVersions: [.v5])
swiftLanguageModes: [.v6])
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ScreamURITemplate

A robust and performant Swift 5 implementation of [RFC6570](https://tools.ietf.org/html/rfc6570) URI Template. Full Level 4 support is provided.
A robust and performant Swift 6 implementation of [RFC6570](https://tools.ietf.org/html/rfc6570) URI Template. Full Level 4 support is provided.

[![CI](https://github.com/SwiftScream/URITemplate/actions/workflows/ci.yml/badge.svg)](https://github.com/SwiftScream/URITemplate/actions/workflows/ci.yml)
[![Codecov branch](https://img.shields.io/codecov/c/github/SwiftScream/URITemplate/master.svg)](https://codecov.io/gh/SwiftScream/URITemplate/branch/master)
Expand All @@ -13,7 +13,7 @@ A robust and performant Swift 5 implementation of [RFC6570](https://tools.ietf.o
## Getting Started

### Swift Package Manager
Add `.package(url: "https://github.com/SwiftScream/URITemplate.git", from: "3.0.0")` to your Package.swift dependencies
Add `.package(url: "https://github.com/SwiftScream/URITemplate.git", from: "5.0.0")` to your Package.swift dependencies

## Usage

Expand All @@ -35,9 +35,9 @@ The error cases contain associated values specifying a string reason for the err
```swift
do {
_ = try URITemplate(string: "https://api.github.com/repos/{}/{repository}")
} catch URITemplate.Error.malformedTemplate(let position, let reason) {
// reason = "Empty Variable Name"
// position = 29th character
} catch {
// error.reason = "Empty Variable Name"
// error.position = 29th character
}
```

Expand Down
2 changes: 1 addition & 1 deletion Sources/ScreamURITemplate/Internal/CharacterSets.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018-2024 Alex Deem
// Copyright 2018-2025 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 Down
51 changes: 29 additions & 22 deletions Sources/ScreamURITemplate/Internal/Components.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018-2024 Alex Deem
// Copyright 2018-2025 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 @@ -17,7 +17,7 @@ import Foundation
typealias ComponentBase = Sendable

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

Expand All @@ -33,10 +33,10 @@ struct LiteralComponent: Component {
literal = string
}

func expand(variables _: TypedVariableProvider) throws -> String {
func expand(variables _: TypedVariableProvider) throws(URITemplate.Error) -> String {
let expansion = String(literal)
guard let encodedExpansion = expansion.addingPercentEncoding(withAllowedCharacters: reservedAndUnreservedCharacterSet) else {
throw URITemplate.Error.expansionFailure(position: literal.startIndex, reason: "Percent Encoding Failed")
throw URITemplate.Error(type: .expansionFailure, position: literal.startIndex, reason: "Percent Encoding Failed")
}
return encodedExpansion
}
Expand All @@ -48,7 +48,7 @@ struct LiteralPercentEncodedTripletComponent: Component {
literal = string
}

func expand(variables _: TypedVariableProvider) throws -> String {
func expand(variables _: TypedVariableProvider) throws(URITemplate.Error) -> String {
return String(literal)
}
}
Expand All @@ -64,28 +64,35 @@ struct ExpressionComponent: Component {
self.templatePosition = templatePosition
}

func expand(variables: TypedVariableProvider) throws -> String {
func expand(variables: TypedVariableProvider) throws(URITemplate.Error) -> String {
let configuration = expressionOperator.expansionConfiguration()
let expansions = try variableList.compactMap { variableSpec -> String? in
guard let value = variables[String(variableSpec.name)] else {
return nil
do {
let expansions = try variableList.compactMap { variableSpec throws(URITemplate.Error) -> String? in
guard let value = variables[String(variableSpec.name)] else {
return nil
}
do throws(FormatError) {
return try value.formatForTemplateExpansion(variableSpec: variableSpec, expansionConfiguration: configuration)
} catch {
throw URITemplate.Error(type: .expansionFailure, position: templatePosition, reason: "Failed expanding variable \"\(variableSpec.name)\": \(error.reason)")
}
}
do {
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)")
}
}

if expansions.count == 0 {
return ""
}
if expansions.count == 0 {
return ""
}

let joinedExpansions = expansions.joined(separator: configuration.separator)
if let prefix = configuration.prefix {
return prefix + joinedExpansions
let joinedExpansions = expansions.joined(separator: configuration.separator)
if let prefix = configuration.prefix {
return prefix + joinedExpansions
}
return joinedExpansions
} catch let error as URITemplate.Error {
throw error
} catch {
// compactMap is not marked up for Typed Throws, the compiler therefore does not know that this is not possible
throw URITemplate.Error(type: .expansionFailure, position: templatePosition, reason: "Failed expanding variable: \(error.localizedDescription)")
}
return joinedExpansions
}

var variableNames: [String] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018-2024 Alex Deem
// Copyright 2018-2025 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 Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018-2024 Alex Deem
// Copyright 2018-2025 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 Down
Loading

0 comments on commit 19c997e

Please sign in to comment.