Skip to content

Commit

Permalink
fix(adapter-commons): multiple type definition issues
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNoim committed Nov 16, 2022
1 parent 7bb44ec commit 6732e2c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/adapter-commons/src/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export interface AdapterParams<
*
* @see {@link https://docs.feathersjs.com/guides/migrating.html#hook-less-service-methods}
*/
export interface InternalServiceMethods<T = any, D = Partial<T>, P extends AdapterParams = AdapterParams> {
export interface InternalServiceMethods<T = any, D = T, P extends AdapterParams = AdapterParams> {
/**
* Retrieve all resources from this service.
* Does not sanitize the query and should only be used on the server.
Expand Down
6 changes: 3 additions & 3 deletions packages/adapter-commons/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const alwaysMulti: { [key: string]: boolean } = {
*/
export abstract class AdapterBase<
T = any,
D = Partial<T>,
D = T,
P extends AdapterParams = AdapterParams,
O extends AdapterServiceOptions = AdapterServiceOptions
> implements InternalServiceMethods<T, D, P>
Expand Down Expand Up @@ -130,8 +130,8 @@ export abstract class AdapterBase<
*/
async _find(_params?: P & { paginate?: PaginationOptions }): Promise<Paginated<T>>
async _find(_params?: P & { paginate: false }): Promise<T[]>
async _find(params?: P): Promise<T | T[] | Paginated<T>>
async _find(params?: P): Promise<T | T[] | Paginated<T>> {
async _find(params?: P): Promise<T[] | Paginated<T>>
async _find(params?: P): Promise<T[] | Paginated<T>> {
const query = await this.sanitizeQuery(params)

return this.$find({
Expand Down
19 changes: 9 additions & 10 deletions packages/adapter-commons/test/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@ export type Data = {
}

export class MethodBase
extends AdapterBase<Data, Partial<Data>, AdapterParams>
extends AdapterBase<Data, Data, AdapterParams>
implements InternalServiceMethods<Data>
{
async $find(_params?: AdapterParams & { paginate?: PaginationOptions }): Promise<Paginated<Data>>
async $find(_params?: AdapterParams & { paginate: false }): Promise<Data[]>
async $find(params?: AdapterParams): Promise<Data | Data[] | Paginated<Data>>
async $find(params?: AdapterParams): Promise<Data | Data[] | Paginated<Data>> {
if (params && params.paginate === false) {
return {
total: 0,
limit: 10,
skip: 0,
data: []
}
return []
}

return []
return {
total: 0,
limit: 10,
skip: 0,
data: []
}
}

async $get(id: Id, _params?: AdapterParams): Promise<Data> {
Expand Down Expand Up @@ -51,7 +50,7 @@ export class MethodBase
}

async $update(id: NullableId, _data: Data, _params?: AdapterParams) {
return Promise.resolve({ id })
return Promise.resolve({ id: id ?? _data.id })
}

async $patch(id: null, _data: Partial<Data>, _params?: AdapterParams): Promise<Data[]>
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-commons/test/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('@feathersjs/adapter-commons/service', () => {
METHODS.forEach((method) => {
it(`${method}`, () => {
const service = new MethodService({})
const args = []
const args: any[] = []

if (method !== 'find') {
args.push('test')
Expand Down

0 comments on commit 6732e2c

Please sign in to comment.