@monodog/backend 1.5.2 → 1.5.4

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.
@@ -1,4 +1,4 @@
1
- // This declaration explicitly tells TypeScript about the specific functions
1
+ // This declaration explicitly tells TypeScript about the specific functions
2
2
  // exported by the '@monodog/monorepo-scanner' package, bypassing TS7016 errors.
3
3
 
4
4
  declare module '@monodog/monorepo-scanner' {
@@ -19,15 +19,14 @@ declare module '@monodog/monorepo-scanner' {
19
19
  */
20
20
  export class MonorepoScanner {
21
21
  // Constructor (when called with `new`)
22
- constructor(options?: any);
23
-
24
- /** * Resets any internal cache state for the scanner.
22
+ constructor(options?: any);
23
+
24
+ /** * Resets any internal cache state for the scanner.
25
25
  */
26
26
  clearCache(): void;
27
-
28
- /** * Retrieves the processed results from the scan.
27
+
28
+ /** * Retrieves the processed results from the scan.
29
29
  */
30
30
  exportResults(result: any, format: 'json' | 'csv' | 'html'): any;
31
-
32
31
  }
33
- }
32
+ }
@@ -1,199 +1,203 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ 'use strict';
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
7
+ Object.defineProperty(exports, '__esModule', { value: true });
6
8
  exports.getCommits = getCommits;
7
9
  exports.storePackage = storePackage;
8
10
  exports.storeCommits = storeCommits;
9
11
  exports.getPackageDependenciesInfo = getPackageDependenciesInfo;
10
12
  exports.storeDependencies = storeDependencies;
11
- const dotenv_1 = __importDefault(require("dotenv"));
12
- const path_1 = __importDefault(require("path"));
13
+ const dotenv_1 = __importDefault(require('dotenv'));
14
+ const path_1 = __importDefault(require('path'));
13
15
  dotenv_1.default.config({ path: path_1.default.resolve(__dirname, '../.env') });
14
- const client_1 = require("@prisma/client");
16
+ const client_1 = require('@prisma/client');
15
17
  const prisma = new client_1.PrismaClient();
16
18
  const API_BASE = `http://localhost:4000/api`;
17
19
  async function getCommits(path) {
18
- const res = await fetch(API_BASE + `/commits/` + encodeURIComponent(path));
19
- if (!res.ok)
20
- throw new Error('Failed to fetch commits');
21
- return await res.json();
20
+ const res = await fetch(API_BASE + `/commits/` + encodeURIComponent(path));
21
+ if (!res.ok) throw new Error('Failed to fetch commits');
22
+ return await res.json();
22
23
  }
