JohannesWill opened a new pull request, #82:
URL: https://github.com/apache/casbin-typeorm-adapter/pull/82

   ## Problem
   
   Since `1.10.0`, importing `typeorm-adapter` throws `Cannot find module 
'mongodb'` (`MODULE_NOT_FOUND`) for any consumer that does not have `mongodb` 
installed — even when using a different driver (PostgreSQL, SQLite, …).
   
   `src/index.ts` re-exports `casbinMongoRule`, and `src/casbinMongoRule.ts` 
imports `mongodb` at the top level. `mongodb` is only an **optional** peer 
dependency of `typeorm` and merely a devDependency here, so it is absent in 
most production installs.
   
   ## Fix
   
   `ObjectId` is only used as a **type** (`public id!: ObjectId;`). Switching 
to a type-only import removes the runtime `require('mongodb')`: with 
`emitDecoratorMetadata`, TypeScript no longer emits a reference to 
`mongodb.ObjectId`.
   
   ```diff
   -import { ObjectId } from 'mongodb';
   +import type { ObjectId } from 'mongodb';
   ```
   
   ## Verification
   
   Compiled output no longer contains any reference to `mongodb`:
   
   ```
   __decorate([
       ObjectIdColumn(),
       __metadata("design:type", Function)
   ], CasbinMongoRule.prototype, "id", void 0);
   ```
   
   `grep -c mongodb lib/casbinMongoRule.js` → `0`. Build (`tsc`) and lint pass.
   
   MongoDB users are unaffected — TypeORM loads the mongodb driver lazily via 
its own `PlatformTools` when a Mongo `DataSource` is actually initialized.
   
   Closes #81
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to