<commit_before>//
//  Registry.swift
//  Bartleby
//
//  Created by <NAME> on 16/09/2015.
//  Copyright © 2015 https://pereira-da-silva.com for Chaosmos SAS
//  All rights reserved you can ask for a license.


import Foundation

#if os(OSX)
    import AppKit
    @objc public class UniversalDocument:NSDocument{}
#else
    import UIKit
    @objc public class UniversalDocument:UIDocument{}
#endif

public enum RegistryError:ErrorType{
    case DuplicatedCollectionName(collectionName:String)
    case AttemptToLoadAnNonSupportedCollection(collectionName:String)
    case UnExistingCollection(collectionName:String)
    case MissingCollectionProxy(collectionName:String)
    case CollectionProxyTypeError
    case RootObjectTypeMissMatch
}



public enum SecurityScopedBookMarkError:ErrorType {
    // Bookmarking
    case BookMarkFailed(message:String)
    // Scoped URL
    case GetScopedURLRessourceFailed(message:String)
    case BookMarkIsStale
}



// MARK: - Equatable

func ==(lhs: Registry, rhs: Registry) -> Bool{
    return lhs.spaceUID==rhs.spaceUID
}


// MARK -


/*

A Registry stores collections of Objects in memory for high performance read and write access
(future versions may implement incremental storage, a modified collection is actually globally serialized)
The registry can be used to developp apps that performs on and off line.
In a Document based app Each document have its own Registry.
Documents can be shared between iOS, tvOS and OSX.

*/
@objc public class Registry:UniversalDocument{
    
    // Should always be true
    static public var encryptedMetadata:Bool=true
    
    // Should always be true
    public var collectionsDataShouldBeCrypted:Bool=true
    
    // The standard text encoding
    private let _textEncoding=NSUTF8StringEncoding
    
    // A notification that is sent when the registry is fully loaded.
    static let REGISTRY_DID_LOAD_NOTIFICATION="registryDidLoad"

    // The file extension for crypted data
    static let CRYPTED_EXTENSION:String=".data"
    
    // The metadata file name
    private let _metadataFileName="metadata".stringByAppendingString(Registry.encryptedMetadata ? Registry.CRYPTED_EXTENSION : ".json" )
    
    // By default the registry uses Json based implementations
    // JRegistryMetadata and JSerializer
    
    // We use a  JRegistryMetadata
    public var registryMetadata=JRegistryMetadata()

    // The spaceUID can be shared between multiple documents-registries
    // It defines a dataSpace where user can live.
    // A user can live in one data space only.
    public var spaceUID:String{
        get{
            return self.registryMetadata.spaceUID
        }
    }
    
    // Set to true when the data has been loaded once or more.
    public var hasBeenLoaded:Bool=false
    
    // Default Serializer
    internal var serializer=JSerializer()
    
    /// The underlining storage hashed by collection name
    private var _collections=Array<Collectible>()
    // The indexes
    private var _indexes=Array<String>()
    
    
    /// We store the URL of the active security bookmarks
    private var _activeSecurityBookmarks=[NSURL]()
    
    
    //MARK: - Centralized ObjectList By UID
    
    // this centralized dictionary allows to access to any referenced object by its UID
    // to resolve aliases, cross reference, it simplify instance mobility from a registry to another, etc..
    // future implementation may include extension for lazy Storage
    
    private static var _objectByUID=Dictionary<String,Any>()
    
    /**
     Registers an instance
     
     - parameter instance: the Identifiable instance
     */
    public static func register<T:Identifiable>(instance:T){
        _objectByUID[instance.UID]=instance<commit_msg>Gitteries Typo fix<commit_after>//
//  Registry.swift
//  Bartleby
//
//  Created by <NAME> on 16/09/2015.
//  Copyright © 2015 https://pereira-da-silva.com for Chaosmos SAS
//  All rights reserved you can ask for a license.


import Foundation

#if os(OSX)
    import AppKit
    @objc public class UniversalDocument:NSDocument{}
#else
    import UIKit
    @objc public class UniversalDocument:UIDocument{}
#endif

public enum RegistryError:ErrorType{
    case DuplicatedCollectionName(collectionName:String)
    case AttemptToLoadAnNonSupportedCollection(collectionName:String)
    case UnExistingCollection(collectionName:String)
    case MissingCollectionProxy(collectionName:String)
    case CollectionProxyTypeError
    case RootObjectTypeMissMatch
}



public enum SecurityScopedBookMarkError:ErrorType {
    // Bookmarking
    case BookMarkFailed(message:String)
    // Scoped URL
    case GetScopedURLRessourceFailed(message:String)
    case BookMarkIsStale
}



// MARK: - Equatable

func ==(lhs: Registry, rhs: Registry) -> Bool{
    return lhs.spaceUID==rhs.spaceUID
}


// MARK -


/*

A Registry stores collections of Objects in memory for high performance read and write access
(future versions may implement incremental storage, a modified collection is actually globally serialized)
The registry can be used to developp apps that performs on and off line.
In a Document based app Each document have its own Registry.
Documents can be shared between iOS, tvOS and OSX.

*/
@objc public class Registry:UniversalDocument{
    
    // Should always be true
    static public var encryptedMetadata:Bool=true
    
    // Should always be true
    public var collectionsDataShouldBeCrypted:Bool=true
    
    // The standard text encoding
    private let _textEncoding=NSUTF8StringEncoding
    
    // A notification that is sent when the registry is fully loaded.
    static let REGISTRY_DID_LOAD_NOTIFICATION="registryDidLoad"

    // The file extension for crypted data
    static let CRYPTED_EXTENSION:String=".data"
    
    // The metadata file name
    private let _metadataFileName="metadata".stringByAppendingString(Registry.encryptedMetadata ? Registry.CRYPTED_EXTENSION : ".json" )
    
    // By default the registry uses Json based implementations
    // JRegistryMetadata and JSerializer
    
    // We use a  JRegistryMetadata
    public var registryMetadata=JRegistryMetadata()

    // The spaceUID can be shared between multiple documents-registries
    // It defines a dataSpace where user can live.
    // A user can live in one data space only.
    public var spaceUID:String{
        get{
            return self.registryMetadata.spaceUID
        }
    }
    
    // Set to true when the data has been loaded once or more.
    public var hasBeenLoaded:Bool=false
    
    // Default Serializer
    internal var serializer=JSerializer()
    
    /// The underlining storage hashed by collection name
    private var _collections=Array<Collectible>()
    // The indexes
    private var _indexes=Array<String>()
    
    /// We store the URL of the active security bookmarks
    private var _activeSecurityBookmarks=[NSURL]()
    
    
    //MARK: - Centralized ObjectList By UID
    
    // this centralized dictionary allows to access to any referenced object by its UID
    // to resolve aliases, cross reference, it simplify instance mobility from a registry to another, etc..
    // future implementation may include extension for lazy Storage
    
    private static var _objectByUID=Dictionary<String,Any>()
    
    /**
     Registers an instance
     
     - parameter instance: the Identifiable instance
     */
    public static func register<T:Identifiable>(instance:T){
        _objectByUID[instance.UID]=instance
{'fraction_non_alphanumeric': 0.0650146549427125, 'fraction_numerical': 0.0034638955502264853, 'mean_word_length': 3.2269144144144146, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4209726', 'n_tokens_mistral': 2040, 'n_tokens_neox': 1939, 'n_words': 709}