@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
package/dist/utils/db-utils.js
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.storePackage = storePackage;
|
|
37
|
-
const PrismaPkg = __importStar(require("@prisma/client"));
|
|
38
|
-
const PrismaClient = PrismaPkg.PrismaClient || PrismaPkg.default || PrismaPkg;
|
|
39
|
-
const Prisma = PrismaPkg.Prisma || PrismaPkg.PrismaClient?.Prisma || PrismaPkg.default?.Prisma || PrismaPkg;
|
|
40
|
-
const config_loader_1 = require("../config-loader");
|
|
41
|
-
// Default settings
|
|
42
|
-
const DEFAULT_PORT = 4000;
|
|
43
|
-
const port = config_loader_1.appConfig.server.port ?? DEFAULT_PORT; //Default port
|
|
44
|
-
const host = config_loader_1.appConfig.server.host ?? 'localhost'; //Default host
|
|
45
|
-
const prisma = new PrismaClient();
|
|
46
|
-
const API_BASE = `http://${host}:${port}/api`;
|
|
47
|
-
async function getCommits(path) {
|
|
48
|
-
const res = await fetch(API_BASE + `/commits/` + encodeURIComponent(path));
|
|
49
|
-
if (!res.ok)
|
|
50
|
-
throw new Error('Failed to fetch commits');
|
|
51
|
-
return (await res.json());
|
|
52
|
-
}
|
|
53
|
-
async function storeCommits(packageName, commits) {
|
|
54
|
-
console.log('Storing commits for:' + packageName);
|
|
55
|
-
// Create or update dependencies
|
|
56
|
-
for (const commit of commits) {
|
|
57
|
-
try {
|
|
58
|
-
await prisma.commit.upsert({
|
|
59
|
-
where: {
|
|
60
|
-
hash_packageName: {
|
|
61
|
-
hash: commit.hash,
|
|
62
|
-
packageName: packageName,
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
update: {
|
|
66
|
-
message: commit.message,
|
|
67
|
-
author: commit.author,
|
|
68
|
-
date: commit.date,
|
|
69
|
-
type: commit.type,
|
|
70
|
-
},
|
|
71
|
-
create: {
|
|
72
|
-
hash: commit.hash,
|
|
73
|
-
message: commit.message,
|
|
74
|
-
author: commit.author,
|
|
75
|
-
date: commit.date,
|
|
76
|
-
type: commit.type,
|
|
77
|
-
packageName: packageName,
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
catch (e) {
|
|
82
|
-
const err = e;
|
|
83
|
-
if (err instanceof Prisma.PrismaClientKnownRequestError &&
|
|
84
|
-
err.code === 'P2002') {
|
|
85
|
-
// Handle unique constraint violation (e.g., commit already exists)
|
|
86
|
-
console.warn(`Skipping commit: ${commit.hash} (Depenndency already exists)`);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
// Handle any other unexpected errors
|
|
90
|
-
console.error(`Failed to store commit: ${commit.hash}`, err);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Store packages in database
|
|
97
|
-
*/
|
|
98
|
-
async function storePackage(pkg) {
|
|
99
|
-
try {
|
|
100
|
-
// Create or update package
|
|
101
|
-
await prisma.package.upsert({
|
|
102
|
-
where: { name: pkg.name },
|
|
103
|
-
update: {
|
|
104
|
-
version: pkg.version,
|
|
105
|
-
type: pkg.type,
|
|
106
|
-
path: pkg.path,
|
|
107
|
-
description: pkg.description,
|
|
108
|
-
license: pkg.license,
|
|
109
|
-
repository: JSON.stringify(pkg.repository),
|
|
110
|
-
scripts: JSON.stringify(pkg.scripts),
|
|
111
|
-
lastUpdated: new Date(),
|
|
112
|
-
},
|
|
113
|
-
create: {
|
|
114
|
-
// Timestamps
|
|
115
|
-
createdAt: new Date(),
|
|
116
|
-
lastUpdated: new Date(),
|
|
117
|
-
dependencies: JSON.stringify(pkg.dependencies), // The total number of direct dependencies
|
|
118
|
-
// Manual Serialization Required: Stores a JSON array string of maintainers, e.g., '["team-frontend"]'
|
|
119
|
-
maintainers: pkg.maintainers.join(','),
|
|
120
|
-
// Manual Serialization Required: Stores the scripts object as a JSON string
|
|
121
|
-
// Example: '{"dev": "vite", "build": "tsc && vite build"}'
|
|
122
|
-
scripts: JSON.stringify(pkg.scripts),
|
|
123
|
-
devDependencies: JSON.stringify(pkg.devDependencies),
|
|
124
|
-
peerDependencies: JSON.stringify(pkg.peerDependencies),
|
|
125
|
-
name: pkg.name,
|
|
126
|
-
version: pkg.version,
|
|
127
|
-
type: pkg.type,
|
|
128
|
-
path: pkg.path,
|
|
129
|
-
description: pkg.description ?? '',
|
|
130
|
-
license: pkg.license ?? '',
|
|
131
|
-
repository: JSON.stringify(pkg.repository),
|
|
132
|
-
status: '',
|
|
133
|
-
},
|
|
134
|
-
});
|
|
135
|
-
const commits = await getCommits(pkg.path ?? '');
|
|
136
|
-
if (commits.length) {
|
|
137
|
-
await storeCommits(pkg.name, commits);
|
|
138
|
-
}
|
|
139
|
-
const dependenciesInfo = getPackageDependenciesInfo(pkg);
|
|
140
|
-
if (dependenciesInfo.length) {
|
|
141
|
-
await storeDependencies(pkg.name, dependenciesInfo);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
catch (error) {
|
|
145
|
-
console.warn(` Failed to store report for ${pkg.name}:`, error);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Get package dependencies
|
|
150
|
-
*/
|
|
151
|
-
function getPackageDependenciesInfo(pkg) {
|
|
152
|
-
const allDeps = [];
|
|
153
|
-
Object.keys(pkg.dependencies || {}).forEach(depName => {
|
|
154
|
-
allDeps.push({
|
|
155
|
-
name: depName,
|
|
156
|
-
version: pkg.dependencies[depName],
|
|
157
|
-
type: 'dependency',
|
|
158
|
-
latest: '',
|
|
159
|
-
outdated: false,
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
Object.keys(pkg.devDependencies || {}).forEach(depName => {
|
|
163
|
-
allDeps.push({
|
|
164
|
-
name: depName,
|
|
165
|
-
version: pkg.devDependencies[depName],
|
|
166
|
-
type: 'devDependency',
|
|
167
|
-
latest: '',
|
|
168
|
-
outdated: false,
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
Object.keys(pkg.peerDependencies || {}).forEach(depName => {
|
|
172
|
-
allDeps.push({
|
|
173
|
-
name: depName,
|
|
174
|
-
version: pkg.peerDependencies[depName],
|
|
175
|
-
type: 'peerDependency',
|
|
176
|
-
latest: '',
|
|
177
|
-
outdated: false,
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
return allDeps;
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Store dependencies in database
|
|
184
|
-
*/
|
|
185
|
-
async function storeDependencies(packageName, dependencies) {
|
|
186
|
-
console.log('Storing Dependencies for:' + packageName);
|
|
187
|
-
// Create or update dependencies
|
|
188
|
-
for (const dep of dependencies) {
|
|
189
|
-
try {
|
|
190
|
-
await prisma.dependencyInfo.upsert({
|
|
191
|
-
where: {
|
|
192
|
-
name_packageName: {
|
|
193
|
-
// This refers to the composite unique constraint
|
|
194
|
-
name: dep.name,
|
|
195
|
-
packageName,
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
update: {
|
|
199
|
-
version: dep.version,
|
|
200
|
-
type: dep.type,
|
|
201
|
-
latest: dep.latest,
|
|
202
|
-
outdated: dep.outdated,
|
|
203
|
-
},
|
|
204
|
-
create: {
|
|
205
|
-
name: dep.name,
|
|
206
|
-
version: dep.version,
|
|
207
|
-
type: dep.type,
|
|
208
|
-
latest: dep.latest,
|
|
209
|
-
outdated: dep.outdated,
|
|
210
|
-
packageName: packageName,
|
|
211
|
-
},
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
catch (e) {
|
|
215
|
-
const err = e;
|
|
216
|
-
if (err instanceof Prisma.PrismaClientKnownRequestError &&
|
|
217
|
-
err.code === 'P2002') {
|
|
218
|
-
// Handle unique constraint violation (e.g., depedency already exists)
|
|
219
|
-
console.warn(`Skipping dependency: ${dep.name} (Depenndency already exists)`);
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
// Handle any other unexpected errors
|
|
223
|
-
console.error(`Failed to store dependency: ${dep.name}`, err);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { scanMonorepo } from '../utils/utilities';
|
|
2
|
-
import { generateReports } from '../utils/monorepo-scanner';
|
|
3
|
-
import { ciStatusManager } from '../utils/ci-status';
|
|
4
|
-
import { storePackage } from '../utils/db-utils';
|
|
5
|
-
|
|
6
|
-
import * as PrismaPkg from '@prisma/client';
|
|
7
|
-
const PrismaClient = (PrismaPkg as any).PrismaClient || (PrismaPkg as any).default || PrismaPkg;
|
|
8
|
-
const prisma = new PrismaClient();
|
|
9
|
-
|
|
10
|
-
export const getPackagesService = async (rootPath: string) => {
|
|
11
|
-
let dbPackages = await prisma.package.findMany();
|
|
12
|
-
if (!dbPackages.length) {
|
|
13
|
-
try {
|
|
14
|
-
const rootDir = rootPath;
|
|
15
|
-
console.log('rootDir -->', rootDir);
|
|
16
|
-
const packages = scanMonorepo(rootDir);
|
|
17
|
-
console.log('packages --> scan', packages.length);
|
|
18
|
-
for (const pkg of packages) {
|
|
19
|
-
await storePackage(pkg);
|
|
20
|
-
}
|
|
21
|
-
} catch (error) {
|
|
22
|
-
throw new Error('Error ' + error);
|
|
23
|
-
}
|
|
24
|
-
dbPackages = await prisma.package.findMany();
|
|
25
|
-
}
|
|
26
|
-
const transformedPackages = dbPackages.map((pkg: any) => {
|
|
27
|
-
// We create a new object 'transformedPkg' based on the database record 'pkg'
|
|
28
|
-
const transformedPkg = { ...pkg };
|
|
29
|
-
|
|
30
|
-
// 1. Maintainers
|
|
31
|
-
transformedPkg.maintainers = pkg.maintainers
|
|
32
|
-
? JSON.parse(pkg.maintainers)
|
|
33
|
-
: [];
|
|
34
|
-
|
|
35
|
-
// 2. Scripts/repository (should default to an object, not an array)
|
|
36
|
-
transformedPkg.scripts = pkg.scripts ? JSON.parse(pkg.scripts) : {};
|
|
37
|
-
transformedPkg.repository = pkg.repository
|
|
38
|
-
? JSON.parse(pkg.repository)
|
|
39
|
-
: {};
|
|
40
|
-
|
|
41
|
-
// 3. Dependencies List
|
|
42
|
-
transformedPkg.dependencies = pkg.dependencies
|
|
43
|
-
? JSON.parse(pkg.dependencies)
|
|
44
|
-
: [];
|
|
45
|
-
transformedPkg.devDependencies = pkg.devDependencies
|
|
46
|
-
? JSON.parse(pkg.devDependencies)
|
|
47
|
-
: [];
|
|
48
|
-
transformedPkg.peerDependencies = pkg.peerDependencies
|
|
49
|
-
? JSON.parse(pkg.peerDependencies)
|
|
50
|
-
: [];
|
|
51
|
-
return transformedPkg; // Return the fully transformed object
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
return transformedPackages;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export const refreshPackagesService = async (rootPath: string) => {
|
|
58
|
-
await prisma.package.deleteMany();
|
|
59
|
-
|
|
60
|
-
const rootDir = rootPath;
|
|
61
|
-
const packages = scanMonorepo(rootDir);
|
|
62
|
-
|
|
63
|
-
console.log('packages -->', packages.length);
|
|
64
|
-
for (const pkg of packages) {
|
|
65
|
-
await storePackage(pkg);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return packages;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export const getPackageDetailService = async (name: string) => {
|
|
72
|
-
|
|
73
|
-
const pkg = await prisma.package.findUnique({
|
|
74
|
-
where: {
|
|
75
|
-
name: name,
|
|
76
|
-
},
|
|
77
|
-
include: {
|
|
78
|
-
dependenciesInfo: true,
|
|
79
|
-
commits: true,
|
|
80
|
-
packageHealth: true,
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
if (!pkg) {
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
const transformedPkg = { ...pkg };
|
|
87
|
-
|
|
88
|
-
transformedPkg.scripts = pkg.scripts ? JSON.parse(pkg.scripts) : {};
|
|
89
|
-
transformedPkg.repository = pkg.repository
|
|
90
|
-
? JSON.parse(pkg.repository)
|
|
91
|
-
: {};
|
|
92
|
-
|
|
93
|
-
transformedPkg.dependencies = pkg.dependencies
|
|
94
|
-
? JSON.parse(pkg.dependencies)
|
|
95
|
-
: [];
|
|
96
|
-
transformedPkg.devDependencies = pkg.devDependencies
|
|
97
|
-
? JSON.parse(pkg.devDependencies)
|
|
98
|
-
: [];
|
|
99
|
-
transformedPkg.peerDependencies = pkg.peerDependencies
|
|
100
|
-
? JSON.parse(pkg.peerDependencies)
|
|
101
|
-
: [];
|
|
102
|
-
|
|
103
|
-
// Get additional package information
|
|
104
|
-
const reports: any[] = await generateReports();
|
|
105
|
-
const packageReport = reports.find((r: any) => r.package.name === name);
|
|
106
|
-
|
|
107
|
-
const result = {
|
|
108
|
-
...transformedPkg,
|
|
109
|
-
report: packageReport,
|
|
110
|
-
ciStatus: await ciStatusManager.getPackageStatus(name),
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
return result;
|
|
114
|
-
|
|
115
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// This declaration explicitly tells TypeScript about the specific functions
|
|
2
|
-
// exported by the '@monodog/monorepo-scanner' package, bypassing TS7016 errors.
|
|
3
|
-
|
|
4
|
-
declare module '@monodog/monorepo-scanner' {
|
|
5
|
-
/**
|
|
6
|
-
* Declares the exported function 'funCheckSecurityAudit'.
|
|
7
|
-
* The actual implementation and return type reside in the source package.
|
|
8
|
-
*/
|
|
9
|
-
export function funCheckSecurityAudit(options?: any): any;
|
|
10
|
-
export function funCheckTestCoverage(options?: any): any;
|
|
11
|
-
export function funCheckLintStatus(options?: any): any;
|
|
12
|
-
export function funCheckBuildStatus(options?: any): any;
|
|
13
|
-
export function generateReports(options?: any): any;
|
|
14
|
-
export function quickScan(options?: any): any;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Defines the exported class structure, including the constructor
|
|
18
|
-
* and the methods used in the backend.
|
|
19
|
-
*/
|
|
20
|
-
export class MonorepoScanner {
|
|
21
|
-
// Constructor (when called with `new`)
|
|
22
|
-
constructor(options?: any);
|
|
23
|
-
|
|
24
|
-
/** * Resets any internal cache state for the scanner.
|
|
25
|
-
*/
|
|
26
|
-
clearCache(): void;
|
|
27
|
-
|
|
28
|
-
/** * Retrieves the processed results from the scan.
|
|
29
|
-
*/
|
|
30
|
-
exportResults(result: any, format: 'json' | 'csv' | 'html'): any;
|
|
31
|
-
}
|
|
32
|
-
}
|
package/src/utils/db-utils.ts
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import type { PackageInfo, DependencyInfo, Commit } from '../types';
|
|
2
|
-
import * as PrismaPkg from '@prisma/client';
|
|
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
|
-
import { appConfig } from '../config-loader';
|
|
7
|
-
|
|
8
|
-
// Default settings
|
|
9
|
-
const DEFAULT_PORT = 4000;
|
|
10
|
-
const port = appConfig.server.port ?? DEFAULT_PORT; //Default port
|
|
11
|
-
const host = appConfig.server.host ?? 'localhost'; //Default host
|
|
12
|
-
|
|
13
|
-
const prisma = new PrismaClient();
|
|
14
|
-
const API_BASE = `http://${host}:${port}/api`;
|
|
15
|
-
|
|
16
|
-
async function getCommits(path: string): Promise<Commit[]> {
|
|
17
|
-
const res = await fetch(API_BASE + `/commits/` + encodeURIComponent(path));
|
|
18
|
-
if (!res.ok) throw new Error('Failed to fetch commits');
|
|
19
|
-
return (await res.json()) as Commit[];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async function storeCommits(
|
|
23
|
-
packageName: string,
|
|
24
|
-
commits: Commit[]
|
|
25
|
-
): Promise<void> {
|
|
26
|
-
console.log('Storing commits for:' + packageName);
|
|
27
|
-
// Create or update dependencies
|
|
28
|
-
for (const commit of commits) {
|
|
29
|
-
try {
|
|
30
|
-
await prisma.commit.upsert({
|
|
31
|
-
where: {
|
|
32
|
-
hash_packageName: {
|
|
33
|
-
hash: commit.hash,
|
|
34
|
-
packageName: packageName,
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
update: {
|
|
38
|
-
message: commit.message,
|
|
39
|
-
author: commit.author,
|
|
40
|
-
date: commit.date,
|
|
41
|
-
type: commit.type,
|
|
42
|
-
},
|
|
43
|
-
create: {
|
|
44
|
-
hash: commit.hash,
|
|
45
|
-
message: commit.message,
|
|
46
|
-
author: commit.author,
|
|
47
|
-
date: commit.date,
|
|
48
|
-
type: commit.type,
|
|
49
|
-
packageName: packageName,
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
} catch (e) {
|
|
53
|
-
const err = e as any;
|
|
54
|
-
if (
|
|
55
|
-
err instanceof Prisma.PrismaClientKnownRequestError &&
|
|
56
|
-
err.code === 'P2002'
|
|
57
|
-
) {
|
|
58
|
-
// Handle unique constraint violation (e.g., commit already exists)
|
|
59
|
-
console.warn(
|
|
60
|
-
`Skipping commit: ${commit.hash} (Depenndency already exists)`
|
|
61
|
-
);
|
|
62
|
-
} else {
|
|
63
|
-
// Handle any other unexpected errors
|
|
64
|
-
console.error(`Failed to store commit: ${commit.hash}`, err);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Store packages in database
|
|
71
|
-
*/
|
|
72
|
-
async function storePackage(pkg: PackageInfo): Promise<void> {
|
|
73
|
-
try {
|
|
74
|
-
// Create or update package
|
|
75
|
-
await prisma.package.upsert({
|
|
76
|
-
where: { name: pkg.name },
|
|
77
|
-
update: {
|
|
78
|
-
version: pkg.version,
|
|
79
|
-
type: pkg.type,
|
|
80
|
-
path: pkg.path,
|
|
81
|
-
description: pkg.description,
|
|
82
|
-
license: pkg.license,
|
|
83
|
-
repository: JSON.stringify(pkg.repository),
|
|
84
|
-
scripts: JSON.stringify(pkg.scripts),
|
|
85
|
-
lastUpdated: new Date(),
|
|
86
|
-
},
|
|
87
|
-
create: {
|
|
88
|
-
// Timestamps
|
|
89
|
-
createdAt: new Date(),
|
|
90
|
-
lastUpdated: new Date(),
|
|
91
|
-
|
|
92
|
-
dependencies: JSON.stringify(pkg.dependencies), // The total number of direct dependencies
|
|
93
|
-
// Manual Serialization Required: Stores a JSON array string of maintainers, e.g., '["team-frontend"]'
|
|
94
|
-
maintainers: pkg.maintainers.join(','),
|
|
95
|
-
|
|
96
|
-
// Manual Serialization Required: Stores the scripts object as a JSON string
|
|
97
|
-
// Example: '{"dev": "vite", "build": "tsc && vite build"}'
|
|
98
|
-
scripts: JSON.stringify(pkg.scripts),
|
|
99
|
-
|
|
100
|
-
devDependencies: JSON.stringify(pkg.devDependencies),
|
|
101
|
-
peerDependencies: JSON.stringify(pkg.peerDependencies),
|
|
102
|
-
name: pkg.name,
|
|
103
|
-
version: pkg.version,
|
|
104
|
-
type: pkg.type,
|
|
105
|
-
path: pkg.path,
|
|
106
|
-
description: pkg.description ?? '',
|
|
107
|
-
license: pkg.license ?? '',
|
|
108
|
-
repository: JSON.stringify(pkg.repository),
|
|
109
|
-
status: '',
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
const commits = await getCommits(pkg.path ?? '');
|
|
114
|
-
if (commits.length) {
|
|
115
|
-
await storeCommits(pkg.name, commits);
|
|
116
|
-
}
|
|
117
|
-
const dependenciesInfo = getPackageDependenciesInfo(pkg);
|
|
118
|
-
if (dependenciesInfo.length) {
|
|
119
|
-
await storeDependencies(pkg.name, dependenciesInfo);
|
|
120
|
-
}
|
|
121
|
-
} catch (error) {
|
|
122
|
-
console.warn(` Failed to store report for ${pkg.name}:`, error);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Get package dependencies
|
|
128
|
-
*/
|
|
129
|
-
function getPackageDependenciesInfo(pkg: PackageInfo): DependencyInfo[] {
|
|
130
|
-
const allDeps: DependencyInfo[] = [];
|
|
131
|
-
Object.keys(pkg.dependencies || {}).forEach(depName => {
|
|
132
|
-
allDeps.push({
|
|
133
|
-
name: depName,
|
|
134
|
-
version: pkg.dependencies[depName],
|
|
135
|
-
type: 'dependency',
|
|
136
|
-
latest: '',
|
|
137
|
-
outdated: false,
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
Object.keys(pkg.devDependencies || {}).forEach(depName => {
|
|
141
|
-
allDeps.push({
|
|
142
|
-
name: depName,
|
|
143
|
-
version: pkg.devDependencies[depName],
|
|
144
|
-
type: 'devDependency',
|
|
145
|
-
latest: '',
|
|
146
|
-
outdated: false,
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
Object.keys(pkg.peerDependencies || {}).forEach(depName => {
|
|
150
|
-
allDeps.push({
|
|
151
|
-
name: depName,
|
|
152
|
-
version: pkg.peerDependencies[depName]!,
|
|
153
|
-
type: 'peerDependency',
|
|
154
|
-
latest: '',
|
|
155
|
-
outdated: false,
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
return allDeps;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Store dependencies in database
|
|
163
|
-
*/
|
|
164
|
-
async function storeDependencies(
|
|
165
|
-
packageName: string,
|
|
166
|
-
dependencies: DependencyInfo[]
|
|
167
|
-
): Promise<void> {
|
|
168
|
-
console.log('Storing Dependencies for:' + packageName);
|
|
169
|
-
// Create or update dependencies
|
|
170
|
-
for (const dep of dependencies) {
|
|
171
|
-
try {
|
|
172
|
-
await prisma.dependencyInfo.upsert({
|
|
173
|
-
where: {
|
|
174
|
-
name_packageName: {
|
|
175
|
-
// This refers to the composite unique constraint
|
|
176
|
-
name: dep.name,
|
|
177
|
-
packageName,
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
update: {
|
|
181
|
-
version: dep.version,
|
|
182
|
-
type: dep.type,
|
|
183
|
-
latest: dep.latest,
|
|
184
|
-
outdated: dep.outdated,
|
|
185
|
-
},
|
|
186
|
-
create: {
|
|
187
|
-
name: dep.name,
|
|
188
|
-
version: dep.version,
|
|
189
|
-
type: dep.type,
|
|
190
|
-
latest: dep.latest,
|
|
191
|
-
outdated: dep.outdated,
|
|
192
|
-
packageName: packageName,
|
|
193
|
-
},
|
|
194
|
-
});
|
|
195
|
-
} catch (e) {
|
|
196
|
-
const err = e as any;
|
|
197
|
-
if (
|
|
198
|
-
err instanceof Prisma.PrismaClientKnownRequestError &&
|
|
199
|
-
err.code === 'P2002'
|
|
200
|
-
) {
|
|
201
|
-
// Handle unique constraint violation (e.g., depedency already exists)
|
|
202
|
-
console.warn(
|
|
203
|
-
`Skipping dependency: ${dep.name} (Depenndency already exists)`
|
|
204
|
-
);
|
|
205
|
-
} else {
|
|
206
|
-
// Handle any other unexpected errors
|
|
207
|
-
console.error(`Failed to store dependency: ${dep.name}`, err);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
export {
|
|
214
|
-
storePackage
|
|
215
|
-
// OPTIONAL: Export other functions if needed
|
|
216
|
-
// getCommits,
|
|
217
|
-
// storeCommits,
|
|
218
|
-
// getPackageDependenciesInfo,
|
|
219
|
-
// storeDependencies,
|
|
220
|
-
};
|
|
File without changes
|