Fix schema lookups and repository resolution to be resilient to mangling#18
Open
kac-axelor wants to merge 2 commits intoaxelor:devfrom
Open
Fix schema lookups and repository resolution to be resilient to mangling#18kac-axelor wants to merge 2 commits intoaxelor:devfrom
kac-axelor wants to merge 2 commits intoaxelor:devfrom
Conversation
c056146 to
8fd5440
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JavaScript bundlers (webpack, turbopack) mangle class and function names in production builds to reduce bundle size:
This is harmless for most code, but breaks any code that reads a class name at runtime and compares it against a string baked in at compile time. Goovee ORM has several such patterns.
TypeORM's
EntityMetadataexposes two relevant properties:metadata.name/metadata.targetName— the class constructor name ((EntityClass as Function).name). Gets mangled.metadata.tableNameWithoutPrefix— the table name after applying the naming strategy, before any globalentityPrefix. Never mangled and stable for schema lookups regardless of DataSource prefix configuration.Similarly,
RelationMetadataexposes.name(the class constructor name, mangled) and.target(the class constructor reference, unaffected by mangling).Changes
1.
src/client/parser/context.ts—isStringFieldschema lookupisStringFieldis called during query parsing to decide whether to wrap a field inlower()/unaccent()for case-insensitive and accent-insensitive search. It looks up the entity's schema definition to check if a field is of typeString.The lookup was using
metadata.targetName(mangled) to find the matching entry inschemaDefs(which stores original names like"AOSPartner"). This silently failed in production, causingisStringFieldto always returnfalseand disabling normalization entirely.The fix resolves the schema entry using the active TypeORM naming strategy — the same logic TypeORM uses to derive the table name from
@Entity()decorator arguments — so the lookup is both mangling-resilient and correct regardless of which naming strategy is configured.2.
src/client/repository/repository.ts—getProtectedFieldsschema lookupgetProtectedFieldsenforces that fields markedinternal(never writable) orreadonly(not updatable after creation) are rejected on create and update operations. It also looks upschemaDefsby entity name.The lookup used
meta.name(mangled), so the entity was never found.getProtectedFieldswould return an empty set, silently bypassing all protected field checks.The fix passes the
repodirectly sogetProtectedFieldscan use the naming strategy from the live connection, matching entries the same way TypeORM resolves them.3.
src/client/repository/repository.tsandsrc/client/repository/query/query.ts— string-basedgetRepositorycallsThree call sites were passing a string (the class constructor name) to TypeORM's
getRepository. Under mangling, this works incidentally —rMeta.nameand the internally registered metadata name are both the same mangled value — but it is fragile. If two entity classes are ever assigned the same mangled name (possible across async chunks),getRepository(string)silently returns the wrong repository.The fix uses the class constructor reference instead, consistent with the already-correct pattern in
join-handler.ts(getRepository(relation.type)).Notes
The
portalproject also adds--no-manglingto itsnext buildcommand as a short-term mitigation while these fixes are released. That flag can be removed once this ORM version is consumed.