Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, NullableId is wrong for update. Only patch and remove are allowed to have a NullableId. Am I wrong @daffl?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. It should just be Id. If the interface were setup for NullableId, it would mean you could completely replace multiple documents with the same id, which isn't possible.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was my bad. A bunch of those issues will be fixed in #2906

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

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