Skip to content

Commit a828b3b

Browse files
committed
Initial commit
0 parents  commit a828b3b

File tree

52 files changed

+10774
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+10774
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Deploy Documentation
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
workflow_dispatch:
8+
9+
# Set permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages.
10+
permissions:
11+
contents: read
12+
id-token: write
13+
pages: write
14+
15+
# Allow one concurrent deployment. Do not cancel in-flight deployments because we don't want assets to be in a
16+
# a semi-deployed state.
17+
concurrency:
18+
group: "deploy-documentation"
19+
cancel-in-progress: false
20+
21+
jobs:
22+
deploy-documentation:
23+
environment:
24+
name: github-pages
25+
url: ${{ steps.deployment.outputs.page_url }}
26+
runs-on: macos-12
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v3
30+
- name: Set Up GitHub Pages
31+
uses: actions/configure-pages@v3
32+
- name: Build Documentation
33+
run: |
34+
xcodebuild docbuild \
35+
-scheme URLQueryItemCoder \
36+
-derivedDataPath /tmp/DerivedData \
37+
-destination 'generic/platform=iOS';
38+
mkdir _site;
39+
$(xcrun --find docc) process-archive \
40+
transform-for-static-hosting /tmp/DerivedData/Build/Products/Debug-iphoneos/URLQueryItemCoder.doccarchive \
41+
--hosting-base-path URLQueryItemCoder \
42+
--output-path _site;
43+
- name: Create index.html
44+
run: |
45+
echo "<script>window.location.href += \"/documentation/urlqueryitemcoder\"</script>" > _site/index.html;
46+
- name: Upload Documentation Artifact to GitHub Pages
47+
uses: actions/upload-pages-artifact@v1
48+
- name: Deploy to GitHub Pages
49+
id: deployment
50+
uses: actions/deploy-pages@v2

.github/workflows/test.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
concurrency:
13+
group: ${{ github.ref_name }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
get-environment-details:
18+
name: Get Environment Details
19+
runs-on: macOS-12
20+
steps:
21+
- name: Print OS SDKs
22+
run: xcodebuild -version -sdk
23+
24+
- name: Print simulators
25+
run: |
26+
xcrun simctl delete unavailable
27+
xcrun simctl list
28+
29+
test-iOS:
30+
name: Test on Latest iOS
31+
runs-on: macOS-12
32+
steps:
33+
- name: Checkout project
34+
uses: actions/checkout@master
35+
36+
- name: Run tests
37+
run: |
38+
set -o pipefail
39+
xcodebuild clean test -scheme URLQueryItemCoder -sdk iphonesimulator -destination "name=iPhone 14 Pro" -configuration Debug -enableCodeCoverage YES | xcpretty -c
40+
41+
test-macOS:
42+
name: Test on Latest macOS
43+
runs-on: macOS-12
44+
steps:
45+
- name: Checkout Project
46+
uses: actions/checkout@master
47+
48+
- name: Run Tests
49+
run: swift test
50+
51+
test-tvOS:
52+
name: Test on Latest tvOS
53+
runs-on: macOS-12
54+
steps:
55+
- name: Checkout project
56+
uses: actions/checkout@master
57+
58+
- name: Run tests
59+
run: |
60+
set -o pipefail
61+
xcodebuild clean test -scheme URLQueryItemCoder -sdk appletvsimulator -destination "name=Apple TV 4K (3rd generation)" -configuration Debug -enableCodeCoverage YES | xcpretty -c
62+
63+
test-watchOS:
64+
name: Test on Latest watchOS
65+
runs-on: macOS-12
66+
steps:
67+
- name: Checkout project
68+
uses: actions/checkout@master
69+
70+
- name: Run tests
71+
run: |
72+
set -o pipefail
73+
xcodebuild clean test -scheme URLQueryItemCoder -sdk watchsimulator -destination "name=Apple Watch Ultra (49mm)" -configuration Debug -enableCodeCoverage YES | xcpretty -c

.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.DS_Store
2+
__MACOSX
3+
*.pbxuser
4+
!default.pbxuser
5+
*.mode1v3
6+
!default.mode1v3
7+
*.mode2v3
8+
!default.mode2v3
9+
*.perspectivev3
10+
!default.perspectivev3
11+
*.xcworkspace
12+
!default.xcworkspace
13+
xcuserdata
14+
profile
15+
*.moved-aside
16+
DerivedData
17+
.idea/
18+
Crashlytics.sh
19+
generatechangelog.sh
20+
Pods/
21+
Carthage
22+
Provisioning
23+
Crashlytics.sh
24+
.swiftpm
25+
.build

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2023 Kyle Hughes
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// swift-tools-version: 5.7
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "URLQueryItemCoder",
7+
platforms: [
8+
.iOS(.v13),
9+
.macOS(.v10_15),
10+
.tvOS(.v13),
11+
.watchOS(.v6),
12+
],
13+
products: [
14+
.library(
15+
name: "URLQueryItemCoder",
16+
targets: [
17+
"URLQueryItemCoder",
18+
]
19+
),
20+
],
21+
dependencies: [],
22+
targets: [
23+
.target(
24+
name: "URLQueryItemCoder",
25+
dependencies: []
26+
),
27+
.testTarget(
28+
name: "URLQueryItemCoderTests",
29+
dependencies: [
30+
"URLQueryItemCoder",
31+
]
32+
),
33+
]
34+
)

