Skip to content

Commit

Permalink
🚀 Prepare for Jenson v2
Browse files Browse the repository at this point in the history
This commit makes several changes to both the Jenson format and the
internal implementations.

First, the Code of Conduct, SwiftFormat configuration, and SwiftLint
configuration files have been copied from Indexing Your Heart as
this package is governed under the organization.

Next, most of the structs included in this package now conform to
Identifiable, Equatable, and Hashable. This will prove useful for
SwiftUI apps that utilize these structs.

Finally, the package has been updated to support Jenson v2, which
includes a new refresh event, an optional application field for
third-party apps and/or APIs, and a story metadata field.

Signed-off-by: Marquis Kurt <[email protected]>
  • Loading branch information
alicerunsonfedora committed Sep 12, 2022
1 parent a2c9ade commit 51d3979
Show file tree
Hide file tree
Showing 14 changed files with 440 additions and 69 deletions.
53 changes: 53 additions & 0 deletions .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Code of Conduct

The Indexing Your Heart project strives to maintain a healthy community that focuses on creating quality content that represents the best the community has to offer. We want to have a healthy, productive community that is willing to take risks and foster relationships with others in an effort to create an inclusive environment that embodies the premise of Indexing Your Heart.

This Code of Conduct describes and governs how the community should act in both the public and private spheres, whenever the project’s reputation is at stake.

- **Code of Conduct Attributions**

This code of conduct is loosely based off of the Ubuntu Code of Conduct from the Ubuntu Project. You can view the code of conduct at [https://ubuntu.com/community/code-of-conduct](https://ubuntu.com/community/code-of-conduct).

Likewise, some inspiration comes from The Contributor Covenant Code of Conduct, which you can access at [https://www.contributor-covenant.org/version/2/0/code_of_conduct/](https://www.contributor-covenant.org/version/2/0/code_of_conduct/).

## Key tenets and goals

### Be respectful

Respect for others is a must have for the project and the community. Every community member is a human, and we must respect that, regardless of background. We will not tolerate hate speech or any form of disrespect that makes anyone in our community feel threatened or uncomfortable.

### Take responsibility for our actions

Every member in the Indexing Your Heart community is a human; naturally, we all make mistakes. When we take responsibility for our actions, we recognize this fact and allow ourselves to correct the wrong and strive to do better.

### Promote collaboration

Some of our best work happens when we collaborate with each other. Fostering an environment that allows for others to contribute ideas, challenge assumptions, and seek to improve the project is critical to making Indexing Your Heart successful.

## Leadership

The Indexing Your Heart community will be governed by the “benevolent dictator”, who delegates community standards enforcement to the Project Council (PC). They will be responsible for overseeing the community and enforcing standards for behavior as defined in this Code of Conduct, in addition to being the best representatives of this Code of Conduct.

This leadership should not be taken lightly, as it is a *privilege* above all else; their power remains effective on the project insofar as the community willingly follows them.

## Enforcement guidelines

The following system will be the framework used to determine the consequences of an offender’s actions that a member of the PC or the “benevolent dictator” has determined violates this Code of Conduct, depending on the severity of the action. Examples are provided for each step in the system, but note that each system is not limited to those examples.

### 1. Written warning

**Examples**: Inappropriate language

A written warning will be issued to the offender upon the first time the Code of Conduct is violated, giving them the opportunity to correct their wrong. A public apology may be requested.

### 2. Temporary ban

**Examples**: Repeated offenses where written warnings were issued

A temporary ban will be placed on the offender for seven consecutive days. They will not be able to communicate with the project or contribute to source code for a the period of time specified.

### 3. Permanent ban

**Examples**: Hate speech, threats, severe damage to the project, or continuous repeat offenses

A permanent ban will be placed on the offender, and the project will sever all ties with the offender. They will not be able to participate in the project.
12 changes: 12 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--maxwidth 120
--binarygrouping none
--commas inline
--decimalgrouping none
--hexgrouping none
--ifdef outdent
--octalgrouping none
--patternlet inline
--semicolons never
--wraparguments before-first
--wrapcollections before-first
--wrapparameters before-first
58 changes: 58 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
disabled_rules:
- force_try
- duplicate_imports
- function_body_length

opt_in_rules:
- file_header
- empty_count
- inclusive_language

included:
- Shared
- Tests

type_name:
allowed_symbols: ["_"]

type_body_length:
warning: 250
error: 400

file_length:
warning: 500
error: 1000

file_header:
required_pattern: |
\/\/
\/\/ .*?\.swift
\/\/ Indexing Your Heart
\/\/
\/\/ Created by .*? on \d{1,2}\/\d{1,2}\/\d{2}\.
\/\/
\/\/ This file is part of Indexing Your Heart\.
\/\/
\/\/ Indexing Your Heart is non-violent software: you can use, redistribute, and\/or modify it under the terms of the
\/\/ CNPLv7\+ as found in the LICENSE file in the source code root directory or at
\/\/ \<https:\/\/git\.pixie\.town\/thufie\/npl-builder\>\.
\/\/
\/\/ Indexing Your Heart comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law\. See the CNPL for
\/\/ details\.
custom_rules:
no_capstone_name:
name: "Require Public-facing Name"
regex: "(Head Over Heels)"
capture_group: 0
match_kinds:
- comment
- identifier
- string
message: "Refer to the project by its public-facing name, Indexing Your Heart."
severity: warning
unneeded_filter:
name: "Possible Unneeded Filter"
regex: ".filter(\\s?)\\{(.+)\\}\\s+for (\\w+) in (\\w+) \\{\\s*(.+)\\s*\\}"
message: "Filter might be unneeded; try using the for-where clause to iterate over a filter."
severity: warning
7 changes: 4 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let package = Package(
platforms: [.iOS(.v15), .macOS(.v12), .macCatalyst(.v15), .tvOS(.v15)],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(name: "JensonKit", targets: ["JensonKit"]),
.library(name: "JensonKit", targets: ["JensonKit"])
],
dependencies: [
// Dependencies declare other packages that this package depends on.
Expand All @@ -19,13 +19,14 @@ let package = Package(
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "JensonKit",
dependencies: []),
dependencies: []
),
.testTarget(
name: "JensonKitTests",
dependencies: ["JensonKit"],
resources: [
.process("Resources")
]
),
)
]
)
17 changes: 17 additions & 0 deletions Sources/JensonKit/Aliases.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Aliases.swift
// Created by Marquis Kurt on 9/12/22.
// This file is part of Indexing Your Heart.
//
// Indexing Your Heart is non-violent software: you can use, redistribute, and/or modify it under the terms of the
// CNPLv7+ as found in the LICENSE file in the source code root directory or at
// <https://git.pixie.town/thufie/npl-builder>.
//
// Indexing Your Heart comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. See the CNPL for
// details.

