diff --git a/implement/elm-fullstack/ElmFullstack/ElmAppCompilation.cs b/implement/elm-fullstack/ElmFullstack/ElmAppCompilation.cs index cc4f9028..4a6ac712 100644 --- a/implement/elm-fullstack/ElmFullstack/ElmAppCompilation.cs +++ b/implement/elm-fullstack/ElmFullstack/ElmAppCompilation.cs @@ -33,7 +33,7 @@ public class ElmAppCompilation { static readonly System.Diagnostics.Stopwatch cacheItemTimeSource = System.Diagnostics.Stopwatch.StartNew(); - static readonly ConcurrentDictionary, CompilationSuccess> compilationResult, TimeSpan lastUseTime)> ElmAppCompilationCache = new(); + static readonly ConcurrentDictionary, CompilationSuccess> compilationResult, TimeSpan lastUseTime)> ElmAppCompilationCache = new(); static void ElmAppCompilationCacheRemoveOlderItems(long retainedSizeLimit) => Cache.RemoveItemsToLimitRetainedSize( @@ -42,7 +42,7 @@ static void ElmAppCompilationCacheRemoveOlderItems(long retainedSizeLimit) => item => item.Value.lastUseTime, retainedSizeLimit); - static public Composition.Result, CompilationSuccess> AsCompletelyLoweredElmApp( + static public Result, CompilationSuccess> AsCompletelyLoweredElmApp( IImmutableDictionary, IReadOnlyList> sourceFiles, ElmAppInterfaceConfig interfaceConfig) { @@ -57,14 +57,14 @@ static public Composition.Result, Compila interfaceConfig, })))); - Composition.Result, CompilationSuccess> compileNew() => + Result, CompilationSuccess> compileNew() => AsCompletelyLoweredElmApp( sourceFiles, rootModuleName: interfaceConfig.RootModuleName.Split('.').ToImmutableList(), interfaceToHostRootModuleName: InterfaceToHostRootModuleName.Split('.').ToImmutableList()); - (Composition.Result, CompilationSuccess> compilationResult, TimeSpan lastUseTime) BuildNextCacheEntry( - Composition.Result, CompilationSuccess> previousEntryCompilationResult) + (Result, CompilationSuccess> compilationResult, TimeSpan lastUseTime) BuildNextCacheEntry( + Result, CompilationSuccess> previousEntryCompilationResult) { if (previousEntryCompilationResult?.Ok != null) return (previousEntryCompilationResult, cacheItemTimeSource.Elapsed); @@ -87,7 +87,7 @@ public record CompilationSuccess( IImmutableDictionary, IReadOnlyList> compiledAppFiles, IImmutableList iterationsReports); - static Composition.Result, CompilationSuccess> AsCompletelyLoweredElmApp( + static Result, CompilationSuccess> AsCompletelyLoweredElmApp( IImmutableDictionary, IReadOnlyList> sourceFiles, IImmutableList rootModuleName, IImmutableList interfaceToHostRootModuleName) => @@ -97,7 +97,7 @@ static Composition.Result, CompilationSuc interfaceToHostRootModuleName, ImmutableStack<(IImmutableList<(CompilerSerialInterface.DependencyKey key, IReadOnlyList value)> discoveredDependencies, CompilationIterationReport previousIterationsReports)>.Empty); - static Composition.Result, CompilationSuccess> AsCompletelyLoweredElmApp( + static Result, CompilationSuccess> AsCompletelyLoweredElmApp( IImmutableDictionary, IReadOnlyList> sourceFiles, IImmutableList rootModuleName, IImmutableList interfaceToHostRootModuleName, @@ -130,7 +130,7 @@ static Composition.Result, CompilationSuc if (compilationSuccess != null) { - return new Composition.Result, CompilationSuccess>( + return new Result, CompilationSuccess>( Ok: new CompilationSuccess(compilationSuccess, stack.Select(frame => frame.iterationReport).ToImmutableList().Add(currentIterationReport))); } @@ -151,7 +151,7 @@ static Composition.Result, CompilationSuc if (0 < otherErrors.Count) { - return new Composition.Result, CompilationSuccess>( + return new Result, CompilationSuccess>( Err: otherErrors.Select(error => new LocatedCompilationError(error.location, error: CompilationError.AsCompilationError(error.error))).ToImmutableList()); } @@ -190,7 +190,7 @@ TimedReport completeDependencyReport(Compi if (elmMakeRequest != null) { - Composition.Result> buildResultValue() + Result> buildResultValue() { try { @@ -207,11 +207,11 @@ Composition.Result> buildResultValue() makeJavascript: elmMakeRequest.outputType.ElmMakeOutputTypeJs != null, enableDebug: elmMakeRequest.enableDebug); - return Composition.Result>.ok(value); + return Result>.ok(value); } catch (Exception e) { - return Composition.Result>.err("Failed with runtime exception: " + e.ToString()); + return Result>.err("Failed with runtime exception: " + e.ToString()); } } @@ -234,13 +234,13 @@ currentIterationReport with var newDependenciesWithError = newDependencies.Where(dep => dep.Item1.result.Ok == null).ToImmutableList(); - /* - * TODO: Instead of returning here, probably forward the result back into the compiler for packaging, for example adding location info. - * This implies expansion of the dependencies API to model the error cases. + /* + * TODO: Instead of returning here, probably forward the result back into the compiler for packaging, for example adding location info. + * This implies expansion of the dependencies API to model the error cases. * */ if (0 < newDependenciesWithError.Count) { - return Composition.Result, CompilationSuccess>.err( + return Result, CompilationSuccess>.err( newDependenciesWithError.Select(dep => new LocatedCompilationError( location: null, error: new CompilationError(DependencyError: dep.Item2.report.dependencyKeySummary + " " + dep.Item1.result.Err))) @@ -523,7 +523,7 @@ static long EstimateCacheItemSizeInMemory(CompilerSerialInterface.LocatedCompila static long EstimateCacheItemSizeInMemory(CompilerSerialInterface.CompilationError compilationError) => compilationError?.MissingDependencyError?.Sum(EstimateCacheItemSizeInMemory) ?? 0; - static long EstimateCacheItemSizeInMemory(Composition.Result, CompilationSuccess> item) => + static long EstimateCacheItemSizeInMemory(Result, CompilationSuccess> item) => (item.Err?.Sum(err => EstimateCacheItemSizeInMemory(err)) ?? 0) + (item.Ok != null ? EstimateCacheItemSizeInMemory(item.Ok) : 0); diff --git a/implement/elm-fullstack/ElmInteractive/InteractiveSession.cs b/implement/elm-fullstack/ElmInteractive/InteractiveSession.cs index 48eb8f2d..63b5a117 100644 --- a/implement/elm-fullstack/ElmInteractive/InteractiveSession.cs +++ b/implement/elm-fullstack/ElmInteractive/InteractiveSession.cs @@ -20,7 +20,7 @@ public InteractiveSession(TreeWithStringPath appCodeTree) this.appCodeTree = appCodeTree; } - public Result SubmitAndGetResultingValue(string submission) + public Pine.Result SubmitAndGetResultingValue(string submission) { var result = ElmInteractive.EvaluateSubmissionAndGetResultingValue( diff --git a/implement/elm-fullstack/Pine/Composition.cs b/implement/elm-fullstack/Pine/Composition.cs index 11d9a11a..138c8cf5 100644 --- a/implement/elm-fullstack/Pine/Composition.cs +++ b/implement/elm-fullstack/Pine/Composition.cs @@ -168,7 +168,7 @@ static public IReadOnlyList BlobValueFromSignedInteger(System.Numerics.Big } static public System.Numerics.BigInteger UnsignedIntegerFromBlobValue(Span blobValue) => - new System.Numerics.BigInteger(blobValue.ToArray(), isUnsigned: true, isBigEndian: true); + new(blobValue.ToArray(), isUnsigned: true, isBigEndian: true); public class TreeWithStringPath : IEquatable { @@ -189,13 +189,13 @@ public TreeWithStringPath(IImmutableList<(string name, TreeWithStringPath compon } static public TreeWithStringPath Blob(byte[] blobContent) => - new TreeWithStringPath(blobContent: blobContent); + new(blobContent: blobContent); static public TreeWithStringPath Blob(IReadOnlyList blobContent) => - new TreeWithStringPath(blobContent: blobContent as byte[] ?? blobContent.ToArray()); + new(blobContent: blobContent as byte[] ?? blobContent.ToArray()); static public TreeWithStringPath Tree(IImmutableList<(string name, TreeWithStringPath component)> treeContent) => - new TreeWithStringPath(treeContent: treeContent); + new(treeContent: treeContent); static public TreeWithStringPath EmptyTree => Tree(ImmutableList<(string name, TreeWithStringPath component)>.Empty); @@ -638,31 +638,6 @@ static public Component FindComponentByHash(Component component, byte[] hash) return null; } - public record Result(ErrT Err = default, OkT Ok = default) - { - static public Result err(ErrT err) => - new() { Err = err }; - - static public Result ok(OkT ok) => - new() { Ok = ok }; - - public Result map(Func okMap) - { - if (Ok == null) - return Result.err(Err); - - return Result.ok(okMap(Ok)); - } - - public Result mapError(Func errMap) - { - if (Ok == null) - return Result.err(errMap(Err)); - - return Result.ok(Ok); - } - } - public record ParseAsTreeWithStringPathResult : Result, TreeWithStringPath> { } diff --git a/implement/elm-fullstack/Pine/LoadFromElmEditor.cs b/implement/elm-fullstack/Pine/LoadFromElmEditor.cs index 367cbcd5..026d426a 100644 --- a/implement/elm-fullstack/Pine/LoadFromElmEditor.cs +++ b/implement/elm-fullstack/Pine/LoadFromElmEditor.cs @@ -150,25 +150,25 @@ static public ParseUrlResult ParseUrl(string url) } } - static public Composition.Result LoadFromUrl(string sourceUrl) + static public Result LoadFromUrl(string sourceUrl) { var parsedUrl = ParseUrl(sourceUrl); if (parsedUrl == null) - return Composition.Result.err("Failed to parse string '" + sourceUrl + "' as Elm Editor URL."); + return Result.err("Failed to parse string '" + sourceUrl + "' as Elm Editor URL."); if (LoadFromGitHubOrGitLab.ParsePathFromUrl(parsedUrl.projectStateString) != null) { var loadFromGitHost = LoadFromGitHubOrGitLab.LoadFromUrl(parsedUrl.projectStateString); - if (loadFromGitHost?.Success == null) + if (loadFromGitHost?.Ok == null) { - return Composition.Result.err( - "Failed to load from Git host: " + loadFromGitHost?.Error?.ToString()); + return Result.err( + "Failed to load from Git host: " + loadFromGitHost?.Err?.ToString()); } - return Composition.Result.ok(new LoadFromUrlSuccess(tree: loadFromGitHost.Success.tree)); + return loadFromGitHost.map(loadFromGitHostSuccess => new LoadFromUrlSuccess(tree: loadFromGitHostSuccess.tree)); } // Support parsing tuples: https://github.com/arogozine/TupleAsJsonArray/tree/e59f8c4edee070b096220b6cab77eba997b19d3a @@ -193,7 +193,7 @@ static public Composition.Result LoadFromUrl(string throw new Exception("Project state has an unexpected shape: " + parsedUrl.projectStateString); } - static public Composition.Result LoadProjectState(ProjectState_2021_01.ProjectState projectState) + static public Result LoadProjectState(ProjectState_2021_01.ProjectState projectState) { Composition.TreeWithStringPath baseComposition = null; @@ -202,13 +202,13 @@ static public Composition.Result LoadProjectState(Pr var loadFromGitHost = LoadFromGitHubOrGitLab.LoadFromUrl(projectState.@base); - if (loadFromGitHost?.Success == null) + if (loadFromGitHost?.Ok == null) { - return Composition.Result.err( - "Failed to load from Git host: " + loadFromGitHost?.Error?.ToString()); + return Result.err( + "Failed to load from Git host: " + loadFromGitHost?.Err?.ToString()); } - baseComposition = loadFromGitHost.Success.tree; + baseComposition = loadFromGitHost.Ok.tree; } return @@ -222,7 +222,7 @@ static public Composition.Result LoadProjectState(Pr /// /// applyProjectStateDifference_2021_01 : ProjectState_2021_01.ProjectStateDifference -> FileTree.FileTreeNode Bytes.Bytes -> Result String (FileTree.FileTreeNode Bytes.Bytes) /// - static public Composition.Result ApplyProjectStateDifference_2021_01( + static public Result ApplyProjectStateDifference_2021_01( ProjectState_2021_01.ProjectStateDifference differenceFromBase, Composition.TreeWithStringPath baseComposition) { @@ -245,7 +245,7 @@ static public Composition.Result LoadProjectState(Pr return previousComposition.SetNodeAtPathSorted(blobChange.Item1, Composition.TreeWithStringPath.Blob(changedBlobValue)); }); - return Composition.Result.ok(projectStateAfterChangeBlobs); + return Result.ok(projectStateAfterChangeBlobs); } } } diff --git a/implement/elm-fullstack/Pine/LoadFromGitHubOrGitLab.cs b/implement/elm-fullstack/Pine/LoadFromGitHubOrGitLab.cs index bc64015c..899a10bc 100644 --- a/implement/elm-fullstack/Pine/LoadFromGitHubOrGitLab.cs +++ b/implement/elm-fullstack/Pine/LoadFromGitHubOrGitLab.cs @@ -39,29 +39,16 @@ static string GitHubOrGitLabRegexPattern( "[^/]+/[^/]+)/(-/|)(?<" + typeGroupName + ">blob|tree)/" + "(?<" + refGroupName + ">[^/]+)($|/(?<" + pathGroupName + ">.*))"; - public class ParseObjectUrlResult - { - public string repository; - - public GitObjectType objectType; - - public string @ref; + public record ParseObjectUrlResult( + string repository, + GitObjectType objectType, + string @ref, + string path); - public string path; - - public enum GitObjectType - { - blob = 1, - tree = 2, - } - - public ParseObjectUrlResult WithRef(string @ref) => new ParseObjectUrlResult - { - repository = repository, - objectType = objectType, - @ref = @ref, - path = path - }; + public enum GitObjectType + { + blob = 1, + tree = 2, } static public ParseObjectUrlResult ParsePathFromUrl(string objectUrl) @@ -85,12 +72,12 @@ static public ParseObjectUrlResult ParsePathFromUrl(string objectUrl) return null; return new ParseObjectUrlResult - { - repository = regexMatch.Groups[repositoryGroupName].Value, - objectType = Enum.Parse(regexMatch.Groups[typeGroupName].Value), - @ref = regexMatch.Groups[refGroupName].Value, - path = regexMatch.Groups[pathGroupName].Value, - }; + ( + repository: regexMatch.Groups[repositoryGroupName].Value, + objectType: Enum.Parse(regexMatch.Groups[typeGroupName].Value), + @ref: regexMatch.Groups[refGroupName].Value, + path: regexMatch.Groups[pathGroupName].Value + ); } static public string BackToUrl(ParseObjectUrlResult parseObjectUrlResult) => @@ -99,15 +86,13 @@ static public string BackToUrl(ParseObjectUrlResult parseObjectUrlResult) => parseObjectUrlResult.@ref + "/" + parseObjectUrlResult.path; - static public LoadFromUrlResult LoadFromUrl(string sourceUrl) + static public Result LoadFromUrl(string sourceUrl) { var parsedUrl = ParsePathFromUrl(sourceUrl); if (parsedUrl == null) - return new LoadFromUrlResult - { - Error = "Failed to parse string '" + sourceUrl + "' as GitHub or GitLab object URL.", - }; + return Result.err( + "Failed to parse string '" + sourceUrl + "' as GitHub or GitLab object URL."); var refLooksLikeCommit = Regex.IsMatch(parsedUrl.@ref, "[A-Fa-f0-9]{40}"); @@ -142,12 +127,10 @@ static public LoadFromUrlResult LoadFromUrl(string sourceUrl) var commit = gitRepository.Lookup(parsedUrl.@ref) as Commit; if (commit == null) - return new LoadFromUrlResult - { - Error = "I did not find the commit for ref '" + parsedUrl.@ref + "'.", - }; + return Result.err( + "I did not find the commit for ref '" + parsedUrl.@ref + "'."); - urlInCommit = BackToUrl(parsedUrl.WithRef(commit.Sha)); + urlInCommit = BackToUrl(parsedUrl with { @ref = commit.Sha }); rootCommit = GetCommitHashAndContent(commit); @@ -156,13 +139,11 @@ static public LoadFromUrlResult LoadFromUrl(string sourceUrl) var findGitObjectResult = FindGitObjectAtPath(commit.Tree, pathNodesNames); - var linkedObject = findGitObjectResult?.Success; + var linkedObject = findGitObjectResult?.Ok; if (linkedObject == null) - return new LoadFromUrlResult - { - Error = "I did not find an object at path '" + parsedUrl.path + "' in " + commit.Sha, - }; + return Result.err( + "I did not find an object at path '" + parsedUrl.path + "' in " + commit.Sha); IEnumerable traceBackTreeParents() { @@ -176,7 +157,7 @@ IEnumerable traceBackTreeParents() foreach (var parent in currentCommit.Parents) { - if (FindGitObjectAtPath(parent.Tree, pathNodesNames)?.Success?.Sha != linkedObject?.Sha) + if (FindGitObjectAtPath(parent.Tree, pathNodesNames)?.Ok?.Sha != linkedObject?.Sha) continue; queue.Enqueue(parent); @@ -188,7 +169,7 @@ IEnumerable traceBackTreeParents() GetCommitHashAndContent(traceBackTreeParents().OrderBy(commit => commit.Author.When).First()); urlInFirstParentCommitWithSameValueAtThisPath = - BackToUrl(parsedUrl.WithRef(firstParentCommitWithSameTree.Value.hash)); + BackToUrl(parsedUrl with { @ref = firstParentCommitWithSameTree.Value.hash }); static Composition.TreeWithStringPath convertToLiteralNodeObjectRecursive(GitObject gitObject) { @@ -235,10 +216,7 @@ static Composition.TreeWithStringPath convertToLiteralNodeObjectRecursive(GitObj } catch (Exception e) { - return new LoadFromUrlResult - { - Error = "Failed to convert from git object:\n" + e.ToString(), - }; + return Result.err("Failed to convert from git object:\n" + e.ToString()); } } @@ -255,46 +233,38 @@ A user got a `System.IO.DirectoryNotFoundException` out of `DeleteLocalDirectory */ } - return new LoadFromUrlResult - { - Success = new LoadFromUrlSuccess - { - tree = literalNodeObject, - urlInCommit = urlInCommit, - urlInFirstParentCommitWithSameValueAtThisPath = urlInFirstParentCommitWithSameValueAtThisPath, - rootCommit = rootCommit.Value, - firstParentCommitWithSameTree = firstParentCommitWithSameTree.Value, - } - }; + return Result.ok( + new LoadFromUrlSuccess + ( + tree: literalNodeObject, + urlInCommit: urlInCommit, + urlInFirstParentCommitWithSameValueAtThisPath: urlInFirstParentCommitWithSameValueAtThisPath, + rootCommit: rootCommit.Value, + firstParentCommitWithSameTree: firstParentCommitWithSameTree.Value + ) + ); } static public (string hash, CommitContent content) GetCommitHashAndContent(Commit commit) { return (commit.Sha, new CommitContent - { - message = commit.Message, - author = GetParticipantSignature(commit.Author), - committer = GetParticipantSignature(commit.Committer), - }); + ( + message: commit.Message, + author: GetParticipantSignature(commit.Author), + committer: GetParticipantSignature(commit.Committer) + )); } static public GitParticipantSignature GetParticipantSignature(Signature signature) { return new GitParticipantSignature - { - name = signature.Name, - email = signature.Email, - }; + ( + name: signature.Name, + email: signature.Email + ); } - class FollowGitPathResult - { - public GitObject Success; - - public object Error; - } - - static FollowGitPathResult FindGitObjectAtPath(Tree root, IEnumerable nodesNames) + static Result FindGitObjectAtPath(Tree root, IEnumerable nodesNames) { if (root == null) return null; @@ -306,10 +276,7 @@ static FollowGitPathResult FindGitObjectAtPath(Tree root, IEnumerable no var currentTree = currentObject as Tree; if (currentTree == null) - return new FollowGitPathResult - { - Error = new object(), - }; + return Result.err(new object()); var treeEntry = currentTree?[nodeName]; @@ -321,10 +288,7 @@ static FollowGitPathResult FindGitObjectAtPath(Tree root, IEnumerable no treeEntry.Target; } - return new FollowGitPathResult - { - Success = currentObject, - }; + return Result.ok(currentObject); } static byte[] GitBlobSHAFromBlobContent(byte[] blobContent) @@ -337,43 +301,24 @@ static byte[] GitBlobSHAFromBlobContent(byte[] blobContent) return hasher.ComputeHash(hashedValue); } - public class LoadFromUrlResult - { - public object Error; - - public LoadFromUrlSuccess Success; - } - - public class LoadFromUrlSuccess + public record LoadFromUrlSuccess( + Composition.TreeWithStringPath tree, + string urlInCommit, + string urlInFirstParentCommitWithSameValueAtThisPath, + (string hash, CommitContent content) rootCommit, + (string hash, CommitContent content) firstParentCommitWithSameTree) { - public Composition.TreeWithStringPath tree; - - public string urlInCommit; - - public string urlInFirstParentCommitWithSameValueAtThisPath; - - public (string hash, CommitContent content) rootCommit; - - public (string hash, CommitContent content) firstParentCommitWithSameTree; - public IReadOnlyList AsBlob => tree?.BlobContent; } - public class CommitContent - { - public string message; - - public GitParticipantSignature author; - - public GitParticipantSignature committer; - } - - public class GitParticipantSignature - { - public string name; + public record CommitContent( + string message, + GitParticipantSignature author, + GitParticipantSignature committer); - public string email; - } + public record GitParticipantSignature( + string name, + string email); /// /// https://github.com/libgit2/libgit2sharp/issues/769#issuecomment-198833179 diff --git a/implement/elm-fullstack/Pine/LoadFromPath.cs b/implement/elm-fullstack/Pine/LoadFromPath.cs index cb7a73f5..088a6ac0 100644 --- a/implement/elm-fullstack/Pine/LoadFromPath.cs +++ b/implement/elm-fullstack/Pine/LoadFromPath.cs @@ -11,14 +11,13 @@ static public class LoadFromPath var loadFromGitHost = LoadFromGitHubOrGitLab.LoadFromUrl(path); - if (loadFromGitHost?.Success == null) + if (loadFromGitHost?.Ok == null) { return Result.err( - "Failed to load from Git host: " + loadFromGitHost?.Error?.ToString()); + "Failed to load from Git host: " + loadFromGitHost?.Err?.ToString()); } - return Result.ok( - (loadFromGitHost.Success.tree, comesFromLocalFilesystem: false)); + return loadFromGitHost.map(loadFromGitHostOk => (loadFromGitHostOk.tree, comesFromLocalFilesystem: false)); } if (LoadFromElmEditor.ParseUrl(path) != null) diff --git a/implement/elm-fullstack/Pine/Result.cs b/implement/elm-fullstack/Pine/Result.cs new file mode 100644 index 00000000..d5194b16 --- /dev/null +++ b/implement/elm-fullstack/Pine/Result.cs @@ -0,0 +1,29 @@ +using System; + +namespace Pine +{ + public record Result(ErrT Err = default, OkT Ok = default) + { + static public Result err(ErrT err) => + new() { Err = err }; + + static public Result ok(OkT ok) => + new() { Ok = ok }; + + public Result map(Func okMap) + { + if (Ok == null) + return Result.err(Err); + + return Result.ok(okMap(Ok)); + } + + public Result mapError(Func errMap) + { + if (Ok == null) + return Result.err(errMap(Err)); + + return Result.ok(Ok); + } + } +} diff --git a/implement/elm-fullstack/WebHost/PersistentProcessLiveRepresentation.cs b/implement/elm-fullstack/WebHost/PersistentProcessLiveRepresentation.cs index bb6b83ad..2f92d054 100644 --- a/implement/elm-fullstack/WebHost/PersistentProcessLiveRepresentation.cs +++ b/implement/elm-fullstack/WebHost/PersistentProcessLiveRepresentation.cs @@ -551,9 +551,7 @@ Composition.TreeWithStringPath loadComponentFromStoreAndAssertIsTree(string comp throw new Exception("Unexpected shape of composition event: " + JsonConvert.SerializeObject(compositionEvent)); } - public record Result(ErrT Err = default, OkT Ok = default); - - static public Composition.Result filePath, IReadOnlyList fileContent)> projectedFiles, IFileStoreReader projectedReader)> + static public Result filePath, IReadOnlyList fileContent)> projectedFiles, IFileStoreReader projectedReader)> TestContinueWithCompositionEvent( CompositionLogRecordInFile.CompositionEvent compositionLogEvent, IFileStoreReader fileStoreReader) @@ -569,11 +567,11 @@ public record Result(ErrT Err = default, OkT Ok = default); } catch (Exception e) { - return Composition.Result filePath, IReadOnlyList fileContent)> projectedFiles, IFileStoreReader projectedReader)>.err( + return Result filePath, IReadOnlyList fileContent)> projectedFiles, IFileStoreReader projectedReader)>.err( "Failed with exception: " + e.ToString()); } - return Composition.Result filePath, IReadOnlyList fileContent)> projectedFiles, IFileStoreReader projectedReader)>.ok( + return Result filePath, IReadOnlyList fileContent)> projectedFiles, IFileStoreReader projectedReader)>.ok( projectionResult); } diff --git a/implement/elm-fullstack/WebHost/StartupAdminInterface.cs b/implement/elm-fullstack/WebHost/StartupAdminInterface.cs index 90aa916d..1d0d804b 100644 --- a/implement/elm-fullstack/WebHost/StartupAdminInterface.cs +++ b/implement/elm-fullstack/WebHost/StartupAdminInterface.cs @@ -838,7 +838,7 @@ static public (int statusCode, AttemptContinueWithCompositionEventReport respons beginTime = beginTime, compositionEvent = compositionLogEvent, totalTimeSpentMilli = (int)totalStopwatch.ElapsedMilliseconds, - result = Composition.Result.err(testContinueResult.Err), + result = Result.err(testContinueResult.Err), }); } @@ -851,7 +851,7 @@ static public (int statusCode, AttemptContinueWithCompositionEventReport respons beginTime = beginTime, compositionEvent = compositionLogEvent, totalTimeSpentMilli = (int)totalStopwatch.ElapsedMilliseconds, - result = Composition.Result.ok("Successfully applied this composition event to the process."), + result = Result.ok("Successfully applied this composition event to the process."), }); } } @@ -868,7 +868,7 @@ public class AttemptContinueWithCompositionEventReport public int totalTimeSpentMilli; - public Composition.Result result; + public Result result; } public class TruncateProcessHistoryReport diff --git a/implement/elm-fullstack/elm-fullstack.csproj b/implement/elm-fullstack/elm-fullstack.csproj index 1a21f9f5..d1bc92c2 100644 --- a/implement/elm-fullstack/elm-fullstack.csproj +++ b/implement/elm-fullstack/elm-fullstack.csproj @@ -24,11 +24,11 @@ - + - + diff --git a/implement/example-apps/elm-editor/src/Backend/VolatileProcess.csx b/implement/example-apps/elm-editor/src/Backend/VolatileProcess.csx index a273d48f..37b66dbb 100644 --- a/implement/example-apps/elm-editor/src/Backend/VolatileProcess.csx +++ b/implement/example-apps/elm-editor/src/Backend/VolatileProcess.csx @@ -11,8 +11,8 @@ // https://www.nuget.org/api/v2/package/Newtonsoft.Json/12.0.2 #r "sha256:b9b4e633ea6c728bad5f7cbbef7f8b842f7e10181731dbe5ec3cd995a6f60287" -// from elm-fullstack-separate-assemblies-289b468ee441567ea57dd964e8a74c2c0a690e2b-linux-x64.zip -#r "sha256:cae11397edf179c7c59608270c6bad6c6834d345427083e9b0fc7268ccfe3d45" +// from elm-fullstack-separate-assemblies-4505d5fa0951dbb5d83383b17058704c58ebc674-linux-x64.zip +#r "sha256:67d1550a5b06e9b361fdc9220062dd960e036e7daaa063e92380d186f93089cf" using System; using System.Collections.Generic; @@ -153,16 +153,16 @@ ResponseStructure GetResponseFromRequest(RequestStructure request) var loadFromGitResult = Pine.LoadFromGitHubOrGitLab.LoadFromUrl(sourcePath); - if (loadFromGitResult?.Success == null) + if (loadFromGitResult?.Ok == null) { return new ResponseStructure { ErrorResponse = ImmutableList.Create( - "Failed to load from path '" + sourcePath + "': " + loadFromGitResult?.Error) + "Failed to load from path '" + sourcePath + "': " + loadFromGitResult?.Err) }; } - if (loadFromGitResult?.Success?.tree == null) + if (loadFromGitResult?.Ok?.tree == null) { return new ResponseStructure { @@ -170,15 +170,15 @@ ResponseStructure GetResponseFromRequest(RequestStructure request) }; } - var composition = Pine.Composition.FromTreeWithStringPath(loadFromGitResult.Success.tree); + var composition = Pine.Composition.FromTreeWithStringPath(loadFromGitResult.Ok.tree); var compositionId = Pine.CommonConversion.StringBase16FromByteArray(Pine.Composition.GetHash(composition)); var blobs = - loadFromGitResult.Success.tree.EnumerateBlobsTransitive() + loadFromGitResult.Ok.tree.EnumerateBlobsTransitive() .ToImmutableList(); - var urlInCommit = loadFromGitResult.Success.urlInCommit; + var urlInCommit = loadFromGitResult.Ok.urlInCommit; ResponseStructure responseErrorExceedingLimit(string limitName) { diff --git a/implement/test-elm-fullstack/TestLoadFromGithub.cs b/implement/test-elm-fullstack/TestLoadFromGithub.cs index 3982cf3e..97aa35db 100644 --- a/implement/test-elm-fullstack/TestLoadFromGithub.cs +++ b/implement/test-elm-fullstack/TestLoadFromGithub.cs @@ -26,10 +26,10 @@ public void Test_LoadFromGithub_Tree() Pine.LoadFromGitHubOrGitLab.LoadFromUrl( "https://github.com/elm-fullstack/elm-fullstack/tree/30c482748f531899aac2b2d4895e5f0e52258be7/implement/PersistentProcess/example-elm-apps/default-full-stack-app"); - Assert.IsNull(loadFromGithubResult.Error, "No error: " + loadFromGithubResult.Error); + Assert.IsNull(loadFromGithubResult.Err, "No error: " + loadFromGithubResult.Err); var loadedFilesNamesAndContents = - loadFromGithubResult.Success.tree.EnumerateBlobsTransitive() + loadFromGithubResult.Ok.tree.EnumerateBlobsTransitive() .Select(blobPathAndContent => ( fileName: string.Join("/", blobPathAndContent.path), fileContent: blobPathAndContent.blobContent)) @@ -61,10 +61,10 @@ public void Test_LoadFromGithub_Tree_at_root() Pine.LoadFromGitHubOrGitLab.LoadFromUrl( "https://github.com/elm-fullstack/elm-fullstack/blob/30c482748f531899aac2b2d4895e5f0e52258be7/"); - Assert.IsNull(loadFromGithubResult.Error, "No error: " + loadFromGithubResult.Error); + Assert.IsNull(loadFromGithubResult.Err, "No error: " + loadFromGithubResult.Err); var loadedFilesNamesAndContents = - loadFromGithubResult.Success.tree.EnumerateBlobsTransitive() + loadFromGithubResult.Ok.tree.EnumerateBlobsTransitive() .Select(blobPathAndContent => ( fileName: string.Join("/", blobPathAndContent.path), fileContent: blobPathAndContent.blobContent)) @@ -96,9 +96,9 @@ public void Test_LoadFromGithub_Object() Pine.LoadFromGitHubOrGitLab.LoadFromUrl( "https://github.com/elm-fullstack/elm-fullstack/blob/30c482748f531899aac2b2d4895e5f0e52258be7/README.md"); - Assert.IsNull(loadFromGithubResult.Error, "No error: " + loadFromGithubResult.Error); + Assert.IsNull(loadFromGithubResult.Err, "No error: " + loadFromGithubResult.Err); - var blobContent = loadFromGithubResult.Success.tree.BlobContent; + var blobContent = loadFromGithubResult.Ok.tree.BlobContent; Assert.IsNotNull(blobContent, "Found blobContent."); @@ -116,25 +116,25 @@ public void LoadFromGithub_Commits_Contents_And_Lineage() Pine.LoadFromGitHubOrGitLab.LoadFromUrl( "https://github.com/Viir/bots/tree/6c5442434768625a4df9d0dfd2f54d61d9d1f61e/implement/applications"); - Assert.IsNull(loadFromGithubResult.Error, "No error: " + loadFromGithubResult.Error); + Assert.IsNull(loadFromGithubResult.Err, "No error: " + loadFromGithubResult.Err); Assert.AreEqual( "https://github.com/Viir/bots/tree/6c5442434768625a4df9d0dfd2f54d61d9d1f61e/implement/applications", - loadFromGithubResult.Success.urlInCommit); + loadFromGithubResult.Ok.urlInCommit); Assert.AreEqual( "https://github.com/Viir/bots/tree/1f915f4583cde98e0491e66bc73d7df0e92d1aac/implement/applications", - loadFromGithubResult.Success.urlInFirstParentCommitWithSameValueAtThisPath); + loadFromGithubResult.Ok.urlInFirstParentCommitWithSameValueAtThisPath); - Assert.AreEqual("6c5442434768625a4df9d0dfd2f54d61d9d1f61e", loadFromGithubResult.Success.rootCommit.hash); - Assert.AreEqual("Support finding development guides\n", loadFromGithubResult.Success.rootCommit.content.message); - Assert.AreEqual("Michael Rätzel", loadFromGithubResult.Success.rootCommit.content.author.name); - Assert.AreEqual("viir@viir.de", loadFromGithubResult.Success.rootCommit.content.author.email); + Assert.AreEqual("6c5442434768625a4df9d0dfd2f54d61d9d1f61e", loadFromGithubResult.Ok.rootCommit.hash); + Assert.AreEqual("Support finding development guides\n", loadFromGithubResult.Ok.rootCommit.content.message); + Assert.AreEqual("Michael Rätzel", loadFromGithubResult.Ok.rootCommit.content.author.name); + Assert.AreEqual("viir@viir.de", loadFromGithubResult.Ok.rootCommit.content.author.email); - Assert.AreEqual("1f915f4583cde98e0491e66bc73d7df0e92d1aac", loadFromGithubResult.Success.firstParentCommitWithSameTree.hash); - Assert.AreEqual("Guide users\n\nClarify the bot uses drones if available.\n", loadFromGithubResult.Success.firstParentCommitWithSameTree.content.message); - Assert.AreEqual("John", loadFromGithubResult.Success.firstParentCommitWithSameTree.content.author.name); - Assert.AreEqual("john-dev@botengine.email", loadFromGithubResult.Success.firstParentCommitWithSameTree.content.author.email); + Assert.AreEqual("1f915f4583cde98e0491e66bc73d7df0e92d1aac", loadFromGithubResult.Ok.firstParentCommitWithSameTree.hash); + Assert.AreEqual("Guide users\n\nClarify the bot uses drones if available.\n", loadFromGithubResult.Ok.firstParentCommitWithSameTree.content.message); + Assert.AreEqual("John", loadFromGithubResult.Ok.firstParentCommitWithSameTree.content.author.name); + Assert.AreEqual("john-dev@botengine.email", loadFromGithubResult.Ok.firstParentCommitWithSameTree.content.author.email); } } }