Skip to content

Commit

Permalink
feat: ensure rust result type is parsed and returned to FE as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
ndom91 committed Nov 19, 2024
1 parent a9c769b commit 574670e
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions apps/desktop/src/lib/vbranches/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,23 @@ import { emptyConflictEntryPresence, type ConflictEntryPresence } from '$lib/con
import { splitMessage } from '$lib/utils/commitMessage';
import { hashCode } from '@gitbutler/ui/utils/string';
import { isDefined } from '@gitbutler/ui/utils/typeguards';
import { Type, Transform } from 'class-transformer';
import { Type, Transform, plainToInstance } from 'class-transformer';
import type { PullRequest } from '$lib/forge/interface/types';

function transformResultToType(type: any, value: any) {
if (!Array.isArray(value)) return plainToInstance(type, value);

return value.map((item) => {
if ('Ok' in item) {
return plainToInstance(type, item.Ok);
}
if ('Err' in item) {
return new Error(item.Err.description);
}
return plainToInstance(type, item);
});
}

export type ChangeType =
/// Entry does not exist in old version
| 'added'
Expand Down Expand Up @@ -138,8 +152,8 @@ export class VirtualBranch {
tree!: string;

// Used in the stacking context where VirtualBranch === Stack
@Type(() => PatchSeries)
series!: PatchSeries[];
@Transform(({ value }) => transformResultToType(PatchSeries, value))
series!: (PatchSeries | Error)[];

get localCommits() {
return this.commits.filter((c) => c.status === 'local');
Expand Down

0 comments on commit 574670e

Please sign in to comment.