-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
977 additions
and
882 deletions.
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,70 @@ | ||
{ | ||
"fileScopedDeclarationPrivacy": { | ||
"accessLevel": "private" | ||
}, | ||
"indentation": { | ||
"spaces": 4 | ||
}, | ||
"indentConditionalCompilationBlocks": true, | ||
"indentSwitchCaseLabels": false, | ||
"lineBreakAroundMultilineExpressionChainComponents": false, | ||
"lineBreakBeforeControlFlowKeywords": false, | ||
"lineBreakBeforeEachArgument": false, | ||
"lineBreakBeforeEachGenericRequirement": false, | ||
"lineLength": 140, | ||
"maximumBlankLines": 1, | ||
"multiElementCollectionTrailingCommas": true, | ||
"noAssignmentInExpressions": { | ||
"allowedFunctions": [ | ||
"XCTAssertNoThrow" | ||
] | ||
}, | ||
"prioritizeKeepingFunctionOutputTogether": false, | ||
"respectsExistingLineBreaks": true, | ||
"rules": { | ||
"AllPublicDeclarationsHaveDocumentation": false, | ||
"AlwaysUseLiteralForEmptyCollectionInit": 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, | ||
"NoAssignmentInExpressions": true, | ||
"NoBlockComments": true, | ||
"NoCasesWithOnlyFallthrough": true, | ||
"NoEmptyTrailingClosureParentheses": true, | ||
"NoLabelsInCasePatterns": true, | ||
"NoLeadingUnderscores": false, | ||
"NoParensAroundConditions": true, | ||
"NoPlaygroundLiterals": true, | ||
"NoVoidReturnOnFunctionSignature": true, | ||
"OmitExplicitReturns": false, | ||
"OneCasePerLine": true, | ||
"OneVariableDeclarationPerLine": true, | ||
"OnlyOneTrailingClosureArgument": true, | ||
"OrderedImports": true, | ||
"ReplaceForEachWithForLoop": true, | ||
"ReturnVoidInsteadOfEmptyTuple": true, | ||
"TypeNamesShouldBeCapitalized": true, | ||
"UseEarlyExits": false, | ||
"UseExplicitNilCheckInConditions": true, | ||
"UseLetInEveryBoundCaseVariable": true, | ||
"UseShorthandTypeNames": true, | ||
"UseSingleLinePropertyGetter": true, | ||
"UseSynthesizedInitializer": true, | ||
"UseTripleSlashForDocumentationComments": true, | ||
"UseWhereClausesInForLoops": false, | ||
"ValidateDocumentationComments": false | ||
}, | ||
"spacesAroundRangeFormationOperators": false, | ||
"tabWidth": 4, | ||
"version": 1 | ||
} |
146 changes: 73 additions & 73 deletions
146
Sources/MultipartKit/FormDataDecoder/FormDataDecoder.Decoder.swift
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,81 +1,81 @@ | ||
// extension FormDataDecoder { | ||
// struct Decoder { | ||
// let codingPath: [any CodingKey] | ||
// let data: MultipartFormData | ||
// let userInfo: [CodingUserInfoKey: Any] | ||
// let previousCodingPath: [any CodingKey]? | ||
// let previousType: (any Decodable.Type)? | ||
extension FormDataDecoder { | ||
struct Decoder { | ||
let codingPath: [any CodingKey] | ||
let data: MultipartFormData<Body> | ||
let userInfo: [CodingUserInfoKey: Any] | ||
let previousCodingPath: [any CodingKey]? | ||
let previousType: (any Decodable.Type)? | ||
|
||
// init( | ||
// codingPath: [any CodingKey], data: MultipartFormData, userInfo: [CodingUserInfoKey: Any], | ||
// previousCodingPath: [any CodingKey]? = nil, previousType: (any Decodable.Type)? = nil | ||
// ) { | ||
// self.codingPath = codingPath | ||
// self.data = data | ||
// self.userInfo = userInfo | ||
// self.previousCodingPath = previousCodingPath | ||
// self.previousType = previousType | ||
// } | ||
// } | ||
// } | ||
init( | ||
codingPath: [any CodingKey], data: MultipartFormData<Body>, userInfo: [CodingUserInfoKey: Any], | ||
previousCodingPath: [any CodingKey]? = nil, previousType: (any Decodable.Type)? = nil | ||
) { | ||
self.codingPath = codingPath | ||
self.data = data | ||
self.userInfo = userInfo | ||
self.previousCodingPath = previousCodingPath | ||
self.previousType = previousType | ||
} | ||
} | ||
} | ||
|
||
// extension FormDataDecoder.Decoder: Decoder { | ||
// func container<Key: CodingKey>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> { | ||
// guard let dictionary = data.dictionary else { | ||
// throw decodingError(expectedType: "dictionary") | ||
// } | ||
// return KeyedDecodingContainer(FormDataDecoder.KeyedContainer(data: dictionary, decoder: self)) | ||
// } | ||
extension FormDataDecoder.Decoder: Decoder { | ||
func container<Key: CodingKey>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> { | ||
guard let dictionary = data.dictionary else { | ||
throw decodingError(expectedType: "dictionary") | ||
} | ||
return KeyedDecodingContainer(FormDataDecoder.KeyedContainer(data: dictionary, decoder: self)) | ||
} | ||
|
||
// func unkeyedContainer() throws -> any UnkeyedDecodingContainer { | ||
// guard let array = data.array else { | ||
// throw decodingError(expectedType: "array") | ||
// } | ||
// return FormDataDecoder.UnkeyedContainer(data: array, decoder: self) | ||
// } | ||
func unkeyedContainer() throws -> any UnkeyedDecodingContainer { | ||
guard let array = data.array else { | ||
throw decodingError(expectedType: "array") | ||
} | ||
return FormDataDecoder.UnkeyedContainer(data: array, decoder: self) | ||
} | ||
|
||
// func singleValueContainer() throws -> any SingleValueDecodingContainer { | ||
// self | ||
// } | ||
// } | ||
func singleValueContainer() throws -> any SingleValueDecodingContainer { | ||
self | ||
} | ||
} | ||
|
||
// extension FormDataDecoder.Decoder { | ||
// func nested(at key: any CodingKey, with data: MultipartFormData) -> Self { | ||
// .init(codingPath: codingPath + [key], data: data, userInfo: userInfo) | ||
// } | ||
// } | ||
extension FormDataDecoder.Decoder { | ||
func nested(at key: any CodingKey, with data: MultipartFormData<Body>) -> Self { | ||
.init(codingPath: codingPath + [key], data: data, userInfo: userInfo) | ||
} | ||
} | ||
|
||
// extension FormDataDecoder.Decoder { | ||
// fileprivate func decodingError(expectedType: String) -> any Error { | ||
// let encounteredType: Any.Type | ||
// let encounteredTypeDescription: String | ||
extension FormDataDecoder.Decoder { | ||
fileprivate func decodingError(expectedType: String) -> any Error { | ||
let encounteredType: Any.Type | ||
let encounteredTypeDescription: String | ||
|
||
// switch data { | ||
// case .nestingDepthExceeded: | ||
// return DecodingError.dataCorrupted( | ||
// .init( | ||
// codingPath: codingPath, | ||
// debugDescription: "Nesting depth exceeded while expecting \(expectedType).", | ||
// underlyingError: nil | ||
// )) | ||
// case .array: | ||
// encounteredType = [MultipartFormData].self | ||
// encounteredTypeDescription = "array" | ||
// case .keyed: | ||
// encounteredType = MultipartFormData.Keyed.self | ||
// encounteredTypeDescription = "dictionary" | ||
// case .single: | ||
// encounteredType = MultipartPart.self | ||
// encounteredTypeDescription = "single value" | ||
// } | ||
switch data { | ||
case .nestingDepthExceeded: | ||
return DecodingError.dataCorrupted( | ||
.init( | ||
codingPath: codingPath, | ||
debugDescription: "Nesting depth exceeded while expecting \(expectedType).", | ||
underlyingError: nil | ||
)) | ||
case .array: | ||
encounteredType = [MultipartFormData<Body>].self | ||
encounteredTypeDescription = "array" | ||
case .keyed: | ||
encounteredType = MultipartFormData<Body>.Keyed.self | ||
encounteredTypeDescription = "dictionary" | ||
case .single: | ||
encounteredType = MultipartPart<Body>.self | ||
encounteredTypeDescription = "single value" | ||
} | ||
|
||
// return DecodingError.typeMismatch( | ||
// encounteredType, | ||
// .init( | ||
// codingPath: codingPath, | ||
// debugDescription: "Expected \(expectedType) but encountered \(encounteredTypeDescription).", | ||
// underlyingError: nil | ||
// ) | ||
// ) | ||
// } | ||
// } | ||
return DecodingError.typeMismatch( | ||
encounteredType, | ||
.init( | ||
codingPath: codingPath, | ||
debugDescription: "Expected \(expectedType) but encountered \(encounteredTypeDescription).", | ||
underlyingError: nil | ||
) | ||
) | ||
} | ||
} |
122 changes: 61 additions & 61 deletions
122
Sources/MultipartKit/FormDataDecoder/FormDataDecoder.KeyedContainer.swift
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,61 +1,61 @@ | ||
// extension FormDataDecoder { | ||
// struct KeyedContainer<K: CodingKey> { | ||
// let data: MultipartFormData.Keyed | ||
// let decoder: FormDataDecoder.Decoder | ||
// } | ||
// } | ||
|
||
// extension FormDataDecoder.KeyedContainer: KeyedDecodingContainerProtocol { | ||
// var allKeys: [K] { | ||
// data.keys.compactMap(K.init(stringValue:)) | ||
// } | ||
|
||
// var codingPath: [any CodingKey] { | ||
// decoder.codingPath | ||
// } | ||
|
||
// func contains(_ key: K) -> Bool { | ||
// data.keys.contains(key.stringValue) | ||
// } | ||
|
||
// func getValue(forKey key: any CodingKey) throws -> MultipartFormData { | ||
// guard let value = data[key.stringValue] else { | ||
// throw DecodingError.keyNotFound( | ||
// key, | ||
// .init( | ||
// codingPath: codingPath, | ||
// debugDescription: "No value associated with key \"\(key.stringValue)\"." | ||
// ) | ||
// ) | ||
// } | ||
// return value | ||
// } | ||
|
||
// func decodeNil(forKey key: K) throws -> Bool { | ||
// false | ||
// } | ||
|
||
// func decode<T: Decodable>(_ type: T.Type, forKey key: K) throws -> T { | ||
// try decoderForKey(key).decode() | ||
// } | ||
|
||
// func nestedContainer<NestedKey: CodingKey>(keyedBy keyType: NestedKey.Type, forKey key: K) throws -> KeyedDecodingContainer<NestedKey> { | ||
// try decoderForKey(key).container(keyedBy: keyType) | ||
// } | ||
|
||
// func nestedUnkeyedContainer(forKey key: K) throws -> any UnkeyedDecodingContainer { | ||
// try decoderForKey(key).unkeyedContainer() | ||
// } | ||
|
||
// func superDecoder() throws -> any Decoder { | ||
// try decoderForKey(BasicCodingKey.super) | ||
// } | ||
|
||
// func superDecoder(forKey key: K) throws -> any Decoder { | ||
// try decoderForKey(key) | ||
// } | ||
|
||
// func decoderForKey(_ key: any CodingKey) throws -> FormDataDecoder.Decoder { | ||
// decoder.nested(at: key, with: try getValue(forKey: key)) | ||
// } | ||
// } | ||
extension FormDataDecoder { | ||
struct KeyedContainer<K: CodingKey> { | ||
let data: MultipartFormData<Body>.Keyed | ||
let decoder: FormDataDecoder.Decoder | ||
} | ||
} | ||
|
||
extension FormDataDecoder.KeyedContainer: KeyedDecodingContainerProtocol { | ||
var allKeys: [K] { | ||
data.keys.compactMap(K.init(stringValue:)) | ||
} | ||
|
||
var codingPath: [any CodingKey] { | ||
decoder.codingPath | ||
} | ||
|
||
func contains(_ key: K) -> Bool { | ||
data.keys.contains(key.stringValue) | ||
} | ||
|
||
func getValue(forKey key: any CodingKey) throws -> MultipartFormData<Body> { | ||
guard let value = data[key.stringValue] else { | ||
throw DecodingError.keyNotFound( | ||
key, | ||
.init( | ||
codingPath: codingPath, | ||
debugDescription: "No value associated with key \"\(key.stringValue)\"." | ||
) | ||
) | ||
} | ||
return value | ||
} | ||
|
||
func decodeNil(forKey key: K) throws -> Bool { | ||
false | ||
} | ||
|
||
func decode<T: Decodable>(_ type: T.Type, forKey key: K) throws -> T { | ||
try decoderForKey(key).decode() | ||
} | ||
|
||
func nestedContainer<NestedKey: CodingKey>(keyedBy keyType: NestedKey.Type, forKey key: K) throws -> KeyedDecodingContainer<NestedKey> { | ||
try decoderForKey(key).container(keyedBy: keyType) | ||
} | ||
|
||
func nestedUnkeyedContainer(forKey key: K) throws -> any UnkeyedDecodingContainer { | ||
try decoderForKey(key).unkeyedContainer() | ||
} | ||
|
||
func superDecoder() throws -> any Decoder { | ||
try decoderForKey(BasicCodingKey.super) | ||
} | ||
|
||
func superDecoder(forKey key: K) throws -> any Decoder { | ||
try decoderForKey(key) | ||
} | ||
|
||
func decoderForKey(_ key: any CodingKey) throws -> FormDataDecoder.Decoder { | ||
decoder.nested(at: key, with: try getValue(forKey: key)) | ||
} | ||
} |
Oops, something went wrong.