From 999dff86a405dcc3a807b4c97569f686c2a8d20a Mon Sep 17 00:00:00 2001 From: Stanley Jones Date: Thu, 6 Feb 2020 13:50:32 -0800 Subject: [PATCH] Fix: whitespace --- src/graph/database.mo | 12 ++++++------ src/graph/main.mo | 6 +++--- src/profile/database.mo | 28 ++++++++++++++-------------- src/profile/utils.mo | 20 ++++++++++---------- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/graph/database.mo b/src/graph/database.mo index 489fd51..cffd741 100644 --- a/src/graph/database.mo +++ b/src/graph/database.mo @@ -12,13 +12,13 @@ module { type Entry = Types.Entry; type EntryId = Types.EntryId; - public class Entries () { + public class Entries() { - func natEq (x : Nat32, y : Nat32) : Bool { x == y }; - func hashEntryId (x : EntryId) : Hash.Hash { Nat.toWord32(Nat.fromNat32(x)) }; + func natEq(x : Nat32, y : Nat32) : Bool { x == y }; + func hashEntryId(x : EntryId) : Hash.Hash { Nat.toWord32(Nat.fromNat32(x)) }; let hashMap = HashMap.HashMap(1, natEq, hashEntryId); - public func addConnection (fromUser : EntryId, toUser : EntryId) { + public func addConnection(fromUser : EntryId, toUser : EntryId) { let entry = getEntry(fromUser); let updated : Entry = { id = entry.id; @@ -28,7 +28,7 @@ module { ignore hashMap.set(fromUser, updated); }; - func getEntry (entryId : EntryId) : Entry { + func getEntry(entryId : EntryId) : Entry { let existing = hashMap.get(entryId); switch (existing) { case (?existing) { existing }; @@ -36,7 +36,7 @@ module { }; }; - public func getConnections (userId : EntryId) : [EntryId] { + public func getConnections(userId : EntryId) : [EntryId] { let entry = getEntry(userId); entry.connections }; diff --git a/src/graph/main.mo b/src/graph/main.mo index 155b861..baeb91d 100644 --- a/src/graph/main.mo +++ b/src/graph/main.mo @@ -7,16 +7,16 @@ type EntryId = Types.EntryId; actor Graph { var entries : Database.Entries = Database.Entries(); - public func healthcheck () : async Bool { true }; + public func healthcheck() : async Bool { true }; // Connections // "public" makes this method available as Graph.connect - public func connect (caller : Nat32, userId : Nat32) : async () { + public func connect(caller : Nat32, userId : Nat32) : async () { entries.addConnection(caller, userId); }; - public func getConnections (userId : EntryId) : async [EntryId] { + public func getConnections(userId : EntryId) : async [EntryId] { entries.getConnections(userId) }; diff --git a/src/profile/database.mo b/src/profile/database.mo index 8b85715..a4baf88 100644 --- a/src/profile/database.mo +++ b/src/profile/database.mo @@ -12,31 +12,31 @@ module { type Profile = Types.Profile; type PrincipalId = Types.PrincipalId; - public class Directory () { + public class Directory() { // The "database" is just a local hash map let hashMap : HashMap.HashMap = init(); var seeded = false; - public func createOne (userId : PrincipalId, _profile : NewProfile) { + public func createOne(userId : PrincipalId, _profile : NewProfile) { ignore hashMap.set(userId, makeProfile(userId, _profile)); }; - public func updateOne (userId : PrincipalId, profile : Profile) { + public func updateOne(userId : PrincipalId, profile : Profile) { ignore hashMap.set(userId, profile); }; - public func findOne (userId : PrincipalId) : ?Profile { + public func findOne(userId : PrincipalId) : ?Profile { hashMap.get(userId) }; - public func findMany (userIds : [PrincipalId]) : [Profile] { - func getProfile (userId : PrincipalId) : Profile { + public func findMany(userIds : [PrincipalId]) : [Profile] { + func getProfile(userId : PrincipalId) : Profile { Option.unwrap(hashMap.get(userId)) }; Array.map(getProfile, userIds) }; - public func findBy (term : Text) : [Profile] { + public func findBy(term : Text) : [Profile] { var profiles : [Profile] = []; for ((id, profile) in hashMap.iter()) { let fullName = profile.firstName # " " # profile.lastName; @@ -62,7 +62,7 @@ module { } }; - func includesText (string : Text, term : Text) : Bool { + func includesText(string : Text, term : Text) : Bool { let stringArray = Iter.toArray(string.chars()); let termArray = Iter.toArray(term.chars()); @@ -82,7 +82,7 @@ module { false }; - public func seed () { + public func seed() { if (seeded) { return; }; let realPeople : [[Text]] = [ @@ -116,7 +116,7 @@ module { [ "Barack", "Obama", - "President (Retired)", + "President(Retired)", "United States of America", "**President**, USA \nJan 2009 – Jan 2017 \nWashington, DC", "**Harvard University** \nJD, Law", @@ -245,7 +245,7 @@ module { seeded := true; }; - func realProfile (row : [Text], index : Nat) : Profile { + func realProfile(row : [Text], index : Nat) : Profile { { id = Nat.toWord32(1000 + index); firstName = row[0]; @@ -258,7 +258,7 @@ module { } }; - func mockProfile (row : [Text], index : Nat) : Profile { + func mockProfile(row : [Text], index : Nat) : Profile { { id = Nat.toWord32(2000 + index); firstName = row[0]; @@ -272,8 +272,8 @@ module { }; }; - func init () : HashMap.HashMap { - func passthrough (hash : PrincipalId) : PrincipalId { hash }; + func init() : HashMap.HashMap { + func passthrough(hash : PrincipalId) : PrincipalId { hash }; HashMap.HashMap(1, Hash.Hash.hashEq, passthrough) }; }; diff --git a/src/profile/utils.mo b/src/profile/utils.mo index ec3f794..aabf4de 100644 --- a/src/profile/utils.mo +++ b/src/profile/utils.mo @@ -12,7 +12,7 @@ module { type PrincipalId = Types.PrincipalId; // Profiles - public func getProfile (directory : Database.Directory, userId : PrincipalId) : Profile { + public func getProfile(directory : Database.Directory, userId : PrincipalId) : Profile { let existing = directory.findOne(userId); switch (existing) { case (?existing) { existing }; @@ -33,16 +33,16 @@ module { // Connections - public func getConnectionProfiles (directory : Database.Directory, entryIds : [Nat32]) : [Profile] { + public func getConnectionProfiles(directory : Database.Directory, entryIds : [Nat32]) : [Profile] { let profileIds = Array.map(fromEntryId, entryIds); directory.findMany(profileIds) }; - public func toEntryId (userId : PrincipalId) : Nat32 { Nat.toNat32(Nat.fromWord32(userId)) }; - public func fromEntryId (entryId : Nat32) : PrincipalId { Nat.toWord32(Nat.fromNat32(entryId)) }; + public func toEntryId(userId : PrincipalId) : Nat32 { Nat.toNat32(Nat.fromWord32(userId)) }; + public func fromEntryId(entryId : Nat32) : PrincipalId { Nat.toWord32(Nat.fromNat32(entryId)) }; - public func includes (x : Nat32, xs : [Nat32]) : Bool { - func isX (y : Nat32) : Bool { x == y }; + public func includes(x : Nat32, xs : [Nat32]) : Bool { + func isX(y : Nat32) : Bool { x == y }; switch (Array.find(isX, xs)) { case (null) { false }; case (_) { true }; @@ -53,14 +53,14 @@ module { let adminIds : [PrincipalId] = []; - public func getUserId (caller : Principal) : PrincipalId { Principal.hash(caller) }; + public func getUserId(caller : Principal) : PrincipalId { Principal.hash(caller) }; - public func isAdmin (userId : PrincipalId) : Bool { - func identity (x : PrincipalId) : Bool { x == userId }; + public func isAdmin(userId : PrincipalId) : Bool { + func identity(x : PrincipalId) : Bool { x == userId }; Option.isSome(Array.find(identity, adminIds)) }; - public func hasAccess (userId : PrincipalId, profile : Profile) : Bool { + public func hasAccess(userId : PrincipalId, profile : Profile) : Bool { userId == profile.id or isAdmin(userId) }; };