@mikro-orm/mongodb 7.0.5 → 7.0.6-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,4 @@
1
- import {
2
- EntityManager,
3
- type EntityName,
4
- type EntityRepository,
5
- type GetRepository,
6
- type TransactionOptions,
7
- type StreamOptions,
8
- type Loaded,
9
- } from '@mikro-orm/core';
1
+ import { EntityManager, type EntityName, type EntityRepository, type GetRepository, type TransactionOptions, type StreamOptions, type Loaded } from '@mikro-orm/core';
10
2
  import type { Collection, Document, TransactionOptions as MongoTransactionOptions } from 'mongodb';
11
3
  import type { MongoDriver } from './MongoDriver.js';
12
4
  import type { MongoEntityRepository } from './MongoEntityRepository.js';
@@ -14,39 +6,29 @@ import type { MongoEntityRepository } from './MongoEntityRepository.js';
14
6
  * @inheritDoc
15
7
  */
16
8
  export declare class MongoEntityManager<Driver extends MongoDriver = MongoDriver> extends EntityManager<Driver> {
17
- /**
18
- * Shortcut to driver's aggregate method. Available in MongoDriver only.
19
- */
20
- aggregate(entityName: EntityName, pipeline: any[]): Promise<any[]>;
21
- /**
22
- * Shortcut to driver's aggregate method. Returns a stream. Available in MongoDriver only.
23
- */
24
- streamAggregate<T extends object>(entityName: EntityName, pipeline: any[]): AsyncIterableIterator<T>;
25
- /**
26
- * @inheritDoc
27
- */
28
- stream<
29
- Entity extends object,
30
- Hint extends string = never,
31
- Fields extends string = never,
32
- Excludes extends string = never,
33
- >(
34
- entityName: EntityName<Entity>,
35
- options?: StreamOptions<NoInfer<Entity>, Hint, Fields, Excludes>,
36
- ): AsyncIterableIterator<Loaded<Entity, Hint, Fields, Excludes>>;
37
- getCollection<T extends Document>(entityOrCollectionName: EntityName<T> | string): Collection<T>;
38
- /**
39
- * @inheritDoc
40
- */
41
- getRepository<T extends object, U extends EntityRepository<T> = MongoEntityRepository<T>>(
42
- entityName: EntityName<T>,
43
- ): GetRepository<T, U>;
44
- /**
45
- * @inheritDoc
46
- */
47
- begin(options?: Omit<TransactionOptions, 'ignoreNestedTransactions'> & MongoTransactionOptions): Promise<void>;
48
- /**
49
- * @inheritDoc
50
- */
51
- transactional<T>(cb: (em: this) => Promise<T>, options?: TransactionOptions & MongoTransactionOptions): Promise<T>;
9
+ /**
10
+ * Shortcut to driver's aggregate method. Available in MongoDriver only.
11
+ */
12
+ aggregate(entityName: EntityName, pipeline: any[]): Promise<any[]>;
13
+ /**
14
+ * Shortcut to driver's aggregate method. Returns a stream. Available in MongoDriver only.
15
+ */
16
+ streamAggregate<T extends object>(entityName: EntityName, pipeline: any[]): AsyncIterableIterator<T>;
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ stream<Entity extends object, Hint extends string = never, Fields extends string = never, Excludes extends string = never>(entityName: EntityName<Entity>, options?: StreamOptions<NoInfer<Entity>, Hint, Fields, Excludes>): AsyncIterableIterator<Loaded<Entity, Hint, Fields, Excludes>>;
21
+ getCollection<T extends Document>(entityOrCollectionName: EntityName<T> | string): Collection<T>;
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ getRepository<T extends object, U extends EntityRepository<T> = MongoEntityRepository<T>>(entityName: EntityName<T>): GetRepository<T, U>;
26
+ /**
27
+ * @inheritDoc
28
+ */
29
+ begin(options?: Omit<TransactionOptions, 'ignoreNestedTransactions'> & MongoTransactionOptions): Promise<void>;
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ transactional<T>(cb: (em: this) => Promise<T>, options?: TransactionOptions & MongoTransactionOptions): Promise<T>;
52
34
  }
@@ -1,48 +1,48 @@
1
- import { EntityManager, Utils } from '@mikro-orm/core';
1
+ import { EntityManager, Utils, } from '@mikro-orm/core';
2
2
  /**
3
3
  * @inheritDoc
4
4
  */
