import { PaginationOptions } from '@feathersjs/adapter-commons' import { MethodNotAllowed } from '@feathersjs/errors/lib' import { Paginated, ServiceMethods, Id, NullableId, Params } from '@feathersjs/feathers' import { KnexAdapter } from './adapter' import { KnexAdapterParams } from './declarations' export * from './declarations' export * from './adapter' export * from './error-handler' export * as transaction from './hooks' export class KnexService< Result = any, Data = Partial, ServiceParams extends Params = KnexAdapterParams, PatchData = Partial > extends KnexAdapter implements ServiceMethods, Data, ServiceParams, PatchData> { async find(params?: ServiceParams & { paginate?: PaginationOptions }): Promise> async find(params?: ServiceParams & { paginate: false }): Promise async find(params?: ServiceParams): Promise | Result[]> async find(params?: ServiceParams): Promise | Result[]> { return this._find({ ...params, query: await this.sanitizeQuery(params) }) } async get(id: Id, params?: ServiceParams): Promise { return this._get(id, { ...params, query: await this.sanitizeQuery(params) }) } async create(data: Data, params?: ServiceParams): Promise async create(data: Data[], params?: ServiceParams): Promise async create(data: Data | Data[], params?: ServiceParams): Promise async create(data: Data | Data[], params?: ServiceParams): Promise { if (Array.isArray(data) && !this.allowsMulti('create', params)) { throw new MethodNotAllowed('Can not create multiple entries') } return this._create(data, params) } async update(id: Id, data: Data, params?: ServiceParams): Promise { return this._update(id, data, { ...params, query: await this.sanitizeQuery(params) }) } async patch(id: Id, data: PatchData, params?: ServiceParams): Promise async patch(id: null, data: PatchData, params?: ServiceParams): Promise async patch(id: NullableId, data: PatchData, params?: ServiceParams): Promise async patch(id: NullableId, data: PatchData, params?: ServiceParams): Promise { const { $limit, ...query } = await this.sanitizeQuery(params) return this._patch(id, data, { ...params, query }) } async remove(id: Id, params?: ServiceParams): Promise async remove(id: null, params?: ServiceParams): Promise async remove(id: NullableId, params?: ServiceParams): Promise async remove(id: NullableId, params?: ServiceParams): Promise { const { $limit, ...query } = await this.sanitizeQuery(params) return this._remove(id, { ...params, query }) } }