unison-codebase-sqlite-0.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

U.Codebase.Sqlite.Operations

Synopsis

branches

loadCausalHashAtPath :: CausalHash -> [NameSegment] -> Transaction (Maybe CausalHash) Source #

Load the causal hash at the given path from the provided root, if Nothing, use the codebase root.

expectCausalHashAtPath :: CausalHash -> [NameSegment] -> Transaction CausalHash Source #

Expect the causal hash at the given path from the provided root, if Nothing, use the codebase root.

expectNamespaceStatsByHash :: BranchHash -> Transaction NamespaceStats Source #

Looks up statistics for a given branch, if none exist, we compute them and save them then return them.

expectNamespaceStatsByHashId :: BranchHashId -> Transaction NamespaceStats Source #

Looks up statistics for a given branch, if none exist, we compute them and save them then return them.

tryGetSquashResult :: BranchHash -> Transaction (Maybe CausalHash) Source #

Get the causal hash which would be the result of squashing the provided branch hash. Returns Nothing if we haven't computed it before.

saveSquashResult :: BranchHash -> CausalHash -> Transaction () Source #

Saves the result of a squash

terms

saveTermComponent Source #

Arguments

:: HashHandle 
-> Maybe ByteString

The serialized term component if we already have it e.g. via sync

-> Hash

term component hash

-> [(Term Symbol, Type Symbol)]

term component

-> Transaction ObjectId 

decls

terms/decls

patches

test for stuff in codebase

watch expression cache

loadWatch :: WatchKind -> Id -> MaybeT Transaction (Term Symbol) Source #

returns Nothing if the expression isn't cached.

clearWatches :: Transaction () Source #

Delete all watches that were put by putWatch.

indexes

nearest common ancestor

prefix index

dependents index

dependents :: DependentsSelector -> Reference -> Transaction (Set Id) Source #

returns a list of known definitions referencing r

dependentsOfComponent :: Hash -> Transaction (Set Id) Source #

returns a list of known definitions referencing h

directDependentsWithinScope :: Set Id -> Set Reference -> Transaction (DefnsF Set TermReferenceId TypeReferenceId) Source #

`directDependentsWithinScope scope query` returns all direct dependents of query that are in scope (not including query itself).

transitiveDependentsWithinScope :: Set Id -> Set Reference -> Transaction (DefnsF Set TermReferenceId TypeReferenceId) Source #

`transitiveDependentsWithinScope scope query` returns all transitive dependents of query that are in scope (not including query itself).

type index

type mentions index

name lookup index

allNamesInPerspective :: NamesPerspective -> Transaction NamesInPerspective Source #

Get all the term and type names for the given namespace from the lookup table. Requires that an index for this branch hash already exists, which is currently only true on Share.

data NamesPerspective Source #

Any time we need to lookup or search names we need to know what the scope of that search should be. This can be complicated to keep track of, so this is a helper type to make it easy to pass around.

You should use namesPerspectiveForRootAndPath to construct this type.

E.g. if we're in loose code, we need to search the correct name lookup for the user's perspective. If their perspective is "myprojects.json.latest.lib.base.data.List", we need to search names using the name index mounted at "myprojects.json.latest.lib.base".

The NamesPerspective representing this viewpoint would be:

