~james/core

core/web/src/lib/repoQuery.ts -rw-r--r-- 1.3 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 15 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { LANGUAGE_COLORS } from "#lib/components/repo/languageColors.ts";
import { SORT_OPTIONS, SORT_VALUES, type QueryDialect } from "#lib/ticketQuery.ts";

export const POPULAR_LANGUAGES = [
	"Go",
	"JavaScript",
	"TypeScript",
	"Python",
	"Rust",
	"OCaml",
	"Haskell",
	"C",
	"C++",
	"Ruby",
	"Swift"
];

const LANGUAGE_OPTIONS = [
	...POPULAR_LANGUAGES,
	...Object.keys(LANGUAGE_COLORS)
		.filter((name) => !POPULAR_LANGUAGES.includes(name))
		.sort((a, b) => a.localeCompare(b))
].map((value) => ({ value }));

type RepoKey = "language" | "author" | "sort";

const repoDialect = (qualifiers: readonly RepoKey[]): QueryDialect<RepoKey> => ({
	qualifiers,
	hints: {
		language: "primary language",
		author: "handle or did",
		sort: "order"
	},
	values: (key) => {
		switch (key) {
			case "language":
				return LANGUAGE_OPTIONS;
			case "sort":
				return SORT_OPTIONS;
			case "author":
				return [];
		}
	},
	problem: (key, value) => {
		const v = value.trim().toLowerCase();
		if (v === "") return `\`${key}:\` needs a value`;
		if (key === "sort" && !SORT_VALUES.has(v)) return `\`${key}:${value}\` is not valid`;
		return null;
	}
});

export const REPO_DIALECT = repoDialect(["language", "author", "sort"]);

export const OWNED_REPO_DIALECT = repoDialect(["language", "sort"]);