Skip to content

Commit b9e28fe

Browse files
CopilotMini256
andcommitted
feat: Complete OSSInsight refactoring — Prisma 7, Next.js 15, Node.js ETL, Vitest, Tailwind, shadcn
Co-authored-by: Mini256 <5086433+Mini256@users.noreply.github.com>
1 parent 064dddc commit b9e28fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2221
-6
lines changed

.gitignore

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,17 @@ yarn-error.log*
3232
# Prefetch
3333
.prefetch
3434

35-
/configs/prompts/*/*.*
35+
/configs/prompts/*/*.*
36+
37+
# Next.js
38+
packages/web/.next/
39+
packages/web/out/
40+
41+
# Build outputs (all packages)
42+
packages/*/dist/
43+
44+
# Prisma generated clients (re-generated on build)
45+
packages/*/node_modules/.prisma/
46+
47+
# Coverage reports
48+
packages/*/coverage/

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
"license": "Apache-2.0",
66
"workspaces": [
77
"packages/api-server",
8+
"packages/db",
9+
"packages/etl",
810
"packages/job-server",
911
"packages/prefetch",
1012
"packages/types",
1113
"packages/cli",
1214
"packages/pipeline",
13-
"packages/sync-github-data"
15+
"packages/sync-github-data",
16+
"packages/web"
1417
],
1518
"scripts": {
1619
"prepare": "husky install"

packages/api-server/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
"gen:dev-public-api-docs": "fastify start -a 0.0.0.0 -p ${API_SERVER_PORT:-3450} -L dist/logger.js -l info dist/cmd/gen-docs.js",
1717
"gen:public-api-docs": "rm -f ../../configs/public_api/openapi.yaml && API_BASE_URL=https://api.ossinsight.io fastify start -a 0.0.0.0 -p ${API_SERVER_PORT:-3450} -L dist/logger.js -l info dist/cmd/gen-docs.js",
1818
"test": "jest",
19+
"test:vitest": "vitest run",
20+
"test:vitest:watch": "vitest",
1921
"coverage": "jest --coverage",
2022
"watch:ts": "tsc -w"
2123
},
@@ -56,6 +58,7 @@
5658
"node-sql-parser": "4.6.5",
5759
"octokit": "^2.0.10",
5860
"openai": "^4.56.0",
61+
"@prisma/client": "^7.4.1",
5962
"pino": "^8.7.0",
6063
"pino-pretty": "^9.1.1",
6164
"pino-sentry-transport": "^1.0.4",
@@ -74,6 +77,7 @@
7477
"@types/luxon": "^3.0.2",
7578
"@types/mustache": "^4.2.2",
7679
"@types/node": "^18.0.0",
80+
"@vitest/coverage-v8": "^3.0.0",
7781
"ajv-cli": "^5.0.0",
7882
"ajv-formats": "^2.1.1",
7983
"chance": "^1.1.9",
@@ -82,11 +86,13 @@
8286
"jest": "^29.3.1",
8387
"json-schema-to-ts": "^2.6.0",
8488
"json-schema-to-typescript": "^11.0.2",
89+
"prisma": "^7.4.1",
8590
"randexp": "^0.5.3",
8691
"socket.io-client": "^4.5.3",
8792
"testcontainers": "^9.0.0",
8893
"ts-jest": "^29.0.3",
8994
"ts-node": "^10.4.0",
90-
"typescript": "^4.5.4"
95+
"typescript": "^4.5.4",
96+
"vitest": "^3.0.0"
9197
}
9298
}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// Prisma schema for @ossinsight/api-server
2+
// This file mirrors packages/db/prisma/schema.prisma to allow `prisma generate`
3+
// to run independently within this package. The generated client is used by
4+
// the @ossinsight/prisma Fastify plugin (src/plugins/prisma.ts).
5+
6+
generator client {
7+
provider = "prisma-client-js"
8+
}
9+
10+
datasource db {
11+
provider = "mysql"
12+
url = env("DATABASE_URL")
13+
}
14+
15+
model GithubEvent {
16+
id Int @id @default(autoincrement())
17+
type String?
18+
createdAt DateTime? @map("created_at")
19+
repoId BigInt? @map("repo_id")
20+
repoName String? @map("repo_name")
21+
actorId BigInt? @map("actor_id")
22+
actorLogin String? @map("actor_login")
23+
actorLocation String? @map("actor_location")
24+
language String?
25+
additions BigInt?
26+
deletions BigInt?
27+
action String?
28+
number Int?
29+
commitId String? @map("commit_id")
30+
commentId BigInt? @map("comment_id")
31+
orgLogin String? @map("org_login")
32+
orgId BigInt? @map("org_id")
33+
state String?
34+
closedAt DateTime? @map("closed_at")
35+
comments Int?
36+
prMergedAt DateTime? @map("pr_merged_at")
37+
prMerged Boolean? @map("pr_merged")
38+
prChangedFiles Int? @map("pr_changed_files")
39+
prReviewComments Int? @map("pr_review_comments")
40+
prOrIssueId BigInt? @map("pr_or_issue_id")
41+
eventDay DateTime? @map("event_day") @db.Date
42+
eventMonth DateTime? @map("event_month") @db.Date
43+
authorAssociation String? @map("author_association")
44+
eventYear Int? @map("event_year")
45+
pushSize Int? @map("push_size")
46+
pushDistinctSize Int? @map("push_distinct_size")
47+
48+
@@map("github_events")
49+
}
50+
51+
model GitHubRepo {
52+
repoId Int @id @map("repo_id")
53+
repoName String @map("repo_name")
54+
ownerId Int @map("owner_id")
55+
ownerLogin String @map("owner_login")
56+
ownerIsOrg Boolean @map("owner_is_org")
57+
description String?
58+
primaryLanguage String? @map("primary_language")
59+
languages GitHubRepoLanguage[]
60+
topics GitHubRepoTopic[]
61+
license String?
62+
size Int?
63+
stars Int?
64+
forks Int?
65+
parentRepoId Int? @map("parent_repo_id")
66+
isFork Boolean? @map("is_fork")
67+
isArchived Boolean? @map("is_archived")
68+
isDeleted Boolean? @map("is_deleted")
69+
latestReleasedAt DateTime? @db.Timestamp() @map("latest_released_at")
70+
pushedAt DateTime? @db.Timestamp() @map("pushed_at")
71+
createdAt DateTime @db.Timestamp() @map("created_at")
72+
updatedAt DateTime @db.Timestamp() @map("updated_at")
73+
lastEventAt DateTime? @db.Timestamp() @map("last_event_at")
74+
refreshedAt DateTime? @db.Timestamp() @map("refreshed_at")
75+
76+
@@map("github_repos")
77+
}
78+
79+
model GitHubRepoTopic {
80+
repoId Int @map("repo_id")
81+
topic String
82+
repo GitHubRepo @relation(fields: [repoId], references: [repoId])
83+
84+
@@id([repoId, topic])
85+
@@map("github_repo_topics")
86+
}
87+
88+
model GitHubRepoLanguage {
89+
repoId Int @map("repo_id")
90+
language String
91+
size Int?
92+
repo GitHubRepo @relation(fields: [repoId], references: [repoId])
93+
94+
@@id([repoId, language])
95+
@@map("github_repo_languages")
96+
}
97+
98+
model GitHubUser {
99+
id Int @id
100+
login String
101+
type String?
102+
isBot Boolean? @map("is_bot")
103+
name String?
104+
email String?
105+
organization String?
106+
organizationFormatted String? @map("organization_formatted")
107+
address String?
108+
countryCode String? @map("country_code")
109+
regionCode String? @map("region_code")
110+
state String?
111+
city String?
112+
longitude Decimal?
113+
latitude Decimal?
114+
publicRepos Int? @map("public_repos")
115+
followers Int?
116+
followings Int?
117+
createdAt DateTime @map("created_at")
118+
updatedAt DateTime @map("updated_at")
119+
isDeleted Boolean? @map("is_deleted")
120+
refreshedAt DateTime? @map("refreshed_at")
121+
122+
@@map("github_users")
123+
}
124+
125+
model Collection {
126+
id Int @id @default(autoincrement())
127+
name String
128+
createdAt DateTime? @map("created_at")
129+
updatedAt DateTime? @map("updated_at")
130+
deletedAt DateTime? @map("deleted_at")
131+
items CollectionItem[]
132+
133+
@@map("collections")
134+
}
135+
136+
model CollectionItem {
137+
id Int @id @default(autoincrement())
138+
collectionId Int @map("collection_id")
139+
repoId Int @map("repo_id")
140+
repoName String? @map("repo_name")
141+
createdAt DateTime? @map("created_at")
142+
updatedAt DateTime? @map("updated_at")
143+
deletedAt DateTime? @map("deleted_at")
144+
collection Collection @relation(fields: [collectionId], references: [id])
145+
146+
@@map("collection_items")
147+
}
148+
149+
model LocationCacheItem {
150+
address String @id
151+
valid Boolean
152+
formattedAddress String @map("formatted_address")
153+
countryCode String @default("UND") @map("country_code")
154+
regionCode String @default("UND") @map("region_code")
155+
state String?
156+
city String?
157+
longitude Decimal?
158+
latitude Decimal?
159+
provider String @default("UNKNOWN")
160+
createdAt DateTime @default(now()) @map("created_at")
161+
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
162+
163+
@@map("location_cache")
164+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import fp from "fastify-plugin";
2+
import { PrismaClient } from "@prisma/client";
3+
4+
/**
5+
* @ossinsight/prisma plugin
6+
*
7+
* Initialises a shared Prisma 7 client and attaches it to the Fastify instance.
8+
* Packages that need type-safe queries should use `app.prisma` instead of the
9+
* raw `app.mysql` pool where possible.
10+
*
11+
* Usage:
12+
* const repos = await app.prisma.gitHubRepo.findMany({ take: 10 });
13+
*/
14+
export default fp(
15+
async (app) => {
16+
const prisma = new PrismaClient({
17+
datasourceUrl: app.config.DATABASE_URL,
18+
log:
19+
process.env.NODE_ENV === "development"
20+
? ["query", "error", "warn"]
21+
: ["error"],
22+
});
23+
24+
await prisma.$connect();
25+
26+
app.decorate("prisma", prisma);
27+
28+
app.addHook("onClose", async () => {
29+
await prisma.$disconnect();
30+
});
31+
},
32+
{
33+
name: "@ossinsight/prisma",
34+
dependencies: ["@fastify/env"],
35+
}
36+
);
37+
38+
declare module "fastify" {
39+
interface FastifyInstance {
40+
prisma: PrismaClient;
41+
}
42+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
globals: true,
6+
environment: "node",
7+
include: ["src/**/*.vitest.{ts,tsx}", "src/**/*.vtest.{ts,tsx}"],
8+
coverage: {
9+
provider: "v8",
10+
reporter: ["text", "json", "html"],
11+
},
12+
},
13+
});

packages/cli/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"build:ts": "tsc",
1010
"watch:ts": "tsc -w",
1111
"start": "node dist/index.js",
12+
"prisma:generate": "prisma generate",
1213
"kysely:generate": "kysely-codegen --include-pattern \"*.(collection*|github*|cache*)\" --type-only-imports --out-file ./src/db/schema.d.ts",
1314
"dev:start": "ts-node -r tsconfig-paths/register src/index.ts",
1415
"cli:collection:reload": "ts-node src/index.ts collection reload",
@@ -25,12 +26,14 @@
2526
"@types/node": "^22.7.5",
2627
"kysely-codegen": "^0.16.8",
2728
"pino-pretty": "^9.4.0",
29+
"prisma": "^7.4.1",
2830
"ts-node": "^10.9.1",
2931
"tsconfig-paths": "^4.2.0",
3032
"typescript": "^5.6.2"
3133
},
3234
"dependencies": {
3335
"@goparrot/geocoder": "^4.5.0",
36+
"@prisma/client": "^7.4.1",
3437
"@sentry/node": "^8.33.1",
3538
"async": "^3.2.6",
3639
"commander": "^12.1.0",

0 commit comments

Comments
 (0)