README.md

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# URLQueryItemCoder
2+
3+
[![Test](https://github.com/kylehughes/URLQueryItemCoder/actions/workflows/test.yml/badge.svg)](https://github.com/kylehughes/URLQueryItemCoder/actions/workflows/test.yml)
4+
5+
*Encoder & decoder for working with `Codable` types as `URLQueryItem`s.*
6+
7+
## About
8+
9+
URLQueryItemCoder provides an implementation of Swift's `Encoder` protocol suitable for encoding an `Encodable` type as
10+
an array of `URLQueryItem`s, and an implementation of Swift's `Decoder` protocol suitable for decoding a `Decodable`
11+
type from an array of `URLQueryItem`s.
12+
13+
This allows us to lift `URLQueryItem` requirements into the type system (e.g. modeling an `HTTP GET` API).
14+
15+
### Capabilities
16+
17+
URLQueryItemCoder is an exhaustive implementation with an exhaustive test suite.
18+
19+
#### Standard
20+
21+
All standard features expected by the protocols are supported.
22+
23+
- [x] Single-value containers
24+
- [x] Keyed containers
25+
- [x] Unkeyed containers
26+
- [x] Nested containers
27+
- [x] Inheritance
28+
29+
#### Extra
30+
31+
All extra features offered by Swift's JSON implementations are supported.
32+
33+
- [x] `Data` special treatment
34+
- [x] `Date` special treatment
35+
- [x] `Double` & `Float` special treatment
36+
- [x] Key conversions
37+
- [x] Sorted keys
38+
39+
## Usage
40+
41+
### Encoding
42+
43+
`URLQueryItemEncoder` can be configured through its initializer or `strategies` and `outputFormatting` properties.
44+
45+
For example, given…
46+
47+
```swift
48+
import URLQueryItemCoder
49+
50+
struct Interval: Codable {
51+
let start: Date
52+
let end: Date
53+
}
54+
55+
struct GetPostsQuery: Codable {
56+
let interval: Interval
57+
let userID: String
58+
}
59+
60+
let interval = Interval(start: .now.addingTimeInterval(-1_000), end: .now)
61+
let query = GetPostsQuery(interval: interval, userID: "123abc")
62+
```
63+
64+
Then…
65+
66+
```swift
67+
let encoder = URLQueryItemEncoder(dateStrategy: .secondsSince1970)
68+
let queryItems = try! encoder.encode(query)
69+
// [
70+
// URLQueryItem(name: "interval.end", value: "1681256918.240762"),
71+
// URLQueryItem(name: "interval.start", value: "1681255918.240762"),
72+
// URLQueryItem(name: "userID", value: "123abc"),
73+
// ]
74+
```
75+
76+
### Decoding
77+
78+
`URLQueryItemDecoder` can be configured through its initializer or `strategy` property.
79+
80+
For example, given…
81+
82+
```swift
83+
import URLQueryItemCoder
84+
85+
struct GetPostsQuery: Codable {
86+
struct Interval: Codable {
87+
let start: Date
88+
let end: Date
89+
}
90+
91+
let interval: Interval
92+
let userID: String
93+
}
94+
95+
let queryItems = [
96+
URLQueryItem(name: "interval.start", value: "1681255918.240762"),
97+
URLQueryItem(name: "interval.end", value: "1681256918.240762"),
98+
URLQueryItem(name: "userID", value: "123abc"),
99+
]
100+
```
101+
102+
Then…
103+
104+
```swift
105+
let decoder = URLQueryItemDecoder(dateStrategy: .secondsSince1970)
106+
let query = try! decoder.decode(GetPostsQuery.self, from: queryItems)
107+
// GetPostsQuery(
108+
// interval: Interval(start: 1681255918.240762, end: 1681256918.240762),
109+
// userID: "123abc"
110+
// )
111+
```
112+
113+
## Supported Platforms
114+
115+
- iOS
116+
- macOS
117+
- tvOS
118+
- watchOS
119+
120+
## Requirements
121+
122+
- Swift 5.7+
123+
124+
## Installation
125+
126+
### Swift Package Manager
127+
128+
```swift
129+
dependencies: [
130+
.package(url: "https://github.com/kylehughes/URLQueryItemCoder.git", .upToNextMajor(from: "1.0.0")),
131+
]
132+
```
133+
134+
## Documentation
135+
136+
[Documentation is available on GitHub Pages.](https://kylehughes.github.io/URLQueryItemCoder).
137+
138+
## Contributions
139+
140+
URLQueryItemCoder is not accepting source contributions at this time. Bug reports will be considered.
141+
142+
## Author
143+
144+
[Kyle Hughes](https://kylehugh.es)
145+
146+
[![my Mastodon][social_image]][social_url]
147+
148+
[social_image]: https://img.shields.io/mastodon/follow/109356914477272810?domain=https%3A%2F%2Fmister.computer&style=social
149+
[social_url]: https://mister.computer/@kyle
150+
151+
## License
152+
153+
URLQueryItemCoder is available under the MIT license.
154+
155+
See `LICENSE` for details.

0 commit comments

Comments
 (0)