-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(datasource/custom): add toml support #28594
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { readLocalFile } from '../../../../util/fs'; | ||
import { parse as parseToml } from '../../../../util/toml'; | ||
import type { Http } from '../../../../util/http'; | ||
import type { CustomDatasourceFetcher } from './types'; | ||
|
||
export class TomlFetcher implements CustomDatasourceFetcher { | ||
async fetch(http: Http, registryURL: string): Promise<unknown> { | ||
const response = await http.getToml(registryURL) | ||
|
||
const contentType = response.headers['content-type']; | ||
if (!contentType?.startsWith('application/toml')) { | ||
return null; | ||
} | ||
|
||
return parseToml(response.body); | ||
} | ||
|
||
async readFile(registryURL: string): Promise<unknown> { | ||
const fileContent = await readLocalFile(registryURL, 'utf8'); | ||
|
||
return parseToml(fileContent!); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -316,6 +316,16 @@ export class Http<Opts extends HttpOptions = HttpOptions> { | |
}); | ||
} | ||
|
||
async getToml(url: string, options?: Opts): Promise<HttpResponse> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs a separate test in It should also parse the toml and support optional schema validation. please do it like the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha, I understand now how the JSON side works. Just to make sure I understand, you want two PRs.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, the split can be done last after this pr There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did some more digging and had some more downtime to look into this. I may be missing something, but I can't do it precisely like The best I can do is to use a more basic type like Still working on the It appears some of the other JSON support floating around is for interfacing with other systems / clients. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, do the parsing in Http class |
||
const opt = options ?? {}; | ||
return await this.get(url, { | ||
headers: { | ||
Accept: 'application/toml' | ||
}, | ||
...opt, | ||
}) | ||
} | ||
|
||
getJson<ResT>(url: string, options?: Opts): Promise<HttpResponse<ResT>>; | ||
getJson<ResT, Schema extends ZodType<ResT> = ZodType<ResT>>( | ||
url: string, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should split this file because it's becoming too big. Should of cause be done in a separate PR.