import Foundation

/// A typealias that indicates an object is able to be identified in a random access collection.
/// This is typically used for objects that will be used in `ForEach` structs in SwiftUI or other equivalents.
public typealias RandomIdentifiedAccessable = Identifiable & Equatable & Hashable
59 changes: 27 additions & 32 deletions Sources/JensonKit/IO/Data+Compression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,58 @@
/// For more information, check out Apple's documentation: https://developer.apple.com/documentation/compression

/*
Copyright 2020 Guilherme Rambo
Copyright 2020 Guilherme Rambo

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:
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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.
*/
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.
*/

import Foundation
import Compression
import Foundation

public extension Data {

/// Compresses the data using the specified compression algorithm.
func compressed(using algo: compression_algorithm = COMPRESSION_LZMA, pageSize: Int = 128) throws -> Data {
var outputData = Data()
let filter = try OutputFilter(.compress, using: Algorithm(rawValue: algo)!, bufferCapacity: pageSize, writingTo: { $0.flatMap({ outputData.append($0) }) })
let filter = try OutputFilter(
.compress,
using: Algorithm(rawValue: algo)!,
bufferCapacity: pageSize,
writingTo: { $0.flatMap { outputData.append($0) } }
)

var index = 0
let bufferSize = count

while true {
let rangeLength = Swift.min(pageSize, bufferSize - index)
let subdata = self.subdata(in: index ..< index + rangeLength)
let subdata = subdata(in: index ..< index + rangeLength)
index += rangeLength
try filter.write(subdata)
if (rangeLength == 0) { break }
if rangeLength == 0 { break }
}

return outputData
}

/// Decompresses the data using the specified compression algorithm.
func decompressed(from algo: compression_algorithm = COMPRESSION_LZMA, pageSize: Int = 128) throws -> Data {
do {
var outputData = Data()
let bufferSize = count
var decompressionIndex = 0

let filter = try InputFilter(.decompress, using: Algorithm(rawValue: algo)!) { (length: Int) -> Data? in
let rangeLength = Swift.min(length, bufferSize - decompressionIndex)
let subdata = self.subdata(in: decompressionIndex ..< decompressionIndex + rangeLength)
decompressionIndex += rangeLength

return subdata
}

while let page = try filter.readData(ofLength: pageSize) {
outputData.append(page)
}
var outputData = Data()
let bufferSize = count
var decompressionIndex = 0
let filter = try InputFilter(.decompress, using: Algorithm(rawValue: algo)!) { (length: Int) -> Data? in
let rangeLength = Swift.min(length, bufferSize - decompressionIndex)
let subdata = self.subdata(in: decompressionIndex ..< decompressionIndex + rangeLength)
decompressionIndex += rangeLength

return outputData
} catch {
// Try legacy decompression if modern decompression fails
fatalError("Decompression failed")
// return try gunzipped()
return subdata
}
while let page = try filter.readData(ofLength: pageSize) {
outputData.append(page)
}
return outputData
}
}
6 changes: 3 additions & 3 deletions Sources/JensonKit/IO/JensonReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
// Indexing Your Heart comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. See the CNPL for
// details.

import Foundation
import Compression
import Foundation

/// A class that reads Jenson files and decodes them into events.
public class JensonReader {
Expand All @@ -36,12 +36,12 @@ public class JensonReader {
/// - Parameter path: The path to the file to read.
public init(fileURLWithPath path: String) throws {
let url = URL(fileURLWithPath: path)
self.data = try Data(contentsOf: url)
data = try Data(contentsOf: url)
}

/// Decode the file data into a Jenson file struct.
public func decode() throws -> JensonFile {
guard let stringContents = String(data: self.data, encoding: .utf8) else {
guard let stringContents = String(data: data, encoding: .utf8) else {
throw ReaderError.malformedData
}
guard var decodedData = Data(base64Encoded: stringContents, options: .ignoreUnknownCharacters) else {
Expand Down
4 changes: 2 additions & 2 deletions Sources/JensonKit/IO/JensonWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
// Indexing Your Heart comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. See the CNPL for
// details.

import Foundation
import Compression
import Foundation

/// A class that writes Jenson files.
public class JensonWriter {
Expand All @@ -23,7 +23,7 @@ public class JensonWriter {
/// Create a file writer.
/// - Parameter jensonFile: The Jenson file struct to write to disk.
public init(contentsOf jensonFile: JensonFile) {
self.contents = jensonFile
contents = jensonFile
}

/// Writes the Jenson file to the specified path.
Expand Down
38 changes: 38 additions & 0 deletions Sources/JensonKit/Models/JensonApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// JensonApp.swift
// Created by Marquis Kurt on 9/12/22.
// This file is part of Indexing Your Heart.
//
// Indexing Your Heart is non-violent software: you can use, redistribute, and/or modify it under the terms of the
// CNPLv7+ as found in the LICENSE file in the source code root directory or at
// <https://git.pixie.town/thufie/npl-builder>.
//
// Indexing Your Heart comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. See the CNPL for
// details.

import Foundation

/// A struct that represents an application in a Jenson manifest file.
/// - Note: This application is only present on Jenson files with manifest v2 or later.
public struct JensonApp: Codable {
/// The UUID generated for this application.
public let id = UUID()

/// The name of the application that authored the file.
var name: String

/// The URL to the website associated with this application.
var website: String?

public init(name: String, website: String? = nil) {
self.name = name
self.website = website
}

private enum CodingKeys: CodingKey {
case name
case website
}
}

extension JensonApp: RandomIdentifiedAccessable {}
Loading

0 comments on commit 51d3979

Please sign in to comment.