technical-debt-radar 1.2.1 → 1.2.2

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.
Files changed (2) hide show
  1. package/dist/index.js +26 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11265,7 +11265,7 @@ var require_volume_estimator = __commonJS({
11265
11265
  if (entryName !== "node_modules" && entryName !== "dist" && entryName !== ".git") {
11266
11266
  await scan(fullPath);
11267
11267
  }
11268
- } else if (entryName.endsWith(".model.ts") || entryName.endsWith(".model.js")) {
11268
+ } else if (entryName.endsWith(".model.ts") || entryName.endsWith(".model.js") || entryName.endsWith(".schema.ts") || entryName.endsWith(".schema.js")) {
11269
11269
  results.push(fullPath);
11270
11270
  }
11271
11271
  }
@@ -11313,10 +11313,13 @@ var require_volume_estimator = __commonJS({
11313
11313
  } catch {
11314
11314
  continue;
11315
11315
  }
11316
- if (!/mongoose\.model|new\s+Schema|new\s+mongoose\.Schema|\bmodel\s*\(\s*['"]/.test(content))
11316
+ if (!/mongoose\.model|new\s+Schema|new\s+mongoose\.Schema|\bmodel\s*\(\s*['"]|@Schema\s*\(/.test(content))
11317
11317
  continue;
11318
11318
  const models = parseMongooseModels(content);
11319
- for (const model of models) {
11319
+ const basename2 = path9.basename(filePath).replace(/\.(schema|model)\.(ts|js)$/, "");
11320
+ const filteredModels = models.length > 1 ? models.filter((m) => m.name.toLowerCase() === basename2.toLowerCase()) : models;
11321
+ const finalModels = filteredModels.length > 0 ? filteredModels : models;
11322
+ for (const model of finalModels) {
11320
11323
  let size = estimateModelSize(model.collectionName);
11321
11324
  if (model.hasCreatedAtIndex) {
11322
11325
  if (size === "S" || size === "M") {
@@ -11332,10 +11335,14 @@ var require_volume_estimator = __commonJS({
11332
11335
  }
11333
11336
  function parseMongooseModels(content) {
11334
11337
  const models = [];
11338
+ const seen = /* @__PURE__ */ new Set();
11335
11339
  const modelRegex = /(?:mongoose\.)?model\s*\(\s*['"](\w+)['"]/g;
11336
11340
  let match;
11337
11341
  while ((match = modelRegex.exec(content)) !== null) {
11338
11342
  const name = match[1];
11343
+ if (seen.has(name))
11344
+ continue;
11345
+ seen.add(name);
11339
11346
  const collectionName = defaultTableName(name);
11340
11347
  let hasCreatedAtIndex = false;
11341
11348
  if (/\.index\s*\(\s*\{[^}]*(createdAt|timestamp|created_at)[^}]*\}/i.test(content)) {
@@ -11346,6 +11353,22 @@ var require_volume_estimator = __commonJS({
11346
11353
  }
11347
11354
  models.push({ name, collectionName, hasCreatedAtIndex });
11348
11355
  }
11356
+ const schemaRegex = /@Schema\s*\([^)]*\)\s*(?:export\s+)?class\s+(\w+)/g;
11357
+ while ((match = schemaRegex.exec(content)) !== null) {
11358
+ const className = match[1];
11359
+ const name = className;
11360
+ if (seen.has(name))
11361
+ continue;
11362
+ seen.add(name);
11363
+ const collectionName = defaultTableName(name);
11364
+ let hasCreatedAtIndex = false;
11365
+ if (/@Schema\s*\(\s*\{[^}]*timestamps\s*:\s*true/.test(content)) {
11366
+ }
11367
+ if (/\.index\s*\(\s*\{[^}]*(createdAt|timestamp|created_at)[^}]*\}/i.test(content)) {
11368
+ hasCreatedAtIndex = true;
11369
+ }
11370
+ models.push({ name, collectionName, hasCreatedAtIndex });
11371
+ }
11349
11372
  return models;
11350
11373
  }
11351
11374
  function estimateModelSize(modelName) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "technical-debt-radar",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Stop Node.js production crashes before merge. 47 detection patterns across 5 categories.",
5
5
  "bin": {
6
6
  "radar": "dist/index.js",