@feathersjs/adapter-commons 5.0.0-pre.33 → 5.0.0-pre.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/lib/declarations.d.ts +27 -23
- package/lib/service.d.ts +40 -66
- package/lib/service.js +7 -86
- package/lib/service.js.map +1 -1
- package/package.json +9 -9
- package/src/declarations.ts +27 -17
- package/src/service.ts +51 -138
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [5.0.0-pre.34](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.33...v5.0.0-pre.34) (2022-12-14)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **adapter-commons:** multiple type definition issues ([#2876](https://github.com/feathersjs/feathers/issues/2876)) ([4ff1ed0](https://github.com/feathersjs/feathers/commit/4ff1ed084eb2b2cb687de27a28c96a0dad4530b7))
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- **adapter:** Add patch data type to adapters and refactor AdapterBase usage ([#2906](https://github.com/feathersjs/feathers/issues/2906)) ([9ddc2e6](https://github.com/feathersjs/feathers/commit/9ddc2e6b028f026f939d6af68125847e5c6734b4))
|
|
15
|
+
|
|
6
16
|
# [5.0.0-pre.33](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.32...v5.0.0-pre.33) (2022-11-08)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @feathersjs/adapter-commons
|
package/lib/declarations.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { Query, Params, Paginated, Id
|
|
2
|
-
export
|
|
1
|
+
import { Query, Params, Paginated, Id } from '@feathersjs/feathers';
|
|
2
|
+
export type FilterQueryOptions = {
|
|
3
3
|
filters?: FilterSettings;
|
|
4
4
|
operators?: string[];
|
|
5
5
|
paginate?: PaginationParams;
|
|
6
6
|
};
|
|
7
|
-
export
|
|
8
|
-
export
|
|
7
|
+
export type QueryFilter = (value: any, options: FilterQueryOptions) => any;
|
|
8
|
+
export type FilterSettings = {
|
|
9
9
|
[key: string]: QueryFilter | true;
|
|
10
10
|
};
|
|
11
11
|
export interface PaginationOptions {
|
|
12
12
|
default?: number;
|
|
13
13
|
max?: number;
|
|
14
14
|
}
|
|
15
|
-
export
|
|
15
|
+
export type PaginationParams = false | PaginationOptions;
|
|
16
16
|
export interface AdapterServiceOptions {
|
|
17
17
|
/**
|
|
18
18
|
* Whether to allow multiple updates for everything (`true`) or specific methods (e.g. `['create', 'remove']`)
|
|
@@ -28,11 +28,15 @@ export interface AdapterServiceOptions {
|
|
|
28
28
|
paginate?: PaginationParams;
|
|
29
29
|
/**
|
|
30
30
|
* A list of additional property query operators to allow in a query
|
|
31
|
+
*
|
|
32
|
+
* @deprecated No longer needed when a query schema is used
|
|
31
33
|
*/
|
|
32
34
|
operators?: string[];
|
|
33
35
|
/**
|
|
34
36
|
* An object of additional top level query filters, e.g. `{ $populate: true }`
|
|
35
37
|
* Can also be a converter function like `{ $ignoreCase: (value) => value === 'true' ? true : false }`
|
|
38
|
+
*
|
|
39
|
+
* @deprecated No longer needed when a query schema is used
|
|
36
40
|
*/
|
|
37
41
|
filters?: FilterSettings;
|
|
38
42
|
/**
|
|
@@ -40,7 +44,7 @@ export interface AdapterServiceOptions {
|
|
|
40
44
|
*/
|
|
41
45
|
events?: string[];
|
|
42
46
|
/**
|
|
43
|
-
* @deprecated
|
|
47
|
+
* @deprecated No longer needed when a query schema is used
|
|
44
48
|
*/
|
|
45
49
|
whitelist?: string[];
|
|
46
50
|
}
|
|
@@ -71,20 +75,20 @@ export interface AdapterParams<Q = AdapterQuery, A extends Partial<AdapterServic
|
|
|
71
75
|
*
|
|
72
76
|
* @see {@link https://docs.feathersjs.com/guides/migrating.html#hook-less-service-methods}
|
|
73
77
|
*/
|
|
74
|
-
export interface InternalServiceMethods<
|
|
78
|
+
export interface InternalServiceMethods<Result = any, Data = Result, PatchData = Partial<Data>, Params extends AdapterParams = AdapterParams, IdType = Id> {
|
|
75
79
|
/**
|
|
76
80
|
* Retrieve all resources from this service.
|
|
77
81
|
* Does not sanitize the query and should only be used on the server.
|
|
78
82
|
*
|
|
79
83
|
* @param _params - Service call parameters {@link Params}
|
|
80
84
|
*/
|
|
81
|
-
|
|
85
|
+
_find(_params?: Params & {
|
|
82
86
|
paginate?: PaginationOptions;
|
|
83
|
-
}): Promise<Paginated<
|
|
84
|
-
|
|
87
|
+
}): Promise<Paginated<Result>>;
|
|
88
|
+
_find(_params?: Params & {
|
|
85
89
|
paginate: false;
|
|
86
|
-
}): Promise<
|
|
87
|
-
|
|
90
|
+
}): Promise<Result[]>;
|
|
91
|
+
_find(params?: Params): Promise<Result[] | Paginated<Result>>;
|
|
88
92
|
/**
|
|
89
93
|
* Retrieve a single resource matching the given ID, skipping any service-level hooks.
|
|
90
94
|
* Does not sanitize the query and should only be used on the server.
|
|
@@ -94,7 +98,7 @@ export interface InternalServiceMethods<T = any, D = Partial<T>, P extends Adapt
|
|
|
94
98
|
* @see {@link HookLessServiceMethods}
|
|
95
99
|
* @see {@link https://docs.feathersjs.com/api/services.html#get-id-params|Feathers API Documentation: .get(id, params)}
|
|
96
100
|
*/
|
|
97
|
-
|
|
101
|
+
_get(id: IdType, params?: Params): Promise<Result>;
|
|
98
102
|
/**
|
|
99
103
|
* Create a new resource for this service, skipping any service-level hooks.
|
|
100
104
|
* Does not sanitize data or checks if multiple updates are allowed and should only be used on the server.
|
|
@@ -104,9 +108,9 @@ export interface InternalServiceMethods<T = any, D = Partial<T>, P extends Adapt
|
|
|
104
108
|
* @see {@link HookLessServiceMethods}
|
|
105
109
|
* @see {@link https://docs.feathersjs.com/api/services.html#create-data-params|Feathers API Documentation: .create(data, params)}
|
|
106
110
|
*/
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
111
|
+
_create(data: Data, params?: Params): Promise<Result>;
|
|
112
|
+
_create(data: Data[], params?: Params): Promise<Result[]>;
|
|
113
|
+
_create(data: Data | Data[], params?: Params): Promise<Result | Result[]>;
|
|
110
114
|
/**
|
|
111
115
|
* Completely replace the resource identified by id, skipping any service-level hooks.
|
|
112
116
|
* Does not sanitize data or query and should only be used on the server.
|
|
@@ -117,7 +121,7 @@ export interface InternalServiceMethods<T = any, D = Partial<T>, P extends Adapt
|
|
|
117
121
|
* @see {@link HookLessServiceMethods}
|
|
118
122
|
* @see {@link https://docs.feathersjs.com/api/services.html#update-id-data-params|Feathers API Documentation: .update(id, data, params)}
|
|
119
123
|
*/
|
|
120
|
-
|
|
124
|
+
_update(id: IdType, data: Data, params?: Params): Promise<Result>;
|
|
121
125
|
/**
|
|
122
126
|
* Merge any resources matching the given ID with the given data, skipping any service-level hooks.
|
|
123
127
|
* Does not sanitize the data or query and should only be used on the server.
|
|
@@ -128,9 +132,9 @@ export interface InternalServiceMethods<T = any, D = Partial<T>, P extends Adapt
|
|
|
128
132
|
* @see {@link HookLessServiceMethods}
|
|
129
133
|
* @see {@link https://docs.feathersjs.com/api/services.html#patch-id-data-params|Feathers API Documentation: .patch(id, data, params)}
|
|
130
134
|
*/
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
135
|
+
_patch(id: null, data: PatchData, params?: Params): Promise<Result[]>;
|
|
136
|
+
_patch(id: IdType, data: PatchData, params?: Params): Promise<Result>;
|
|
137
|
+
_patch(id: IdType | null, data: PatchData, params?: Params): Promise<Result | Result[]>;
|
|
134
138
|
/**
|
|
135
139
|
* Remove resources matching the given ID from the this service, skipping any service-level hooks.
|
|
136
140
|
* Does not sanitize query and should only be used on the server.
|
|
@@ -140,7 +144,7 @@ export interface InternalServiceMethods<T = any, D = Partial<T>, P extends Adapt
|
|
|
140
144
|
* @see {@link HookLessServiceMethods}
|
|
141
145
|
* @see {@link https://docs.feathersjs.com/api/services.html#remove-id-params|Feathers API Documentation: .remove(id, params)}
|
|
142
146
|
*/
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
147
|
+
_remove(id: null, params?: Params): Promise<Result[]>;
|
|
148
|
+
_remove(id: IdType, params?: Params): Promise<Result>;
|
|
149
|
+
_remove(id: IdType | null, params?: Params): Promise<Result | Result[]>;
|
|
146
150
|
}
|
package/lib/service.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { Id,
|
|
1
|
+
import { Id, Paginated, Query } from '@feathersjs/feathers';
|
|
2
2
|
import { AdapterParams, AdapterServiceOptions, InternalServiceMethods, PaginationOptions } from './declarations';
|
|
3
|
+
export declare const VALIDATED: unique symbol;
|
|
3
4
|
/**
|
|
4
5
|
* An abstract base class that a database adapter can extend from to implement the
|
|
5
6
|
* `__find`, `__get`, `__update`, `__patch` and `__remove` methods.
|
|
6
7
|
*/
|
|
7
|
-
export declare abstract class AdapterBase<
|
|
8
|
-
options:
|
|
9
|
-
constructor(options:
|
|
8
|
+
export declare abstract class AdapterBase<Result = any, Data = Result, PatchData = Partial<Data>, ServiceParams extends AdapterParams = AdapterParams, Options extends AdapterServiceOptions = AdapterServiceOptions, IdType = Id> implements InternalServiceMethods<Result, Data, PatchData, ServiceParams, IdType> {
|
|
9
|
+
options: Options;
|
|
10
|
+
constructor(options: Options);
|
|
10
11
|
get id(): string;
|
|
11
12
|
get events(): string[];
|
|
12
13
|
/**
|
|
@@ -15,7 +16,7 @@ export declare abstract class AdapterBase<T = any, D = Partial<T>, P extends Ada
|
|
|
15
16
|
* @param params The service call params.
|
|
16
17
|
* @returns Wether or not multiple updates are allowed.
|
|
17
18
|
*/
|
|
18
|
-
allowsMulti(method: string, params?:
|
|
19
|
+
allowsMulti(method: string, params?: ServiceParams): boolean | string[];
|
|
19
20
|
/**
|
|
20
21
|
* Returns the combined options for a service call. Options will be merged
|
|
21
22
|
* with `this.options` and `params.adapter` for dynamic overrides.
|
|
@@ -23,15 +24,7 @@ export declare abstract class AdapterBase<T = any, D = Partial<T>, P extends Ada
|
|
|
23
24
|
* @param params The parameters for the service method call
|
|
24
25
|
* @returns The actual options for this call
|
|
25
26
|
*/
|
|
26
|
-
getOptions(params:
|
|
27
|
-
/**
|
|
28
|
-
* Sanitize the incoming data, e.g. removing invalid keywords etc.
|
|
29
|
-
*
|
|
30
|
-
* @param data The data to sanitize
|
|
31
|
-
* @param _params Service call parameters
|
|
32
|
-
* @returns The sanitized data
|
|
33
|
-
*/
|
|
34
|
-
sanitizeData<X = Partial<D>>(data: X, _params: P): Promise<X>;
|
|
27
|
+
getOptions(params: ServiceParams): Options;
|
|
35
28
|
/**
|
|
36
29
|
* Returns a sanitized version of `params.query`, converting filter values
|
|
37
30
|
* (like $limit and $skip) into the expected type. Will throw an error if
|
|
@@ -41,95 +34,76 @@ export declare abstract class AdapterBase<T = any, D = Partial<T>, P extends Ada
|
|
|
41
34
|
* @param params The service call parameter.
|
|
42
35
|
* @returns A new object containing the sanitized query.
|
|
43
36
|
*/
|
|
44
|
-
sanitizeQuery(params?:
|
|
45
|
-
abstract $find(_params?: P & {
|
|
46
|
-
paginate?: PaginationOptions;
|
|
47
|
-
}): Promise<Paginated<T>>;
|
|
48
|
-
abstract $find(_params?: P & {
|
|
49
|
-
paginate: false;
|
|
50
|
-
}): Promise<T[]>;
|
|
51
|
-
abstract $find(params?: P): Promise<T[] | Paginated<T>>;
|
|
37
|
+
sanitizeQuery(params?: ServiceParams): Promise<Query>;
|
|
52
38
|
/**
|
|
53
|
-
* Retrieve all resources from this service
|
|
54
|
-
*
|
|
39
|
+
* Retrieve all resources from this service.
|
|
40
|
+
* Does not sanitize the query and should only be used on the server.
|
|
55
41
|
*
|
|
56
|
-
* @param
|
|
57
|
-
* @see {@link HookLessServiceMethods}
|
|
58
|
-
* @see {@link https://docs.feathersjs.com/api/services.html#find-params|Feathers API Documentation: .find(params)}
|
|
42
|
+
* @param _params - Service call parameters {@link ServiceParams}
|
|
59
43
|
*/
|
|
60
|
-
_find(_params?:
|
|
44
|
+
abstract _find(_params?: ServiceParams & {
|
|
61
45
|
paginate?: PaginationOptions;
|
|
62
|
-
}): Promise<Paginated<
|
|
63
|
-
_find(_params?:
|
|
46
|
+
}): Promise<Paginated<Result>>;
|
|
47
|
+
abstract _find(_params?: ServiceParams & {
|
|
64
48
|
paginate: false;
|
|
65
|
-
}): Promise<
|
|
66
|
-
_find(params?:
|
|
67
|
-
abstract $get(id: Id, params?: P): Promise<T>;
|
|
49
|
+
}): Promise<Result[]>;
|
|
50
|
+
abstract _find(params?: ServiceParams): Promise<Result[] | Paginated<Result>>;
|
|
68
51
|
/**
|
|
69
|
-
* Retrieve a single resource matching the given ID, skipping any service-level hooks
|
|
70
|
-
*
|
|
52
|
+
* Retrieve a single resource matching the given ID, skipping any service-level hooks.
|
|
53
|
+
* Does not sanitize the query and should only be used on the server.
|
|
71
54
|
*
|
|
72
55
|
* @param id - ID of the resource to locate
|
|
73
|
-
* @param params - Service call parameters {@link
|
|
56
|
+
* @param params - Service call parameters {@link ServiceParams}
|
|
74
57
|
* @see {@link HookLessServiceMethods}
|
|
75
58
|
* @see {@link https://docs.feathersjs.com/api/services.html#get-id-params|Feathers API Documentation: .get(id, params)}
|
|
76
59
|
*/
|
|
77
|
-
_get(id:
|
|
78
|
-
abstract $create(data: Partial<D>, params?: P): Promise<T>;
|
|
79
|
-
abstract $create(data: Partial<D>[], params?: P): Promise<T[]>;
|
|
80
|
-
abstract $create(data: Partial<D> | Partial<D>[], params?: P): Promise<T | T[]>;
|
|
60
|
+
abstract _get(id: IdType, params?: ServiceParams): Promise<Result>;
|
|
81
61
|
/**
|
|
82
|
-
* Create a new resource for this service, skipping any service-level hooks
|
|
83
|
-
*
|
|
62
|
+
* Create a new resource for this service, skipping any service-level hooks.
|
|
63
|
+
* Does not check if multiple updates are allowed and should only be used on the server.
|
|
84
64
|
*
|
|
85
65
|
* @param data - Data to insert into this service.
|
|
86
|
-
* @param params - Service call parameters {@link
|
|
66
|
+
* @param params - Service call parameters {@link ServiceParams}
|
|
87
67
|
* @see {@link HookLessServiceMethods}
|
|
88
68
|
* @see {@link https://docs.feathersjs.com/api/services.html#create-data-params|Feathers API Documentation: .create(data, params)}
|
|
89
69
|
*/
|
|
90
|
-
_create(data:
|
|
91
|
-
_create(data:
|
|
92
|
-
_create(data:
|
|
93
|
-
abstract $update(id: Id, data: D, params?: P): Promise<T>;
|
|
70
|
+
abstract _create(data: Data, params?: ServiceParams): Promise<Result>;
|
|
71
|
+
abstract _create(data: Data[], params?: ServiceParams): Promise<Result[]>;
|
|
72
|
+
abstract _create(data: Data | Data[], params?: ServiceParams): Promise<Result | Result[]>;
|
|
94
73
|
/**
|
|
95
|
-
*
|
|
74
|
+
* Completely replace the resource identified by id, skipping any service-level hooks.
|
|
75
|
+
* Does not sanitize the query and should only be used on the server.
|
|
96
76
|
*
|
|
97
77
|
* @param id - ID of the resource to be updated
|
|
98
78
|
* @param data - Data to be put in place of the current resource.
|
|
99
|
-
* @param params - Service call parameters {@link
|
|
79
|
+
* @param params - Service call parameters {@link ServiceParams}
|
|
100
80
|
* @see {@link HookLessServiceMethods}
|
|
101
81
|
* @see {@link https://docs.feathersjs.com/api/services.html#update-id-data-params|Feathers API Documentation: .update(id, data, params)}
|
|
102
82
|
*/
|
|
103
|
-
_update(id:
|
|
104
|
-
abstract $patch(id: null, data: Partial<D>, params?: P): Promise<T[]>;
|
|
105
|
-
abstract $patch(id: Id, data: Partial<D>, params?: P): Promise<T>;
|
|
106
|
-
abstract $patch(id: NullableId, data: Partial<D>, params?: P): Promise<T | T[]>;
|
|
83
|
+
abstract _update(id: IdType, data: Data, params?: ServiceParams): Promise<Result>;
|
|
107
84
|
/**
|
|
108
85
|
* Merge any resources matching the given ID with the given data, skipping any service-level hooks.
|
|
109
|
-
*
|
|
86
|
+
* Does not sanitize the query and should only be used on the server.
|
|
110
87
|
*
|
|
111
88
|
* @param id - ID of the resource to be patched
|
|
112
89
|
* @param data - Data to merge with the current resource.
|
|
113
|
-
* @param params - Service call parameters {@link
|
|
90
|
+
* @param params - Service call parameters {@link ServiceParams}
|
|
114
91
|
* @see {@link HookLessServiceMethods}
|
|
115
92
|
* @see {@link https://docs.feathersjs.com/api/services.html#patch-id-data-params|Feathers API Documentation: .patch(id, data, params)}
|
|
116
93
|
*/
|
|
117
|
-
_patch(id: null, data:
|
|
118
|
-
_patch(id:
|
|
119
|
-
_patch(id:
|
|
120
|
-
abstract $remove(id: null, params?: P): Promise<T[]>;
|
|
121
|
-
abstract $remove(id: Id, params?: P): Promise<T>;
|
|
122
|
-
abstract $remove(id: NullableId, params?: P): Promise<T | T[]>;
|
|
94
|
+
abstract _patch(id: null, data: PatchData, params?: ServiceParams): Promise<Result[]>;
|
|
95
|
+
abstract _patch(id: IdType, data: PatchData, params?: ServiceParams): Promise<Result>;
|
|
96
|
+
abstract _patch(id: IdType | null, data: PatchData, params?: ServiceParams): Promise<Result | Result[]>;
|
|
123
97
|
/**
|
|
124
98
|
* Remove resources matching the given ID from the this service, skipping any service-level hooks.
|
|
125
|
-
*
|
|
99
|
+
* Does not sanitize query and should only be used on the server.
|
|
126
100
|
*
|
|
127
101
|
* @param id - ID of the resource to be removed
|
|
128
|
-
* @param params - Service call parameters {@link
|
|
102
|
+
* @param params - Service call parameters {@link ServiceParams}
|
|
129
103
|
* @see {@link HookLessServiceMethods}
|
|
130
104
|
* @see {@link https://docs.feathersjs.com/api/services.html#remove-id-params|Feathers API Documentation: .remove(id, params)}
|
|
131
105
|
*/
|
|
132
|
-
_remove(id: null, params?:
|
|
133
|
-
_remove(id:
|
|
134
|
-
_remove(id:
|
|
106
|
+
abstract _remove(id: null, params?: ServiceParams): Promise<Result[]>;
|
|
107
|
+
abstract _remove(id: IdType, params?: ServiceParams): Promise<Result>;
|
|
108
|
+
abstract _remove(id: IdType | null, params?: ServiceParams): Promise<Result | Result[]>;
|
|
135
109
|
}
|
package/lib/service.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AdapterBase = void 0;
|
|
4
|
-
const errors_1 = require("@feathersjs/errors");
|
|
3
|
+
exports.AdapterBase = exports.VALIDATED = void 0;
|
|
5
4
|
const query_1 = require("./query");
|
|
5
|
+
exports.VALIDATED = Symbol('@feathersjs/adapter/sanitized');
|
|
6
6
|
const alwaysMulti = {
|
|
7
7
|
find: true,
|
|
8
8
|
get: false,
|
|
@@ -42,7 +42,7 @@ class AdapterBase {
|
|
|
42
42
|
return always;
|
|
43
43
|
}
|
|
44
44
|
const { multi } = this.getOptions(params);
|
|
45
|
-
if (multi === true || multi
|
|
45
|
+
if (multi === true || !multi) {
|
|
46
46
|
return multi;
|
|
47
47
|
}
|
|
48
48
|
return multi.includes(method);
|
|
@@ -62,16 +62,6 @@ class AdapterBase {
|
|
|
62
62
|
...params.adapter
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
-
/**
|
|
66
|
-
* Sanitize the incoming data, e.g. removing invalid keywords etc.
|
|
67
|
-
*
|
|
68
|
-
* @param data The data to sanitize
|
|
69
|
-
* @param _params Service call parameters
|
|
70
|
-
* @returns The sanitized data
|
|
71
|
-
*/
|
|
72
|
-
async sanitizeData(data, _params) {
|
|
73
|
-
return data;
|
|
74
|
-
}
|
|
75
65
|
/**
|
|
76
66
|
* Returns a sanitized version of `params.query`, converting filter values
|
|
77
67
|
* (like $limit and $skip) into the expected type. Will throw an error if
|
|
@@ -82,6 +72,10 @@ class AdapterBase {
|
|
|
82
72
|
* @returns A new object containing the sanitized query.
|
|
83
73
|
*/
|
|
84
74
|
async sanitizeQuery(params = {}) {
|
|
75
|
+
// We don't need legacy query sanitisation if the query has been validated by a schema already
|
|
76
|
+
if (params.query && params.query[exports.VALIDATED]) {
|
|
77
|
+
return params.query || {};
|
|
78
|
+
}
|
|
85
79
|
const options = this.getOptions(params);
|
|
86
80
|
const { query, filters } = (0, query_1.filterQuery)(params.query, options);
|
|
87
81
|
return {
|
|
@@ -89,79 +83,6 @@ class AdapterBase {
|
|
|
89
83
|
...query
|
|
90
84
|
};
|
|
91
85
|
}
|
|
92
|
-
async _find(params) {
|
|
93
|
-
const query = await this.sanitizeQuery(params);
|
|
94
|
-
return this.$find({
|
|
95
|
-
...params,
|
|
96
|
-
query
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Retrieve a single resource matching the given ID, skipping any service-level hooks but sanitize the query
|
|
101
|
-
* with allowed filters and properties by calling `sanitizeQuery`.
|
|
102
|
-
*
|
|
103
|
-
* @param id - ID of the resource to locate
|
|
104
|
-
* @param params - Service call parameters {@link Params}
|
|
105
|
-
* @see {@link HookLessServiceMethods}
|
|
106
|
-
* @see {@link https://docs.feathersjs.com/api/services.html#get-id-params|Feathers API Documentation: .get(id, params)}
|
|
107
|
-
*/
|
|
108
|
-
async _get(id, params) {
|
|
109
|
-
const query = await this.sanitizeQuery(params);
|
|
110
|
-
return this.$get(id, {
|
|
111
|
-
...params,
|
|
112
|
-
query
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
async _create(data, params) {
|
|
116
|
-
if (Array.isArray(data) && !this.allowsMulti('create', params)) {
|
|
117
|
-
throw new errors_1.MethodNotAllowed('Can not create multiple entries');
|
|
118
|
-
}
|
|
119
|
-
const payload = Array.isArray(data)
|
|
120
|
-
? await Promise.all(data.map((current) => this.sanitizeData(current, params)))
|
|
121
|
-
: await this.sanitizeData(data, params);
|
|
122
|
-
return this.$create(payload, params);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Replace any resources matching the given ID with the given data, skipping any service-level hooks.
|
|
126
|
-
*
|
|
127
|
-
* @param id - ID of the resource to be updated
|
|
128
|
-
* @param data - Data to be put in place of the current resource.
|
|
129
|
-
* @param params - Service call parameters {@link Params}
|
|
130
|
-
* @see {@link HookLessServiceMethods}
|
|
131
|
-
* @see {@link https://docs.feathersjs.com/api/services.html#update-id-data-params|Feathers API Documentation: .update(id, data, params)}
|
|
132
|
-
*/
|
|
133
|
-
async _update(id, data, params) {
|
|
134
|
-
if (id === null || Array.isArray(data)) {
|
|
135
|
-
throw new errors_1.BadRequest("You can not replace multiple instances. Did you mean 'patch'?");
|
|
136
|
-
}
|
|
137
|
-
const payload = await this.sanitizeData(data, params);
|
|
138
|
-
const query = await this.sanitizeQuery(params);
|
|
139
|
-
return this.$update(id, payload, {
|
|
140
|
-
...params,
|
|
141
|
-
query
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
async _patch(id, data, params) {
|
|
145
|
-
if (id === null && !this.allowsMulti('patch', params)) {
|
|
146
|
-
throw new errors_1.MethodNotAllowed('Can not patch multiple entries');
|
|
147
|
-
}
|
|
148
|
-
const { $limit, ...query } = await this.sanitizeQuery(params);
|
|
149
|
-
const payload = await this.sanitizeData(data, params);
|
|
150
|
-
return this.$patch(id, payload, {
|
|
151
|
-
...params,
|
|
152
|
-
query
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
async _remove(id, params) {
|
|
156
|
-
if (id === null && !this.allowsMulti('remove', params)) {
|
|
157
|
-
throw new errors_1.MethodNotAllowed('Can not remove multiple entries');
|
|
158
|
-
}
|
|
159
|
-
const { $limit, ...query } = await this.sanitizeQuery(params);
|
|
160
|
-
return this.$remove(id, {
|
|
161
|
-
...params,
|
|
162
|
-
query
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
86
|
}
|
|
166
87
|
exports.AdapterBase = AdapterBase;
|
|
167
88
|
//# sourceMappingURL=service.js.map
|
package/lib/service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";;;AAOA,mCAAqC;AAExB,QAAA,SAAS,GAAG,MAAM,CAAC,+BAA+B,CAAC,CAAA;AAEhE,MAAM,WAAW,GAA+B;IAC9C,IAAI,EAAE,IAAI;IACV,GAAG,EAAE,KAAK;IACV,MAAM,EAAE,KAAK;CACd,CAAA;AAED;;;GAGG;AACH,MAAsB,WAAW;IAW/B,YAAY,OAAgB;QAC1B,IAAI,CAAC,OAAO,GAAG;YACb,EAAE,EAAE,IAAI;YACR,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE,KAAK;YACf,KAAK,EAAE,KAAK;YACZ,OAAO,EAAE,EAAE;YACX,SAAS,EAAE,EAAE;YACb,GAAG,OAAO;SACX,CAAA;IACH,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAA;IACxB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAA;IAC5B,CAAC;IAED;;;;;OAKG;IACH,WAAW,CAAC,MAAc,EAAE,SAAwB,EAAmB;QACrE,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAA;QAElC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;YACjC,OAAO,MAAM,CAAA;SACd;QAED,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;QAEzC,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,EAAE;YAC5B,OAAO,KAAK,CAAA;SACb;QAED,OAAO,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IAC/B,CAAC;IAED;;;;;;OAMG;IACH,UAAU,CAAC,MAAqB;QAC9B,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAA;QAExF,OAAO;YACL,GAAG,IAAI,CAAC,OAAO;YACf,QAAQ;YACR,GAAG,MAAM,CAAC,OAAO;SAClB,CAAA;IACH,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,aAAa,CAAC,SAAwB,EAAmB;QAC7D,8FAA8F;QAC9F,IAAI,MAAM,CAAC,KAAK,IAAK,MAAM,CAAC,KAAa,CAAC,iBAAS,CAAC,EAAE;YACpD,OAAO,MAAM,CAAC,KAAK,IAAI,EAAE,CAAA;SAC1B;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;QACvC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,IAAA,mBAAW,EAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAE7D,OAAO;YACL,GAAG,OAAO;YACV,GAAG,KAAK;SACT,CAAA;IACH,CAAC;CA0EF;AAtKD,kCAsKC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@feathersjs/adapter-commons",
|
|
3
|
-
"version": "5.0.0-pre.
|
|
3
|
+
"version": "5.0.0-pre.34",
|
|
4
4
|
"description": "Shared database adapter utility functions",
|
|
5
5
|
"homepage": "https://feathersjs.com",
|
|
6
6
|
"keywords": [
|
|
@@ -50,19 +50,19 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@feathersjs/commons": "^5.0.0-pre.
|
|
54
|
-
"@feathersjs/errors": "^5.0.0-pre.
|
|
55
|
-
"@feathersjs/feathers": "^5.0.0-pre.
|
|
53
|
+
"@feathersjs/commons": "^5.0.0-pre.34",
|
|
54
|
+
"@feathersjs/errors": "^5.0.0-pre.34",
|
|
55
|
+
"@feathersjs/feathers": "^5.0.0-pre.34"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@types/mocha": "^10.0.
|
|
58
|
+
"@types/mocha": "^10.0.1",
|
|
59
59
|
"@types/mongodb": "^4.0.6",
|
|
60
|
-
"@types/node": "^18.11.
|
|
60
|
+
"@types/node": "^18.11.10",
|
|
61
61
|
"mocha": "^10.1.0",
|
|
62
|
-
"mongodb": "^4.
|
|
62
|
+
"mongodb": "^4.12.1",
|
|
63
63
|
"shx": "^0.3.4",
|
|
64
64
|
"ts-node": "^10.9.1",
|
|
65
|
-
"typescript": "^4.
|
|
65
|
+
"typescript": "^4.9.3"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "42cca600d00f0b3b9d89fa79be30fcd46bc50132"
|
|
68
68
|
}
|
package/src/declarations.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Query, Params, Paginated, Id
|
|
1
|
+
import { Query, Params, Paginated, Id } from '@feathersjs/feathers'
|
|
2
2
|
|
|
3
3
|
export type FilterQueryOptions = {
|
|
4
4
|
filters?: FilterSettings
|
|
@@ -34,11 +34,15 @@ export interface AdapterServiceOptions {
|
|
|
34
34
|
paginate?: PaginationParams
|
|
35
35
|
/**
|
|
36
36
|
* A list of additional property query operators to allow in a query
|
|
37
|
+
*
|
|
38
|
+
* @deprecated No longer needed when a query schema is used
|
|
37
39
|
*/
|
|
38
40
|
operators?: string[]
|
|
39
41
|
/**
|
|
40
42
|
* An object of additional top level query filters, e.g. `{ $populate: true }`
|
|
41
43
|
* 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
|
|
42
46
|
*/
|
|
43
47
|
filters?: FilterSettings
|
|
44
48
|
/**
|
|
@@ -46,7 +50,7 @@ export interface AdapterServiceOptions {
|
|
|
46
50
|
*/
|
|
47
51
|
events?: string[]
|
|
48
52
|
/**
|
|
49
|
-
* @deprecated
|
|
53
|
+
* @deprecated No longer needed when a query schema is used
|
|
50
54
|
*/
|
|
51
55
|
whitelist?: string[]
|
|
52
56
|
}
|
|
@@ -80,16 +84,22 @@ export interface AdapterParams<
|
|
|
80
84
|
*
|
|
81
85
|
* @see {@link https://docs.feathersjs.com/guides/migrating.html#hook-less-service-methods}
|
|
82
86
|
*/
|
|
83
|
-
export interface InternalServiceMethods<
|
|
87
|
+
export interface InternalServiceMethods<
|
|
88
|
+
Result = any,
|
|
89
|
+
Data = Result,
|
|
90
|
+
PatchData = Partial<Data>,
|
|
91
|
+
Params extends AdapterParams = AdapterParams,
|
|
92
|
+
IdType = Id
|
|
93
|
+
> {
|
|
84
94
|
/**
|
|
85
95
|
* Retrieve all resources from this service.
|
|
86
96
|
* Does not sanitize the query and should only be used on the server.
|
|
87
97
|
*
|
|
88
98
|
* @param _params - Service call parameters {@link Params}
|
|
89
99
|
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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>>
|
|
93
103
|
|
|
94
104
|
/**
|
|
95
105
|
* Retrieve a single resource matching the given ID, skipping any service-level hooks.
|
|
@@ -100,7 +110,7 @@ export interface InternalServiceMethods<T = any, D = Partial<T>, P extends Adapt
|
|
|
100
110
|
* @see {@link HookLessServiceMethods}
|
|
101
111
|
* @see {@link https://docs.feathersjs.com/api/services.html#get-id-params|Feathers API Documentation: .get(id, params)}
|
|
102
112
|
*/
|
|
103
|
-
|
|
113
|
+
_get(id: IdType, params?: Params): Promise<Result>
|
|
104
114
|
|
|
105
115
|
/**
|
|
106
116
|
* Create a new resource for this service, skipping any service-level hooks.
|
|
@@ -111,9 +121,9 @@ export interface InternalServiceMethods<T = any, D = Partial<T>, P extends Adapt
|
|
|
111
121
|
* @see {@link HookLessServiceMethods}
|
|
112
122
|
* @see {@link https://docs.feathersjs.com/api/services.html#create-data-params|Feathers API Documentation: .create(data, params)}
|
|
113
123
|
*/
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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[]>
|
|
117
127
|
|
|
118
128
|
/**
|
|
119
129
|
* Completely replace the resource identified by id, skipping any service-level hooks.
|
|
@@ -125,7 +135,7 @@ export interface InternalServiceMethods<T = any, D = Partial<T>, P extends Adapt
|
|
|
125
135
|
* @see {@link HookLessServiceMethods}
|
|
126
136
|
* @see {@link https://docs.feathersjs.com/api/services.html#update-id-data-params|Feathers API Documentation: .update(id, data, params)}
|
|
127
137
|
*/
|
|
128
|
-
|
|
138
|
+
_update(id: IdType, data: Data, params?: Params): Promise<Result>
|
|
129
139
|
|
|
130
140
|
/**
|
|
131
141
|
* 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 = Partial<T>, P extends Adapt
|
|
|
137
147
|
* @see {@link HookLessServiceMethods}
|
|
138
148
|
* @see {@link https://docs.feathersjs.com/api/services.html#patch-id-data-params|Feathers API Documentation: .patch(id, data, params)}
|
|
139
149
|
*/
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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[]>
|
|
143
153
|
|
|
144
154
|
/**
|
|
145
155
|
* 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 = Partial<T>, P extends Adapt
|
|
|
150
160
|
* @see {@link HookLessServiceMethods}
|
|
151
161
|
* @see {@link https://docs.feathersjs.com/api/services.html#remove-id-params|Feathers API Documentation: .remove(id, params)}
|
|
152
162
|
*/
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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[]>
|
|
156
166
|
}
|
package/src/service.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Id, NullableId, Paginated, Query } from '@feathersjs/feathers'
|
|
1
|
+
import { Id, Paginated, Query } from '@feathersjs/feathers'
|
|
3
2
|
import {
|
|
4
3
|
AdapterParams,
|
|
5
4
|
AdapterServiceOptions,
|
|
@@ -8,6 +7,8 @@ import {
|
|
|
8
7
|
} from './declarations'
|
|
9
8
|
import { filterQuery } from './query'
|
|
10
9
|
|
|
10
|
+
export const VALIDATED = Symbol('@feathersjs/adapter/sanitized')
|
|
11
|
+
|
|
11
12
|
const alwaysMulti: { [key: string]: boolean } = {
|
|
12
13
|
find: true,
|
|
13
14
|
get: false,
|
|
@@ -19,15 +20,17 @@ const alwaysMulti: { [key: string]: boolean } = {
|
|
|
19
20
|
* `__find`, `__get`, `__update`, `__patch` and `__remove` methods.
|
|
20
21
|
*/
|
|
21
22
|
export abstract class AdapterBase<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
Result = any,
|
|
24
|
+
Data = Result,
|
|
25
|
+
PatchData = Partial<Data>,
|
|
26
|
+
ServiceParams extends AdapterParams = AdapterParams,
|
|
27
|
+
Options extends AdapterServiceOptions = AdapterServiceOptions,
|
|
28
|
+
IdType = Id
|
|
29
|
+
> implements InternalServiceMethods<Result, Data, PatchData, ServiceParams, IdType>
|
|
27
30
|
{
|
|
28
|
-
options:
|
|
31
|
+
options: Options
|
|
29
32
|
|
|
30
|
-
constructor(options:
|
|
33
|
+
constructor(options: Options) {
|
|
31
34
|
this.options = {
|
|
32
35
|
id: 'id',
|
|
33
36
|
events: [],
|
|
@@ -53,7 +56,7 @@ export abstract class AdapterBase<
|
|
|
53
56
|
* @param params The service call params.
|
|
54
57
|
* @returns Wether or not multiple updates are allowed.
|
|
55
58
|
*/
|
|
56
|
-
allowsMulti(method: string, params:
|
|
59
|
+
allowsMulti(method: string, params: ServiceParams = {} as ServiceParams) {
|
|
57
60
|
const always = alwaysMulti[method]
|
|
58
61
|
|
|
59
62
|
if (typeof always !== 'undefined') {
|
|
@@ -62,7 +65,7 @@ export abstract class AdapterBase<
|
|
|
62
65
|
|
|
63
66
|
const { multi } = this.getOptions(params)
|
|
64
67
|
|
|
65
|
-
if (multi === true || multi
|
|
68
|
+
if (multi === true || !multi) {
|
|
66
69
|
return multi
|
|
67
70
|
}
|
|
68
71
|
|
|
@@ -76,7 +79,7 @@ export abstract class AdapterBase<
|
|
|
76
79
|
* @param params The parameters for the service method call
|
|
77
80
|
* @returns The actual options for this call
|
|
78
81
|
*/
|
|
79
|
-
getOptions(params:
|
|
82
|
+
getOptions(params: ServiceParams): Options {
|
|
80
83
|
const paginate = params.paginate !== undefined ? params.paginate : this.options.paginate
|
|
81
84
|
|
|
82
85
|
return {
|
|
@@ -86,17 +89,6 @@ export abstract class AdapterBase<
|
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
91
|
|
|
89
|
-
/**
|
|
90
|
-
* Sanitize the incoming data, e.g. removing invalid keywords etc.
|
|
91
|
-
*
|
|
92
|
-
* @param data The data to sanitize
|
|
93
|
-
* @param _params Service call parameters
|
|
94
|
-
* @returns The sanitized data
|
|
95
|
-
*/
|
|
96
|
-
async sanitizeData<X = Partial<D>>(data: X, _params: P) {
|
|
97
|
-
return data
|
|
98
|
-
}
|
|
99
|
-
|
|
100
92
|
/**
|
|
101
93
|
* Returns a sanitized version of `params.query`, converting filter values
|
|
102
94
|
* (like $limit and $skip) into the expected type. Will throw an error if
|
|
@@ -106,7 +98,12 @@ export abstract class AdapterBase<
|
|
|
106
98
|
* @param params The service call parameter.
|
|
107
99
|
* @returns A new object containing the sanitized query.
|
|
108
100
|
*/
|
|
109
|
-
async sanitizeQuery(params:
|
|
101
|
+
async sanitizeQuery(params: ServiceParams = {} as ServiceParams): Promise<Query> {
|
|
102
|
+
// We don't need legacy query sanitisation if the query has been validated by a schema already
|
|
103
|
+
if (params.query && (params.query as any)[VALIDATED]) {
|
|
104
|
+
return params.query || {}
|
|
105
|
+
}
|
|
106
|
+
|
|
110
107
|
const options = this.getOptions(params)
|
|
111
108
|
const { query, filters } = filterQuery(params.query, options)
|
|
112
109
|
|
|
@@ -116,160 +113,76 @@ export abstract class AdapterBase<
|
|
|
116
113
|
}
|
|
117
114
|
}
|
|
118
115
|
|
|
119
|
-
abstract $find(_params?: P & { paginate?: PaginationOptions }): Promise<Paginated<T>>
|
|
120
|
-
abstract $find(_params?: P & { paginate: false }): Promise<T[]>
|
|
121
|
-
abstract $find(params?: P): Promise<T[] | Paginated<T>>
|
|
122
|
-
|
|
123
116
|
/**
|
|
124
|
-
* Retrieve all resources from this service
|
|
125
|
-
*
|
|
117
|
+
* Retrieve all resources from this service.
|
|
118
|
+
* Does not sanitize the query and should only be used on the server.
|
|
126
119
|
*
|
|
127
|
-
* @param
|
|
128
|
-
* @see {@link HookLessServiceMethods}
|
|
129
|
-
* @see {@link https://docs.feathersjs.com/api/services.html#find-params|Feathers API Documentation: .find(params)}
|
|
120
|
+
* @param _params - Service call parameters {@link ServiceParams}
|
|
130
121
|
*/
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
async _find(params?: P): Promise<T | T[] | Paginated<T>> {
|
|
135
|
-
const query = await this.sanitizeQuery(params)
|
|
136
|
-
|
|
137
|
-
return this.$find({
|
|
138
|
-
...params,
|
|
139
|
-
query
|
|
140
|
-
})
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
abstract $get(id: Id, params?: P): Promise<T>
|
|
122
|
+
abstract _find(_params?: ServiceParams & { paginate?: PaginationOptions }): Promise<Paginated<Result>>
|
|
123
|
+
abstract _find(_params?: ServiceParams & { paginate: false }): Promise<Result[]>
|
|
124
|
+
abstract _find(params?: ServiceParams): Promise<Result[] | Paginated<Result>>
|
|
144
125
|
|
|
145
126
|
/**
|
|
146
|
-
* Retrieve a single resource matching the given ID, skipping any service-level hooks
|
|
147
|
-
*
|
|
127
|
+
* Retrieve a single resource matching the given ID, skipping any service-level hooks.
|
|
128
|
+
* Does not sanitize the query and should only be used on the server.
|
|
148
129
|
*
|
|
149
130
|
* @param id - ID of the resource to locate
|
|
150
|
-
* @param params - Service call parameters {@link
|
|
131
|
+
* @param params - Service call parameters {@link ServiceParams}
|
|
151
132
|
* @see {@link HookLessServiceMethods}
|
|
152
133
|
* @see {@link https://docs.feathersjs.com/api/services.html#get-id-params|Feathers API Documentation: .get(id, params)}
|
|
153
134
|
*/
|
|
154
|
-
|
|
155
|
-
const query = await this.sanitizeQuery(params)
|
|
156
|
-
|
|
157
|
-
return this.$get(id, {
|
|
158
|
-
...params,
|
|
159
|
-
query
|
|
160
|
-
})
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
abstract $create(data: Partial<D>, params?: P): Promise<T>
|
|
164
|
-
abstract $create(data: Partial<D>[], params?: P): Promise<T[]>
|
|
165
|
-
abstract $create(data: Partial<D> | Partial<D>[], params?: P): Promise<T | T[]>
|
|
135
|
+
abstract _get(id: IdType, params?: ServiceParams): Promise<Result>
|
|
166
136
|
|
|
167
137
|
/**
|
|
168
|
-
* Create a new resource for this service, skipping any service-level hooks
|
|
169
|
-
*
|
|
138
|
+
* Create a new resource for this service, skipping any service-level hooks.
|
|
139
|
+
* Does not check if multiple updates are allowed and should only be used on the server.
|
|
170
140
|
*
|
|
171
141
|
* @param data - Data to insert into this service.
|
|
172
|
-
* @param params - Service call parameters {@link
|
|
142
|
+
* @param params - Service call parameters {@link ServiceParams}
|
|
173
143
|
* @see {@link HookLessServiceMethods}
|
|
174
144
|
* @see {@link https://docs.feathersjs.com/api/services.html#create-data-params|Feathers API Documentation: .create(data, params)}
|
|
175
145
|
*/
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
async _create(data: Partial<D> | Partial<D>[], params?: P): Promise<T | T[]> {
|
|
180
|
-
if (Array.isArray(data) && !this.allowsMulti('create', params)) {
|
|
181
|
-
throw new MethodNotAllowed('Can not create multiple entries')
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const payload = Array.isArray(data)
|
|
185
|
-
? await Promise.all(data.map((current) => this.sanitizeData(current, params)))
|
|
186
|
-
: await this.sanitizeData(data, params)
|
|
187
|
-
|
|
188
|
-
return this.$create(payload, params)
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
abstract $update(id: Id, data: D, params?: P): Promise<T>
|
|
146
|
+
abstract _create(data: Data, params?: ServiceParams): Promise<Result>
|
|
147
|
+
abstract _create(data: Data[], params?: ServiceParams): Promise<Result[]>
|
|
148
|
+
abstract _create(data: Data | Data[], params?: ServiceParams): Promise<Result | Result[]>
|
|
192
149
|
|
|
193
150
|
/**
|
|
194
|
-
*
|
|
151
|
+
* Completely replace the resource identified by id, skipping any service-level hooks.
|
|
152
|
+
* Does not sanitize the query and should only be used on the server.
|
|
195
153
|
*
|
|
196
154
|
* @param id - ID of the resource to be updated
|
|
197
155
|
* @param data - Data to be put in place of the current resource.
|
|
198
|
-
* @param params - Service call parameters {@link
|
|
156
|
+
* @param params - Service call parameters {@link ServiceParams}
|
|
199
157
|
* @see {@link HookLessServiceMethods}
|
|
200
158
|
* @see {@link https://docs.feathersjs.com/api/services.html#update-id-data-params|Feathers API Documentation: .update(id, data, params)}
|
|
201
159
|
*/
|
|
202
|
-
|
|
203
|
-
if (id === null || Array.isArray(data)) {
|
|
204
|
-
throw new BadRequest("You can not replace multiple instances. Did you mean 'patch'?")
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const payload = await this.sanitizeData(data, params)
|
|
208
|
-
const query = await this.sanitizeQuery(params)
|
|
209
|
-
|
|
210
|
-
return this.$update(id, payload, {
|
|
211
|
-
...params,
|
|
212
|
-
query
|
|
213
|
-
})
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
abstract $patch(id: null, data: Partial<D>, params?: P): Promise<T[]>
|
|
217
|
-
abstract $patch(id: Id, data: Partial<D>, params?: P): Promise<T>
|
|
218
|
-
abstract $patch(id: NullableId, data: Partial<D>, params?: P): Promise<T | T[]>
|
|
160
|
+
abstract _update(id: IdType, data: Data, params?: ServiceParams): Promise<Result>
|
|
219
161
|
|
|
220
162
|
/**
|
|
221
163
|
* Merge any resources matching the given ID with the given data, skipping any service-level hooks.
|
|
222
|
-
*
|
|
164
|
+
* Does not sanitize the query and should only be used on the server.
|
|
223
165
|
*
|
|
224
166
|
* @param id - ID of the resource to be patched
|
|
225
167
|
* @param data - Data to merge with the current resource.
|
|
226
|
-
* @param params - Service call parameters {@link
|
|
168
|
+
* @param params - Service call parameters {@link ServiceParams}
|
|
227
169
|
* @see {@link HookLessServiceMethods}
|
|
228
170
|
* @see {@link https://docs.feathersjs.com/api/services.html#patch-id-data-params|Feathers API Documentation: .patch(id, data, params)}
|
|
229
171
|
*/
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
async _patch(id: NullableId, data: Partial<D>, params?: P): Promise<T | T[]> {
|
|
234
|
-
if (id === null && !this.allowsMulti('patch', params)) {
|
|
235
|
-
throw new MethodNotAllowed('Can not patch multiple entries')
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const { $limit, ...query } = await this.sanitizeQuery(params)
|
|
239
|
-
const payload = await this.sanitizeData(data, params)
|
|
240
|
-
|
|
241
|
-
return this.$patch(id, payload, {
|
|
242
|
-
...params,
|
|
243
|
-
query
|
|
244
|
-
})
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
abstract $remove(id: null, params?: P): Promise<T[]>
|
|
248
|
-
abstract $remove(id: Id, params?: P): Promise<T>
|
|
249
|
-
abstract $remove(id: NullableId, params?: P): Promise<T | T[]>
|
|
172
|
+
abstract _patch(id: null, data: PatchData, params?: ServiceParams): Promise<Result[]>
|
|
173
|
+
abstract _patch(id: IdType, data: PatchData, params?: ServiceParams): Promise<Result>
|
|
174
|
+
abstract _patch(id: IdType | null, data: PatchData, params?: ServiceParams): Promise<Result | Result[]>
|
|
250
175
|
|
|
251
176
|
/**
|
|
252
177
|
* Remove resources matching the given ID from the this service, skipping any service-level hooks.
|
|
253
|
-
*
|
|
178
|
+
* Does not sanitize query and should only be used on the server.
|
|
254
179
|
*
|
|
255
180
|
* @param id - ID of the resource to be removed
|
|
256
|
-
* @param params - Service call parameters {@link
|
|
181
|
+
* @param params - Service call parameters {@link ServiceParams}
|
|
257
182
|
* @see {@link HookLessServiceMethods}
|
|
258
183
|
* @see {@link https://docs.feathersjs.com/api/services.html#remove-id-params|Feathers API Documentation: .remove(id, params)}
|
|
259
184
|
*/
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
async _remove(id: NullableId, params?: P): Promise<T | T[]> {
|
|
264
|
-
if (id === null && !this.allowsMulti('remove', params)) {
|
|
265
|
-
throw new MethodNotAllowed('Can not remove multiple entries')
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
const { $limit, ...query } = await this.sanitizeQuery(params)
|
|
269
|
-
|
|
270
|
-
return this.$remove(id, {
|
|
271
|
-
...params,
|
|
272
|
-
query
|
|
273
|
-
})
|
|
274
|
-
}
|
|
185
|
+
abstract _remove(id: null, params?: ServiceParams): Promise<Result[]>
|
|
186
|
+
abstract _remove(id: IdType, params?: ServiceParams): Promise<Result>
|
|
187
|
+
abstract _remove(id: IdType | null, params?: ServiceParams): Promise<Result | Result[]>
|
|
275
188
|
}
|