Replies: 1 comment 13 replies
-
Not sure if I understand you, but in my proposed implementation
We can have these, no problem, but if user passes a function (returned from discoverEntities) to type Options =
| {
entities: Array<string | EntityType> // I don't remember the exact type name for entities
entitiesTs: Array<string | EntityType>
}
| {
entities: (config: Configuration) => AsyncGenerator<{path: string, exports: Record<string, unknown>}>
}Now TypeScript should allow only use of the Here are links:
The problem with it though is that I don't have a sync version, and those loaders moving away from CJS support, so some of them don't have API for
I have proposed this originally because I'm concerned about how having Node.js builtin modules in the core would affect compatibility with bundlers. Not sure if having things that depend on those in the same module (e.g exposed from Also, I don't think we need interface DiscoverEntitiesGeneratorEntry {
path: string // Should be useful for logs and ts-morph :)
exports: Record<string, unknown> // The module will be imported and the exports returned as this object
}
type DicoverEntitiesGenerator = (config: Configuration) => AsyncGenerator<DiscoverEntitiesGeneratorEntry>
declare function discoverEntities(patterns: string | string[]): DicoverEntitiesGeneratorBtw, I was thinking to rework declare function defineBetterSqliteConfig<TConfig extends BetterSqliteOptions>(config: TConfig): TConfigThis way we should have an actual config shape as return type |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
V6 added
MikroORM.initSyncmethod, with a few limitations:MIKRO_ORM_TYPEenv varI'd like to redesign this. Instead of
MikroORM.initSync, we could just use the constructor:new MikroORM, which would do exactly the same. Now the question is what to do with the current asyncinitfactory.connectoption feels unnecessary, we can remove that without any harm, connection gets established lazily when needed (and people can still useorm.connect()if they want to)ensureIndexescould be removed in favor of an explicitorm.schema.ensureIndexescallMIKRO_ORM_TYPEenv var is something I wanted to remove anyway, people should use driver exports, which will provide the type implicitly, or have a minimal ORM config with the driver optioncreateRequireinstead of dynamicimport, this could work withnew MikroORMtoo, with a possible opt-out for production buildsShould we even keep this
initmethod, or should we instead provide some helper for this?People using ESM can use the top-level await even in the ORM config:
But we'd most likely need a way to do this for CJS projects too. Maybe a dedicated CJS helper that would use
requireinternally could do the job.We'd have to keep the dual
entitiesandentitiesTssupport inside this newdiscoverEntitieshelper somehow, I guess. But then we couldn't use thepreferTsORM config option (same forbaseDir), since this would live outside of the config (but we could still rely on the option frompackage.jsonhere, or have a second parameter in that method). Or maybe we could just keep a single version, and detect the TS support, based on it, we would change the extension in the pattern (but that sounds way too magical). Or have a wrapper around the whole config, e.g.defineAsyncConfig, which would support it internally. Ideas welcome.This new
discoverEntitiescould even live in a different package, but given the switch totinyglobby, which is indeed a very small dependency, it feels unnecessary.Now the real question: isn't the async
initmethod better than that? Either way, the sync variant will be used throughout the docs in v7, and folder-based discovery will have its own section in docs for those who want it. We need to show the simple way to use the ORM, so we don't scare people who want to try it, and the folder-based discovery can often impose a lot of unexpected issues down the path (e.g. bundling).I have a draft PR for removing
initSyncin favor of the constructor ready here: #6974It also changes some things around the async
initmethod too, but still keeps the folder-based discovery available as it was.Beta Was this translation helpful? Give feedback.
All reactions