5
5
  export class MongoEntityManager extends EntityManager {
6
- /**
7
- * Shortcut to driver's aggregate method. Available in MongoDriver only.
8
- */
9
- async aggregate(entityName, pipeline) {
10
- return this.getDriver().aggregate(entityName, pipeline, this.getTransactionContext());
11
- }
12
- /**
13
- * Shortcut to driver's aggregate method. Returns a stream. Available in MongoDriver only.
14
- */
15
- async *streamAggregate(entityName, pipeline) {
16
- yield* this.getDriver().streamAggregate(entityName, pipeline, this.getTransactionContext());
17
- }
18
- /**
19
- * @inheritDoc
20
- */
21
- async *stream(entityName, options = {}) {
22
- if (!Utils.isEmpty(options.populate)) {
23
- throw new Error('Populate option is not supported when streaming results in MongoDB');
6
+ /**
7
+ * Shortcut to driver's aggregate method. Available in MongoDriver only.
8
+ */
9
+ async aggregate(entityName, pipeline) {
10
+ return this.getDriver().aggregate(entityName, pipeline, this.getTransactionContext());
11
+ }
12
+ /**
13
+ * Shortcut to driver's aggregate method. Returns a stream. Available in MongoDriver only.
14
+ */
15
+ async *streamAggregate(entityName, pipeline) {
16
+ yield* this.getDriver().streamAggregate(entityName, pipeline, this.getTransactionContext());
17
+ }
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ async *stream(entityName, options = {}) {
22
+ if (!Utils.isEmpty(options.populate)) {
23
+ throw new Error('Populate option is not supported when streaming results in MongoDB');
24
+ }
25
+ yield* super.stream(entityName, options);
26
+ }
27
+ getCollection(entityOrCollectionName) {
28
+ return this.getConnection().getCollection(entityOrCollectionName);
29
+ }
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ getRepository(entityName) {
34
+ return super.getRepository(entityName);
35
+ }
36
+ /**
37
+ * @inheritDoc
38
+ */
39
+ async begin(options = {}) {
40
+ return super.begin(options);
41
+ }
42
+ /**
43
+ * @inheritDoc
44
+ */
45
+ async transactional(cb, options = {}) {
46
+ return super.transactional(cb, options);
24
47
  }
25
- yield* super.stream(entityName, options);
26
- }
27
- getCollection(entityOrCollectionName) {
28
- return this.getConnection().getCollection(entityOrCollectionName);
29
- }
30
- /**
31
- * @inheritDoc
32
- */
33
- getRepository(entityName) {
34
- return super.getRepository(entityName);
35
- }
36
- /**
37
- * @inheritDoc
38
- */
39
- async begin(options = {}) {
40
- return super.begin(options);
41
- }
42
- /**
43
- * @inheritDoc
44
- */
45
- async transactional(cb, options = {}) {
46
- return super.transactional(cb, options);
47
- }
48
48
  }
@@ -3,15 +3,15 @@ import type { Collection } from 'mongodb';
3
3
  import type { MongoEntityManager } from './MongoEntityManager.js';
4
4
  /** Entity repository with MongoDB-specific methods such as `aggregate()`. */
5
5
  export declare class MongoEntityRepository<T extends object> extends EntityRepository<T> {
6
- protected readonly em: MongoEntityManager;
7
- constructor(em: MongoEntityManager, entityName: EntityName<T>);
8
- /**
9
- * Shortcut to driver's aggregate method. Available in MongoDriver only.
10
- */
11
- aggregate(pipeline: any[]): Promise<any[]>;
12
- getCollection(): Collection<T>;
13
- /**
14
- * @inheritDoc
15
- */
16
- getEntityManager(): MongoEntityManager;
6
+ protected readonly em: MongoEntityManager;
7
+ constructor(em: MongoEntityManager, entityName: EntityName<T>);
8
+ /**
9
+ * Shortcut to driver's aggregate method. Available in MongoDriver only.
10
+ */
11
+ aggregate(pipeline: any[]): Promise<any[]>;
12
+ getCollection(): Collection<T>;
13
+ /**
14
+ * @inheritDoc
15
+ */
16
+ getEntityManager(): MongoEntityManager;
17
17
  }
@@ -1,24 +1,24 @@
1
1
  import { EntityRepository } from '@mikro-orm/core';
2
2
  /** Entity repository with MongoDB-specific methods such as `aggregate()`. */
3
3
  export class MongoEntityRepository extends EntityRepository {
4
- em;
5
- constructor(em, entityName) {
6
- super(em, entityName);
7
- this.em = em;
8
- }
9
- /**
10
- * Shortcut to driver's aggregate method. Available in MongoDriver only.
11
- */
12
- async aggregate(pipeline) {
13
- return this.getEntityManager().aggregate(this.entityName, pipeline);
14
- }
15
- getCollection() {
16
- return this.getEntityManager().getCollection(this.entityName);
17
- }
18
- /**
19
- * @inheritDoc
20
- */
21
- getEntityManager() {
22
- return this.em;
23
- }
4
+ em;
5
+ constructor(em, entityName) {
6
+ super(em, entityName);
7
+ this.em = em;
8
+ }
9
+ /**
10
+ * Shortcut to driver's aggregate method. Available in MongoDriver only.
11
+ */
12
+ async aggregate(pipeline) {
13
+ return this.getEntityManager().aggregate(this.entityName, pipeline);
14
+ }
15
+ getCollection() {
16
+ return this.getEntityManager().getCollection(this.entityName);
17
+ }
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ getEntityManager() {
22
+ return this.em;
23
+ }
24
24
  }
@@ -1,8 +1,8 @@
1
1
  import { ExceptionConverter, type Dictionary, type DriverException } from '@mikro-orm/core';
2
2
  /** Converts MongoDB native errors into typed MikroORM driver exceptions. */
3
3
  export declare class MongoExceptionConverter extends ExceptionConverter {
4
- /**
5
- * @see https://gist.github.com/rluvaton/a97a8da46ab6541a3e5702e83b9d357b
6
- */
7
- convertException(exception: Error & Dictionary): DriverException;
4
+ /**
5
+ * @see https://gist.github.com/rluvaton/a97a8da46ab6541a3e5702e83b9d357b
6
+ */
7
+ convertException(exception: Error & Dictionary): DriverException;
8
8
  }
@@ -1,17 +1,17 @@
1
- import { UniqueConstraintViolationException, ExceptionConverter, TableExistsException } from '@mikro-orm/core';
1
+ import { UniqueConstraintViolationException, ExceptionConverter, TableExistsException, } from '@mikro-orm/core';
2
2
  /** Converts MongoDB native errors into typed MikroORM driver exceptions. */
3
3
  export class MongoExceptionConverter extends ExceptionConverter {
4
- /**
5
- * @see https://gist.github.com/rluvaton/a97a8da46ab6541a3e5702e83b9d357b
6
- */
7
- /* v8 ignore next */
8
- convertException(exception) {
9
- switch (exception.code) {
10
- case 48:
11
- return new TableExistsException(exception);
12
- case 11000:
13
- return new UniqueConstraintViolationException(exception);
4
+ /**
5
+ * @see https://gist.github.com/rluvaton/a97a8da46ab6541a3e5702e83b9d357b
6
+ */
7
+ /* v8 ignore next */
8
+ convertException(exception) {
9
+ switch (exception.code) {
10
+ case 48:
11
+ return new TableExistsException(exception);
12
+ case 11000:
13
+ return new UniqueConstraintViolationException(exception);
14
+ }
15
+ return super.convertException(exception);
14
16
  }
15
- return super.convertException(exception);
16
- }
17
17
  }
@@ -1,63 +1,24 @@
1
- import {
2
- type AnyEntity,
3
- type EntityClass,
4
- type EntitySchema,
5
- MikroORM,
6
- type Options,
7
- type IDatabaseDriver,
8
- type EntityManager,
9
- type EntityManagerType,
10
- type IMigrator,
11
- } from '@mikro-orm/core';
1
+ import { type AnyEntity, type EntityClass, type EntitySchema, MikroORM, type Options, type IDatabaseDriver, type EntityManager, type EntityManagerType, type IMigrator } from '@mikro-orm/core';
12
2
  import { MongoDriver } from './MongoDriver.js';
13
3
  import type { MongoEntityManager } from './MongoEntityManager.js';
14
4
  /** Configuration options for the MongoDB driver. */
15
- export type MongoOptions<
16
- EM extends MongoEntityManager = MongoEntityManager,
17
- Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (
18
- | string
19
- | EntityClass<AnyEntity>
20
- | EntitySchema
21
- )[],
22
- > = Partial<Options<MongoDriver, EM, Entities>>;
5
+ export type MongoOptions<EM extends MongoEntityManager = MongoEntityManager, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> = Partial<Options<MongoDriver, EM, Entities>>;
23
6
  /** Creates a type-safe configuration object for the MongoDB driver. */
24
- export declare function defineMongoConfig<
25
- EM extends MongoEntityManager = MongoEntityManager,
26
- Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (
27
- | string
28
- | EntityClass<AnyEntity>
29
- | EntitySchema
30
- )[],
31
- >(options: MongoOptions<EM, Entities>): MongoOptions<EM, Entities>;
7
+ export declare function defineMongoConfig<EM extends MongoEntityManager = MongoEntityManager, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: MongoOptions<EM, Entities>): MongoOptions<EM, Entities>;
32
8
  /**
33
9
  * @inheritDoc
34
10
  */
35
- export declare class MongoMikroORM<
36
- EM extends MongoEntityManager = MongoEntityManager,
37
- Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (
38
- | string
39
- | EntityClass<AnyEntity>
40
- | EntitySchema
41
- )[],
42
- > extends MikroORM<MongoDriver, EM, Entities> {
43
- /**
44
- * @inheritDoc
45
- */
46
- static init<
47
- D extends IDatabaseDriver = MongoDriver,
48
- EM extends EntityManager<D> = D[typeof EntityManagerType] & EntityManager<D>,
49
- Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (
50
- | string
51
- | EntityClass<AnyEntity>
52
- | EntitySchema
53
- )[],
54
- >(options: Partial<Options<D, EM, Entities>>): Promise<MikroORM<D, EM, Entities>>;
55
- /**
56
- * @inheritDoc
57
- */
58
- constructor(options: Partial<Options<MongoDriver, EM, Entities>>);
59
- /**
60
- * Gets the Migrator.
61
- */
62
- get migrator(): IMigrator;
11
+ export declare class MongoMikroORM<EM extends MongoEntityManager = MongoEntityManager, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> extends MikroORM<MongoDriver, EM, Entities> {
12
+ /**
13
+ * @inheritDoc
14
+ */
15
+ static init<D extends IDatabaseDriver = MongoDriver, EM extends EntityManager<D> = D[typeof EntityManagerType] & EntityManager<D>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: Partial<Options<D, EM, Entities>>): Promise<MikroORM<D, EM, Entities>>;
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ constructor(options: Partial<Options<MongoDriver, EM, Entities>>);
20
+ /**
21
+ * Gets the Migrator.
22
+ */
23
+ get migrator(): IMigrator;
63
24
  }
package/MongoMikroORM.js CHANGED
@@ -1,31 +1,31 @@
1
- import { defineConfig, MikroORM } from '@mikro-orm/core';
1
+ import { defineConfig, MikroORM, } from '@mikro-orm/core';
2
2
  import { MongoDriver } from './MongoDriver.js';
3
3
  /** Creates a type-safe configuration object for the MongoDB driver. */
4
4
  export function defineMongoConfig(options) {
5
- return defineConfig({ driver: MongoDriver, ...options });
5
+ return defineConfig({ driver: MongoDriver, ...options });
6
6
  }
7
7
  /**
8
8
  * @inheritDoc
9
9
  */
10
10
  export class MongoMikroORM extends MikroORM {
11
- /**
12
- * @inheritDoc
13
- */
14
- static async init(options) {
15
- return super.init(defineMongoConfig(options));
16
- }
17
- /**
18
- * @inheritDoc
19
- */
20
- constructor(options) {
21
- super(defineMongoConfig(options));
22
- }
23
- /**
24
- * Gets the Migrator.
25
- */
26
- get migrator() {
27
- return this.driver
28
- .getPlatform()
29
- .getExtension('Migrator', '@mikro-orm/migrator', '@mikro-orm/migrations-mongodb', this.em);
30
- }
11
+ /**
12
+ * @inheritDoc
13
+ */
14
+ static async init(options) {
15
+ return super.init(defineMongoConfig(options));
16
+ }
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ constructor(options) {
21
+ super(defineMongoConfig(options));
22
+ }
23
+ /**
24
+ * Gets the Migrator.
25
+ */
26
+ get migrator() {
27
+ return this.driver
28
+ .getPlatform()
29
+ .getExtension('Migrator', '@mikro-orm/migrator', '@mikro-orm/migrations-mongodb', this.em);
30
+ }
31
31
  }
@@ -1,45 +1,30 @@
1
1
  import { ObjectId } from 'mongodb';
2
- import {
3
- Platform,
4
- type IPrimaryKey,
5
- type Primary,
6
- type NamingStrategy,
7
- type Constructor,
8
- type EntityRepository,
9
- type EntityProperty,
10
- type PopulateOptions,
11
- type EntityMetadata,
12
- type IDatabaseDriver,
13
- type EntityManager,
14
- type Configuration,
15
- type MikroORM,
16
- type TransformContext,
17
- } from '@mikro-orm/core';
2
+ import { Platform, type IPrimaryKey, type Primary, type NamingStrategy, type Constructor, type EntityRepository, type EntityProperty, type PopulateOptions, type EntityMetadata, type IDatabaseDriver, type EntityManager, type Configuration, type MikroORM, type TransformContext } from '@mikro-orm/core';
18
3
  import { MongoExceptionConverter } from './MongoExceptionConverter.js';
19
4
  import { MongoSchemaGenerator } from './MongoSchemaGenerator.js';
20
5
  /** Platform implementation for MongoDB. */
21
6
  export declare class MongoPlatform extends Platform {
22
- protected readonly exceptionConverter: MongoExceptionConverter;
23
- setConfig(config: Configuration): void;
24
- getNamingStrategy(): {
25
- new (): NamingStrategy;
26
- };
27
- getRepositoryClass<T extends object>(): Constructor<EntityRepository<T>>;
28
- /** @inheritDoc */
29
- lookupExtensions(orm: MikroORM): void;
30
- /** @inheritDoc */
31
- getExtension<T>(extensionName: string, extensionKey: string, moduleName: string, em: EntityManager): T;
32
- getSchemaGenerator(driver: IDatabaseDriver, em?: EntityManager): MongoSchemaGenerator;
33
- normalizePrimaryKey<T extends number | string = number | string>(data: Primary<T> | IPrimaryKey | ObjectId): T;
34
- denormalizePrimaryKey(data: number | string): IPrimaryKey;
35
- usesImplicitTransactions(): boolean;
36
- convertsJsonAutomatically(): boolean;
37
- convertJsonToDatabaseValue(value: unknown): unknown;
38
- convertJsonToJSValue(value: unknown, context?: TransformContext): unknown;
39
- marshallArray(values: string[]): string;
40
- cloneEmbeddable<T>(data: T): T;
41
- shouldHaveColumn<T>(prop: EntityProperty<T>, populate: PopulateOptions<T>[], exclude?: string[]): boolean;
42
- validateMetadata(meta: EntityMetadata): void;
43
- isAllowedTopLevelOperator(operator: string): boolean;
44
- getDefaultClientUrl(): string;
7
+ protected readonly exceptionConverter: MongoExceptionConverter;
8
+ setConfig(config: Configuration): void;
9
+ getNamingStrategy(): {
10
+ new (): NamingStrategy;
11
+ };
12
+ getRepositoryClass<T extends object>(): Constructor<EntityRepository<T>>;
13
+ /** @inheritDoc */
14
+ lookupExtensions(orm: MikroORM): void;
15
+ /** @inheritDoc */
16
+ getExtension<T>(extensionName: string, extensionKey: string, moduleName: string, em: EntityManager): T;
17
+ getSchemaGenerator(driver: IDatabaseDriver, em?: EntityManager): MongoSchemaGenerator;
18
+ normalizePrimaryKey<T extends number | string = number | string>(data: Primary<T> | IPrimaryKey | ObjectId): T;
19
+ denormalizePrimaryKey(data: number | string): IPrimaryKey;
20
+ usesImplicitTransactions(): boolean;
21
+ convertsJsonAutomatically(): boolean;
22
+ convertJsonToDatabaseValue(value: unknown): unknown;
23
+ convertJsonToJSValue(value: unknown, context?: TransformContext): unknown;
24
+ marshallArray(values: string[]): string;
25
+ cloneEmbeddable<T>(data: T): T;
26
+ shouldHaveColumn<T>(prop: EntityProperty<T>, populate: PopulateOptions<T>[], exclude?: string[]): boolean;
27
+ validateMetadata(meta: EntityMetadata): void;
28
+ isAllowedTopLevelOperator(operator: string): boolean;
29
+ getDefaultClientUrl(): string;
45
30
  }