Praeco: Fix Invalid TableName In @smrt() Decorators

by SLV Team 52 views
Praeco: Fix Invalid tableName in @smrt() Decorators

Hey guys! Let's dive into a Praeco issue where we need to remove an invalid tableName from the @smrt() decorators. This was causing some hiccups in our system, and we're going to break down the problem, impact, root cause, solution, and testing steps. Let's make sure everything is running smoothly!

Problem

In Praeco's SMRT classes, the tableName option was being used in the @smrt() decorator. However, in SMRT version 0.5.1, this tableName option isn't valid. This invalid option led to the AST scanner failing to parse these decorators, resulting in an incomplete test manifest. Think of it like trying to fit a square peg in a round hole – it just doesn't work, and in our case, it was preventing the scanner from doing its job correctly.

The Nitty-Gritty Details

The @smrt() decorator is crucial for defining how our Smart Objects interact within the system. It specifies things like API endpoints and command-line interface configurations. However, the inclusion of tableName, an obsolete option, threw a wrench in the gears. The AST (Abstract Syntax Tree) scanner, which helps us analyze our code, choked on this invalid parameter, leading to only a partial manifest being generated.

Impact

The impact of this issue was pretty significant. Out of the 12+ SMRT classes we have, only 5 were being correctly detected by the scanner. Here’s the breakdown:

  • Detected: council, meeting, meetings, councilmember, proof (These guys were found and included in the manifest.)
  • Missing: agenda, document, member, praeco, proofs, report, source (These classes were left out in the cold, causing issues down the line.)

This partial detection led to tests failing with errors like "Cannot find manifest for class 'PraecoSource'" and similar messages. Basically, if the scanner didn't recognize a class, the tests couldn't run properly, which is a big no-no in software development. We need all our tests to pass to ensure our code is solid!

Root Cause

Okay, so why did this happen? The root cause is that tableName simply isn't a valid option for the @smrt() decorator in SMRT 0.5.1. It's like trying to use an outdated instruction manual for a new piece of equipment – it just doesn't match up.

Here’s what the problematic code looked like:

// ❌ Invalid - causes scanner failure
@smrt({
  tableName: 'praeco_sources',  // Not recognized!
  api: { include: ['list', 'get'] },
})

The TypeScript compiler also flagged this with an error:

error TS2353: Object literal may only specify known properties, and '"tableName"' does not exist in type {...}

This error message is TypeScript's way of saying, "Hey, I don't recognize this tableName thing!" So, it was clear we needed to remove it.

Files Affected

This issue affected several files within the Praeco project. Specifically, these files needed our attention:

  1. src/agenda.ts
  2. src/council.ts
  3. src/document.ts
  4. src/meeting.ts
  5. src/member.ts
  6. src/praeco.ts
  7. src/proof.ts
  8. src/report.ts
  9. src/source.ts

Each of these files contained the problematic tableName in the @smrt() decorator, and we needed to clean them up.

Solution

The solution here is straightforward: remove the tableName option from all @smrt() decorators. Yep, that's it! By taking out this invalid parameter, we allow the AST scanner to correctly parse the decorators and generate a complete manifest.

Here’s the corrected code:

// ✅ Correct
@smrt({
  api: { include: ['list', 'get', 'create', 'update'] },
  mcp: { include: ['list', 'get'] },
  cli: true
})
export class PraecoSource extends SmrtObject {
  // ... fields
}

The cool part is that the table name is automatically derived from the class name (in lowercase plural form). So, for example, PraecoSource becomes praeco_sources. This means we don't need to specify it manually, which simplifies our code and reduces the chance of errors.

Testing

Testing is super important to make sure our fix actually works and doesn't introduce any new issues. Here’s how we tested this solution:

  1. Run npm run build: This command builds our project. After removing tableName, running this command should find all 12 classes. This is our first sign that things are on the right track.
  2. Check dist/manifest.json: This file contains the manifest generated by the scanner. We need to make sure it includes all our objects. If all 12 classes are listed here, that’s a great indication that our fix is working.
  3. Run npm test: This command runs our test suite. The tests should pass without any "Cannot find manifest" errors. If the tests pass, we know that the system can find and use all the SMRT classes correctly.

By following these steps, we can confidently say that our fix has resolved the issue and hasn't broken anything else.

Related

This issue is related to SMRT #159, which fixed manifest loading for published packages in v0.5.1. It's also important to note that this is a Praeco-specific issue and not a framework-level bug. This means the problem was isolated to our Praeco codebase and not a widespread issue in the underlying SMRT framework.

So, there you have it! We tackled an issue with Praeco where an invalid tableName in the @smrt() decorator was causing problems with our AST scanner and test manifests. By removing the tableName option and running thorough tests, we've ensured that our system is back on track. Remember, keeping our code clean and up-to-date is key to building robust and reliable applications. Keep coding, and stay awesome!