fix: mikro-orm 7.1.x scaffold hardening — AnyMikroORM, readonly options, age-gate healing - #246
Conversation
… options, age-gate exclusion healing Addresses the four reported scaffold bugs on mikro-orm 7.1.x. Bugs 1-3 no longer reproduce on current published packages (verified: fresh scaffold with billing-stripe + iam-base typechecks clean), but the report's requested hardening is real: - @forklaunch/core exports AnyMikroORM (persistence) so user-authored helpers have a readonly-accepting ORM type instead of hand-rolling MikroORM<any, any, any> (published as [email protected]) - @forklaunch/testing: AnyMikroOrmOptions accepts defineConfig's readonly entities in BlueprintTestHarness.getConfig and MikroOrmTestConfig; AnyMikroORM/AnyMikroOrmOptions exported at the package level (published as [email protected]) - service/worker test-utils templates type orm as AnyMikroORM from @forklaunch/testing instead of bare MikroORM - pnpm-workspace rewrites normalize versioned @forklaunch/*@x.y.z entries in minimumReleaseAgeExclude to bare package names, healing the stale-pin ERR_PNPM_MINIMUM_RELEASE_AGE_VIOLATION loop after upgrades (first-party packages are always exempt from the age gate); covered by unit tests and verified live on a scaffold - CLI scaffold floors synced (core ~1.5.13, testing ~1.2.25) Co-Authored-By: Claude Fable 5 <[email protected]>
📝 WalkthroughWalkthroughThe PR adds generalized MikroORM types, updates database-enabled templates, normalizes ChangesForklaunch release and typing updates
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cli/src/core/pnpm_workspace.rs`:
- Around line 209-210: Update the error context in the workspace serialization
return path to use the removal-specific error message constant instead of
ERROR_FAILED_TO_ADD_PROJECT_METADATA_TO_PNPM_WORKSPACE, so failures during
project removal identify the correct operation.
In `@cli/src/templates/project/worker/__test__/test-utils.ts`:
- Line 10: Close the is_database_enabled template block in the worker test
utility immediately after the conditional import, matching the closure pattern
used by the service template so rendering remains reliable.
In `@framework/testing/src/database.ts`:
- Around line 20-22: Update AnyMikroOrmOptions to omit and explicitly override
both entities and entitiesTs, allowing readonly entity configurations for each
while preserving their element types. Add a type-level test covering readonly
entities and readonly entitiesTs.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 51b957af-3670-4ca6-9ee7-47f6f7fde636
⛔ Files ignored due to path filters (1)
blueprint/pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (30)
blueprint/billing-base/package.jsonblueprint/billing-stripe/package.jsonblueprint/client-sdk/package.jsonblueprint/core/package.jsonblueprint/ecommerce-stripe/package.jsonblueprint/iam-base/package.jsonblueprint/iam-better-auth/package.jsonblueprint/implementations/billing/base/package.jsonblueprint/implementations/billing/stripe/package.jsonblueprint/implementations/ecommerce/base/package.jsonblueprint/implementations/iam/base/package.jsonblueprint/implementations/worker/bullmq/package.jsonblueprint/implementations/worker/database/package.jsonblueprint/implementations/worker/kafka/package.jsonblueprint/implementations/worker/redis/package.jsonblueprint/monitoring/package.jsonblueprint/package.jsonblueprint/pnpm-workspace.yamlblueprint/sample-worker/package.jsoncli/src/core/package_json/package_json_constants.rscli/src/core/pnpm_workspace.rscli/src/templates/project/service/__test__/test-utils.tscli/src/templates/project/worker/__test__/test-utils.tsframework/core/package.jsonframework/core/src/persistence/index.tsframework/core/src/persistence/mikroOrm.types.tsframework/testing/package.jsonframework/testing/src/database.tsframework/testing/src/harness.tsframework/testing/src/index.ts
| Ok(to_string(&pnpm_workspace) | ||
| .with_context(|| ERROR_FAILED_TO_ADD_PROJECT_METADATA_TO_PNPM_WORKSPACE)?) |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Use the removal error context.
If workspace serialization fails during project removal, this function reports that project metadata could not be added. Use the removal-specific error context so the failure message identifies the operation correctly.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@cli/src/core/pnpm_workspace.rs` around lines 209 - 210, Update the error
context in the workspace serialization return path to use the removal-specific
error message constant instead of
ERROR_FAILED_TO_ADD_PROJECT_METADATA_TO_PNPM_WORKSPACE, so failures during
project removal identify the correct operation.
| TestSetupResult | ||
| } from '@forklaunch/testing'; | ||
| {{#is_database_enabled}}import { EntityManager, MikroORM } from '@mikro-orm/core'; | ||
| {{#is_database_enabled}}import { EntityManager } from '@mikro-orm/core'; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
Close the is_database_enabled template block.
Line 10 opens a template conditional and never closes it. The worker test utility cannot be rendered reliably. Add the closing tag, as the service template does.
Proposed fix
-{{`#is_database_enabled`}}import { EntityManager } from '`@mikro-orm/core`';
+{{`#is_database_enabled`}}import { EntityManager } from '`@mikro-orm/core`';{{/is_database_enabled}}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| {{#is_database_enabled}}import { EntityManager } from '@mikro-orm/core'; | |
| {{`#is_database_enabled`}}import { EntityManager } from '`@mikro-orm/core`';{{/is_database_enabled}} |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@cli/src/templates/project/worker/__test__/test-utils.ts` at line 10, Close
the is_database_enabled template block in the worker test utility immediately
after the conditional import, matching the closure pattern used by the service
template so rendering remains reliable.
| export type AnyMikroOrmOptions = Partial<Omit<Options, 'entities'>> & { | ||
| entities?: readonly NonNullable<Options['entities']>[number][]; | ||
| }; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
rg -n -C 4 '\bentitiesTs\b' framework cli blueprint --glob '*.ts' --glob '*.tsx'Repository: forklaunch/forklaunch
Length of output: 159
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
file="$(fd -t f '^database\.ts$' . | grep -F 'framework/testing/src/database.ts' | head -n 1)"
printf '%s\n' "FILE=$file"
wc -l "$file"
ast-grep outline "$file"
sed -n '1,180p' "$file"
printf '%s\n' '--- usages ---'
rg -n -C 5 'AnyMikroOrmOptions|MikroOrmTestConfig|setupTestORM|entitiesTs|defineConfig' framework cli blueprint --glob '*.ts' --glob '*.tsx' || true
printf '%s\n' '--- MikroORM version/source references ---'
rg -n -C 3 '"`@mikro-orm/core`"|mikro-orm' --glob 'package.json' --glob 'pnpm-lock.yaml' --glob 'yarn.lock' --glob 'package-lock.json' .Repository: forklaunch/forklaunch
Length of output: 50377
🌐 Web query:
MikroORM v7.1.11 Configuration.ts Options entitiesTs Entities generic readonly source
💡 Result:
In MikroORM v7.1.11, the entitiesTs option is a configuration property used during folder-based entity discovery to specify the paths to TypeScript source files [1][2]. Key details regarding this option include: Purpose: When your application runs in a TypeScript environment (such as using tsx, swc, or during testing), MikroORM needs to discover and load your entities from.ts files rather than the compiled.js files [1][3]. The entitiesTs option informs the ORM where to find these source files [2][4]. Usage: You should provide this option whenever you use glob patterns or folder paths for entity discovery in your configuration [1][3]. For example, you would typically set entities to point to your build output (e.g.,./dist//.entity.js) and entitiesTs to point to your source code (e.g.,./src//.entity.ts) [3][5]. Behavior: MikroORM automatically detects when the application is running in TypeScript mode and will prioritize the paths provided in entitiesTs [3][6]. If you are using direct class references (e.g., entities: [User, Post]), this option is not required, as the class references already point to the correct files [7]. Configuration Example: import { defineConfig } from '@mikro-orm/sqlite'; export default defineConfig({ entities: ['./dist//.entity.js'], entitiesTs: ['./src//.entity.ts'], }); It is important not to mix compiled JS paths and TS source paths in the same array; always separate them using the appropriate configuration keys [3][5]. The entitiesTs property accepts an array of strings (paths or globs) or entity class references, matching the type signature of the main entities option [2][4].
Citations:
- 1: https://mikro-orm.io/docs/configuration
- 2: https://mikro-orm.io/api/core/interface/Options
- 3: https://mikro-orm.io/docs/folder-based-discovery
- 4: https://github.com/mikro-orm/mikro-orm/blob/master/packages/core/src/utils/Configuration.ts
- 5: https://mikro-orm.io/docs/folder-based-discovery.md
- 6: https://mikro-orm.io/docs/metadata-providers
- 7: should `useTsNode` even be set in the config? mikro-orm/mikro-orm#1340
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
url='https://raw.githubusercontent.com/mikro-orm/mikro-orm/v7.1.11/packages/core/src/utils/Configuration.ts'
tmp="$(mktemp)"
trap 'rm -f "$tmp"' EXIT
curl -fsSL "$url" -o "$tmp"
printf '%s\n' '--- Options and entitiesTs declarations ---'
rg -n -C 12 'interface Options|type Options|entitiesTs|entities\??:' "$tmp"
printf '%s\n' '--- Entities generic declarations ---'
rg -n -C 8 'Entities extends|type Entities|export type Entity|EntityClass' "$tmp" | head -n 160Repository: forklaunch/forklaunch
Length of output: 7328
Widen entitiesTs for readonly configurations.
Options uses the same Entities generic for entities and entitiesTs. Since AnyMikroOrmOptions overrides only entities, entitiesTs retains the mutable default array type. Omit and override entitiesTs too, then add a type-level test for readonly entities and entitiesTs.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@framework/testing/src/database.ts` around lines 20 - 22, Update
AnyMikroOrmOptions to omit and explicitly override both entities and entitiesTs,
allowing readonly entity configurations for each while preserving their element
types. Add a type-level test covering readonly entities and readonly entitiesTs.
Summary
Response to the four reported scaffold bugs on mikro-orm 7.1.x (readonly entities generics).
Audit result first: bugs 1–3 as filed do not reproduce on current main + current published packages — a fresh
init application -m billing-stripe -m iam-basetypechecks with zero errors, because the entity/constraint alignment (nullable drift, DTO/schema optionality) and theAnyMikroORMrelaxations shipped across framework 1.5.11–1.5.12 / implementation 1.0.30/1.1.30 / CLI 1.4.4. The reporter was on the pre-alignment versions. What remains valid from the report is the requested hardening, all implemented here:@forklaunch/[email protected]exportsAnyMikroORMfrom/persistence— the documented type for ORM-valued params/fields that must acceptMikroORM.init()instances@forklaunch/[email protected]addsAnyMikroOrmOptions(acceptsdefineConfig's readonlyentities) forBlueprintTestHarness.getConfigandMikroOrmTestConfig, and exportsAnyMikroORM/AnyMikroOrmOptionsat package level; service/workertest-utilstemplates now typeormasAnyMikroORMforklaunch upgrade/minimumReleaseAgeExcludegeneration is not in this repo (platform-side), but every CLI workspace-yaml rewrite now heals stale entries: versioned@forklaunch/*@x.y.zexclusions normalize to bare package names (first-party packages are always exempt from the age gate), deduped, third-party entries untouched. Unit-tested and verified live: injected@forklaunch/[email protected]pins normalized on the nextinit serviceVerification
tsgo --noEmitclean in core and billing including__test__init service,[email protected]preservedcargo test: 335 passed (2 new); core 371 tests pass; scaffold floors synced viacheck_blueprint_deps --fix🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Maintenance