UNPKG

moleculer-mongobubble

Version:

A Moleculer module for generating CRUD APIs using MongoBubble.

21 lines (20 loc) 1.16 kB
import { ClonableConstructor, MongoRepositoryOptions } from '@mongobubble/core'; import { ObjectId } from 'bson'; import { ServiceSchema } from 'moleculer'; import { EntityWithLifecycle, LifecyclePluginOptions, MongoBubble } from 'mongobubble'; import { Document } from 'mongodb'; export type MongoBubbleMixinOptions = { reuseGlobalClient?: boolean; reuseLocalRepository?: boolean; dbName: string; uri?: string; }; export type MongoBubbleMixin<TEntity extends EntityWithLifecycle<TEntity, Identity>, Identity> = Partial<ServiceSchema> & { repository?: MongoBubble<TEntity, Identity>; mongobubbleMixinOptions: MongoBubbleMixinOptions; }; export type EntityClassWithStatics<TEntity> = ClonableConstructor<TEntity> & Partial<{ COLLECTION: string; parseId: (id: string) => ObjectId | number | string; }>; export default function createDbServiceMixin<TEntity extends EntityWithLifecycle<TEntity, Identity>, Identity = ObjectId>(entityClass: EntityClassWithStatics<TEntity>, mixinOptions?: MongoBubbleMixinOptions, repositoryOptions?: Document & MongoRepositoryOptions<TEntity> & LifecyclePluginOptions): Partial<ServiceSchema>;