Skip to content

Commit 9ddc2e6

Browse files
authored
feat(adapter): Add patch data type to adapters and refactor AdapterBase usage (#2906)
1 parent b66c734 commit 9ddc2e6

File tree

22 files changed

+5914
-3334
lines changed

22 files changed

+5914
-3334
lines changed

docs/api/databases/common.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ app.use('/messages', service({ id, events, paginate }))
3939
### Options
4040

4141
- `id` (_optional_) - The name of the id field property (usually set by default to `id` or `_id`).
42-
- `events` (_optional_) - A list of [custom service events](../events.md#custom-events) sent by this service
4342
- `paginate` (_optional_) - A [pagination object](#pagination) containing a `default` and `max` page size
44-
- `allow` (_optional_) - A list of additional non-standard query parameters to allow (e.g `[ '$regex', '$populate' ]`)
4543
- `multi` (_optional_, default: `false`) - Allow `create` with arrays and `patch` and `remove` with id `null` to change multiple items. Can be `true` for all methods or an array of allowed methods (e.g. `[ 'remove', 'create' ]`)
4644

45+
The following legacy options are still available but should be avoided:
46+
47+
- `events` (_optional_, **deprecated**) - A list of [custom service events](../events.md#custom-events) sent by this service. Use the `events` option when [registering the service with app.use](../application.md#usepath-service--options) instead.
48+
- `operators` (_optional_, **deprecated**) - A list of additional non-standard query parameters to allow (e.g `[ '$regex' ]`). Not necessary when using a [query schema validator](../schema/validators.md#validatequery)
49+
- `filters` (_optional_, **deprecated**) - A list of top level `$` query parameters to allow (e.g. `[ '$populate' ]`). Not necessary when using a [query schema validator](../schema/validators.md#validatequery)
50+
4751
## Pagination
4852

4953
When initializing an adapter you can set the following pagination options in the `paginate` object:
@@ -92,13 +96,17 @@ app.service('todos').find({
9296
})
9397
```
9498

95-
> **Note:** Disabling or changing the default pagination is not available in the client. Only `params.query` is passed to the server (also see a [workaround here](https://github.com/feathersjs/feathers/issues/382#issuecomment-238407741))
99+
<BlockQuote type="info" label="note">
100+
101+
Disabling or changing the default pagination is not available in the client. Only `params.query` is passed to the server (also see a [workaround here](https://github.com/feathersjs/feathers/issues/382#issuecomment-238407741))
102+
103+
</BlockQuote>
96104

97105
## Extending Adapters
98106

99-
There are two ways to extend existing database adapters. Either by extending the ES6 base class or by adding functionality through hooks.
107+
There are two ways to extend existing database adapters. Either by extending the base class or by adding functionality through hooks.
100108

101-
### Classes (ES6)
109+
### Classes
102110

103111
All modules also export an [ES6 class](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes) as `Service` that can be directly extended like this:
104112

docs/package-lock.json

Lines changed: 286 additions & 285 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 5116 additions & 2624 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/adapter-commons/src/declarations.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Query, Params, Paginated, Id, NullableId } from '@feathersjs/feathers'
1+
import { Query, Params, Paginated, Id } from '@feathersjs/feathers'
22

33
export type FilterQueryOptions = {
44
filters?: FilterSettings
@@ -34,19 +34,23 @@ export interface AdapterServiceOptions {
3434
paginate?: PaginationParams
3535
/**
3636
* A list of additional property query operators to allow in a query
37+
*
38+
* @deprecated No longer needed when a query schema is used
3739
*/
3840
operators?: string[]
3941
/**
4042
* An object of additional top level query filters, e.g. `{ $populate: true }`
4143
* Can also be a converter function like `{ $ignoreCase: (value) => value === 'true' ? true : false }`
44+
*
45+
* @deprecated No longer needed when a query schema is used
4246
*/
4347
filters?: FilterSettings
4448
/**
4549
* @deprecated Use service `events` option when registering the service with `app.use`.
4650
*/
4751
events?: string[]
4852
/**
49-
* @deprecated renamed to `operators`.
53+
* @deprecated No longer needed when a query schema is used
5054
*/
5155
whitelist?: string[]
5256
}
@@ -80,16 +84,22 @@ export interface AdapterParams<
8084
*
8185
* @see {@link https://docs.feathersjs.com/guides/migrating.html#hook-less-service-methods}
8286
*/
83-
export interface InternalServiceMethods<T = any, D = T, P extends AdapterParams = AdapterParams> {
87+
export interface InternalServiceMethods<
88+
Result = any,
89+
Data = Result,
90+
PatchData = Partial<Data>,
91+
Params extends AdapterParams = AdapterParams,
92+
IdType = Id
93+
> {
8494
/**
8595
* Retrieve all resources from this service.
8696
* Does not sanitize the query and should only be used on the server.
8797
*
8898
* @param _params - Service call parameters {@link Params}
8999
*/
90-
$find(_params?: P & { paginate?: PaginationOptions }): Promise<Paginated<T>>
91-
$find(_params?: P & { paginate: false }): Promise<T[]>
92-
$find(params?: P): Promise<T[] | Paginated<T>>
100+
_find(_params?: Params & { paginate?: PaginationOptions }): Promise<Paginated<Result>>
101+
_find(_params?: Params & { paginate: false }): Promise<Result[]>
102+
_find(params?: Params): Promise<Result[] | Paginated<Result>>
93103

94104
/**
95105
* Retrieve a single resource matching the given ID, skipping any service-level hooks.
@@ -100,7 +110,7 @@ export interface InternalServiceMethods<T = any, D = T, P extends AdapterParams
100110
* @see {@link HookLessServiceMethods}
101111
* @see {@link https://docs.feathersjs.com/api/services.html#get-id-params|Feathers API Documentation: .get(id, params)}
102112
*/
103-
$get(id: Id, params?: P): Promise<T>
113+
_get(id: IdType, params?: Params): Promise<Result>
104114

105115
/**
106116
* Create a new resource for this service, skipping any service-level hooks.
@@ -111,9 +121,9 @@ export interface InternalServiceMethods<T = any, D = T, P extends AdapterParams
111121
* @see {@link HookLessServiceMethods}
112122
* @see {@link https://docs.feathersjs.com/api/services.html#create-data-params|Feathers API Documentation: .create(data, params)}
113123
*/
114-
$create(data: Partial<D>, params?: P): Promise<T>
115-
$create(data: Partial<D>[], params?: P): Promise<T[]>
116-
$create(data: Partial<D> | Partial<D>[], params?: P): Promise<T | T[]>
124+
_create(data: Data, params?: Params): Promise<Result>
125+
_create(data: Data[], params?: Params): Promise<Result[]>
126+
_create(data: Data | Data[], params?: Params): Promise<Result | Result[]>
117127

118128
/**
119129
* Completely replace the resource identified by id, skipping any service-level hooks.
@@ -125,7 +135,7 @@ export interface InternalServiceMethods<T = any, D = T, P extends AdapterParams
125135
* @see {@link HookLessServiceMethods}
126136
* @see {@link https://docs.feathersjs.com/api/services.html#update-id-data-params|Feathers API Documentation: .update(id, data, params)}
127137
*/
128-
$update(id: Id, data: D, params?: P): Promise<T>
138+
_update(id: IdType, data: Data, params?: Params): Promise<Result>
129139

130140
/**
131141
* Merge any resources matching the given ID with the given data, skipping any service-level hooks.
@@ -137,9 +147,9 @@ export interface InternalServiceMethods<T = any, D = T, P extends AdapterParams
137147
* @see {@link HookLessServiceMethods}
138148
* @see {@link https://docs.feathersjs.com/api/services.html#patch-id-data-params|Feathers API Documentation: .patch(id, data, params)}
139149
*/
140-
$patch(id: null, data: Partial<D>, params?: P): Promise<T[]>
141-
$patch(id: Id, data: Partial<D>, params?: P): Promise<T>
142-
$patch(id: NullableId, data: Partial<D>, params?: P): Promise<T | T[]>
150+
_patch(id: null, data: PatchData, params?: Params): Promise<Result[]>
151+
_patch(id: IdType, data: PatchData, params?: Params): Promise<Result>
152+
_patch(id: IdType | null, data: PatchData, params?: Params): Promise<Result | Result[]>
143153

144154
/**
145155
* Remove resources matching the given ID from the this service, skipping any service-level hooks.
@@ -150,7 +160,7 @@ export interface InternalServiceMethods<T = any, D = T, P extends AdapterParams
150160
* @see {@link HookLessServiceMethods}
151161
* @see {@link https://docs.feathersjs.com/api/services.html#remove-id-params|Feathers API Documentation: .remove(id, params)}
152162
*/
153-
$remove(id: null, params?: P): Promise<T[]>
154-
$remove(id: Id, params?: P): Promise<T>
155-
$remove(id: NullableId, params?: P): Promise<T | T[]>
163+
_remove(id: null, params?: Params): Promise<Result[]>
164+
_remove(id: IdType, params?: Params): Promise<Result>
165+
_remove(id: IdType | null, params?: Params): Promise<Result | Result[]>
156166
}

0 commit comments

Comments
 (0)