Skip to content

Commit 4ff1ed0

Browse files
authored
fix(adapter-commons): multiple type definition issues (#2876)
1 parent 7d03b57 commit 4ff1ed0

4 files changed

Lines changed: 14 additions & 15 deletions

File tree

packages/adapter-commons/src/declarations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export interface AdapterParams<
8080
*
8181
* @see {@link https://docs.feathersjs.com/guides/migrating.html#hook-less-service-methods}
8282
*/
83-
export interface InternalServiceMethods<T = any, D = Partial<T>, P extends AdapterParams = AdapterParams> {
83+
export interface InternalServiceMethods<T = any, D = T, P extends AdapterParams = AdapterParams> {
8484
/**
8585
* Retrieve all resources from this service.
8686
* Does not sanitize the query and should only be used on the server.

packages/adapter-commons/src/service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const alwaysMulti: { [key: string]: boolean } = {
2020
*/
2121
export abstract class AdapterBase<
2222
T = any,
23-
D = Partial<T>,
23+
D = T,
2424
P extends AdapterParams = AdapterParams,
2525
O extends AdapterServiceOptions = AdapterServiceOptions
2626
> implements InternalServiceMethods<T, D, P>
@@ -130,8 +130,8 @@ export abstract class AdapterBase<
130130
*/
131131
async _find(_params?: P & { paginate?: PaginationOptions }): Promise<Paginated<T>>
132132
async _find(_params?: P & { paginate: false }): Promise<T[]>
133-
async _find(params?: P): Promise<T | T[] | Paginated<T>>
134-
async _find(params?: P): Promise<T | T[] | Paginated<T>> {
133+
async _find(params?: P): Promise<T[] | Paginated<T>>
134+
async _find(params?: P): Promise<T[] | Paginated<T>> {
135135
const query = await this.sanitizeQuery(params)
136136

137137
return this.$find({

packages/adapter-commons/test/fixture.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,22 @@ export type Data = {
66
}
77

88
export class MethodBase
9-
extends AdapterBase<Data, Partial<Data>, AdapterParams>
9+
extends AdapterBase<Data, Data, AdapterParams>
1010
implements InternalServiceMethods<Data>
1111
{
1212
async $find(_params?: AdapterParams & { paginate?: PaginationOptions }): Promise<Paginated<Data>>
1313
async $find(_params?: AdapterParams & { paginate: false }): Promise<Data[]>
14-
async $find(params?: AdapterParams): Promise<Data | Data[] | Paginated<Data>>
1514
async $find(params?: AdapterParams): Promise<Data | Data[] | Paginated<Data>> {
1615
if (params && params.paginate === false) {
17-
return {
18-
total: 0,
19-
limit: 10,
20-
skip: 0,
21-
data: []
22-
}
16+
return []
2317
}
2418

25-
return []
19+
return {
20+
total: 0,
21+
limit: 10,
22+
skip: 0,
23+
data: []
24+
}
2625
}
2726

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

5352
async $update(id: NullableId, _data: Data, _params?: AdapterParams) {
54-
return Promise.resolve({ id })
53+
return Promise.resolve({ id: id ?? _data.id })
5554
}
5655

5756
async $patch(id: null, _data: Partial<Data>, _params?: AdapterParams): Promise<Data[]>

packages/adapter-commons/test/service.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('@feathersjs/adapter-commons/service', () => {
1616
METHODS.forEach((method) => {
1717
it(`${method}`, () => {
1818
const service = new MethodService({})
19-
const args = []
19+
const args: any[] = []
2020

2121
if (method !== 'find') {
2222
args.push('test')

0 commit comments

Comments
 (0)