@manojkmfsi/monodog 1.0.23 → 1.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +6 -0
- package/dist/controllers/{commitController.js → commit-controller.js} +5 -4
- package/dist/controllers/{configController.js → config-controller.js} +3 -3
- package/dist/controllers/{healthController.js → health-controller.js} +3 -3
- package/dist/controllers/{packageController.js → package-controller.js} +6 -6
- package/dist/index.js +11 -236
- package/dist/middleware/dashboard-startup.js +122 -0
- package/dist/middleware/error-handler.js +43 -0
- package/dist/middleware/index.js +21 -0
- package/dist/middleware/security.js +78 -0
- package/dist/middleware/server-startup.js +111 -0
- package/dist/repositories/commit-repository.js +97 -0
- package/dist/repositories/dependency-repository.js +97 -0
- package/dist/repositories/index.js +18 -0
- package/dist/repositories/package-health-repository.js +65 -0
- package/dist/repositories/package-repository.js +126 -0
- package/dist/repositories/prisma-client.js +57 -0
- package/dist/routes/{commitRoutes.js → commit-routes.js} +2 -2
- package/dist/routes/{configRoutes.js → config-routes.js} +3 -3
- package/dist/routes/{healthRoutes.js → health-routes.js} +3 -3
- package/dist/routes/{packageRoutes.js → package-routes.js} +5 -5
- package/dist/services/{commitService.js → commit-service.js} +2 -2
- package/dist/services/{configService.js → config-service.js} +2 -40
- package/dist/services/{healthService.js → health-service.js} +11 -63
- package/dist/services/{packageService.js → package-service.js} +80 -54
- package/dist/types/git.js +11 -0
- package/dist/types/index.js +1 -0
- package/package.json +1 -1
- package/src/controllers/{commitController.ts → commit-controller.ts} +7 -5
- package/src/controllers/{configController.ts → config-controller.ts} +4 -3
- package/src/controllers/{healthController.ts → health-controller.ts} +4 -3
- package/src/controllers/{packageController.ts → package-controller.ts} +7 -6
- package/src/index.ts +9 -281
- package/src/middleware/dashboard-startup.ts +150 -0
- package/src/middleware/error-handler.ts +63 -0
- package/src/middleware/index.ts +18 -0
- package/src/middleware/security.ts +81 -0
- package/src/middleware/server-startup.ts +140 -0
- package/src/repositories/commit-repository.ts +107 -0
- package/src/repositories/dependency-repository.ts +109 -0
- package/src/repositories/index.ts +10 -0
- package/src/repositories/package-health-repository.ts +75 -0
- package/src/repositories/package-repository.ts +142 -0
- package/src/repositories/prisma-client.ts +25 -0
- package/src/routes/{commitRoutes.ts → commit-routes.ts} +1 -1
- package/src/routes/{configRoutes.ts → config-routes.ts} +1 -1
- package/src/routes/{healthRoutes.ts → health-routes.ts} +1 -1
- package/src/routes/{packageRoutes.ts → package-routes.ts} +1 -1
- package/src/services/{commitService.ts → commit-service.ts} +1 -1
- package/src/services/{configService.ts → config-service.ts} +22 -9
- package/src/services/{gitService.ts → git-service.ts} +4 -4
- package/src/services/{healthService.ts → health-service.ts} +17 -35
- package/src/services/package-service.ts +201 -0
- package/src/types/database.ts +57 -1
- package/src/types/git.ts +8 -8
- package/src/types/index.ts +1 -1
- package/dist/utils/db-utils.js +0 -227
- package/src/services/packageService.ts +0 -115
- package/src/types/monorepo-scanner.d.ts +0 -32
- package/src/utils/db-utils.ts +0 -220
- /package/dist/services/{gitService.js → git-service.js} +0 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server startup logic for the API backend
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import express from 'express';
|
|
6
|
+
import { json } from 'body-parser';
|
|
7
|
+
import type { Express } from 'express';
|
|
8
|
+
|
|
9
|
+
import { appConfig } from '../config-loader';
|
|
10
|
+
import {
|
|
11
|
+
errorHandler,
|
|
12
|
+
notFoundHandler,
|
|
13
|
+
requestLogger,
|
|
14
|
+
} from './error-handler';
|
|
15
|
+
import {
|
|
16
|
+
createHelmetMiddleware,
|
|
17
|
+
createApiCorsMiddleware,
|
|
18
|
+
createTimeoutMiddleware,
|
|
19
|
+
buildApiUrl,
|
|
20
|
+
buildDashboardUrl,
|
|
21
|
+
} from './security';
|
|
22
|
+
|
|
23
|
+
import packageRouter from '../routes/package-routes';
|
|
24
|
+
import commitRouter from '../routes/commit-routes';
|
|
25
|
+
import healthRouter from '../routes/health-routes';
|
|
26
|
+
import configRouter from '../routes/config-routes';
|
|
27
|
+
|
|
28
|
+
// Security constants
|
|
29
|
+
const PORT_MIN = 1024;
|
|
30
|
+
const PORT_MAX = 65535;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Validate port number
|
|
34
|
+
*/
|
|
35
|
+
function validatePort(port: string | number): number {
|
|
36
|
+
const portNum = typeof port === 'string' ? parseInt(port, 10) : port;
|
|
37
|
+
|
|
38
|
+
if (isNaN(portNum) || portNum < PORT_MIN || portNum > PORT_MAX) {
|
|
39
|
+
throw new Error(`Port must be between ${PORT_MIN} and ${PORT_MAX}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return portNum;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Create Express app with middleware configuration
|
|
47
|
+
*/
|
|
48
|
+
function createApp(rootPath: string): Express {
|
|
49
|
+
const app = express();
|
|
50
|
+
|
|
51
|
+
// Timeout middleware
|
|
52
|
+
app.use(createTimeoutMiddleware());
|
|
53
|
+
|
|
54
|
+
// Store root path for routes
|
|
55
|
+
app.locals.rootPath = rootPath;
|
|
56
|
+
|
|
57
|
+
// Security and CORS setup
|
|
58
|
+
const dashboardUrl = buildDashboardUrl(appConfig);
|
|
59
|
+
const apiUrl = buildApiUrl(appConfig.server.host, appConfig.server.port);
|
|
60
|
+
|
|
61
|
+
app.use(createHelmetMiddleware(apiUrl));
|
|
62
|
+
app.use(createApiCorsMiddleware(dashboardUrl));
|
|
63
|
+
|
|
64
|
+
// Body parser
|
|
65
|
+
app.use(json({ limit: '1mb' }));
|
|
66
|
+
|
|
67
|
+
// Request logging
|
|
68
|
+
app.use(requestLogger);
|
|
69
|
+
|
|
70
|
+
// Routes
|
|
71
|
+
app.use('/api/packages', packageRouter);
|
|
72
|
+
app.use('/api/commits/', commitRouter);
|
|
73
|
+
app.use('/api/health/', healthRouter);
|
|
74
|
+
app.use('/api/config/', configRouter);
|
|
75
|
+
|
|
76
|
+
// 404 handler
|
|
77
|
+
app.use('*', notFoundHandler);
|
|
78
|
+
|
|
79
|
+
// Global error handler (must be last)
|
|
80
|
+
app.use(errorHandler);
|
|
81
|
+
|
|
82
|
+
return app;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Start the API server
|
|
87
|
+
*/
|
|
88
|
+
export function startServer(rootPath: string): void {
|
|
89
|
+
try {
|
|
90
|
+
const port = appConfig.server.port;
|
|
91
|
+
const host = appConfig.server.host;
|
|
92
|
+
const validatedPort = validatePort(port);
|
|
93
|
+
|
|
94
|
+
const app = createApp(rootPath);
|
|
95
|
+
|
|
96
|
+
const server = app.listen(validatedPort, host, () => {
|
|
97
|
+
console.log(`Backend server running on http://${host}:${validatedPort}`);
|
|
98
|
+
console.log('API endpoints available:');
|
|
99
|
+
console.log(' - GET /api/health');
|
|
100
|
+
console.log(' - GET /api/packages/refresh');
|
|
101
|
+
console.log(' - GET /api/packages');
|
|
102
|
+
console.log(' - GET /api/packages/:name');
|
|
103
|
+
console.log(' - PUT /api/packages/update-config');
|
|
104
|
+
console.log(' - GET /api/commits/:packagePath');
|
|
105
|
+
console.log(' - GET /api/health/packages');
|
|
106
|
+
console.log(' - PUT /api/config/files/:id');
|
|
107
|
+
console.log(' - GET /api/config/files');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
server.on('error', (err: NodeJS.ErrnoException) => {
|
|
111
|
+
if (err.code === 'EADDRINUSE') {
|
|
112
|
+
console.error(
|
|
113
|
+
`Error: Port ${validatedPort} is already in use. Please specify a different port.`
|
|
114
|
+
);
|
|
115
|
+
process.exit(1);
|
|
116
|
+
} else if (err.code === 'EACCES') {
|
|
117
|
+
console.error(
|
|
118
|
+
`Error: Permission denied to listen on port ${validatedPort}. Use a port above 1024.`
|
|
119
|
+
);
|
|
120
|
+
process.exit(1);
|
|
121
|
+
} else {
|
|
122
|
+
console.error('Server failed to start:', err.message);
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// Graceful shutdown
|
|
128
|
+
process.on('SIGTERM', () => {
|
|
129
|
+
console.log('SIGTERM signal received: closing HTTP server');
|
|
130
|
+
server.close(() => {
|
|
131
|
+
console.log('HTTP server closed');
|
|
132
|
+
process.exit(0);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
} catch (error: unknown) {
|
|
136
|
+
const err = error as Error & { message?: string };
|
|
137
|
+
console.error('Failed to start server:', err?.message || String(error));
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { getPrismaClient, getPrismaErrors } from './prisma-client';
|
|
2
|
+
import type { Commit } from '../types';
|
|
3
|
+
|
|
4
|
+
const prisma = getPrismaClient();
|
|
5
|
+
const Prisma = getPrismaErrors();
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Commit Repository - Handles all Commit-related database operations
|
|
9
|
+
*/
|
|
10
|
+
export class CommitRepository {
|
|
11
|
+
/**
|
|
12
|
+
* Find all commits for a package
|
|
13
|
+
*/
|
|
14
|
+
static async findByPackageName(packageName: string) {
|
|
15
|
+
return await prisma.commit.findMany({
|
|
16
|
+
where: { packageName },
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Find a specific commit
|
|
22
|
+
*/
|
|
23
|
+
static async findByHash(hash: string, packageName: string) {
|
|
24
|
+
return await prisma.commit.findUnique({
|
|
25
|
+
where: {
|
|
26
|
+
hash_packageName: {
|
|
27
|
+
hash,
|
|
28
|
+
packageName,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Create or update a commit
|
|
36
|
+
*/
|
|
37
|
+
static async upsert(data: {
|
|
38
|
+
hash: string;
|
|
39
|
+
message?: string;
|
|
40
|
+
author?: string;
|
|
41
|
+
date?: string | Date;
|
|
42
|
+
type?: string;
|
|
43
|
+
packageName: string;
|
|
44
|
+
}) {
|
|
45
|
+
try {
|
|
46
|
+
return await prisma.commit.upsert({
|
|
47
|
+
where: {
|
|
48
|
+
hash_packageName: {
|
|
49
|
+
hash: data.hash,
|
|
50
|
+
packageName: data.packageName,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
update: {
|
|
54
|
+
message: data.message || '',
|
|
55
|
+
author: data.author || '',
|
|
56
|
+
date: data.date,
|
|
57
|
+
type: data.type || '',
|
|
58
|
+
},
|
|
59
|
+
create: {
|
|
60
|
+
hash: data.hash,
|
|
61
|
+
message: data.message || '',
|
|
62
|
+
author: data.author || '',
|
|
63
|
+
date: data.date,
|
|
64
|
+
type: data.type || '',
|
|
65
|
+
packageName: data.packageName,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
} catch (e) {
|
|
69
|
+
const err = e as Error & { code?: string };
|
|
70
|
+
if (
|
|
71
|
+
err instanceof Prisma.PrismaClientKnownRequestError &&
|
|
72
|
+
err.code === 'P2002'
|
|
73
|
+
) {
|
|
74
|
+
console.warn(`Skipping commit: ${data.hash} (Commit already exists)`);
|
|
75
|
+
} else {
|
|
76
|
+
console.error(`Failed to store commit: ${data.hash}`, err);
|
|
77
|
+
throw err;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Store multiple commits
|
|
84
|
+
*/
|
|
85
|
+
static async storeMany(packageName: string, commits: Commit[]) {
|
|
86
|
+
console.log('Storing commits for: ' + packageName);
|
|
87
|
+
for (const commit of commits) {
|
|
88
|
+
await this.upsert({
|
|
89
|
+
hash: commit.hash,
|
|
90
|
+
message: commit.message,
|
|
91
|
+
author: commit.author,
|
|
92
|
+
date: commit.date,
|
|
93
|
+
type: commit.type,
|
|
94
|
+
packageName,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Delete all commits for a package
|
|
101
|
+
*/
|
|
102
|
+
static async deleteByPackageName(packageName: string) {
|
|
103
|
+
return await prisma.commit.deleteMany({
|
|
104
|
+
where: { packageName },
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { getPrismaClient, getPrismaErrors } from './prisma-client';
|
|
2
|
+
import type { DependencyInfo } from '../types';
|
|
3
|
+
|
|
4
|
+
const prisma = getPrismaClient();
|
|
5
|
+
const Prisma = getPrismaErrors();
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Dependency Repository - Handles all DependencyInfo-related database operations
|
|
9
|
+
*/
|
|
10
|
+
export class DependencyRepository {
|
|
11
|
+
/**
|
|
12
|
+
* Find all dependencies for a package
|
|
13
|
+
*/
|
|
14
|
+
static async findByPackageName(packageName: string) {
|
|
15
|
+
return await prisma.dependencyInfo.findMany({
|
|
16
|
+
where: { packageName },
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Find a specific dependency
|
|
22
|
+
*/
|
|
23
|
+
static async findByNameAndPackage(name: string, packageName: string) {
|
|
24
|
+
return await prisma.dependencyInfo.findUnique({
|
|
25
|
+
where: {
|
|
26
|
+
name_packageName: {
|
|
27
|
+
name,
|
|
28
|
+
packageName,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Create or update a dependency
|
|
36
|
+
*/
|
|
37
|
+
static async upsert(data: {
|
|
38
|
+
name: string;
|
|
39
|
+
version: string;
|
|
40
|
+
type: string;
|
|
41
|
+
latest?: string;
|
|
42
|
+
outdated?: boolean;
|
|
43
|
+
packageName: string;
|
|
44
|
+
}) {
|
|
45
|
+
try {
|
|
46
|
+
return await prisma.dependencyInfo.upsert({
|
|
47
|
+
where: {
|
|
48
|
+
name_packageName: {
|
|
49
|
+
name: data.name,
|
|
50
|
+
packageName: data.packageName,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
update: {
|
|
54
|
+
version: data.version,
|
|
55
|
+
type: data.type,
|
|
56
|
+
latest: data.latest || '',
|
|
57
|
+
outdated: data.outdated ?? false,
|
|
58
|
+
},
|
|
59
|
+
create: {
|
|
60
|
+
name: data.name,
|
|
61
|
+
version: data.version,
|
|
62
|
+
type: data.type,
|
|
63
|
+
latest: data.latest || '',
|
|
64
|
+
outdated: data.outdated ?? false,
|
|
65
|
+
packageName: data.packageName,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
} catch (e) {
|
|
69
|
+
const err = e as Error & { code?: string };
|
|
70
|
+
if (
|
|
71
|
+
err instanceof Prisma.PrismaClientKnownRequestError &&
|
|
72
|
+
err.code === 'P2002'
|
|
73
|
+
) {
|
|
74
|
+
console.warn(
|
|
75
|
+
`Skipping dependency: ${data.name} (Dependency already exists)`
|
|
76
|
+
);
|
|
77
|
+
} else {
|
|
78
|
+
console.error(`Failed to store dependency: ${data.name}`, err);
|
|
79
|
+
throw err;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Store multiple dependencies
|
|
86
|
+
*/
|
|
87
|
+
static async storeMany(packageName: string, dependencies: DependencyInfo[]) {
|
|
88
|
+
console.log('Storing Dependencies for: ' + packageName);
|
|
89
|
+
for (const dep of dependencies) {
|
|
90
|
+
await this.upsert({
|
|
91
|
+
name: dep.name,
|
|
92
|
+
version: dep.version,
|
|
93
|
+
type: dep.type,
|
|
94
|
+
latest: dep.latest,
|
|
95
|
+
outdated: dep.outdated,
|
|
96
|
+
packageName,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Delete all dependencies for a package
|
|
103
|
+
*/
|
|
104
|
+
static async deleteByPackageName(packageName: string) {
|
|
105
|
+
return await prisma.dependencyInfo.deleteMany({
|
|
106
|
+
where: { packageName },
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Repository Pattern Index
|
|
3
|
+
* Exports all repositories for data access layer
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export { PackageRepository } from './package-repository';
|
|
7
|
+
export { PackageHealthRepository } from './package-health-repository';
|
|
8
|
+
export { CommitRepository } from './commit-repository';
|
|
9
|
+
export { DependencyRepository } from './dependency-repository';
|
|
10
|
+
export { getPrismaClient, getPrismaErrors } from './prisma-client';
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { getPrismaClient } from './prisma-client';
|
|
2
|
+
|
|
3
|
+
const prisma = getPrismaClient();
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Package Health Repository - Handles all PackageHealth-related database operations
|
|
7
|
+
*/
|
|
8
|
+
export class PackageHealthRepository {
|
|
9
|
+
/**
|
|
10
|
+
* Find all package health records
|
|
11
|
+
*/
|
|
12
|
+
static async findAll() {
|
|
13
|
+
return await prisma.packageHealth.findMany();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Find package health by package name
|
|
18
|
+
*/
|
|
19
|
+
static async findByPackageName(packageName: string) {
|
|
20
|
+
return await prisma.packageHealth.findUnique({
|
|
21
|
+
where: { packageName },
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Create or update package health record
|
|
27
|
+
*/
|
|
28
|
+
static async upsert(data: {
|
|
29
|
+
packageName: string;
|
|
30
|
+
packageOverallScore: number;
|
|
31
|
+
packageBuildStatus: string;
|
|
32
|
+
packageTestCoverage: number;
|
|
33
|
+
packageLintStatus: string;
|
|
34
|
+
packageSecurity: string;
|
|
35
|
+
packageDependencies?: string;
|
|
36
|
+
}) {
|
|
37
|
+
return await prisma.packageHealth.upsert({
|
|
38
|
+
where: { packageName: data.packageName },
|
|
39
|
+
update: {
|
|
40
|
+
packageOverallScore: data.packageOverallScore,
|
|
41
|
+
packageBuildStatus: data.packageBuildStatus,
|
|
42
|
+
packageTestCoverage: data.packageTestCoverage,
|
|
43
|
+
packageLintStatus: data.packageLintStatus,
|
|
44
|
+
packageSecurity: data.packageSecurity,
|
|
45
|
+
packageDependencies: data.packageDependencies || '',
|
|
46
|
+
updatedAt: new Date(),
|
|
47
|
+
},
|
|
48
|
+
create: {
|
|
49
|
+
packageName: data.packageName,
|
|
50
|
+
packageOverallScore: data.packageOverallScore,
|
|
51
|
+
packageBuildStatus: data.packageBuildStatus,
|
|
52
|
+
packageTestCoverage: data.packageTestCoverage,
|
|
53
|
+
packageLintStatus: data.packageLintStatus,
|
|
54
|
+
packageSecurity: data.packageSecurity,
|
|
55
|
+
packageDependencies: data.packageDependencies || '',
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Delete package health record
|
|
62
|
+
*/
|
|
63
|
+
static async deleteByPackageName(packageName: string) {
|
|
64
|
+
return await prisma.packageHealth.delete({
|
|
65
|
+
where: { packageName },
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Delete all package health records
|
|
71
|
+
*/
|
|
72
|
+
static async deleteAll() {
|
|
73
|
+
return await prisma.packageHealth.deleteMany();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { getPrismaClient } from './prisma-client';
|
|
2
|
+
import type { PackageInfo } from '../types';
|
|
3
|
+
|
|
4
|
+
const prisma = getPrismaClient();
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Package Repository - Handles all Package-related database operations
|
|
8
|
+
*/
|
|
9
|
+
export class PackageRepository {
|
|
10
|
+
/**
|
|
11
|
+
* Find all packages
|
|
12
|
+
*/
|
|
13
|
+
static async findAll() {
|
|
14
|
+
return await prisma.package.findMany();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Find a package by name
|
|
19
|
+
*/
|
|
20
|
+
static async findByName(name: string) {
|
|
21
|
+
return await prisma.package.findUnique({
|
|
22
|
+
where: { name },
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Find a package with related data
|
|
28
|
+
*/
|
|
29
|
+
static async findByNameWithRelations(name: string) {
|
|
30
|
+
return await prisma.package.findUnique({
|
|
31
|
+
where: { name },
|
|
32
|
+
include: {
|
|
33
|
+
dependenciesInfo: true,
|
|
34
|
+
commits: true,
|
|
35
|
+
packageHealth: true,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Create or update a package
|
|
42
|
+
*/
|
|
43
|
+
static async upsert(data: {
|
|
44
|
+
name: string;
|
|
45
|
+
version?: string;
|
|
46
|
+
type?: string;
|
|
47
|
+
path?: string;
|
|
48
|
+
description?: string;
|
|
49
|
+
license?: string;
|
|
50
|
+
repository?: Record<string, unknown>;
|
|
51
|
+
scripts?: Record<string, unknown>;
|
|
52
|
+
dependencies?: Record<string, unknown>;
|
|
53
|
+
devDependencies?: Record<string, unknown>;
|
|
54
|
+
peerDependencies?: Record<string, unknown>;
|
|
55
|
+
maintainers?: string;
|
|
56
|
+
status?: string;
|
|
57
|
+
}) {
|
|
58
|
+
const createData = {
|
|
59
|
+
createdAt: new Date(),
|
|
60
|
+
lastUpdated: new Date(),
|
|
61
|
+
dependencies: JSON.stringify(data.dependencies || {}),
|
|
62
|
+
maintainers: typeof data.maintainers === 'string' ? data.maintainers : '',
|
|
63
|
+
scripts: JSON.stringify(data.scripts || {}),
|
|
64
|
+
devDependencies: JSON.stringify(data.devDependencies || {}),
|
|
65
|
+
peerDependencies: JSON.stringify(data.peerDependencies || {}),
|
|
66
|
+
name: data.name,
|
|
67
|
+
version: data.version || '',
|
|
68
|
+
type: data.type || '',
|
|
69
|
+
path: data.path || '',
|
|
70
|
+
description: data.description || '',
|
|
71
|
+
license: data.license || '',
|
|
72
|
+
repository: JSON.stringify(data.repository || {}),
|
|
73
|
+
status: data.status || '',
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const updateData = {
|
|
77
|
+
version: data.version,
|
|
78
|
+
type: data.type,
|
|
79
|
+
path: data.path,
|
|
80
|
+
description: data.description,
|
|
81
|
+
license: data.license,
|
|
82
|
+
repository: JSON.stringify(data.repository || {}),
|
|
83
|
+
scripts: JSON.stringify(data.scripts || {}),
|
|
84
|
+
lastUpdated: new Date(),
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
return await prisma.package.upsert({
|
|
88
|
+
where: { name: data.name },
|
|
89
|
+
create: createData,
|
|
90
|
+
update: updateData,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Update package status
|
|
96
|
+
*/
|
|
97
|
+
static async updateStatus(name: string, status: string) {
|
|
98
|
+
return await prisma.package.update({
|
|
99
|
+
where: { name },
|
|
100
|
+
data: { status },
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Update package configuration
|
|
106
|
+
*/
|
|
107
|
+
static async updateConfig(name: string, updateData: Record<string, unknown>) {
|
|
108
|
+
const data: Record<string, unknown> = {
|
|
109
|
+
lastUpdated: new Date(),
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
if (updateData.version) data.version = updateData.version;
|
|
113
|
+
if (updateData.description !== undefined) data.description = updateData.description || '';
|
|
114
|
+
if (updateData.license !== undefined) data.license = updateData.license || '';
|
|
115
|
+
if (updateData.scripts) data.scripts = JSON.stringify(updateData.scripts);
|
|
116
|
+
if (updateData.repository) data.repository = JSON.stringify(updateData.repository);
|
|
117
|
+
if (updateData.dependencies) data.dependencies = JSON.stringify(updateData.dependencies);
|
|
118
|
+
if (updateData.devDependencies) data.devDependencies = JSON.stringify(updateData.devDependencies);
|
|
119
|
+
if (updateData.peerDependencies) data.peerDependencies = JSON.stringify(updateData.peerDependencies);
|
|
120
|
+
|
|
121
|
+
return await prisma.package.update({
|
|
122
|
+
where: { name },
|
|
123
|
+
data,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Delete all packages
|
|
129
|
+
*/
|
|
130
|
+
static async deleteAll() {
|
|
131
|
+
return await prisma.package.deleteMany();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Delete a package by name
|
|
136
|
+
*/
|
|
137
|
+
static async deleteByName(name: string) {
|
|
138
|
+
return await prisma.package.delete({
|
|
139
|
+
where: { name },
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as PrismaPkg from '@prisma/client';
|
|
2
|
+
|
|
3
|
+
const PrismaClient = (PrismaPkg as any).PrismaClient || (PrismaPkg as any).default || PrismaPkg;
|
|
4
|
+
const Prisma = (PrismaPkg as any).Prisma || (PrismaPkg as any).PrismaClient?.Prisma || (PrismaPkg as any).default?.Prisma || PrismaPkg;
|
|
5
|
+
|
|
6
|
+
let prismaInstance: ReturnType<typeof PrismaClient> | null = null;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Get singleton instance of Prisma Client
|
|
10
|
+
*/
|
|
11
|
+
export function getPrismaClient() {
|
|
12
|
+
if (!prismaInstance) {
|
|
13
|
+
prismaInstance = new PrismaClient();
|
|
14
|
+
}
|
|
15
|
+
return prismaInstance;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Get Prisma error classes for error handling
|
|
20
|
+
*/
|
|
21
|
+
export function getPrismaErrors() {
|
|
22
|
+
return Prisma;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default getPrismaClient;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
|
-
import { getPackages, refreshPackages, getPackageDetail, updatePackageConfig } from '../controllers/
|
|
2
|
+
import { getPackages, refreshPackages, getPackageDetail, updatePackageConfig } from '../controllers/package-controller';
|
|
3
3
|
|
|
4
4
|
const packageRouter = express.Router();
|
|
5
5
|
|