Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat(typescript): Improve adapter typings#2605

Merged
daffl merged 1 commit intodovefeathersjs/feathers:dovefrom
adapter-typesfeathersjs/feathers:adapter-typesCopy head branch name to clipboard
Apr 23, 2022
Merged

feat(typescript): Improve adapter typings#2605
daffl merged 1 commit intodovefeathersjs/feathers:dovefrom
adapter-typesfeathersjs/feathers:adapter-typesCopy head branch name to clipboard

Conversation

@daffl
Copy link
Member

@daffl daffl commented Apr 23, 2022

This is a follow-up to #2600 and closes #2564.

It updates the adapter types with the proper overloads, most importantly returning an array when passing { paginate: false }. It also adds an AdapterBase service from which other adapters can now extend implementing only the hook-less service methods and no service interface. The reason is that generated services will now extend from those and then implement the official service methods which will by default in turn call their internal counterpart. This allows to implement the service methods you want with different parameter types and return values without being restricted by any incompatible interfaces.

export class UserService extends MemoryAdapter<UserResult, UserData, UserServiceParams> {
  async find (params?: UserServiceParams & { paginate?: PaginationOptions }): Promise<Paginated<T>>;
  async find (params?: UserServiceParams & { paginate: false }): Promise<UserResult[]>;
  async find (params?: UserServiceParams): Promise<Paginated<UserResult>|UserResult[]>;
  async find (params?: UserServiceParams): Promise<Paginated<UserResult>|UserResult[]> {
    return this._find(params);
  }

  async get (id: Id, params?: UserServiceParams) {
    return {
      id,
      message: 'I can return whatever I want here'
    };
  }

  async create (data: UserCreateData, params?: UserServiceParams) {
    return this._create(data, params);
  }

  async update (id: Id, data: D, params?: UserServiceParams): Promise<T> {
    return this._update(id, data, params);
  }

  async patch (id: Id, data: Partial<D>, params?: UserServiceParams): Promise<UserResult>;
  async patch (id: null, data: Partial<D>, params?: UserServiceParams): Promise<UserResult[]>;
  async patch (id: NullableId, data: Partial<D>, params?: UserServiceParams): Promise<UserResult | UserResult[]> {
    return this._patch(id, data, params);
  }

  async remove (id: Id, params?: UserServiceParams): Promise<UserResult>;
  async remove (id: null, params?: UserServiceParams): Promise<UserResult[]>;
  async remove (id: NullableId, params?: UserServiceParams): Promise<UserResult | UserResult[]> {
    return this._remove(id, params);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pagination and query TypeScript improvements

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.