@ NamesPerspective { nameLookupBranchHashId = #libbasehash , pathToMountedNameLookup = ["myprojects.json", "latest", "lib", "base"] , relativePerspective = ["data", List] } @

Constructors

NamesPerspective 

Fields

termNamesForRefWithinNamespace :: NamesPerspective -> Referent -> Maybe ReversedName -> Transaction [ReversedName] Source #

NOTE: requires that the codebase has an up-to-date name lookup index. As of writing, this is only true on Share.

Get the list of a names for a given Referent.

typeNamesForRefWithinNamespace :: NamesPerspective -> Reference -> Maybe ReversedName -> Transaction [ReversedName] Source #

NOTE: requires that the codebase has an up-to-date name lookup index. As of writing, this is only true on Share.

Get the list of a names for a given Reference, with an optional required suffix.

recursiveTermNameSearch :: NamesPerspective -> Referent -> Transaction (Maybe ReversedName) Source #

Searches all dependencies transitively looking for the provided ref within the provided namespace. Prefer termNamesForRefWithinNamespace in most cases. This is slower and only necessary when resolving the name of refs when you don't know which dependency it may exist in.

Searching transitive dependencies is exponential so we want to replace this with a more efficient approach as soon as possible.

Note: this returns the first name it finds by searching in order of: Names in the current namespace, then names in the current namespace's dependencies, then through the current namespace's dependencies' dependencies, etc.

recursiveTypeNameSearch :: NamesPerspective -> Reference -> Transaction (Maybe ReversedName) Source #

Searches all dependencies transitively looking for the provided ref within the provided namespace. Prefer typeNamesForRefWithinNamespace in most cases. This is slower and only necessary when resolving the name of references when you don't know which dependency it may exist in.

Searching transitive dependencies is exponential so we want to replace this with a more efficient approach as soon as possible.

Note: this returns the first name it finds by searching in order of: Names in the current namespace, then names in the current namespace's dependencies, then through the current namespace's dependencies' dependencies, etc.

checkBranchHashNameLookupExists :: BranchHash -> Transaction Bool Source #

Check whether we've already got an index for a given branch hash.

associateNameLookupMounts :: BranchHash -> [(PathSegments, BranchHash)] -> Transaction () Source #

Save a list of (mount-path, branch hash) mounts for the provided name lookup index branch hash.

E.g. associateNameLookupMounts #roothash [(["lib", "base"], #basehash)]

longestMatchingTermNameForSuffixification :: NamesPerspective -> NamedRef Referent -> Transaction (Maybe (NamedRef (Referent, Maybe ConstructorType))) Source #

Get the name within the provided namespace that has the longest matching suffix with the provided name, but a different ref. This is a bit of a hack but allows us to shortcut suffixification. We can clean this up if we make a custom PPE type just for sqlite pretty printing, but for now this works fine.

longestMatchingTypeNameForSuffixification :: NamesPerspective -> NamedRef Reference -> Transaction (Maybe (NamedRef Reference)) Source #

Get the name within the provided namespace that has the longest matching suffix with the provided name, but a different ref. This is a bit of a hack but allows us to shortcut suffixification. We can clean this up if we make a custom PPE type just for sqlite pretty printing, but for now this works fine.

deleteNameLookupsExceptFor :: Set BranchHash -> Transaction () Source #

Delete any name lookup that's not in the provided list.

This can be used to garbage collect unreachable name lookups.

fuzzySearchDefinitions Source #

Arguments

:: Bool 
-> NamesPerspective 
-> Int

Will return at most n terms and n types; i.e. max number of results is 2n

-> [Text] 
-> Transaction ([NamedRef (Referent, Maybe ConstructorType)], [NamedRef Reference]) 

Search for term or type names which contain the provided list of segments in order. Search is case insensitive.

namesPerspectiveForRootAndPath :: BranchHash -> PathSegments -> Transaction NamesPerspective Source #

Determine which nameLookup is the closest parent of the provided perspective.

Returns (rootBranchId of the closest parent index, namespace that index is mounted at, location of the perspective within the mounted namespace)

E.g. If your namespace is "lib.distributed.lib.base.data.List", you'd get back (rootBranchId of the lib.distributed.lib.base name lookup, "lib.distributed.lib.base", "data.List")

Or if your namespace is "subnamespace.user", you'd get back (the rootBranchId you provided, "", "subnamespace.user")

Projects

reflog

getDeprecatedRootReflog :: Int -> Transaction [Entry CausalHash Text] Source #

Gets the specified number of reflog entries in chronological order, most recent first.

getProjectReflog :: Int -> ProjectId -> Transaction [Entry Project ProjectBranch CausalHash] Source #

Gets the specified number of reflog entries for the given project in chronological order, most recent first.

getProjectBranchReflog :: Int -> ProjectBranchId -> Transaction [Entry Project ProjectBranch CausalHash] Source #

Gets the specified number of reflog entries for the specified ProjectBranch in chronological order, most recent first.

getGlobalReflog :: Int -> Transaction [Entry Project ProjectBranch CausalHash] Source #

Gets the specified number of reflog entries in chronological order, most recent first.

low-level stuff

saveDbBranch :: HashHandle -> BranchHash -> NamespaceStats -> DbBranchV -> Transaction BranchObjectId Source #

Save a DbBranch, given its hash (which the caller is expected to produce from the branch).

Note: long-standing question: should this package depend on the hashing package? (If so, we would only need to take the DbBranch, and hash internally).

saveDbBranchUnderHashId :: HashHandle -> BranchHashId -> NamespaceStats -> DbBranchV -> Transaction BranchObjectId Source #

Variant of saveDbBranch that might be preferred by callers that already have a hash id, not a hash.

expectDbBranchByCausalHashId :: CausalHashId -> Transaction DbBranch Source #

Expect a branch value given its causal hash id.

somewhat unexpectedly unused definitions

diffPatch :: LocalPatch -> LocalPatch -> LocalPatchDiff Source #

produces a diff diff = full - ref; full = diff + ref

s2cDecl :: LocalIds -> Decl Symbol -> Transaction (Decl Symbol) Source #

Unlocalize a decl.

derivedDependencies :: Id -> Transaction (Set Id) Source #

returns empty set for unknown inputs; doesn't distinguish between term and decl

internal stuff that probably need not be exported, but the 1->2 migration needs it

data BranchV m Source #

Constructors

BranchV2 !(Branch m) 
BranchV3 !(BranchV3 m)