Skip to content

Commit 451d5cb

Browse files
committed
fix: Fix serialization bug in storage
1 parent 4618c74 commit 451d5cb

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/storage/serialization.ts

+24-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isObject } from "@/helpers";
12
import type { GitHubGraphQl } from "@/services/github/types";
23
import { GitHub } from "@/types";
34
import { convertStringToURL } from "@/utils";
@@ -91,16 +92,22 @@ export function fromGraphQlData(
9192
}
9293
}
9394

95+
type ParsedFundingLink = {
96+
url: string;
97+
platform: string;
98+
};
99+
94100
export function fromDbObject(
95101
row: ParamsObject,
96102
): Result<GitHub.Repository, unknown> {
97103
try {
98104
const parsedLatestRelease = row.latestRelease
99105
? JSON.parse(row.latestRelease as string)
100106
: undefined;
101-
const parsedFundingLinks = row.fundingLinks
102-
? JSON.parse(row.fundingLinks as string)
103-
: undefined;
107+
108+
const parsedFundingLinks: ParsedFundingLink[] = row.fundingLinks
109+
? (JSON.parse(row.fundingLinks as string) as ParsedFundingLink[])
110+
: [];
104111
const repo = new GitHub.Repository({
105112
id: row.id as string,
106113
name: row.name as string,
@@ -120,7 +127,7 @@ export function fromDbObject(
120127
isFork: !!(row.isFork as number),
121128
isPrivate: !!(row.isPrivate as number),
122129
isTemplate: !!(row.isTemplate as number),
123-
latestRelease: parsedLatestRelease
130+
latestRelease: isObject(parsedLatestRelease)
124131
? {
125132
name: parsedLatestRelease.name as string,
126133
publishedAt: DateTime.fromISO(
@@ -153,14 +160,21 @@ export function fromDbObject(
153160
: undefined,
154161
updatedAt: DateTime.fromISO(row.updatedAt as string).toUTC(),
155162
importedAt: DateTime.fromISO(row.importedAt as string).toUTC(),
156-
languages: row.languages ? JSON.parse(row.languages as string) : [],
163+
languages: row.languages
164+
? (JSON.parse(row.languages as string) as string[])
165+
: [],
157166
});
158167

159-
for (const link of parsedFundingLinks) {
160-
repo.fundingLinks.push({
161-
url: convertStringToURL(link.url),
162-
platform: link.platform,
163-
});
168+
if (parsedFundingLinks && Array.isArray(parsedFundingLinks)) {
169+
for (const link of parsedFundingLinks) {
170+
repo.fundingLinks.push({
171+
url: convertStringToURL(link.url),
172+
platform:
173+
GitHub.FundingPlatform[
174+
link.platform as keyof typeof GitHub.FundingPlatform
175+
],
176+
});
177+
}
164178
}
165179
return ok(repo);
166180
} catch (error) {

0 commit comments

Comments
 (0)