Function bodies 84 total
getDataSource function · typescript · L65-L77 (13 LOC)lib/db/data-source.ts
export function getDataSource(): DataSource {
const existing = cache.byClass.get(Skill);
if (existing) return existing;
// Cache miss: a new bundle identity showed up. Tear down every old
// DataSource before creating the new one so we don't leak pools.
for (const old of cache.byClass.values()) destroyQuietly(old);
cache.byClass.clear();
const ds = buildDataSource();
cache.byClass.set(Skill, ds);
return ds;
}ensureInitialized function · typescript · L79-L93 (15 LOC)lib/db/data-source.ts
export async function ensureInitialized(): Promise<DataSource> {
const ds = getDataSource();
if (!ds.isInitialized) {
try {
await ds.initialize();
} catch (err) {
// Failed init leaves TypeORM in a half-built state. Drop this instance
// from the cache so the next call builds a fresh one instead of
// hitting "Called end on pool more than once".
cache.byClass.delete(Skill);
throw err;
}
}
return ds;
}Account class · typescript · L5-L42 (38 LOC)lib/db/entities/account.entity.ts
export class Account {
@PrimaryGeneratedColumn("uuid")
id!: string;
@Index()
@Column({ type: "uuid" })
userId!: string;
@Column({ type: "text" })
type!: string;
@Column({ type: "text" })
provider!: string;
@Column({ type: "text" })
providerAccountId!: string;
@Column({ type: "text", nullable: true })
refresh_token!: string | null;
@Column({ type: "text", nullable: true })
access_token!: string | null;
@Column({ type: "bigint", nullable: true })
expires_at!: string | null;
@Column({ type: "text", nullable: true })
token_type!: string | null;
@Column({ type: "text", nullable: true })
scope!: string | null;
@Column({ type: "text", nullable: true })
id_token!: string | null;
@Column({ type: "text", nullable: true })
session_state!: string | null;
}Base class · typescript · L3-L12 (10 LOC)lib/db/entities/base.entity.ts
export abstract class Base {
@PrimaryGeneratedColumn("uuid")
id!: string;
@CreateDateColumn({ type: "timestamptz" })
createdAt!: Date;
@UpdateDateColumn({ type: "timestamptz" })
updatedAt!: Date;
}Favorite class · typescript · L4-L14 (11 LOC)lib/db/entities/favorite.entity.ts
export class Favorite {
@PrimaryColumn({ type: "uuid" })
userId!: string;
@Index()
@PrimaryColumn({ type: "uuid" })
skillId!: string;
@CreateDateColumn({ type: "timestamptz" })
createdAt!: Date;
}InstallLog class · typescript · L7-L22 (16 LOC)lib/db/entities/install-log.entity.ts
export class InstallLog {
@PrimaryGeneratedColumn("uuid")
id!: string;
@Column({ type: "uuid", nullable: true })
userId!: string | null;
@Column({ type: "uuid" })
skillId!: string;
@Column({ type: "text" })
source!: InstallSource;
@CreateDateColumn({ type: "timestamptz" })
createdAt!: Date;
}Session class · typescript · L4-L18 (15 LOC)lib/db/entities/session.entity.ts
export class Session {
@PrimaryGeneratedColumn("uuid")
id!: string;
@Index({ unique: true })
@Column({ type: "text" })
sessionToken!: string;
@Index()
@Column({ type: "uuid" })
userId!: string;
@Column({ type: "timestamptz" })
expires!: Date;
}Methodology: Repobility · https://repobility.com/research/state-of-ai-code-2026/
Skill class · typescript · L15-L68 (54 LOC)lib/db/entities/skill.entity.ts
export class Skill extends Base {
@Index({ unique: true })
@Column({ type: "text" })
slug!: string;
@Column({ type: "text" })
name!: string;
@Column({ type: "text" })
tagline!: string;
@Column({ type: "text" })
description!: string;
@Column({ type: "text" })
version!: string;
@Column({ type: "text" })
author!: string;
@Column({ type: "text" })
repoUrl!: string;
@Column({ type: "text", nullable: true })
homepageUrl!: string | null;
@Column({ type: "text", nullable: true })
licenseSpdx!: string | null;
@Index()
@Column({ type: "text" })
category!: SkillCategory;
@Column({ type: "text", array: true, default: () => "'{}'" })
tags!: string[];
@Column({ type: "int", default: 0 })
installCount!: number;
@Column({ type: "int", default: 0 })
favoriteCount!: number;
@Column({ type: "boolean", default: false })
featured!: boolean;
@Column({ type: "timestamptz", nullable: true })
publishedAt!: Date | null;
@Column({ tUser class · typescript · L5-L22 (18 LOC)lib/db/entities/user.entity.ts
export class User extends Base {
@Index({ unique: true })
@Column({ type: "bigint" })
githubId!: string;
@Index({ unique: true })
@Column({ type: "text" })
username!: string;
@Column({ type: "text", nullable: true })
name!: string | null;
@Column({ type: "text", nullable: true })
avatarUrl!: string | null;
@Column({ type: "text", nullable: true })
email!: string | null;
}InitialSchema1776188627566 class · typescript · L3-L73 (71 LOC)lib/db/migrations/1776188627566-InitialSchema.ts
export class InitialSchema1776188627566 implements MigrationInterface {
name = 'InitialSchema1776188627566'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`);
await queryRunner.query(`CREATE TABLE "user" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "githubId" bigint NOT NULL, "username" text NOT NULL, "name" text, "avatarUrl" text, "email" text, CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_0d84cc6a830f0e4ebbfcd6381d" ON "user" ("githubId") `);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_78a916df40e02a9deb1c4b75ed" ON "user" ("username") `);
await queryRunner.query(`CREATE TABLE "skill" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP WITH Tup method · typescript · L6-L47 (42 LOC)lib/db/migrations/1776188627566-InitialSchema.ts
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`);
await queryRunner.query(`CREATE TABLE "user" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "githubId" bigint NOT NULL, "username" text NOT NULL, "name" text, "avatarUrl" text, "email" text, CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_0d84cc6a830f0e4ebbfcd6381d" ON "user" ("githubId") `);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_78a916df40e02a9deb1c4b75ed" ON "user" ("username") `);
await queryRunner.query(`CREATE TABLE "skill" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "slug" text NOT NULdown method · typescript · L49-L71 (23 LOC)lib/db/migrations/1776188627566-InitialSchema.ts
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "public"."idx_skill_search_vector"`);
await queryRunner.query(`ALTER TABLE "skill" DROP COLUMN "searchVector"`);
await queryRunner.query(`DROP FUNCTION IF EXISTS skill_search_vector(text, text, text[], text)`);
await queryRunner.query(`DROP INDEX "public"."IDX_31266a690d39e423c772e1fee0"`);
await queryRunner.query(`DROP TABLE "favorite"`);
await queryRunner.query(`DROP INDEX "public"."IDX_32054f2625f6b8e31319d0e020"`);
await queryRunner.query(`DROP INDEX "public"."IDX_60328bf27019ff5498c4b97742"`);
await queryRunner.query(`DROP TABLE "account"`);
await queryRunner.query(`DROP INDEX "public"."idx_install_skill_created"`);
await queryRunner.query(`DROP TABLE "install_log"`);
await queryRunner.query(`DROP INDEX "public"."IDX_3d2f174ef04fb312fdebd0ddc5"`);
await queryRunner.query(`DROP INDEX "pubFavoriteRepository class · typescript · L4-L48 (45 LOC)lib/db/repositories/favorite.repository.ts
export class FavoriteRepository {
async favorite(userId: string, skillId: string): Promise<{ count: number }> {
const ds = await ensureInitialized();
return ds.transaction(async (m) => {
const existing = await m.getRepository(Favorite).findOne({ where: { userId, skillId } });
if (existing) {
const skill = await m.getRepository(Skill).findOneByOrFail({ id: skillId });
return { count: skill.favoriteCount };
}
await m.getRepository(Favorite).insert({ userId, skillId });
await m.getRepository(Skill).increment({ id: skillId }, "favoriteCount", 1);
const skill = await m.getRepository(Skill).findOneByOrFail({ id: skillId });
return { count: skill.favoriteCount };
});
}
async unfavorite(userId: string, skillId: string): Promise<{ count: number }> {
const ds = await ensureInitialized();
return ds.transaction(async (m) => {
const res = await m.getRepository(Favorite).delete({ userId, skillId });
if (isFavorited method · typescript · L32-L36 (5 LOC)lib/db/repositories/favorite.repository.ts
async isFavorited(userId: string, skillId: string): Promise<boolean> {
const ds = await ensureInitialized();
const row = await ds.getRepository(Favorite).findOne({ where: { userId, skillId } });
return !!row;
}listForUser method · typescript · L38-L47 (10 LOC)lib/db/repositories/favorite.repository.ts
async listForUser(userId: string): Promise<Skill[]> {
const ds = await ensureInitialized();
return ds
.getRepository(Skill)
.createQueryBuilder("s")
.innerJoin(Favorite, "f", 'f."skillId" = s.id AND f."userId" = :userId', { userId })
.where('s."deletedAt" IS NULL')
.orderBy('f."createdAt"', "DESC")
.getMany();
}Powered by Repobility — scan your code at https://repobility.com
InstallLogRepository class · typescript · L4-L21 (18 LOC)lib/db/repositories/install-log.repository.ts
export class InstallLogRepository {
async log(userId: string | null, skillId: string, source: InstallSource): Promise<void> {
const ds = await ensureInitialized();
await ds.transaction(async (m) => {
await m.getRepository(InstallLog).insert({ userId, skillId, source });
await m.getRepository(Skill).increment({ id: skillId }, "installCount", 1);
});
}
async listForUser(userId: string, limit = 50): Promise<InstallLog[]> {
const ds = await ensureInitialized();
return ds.getRepository(InstallLog).find({
where: { userId },
order: { createdAt: "DESC" },
take: limit,
});
}
}log method · typescript · L5-L11 (7 LOC)lib/db/repositories/install-log.repository.ts
async log(userId: string | null, skillId: string, source: InstallSource): Promise<void> {
const ds = await ensureInitialized();
await ds.transaction(async (m) => {
await m.getRepository(InstallLog).insert({ userId, skillId, source });
await m.getRepository(Skill).increment({ id: skillId }, "installCount", 1);
});
}listForUser method · typescript · L13-L20 (8 LOC)lib/db/repositories/install-log.repository.ts
async listForUser(userId: string, limit = 50): Promise<InstallLog[]> {
const ds = await ensureInitialized();
return ds.getRepository(InstallLog).find({
where: { userId },
order: { createdAt: "DESC" },
take: limit,
});
}SkillRepository class · typescript · L34-L133 (100 LOC)lib/db/repositories/skill.repository.ts
export class SkillRepository {
async upsertFromRegistry(input: SkillUpsertInput): Promise<"added" | "updated"> {
const ds = await ensureInitialized();
const repo = ds.getRepository(Skill);
const existing = await repo.findOne({ where: { slug: input.slug } });
if (existing) {
Object.assign(existing, input, { deletedAt: null, lastSyncedAt: new Date() });
await repo.save(existing);
return "updated";
}
const created = repo.create({ ...input, lastSyncedAt: new Date() });
await repo.save(created);
return "added";
}
async softDeleteMissing(presentSlugs: string[]): Promise<number> {
const ds = await ensureInitialized();
const repo = ds.getRepository(Skill);
const qb = repo
.createQueryBuilder()
.update(Skill)
.set({ deletedAt: () => "now()" })
.where('"deletedAt" IS NULL');
if (presentSlugs.length > 0) {
qb.andWhere('"slug" NOT IN (:...slugs)', { slugs: presentSlugs });
}
const res = aupsertFromRegistry method · typescript · L35-L47 (13 LOC)lib/db/repositories/skill.repository.ts
async upsertFromRegistry(input: SkillUpsertInput): Promise<"added" | "updated"> {
const ds = await ensureInitialized();
const repo = ds.getRepository(Skill);
const existing = await repo.findOne({ where: { slug: input.slug } });
if (existing) {
Object.assign(existing, input, { deletedAt: null, lastSyncedAt: new Date() });
await repo.save(existing);
return "updated";
}
const created = repo.create({ ...input, lastSyncedAt: new Date() });
await repo.save(created);
return "added";
}softDeleteMissing method · typescript · L49-L62 (14 LOC)lib/db/repositories/skill.repository.ts
async softDeleteMissing(presentSlugs: string[]): Promise<number> {
const ds = await ensureInitialized();
const repo = ds.getRepository(Skill);
const qb = repo
.createQueryBuilder()
.update(Skill)
.set({ deletedAt: () => "now()" })
.where('"deletedAt" IS NULL');
if (presentSlugs.length > 0) {
qb.andWhere('"slug" NOT IN (:...slugs)', { slugs: presentSlugs });
}
const res = await qb.execute();
return res.affected ?? 0;
}findLatestSync method · typescript · L64-L69 (6 LOC)lib/db/repositories/skill.repository.ts
async findLatestSync(): Promise<Date | null> {
const ds = await ensureInitialized();
const repo = ds.getRepository(Skill);
const row = await repo.findOne({ where: {}, order: { lastSyncedAt: "DESC" } });
return row?.lastSyncedAt ?? null;
}search method · typescript · L71-L93 (23 LOC)lib/db/repositories/skill.repository.ts
async search(args: SearchArgs): Promise<SearchResult> {
const ds = await ensureInitialized();
const qb = ds.getRepository(Skill).createQueryBuilder("s").where('s."deletedAt" IS NULL');
if (args.q) {
qb.andWhere('s."searchVector" @@ plainto_tsquery(\'english\', :q)', { q: args.q })
.addSelect("ts_rank(s.\"searchVector\", plainto_tsquery('english', :q))", "rank")
.orderBy("rank", "DESC");
} else if (args.sort === "newest") {
qb.orderBy('s."publishedAt"', "DESC", "NULLS LAST");
} else if (args.sort === "name") {
qb.orderBy('s."name"', "ASC");
} else {
qb.orderBy('s."installCount"', "DESC");
}
if (args.category) qb.andWhere('s."category" = :category', { category: args.category });
if (args.tag) qb.andWhere(':tag = ANY(s."tags")', { tag: args.tag });
const total = await qb.getCount();
const items = await qb.skip((args.page - 1) * args.pageSize).take(args.pageSize).getMany();
return { items, total };Repobility — same analyzer, your code, free for public repos · /scan/
findBySlug method · typescript · L95-L98 (4 LOC)lib/db/repositories/skill.repository.ts
async findBySlug(slug: string): Promise<Skill | null> {
const ds = await ensureInitialized();
return ds.getRepository(Skill).findOne({ where: { slug, deletedAt: IsNull() } });
}listFeatured method · typescript · L100-L106 (7 LOC)lib/db/repositories/skill.repository.ts
async listFeatured(limit = 1): Promise<Skill[]> {
const ds = await ensureInitialized();
return ds.getRepository(Skill).find({
where: { featured: true, deletedAt: IsNull() },
take: limit,
});
}listNewest method · typescript · L108-L115 (8 LOC)lib/db/repositories/skill.repository.ts
async listNewest(limit = 12): Promise<Skill[]> {
const ds = await ensureInitialized();
return ds.getRepository(Skill).find({
where: { deletedAt: IsNull() },
order: { publishedAt: "DESC" },
take: limit,
});
}listTrending method · typescript · L117-L132 (16 LOC)lib/db/repositories/skill.repository.ts
async listTrending(limit = 4): Promise<Skill[]> {
const ds = await ensureInitialized();
const rows = await ds.query(
`SELECT s.* FROM skill s
JOIN (
SELECT "skillId", COUNT(*) AS hits FROM install_log
WHERE "createdAt" > now() - interval '7 days'
GROUP BY "skillId"
) i ON i."skillId" = s.id
WHERE s."deletedAt" IS NULL
ORDER BY i.hits DESC
LIMIT $1`,
[limit],
);
return rows as Skill[];
}renderMarkdown function · typescript · L7-L15 (9 LOC)lib/markdown.ts
export async function renderMarkdown(md: string): Promise<string> {
const file = await unified()
.use(remarkParse)
.use(remarkRehype, { allowDangerousHtml: false })
.use(rehypeSanitize)
.use(rehypeStringify)
.process(md);
return String(file);
}createGithubClient function · typescript · L14-L43 (30 LOC)lib/registry/github.ts
export function createGithubClient(repo: string, token?: string): GithubClient {
const [owner, name] = repo.split("/");
if (!owner || !name) throw new Error(`invalid GITHUB_REGISTRY_REPO: ${repo}`);
const octokit = new Octokit({ auth: token });
return {
async fetchRegistryIndex() {
const repoInfo = await octokit.rest.repos.get({ owner, repo: name });
const commit = await octokit.rest.repos.getCommit({ owner, repo: name, ref: repoInfo.data.default_branch });
const indexRaw = await octokit.rest.repos.getContent({
owner,
repo: name,
path: "registry.json",
mediaType: { format: "raw" },
});
const entries = JSON.parse(indexRaw.data as unknown as string) as RegistryEntry[];
return { entries, repoSha: commit.data.sha };
},
async fetchSkillFile(path, file) {
const res = await octokit.rest.repos.getContent({
owner,
repo: name,
path: `${path}/${file}`,
mediaType: { formaparseSkillYaml function · typescript · L26-L36 (11 LOC)lib/registry/parser.ts
export function parseSkillYaml(raw: string): ParseResult {
let obj: unknown;
try {
obj = parseYaml(raw);
} catch (e) {
return { ok: false, error: `yaml parse error: ${(e as Error).message}` };
}
const res = ParsedSkillSchema.safeParse(obj);
if (!res.success) return { ok: false, error: res.error.message };
return { ok: true, data: res.data };
}syncRegistry function · typescript · L23-L69 (47 LOC)lib/registry/sync.ts
export async function syncRegistry(deps: SyncDeps): Promise<SyncResult> {
const { github, repo, repoUrlFor, logger } = deps;
const result: SyncResult = { added: 0, updated: 0, removed: 0, errors: [] };
const { entries } = await github.fetchRegistryIndex();
const presentSlugs: string[] = [];
for (const entry of entries) {
try {
const [yamlRaw, readme] = await Promise.all([
github.fetchSkillFile(entry.path, "skill.yaml"),
github.fetchSkillFile(entry.path, "README.md"),
]);
const parsed = parseSkillYaml(yamlRaw);
if (!parsed.ok) {
result.errors.push({ slug: entry.slug, error: parsed.error });
logger.warn("skill parse failed", { slug: entry.slug, error: parsed.error });
continue;
}
const data = parsed.data;
const action = await repo.upsertFromRegistry({
slug: data.slug,
name: data.name,
tagline: data.tagline,
description: readme,
version: data.version,
Open data scored by Repobility · https://repobility.com
cn function · typescript · L4-L6 (3 LOC)lib/utils.ts
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}main function · typescript · L27-L60 (34 LOC)scripts/capture-screenshots.ts
async function main() {
await fs.mkdir(OUT, { recursive: true });
const browser = await chromium.launch();
const context = await browser.newContext({
viewport: { width: 1440, height: 900 },
deviceScaleFactor: 2, // Retina — README screenshots look crisp
});
const page = await context.newPage();
for (const shot of shots) {
if (shot.darkMode) {
// Set localStorage before navigating so the pre-hydration theme script
// picks it up on first paint.
await page.addInitScript(() => {
localStorage.setItem("theme", "dark");
});
} else {
await page.addInitScript(() => {
localStorage.setItem("theme", "light");
});
}
await page.goto(BASE + shot.path, { waitUntil: "networkidle" });
// Let fonts and any delayed network settle.
await page.waitForTimeout(500);
const dest = path.join(OUT, shot.file);
await page.screenshot({ path: dest, fullPage: shot.fullPage });
console.log(`✓ ${shot.file}`);main function · typescript · L130-L140 (11 LOC)scripts/seed.ts
async function main() {
const ds = await ensureInitialized();
const repo = ds.getRepository(Skill);
for (const s of skills) {
const existing = await repo.findOne({ where: { slug: s.slug! } });
if (existing) await repo.save({ ...existing, ...s });
else await repo.save(repo.create(s));
}
console.log(`seeded ${skills.length} skills`);
await ds.destroy();
}‹ prevpage 2 / 2