23
24
  async function storeCommits(packageName, commits) {
24
- console.log('💾 Storing commits for:' + packageName);
25
- // Create or update dependencies
26
- for (const commit of commits) {
27
- try {
28
- await prisma.commit.upsert({
29
- where: {
30
- hash: commit.hash,
31
- },
32
- update: {
33
- message: commit.message,
34
- author: commit.author,
35
- date: commit.date,
36
- type: commit.type,
37
- },
38
- create: {
39
- hash: commit.hash,
40
- message: commit.message,
41
- author: commit.author,
42
- date: commit.date,
43
- type: commit.type,
44
- packageName: packageName,
45
- },
46
- });
47
- }
48
- catch (e) {
49
- if (e instanceof client_1.Prisma.PrismaClientKnownRequestError &&
50
- e.code === 'P2002') {
51
- // Handle unique constraint violation (e.g., commit already exists)
52
- console.warn(`Skipping commit: ${commit.hash} (Depenndency already exists)`);
53
- }
54
- else {
55
- // Handle any other unexpected errors
56
- console.error(`Failed to store commit: ${commit.hash}`, e);
57
- }
58
- }
25
+ console.log('💾 Storing commits for:' + packageName);
26
+ // Create or update dependencies
27
+ for (const commit of commits) {
28
+ try {
29
+ await prisma.commit.upsert({
30
+ where: {
31
+ hash: commit.hash,
32
+ },
33
+ update: {
34
+ message: commit.message,
35
+ author: commit.author,
36
+ date: commit.date,
37
+ type: commit.type,
38
+ },
39
+ create: {
40
+ hash: commit.hash,
41
+ message: commit.message,
42
+ author: commit.author,
43
+ date: commit.date,
44
+ type: commit.type,
45
+ packageName: packageName,
46
+ },
47
+ });
48
+ } catch (e) {
49
+ if (
50
+ e instanceof client_1.Prisma.PrismaClientKnownRequestError &&
51
+ e.code === 'P2002'
52
+ ) {
53
+ // Handle unique constraint violation (e.g., commit already exists)
54
+ console.warn(
55
+ `Skipping commit: ${commit.hash} (Depenndency already exists)`
56
+ );
57
+ } else {
58
+ // Handle any other unexpected errors
59
+ console.error(`Failed to store commit: ${commit.hash}`, e);
60
+ }
59
61
  }
62
+ }
60
63
  }
61
64
  /**
62
65
  * Store packages in database
63
66
  */
64
67
  async function storePackage(pkg) {
65
- try {
66
- // Create or update package
67
- await prisma.package.upsert({
68
- where: { name: pkg.name },
69
- update: {
70
- version: pkg.version,
71
- type: pkg.type,
72
- path: pkg.path,
73
- description: pkg.description,
74
- license: pkg.license,
75
- repository: JSON.stringify(pkg.repository),
76
- scripts: JSON.stringify(pkg.scripts),
77
- lastUpdated: new Date(),
78
- },
79
- create: {
80
- // Timestamps
81
- createdAt: new Date(),
82
- lastUpdated: new Date(),
83
- // Key Metrics and Relationships
84
- dependencies: JSON.stringify(pkg.dependencies), // The total number of direct dependencies (12 in your example)
85
- // Manual Serialization Required: Stores a JSON array string of maintainers, e.g., '["team-frontend"]'
86
- maintainers: pkg.maintainers.join(','),
87
- // Manual Serialization Required: Stores a JSON array string of tags, e.g., '["core", "ui"]'
88
- // Manual Serialization Required: Stores the scripts object as a JSON string
89
- // Example: '{"dev": "vite", "build": "tsc && vite build"}'
90
- scripts: JSON.stringify(pkg.scripts),
91
- // Dependency Lists (Manual Serialization Required)
92
- // Stores a JSON array string of dependencies.
93
- // dependenciesList: JSON.stringify(pkg.dependenciesList),
94
- devDependencies: JSON.stringify(pkg.devDependencies),
95
- peerDependencies: JSON.stringify(pkg.peerDependencies),
96
- name: pkg.name,
97
- version: pkg.version,
98
- type: pkg.type,
99
- path: pkg.path,
100
- description: pkg.description ?? '',
101
- license: pkg.license ?? '',
102
- repository: JSON.stringify(pkg.repository),
103
- status: '',
104
- },
105
- });
106
- const commits = await getCommits(pkg.path ?? '');
107
- if (commits.length) {
108
- await storeCommits(pkg.name, commits);
109
- }
110
- const dependenciesInfo = getPackageDependenciesInfo(pkg);
111
- if (dependenciesInfo.length) {
112
- await storeDependencies(pkg.name, dependenciesInfo);
113
- }
68
+ try {
69
+ // Create or update package
70
+ await prisma.package.upsert({
71
+ where: { name: pkg.name },
72
+ update: {
73
+ version: pkg.version,
74
+ type: pkg.type,
75
+ path: pkg.path,
76
+ description: pkg.description,
77
+ license: pkg.license,
78
+ repository: JSON.stringify(pkg.repository),
79
+ scripts: JSON.stringify(pkg.scripts),
80
+ lastUpdated: new Date(),
81
+ },
82
+ create: {
83
+ // Timestamps
84
+ createdAt: new Date(),
85
+ lastUpdated: new Date(),
86
+ // Key Metrics and Relationships
87
+ dependencies: JSON.stringify(pkg.dependencies), // The total number of direct dependencies (12 in your example)
88
+ // Manual Serialization Required: Stores a JSON array string of maintainers, e.g., '["team-frontend"]'
89
+ maintainers: pkg.maintainers.join(','),
90
+ // Manual Serialization Required: Stores a JSON array string of tags, e.g., '["core", "ui"]'
91
+ // Manual Serialization Required: Stores the scripts object as a JSON string
92
+ // Example: '{"dev": "vite", "build": "tsc && vite build"}'
93
+ scripts: JSON.stringify(pkg.scripts),
94
+ // Dependency Lists (Manual Serialization Required)
95
+ // Stores a JSON array string of dependencies.
96
+ // dependenciesList: JSON.stringify(pkg.dependenciesList),
97
+ devDependencies: JSON.stringify(pkg.devDependencies),
98
+ peerDependencies: JSON.stringify(pkg.peerDependencies),
99
+ name: pkg.name,
100
+ version: pkg.version,
101
+ type: pkg.type,
102
+ path: pkg.path,
103
+ description: pkg.description ?? '',
104
+ license: pkg.license ?? '',
105
+ repository: JSON.stringify(pkg.repository),
106
+ status: '',
107
+ },
108
+ });
109
+ const commits = await getCommits(pkg.path ?? '');
110
+ if (commits.length) {
111
+ await storeCommits(pkg.name, commits);
114
112
  }
115
- catch (error) {
116
- console.warn(`⚠️ Failed to store report for ${pkg.name}:`, error);
113
+ const dependenciesInfo = getPackageDependenciesInfo(pkg);
114
+ if (dependenciesInfo.length) {
115
+ await storeDependencies(pkg.name, dependenciesInfo);
117
116
  }
117
+ } catch (error) {
118
+ console.warn(`⚠️ Failed to store report for ${pkg.name}:`, error);
119
+ }
118
120
  }
119
121
  /**
120
122
  * Get package dependencies
121
123
  */
122
124
  function getPackageDependenciesInfo(pkg) {
123
- const allDeps = [];
124
- Object.keys(pkg.dependencies || {}).forEach(depName => {
125
- allDeps.push({
126
- name: depName,
127
- version: pkg.dependencies[depName],
128
- type: 'dependency',
129
- latest: '',
130
- outdated: false,
131
- });
125
+ const allDeps = [];
126
+ Object.keys(pkg.dependencies || {}).forEach(depName => {
127
+ allDeps.push({
128
+ name: depName,
129
+ version: pkg.dependencies[depName],
130
+ type: 'dependency',
131
+ latest: '',
132
+ outdated: false,
132
133
  });
133
- Object.keys(pkg.devDependencies || {}).forEach(depName => {
134
- allDeps.push({
135
- name: depName,
136
- version: pkg.devDependencies[depName],
137
- type: 'devDependency',
138
- latest: '',
139
- outdated: false,
140
- });
134
+ });
135
+ Object.keys(pkg.devDependencies || {}).forEach(depName => {
136
+ allDeps.push({
137
+ name: depName,
138
+ version: pkg.devDependencies[depName],
139
+ type: 'devDependency',
140
+ latest: '',
141
+ outdated: false,
141
142
  });
142
- Object.keys(pkg.peerDependencies || {}).forEach(depName => {
143
- allDeps.push({
144
- name: depName,
145
- version: pkg.peerDependencies[depName],
146
- type: 'peerDependency',
147
- latest: '',
148
- outdated: false,
149
- });
143
+ });
144
+ Object.keys(pkg.peerDependencies || {}).forEach(depName => {
145
+ allDeps.push({
146
+ name: depName,
147
+ version: pkg.peerDependencies[depName],
148
+ type: 'peerDependency',
149
+ latest: '',
150
+ outdated: false,
150
151
  });
151
- return allDeps;
152
+ });
153
+ return allDeps;
152
154
  }
153
155
  /**
154
156
  * Store dependencies in database
155
157
  */
156
158
  async function storeDependencies(packageName, dependencies) {
157
- console.log('💾 Storing Dependencies for:' + packageName);
158
- // Create or update dependencies
159
- for (const dep of dependencies) {
160
- try {
161
- await prisma.dependencyInfo.upsert({
162
- where: {
163
- name_packageName: {
164
- // This refers to the composite unique constraint
165
- name: dep.name,
166
- packageName,
167
- },
168
- },
169
- update: {
170
- version: dep.version,
171
- type: dep.type,
172
- latest: dep.latest,
173
- outdated: dep.outdated,
174
- },
175
- create: {
176
- name: dep.name,
177
- version: dep.version,
178
- type: dep.type,
179
- latest: dep.latest,
180
- outdated: dep.outdated,
181
- packageName: packageName,
182
- },
183
- });
184
- console.log('💾 Dependencies stored in database:' + dep.name);
185
- }
186
- catch (e) {
187
- if (e instanceof client_1.Prisma.PrismaClientKnownRequestError &&
188
- e.code === 'P2002') {
189
- // Handle unique constraint violation (e.g., depedency already exists)
190
- console.warn(`Skipping dependency: ${dep.name} (Depenndency already exists)`);
191
- }
192
- else {
193
- // Handle any other unexpected errors
194
- console.error(`Failed to store dependency: ${dep.name}`, e);
195
- }
196
- }
159
+ console.log('💾 Storing Dependencies for:' + packageName);
160
+ // Create or update dependencies
161
+ for (const dep of dependencies) {
162
+ try {
163
+ await prisma.dependencyInfo.upsert({
164
+ where: {
165
+ name_packageName: {
166
+ // This refers to the composite unique constraint
167
+ name: dep.name,
168
+ packageName,
169
+ },
170
+ },
171
+ update: {
172
+ version: dep.version,
173
+ type: dep.type,
174
+ latest: dep.latest,
175
+ outdated: dep.outdated,
176
+ },
177
+ create: {
178
+ name: dep.name,
179
+ version: dep.version,
180
+ type: dep.type,
181
+ latest: dep.latest,
182
+ outdated: dep.outdated,
183
+ packageName: packageName,
184
+ },
185
+ });
186
+ console.log('💾 Dependencies stored in database:' + dep.name);
187
+ } catch (e) {
188
+ if (
189
+ e instanceof client_1.Prisma.PrismaClientKnownRequestError &&
190
+ e.code === 'P2002'
191
+ ) {
192
+ // Handle unique constraint violation (e.g., depedency already exists)
193
+ console.warn(
194
+ `Skipping dependency: ${dep.name} (Depenndency already exists)`
195
+ );
196
+ } else {
197
+ // Handle any other unexpected errors
198
+ console.error(`Failed to store dependency: ${dep.name}`, e);
199
+ }
197
200
  }
201
+ }
198
202
  }
199
- //# sourceMappingURL=helpers.js.map
203
+ //# sourceMappingURL=helpers.js.map
@@ -1,16 +1,17 @@
1
-
2
- import {
3
-
4
- PackageInfo,
5
- DependencyInfo,
6
- } from '@monodog/utils/helpers'
1
+ import { PackageInfo, DependencyInfo } from '@monodog/utils/helpers';
7
2
  // import dotenv from 'dotenv';
8
3
  import path from 'path';
9
4
  // dotenv.config({ path: path.resolve(__dirname, '../.env') });
10
- import { PrismaClient, Prisma, Commit } from '@prisma/client';
5
+ // Fallback import to handle environments where PrismaClient isn't a named export
6
+ import * as PrismaPkg from '@prisma/client';
7
+ const PrismaClient = (PrismaPkg as any).PrismaClient || (PrismaPkg as any).default || PrismaPkg;
8
+ // Provide a fallback reference to the Prisma namespace so errors like
9
+ // Prisma.PrismaClientKnownRequestError can be referenced safely.
10
+ const Prisma = (PrismaPkg as any).Prisma || (PrismaPkg as any).PrismaClient?.Prisma || (PrismaPkg as any).default?.Prisma || PrismaPkg;
11
+ // Import the validateConfig function from your utils
11
12
  import { loadConfig } from '../config-loader';
12
13
 
13
- const appConfig = loadConfig();
14
+ const appConfig = loadConfig();
14
15
 
15
16
  // Default settings
16
17
  const DEFAULT_PORT = 4000;
@@ -23,9 +24,16 @@ const API_BASE = `http://${host}:${port}/api`;
23
24
  async function getCommits(path: string): Promise<Commit[]> {
24
25
  const res = await fetch(API_BASE + `/commits/` + encodeURIComponent(path));
25
26
  if (!res.ok) throw new Error('Failed to fetch commits');
26
- return await res.json() as Commit[];
27
+ return (await res.json()) as Commit[];
28
+ }
29
+ // Commit type used by getCommits/storeCommits
30
+ export interface Commit {
31
+ hash: string;
32
+ message?: string;
33
+ author?: string;
34
+ date?: string;
35
+ type?: string;
27
36
  }
28
-
29
37
  async function storeCommits(
30
38
  packageName: string,
31
39
  commits: Commit[]
@@ -54,9 +62,10 @@ async function storeCommits(
54
62
  },
55
63
  });
56
64
  } catch (e) {
65
+ const err = e as any;
57
66
  if (
58
- e instanceof Prisma.PrismaClientKnownRequestError &&
59
- e.code === 'P2002'
67
+ err instanceof Prisma.PrismaClientKnownRequestError &&
68
+ err.code === 'P2002'
60
69
  ) {
61
70
  // Handle unique constraint violation (e.g., commit already exists)
62
71
  console.warn(
@@ -64,7 +73,7 @@ async function storeCommits(
64
73
  );
65
74
  } else {
66
75
  // Handle any other unexpected errors
67
- console.error(`Failed to store commit: ${commit.hash}`, e);
76
+ console.error(`Failed to store commit: ${commit.hash}`, err);
68
77
  }
69
78
  }
70
79
  }
@@ -73,68 +82,63 @@ async function storeCommits(
73
82
  * Store packages in database
74
83
  */
75
84
  async function storePackage(pkg: PackageInfo): Promise<void> {
76
- try {
77
-
78
- // Create or update package
79
- await prisma.package.upsert({
80
- where: { name: pkg.name },
81
- update: {
82
- version: pkg.version,
83
- type: pkg.type,
84
- path: pkg.path,
85
- description: pkg.description,
86
- license: pkg.license,
87
- repository: JSON.stringify(pkg.repository),
88
- scripts: JSON.stringify(pkg.scripts),
89
- lastUpdated: new Date(),
90
- },
91
- create: {
92
- // Timestamps
93
- createdAt: new Date(),
94
- lastUpdated: new Date(),
95
-
96
- // Key Metrics and Relationships
97
- dependencies: JSON.stringify(pkg.dependencies), // The total number of direct dependencies (12 in your example)
98
- // Manual Serialization Required: Stores a JSON array string of maintainers, e.g., '["team-frontend"]'
99
- maintainers: pkg.maintainers.join(','),
100
- // Manual Serialization Required: Stores a JSON array string of tags, e.g., '["core", "ui"]'
101
-
102
- // Manual Serialization Required: Stores the scripts object as a JSON string
103
- // Example: '{"dev": "vite", "build": "tsc && vite build"}'
104
- scripts: JSON.stringify(pkg.scripts),
105
-
106
- // Dependency Lists (Manual Serialization Required)
107
- // Stores a JSON array string of dependencies.
108
- // dependenciesList: JSON.stringify(pkg.dependenciesList),
109
- devDependencies: JSON.stringify(pkg.devDependencies),
110
- peerDependencies: JSON.stringify(pkg.peerDependencies),
111
- name: pkg.name,
112
- version: pkg.version,
113
- type: pkg.type,
114
- path: pkg.path,
115
- description: pkg.description??'',
116
- license: pkg.license??'',
117
- repository: JSON.stringify(pkg.repository),
118
- status: '',
119
- },
120
- });
121
-
122
- const commits = await getCommits(pkg.path ?? '');
123
- if (commits.length) {
124
- await storeCommits(pkg.name, commits);
125
- }
126
- const dependenciesInfo = getPackageDependenciesInfo(pkg);
127
- if (dependenciesInfo.length) {
128
- await storeDependencies(pkg.name, dependenciesInfo);
129
- }
85
+ try {
86
+ // Create or update package
87
+ await prisma.package.upsert({
88
+ where: { name: pkg.name },
89
+ update: {
90
+ version: pkg.version,
91
+ type: pkg.type,
92
+ path: pkg.path,
93
+ description: pkg.description,
94
+ license: pkg.license,
95
+ repository: JSON.stringify(pkg.repository),
96
+ scripts: JSON.stringify(pkg.scripts),
97
+ lastUpdated: new Date(),
98
+ },
99
+ create: {
100
+ // Timestamps
101
+ createdAt: new Date(),
102
+ lastUpdated: new Date(),
103
+
104
+ // Key Metrics and Relationships
105
+ dependencies: JSON.stringify(pkg.dependencies), // The total number of direct dependencies (12 in your example)
106
+ // Manual Serialization Required: Stores a JSON array string of maintainers, e.g., '["team-frontend"]'
107
+ maintainers: pkg.maintainers.join(','),
108
+ // Manual Serialization Required: Stores a JSON array string of tags, e.g., '["core", "ui"]'
109
+
110
+ // Manual Serialization Required: Stores the scripts object as a JSON string
111
+ // Example: '{"dev": "vite", "build": "tsc && vite build"}'
112
+ scripts: JSON.stringify(pkg.scripts),
113
+
114
+ // Dependency Lists (Manual Serialization Required)
115
+ // Stores a JSON array string of dependencies.
116
+ // dependenciesList: JSON.stringify(pkg.dependenciesList),
117
+ devDependencies: JSON.stringify(pkg.devDependencies),
118
+ peerDependencies: JSON.stringify(pkg.peerDependencies),
119
+ name: pkg.name,
120
+ version: pkg.version,
121
+ type: pkg.type,
122
+ path: pkg.path,
123
+ description: pkg.description ?? '',
124
+ license: pkg.license ?? '',
125
+ repository: JSON.stringify(pkg.repository),
126
+ status: '',
127
+ },
128
+ });
130
129
 
131
- } catch (error) {
132
- console.warn(
133
- `⚠️ Failed to store report for ${pkg.name}:`,
134
- error
135
- );
130
+ const commits = await getCommits(pkg.path ?? '');
131
+ if (commits.length) {
132
+ await storeCommits(pkg.name, commits);
133
+ }
134
+ const dependenciesInfo = getPackageDependenciesInfo(pkg);
135
+ if (dependenciesInfo.length) {
136
+ await storeDependencies(pkg.name, dependenciesInfo);
136
137
  }
138
+ } catch (error) {
139
+ console.warn(`⚠️ Failed to store report for ${pkg.name}:`, error);
137
140
  }
141
+ }
138
142
 
139
143
  /**
140
144
  * Get package dependencies
@@ -207,9 +211,10 @@ async function storeDependencies(
207
211
  });
208
212
  console.log('💾 Dependencies stored in database:' + dep.name);
209
213
  } catch (e) {
214
+ const err = e as any;
210
215
  if (
211
- e instanceof Prisma.PrismaClientKnownRequestError &&
212
- e.code === 'P2002'
216
+ err instanceof Prisma.PrismaClientKnownRequestError &&
217
+ err.code === 'P2002'
213
218
  ) {
214
219
  // Handle unique constraint violation (e.g., depedency already exists)
215
220
  console.warn(
@@ -217,7 +222,7 @@ async function storeDependencies(
217
222
  );
218
223
  } else {
219
224
  // Handle any other unexpected errors
220
- console.error(`Failed to store dependency: ${dep.name}`, e);
225
+ console.error(`Failed to store dependency: ${dep.name}`, err);
221
226
  }
222
227
  }
223
228
  }
@@ -228,5 +233,5 @@ export {
228
233
  storePackage,
229
234
  storeCommits,
230
235
  getPackageDependenciesInfo,
231
- storeDependencies
232
- }
236
+ storeDependencies,
237
+ };
package/tsconfig.json CHANGED
@@ -10,7 +10,6 @@
10
10
  "outDir": "./dist",
11
11
  "rootDir": "./src",
12
12
  "allowJs": true
13
-
14
13
  },
15
14
  "include": ["src/**/*"]
16
15
  }