import { CompiledSchema, IDbPlugin } from '@agrejus/db-framework-core'; import { DbSet } from '../DbSet'; import { DbSetOptions } from '../types'; import { DbSetInstanceCreator } from './types'; export class DbSetBuilder { private _onDbSetCreated: (dbset: DbSet) => void; private readonly _schema: CompiledSchema; private readonly _dbPlugin: IDbPlugin; private _isStateful: boolean = false; constructor(dbPlugin: IDbPlugin, schema: CompiledSchema, onDbSetCreated: (dbset: DbSet) => void) { this._schema = schema; this._dbPlugin = dbPlugin; this._onDbSetCreated = onDbSetCreated; } stateful() { this._isStateful = true; return this; } create(): DbSet; create>(extend: (i: DbSetInstanceCreator, dbPlugin: IDbPlugin, schema: CompiledSchema, options: DbSetOptions) => TExtension): TExtension; create = never>(extend?: (i: DbSetInstanceCreator, dbPlugin: IDbPlugin, schema: CompiledSchema, options: DbSetOptions) => TExtension) { if (extend == null) { return new DbSet(this._dbPlugin, this._schema, { stateful: this._isStateful }); } return extend(DbSet, this._dbPlugin, this._schema, { stateful: this._isStateful }); } }