Support typed errors. Misc formatting

This commit is contained in:
John Estropia
2024-09-10 11:14:39 +09:00
parent c9e091a6a4
commit 5dcf29011a
74 changed files with 3987 additions and 1441 deletions

View File

@@ -39,8 +39,10 @@ extension DataStack: FetchableSource, QueryableSource {
- parameter object: a reference to the object created/fetched outside the `DataStack`
- returns: the `DynamicObject` instance if the object exists in the `DataStack`, or `nil` if not found.
*/
public func fetchExisting<O: DynamicObject>(_ object: O) -> O? {
public func fetchExisting<O: DynamicObject>(
_ object: O
) -> O? {
return self.mainContext.fetchExisting(object)
}
@@ -50,8 +52,10 @@ extension DataStack: FetchableSource, QueryableSource {
- parameter objectID: the `NSManagedObjectID` for the object
- returns: the `DynamicObject` instance if the object exists in the `DataStack`, or `nil` if not found.
*/
public func fetchExisting<O: DynamicObject>(_ objectID: NSManagedObjectID) -> O? {
public func fetchExisting<O: DynamicObject>(
_ objectID: NSManagedObjectID
) -> O? {
return self.mainContext.fetchExisting(objectID)
}
@@ -61,8 +65,10 @@ extension DataStack: FetchableSource, QueryableSource {
- parameter objects: an array of `DynamicObject`s created/fetched outside the `DataStack`
- returns: the `DynamicObject` array for objects that exists in the `DataStack`
*/
public func fetchExisting<O: DynamicObject, S: Sequence>(_ objects: S) -> [O] where S.Iterator.Element == O {
public func fetchExisting<O: DynamicObject, S: Sequence>(
_ objects: S
) -> [O] where S.Iterator.Element == O {
return self.mainContext.fetchExisting(objects)
}
@@ -72,8 +78,10 @@ extension DataStack: FetchableSource, QueryableSource {
- parameter objectIDs: the `NSManagedObjectID` array for the objects
- returns: the `DynamicObject` array for objects that exists in the `DataStack`
*/
public func fetchExisting<O: DynamicObject, S: Sequence>(_ objectIDs: S) -> [O] where S.Iterator.Element == NSManagedObjectID {
public func fetchExisting<O: DynamicObject, S: Sequence>(
_ objectIDs: S
) -> [O] where S.Iterator.Element == NSManagedObjectID {
return self.mainContext.fetchExisting(objectIDs)
}
@@ -85,8 +93,11 @@ extension DataStack: FetchableSource, QueryableSource {
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
*/
public func fetchOne<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> O? {
public func fetchOne<O>(
_ from: From<O>,
_ fetchClauses: FetchClause...
) throws(CoreStoreError) -> O? {
Internals.assert(
Thread.isMainThread,
"Attempted to fetch from a \(Internals.typeName(self)) outside the main thread."
@@ -102,8 +113,11 @@ extension DataStack: FetchableSource, QueryableSource {
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
*/
public func fetchOne<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> O? {
public func fetchOne<O>(
_ from: From<O>,
_ fetchClauses: [FetchClause]
) throws(CoreStoreError) -> O? {
Internals.assert(
Thread.isMainThread,
"Attempted to fetch from a \(Internals.typeName(self)) outside the main thread."
@@ -124,8 +138,10 @@ extension DataStack: FetchableSource, QueryableSource {
- returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
*/
public func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> B.ObjectType? {
public func fetchOne<B: FetchChainableBuilderType>(
_ clauseChain: B
) throws(CoreStoreError) -> B.ObjectType? {
Internals.assert(
Thread.isMainThread,
"Attempted to fetch from a \(Internals.typeName(self)) outside the main thread."
@@ -141,8 +157,11 @@ extension DataStack: FetchableSource, QueryableSource {
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
*/
public func fetchAll<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> [O] {
public func fetchAll<O>(
_ from: From<O>,
_ fetchClauses: FetchClause...
) throws(CoreStoreError) -> [O] {
Internals.assert(
Thread.isMainThread,
"Attempted to fetch from a \(Internals.typeName(self)) outside the main thread."
@@ -158,8 +177,11 @@ extension DataStack: FetchableSource, QueryableSource {
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
*/
public func fetchAll<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> [O] {
public func fetchAll<O>(
_ from: From<O>,
_ fetchClauses: [FetchClause]
) throws(CoreStoreError) -> [O] {
Internals.assert(
Thread.isMainThread,
"Attempted to fetch from a \(Internals.typeName(self)) outside the main thread."
@@ -180,7 +202,9 @@ extension DataStack: FetchableSource, QueryableSource {
- returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
*/
public func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> [B.ObjectType] {
public func fetchAll<B: FetchChainableBuilderType>(
_ clauseChain: B
) throws(CoreStoreError) -> [B.ObjectType] {
Internals.assert(
Thread.isMainThread,
@@ -197,8 +221,11 @@ extension DataStack: FetchableSource, QueryableSource {
- returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
*/
public func fetchCount<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> Int {
public func fetchCount<O>(
_ from: From<O>,
_ fetchClauses: FetchClause...
) throws(CoreStoreError) -> Int {
Internals.assert(
Thread.isMainThread,
"Attempted to fetch from a \(Internals.typeName(self)) outside the main thread."
@@ -214,8 +241,11 @@ extension DataStack: FetchableSource, QueryableSource {
- returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
*/
public func fetchCount<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> Int {
public func fetchCount<O>(
_ from: From<O>,
_ fetchClauses: [FetchClause]
) throws(CoreStoreError) -> Int {
Internals.assert(
Thread.isMainThread,
"Attempted to fetch from a \(Internals.typeName(self)) outside the main thread."
@@ -236,8 +266,10 @@ extension DataStack: FetchableSource, QueryableSource {
- returns: the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
*/
public func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> Int {
public func fetchCount<B: FetchChainableBuilderType>(
_ clauseChain: B
) throws(CoreStoreError) -> Int {
Internals.assert(
Thread.isMainThread,
"Attempted to fetch from a \(Internals.typeName(self)) outside the main thread."
@@ -253,8 +285,11 @@ extension DataStack: FetchableSource, QueryableSource {
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
*/
public func fetchObjectID<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> NSManagedObjectID? {
public func fetchObjectID<O>(
_ from: From<O>,
_ fetchClauses: FetchClause...
) throws(CoreStoreError) -> NSManagedObjectID? {
Internals.assert(
Thread.isMainThread,
"Attempted to fetch from a \(Internals.typeName(self)) outside the main thread."
@@ -270,8 +305,11 @@ extension DataStack: FetchableSource, QueryableSource {
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
*/
public func fetchObjectID<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> NSManagedObjectID? {
public func fetchObjectID<O>(
_ from: From<O>,
_ fetchClauses: [FetchClause]
) throws(CoreStoreError) -> NSManagedObjectID? {
Internals.assert(
Thread.isMainThread,
"Attempted to fetch from a \(Internals.typeName(self)) outside the main thread."
@@ -292,8 +330,10 @@ extension DataStack: FetchableSource, QueryableSource {
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
*/
public func fetchObjectID<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> NSManagedObjectID? {
public func fetchObjectID<B: FetchChainableBuilderType>(
_ clauseChain: B
) throws(CoreStoreError) -> NSManagedObjectID? {
Internals.assert(
Thread.isMainThread,
"Attempted to fetch from a \(Internals.typeName(self)) outside the main thread."
@@ -309,8 +349,11 @@ extension DataStack: FetchableSource, QueryableSource {
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
*/
public func fetchObjectIDs<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> [NSManagedObjectID] {
public func fetchObjectIDs<O>(
_ from: From<O>,
_ fetchClauses: FetchClause...
) throws(CoreStoreError) -> [NSManagedObjectID] {
Internals.assert(
Thread.isMainThread,
"Attempted to fetch from a \(Internals.typeName(self)) outside the main thread."
@@ -326,8 +369,11 @@ extension DataStack: FetchableSource, QueryableSource {
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
*/
public func fetchObjectIDs<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> [NSManagedObjectID] {
public func fetchObjectIDs<O>(
_ from: From<O>,
_ fetchClauses: [FetchClause]
) throws(CoreStoreError) -> [NSManagedObjectID] {
Internals.assert(
Thread.isMainThread,
"Attempted to fetch from a \(Internals.typeName(self)) outside the main thread."
@@ -348,8 +394,10 @@ extension DataStack: FetchableSource, QueryableSource {
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
*/
public func fetchObjectIDs<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> [NSManagedObjectID] {
public func fetchObjectIDs<B: FetchChainableBuilderType>(
_ clauseChain: B
) throws(CoreStoreError) -> [NSManagedObjectID] {
Internals.assert(
Thread.isMainThread,
"Attempted to fetch from a \(Internals.typeName(self)) outside the main thread."
@@ -371,8 +419,12 @@ extension DataStack: FetchableSource, QueryableSource {
- returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select<U>` parameter.
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
*/
public func queryValue<O, U: QueryableAttributeType>(_ from: From<O>, _ selectClause: Select<O, U>, _ queryClauses: QueryClause...) throws -> U? {
public func queryValue<O, U: QueryableAttributeType>(
_ from: From<O>,
_ selectClause: Select<O, U>,
_ queryClauses: QueryClause...
) throws(CoreStoreError) -> U? {
Internals.assert(
Thread.isMainThread,
"Attempted to query from a \(Internals.typeName(self)) outside the main thread."
@@ -391,8 +443,12 @@ extension DataStack: FetchableSource, QueryableSource {
- returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select<U>` parameter.
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
*/
public func queryValue<O, U: QueryableAttributeType>(_ from: From<O>, _ selectClause: Select<O, U>, _ queryClauses: [QueryClause]) throws -> U? {
public func queryValue<O, U: QueryableAttributeType>(
_ from: From<O>,
_ selectClause: Select<O, U>,
_ queryClauses: [QueryClause]
) throws(CoreStoreError) -> U? {
Internals.assert(
Thread.isMainThread,
"Attempted to query from a \(Internals.typeName(self)) outside the main thread."
@@ -415,13 +471,19 @@ extension DataStack: FetchableSource, QueryableSource {
- returns: the result of the the query as specified by the `QueryChainableBuilderType`, or `nil` if no match was found.
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
*/
public func queryValue<B: QueryChainableBuilderType>(_ clauseChain: B) throws -> B.ResultType? where B.ResultType: QueryableAttributeType {
public func queryValue<B: QueryChainableBuilderType>(
_ clauseChain: B
) throws(CoreStoreError) -> B.ResultType? where B.ResultType: QueryableAttributeType {
Internals.assert(
Thread.isMainThread,
"Attempted to query from a \(Internals.typeName(self)) outside the main thread."
)
return try self.mainContext.queryValue(clauseChain.from, clauseChain.select, clauseChain.queryClauses)
return try self.mainContext.queryValue(
clauseChain.from,
clauseChain.select,
clauseChain.queryClauses
)
}
/**
@@ -435,8 +497,12 @@ extension DataStack: FetchableSource, QueryableSource {
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
*/
public func queryAttributes<O>(_ from: From<O>, _ selectClause: Select<O, NSDictionary>, _ queryClauses: QueryClause...) throws -> [[String: Any]] {
public func queryAttributes<O>(
_ from: From<O>,
_ selectClause: Select<O, NSDictionary>,
_ queryClauses: QueryClause...
) throws(CoreStoreError) -> [[String: Any]] {
Internals.assert(
Thread.isMainThread,
"Attempted to query from a \(Internals.typeName(self)) outside the main thread."
@@ -455,8 +521,12 @@ extension DataStack: FetchableSource, QueryableSource {
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
*/
public func queryAttributes<O>(_ from: From<O>, _ selectClause: Select<O, NSDictionary>, _ queryClauses: [QueryClause]) throws -> [[String: Any]] {
public func queryAttributes<O>(
_ from: From<O>,
_ selectClause: Select<O, NSDictionary>,
_ queryClauses: [QueryClause]
) throws(CoreStoreError) -> [[String: Any]] {
Internals.assert(
Thread.isMainThread,
"Attempted to query from a \(Internals.typeName(self)) outside the main thread."
@@ -488,13 +558,19 @@ extension DataStack: FetchableSource, QueryableSource {
- returns: the result of the the query as specified by the `QueryChainableBuilderType`
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
*/
public func queryAttributes<B: QueryChainableBuilderType>(_ clauseChain: B) throws -> [[String: Any]] where B.ResultType == NSDictionary {
public func queryAttributes<B: QueryChainableBuilderType>(
_ clauseChain: B
) throws(CoreStoreError) -> [[String: Any]] where B.ResultType == NSDictionary {
Internals.assert(
Thread.isMainThread,
"Attempted to query from a \(Internals.typeName(self)) outside the main thread."
)
return try self.mainContext.queryAttributes(clauseChain.from, clauseChain.select, clauseChain.queryClauses)
return try self.mainContext.queryAttributes(
clauseChain.from,
clauseChain.select,
clauseChain.queryClauses
)
}